wujian
8 天以前 cd44522023ba6fece1d93670bfef5f73b5d09f57
jcdm-main/src/main/java/com/jcdm/main/plcserver/sub/OPCUaSubscription.java
@@ -4,7 +4,9 @@
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.jcdm.framework.websocket.WebSocketUsers;
import com.jcdm.main.constant.Constants;
@@ -17,24 +19,25 @@
import com.jcdm.main.da.passingStationCollection.query.ProductOrderQuery;
import com.jcdm.main.da.passingStationCollection.query.ProductOrderVO;
import com.jcdm.main.da.passingStationCollection.service.IDaPassingStationCollectionService;
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.jcdm.main.work.domain.KeyCodeRelation;
import com.jcdm.main.work.domain.QingYanTestInfo;
import com.jcdm.main.work.domain.SendFactoryMes;
import com.jcdm.main.work.domain.WorkOrder;
import com.jcdm.main.work.service.KeyCodeCheckService;
import com.jcdm.main.work.service.KeyCodeRelationService;
import com.jcdm.main.work.service.WorkOrderService;
import com.jcdm.main.work.service.*;
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 javax.websocket.Session;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;
@@ -44,33 +47,10 @@
    public SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    //新自动工站
    public List<String> automaticList = Arrays.asList("OP280","OP310A","OP310B", "OP300A","OP300B", "OP320A","OP320B", "OP340A","OP340B", "OP350A","OP350B", "OP360","OP365","OP370", "OP390", "OP470");
    //采集模组工位 ModuleCode
    public List<String> moduleCodeList = Arrays.asList("OP300A","OP300B","OP320A","OP320B","OP340A","OP340B","OP365", "OP350A", "OP350B", "OP330");
    //区分模组型号工位
    public List<String> distinguishingModules = Arrays.asList("OP300","OP310", "OP340", "OP350", "OP330");
    //区分小车码
    public List<String> agvId = Arrays.asList("OP360", "OP390", "OP470","OP280");
    //区分pack型号的工位
    public List<String> packIdList = Arrays.asList("OP280","OP360","OP390","OP470");
    //测试设备手动工位
    public List<String> testList = Arrays.asList("OP430-1","OP430-2","OP430-3","OP430-4","OP480-1","OP480-2","OP480-3","OP440");
    //空的
    public List<String> nullList = Arrays.asList("OP250","OP260");
    public static MiloService miloService;
    Map<String, Session> map = WebSocketUsers.getUsers();
    public IDaPassingStationCollectionService daPassingStationCollectionService;
@@ -82,6 +62,12 @@
    public static WorkOrderService workOrderService;
    public static KeyCodeCheckService keyCodeCheckService;
    public static KeyCodeRelationService keyCodeRelationService;
    public static QingYanTestInfoService qingYanTestInfoService;
    public static SendFactoryMesService sendFactoryMesService;
    public static List<SendFactoryMes> sendFactoryMesList;
    @Value("${orderLineUrl}")
    private static String orderLineUrl;
    public OPCUaSubscription(MiloService miloService,
                             IDaPassingStationCollectionService daPassingStationCollectionService,
@@ -90,7 +76,9 @@
                             IOmProductionOrdeInfoService omProductionOrdeInfoService,
                             WorkOrderService workOrderService,
                             KeyCodeCheckService keyCodeCheckService,
                             KeyCodeRelationService keyCodeRelationService) {
                             KeyCodeRelationService keyCodeRelationService,
                             QingYanTestInfoService qingYanTestInfoService,
                             List<SendFactoryMes> sendFactoryMesList) {
        OPCUaSubscription.miloService = miloService;
        this.daPassingStationCollectionService = daPassingStationCollectionService;
        OPCUaSubscription.collectionParamConfService = collectionParamConfService;
@@ -99,6 +87,8 @@
        OPCUaSubscription.workOrderService = workOrderService;
        OPCUaSubscription.keyCodeCheckService = keyCodeCheckService;
        OPCUaSubscription.keyCodeRelationService = keyCodeRelationService;
        OPCUaSubscription.qingYanTestInfoService = qingYanTestInfoService;
        OPCUaSubscription.sendFactoryMesList = sendFactoryMesList;
    }
