From c9c1560eeffdc73c38ab8ef6e1492b164b2360f5 Mon Sep 17 00:00:00 2001 From: admin <15939171744@163.com> Date: 星期日, 16 六月 2024 09:32:56 +0800 Subject: [PATCH] 临时表功能上传 --- jcdm-main/src/main/java/com/jcdm/main/plcserver/sub/OPCUaSubscription.java | 148 ++++++++++++++++++++++++++++++------------------ 1 files changed, 92 insertions(+), 56 deletions(-) diff --git a/jcdm-main/src/main/java/com/jcdm/main/plcserver/sub/OPCUaSubscription.java b/jcdm-main/src/main/java/com/jcdm/main/plcserver/sub/OPCUaSubscription.java index ba7bcee..99ba9d3 100644 --- a/jcdm-main/src/main/java/com/jcdm/main/plcserver/sub/OPCUaSubscription.java +++ b/jcdm-main/src/main/java/com/jcdm/main/plcserver/sub/OPCUaSubscription.java @@ -24,20 +24,28 @@ import com.jcdm.main.plcserver.conf.OPCElement; import com.jcdm.main.plcserver.util.TimeUtil; import com.jcdm.main.restful.factoryMes.service.RestfulService; +import com.jcdm.main.restful.qingYan.doman.ChildVO; +import com.jcdm.main.restful.qingYan.doman.ParentVO; import com.kangaroohy.milo.model.ReadWriteEntity; import com.kangaroohy.milo.runner.subscription.SubscriptionCallback; import com.kangaroohy.milo.service.MiloService; +import lombok.extern.slf4j.Slf4j; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import javax.websocket.Session; import java.text.SimpleDateFormat; +import java.time.Instant; import java.util.*; import java.util.stream.Collectors; - +@Slf4j @Component public class OPCUaSubscription implements SubscriptionCallback { + + private static final Logger logger = LoggerFactory.getLogger("sys-user"); public SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); @@ -98,6 +106,7 @@ @Override public void onSubscribe(String identifier, Object value) { + logger.info("鍦板潃锛�"+identifier+"鍊硷細"+value); try { if(null != value && Integer.valueOf(value.toString())!= 0) { String[] nodes = identifier.split("[.]"); @@ -198,6 +207,7 @@ // } if(testList.stream().anyMatch(s -> s.equals(device))){ String RecordDataDoneAddress = thoroughfare + "." + device + ".RecordDataDone"; + miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(RecordDataDoneAddress).value(21).build()); // Object packCodeObject = miloService.readFromOpcUa(thoroughfare + "." + device + ".ModuleCode").getValue(); // DaTestDeviceInterface deviceInterfaceOne = null; // @@ -214,7 +224,6 @@ // writeToOpc(RecordDataDoneAddress, (short) 22); // } // writeToOpc(RecordDataDoneAddress, (short) 21); - miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(RecordDataDoneAddress).value(21).build()); } @@ -237,11 +246,15 @@ List<Object> collect = list1.stream().map(ReadWriteEntity::getValue).collect(Collectors.toList()); String joinedString = String.join(",", collect.toString()); WebSocketUsers.sendMessageToUserByText(map.get(device), TightenTheConversionOkNg(joinedString)); + if(device.contains("270") || device.contains("260")){ + logger.info("璇诲彇鍒板伐浣峽}鐨凷caner鏁版嵁锛歿}",device,TightenTheConversionOkNg(joinedString)); + } } } } } catch (Exception e) { - + logger.info("璁㈤槄鏂规硶鎶ラ敊:{}"+e.getMessage()); + logger.error("璁㈤槄鏂规硶鎶ラ敊",e); } } @@ -267,56 +280,61 @@ if(nullList.stream().noneMatch(s -> s.equals(device))){ if(moduleCodeList.stream().anyMatch(s -> s.equals(device))){ read = read + "ModuleCode"; - if(device.equals("OP365")){ - try { - saveStationInfo365(thoroughfare,device); - }catch (Exception e){ - e.printStackTrace(); - } - } + }else { read = read + "PACKCode"; } } - snCode = miloService.readFromOpcUa(read).getValue().toString(); - - if(null == snCode || "".equals(snCode)){ - result = "22"; - }else{ - - String workOrderNo = ""; - String productCode = ""; - //2銆佷繚瀛樿繃绔欓噰闆嗘暟鎹� - Object orderNumberObject = miloService.readFromOpcUa(thoroughfare + "." + device + "." + "WorkOrderNumber").getValue(); - if(orderNumberObject!=null){ - workOrderNo = orderNumberObject.toString(); - } - - Object productCodeObject = miloService.readFromOpcUa(thoroughfare + "." + device + "." + "ProductType").getValue(); - if(productCodeObject!=null){ - productCode = productCodeObject.toString(); - } - - saveStationInfo(snCode,thoroughfare,device,workOrderNo,productCode); - //3銆佷繚瀛樺弬鏁伴噰闆嗘暟鎹� - SaveParamData(snCode,thoroughfare,device,workOrderNo,productCode); - - //濡傛灉鏄湯灏惧伐绔欒鎶ュ伐 - if(device.equals("OP500")){ - RestfulService.getWorkReportResultFeedback(snCode,device,format.format(new Date())); - //1銆佹洿鏂板伐鍗曚俊鎭� - updateOrderInfo(snCode); - } - try{ - daParamCollectionService.pushGeelycvMesFeedback(snCode,device); + if(device.equals("OP365")){ + try { + result = saveStationInfo365(thoroughfare,device); + return result; +// return saveStationInfo365(thoroughfare,device); +// return result; }catch (Exception e){ + e.printStackTrace(); } - result = "21"; + }else { + snCode = miloService.readFromOpcUa(read).getValue().toString(); + + if(null == snCode || "".equals(snCode)){ + result = "22"; + }else{ + + String workOrderNo = ""; + String productCode = ""; + //2銆佷繚瀛樿繃绔欓噰闆嗘暟鎹� + Object orderNumberObject = miloService.readFromOpcUa(thoroughfare + "." + device + "." + "WorkOrderNumber").getValue(); + if(orderNumberObject!=null){ + workOrderNo = orderNumberObject.toString(); + } + + Object productCodeObject = miloService.readFromOpcUa(thoroughfare + "." + device + "." + "ProductType").getValue(); + if(productCodeObject!=null){ + productCode = productCodeObject.toString(); + } + + saveStationInfo(snCode,thoroughfare,device,workOrderNo,productCode); + //3銆佷繚瀛樺弬鏁伴噰闆嗘暟鎹� + List<DaParamCollection> daParamCollectionList = SaveParamData(snCode,thoroughfare,device,workOrderNo,productCode); + + //濡傛灉鏄湯灏惧伐绔欒鎶ュ伐 + if(device.equals("OP500")){ + RestfulService.getWorkReportResultFeedback(snCode,device,format.format(new Date())); + //1銆佹洿鏂板伐鍗曚俊鎭� + updateOrderInfo(snCode); + } + try{ + daParamCollectionService.automaticWorkstationPushGeelycvMesFeedback(snCode,device,daParamCollectionList); + }catch (Exception e){ + } + result = "21"; + + } } - }catch (Exception e) { - System.out.println(e.getMessage()); + logger.error("鍑虹珯淇濆瓨鏁版嵁寮傚父锛�"+e); } return result; } @@ -376,11 +394,12 @@ daPassingStationCollectionService.insertDaPassingStationCollection(daPassingStationCollection); } - public static void SaveParamData(String packCode,String thoroughfare,String device,String workOrderNo,String productType) throws Exception { + public static List<DaParamCollection> SaveParamData(String packCode,String thoroughfare,String device,String workOrderNo,String productType) throws Exception { List<DaCollectionParamConf> list; DaCollectionParamConf daCollectionParamConf = new DaCollectionParamConf(); daCollectionParamConf.setGatherAddress(thoroughfare+ "." + device); list = collectionParamConfService.selectDaCollectionParamConfList(daCollectionParamConf); + List<DaParamCollection> daParamCollectionlist = new ArrayList<>(); List<String> nodeIdList = list.stream().map(info -> { String nodeid = info.getGatherAddress(); @@ -394,11 +413,12 @@ readWriteEntityList.get(i).setValue(" "); } } - List<DaParamCollection> daParamCollectionlist = new ArrayList<>(); + for(int i=0;i<nodeIdList.size();i++){ if(!readWriteEntityList.get(i).getValue().toString().equals("0.0")){ String tt = readWriteEntityList.get(i).getValue().toString(); DaParamCollection ParamCollection = new DaParamCollection(); + ChildVO childVO = new ChildVO(); ParamCollection.setParamCode(list.get(i).getCollectParameterId()); ParamCollection.setLocationCode(device); if(tt.contains("Time")){ @@ -430,12 +450,16 @@ } } daParamCollectionService.saveBeachDaParamCollection(daParamCollectionlist); - } - addBaseData(workOrderNo,productType,device,packCode); + } + List<DaParamCollection> baseDataList = addBaseData(workOrderNo,productType,device,packCode); + for (int i = 0; i < baseDataList.size(); i++){ + daParamCollectionlist.add(baseDataList.get(i)); + } + return daParamCollectionlist; } - public static void addBaseData(String workOrderNo,String productCode,String locationCode,String packCode){ + public static List<DaParamCollection> addBaseData(String workOrderNo,String productCode,String locationCode,String packCode){ Map<String, String> map = new HashMap<>(); map.put("GC", "鍗楁禂宸ュ巶"); map.put("CXBH", "Pack绾�"); @@ -458,6 +482,7 @@ confList.add(saveData); }); daParamCollectionService.insertBatch(confList); + return confList; } public static void getFactoryOrder(String locationCode){ @@ -502,13 +527,22 @@ try { value = Float.parseFloat(part); // 灏濊瘯灏嗗瓧绗︿覆杞崲涓烘诞鐐规暟 String replacement; - if (value == 1f) { + if(i<2){ + replacement = part; + }else{ + if (value == 1f) { + replacement = "OK"; + } else{ + replacement = "NG"; + } + } + /* if (value == 1f) { replacement = "OK"; } else if (value == 2f) { replacement = "NG"; } else { replacement = part; // 濡傛灉涓嶆槸1鎴�2锛屽垯淇濇寔涓嶅彉 - } + }*/ sb.append(replacement); if (i < parts.length - 1) { sb.append(','); // 娣诲姞閫楀彿锛堥櫎浜嗘渶鍚庝竴涓厓绱狅級 @@ -541,7 +575,7 @@ /** * 淇濆瓨杩囩珯閲囬泦 */ - public void saveStationInfo365(String thoroughfare,String device) throws Exception { + public String saveStationInfo365(String thoroughfare,String device) throws Exception { String RecordDataDoneAddress = thoroughfare + "." + device + ".RecordDataDone"; String prefix = thoroughfare+"."+device+"."; List<DaPassingStationCollection> passingStationCollections = new ArrayList<>(); @@ -578,11 +612,13 @@ passingStationCollections.add(daPassingStationCollection); } daPassingStationCollectionService.saveBeachDaPassingStationCollection(passingStationCollections); - miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(RecordDataDoneAddress).value(21).build()); - return; +// miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(RecordDataDoneAddress).value(21).build()); + logger.info("宸ヤ綅{}鍥炲21",device); + + return "21"; }else { - miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(RecordDataDoneAddress).value(22).build()); - return; +// miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(RecordDataDoneAddress).value(22).build()); + return "22"; } } -- Gitblit v1.9.3