package com.ann.demo.controller;

import com.ann.demo.entity.constant.InterfaceName;
import com.ann.demo.service.AnalysisService;
import org.apache.cxf.endpoint.Client;
import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Objects;

/**
 * @Author: LeiJiaXin
 * @Date: 2019/7/11 18:47
 */
@Controller
@RequestMapping("/")
public class TestController {

    @Autowired
    AnalysisService analysisService;

    @RequestMapping("/demo")
    public String aa() {
        return "demo";
    }

    /*@ResponseBody*/
    @RequestMapping("/haha")
    public String cc(InterfaceForm interfaceForm) {
        JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
        Client client = dcf.createClient(interfaceForm.getUrl());
        Object[] objects = new Object[0];
        try {
            // invoke("方法名",参数1,参数2,参数3....);
            if (Objects.equals(interfaceForm.getInterfaceName(), "ReceiveDict") ||
                    Objects.equals(interfaceForm.getInterfaceName(), "InpSummary") ||
                    Objects.equals(interfaceForm.getInterfaceName(), "handNumbnessReport") ||
                    Objects.equals(interfaceForm.getInterfaceName(), InterfaceName.ICU_REPORT) ||
                    Objects.equals(interfaceForm.getInterfaceName(), InterfaceName.BLOODAPPLY_REPORT) ||
                    Objects.equals(interfaceForm.getInterfaceName(), InterfaceName.DOCTOR_DATA) ||
                    Objects.equals(interfaceForm.getInterfaceName(), InterfaceName.NURSE_DATA)) {
                objects = client.invoke(interfaceForm.getInterfaceName(), interfaceForm.getContent());
            } else {
                objects = client.invoke(interfaceForm.getInterfaceName(), interfaceForm.getParameter(), interfaceForm.getContent());
            }
            System.out.println(objects[0]);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "redirect:/demo";
    }

}
