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;
import java.util.concurrent.*;

/**
 * @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(), "ICUReport") ||
                    Objects.equals(interfaceForm.getInterfaceName(), "BloodTransfusionUrl") ||
                    Objects.equals(interfaceForm.getInterfaceName(), InterfaceName.DOCTOR_DATA) ||
                    Objects.equals(interfaceForm.getInterfaceName(), InterfaceName.NURSE_DATA) ||
                    Objects.equals(interfaceForm.getInterfaceName(), InterfaceName.PARAMETER_EXAMAPPLYSTATECHANGE)) {
                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";
    }

    @ResponseBody
    @RequestMapping("/bb")
    public void cc() {

    }

    @ResponseBody
    @RequestMapping("/pp")
    public String pp() throws ExecutionException, InterruptedException {
        for(int i=0;i<100;i++){
            new EatThread().start();
        }

//        Thread thread =  new Thread();
//        thread.start();
//
//        System.out.println("----程序开始运行----");
//        Date date1 = new Date();
//
//        int taskSize = 10;
//        // 创建一个线程池
//        ExecutorService pool = Executors.newFixedThreadPool(taskSize);
//        // 创建多个有返回值的任务
//        List<Future> list = new ArrayList<Future>();
//        for (int i = 0; i < taskSize; i++) {
//            Callable c = new MyCallable(i + " ");
//            // 执行任务并获取Future对象
//            Future f = pool.submit(c);
//            // System.out.println(">>>" + f.get().toString());
//            list.add(f);
//        }
//        // 关闭线程池
//        pool.shutdown();
//
//        // 获取所有并发任务的运行结果
//        for (Future f : list) {
//            // 从Future对象上获取任务的返回值，并输出到控制台
//            System.out.println(">>>" + f.get().toString());
//        }
//
//        Date date2 = new Date();
//        System.out.println("----程序结束运行----，程序运行时间【"
//                + (date2.getTime() - date1.getTime()) + "毫秒】");

        return "不要生气了！！！";
    }

    @RequestMapping("/dd")
    public String dd() {
        //analysisService.delete();
        return "不要生气了！！！";
    }


}


