|
|
@@ -1,6 +1,7 @@
|
|
|
package com.github.zuihou.business.controller.externalApi;
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
+import cn.hutool.json.JSONUtil;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
@@ -60,6 +61,8 @@ import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
+import java.util.stream.Stream;
|
|
|
+
|
|
|
import com.github.zuihou.business.externalApi.entity.R2;
|
|
|
|
|
|
@Slf4j
|
|
|
@@ -531,27 +534,47 @@ public class ProductionTasksController {
|
|
|
BaseContextHandler.setTenant("0000");
|
|
|
String instructionUrl="http://192.168.123.7/api-acq/v1/devicecltdata/saveDeviceInfoToIOTDB";
|
|
|
String ccsUrl="http://192.168.11.240:8089/api/GetDigitalTwins";
|
|
|
- JSONArray jsonArray = new JSONArray();
|
|
|
|
|
|
+ JSONArray jsonArray = new JSONArray();
|
|
|
String resultData = msgUtil.httpForPost(ccsUrl, "");
|
|
|
JSONArray returnArr = JSONObject.parseArray(resultData);
|
|
|
- returnArr.stream().filter(item->{
|
|
|
+ List<Object> deviceList = returnArr.stream().filter(item->{
|
|
|
JSONObject itemObject = (JSONObject)item;
|
|
|
Productionresource productionresource = productionresourceBizService.getById(itemObject.getString("resourceId"));
|
|
|
return StringUtil.isNotEmpty(productionresource.getModeSpecification());
|
|
|
- }).forEach(item->{
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+
|
|
|
+ Map<String, String> dataMap = null;
|
|
|
+ List<Productionresource> KEDEList = productionresourceBizService.list(new LbqWrapper<Productionresource>().eq(Productionresource::getModeSpecification, "KEDE").orderByAsc(Productionresource::getId));
|
|
|
+ JSONObject template = (JSONObject)deviceList.get(0);
|
|
|
+ if(KEDEList.size()>0) {
|
|
|
+ KEDEList.stream().forEach(obj -> {
|
|
|
+ JSONObject instance = new JSONObject();
|
|
|
+ BeanUtil.copyProperties(template, instance);
|
|
|
+ instance.put("resourceId", obj.getId());
|
|
|
+ instance.put("deviceName", obj.getName());
|
|
|
+ deviceList.add(instance);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ deviceList.stream().forEach(item->{
|
|
|
JSONObject jsonParam= new JSONObject();
|
|
|
- JSONObject itemObject = (JSONObject)item;
|
|
|
+ JSONObject itemObject = (JSONObject)item;
|
|
|
Productionresource productionresource = productionresourceBizService.getById(itemObject.getString("resourceId"));
|
|
|
itemObject.remove("id");
|
|
|
itemObject.put("ip", productionresource.getIp());
|
|
|
itemObject.put("ACQ_SERVICE_STATUS", "1");
|
|
|
+ if(productionresource.getModeSpecification().equals("KEDE")){
|
|
|
+ //处理机床数据
|
|
|
+ itemObject = this.getKEDEMachineData(productionresource, itemObject);
|
|
|
+ }
|
|
|
jsonParam.put("cltParamInfo", itemObject);
|
|
|
jsonParam.put("deviceNo", productionresource.getCode());
|
|
|
jsonParam.put("recordTime", new Date());
|
|
|
jsonArray.add(jsonParam);
|
|
|
});
|
|
|
//System.out.println(jsonArray.toJSONString());
|
|
|
+
|
|
|
String returnData = msgUtil.httpForPost(instructionUrl,jsonArray.toJSONString());
|
|
|
return R2.success(returnData);
|
|
|
}
|
|
|
@@ -560,4 +583,30 @@ public class ProductionTasksController {
|
|
|
public void syncMesDeviceInfo(){
|
|
|
this.saveDeviceInfoToIOTDB(new HashMap());
|
|
|
}
|
|
|
+
|
|
|
+ //@ApiOperation(value = "科德机床数据采集", notes = "科德机床数据采集")
|
|
|
+ //@PostMapping("/DataCollector/getKEDEMachineInfo")
|
|
|
+ private JSONObject getKEDEMachineData(Productionresource productionresource, JSONObject instance) {
|
|
|
+ boolean bool = productionresource.getOnlineStatus()=="0" || productionresource.getStatus()=="0" ? true:false;
|
|
|
+ List<String> urls = Stream.of("opc.tcp://192.168.11.63:12686","opc.tcp://192.168.11.64:12686","opc.tcp://192.168.11.65:12686").collect(Collectors.toList());
|
|
|
+ String url = productionresource.getName().contains("1")? urls.get(0) :(productionresource.getName().contains("2")? urls.get(1):urls.get(2));
|
|
|
+
|
|
|
+ List<String> dataList = null;
|
|
|
+ //解析数据
|
|
|
+ try{
|
|
|
+ Map dataMap = msgUtil.getKEDEMachineInfo(url);
|
|
|
+ dataList = new ArrayList<String>(dataMap.values());
|
|
|
+ instance.put("feedRate", !bool?dataList.get(0): null);
|
|
|
+ instance.put("spindleMagnification", !bool?dataList.get(1): null);
|
|
|
+ instance.put("spindleSpeed", !bool?dataList.get(2): null);
|
|
|
+ instance.put("spindleLoad", !bool?dataList.get(3): null);
|
|
|
+ }
|
|
|
+ catch (Exception ex){
|
|
|
+ instance.put("feedRate", null);
|
|
|
+ instance.put("spindleMagnification", null);
|
|
|
+ instance.put("spindleSpeed", null);
|
|
|
+ instance.put("spindleLoad", null);
|
|
|
+ }
|
|
|
+ return instance;
|
|
|
+ }
|
|
|
}
|