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;
|
}
|
|
|
}
|