package com.jcdm.main.plcserver.sub;
|
|
|
import cn.hutool.core.collection.CollUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.http.HttpRequest;
|
import cn.hutool.http.HttpResponse;
|
import cn.hutool.json.JSONObject;
|
import cn.hutool.json.JSONUtil;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.jcdm.common.core.domain.AjaxResult;
|
import com.jcdm.framework.websocket.WebSocketUsers;
|
import com.jcdm.main.constant.Constants;
|
import com.jcdm.main.da.cellData.domain.DaCellData;
|
import com.jcdm.main.da.cellData.service.IDaCellDataService;
|
import com.jcdm.main.da.collectionParamConf.domain.DaCollectionParamConf;
|
import com.jcdm.main.da.collectionParamConf.service.IDaCollectionParamConfService;
|
import com.jcdm.main.da.paramCollection.domain.DaParamCollection;
|
import com.jcdm.main.da.paramCollection.service.IDaParamCollectionService;
|
import com.jcdm.main.da.passingStationCollection.domain.DaPassingStationCollection;
|
import com.jcdm.main.da.passingStationCollection.service.IDaPassingStationCollectionService;
|
import com.jcdm.main.da.testDeviceInterfaceTemp.domain.DaTestDeviceInterfaceTemp;
|
import com.jcdm.main.da.testDeviceInterfaceTemp.service.IDaTestDeviceInterfaceTempService;
|
import com.jcdm.main.om.productionOrde.domain.OmProductionOrdeInfo;
|
import com.jcdm.main.om.productionOrde.service.IOmProductionOrdeInfoService;
|
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.springframework.beans.factory.annotation.Value;
|
import org.springframework.stereotype.Component;
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
import javax.websocket.Session;
|
import java.text.SimpleDateFormat;
|
import java.util.*;
|
import java.util.concurrent.CompletableFuture;
|
import java.util.stream.Collectors;
|
|
|
@Slf4j
|
@Component
|
public class OPCUaSubscription implements SubscriptionCallback {
|
|
public static SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
Map<String, Session> map = WebSocketUsers.getUsers();
|
public static MiloService miloService;
|
|
|
public static IDaPassingStationCollectionService daPassingStationCollectionService;
|
|
public static IDaCollectionParamConfService collectionParamConfService;
|
|
public static IDaParamCollectionService daParamCollectionService;
|
|
public static IOmProductionOrdeInfoService omProductionOrdeInfoService;
|
|
public static IDaTestDeviceInterfaceTempService daTestDeviceInterfaceTempService;
|
|
public static IDaCellDataService daCellDataService;
|
|
public OPCUaSubscription(MiloService miloService,
|
IDaPassingStationCollectionService daPassingStationCollectionService,
|
IDaCollectionParamConfService collectionParamConfService,
|
IDaParamCollectionService daParamCollectionService,
|
IOmProductionOrdeInfoService omProductionOrdeInfoService,
|
IDaTestDeviceInterfaceTempService daTestDeviceInterfaceTempService,
|
IDaCellDataService daCellDataService) {
|
OPCUaSubscription.miloService = miloService;
|
OPCUaSubscription.daPassingStationCollectionService = daPassingStationCollectionService;
|
OPCUaSubscription.collectionParamConfService = collectionParamConfService;
|
OPCUaSubscription.daParamCollectionService = daParamCollectionService;
|
OPCUaSubscription.omProductionOrdeInfoService = omProductionOrdeInfoService;
|
OPCUaSubscription.daTestDeviceInterfaceTempService = daTestDeviceInterfaceTempService;
|
OPCUaSubscription.daCellDataService = daCellDataService;
|
}
|
|
|
@Override
|
public void onSubscribe(String identifier, Object value) {
|
log.info("地址:"+identifier+"值:"+value);
|
try {
|
if(null != value && !Constants.ZERO.equals(value.toString())) {
|
String[] nodes = identifier.split("[.]");
|
String thoroughfare = nodes[0];//通道
|
String device = nodes[1];//设备
|
String tab = nodes[2];//标记
|
String valueString = value.toString();//地址值
|
|
CompletableFuture<Void> cp1 = CompletableFuture.runAsync(() -> {
|
subHandle(thoroughfare,device,tab,valueString);
|
});
|
|
}
|
} catch (Exception e) {
|
log.error(e.getMessage());
|
}
|
}
|
|
public void subHandle(String thoroughfare,String device,String tab,String valueString){
|
try{
|
//出入站
|
if (Constants.RECORD_DATA.equals(tab)) {
|
if (Constants.ONE.equals(valueString)) {//入站
|
Integer recordDataDone = 11;
|
miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".RecordDataDone").value(recordDataDone).build());
|
} else if(Constants.TWO.equals(valueString)){//出站
|
Integer recordDataDone = 21;
|
miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".RecordDataDone").value(recordDataDone).build());
|
}
|
}
|
}catch (Exception e) {
|
log.error(e.getMessage());
|
}
|
}
|
}
|