cl
2024-05-23 ba1a7a9ef126296e2798e313dc5b43f775a1123c
guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/OP050Callback.java
@@ -1,11 +1,14 @@
package cn.stylefeng.guns.plcserver.callback;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.stylefeng.guns.modular.bs.collectionParamConf.model.params.CollectionParamConfParam;
import cn.stylefeng.guns.modular.bs.collectionParamConf.model.result.CollectionParamConfResult;
import cn.stylefeng.guns.modular.bs.collectionParamConf.service.CollectionParamConfService;
import cn.stylefeng.guns.modular.bs.equipmentInfo.service.EquipmentInfoService;
import cn.stylefeng.guns.modular.bs.locationInfo.service.LocationInfoService;
import cn.stylefeng.guns.modular.cm.paramCollection.entity.ParamCollection;
import cn.stylefeng.guns.modular.cm.paramCollection.model.params.ParamCollectionParam;
import cn.stylefeng.guns.modular.cm.paramCollection.service.ParamCollectionService;
import cn.stylefeng.guns.modular.cm.passingStationCollection.model.params.PassingStationCollectionParam;
@@ -28,7 +31,6 @@
import cn.stylefeng.guns.plcserver.opc.GlobalVariable;
import cn.stylefeng.guns.plcserver.opc.OPCElement;
import cn.stylefeng.guns.plcserver.opc.unit.OPCUnit;
import cn.stylefeng.guns.plcserver.tool.DateTool;
import cn.stylefeng.guns.plcserver.tool.LogUtil;
import com.kangaroohy.milo.model.ReadWriteEntity;
@@ -43,7 +45,7 @@
import java.util.List;
@Component
public class OP050Callback implements SubscriptionCallback {
public class OP050Callback{
    public MiloService miloService;
@@ -94,7 +96,7 @@
    private static String PRODUCTION_LINE  = "OP";//产线号
    private static String LOCATION_CODE  = "OP050";//工位号
    private static List list = null;
    private static String PRODUCT_STATE = "合格";
    public OP050Callback(MiloService miloService,
                         ProductionOrdeInfoService productionOrdeInfoService,
                         PassingStationCollectionService passingStationCollectionService,
@@ -126,42 +128,7 @@
        this.productionOrderRecordsService = productionOrderRecordsService;
        this.productionOrderBatchInfoService = productionOrderBatchInfoService;
    }
    @Override
    public void onSubscribe(String identifier, Object value) {
        String ecpStr = "";//异常记录标记
        try {
            //心跳
            if(null != value && identifier.equals(OPCElement.OP050_F_HEART_BEAT)){
                if( "false".equals(value.toString()))
                {
                    ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP050_F_HEART_BEAT,true);
                    miloService.writeToOpcUa(entity);
                }
            }
            //PLC进站
            else if(null != value && identifier.equals(OPCElement.OP050_J_PLC_START)){
                if("true".equals(value.toString())){
                    handleOrder();
                }
            }
            //PLC出站
            else if(null != value && identifier.equals(OPCElement.OP050_J_PLC_FINISH)){
                if("true".equals(value.toString())){
                    handleMaterial();
                    handleFinsh();
                    handleInfo();
                }
            }else{
                System.out.println("值没有变");
            }
        } catch (Exception e) {
            ecpStr ="出现异常:" + logUtil.getTrace(e);
        }finally {
            if(!"".equals(ecpStr)){
                logger.info(ecpStr+"\r\n");
            }
        }
    }
    //PC读工单
    public void handleOrder() throws Exception {
@@ -194,10 +161,33 @@
    }
    public void handleFinsh() throws Exception{
        logger.info("handleFinsh PC处理开始!");
        String S_PRODUCT_STATE_CODE = miloService.
        Object copSfcCode = miloService.
                readFromOpcUa(OPCElement.OP050_S_SFC_CODE_COP)
                .getValue();
        Object bopSfcCode = miloService.
                readFromOpcUa(OPCElement.OP050_S_SFC_CODE_BOP)
                .getValue();
        Object object = miloService.
                readFromOpcUa(OPCElement.OP050_S_PRODUCT_STATE_CODE)
                .getValue().toString();
                .getValue();
        String S_PRODUCT_STATE_CODE = "";
        if(null != object){
            S_PRODUCT_STATE_CODE = object.toString();
        }
        if("2".equals(S_PRODUCT_STATE_CODE)){
            PRODUCT_STATE = "不合格";
        }
        ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP050_J_PC_FINISH,true);
        miloService.writeToOpcUa(entity);//写PC完成
        PassingStationCollectionParam param = new PassingStationCollectionParam();
        param.setWorkOrderNo(S_ORDER_CODE);
@@ -211,26 +201,22 @@
        passingStationCollectionService.add(param);
        String copSfcCode = miloService.
                readFromOpcUa(OPCElement.OP050_S_SFC_CODE_COP)
                .getValue().toString();
        String bopSfcCode = miloService.
                readFromOpcUa(OPCElement.OP050_S_SFC_CODE_BOP)
                .getValue().toString();
        if(null != copSfcCode && null != bopSfcCode){
        //根据分总成编码,将EOP物料数据绑定关系修改为总成编码
        materialTraceabilityService.updateSFC(S_SFC_CODE,copSfcCode);
        materialTraceabilityService.updateSFC(S_SFC_CODE,bopSfcCode);
            materialTraceabilityService.updateSFC(S_SFC_CODE,copSfcCode.toString());
            materialTraceabilityService.updateSFC(S_SFC_CODE,bopSfcCode.toString());
        //根据分总成编码,将EOP过站数据绑定关系修改为总成编码
        passingStationCollectionService.updateSFC(S_SFC_CODE,copSfcCode);
        passingStationCollectionService.updateSFC(S_SFC_CODE,bopSfcCode);
            //根据分总成编码,将EOP过站数据绑定关系修改为总成编码
            passingStationCollectionService.updateSFC(S_SFC_CODE,copSfcCode.toString());
            passingStationCollectionService.updateSFC(S_SFC_CODE,bopSfcCode.toString());
        //根据分总成编码,将EOP采集数据绑定关系修改为总成编码
        paramCollectionService.updateSFC(S_SFC_CODE,copSfcCode);
        paramCollectionService.updateSFC(S_SFC_CODE,bopSfcCode);
            //根据分总成编码,将EOP采集数据绑定关系修改为总成编码
            paramCollectionService.updateSFC(S_SFC_CODE,copSfcCode.toString());
            paramCollectionService.updateSFC(S_SFC_CODE,bopSfcCode.toString());
        }
        logger.info("S_SFC_CODE:"+S_SFC_CODE);
        logger.info("copSfcCode:"+copSfcCode);
        logger.info("bopSfcCode:"+bopSfcCode);
@@ -244,13 +230,14 @@
        String isProductState = "true";
        for(int i=0;i<passingStationCollectionResultList.size();i++){
            PassingStationCollectionResult passingStationCollectionResult = passingStationCollectionResultList.get(i);
            if("false".equals(passingStationCollectionResult.getOutRsSign())){
            if("2".equals(passingStationCollectionResult.getOutRsSign())){
                isProductState = "false";
                break;
            }
        }
        //修改报工记录
        if("false".equals(S_PRODUCT_STATE_CODE) || "false".equals(isProductState)){
        if("2".equals(S_PRODUCT_STATE_CODE) || "false".equals(isProductState)){
            isProductState = "true";
            ProductionOrderRecordsParam productionOrderRecordsParam = new ProductionOrderRecordsParam();
            productionOrderRecordsParam.setWorkOrderNo(S_ORDER_CODE);
            productionOrderRecordsParam.setProductNo(S_SFC_CODE);
@@ -258,17 +245,19 @@
            if(list.size()>0){
                ProductionOrderRecordsResult productionOrderRecordsResult = list.get(0);
                productionOrderRecordsParam.setId(productionOrderRecordsResult.getId());
                productionOrderRecordsParam.setWhetherPass("false");
                productionOrderRecordsParam.setWhetherPass("不合格");
                productionOrderRecordsParam.setEndTime(DateTool.getLocalTimeForDate());
                productionOrderRecordsService.update(productionOrderRecordsParam);
            }
        }
        ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP050_J_PC_FINISH,true);
        miloService.writeToOpcUa(entity);//写PC完成
        logger.info("handleFinsh PC处理完成!");
    }
    public void handleMaterial() {
        if(S_ORDER_CODE.isEmpty()){
            return;
        }
        //查询批次上料信息
        ProductionOrderBatchInfoParam productionOrderBatchInfoParam = new ProductionOrderBatchInfoParam();
        productionOrderBatchInfoParam.setWorkOrderNo(S_ORDER_CODE);
@@ -309,28 +298,54 @@
            list = collectionParamConfService.findListBySpec(collectionParamConfParam);
        }
        if(null != list && !list.isEmpty()) {
            List<String> nodeIdList = new ArrayList<>();
            for (int i = 0; i < list.size(); i++) {
                CollectionParamConfResult result = (CollectionParamConfResult) list.get(i);
                Object value = miloService.
                        readFromOpcUa(result.getGatherAddress())
                        .getValue();//读参数值
                if(null != value) {
                    ParamCollectionParam paramCollectionParam = new ParamCollectionParam();
                    paramCollectionParam.setParamCode(result.getParamCode());
                    paramCollectionParam.setParamName(result.getParamName());
                    paramCollectionParam.setWorkOrderNo(S_ORDER_CODE);
                    paramCollectionParam.setSfcCode(S_SFC_CODE);
                    paramCollectionParam.setProductCode(S_PRODUCT_CODE);
                    paramCollectionParam.setProductionLine(result.getProductionLine());
                    paramCollectionParam.setLocationCode(result.getLocationCode());
                    paramCollectionParam.setParamValue(value.toString());
                    paramCollectionParam.setParamLower(result.getParamLower());
                    paramCollectionParam.setParamUpper(result.getParamUpper());
                    paramCollectionParam.setParamStandard(result.getParamCentral());
                    paramCollectionParam.setCollectionTime(DateTool.getLocalTimeForDate());
                    paramCollectionParam.setUnit(result.getUnit());
                    paramCollectionService.add(paramCollectionParam);
                nodeIdList.add(result.getGatherAddress());
            }
            List<ReadWriteEntity> readWriteEntityList = new ArrayList<>();
            if(CollUtil.isNotEmpty(nodeIdList)){
                readWriteEntityList = miloService.readFromOpcUa(nodeIdList);
            }
            List<ParamCollection> paramCollectionlist = new ArrayList<>();
            if (CollUtil.isNotEmpty(nodeIdList)){
                for(int i=0;i<nodeIdList.size();i++){
                    if(ObjectUtil.isNotEmpty(readWriteEntityList.get(i).getValue())){
                        CollectionParamConfResult result = (CollectionParamConfResult) list.get(i);
                        String value = "0";
                        if (readWriteEntityList.get(i).getValue() != null){
                            value = readWriteEntityList.get(i).getValue().toString();
                        }
                        if(result.getParamName() != null && result.getParamName().contains("状态")){
                            if("2".equals(value)){
                                value = "不合格";
                            }else {
                                value = "合格";
                            }
                        }
                        ParamCollection paramCollectionParam = new ParamCollection();
                        paramCollectionParam.setParamCode(result.getParamCode());
                        paramCollectionParam.setParamName(result.getParamName());
                        paramCollectionParam.setWorkOrderNo(S_ORDER_CODE);
                        paramCollectionParam.setSfcCode(S_SFC_CODE);
                        paramCollectionParam.setProductCode(S_PRODUCT_CODE);
                        paramCollectionParam.setProductionLine(result.getProductionLine());
                        paramCollectionParam.setLocationCode(result.getLocationCode());
                        paramCollectionParam.setParamValue(value.toString());
                        paramCollectionParam.setParamLower(result.getParamLower());
                        paramCollectionParam.setParamUpper(result.getParamUpper());
                        paramCollectionParam.setParamStandard(result.getParamCentral());
                        paramCollectionParam.setCollectionTime(DateTool.getLocalTimeForDate());
                        paramCollectionParam.setUnit(result.getUnit());
                        paramCollectionParam.setSpareField2(PRODUCT_STATE);
                        paramCollectionlist.add(paramCollectionParam);
                    }
                }
                paramCollectionService.saveBatch(paramCollectionlist);
            }
        }