zhuguifei
2026-03-10 58402bd5e762361363a0f7d7907153c77dbb819f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
package com.shlanbao.tzsc.pms.sys.InterfaceTest.controller;
 
import com.google.gson.Gson;
import com.shlanbao.tzsc.base.controller.BaseController;
import com.shlanbao.tzsc.base.interceptor.PMSXmlDataInterceptor;
import com.shlanbao.tzsc.base.model.DataGrid;
import com.shlanbao.tzsc.base.model.Json;
import com.shlanbao.tzsc.base.model.Tree;
import com.shlanbao.tzsc.data.webservice.client.SendMessageClient;
import com.shlanbao.tzsc.utils.extents.MethodName;
import com.shlanbao.tzsc.utils.tools.RedisUtil;
import com.shlanbao.tzsc.utils.tools.StringUtil;
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
 
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
 
/**
 * 接口测试控制器
 * @author bsw
 * @create 2019年12月30日
 */
@Controller
@RequestMapping("/pms/test")
public class InterfaceTestController extends BaseController {
 
    /**
     * 所有接口方法
     * @author bsw
     * @create 2019年12月30日
 
     * @return
     */
    @RequestMapping("/getAllMethods")
    @ResponseBody
    public String getAllMethods(){
        try {
            List<Tree> list = new ArrayList<>();
            Class cl = Class.forName("com.shlanbao.tzsc.data.webservice.client.SendMessageClient");
            Method[] methods = cl.getMethods();
                if(methods != null) {
 
                    Tree tree = null;
                    for (Method method : methods) {
 
                        MethodName methodName = method.getAnnotation(MethodName.class);
                        if (methodName == null){
                            continue;
                        }
                        tree = new Tree();
                        tree.setId(method.getName());
                        tree.setText(methodName.name());
 
                        list.add(tree);
                    }
                }
            Gson gson=new Gson();
            String json = gson.toJson(list);
            //返回到前台
            return json;
        } catch (Exception e) {
            log.error(message, e);
        }
        return null;
    }
    /**
     * @Description //根据方法名称调用接口发送xml消息
     * @Author bsw
     * @Date 2019/12/30 8:51
     * @Param [method, xml]
     * @return void
     **/
    @RequestMapping("/sendMsg")
    @ResponseBody
    public void sendMsg(String method,String xml) {
        try {
            Class cl = Class.forName("com.shlanbao.tzsc.data.webservice.client.SendMessageClient");
            SendMessageClient client = (SendMessageClient) cl.newInstance();
            Method[] methods = cl.getMethods();
            if (methods != null) {
                for (Method me : methods) {
                    if (me.getName().equals(method)){
 
                        me.invoke(client,xml);
                    }
                }
            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }
    
    
    /**
     * @Author bsw
     * @Description 反馈一次成品率
     * @Date 2021/8/18 17:14 
     * @Param [prod, date, rate]
     * @return com.shlanbao.tzsc.base.model.Json
     **/
 
    @RequestMapping("/sendFirstPassYield")
    @ResponseBody
    public Json sendFirstPassYield(String prod,String date,String rate) {
        Json json = new Json();
        json.setSuccess(true);
        json.setMsg("年月:"+date+",品牌:" + prod +",一次成品率:" + rate);
        String xml = "";
        try{
            Document document;
            document= DocumentHelper.createDocument();
 
            Element datasetElement = document.addElement("dataset");
            Element journalElement =  datasetElement.addElement("data");
            Element brand =  journalElement.addElement("brand");
            brand.setText(StringUtil.nullToString( prod));//牌号
            Element value =  journalElement.addElement("value");
            value.setText(rate); //一次成品率
            Element time =  journalElement.addElement("time");
            time.setText(date); //一次成品率
            xml=document.asXML();
        }catch (Exception e) {
 
            e.printStackTrace();
        }
        SendMessageClient.SendPRValueToMes(xml);
        PMSXmlDataInterceptor.getInstance().addLog(true,"发送一次成品率", 1, xml);
        return json;
    }
    
    
}