@@ -160,6 +150,15 @@
                        PART1.add(Constants.OP065);
                        if (Constants.OP010.equals(device)){
                            //010工位无过站记录,只给放行信号
                            List<SendFactoryMes> collect = sendFactoryMesList.stream().filter(x -> device.equals(x.getLocationCode())).collect(Collectors.toList());
                            if (CollUtil.isNotEmpty(collect)){
                                for (SendFactoryMes sendFactoryMes : collect) {
                                    ChildVO childVO = new ChildVO();
                                    childVO.setItemCode(sendFactoryMes.getItemCode());
                                    childVO.setItemText(sendFactoryMes.getItemText());
                                    childVO.setItemType(sendFactoryMes.getItemType());
                                }
                            }
                            miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".RecordDataDone").value(21).build());
                            log.info("写入到工位{}的RecordDataDone数据:{}",device,21);
                        }else if (PART1.contains(device)){
@@ -181,15 +180,26 @@
                            if (CollUtil.isNotEmpty(collect)){
                                query.setProductNum(collect.get(0).getProductNum());
                            }
                            ProductOrderVO vo = daPassingStationCollectionService.queryMessFromLine(query);
//                            ProductOrderVO vo = daPassingStationCollectionService.queryMessFromLine(query);
                            ProductOrderVO vo = new ProductOrderVO();
                            ProductOrderChild child = new ProductOrderChild();
                            child.setModel("modelCode123123123");
                            child.setStationCode("M1OP100-1");
                            child.setProductNum("productNum123113");
                            child.setMaterialCode("materialCode2323");
                            child.setProductionOrderNum("proOrderNum123");
                            vo.setData(child);
                            vo.setCode(Constants.SUCCESS);
                            if (Constants.SUCCESS.equals(vo.getCode())){
                                WorkOrder workOrder = new WorkOrder();
                                ProductOrderChild data = vo.getData();
                                workOrder.setId(123L);
                                workOrder.setProductNum(data.getProductNum());
                                workOrder.setProductionOrderNum(data.getProductionOrderNum());
                                workOrder.setStationCode(data.getStationCode());
                                workOrder.setMaterialCode(data.getMaterialCode());
                                workOrder.setModel(data.getModel());
                                workOrder.setCreateTime(new Date());
                                workOrderService.save(workOrder);
                                //写入模组码、工单号、产品型号到plc
                                log.info("写入模组码、工单号、产品型号到plc");
@@ -211,7 +221,7 @@
                                if (CollUtil.isNotEmpty(paramCollectionList1)){
                                    List<KeyCodeRelation> relationList = new ArrayList<>();
                                    for (ReadWriteEntity readWriteEntity : paramCollectionList1) {
                                        if (ObjectUtil.isNotNull(readWriteEntity.getValue())){
                                        if (ObjectUtil.isNotNull(readWriteEntity.getValue()) && StrUtil.isNotBlank(readWriteEntity.getValue().toString())){
                                            KeyCodeRelation keyCodeRelation = new KeyCodeRelation();
                                            keyCodeRelation.setModuleCode(data.getModel());
                                            keyCodeRelation.setKeyCode(readWriteEntity.getValue().toString());
@@ -347,22 +357,29 @@
                .eq(DaCollectionParamConf::getRemarks, Constants.ONE));
        if (CollUtil.isNotEmpty(list)){
            List<DaParamCollection> saveParamList = new ArrayList<>();
            List<String> collect1 = list.stream().filter(x -> Constants.INT_ONE.equals(x.getKeyNum()))
                    .map(DaCollectionParamConf::getGatherAddress).collect(Collectors.toList());
            List<DaCollectionParamConf> confColl1 = list.stream().filter(x -> Constants.INT_ONE.equals(x.getKeyNum())).collect(Collectors.toList());
            List<DaCollectionParamConf> confColl2 = list.stream().filter(x -> Constants.INT_TWO.equals(x.getKeyNum())).collect(Collectors.toList());
            List<DaCollectionParamConf> confColl3 = list.stream().filter(x -> Constants.INT_THREE.equals(x.getKeyNum())).collect(Collectors.toList());
            List<DaCollectionParamConf> confColl4 = list.stream().filter(x -> Constants.INT_FOUR.equals(x.getKeyNum())).collect(Collectors.toList());
            List<DaCollectionParamConf> confColl0 = list.stream().filter(x -> Constants.INT_ZERO.equals(x.getKeyNum())).collect(Collectors.toList());
            List<String> collect1 = confColl1.stream().map(DaCollectionParamConf::getGatherAddress).collect(Collectors.toList());
            List<ReadWriteEntity> paramCollectionList1 = miloService.readFromOpcUa(collect1);
            List<String> collect2 = list.stream().filter(x -> Constants.INT_TWO.equals(x.getKeyNum()))
            List<String> collect2 = confColl2.stream()
                    .map(DaCollectionParamConf::getGatherAddress).collect(Collectors.toList());
            List<ReadWriteEntity> paramCollectionList2 = miloService.readFromOpcUa(collect2);
            List<String> collect3 = list.stream().filter(x -> Constants.INT_THREE.equals(x.getKeyNum()))
            List<String> collect3 = confColl3.stream()
                    .map(DaCollectionParamConf::getGatherAddress).collect(Collectors.toList());
            List<ReadWriteEntity> paramCollectionList3 = miloService.readFromOpcUa(collect3);
            List<String> collect4 = list.stream().filter(x -> Constants.INT_FOUR.equals(x.getKeyNum()))
            List<String> collect4 = confColl4.stream()
                    .map(DaCollectionParamConf::getGatherAddress).collect(Collectors.toList());
            List<ReadWriteEntity> paramCollectionList4 = miloService.readFromOpcUa(collect4);
            List<String> collect0 = list.stream().filter(x -> Constants.INT_ZERO.equals(x.getKeyNum()))
            List<String> collect0 = confColl0.stream()
                    .map(DaCollectionParamConf::getGatherAddress).collect(Collectors.toList());
            List<ReadWriteEntity> paramCollectionList0 = miloService.readFromOpcUa(collect0);
            if (CollUtil.isNotEmpty(paramCollectionList1)){
                List<ChildVO> checkList = new ArrayList<>();
                for (int i = 0; i < paramCollectionList1.size(); i++) {
                    DaParamCollection daParamCollection = new DaParamCollection();
                    if (CollUtil.isNotEmpty(keyCodeList) && keyCodeList.size() == 4){
@@ -378,6 +395,34 @@
                    daParamCollection.setLocationCode(device);
                    daParamCollection.setCollectionTime(new Date());
                    saveParamList.add(daParamCollection);
                    ChildVO childVO = new ChildVO();
                    childVO.setItemCode(confColl1.get(i).getCollectParameterName());
                    childVO.setItemType(confColl1.get(i).getItemType());
                    childVO.setItemValue(paramValue);
                    childVO.setItemText(confColl1.get(i).getParameterSetName());
                    childVO.setCheckResult("1");
                    childVO.setCheckTime(new Date().toString());
                    checkList.add(childVO);
                }
                //上传到工厂mes
                ParentVO vo = new ParentVO();
                vo.setStationCode(device);
                vo.setCheckList(checkList);
                vo.setSiteCode("3983");
                vo.setRecordId(UUID.randomUUID().toString());
                vo.setTotalResult("1");
                if (CollUtil.isNotEmpty(keyCodeList) && keyCodeList.size() == 4){
                    vo.setProductNum(keyCodeList.get(0));
                }
                try{
                    CompletableFuture<Void> cp1 = CompletableFuture.runAsync(() -> {
                        log.info("开始执行异步方法");
                        HttpResponse execute = HttpRequest.post(orderLineUrl).body(JSONUtil.toJsonStr(vo)).execute();
                        System.out.println(execute.body());
                        log.info("异步方法执行结束");
                    });
                }catch (Exception e){
                    System.out.println(e.getMessage());
                }
            }
            if (CollUtil.isNotEmpty(paramCollectionList2)){
@@ -469,11 +514,11 @@
        Object value1 = miloService.readFromOpcUa(thoroughfare + "." + device + ".CellCode_1").getValue();
        if (ObjectUtil.isNotNull(value1)){
            String string = value1.toString();
            List<DaParamCollection> list = daParamCollectionService.list(new LambdaQueryWrapper<DaParamCollection>()
                    .eq(DaParamCollection::getKeyCode, string));
            List<QingYanTestInfo> list = qingYanTestInfoService.list(new LambdaQueryWrapper<QingYanTestInfo>()
                    .eq(QingYanTestInfo::getKeyCode, string));
            if (CollUtil.isNotEmpty(list)){
                DaParamCollection daParamCollection = list.get(0);
                if (Constants.ONE.equals(daParamCollection.getState())){
                QingYanTestInfo qingYanTestInfo = list.get(0);
                if (Constants.ONE.equals(qingYanTestInfo.getStatus())){
                    miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".CellStatus_1").value(1).build());
                }else {
                    flag = false;
@@ -484,11 +529,11 @@
        Object value2 = miloService.readFromOpcUa(thoroughfare + "." + device + ".CellCode_2").getValue();
        if (ObjectUtil.isNotNull(value2)){
            String string = value2.toString();
            List<DaParamCollection> list = daParamCollectionService.list(new LambdaQueryWrapper<DaParamCollection>()
                    .eq(DaParamCollection::getKeyCode, string));
            List<QingYanTestInfo> list = qingYanTestInfoService.list(new LambdaQueryWrapper<QingYanTestInfo>()
                    .eq(QingYanTestInfo::getKeyCode, string));
            if (CollUtil.isNotEmpty(list)){
                DaParamCollection paramCollection = list.get(0);
                if (Constants.ONE.equals(paramCollection.getState())){
                QingYanTestInfo qingYanTestInfo = list.get(0);
                if (Constants.ONE.equals(qingYanTestInfo.getStatus())){
                    miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".CellStatus_2").value(1).build());
                }else {
                    flag = false;
@@ -499,11 +544,11 @@
        Object value3 = miloService.readFromOpcUa(thoroughfare + "." + device + ".CellCode_3").getValue();
        if (ObjectUtil.isNotNull(value3)){
            String string = value3.toString();
            List<DaParamCollection> list = daParamCollectionService.list(new LambdaQueryWrapper<DaParamCollection>()
                    .eq(DaParamCollection::getKeyCode, string));
            List<QingYanTestInfo> list = qingYanTestInfoService.list(new LambdaQueryWrapper<QingYanTestInfo>()
                    .eq(QingYanTestInfo::getKeyCode, string));
            if (CollUtil.isNotEmpty(list)){
                DaParamCollection paramCollection = list.get(0);
                if (Constants.ONE.equals(paramCollection.getState())){
                QingYanTestInfo qingYanTestInfo = list.get(0);
                if (Constants.ONE.equals(qingYanTestInfo.getStatus())){
                    miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".CellStatus_3").value(1).build());
                }else {
                    flag = false;
@@ -514,11 +559,11 @@
        Object value4 = miloService.readFromOpcUa(thoroughfare + "." + device + ".CellCode_4").getValue();
        if (ObjectUtil.isNotNull(value4)){
            String string = value4.toString();
            List<DaParamCollection> list = daParamCollectionService.list(new LambdaQueryWrapper<DaParamCollection>()
                    .eq(DaParamCollection::getKeyCode, string));
            List<QingYanTestInfo> list = qingYanTestInfoService.list(new LambdaQueryWrapper<QingYanTestInfo>()
                    .eq(QingYanTestInfo::getKeyCode, string));
            if (CollUtil.isNotEmpty(list)){
                DaParamCollection paramCollection = list.get(0);
                if (Constants.ONE.equals(paramCollection.getState())){
                QingYanTestInfo qingYanTestInfo = list.get(0);
                if (Constants.ONE.equals(qingYanTestInfo.getStatus())){
                    miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".CellStatus_4").value(1).build());
                }else {
                    flag = false;