package com.huigou.bpm.webservice.demo.impl;

import com.huigou.bpm.webservice.application.OtherSystemConfigApplication;
import com.huigou.bpm.webservice.application.WebServiceConfigTypeApplication;
import com.huigou.context.User;
import com.huigou.bpm.webservice.demo.TestWebService;
import com.huigou.bpm.webservice.model.WsRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;

import javax.jws.WebService;
import java.lang.reflect.Method;
import java.lang.reflect.Parameter;
import java.util.ArrayList;
import java.util.List;

@WebService(endpointInterface = "com.huigou.bpm.webservice.demo.impl.TestWebServiceImpl",serviceName = "testWebService", targetNamespace = "http://bpm.service.com/")
public class TestWebServiceImpl implements TestWebService {
    @Autowired
    private ApplicationContext applicationContext;
    @Autowired
    private WebServiceConfigTypeApplication webServiceConfigTypeApplication;
    @Autowired
    private OtherSystemConfigApplication otherSystemConfigApplication;

    @Override
    public String getHelloWord() {
        return "hello word idiisspdofsdf";
    }

    @Override
    public User getUserString(String userId) {
        User user = new User();
        user.setId(userId);
        user.setName("张三");
        user.setCode("zhangsan");
        return user;
    }

    @Override
    public User getUserByRequest(WsRequest wsRequest) {
        Object obj = applicationContext.getBean("operatorApplication");
        Class cls = obj.getClass();
        Object result=null;
        Method[] ms = cls.getMethods();
        for (Method method : ms){
            if("createOperatorByPersonId".equals(method.getName())){
                try{
                    List<Class> paramList = new ArrayList<Class>();
                    Parameter[] params = method.getParameters();
                    for (Parameter p : params) {
                        paramList.add(p.getType());
                        System.out.println(p.getName());
                    }
                    result = method.invoke(obj,"92208DB64549346BE050007F010012C2");
                }catch (Exception e){
                    e.printStackTrace();
                }
            }
        }
        System.out.println(wsRequest.toString());
        System.out.println(wsRequest.getParam().get("lisi").toString());
        return null;
    }
}
