cl
2024-07-29 b321b8a09092c35c2008f865ce35d6025bc09133
提交 | 用户 | 时间
b78728 1 package com.jcdm.main.plcserver.sub;
A 2
3
4 import cn.hutool.core.collection.CollUtil;
5 import cn.hutool.core.util.ObjectUtil;
6 import cn.hutool.core.util.StrUtil;
7 import cn.hutool.http.HttpRequest;
8 import cn.hutool.http.HttpResponse;
9 import cn.hutool.json.JSONObject;
10 import cn.hutool.json.JSONUtil;
11 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
12 import com.jcdm.common.core.domain.AjaxResult;
13 import com.jcdm.framework.websocket.WebSocketUsers;
14 import com.jcdm.main.constant.Constants;
15 import com.jcdm.main.da.cellData.domain.DaCellData;
16 import com.jcdm.main.da.cellData.service.IDaCellDataService;
17 import com.jcdm.main.da.collectionParamConf.domain.DaCollectionParamConf;
18 import com.jcdm.main.da.collectionParamConf.service.IDaCollectionParamConfService;
19 import com.jcdm.main.da.paramCollection.domain.DaParamCollection;
20 import com.jcdm.main.da.paramCollection.service.IDaParamCollectionService;
21 import com.jcdm.main.da.passingStationCollection.domain.DaPassingStationCollection;
22 import com.jcdm.main.da.passingStationCollection.service.IDaPassingStationCollectionService;
23 import com.jcdm.main.da.testDeviceInterfaceTemp.domain.DaTestDeviceInterfaceTemp;
24 import com.jcdm.main.da.testDeviceInterfaceTemp.service.IDaTestDeviceInterfaceTempService;
25 import com.jcdm.main.om.productionOrde.domain.OmProductionOrdeInfo;
26 import com.jcdm.main.om.productionOrde.service.IOmProductionOrdeInfoService;
27 import com.jcdm.main.plcserver.util.TimeUtil;
28 import com.jcdm.main.restful.factoryMes.service.RestfulService;
29 import com.jcdm.main.restful.qingYan.doman.ChildVO;
30 import com.jcdm.main.restful.qingYan.doman.ParentVO;
31 import com.kangaroohy.milo.model.ReadWriteEntity;
32 import com.kangaroohy.milo.runner.subscription.SubscriptionCallback;
33 import com.kangaroohy.milo.service.MiloService;
34 import lombok.extern.slf4j.Slf4j;
35 import org.springframework.beans.factory.annotation.Value;
36 import org.springframework.stereotype.Component;
37 import org.springframework.web.bind.annotation.GetMapping;
38
39 import javax.websocket.Session;
40 import java.text.SimpleDateFormat;
41 import java.util.*;
42 import java.util.concurrent.CompletableFuture;
43 import java.util.stream.Collectors;
44
45
46 @Slf4j
47 @Component
48 public class OPCUaSubscription implements SubscriptionCallback {
49
50     public static SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
51
52
53     Map<String, Session> map = WebSocketUsers.getUsers();
54     public static MiloService miloService;
55
56
57     public static IDaPassingStationCollectionService daPassingStationCollectionService;
58
59     public static IDaCollectionParamConfService collectionParamConfService;
60
61     public static IDaParamCollectionService daParamCollectionService;
62
63     public static IOmProductionOrdeInfoService omProductionOrdeInfoService;
64
65     public static IDaTestDeviceInterfaceTempService daTestDeviceInterfaceTempService;
66
67     public static IDaCellDataService daCellDataService;
68
69     public OPCUaSubscription(MiloService miloService,
70                              IDaPassingStationCollectionService daPassingStationCollectionService,
71                              IDaCollectionParamConfService collectionParamConfService,
72                              IDaParamCollectionService daParamCollectionService,
73                              IOmProductionOrdeInfoService omProductionOrdeInfoService,
74                              IDaTestDeviceInterfaceTempService daTestDeviceInterfaceTempService,
75                              IDaCellDataService daCellDataService) {
76         OPCUaSubscription.miloService = miloService;
77         OPCUaSubscription.daPassingStationCollectionService = daPassingStationCollectionService;
78         OPCUaSubscription.collectionParamConfService = collectionParamConfService;
79         OPCUaSubscription.daParamCollectionService = daParamCollectionService;
80         OPCUaSubscription.omProductionOrdeInfoService = omProductionOrdeInfoService;
81         OPCUaSubscription.daTestDeviceInterfaceTempService = daTestDeviceInterfaceTempService;
82         OPCUaSubscription.daCellDataService = daCellDataService;
83     }
84
85
86     @Override
87     public void onSubscribe(String identifier, Object value) {
88         log.info("地址:"+identifier+"值:"+value);
89         try {
90             if(null != value && !Constants.ZERO.equals(value.toString())) {
91                 String[] nodes = identifier.split("[.]");
92                 String thoroughfare = nodes[0];//通道
93                 String device = nodes[1];//设备
94                 String tab = nodes[2];//标记
95                 String valueString = value.toString();//地址值
96
97                 CompletableFuture<Void> cp1 = CompletableFuture.runAsync(() -> {
98                     subHandle(thoroughfare,device,tab,valueString);
99                 });
100
101             }
102         } catch (Exception e) {
103             log.error(e.getMessage());
104         }
105     }
106
107     public void subHandle(String thoroughfare,String device,String tab,String valueString){
108         try{
b321b8 109             //出入站
C 110             if (Constants.RECORD_DATA.equals(tab)) {
111                 if (Constants.ONE.equals(valueString)) {//入站
112                     Integer recordDataDone = 11;
113                     miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".RecordDataDone").value(recordDataDone).build());
114                 } else if(Constants.TWO.equals(valueString)){//出站
115                     Integer recordDataDone = 21;
116                     miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".RecordDataDone").value(recordDataDone).build());
b78728 117                 }
A 118             }
119         }catch (Exception e) {
120             log.error(e.getMessage());
121         }
122     }
123 }