|
|
|
@ -0,0 +1,119 @@
|
|
|
|
|
package cn.estsh.i3plus.ext.mes.pcn.apiservice.serviceimpl.equiplog;
|
|
|
|
|
|
|
|
|
|
import cn.estsh.i3plus.ext.mes.pcn.api.busi.IWriteOPCEquipmentService;
|
|
|
|
|
import cn.estsh.i3plus.mes.pcn.util.datatable.DataColumnCollection;
|
|
|
|
|
import cn.estsh.i3plus.pojo.base.enumutil.WmsEnumUtil;
|
|
|
|
|
import cn.estsh.impp.framework.boot.exception.ImppBusiException;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.json.XML;
|
|
|
|
|
import com.alibaba.excel.util.StringUtils;
|
|
|
|
|
|
|
|
|
|
import cn.estsh.impp.framework.boot.util.ResultBean;
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.springframework.http.*;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import org.springframework.web.client.RestTemplate;
|
|
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @Description : WriteOPCEquipmentServiceImpl
|
|
|
|
|
* @Author :gsz
|
|
|
|
|
* @Date 2024/5/29 10:48
|
|
|
|
|
* @Modify
|
|
|
|
|
**/
|
|
|
|
|
@Slf4j
|
|
|
|
|
@Service("WriteOPCEquipmentServiceImpl")
|
|
|
|
|
public class WriteOPCEquipmentServiceImpl implements IWriteOPCEquipmentService {
|
|
|
|
|
@Override
|
|
|
|
|
public ResultBean doOPCEquipment(List<Map<String, Object>> listData,String xmlString) {
|
|
|
|
|
|
|
|
|
|
RestTemplate restTemplate = new RestTemplate();
|
|
|
|
|
HttpHeaders headers = new HttpHeaders();
|
|
|
|
|
// headers.setContentType(MediaType.APPLICATION_JSON_UTF8); //application/soap+xml;charset=UTF-8
|
|
|
|
|
headers.setContentType(MediaType.APPLICATION_JSON_UTF8);
|
|
|
|
|
cn.hutool.json.JSONObject jsonObjectParam = XML.toJSONObject(xmlString);
|
|
|
|
|
String content = jsonObjectParam.toString();
|
|
|
|
|
HttpEntity<String> request = new HttpEntity<>(content, headers);
|
|
|
|
|
String url = String.format("http://172.28.16.50:8111/WriteOPCEquipmentService" );
|
|
|
|
|
ResponseEntity<String> response = restTemplate.postForEntity(url, request, String.class);
|
|
|
|
|
|
|
|
|
|
if (response.getStatusCode().is2xxSuccessful()) {
|
|
|
|
|
String bodyJson = response.getBody();
|
|
|
|
|
JSONObject jsonObject = JSON.parseObject(bodyJson);
|
|
|
|
|
if ("0" == jsonObject.getString("code")) {
|
|
|
|
|
return new ResultBean(WmsEnumUtil.RC_RESPONSE_TIPS.OK.getCodeStatus(),
|
|
|
|
|
"OK");
|
|
|
|
|
} else {
|
|
|
|
|
throw new ImppBusiException(String.format("Error message【%s】", jsonObject.getString("message")));
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
throw new ImppBusiException(String.format("Error Code %s", response.getStatusCode().toString()));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
private String convertListToXml(DataColumnCollection newTable, List<Map<String, Object>> listData, String rootNodeName, String nodeName,
|
|
|
|
|
String rootClassName, String nodeClassName) {
|
|
|
|
|
if (listData == null || listData.size() == 0) {
|
|
|
|
|
throw new RuntimeException("listData is null ! ");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
|
|
|
|
|
|
if (rootNodeName != null && !rootNodeName.isEmpty() && rootClassName != null && !rootClassName.isEmpty()) {
|
|
|
|
|
sb.append(String.format("<%s class=\"%s\">\n", rootNodeName, rootClassName));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (Map<String, Object> row : listData) {
|
|
|
|
|
// 子节点的类名可能为空,这种情况下不需要填充类名
|
|
|
|
|
if (StringUtils.isEmpty(nodeClassName)) {
|
|
|
|
|
sb.append(String.format("<%s>\n", nodeName));
|
|
|
|
|
} else {
|
|
|
|
|
sb.append(String.format("<%s class=\"%s\">\n", nodeName, nodeClassName));
|
|
|
|
|
}
|
|
|
|
|
newTable.forEach( s ->
|
|
|
|
|
sb.append(String.format("<%s>%s</%s>\n", s, row.get(s.getColumnName()), s))
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
sb.append(String.format("</%s>\n", nodeName));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (rootNodeName != null && !rootNodeName.isEmpty()) {
|
|
|
|
|
sb.append(String.format("</%s>\n", rootNodeName));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return sb.toString();
|
|
|
|
|
}
|
|
|
|
|
// private HashMap<String,String> getData(String serviceCode, String xmlPara){
|
|
|
|
|
// HashMap<String,String> res = new HashMap<>();
|
|
|
|
|
// String endpoint = "http://124.205.248.2:8080/eSales/esales.asmx?WSDL";
|
|
|
|
|
// PostMethod postMethod = new PostMethod(endpoint);
|
|
|
|
|
// byte[] b;
|
|
|
|
|
// try {
|
|
|
|
|
// b = xmlPara.getBytes("utf-8");
|
|
|
|
|
// InputStream is = new ByteArrayInputStream(b,0,b.length);
|
|
|
|
|
// RequestEntity re = new InputStreamRequestEntity(is,b.length,"application/soap+xml; charset=utf-8");
|
|
|
|
|
// //把Soap请求数据添加到PostMethod中
|
|
|
|
|
// postMethod.setRequestEntity(re);
|
|
|
|
|
//
|
|
|
|
|
// //生成一个HttpClient对象,并发出postMethod请求
|
|
|
|
|
// HttpClient httpClient = new HttpClient();
|
|
|
|
|
// int statusCode = httpClient.executeMethod(postMethod);
|
|
|
|
|
// if(200==statusCode){
|
|
|
|
|
// String getServerData = postMethod.getResponseBodyAsString();
|
|
|
|
|
// //System.out.println("----->"+getServerData);
|
|
|
|
|
// //获取返回值状态标识,标识为0:成功;非0:失败
|
|
|
|
|
// res.put("status", "0");
|
|
|
|
|
// res.put("msg", msg);
|
|
|
|
|
// }
|
|
|
|
|
// } catch (Exception e) {
|
|
|
|
|
// res.put("status", "1");
|
|
|
|
|
// res.put("msg", e.toString());
|
|
|
|
|
// e.printStackTrace();
|
|
|
|
|
// }
|
|
|
|
|
// return res;
|
|
|
|
|
// }
|
|
|
|
|
}
|