cl
2024-01-20 d434812c124e2dab22487f8d40d8ad6c3b8ad19c
修改数据采集
已修改3个文件
已添加42个文件
14059 ■■■■■ 文件已修改
guns-vip-main/pom.xml 17 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/BOP010Callback.java 347 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/BOP020Callback.java 282 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/BOP030BCallback.java 282 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/BOP030Callback.java 282 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/BOP040BCallback.java 282 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/BOP040Callback.java 282 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/COP010Callback.java 351 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/COP020Callback.java 284 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/COP030Callback.java 284 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/DOP010Callback.java 343 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/DOP020Callback.java 282 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/EOP010Callback.java 290 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/EOP020Callback.java 282 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/EOP030Callback.java 282 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/EOP040Callback.java 282 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/EOP050Callback.java 282 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/EOP060Callback.java 282 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/EOP070Callback.java 282 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/EOP080Callback.java 282 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/EOP090BCallback.java 282 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/EOP090Callback.java 282 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/InitCallback.java 1162 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/OP010Callback.java 420 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/OP020Callback.java 298 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/OP030Callback.java 297 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/OP040Callback.java 297 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/OP050Callback.java 338 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/OP070Callback.java 298 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/OP080Callback.java 349 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/OP090Callback.java 332 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/OP100Callback.java 298 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/OP110Callback.java 298 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/OP120BCallback.java 298 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/OP120Callback.java 298 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/OP130BCallback.java 297 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/OP130Callback.java 298 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/OP140Callback.java 298 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/OP150Callback.java 298 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/OP160Callback.java 298 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/OP170Callback.java 315 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/StateCallback.java 293 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/init/CustomRunner.java 817 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/opc/GlobalVariable.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
guns-vip-main/src/main/resources/application.yml 12 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
guns-vip-main/pom.xml
@@ -135,6 +135,23 @@
            <artifactId>spring-boot-starter-websocket</artifactId>
        </dependency>
        <dependency>
            <groupId>com.kangaroohy</groupId>
            <artifactId>milo-spring-boot-starter</artifactId>
            <version>3.0.5</version>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-pool2</artifactId>
            <version>2.12.0</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/com.google.guava/guava -->
        <dependency>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
            <version>33.0.0-jre</version>
        </dependency>
    </dependencies>
    <build>
guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/BOP010Callback.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,347 @@
package cn.stylefeng.guns.plcserver.callback;
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.model.params.LocationInfoParam;
import cn.stylefeng.guns.modular.bs.locationInfo.model.result.LocationInfoResult;
import cn.stylefeng.guns.modular.bs.locationInfo.service.LocationInfoService;
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;
import cn.stylefeng.guns.modular.cm.passingStationCollection.service.PassingStationCollectionService;
import cn.stylefeng.guns.modular.dq.materialTraceability.model.params.MaterialTraceabilityParam;
import cn.stylefeng.guns.modular.dq.materialTraceability.service.MaterialTraceabilityService;
import cn.stylefeng.guns.modular.em.equipmentAlarm.service.EquipmentAlarmService;
import cn.stylefeng.guns.modular.em.equipmentStatus.service.EquipmentStatusService;
import cn.stylefeng.guns.modular.gm.greaseManage.service.GreaseManageService;
import cn.stylefeng.guns.modular.om.productionOrdeInfo.model.params.ProductionOrdeInfoParam;
import cn.stylefeng.guns.modular.om.productionOrdeInfo.model.result.ProductionOrdeInfoResult;
import cn.stylefeng.guns.modular.om.productionOrdeInfo.service.ProductionOrdeInfoService;
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.model.params.ProductionOrderBatchInfoParam;
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.model.result.ProductionOrderBatchInfoResult;
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.service.ProductionOrderBatchInfoService;
import cn.stylefeng.guns.modular.om.productionOrderRecords.service.ProductionOrderRecordsService;
import cn.stylefeng.guns.modular.sc.repairManageInfo.model.params.RepairManageInfoParam;
import cn.stylefeng.guns.modular.sc.repairManageInfo.model.result.RepairManageInfoResult;
import cn.stylefeng.guns.modular.sc.repairManageInfo.service.RepairManageInfoService;
import cn.stylefeng.guns.modular.sc.serialNumbersConf.service.SerialNumbersConfService;
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;
import com.kangaroohy.milo.runner.subscription.SubscriptionCallback;
import com.kangaroohy.milo.service.MiloService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Random;
@Component
public class BOP010Callback implements SubscriptionCallback {
    public MiloService miloService;
    @Autowired
    public ProductionOrdeInfoService productionOrdeInfoService;
    @Autowired
    public PassingStationCollectionService passingStationCollectionService;
    @Autowired
    public ParamCollectionService paramCollectionService;
    @Autowired
    public CollectionParamConfService collectionParamConfService;
    @Autowired
    public SerialNumbersConfService serialNumbersConfService;
    @Autowired
    private EquipmentStatusService equipmentStatusService;
    @Autowired
    private EquipmentAlarmService equipmentAlarmService;
    @Autowired
    private MaterialTraceabilityService materialTraceabilityService;
    @Autowired
    private EquipmentInfoService equipmentInfoService;
    @Autowired
    private RepairManageInfoService repairManageInfoService;
    @Autowired
    private LocationInfoService locationInfoService;
    @Autowired
    private GreaseManageService greaseManageService;
    @Autowired
    private ProductionOrderRecordsService productionOrderRecordsService;
    @Autowired
    private ProductionOrderBatchInfoService productionOrderBatchInfoService;
    private static Logger logger;
    LogUtil logUtil = new LogUtil();
    static {
        logger = Logger.getLogger(BOP010Callback.class);
    }
    private static Date IN_TIME = null;
    private static String S_ORDER_CODE = "";//工单编号
    private static String S_PRODUCT_CODE = "";//产品编号
    private static String S_PRODUCT_TYPE= "";//产品类型
    private static String S_SFC_CODE = "";//总成编码
    private static String PRODUCTION_LINE  = "BOP";//产线号
    private static String LOCATION_CODE  = "BOP010";//工位号
    private static List list = null;
    public BOP010Callback(MiloService miloService,
                          ProductionOrdeInfoService productionOrdeInfoService,
                          PassingStationCollectionService passingStationCollectionService,
                          ParamCollectionService paramCollectionService,
                          CollectionParamConfService collectionParamConfService,
                          SerialNumbersConfService serialNumbersConfService,
                          EquipmentStatusService equipmentStatusService,
                          EquipmentAlarmService equipmentAlarmService,
                          MaterialTraceabilityService materialTraceabilityService,
                          EquipmentInfoService equipmentInfoService,
                          RepairManageInfoService repairManageInfoService,
                          LocationInfoService locationInfoService,
                          GreaseManageService greaseManageService,
                          ProductionOrderRecordsService productionOrderRecordsService,
                          ProductionOrderBatchInfoService productionOrderBatchInfoService) {
        this.miloService = miloService;
        this.productionOrdeInfoService = productionOrdeInfoService;
        this.passingStationCollectionService = passingStationCollectionService;
        this.paramCollectionService = paramCollectionService;
        this.collectionParamConfService = collectionParamConfService;
        this.serialNumbersConfService = serialNumbersConfService;
        this.equipmentStatusService = equipmentStatusService;
        this.equipmentAlarmService = equipmentAlarmService;
        this.materialTraceabilityService = materialTraceabilityService;
        this.equipmentInfoService = equipmentInfoService;
        this.repairManageInfoService = repairManageInfoService;
        this.locationInfoService = locationInfoService;
        this.greaseManageService = greaseManageService;
        this.productionOrderRecordsService = productionOrderRecordsService;
        this.productionOrderBatchInfoService = productionOrderBatchInfoService;
    }
    @Override
    public void onSubscribe(String identifier, Object value) {
        String ecpStr = "";//异常记录标记
        try {
            //心跳
            if(null != value && identifier.equals(OPCElement.COP010_F_HEART_BEAT)){
                if( "false".equals(value.toString()))
                {
                    ReadWriteEntity entity = new ReadWriteEntity(OPCElement.BOP010_F_HEART_BEAT,true);
                    miloService.writeToOpcUa(entity);
                }
            }
            //PLC进站
            else if(null != value && identifier.equals(OPCElement.BOP010_J_PLC_START)){
                if("true".equals(value.toString())){
                    String isRepair = miloService.
                            readFromOpcUa(OPCElement.BOP010_P_REPAIR)
                            .getValue().toString();//是否返修
                    if(isRepair.equals("true")){
                        handleRepair();
                    }else{
                        handleOrder();
                    }
                }
            }
            //PLC出站
            else if(null != value && identifier.equals(OPCElement.BOP010_J_PLC_FINISH)){
                if("true".equals(value.toString())){
                    handleFinsh();
                    handleInfo();
                    handleMaterial();
                }
            }else{
                System.out.println("BOP010值没有变");
            }
        } catch (Exception e) {
            ecpStr ="出现异常:" + logUtil.getTrace(e);
        }finally {
            if(!"".equals(ecpStr)){
                logger.info(ecpStr+"\r\n");
            }
        }
    }
    public void handleOrder() throws Exception{
        IN_TIME = DateTool.getLocalTimeForDate();
        ProductionOrdeInfoParam param = new ProductionOrdeInfoParam();
        param.setProductionLine("");//产线
        param.setOrderStatus("3");//工单状态
        List<ProductionOrdeInfoResult> list = productionOrdeInfoService.findListBySpec(param);
        if(list.size()>0) {
            ProductionOrdeInfoResult result = list.get(0);
            S_ORDER_CODE = result.getWorkOrderNo();
            S_PRODUCT_CODE = result.getMaterialCode();
            S_PRODUCT_TYPE = GlobalVariable.PRODUCT_TYPE_MAP.get(S_PRODUCT_CODE);
            //自动生成唯一码
            Random random = new Random(System.currentTimeMillis());
            S_SFC_CODE = "BOP"+random.nextLong();
            List<ReadWriteEntity> lists = new ArrayList<>();
            lists.add(new ReadWriteEntity(OPCElement.BOP010_S_ORDER_CODE,S_ORDER_CODE));
            lists.add(new ReadWriteEntity(OPCElement.BOP010_S_PRODUCT_CODE,S_PRODUCT_TYPE));
            lists.add(new ReadWriteEntity(OPCElement.BOP010_S_SFC_CODE,S_SFC_CODE));
            lists.add(new ReadWriteEntity(OPCElement.BOP010_S_NUMBER,result.getPlanQty().toString()));
            lists.add(new ReadWriteEntity(OPCElement.BOP010_J_PC_WRITE_ORDER,true));
            miloService.writeToOpcUa(lists);
            logger.info("BOP010工位,handleOrder PC处理完成!2");
        }else{
            logger.info("BOP010工位没有可执行的工单,请联系工单管理员下发该产线的工单!");
        }
    }
    public void handleFinsh() throws Exception {
        logger.info("handleFinsh PC处理开始!");
        String S_PRODUCT_STATE_CODE = miloService.
                readFromOpcUa(OPCElement.BOP010_S_PRODUCT_STATE_CODE)
                .getValue().toString();
        //处理过站信息
        PassingStationCollectionParam param = new PassingStationCollectionParam();
        param.setWorkOrderNo(S_ORDER_CODE);
        param.setProductCode(S_PRODUCT_CODE);
        param.setSfcCode(S_SFC_CODE);
        param.setProductionLine(PRODUCTION_LINE);
        param.setLocationCode(LOCATION_CODE);
        param.setInboundTime(IN_TIME);
        param.setOutboundTime(DateTool.getLocalTimeForDate());
        param.setOutRsSign(S_PRODUCT_STATE_CODE);//出站是否合格
        passingStationCollectionService.add(param);
        ReadWriteEntity entity = new ReadWriteEntity(OPCElement.BOP010_J_PC_FINISH,true);
        miloService.writeToOpcUa(entity);//写PC完成
        logger.info("handleFinsh PC处理完成!");
    }
    public void handleMaterial() {
        //查询批次上料信息
        ProductionOrderBatchInfoParam productionOrderBatchInfoParam = new ProductionOrderBatchInfoParam();
        productionOrderBatchInfoParam.setWorkOrderNo(S_ORDER_CODE);
        productionOrderBatchInfoParam.setLocationCode(LOCATION_CODE);
        List<ProductionOrderBatchInfoResult> list = productionOrderBatchInfoService.findListBySpec(productionOrderBatchInfoParam);
        for(int i=0;i<list.size();i++){
            ProductionOrderBatchInfoResult productionOrderBatchInfoResult = list.get(i);
            int remainingQuantity =  productionOrderBatchInfoResult.getResidueQuantity();//剩余数量
            if(remainingQuantity>0 ){
                //新增物料追溯
                MaterialTraceabilityParam materialTraceabilityParam = new MaterialTraceabilityParam();
                materialTraceabilityParam.setWorkOrderNo(S_ORDER_CODE);
                materialTraceabilityParam.setProductCode(S_PRODUCT_CODE);
                materialTraceabilityParam.setProductNo(S_SFC_CODE);
                materialTraceabilityParam.setLineCode(PRODUCTION_LINE);
                materialTraceabilityParam.setLocationCode(LOCATION_CODE);
                materialTraceabilityParam.setAssemblyQty(1);
                materialTraceabilityParam.setAssemblyTime(DateTool.getLocalTimeForDate());
                materialTraceabilityParam.setMaterialCode(productionOrderBatchInfoResult.getMaterialCode());//物料编码
                materialTraceabilityParam.setMaterialBatchNo(productionOrderBatchInfoResult.getBatch());//物料批次
                materialTraceabilityService.add(materialTraceabilityParam);
                //更新剩余数量
                productionOrderBatchInfoParam.setId(productionOrderBatchInfoResult.getId());
                productionOrderBatchInfoParam.setResidueQuantity(remainingQuantity-1);//剩余数量
                productionOrderBatchInfoService.update(productionOrderBatchInfoParam);
            }
        }
    }
    //PC读参数信息
    public void handleInfo() throws Exception {
        logger.info("handleInfo START!");
        if(null == list){
            CollectionParamConfParam collectionParamConfParam = new CollectionParamConfParam();
            collectionParamConfParam.setLocationCode(LOCATION_CODE);
            list = collectionParamConfService.findListBySpec(collectionParamConfParam);
        }
        if(null != list && !list.isEmpty()) {
            for (int i = 0; i < list.size(); i++) {
                CollectionParamConfResult result = (CollectionParamConfResult) list.get(i);
                String value = miloService.
                        readFromOpcUa(result.getGatherAddress())
                        .getValue().toString();//读参数值
                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);
                paramCollectionParam.setParamLower(result.getParamLower());
                paramCollectionParam.setParamUpper(result.getParamUpper());
                paramCollectionParam.setParamStandard(result.getParamCentral());
                paramCollectionParam.setCollectionTime(DateTool.getLocalTimeForDate());
                paramCollectionParam.setUnit(result.getUnit());
                paramCollectionService.add(paramCollectionParam);
            }
        }
        logger.info("handleInfo END!");
    }
    public void handleRepair() throws Exception{
        RepairManageInfoParam repairManageInfoParam = new RepairManageInfoParam();
        repairManageInfoParam.setLocationCode(LOCATION_CODE);
        repairManageInfoParam.setManageType("2");
        repairManageInfoParam.setUpPlc("0");
        List<RepairManageInfoResult> list = repairManageInfoService.findListBySpec(repairManageInfoParam);
        if(list.size()>0) {
            RepairManageInfoResult result = list.get(0);
            //自动生成唯一码
            Random random = new Random(System.currentTimeMillis());
            S_SFC_CODE = "BOP" + random.nextLong();
            S_ORDER_CODE = result.getWorkOrderNo();
            S_PRODUCT_CODE = result.getProductCode();
            S_PRODUCT_TYPE = GlobalVariable.PRODUCT_TYPE_MAP.get(S_PRODUCT_CODE);
            String  repairLocation = result.getPoorLocationCode();//
            //根据工位编码查询工位表中配置的返修工位号
            LocationInfoParam param = new LocationInfoParam();
            param.setLocationCode(repairLocation);
            List<LocationInfoResult> results = locationInfoService.findListBySpec(param);
            if(results.size()>0) {
                LocationInfoResult r = results.get(0);
                String repairLocationNo = r.getSpareField2();
                if(null != repairLocationNo && "" != repairLocationNo){
                    List<ReadWriteEntity> lists = new ArrayList<>();
                    lists.add(new ReadWriteEntity(OPCElement.BOP010_S_ORDER_CODE,S_ORDER_CODE));
                    lists.add(new ReadWriteEntity(OPCElement.BOP010_S_PRODUCT_CODE,S_PRODUCT_TYPE));
                    lists.add(new ReadWriteEntity(OPCElement.BOP010_S_SFC_CODE,S_SFC_CODE));
                    lists.add(new ReadWriteEntity(OPCElement.BOP010_P_REPAIR_LOCATION,repairLocationNo));
                    lists.add(new ReadWriteEntity(OPCElement.BOP010_J_PC_WRITE_ORDER,true));
                    miloService.writeToOpcUa(lists);
                    //更新为已经返修上线
                    Long id = result.getId();
                    repairManageInfoParam.setId(id);
                    repairManageInfoParam.setUpPlc("1");
                    repairManageInfoService.update(repairManageInfoParam);
                }else{
                    logger.info("BOP010工位,handleRepair è¯·æŸ¥è¯¢"+repairLocation+"工位是否配置返修工位号!");
                }
            }else{
                logger.info("BOP010工位,handleRepair æ— æ³•æŸ¥è¯¢åˆ°"+repairLocation+"工位!");
            }
        }
    }
}
guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/BOP020Callback.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,282 @@
package cn.stylefeng.guns.plcserver.callback;
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.model.params.ParamCollectionParam;
import cn.stylefeng.guns.modular.cm.paramCollection.service.ParamCollectionService;
import cn.stylefeng.guns.modular.cm.passingStationCollection.model.params.PassingStationCollectionParam;
import cn.stylefeng.guns.modular.cm.passingStationCollection.service.PassingStationCollectionService;
import cn.stylefeng.guns.modular.dq.materialTraceability.model.params.MaterialTraceabilityParam;
import cn.stylefeng.guns.modular.dq.materialTraceability.service.MaterialTraceabilityService;
import cn.stylefeng.guns.modular.em.equipmentAlarm.service.EquipmentAlarmService;
import cn.stylefeng.guns.modular.em.equipmentStatus.service.EquipmentStatusService;
import cn.stylefeng.guns.modular.gm.greaseManage.service.GreaseManageService;
import cn.stylefeng.guns.modular.om.productionOrdeInfo.service.ProductionOrdeInfoService;
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.model.params.ProductionOrderBatchInfoParam;
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.model.result.ProductionOrderBatchInfoResult;
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.service.ProductionOrderBatchInfoService;
import cn.stylefeng.guns.modular.om.productionOrderRecords.service.ProductionOrderRecordsService;
import cn.stylefeng.guns.modular.sc.repairManageInfo.service.RepairManageInfoService;
import cn.stylefeng.guns.modular.sc.serialNumbersConf.service.SerialNumbersConfService;
import cn.stylefeng.guns.plcserver.opc.GlobalVariable;
import cn.stylefeng.guns.plcserver.opc.OPCElement;
import cn.stylefeng.guns.plcserver.tool.DateTool;
import cn.stylefeng.guns.plcserver.tool.LogUtil;
import com.kangaroohy.milo.model.ReadWriteEntity;
import com.kangaroohy.milo.runner.subscription.SubscriptionCallback;
import com.kangaroohy.milo.service.MiloService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@Component
public class BOP020Callback implements SubscriptionCallback {
    public MiloService miloService;
    @Autowired
    public ProductionOrdeInfoService productionOrdeInfoService;
    @Autowired
    public PassingStationCollectionService passingStationCollectionService;
    @Autowired
    public ParamCollectionService paramCollectionService;
    @Autowired
    public CollectionParamConfService collectionParamConfService;
    @Autowired
    public SerialNumbersConfService serialNumbersConfService;
    @Autowired
    private EquipmentStatusService equipmentStatusService;
    @Autowired
    private EquipmentAlarmService equipmentAlarmService;
    @Autowired
    private MaterialTraceabilityService materialTraceabilityService;
    @Autowired
    private EquipmentInfoService equipmentInfoService;
    @Autowired
    private RepairManageInfoService repairManageInfoService;
    @Autowired
    private LocationInfoService locationInfoService;
    @Autowired
    private GreaseManageService greaseManageService;
    @Autowired
    private ProductionOrderRecordsService productionOrderRecordsService;
    @Autowired
    private ProductionOrderBatchInfoService productionOrderBatchInfoService;
    private static Logger logger;
    LogUtil logUtil = new LogUtil();
    static {
        logger = Logger.getLogger(BOP020Callback.class);
    }
    private static Date IN_TIME = null;
    private static String S_ORDER_CODE = "";//工单编号
    private static String S_PRODUCT_CODE = "";//产品编号
    private static String S_PRODUCT_TYPE= "";//产品类型
    private static String S_SFC_CODE = "";//总成编码
    private static String PRODUCTION_LINE  = "BOP";//产线号
    private static String LOCATION_CODE  = "BOP020";//工位号
    private static List list = null;
    public BOP020Callback(MiloService miloService,
                          ProductionOrdeInfoService productionOrdeInfoService,
                          PassingStationCollectionService passingStationCollectionService,
                          ParamCollectionService paramCollectionService,
                          CollectionParamConfService collectionParamConfService,
                          SerialNumbersConfService serialNumbersConfService,
                          EquipmentStatusService equipmentStatusService,
                          EquipmentAlarmService equipmentAlarmService,
                          MaterialTraceabilityService materialTraceabilityService,
                          EquipmentInfoService equipmentInfoService,
                          RepairManageInfoService repairManageInfoService,
                          LocationInfoService locationInfoService,
                          GreaseManageService greaseManageService,
                          ProductionOrderRecordsService productionOrderRecordsService,
                          ProductionOrderBatchInfoService productionOrderBatchInfoService) {
        this.miloService = miloService;
        this.productionOrdeInfoService = productionOrdeInfoService;
        this.passingStationCollectionService = passingStationCollectionService;
        this.paramCollectionService = paramCollectionService;
        this.collectionParamConfService = collectionParamConfService;
        this.serialNumbersConfService = serialNumbersConfService;
        this.equipmentStatusService = equipmentStatusService;
        this.equipmentAlarmService = equipmentAlarmService;
        this.materialTraceabilityService = materialTraceabilityService;
        this.equipmentInfoService = equipmentInfoService;
        this.repairManageInfoService = repairManageInfoService;
        this.locationInfoService = locationInfoService;
        this.greaseManageService = greaseManageService;
        this.productionOrderRecordsService = productionOrderRecordsService;
        this.productionOrderBatchInfoService = productionOrderBatchInfoService;
    }
    @Override
    public void onSubscribe(String identifier, Object value) {
        String ecpStr = "";//异常记录标记
        try {
            //心跳
            if(null != value && identifier.equals(OPCElement.BOP020_F_HEART_BEAT)){
                if( "false".equals(value.toString()))
                {
                    ReadWriteEntity entity = new ReadWriteEntity(OPCElement.BOP020_F_HEART_BEAT,true);
                    miloService.writeToOpcUa(entity);
                }
            }
            //PLC进站
            else if(null != value && identifier.equals(OPCElement.BOP020_J_PLC_START)){
                if("true".equals(value.toString())){
                    handleOrder();
                }
            }
            //PLC出站
            else if(null != value && identifier.equals(OPCElement.BOP020_J_PLC_FINISH)){
                if("true".equals(value.toString())){
                    handleFinsh();
                    handleInfo();
                    handleMaterial();
                }
            }else{
                System.out.println("BOP020值没有变");
            }
        } catch (Exception e) {
            ecpStr ="出现异常:" + logUtil.getTrace(e);
        }finally {
            if(!"".equals(ecpStr)){
                logger.info(ecpStr+"\r\n");
            }
        }
    }
    //PC读工单
    public void handleOrder() throws Exception {
        logger.info("handleOrder PC处理开始!");
        IN_TIME = DateTool.getLocalTimeForDate();
        List<String> lists = new ArrayList<>();
        lists.add(OPCElement.BOP020_S_ORDER_CODE);
        lists.add(OPCElement.BOP020_S_PRODUCT_CODE);
        lists.add(OPCElement.BOP020_S_SFC_CODE);
        List<ReadWriteEntity> returnLists= miloService.readFromOpcUa(lists);
        returnLists.forEach(element->{
            switch(element.getIdentifier()){
                case OPCElement.BOP020_S_ORDER_CODE:
                    S_ORDER_CODE = element.getValue().toString();
                    break;
                case OPCElement.BOP020_S_PRODUCT_CODE:
                    S_PRODUCT_TYPE = element.getValue().toString();
                    S_PRODUCT_CODE = GlobalVariable.PRODUCT_CODE_MAP.get(S_PRODUCT_TYPE);
                    break;
                case OPCElement.BOP020_S_SFC_CODE:
                    S_SFC_CODE = element.getValue().toString();
                    break;
                default:
                    break;
            }
        });
        ReadWriteEntity entity = new ReadWriteEntity(OPCElement.BOP020_J_PC_WRITE_ORDER,true);
        miloService.writeToOpcUa(entity);
        logger.info("handleOrder PC处理完成!");
    }
    public void handleFinsh() throws Exception {
        logger.info("handleFinsh PC处理开始!");
        String S_PRODUCT_STATE_CODE = miloService.
                readFromOpcUa(OPCElement.BOP020_S_PRODUCT_STATE_CODE)
                .getValue().toString();
        //处理过站信息
        PassingStationCollectionParam param = new PassingStationCollectionParam();
        param.setWorkOrderNo(S_ORDER_CODE);
        param.setProductCode(S_PRODUCT_CODE);
        param.setSfcCode(S_SFC_CODE);
        param.setProductionLine(PRODUCTION_LINE);
        param.setLocationCode(LOCATION_CODE);
        param.setInboundTime(IN_TIME);
        param.setOutboundTime(DateTool.getLocalTimeForDate());
        param.setOutRsSign(S_PRODUCT_STATE_CODE);//出站是否合格
        passingStationCollectionService.add(param);
        ReadWriteEntity entity = new ReadWriteEntity(OPCElement.BOP020_J_PC_FINISH,true);
        miloService.writeToOpcUa(entity);//写PC完成
        logger.info("handleFinsh PC处理完成!");
    }
    public void handleMaterial() {
        //查询批次上料信息
        ProductionOrderBatchInfoParam productionOrderBatchInfoParam = new ProductionOrderBatchInfoParam();
        productionOrderBatchInfoParam.setWorkOrderNo(S_ORDER_CODE);
        productionOrderBatchInfoParam.setLocationCode(LOCATION_CODE);
        List<ProductionOrderBatchInfoResult> list = productionOrderBatchInfoService.findListBySpec(productionOrderBatchInfoParam);
        for(int i=0;i<list.size();i++){
            ProductionOrderBatchInfoResult productionOrderBatchInfoResult = list.get(i);
            int remainingQuantity =  productionOrderBatchInfoResult.getResidueQuantity();//剩余数量
            if(remainingQuantity>0 ){
                //新增物料追溯
                MaterialTraceabilityParam materialTraceabilityParam = new MaterialTraceabilityParam();
                materialTraceabilityParam.setWorkOrderNo(S_ORDER_CODE);
                materialTraceabilityParam.setProductCode(S_PRODUCT_CODE);
                materialTraceabilityParam.setProductNo(S_SFC_CODE);
                materialTraceabilityParam.setLineCode(PRODUCTION_LINE);
                materialTraceabilityParam.setLocationCode(LOCATION_CODE);
                materialTraceabilityParam.setAssemblyQty(1);
                materialTraceabilityParam.setAssemblyTime(DateTool.getLocalTimeForDate());
                materialTraceabilityParam.setMaterialCode(productionOrderBatchInfoResult.getMaterialCode());//物料编码
                materialTraceabilityParam.setMaterialBatchNo(productionOrderBatchInfoResult.getBatch());//物料批次
                materialTraceabilityService.add(materialTraceabilityParam);
                //更新剩余数量
                productionOrderBatchInfoParam.setId(productionOrderBatchInfoResult.getId());
                productionOrderBatchInfoParam.setResidueQuantity(remainingQuantity-1);//剩余数量
                productionOrderBatchInfoService.update(productionOrderBatchInfoParam);
            }
        }
    }
    //PC读参数信息
    public void handleInfo() throws Exception {
        logger.info("handleInfo START!");
        if(null == list){
            CollectionParamConfParam collectionParamConfParam = new CollectionParamConfParam();
            collectionParamConfParam.setLocationCode(LOCATION_CODE);
            list = collectionParamConfService.findListBySpec(collectionParamConfParam);
        }
        if(null != list && !list.isEmpty()) {
            for (int i = 0; i < list.size(); i++) {
                CollectionParamConfResult result = (CollectionParamConfResult) list.get(i);
                String value = miloService.
                        readFromOpcUa(result.getGatherAddress())
                        .getValue().toString();//读参数值
                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);
                paramCollectionParam.setParamLower(result.getParamLower());
                paramCollectionParam.setParamUpper(result.getParamUpper());
                paramCollectionParam.setParamStandard(result.getParamCentral());
                paramCollectionParam.setCollectionTime(DateTool.getLocalTimeForDate());
                paramCollectionParam.setUnit(result.getUnit());
                paramCollectionService.add(paramCollectionParam);
            }
        }
        logger.info("handleInfo END!");
    }
}
guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/BOP030BCallback.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,282 @@
package cn.stylefeng.guns.plcserver.callback;
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.model.params.ParamCollectionParam;
import cn.stylefeng.guns.modular.cm.paramCollection.service.ParamCollectionService;
import cn.stylefeng.guns.modular.cm.passingStationCollection.model.params.PassingStationCollectionParam;
import cn.stylefeng.guns.modular.cm.passingStationCollection.service.PassingStationCollectionService;
import cn.stylefeng.guns.modular.dq.materialTraceability.model.params.MaterialTraceabilityParam;
import cn.stylefeng.guns.modular.dq.materialTraceability.service.MaterialTraceabilityService;
import cn.stylefeng.guns.modular.em.equipmentAlarm.service.EquipmentAlarmService;
import cn.stylefeng.guns.modular.em.equipmentStatus.service.EquipmentStatusService;
import cn.stylefeng.guns.modular.gm.greaseManage.service.GreaseManageService;
import cn.stylefeng.guns.modular.om.productionOrdeInfo.service.ProductionOrdeInfoService;
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.model.params.ProductionOrderBatchInfoParam;
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.model.result.ProductionOrderBatchInfoResult;
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.service.ProductionOrderBatchInfoService;
import cn.stylefeng.guns.modular.om.productionOrderRecords.service.ProductionOrderRecordsService;
import cn.stylefeng.guns.modular.sc.repairManageInfo.service.RepairManageInfoService;
import cn.stylefeng.guns.modular.sc.serialNumbersConf.service.SerialNumbersConfService;
import cn.stylefeng.guns.plcserver.opc.GlobalVariable;
import cn.stylefeng.guns.plcserver.opc.OPCElement;
import cn.stylefeng.guns.plcserver.tool.DateTool;
import cn.stylefeng.guns.plcserver.tool.LogUtil;
import com.kangaroohy.milo.model.ReadWriteEntity;
import com.kangaroohy.milo.runner.subscription.SubscriptionCallback;
import com.kangaroohy.milo.service.MiloService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@Component
public class BOP030BCallback implements SubscriptionCallback {
    public MiloService miloService;
    @Autowired
    public ProductionOrdeInfoService productionOrdeInfoService;
    @Autowired
    public PassingStationCollectionService passingStationCollectionService;
    @Autowired
    public ParamCollectionService paramCollectionService;
    @Autowired
    public CollectionParamConfService collectionParamConfService;
    @Autowired
    public SerialNumbersConfService serialNumbersConfService;
    @Autowired
    private EquipmentStatusService equipmentStatusService;
    @Autowired
    private EquipmentAlarmService equipmentAlarmService;
    @Autowired
    private MaterialTraceabilityService materialTraceabilityService;
    @Autowired
    private EquipmentInfoService equipmentInfoService;
    @Autowired
    private RepairManageInfoService repairManageInfoService;
    @Autowired
    private LocationInfoService locationInfoService;
    @Autowired
    private GreaseManageService greaseManageService;
    @Autowired
    private ProductionOrderRecordsService productionOrderRecordsService;
    @Autowired
    private ProductionOrderBatchInfoService productionOrderBatchInfoService;
    private static Logger logger;
    LogUtil logUtil = new LogUtil();
    static {
        logger = Logger.getLogger(BOP030BCallback.class);
    }
    private static Date IN_TIME = null;
    private static String S_ORDER_CODE = "";//工单编号
    private static String S_PRODUCT_CODE = "";//产品编号
    private static String S_PRODUCT_TYPE= "";//产品类型
    private static String S_SFC_CODE = "";//总成编码
    private static String PRODUCTION_LINE  = "BOP";//产线号
    private static String LOCATION_CODE  = "BOP030B";//工位号
    private static List list = null;
    public BOP030BCallback(MiloService miloService,
                           ProductionOrdeInfoService productionOrdeInfoService,
                           PassingStationCollectionService passingStationCollectionService,
                           ParamCollectionService paramCollectionService,
                           CollectionParamConfService collectionParamConfService,
                           SerialNumbersConfService serialNumbersConfService,
                           EquipmentStatusService equipmentStatusService,
                           EquipmentAlarmService equipmentAlarmService,
                           MaterialTraceabilityService materialTraceabilityService,
                           EquipmentInfoService equipmentInfoService,
                           RepairManageInfoService repairManageInfoService,
                           LocationInfoService locationInfoService,
                           GreaseManageService greaseManageService,
                           ProductionOrderRecordsService productionOrderRecordsService,
                           ProductionOrderBatchInfoService productionOrderBatchInfoService) {
        this.miloService = miloService;
        this.productionOrdeInfoService = productionOrdeInfoService;
        this.passingStationCollectionService = passingStationCollectionService;
        this.paramCollectionService = paramCollectionService;
        this.collectionParamConfService = collectionParamConfService;
        this.serialNumbersConfService = serialNumbersConfService;
        this.equipmentStatusService = equipmentStatusService;
        this.equipmentAlarmService = equipmentAlarmService;
        this.materialTraceabilityService = materialTraceabilityService;
        this.equipmentInfoService = equipmentInfoService;
        this.repairManageInfoService = repairManageInfoService;
        this.locationInfoService = locationInfoService;
        this.greaseManageService = greaseManageService;
        this.productionOrderRecordsService = productionOrderRecordsService;
        this.productionOrderBatchInfoService = productionOrderBatchInfoService;
    }
    @Override
    public void onSubscribe(String identifier, Object value) {
        String ecpStr = "";//异常记录标记
        try {
            //心跳
            if(null != value && identifier.equals(OPCElement.BOP030B_F_HEART_BEAT)){
                if( "false".equals(value.toString()))
                {
                    ReadWriteEntity entity = new ReadWriteEntity(OPCElement.BOP030B_F_HEART_BEAT,true);
                    miloService.writeToOpcUa(entity);
                }
            }
            //PLC进站
            else if(null != value && identifier.equals(OPCElement.BOP030B_J_PLC_START)){
                if("true".equals(value.toString())){
                    handleOrder();
                }
            }
            //PLC出站
            else if(null != value && identifier.equals(OPCElement.BOP030B_J_PLC_FINISH)){
                if("true".equals(value.toString())){
                    handleFinsh();
                    handleInfo();
                    handleMaterial();
                }
            }else{
                System.out.println("BOP030B值没有变");
            }
        } catch (Exception e) {
            ecpStr ="出现异常:" + logUtil.getTrace(e);
        }finally {
            if(!"".equals(ecpStr)){
                logger.info(ecpStr+"\r\n");
            }
        }
    }
    //PC读工单
    public void handleOrder() throws Exception {
        logger.info("handleOrder PC处理开始!");
        IN_TIME = DateTool.getLocalTimeForDate();
        List<String> lists = new ArrayList<>();
        lists.add(OPCElement.BOP030B_S_ORDER_CODE);
        lists.add(OPCElement.BOP030B_S_PRODUCT_CODE);
        lists.add(OPCElement.BOP030B_S_SFC_CODE);
        List<ReadWriteEntity> returnLists= miloService.readFromOpcUa(lists);
        returnLists.forEach(element->{
            switch(element.getIdentifier()){
                case OPCElement.BOP030B_S_ORDER_CODE:
                    S_ORDER_CODE = element.getValue().toString();
                    break;
                case OPCElement.BOP030B_S_PRODUCT_CODE:
                    S_PRODUCT_TYPE = element.getValue().toString();
                    S_PRODUCT_CODE = GlobalVariable.PRODUCT_CODE_MAP.get(S_PRODUCT_TYPE);
                    break;
                case OPCElement.BOP030B_S_SFC_CODE:
                    S_SFC_CODE = element.getValue().toString();
                    break;
                default:
                    break;
            }
        });
        ReadWriteEntity entity = new ReadWriteEntity(OPCElement.BOP030B_J_PC_WRITE_ORDER,true);
        miloService.writeToOpcUa(entity);
        logger.info("handleOrder PC处理完成!");
    }
    public void handleFinsh() throws Exception {
        logger.info("handleFinsh PC处理开始!");
        String S_PRODUCT_STATE_CODE = miloService.
                readFromOpcUa(OPCElement.BOP030B_S_PRODUCT_STATE_CODE)
                .getValue().toString();
        //处理过站信息
        PassingStationCollectionParam param = new PassingStationCollectionParam();
        param.setWorkOrderNo(S_ORDER_CODE);
        param.setProductCode(S_PRODUCT_CODE);
        param.setSfcCode(S_SFC_CODE);
        param.setProductionLine(PRODUCTION_LINE);
        param.setLocationCode(LOCATION_CODE);
        param.setInboundTime(IN_TIME);
        param.setOutboundTime(DateTool.getLocalTimeForDate());
        param.setOutRsSign(S_PRODUCT_STATE_CODE);//出站是否合格
        passingStationCollectionService.add(param);
        ReadWriteEntity entity = new ReadWriteEntity(OPCElement.BOP030B_J_PC_FINISH,true);
        miloService.writeToOpcUa(entity);//写PC完成
        logger.info("handleFinsh PC处理完成!");
    }
    public void handleMaterial() {
        //查询批次上料信息
        ProductionOrderBatchInfoParam productionOrderBatchInfoParam = new ProductionOrderBatchInfoParam();
        productionOrderBatchInfoParam.setWorkOrderNo(S_ORDER_CODE);
        productionOrderBatchInfoParam.setLocationCode(LOCATION_CODE);
        List<ProductionOrderBatchInfoResult> list = productionOrderBatchInfoService.findListBySpec(productionOrderBatchInfoParam);
        for(int i=0;i<list.size();i++){
            ProductionOrderBatchInfoResult productionOrderBatchInfoResult = list.get(i);
            int remainingQuantity =  productionOrderBatchInfoResult.getResidueQuantity();//剩余数量
            if(remainingQuantity>0 ){
                //新增物料追溯
                MaterialTraceabilityParam materialTraceabilityParam = new MaterialTraceabilityParam();
                materialTraceabilityParam.setWorkOrderNo(S_ORDER_CODE);
                materialTraceabilityParam.setProductCode(S_PRODUCT_CODE);
                materialTraceabilityParam.setProductNo(S_SFC_CODE);
                materialTraceabilityParam.setLineCode(PRODUCTION_LINE);
                materialTraceabilityParam.setLocationCode(LOCATION_CODE);
                materialTraceabilityParam.setAssemblyQty(1);
                materialTraceabilityParam.setAssemblyTime(DateTool.getLocalTimeForDate());
                materialTraceabilityParam.setMaterialCode(productionOrderBatchInfoResult.getMaterialCode());//物料编码
                materialTraceabilityParam.setMaterialBatchNo(productionOrderBatchInfoResult.getBatch());//物料批次
                materialTraceabilityService.add(materialTraceabilityParam);
                //更新剩余数量
                productionOrderBatchInfoParam.setId(productionOrderBatchInfoResult.getId());
                productionOrderBatchInfoParam.setResidueQuantity(remainingQuantity-1);//剩余数量
                productionOrderBatchInfoService.update(productionOrderBatchInfoParam);
            }
        }
    }
    //PC读参数信息
    public void handleInfo() throws Exception {
        logger.info("handleInfo START!");
        if(null == list){
            CollectionParamConfParam collectionParamConfParam = new CollectionParamConfParam();
            collectionParamConfParam.setLocationCode(LOCATION_CODE);
            list = collectionParamConfService.findListBySpec(collectionParamConfParam);
        }
        if(null != list && !list.isEmpty()) {
            for (int i = 0; i < list.size(); i++) {
                CollectionParamConfResult result = (CollectionParamConfResult) list.get(i);
                String value = miloService.
                        readFromOpcUa(result.getGatherAddress())
                        .getValue().toString();//读参数值
                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);
                paramCollectionParam.setParamLower(result.getParamLower());
                paramCollectionParam.setParamUpper(result.getParamUpper());
                paramCollectionParam.setParamStandard(result.getParamCentral());
                paramCollectionParam.setCollectionTime(DateTool.getLocalTimeForDate());
                paramCollectionParam.setUnit(result.getUnit());
                paramCollectionService.add(paramCollectionParam);
            }
        }
        logger.info("handleInfo END!");
    }
}
guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/BOP030Callback.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,282 @@
package cn.stylefeng.guns.plcserver.callback;
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.model.params.ParamCollectionParam;
import cn.stylefeng.guns.modular.cm.paramCollection.service.ParamCollectionService;
import cn.stylefeng.guns.modular.cm.passingStationCollection.model.params.PassingStationCollectionParam;
import cn.stylefeng.guns.modular.cm.passingStationCollection.service.PassingStationCollectionService;
import cn.stylefeng.guns.modular.dq.materialTraceability.model.params.MaterialTraceabilityParam;
import cn.stylefeng.guns.modular.dq.materialTraceability.service.MaterialTraceabilityService;
import cn.stylefeng.guns.modular.em.equipmentAlarm.service.EquipmentAlarmService;
import cn.stylefeng.guns.modular.em.equipmentStatus.service.EquipmentStatusService;
import cn.stylefeng.guns.modular.gm.greaseManage.service.GreaseManageService;
import cn.stylefeng.guns.modular.om.productionOrdeInfo.service.ProductionOrdeInfoService;
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.model.params.ProductionOrderBatchInfoParam;
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.model.result.ProductionOrderBatchInfoResult;
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.service.ProductionOrderBatchInfoService;
import cn.stylefeng.guns.modular.om.productionOrderRecords.service.ProductionOrderRecordsService;
import cn.stylefeng.guns.modular.sc.repairManageInfo.service.RepairManageInfoService;
import cn.stylefeng.guns.modular.sc.serialNumbersConf.service.SerialNumbersConfService;
import cn.stylefeng.guns.plcserver.opc.GlobalVariable;
import cn.stylefeng.guns.plcserver.opc.OPCElement;
import cn.stylefeng.guns.plcserver.tool.DateTool;
import cn.stylefeng.guns.plcserver.tool.LogUtil;
import com.kangaroohy.milo.model.ReadWriteEntity;
import com.kangaroohy.milo.runner.subscription.SubscriptionCallback;
import com.kangaroohy.milo.service.MiloService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@Component
public class BOP030Callback implements SubscriptionCallback {
    public MiloService miloService;
    @Autowired
    public ProductionOrdeInfoService productionOrdeInfoService;
    @Autowired
    public PassingStationCollectionService passingStationCollectionService;
    @Autowired
    public ParamCollectionService paramCollectionService;
    @Autowired
    public CollectionParamConfService collectionParamConfService;
    @Autowired
    public SerialNumbersConfService serialNumbersConfService;
    @Autowired
    private EquipmentStatusService equipmentStatusService;
    @Autowired
    private EquipmentAlarmService equipmentAlarmService;
    @Autowired
    private MaterialTraceabilityService materialTraceabilityService;
    @Autowired
    private EquipmentInfoService equipmentInfoService;
    @Autowired
    private RepairManageInfoService repairManageInfoService;
    @Autowired
    private LocationInfoService locationInfoService;
    @Autowired
    private GreaseManageService greaseManageService;
    @Autowired
    private ProductionOrderRecordsService productionOrderRecordsService;
    @Autowired
    private ProductionOrderBatchInfoService productionOrderBatchInfoService;
    private static Logger logger;
    LogUtil logUtil = new LogUtil();
    static {
        logger = Logger.getLogger(BOP030Callback.class);
    }
    private static Date IN_TIME = null;
    private static String S_ORDER_CODE = "";//工单编号
    private static String S_PRODUCT_CODE = "";//产品编号
    private static String S_PRODUCT_TYPE= "";//产品类型
    private static String S_SFC_CODE = "";//总成编码
    private static String PRODUCTION_LINE  = "BOP";//产线号
    private static String LOCATION_CODE  = "BOP030";//工位号
    private static List list = null;
    public BOP030Callback(MiloService miloService,
                          ProductionOrdeInfoService productionOrdeInfoService,
                          PassingStationCollectionService passingStationCollectionService,
                          ParamCollectionService paramCollectionService,
                          CollectionParamConfService collectionParamConfService,
                          SerialNumbersConfService serialNumbersConfService,
                          EquipmentStatusService equipmentStatusService,
                          EquipmentAlarmService equipmentAlarmService,
                          MaterialTraceabilityService materialTraceabilityService,
                          EquipmentInfoService equipmentInfoService,
                          RepairManageInfoService repairManageInfoService,
                          LocationInfoService locationInfoService,
                          GreaseManageService greaseManageService,
                          ProductionOrderRecordsService productionOrderRecordsService,
                          ProductionOrderBatchInfoService productionOrderBatchInfoService) {
        this.miloService = miloService;
        this.productionOrdeInfoService = productionOrdeInfoService;
        this.passingStationCollectionService = passingStationCollectionService;
        this.paramCollectionService = paramCollectionService;
        this.collectionParamConfService = collectionParamConfService;
        this.serialNumbersConfService = serialNumbersConfService;
        this.equipmentStatusService = equipmentStatusService;
        this.equipmentAlarmService = equipmentAlarmService;
        this.materialTraceabilityService = materialTraceabilityService;
        this.equipmentInfoService = equipmentInfoService;
        this.repairManageInfoService = repairManageInfoService;
        this.locationInfoService = locationInfoService;
        this.greaseManageService = greaseManageService;
        this.productionOrderRecordsService = productionOrderRecordsService;
        this.productionOrderBatchInfoService = productionOrderBatchInfoService;
    }
    @Override
    public void onSubscribe(String identifier, Object value) {
        String ecpStr = "";//异常记录标记
        try {
            //心跳
            if(null != value && identifier.equals(OPCElement.BOP030_F_HEART_BEAT)){
                if( "false".equals(value.toString()))
                {
                    ReadWriteEntity entity = new ReadWriteEntity(OPCElement.BOP030_F_HEART_BEAT,true);
                    miloService.writeToOpcUa(entity);
                }
            }
            //PLC进站
            else if(null != value && identifier.equals(OPCElement.BOP030_J_PLC_START)){
                if("true".equals(value.toString())){
                    handleOrder();
                }
            }
            //PLC出站
            else if(null != value && identifier.equals(OPCElement.BOP030_J_PLC_FINISH)){
                if("true".equals(value.toString())){
                    handleFinsh();
                    handleInfo();
                    handleMaterial();
                }
            }else{
                System.out.println("BOP030值没有变");
            }
        } catch (Exception e) {
            ecpStr ="出现异常:" + logUtil.getTrace(e);
        }finally {
            if(!"".equals(ecpStr)){
                logger.info(ecpStr+"\r\n");
            }
        }
    }
    //PC读工单
    public void handleOrder() throws Exception {
        logger.info("handleOrder PC处理开始!");
        IN_TIME = DateTool.getLocalTimeForDate();
        List<String> lists = new ArrayList<>();
        lists.add(OPCElement.BOP030_S_ORDER_CODE);
        lists.add(OPCElement.BOP030_S_PRODUCT_CODE);
        lists.add(OPCElement.BOP030_S_SFC_CODE);
        List<ReadWriteEntity> returnLists= miloService.readFromOpcUa(lists);
        returnLists.forEach(element->{
            switch(element.getIdentifier()){
                case OPCElement.BOP030_S_ORDER_CODE:
                    S_ORDER_CODE = element.getValue().toString();
                    break;
                case OPCElement.BOP030_S_PRODUCT_CODE:
                    S_PRODUCT_TYPE = element.getValue().toString();
                    S_PRODUCT_CODE = GlobalVariable.PRODUCT_CODE_MAP.get(S_PRODUCT_TYPE);
                    break;
                case OPCElement.BOP030_S_SFC_CODE:
                    S_SFC_CODE = element.getValue().toString();
                    break;
                default:
                    break;
            }
        });
        ReadWriteEntity entity = new ReadWriteEntity(OPCElement.BOP030_J_PC_WRITE_ORDER,true);
        miloService.writeToOpcUa(entity);
        logger.info("handleOrder PC处理完成!");
    }
    public void handleFinsh() throws Exception {
        logger.info("handleFinsh PC处理开始!");
        String S_PRODUCT_STATE_CODE = miloService.
                readFromOpcUa(OPCElement.BOP030_S_PRODUCT_STATE_CODE)
                .getValue().toString();
        //处理过站信息
        PassingStationCollectionParam param = new PassingStationCollectionParam();
        param.setWorkOrderNo(S_ORDER_CODE);
        param.setProductCode(S_PRODUCT_CODE);
        param.setSfcCode(S_SFC_CODE);
        param.setProductionLine(PRODUCTION_LINE);
        param.setLocationCode(LOCATION_CODE);
        param.setInboundTime(IN_TIME);
        param.setOutboundTime(DateTool.getLocalTimeForDate());
        param.setOutRsSign(S_PRODUCT_STATE_CODE);//出站是否合格
        passingStationCollectionService.add(param);
        ReadWriteEntity entity = new ReadWriteEntity(OPCElement.BOP030_J_PC_FINISH,true);
        miloService.writeToOpcUa(entity);//写PC完成
        logger.info("handleFinsh PC处理完成!");
    }
    public void handleMaterial() {
        //查询批次上料信息
        ProductionOrderBatchInfoParam productionOrderBatchInfoParam = new ProductionOrderBatchInfoParam();
        productionOrderBatchInfoParam.setWorkOrderNo(S_ORDER_CODE);
        productionOrderBatchInfoParam.setLocationCode(LOCATION_CODE);
        List<ProductionOrderBatchInfoResult> list = productionOrderBatchInfoService.findListBySpec(productionOrderBatchInfoParam);
        for(int i=0;i<list.size();i++){
            ProductionOrderBatchInfoResult productionOrderBatchInfoResult = list.get(i);
            int remainingQuantity =  productionOrderBatchInfoResult.getResidueQuantity();//剩余数量
            if(remainingQuantity>0 ){
                //新增物料追溯
                MaterialTraceabilityParam materialTraceabilityParam = new MaterialTraceabilityParam();
                materialTraceabilityParam.setWorkOrderNo(S_ORDER_CODE);
                materialTraceabilityParam.setProductCode(S_PRODUCT_CODE);
                materialTraceabilityParam.setProductNo(S_SFC_CODE);
                materialTraceabilityParam.setLineCode(PRODUCTION_LINE);
                materialTraceabilityParam.setLocationCode(LOCATION_CODE);
                materialTraceabilityParam.setAssemblyQty(1);
                materialTraceabilityParam.setAssemblyTime(DateTool.getLocalTimeForDate());
                materialTraceabilityParam.setMaterialCode(productionOrderBatchInfoResult.getMaterialCode());//物料编码
                materialTraceabilityParam.setMaterialBatchNo(productionOrderBatchInfoResult.getBatch());//物料批次
                materialTraceabilityService.add(materialTraceabilityParam);
                //更新剩余数量
                productionOrderBatchInfoParam.setId(productionOrderBatchInfoResult.getId());
                productionOrderBatchInfoParam.setResidueQuantity(remainingQuantity-1);//剩余数量
                productionOrderBatchInfoService.update(productionOrderBatchInfoParam);
            }
        }
    }
    //PC读参数信息
    public void handleInfo() throws Exception {
        logger.info("handleInfo START!");
        if(null == list){
            CollectionParamConfParam collectionParamConfParam = new CollectionParamConfParam();
            collectionParamConfParam.setLocationCode(LOCATION_CODE);
            list = collectionParamConfService.findListBySpec(collectionParamConfParam);
        }
        if(null != list && !list.isEmpty()) {
            for (int i = 0; i < list.size(); i++) {
                CollectionParamConfResult result = (CollectionParamConfResult) list.get(i);
                String value = miloService.
                        readFromOpcUa(result.getGatherAddress())
                        .getValue().toString();//读参数值
                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);
                paramCollectionParam.setParamLower(result.getParamLower());
                paramCollectionParam.setParamUpper(result.getParamUpper());
                paramCollectionParam.setParamStandard(result.getParamCentral());
                paramCollectionParam.setCollectionTime(DateTool.getLocalTimeForDate());
                paramCollectionParam.setUnit(result.getUnit());
                paramCollectionService.add(paramCollectionParam);
            }
        }
        logger.info("handleInfo END!");
    }
}
guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/BOP040BCallback.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,282 @@
package cn.stylefeng.guns.plcserver.callback;
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.model.params.ParamCollectionParam;
import cn.stylefeng.guns.modular.cm.paramCollection.service.ParamCollectionService;
import cn.stylefeng.guns.modular.cm.passingStationCollection.model.params.PassingStationCollectionParam;
import cn.stylefeng.guns.modular.cm.passingStationCollection.service.PassingStationCollectionService;
import cn.stylefeng.guns.modular.dq.materialTraceability.model.params.MaterialTraceabilityParam;
import cn.stylefeng.guns.modular.dq.materialTraceability.service.MaterialTraceabilityService;
import cn.stylefeng.guns.modular.em.equipmentAlarm.service.EquipmentAlarmService;
import cn.stylefeng.guns.modular.em.equipmentStatus.service.EquipmentStatusService;
import cn.stylefeng.guns.modular.gm.greaseManage.service.GreaseManageService;
import cn.stylefeng.guns.modular.om.productionOrdeInfo.service.ProductionOrdeInfoService;
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.model.params.ProductionOrderBatchInfoParam;
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.model.result.ProductionOrderBatchInfoResult;
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.service.ProductionOrderBatchInfoService;
import cn.stylefeng.guns.modular.om.productionOrderRecords.service.ProductionOrderRecordsService;
import cn.stylefeng.guns.modular.sc.repairManageInfo.service.RepairManageInfoService;
import cn.stylefeng.guns.modular.sc.serialNumbersConf.service.SerialNumbersConfService;
import cn.stylefeng.guns.plcserver.opc.GlobalVariable;
import cn.stylefeng.guns.plcserver.opc.OPCElement;
import cn.stylefeng.guns.plcserver.tool.DateTool;
import cn.stylefeng.guns.plcserver.tool.LogUtil;
import com.kangaroohy.milo.model.ReadWriteEntity;
import com.kangaroohy.milo.runner.subscription.SubscriptionCallback;
import com.kangaroohy.milo.service.MiloService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@Component
public class BOP040BCallback implements SubscriptionCallback {
    public MiloService miloService;
    @Autowired
    public ProductionOrdeInfoService productionOrdeInfoService;
    @Autowired
    public PassingStationCollectionService passingStationCollectionService;
    @Autowired
    public ParamCollectionService paramCollectionService;
    @Autowired
    public CollectionParamConfService collectionParamConfService;
    @Autowired
    public SerialNumbersConfService serialNumbersConfService;
    @Autowired
    private EquipmentStatusService equipmentStatusService;
    @Autowired
    private EquipmentAlarmService equipmentAlarmService;
    @Autowired
    private MaterialTraceabilityService materialTraceabilityService;
    @Autowired
    private EquipmentInfoService equipmentInfoService;
    @Autowired
    private RepairManageInfoService repairManageInfoService;
    @Autowired
    private LocationInfoService locationInfoService;
    @Autowired
    private GreaseManageService greaseManageService;
    @Autowired
    private ProductionOrderRecordsService productionOrderRecordsService;
    @Autowired
    private ProductionOrderBatchInfoService productionOrderBatchInfoService;
    private static Logger logger;
    LogUtil logUtil = new LogUtil();
    static {
        logger = Logger.getLogger(BOP040BCallback.class);
    }
    private static Date IN_TIME = null;
    private static String S_ORDER_CODE = "";//工单编号
    private static String S_PRODUCT_CODE = "";//产品编号
    private static String S_PRODUCT_TYPE= "";//产品类型
    private static String S_SFC_CODE = "";//总成编码
    private static String PRODUCTION_LINE  = "BOP";//产线号
    private static String LOCATION_CODE  = "BOP040B";//工位号
    private static List list = null;
    public BOP040BCallback(MiloService miloService,
                           ProductionOrdeInfoService productionOrdeInfoService,
                           PassingStationCollectionService passingStationCollectionService,
                           ParamCollectionService paramCollectionService,
                           CollectionParamConfService collectionParamConfService,
                           SerialNumbersConfService serialNumbersConfService,
                           EquipmentStatusService equipmentStatusService,
                           EquipmentAlarmService equipmentAlarmService,
                           MaterialTraceabilityService materialTraceabilityService,
                           EquipmentInfoService equipmentInfoService,
                           RepairManageInfoService repairManageInfoService,
                           LocationInfoService locationInfoService,
                           GreaseManageService greaseManageService,
                           ProductionOrderRecordsService productionOrderRecordsService,
                           ProductionOrderBatchInfoService productionOrderBatchInfoService) {
        this.miloService = miloService;
        this.productionOrdeInfoService = productionOrdeInfoService;
        this.passingStationCollectionService = passingStationCollectionService;
        this.paramCollectionService = paramCollectionService;
        this.collectionParamConfService = collectionParamConfService;
        this.serialNumbersConfService = serialNumbersConfService;
        this.equipmentStatusService = equipmentStatusService;
        this.equipmentAlarmService = equipmentAlarmService;
        this.materialTraceabilityService = materialTraceabilityService;
        this.equipmentInfoService = equipmentInfoService;
        this.repairManageInfoService = repairManageInfoService;
        this.locationInfoService = locationInfoService;
        this.greaseManageService = greaseManageService;
        this.productionOrderRecordsService = productionOrderRecordsService;
        this.productionOrderBatchInfoService = productionOrderBatchInfoService;
    }
    @Override
    public void onSubscribe(String identifier, Object value) {
        String ecpStr = "";//异常记录标记
        try {
            //心跳
            if(null != value && identifier.equals(OPCElement.BOP040B_F_HEART_BEAT)){
                if( "false".equals(value.toString()))
                {
                    ReadWriteEntity entity = new ReadWriteEntity(OPCElement.BOP040B_F_HEART_BEAT,true);
                    miloService.writeToOpcUa(entity);
                }
            }
            //PLC进站
            else if(null != value && identifier.equals(OPCElement.BOP040B_J_PLC_START)){
                if("true".equals(value.toString())){
                    handleOrder();
                }
            }
            //PLC出站
            else if(null != value && identifier.equals(OPCElement.BOP040B_J_PLC_FINISH)){
                if("true".equals(value.toString())){
                    handleFinsh();
                    handleInfo();
                    handleMaterial();
                }
            }else{
                System.out.println("BOP040B值没有变");
            }
        } catch (Exception e) {
            ecpStr ="出现异常:" + logUtil.getTrace(e);
        }finally {
            if(!"".equals(ecpStr)){
                logger.info(ecpStr+"\r\n");
            }
        }
    }
    //PC读工单
    public void handleOrder() throws Exception {
        logger.info("handleOrder PC处理开始!");
        IN_TIME = DateTool.getLocalTimeForDate();
        List<String> lists = new ArrayList<>();
        lists.add(OPCElement.BOP040B_S_ORDER_CODE);
        lists.add(OPCElement.BOP040B_S_PRODUCT_CODE);
        lists.add(OPCElement.BOP040B_S_SFC_CODE);
        List<ReadWriteEntity> returnLists= miloService.readFromOpcUa(lists);
        returnLists.forEach(element->{
            switch(element.getIdentifier()){
                case OPCElement.BOP040B_S_ORDER_CODE:
                    S_ORDER_CODE = element.getValue().toString();
                    break;
                case OPCElement.BOP040B_S_PRODUCT_CODE:
                    S_PRODUCT_TYPE = element.getValue().toString();
                    S_PRODUCT_CODE = GlobalVariable.PRODUCT_CODE_MAP.get(S_PRODUCT_TYPE);
                    break;
                case OPCElement.BOP040B_S_SFC_CODE:
                    S_SFC_CODE = element.getValue().toString();
                    break;
                default:
                    break;
            }
        });
        ReadWriteEntity entity = new ReadWriteEntity(OPCElement.BOP040B_J_PC_WRITE_ORDER,true);
        miloService.writeToOpcUa(entity);
        logger.info("handleOrder PC处理完成!");
    }
    public void handleFinsh() throws Exception {
        logger.info("handleFinsh PC处理开始!");
        String S_PRODUCT_STATE_CODE = miloService.
                readFromOpcUa(OPCElement.BOP040B_S_PRODUCT_STATE_CODE)
                .getValue().toString();
        //处理过站信息
        PassingStationCollectionParam param = new PassingStationCollectionParam();
        param.setWorkOrderNo(S_ORDER_CODE);
        param.setProductCode(S_PRODUCT_CODE);
        param.setSfcCode(S_SFC_CODE);
        param.setProductionLine(PRODUCTION_LINE);
        param.setLocationCode(LOCATION_CODE);
        param.setInboundTime(IN_TIME);
        param.setOutboundTime(DateTool.getLocalTimeForDate());
        param.setOutRsSign(S_PRODUCT_STATE_CODE);//出站是否合格
        passingStationCollectionService.add(param);
        ReadWriteEntity entity = new ReadWriteEntity(OPCElement.BOP040B_J_PC_FINISH,true);
        miloService.writeToOpcUa(entity);//写PC完成
        logger.info("handleFinsh PC处理完成!");
    }
    public void handleMaterial() {
        //查询批次上料信息
        ProductionOrderBatchInfoParam productionOrderBatchInfoParam = new ProductionOrderBatchInfoParam();
        productionOrderBatchInfoParam.setWorkOrderNo(S_ORDER_CODE);
        productionOrderBatchInfoParam.setLocationCode(LOCATION_CODE);
        List<ProductionOrderBatchInfoResult> list = productionOrderBatchInfoService.findListBySpec(productionOrderBatchInfoParam);
        for(int i=0;i<list.size();i++){
            ProductionOrderBatchInfoResult productionOrderBatchInfoResult = list.get(i);
            int remainingQuantity =  productionOrderBatchInfoResult.getResidueQuantity();//剩余数量
            if(remainingQuantity>0 ){
                //新增物料追溯
                MaterialTraceabilityParam materialTraceabilityParam = new MaterialTraceabilityParam();
                materialTraceabilityParam.setWorkOrderNo(S_ORDER_CODE);
                materialTraceabilityParam.setProductCode(S_PRODUCT_CODE);
                materialTraceabilityParam.setProductNo(S_SFC_CODE);
                materialTraceabilityParam.setLineCode(PRODUCTION_LINE);
                materialTraceabilityParam.setLocationCode(LOCATION_CODE);
                materialTraceabilityParam.setAssemblyQty(1);
                materialTraceabilityParam.setAssemblyTime(DateTool.getLocalTimeForDate());
                materialTraceabilityParam.setMaterialCode(productionOrderBatchInfoResult.getMaterialCode());//物料编码
                materialTraceabilityParam.setMaterialBatchNo(productionOrderBatchInfoResult.getBatch());//物料批次
                materialTraceabilityService.add(materialTraceabilityParam);
                //更新剩余数量
                productionOrderBatchInfoParam.setId(productionOrderBatchInfoResult.getId());
                productionOrderBatchInfoParam.setResidueQuantity(remainingQuantity-1);//剩余数量
                productionOrderBatchInfoService.update(productionOrderBatchInfoParam);
            }
        }
    }
    //PC读参数信息
    public void handleInfo() throws Exception {
        logger.info("handleInfo START!");
        if(null == list){
            CollectionParamConfParam collectionParamConfParam = new CollectionParamConfParam();
            collectionParamConfParam.setLocationCode(LOCATION_CODE);
            list = collectionParamConfService.findListBySpec(collectionParamConfParam);
        }
        if(null != list && !list.isEmpty()) {
            for (int i = 0; i < list.size(); i++) {
                CollectionParamConfResult result = (CollectionParamConfResult) list.get(i);
                String value = miloService.
                        readFromOpcUa(result.getGatherAddress())
                        .getValue().toString();//读参数值
                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);
                paramCollectionParam.setParamLower(result.getParamLower());
                paramCollectionParam.setParamUpper(result.getParamUpper());
                paramCollectionParam.setParamStandard(result.getParamCentral());
                paramCollectionParam.setCollectionTime(DateTool.getLocalTimeForDate());
                paramCollectionParam.setUnit(result.getUnit());
                paramCollectionService.add(paramCollectionParam);
            }
        }
        logger.info("handleInfo END!");
    }
}
guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/BOP040Callback.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,282 @@
package cn.stylefeng.guns.plcserver.callback;
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.model.params.ParamCollectionParam;
import cn.stylefeng.guns.modular.cm.paramCollection.service.ParamCollectionService;
import cn.stylefeng.guns.modular.cm.passingStationCollection.model.params.PassingStationCollectionParam;
import cn.stylefeng.guns.modular.cm.passingStationCollection.service.PassingStationCollectionService;
import cn.stylefeng.guns.modular.dq.materialTraceability.model.params.MaterialTraceabilityParam;
import cn.stylefeng.guns.modular.dq.materialTraceability.service.MaterialTraceabilityService;
import cn.stylefeng.guns.modular.em.equipmentAlarm.service.EquipmentAlarmService;
import cn.stylefeng.guns.modular.em.equipmentStatus.service.EquipmentStatusService;
import cn.stylefeng.guns.modular.gm.greaseManage.service.GreaseManageService;
import cn.stylefeng.guns.modular.om.productionOrdeInfo.service.ProductionOrdeInfoService;
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.model.params.ProductionOrderBatchInfoParam;
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.model.result.ProductionOrderBatchInfoResult;
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.service.ProductionOrderBatchInfoService;
import cn.stylefeng.guns.modular.om.productionOrderRecords.service.ProductionOrderRecordsService;
import cn.stylefeng.guns.modular.sc.repairManageInfo.service.RepairManageInfoService;
import cn.stylefeng.guns.modular.sc.serialNumbersConf.service.SerialNumbersConfService;
import cn.stylefeng.guns.plcserver.opc.GlobalVariable;
import cn.stylefeng.guns.plcserver.opc.OPCElement;
import cn.stylefeng.guns.plcserver.tool.DateTool;
import cn.stylefeng.guns.plcserver.tool.LogUtil;
import com.kangaroohy.milo.model.ReadWriteEntity;
import com.kangaroohy.milo.runner.subscription.SubscriptionCallback;
import com.kangaroohy.milo.service.MiloService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@Component
public class BOP040Callback implements SubscriptionCallback {
    public MiloService miloService;
    @Autowired
    public ProductionOrdeInfoService productionOrdeInfoService;
    @Autowired
    public PassingStationCollectionService passingStationCollectionService;
    @Autowired
    public ParamCollectionService paramCollectionService;
    @Autowired
    public CollectionParamConfService collectionParamConfService;
    @Autowired
    public SerialNumbersConfService serialNumbersConfService;
    @Autowired
    private EquipmentStatusService equipmentStatusService;
    @Autowired
    private EquipmentAlarmService equipmentAlarmService;
    @Autowired
    private MaterialTraceabilityService materialTraceabilityService;
    @Autowired
    private EquipmentInfoService equipmentInfoService;
    @Autowired
    private RepairManageInfoService repairManageInfoService;
    @Autowired
    private LocationInfoService locationInfoService;
    @Autowired
    private GreaseManageService greaseManageService;
    @Autowired
    private ProductionOrderRecordsService productionOrderRecordsService;
    @Autowired
    private ProductionOrderBatchInfoService productionOrderBatchInfoService;
    private static Logger logger;
    LogUtil logUtil = new LogUtil();
    static {
        logger = Logger.getLogger(BOP040Callback.class);
    }
    private static Date IN_TIME = null;
    private static String S_ORDER_CODE = "";//工单编号
    private static String S_PRODUCT_CODE = "";//产品编号
    private static String S_PRODUCT_TYPE= "";//产品类型
    private static String S_SFC_CODE = "";//总成编码
    private static String PRODUCTION_LINE  = "BOP";//产线号
    private static String LOCATION_CODE  = "BOP040";//工位号
    private static List list = null;
    public BOP040Callback(MiloService miloService,
                          ProductionOrdeInfoService productionOrdeInfoService,
                          PassingStationCollectionService passingStationCollectionService,
                          ParamCollectionService paramCollectionService,
                          CollectionParamConfService collectionParamConfService,
                          SerialNumbersConfService serialNumbersConfService,
                          EquipmentStatusService equipmentStatusService,
                          EquipmentAlarmService equipmentAlarmService,
                          MaterialTraceabilityService materialTraceabilityService,
                          EquipmentInfoService equipmentInfoService,
                          RepairManageInfoService repairManageInfoService,
                          LocationInfoService locationInfoService,
                          GreaseManageService greaseManageService,
                          ProductionOrderRecordsService productionOrderRecordsService,
                          ProductionOrderBatchInfoService productionOrderBatchInfoService) {
        this.miloService = miloService;
        this.productionOrdeInfoService = productionOrdeInfoService;
        this.passingStationCollectionService = passingStationCollectionService;
        this.paramCollectionService = paramCollectionService;
        this.collectionParamConfService = collectionParamConfService;
        this.serialNumbersConfService = serialNumbersConfService;
        this.equipmentStatusService = equipmentStatusService;
        this.equipmentAlarmService = equipmentAlarmService;
        this.materialTraceabilityService = materialTraceabilityService;
        this.equipmentInfoService = equipmentInfoService;
        this.repairManageInfoService = repairManageInfoService;
        this.locationInfoService = locationInfoService;
        this.greaseManageService = greaseManageService;
        this.productionOrderRecordsService = productionOrderRecordsService;
        this.productionOrderBatchInfoService = productionOrderBatchInfoService;
    }
    @Override
    public void onSubscribe(String identifier, Object value) {
        String ecpStr = "";//异常记录标记
        try {
            //心跳
            if(null != value && identifier.equals(OPCElement.BOP040_F_HEART_BEAT)){
                if( "false".equals(value.toString()))
                {
                    ReadWriteEntity entity = new ReadWriteEntity(OPCElement.BOP040_F_HEART_BEAT,true);
                    miloService.writeToOpcUa(entity);
                }
            }
            //PLC进站
            else if(null != value && identifier.equals(OPCElement.BOP040_J_PLC_START)){
                if("true".equals(value.toString())){
                    handleOrder();
                }
            }
            //PLC出站
            else if(null != value && identifier.equals(OPCElement.BOP040_J_PLC_FINISH)){
                if("true".equals(value.toString())){
                    handleFinsh();
                    handleInfo();
                    handleMaterial();
                }
            }else{
                System.out.println("BOP040值没有变");
            }
        } catch (Exception e) {
            ecpStr ="出现异常:" + logUtil.getTrace(e);
        }finally {
            if(!"".equals(ecpStr)){
                logger.info(ecpStr+"\r\n");
            }
        }
    }
    //PC读工单
    public void handleOrder() throws Exception {
        logger.info("handleOrder PC处理开始!");
        IN_TIME = DateTool.getLocalTimeForDate();
        List<String> lists = new ArrayList<>();
        lists.add(OPCElement.BOP040_S_ORDER_CODE);
        lists.add(OPCElement.BOP040_S_PRODUCT_CODE);
        lists.add(OPCElement.BOP040_S_SFC_CODE);
        List<ReadWriteEntity> returnLists= miloService.readFromOpcUa(lists);
        returnLists.forEach(element->{
            switch(element.getIdentifier()){
                case OPCElement.BOP040_S_ORDER_CODE:
                    S_ORDER_CODE = element.getValue().toString();
                    break;
                case OPCElement.BOP040_S_PRODUCT_CODE:
                    S_PRODUCT_TYPE = element.getValue().toString();
                    S_PRODUCT_CODE = GlobalVariable.PRODUCT_CODE_MAP.get(S_PRODUCT_TYPE);
                    break;
                case OPCElement.BOP040_S_SFC_CODE:
                    S_SFC_CODE = element.getValue().toString();
                    break;
                default:
                    break;
            }
        });
        ReadWriteEntity entity = new ReadWriteEntity(OPCElement.BOP040_J_PC_WRITE_ORDER,true);
        miloService.writeToOpcUa(entity);
        logger.info("handleOrder PC处理完成!");
    }
    public void handleFinsh() throws Exception {
        logger.info("handleFinsh PC处理开始!");
        String S_PRODUCT_STATE_CODE = miloService.
                readFromOpcUa(OPCElement.BOP040_S_PRODUCT_STATE_CODE)
                .getValue().toString();
        //处理过站信息
        PassingStationCollectionParam param = new PassingStationCollectionParam();
        param.setWorkOrderNo(S_ORDER_CODE);
        param.setProductCode(S_PRODUCT_CODE);
        param.setSfcCode(S_SFC_CODE);
        param.setProductionLine(PRODUCTION_LINE);
        param.setLocationCode(LOCATION_CODE);
        param.setInboundTime(IN_TIME);
        param.setOutboundTime(DateTool.getLocalTimeForDate());
        param.setOutRsSign(S_PRODUCT_STATE_CODE);//出站是否合格
        passingStationCollectionService.add(param);
        ReadWriteEntity entity = new ReadWriteEntity(OPCElement.BOP040_J_PC_FINISH,true);
        miloService.writeToOpcUa(entity);//写PC完成
        logger.info("handleFinsh PC处理完成!");
    }
    public void handleMaterial() {
        //查询批次上料信息
        ProductionOrderBatchInfoParam productionOrderBatchInfoParam = new ProductionOrderBatchInfoParam();
        productionOrderBatchInfoParam.setWorkOrderNo(S_ORDER_CODE);
        productionOrderBatchInfoParam.setLocationCode(LOCATION_CODE);
        List<ProductionOrderBatchInfoResult> list = productionOrderBatchInfoService.findListBySpec(productionOrderBatchInfoParam);
        for(int i=0;i<list.size();i++){
            ProductionOrderBatchInfoResult productionOrderBatchInfoResult = list.get(i);
            int remainingQuantity =  productionOrderBatchInfoResult.getResidueQuantity();//剩余数量
            if(remainingQuantity>0 ){
                //新增物料追溯
                MaterialTraceabilityParam materialTraceabilityParam = new MaterialTraceabilityParam();
                materialTraceabilityParam.setWorkOrderNo(S_ORDER_CODE);
                materialTraceabilityParam.setProductCode(S_PRODUCT_CODE);
                materialTraceabilityParam.setProductNo(S_SFC_CODE);
                materialTraceabilityParam.setLineCode(PRODUCTION_LINE);
                materialTraceabilityParam.setLocationCode(LOCATION_CODE);
                materialTraceabilityParam.setAssemblyQty(1);
                materialTraceabilityParam.setAssemblyTime(DateTool.getLocalTimeForDate());
                materialTraceabilityParam.setMaterialCode(productionOrderBatchInfoResult.getMaterialCode());//物料编码
                materialTraceabilityParam.setMaterialBatchNo(productionOrderBatchInfoResult.getBatch());//物料批次
                materialTraceabilityService.add(materialTraceabilityParam);
                //更新剩余数量
                productionOrderBatchInfoParam.setId(productionOrderBatchInfoResult.getId());
                productionOrderBatchInfoParam.setResidueQuantity(remainingQuantity-1);//剩余数量
                productionOrderBatchInfoService.update(productionOrderBatchInfoParam);
            }
        }
    }
    //PC读参数信息
    public void handleInfo() throws Exception {
        logger.info("handleInfo START!");
        if(null == list){
            CollectionParamConfParam collectionParamConfParam = new CollectionParamConfParam();
            collectionParamConfParam.setLocationCode(LOCATION_CODE);
            list = collectionParamConfService.findListBySpec(collectionParamConfParam);
        }
        if(null != list && !list.isEmpty()) {
            for (int i = 0; i < list.size(); i++) {
                CollectionParamConfResult result = (CollectionParamConfResult) list.get(i);
                String value = miloService.
                        readFromOpcUa(result.getGatherAddress())
                        .getValue().toString();//读参数值
                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);
                paramCollectionParam.setParamLower(result.getParamLower());
                paramCollectionParam.setParamUpper(result.getParamUpper());
                paramCollectionParam.setParamStandard(result.getParamCentral());
                paramCollectionParam.setCollectionTime(DateTool.getLocalTimeForDate());
                paramCollectionParam.setUnit(result.getUnit());
                paramCollectionService.add(paramCollectionParam);
            }
        }
        logger.info("handleInfo END!");
    }
}
guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/COP010Callback.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,351 @@
package cn.stylefeng.guns.plcserver.callback;
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.model.params.LocationInfoParam;
import cn.stylefeng.guns.modular.bs.locationInfo.model.result.LocationInfoResult;
import cn.stylefeng.guns.modular.bs.locationInfo.service.LocationInfoService;
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;
import cn.stylefeng.guns.modular.cm.passingStationCollection.service.PassingStationCollectionService;
import cn.stylefeng.guns.modular.dq.materialTraceability.model.params.MaterialTraceabilityParam;
import cn.stylefeng.guns.modular.dq.materialTraceability.service.MaterialTraceabilityService;
import cn.stylefeng.guns.modular.em.equipmentAlarm.service.EquipmentAlarmService;
import cn.stylefeng.guns.modular.em.equipmentStatus.service.EquipmentStatusService;
import cn.stylefeng.guns.modular.gm.greaseManage.service.GreaseManageService;
import cn.stylefeng.guns.modular.om.productionOrdeInfo.model.params.ProductionOrdeInfoParam;
import cn.stylefeng.guns.modular.om.productionOrdeInfo.model.result.ProductionOrdeInfoResult;
import cn.stylefeng.guns.modular.om.productionOrdeInfo.service.ProductionOrdeInfoService;
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.model.params.ProductionOrderBatchInfoParam;
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.model.result.ProductionOrderBatchInfoResult;
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.service.ProductionOrderBatchInfoService;
import cn.stylefeng.guns.modular.om.productionOrderRecords.model.params.ProductionOrderRecordsParam;
import cn.stylefeng.guns.modular.om.productionOrderRecords.model.result.ProductionOrderRecordsResult;
import cn.stylefeng.guns.modular.om.productionOrderRecords.service.ProductionOrderRecordsService;
import cn.stylefeng.guns.modular.sc.repairManageInfo.model.params.RepairManageInfoParam;
import cn.stylefeng.guns.modular.sc.repairManageInfo.model.result.RepairManageInfoResult;
import cn.stylefeng.guns.modular.sc.repairManageInfo.service.RepairManageInfoService;
import cn.stylefeng.guns.modular.sc.serialNumbersConf.model.params.SerialNumbersConfParam;
import cn.stylefeng.guns.modular.sc.serialNumbersConf.model.result.SerialNumbersConfResult;
import cn.stylefeng.guns.modular.sc.serialNumbersConf.service.SerialNumbersConfService;
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.opc.unit.SFCCodeTool;
import cn.stylefeng.guns.plcserver.tool.DateTool;
import cn.stylefeng.guns.plcserver.tool.LogUtil;
import com.kangaroohy.milo.model.ReadWriteEntity;
import com.kangaroohy.milo.runner.subscription.SubscriptionCallback;
import com.kangaroohy.milo.service.MiloService;
import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.*;
@Component
public class COP010Callback implements SubscriptionCallback {
    public MiloService miloService;
    @Autowired
    public ProductionOrdeInfoService productionOrdeInfoService;
    @Autowired
    public PassingStationCollectionService passingStationCollectionService;
    @Autowired
    public ParamCollectionService paramCollectionService;
    @Autowired
    public CollectionParamConfService collectionParamConfService;
    @Autowired
    public SerialNumbersConfService serialNumbersConfService;
    @Autowired
    private EquipmentStatusService equipmentStatusService;
    @Autowired
    private EquipmentAlarmService equipmentAlarmService;
    @Autowired
    private MaterialTraceabilityService materialTraceabilityService;
    @Autowired
    private EquipmentInfoService equipmentInfoService;
    @Autowired
    private RepairManageInfoService repairManageInfoService;
    @Autowired
    private LocationInfoService locationInfoService;
    @Autowired
    private GreaseManageService greaseManageService;
    @Autowired
    private ProductionOrderRecordsService productionOrderRecordsService;
    @Autowired
    private ProductionOrderBatchInfoService productionOrderBatchInfoService;
    private static Logger logger;
    LogUtil logUtil = new LogUtil();
    static {
        logger = Logger.getLogger(COP010Callback.class);
    }
    private static Date IN_TIME = null;
    private static String S_ORDER_CODE = "";//工单编号
    private static String S_PRODUCT_CODE = "";//产品编号
    private static String S_PRODUCT_TYPE= "";//产品类型
    private static String S_SFC_CODE = "";//总成编码
    private static String PRODUCTION_LINE  = "COP";//产线号
    private static String LOCATION_CODE  = "COP010";//工位号
    private static List list = null;
    public COP010Callback(MiloService miloService,
                          ProductionOrdeInfoService productionOrdeInfoService,
                          PassingStationCollectionService passingStationCollectionService,
                          ParamCollectionService paramCollectionService,
                          CollectionParamConfService collectionParamConfService,
                          SerialNumbersConfService serialNumbersConfService,
                          EquipmentStatusService equipmentStatusService,
                          EquipmentAlarmService equipmentAlarmService,
                          MaterialTraceabilityService materialTraceabilityService,
                          EquipmentInfoService equipmentInfoService,
                          RepairManageInfoService repairManageInfoService,
                          LocationInfoService locationInfoService,
                          GreaseManageService greaseManageService,
                          ProductionOrderRecordsService productionOrderRecordsService,
                          ProductionOrderBatchInfoService productionOrderBatchInfoService) {
        this.miloService = miloService;
        this.productionOrdeInfoService = productionOrdeInfoService;
        this.passingStationCollectionService = passingStationCollectionService;
        this.paramCollectionService = paramCollectionService;
        this.collectionParamConfService = collectionParamConfService;
        this.serialNumbersConfService = serialNumbersConfService;
        this.equipmentStatusService = equipmentStatusService;
        this.equipmentAlarmService = equipmentAlarmService;
        this.materialTraceabilityService = materialTraceabilityService;
        this.equipmentInfoService = equipmentInfoService;
        this.repairManageInfoService = repairManageInfoService;
        this.locationInfoService = locationInfoService;
        this.greaseManageService = greaseManageService;
        this.productionOrderRecordsService = productionOrderRecordsService;
        this.productionOrderBatchInfoService = productionOrderBatchInfoService;
    }
    @Override
    public void onSubscribe(String identifier, Object value) {
        String ecpStr = "";//异常记录标记
        try {
            //心跳
            if(null != value && identifier.equals(OPCElement.COP010_F_HEART_BEAT)){
                if( "false".equals(value.toString()))
                {
                    ReadWriteEntity entity = new ReadWriteEntity(OPCElement.COP010_F_HEART_BEAT,true);
                    miloService.writeToOpcUa(entity);
                }
            }
            //PLC进站
            else if(null != value && identifier.equals(OPCElement.COP010_J_PLC_START)){
                if("true".equals(value.toString())){
                    String isRepair = miloService.
                            readFromOpcUa(OPCElement.COP010_P_REPAIR)
                            .getValue().toString();//是否返修
                    if(isRepair.equals("true")){
                        handleRepair();
                    }else{
                        handleOrder();
                    }
                }
            }
            //PLC出站
            else if(null != value && identifier.equals(OPCElement.COP010_J_PLC_FINISH)){
                if("true".equals(value.toString())){
                    handleFinsh();
                    handleInfo();
                    handleMaterial();
                }
            }else{
                System.out.println("COP010值没有变");
            }
        } catch (Exception e) {
            ecpStr ="出现异常:" + logUtil.getTrace(e);
        }finally {
            if(!"".equals(ecpStr)){
                logger.info(ecpStr+"\r\n");
            }
            System.out.println("finally" +ecpStr);
        }
    }
    public void handleOrder() throws Exception{
        IN_TIME = DateTool.getLocalTimeForDate();
        ProductionOrdeInfoParam param = new ProductionOrdeInfoParam();
        param.setProductionLine("");//产线
        param.setOrderStatus("3");//工单状态
        List<ProductionOrdeInfoResult> list = productionOrdeInfoService.findListBySpec(param);
        if(list.size()>0) {
            ProductionOrdeInfoResult result = list.get(0);
            S_ORDER_CODE = result.getWorkOrderNo();
            S_PRODUCT_CODE = result.getMaterialCode();
            S_PRODUCT_TYPE = GlobalVariable.PRODUCT_TYPE_MAP.get(S_PRODUCT_CODE);
            //自动生成唯一码
            Random random = new Random(System.currentTimeMillis());
            S_SFC_CODE = "COP"+random.nextLong();
            List<ReadWriteEntity> lists = new ArrayList<>();
            lists.add(new ReadWriteEntity(OPCElement.COP010_S_ORDER_CODE,S_ORDER_CODE));
            lists.add(new ReadWriteEntity(OPCElement.COP010_S_PRODUCT_CODE,S_PRODUCT_TYPE));
            lists.add(new ReadWriteEntity(OPCElement.COP010_S_SFC_CODE,S_SFC_CODE));
            lists.add(new ReadWriteEntity(OPCElement.COP010_S_NUMBER,result.getPlanQty().toString()));
            lists.add(new ReadWriteEntity(OPCElement.COP010_J_PC_WRITE_ORDER,true));
            miloService.writeToOpcUa(lists);
            logger.info("COP010工位,handleOrder PC处理完成!2");
        }else{
            logger.info("COP010工位没有可执行的工单,请联系工单管理员下发该产线的工单!");
        }
    }
    public void handleFinsh() throws Exception {
        logger.info("handleFinsh PC处理开始!");
        String S_PRODUCT_STATE_CODE = miloService.
                readFromOpcUa(OPCElement.COP010_S_PRODUCT_STATE_CODE)
                .getValue().toString();
        //处理过站信息
        PassingStationCollectionParam param = new PassingStationCollectionParam();
        param.setWorkOrderNo(S_ORDER_CODE);
        param.setProductCode(S_PRODUCT_CODE);
        param.setSfcCode(S_SFC_CODE);
        param.setProductionLine(PRODUCTION_LINE);
        param.setLocationCode(LOCATION_CODE);
        param.setInboundTime(IN_TIME);
        param.setOutboundTime(DateTool.getLocalTimeForDate());
        param.setOutRsSign(S_PRODUCT_STATE_CODE);//出站是否合格
        passingStationCollectionService.add(param);
        ReadWriteEntity entity = new ReadWriteEntity(OPCElement.COP010_J_PC_FINISH,true);
        miloService.writeToOpcUa(entity);//写PC完成
        logger.info("handleFinsh PC处理完成!");
    }
    public void handleMaterial() {
        //查询批次上料信息
        ProductionOrderBatchInfoParam productionOrderBatchInfoParam = new ProductionOrderBatchInfoParam();
        productionOrderBatchInfoParam.setWorkOrderNo(S_ORDER_CODE);
        productionOrderBatchInfoParam.setLocationCode(LOCATION_CODE);
        List<ProductionOrderBatchInfoResult> list = productionOrderBatchInfoService.findListBySpec(productionOrderBatchInfoParam);
        for(int i=0;i<list.size();i++){
            ProductionOrderBatchInfoResult productionOrderBatchInfoResult = list.get(i);
            int remainingQuantity =  productionOrderBatchInfoResult.getResidueQuantity();//剩余数量
            if(remainingQuantity>0 ){
                //新增物料追溯
                MaterialTraceabilityParam materialTraceabilityParam = new MaterialTraceabilityParam();
                materialTraceabilityParam.setWorkOrderNo(S_ORDER_CODE);
                materialTraceabilityParam.setProductCode(S_PRODUCT_CODE);
                materialTraceabilityParam.setProductNo(S_SFC_CODE);
                materialTraceabilityParam.setLineCode(PRODUCTION_LINE);
                materialTraceabilityParam.setLocationCode(LOCATION_CODE);
                materialTraceabilityParam.setAssemblyQty(1);
                materialTraceabilityParam.setAssemblyTime(DateTool.getLocalTimeForDate());
                materialTraceabilityParam.setMaterialCode(productionOrderBatchInfoResult.getMaterialCode());//物料编码
                materialTraceabilityParam.setMaterialBatchNo(productionOrderBatchInfoResult.getBatch());//物料批次
                materialTraceabilityService.add(materialTraceabilityParam);
                //更新剩余数量
                productionOrderBatchInfoParam.setId(productionOrderBatchInfoResult.getId());
                productionOrderBatchInfoParam.setResidueQuantity(remainingQuantity-1);//剩余数量
                productionOrderBatchInfoService.update(productionOrderBatchInfoParam);
            }
        }
    }
    //PC读参数信息
    public void handleInfo() throws Exception {
        logger.info("handleInfo START!");
        if(null == list){
            CollectionParamConfParam collectionParamConfParam = new CollectionParamConfParam();
            collectionParamConfParam.setLocationCode(LOCATION_CODE);
            list = collectionParamConfService.findListBySpec(collectionParamConfParam);
        }
        if(null != list && !list.isEmpty()) {
            for (int i = 0; i < list.size(); i++) {
                CollectionParamConfResult result = (CollectionParamConfResult) list.get(i);
                String value = miloService.
                        readFromOpcUa(result.getGatherAddress())
                        .getValue().toString();//读参数值
                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);
                paramCollectionParam.setParamLower(result.getParamLower());
                paramCollectionParam.setParamUpper(result.getParamUpper());
                paramCollectionParam.setParamStandard(result.getParamCentral());
                paramCollectionParam.setCollectionTime(DateTool.getLocalTimeForDate());
                paramCollectionParam.setUnit(result.getUnit());
                paramCollectionService.add(paramCollectionParam);
            }
        }
        logger.info("handleInfo END!");
    }
    public void handleRepair() throws Exception{
        RepairManageInfoParam repairManageInfoParam = new RepairManageInfoParam();
        repairManageInfoParam.setLocationCode(LOCATION_CODE);
        repairManageInfoParam.setManageType("2");
        repairManageInfoParam.setUpPlc("0");
        List<RepairManageInfoResult> list = repairManageInfoService.findListBySpec(repairManageInfoParam);
        if(list.size()>0) {
            RepairManageInfoResult result = list.get(0);
            //自动生成唯一码
            Random random = new Random(System.currentTimeMillis());
            S_SFC_CODE = "COP" + random.nextLong();
            S_ORDER_CODE = result.getWorkOrderNo();
            S_PRODUCT_CODE = result.getProductCode();
            S_PRODUCT_TYPE = GlobalVariable.PRODUCT_TYPE_MAP.get(S_PRODUCT_CODE);
            String  repairLocation = result.getPoorLocationCode();//
            //根据工位编码查询工位表中配置的返修工位号
            LocationInfoParam param = new LocationInfoParam();
            param.setLocationCode(repairLocation);
            List<LocationInfoResult> results = locationInfoService.findListBySpec(param);
            if(results.size()>0) {
                LocationInfoResult r = results.get(0);
                String repairLocationNo = r.getSpareField2();
                if(null != repairLocationNo && "" != repairLocationNo){
                    List<ReadWriteEntity> lists = new ArrayList<>();
                    lists.add(new ReadWriteEntity(OPCElement.COP010_S_ORDER_CODE,S_ORDER_CODE));
                    lists.add(new ReadWriteEntity(OPCElement.COP010_S_PRODUCT_CODE,S_PRODUCT_TYPE));
                    lists.add(new ReadWriteEntity(OPCElement.COP010_S_SFC_CODE,S_SFC_CODE));
                    lists.add(new ReadWriteEntity(OPCElement.COP010_P_REPAIR_LOCATION,repairLocationNo));
                    lists.add(new ReadWriteEntity(OPCElement.COP010_J_PC_WRITE_ORDER,true));
                    miloService.writeToOpcUa(lists);
                    //更新为已经返修上线
                    Long id = result.getId();
                    repairManageInfoParam.setId(id);
                    repairManageInfoParam.setUpPlc("1");
                    repairManageInfoService.update(repairManageInfoParam);
                }else{
                    logger.info("COP010工位,handleRepair è¯·æŸ¥è¯¢"+repairLocation+"工位是否配置返修工位号!");
                }
            }else{
                logger.info("COP010工位,handleRepair æ— æ³•æŸ¥è¯¢åˆ°"+repairLocation+"工位!");
            }
        }
    }
}
guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/COP020Callback.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,284 @@
package cn.stylefeng.guns.plcserver.callback;
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.model.params.ParamCollectionParam;
import cn.stylefeng.guns.modular.cm.paramCollection.service.ParamCollectionService;
import cn.stylefeng.guns.modular.cm.passingStationCollection.model.params.PassingStationCollectionParam;
import cn.stylefeng.guns.modular.cm.passingStationCollection.service.PassingStationCollectionService;
import cn.stylefeng.guns.modular.dq.materialTraceability.model.params.MaterialTraceabilityParam;
import cn.stylefeng.guns.modular.dq.materialTraceability.service.MaterialTraceabilityService;
import cn.stylefeng.guns.modular.em.equipmentAlarm.service.EquipmentAlarmService;
import cn.stylefeng.guns.modular.em.equipmentStatus.service.EquipmentStatusService;
import cn.stylefeng.guns.modular.gm.greaseManage.service.GreaseManageService;
import cn.stylefeng.guns.modular.om.productionOrdeInfo.service.ProductionOrdeInfoService;
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.model.params.ProductionOrderBatchInfoParam;
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.model.result.ProductionOrderBatchInfoResult;
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.service.ProductionOrderBatchInfoService;
import cn.stylefeng.guns.modular.om.productionOrderRecords.model.params.ProductionOrderRecordsParam;
import cn.stylefeng.guns.modular.om.productionOrderRecords.model.result.ProductionOrderRecordsResult;
import cn.stylefeng.guns.modular.om.productionOrderRecords.service.ProductionOrderRecordsService;
import cn.stylefeng.guns.modular.sc.repairManageInfo.service.RepairManageInfoService;
import cn.stylefeng.guns.modular.sc.serialNumbersConf.service.SerialNumbersConfService;
import cn.stylefeng.guns.plcserver.opc.GlobalVariable;
import cn.stylefeng.guns.plcserver.opc.OPCElement;
import cn.stylefeng.guns.plcserver.tool.DateTool;
import cn.stylefeng.guns.plcserver.tool.LogUtil;
import com.kangaroohy.milo.model.ReadWriteEntity;
import com.kangaroohy.milo.runner.subscription.SubscriptionCallback;
import com.kangaroohy.milo.service.MiloService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@Component
public class COP020Callback implements SubscriptionCallback {
    public MiloService miloService;
    @Autowired
    public ProductionOrdeInfoService productionOrdeInfoService;
    @Autowired
    public PassingStationCollectionService passingStationCollectionService;
    @Autowired
    public ParamCollectionService paramCollectionService;
    @Autowired
    public CollectionParamConfService collectionParamConfService;
    @Autowired
    public SerialNumbersConfService serialNumbersConfService;
    @Autowired
    private EquipmentStatusService equipmentStatusService;
    @Autowired
    private EquipmentAlarmService equipmentAlarmService;
    @Autowired
    private MaterialTraceabilityService materialTraceabilityService;
    @Autowired
    private EquipmentInfoService equipmentInfoService;
    @Autowired
    private RepairManageInfoService repairManageInfoService;
    @Autowired
    private LocationInfoService locationInfoService;
    @Autowired
    private GreaseManageService greaseManageService;
    @Autowired
    private ProductionOrderRecordsService productionOrderRecordsService;
    @Autowired
    private ProductionOrderBatchInfoService productionOrderBatchInfoService;
    private static Logger logger;
    LogUtil logUtil = new LogUtil();
    static {
        logger = Logger.getLogger(COP020Callback.class);
    }
    private static Date IN_TIME = null;
    private static String S_ORDER_CODE = "";//工单编号
    private static String S_PRODUCT_CODE = "";//产品编号
    private static String S_PRODUCT_TYPE= "";//产品类型
    private static String S_SFC_CODE = "";//总成编码
    private static String PRODUCTION_LINE  = "COP";//产线号
    private static String LOCATION_CODE  = "COP020";//工位号
    private static List list = null;
    public COP020Callback(MiloService miloService,
                          ProductionOrdeInfoService productionOrdeInfoService,
                          PassingStationCollectionService passingStationCollectionService,
                          ParamCollectionService paramCollectionService,
                          CollectionParamConfService collectionParamConfService,
                          SerialNumbersConfService serialNumbersConfService,
                          EquipmentStatusService equipmentStatusService,
                          EquipmentAlarmService equipmentAlarmService,
                          MaterialTraceabilityService materialTraceabilityService,
                          EquipmentInfoService equipmentInfoService,
                          RepairManageInfoService repairManageInfoService,
                          LocationInfoService locationInfoService,
                          GreaseManageService greaseManageService,
                          ProductionOrderRecordsService productionOrderRecordsService,
                          ProductionOrderBatchInfoService productionOrderBatchInfoService) {
        this.miloService = miloService;
        this.productionOrdeInfoService = productionOrdeInfoService;
        this.passingStationCollectionService = passingStationCollectionService;
        this.paramCollectionService = paramCollectionService;
        this.collectionParamConfService = collectionParamConfService;
        this.serialNumbersConfService = serialNumbersConfService;
        this.equipmentStatusService = equipmentStatusService;
        this.equipmentAlarmService = equipmentAlarmService;
        this.materialTraceabilityService = materialTraceabilityService;
        this.equipmentInfoService = equipmentInfoService;
        this.repairManageInfoService = repairManageInfoService;
        this.locationInfoService = locationInfoService;
        this.greaseManageService = greaseManageService;
        this.productionOrderRecordsService = productionOrderRecordsService;
        this.productionOrderBatchInfoService = productionOrderBatchInfoService;
    }
    @Override
    public void onSubscribe(String identifier, Object value) {
        String ecpStr = "";//异常记录标记
        try {
            //心跳
            if(null != value && identifier.equals(OPCElement.COP020_F_HEART_BEAT)){
                if( "false".equals(value.toString()))
                {
                    ReadWriteEntity entity = new ReadWriteEntity(OPCElement.COP020_F_HEART_BEAT,true);
                    miloService.writeToOpcUa(entity);
                }
            }
            //PLC进站
            else if(null != value && identifier.equals(OPCElement.COP020_J_PLC_START)){
                if("true".equals(value.toString())){
                    handleOrder();
                }
            }
            //PLC出站
            else if(null != value && identifier.equals(OPCElement.COP020_J_PLC_FINISH)){
                if("true".equals(value.toString())){
                    handleFinsh();
                    handleInfo();
                    handleMaterial();
                }
            }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 {
        logger.info("handleOrder PC处理开始!");
        IN_TIME = DateTool.getLocalTimeForDate();
        List<String> lists = new ArrayList<>();
        lists.add(OPCElement.COP020_S_ORDER_CODE);
        lists.add(OPCElement.COP020_S_PRODUCT_CODE);
        lists.add(OPCElement.COP020_S_SFC_CODE);
        List<ReadWriteEntity> returnLists= miloService.readFromOpcUa(lists);
        returnLists.forEach(element->{
            switch(element.getIdentifier()){
                case OPCElement.COP020_S_ORDER_CODE:
                    S_ORDER_CODE = element.getValue().toString();
                    break;
                case OPCElement.COP020_S_PRODUCT_CODE:
                    S_PRODUCT_TYPE = element.getValue().toString();
                    S_PRODUCT_CODE = GlobalVariable.PRODUCT_CODE_MAP.get(S_PRODUCT_TYPE);
                    break;
                case OPCElement.COP020_S_SFC_CODE:
                    S_SFC_CODE = element.getValue().toString();
                    break;
                default:
                    break;
            }
        });
        ReadWriteEntity entity = new ReadWriteEntity(OPCElement.COP020_J_PC_WRITE_ORDER,true);
        miloService.writeToOpcUa(entity);
        logger.info("handleOrder PC处理完成!");
    }
    public void handleFinsh() throws Exception {
        logger.info("handleFinsh PC处理开始!");
        String S_PRODUCT_STATE_CODE = miloService.
                readFromOpcUa(OPCElement.COP020_S_PRODUCT_STATE_CODE)
                .getValue().toString();
        //处理过站信息
        PassingStationCollectionParam param = new PassingStationCollectionParam();
        param.setWorkOrderNo(S_ORDER_CODE);
        param.setProductCode(S_PRODUCT_CODE);
        param.setSfcCode(S_SFC_CODE);
        param.setProductionLine(PRODUCTION_LINE);
        param.setLocationCode(LOCATION_CODE);
        param.setInboundTime(IN_TIME);
        param.setOutboundTime(DateTool.getLocalTimeForDate());
        param.setOutRsSign(S_PRODUCT_STATE_CODE);//出站是否合格
        passingStationCollectionService.add(param);
        ReadWriteEntity entity = new ReadWriteEntity(OPCElement.COP020_J_PC_FINISH,true);
        miloService.writeToOpcUa(entity);//写PC完成
        logger.info("handleFinsh PC处理完成!");
    }
    public void handleMaterial() {
        //查询批次上料信息
        ProductionOrderBatchInfoParam productionOrderBatchInfoParam = new ProductionOrderBatchInfoParam();
        productionOrderBatchInfoParam.setWorkOrderNo(S_ORDER_CODE);
        productionOrderBatchInfoParam.setLocationCode(LOCATION_CODE);
        List<ProductionOrderBatchInfoResult> list = productionOrderBatchInfoService.findListBySpec(productionOrderBatchInfoParam);
        for(int i=0;i<list.size();i++){
            ProductionOrderBatchInfoResult productionOrderBatchInfoResult = list.get(i);
            int remainingQuantity =  productionOrderBatchInfoResult.getResidueQuantity();//剩余数量
            if(remainingQuantity>0 ){
                //新增物料追溯
                MaterialTraceabilityParam materialTraceabilityParam = new MaterialTraceabilityParam();
                materialTraceabilityParam.setWorkOrderNo(S_ORDER_CODE);
                materialTraceabilityParam.setProductCode(S_PRODUCT_CODE);
                materialTraceabilityParam.setProductNo(S_SFC_CODE);
                materialTraceabilityParam.setLineCode(PRODUCTION_LINE);
                materialTraceabilityParam.setLocationCode(LOCATION_CODE);
                materialTraceabilityParam.setAssemblyQty(1);
                materialTraceabilityParam.setAssemblyTime(DateTool.getLocalTimeForDate());
                materialTraceabilityParam.setMaterialCode(productionOrderBatchInfoResult.getMaterialCode());//物料编码
                materialTraceabilityParam.setMaterialBatchNo(productionOrderBatchInfoResult.getBatch());//物料批次
                materialTraceabilityService.add(materialTraceabilityParam);
                //更新剩余数量
                productionOrderBatchInfoParam.setId(productionOrderBatchInfoResult.getId());
                productionOrderBatchInfoParam.setResidueQuantity(remainingQuantity-1);//剩余数量
                productionOrderBatchInfoService.update(productionOrderBatchInfoParam);
            }
        }
    }
    //PC读参数信息
    public void handleInfo() throws Exception {
        logger.info("handleInfo START!");
        if(null == list){
            CollectionParamConfParam collectionParamConfParam = new CollectionParamConfParam();
            collectionParamConfParam.setLocationCode(LOCATION_CODE);
            list = collectionParamConfService.findListBySpec(collectionParamConfParam);
        }
        if(null != list && !list.isEmpty()) {
            for (int i = 0; i < list.size(); i++) {
                CollectionParamConfResult result = (CollectionParamConfResult) list.get(i);
                String value = miloService.
                        readFromOpcUa(result.getGatherAddress())
                        .getValue().toString();//读参数值
                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);
                paramCollectionParam.setParamLower(result.getParamLower());
                paramCollectionParam.setParamUpper(result.getParamUpper());
                paramCollectionParam.setParamStandard(result.getParamCentral());
                paramCollectionParam.setCollectionTime(DateTool.getLocalTimeForDate());
                paramCollectionParam.setUnit(result.getUnit());
                paramCollectionService.add(paramCollectionParam);
            }
        }
        logger.info("handleInfo END!");
    }
}
guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/COP030Callback.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,284 @@
package cn.stylefeng.guns.plcserver.callback;
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.model.params.ParamCollectionParam;
import cn.stylefeng.guns.modular.cm.paramCollection.service.ParamCollectionService;
import cn.stylefeng.guns.modular.cm.passingStationCollection.model.params.PassingStationCollectionParam;
import cn.stylefeng.guns.modular.cm.passingStationCollection.service.PassingStationCollectionService;
import cn.stylefeng.guns.modular.dq.materialTraceability.model.params.MaterialTraceabilityParam;
import cn.stylefeng.guns.modular.dq.materialTraceability.service.MaterialTraceabilityService;
import cn.stylefeng.guns.modular.em.equipmentAlarm.service.EquipmentAlarmService;
import cn.stylefeng.guns.modular.em.equipmentStatus.service.EquipmentStatusService;
import cn.stylefeng.guns.modular.gm.greaseManage.service.GreaseManageService;
import cn.stylefeng.guns.modular.om.productionOrdeInfo.service.ProductionOrdeInfoService;
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.model.params.ProductionOrderBatchInfoParam;
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.model.result.ProductionOrderBatchInfoResult;
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.service.ProductionOrderBatchInfoService;
import cn.stylefeng.guns.modular.om.productionOrderRecords.model.params.ProductionOrderRecordsParam;
import cn.stylefeng.guns.modular.om.productionOrderRecords.model.result.ProductionOrderRecordsResult;
import cn.stylefeng.guns.modular.om.productionOrderRecords.service.ProductionOrderRecordsService;
import cn.stylefeng.guns.modular.sc.repairManageInfo.service.RepairManageInfoService;
import cn.stylefeng.guns.modular.sc.serialNumbersConf.service.SerialNumbersConfService;
import cn.stylefeng.guns.plcserver.opc.GlobalVariable;
import cn.stylefeng.guns.plcserver.opc.OPCElement;
import cn.stylefeng.guns.plcserver.tool.DateTool;
import cn.stylefeng.guns.plcserver.tool.LogUtil;
import com.kangaroohy.milo.model.ReadWriteEntity;
import com.kangaroohy.milo.runner.subscription.SubscriptionCallback;
import com.kangaroohy.milo.service.MiloService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@Component
public class COP030Callback implements SubscriptionCallback {
    public MiloService miloService;
    @Autowired
    public ProductionOrdeInfoService productionOrdeInfoService;
    @Autowired
    public PassingStationCollectionService passingStationCollectionService;
    @Autowired
    public ParamCollectionService paramCollectionService;
    @Autowired
    public CollectionParamConfService collectionParamConfService;
    @Autowired
    public SerialNumbersConfService serialNumbersConfService;
    @Autowired
    private EquipmentStatusService equipmentStatusService;
    @Autowired
    private EquipmentAlarmService equipmentAlarmService;
    @Autowired
    private MaterialTraceabilityService materialTraceabilityService;
    @Autowired
    private EquipmentInfoService equipmentInfoService;
    @Autowired
    private RepairManageInfoService repairManageInfoService;
    @Autowired
    private LocationInfoService locationInfoService;
    @Autowired
    private GreaseManageService greaseManageService;
    @Autowired
    private ProductionOrderRecordsService productionOrderRecordsService;
    @Autowired
    private ProductionOrderBatchInfoService productionOrderBatchInfoService;
    private static Logger logger;
    LogUtil logUtil = new LogUtil();
    static {
        logger = Logger.getLogger(COP020Callback.class);
    }
    private static Date IN_TIME = null;
    private static String S_ORDER_CODE = "";//工单编号
    private static String S_PRODUCT_CODE = "";//产品编号
    private static String S_PRODUCT_TYPE= "";//产品类型
    private static String S_SFC_CODE = "";//总成编码
    private static String PRODUCTION_LINE  = "COP";//产线号
    private static String LOCATION_CODE  = "COP030";//工位号
    private static List list = null;
    public COP030Callback(MiloService miloService,
                           ProductionOrdeInfoService productionOrdeInfoService,
                           PassingStationCollectionService passingStationCollectionService,
                           ParamCollectionService paramCollectionService,
                           CollectionParamConfService collectionParamConfService,
                           SerialNumbersConfService serialNumbersConfService,
                           EquipmentStatusService equipmentStatusService,
                           EquipmentAlarmService equipmentAlarmService,
                           MaterialTraceabilityService materialTraceabilityService,
                           EquipmentInfoService equipmentInfoService,
                           RepairManageInfoService repairManageInfoService,
                           LocationInfoService locationInfoService,
                           GreaseManageService greaseManageService,
                           ProductionOrderRecordsService productionOrderRecordsService,
                           ProductionOrderBatchInfoService productionOrderBatchInfoService) {
        this.miloService = miloService;
        this.productionOrdeInfoService = productionOrdeInfoService;
        this.passingStationCollectionService = passingStationCollectionService;
        this.paramCollectionService = paramCollectionService;
        this.collectionParamConfService = collectionParamConfService;
        this.serialNumbersConfService = serialNumbersConfService;
        this.equipmentStatusService = equipmentStatusService;
        this.equipmentAlarmService = equipmentAlarmService;
        this.materialTraceabilityService = materialTraceabilityService;
        this.equipmentInfoService = equipmentInfoService;
        this.repairManageInfoService = repairManageInfoService;
        this.locationInfoService = locationInfoService;
        this.greaseManageService = greaseManageService;
        this.productionOrderRecordsService = productionOrderRecordsService;
        this.productionOrderBatchInfoService = productionOrderBatchInfoService;
    }
    @Override
    public void onSubscribe(String identifier, Object value) {
        String ecpStr = "";//异常记录标记
        try {
            //心跳
            if(null != value && identifier.equals(OPCElement.COP030_F_HEART_BEAT)){
                if( "false".equals(value.toString()))
                {
                    ReadWriteEntity entity = new ReadWriteEntity(OPCElement.COP030_F_HEART_BEAT,true);
                    miloService.writeToOpcUa(entity);
                }
            }
            //PLC进站
            else if(null != value && identifier.equals(OPCElement.COP030_J_PLC_START)){
                if("true".equals(value.toString())){
                    handleOrder();
                }
            }
            //PLC出站
            else if(null != value && identifier.equals(OPCElement.COP030_J_PLC_FINISH)){
                if("true".equals(value.toString())){
                    handleFinsh();
                    handleInfo();
                    handleMaterial();
                }
            }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 {
        logger.info("handleOrder PC处理开始!");
        IN_TIME = DateTool.getLocalTimeForDate();
        List<String> lists = new ArrayList<>();
        lists.add(OPCElement.COP030_S_ORDER_CODE);
        lists.add(OPCElement.COP030_S_PRODUCT_CODE);
        lists.add(OPCElement.COP030_S_SFC_CODE);
        List<ReadWriteEntity> returnLists= miloService.readFromOpcUa(lists);
        returnLists.forEach(element->{
            switch(element.getIdentifier()){
                case OPCElement.COP030_S_ORDER_CODE:
                    S_ORDER_CODE = element.getValue().toString();
                    break;
                case OPCElement.COP030_S_PRODUCT_CODE:
                    S_PRODUCT_TYPE = element.getValue().toString();
                    S_PRODUCT_CODE = GlobalVariable.PRODUCT_CODE_MAP.get(S_PRODUCT_TYPE);
                    break;
                case OPCElement.COP030_S_SFC_CODE:
                    S_SFC_CODE = element.getValue().toString();
                    break;
                default:
                    break;
            }
        });
        ReadWriteEntity entity = new ReadWriteEntity(OPCElement.COP030_J_PC_WRITE_ORDER,true);
        miloService.writeToOpcUa(entity);
        logger.info("handleOrder PC处理完成!");
    }
    public void handleFinsh() throws Exception {
        logger.info("handleFinsh PC处理开始!");
        String S_PRODUCT_STATE_CODE = miloService.
                readFromOpcUa(OPCElement.COP030_S_PRODUCT_STATE_CODE)
                .getValue().toString();
        //处理过站信息
        PassingStationCollectionParam param = new PassingStationCollectionParam();
        param.setWorkOrderNo(S_ORDER_CODE);
        param.setProductCode(S_PRODUCT_CODE);
        param.setSfcCode(S_SFC_CODE);
        param.setProductionLine(PRODUCTION_LINE);
        param.setLocationCode(LOCATION_CODE);
        param.setInboundTime(IN_TIME);
        param.setOutboundTime(DateTool.getLocalTimeForDate());
        param.setOutRsSign(S_PRODUCT_STATE_CODE);//出站是否合格
        passingStationCollectionService.add(param);
        ReadWriteEntity entity = new ReadWriteEntity(OPCElement.COP030_J_PC_FINISH,true);
        miloService.writeToOpcUa(entity);//写PC完成
        logger.info("handleFinsh PC处理完成!");
    }
    public void handleMaterial() {
        //查询批次上料信息
        ProductionOrderBatchInfoParam productionOrderBatchInfoParam = new ProductionOrderBatchInfoParam();
        productionOrderBatchInfoParam.setWorkOrderNo(S_ORDER_CODE);
        productionOrderBatchInfoParam.setLocationCode(LOCATION_CODE);
        List<ProductionOrderBatchInfoResult> list = productionOrderBatchInfoService.findListBySpec(productionOrderBatchInfoParam);
        for(int i=0;i<list.size();i++){
            ProductionOrderBatchInfoResult productionOrderBatchInfoResult = list.get(i);
            int remainingQuantity =  productionOrderBatchInfoResult.getResidueQuantity();//剩余数量
            if(remainingQuantity>0 ){
                //新增物料追溯
                MaterialTraceabilityParam materialTraceabilityParam = new MaterialTraceabilityParam();
                materialTraceabilityParam.setWorkOrderNo(S_ORDER_CODE);
                materialTraceabilityParam.setProductCode(S_PRODUCT_CODE);
                materialTraceabilityParam.setProductNo(S_SFC_CODE);
                materialTraceabilityParam.setLineCode(PRODUCTION_LINE);
                materialTraceabilityParam.setLocationCode(LOCATION_CODE);
                materialTraceabilityParam.setAssemblyQty(1);
                materialTraceabilityParam.setAssemblyTime(DateTool.getLocalTimeForDate());
                materialTraceabilityParam.setMaterialCode(productionOrderBatchInfoResult.getMaterialCode());//物料编码
                materialTraceabilityParam.setMaterialBatchNo(productionOrderBatchInfoResult.getBatch());//物料批次
                materialTraceabilityService.add(materialTraceabilityParam);
                //更新剩余数量
                productionOrderBatchInfoParam.setId(productionOrderBatchInfoResult.getId());
                productionOrderBatchInfoParam.setResidueQuantity(remainingQuantity-1);//剩余数量
                productionOrderBatchInfoService.update(productionOrderBatchInfoParam);
            }
        }
    }
    //PC读参数信息
    public void handleInfo() throws Exception {
        logger.info("handleInfo START!");
        if(null == list){
            CollectionParamConfParam collectionParamConfParam = new CollectionParamConfParam();
            collectionParamConfParam.setLocationCode(LOCATION_CODE);
            list = collectionParamConfService.findListBySpec(collectionParamConfParam);
        }
        if(null != list && !list.isEmpty()) {
            for (int i = 0; i < list.size(); i++) {
                CollectionParamConfResult result = (CollectionParamConfResult) list.get(i);
                String value = miloService.
                        readFromOpcUa(result.getGatherAddress())
                        .getValue().toString();//读参数值
                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);
                paramCollectionParam.setParamLower(result.getParamLower());
                paramCollectionParam.setParamUpper(result.getParamUpper());
                paramCollectionParam.setParamStandard(result.getParamCentral());
                paramCollectionParam.setCollectionTime(DateTool.getLocalTimeForDate());
                paramCollectionParam.setUnit(result.getUnit());
                paramCollectionService.add(paramCollectionParam);
            }
        }
        logger.info("handleInfo END!");
    }
}
guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/DOP010Callback.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,343 @@
package cn.stylefeng.guns.plcserver.callback;
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.model.params.LocationInfoParam;
import cn.stylefeng.guns.modular.bs.locationInfo.model.result.LocationInfoResult;
import cn.stylefeng.guns.modular.bs.locationInfo.service.LocationInfoService;
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;
import cn.stylefeng.guns.modular.cm.passingStationCollection.service.PassingStationCollectionService;
import cn.stylefeng.guns.modular.dq.materialTraceability.model.params.MaterialTraceabilityParam;
import cn.stylefeng.guns.modular.dq.materialTraceability.service.MaterialTraceabilityService;
import cn.stylefeng.guns.modular.em.equipmentAlarm.service.EquipmentAlarmService;
import cn.stylefeng.guns.modular.em.equipmentStatus.service.EquipmentStatusService;
import cn.stylefeng.guns.modular.gm.greaseManage.service.GreaseManageService;
import cn.stylefeng.guns.modular.om.productionOrdeInfo.model.params.ProductionOrdeInfoParam;
import cn.stylefeng.guns.modular.om.productionOrdeInfo.model.result.ProductionOrdeInfoResult;
import cn.stylefeng.guns.modular.om.productionOrdeInfo.service.ProductionOrdeInfoService;
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.model.params.ProductionOrderBatchInfoParam;
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.model.result.ProductionOrderBatchInfoResult;
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.service.ProductionOrderBatchInfoService;
import cn.stylefeng.guns.modular.om.productionOrderRecords.service.ProductionOrderRecordsService;
import cn.stylefeng.guns.modular.sc.repairManageInfo.model.params.RepairManageInfoParam;
import cn.stylefeng.guns.modular.sc.repairManageInfo.model.result.RepairManageInfoResult;
import cn.stylefeng.guns.modular.sc.repairManageInfo.service.RepairManageInfoService;
import cn.stylefeng.guns.modular.sc.serialNumbersConf.service.SerialNumbersConfService;
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;
import com.kangaroohy.milo.runner.subscription.SubscriptionCallback;
import com.kangaroohy.milo.service.MiloService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Random;
@Component
public class DOP010Callback implements SubscriptionCallback {
    public MiloService miloService;
    @Autowired
    public ProductionOrdeInfoService productionOrdeInfoService;
    @Autowired
    public PassingStationCollectionService passingStationCollectionService;
    @Autowired
    public ParamCollectionService paramCollectionService;
    @Autowired
    public CollectionParamConfService collectionParamConfService;
    @Autowired
    public SerialNumbersConfService serialNumbersConfService;
    @Autowired
    private EquipmentStatusService equipmentStatusService;
    @Autowired
    private EquipmentAlarmService equipmentAlarmService;
    @Autowired
    private MaterialTraceabilityService materialTraceabilityService;
    @Autowired
    private EquipmentInfoService equipmentInfoService;
    @Autowired
    private RepairManageInfoService repairManageInfoService;
    @Autowired
    private LocationInfoService locationInfoService;
    @Autowired
    private GreaseManageService greaseManageService;
    @Autowired
    private ProductionOrderRecordsService productionOrderRecordsService;
    @Autowired
    private ProductionOrderBatchInfoService productionOrderBatchInfoService;
    private static Logger logger;
    LogUtil logUtil = new LogUtil();
    static {
        logger = Logger.getLogger(DOP010Callback.class);
    }
    private static Date IN_TIME = null;
    private static String S_ORDER_CODE = "";//工单编号
    private static String S_PRODUCT_CODE = "";//产品编号
    private static String S_PRODUCT_TYPE= "";//产品类型
    private static String S_SFC_CODE = "";//总成编码
    private static String PRODUCTION_LINE  = "BOP";//产线号
    private static String LOCATION_CODE  = "DOP010";//工位号
    private static List list = null;
    public DOP010Callback(MiloService miloService,
                          ProductionOrdeInfoService productionOrdeInfoService,
                          PassingStationCollectionService passingStationCollectionService,
                          ParamCollectionService paramCollectionService,
                          CollectionParamConfService collectionParamConfService,
                          SerialNumbersConfService serialNumbersConfService,
                          EquipmentStatusService equipmentStatusService,
                          EquipmentAlarmService equipmentAlarmService,
                          MaterialTraceabilityService materialTraceabilityService,
                          EquipmentInfoService equipmentInfoService,
                          RepairManageInfoService repairManageInfoService,
                          LocationInfoService locationInfoService,
                          GreaseManageService greaseManageService,
                          ProductionOrderRecordsService productionOrderRecordsService,
                          ProductionOrderBatchInfoService productionOrderBatchInfoService) {
        this.miloService = miloService;
        this.productionOrdeInfoService = productionOrdeInfoService;
        this.passingStationCollectionService = passingStationCollectionService;
        this.paramCollectionService = paramCollectionService;
        this.collectionParamConfService = collectionParamConfService;
        this.serialNumbersConfService = serialNumbersConfService;
        this.equipmentStatusService = equipmentStatusService;
        this.equipmentAlarmService = equipmentAlarmService;
        this.materialTraceabilityService = materialTraceabilityService;
        this.equipmentInfoService = equipmentInfoService;
        this.repairManageInfoService = repairManageInfoService;
        this.locationInfoService = locationInfoService;
        this.greaseManageService = greaseManageService;
        this.productionOrderRecordsService = productionOrderRecordsService;
        this.productionOrderBatchInfoService = productionOrderBatchInfoService;
    }
    @Override
    public void onSubscribe(String identifier, Object value) {
        String ecpStr = "";//异常记录标记
        try {
            //心跳
            if(null != value && identifier.equals(OPCElement.COP010_F_HEART_BEAT)){
                if( "false".equals(value.toString()))
                {
                    ReadWriteEntity entity = new ReadWriteEntity(OPCElement.DOP010_F_HEART_BEAT,true);
                    miloService.writeToOpcUa(entity);
                }
            }
            //PLC进站
            else if(null != value && identifier.equals(OPCElement.DOP010_J_PLC_START)){
                if("true".equals(value.toString())){
                    String isRepair = miloService.
                            readFromOpcUa(OPCElement.DOP010_P_REPAIR)
                            .getValue().toString();//是否返修
                    if(isRepair.equals("true")){
                        handleRepair();
                    }else{
                        handleOrder();
                    }
                }
            }
            //PLC出站
            else if(null != value && identifier.equals(OPCElement.DOP010_J_PLC_FINISH)){
                if("true".equals(value.toString())){
                    handleFinsh();
                    //handleInfo();
                    handleMaterial();
                }
            }else{
                System.out.println("值没有变");
            }
        } catch (Exception e) {
            ecpStr ="出现异常:" + logUtil.getTrace(e);
        }finally {
            if(!"".equals(ecpStr)){
                logger.info(ecpStr+"\r\n");
            }
        }
    }
    public void handleOrder() throws Exception{
        IN_TIME = DateTool.getLocalTimeForDate();
        ProductionOrdeInfoParam param = new ProductionOrdeInfoParam();
        param.setProductionLine("");//产线
        param.setOrderStatus("3");//工单状态
        List<ProductionOrdeInfoResult> list = productionOrdeInfoService.findListBySpec(param);
        if(list.size()>0) {
            ProductionOrdeInfoResult result = list.get(0);
            S_ORDER_CODE = result.getWorkOrderNo();
            S_PRODUCT_CODE = result.getMaterialCode();
            S_PRODUCT_TYPE = GlobalVariable.PRODUCT_TYPE_MAP.get(S_PRODUCT_CODE);
            //自动生成唯一码
            Random random = new Random(System.currentTimeMillis());
            S_SFC_CODE = "EOP"+ random.nextLong();
            List<ReadWriteEntity> lists = new ArrayList<>();
            lists.add(new ReadWriteEntity(OPCElement.DOP010_S_ORDER_CODE,S_ORDER_CODE));
            lists.add(new ReadWriteEntity(OPCElement.DOP010_S_PRODUCT_CODE,S_PRODUCT_TYPE));
            lists.add(new ReadWriteEntity(OPCElement.DOP010_S_SFC_CODE,S_SFC_CODE));
            lists.add(new ReadWriteEntity(OPCElement.DOP010_S_NUMBER,result.getPlanQty().toString()));
            lists.add(new ReadWriteEntity(OPCElement.DOP010_J_PC_WRITE_ORDER,true));
            miloService.writeToOpcUa(lists);
            logger.info("DOP010工位,handleOrder PC处理完成!");
        }else{
            logger.info("DOP010工位没有可执行的工单,请联系工单管理员下发该产线的工单!");
        }
    }
    public void handleFinsh() throws Exception {
        logger.info("handleFinsh PC处理开始!");
        String S_PRODUCT_STATE_CODE = miloService.
                readFromOpcUa(OPCElement.DOP010_S_PRODUCT_STATE_CODE)
                .getValue().toString();
        //处理过站信息
        PassingStationCollectionParam param = new PassingStationCollectionParam();
        param.setWorkOrderNo(S_ORDER_CODE);
        param.setProductCode(S_PRODUCT_CODE);
        param.setSfcCode(S_SFC_CODE);
        param.setProductionLine(PRODUCTION_LINE);
        param.setLocationCode(LOCATION_CODE);
        param.setInboundTime(IN_TIME);
        param.setOutboundTime(DateTool.getLocalTimeForDate());
        param.setOutRsSign(S_PRODUCT_STATE_CODE);//出站是否合格
        passingStationCollectionService.add(param);
        ReadWriteEntity entity = new ReadWriteEntity(OPCElement.DOP010_J_PC_FINISH,true);
        miloService.writeToOpcUa(entity);//写PC完成
        logger.info("handleFinsh PC处理完成!");
    }
    public void handleMaterial() {
        //查询批次上料信息
        ProductionOrderBatchInfoParam productionOrderBatchInfoParam = new ProductionOrderBatchInfoParam();
        productionOrderBatchInfoParam.setWorkOrderNo(S_ORDER_CODE);
        productionOrderBatchInfoParam.setLocationCode(LOCATION_CODE);
        List<ProductionOrderBatchInfoResult> list = productionOrderBatchInfoService.findListBySpec(productionOrderBatchInfoParam);
        for(int i=0;i<list.size();i++){
            ProductionOrderBatchInfoResult productionOrderBatchInfoResult = list.get(i);
            int remainingQuantity =  productionOrderBatchInfoResult.getResidueQuantity();//剩余数量
            if(remainingQuantity>0 ){
                //新增物料追溯
                MaterialTraceabilityParam materialTraceabilityParam = new MaterialTraceabilityParam();
                materialTraceabilityParam.setWorkOrderNo(S_ORDER_CODE);
                materialTraceabilityParam.setProductCode(S_PRODUCT_CODE);
                materialTraceabilityParam.setProductNo(S_SFC_CODE);
                materialTraceabilityParam.setLineCode(PRODUCTION_LINE);
                materialTraceabilityParam.setLocationCode(LOCATION_CODE);
                materialTraceabilityParam.setAssemblyQty(1);
                materialTraceabilityParam.setAssemblyTime(DateTool.getLocalTimeForDate());
                materialTraceabilityParam.setMaterialCode(productionOrderBatchInfoResult.getMaterialCode());//物料编码
                materialTraceabilityParam.setMaterialBatchNo(productionOrderBatchInfoResult.getBatch());//物料批次
                materialTraceabilityService.add(materialTraceabilityParam);
                //更新剩余数量
                productionOrderBatchInfoParam.setId(productionOrderBatchInfoResult.getId());
                productionOrderBatchInfoParam.setResidueQuantity(remainingQuantity-1);//剩余数量
                productionOrderBatchInfoService.update(productionOrderBatchInfoParam);
            }
        }
    }
    //PC读参数信息
    public void handleInfo() throws Exception {
        logger.info("handleInfo START!");
        if(null == list){
            CollectionParamConfParam collectionParamConfParam = new CollectionParamConfParam();
            collectionParamConfParam.setLocationCode(LOCATION_CODE);
            list = collectionParamConfService.findListBySpec(collectionParamConfParam);
        }
        if(null != list && !list.isEmpty()) {
            for (int i = 0; i < list.size(); i++) {
                CollectionParamConfResult result = (CollectionParamConfResult) list.get(i);
                String value = miloService.
                        readFromOpcUa(result.getGatherAddress())
                        .getValue().toString();//读参数值
                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);
                paramCollectionParam.setParamLower(result.getParamLower());
                paramCollectionParam.setParamUpper(result.getParamUpper());
                paramCollectionParam.setParamStandard(result.getParamCentral());
                paramCollectionParam.setCollectionTime(DateTool.getLocalTimeForDate());
                paramCollectionParam.setUnit(result.getUnit());
                paramCollectionService.add(paramCollectionParam);
            }
        }
        logger.info("handleInfo END!");
    }
    public void handleRepair() throws Exception{
        RepairManageInfoParam repairManageInfoParam = new RepairManageInfoParam();
        repairManageInfoParam.setLocationCode(LOCATION_CODE);
        repairManageInfoParam.setManageType("2");
        repairManageInfoParam.setUpPlc("0");
        List<RepairManageInfoResult> list = repairManageInfoService.findListBySpec(repairManageInfoParam);
        if(list.size()>0) {
            RepairManageInfoResult result = list.get(0);
            //自动生成唯一码
            Random random = new Random(System.currentTimeMillis());
            S_SFC_CODE = "BOP" + random.nextLong();
            S_ORDER_CODE = result.getWorkOrderNo();
            S_PRODUCT_CODE = result.getProductCode();
            S_PRODUCT_TYPE = GlobalVariable.PRODUCT_TYPE_MAP.get(S_PRODUCT_CODE);
            String  repairLocation = result.getPoorLocationCode();//
            //根据工位编码查询工位表中配置的返修工位号
            LocationInfoParam param = new LocationInfoParam();
            param.setLocationCode(repairLocation);
            List<LocationInfoResult> results = locationInfoService.findListBySpec(param);
            if(results.size()>0) {
                LocationInfoResult r = results.get(0);
                String repairLocationNo = r.getSpareField2();
                if(null != repairLocationNo && "" != repairLocationNo){
                    List<ReadWriteEntity> lists = new ArrayList<>();
                    lists.add(new ReadWriteEntity(OPCElement.DOP010_S_ORDER_CODE,S_ORDER_CODE));
                    lists.add(new ReadWriteEntity(OPCElement.DOP010_S_PRODUCT_CODE,S_PRODUCT_TYPE));
                    lists.add(new ReadWriteEntity(OPCElement.DOP010_S_SFC_CODE,S_SFC_CODE));
                    lists.add(new ReadWriteEntity(OPCElement.DOP010_P_REPAIR_LOCATION,repairLocationNo));
                    lists.add(new ReadWriteEntity(OPCElement.DOP010_J_PC_WRITE_ORDER,true));
                    miloService.writeToOpcUa(lists);
                    //更新为已经返修上线
                    Long id = result.getId();
                    repairManageInfoParam.setId(id);
                    repairManageInfoParam.setUpPlc("1");
                    repairManageInfoService.update(repairManageInfoParam);
                }else{
                    logger.info("DOP010工位,handleRepair è¯·æŸ¥è¯¢"+repairLocation+"工位是否配置返修工位号!");
                }
            }else{
                logger.info("DOP010工位,handleRepair æ— æ³•æŸ¥è¯¢åˆ°"+repairLocation+"工位!");
            }
        }
    }
}
guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/DOP020Callback.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,282 @@
package cn.stylefeng.guns.plcserver.callback;
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.model.params.ParamCollectionParam;
import cn.stylefeng.guns.modular.cm.paramCollection.service.ParamCollectionService;
import cn.stylefeng.guns.modular.cm.passingStationCollection.model.params.PassingStationCollectionParam;
import cn.stylefeng.guns.modular.cm.passingStationCollection.service.PassingStationCollectionService;
import cn.stylefeng.guns.modular.dq.materialTraceability.model.params.MaterialTraceabilityParam;
import cn.stylefeng.guns.modular.dq.materialTraceability.service.MaterialTraceabilityService;
import cn.stylefeng.guns.modular.em.equipmentAlarm.service.EquipmentAlarmService;
import cn.stylefeng.guns.modular.em.equipmentStatus.service.EquipmentStatusService;
import cn.stylefeng.guns.modular.gm.greaseManage.service.GreaseManageService;
import cn.stylefeng.guns.modular.om.productionOrdeInfo.service.ProductionOrdeInfoService;
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.model.params.ProductionOrderBatchInfoParam;
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.model.result.ProductionOrderBatchInfoResult;
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.service.ProductionOrderBatchInfoService;
import cn.stylefeng.guns.modular.om.productionOrderRecords.service.ProductionOrderRecordsService;
import cn.stylefeng.guns.modular.sc.repairManageInfo.service.RepairManageInfoService;
import cn.stylefeng.guns.modular.sc.serialNumbersConf.service.SerialNumbersConfService;
import cn.stylefeng.guns.plcserver.opc.GlobalVariable;
import cn.stylefeng.guns.plcserver.opc.OPCElement;
import cn.stylefeng.guns.plcserver.tool.DateTool;
import cn.stylefeng.guns.plcserver.tool.LogUtil;
import com.kangaroohy.milo.model.ReadWriteEntity;
import com.kangaroohy.milo.runner.subscription.SubscriptionCallback;
import com.kangaroohy.milo.service.MiloService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@Component
public class DOP020Callback implements SubscriptionCallback {
    public MiloService miloService;
    @Autowired
    public ProductionOrdeInfoService productionOrdeInfoService;
    @Autowired
    public PassingStationCollectionService passingStationCollectionService;
    @Autowired
    public ParamCollectionService paramCollectionService;
    @Autowired
    public CollectionParamConfService collectionParamConfService;
    @Autowired
    public SerialNumbersConfService serialNumbersConfService;
    @Autowired
    private EquipmentStatusService equipmentStatusService;
    @Autowired
    private EquipmentAlarmService equipmentAlarmService;
    @Autowired
    private MaterialTraceabilityService materialTraceabilityService;
    @Autowired
    private EquipmentInfoService equipmentInfoService;
    @Autowired
    private RepairManageInfoService repairManageInfoService;
    @Autowired
    private LocationInfoService locationInfoService;
    @Autowired
    private GreaseManageService greaseManageService;
    @Autowired
    private ProductionOrderRecordsService productionOrderRecordsService;
    @Autowired
    private ProductionOrderBatchInfoService productionOrderBatchInfoService;
    private static Logger logger;
    LogUtil logUtil = new LogUtil();
    static {
        logger = Logger.getLogger(DOP020Callback.class);
    }
    private static Date IN_TIME = null;
    private static String S_ORDER_CODE = "";//工单编号
    private static String S_PRODUCT_CODE = "";//产品编号
    private static String S_PRODUCT_TYPE= "";//产品类型
    private static String S_SFC_CODE = "";//总成编码
    private static String PRODUCTION_LINE  = "EOP";//产线号
    private static String LOCATION_CODE  = "DOP020";//工位号
    private static List list = null;
    public DOP020Callback(MiloService miloService,
                          ProductionOrdeInfoService productionOrdeInfoService,
                          PassingStationCollectionService passingStationCollectionService,
                          ParamCollectionService paramCollectionService,
                          CollectionParamConfService collectionParamConfService,
                          SerialNumbersConfService serialNumbersConfService,
                          EquipmentStatusService equipmentStatusService,
                          EquipmentAlarmService equipmentAlarmService,
                          MaterialTraceabilityService materialTraceabilityService,
                          EquipmentInfoService equipmentInfoService,
                          RepairManageInfoService repairManageInfoService,
                          LocationInfoService locationInfoService,
                          GreaseManageService greaseManageService,
                          ProductionOrderRecordsService productionOrderRecordsService,
                          ProductionOrderBatchInfoService productionOrderBatchInfoService) {
        this.miloService = miloService;
        this.productionOrdeInfoService = productionOrdeInfoService;
        this.passingStationCollectionService = passingStationCollectionService;
        this.paramCollectionService = paramCollectionService;
        this.collectionParamConfService = collectionParamConfService;
        this.serialNumbersConfService = serialNumbersConfService;
        this.equipmentStatusService = equipmentStatusService;
        this.equipmentAlarmService = equipmentAlarmService;
        this.materialTraceabilityService = materialTraceabilityService;
        this.equipmentInfoService = equipmentInfoService;
        this.repairManageInfoService = repairManageInfoService;
        this.locationInfoService = locationInfoService;
        this.greaseManageService = greaseManageService;
        this.productionOrderRecordsService = productionOrderRecordsService;
        this.productionOrderBatchInfoService = productionOrderBatchInfoService;
    }
    @Override
    public void onSubscribe(String identifier, Object value) {
        String ecpStr = "";//异常记录标记
        try {
            //心跳
            if(null != value && identifier.equals(OPCElement.DOP020_F_HEART_BEAT)){
                if( "false".equals(value.toString()))
                {
                    ReadWriteEntity entity = new ReadWriteEntity(OPCElement.DOP020_F_HEART_BEAT,true);
                    miloService.writeToOpcUa(entity);
                }
            }
            //PLC进站
            else if(null != value && identifier.equals(OPCElement.DOP020_J_PLC_START)){
                if("true".equals(value.toString())){
                    handleOrder();
                }
            }
            //PLC出站
            else if(null != value && identifier.equals(OPCElement.DOP020_J_PLC_FINISH)){
                if("true".equals(value.toString())){
                    handleFinsh();
                    handleInfo();
                    handleMaterial();
                }
            }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 {
        logger.info("handleOrder PC处理开始!");
        IN_TIME = DateTool.getLocalTimeForDate();
        List<String> lists = new ArrayList<>();
        lists.add(OPCElement.DOP020_S_ORDER_CODE);
        lists.add(OPCElement.DOP020_S_PRODUCT_CODE);
        lists.add(OPCElement.DOP020_S_SFC_CODE);
        List<ReadWriteEntity> returnLists= miloService.readFromOpcUa(lists);
        returnLists.forEach(element->{
            switch(element.getIdentifier()){
                case OPCElement.DOP020_S_ORDER_CODE:
                    S_ORDER_CODE = element.getValue().toString();
                    break;
                case OPCElement.DOP020_S_PRODUCT_CODE:
                    S_PRODUCT_TYPE = element.getValue().toString();
                    S_PRODUCT_CODE = GlobalVariable.PRODUCT_CODE_MAP.get(S_PRODUCT_TYPE);
                    break;
                case OPCElement.DOP020_S_SFC_CODE:
                    S_SFC_CODE = element.getValue().toString();
                    break;
                default:
                    break;
            }
        });
        ReadWriteEntity entity = new ReadWriteEntity(OPCElement.DOP020_J_PC_WRITE_ORDER,true);
        miloService.writeToOpcUa(entity);
        logger.info("handleOrder PC处理完成!");
    }
    public void handleFinsh() throws Exception {
        logger.info("handleFinsh PC处理开始!");
        String S_PRODUCT_STATE_CODE = miloService.
                readFromOpcUa(OPCElement.DOP020_S_PRODUCT_STATE_CODE)
                .getValue().toString();
        //处理过站信息
        PassingStationCollectionParam param = new PassingStationCollectionParam();
        param.setWorkOrderNo(S_ORDER_CODE);
        param.setProductCode(S_PRODUCT_CODE);
        param.setSfcCode(S_SFC_CODE);
        param.setProductionLine(PRODUCTION_LINE);
        param.setLocationCode(LOCATION_CODE);
        param.setInboundTime(IN_TIME);
        param.setOutboundTime(DateTool.getLocalTimeForDate());
        param.setOutRsSign(S_PRODUCT_STATE_CODE);//出站是否合格
        passingStationCollectionService.add(param);
        ReadWriteEntity entity = new ReadWriteEntity(OPCElement.DOP020_J_PC_FINISH,true);
        miloService.writeToOpcUa(entity);//写PC完成
        logger.info("handleFinsh PC处理完成!");
    }
    public void handleMaterial() {
        //查询批次上料信息
        ProductionOrderBatchInfoParam productionOrderBatchInfoParam = new ProductionOrderBatchInfoParam();
        productionOrderBatchInfoParam.setWorkOrderNo(S_ORDER_CODE);
        productionOrderBatchInfoParam.setLocationCode(LOCATION_CODE);
        List<ProductionOrderBatchInfoResult> list = productionOrderBatchInfoService.findListBySpec(productionOrderBatchInfoParam);
        for(int i=0;i<list.size();i++){
            ProductionOrderBatchInfoResult productionOrderBatchInfoResult = list.get(i);
            int remainingQuantity =  productionOrderBatchInfoResult.getResidueQuantity();//剩余数量
            if(remainingQuantity>0 ){
                //新增物料追溯
                MaterialTraceabilityParam materialTraceabilityParam = new MaterialTraceabilityParam();
                materialTraceabilityParam.setWorkOrderNo(S_ORDER_CODE);
                materialTraceabilityParam.setProductCode(S_PRODUCT_CODE);
                materialTraceabilityParam.setProductNo(S_SFC_CODE);
                materialTraceabilityParam.setLineCode(PRODUCTION_LINE);
                materialTraceabilityParam.setLocationCode(LOCATION_CODE);
                materialTraceabilityParam.setAssemblyQty(1);
                materialTraceabilityParam.setAssemblyTime(DateTool.getLocalTimeForDate());
                materialTraceabilityParam.setMaterialCode(productionOrderBatchInfoResult.getMaterialCode());//物料编码
                materialTraceabilityParam.setMaterialBatchNo(productionOrderBatchInfoResult.getBatch());//物料批次
                materialTraceabilityService.add(materialTraceabilityParam);
                //更新剩余数量
                productionOrderBatchInfoParam.setId(productionOrderBatchInfoResult.getId());
                productionOrderBatchInfoParam.setResidueQuantity(remainingQuantity-1);//剩余数量
                productionOrderBatchInfoService.update(productionOrderBatchInfoParam);
            }
        }
    }
    //PC读参数信息
    public void handleInfo() throws Exception {
        logger.info("handleInfo START!");
        if(null == list){
            CollectionParamConfParam collectionParamConfParam = new CollectionParamConfParam();
            collectionParamConfParam.setLocationCode(LOCATION_CODE);
            list = collectionParamConfService.findListBySpec(collectionParamConfParam);
        }
        if(null != list && !list.isEmpty()) {
            for (int i = 0; i < list.size(); i++) {
                CollectionParamConfResult result = (CollectionParamConfResult) list.get(i);
                String value = miloService.
                        readFromOpcUa(result.getGatherAddress())
                        .getValue().toString();//读参数值
                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);
                paramCollectionParam.setParamLower(result.getParamLower());
                paramCollectionParam.setParamUpper(result.getParamUpper());
                paramCollectionParam.setParamStandard(result.getParamCentral());
                paramCollectionParam.setCollectionTime(DateTool.getLocalTimeForDate());
                paramCollectionParam.setUnit(result.getUnit());
                paramCollectionService.add(paramCollectionParam);
            }
        }
        logger.info("handleInfo END!");
    }
}
guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/EOP010Callback.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,290 @@
package cn.stylefeng.guns.plcserver.callback;
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.model.params.ParamCollectionParam;
import cn.stylefeng.guns.modular.cm.paramCollection.service.ParamCollectionService;
import cn.stylefeng.guns.modular.cm.passingStationCollection.model.params.PassingStationCollectionParam;
import cn.stylefeng.guns.modular.cm.passingStationCollection.service.PassingStationCollectionService;
import cn.stylefeng.guns.modular.dq.materialTraceability.model.params.MaterialTraceabilityParam;
import cn.stylefeng.guns.modular.dq.materialTraceability.service.MaterialTraceabilityService;
import cn.stylefeng.guns.modular.em.equipmentAlarm.service.EquipmentAlarmService;
import cn.stylefeng.guns.modular.em.equipmentStatus.service.EquipmentStatusService;
import cn.stylefeng.guns.modular.gm.greaseManage.service.GreaseManageService;
import cn.stylefeng.guns.modular.om.productionOrdeInfo.service.ProductionOrdeInfoService;
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.model.params.ProductionOrderBatchInfoParam;
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.model.result.ProductionOrderBatchInfoResult;
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.service.ProductionOrderBatchInfoService;
import cn.stylefeng.guns.modular.om.productionOrderRecords.service.ProductionOrderRecordsService;
import cn.stylefeng.guns.modular.sc.repairManageInfo.service.RepairManageInfoService;
import cn.stylefeng.guns.modular.sc.serialNumbersConf.service.SerialNumbersConfService;
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;
import com.kangaroohy.milo.runner.subscription.SubscriptionCallback;
import com.kangaroohy.milo.service.MiloService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@Component
public class EOP010Callback implements SubscriptionCallback {
    public MiloService miloService;
    @Autowired
    public ProductionOrdeInfoService productionOrdeInfoService;
    @Autowired
    public PassingStationCollectionService passingStationCollectionService;
    @Autowired
    public ParamCollectionService paramCollectionService;
    @Autowired
    public CollectionParamConfService collectionParamConfService;
    @Autowired
    public SerialNumbersConfService serialNumbersConfService;
    @Autowired
    private EquipmentStatusService equipmentStatusService;
    @Autowired
    private EquipmentAlarmService equipmentAlarmService;
    @Autowired
    private MaterialTraceabilityService materialTraceabilityService;
    @Autowired
    private EquipmentInfoService equipmentInfoService;
    @Autowired
    private RepairManageInfoService repairManageInfoService;
    @Autowired
    private LocationInfoService locationInfoService;
    @Autowired
    private GreaseManageService greaseManageService;
    @Autowired
    private ProductionOrderRecordsService productionOrderRecordsService;
    @Autowired
    private ProductionOrderBatchInfoService productionOrderBatchInfoService;
    private static Logger logger;
    LogUtil logUtil = new LogUtil();
    static {
        logger = Logger.getLogger(EOP010Callback.class);
    }
    private static Date IN_TIME = null;
    private static String S_ORDER_CODE = "";//工单编号
    private static String S_PRODUCT_CODE = "";//产品编号
    private static String S_PRODUCT_TYPE= "";//产品类型
    private static String S_SFC_CODE = "";//总成编码
    private static String PRODUCTION_LINE  = "EOP";//产线号
    private static String LOCATION_CODE  = "EOP010";//工位号
    private static List list = null;
    public EOP010Callback(MiloService miloService,
                          ProductionOrdeInfoService productionOrdeInfoService,
                          PassingStationCollectionService passingStationCollectionService,
                          ParamCollectionService paramCollectionService,
                          CollectionParamConfService collectionParamConfService,
                          SerialNumbersConfService serialNumbersConfService,
                          EquipmentStatusService equipmentStatusService,
                          EquipmentAlarmService equipmentAlarmService,
                          MaterialTraceabilityService materialTraceabilityService,
                          EquipmentInfoService equipmentInfoService,
                          RepairManageInfoService repairManageInfoService,
                          LocationInfoService locationInfoService,
                          GreaseManageService greaseManageService,
                          ProductionOrderRecordsService productionOrderRecordsService,
                          ProductionOrderBatchInfoService productionOrderBatchInfoService) {
        this.miloService = miloService;
        this.productionOrdeInfoService = productionOrdeInfoService;
        this.passingStationCollectionService = passingStationCollectionService;
        this.paramCollectionService = paramCollectionService;
        this.collectionParamConfService = collectionParamConfService;
        this.serialNumbersConfService = serialNumbersConfService;
        this.equipmentStatusService = equipmentStatusService;
        this.equipmentAlarmService = equipmentAlarmService;
        this.materialTraceabilityService = materialTraceabilityService;
        this.equipmentInfoService = equipmentInfoService;
        this.repairManageInfoService = repairManageInfoService;
        this.locationInfoService = locationInfoService;
        this.greaseManageService = greaseManageService;
        this.productionOrderRecordsService = productionOrderRecordsService;
        this.productionOrderBatchInfoService = productionOrderBatchInfoService;
    }
    @Override
    public void onSubscribe(String identifier, Object value) {
        String ecpStr = "";//异常记录标记
        try {
            //心跳
            if(null != value && identifier.equals(OPCElement.EOP010_F_HEART_BEAT)){
                if( "false".equals(value.toString()))
                {
                    ReadWriteEntity entity = new ReadWriteEntity(OPCElement.EOP010_F_HEART_BEAT,true);
                    miloService.writeToOpcUa(entity);
                }
            }
            //PLC进站
            else if(null != value && identifier.equals(OPCElement.EOP010_J_PLC_START)){
                if("true".equals(value.toString())){
                    handleOrder();
                }
            }
            //PLC出站
            else if(null != value && identifier.equals(OPCElement.EOP010_J_PLC_FINISH)){
                if("true".equals(value.toString())){
                    handleFinsh();
                    handleInfo();
                    handleMaterial();
                }
            }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 {
        logger.info("handleOrder PC处理开始!");
        IN_TIME = DateTool.getLocalTimeForDate();
        List<String> lists = new ArrayList<>();
        lists.add(OPCElement.EOP010_S_ORDER_CODE);
        lists.add(OPCElement.EOP010_S_PRODUCT_CODE);
        lists.add(OPCElement.EOP010_S_SFC_CODE);
        List<ReadWriteEntity> returnLists= miloService.readFromOpcUa(lists);
        returnLists.forEach(element->{
            switch(element.getIdentifier()){
                case OPCElement.EOP010_S_ORDER_CODE:
                    S_ORDER_CODE = element.getValue().toString();
                    break;
                case OPCElement.EOP010_S_PRODUCT_CODE:
                    S_PRODUCT_TYPE = element.getValue().toString();
                    S_PRODUCT_CODE = GlobalVariable.PRODUCT_CODE_MAP.get(S_PRODUCT_TYPE);
                    break;
                case OPCElement.EOP010_S_SFC_CODE:
                    S_SFC_CODE = element.getValue().toString();
                    break;
                default:
                    break;
            }
        });
        ReadWriteEntity entity = new ReadWriteEntity(OPCElement.EOP010_J_PC_WRITE_ORDER,true);
        miloService.writeToOpcUa(entity);
        logger.info("handleOrder PC处理完成!");
    }
    public void handleFinsh() throws Exception {
        logger.info("handleFinsh PC处理开始!");
        String S_PRODUCT_STATE_CODE = miloService.
                readFromOpcUa(OPCElement.EOP010_S_PRODUCT_STATE_CODE)
                .getValue().toString();
        //处理过站信息
        PassingStationCollectionParam param = new PassingStationCollectionParam();
        param.setWorkOrderNo(S_ORDER_CODE);
        param.setProductCode(S_PRODUCT_CODE);
        param.setSfcCode(S_SFC_CODE);
        param.setProductionLine(PRODUCTION_LINE);
        param.setLocationCode(LOCATION_CODE);
        param.setInboundTime(IN_TIME);
        param.setOutboundTime(DateTool.getLocalTimeForDate());
        param.setOutRsSign(S_PRODUCT_STATE_CODE);//出站是否合格
        passingStationCollectionService.add(param);
        ReadWriteEntity entity = new ReadWriteEntity(OPCElement.EOP010_J_PC_FINISH,true);
        miloService.writeToOpcUa(entity);//写PC完成
        logger.info("handleFinsh PC处理完成!");
    }
    public void handleMaterial() throws Exception{
        String materialCode = miloService.
                readFromOpcUa(OPCElement.EOP010_S_MATERIAL_CODE)
                .getValue().toString();
        MaterialTraceabilityParam materialTraceabilityParam = new MaterialTraceabilityParam();
        materialTraceabilityParam.setWorkOrderNo(S_ORDER_CODE);
        materialTraceabilityParam.setProductCode(S_PRODUCT_CODE);
        materialTraceabilityParam.setProductNo(S_SFC_CODE);
        materialTraceabilityParam.setLineCode(PRODUCTION_LINE);
        materialTraceabilityParam.setLocationCode(LOCATION_CODE);
        materialTraceabilityParam.setMaterialCode(materialCode);
        materialTraceabilityParam.setAssemblyQty(1);
        materialTraceabilityParam.setAssemblyTime(DateTool.getLocalTimeForDate());
        materialTraceabilityService.add(materialTraceabilityParam);
        //查询批次上料信息
        ProductionOrderBatchInfoParam productionOrderBatchInfoParam = new ProductionOrderBatchInfoParam();
        productionOrderBatchInfoParam.setWorkOrderNo(S_ORDER_CODE);
        productionOrderBatchInfoParam.setLocationCode(LOCATION_CODE);
        List<ProductionOrderBatchInfoResult> list1 = productionOrderBatchInfoService.findListBySpec(productionOrderBatchInfoParam);
        for(int i=0;i<list1.size();i++){
            ProductionOrderBatchInfoResult productionOrderBatchInfoResult = list1.get(i);
            int remainingQuantity =  productionOrderBatchInfoResult.getResidueQuantity();//剩余数量
            if(remainingQuantity>0 ){
                //新增物料追溯
                materialTraceabilityParam.setMaterialCode(productionOrderBatchInfoResult.getMaterialCode());//物料编码
                materialTraceabilityParam.setMaterialBatchNo(productionOrderBatchInfoResult.getBatch());//物料批次
                materialTraceabilityService.add(materialTraceabilityParam);
                //更新剩余数量
                productionOrderBatchInfoParam.setId(productionOrderBatchInfoResult.getId());
                productionOrderBatchInfoParam.setResidueQuantity(remainingQuantity-1);//剩余数量
                productionOrderBatchInfoService.update(productionOrderBatchInfoParam);
            }
        }
    }
    //PC读参数信息
    public void handleInfo() throws Exception {
        logger.info("handleInfo START!");
        if(null == list){
            CollectionParamConfParam collectionParamConfParam = new CollectionParamConfParam();
            collectionParamConfParam.setLocationCode(LOCATION_CODE);
            list = collectionParamConfService.findListBySpec(collectionParamConfParam);
        }
        if(null != list && !list.isEmpty()) {
            for (int i = 0; i < list.size(); i++) {
                CollectionParamConfResult result = (CollectionParamConfResult) list.get(i);
                String value = miloService.
                        readFromOpcUa(result.getGatherAddress())
                        .getValue().toString();//读参数值
                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);
                paramCollectionParam.setParamLower(result.getParamLower());
                paramCollectionParam.setParamUpper(result.getParamUpper());
                paramCollectionParam.setParamStandard(result.getParamCentral());
                paramCollectionParam.setCollectionTime(DateTool.getLocalTimeForDate());
                paramCollectionParam.setUnit(result.getUnit());
                paramCollectionService.add(paramCollectionParam);
            }
        }
        logger.info("handleInfo END!");
    }
}
guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/EOP020Callback.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,282 @@
package cn.stylefeng.guns.plcserver.callback;
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.model.params.ParamCollectionParam;
import cn.stylefeng.guns.modular.cm.paramCollection.service.ParamCollectionService;
import cn.stylefeng.guns.modular.cm.passingStationCollection.model.params.PassingStationCollectionParam;
import cn.stylefeng.guns.modular.cm.passingStationCollection.service.PassingStationCollectionService;
import cn.stylefeng.guns.modular.dq.materialTraceability.model.params.MaterialTraceabilityParam;
import cn.stylefeng.guns.modular.dq.materialTraceability.service.MaterialTraceabilityService;
import cn.stylefeng.guns.modular.em.equipmentAlarm.service.EquipmentAlarmService;
import cn.stylefeng.guns.modular.em.equipmentStatus.service.EquipmentStatusService;
import cn.stylefeng.guns.modular.gm.greaseManage.service.GreaseManageService;
import cn.stylefeng.guns.modular.om.productionOrdeInfo.service.ProductionOrdeInfoService;
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.model.params.ProductionOrderBatchInfoParam;
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.model.result.ProductionOrderBatchInfoResult;
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.service.ProductionOrderBatchInfoService;
import cn.stylefeng.guns.modular.om.productionOrderRecords.service.ProductionOrderRecordsService;
import cn.stylefeng.guns.modular.sc.repairManageInfo.service.RepairManageInfoService;
import cn.stylefeng.guns.modular.sc.serialNumbersConf.service.SerialNumbersConfService;
import cn.stylefeng.guns.plcserver.opc.GlobalVariable;
import cn.stylefeng.guns.plcserver.opc.OPCElement;
import cn.stylefeng.guns.plcserver.tool.DateTool;
import cn.stylefeng.guns.plcserver.tool.LogUtil;
import com.kangaroohy.milo.model.ReadWriteEntity;
import com.kangaroohy.milo.runner.subscription.SubscriptionCallback;
import com.kangaroohy.milo.service.MiloService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@Component
public class EOP020Callback implements SubscriptionCallback {
    public MiloService miloService;
    @Autowired
    public ProductionOrdeInfoService productionOrdeInfoService;
    @Autowired
    public PassingStationCollectionService passingStationCollectionService;
    @Autowired
    public ParamCollectionService paramCollectionService;
    @Autowired
    public CollectionParamConfService collectionParamConfService;
    @Autowired
    public SerialNumbersConfService serialNumbersConfService;
    @Autowired
    private EquipmentStatusService equipmentStatusService;
    @Autowired
    private EquipmentAlarmService equipmentAlarmService;
    @Autowired
    private MaterialTraceabilityService materialTraceabilityService;
    @Autowired
    private EquipmentInfoService equipmentInfoService;
    @Autowired
    private RepairManageInfoService repairManageInfoService;
    @Autowired
    private LocationInfoService locationInfoService;
    @Autowired
    private GreaseManageService greaseManageService;
    @Autowired
    private ProductionOrderRecordsService productionOrderRecordsService;
    @Autowired
    private ProductionOrderBatchInfoService productionOrderBatchInfoService;
    private static Logger logger;
    LogUtil logUtil = new LogUtil();
    static {
        logger = Logger.getLogger(EOP020Callback.class);
    }
    private static Date IN_TIME = null;
    private static String S_ORDER_CODE = "";//工单编号
    private static String S_PRODUCT_CODE = "";//产品编号
    private static String S_PRODUCT_TYPE= "";//产品类型
    private static String S_SFC_CODE = "";//总成编码
    private static String PRODUCTION_LINE  = "EOP";//产线号
    private static String LOCATION_CODE  = "EOP020";//工位号
    private static List list = null;
    public EOP020Callback(MiloService miloService,
                          ProductionOrdeInfoService productionOrdeInfoService,
                          PassingStationCollectionService passingStationCollectionService,
                          ParamCollectionService paramCollectionService,
                          CollectionParamConfService collectionParamConfService,
                          SerialNumbersConfService serialNumbersConfService,
                          EquipmentStatusService equipmentStatusService,
                          EquipmentAlarmService equipmentAlarmService,
                          MaterialTraceabilityService materialTraceabilityService,
                          EquipmentInfoService equipmentInfoService,
                          RepairManageInfoService repairManageInfoService,
                          LocationInfoService locationInfoService,
                          GreaseManageService greaseManageService,
                          ProductionOrderRecordsService productionOrderRecordsService,
                          ProductionOrderBatchInfoService productionOrderBatchInfoService) {
        this.miloService = miloService;
        this.productionOrdeInfoService = productionOrdeInfoService;
        this.passingStationCollectionService = passingStationCollectionService;
        this.paramCollectionService = paramCollectionService;
        this.collectionParamConfService = collectionParamConfService;
        this.serialNumbersConfService = serialNumbersConfService;
        this.equipmentStatusService = equipmentStatusService;
        this.equipmentAlarmService = equipmentAlarmService;
        this.materialTraceabilityService = materialTraceabilityService;
        this.equipmentInfoService = equipmentInfoService;
        this.repairManageInfoService = repairManageInfoService;
        this.locationInfoService = locationInfoService;
        this.greaseManageService = greaseManageService;
        this.productionOrderRecordsService = productionOrderRecordsService;
        this.productionOrderBatchInfoService = productionOrderBatchInfoService;
    }
    @Override
    public void onSubscribe(String identifier, Object value) {
        String ecpStr = "";//异常记录标记
        try {
            //心跳
            if(null != value && identifier.equals(OPCElement.EOP020_F_HEART_BEAT)){
                if( "false".equals(value.toString()))
                {
                    ReadWriteEntity entity = new ReadWriteEntity(OPCElement.EOP020_F_HEART_BEAT,true);
                    miloService.writeToOpcUa(entity);
                }
            }
            //PLC进站
            else if(null != value && identifier.equals(OPCElement.EOP020_J_PLC_START)){
                if("true".equals(value.toString())){
                    handleOrder();
                }
            }
            //PLC出站
            else if(null != value && identifier.equals(OPCElement.EOP020_J_PLC_FINISH)){
                if("true".equals(value.toString())){
                    handleFinsh();
                    handleInfo();
                    handleMaterial();
                }
            }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 {
        logger.info("handleOrder PC处理开始!");
        IN_TIME = DateTool.getLocalTimeForDate();
        List<String> lists = new ArrayList<>();
        lists.add(OPCElement.EOP020_S_ORDER_CODE);
        lists.add(OPCElement.EOP020_S_PRODUCT_CODE);
        lists.add(OPCElement.EOP020_S_SFC_CODE);
        List<ReadWriteEntity> returnLists= miloService.readFromOpcUa(lists);
        returnLists.forEach(element->{
            switch(element.getIdentifier()){
                case OPCElement.EOP020_S_ORDER_CODE:
                    S_ORDER_CODE = element.getValue().toString();
                    break;
                case OPCElement.EOP020_S_PRODUCT_CODE:
                    S_PRODUCT_TYPE = element.getValue().toString();
                    S_PRODUCT_CODE = GlobalVariable.PRODUCT_CODE_MAP.get(S_PRODUCT_TYPE);
                    break;
                case OPCElement.EOP020_S_SFC_CODE:
                    S_SFC_CODE = element.getValue().toString();
                    break;
                default:
                    break;
            }
        });
        ReadWriteEntity entity = new ReadWriteEntity(OPCElement.EOP020_J_PC_WRITE_ORDER,true);
        miloService.writeToOpcUa(entity);
        logger.info("handleOrder PC处理完成!");
    }
    public void handleFinsh() throws Exception {
        logger.info("handleFinsh PC处理开始!");
        String S_PRODUCT_STATE_CODE = miloService.
                readFromOpcUa(OPCElement.EOP020_S_PRODUCT_STATE_CODE)
                .getValue().toString();
        //处理过站信息
        PassingStationCollectionParam param = new PassingStationCollectionParam();
        param.setWorkOrderNo(S_ORDER_CODE);
        param.setProductCode(S_PRODUCT_CODE);
        param.setSfcCode(S_SFC_CODE);
        param.setProductionLine(PRODUCTION_LINE);
        param.setLocationCode(LOCATION_CODE);
        param.setInboundTime(IN_TIME);
        param.setOutboundTime(DateTool.getLocalTimeForDate());
        param.setOutRsSign(S_PRODUCT_STATE_CODE);//出站是否合格
        passingStationCollectionService.add(param);
        ReadWriteEntity entity = new ReadWriteEntity(OPCElement.EOP020_J_PC_FINISH,true);
        miloService.writeToOpcUa(entity);//写PC完成
        logger.info("handleFinsh PC处理完成!");
    }
    public void handleMaterial() {
        //查询批次上料信息
        ProductionOrderBatchInfoParam productionOrderBatchInfoParam = new ProductionOrderBatchInfoParam();
        productionOrderBatchInfoParam.setWorkOrderNo(S_ORDER_CODE);
        productionOrderBatchInfoParam.setLocationCode(LOCATION_CODE);
        List<ProductionOrderBatchInfoResult> list = productionOrderBatchInfoService.findListBySpec(productionOrderBatchInfoParam);
        for(int i=0;i<list.size();i++){
            ProductionOrderBatchInfoResult productionOrderBatchInfoResult = list.get(i);
            int remainingQuantity =  productionOrderBatchInfoResult.getResidueQuantity();//剩余数量
            if(remainingQuantity>0 ){
                //新增物料追溯
                MaterialTraceabilityParam materialTraceabilityParam = new MaterialTraceabilityParam();
                materialTraceabilityParam.setWorkOrderNo(S_ORDER_CODE);
                materialTraceabilityParam.setProductCode(S_PRODUCT_CODE);
                materialTraceabilityParam.setProductNo(S_SFC_CODE);
                materialTraceabilityParam.setLineCode(PRODUCTION_LINE);
                materialTraceabilityParam.setLocationCode(LOCATION_CODE);
                materialTraceabilityParam.setAssemblyQty(1);
                materialTraceabilityParam.setAssemblyTime(DateTool.getLocalTimeForDate());
                materialTraceabilityParam.setMaterialCode(productionOrderBatchInfoResult.getMaterialCode());//物料编码
                materialTraceabilityParam.setMaterialBatchNo(productionOrderBatchInfoResult.getBatch());//物料批次
                materialTraceabilityService.add(materialTraceabilityParam);
                //更新剩余数量
                productionOrderBatchInfoParam.setId(productionOrderBatchInfoResult.getId());
                productionOrderBatchInfoParam.setResidueQuantity(remainingQuantity-1);//剩余数量
                productionOrderBatchInfoService.update(productionOrderBatchInfoParam);
            }
        }
    }
    //PC读参数信息
    public void handleInfo() throws Exception {
        logger.info("handleInfo START!");
        if(null == list){
            CollectionParamConfParam collectionParamConfParam = new CollectionParamConfParam();
            collectionParamConfParam.setLocationCode(LOCATION_CODE);
            list = collectionParamConfService.findListBySpec(collectionParamConfParam);
        }
        if(null != list && !list.isEmpty()) {
            for (int i = 0; i < list.size(); i++) {
                CollectionParamConfResult result = (CollectionParamConfResult) list.get(i);
                String value = miloService.
                        readFromOpcUa(result.getGatherAddress())
                        .getValue().toString();//读参数值
                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);
                paramCollectionParam.setParamLower(result.getParamLower());
                paramCollectionParam.setParamUpper(result.getParamUpper());
                paramCollectionParam.setParamStandard(result.getParamCentral());
                paramCollectionParam.setCollectionTime(DateTool.getLocalTimeForDate());
                paramCollectionParam.setUnit(result.getUnit());
                paramCollectionService.add(paramCollectionParam);
            }
        }
        logger.info("handleInfo END!");
    }
}
guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/EOP030Callback.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,282 @@
package cn.stylefeng.guns.plcserver.callback;
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.model.params.ParamCollectionParam;
import cn.stylefeng.guns.modular.cm.paramCollection.service.ParamCollectionService;
import cn.stylefeng.guns.modular.cm.passingStationCollection.model.params.PassingStationCollectionParam;
import cn.stylefeng.guns.modular.cm.passingStationCollection.service.PassingStationCollectionService;
import cn.stylefeng.guns.modular.dq.materialTraceability.model.params.MaterialTraceabilityParam;
import cn.stylefeng.guns.modular.dq.materialTraceability.service.MaterialTraceabilityService;
import cn.stylefeng.guns.modular.em.equipmentAlarm.service.EquipmentAlarmService;
import cn.stylefeng.guns.modular.em.equipmentStatus.service.EquipmentStatusService;
import cn.stylefeng.guns.modular.gm.greaseManage.service.GreaseManageService;
import cn.stylefeng.guns.modular.om.productionOrdeInfo.service.ProductionOrdeInfoService;
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.model.params.ProductionOrderBatchInfoParam;
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.model.result.ProductionOrderBatchInfoResult;
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.service.ProductionOrderBatchInfoService;
import cn.stylefeng.guns.modular.om.productionOrderRecords.service.ProductionOrderRecordsService;
import cn.stylefeng.guns.modular.sc.repairManageInfo.service.RepairManageInfoService;
import cn.stylefeng.guns.modular.sc.serialNumbersConf.service.SerialNumbersConfService;
import cn.stylefeng.guns.plcserver.opc.GlobalVariable;
import cn.stylefeng.guns.plcserver.opc.OPCElement;
import cn.stylefeng.guns.plcserver.tool.DateTool;
import cn.stylefeng.guns.plcserver.tool.LogUtil;
import com.kangaroohy.milo.model.ReadWriteEntity;
import com.kangaroohy.milo.runner.subscription.SubscriptionCallback;
import com.kangaroohy.milo.service.MiloService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@Component
public class EOP030Callback implements SubscriptionCallback {
    public MiloService miloService;
    @Autowired
    public ProductionOrdeInfoService productionOrdeInfoService;
    @Autowired
    public PassingStationCollectionService passingStationCollectionService;
    @Autowired
    public ParamCollectionService paramCollectionService;
    @Autowired
    public CollectionParamConfService collectionParamConfService;
    @Autowired
    public SerialNumbersConfService serialNumbersConfService;
    @Autowired
    private EquipmentStatusService equipmentStatusService;
    @Autowired
    private EquipmentAlarmService equipmentAlarmService;
    @Autowired
    private MaterialTraceabilityService materialTraceabilityService;
    @Autowired
    private EquipmentInfoService equipmentInfoService;
    @Autowired
    private RepairManageInfoService repairManageInfoService;
    @Autowired
    private LocationInfoService locationInfoService;
    @Autowired
    private GreaseManageService greaseManageService;
    @Autowired
    private ProductionOrderRecordsService productionOrderRecordsService;
    @Autowired
    private ProductionOrderBatchInfoService productionOrderBatchInfoService;
    private static Logger logger;
    LogUtil logUtil = new LogUtil();
    static {
        logger = Logger.getLogger(EOP030Callback.class);
    }
    private static Date IN_TIME = null;
    private static String S_ORDER_CODE = "";//工单编号
    private static String S_PRODUCT_CODE = "";//产品编号
    private static String S_PRODUCT_TYPE= "";//产品类型
    private static String S_SFC_CODE = "";//总成编码
    private static String PRODUCTION_LINE  = "EOP";//产线号
    private static String LOCATION_CODE  = "EOP030";//工位号
    private static List list = null;
    public EOP030Callback(MiloService miloService,
                          ProductionOrdeInfoService productionOrdeInfoService,
                          PassingStationCollectionService passingStationCollectionService,
                          ParamCollectionService paramCollectionService,
                          CollectionParamConfService collectionParamConfService,
                          SerialNumbersConfService serialNumbersConfService,
                          EquipmentStatusService equipmentStatusService,
                          EquipmentAlarmService equipmentAlarmService,
                          MaterialTraceabilityService materialTraceabilityService,
                          EquipmentInfoService equipmentInfoService,
                          RepairManageInfoService repairManageInfoService,
                          LocationInfoService locationInfoService,
                          GreaseManageService greaseManageService,
                          ProductionOrderRecordsService productionOrderRecordsService,
                          ProductionOrderBatchInfoService productionOrderBatchInfoService) {
        this.miloService = miloService;
        this.productionOrdeInfoService = productionOrdeInfoService;
        this.passingStationCollectionService = passingStationCollectionService;
        this.paramCollectionService = paramCollectionService;
        this.collectionParamConfService = collectionParamConfService;
        this.serialNumbersConfService = serialNumbersConfService;
        this.equipmentStatusService = equipmentStatusService;
        this.equipmentAlarmService = equipmentAlarmService;
        this.materialTraceabilityService = materialTraceabilityService;
        this.equipmentInfoService = equipmentInfoService;
        this.repairManageInfoService = repairManageInfoService;
        this.locationInfoService = locationInfoService;
        this.greaseManageService = greaseManageService;
        this.productionOrderRecordsService = productionOrderRecordsService;
        this.productionOrderBatchInfoService = productionOrderBatchInfoService;
    }
    @Override
    public void onSubscribe(String identifier, Object value) {
        String ecpStr = "";//异常记录标记
        try {
            //心跳
            if(null != value && identifier.equals(OPCElement.EOP030_F_HEART_BEAT)){
                if( "false".equals(value.toString()))
                {
                    ReadWriteEntity entity = new ReadWriteEntity(OPCElement.EOP030_F_HEART_BEAT,true);
                    miloService.writeToOpcUa(entity);
                }
            }
            //PLC进站
            else if(null != value && identifier.equals(OPCElement.EOP030_J_PLC_START)){
                if("true".equals(value.toString())){
                    handleOrder();
                }
            }
            //PLC出站
            else if(null != value && identifier.equals(OPCElement.EOP030_J_PLC_FINISH)){
                if("true".equals(value.toString())){
                    handleFinsh();
                    handleInfo();
                    handleMaterial();
                }
            }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 {
        logger.info("handleOrder PC处理开始!");
        IN_TIME = DateTool.getLocalTimeForDate();
        List<String> lists = new ArrayList<>();
        lists.add(OPCElement.EOP030_S_ORDER_CODE);
        lists.add(OPCElement.EOP030_S_PRODUCT_CODE);
        lists.add(OPCElement.EOP030_S_SFC_CODE);
        List<ReadWriteEntity> returnLists= miloService.readFromOpcUa(lists);
        returnLists.forEach(element->{
            switch(element.getIdentifier()){
                case OPCElement.EOP030_S_ORDER_CODE:
                    S_ORDER_CODE = element.getValue().toString();
                    break;
                case OPCElement.EOP030_S_PRODUCT_CODE:
                    S_PRODUCT_TYPE = element.getValue().toString();
                    S_PRODUCT_CODE = GlobalVariable.PRODUCT_CODE_MAP.get(S_PRODUCT_TYPE);
                    break;
                case OPCElement.EOP030_S_SFC_CODE:
                    S_SFC_CODE = element.getValue().toString();
                    break;
                default:
                    break;
            }
        });
        ReadWriteEntity entity = new ReadWriteEntity(OPCElement.EOP030_J_PC_WRITE_ORDER,true);
        miloService.writeToOpcUa(entity);
        logger.info("handleOrder PC处理完成!");
    }
    public void handleFinsh() throws Exception {
        logger.info("handleFinsh PC处理开始!");
        String S_PRODUCT_STATE_CODE = miloService.
                readFromOpcUa(OPCElement.EOP030_S_PRODUCT_STATE_CODE)
                .getValue().toString();
        //处理过站信息
        PassingStationCollectionParam param = new PassingStationCollectionParam();
        param.setWorkOrderNo(S_ORDER_CODE);
        param.setProductCode(S_PRODUCT_CODE);
        param.setSfcCode(S_SFC_CODE);
        param.setProductionLine(PRODUCTION_LINE);
        param.setLocationCode(LOCATION_CODE);
        param.setInboundTime(IN_TIME);
        param.setOutboundTime(DateTool.getLocalTimeForDate());
        param.setOutRsSign(S_PRODUCT_STATE_CODE);//出站是否合格
        passingStationCollectionService.add(param);
        ReadWriteEntity entity = new ReadWriteEntity(OPCElement.EOP030_J_PC_FINISH,true);
        miloService.writeToOpcUa(entity);//写PC完成
        logger.info("handleFinsh PC处理完成!");
    }
    public void handleMaterial() {
        //查询批次上料信息
        ProductionOrderBatchInfoParam productionOrderBatchInfoParam = new ProductionOrderBatchInfoParam();
        productionOrderBatchInfoParam.setWorkOrderNo(S_ORDER_CODE);
        productionOrderBatchInfoParam.setLocationCode(LOCATION_CODE);
        List<ProductionOrderBatchInfoResult> list = productionOrderBatchInfoService.findListBySpec(productionOrderBatchInfoParam);
        for(int i=0;i<list.size();i++){
            ProductionOrderBatchInfoResult productionOrderBatchInfoResult = list.get(i);
            int remainingQuantity =  productionOrderBatchInfoResult.getResidueQuantity();//剩余数量
            if(remainingQuantity>0 ){
                //新增物料追溯
                MaterialTraceabilityParam materialTraceabilityParam = new MaterialTraceabilityParam();
                materialTraceabilityParam.setWorkOrderNo(S_ORDER_CODE);
                materialTraceabilityParam.setProductCode(S_PRODUCT_CODE);
                materialTraceabilityParam.setProductNo(S_SFC_CODE);
                materialTraceabilityParam.setLineCode(PRODUCTION_LINE);
                materialTraceabilityParam.setLocationCode(LOCATION_CODE);
                materialTraceabilityParam.setAssemblyQty(1);
                materialTraceabilityParam.setAssemblyTime(DateTool.getLocalTimeForDate());
                materialTraceabilityParam.setMaterialCode(productionOrderBatchInfoResult.getMaterialCode());//物料编码
                materialTraceabilityParam.setMaterialBatchNo(productionOrderBatchInfoResult.getBatch());//物料批次
                materialTraceabilityService.add(materialTraceabilityParam);
                //更新剩余数量
                productionOrderBatchInfoParam.setId(productionOrderBatchInfoResult.getId());
                productionOrderBatchInfoParam.setResidueQuantity(remainingQuantity-1);//剩余数量
                productionOrderBatchInfoService.update(productionOrderBatchInfoParam);
            }
        }
    }
    //PC读参数信息
    public void handleInfo() throws Exception {
        logger.info("handleInfo START!");
        if(null == list){
            CollectionParamConfParam collectionParamConfParam = new CollectionParamConfParam();
            collectionParamConfParam.setLocationCode(LOCATION_CODE);
            list = collectionParamConfService.findListBySpec(collectionParamConfParam);
        }
        if(null != list && !list.isEmpty()) {
            for (int i = 0; i < list.size(); i++) {
                CollectionParamConfResult result = (CollectionParamConfResult) list.get(i);
                String value = miloService.
                        readFromOpcUa(result.getGatherAddress())
                        .getValue().toString();//读参数值
                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);
                paramCollectionParam.setParamLower(result.getParamLower());
                paramCollectionParam.setParamUpper(result.getParamUpper());
                paramCollectionParam.setParamStandard(result.getParamCentral());
                paramCollectionParam.setCollectionTime(DateTool.getLocalTimeForDate());
                paramCollectionParam.setUnit(result.getUnit());
                paramCollectionService.add(paramCollectionParam);
            }
        }
        logger.info("handleInfo END!");
    }
}
guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/EOP040Callback.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,282 @@
package cn.stylefeng.guns.plcserver.callback;
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.model.params.ParamCollectionParam;
import cn.stylefeng.guns.modular.cm.paramCollection.service.ParamCollectionService;
import cn.stylefeng.guns.modular.cm.passingStationCollection.model.params.PassingStationCollectionParam;
import cn.stylefeng.guns.modular.cm.passingStationCollection.service.PassingStationCollectionService;
import cn.stylefeng.guns.modular.dq.materialTraceability.model.params.MaterialTraceabilityParam;
import cn.stylefeng.guns.modular.dq.materialTraceability.service.MaterialTraceabilityService;
import cn.stylefeng.guns.modular.em.equipmentAlarm.service.EquipmentAlarmService;
import cn.stylefeng.guns.modular.em.equipmentStatus.service.EquipmentStatusService;
import cn.stylefeng.guns.modular.gm.greaseManage.service.GreaseManageService;
import cn.stylefeng.guns.modular.om.productionOrdeInfo.service.ProductionOrdeInfoService;
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.model.params.ProductionOrderBatchInfoParam;
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.model.result.ProductionOrderBatchInfoResult;
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.service.ProductionOrderBatchInfoService;
import cn.stylefeng.guns.modular.om.productionOrderRecords.service.ProductionOrderRecordsService;
import cn.stylefeng.guns.modular.sc.repairManageInfo.service.RepairManageInfoService;
import cn.stylefeng.guns.modular.sc.serialNumbersConf.service.SerialNumbersConfService;
import cn.stylefeng.guns.plcserver.opc.GlobalVariable;
import cn.stylefeng.guns.plcserver.opc.OPCElement;
import cn.stylefeng.guns.plcserver.tool.DateTool;
import cn.stylefeng.guns.plcserver.tool.LogUtil;
import com.kangaroohy.milo.model.ReadWriteEntity;
import com.kangaroohy.milo.runner.subscription.SubscriptionCallback;
import com.kangaroohy.milo.service.MiloService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@Component
public class EOP040Callback implements SubscriptionCallback {
    public MiloService miloService;
    @Autowired
    public ProductionOrdeInfoService productionOrdeInfoService;
    @Autowired
    public PassingStationCollectionService passingStationCollectionService;
    @Autowired
    public ParamCollectionService paramCollectionService;
    @Autowired
    public CollectionParamConfService collectionParamConfService;
    @Autowired
    public SerialNumbersConfService serialNumbersConfService;
    @Autowired
    private EquipmentStatusService equipmentStatusService;
    @Autowired
    private EquipmentAlarmService equipmentAlarmService;
    @Autowired
    private MaterialTraceabilityService materialTraceabilityService;
    @Autowired
    private EquipmentInfoService equipmentInfoService;
    @Autowired
    private RepairManageInfoService repairManageInfoService;
    @Autowired
    private LocationInfoService locationInfoService;
    @Autowired
    private GreaseManageService greaseManageService;
    @Autowired
    private ProductionOrderRecordsService productionOrderRecordsService;
    @Autowired
    private ProductionOrderBatchInfoService productionOrderBatchInfoService;
    private static Logger logger;
    LogUtil logUtil = new LogUtil();
    static {
        logger = Logger.getLogger(EOP040Callback.class);
    }
    private static Date IN_TIME = null;
    private static String S_ORDER_CODE = "";//工单编号
    private static String S_PRODUCT_CODE = "";//产品编号
    private static String S_PRODUCT_TYPE= "";//产品类型
    private static String S_SFC_CODE = "";//总成编码
    private static String PRODUCTION_LINE  = "EOP";//产线号
    private static String LOCATION_CODE  = "EOP040";//工位号
    private static List list = null;
    public EOP040Callback(MiloService miloService,
                          ProductionOrdeInfoService productionOrdeInfoService,
                          PassingStationCollectionService passingStationCollectionService,
                          ParamCollectionService paramCollectionService,
                          CollectionParamConfService collectionParamConfService,
                          SerialNumbersConfService serialNumbersConfService,
                          EquipmentStatusService equipmentStatusService,
                          EquipmentAlarmService equipmentAlarmService,
                          MaterialTraceabilityService materialTraceabilityService,
                          EquipmentInfoService equipmentInfoService,
                          RepairManageInfoService repairManageInfoService,
                          LocationInfoService locationInfoService,
                          GreaseManageService greaseManageService,
                          ProductionOrderRecordsService productionOrderRecordsService,
                          ProductionOrderBatchInfoService productionOrderBatchInfoService) {
        this.miloService = miloService;
        this.productionOrdeInfoService = productionOrdeInfoService;
        this.passingStationCollectionService = passingStationCollectionService;
        this.paramCollectionService = paramCollectionService;
        this.collectionParamConfService = collectionParamConfService;
        this.serialNumbersConfService = serialNumbersConfService;
        this.equipmentStatusService = equipmentStatusService;
        this.equipmentAlarmService = equipmentAlarmService;
        this.materialTraceabilityService = materialTraceabilityService;
        this.equipmentInfoService = equipmentInfoService;
        this.repairManageInfoService = repairManageInfoService;
        this.locationInfoService = locationInfoService;
        this.greaseManageService = greaseManageService;
        this.productionOrderRecordsService = productionOrderRecordsService;
        this.productionOrderBatchInfoService = productionOrderBatchInfoService;
    }
    @Override
    public void onSubscribe(String identifier, Object value) {
        String ecpStr = "";//异常记录标记
        try {
            //心跳
            if(null != value && identifier.equals(OPCElement.EOP040_F_HEART_BEAT)){
                if( "false".equals(value.toString()))
                {
                    ReadWriteEntity entity = new ReadWriteEntity(OPCElement.EOP040_F_HEART_BEAT,true);
                    miloService.writeToOpcUa(entity);
                }
            }
            //PLC进站
            else if(null != value && identifier.equals(OPCElement.EOP040_J_PLC_START)){
                if("true".equals(value.toString())){
                    handleOrder();
                }
            }
            //PLC出站
            else if(null != value && identifier.equals(OPCElement.EOP040_J_PLC_FINISH)){
                if("true".equals(value.toString())){
                    handleFinsh();
                    handleInfo();
                    handleMaterial();
                }
            }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 {
        logger.info("handleOrder PC处理开始!");
        IN_TIME = DateTool.getLocalTimeForDate();
        List<String> lists = new ArrayList<>();
        lists.add(OPCElement.EOP040_S_ORDER_CODE);
        lists.add(OPCElement.EOP040_S_PRODUCT_CODE);
        lists.add(OPCElement.EOP040_S_SFC_CODE);
        List<ReadWriteEntity> returnLists= miloService.readFromOpcUa(lists);
        returnLists.forEach(element->{
            switch(element.getIdentifier()){
                case OPCElement.EOP040_S_ORDER_CODE:
                    S_ORDER_CODE = element.getValue().toString();
                    break;
                case OPCElement.EOP040_S_PRODUCT_CODE:
                    S_PRODUCT_TYPE = element.getValue().toString();
                    S_PRODUCT_CODE = GlobalVariable.PRODUCT_CODE_MAP.get(S_PRODUCT_TYPE);
                    break;
                case OPCElement.EOP040_S_SFC_CODE:
                    S_SFC_CODE = element.getValue().toString();
                    break;
                default:
                    break;
            }
        });
        ReadWriteEntity entity = new ReadWriteEntity(OPCElement.EOP040_J_PC_WRITE_ORDER,true);
        miloService.writeToOpcUa(entity);
        logger.info("handleOrder PC处理完成!");
    }
    public void handleFinsh() throws Exception {
        logger.info("handleFinsh PC处理开始!");
        String S_PRODUCT_STATE_CODE = miloService.
                readFromOpcUa(OPCElement.EOP040_S_PRODUCT_STATE_CODE)
                .getValue().toString();
        //处理过站信息
        PassingStationCollectionParam param = new PassingStationCollectionParam();
        param.setWorkOrderNo(S_ORDER_CODE);
        param.setProductCode(S_PRODUCT_CODE);
        param.setSfcCode(S_SFC_CODE);
        param.setProductionLine(PRODUCTION_LINE);
        param.setLocationCode(LOCATION_CODE);
        param.setInboundTime(IN_TIME);
        param.setOutboundTime(DateTool.getLocalTimeForDate());
        param.setOutRsSign(S_PRODUCT_STATE_CODE);//出站是否合格
        passingStationCollectionService.add(param);
        ReadWriteEntity entity = new ReadWriteEntity(OPCElement.EOP040_J_PC_FINISH,true);
        miloService.writeToOpcUa(entity);//写PC完成
        logger.info("handleFinsh PC处理完成!");
    }
    public void handleMaterial() {
        //查询批次上料信息
        ProductionOrderBatchInfoParam productionOrderBatchInfoParam = new ProductionOrderBatchInfoParam();
        productionOrderBatchInfoParam.setWorkOrderNo(S_ORDER_CODE);
        productionOrderBatchInfoParam.setLocationCode(LOCATION_CODE);
        List<ProductionOrderBatchInfoResult> list = productionOrderBatchInfoService.findListBySpec(productionOrderBatchInfoParam);
        for(int i=0;i<list.size();i++){
            ProductionOrderBatchInfoResult productionOrderBatchInfoResult = list.get(i);
            int remainingQuantity =  productionOrderBatchInfoResult.getResidueQuantity();//剩余数量
            if(remainingQuantity>0 ){
                //新增物料追溯
                MaterialTraceabilityParam materialTraceabilityParam = new MaterialTraceabilityParam();
                materialTraceabilityParam.setWorkOrderNo(S_ORDER_CODE);
                materialTraceabilityParam.setProductCode(S_PRODUCT_CODE);
                materialTraceabilityParam.setProductNo(S_SFC_CODE);
                materialTraceabilityParam.setLineCode(PRODUCTION_LINE);
                materialTraceabilityParam.setLocationCode(LOCATION_CODE);
                materialTraceabilityParam.setAssemblyQty(1);
                materialTraceabilityParam.setAssemblyTime(DateTool.getLocalTimeForDate());
                materialTraceabilityParam.setMaterialCode(productionOrderBatchInfoResult.getMaterialCode());//物料编码
                materialTraceabilityParam.setMaterialBatchNo(productionOrderBatchInfoResult.getBatch());//物料批次
                materialTraceabilityService.add(materialTraceabilityParam);
                //更新剩余数量
                productionOrderBatchInfoParam.setId(productionOrderBatchInfoResult.getId());
                productionOrderBatchInfoParam.setResidueQuantity(remainingQuantity-1);//剩余数量
                productionOrderBatchInfoService.update(productionOrderBatchInfoParam);
            }
        }
    }
    //PC读参数信息
    public void handleInfo() throws Exception {
        logger.info("handleInfo START!");
        if(null == list){
            CollectionParamConfParam collectionParamConfParam = new CollectionParamConfParam();
            collectionParamConfParam.setLocationCode(LOCATION_CODE);
            list = collectionParamConfService.findListBySpec(collectionParamConfParam);
        }
        if(null != list && !list.isEmpty()) {
            for (int i = 0; i < list.size(); i++) {
                CollectionParamConfResult result = (CollectionParamConfResult) list.get(i);
                String value = miloService.
                        readFromOpcUa(result.getGatherAddress())
                        .getValue().toString();//读参数值
                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);
                paramCollectionParam.setParamLower(result.getParamLower());
                paramCollectionParam.setParamUpper(result.getParamUpper());
                paramCollectionParam.setParamStandard(result.getParamCentral());
                paramCollectionParam.setCollectionTime(DateTool.getLocalTimeForDate());
                paramCollectionParam.setUnit(result.getUnit());
                paramCollectionService.add(paramCollectionParam);
            }
        }
        logger.info("handleInfo END!");
    }
}
guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/EOP050Callback.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,282 @@
package cn.stylefeng.guns.plcserver.callback;
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.model.params.ParamCollectionParam;
import cn.stylefeng.guns.modular.cm.paramCollection.service.ParamCollectionService;
import cn.stylefeng.guns.modular.cm.passingStationCollection.model.params.PassingStationCollectionParam;
import cn.stylefeng.guns.modular.cm.passingStationCollection.service.PassingStationCollectionService;
import cn.stylefeng.guns.modular.dq.materialTraceability.model.params.MaterialTraceabilityParam;
import cn.stylefeng.guns.modular.dq.materialTraceability.service.MaterialTraceabilityService;
import cn.stylefeng.guns.modular.em.equipmentAlarm.service.EquipmentAlarmService;
import cn.stylefeng.guns.modular.em.equipmentStatus.service.EquipmentStatusService;
import cn.stylefeng.guns.modular.gm.greaseManage.service.GreaseManageService;
import cn.stylefeng.guns.modular.om.productionOrdeInfo.service.ProductionOrdeInfoService;
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.model.params.ProductionOrderBatchInfoParam;
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.model.result.ProductionOrderBatchInfoResult;
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.service.ProductionOrderBatchInfoService;
import cn.stylefeng.guns.modular.om.productionOrderRecords.service.ProductionOrderRecordsService;
import cn.stylefeng.guns.modular.sc.repairManageInfo.service.RepairManageInfoService;
import cn.stylefeng.guns.modular.sc.serialNumbersConf.service.SerialNumbersConfService;
import cn.stylefeng.guns.plcserver.opc.GlobalVariable;
import cn.stylefeng.guns.plcserver.opc.OPCElement;
import cn.stylefeng.guns.plcserver.tool.DateTool;
import cn.stylefeng.guns.plcserver.tool.LogUtil;
import com.kangaroohy.milo.model.ReadWriteEntity;
import com.kangaroohy.milo.runner.subscription.SubscriptionCallback;
import com.kangaroohy.milo.service.MiloService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@Component
public class EOP050Callback implements SubscriptionCallback {
    public MiloService miloService;
    @Autowired
    public ProductionOrdeInfoService productionOrdeInfoService;
    @Autowired
    public PassingStationCollectionService passingStationCollectionService;
    @Autowired
    public ParamCollectionService paramCollectionService;
    @Autowired
    public CollectionParamConfService collectionParamConfService;
    @Autowired
    public SerialNumbersConfService serialNumbersConfService;
    @Autowired
    private EquipmentStatusService equipmentStatusService;
    @Autowired
    private EquipmentAlarmService equipmentAlarmService;
    @Autowired
    private MaterialTraceabilityService materialTraceabilityService;
    @Autowired
    private EquipmentInfoService equipmentInfoService;
    @Autowired
    private RepairManageInfoService repairManageInfoService;
    @Autowired
    private LocationInfoService locationInfoService;
    @Autowired
    private GreaseManageService greaseManageService;
    @Autowired
    private ProductionOrderRecordsService productionOrderRecordsService;
    @Autowired
    private ProductionOrderBatchInfoService productionOrderBatchInfoService;
    private static Logger logger;
    LogUtil logUtil = new LogUtil();
    static {
        logger = Logger.getLogger(EOP050Callback.class);
    }
    private static Date IN_TIME = null;
    private static String S_ORDER_CODE = "";//工单编号
    private static String S_PRODUCT_CODE = "";//产品编号
    private static String S_PRODUCT_TYPE= "";//产品类型
    private static String S_SFC_CODE = "";//总成编码
    private static String PRODUCTION_LINE  = "EOP";//产线号
    private static String LOCATION_CODE  = "EOP050";//工位号
    private static List list = null;
    public EOP050Callback(MiloService miloService,
                          ProductionOrdeInfoService productionOrdeInfoService,
                          PassingStationCollectionService passingStationCollectionService,
                          ParamCollectionService paramCollectionService,
                          CollectionParamConfService collectionParamConfService,
                          SerialNumbersConfService serialNumbersConfService,
                          EquipmentStatusService equipmentStatusService,
                          EquipmentAlarmService equipmentAlarmService,
                          MaterialTraceabilityService materialTraceabilityService,
                          EquipmentInfoService equipmentInfoService,
                          RepairManageInfoService repairManageInfoService,
                          LocationInfoService locationInfoService,
                          GreaseManageService greaseManageService,
                          ProductionOrderRecordsService productionOrderRecordsService,
                          ProductionOrderBatchInfoService productionOrderBatchInfoService) {
        this.miloService = miloService;
        this.productionOrdeInfoService = productionOrdeInfoService;
        this.passingStationCollectionService = passingStationCollectionService;
        this.paramCollectionService = paramCollectionService;
        this.collectionParamConfService = collectionParamConfService;
        this.serialNumbersConfService = serialNumbersConfService;
        this.equipmentStatusService = equipmentStatusService;
        this.equipmentAlarmService = equipmentAlarmService;
        this.materialTraceabilityService = materialTraceabilityService;
        this.equipmentInfoService = equipmentInfoService;
        this.repairManageInfoService = repairManageInfoService;
        this.locationInfoService = locationInfoService;
        this.greaseManageService = greaseManageService;
        this.productionOrderRecordsService = productionOrderRecordsService;
        this.productionOrderBatchInfoService = productionOrderBatchInfoService;
    }
    @Override
    public void onSubscribe(String identifier, Object value) {
        String ecpStr = "";//异常记录标记
        try {
            //心跳
            if(null != value && identifier.equals(OPCElement.EOP050_F_HEART_BEAT)){
                if( "false".equals(value.toString()))
                {
                    ReadWriteEntity entity = new ReadWriteEntity(OPCElement.EOP050_F_HEART_BEAT,true);
                    miloService.writeToOpcUa(entity);
                }
            }
            //PLC进站
            else if(null != value && identifier.equals(OPCElement.EOP050_J_PLC_START)){
                if("true".equals(value.toString())){
                    handleOrder();
                }
            }
            //PLC出站
            else if(null != value && identifier.equals(OPCElement.EOP050_J_PLC_FINISH)){
                if("true".equals(value.toString())){
                    handleFinsh();
                    handleInfo();
                    handleMaterial();
                }
            }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 {
        logger.info("handleOrder PC处理开始!");
        IN_TIME = DateTool.getLocalTimeForDate();
        List<String> lists = new ArrayList<>();
        lists.add(OPCElement.EOP050_S_ORDER_CODE);
        lists.add(OPCElement.EOP050_S_PRODUCT_CODE);
        lists.add(OPCElement.EOP050_S_SFC_CODE);
        List<ReadWriteEntity> returnLists= miloService.readFromOpcUa(lists);
        returnLists.forEach(element->{
            switch(element.getIdentifier()){
                case OPCElement.EOP050_S_ORDER_CODE:
                    S_ORDER_CODE = element.getValue().toString();
                    break;
                case OPCElement.EOP050_S_PRODUCT_CODE:
                    S_PRODUCT_TYPE = element.getValue().toString();
                    S_PRODUCT_CODE = GlobalVariable.PRODUCT_CODE_MAP.get(S_PRODUCT_TYPE);
                    break;
                case OPCElement.EOP050_S_SFC_CODE:
                    S_SFC_CODE = element.getValue().toString();
                    break;
                default:
                    break;
            }
        });
        ReadWriteEntity entity = new ReadWriteEntity(OPCElement.EOP050_J_PC_WRITE_ORDER,true);
        miloService.writeToOpcUa(entity);
        logger.info("handleOrder PC处理完成!");
    }
    public void handleFinsh() throws Exception {
        logger.info("handleFinsh PC处理开始!");
        String S_PRODUCT_STATE_CODE = miloService.
                readFromOpcUa(OPCElement.EOP050_S_PRODUCT_STATE_CODE)
                .getValue().toString();
        //处理过站信息
        PassingStationCollectionParam param = new PassingStationCollectionParam();
        param.setWorkOrderNo(S_ORDER_CODE);
        param.setProductCode(S_PRODUCT_CODE);
        param.setSfcCode(S_SFC_CODE);
        param.setProductionLine(PRODUCTION_LINE);
        param.setLocationCode(LOCATION_CODE);
        param.setInboundTime(IN_TIME);
        param.setOutboundTime(DateTool.getLocalTimeForDate());
        param.setOutRsSign(S_PRODUCT_STATE_CODE);//出站是否合格
        passingStationCollectionService.add(param);
        ReadWriteEntity entity = new ReadWriteEntity(OPCElement.EOP050_J_PC_FINISH,true);
        miloService.writeToOpcUa(entity);//写PC完成
        logger.info("handleFinsh PC处理完成!");
    }
    public void handleMaterial() {
        //查询批次上料信息
        ProductionOrderBatchInfoParam productionOrderBatchInfoParam = new ProductionOrderBatchInfoParam();
        productionOrderBatchInfoParam.setWorkOrderNo(S_ORDER_CODE);
        productionOrderBatchInfoParam.setLocationCode(LOCATION_CODE);
        List<ProductionOrderBatchInfoResult> list = productionOrderBatchInfoService.findListBySpec(productionOrderBatchInfoParam);
        for(int i=0;i<list.size();i++){
            ProductionOrderBatchInfoResult productionOrderBatchInfoResult = list.get(i);
            int remainingQuantity =  productionOrderBatchInfoResult.getResidueQuantity();//剩余数量
            if(remainingQuantity>0 ){
                //新增物料追溯
                MaterialTraceabilityParam materialTraceabilityParam = new MaterialTraceabilityParam();
                materialTraceabilityParam.setWorkOrderNo(S_ORDER_CODE);
                materialTraceabilityParam.setProductCode(S_PRODUCT_CODE);
                materialTraceabilityParam.setProductNo(S_SFC_CODE);
                materialTraceabilityParam.setLineCode(PRODUCTION_LINE);
                materialTraceabilityParam.setLocationCode(LOCATION_CODE);
                materialTraceabilityParam.setAssemblyQty(1);
                materialTraceabilityParam.setAssemblyTime(DateTool.getLocalTimeForDate());
                materialTraceabilityParam.setMaterialCode(productionOrderBatchInfoResult.getMaterialCode());//物料编码
                materialTraceabilityParam.setMaterialBatchNo(productionOrderBatchInfoResult.getBatch());//物料批次
                materialTraceabilityService.add(materialTraceabilityParam);
                //更新剩余数量
                productionOrderBatchInfoParam.setId(productionOrderBatchInfoResult.getId());
                productionOrderBatchInfoParam.setResidueQuantity(remainingQuantity-1);//剩余数量
                productionOrderBatchInfoService.update(productionOrderBatchInfoParam);
            }
        }
    }
    //PC读参数信息
    public void handleInfo() throws Exception {
        logger.info("handleInfo START!");
        if(null == list){
            CollectionParamConfParam collectionParamConfParam = new CollectionParamConfParam();
            collectionParamConfParam.setLocationCode(LOCATION_CODE);
            list = collectionParamConfService.findListBySpec(collectionParamConfParam);
        }
        if(null != list && !list.isEmpty()) {
            for (int i = 0; i < list.size(); i++) {
                CollectionParamConfResult result = (CollectionParamConfResult) list.get(i);
                String value = miloService.
                        readFromOpcUa(result.getGatherAddress())
                        .getValue().toString();//读参数值
                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);
                paramCollectionParam.setParamLower(result.getParamLower());
                paramCollectionParam.setParamUpper(result.getParamUpper());
                paramCollectionParam.setParamStandard(result.getParamCentral());
                paramCollectionParam.setCollectionTime(DateTool.getLocalTimeForDate());
                paramCollectionParam.setUnit(result.getUnit());
                paramCollectionService.add(paramCollectionParam);
            }
        }
        logger.info("handleInfo END!");
    }
}
guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/EOP060Callback.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,282 @@
package cn.stylefeng.guns.plcserver.callback;
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.model.params.ParamCollectionParam;
import cn.stylefeng.guns.modular.cm.paramCollection.service.ParamCollectionService;
import cn.stylefeng.guns.modular.cm.passingStationCollection.model.params.PassingStationCollectionParam;
import cn.stylefeng.guns.modular.cm.passingStationCollection.service.PassingStationCollectionService;
import cn.stylefeng.guns.modular.dq.materialTraceability.model.params.MaterialTraceabilityParam;
import cn.stylefeng.guns.modular.dq.materialTraceability.service.MaterialTraceabilityService;
import cn.stylefeng.guns.modular.em.equipmentAlarm.service.EquipmentAlarmService;
import cn.stylefeng.guns.modular.em.equipmentStatus.service.EquipmentStatusService;
import cn.stylefeng.guns.modular.gm.greaseManage.service.GreaseManageService;
import cn.stylefeng.guns.modular.om.productionOrdeInfo.service.ProductionOrdeInfoService;
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.model.params.ProductionOrderBatchInfoParam;
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.model.result.ProductionOrderBatchInfoResult;
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.service.ProductionOrderBatchInfoService;
import cn.stylefeng.guns.modular.om.productionOrderRecords.service.ProductionOrderRecordsService;
import cn.stylefeng.guns.modular.sc.repairManageInfo.service.RepairManageInfoService;
import cn.stylefeng.guns.modular.sc.serialNumbersConf.service.SerialNumbersConfService;
import cn.stylefeng.guns.plcserver.opc.GlobalVariable;
import cn.stylefeng.guns.plcserver.opc.OPCElement;
import cn.stylefeng.guns.plcserver.tool.DateTool;
import cn.stylefeng.guns.plcserver.tool.LogUtil;
import com.kangaroohy.milo.model.ReadWriteEntity;
import com.kangaroohy.milo.runner.subscription.SubscriptionCallback;
import com.kangaroohy.milo.service.MiloService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@Component
public class EOP060Callback implements SubscriptionCallback {
    public MiloService miloService;
    @Autowired
    public ProductionOrdeInfoService productionOrdeInfoService;
    @Autowired
    public PassingStationCollectionService passingStationCollectionService;
    @Autowired
    public ParamCollectionService paramCollectionService;
    @Autowired
    public CollectionParamConfService collectionParamConfService;
    @Autowired
    public SerialNumbersConfService serialNumbersConfService;
    @Autowired
    private EquipmentStatusService equipmentStatusService;
    @Autowired
    private EquipmentAlarmService equipmentAlarmService;
    @Autowired
    private MaterialTraceabilityService materialTraceabilityService;
    @Autowired
    private EquipmentInfoService equipmentInfoService;
    @Autowired
    private RepairManageInfoService repairManageInfoService;
    @Autowired
    private LocationInfoService locationInfoService;
    @Autowired
    private GreaseManageService greaseManageService;
    @Autowired
    private ProductionOrderRecordsService productionOrderRecordsService;
    @Autowired
    private ProductionOrderBatchInfoService productionOrderBatchInfoService;
    private static Logger logger;
    LogUtil logUtil = new LogUtil();
    static {
        logger = Logger.getLogger(EOP060Callback.class);
    }
    private static Date IN_TIME = null;
    private static String S_ORDER_CODE = "";//工单编号
    private static String S_PRODUCT_CODE = "";//产品编号
    private static String S_PRODUCT_TYPE= "";//产品类型
    private static String S_SFC_CODE = "";//总成编码
    private static String PRODUCTION_LINE  = "EOP";//产线号
    private static String LOCATION_CODE  = "EOP060";//工位号
    private static List list = null;
    public EOP060Callback(MiloService miloService,
                          ProductionOrdeInfoService productionOrdeInfoService,
                          PassingStationCollectionService passingStationCollectionService,
                          ParamCollectionService paramCollectionService,
                          CollectionParamConfService collectionParamConfService,
                          SerialNumbersConfService serialNumbersConfService,
                          EquipmentStatusService equipmentStatusService,
                          EquipmentAlarmService equipmentAlarmService,
                          MaterialTraceabilityService materialTraceabilityService,
                          EquipmentInfoService equipmentInfoService,
                          RepairManageInfoService repairManageInfoService,
                          LocationInfoService locationInfoService,
                          GreaseManageService greaseManageService,
                          ProductionOrderRecordsService productionOrderRecordsService,
                          ProductionOrderBatchInfoService productionOrderBatchInfoService) {
        this.miloService = miloService;
        this.productionOrdeInfoService = productionOrdeInfoService;
        this.passingStationCollectionService = passingStationCollectionService;
        this.paramCollectionService = paramCollectionService;
        this.collectionParamConfService = collectionParamConfService;
        this.serialNumbersConfService = serialNumbersConfService;
        this.equipmentStatusService = equipmentStatusService;
        this.equipmentAlarmService = equipmentAlarmService;
        this.materialTraceabilityService = materialTraceabilityService;
        this.equipmentInfoService = equipmentInfoService;
        this.repairManageInfoService = repairManageInfoService;
        this.locationInfoService = locationInfoService;
        this.greaseManageService = greaseManageService;
        this.productionOrderRecordsService = productionOrderRecordsService;
        this.productionOrderBatchInfoService = productionOrderBatchInfoService;
    }
    @Override
    public void onSubscribe(String identifier, Object value) {
        String ecpStr = "";//异常记录标记
        try {
            //心跳
            if(null != value && identifier.equals(OPCElement.EOP060_F_HEART_BEAT)){
                if( "false".equals(value.toString()))
                {
                    ReadWriteEntity entity = new ReadWriteEntity(OPCElement.EOP060_F_HEART_BEAT,true);
                    miloService.writeToOpcUa(entity);
                }
            }
            //PLC进站
            else if(null != value && identifier.equals(OPCElement.EOP060_J_PLC_START)){
                if("true".equals(value.toString())){
                    handleOrder();
                }
            }
            //PLC出站
            else if(null != value && identifier.equals(OPCElement.EOP060_J_PLC_FINISH)){
                if("true".equals(value.toString())){
                    handleFinsh();
                    handleInfo();
                    handleMaterial();
                }
            }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 {
        logger.info("handleOrder PC处理开始!");
        IN_TIME = DateTool.getLocalTimeForDate();
        List<String> lists = new ArrayList<>();
        lists.add(OPCElement.EOP060_S_ORDER_CODE);
        lists.add(OPCElement.EOP060_S_PRODUCT_CODE);
        lists.add(OPCElement.EOP060_S_SFC_CODE);
        List<ReadWriteEntity> returnLists= miloService.readFromOpcUa(lists);
        returnLists.forEach(element->{
            switch(element.getIdentifier()){
                case OPCElement.EOP060_S_ORDER_CODE:
                    S_ORDER_CODE = element.getValue().toString();
                    break;
                case OPCElement.EOP060_S_PRODUCT_CODE:
                    S_PRODUCT_TYPE = element.getValue().toString();
                    S_PRODUCT_CODE = GlobalVariable.PRODUCT_CODE_MAP.get(S_PRODUCT_TYPE);
                    break;
                case OPCElement.EOP060_S_SFC_CODE:
                    S_SFC_CODE = element.getValue().toString();
                    break;
                default:
                    break;
            }
        });
        ReadWriteEntity entity = new ReadWriteEntity(OPCElement.EOP060_J_PC_WRITE_ORDER,true);
        miloService.writeToOpcUa(entity);
        logger.info("handleOrder PC处理完成!");
    }
    public void handleFinsh() throws Exception {
        logger.info("handleFinsh PC处理开始!");
        String S_PRODUCT_STATE_CODE = miloService.
                readFromOpcUa(OPCElement.EOP060_S_PRODUCT_STATE_CODE)
                .getValue().toString();
        //处理过站信息
        PassingStationCollectionParam param = new PassingStationCollectionParam();
        param.setWorkOrderNo(S_ORDER_CODE);
        param.setProductCode(S_PRODUCT_CODE);
        param.setSfcCode(S_SFC_CODE);
        param.setProductionLine(PRODUCTION_LINE);
        param.setLocationCode(LOCATION_CODE);
        param.setInboundTime(IN_TIME);
        param.setOutboundTime(DateTool.getLocalTimeForDate());
        param.setOutRsSign(S_PRODUCT_STATE_CODE);//出站是否合格
        passingStationCollectionService.add(param);
        ReadWriteEntity entity = new ReadWriteEntity(OPCElement.EOP060_J_PC_FINISH,true);
        miloService.writeToOpcUa(entity);//写PC完成
        logger.info("handleFinsh PC处理完成!");
    }
    public void handleMaterial() {
        //查询批次上料信息
        ProductionOrderBatchInfoParam productionOrderBatchInfoParam = new ProductionOrderBatchInfoParam();
        productionOrderBatchInfoParam.setWorkOrderNo(S_ORDER_CODE);
        productionOrderBatchInfoParam.setLocationCode(LOCATION_CODE);
        List<ProductionOrderBatchInfoResult> list = productionOrderBatchInfoService.findListBySpec(productionOrderBatchInfoParam);
        for(int i=0;i<list.size();i++){
            ProductionOrderBatchInfoResult productionOrderBatchInfoResult = list.get(i);
            int remainingQuantity =  productionOrderBatchInfoResult.getResidueQuantity();//剩余数量
            if(remainingQuantity>0 ){
                //新增物料追溯
                MaterialTraceabilityParam materialTraceabilityParam = new MaterialTraceabilityParam();
                materialTraceabilityParam.setWorkOrderNo(S_ORDER_CODE);
                materialTraceabilityParam.setProductCode(S_PRODUCT_CODE);
                materialTraceabilityParam.setProductNo(S_SFC_CODE);
                materialTraceabilityParam.setLineCode(PRODUCTION_LINE);
                materialTraceabilityParam.setLocationCode(LOCATION_CODE);
                materialTraceabilityParam.setAssemblyQty(1);
                materialTraceabilityParam.setAssemblyTime(DateTool.getLocalTimeForDate());
                materialTraceabilityParam.setMaterialCode(productionOrderBatchInfoResult.getMaterialCode());//物料编码
                materialTraceabilityParam.setMaterialBatchNo(productionOrderBatchInfoResult.getBatch());//物料批次
                materialTraceabilityService.add(materialTraceabilityParam);
                //更新剩余数量
                productionOrderBatchInfoParam.setId(productionOrderBatchInfoResult.getId());
                productionOrderBatchInfoParam.setResidueQuantity(remainingQuantity-1);//剩余数量
                productionOrderBatchInfoService.update(productionOrderBatchInfoParam);
            }
        }
    }
    //PC读参数信息
    public void handleInfo() throws Exception {
        logger.info("handleInfo START!");
        if(null == list){
            CollectionParamConfParam collectionParamConfParam = new CollectionParamConfParam();
            collectionParamConfParam.setLocationCode(LOCATION_CODE);
            list = collectionParamConfService.findListBySpec(collectionParamConfParam);
        }
        if(null != list && !list.isEmpty()) {
            for (int i = 0; i < list.size(); i++) {
                CollectionParamConfResult result = (CollectionParamConfResult) list.get(i);
                String value = miloService.
                        readFromOpcUa(result.getGatherAddress())
                        .getValue().toString();//读参数值
                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);
                paramCollectionParam.setParamLower(result.getParamLower());
                paramCollectionParam.setParamUpper(result.getParamUpper());
                paramCollectionParam.setParamStandard(result.getParamCentral());
                paramCollectionParam.setCollectionTime(DateTool.getLocalTimeForDate());
                paramCollectionParam.setUnit(result.getUnit());
                paramCollectionService.add(paramCollectionParam);
            }
        }
        logger.info("handleInfo END!");
    }
}
guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/EOP070Callback.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,282 @@
package cn.stylefeng.guns.plcserver.callback;
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.model.params.ParamCollectionParam;
import cn.stylefeng.guns.modular.cm.paramCollection.service.ParamCollectionService;
import cn.stylefeng.guns.modular.cm.passingStationCollection.model.params.PassingStationCollectionParam;
import cn.stylefeng.guns.modular.cm.passingStationCollection.service.PassingStationCollectionService;
import cn.stylefeng.guns.modular.dq.materialTraceability.model.params.MaterialTraceabilityParam;
import cn.stylefeng.guns.modular.dq.materialTraceability.service.MaterialTraceabilityService;
import cn.stylefeng.guns.modular.em.equipmentAlarm.service.EquipmentAlarmService;
import cn.stylefeng.guns.modular.em.equipmentStatus.service.EquipmentStatusService;
import cn.stylefeng.guns.modular.gm.greaseManage.service.GreaseManageService;
import cn.stylefeng.guns.modular.om.productionOrdeInfo.service.ProductionOrdeInfoService;
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.model.params.ProductionOrderBatchInfoParam;
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.model.result.ProductionOrderBatchInfoResult;
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.service.ProductionOrderBatchInfoService;
import cn.stylefeng.guns.modular.om.productionOrderRecords.service.ProductionOrderRecordsService;
import cn.stylefeng.guns.modular.sc.repairManageInfo.service.RepairManageInfoService;
import cn.stylefeng.guns.modular.sc.serialNumbersConf.service.SerialNumbersConfService;
import cn.stylefeng.guns.plcserver.opc.GlobalVariable;
import cn.stylefeng.guns.plcserver.opc.OPCElement;
import cn.stylefeng.guns.plcserver.tool.DateTool;
import cn.stylefeng.guns.plcserver.tool.LogUtil;
import com.kangaroohy.milo.model.ReadWriteEntity;
import com.kangaroohy.milo.runner.subscription.SubscriptionCallback;
import com.kangaroohy.milo.service.MiloService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@Component
public class EOP070Callback implements SubscriptionCallback {
    public MiloService miloService;
    @Autowired
    public ProductionOrdeInfoService productionOrdeInfoService;
    @Autowired
    public PassingStationCollectionService passingStationCollectionService;
    @Autowired
    public ParamCollectionService paramCollectionService;
    @Autowired
    public CollectionParamConfService collectionParamConfService;
    @Autowired
    public SerialNumbersConfService serialNumbersConfService;
    @Autowired
    private EquipmentStatusService equipmentStatusService;
    @Autowired
    private EquipmentAlarmService equipmentAlarmService;
    @Autowired
    private MaterialTraceabilityService materialTraceabilityService;
    @Autowired
    private EquipmentInfoService equipmentInfoService;
    @Autowired
    private RepairManageInfoService repairManageInfoService;
    @Autowired
    private LocationInfoService locationInfoService;
    @Autowired
    private GreaseManageService greaseManageService;
    @Autowired
    private ProductionOrderRecordsService productionOrderRecordsService;
    @Autowired
    private ProductionOrderBatchInfoService productionOrderBatchInfoService;
    private static Logger logger;
    LogUtil logUtil = new LogUtil();
    static {
        logger = Logger.getLogger(EOP070Callback.class);
    }
    private static Date IN_TIME = null;
    private static String S_ORDER_CODE = "";//工单编号
    private static String S_PRODUCT_CODE = "";//产品编号
    private static String S_PRODUCT_TYPE= "";//产品类型
    private static String S_SFC_CODE = "";//总成编码
    private static String PRODUCTION_LINE  = "EOP";//产线号
    private static String LOCATION_CODE  = "EOP070";//工位号
    private static List list = null;
    public EOP070Callback(MiloService miloService,
                          ProductionOrdeInfoService productionOrdeInfoService,
                          PassingStationCollectionService passingStationCollectionService,
                          ParamCollectionService paramCollectionService,
                          CollectionParamConfService collectionParamConfService,
                          SerialNumbersConfService serialNumbersConfService,
                          EquipmentStatusService equipmentStatusService,
                          EquipmentAlarmService equipmentAlarmService,
                          MaterialTraceabilityService materialTraceabilityService,
                          EquipmentInfoService equipmentInfoService,
                          RepairManageInfoService repairManageInfoService,
                          LocationInfoService locationInfoService,
                          GreaseManageService greaseManageService,
                          ProductionOrderRecordsService productionOrderRecordsService,
                          ProductionOrderBatchInfoService productionOrderBatchInfoService) {
        this.miloService = miloService;
        this.productionOrdeInfoService = productionOrdeInfoService;
        this.passingStationCollectionService = passingStationCollectionService;
        this.paramCollectionService = paramCollectionService;
        this.collectionParamConfService = collectionParamConfService;
        this.serialNumbersConfService = serialNumbersConfService;
        this.equipmentStatusService = equipmentStatusService;
        this.equipmentAlarmService = equipmentAlarmService;
        this.materialTraceabilityService = materialTraceabilityService;
        this.equipmentInfoService = equipmentInfoService;
        this.repairManageInfoService = repairManageInfoService;
        this.locationInfoService = locationInfoService;
        this.greaseManageService = greaseManageService;
        this.productionOrderRecordsService = productionOrderRecordsService;
        this.productionOrderBatchInfoService = productionOrderBatchInfoService;
    }
    @Override
    public void onSubscribe(String identifier, Object value) {
        String ecpStr = "";//异常记录标记
        try {
            //心跳
            if(null != value && identifier.equals(OPCElement.EOP070_F_HEART_BEAT)){
                if( "false".equals(value.toString()))
                {
                    ReadWriteEntity entity = new ReadWriteEntity(OPCElement.EOP070_F_HEART_BEAT,true);
                    miloService.writeToOpcUa(entity);
                }
            }
            //PLC进站
            else if(null != value && identifier.equals(OPCElement.EOP070_J_PLC_START)){
                if("true".equals(value.toString())){
                    handleOrder();
                }
            }
            //PLC出站
            else if(null != value && identifier.equals(OPCElement.EOP070_J_PLC_FINISH)){
                if("true".equals(value.toString())){
                    handleFinsh();
                    handleInfo();
                    handleMaterial();
                }
            }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 {
        logger.info("handleOrder PC处理开始!");
        IN_TIME = DateTool.getLocalTimeForDate();
        List<String> lists = new ArrayList<>();
        lists.add(OPCElement.EOP070_S_ORDER_CODE);
        lists.add(OPCElement.EOP070_S_PRODUCT_CODE);
        lists.add(OPCElement.EOP070_S_SFC_CODE);
        List<ReadWriteEntity> returnLists= miloService.readFromOpcUa(lists);
        returnLists.forEach(element->{
            switch(element.getIdentifier()){
                case OPCElement.EOP070_S_ORDER_CODE:
                    S_ORDER_CODE = element.getValue().toString();
                    break;
                case OPCElement.EOP070_S_PRODUCT_CODE:
                    S_PRODUCT_TYPE = element.getValue().toString();
                    S_PRODUCT_CODE = GlobalVariable.PRODUCT_CODE_MAP.get(S_PRODUCT_TYPE);
                    break;
                case OPCElement.EOP070_S_SFC_CODE:
                    S_SFC_CODE = element.getValue().toString();
                    break;
                default:
                    break;
            }
        });
        ReadWriteEntity entity = new ReadWriteEntity(OPCElement.EOP070_J_PC_WRITE_ORDER,true);
        miloService.writeToOpcUa(entity);
        logger.info("handleOrder PC处理完成!");
    }
    public void handleFinsh() throws Exception {
        logger.info("handleFinsh PC处理开始!");
        String S_PRODUCT_STATE_CODE = miloService.
                readFromOpcUa(OPCElement.EOP070_S_PRODUCT_STATE_CODE)
                .getValue().toString();
        //处理过站信息
        PassingStationCollectionParam param = new PassingStationCollectionParam();
        param.setWorkOrderNo(S_ORDER_CODE);
        param.setProductCode(S_PRODUCT_CODE);
        param.setSfcCode(S_SFC_CODE);
        param.setProductionLine(PRODUCTION_LINE);
        param.setLocationCode(LOCATION_CODE);
        param.setInboundTime(IN_TIME);
        param.setOutboundTime(DateTool.getLocalTimeForDate());
        param.setOutRsSign(S_PRODUCT_STATE_CODE);//出站是否合格
        passingStationCollectionService.add(param);
        ReadWriteEntity entity = new ReadWriteEntity(OPCElement.EOP070_J_PC_FINISH,true);
        miloService.writeToOpcUa(entity);//写PC完成
        logger.info("handleFinsh PC处理完成!");
    }
    public void handleMaterial() {
        //查询批次上料信息
        ProductionOrderBatchInfoParam productionOrderBatchInfoParam = new ProductionOrderBatchInfoParam();
        productionOrderBatchInfoParam.setWorkOrderNo(S_ORDER_CODE);
        productionOrderBatchInfoParam.setLocationCode(LOCATION_CODE);
        List<ProductionOrderBatchInfoResult> list = productionOrderBatchInfoService.findListBySpec(productionOrderBatchInfoParam);
        for(int i=0;i<list.size();i++){
            ProductionOrderBatchInfoResult productionOrderBatchInfoResult = list.get(i);
            int remainingQuantity =  productionOrderBatchInfoResult.getResidueQuantity();//剩余数量
            if(remainingQuantity>0 ){
                //新增物料追溯
                MaterialTraceabilityParam materialTraceabilityParam = new MaterialTraceabilityParam();
                materialTraceabilityParam.setWorkOrderNo(S_ORDER_CODE);
                materialTraceabilityParam.setProductCode(S_PRODUCT_CODE);
                materialTraceabilityParam.setProductNo(S_SFC_CODE);
                materialTraceabilityParam.setLineCode(PRODUCTION_LINE);
                materialTraceabilityParam.setLocationCode(LOCATION_CODE);
                materialTraceabilityParam.setAssemblyQty(1);
                materialTraceabilityParam.setAssemblyTime(DateTool.getLocalTimeForDate());
                materialTraceabilityParam.setMaterialCode(productionOrderBatchInfoResult.getMaterialCode());//物料编码
                materialTraceabilityParam.setMaterialBatchNo(productionOrderBatchInfoResult.getBatch());//物料批次
                materialTraceabilityService.add(materialTraceabilityParam);
                //更新剩余数量
                productionOrderBatchInfoParam.setId(productionOrderBatchInfoResult.getId());
                productionOrderBatchInfoParam.setResidueQuantity(remainingQuantity-1);//剩余数量
                productionOrderBatchInfoService.update(productionOrderBatchInfoParam);
            }
        }
    }
    //PC读参数信息
    public void handleInfo() throws Exception {
        logger.info("handleInfo START!");
        if(null == list){
            CollectionParamConfParam collectionParamConfParam = new CollectionParamConfParam();
            collectionParamConfParam.setLocationCode(LOCATION_CODE);
            list = collectionParamConfService.findListBySpec(collectionParamConfParam);
        }
        if(null != list && !list.isEmpty()) {
            for (int i = 0; i < list.size(); i++) {
                CollectionParamConfResult result = (CollectionParamConfResult) list.get(i);
                String value = miloService.
                        readFromOpcUa(result.getGatherAddress())
                        .getValue().toString();//读参数值
                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);
                paramCollectionParam.setParamLower(result.getParamLower());
                paramCollectionParam.setParamUpper(result.getParamUpper());
                paramCollectionParam.setParamStandard(result.getParamCentral());
                paramCollectionParam.setCollectionTime(DateTool.getLocalTimeForDate());
                paramCollectionParam.setUnit(result.getUnit());
                paramCollectionService.add(paramCollectionParam);
            }
        }
        logger.info("handleInfo END!");
    }
}
guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/EOP080Callback.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,282 @@
package cn.stylefeng.guns.plcserver.callback;
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.model.params.ParamCollectionParam;
import cn.stylefeng.guns.modular.cm.paramCollection.service.ParamCollectionService;
import cn.stylefeng.guns.modular.cm.passingStationCollection.model.params.PassingStationCollectionParam;
import cn.stylefeng.guns.modular.cm.passingStationCollection.service.PassingStationCollectionService;
import cn.stylefeng.guns.modular.dq.materialTraceability.model.params.MaterialTraceabilityParam;
import cn.stylefeng.guns.modular.dq.materialTraceability.service.MaterialTraceabilityService;
import cn.stylefeng.guns.modular.em.equipmentAlarm.service.EquipmentAlarmService;
import cn.stylefeng.guns.modular.em.equipmentStatus.service.EquipmentStatusService;
import cn.stylefeng.guns.modular.gm.greaseManage.service.GreaseManageService;
import cn.stylefeng.guns.modular.om.productionOrdeInfo.service.ProductionOrdeInfoService;
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.model.params.ProductionOrderBatchInfoParam;
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.model.result.ProductionOrderBatchInfoResult;
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.service.ProductionOrderBatchInfoService;
import cn.stylefeng.guns.modular.om.productionOrderRecords.service.ProductionOrderRecordsService;
import cn.stylefeng.guns.modular.sc.repairManageInfo.service.RepairManageInfoService;
import cn.stylefeng.guns.modular.sc.serialNumbersConf.service.SerialNumbersConfService;
import cn.stylefeng.guns.plcserver.opc.GlobalVariable;
import cn.stylefeng.guns.plcserver.opc.OPCElement;
import cn.stylefeng.guns.plcserver.tool.DateTool;
import cn.stylefeng.guns.plcserver.tool.LogUtil;
import com.kangaroohy.milo.model.ReadWriteEntity;
import com.kangaroohy.milo.runner.subscription.SubscriptionCallback;
import com.kangaroohy.milo.service.MiloService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@Component
public class EOP080Callback implements SubscriptionCallback {
    public MiloService miloService;
    @Autowired
    public ProductionOrdeInfoService productionOrdeInfoService;
    @Autowired
    public PassingStationCollectionService passingStationCollectionService;
    @Autowired
    public ParamCollectionService paramCollectionService;
    @Autowired
    public CollectionParamConfService collectionParamConfService;
    @Autowired
    public SerialNumbersConfService serialNumbersConfService;
    @Autowired
    private EquipmentStatusService equipmentStatusService;
    @Autowired
    private EquipmentAlarmService equipmentAlarmService;
    @Autowired
    private MaterialTraceabilityService materialTraceabilityService;
    @Autowired
    private EquipmentInfoService equipmentInfoService;
    @Autowired
    private RepairManageInfoService repairManageInfoService;
    @Autowired
    private LocationInfoService locationInfoService;
    @Autowired
    private GreaseManageService greaseManageService;
    @Autowired
    private ProductionOrderRecordsService productionOrderRecordsService;
    @Autowired
    private ProductionOrderBatchInfoService productionOrderBatchInfoService;
    private static Logger logger;
    LogUtil logUtil = new LogUtil();
    static {
        logger = Logger.getLogger(EOP080Callback.class);
    }
    private static Date IN_TIME = null;
    private static String S_ORDER_CODE = "";//工单编号
    private static String S_PRODUCT_CODE = "";//产品编号
    private static String S_PRODUCT_TYPE= "";//产品类型
    private static String S_SFC_CODE = "";//总成编码
    private static String PRODUCTION_LINE  = "EOP";//产线号
    private static String LOCATION_CODE  = "EOP080";//工位号
    private static List list = null;
    public EOP080Callback(MiloService miloService,
                          ProductionOrdeInfoService productionOrdeInfoService,
                          PassingStationCollectionService passingStationCollectionService,
                          ParamCollectionService paramCollectionService,
                          CollectionParamConfService collectionParamConfService,
                          SerialNumbersConfService serialNumbersConfService,
                          EquipmentStatusService equipmentStatusService,
                          EquipmentAlarmService equipmentAlarmService,
                          MaterialTraceabilityService materialTraceabilityService,
                          EquipmentInfoService equipmentInfoService,
                          RepairManageInfoService repairManageInfoService,
                          LocationInfoService locationInfoService,
                          GreaseManageService greaseManageService,
                          ProductionOrderRecordsService productionOrderRecordsService,
                          ProductionOrderBatchInfoService productionOrderBatchInfoService) {
        this.miloService = miloService;
        this.productionOrdeInfoService = productionOrdeInfoService;
        this.passingStationCollectionService = passingStationCollectionService;
        this.paramCollectionService = paramCollectionService;
        this.collectionParamConfService = collectionParamConfService;
        this.serialNumbersConfService = serialNumbersConfService;
        this.equipmentStatusService = equipmentStatusService;
        this.equipmentAlarmService = equipmentAlarmService;
        this.materialTraceabilityService = materialTraceabilityService;
        this.equipmentInfoService = equipmentInfoService;
        this.repairManageInfoService = repairManageInfoService;
        this.locationInfoService = locationInfoService;
        this.greaseManageService = greaseManageService;
        this.productionOrderRecordsService = productionOrderRecordsService;
        this.productionOrderBatchInfoService = productionOrderBatchInfoService;
    }
    @Override
    public void onSubscribe(String identifier, Object value) {
        String ecpStr = "";//异常记录标记
        try {
            //心跳
            if(null != value && identifier.equals(OPCElement.EOP080_F_HEART_BEAT)){
                if( "false".equals(value.toString()))
                {
                    ReadWriteEntity entity = new ReadWriteEntity(OPCElement.EOP080_F_HEART_BEAT,true);
                    miloService.writeToOpcUa(entity);
                }
            }
            //PLC进站
            else if(null != value && identifier.equals(OPCElement.EOP080_J_PLC_START)){
                if("true".equals(value.toString())){
                    handleOrder();
                }
            }
            //PLC出站
            else if(null != value && identifier.equals(OPCElement.EOP080_J_PLC_FINISH)){
                if("true".equals(value.toString())){
                    handleFinsh();
                    handleInfo();
                    handleMaterial();
                }
            }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 {
        logger.info("handleOrder PC处理开始!");
        IN_TIME = DateTool.getLocalTimeForDate();
        List<String> lists = new ArrayList<>();
        lists.add(OPCElement.EOP080_S_ORDER_CODE);
        lists.add(OPCElement.EOP080_S_PRODUCT_CODE);
        lists.add(OPCElement.EOP080_S_SFC_CODE);
        List<ReadWriteEntity> returnLists= miloService.readFromOpcUa(lists);
        returnLists.forEach(element->{
            switch(element.getIdentifier()){
                case OPCElement.EOP080_S_ORDER_CODE:
                    S_ORDER_CODE = element.getValue().toString();
                    break;
                case OPCElement.EOP080_S_PRODUCT_CODE:
                    S_PRODUCT_TYPE = element.getValue().toString();
                    S_PRODUCT_CODE = GlobalVariable.PRODUCT_CODE_MAP.get(S_PRODUCT_TYPE);
                    break;
                case OPCElement.EOP080_S_SFC_CODE:
                    S_SFC_CODE = element.getValue().toString();
                    break;
                default:
                    break;
            }
        });
        ReadWriteEntity entity = new ReadWriteEntity(OPCElement.EOP080_J_PC_WRITE_ORDER,true);
        miloService.writeToOpcUa(entity);
        logger.info("handleOrder PC处理完成!");
    }
    public void handleFinsh() throws Exception {
        logger.info("handleFinsh PC处理开始!");
        String S_PRODUCT_STATE_CODE = miloService.
                readFromOpcUa(OPCElement.EOP080_S_PRODUCT_STATE_CODE)
                .getValue().toString();
        //处理过站信息
        PassingStationCollectionParam param = new PassingStationCollectionParam();
        param.setWorkOrderNo(S_ORDER_CODE);
        param.setProductCode(S_PRODUCT_CODE);
        param.setSfcCode(S_SFC_CODE);
        param.setProductionLine(PRODUCTION_LINE);
        param.setLocationCode(LOCATION_CODE);
        param.setInboundTime(IN_TIME);
        param.setOutboundTime(DateTool.getLocalTimeForDate());
        param.setOutRsSign(S_PRODUCT_STATE_CODE);//出站是否合格
        passingStationCollectionService.add(param);
        ReadWriteEntity entity = new ReadWriteEntity(OPCElement.EOP080_J_PC_FINISH,true);
        miloService.writeToOpcUa(entity);//写PC完成
        logger.info("handleFinsh PC处理完成!");
    }
    public void handleMaterial() {
        //查询批次上料信息
        ProductionOrderBatchInfoParam productionOrderBatchInfoParam = new ProductionOrderBatchInfoParam();
        productionOrderBatchInfoParam.setWorkOrderNo(S_ORDER_CODE);
        productionOrderBatchInfoParam.setLocationCode(LOCATION_CODE);
        List<ProductionOrderBatchInfoResult> list = productionOrderBatchInfoService.findListBySpec(productionOrderBatchInfoParam);
        for(int i=0;i<list.size();i++){
            ProductionOrderBatchInfoResult productionOrderBatchInfoResult = list.get(i);
            int remainingQuantity =  productionOrderBatchInfoResult.getResidueQuantity();//剩余数量
            if(remainingQuantity>0 ){
                //新增物料追溯
                MaterialTraceabilityParam materialTraceabilityParam = new MaterialTraceabilityParam();
                materialTraceabilityParam.setWorkOrderNo(S_ORDER_CODE);
                materialTraceabilityParam.setProductCode(S_PRODUCT_CODE);
                materialTraceabilityParam.setProductNo(S_SFC_CODE);
                materialTraceabilityParam.setLineCode(PRODUCTION_LINE);
                materialTraceabilityParam.setLocationCode(LOCATION_CODE);
                materialTraceabilityParam.setAssemblyQty(1);
                materialTraceabilityParam.setAssemblyTime(DateTool.getLocalTimeForDate());
                materialTraceabilityParam.setMaterialCode(productionOrderBatchInfoResult.getMaterialCode());//物料编码
                materialTraceabilityParam.setMaterialBatchNo(productionOrderBatchInfoResult.getBatch());//物料批次
                materialTraceabilityService.add(materialTraceabilityParam);
                //更新剩余数量
                productionOrderBatchInfoParam.setId(productionOrderBatchInfoResult.getId());
                productionOrderBatchInfoParam.setResidueQuantity(remainingQuantity-1);//剩余数量
                productionOrderBatchInfoService.update(productionOrderBatchInfoParam);
            }
        }
    }
    //PC读参数信息
    public void handleInfo() throws Exception {
        logger.info("handleInfo START!");
        if(null == list){
            CollectionParamConfParam collectionParamConfParam = new CollectionParamConfParam();
            collectionParamConfParam.setLocationCode(LOCATION_CODE);
            list = collectionParamConfService.findListBySpec(collectionParamConfParam);
        }
        if(null != list && !list.isEmpty()) {
            for (int i = 0; i < list.size(); i++) {
                CollectionParamConfResult result = (CollectionParamConfResult) list.get(i);
                String value = miloService.
                        readFromOpcUa(result.getGatherAddress())
                        .getValue().toString();//读参数值
                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);
                paramCollectionParam.setParamLower(result.getParamLower());
                paramCollectionParam.setParamUpper(result.getParamUpper());
                paramCollectionParam.setParamStandard(result.getParamCentral());
                paramCollectionParam.setCollectionTime(DateTool.getLocalTimeForDate());
                paramCollectionParam.setUnit(result.getUnit());
                paramCollectionService.add(paramCollectionParam);
            }
        }
        logger.info("handleInfo END!");
    }
}
guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/EOP090BCallback.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,282 @@
package cn.stylefeng.guns.plcserver.callback;
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.model.params.ParamCollectionParam;
import cn.stylefeng.guns.modular.cm.paramCollection.service.ParamCollectionService;
import cn.stylefeng.guns.modular.cm.passingStationCollection.model.params.PassingStationCollectionParam;
import cn.stylefeng.guns.modular.cm.passingStationCollection.service.PassingStationCollectionService;
import cn.stylefeng.guns.modular.dq.materialTraceability.model.params.MaterialTraceabilityParam;
import cn.stylefeng.guns.modular.dq.materialTraceability.service.MaterialTraceabilityService;
import cn.stylefeng.guns.modular.em.equipmentAlarm.service.EquipmentAlarmService;
import cn.stylefeng.guns.modular.em.equipmentStatus.service.EquipmentStatusService;
import cn.stylefeng.guns.modular.gm.greaseManage.service.GreaseManageService;
import cn.stylefeng.guns.modular.om.productionOrdeInfo.service.ProductionOrdeInfoService;
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.model.params.ProductionOrderBatchInfoParam;
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.model.result.ProductionOrderBatchInfoResult;
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.service.ProductionOrderBatchInfoService;
import cn.stylefeng.guns.modular.om.productionOrderRecords.service.ProductionOrderRecordsService;
import cn.stylefeng.guns.modular.sc.repairManageInfo.service.RepairManageInfoService;
import cn.stylefeng.guns.modular.sc.serialNumbersConf.service.SerialNumbersConfService;
import cn.stylefeng.guns.plcserver.opc.GlobalVariable;
import cn.stylefeng.guns.plcserver.opc.OPCElement;
import cn.stylefeng.guns.plcserver.tool.DateTool;
import cn.stylefeng.guns.plcserver.tool.LogUtil;
import com.kangaroohy.milo.model.ReadWriteEntity;
import com.kangaroohy.milo.runner.subscription.SubscriptionCallback;
import com.kangaroohy.milo.service.MiloService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@Component
public class EOP090BCallback implements SubscriptionCallback {
    public MiloService miloService;
    @Autowired
    public ProductionOrdeInfoService productionOrdeInfoService;
    @Autowired
    public PassingStationCollectionService passingStationCollectionService;
    @Autowired
    public ParamCollectionService paramCollectionService;
    @Autowired
    public CollectionParamConfService collectionParamConfService;
    @Autowired
    public SerialNumbersConfService serialNumbersConfService;
    @Autowired
    private EquipmentStatusService equipmentStatusService;
    @Autowired
    private EquipmentAlarmService equipmentAlarmService;
    @Autowired
    private MaterialTraceabilityService materialTraceabilityService;
    @Autowired
    private EquipmentInfoService equipmentInfoService;
    @Autowired
    private RepairManageInfoService repairManageInfoService;
    @Autowired
    private LocationInfoService locationInfoService;
    @Autowired
    private GreaseManageService greaseManageService;
    @Autowired
    private ProductionOrderRecordsService productionOrderRecordsService;
    @Autowired
    private ProductionOrderBatchInfoService productionOrderBatchInfoService;
    private static Logger logger;
    LogUtil logUtil = new LogUtil();
    static {
        logger = Logger.getLogger(EOP090BCallback.class);
    }
    private static Date IN_TIME = null;
    private static String S_ORDER_CODE = "";//工单编号
    private static String S_PRODUCT_CODE = "";//产品编号
    private static String S_PRODUCT_TYPE= "";//产品类型
    private static String S_SFC_CODE = "";//总成编码
    private static String PRODUCTION_LINE  = "EOP";//产线号
    private static String LOCATION_CODE  = "EOP090B";//工位号
    private static List list = null;
    public EOP090BCallback(MiloService miloService,
                           ProductionOrdeInfoService productionOrdeInfoService,
                           PassingStationCollectionService passingStationCollectionService,
                           ParamCollectionService paramCollectionService,
                           CollectionParamConfService collectionParamConfService,
                           SerialNumbersConfService serialNumbersConfService,
                           EquipmentStatusService equipmentStatusService,
                           EquipmentAlarmService equipmentAlarmService,
                           MaterialTraceabilityService materialTraceabilityService,
                           EquipmentInfoService equipmentInfoService,
                           RepairManageInfoService repairManageInfoService,
                           LocationInfoService locationInfoService,
                           GreaseManageService greaseManageService,
                           ProductionOrderRecordsService productionOrderRecordsService,
                           ProductionOrderBatchInfoService productionOrderBatchInfoService) {
        this.miloService = miloService;
        this.productionOrdeInfoService = productionOrdeInfoService;
        this.passingStationCollectionService = passingStationCollectionService;
        this.paramCollectionService = paramCollectionService;
        this.collectionParamConfService = collectionParamConfService;
        this.serialNumbersConfService = serialNumbersConfService;
        this.equipmentStatusService = equipmentStatusService;
        this.equipmentAlarmService = equipmentAlarmService;
        this.materialTraceabilityService = materialTraceabilityService;
        this.equipmentInfoService = equipmentInfoService;
        this.repairManageInfoService = repairManageInfoService;
        this.locationInfoService = locationInfoService;
        this.greaseManageService = greaseManageService;
        this.productionOrderRecordsService = productionOrderRecordsService;
        this.productionOrderBatchInfoService = productionOrderBatchInfoService;
    }
    @Override
    public void onSubscribe(String identifier, Object value) {
        String ecpStr = "";//异常记录标记
        try {
            //心跳
            if(null != value && identifier.equals(OPCElement.EOP090B_F_HEART_BEAT)){
                if( "false".equals(value.toString()))
                {
                    ReadWriteEntity entity = new ReadWriteEntity(OPCElement.EOP090B_F_HEART_BEAT,true);
                    miloService.writeToOpcUa(entity);
                }
            }
            //PLC进站
            else if(null != value && identifier.equals(OPCElement.EOP090B_J_PLC_START)){
                if("true".equals(value.toString())){
                    handleOrder();
                }
            }
            //PLC出站
            else if(null != value && identifier.equals(OPCElement.EOP090B_J_PLC_FINISH)){
                if("true".equals(value.toString())){
                    handleFinsh();
                    handleInfo();
                    handleMaterial();
                }
            }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 {
        logger.info("handleOrder PC处理开始!");
        IN_TIME = DateTool.getLocalTimeForDate();
        List<String> lists = new ArrayList<>();
        lists.add(OPCElement.EOP090B_S_ORDER_CODE);
        lists.add(OPCElement.EOP090B_S_PRODUCT_CODE);
        lists.add(OPCElement.EOP090B_S_SFC_CODE);
        List<ReadWriteEntity> returnLists= miloService.readFromOpcUa(lists);
        returnLists.forEach(element->{
            switch(element.getIdentifier()){
                case OPCElement.EOP090B_S_ORDER_CODE:
                    S_ORDER_CODE = element.getValue().toString();
                    break;
                case OPCElement.EOP090B_S_PRODUCT_CODE:
                    S_PRODUCT_TYPE = element.getValue().toString();
                    S_PRODUCT_CODE = GlobalVariable.PRODUCT_CODE_MAP.get(S_PRODUCT_TYPE);
                    break;
                case OPCElement.EOP090B_S_SFC_CODE:
                    S_SFC_CODE = element.getValue().toString();
                    break;
                default:
                    break;
            }
        });
        ReadWriteEntity entity = new ReadWriteEntity(OPCElement.EOP090B_J_PC_WRITE_ORDER,true);
        miloService.writeToOpcUa(entity);
        logger.info("handleOrder PC处理完成!");
    }
    public void handleFinsh() throws Exception {
        logger.info("handleFinsh PC处理开始!");
        String S_PRODUCT_STATE_CODE = miloService.
                readFromOpcUa(OPCElement.EOP090B_S_PRODUCT_STATE_CODE)
                .getValue().toString();
        //处理过站信息
        PassingStationCollectionParam param = new PassingStationCollectionParam();
        param.setWorkOrderNo(S_ORDER_CODE);
        param.setProductCode(S_PRODUCT_CODE);
        param.setSfcCode(S_SFC_CODE);
        param.setProductionLine(PRODUCTION_LINE);
        param.setLocationCode(LOCATION_CODE);
        param.setInboundTime(IN_TIME);
        param.setOutboundTime(DateTool.getLocalTimeForDate());
        param.setOutRsSign(S_PRODUCT_STATE_CODE);//出站是否合格
        passingStationCollectionService.add(param);
        ReadWriteEntity entity = new ReadWriteEntity(OPCElement.EOP090B_J_PC_FINISH,true);
        miloService.writeToOpcUa(entity);//写PC完成
        logger.info("handleFinsh PC处理完成!");
    }
    public void handleMaterial() {
        //查询批次上料信息
        ProductionOrderBatchInfoParam productionOrderBatchInfoParam = new ProductionOrderBatchInfoParam();
        productionOrderBatchInfoParam.setWorkOrderNo(S_ORDER_CODE);
        productionOrderBatchInfoParam.setLocationCode(LOCATION_CODE);
        List<ProductionOrderBatchInfoResult> list = productionOrderBatchInfoService.findListBySpec(productionOrderBatchInfoParam);
        for(int i=0;i<list.size();i++){
            ProductionOrderBatchInfoResult productionOrderBatchInfoResult = list.get(i);
            int remainingQuantity =  productionOrderBatchInfoResult.getResidueQuantity();//剩余数量
            if(remainingQuantity>0 ){
                //新增物料追溯
                MaterialTraceabilityParam materialTraceabilityParam = new MaterialTraceabilityParam();
                materialTraceabilityParam.setWorkOrderNo(S_ORDER_CODE);
                materialTraceabilityParam.setProductCode(S_PRODUCT_CODE);
                materialTraceabilityParam.setProductNo(S_SFC_CODE);
                materialTraceabilityParam.setLineCode(PRODUCTION_LINE);
                materialTraceabilityParam.setLocationCode(LOCATION_CODE);
                materialTraceabilityParam.setAssemblyQty(1);
                materialTraceabilityParam.setAssemblyTime(DateTool.getLocalTimeForDate());
                materialTraceabilityParam.setMaterialCode(productionOrderBatchInfoResult.getMaterialCode());//物料编码
                materialTraceabilityParam.setMaterialBatchNo(productionOrderBatchInfoResult.getBatch());//物料批次
                materialTraceabilityService.add(materialTraceabilityParam);
                //更新剩余数量
                productionOrderBatchInfoParam.setId(productionOrderBatchInfoResult.getId());
                productionOrderBatchInfoParam.setResidueQuantity(remainingQuantity-1);//剩余数量
                productionOrderBatchInfoService.update(productionOrderBatchInfoParam);
            }
        }
    }
    //PC读参数信息
    public void handleInfo() throws Exception {
        logger.info("handleInfo START!");
        if(null == list){
            CollectionParamConfParam collectionParamConfParam = new CollectionParamConfParam();
            collectionParamConfParam.setLocationCode(LOCATION_CODE);
            list = collectionParamConfService.findListBySpec(collectionParamConfParam);
        }
        if(null != list && !list.isEmpty()) {
            for (int i = 0; i < list.size(); i++) {
                CollectionParamConfResult result = (CollectionParamConfResult) list.get(i);
                String value = miloService.
                        readFromOpcUa(result.getGatherAddress())
                        .getValue().toString();//读参数值
                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);
                paramCollectionParam.setParamLower(result.getParamLower());
                paramCollectionParam.setParamUpper(result.getParamUpper());
                paramCollectionParam.setParamStandard(result.getParamCentral());
                paramCollectionParam.setCollectionTime(DateTool.getLocalTimeForDate());
                paramCollectionParam.setUnit(result.getUnit());
                paramCollectionService.add(paramCollectionParam);
            }
        }
        logger.info("handleInfo END!");
    }
}
guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/EOP090Callback.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,282 @@
package cn.stylefeng.guns.plcserver.callback;
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.model.params.ParamCollectionParam;
import cn.stylefeng.guns.modular.cm.paramCollection.service.ParamCollectionService;
import cn.stylefeng.guns.modular.cm.passingStationCollection.model.params.PassingStationCollectionParam;
import cn.stylefeng.guns.modular.cm.passingStationCollection.service.PassingStationCollectionService;
import cn.stylefeng.guns.modular.dq.materialTraceability.model.params.MaterialTraceabilityParam;
import cn.stylefeng.guns.modular.dq.materialTraceability.service.MaterialTraceabilityService;
import cn.stylefeng.guns.modular.em.equipmentAlarm.service.EquipmentAlarmService;
import cn.stylefeng.guns.modular.em.equipmentStatus.service.EquipmentStatusService;
import cn.stylefeng.guns.modular.gm.greaseManage.service.GreaseManageService;
import cn.stylefeng.guns.modular.om.productionOrdeInfo.service.ProductionOrdeInfoService;
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.model.params.ProductionOrderBatchInfoParam;
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.model.result.ProductionOrderBatchInfoResult;
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.service.ProductionOrderBatchInfoService;
import cn.stylefeng.guns.modular.om.productionOrderRecords.service.ProductionOrderRecordsService;
import cn.stylefeng.guns.modular.sc.repairManageInfo.service.RepairManageInfoService;
import cn.stylefeng.guns.modular.sc.serialNumbersConf.service.SerialNumbersConfService;
import cn.stylefeng.guns.plcserver.opc.GlobalVariable;
import cn.stylefeng.guns.plcserver.opc.OPCElement;
import cn.stylefeng.guns.plcserver.tool.DateTool;
import cn.stylefeng.guns.plcserver.tool.LogUtil;
import com.kangaroohy.milo.model.ReadWriteEntity;
import com.kangaroohy.milo.runner.subscription.SubscriptionCallback;
import com.kangaroohy.milo.service.MiloService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@Component
public class EOP090Callback implements SubscriptionCallback {
    public MiloService miloService;
    @Autowired
    public ProductionOrdeInfoService productionOrdeInfoService;
    @Autowired
    public PassingStationCollectionService passingStationCollectionService;
    @Autowired
    public ParamCollectionService paramCollectionService;
    @Autowired
    public CollectionParamConfService collectionParamConfService;
    @Autowired
    public SerialNumbersConfService serialNumbersConfService;
    @Autowired
    private EquipmentStatusService equipmentStatusService;
    @Autowired
    private EquipmentAlarmService equipmentAlarmService;
    @Autowired
    private MaterialTraceabilityService materialTraceabilityService;
    @Autowired
    private EquipmentInfoService equipmentInfoService;
    @Autowired
    private RepairManageInfoService repairManageInfoService;
    @Autowired
    private LocationInfoService locationInfoService;
    @Autowired
    private GreaseManageService greaseManageService;
    @Autowired
    private ProductionOrderRecordsService productionOrderRecordsService;
    @Autowired
    private ProductionOrderBatchInfoService productionOrderBatchInfoService;
    private static Logger logger;
    LogUtil logUtil = new LogUtil();
    static {
        logger = Logger.getLogger(EOP090Callback.class);
    }
    private static Date IN_TIME = null;
    private static String S_ORDER_CODE = "";//工单编号
    private static String S_PRODUCT_CODE = "";//产品编号
    private static String S_PRODUCT_TYPE= "";//产品类型
    private static String S_SFC_CODE = "";//总成编码
    private static String PRODUCTION_LINE  = "EOP";//产线号
    private static String LOCATION_CODE  = "EOP090";//工位号
    private static List list = null;
    public EOP090Callback(MiloService miloService,
                          ProductionOrdeInfoService productionOrdeInfoService,
                          PassingStationCollectionService passingStationCollectionService,
                          ParamCollectionService paramCollectionService,
                          CollectionParamConfService collectionParamConfService,
                          SerialNumbersConfService serialNumbersConfService,
                          EquipmentStatusService equipmentStatusService,
                          EquipmentAlarmService equipmentAlarmService,
                          MaterialTraceabilityService materialTraceabilityService,
                          EquipmentInfoService equipmentInfoService,
                          RepairManageInfoService repairManageInfoService,
                          LocationInfoService locationInfoService,
                          GreaseManageService greaseManageService,
                          ProductionOrderRecordsService productionOrderRecordsService,
                          ProductionOrderBatchInfoService productionOrderBatchInfoService) {
        this.miloService = miloService;
        this.productionOrdeInfoService = productionOrdeInfoService;
        this.passingStationCollectionService = passingStationCollectionService;
        this.paramCollectionService = paramCollectionService;
        this.collectionParamConfService = collectionParamConfService;
        this.serialNumbersConfService = serialNumbersConfService;
        this.equipmentStatusService = equipmentStatusService;
        this.equipmentAlarmService = equipmentAlarmService;
        this.materialTraceabilityService = materialTraceabilityService;
        this.equipmentInfoService = equipmentInfoService;
        this.repairManageInfoService = repairManageInfoService;
        this.locationInfoService = locationInfoService;
        this.greaseManageService = greaseManageService;
        this.productionOrderRecordsService = productionOrderRecordsService;
        this.productionOrderBatchInfoService = productionOrderBatchInfoService;
    }
    @Override
    public void onSubscribe(String identifier, Object value) {
        String ecpStr = "";//异常记录标记
        try {
            //心跳
            if(null != value && identifier.equals(OPCElement.EOP090_F_HEART_BEAT)){
                if( "false".equals(value.toString()))
                {
                    ReadWriteEntity entity = new ReadWriteEntity(OPCElement.EOP090_F_HEART_BEAT,true);
                    miloService.writeToOpcUa(entity);
                }
            }
            //PLC进站
            else if(null != value && identifier.equals(OPCElement.EOP090_J_PLC_START)){
                if("true".equals(value.toString())){
                    handleOrder();
                }
            }
            //PLC出站
            else if(null != value && identifier.equals(OPCElement.EOP090_J_PLC_FINISH)){
                if("true".equals(value.toString())){
                    handleFinsh();
                    handleInfo();
                    handleMaterial();
                }
            }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 {
        logger.info("handleOrder PC处理开始!");
        IN_TIME = DateTool.getLocalTimeForDate();
        List<String> lists = new ArrayList<>();
        lists.add(OPCElement.EOP090_S_ORDER_CODE);
        lists.add(OPCElement.EOP090_S_PRODUCT_CODE);
        lists.add(OPCElement.EOP090_S_SFC_CODE);
        List<ReadWriteEntity> returnLists= miloService.readFromOpcUa(lists);
        returnLists.forEach(element->{
            switch(element.getIdentifier()){
                case OPCElement.EOP090_S_ORDER_CODE:
                    S_ORDER_CODE = element.getValue().toString();
                    break;
                case OPCElement.EOP090_S_PRODUCT_CODE:
                    S_PRODUCT_TYPE = element.getValue().toString();
                    S_PRODUCT_CODE = GlobalVariable.PRODUCT_CODE_MAP.get(S_PRODUCT_TYPE);
                    break;
                case OPCElement.EOP090_S_SFC_CODE:
                    S_SFC_CODE = element.getValue().toString();
                    break;
                default:
                    break;
            }
        });
        ReadWriteEntity entity = new ReadWriteEntity(OPCElement.EOP090_J_PC_WRITE_ORDER,true);
        miloService.writeToOpcUa(entity);
        logger.info("handleOrder PC处理完成!");
    }
    public void handleFinsh() throws Exception {
        logger.info("handleFinsh PC处理开始!");
        String S_PRODUCT_STATE_CODE = miloService.
                readFromOpcUa(OPCElement.EOP090_S_PRODUCT_STATE_CODE)
                .getValue().toString();
        //处理过站信息
        PassingStationCollectionParam param = new PassingStationCollectionParam();
        param.setWorkOrderNo(S_ORDER_CODE);
        param.setProductCode(S_PRODUCT_CODE);
        param.setSfcCode(S_SFC_CODE);
        param.setProductionLine(PRODUCTION_LINE);
        param.setLocationCode(LOCATION_CODE);
        param.setInboundTime(IN_TIME);
        param.setOutboundTime(DateTool.getLocalTimeForDate());
        param.setOutRsSign(S_PRODUCT_STATE_CODE);//出站是否合格
        passingStationCollectionService.add(param);
        ReadWriteEntity entity = new ReadWriteEntity(OPCElement.EOP090_J_PC_FINISH,true);
        miloService.writeToOpcUa(entity);//写PC完成
        logger.info("handleFinsh PC处理完成!");
    }
    public void handleMaterial() {
        //查询批次上料信息
        ProductionOrderBatchInfoParam productionOrderBatchInfoParam = new ProductionOrderBatchInfoParam();
        productionOrderBatchInfoParam.setWorkOrderNo(S_ORDER_CODE);
        productionOrderBatchInfoParam.setLocationCode(LOCATION_CODE);
        List<ProductionOrderBatchInfoResult> list = productionOrderBatchInfoService.findListBySpec(productionOrderBatchInfoParam);
        for(int i=0;i<list.size();i++){
            ProductionOrderBatchInfoResult productionOrderBatchInfoResult = list.get(i);
            int remainingQuantity =  productionOrderBatchInfoResult.getResidueQuantity();//剩余数量
            if(remainingQuantity>0 ){
                //新增物料追溯
                MaterialTraceabilityParam materialTraceabilityParam = new MaterialTraceabilityParam();
                materialTraceabilityParam.setWorkOrderNo(S_ORDER_CODE);
                materialTraceabilityParam.setProductCode(S_PRODUCT_CODE);
                materialTraceabilityParam.setProductNo(S_SFC_CODE);
                materialTraceabilityParam.setLineCode(PRODUCTION_LINE);
                materialTraceabilityParam.setLocationCode(LOCATION_CODE);
                materialTraceabilityParam.setAssemblyQty(1);
                materialTraceabilityParam.setAssemblyTime(DateTool.getLocalTimeForDate());
                materialTraceabilityParam.setMaterialCode(productionOrderBatchInfoResult.getMaterialCode());//物料编码
                materialTraceabilityParam.setMaterialBatchNo(productionOrderBatchInfoResult.getBatch());//物料批次
                materialTraceabilityService.add(materialTraceabilityParam);
                //更新剩余数量
                productionOrderBatchInfoParam.setId(productionOrderBatchInfoResult.getId());
                productionOrderBatchInfoParam.setResidueQuantity(remainingQuantity-1);//剩余数量
                productionOrderBatchInfoService.update(productionOrderBatchInfoParam);
            }
        }
    }
    //PC读参数信息
    public void handleInfo() throws Exception {
        logger.info("handleInfo START!");
        if(null == list){
            CollectionParamConfParam collectionParamConfParam = new CollectionParamConfParam();
            collectionParamConfParam.setLocationCode(LOCATION_CODE);
            list = collectionParamConfService.findListBySpec(collectionParamConfParam);
        }
        if(null != list && !list.isEmpty()) {
            for (int i = 0; i < list.size(); i++) {
                CollectionParamConfResult result = (CollectionParamConfResult) list.get(i);
                String value = miloService.
                        readFromOpcUa(result.getGatherAddress())
                        .getValue().toString();//读参数值
                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);
                paramCollectionParam.setParamLower(result.getParamLower());
                paramCollectionParam.setParamUpper(result.getParamUpper());
                paramCollectionParam.setParamStandard(result.getParamCentral());
                paramCollectionParam.setCollectionTime(DateTool.getLocalTimeForDate());
                paramCollectionParam.setUnit(result.getUnit());
                paramCollectionService.add(paramCollectionParam);
            }
        }
        logger.info("handleInfo END!");
    }
}
guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/InitCallback.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,1162 @@
package cn.stylefeng.guns.plcserver.callback;
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.model.params.EquipmentInfoParam;
import cn.stylefeng.guns.modular.bs.equipmentInfo.model.result.EquipmentInfoResult;
import cn.stylefeng.guns.modular.bs.equipmentInfo.service.EquipmentInfoService;
import cn.stylefeng.guns.modular.bs.locationInfo.model.params.LocationInfoParam;
import cn.stylefeng.guns.modular.bs.locationInfo.model.result.LocationInfoResult;
import cn.stylefeng.guns.modular.bs.locationInfo.service.LocationInfoService;
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;
import cn.stylefeng.guns.modular.cm.passingStationCollection.service.PassingStationCollectionService;
import cn.stylefeng.guns.modular.dq.materialTraceability.model.params.MaterialTraceabilityParam;
import cn.stylefeng.guns.modular.dq.materialTraceability.service.MaterialTraceabilityService;
import cn.stylefeng.guns.modular.em.equipmentAlarm.model.params.EquipmentAlarmParam;
import cn.stylefeng.guns.modular.em.equipmentAlarm.service.EquipmentAlarmService;
import cn.stylefeng.guns.modular.em.equipmentStatus.model.params.EquipmentStatusParam;
import cn.stylefeng.guns.modular.em.equipmentStatus.model.result.EquipmentStatusResult;
import cn.stylefeng.guns.modular.em.equipmentStatus.service.EquipmentStatusService;
import cn.stylefeng.guns.modular.gm.greaseManage.service.GreaseManageService;
import cn.stylefeng.guns.modular.om.productionOrdeInfo.model.params.ProductionOrdeInfoParam;
import cn.stylefeng.guns.modular.om.productionOrdeInfo.model.result.ProductionOrdeInfoResult;
import cn.stylefeng.guns.modular.om.productionOrdeInfo.service.ProductionOrdeInfoService;
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.model.params.ProductionOrderBatchInfoParam;
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.model.result.ProductionOrderBatchInfoResult;
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.service.ProductionOrderBatchInfoService;
import cn.stylefeng.guns.modular.om.productionOrderRecords.model.params.ProductionOrderRecordsParam;
import cn.stylefeng.guns.modular.om.productionOrderRecords.model.result.ProductionOrderRecordsResult;
import cn.stylefeng.guns.modular.om.productionOrderRecords.service.ProductionOrderRecordsService;
import cn.stylefeng.guns.modular.sc.repairManageInfo.model.params.RepairManageInfoParam;
import cn.stylefeng.guns.modular.sc.repairManageInfo.model.result.RepairManageInfoResult;
import cn.stylefeng.guns.modular.sc.repairManageInfo.service.RepairManageInfoService;
import cn.stylefeng.guns.modular.sc.serialNumbersConf.model.params.SerialNumbersConfParam;
import cn.stylefeng.guns.modular.sc.serialNumbersConf.model.result.SerialNumbersConfResult;
import cn.stylefeng.guns.modular.sc.serialNumbersConf.service.SerialNumbersConfService;
import cn.stylefeng.guns.plcserver.opc.GlobalVariable;
import cn.stylefeng.guns.plcserver.opc.OPCElement;
import cn.stylefeng.guns.plcserver.opc.unit.SFCCodeTool;
import cn.stylefeng.guns.plcserver.tool.DateTool;
import cn.stylefeng.guns.plcserver.tool.LogUtil;
import com.kangaroohy.milo.model.ReadWriteEntity;
import com.kangaroohy.milo.runner.subscription.SubscriptionCallback;
import com.kangaroohy.milo.service.MiloService;
import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
@Component
public class InitCallback implements SubscriptionCallback {
    public MiloService miloService;
    @Autowired
    public ProductionOrdeInfoService productionOrdeInfoService;
    @Autowired
    public PassingStationCollectionService passingStationCollectionService;
    @Autowired
    public ParamCollectionService paramCollectionService;
    @Autowired
    public CollectionParamConfService collectionParamConfService;
    @Autowired
    public SerialNumbersConfService serialNumbersConfService;
    @Autowired
    private EquipmentStatusService equipmentStatusService;
    @Autowired
    private EquipmentAlarmService equipmentAlarmService;
    @Autowired
    private MaterialTraceabilityService materialTraceabilityService;
    @Autowired
    private EquipmentInfoService equipmentInfoService;
    @Autowired
    private RepairManageInfoService repairManageInfoService;
    @Autowired
    private LocationInfoService locationInfoService;
    @Autowired
    private GreaseManageService greaseManageService;
    @Autowired
    private ProductionOrderRecordsService productionOrderRecordsService;
    @Autowired
    private ProductionOrderBatchInfoService productionOrderBatchInfoService;
    private static Logger logger;
    LogUtil logUtil = new LogUtil();
    static {
        logger = Logger.getLogger(InitCallback.class);
    }
    private static Date IN_TIME = null;
    private static String S_ORDER_CODE = "";//工单编号
    private static String S_PRODUCT_CODE = "";//产品编号
    private static String S_PRODUCT_TYPE= "";//产品类型
    private static String S_SFC_CODE = "";//总成编码
    private static String PRODUCTION_LINE  = "OP";//产线号
    private static String LOCATION_CODE  = "OP010";//工位号
    private static List list = null;
    private static Integer ACTUAL_ONLINE_QTY  = 0 ;//上线数量
    OP010Callback OP010Callback;
    OP020Callback OP020Callback;
    OP030Callback OP030Callback;
    OP040Callback OP040Callback;
    OP050Callback OP050Callback;
    OP070Callback OP070Callback;
    OP080Callback OP080Callback;
    OP090Callback OP090Callback;
    OP100Callback OP100Callback;
    OP110Callback OP110Callback;
    OP120Callback OP120Callback;
    OP120BCallback OP120BCallback;
    OP130Callback OP130Callback;
    OP130BCallback OP130BCallback;
    OP140Callback OP140Callback;
    OP150Callback OP150Callback;
    OP160Callback OP160Callback;
    OP170Callback OP170Callback;
    BOP010Callback BOP010Callback;
    BOP020Callback BOP020Callback;
    BOP030Callback BOP030Callback;
    BOP030BCallback BOP030BCallback;
    BOP040Callback BOP040Callback;
    BOP040BCallback BOP040BCallback;
    COP010Callback COP010Callback;
    COP020Callback COP020Callback;
    COP030Callback COP030Callback;
    DOP010Callback DOP010Callback;
    DOP020Callback DOP020Callback;
    EOP010Callback EOP010Callback;
    EOP020Callback EOP020Callback;
    EOP030Callback EOP030Callback;
    EOP040Callback EOP040Callback;
    EOP050Callback EOP050Callback;
    EOP060Callback EOP060Callback;
    EOP070Callback EOP070Callback;
    EOP080Callback EOP080Callback;
    EOP090Callback EOP090Callback;
    EOP090BCallback EOP090BCallback;
    StateCallback StateCallback;
    public InitCallback(MiloService miloService,
                        ProductionOrdeInfoService productionOrdeInfoService,
                        PassingStationCollectionService passingStationCollectionService,
                        ParamCollectionService paramCollectionService,
                        CollectionParamConfService collectionParamConfService,
                        SerialNumbersConfService serialNumbersConfService,
                        EquipmentStatusService equipmentStatusService,
                        EquipmentAlarmService equipmentAlarmService,
                        MaterialTraceabilityService materialTraceabilityService,
                        EquipmentInfoService equipmentInfoService,
                        RepairManageInfoService repairManageInfoService,
                        LocationInfoService locationInfoService,
                        GreaseManageService greaseManageService,
                        ProductionOrderRecordsService productionOrderRecordsService,
                        ProductionOrderBatchInfoService productionOrderBatchInfoService) {
        this.miloService = miloService;
        this.productionOrdeInfoService = productionOrdeInfoService;
        this.passingStationCollectionService = passingStationCollectionService;
        this.paramCollectionService = paramCollectionService;
        this.collectionParamConfService = collectionParamConfService;
        this.serialNumbersConfService = serialNumbersConfService;
        this.equipmentStatusService = equipmentStatusService;
        this.equipmentAlarmService = equipmentAlarmService;
        this.materialTraceabilityService = materialTraceabilityService;
        this.equipmentInfoService = equipmentInfoService;
        this.repairManageInfoService = repairManageInfoService;
        this.locationInfoService = locationInfoService;
        this.greaseManageService = greaseManageService;
        this.productionOrderRecordsService = productionOrderRecordsService;
        this.productionOrderBatchInfoService = productionOrderBatchInfoService;
        OP010Callback = new OP010Callback(miloService,productionOrdeInfoService,
                passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService,
                equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService,
                repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService,
                productionOrderBatchInfoService);
        OP020Callback = new OP020Callback(miloService,productionOrdeInfoService,
                passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService,
                equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService,
                repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService,
                productionOrderBatchInfoService);
        OP030Callback = new OP030Callback(miloService,productionOrdeInfoService,
                passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService,
                equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService,
                repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService,
                productionOrderBatchInfoService);
        OP040Callback = new OP040Callback(miloService,productionOrdeInfoService,
                passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService,
                equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService,
                repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService,
                productionOrderBatchInfoService);
        OP050Callback = new OP050Callback(miloService,productionOrdeInfoService,
                passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService,
                equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService,
                repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService,
                productionOrderBatchInfoService);
   /*     OP060Callback = new OP060Callback(miloService,productionOrdeInfoService,
                passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService,
                equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService,
                repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService,
                productionOrderBatchInfoService);*/
        OP070Callback = new OP070Callback(miloService,productionOrdeInfoService,
                passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService,
                equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService,
                repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService,
                productionOrderBatchInfoService);
        OP080Callback = new OP080Callback(miloService,productionOrdeInfoService,
                passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService,
                equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService,
                repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService,
                productionOrderBatchInfoService);
        OP090Callback = new OP090Callback(miloService,productionOrdeInfoService,
                passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService,
                equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService,
                repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService,
                productionOrderBatchInfoService);
        OP100Callback = new OP100Callback(miloService,productionOrdeInfoService,
                passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService,
                equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService,
                repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService,
                productionOrderBatchInfoService);
        OP110Callback = new OP110Callback(miloService,productionOrdeInfoService,
                passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService,
                equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService,
                repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService,
                productionOrderBatchInfoService);
        OP120Callback = new OP120Callback(miloService,productionOrdeInfoService,
                passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService,
                equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService,
                repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService,
                productionOrderBatchInfoService);
        OP120BCallback = new OP120BCallback(miloService,productionOrdeInfoService,
                passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService,
                equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService,
                repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService,
                productionOrderBatchInfoService);
        OP130Callback = new OP130Callback(miloService,productionOrdeInfoService,
                passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService,
                equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService,
                repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService,
                productionOrderBatchInfoService);
        OP130BCallback = new OP130BCallback(miloService,productionOrdeInfoService,
                passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService,
                equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService,
                repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService,
                productionOrderBatchInfoService);
        OP140Callback = new OP140Callback(miloService,productionOrdeInfoService,
                passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService,
                equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService,
                repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService,
                productionOrderBatchInfoService);
        OP150Callback = new OP150Callback(miloService,productionOrdeInfoService,
                passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService,
                equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService,
                repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService,
                productionOrderBatchInfoService);
        OP160Callback = new OP160Callback(miloService,productionOrdeInfoService,
                passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService,
                equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService,
                repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService,
                productionOrderBatchInfoService);
        OP170Callback = new OP170Callback(miloService,productionOrdeInfoService,
                passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService,
                equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService,
                repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService,
                productionOrderBatchInfoService);
        COP010Callback = new COP010Callback(miloService,productionOrdeInfoService,
                passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService,
                equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService,
                repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService,
                productionOrderBatchInfoService);
        COP020Callback = new COP020Callback(miloService,productionOrdeInfoService,
                passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService,
                equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService,
                repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService,
                productionOrderBatchInfoService);
        COP030Callback = new COP030Callback(miloService,productionOrdeInfoService,
                passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService,
                equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService,
                repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService,
                productionOrderBatchInfoService);
        BOP010Callback = new BOP010Callback(miloService,productionOrdeInfoService,
                passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService,
                equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService,
                repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService,
                productionOrderBatchInfoService);
        BOP020Callback = new BOP020Callback(miloService,productionOrdeInfoService,
                passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService,
                equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService,
                repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService,
                productionOrderBatchInfoService);
        BOP030Callback = new BOP030Callback(miloService,productionOrdeInfoService,
                passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService,
                equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService,
                repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService,
                productionOrderBatchInfoService);
        BOP030BCallback = new BOP030BCallback(miloService,productionOrdeInfoService,
                passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService,
                equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService,
                repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService,
                productionOrderBatchInfoService);
        BOP040Callback = new BOP040Callback(miloService,productionOrdeInfoService,
                passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService,
                equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService,
                repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService,
                productionOrderBatchInfoService);
        BOP040BCallback = new BOP040BCallback(miloService,productionOrdeInfoService,
                passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService,
                equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService,
                repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService,
                productionOrderBatchInfoService);
        DOP010Callback = new DOP010Callback(miloService,productionOrdeInfoService,
                passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService,
                equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService,
                repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService,
                productionOrderBatchInfoService);
        DOP020Callback = new DOP020Callback(miloService,productionOrdeInfoService,
                passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService,
                equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService,
                repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService,
                productionOrderBatchInfoService);
        EOP010Callback = new EOP010Callback(miloService,productionOrdeInfoService,
                passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService,
                equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService,
                repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService,
                productionOrderBatchInfoService);
        EOP020Callback = new EOP020Callback(miloService,productionOrdeInfoService,
                passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService,
                equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService,
                repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService,
                productionOrderBatchInfoService);
        EOP030Callback = new EOP030Callback(miloService,productionOrdeInfoService,
                passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService,
                equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService,
                repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService,
                productionOrderBatchInfoService);
        EOP040Callback = new EOP040Callback(miloService,productionOrdeInfoService,
                passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService,
                equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService,
                repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService,
                productionOrderBatchInfoService);
        EOP050Callback = new EOP050Callback(miloService,productionOrdeInfoService,
                passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService,
                equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService,
                repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService,
                productionOrderBatchInfoService);
        EOP060Callback = new EOP060Callback(miloService,productionOrdeInfoService,
                passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService,
                equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService,
                repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService,
                productionOrderBatchInfoService);
        EOP070Callback = new EOP070Callback(miloService,productionOrdeInfoService,
                passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService,
                equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService,
                repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService,
                productionOrderBatchInfoService);
        EOP080Callback = new EOP080Callback(miloService,productionOrdeInfoService,
                passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService,
                equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService,
                repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService,
                productionOrderBatchInfoService);
        EOP090Callback = new EOP090Callback(miloService,productionOrdeInfoService,
                passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService,
                equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService,
                repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService,
                productionOrderBatchInfoService);
        EOP090BCallback = new EOP090BCallback(miloService,productionOrdeInfoService,
                passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService,
                equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService,
                repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService,
                productionOrderBatchInfoService);
        StateCallback = new StateCallback(miloService,productionOrdeInfoService,
                passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService,
                equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService,
                repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService,
                productionOrderBatchInfoService);
    }
    @Override
    public void onSubscribe(String identifier, Object value) {
        String ecpStr = "";//异常记录标记
        try {
            if(null != value) {
                //OP010
                //心跳
                if (identifier.equals(OPCElement.OP010_F_HEART_BEAT) && null != value && "false".equals(value.toString())) {
                    ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP010_F_HEART_BEAT, true);
                    miloService.writeToOpcUa(entity);
                }
                //PLC进站
                else if (identifier.equals(OPCElement.OP010_J_PLC_START) && null != value && "true".equals(value.toString())) {
                    String isRepair = miloService.readFromOpcUa(OPCElement.OP010_P_REPAIR).getValue().toString();//是否返修
                    if (isRepair.equals("true")) {
                        OP010Callback.handleRepair();
                    } else {
                        OP010Callback.handleOrder();
                    }
                }
                //PLC出站
                else if (identifier.equals(OPCElement.OP010_J_PLC_FINISH) && null != value && "true".equals(value.toString())) {
                    OP010Callback.handleFinsh();
                    OP010Callback.handleMaterial();
                }
                //OP020
                //心跳
                else if (identifier.equals(OPCElement.OP020_F_HEART_BEAT) && null != value && "false".equals(value.toString())) {
                    ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP020_F_HEART_BEAT, true);
                    miloService.writeToOpcUa(entity);
                }
                //PLC进站
                else if (identifier.equals(OPCElement.OP020_J_PLC_START) && null != value && "true".equals(value.toString())) {
                    OP020Callback.handleOrder();
                }
                //PLC出站
                else if (identifier.equals(OPCElement.OP020_J_PLC_FINISH) && null != value && "true".equals(value.toString())) {
                    OP020Callback.handleFinsh();
                    OP020Callback.handleMaterial();
                    OP020Callback.handleInfo();
                }
                //OP030
                //心跳
                else if (identifier.equals(OPCElement.OP030_F_HEART_BEAT) && null != value && "false".equals(value.toString())) {
                    ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP030_F_HEART_BEAT, true);
                    miloService.writeToOpcUa(entity);
                }
                //PLC进站
                else if (identifier.equals(OPCElement.OP030_J_PLC_START) && null != value && "true".equals(value.toString())) {
                    OP030Callback.handleOrder();
                }
                //PLC出站
                else if (identifier.equals(OPCElement.OP030_J_PLC_FINISH) && null != value && "true".equals(value.toString())) {
                    OP030Callback.handleFinsh();
                    OP030Callback.handleMaterial();
                    OP030Callback.handleInfo();
                }
                //OP040
                //心跳
                else if (identifier.equals(OPCElement.OP040_F_HEART_BEAT) && null != value && "false".equals(value.toString())) {
                    ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP040_F_HEART_BEAT, true);
                    miloService.writeToOpcUa(entity);
                }
                //PLC进站
                else if (identifier.equals(OPCElement.OP040_J_PLC_START) && null != value && "true".equals(value.toString())) {
                    OP040Callback.handleOrder();
                }
                //PLC出站
                else if (identifier.equals(OPCElement.OP040_J_PLC_FINISH) && null != value && "true".equals(value.toString())) {
                    OP040Callback.handleFinsh();
                    OP040Callback.handleMaterial();
                    OP040Callback.handleInfo();
                }
                //OP050
                //心跳
                else if (identifier.equals(OPCElement.OP050_F_HEART_BEAT) && null != value && "false".equals(value.toString())) {
                    ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP050_F_HEART_BEAT, true);
                    miloService.writeToOpcUa(entity);
                }
                //PLC进站
                else if (identifier.equals(OPCElement.OP050_J_PLC_START) && null != value && "true".equals(value.toString())) {
                    OP050Callback.handleOrder();
                }
                //PLC出站
                else if (identifier.equals(OPCElement.OP050_J_PLC_FINISH) && null != value && "true".equals(value.toString())) {
                    OP050Callback.handleMaterial();
                    OP050Callback.handleInfo();
                    OP050Callback.handleFinsh();
                }
                //OP070
                //心跳
                else if (identifier.equals(OPCElement.OP070_F_HEART_BEAT) && null != value && "false".equals(value.toString())) {
                    ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP070_F_HEART_BEAT, true);
                    miloService.writeToOpcUa(entity);
                }
                //PLC进站
                else if (identifier.equals(OPCElement.OP070_J_PLC_START) && null != value && "true".equals(value.toString())) {
                    OP070Callback.handleOrder();
                }
                //PLC出站
                else if (identifier.equals(OPCElement.OP070_J_PLC_FINISH) && null != value && "true".equals(value.toString())) {
                    OP070Callback.handleFinsh();
                    OP070Callback.handleMaterial();
                    OP070Callback.handleInfo();
                }
                //OP080
                //心跳
                else if (identifier.equals(OPCElement.OP080_F_HEART_BEAT) && null != value && "false".equals(value.toString())) {
                    ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP080_F_HEART_BEAT, true);
                    miloService.writeToOpcUa(entity);
                }
                //PLC进站
                else if (identifier.equals(OPCElement.OP080_J_PLC_START) && null != value && "true".equals(value.toString())) {
                    String isRepair = miloService.readFromOpcUa(OPCElement.OP080_P_REPAIR).getValue().toString();//是否返修
                    if (isRepair.equals("true")) {
                        OP080Callback.handleRepair();
                    } else {
                        OP080Callback.handleOrder();
                    }
                }
                //PLC出站
                else if (identifier.equals(OPCElement.OP080_J_PLC_FINISH) && null != value && "true".equals(value.toString())) {
                    OP080Callback.handleFinsh();
                    OP080Callback.handleMaterial();
                    OP080Callback.handleInfo();
                }
                //OP090
                //心跳
                else if (identifier.equals(OPCElement.OP090_F_HEART_BEAT) && null != value && "false".equals(value.toString())) {
                    ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP090_F_HEART_BEAT, true);
                    miloService.writeToOpcUa(entity);
                }
                //PLC进站
                else if (identifier.equals(OPCElement.OP090_J_PLC_START) && null != value && "true".equals(value.toString())) {
                    OP090Callback.handleOrder();
                }
                //PLC出站
                else if (identifier.equals(OPCElement.OP100_J_PLC_FINISH) && null != value && "true".equals(value.toString())) {
                    OP100Callback.handleMaterial();
                    OP100Callback.handleInfo();
                    OP100Callback.handleFinsh();
                }
                //OP110
                //心跳
                else if (identifier.equals(OPCElement.OP110_F_HEART_BEAT) && null != value && "false".equals(value.toString())) {
                    ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP110_F_HEART_BEAT, true);
                    miloService.writeToOpcUa(entity);
                }
                //PLC进站
                else if (identifier.equals(OPCElement.OP110_J_PLC_START) && null != value && "true".equals(value.toString())) {
                    OP110Callback.handleOrder();
                }
                //PLC出站
                else if (identifier.equals(OPCElement.OP110_J_PLC_FINISH) && null != value && "true".equals(value.toString())) {
                    OP110Callback.handleFinsh();
                    OP110Callback.handleMaterial();
                    OP110Callback.handleInfo();
                }
                //OP120
                //心跳
                else if (identifier.equals(OPCElement.OP120_F_HEART_BEAT) && null != value && "false".equals(value.toString())) {
                    ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP120_F_HEART_BEAT, true);
                    miloService.writeToOpcUa(entity);
                }
                //PLC进站
                else if (identifier.equals(OPCElement.OP120_J_PLC_START) && null != value && "true".equals(value.toString())) {
                    OP120Callback.handleOrder();
                }
                //PLC出站
                else if (identifier.equals(OPCElement.OP120_J_PLC_FINISH) && null != value && "true".equals(value.toString())) {
                    OP120Callback.handleFinsh();
                    OP120Callback.handleMaterial();
                    OP120Callback.handleInfo();
                }
                //OP120B
                //心跳
                else if (identifier.equals(OPCElement.OP120B_F_HEART_BEAT) && null != value && "false".equals(value.toString())) {
                    ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP120B_F_HEART_BEAT, true);
                    miloService.writeToOpcUa(entity);
                }
                //PLC进站
                else if (identifier.equals(OPCElement.OP120B_J_PLC_START) && null != value && "true".equals(value.toString())) {
                    OP120BCallback.handleOrder();
                }
                //PLC出站
                else if (identifier.equals(OPCElement.OP120B_J_PLC_FINISH) && null != value && "true".equals(value.toString())) {
                    OP120BCallback.handleFinsh();
                    OP120BCallback.handleMaterial();
                    OP120BCallback.handleInfo();
                }
                //OP130
                //心跳
                else if (identifier.equals(OPCElement.OP130_F_HEART_BEAT) && null != value && "false".equals(value.toString())) {
                    ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP130_F_HEART_BEAT, true);
                    miloService.writeToOpcUa(entity);
                }
                //PLC进站
                else if (identifier.equals(OPCElement.OP130_J_PLC_START) && null != value && "true".equals(value.toString())) {
                    OP130Callback.handleOrder();
                }
                //PLC出站
                else if (identifier.equals(OPCElement.OP130_J_PLC_FINISH) && null != value && "true".equals(value.toString())) {
                    OP130Callback.handleFinsh();
                    OP130Callback.handleMaterial();
                    OP130Callback.handleInfo();
                }
                //OP130B
                //心跳
                else if (identifier.equals(OPCElement.OP130B_F_HEART_BEAT) && null != value && "false".equals(value.toString())) {
                    ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP130B_F_HEART_BEAT, true);
                    miloService.writeToOpcUa(entity);
                }
                //PLC进站
                else if (identifier.equals(OPCElement.OP130B_J_PLC_START) && null != value && "true".equals(value.toString())) {
                    OP130BCallback.handleOrder();
                }
                //PLC出站
                else if (identifier.equals(OPCElement.OP130B_J_PLC_FINISH) && null != value && "true".equals(value.toString())) {
                    OP130BCallback.handleFinsh();
                    OP130BCallback.handleMaterial();
                    OP130BCallback.handleInfo();
                }
                //OP140
                //心跳
                else if (identifier.equals(OPCElement.OP140_F_HEART_BEAT) && null != value && "false".equals(value.toString())) {
                    ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP140_F_HEART_BEAT, true);
                    miloService.writeToOpcUa(entity);
                }
                //PLC进站
                else if (identifier.equals(OPCElement.OP140_J_PLC_START) && null != value && "true".equals(value.toString())) {
                    OP140Callback.handleOrder();
                }
                //PLC出站
                else if (identifier.equals(OPCElement.OP140_J_PLC_FINISH) && null != value && "true".equals(value.toString())) {
                    OP140Callback.handleFinsh();
                    OP140Callback.handleMaterial();
                    OP140Callback.handleInfo();
                }
                //OP150
                //心跳
                else if (identifier.equals(OPCElement.OP150_F_HEART_BEAT) && null != value && "false".equals(value.toString())) {
                    ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP150_F_HEART_BEAT, true);
                    miloService.writeToOpcUa(entity);
                }
                //PLC进站
                else if (identifier.equals(OPCElement.OP150_J_PLC_START) && null != value && "true".equals(value.toString())) {
                    OP150Callback.handleOrder();
                }
                //PLC出站
                else if (identifier.equals(OPCElement.OP150_J_PLC_FINISH) && null != value && "true".equals(value.toString())) {
                    OP150Callback.handleFinsh();
                    OP150Callback.handleMaterial();
                    OP150Callback.handleInfo();
                }
                //OP160
                //心跳
                else if (identifier.equals(OPCElement.OP160_F_HEART_BEAT) && null != value && "false".equals(value.toString())) {
                    ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP160_F_HEART_BEAT, true);
                    miloService.writeToOpcUa(entity);
                }
                //PLC进站
                else if (identifier.equals(OPCElement.OP160_J_PLC_START) && null != value && "true".equals(value.toString())) {
                    OP160Callback.handleOrder();
                }
                //PLC出站
                else if (identifier.equals(OPCElement.OP160_J_PLC_FINISH) && null != value && "true".equals(value.toString())) {
                    OP160Callback.handleFinsh();
                    OP160Callback.handleMaterial();
                    OP160Callback.handleInfo();
                }
                //OP170
                //心跳
                else if (identifier.equals(OPCElement.OP170_F_HEART_BEAT) && null != value && "false".equals(value.toString())) {
                    ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP170_F_HEART_BEAT, true);
                    miloService.writeToOpcUa(entity);
                }
                //PLC进站
                else if (identifier.equals(OPCElement.OP170_J_PLC_START) && null != value && "true".equals(value.toString())) {
                    OP170Callback.handleOrder();
                }
                //PLC出站
                else if (identifier.equals(OPCElement.OP170_J_PLC_FINISH) && null != value && "true".equals(value.toString())) {
                    OP170Callback.handleFinsh();
                    OP170Callback.handleMaterial();
                    //OP170Callback.handleInfo();
                }
                //BOP010
                //心跳
                else if (identifier.equals(OPCElement.BOP010_F_HEART_BEAT) && null != value && "false".equals(value.toString())) {
                    ReadWriteEntity entity = new ReadWriteEntity(OPCElement.BOP010_F_HEART_BEAT, true);
                    miloService.writeToOpcUa(entity);
                }
                //PLC进站
                else if (identifier.equals(OPCElement.BOP010_J_PLC_START) && null != value && "true".equals(value.toString())) {
                    String isRepair = miloService.readFromOpcUa(OPCElement.BOP010_P_REPAIR).getValue().toString();//是否返修
                    if (isRepair.equals("true")) {
                        BOP010Callback.handleRepair();
                    } else {
                        BOP010Callback.handleOrder();
                    }
                }
                //PLC出站
                else if (identifier.equals(OPCElement.BOP010_J_PLC_FINISH) && null != value && "true".equals(value.toString())) {
                    BOP010Callback.handleFinsh();
                    BOP010Callback.handleMaterial();
                    //BOP010Callback.handleInfo();
                }
                //BOP020
                //心跳
                else if (identifier.equals(OPCElement.BOP020_F_HEART_BEAT) && null != value && "false".equals(value.toString())) {
                    ReadWriteEntity entity = new ReadWriteEntity(OPCElement.BOP020_F_HEART_BEAT, true);
                    miloService.writeToOpcUa(entity);
                }
                //PLC进站
                else if (identifier.equals(OPCElement.BOP020_J_PLC_START) && null != value && "true".equals(value.toString())) {
                    BOP020Callback.handleOrder();
                }
                //PLC出站
                else if (identifier.equals(OPCElement.BOP020_J_PLC_FINISH) && null != value && "true".equals(value.toString())) {
                    BOP020Callback.handleFinsh();
                    BOP020Callback.handleMaterial();
                    BOP020Callback.handleInfo();
                }
                //BOP030
                //心跳
                else if (identifier.equals(OPCElement.BOP030_F_HEART_BEAT) && null != value && "false".equals(value.toString())) {
                    ReadWriteEntity entity = new ReadWriteEntity(OPCElement.BOP030_F_HEART_BEAT, true);
                    miloService.writeToOpcUa(entity);
                }
                //PLC进站
                else if (identifier.equals(OPCElement.BOP030_J_PLC_START) && null != value && "true".equals(value.toString())) {
                    BOP030Callback.handleOrder();
                }
                //PLC出站
                else if (identifier.equals(OPCElement.BOP030_J_PLC_FINISH) && null != value && "true".equals(value.toString())) {
                    BOP030Callback.handleFinsh();
                    BOP030Callback.handleMaterial();
                    BOP030Callback.handleInfo();
                }
                //BOP030B
                //心跳
                else if (identifier.equals(OPCElement.BOP030B_F_HEART_BEAT) && null != value && "false".equals(value.toString())) {
                    ReadWriteEntity entity = new ReadWriteEntity(OPCElement.BOP030B_F_HEART_BEAT, true);
                    miloService.writeToOpcUa(entity);
                }
                //PLC进站
                else if (identifier.equals(OPCElement.BOP030B_J_PLC_START) && null != value && "true".equals(value.toString())) {
                    BOP030BCallback.handleOrder();
                }
                //PLC出站
                else if (identifier.equals(OPCElement.BOP030B_J_PLC_FINISH) && null != value && "true".equals(value.toString())) {
                    BOP030BCallback.handleFinsh();
                    //BOP030BCallback.handleMaterial();
                    //BOP030BCallback.handleInfo();
                }
                //BOP040
                //心跳
                else if (identifier.equals(OPCElement.BOP040_F_HEART_BEAT) && null != value && "false".equals(value.toString())) {
                    ReadWriteEntity entity = new ReadWriteEntity(OPCElement.BOP040_F_HEART_BEAT, true);
                    miloService.writeToOpcUa(entity);
                }
                //PLC进站
                else if (identifier.equals(OPCElement.BOP040_J_PLC_START) && null != value && "true".equals(value.toString())) {
                    BOP040Callback.handleOrder();
                }
                //PLC出站
                else if (identifier.equals(OPCElement.BOP040_J_PLC_FINISH) && null != value && "true".equals(value.toString())) {
                    BOP040Callback.handleFinsh();
                    BOP040Callback.handleMaterial();
                    BOP040Callback.handleInfo();
                }
                //BOP040B
                //心跳
                else if (identifier.equals(OPCElement.BOP040B_F_HEART_BEAT) && null != value && "false".equals(value.toString())) {
                    ReadWriteEntity entity = new ReadWriteEntity(OPCElement.BOP040B_F_HEART_BEAT, true);
                    miloService.writeToOpcUa(entity);
                }
                //PLC进站
                else if (identifier.equals(OPCElement.BOP040B_J_PLC_START) && null != value && "true".equals(value.toString())) {
                    BOP040BCallback.handleOrder();
                }
                //PLC出站
                else if (identifier.equals(OPCElement.BOP040B_J_PLC_FINISH) && null != value && "true".equals(value.toString())) {
                    BOP040BCallback.handleFinsh();
                   // BOP040BCallback.handleMaterial();
                    //BOP040BCallback.handleInfo();
                }
                //COP010
                //心跳
                else if (identifier.equals(OPCElement.COP010_F_HEART_BEAT) && null != value && "false".equals(value.toString())) {
                    ReadWriteEntity entity = new ReadWriteEntity(OPCElement.COP010_F_HEART_BEAT, true);
                    miloService.writeToOpcUa(entity);
                }
                //PLC进站
                else if (identifier.equals(OPCElement.COP010_J_PLC_START) && null != value && "true".equals(value.toString())) {
                    String isRepair = miloService.readFromOpcUa(OPCElement.COP010_P_REPAIR).getValue().toString();//是否返修
                    if (isRepair.equals("true")) {
                        COP010Callback.handleRepair();
                    } else {
                        COP010Callback.handleOrder();
                    }
                }
                //PLC出站
                else if (identifier.equals(OPCElement.COP010_J_PLC_FINISH) && null != value && "true".equals(value.toString())) {
                    COP010Callback.handleFinsh();
                    COP010Callback.handleMaterial();
                    //COP010Callback.handleInfo();
                }
                //COP020
                //心跳
                else if (identifier.equals(OPCElement.COP020_F_HEART_BEAT) && null != value && "false".equals(value.toString())) {
                    ReadWriteEntity entity = new ReadWriteEntity(OPCElement.COP020_F_HEART_BEAT, true);
                    miloService.writeToOpcUa(entity);
                }
                //PLC进站
                else if (identifier.equals(OPCElement.COP020_J_PLC_START) && null != value && "true".equals(value.toString())) {
                    COP020Callback.handleOrder();
                }
                //PLC出站
                else if (identifier.equals(OPCElement.COP020_J_PLC_FINISH) && null != value && "true".equals(value.toString())) {
                    COP020Callback.handleFinsh();
                    COP020Callback.handleMaterial();
                    COP020Callback.handleInfo();
                }
                //COP030
                //心跳
                else if (identifier.equals(OPCElement.COP030_F_HEART_BEAT) && null != value && "false".equals(value.toString())) {
                    ReadWriteEntity entity = new ReadWriteEntity(OPCElement.COP030_F_HEART_BEAT, true);
                    miloService.writeToOpcUa(entity);
                }
                //PLC进站
                else if (identifier.equals(OPCElement.COP030_J_PLC_START) && null != value && "true".equals(value.toString())) {
                    COP030Callback.handleOrder();
                }
                //PLC出站
                else if (identifier.equals(OPCElement.COP030_J_PLC_FINISH) && null != value && "true".equals(value.toString())) {
                    COP030Callback.handleFinsh();
                    COP030Callback.handleMaterial();
                    COP030Callback.handleInfo();
                }
                //DOP010
                //心跳
                else if (identifier.equals(OPCElement.DOP010_F_HEART_BEAT) && null != value && "false".equals(value.toString())) {
                    ReadWriteEntity entity = new ReadWriteEntity(OPCElement.DOP010_F_HEART_BEAT, true);
                    miloService.writeToOpcUa(entity);
                }
                //PLC进站
                else if (identifier.equals(OPCElement.DOP010_J_PLC_START) && null != value && "true".equals(value.toString())) {
                    String isRepair = miloService.readFromOpcUa(OPCElement.DOP010_P_REPAIR).getValue().toString();//是否返修
                    if (isRepair.equals("true")) {
                        DOP010Callback.handleRepair();
                    } else {
                        DOP010Callback.handleOrder();
                    }
                }
                //PLC出站
                else if (identifier.equals(OPCElement.DOP010_J_PLC_FINISH) && null != value && "true".equals(value.toString())) {
                    DOP010Callback.handleFinsh();
                    DOP010Callback.handleMaterial();
                    //DOP010Callback.handleInfo();
                }
                //DOP020
                //心跳
                else if (identifier.equals(OPCElement.DOP020_F_HEART_BEAT) && null != value && "false".equals(value.toString())) {
                    ReadWriteEntity entity = new ReadWriteEntity(OPCElement.DOP020_F_HEART_BEAT, true);
                    miloService.writeToOpcUa(entity);
                }
                //PLC进站
                else if (identifier.equals(OPCElement.DOP020_J_PLC_START) && null != value && "true".equals(value.toString())) {
                    DOP020Callback.handleOrder();
                }
                //PLC出站
                else if (identifier.equals(OPCElement.DOP020_J_PLC_FINISH) && null != value && "true".equals(value.toString())) {
                    DOP020Callback.handleFinsh();
                    DOP020Callback.handleMaterial();
                    DOP020Callback.handleInfo();
                }
                //EOP010
                //心跳
                else if (identifier.equals(OPCElement.EOP010_F_HEART_BEAT) && null != value && "false".equals(value.toString())) {
                    ReadWriteEntity entity = new ReadWriteEntity(OPCElement.EOP010_F_HEART_BEAT, true);
                    miloService.writeToOpcUa(entity);
                }
                //PLC进站
                else if (identifier.equals(OPCElement.EOP010_J_PLC_START) && null != value && "true".equals(value.toString())) {
                    EOP010Callback.handleOrder();
                }
                //PLC出站
                else if (identifier.equals(OPCElement.EOP010_J_PLC_FINISH) && null != value && "true".equals(value.toString())) {
                    EOP010Callback.handleFinsh();
                    EOP010Callback.handleMaterial();
                    EOP010Callback.handleInfo();
                }
                //EOP020
                //心跳
                else if (identifier.equals(OPCElement.EOP020_F_HEART_BEAT) && null != value && "false".equals(value.toString())) {
                    ReadWriteEntity entity = new ReadWriteEntity(OPCElement.EOP020_F_HEART_BEAT, true);
                    miloService.writeToOpcUa(entity);
                }
                //PLC进站
                else if (identifier.equals(OPCElement.EOP020_J_PLC_START) && null != value && "true".equals(value.toString())) {
                    EOP020Callback.handleOrder();
                }
                //PLC出站
                else if (identifier.equals(OPCElement.EOP020_J_PLC_FINISH) && null != value && "true".equals(value.toString())) {
                    EOP020Callback.handleFinsh();
                    EOP020Callback.handleMaterial();
                    EOP020Callback.handleInfo();
                }
                //EOP030
                //心跳
                else if (identifier.equals(OPCElement.EOP030_F_HEART_BEAT) && null != value && "false".equals(value.toString())) {
                    ReadWriteEntity entity = new ReadWriteEntity(OPCElement.EOP030_F_HEART_BEAT, true);
                    miloService.writeToOpcUa(entity);
                }
                //PLC进站
                else if (identifier.equals(OPCElement.EOP030_J_PLC_START) && null != value && "true".equals(value.toString())) {
                    EOP030Callback.handleOrder();
                }
                //PLC出站
                else if (identifier.equals(OPCElement.EOP030_J_PLC_FINISH) && null != value && "true".equals(value.toString())) {
                    EOP030Callback.handleFinsh();
                    EOP030Callback.handleMaterial();
                    EOP030Callback.handleInfo();
                }
                //EOP040
                //心跳
                else if (identifier.equals(OPCElement.EOP040_F_HEART_BEAT) && null != value && "false".equals(value.toString())) {
                    ReadWriteEntity entity = new ReadWriteEntity(OPCElement.EOP040_F_HEART_BEAT, true);
                    miloService.writeToOpcUa(entity);
                }
                //PLC进站
                else if (identifier.equals(OPCElement.EOP040_J_PLC_START) && null != value && "true".equals(value.toString())) {
                    EOP040Callback.handleOrder();
                }
                //PLC出站
                else if (identifier.equals(OPCElement.EOP040_J_PLC_FINISH) && null != value && "true".equals(value.toString())) {
                    EOP040Callback.handleFinsh();
                    EOP040Callback.handleMaterial();
                    EOP040Callback.handleInfo();
                }
                //EOP050
                //心跳
                else if (identifier.equals(OPCElement.EOP050_F_HEART_BEAT) && null != value && "false".equals(value.toString())) {
                    ReadWriteEntity entity = new ReadWriteEntity(OPCElement.EOP050_F_HEART_BEAT, true);
                    miloService.writeToOpcUa(entity);
                }
                //PLC进站
                else if (identifier.equals(OPCElement.EOP050_J_PLC_START) && null != value && "true".equals(value.toString())) {
                    EOP050Callback.handleOrder();
                }
                //PLC出站
                else if (identifier.equals(OPCElement.EOP050_J_PLC_FINISH) && null != value && "true".equals(value.toString())) {
                    EOP050Callback.handleFinsh();
                    EOP050Callback.handleMaterial();
                    EOP050Callback.handleInfo();
                }
                //EOP060
                //心跳
                else if (identifier.equals(OPCElement.EOP060_F_HEART_BEAT) && null != value && "false".equals(value.toString())) {
                    ReadWriteEntity entity = new ReadWriteEntity(OPCElement.EOP060_F_HEART_BEAT, true);
                    miloService.writeToOpcUa(entity);
                }
                //PLC进站
                else if (identifier.equals(OPCElement.EOP060_J_PLC_START) && null != value && "true".equals(value.toString())) {
                    EOP060Callback.handleOrder();
                }
                //PLC出站
                else if (identifier.equals(OPCElement.EOP060_J_PLC_FINISH) && null != value && "true".equals(value.toString())) {
                    EOP060Callback.handleFinsh();
                    EOP060Callback.handleMaterial();
                    EOP060Callback.handleInfo();
                }
                //EOP070
                //心跳
                else if (identifier.equals(OPCElement.EOP070_F_HEART_BEAT) && null != value && "false".equals(value.toString())) {
                    ReadWriteEntity entity = new ReadWriteEntity(OPCElement.EOP070_F_HEART_BEAT, true);
                    miloService.writeToOpcUa(entity);
                }
                //PLC进站
                else if (identifier.equals(OPCElement.EOP070_J_PLC_START) && null != value && "true".equals(value.toString())) {
                    EOP070Callback.handleOrder();
                }
                //PLC出站
                else if (identifier.equals(OPCElement.EOP070_J_PLC_FINISH) && null != value && "true".equals(value.toString())) {
                    EOP070Callback.handleFinsh();
                    EOP070Callback.handleMaterial();
                    EOP070Callback.handleInfo();
                }
                //EOP080
                //心跳
                else if (identifier.equals(OPCElement.EOP080_F_HEART_BEAT) && null != value && "false".equals(value.toString())) {
                    ReadWriteEntity entity = new ReadWriteEntity(OPCElement.EOP080_F_HEART_BEAT, true);
                    miloService.writeToOpcUa(entity);
                }
                //PLC进站
                else if (identifier.equals(OPCElement.EOP080_J_PLC_START) && null != value && "true".equals(value.toString())) {
                    EOP080Callback.handleOrder();
                }
                //PLC出站
                else if (identifier.equals(OPCElement.EOP080_J_PLC_FINISH) && null != value && "true".equals(value.toString())) {
                    EOP080Callback.handleFinsh();
                    EOP080Callback.handleMaterial();
                    EOP080Callback.handleInfo();
                }
                //EOP090
                //心跳
                else if (identifier.equals(OPCElement.EOP090_F_HEART_BEAT) && null != value && "false".equals(value.toString())) {
                    ReadWriteEntity entity = new ReadWriteEntity(OPCElement.EOP090_F_HEART_BEAT, true);
                    miloService.writeToOpcUa(entity);
                }
                //PLC进站
                else if (identifier.equals(OPCElement.EOP090_J_PLC_START) && null != value && "true".equals(value.toString())) {
                    EOP090Callback.handleOrder();
                }
                //PLC出站
                else if (identifier.equals(OPCElement.EOP090_J_PLC_FINISH) && null != value && "true".equals(value.toString())) {
                    EOP090Callback.handleFinsh();
                    EOP090Callback.handleMaterial();
                    EOP090Callback.handleInfo();
                }
                //EOP090B
                //心跳
                else if (identifier.equals(OPCElement.EOP090B_F_HEART_BEAT) && null != value && "false".equals(value.toString())) {
                    ReadWriteEntity entity = new ReadWriteEntity(OPCElement.EOP090B_F_HEART_BEAT, true);
                    miloService.writeToOpcUa(entity);
                }
                //PLC进站
                else if (identifier.equals(OPCElement.EOP090B_J_PLC_START) && null != value && "true".equals(value.toString())) {
                    EOP090BCallback.handleOrder();
                }
                //PLC出站
                else if (identifier.equals(OPCElement.EOP090B_J_PLC_FINISH) && null != value && "true".equals(value.toString())) {
                    EOP090BCallback.handleFinsh();
                    EOP090BCallback.handleMaterial();
                    EOP090BCallback.handleInfo();
                }
                else if (identifier.contains("STATE") && null != value && "true".equals(value.toString())) {
                    EquipmentInfoParam equipmentInfoParam = new EquipmentInfoParam();
                    equipmentInfoParam.setSpareField1(identifier);
                    List<EquipmentInfoResult> lists = equipmentInfoService.findListBySpec(equipmentInfoParam);
                    if(!lists.isEmpty()){
                        EquipmentInfoResult result = (EquipmentInfoResult) list.get(0);
                        String equipmentNo = result.getEquipmentNo();
                        EquipmentStatusParam equipmentStatusParam = new EquipmentStatusParam();
                        equipmentStatusParam.setEquipmentNo(equipmentNo);
                        List statuslist = equipmentStatusService.findListBySpec(equipmentStatusParam);
                        if(statuslist.size()>0){
                            EquipmentStatusResult equipmentStatusResult = (EquipmentStatusResult) statuslist.get(0);
                            if(!value.equals(equipmentStatusResult.getStatus())){
                                equipmentStatusParam.setId(equipmentStatusResult.getId());
                                equipmentStatusParam.setStatus(value.toString());
                                equipmentStatusParam.setUpdateTime(DateTool.getLocalTimeForDate());
                                equipmentStatusService.update(equipmentStatusParam);//更新设备状态
                                //添加设备报警
                                if("3".equals(value)){
                                    EquipmentAlarmParam equipmentAlarmParam = new EquipmentAlarmParam();
                                    equipmentAlarmParam.setEquipmentNo(equipmentNo);
                                    equipmentAlarmParam.setEquipmentName(result.getEquipmentName());
                                    equipmentAlarmParam.setWorkshopCode(result.getWorkshopCode());
                                    equipmentAlarmParam.setProductionLineCode(result.getProductionLineCode());
                                    equipmentAlarmParam.setLocationCode(result.getLocationCode());
                                    equipmentAlarmParam.setErrorDesc(result.getEquipmentName()+"报警!");
                                    equipmentAlarmParam.setAlarmTime(DateTool.getLocalTimeForDate());
                                    equipmentAlarmService.add(equipmentAlarmParam);
                                }
                            }
                        }else{
                            equipmentStatusParam.setEquipmentName(result.getEquipmentName());
                            equipmentStatusParam.setWorkshopCode(result.getWorkshopCode());
                            equipmentStatusParam.setProductionLineCode(result.getProductionLineCode());
                            equipmentStatusParam.setLocationCode(result.getLocationCode());
                            equipmentStatusParam.setStatus(value.toString());
                            equipmentStatusParam.setUpdateTime(DateTool.getLocalTimeForDate());
                            equipmentStatusService.add(equipmentStatusParam);
                            //添加设备报警
                            if("3".equals(value)){
                                EquipmentAlarmParam equipmentAlarmParam = new EquipmentAlarmParam();
                                equipmentAlarmParam.setEquipmentNo(equipmentNo);
                                equipmentAlarmParam.setEquipmentName(result.getEquipmentName());
                                equipmentAlarmParam.setWorkshopCode(result.getWorkshopCode());
                                equipmentAlarmParam.setProductionLineCode(result.getProductionLineCode());
                                equipmentAlarmParam.setLocationCode(result.getLocationCode());
                                equipmentAlarmParam.setErrorDesc(result.getEquipmentName()+"报警!");
                                equipmentAlarmParam.setAlarmTime(DateTool.getLocalTimeForDate());
                                equipmentAlarmService.add(equipmentAlarmParam);
                            }
                        }
                    }
                    // handleOilState("DOP020");
                    StateCallback.handleOilStateOP050("OP050");
                    StateCallback.handleOilStateBOP030("BOP030");
                }
                else {
                    System.out.println("值没有变");
                }
            }else {
                System.out.println("值为空");
            }
        } catch (Exception e) {
            ecpStr ="出现异常:" + logUtil.getTrace(e);
        }finally {
            if(!"".equals(ecpStr)){
                System.out.println(ecpStr+"\r\n");
                logger.info(ecpStr+"\r\n");
            }
        }
    }
}
guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/OP010Callback.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,420 @@
package cn.stylefeng.guns.plcserver.callback;
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.model.params.LocationInfoParam;
import cn.stylefeng.guns.modular.bs.locationInfo.model.result.LocationInfoResult;
import cn.stylefeng.guns.modular.bs.locationInfo.service.LocationInfoService;
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;
import cn.stylefeng.guns.modular.cm.passingStationCollection.service.PassingStationCollectionService;
import cn.stylefeng.guns.modular.dq.materialTraceability.model.params.MaterialTraceabilityParam;
import cn.stylefeng.guns.modular.dq.materialTraceability.service.MaterialTraceabilityService;
import cn.stylefeng.guns.modular.em.equipmentAlarm.service.EquipmentAlarmService;
import cn.stylefeng.guns.modular.em.equipmentStatus.service.EquipmentStatusService;
import cn.stylefeng.guns.modular.gm.greaseManage.service.GreaseManageService;
import cn.stylefeng.guns.modular.om.productionOrdeInfo.model.params.ProductionOrdeInfoParam;
import cn.stylefeng.guns.modular.om.productionOrdeInfo.model.result.ProductionOrdeInfoResult;
import cn.stylefeng.guns.modular.om.productionOrdeInfo.service.ProductionOrdeInfoService;
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.model.params.ProductionOrderBatchInfoParam;
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.model.result.ProductionOrderBatchInfoResult;
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.service.ProductionOrderBatchInfoService;
import cn.stylefeng.guns.modular.om.productionOrderRecords.model.params.ProductionOrderRecordsParam;
import cn.stylefeng.guns.modular.om.productionOrderRecords.model.result.ProductionOrderRecordsResult;
import cn.stylefeng.guns.modular.om.productionOrderRecords.service.ProductionOrderRecordsService;
import cn.stylefeng.guns.modular.sc.repairManageInfo.model.params.RepairManageInfoParam;
import cn.stylefeng.guns.modular.sc.repairManageInfo.model.result.RepairManageInfoResult;
import cn.stylefeng.guns.modular.sc.repairManageInfo.service.RepairManageInfoService;
import cn.stylefeng.guns.modular.sc.serialNumbersConf.model.params.SerialNumbersConfParam;
import cn.stylefeng.guns.modular.sc.serialNumbersConf.model.result.SerialNumbersConfResult;
import cn.stylefeng.guns.modular.sc.serialNumbersConf.service.SerialNumbersConfService;
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.opc.unit.SFCCodeTool;
import cn.stylefeng.guns.plcserver.tool.DateTool;
import cn.stylefeng.guns.plcserver.tool.LogUtil;
import com.kangaroohy.milo.model.ReadWriteEntity;
import com.kangaroohy.milo.runner.subscription.SubscriptionCallback;
import com.kangaroohy.milo.service.MiloService;
import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
@Component
public class OP010Callback implements SubscriptionCallback {
    public MiloService miloService;
    @Autowired
    public ProductionOrdeInfoService productionOrdeInfoService;
    @Autowired
    public PassingStationCollectionService passingStationCollectionService;
    @Autowired
    public ParamCollectionService paramCollectionService;
    @Autowired
    public CollectionParamConfService collectionParamConfService;
    @Autowired
    public SerialNumbersConfService serialNumbersConfService;
    @Autowired
    private EquipmentStatusService equipmentStatusService;
    @Autowired
    private EquipmentAlarmService equipmentAlarmService;
    @Autowired
    private MaterialTraceabilityService materialTraceabilityService;
    @Autowired
    private EquipmentInfoService equipmentInfoService;
    @Autowired
    private RepairManageInfoService repairManageInfoService;
    @Autowired
    private LocationInfoService locationInfoService;
    @Autowired
    private GreaseManageService greaseManageService;
    @Autowired
    private ProductionOrderRecordsService productionOrderRecordsService;
    @Autowired
    private ProductionOrderBatchInfoService productionOrderBatchInfoService;
    private static Logger logger;
    LogUtil logUtil = new LogUtil();
    static {
        logger = Logger.getLogger(OP010Callback.class);
    }
    private static Date IN_TIME = null;
    private static String S_ORDER_CODE = "";//工单编号
    private static String S_PRODUCT_CODE = "";//产品编号
    private static String S_PRODUCT_TYPE= "";//产品类型
    private static String S_SFC_CODE = "";//总成编码
    private static String PRODUCTION_LINE  = "OP";//产线号
    private static String LOCATION_CODE  = "OP010";//工位号
    private static List list = null;
    private static Integer ACTUAL_ONLINE_QTY  = 0 ;//上线数量
    public OP010Callback(MiloService miloService,
                         ProductionOrdeInfoService productionOrdeInfoService,
                         PassingStationCollectionService passingStationCollectionService,
                         ParamCollectionService paramCollectionService,
                         CollectionParamConfService collectionParamConfService,
                         SerialNumbersConfService serialNumbersConfService,
                         EquipmentStatusService equipmentStatusService,
                         EquipmentAlarmService equipmentAlarmService,
                         MaterialTraceabilityService materialTraceabilityService,
                         EquipmentInfoService equipmentInfoService,
                         RepairManageInfoService repairManageInfoService,
                         LocationInfoService locationInfoService,
                         GreaseManageService greaseManageService,
                         ProductionOrderRecordsService productionOrderRecordsService,
                         ProductionOrderBatchInfoService productionOrderBatchInfoService) {
        this.miloService = miloService;
        this.productionOrdeInfoService = productionOrdeInfoService;
        this.passingStationCollectionService = passingStationCollectionService;
        this.paramCollectionService = paramCollectionService;
        this.collectionParamConfService = collectionParamConfService;
        this.serialNumbersConfService = serialNumbersConfService;
        this.equipmentStatusService = equipmentStatusService;
        this.equipmentAlarmService = equipmentAlarmService;
        this.materialTraceabilityService = materialTraceabilityService;
        this.equipmentInfoService = equipmentInfoService;
        this.repairManageInfoService = repairManageInfoService;
        this.locationInfoService = locationInfoService;
        this.greaseManageService = greaseManageService;
        this.productionOrderRecordsService = productionOrderRecordsService;
        this.productionOrderBatchInfoService = productionOrderBatchInfoService;
    }
    @Override
    public void onSubscribe(String identifier, Object value) {
        String ecpStr = "";//异常记录标记
        try {
            //心跳
            if(null != value && identifier.equals(OPCElement.OP010_F_HEART_BEAT)){
                if( "false".equals(value.toString()))
                {
                    ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP010_F_HEART_BEAT,true);
                    miloService.writeToOpcUa(entity);
                }
            }
            //PLC进站
            else if(null != value && identifier.equals(OPCElement.OP010_J_PLC_START)){
                if("true".equals(value.toString())){
                    String isRepair = miloService.
                            readFromOpcUa(OPCElement.OP010_P_REPAIR)
                            .getValue().toString();//是否返修
                    if(isRepair.equals("true")){
                        handleRepair();
                    }else{
                        handleOrder();
                    }
                    handleOrder();
                }
            }
            //PLC出站
            else if(null != value && identifier.equals(OPCElement.OP010_J_PLC_FINISH)){
                if("true".equals(value.toString())){
                    handleFinsh();
                    handleMaterial();
                }
            }else{
                System.out.println("值没有变");
            }
        } catch (Exception e) {
            ecpStr ="出现异常:" + logUtil.getTrace(e);
        }finally {
            if(!"".equals(ecpStr)){
                logger.info(ecpStr+"\r\n");
            }
            System.out.println("finally" +ecpStr);
        }
    }
    //PC读工单
    public void handleOrder() throws Exception{
        logger.info("OP010工位,handleOrder PC处理开始!");
        IN_TIME = DateTool.getLocalTimeForDate();
        ProductionOrdeInfoParam param = new ProductionOrdeInfoParam();
        param.setProductionLine("");//产线
        param.setOrderStatus("3");//工单状态
        List<ProductionOrdeInfoResult> list = productionOrdeInfoService.findListBySpec(param);
        if(!list.isEmpty()) {
            ProductionOrdeInfoResult result = list.get(0);
            String softwareVersionCode = result.getSoftwareVersionCode();//产品型号
            String productCompanyCode = result.getProductCompanyCode();//班次
            //序列号
            String serialNumbers = "0000";
            SerialNumbersConfParam serialNumbersConfParam = new SerialNumbersConfParam();
            Calendar calendar = Calendar.getInstance();
            String Years = String.valueOf(calendar.get(Calendar.YEAR)); //年份
            String Months = StringUtils.leftPad(String.valueOf(calendar.get(Calendar.MONTH) + 1),2, "0"); //月份
            String Dates = StringUtils.leftPad(String.valueOf(calendar.get(Calendar.DATE)),2, "0"); //日期
            serialNumbersConfParam.setYears(Years+Months+Dates);//获取当前是哪一天
            serialNumbersConfParam.setState("1");
            List<SerialNumbersConfResult> serialNumberslist = serialNumbersConfService.findListBySpec(serialNumbersConfParam);
            if(!serialNumberslist.isEmpty()){
                SerialNumbersConfResult serialNumbersConfResult = serialNumberslist.get(0);
                serialNumbers = serialNumbersConfResult.getSerialNumber();
                serialNumbersConfParam.setId(serialNumbersConfResult.getId());
            }else{
                serialNumbersConfParam.setSerialNumber(serialNumbers);
                serialNumbersConfParam.setLengths("4");
                serialNumbersConfService.add(serialNumbersConfParam);
                List<SerialNumbersConfResult> serialNumberslist2 = serialNumbersConfService.findListBySpec(serialNumbersConfParam);
                if(!serialNumberslist2.isEmpty()){
                    SerialNumbersConfResult serialNumbersConfResult = serialNumberslist2.get(0);
                    //serialNumbers = serialNumbersConfResult.getSerialNumber();
                    serialNumbersConfParam.setId(serialNumbersConfResult.getId());
                }
            }
            //更新序列号+1
            int i = Integer.valueOf(serialNumbers)+1;
            serialNumbers = StringUtils.leftPad(String.valueOf(i),4, "0");
            serialNumbersConfParam.setSerialNumber(serialNumbers);
            serialNumbersConfService.update(serialNumbersConfParam);
            //生成总成编码
            String sfcCode = SFCCodeTool.createCodingRulesSFC(softwareVersionCode,productCompanyCode,serialNumbers);//总成号
            S_SFC_CODE = sfcCode;
            S_ORDER_CODE = result.getWorkOrderNo();
            S_PRODUCT_CODE = result.getMaterialCode();
            S_PRODUCT_TYPE = GlobalVariable.PRODUCT_TYPE_MAP.get(S_PRODUCT_CODE);
            ACTUAL_ONLINE_QTY = result.getActualOnlineQty();
            //新增报工记录
            ProductionOrderRecordsParam productionOrderRecordsParam = new ProductionOrderRecordsParam();
            productionOrderRecordsParam.setWorkOrderNo(S_ORDER_CODE);
            productionOrderRecordsParam.setProductNo(S_SFC_CODE);
            productionOrderRecordsParam.setMaterialCode(S_PRODUCT_CODE);
            productionOrderRecordsParam.setStartTime(DateTool.getLocalTimeForDate());
            productionOrderRecordsParam.setWhetherPass("true");
            productionOrderRecordsService.add(productionOrderRecordsParam);
            List<ReadWriteEntity> lists = new ArrayList<>();
            lists.add(new ReadWriteEntity(OPCElement.OP010_S_ORDER_CODE,S_ORDER_CODE));
            lists.add(new ReadWriteEntity(OPCElement.OP010_S_PRODUCT_CODE,S_PRODUCT_TYPE));
            lists.add(new ReadWriteEntity(OPCElement.OP010_S_SFC_CODE,S_SFC_CODE));
            lists.add(new ReadWriteEntity(OPCElement.OP010_S_NUMBER,result.getPlanQty().toString()));
            lists.add(new ReadWriteEntity(OPCElement.OP010_J_PC_WRITE_ORDER,true));
            miloService.writeToOpcUa(lists);
            logger.info("OP010工位,handleOrder PC处理完成!^--------------------------------------------");
        }else{
            logger.info("OP010工位没有可执行的工单,请联系工单管理员下发该产线的工单!");
        }
    }
    public void handleFinsh() throws Exception {
        logger.info("handleFinsh PC处理开始!");
        String S_PRODUCT_STATE_CODE = miloService.
                readFromOpcUa(OPCElement.OP010_S_PRODUCT_STATE_CODE)
                .getValue().toString();
        if("2".equals(S_PRODUCT_STATE_CODE)){
            ProductionOrderRecordsParam productionOrderRecordsParam = new ProductionOrderRecordsParam();
            productionOrderRecordsParam.setWorkOrderNo(S_ORDER_CODE);
            productionOrderRecordsParam.setProductNo(S_SFC_CODE);
            List<ProductionOrderRecordsResult> list = productionOrderRecordsService.findListBySpec(productionOrderRecordsParam);
            if(!list.isEmpty()){
                ProductionOrderRecordsResult productionOrderRecordsResult = list.get(0);
                productionOrderRecordsParam.setId(productionOrderRecordsResult.getId());
                productionOrderRecordsParam.setWhetherPass(S_PRODUCT_STATE_CODE);
                productionOrderRecordsService.update(productionOrderRecordsParam);
            }
        }
        //处理过站信息
        PassingStationCollectionParam param = new PassingStationCollectionParam();
        param.setWorkOrderNo(S_ORDER_CODE);
        param.setProductCode(S_PRODUCT_CODE);
        param.setSfcCode(S_SFC_CODE);
        param.setProductionLine(PRODUCTION_LINE);
        param.setLocationCode(LOCATION_CODE);
        param.setInboundTime(IN_TIME);
        param.setOutboundTime(DateTool.getLocalTimeForDate());
        param.setOutRsSign(S_PRODUCT_STATE_CODE);//出站是否合格
        passingStationCollectionService.add(param);
        ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP010_J_PC_FINISH,true);
        miloService.writeToOpcUa(entity);//写PC完成
        logger.info("handleFinsh PC处理完成!");
    }
    public void handleMaterial() {
        //查询批次上料信息
        ProductionOrderBatchInfoParam productionOrderBatchInfoParam = new ProductionOrderBatchInfoParam();
        productionOrderBatchInfoParam.setWorkOrderNo(S_ORDER_CODE);
        productionOrderBatchInfoParam.setLocationCode(LOCATION_CODE);
        List<ProductionOrderBatchInfoResult> list = productionOrderBatchInfoService.findListBySpec(productionOrderBatchInfoParam);
        for(int i=0;i<list.size();i++){
            ProductionOrderBatchInfoResult productionOrderBatchInfoResult = list.get(i);
            int remainingQuantity =  productionOrderBatchInfoResult.getResidueQuantity();//剩余数量
            if(remainingQuantity>0 ){
                //新增物料追溯
                MaterialTraceabilityParam materialTraceabilityParam = new MaterialTraceabilityParam();
                materialTraceabilityParam.setWorkOrderNo(S_ORDER_CODE);
                materialTraceabilityParam.setProductCode(S_PRODUCT_CODE);
                materialTraceabilityParam.setProductNo(S_SFC_CODE);
                materialTraceabilityParam.setLineCode(PRODUCTION_LINE);
                materialTraceabilityParam.setLocationCode(LOCATION_CODE);
                materialTraceabilityParam.setAssemblyQty(1);
                materialTraceabilityParam.setAssemblyTime(DateTool.getLocalTimeForDate());
                materialTraceabilityParam.setMaterialCode(productionOrderBatchInfoResult.getMaterialCode());//物料编码
                materialTraceabilityParam.setMaterialBatchNo(productionOrderBatchInfoResult.getBatch());//物料批次
                materialTraceabilityService.add(materialTraceabilityParam);
                //更新剩余数量
                productionOrderBatchInfoParam.setId(productionOrderBatchInfoResult.getId());
                productionOrderBatchInfoParam.setResidueQuantity(remainingQuantity-1);//剩余数量
                productionOrderBatchInfoService.update(productionOrderBatchInfoParam);
            }
        }
    }
    public void handleRepair() throws Exception{
        RepairManageInfoParam repairManageInfoParam = new RepairManageInfoParam();
        repairManageInfoParam.setLocationCode(LOCATION_CODE);
        repairManageInfoParam.setManageType("2");
        repairManageInfoParam.setUpPlc("0");
        List<RepairManageInfoResult> list = repairManageInfoService.findListBySpec(repairManageInfoParam);
        if(list.size()>0) {
            RepairManageInfoResult result = list.get(0);
            S_SFC_CODE = result.getSfc();
            S_ORDER_CODE = result.getWorkOrderNo();
            S_PRODUCT_CODE = result.getProductCode();
            S_PRODUCT_TYPE = GlobalVariable.PRODUCT_TYPE_MAP.get(S_PRODUCT_CODE);
            String  repairLocation = result.getPoorLocationCode();//
            //根据工位编码查询工位表中配置的返修工位号
            LocationInfoParam param = new LocationInfoParam();
            param.setLocationCode(repairLocation);
            List<LocationInfoResult> results = locationInfoService.findListBySpec(param);
            if(results.size()>0) {
                LocationInfoResult r = results.get(0);
                String repairLocationNo = r.getSpareField2();
                if(null != repairLocationNo && "" != repairLocationNo){
                    List<ReadWriteEntity> lists = new ArrayList<>();
                    lists.add(new ReadWriteEntity(OPCElement.OP010_S_ORDER_CODE,S_ORDER_CODE));
                    lists.add(new ReadWriteEntity(OPCElement.OP010_S_PRODUCT_CODE,S_PRODUCT_TYPE));
                    lists.add(new ReadWriteEntity(OPCElement.OP010_S_SFC_CODE,S_SFC_CODE));
                    lists.add(new ReadWriteEntity(OPCElement.OP010_P_REPAIR_LOCATION,repairLocationNo));
                    lists.add(new ReadWriteEntity(OPCElement.OP010_J_PC_WRITE_ORDER,true));
                    miloService.writeToOpcUa(lists);
                    //更新为已经返修上线
                    Long id = result.getId();
                    repairManageInfoParam.setId(id);
                    repairManageInfoParam.setUpPlc("1");
                    repairManageInfoService.update(repairManageInfoParam);
                }else{
                    logger.info("OP010工位,handleRepair è¯·æŸ¥è¯¢"+repairLocation+"工位是否配置返修工位号!");
                }
            }else{
                logger.info("OP010工位,handleRepair æ— æ³•æŸ¥è¯¢åˆ°"+repairLocation+"工位!");
            }
        }
    }
    //PC读参数信息
    public void handleInfo() throws Exception {
        logger.info("handleInfo START!");
        if(null == list){
            CollectionParamConfParam collectionParamConfParam = new CollectionParamConfParam();
            collectionParamConfParam.setLocationCode(LOCATION_CODE);
            list = collectionParamConfService.findListBySpec(collectionParamConfParam);
        }
        if(null != list && !list.isEmpty()) {
            for (int i = 0; i < list.size(); i++) {
                CollectionParamConfResult result = (CollectionParamConfResult) list.get(i);
                String value = miloService.
                        readFromOpcUa(result.getGatherAddress())
                        .getValue().toString();//读参数值
                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);
                paramCollectionParam.setParamLower(result.getParamLower());
                paramCollectionParam.setParamUpper(result.getParamUpper());
                paramCollectionParam.setParamStandard(result.getParamCentral());
                paramCollectionParam.setCollectionTime(DateTool.getLocalTimeForDate());
                paramCollectionParam.setUnit(result.getUnit());
                paramCollectionService.add(paramCollectionParam);
            }
        }
        logger.info("handleInfo END!");
    }
}
guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/OP020Callback.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,298 @@
package cn.stylefeng.guns.plcserver.callback;
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.model.params.ParamCollectionParam;
import cn.stylefeng.guns.modular.cm.paramCollection.service.ParamCollectionService;
import cn.stylefeng.guns.modular.cm.passingStationCollection.model.params.PassingStationCollectionParam;
import cn.stylefeng.guns.modular.cm.passingStationCollection.service.PassingStationCollectionService;
import cn.stylefeng.guns.modular.dq.materialTraceability.model.params.MaterialTraceabilityParam;
import cn.stylefeng.guns.modular.dq.materialTraceability.service.MaterialTraceabilityService;
import cn.stylefeng.guns.modular.em.equipmentAlarm.service.EquipmentAlarmService;
import cn.stylefeng.guns.modular.em.equipmentStatus.service.EquipmentStatusService;
import cn.stylefeng.guns.modular.gm.greaseManage.service.GreaseManageService;
import cn.stylefeng.guns.modular.om.productionOrdeInfo.service.ProductionOrdeInfoService;
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.model.params.ProductionOrderBatchInfoParam;
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.model.result.ProductionOrderBatchInfoResult;
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.service.ProductionOrderBatchInfoService;
import cn.stylefeng.guns.modular.om.productionOrderRecords.model.params.ProductionOrderRecordsParam;
import cn.stylefeng.guns.modular.om.productionOrderRecords.model.result.ProductionOrderRecordsResult;
import cn.stylefeng.guns.modular.om.productionOrderRecords.service.ProductionOrderRecordsService;
import cn.stylefeng.guns.modular.sc.repairManageInfo.service.RepairManageInfoService;
import cn.stylefeng.guns.modular.sc.serialNumbersConf.service.SerialNumbersConfService;
import cn.stylefeng.guns.plcserver.opc.GlobalVariable;
import cn.stylefeng.guns.plcserver.opc.OPCElement;
import cn.stylefeng.guns.plcserver.tool.DateTool;
import cn.stylefeng.guns.plcserver.tool.LogUtil;
import com.kangaroohy.milo.model.ReadWriteEntity;
import com.kangaroohy.milo.runner.subscription.SubscriptionCallback;
import com.kangaroohy.milo.service.MiloService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@Component
public class OP020Callback implements SubscriptionCallback {
    public MiloService miloService;
    @Autowired
    public ProductionOrdeInfoService productionOrdeInfoService;
    @Autowired
    public PassingStationCollectionService passingStationCollectionService;
    @Autowired
    public ParamCollectionService paramCollectionService;
    @Autowired
    public CollectionParamConfService collectionParamConfService;
    @Autowired
    public SerialNumbersConfService serialNumbersConfService;
    @Autowired
    private EquipmentStatusService equipmentStatusService;
    @Autowired
    private EquipmentAlarmService equipmentAlarmService;
    @Autowired
    private MaterialTraceabilityService materialTraceabilityService;
    @Autowired
    private EquipmentInfoService equipmentInfoService;
    @Autowired
    private RepairManageInfoService repairManageInfoService;
    @Autowired
    private LocationInfoService locationInfoService;
    @Autowired
    private GreaseManageService greaseManageService;
    @Autowired
    private ProductionOrderRecordsService productionOrderRecordsService;
    @Autowired
    private ProductionOrderBatchInfoService productionOrderBatchInfoService;
    private static Logger logger;
    LogUtil logUtil = new LogUtil();
    static {
        logger = Logger.getLogger(OP020Callback.class);
    }
    private static Date IN_TIME = null;
    private static String S_ORDER_CODE = "";//工单编号
    private static String S_PRODUCT_CODE = "";//产品编号
    private static String S_PRODUCT_TYPE= "";//产品类型
    private static String S_SFC_CODE = "";//总成编码
    private static String PRODUCTION_LINE  = "OP";//产线号
    private static String LOCATION_CODE  = "OP020";//工位号
    private static List list = null;
    public OP020Callback(MiloService miloService,
                         ProductionOrdeInfoService productionOrdeInfoService,
                         PassingStationCollectionService passingStationCollectionService,
                         ParamCollectionService paramCollectionService,
                         CollectionParamConfService collectionParamConfService,
                         SerialNumbersConfService serialNumbersConfService,
                         EquipmentStatusService equipmentStatusService,
                         EquipmentAlarmService equipmentAlarmService,
                         MaterialTraceabilityService materialTraceabilityService,
                         EquipmentInfoService equipmentInfoService,
                         RepairManageInfoService repairManageInfoService,
                         LocationInfoService locationInfoService,
                         GreaseManageService greaseManageService,
                         ProductionOrderRecordsService productionOrderRecordsService,
                         ProductionOrderBatchInfoService productionOrderBatchInfoService) {
        this.miloService = miloService;
        this.productionOrdeInfoService = productionOrdeInfoService;
        this.passingStationCollectionService = passingStationCollectionService;
        this.paramCollectionService = paramCollectionService;
        this.collectionParamConfService = collectionParamConfService;
        this.serialNumbersConfService = serialNumbersConfService;
        this.equipmentStatusService = equipmentStatusService;
        this.equipmentAlarmService = equipmentAlarmService;
        this.materialTraceabilityService = materialTraceabilityService;
        this.equipmentInfoService = equipmentInfoService;
        this.repairManageInfoService = repairManageInfoService;
        this.locationInfoService = locationInfoService;
        this.greaseManageService = greaseManageService;
        this.productionOrderRecordsService = productionOrderRecordsService;
        this.productionOrderBatchInfoService = productionOrderBatchInfoService;
    }
    @Override
    public void onSubscribe(String identifier, Object value) {
        String ecpStr = "";//异常记录标记
        try {
            //心跳
            if(null != value && identifier.equals(OPCElement.OP020_F_HEART_BEAT)){
                if( "false".equals(value.toString()))
                {
                    ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP020_F_HEART_BEAT,true);
                    miloService.writeToOpcUa(entity);
                }
            }
            //PLC进站
            else if(null != value && identifier.equals(OPCElement.OP020_J_PLC_START)){
                if("true".equals(value.toString())){
                    handleOrder();
                }
            }
            //PLC出站
            else if(null != value && identifier.equals(OPCElement.OP020_J_PLC_FINISH)){
                if("true".equals(value.toString())){
                    handleFinsh();
                    handleInfo();
                    handleMaterial();
                }
            }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 {
        logger.info("handleOrder PC处理开始!");
        IN_TIME = DateTool.getLocalTimeForDate();
        List<String> lists = new ArrayList<>();
        lists.add(OPCElement.OP020_S_ORDER_CODE);
        lists.add(OPCElement.OP020_S_PRODUCT_CODE);
        lists.add(OPCElement.OP020_S_SFC_CODE);
        List<ReadWriteEntity> returnLists= miloService.readFromOpcUa(lists);
        returnLists.forEach(element->{
            switch(element.getIdentifier()){
                case OPCElement.OP020_S_ORDER_CODE:
                    S_ORDER_CODE = element.getValue().toString();
                    break;
                case OPCElement.OP020_S_PRODUCT_CODE:
                    S_PRODUCT_TYPE = element.getValue().toString();
                    S_PRODUCT_CODE = GlobalVariable.PRODUCT_CODE_MAP.get(S_PRODUCT_TYPE);
                    break;
                case OPCElement.OP020_S_SFC_CODE:
                    S_SFC_CODE = element.getValue().toString();
                    break;
                default:
                    break;
            }
        });
        ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP020_J_PC_WRITE_ORDER,true);
        miloService.writeToOpcUa(entity);
        logger.info("handleOrder PC处理完成!");
    }
    public void handleFinsh() throws Exception {
        logger.info("handleFinsh PC处理开始!");
        String S_PRODUCT_STATE_CODE = miloService.
                readFromOpcUa(OPCElement.OP020_S_PRODUCT_STATE_CODE)
                .getValue().toString();
        if("2".equals(S_PRODUCT_STATE_CODE)){
            ProductionOrderRecordsParam productionOrderRecordsParam = new ProductionOrderRecordsParam();
            productionOrderRecordsParam.setWorkOrderNo(S_ORDER_CODE);
            productionOrderRecordsParam.setProductNo(S_SFC_CODE);
            List<ProductionOrderRecordsResult> list = productionOrderRecordsService.findListBySpec(productionOrderRecordsParam);
            if(!list.isEmpty()){
                ProductionOrderRecordsResult productionOrderRecordsResult = list.get(0);
                productionOrderRecordsParam.setId(productionOrderRecordsResult.getId());
                productionOrderRecordsParam.setWhetherPass(S_PRODUCT_STATE_CODE);
                productionOrderRecordsService.update(productionOrderRecordsParam);
            }
        }
        //处理过站信息
        PassingStationCollectionParam param = new PassingStationCollectionParam();
        param.setWorkOrderNo(S_ORDER_CODE);
        param.setProductCode(S_PRODUCT_CODE);
        param.setSfcCode(S_SFC_CODE);
        param.setProductionLine(PRODUCTION_LINE);
        param.setLocationCode(LOCATION_CODE);
        param.setInboundTime(IN_TIME);
        param.setOutboundTime(DateTool.getLocalTimeForDate());
        param.setOutRsSign(S_PRODUCT_STATE_CODE);//出站是否合格
        passingStationCollectionService.add(param);
        ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP020_J_PC_FINISH,true);
        miloService.writeToOpcUa(entity);//写PC完成
        logger.info("handleFinsh PC处理完成!");
    }
    public void handleMaterial() {
        //查询批次上料信息
        ProductionOrderBatchInfoParam productionOrderBatchInfoParam = new ProductionOrderBatchInfoParam();
        productionOrderBatchInfoParam.setWorkOrderNo(S_ORDER_CODE);
        productionOrderBatchInfoParam.setLocationCode(LOCATION_CODE);
        List<ProductionOrderBatchInfoResult> list = productionOrderBatchInfoService.findListBySpec(productionOrderBatchInfoParam);
        for(int i=0;i<list.size();i++){
            ProductionOrderBatchInfoResult productionOrderBatchInfoResult = list.get(i);
            int remainingQuantity =  productionOrderBatchInfoResult.getResidueQuantity();//剩余数量
            if(remainingQuantity>0 ){
                //新增物料追溯
                MaterialTraceabilityParam materialTraceabilityParam = new MaterialTraceabilityParam();
                materialTraceabilityParam.setWorkOrderNo(S_ORDER_CODE);
                materialTraceabilityParam.setProductCode(S_PRODUCT_CODE);
                materialTraceabilityParam.setProductNo(S_SFC_CODE);
                materialTraceabilityParam.setLineCode(PRODUCTION_LINE);
                materialTraceabilityParam.setLocationCode(LOCATION_CODE);
                materialTraceabilityParam.setAssemblyQty(1);
                materialTraceabilityParam.setAssemblyTime(DateTool.getLocalTimeForDate());
                materialTraceabilityParam.setMaterialCode(productionOrderBatchInfoResult.getMaterialCode());//物料编码
                materialTraceabilityParam.setMaterialBatchNo(productionOrderBatchInfoResult.getBatch());//物料批次
                materialTraceabilityService.add(materialTraceabilityParam);
                //更新剩余数量
                productionOrderBatchInfoParam.setId(productionOrderBatchInfoResult.getId());
                productionOrderBatchInfoParam.setResidueQuantity(remainingQuantity-1);//剩余数量
                productionOrderBatchInfoService.update(productionOrderBatchInfoParam);
            }
        }
    }
    //PC读参数信息
    public void handleInfo() throws Exception {
        logger.info("handleInfo START!");
        if(null == list){
            CollectionParamConfParam collectionParamConfParam = new CollectionParamConfParam();
            collectionParamConfParam.setLocationCode(LOCATION_CODE);
            list = collectionParamConfService.findListBySpec(collectionParamConfParam);
        }
        if(null != list && !list.isEmpty()) {
            for (int i = 0; i < list.size(); i++) {
                CollectionParamConfResult result = (CollectionParamConfResult) list.get(i);
                String value = miloService.
                        readFromOpcUa(result.getGatherAddress())
                        .getValue().toString();//读参数值
                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);
                paramCollectionParam.setParamLower(result.getParamLower());
                paramCollectionParam.setParamUpper(result.getParamUpper());
                paramCollectionParam.setParamStandard(result.getParamCentral());
                paramCollectionParam.setCollectionTime(DateTool.getLocalTimeForDate());
                paramCollectionParam.setUnit(result.getUnit());
                paramCollectionService.add(paramCollectionParam);
            }
        }
        logger.info("handleInfo END!");
    }
}
guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/OP030Callback.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,297 @@
package cn.stylefeng.guns.plcserver.callback;
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.model.params.ParamCollectionParam;
import cn.stylefeng.guns.modular.cm.paramCollection.service.ParamCollectionService;
import cn.stylefeng.guns.modular.cm.passingStationCollection.model.params.PassingStationCollectionParam;
import cn.stylefeng.guns.modular.cm.passingStationCollection.service.PassingStationCollectionService;
import cn.stylefeng.guns.modular.dq.materialTraceability.model.params.MaterialTraceabilityParam;
import cn.stylefeng.guns.modular.dq.materialTraceability.service.MaterialTraceabilityService;
import cn.stylefeng.guns.modular.em.equipmentAlarm.service.EquipmentAlarmService;
import cn.stylefeng.guns.modular.em.equipmentStatus.service.EquipmentStatusService;
import cn.stylefeng.guns.modular.gm.greaseManage.service.GreaseManageService;
import cn.stylefeng.guns.modular.om.productionOrdeInfo.service.ProductionOrdeInfoService;
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.model.params.ProductionOrderBatchInfoParam;
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.model.result.ProductionOrderBatchInfoResult;
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.service.ProductionOrderBatchInfoService;
import cn.stylefeng.guns.modular.om.productionOrderRecords.model.params.ProductionOrderRecordsParam;
import cn.stylefeng.guns.modular.om.productionOrderRecords.model.result.ProductionOrderRecordsResult;
import cn.stylefeng.guns.modular.om.productionOrderRecords.service.ProductionOrderRecordsService;
import cn.stylefeng.guns.modular.sc.repairManageInfo.service.RepairManageInfoService;
import cn.stylefeng.guns.modular.sc.serialNumbersConf.service.SerialNumbersConfService;
import cn.stylefeng.guns.plcserver.opc.GlobalVariable;
import cn.stylefeng.guns.plcserver.opc.OPCElement;
import cn.stylefeng.guns.plcserver.tool.DateTool;
import cn.stylefeng.guns.plcserver.tool.LogUtil;
import com.kangaroohy.milo.model.ReadWriteEntity;
import com.kangaroohy.milo.runner.subscription.SubscriptionCallback;
import com.kangaroohy.milo.service.MiloService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@Component
public class OP030Callback implements SubscriptionCallback {
    public MiloService miloService;
    @Autowired
    public ProductionOrdeInfoService productionOrdeInfoService;
    @Autowired
    public PassingStationCollectionService passingStationCollectionService;
    @Autowired
    public ParamCollectionService paramCollectionService;
    @Autowired
    public CollectionParamConfService collectionParamConfService;
    @Autowired
    public SerialNumbersConfService serialNumbersConfService;
    @Autowired
    private EquipmentStatusService equipmentStatusService;
    @Autowired
    private EquipmentAlarmService equipmentAlarmService;
    @Autowired
    private MaterialTraceabilityService materialTraceabilityService;
    @Autowired
    private EquipmentInfoService equipmentInfoService;
    @Autowired
    private RepairManageInfoService repairManageInfoService;
    @Autowired
    private LocationInfoService locationInfoService;
    @Autowired
    private GreaseManageService greaseManageService;
    @Autowired
    private ProductionOrderRecordsService productionOrderRecordsService;
    @Autowired
    private ProductionOrderBatchInfoService productionOrderBatchInfoService;
    private static Logger logger;
    LogUtil logUtil = new LogUtil();
    static {
        logger = Logger.getLogger(OP030Callback.class);
    }
    private static Date IN_TIME = null;
    private static String S_ORDER_CODE = "";//工单编号
    private static String S_PRODUCT_CODE = "";//产品编号
    private static String S_PRODUCT_TYPE= "";//产品类型
    private static String S_SFC_CODE = "";//总成编码
    private static String PRODUCTION_LINE  = "OP";//产线号
    private static String LOCATION_CODE  = "OP030";//工位号
    private static List list = null;
    public OP030Callback(MiloService miloService,
                         ProductionOrdeInfoService productionOrdeInfoService,
                         PassingStationCollectionService passingStationCollectionService,
                         ParamCollectionService paramCollectionService,
                         CollectionParamConfService collectionParamConfService,
                         SerialNumbersConfService serialNumbersConfService,
                         EquipmentStatusService equipmentStatusService,
                         EquipmentAlarmService equipmentAlarmService,
                         MaterialTraceabilityService materialTraceabilityService,
                         EquipmentInfoService equipmentInfoService,
                         RepairManageInfoService repairManageInfoService,
                         LocationInfoService locationInfoService,
                         GreaseManageService greaseManageService,
                         ProductionOrderRecordsService productionOrderRecordsService,
                         ProductionOrderBatchInfoService productionOrderBatchInfoService) {
        this.miloService = miloService;
        this.productionOrdeInfoService = productionOrdeInfoService;
        this.passingStationCollectionService = passingStationCollectionService;
        this.paramCollectionService = paramCollectionService;
        this.collectionParamConfService = collectionParamConfService;
        this.serialNumbersConfService = serialNumbersConfService;
        this.equipmentStatusService = equipmentStatusService;
        this.equipmentAlarmService = equipmentAlarmService;
        this.materialTraceabilityService = materialTraceabilityService;
        this.equipmentInfoService = equipmentInfoService;
        this.repairManageInfoService = repairManageInfoService;
        this.locationInfoService = locationInfoService;
        this.greaseManageService = greaseManageService;
        this.productionOrderRecordsService = productionOrderRecordsService;
        this.productionOrderBatchInfoService = productionOrderBatchInfoService;
    }
    @Override
    public void onSubscribe(String identifier, Object value) {
        String ecpStr = "";//异常记录标记
        try {
            //心跳
            if(null != value && identifier.equals(OPCElement.OP030_F_HEART_BEAT)){
                if( "false".equals(value.toString()))
                {
                    ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP030_F_HEART_BEAT,true);
                    miloService.writeToOpcUa(entity);
                }
            }
            //PLC进站
            else if(null != value && identifier.equals(OPCElement.OP030_J_PLC_START)){
                if("true".equals(value.toString())){
                    handleOrder();
                }
            }
            //PLC出站
            else if(null != value && identifier.equals(OPCElement.OP030_J_PLC_FINISH)){
                if("true".equals(value.toString())){
                    handleFinsh();
                    handleInfo();
                    handleMaterial();
                }
            }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 {
        logger.info("handleOrder PC处理开始!");
        IN_TIME = DateTool.getLocalTimeForDate();
        List<String> lists = new ArrayList<>();
        lists.add(OPCElement.OP030_S_ORDER_CODE);
        lists.add(OPCElement.OP030_S_PRODUCT_CODE);
        lists.add(OPCElement.OP030_S_SFC_CODE);
        List<ReadWriteEntity> returnLists= miloService.readFromOpcUa(lists);
        returnLists.forEach(element->{
            switch(element.getIdentifier()){
                case OPCElement.OP030_S_ORDER_CODE:
                    S_ORDER_CODE = element.getValue().toString();
                    break;
                case OPCElement.OP030_S_PRODUCT_CODE:
                    S_PRODUCT_TYPE = element.getValue().toString();
                    S_PRODUCT_CODE = GlobalVariable.PRODUCT_CODE_MAP.get(S_PRODUCT_TYPE);
                    break;
                case OPCElement.OP030_S_SFC_CODE:
                    S_SFC_CODE = element.getValue().toString();
                    break;
                default:
                    break;
            }
        });
        ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP030_J_PC_WRITE_ORDER,true);
        miloService.writeToOpcUa(entity);
        logger.info("handleOrder PC处理完成!");
    }
    public void handleFinsh() throws Exception {
        logger.info("handleFinsh PC处理开始!");
        String S_PRODUCT_STATE_CODE = miloService.
                readFromOpcUa(OPCElement.OP030_S_PRODUCT_STATE_CODE)
                .getValue().toString();
        if("2".equals(S_PRODUCT_STATE_CODE)){
            ProductionOrderRecordsParam productionOrderRecordsParam = new ProductionOrderRecordsParam();
            productionOrderRecordsParam.setWorkOrderNo(S_ORDER_CODE);
            productionOrderRecordsParam.setProductNo(S_SFC_CODE);
            List<ProductionOrderRecordsResult> list = productionOrderRecordsService.findListBySpec(productionOrderRecordsParam);
            if(!list.isEmpty()){
                ProductionOrderRecordsResult productionOrderRecordsResult = list.get(0);
                productionOrderRecordsParam.setId(productionOrderRecordsResult.getId());
                productionOrderRecordsParam.setWhetherPass(S_PRODUCT_STATE_CODE);
                productionOrderRecordsService.update(productionOrderRecordsParam);
            }
        }
        //处理过站信息
        PassingStationCollectionParam param = new PassingStationCollectionParam();
        param.setWorkOrderNo(S_ORDER_CODE);
        param.setProductCode(S_PRODUCT_CODE);
        param.setSfcCode(S_SFC_CODE);
        param.setProductionLine(PRODUCTION_LINE);
        param.setLocationCode(LOCATION_CODE);
        param.setInboundTime(IN_TIME);
        param.setOutboundTime(DateTool.getLocalTimeForDate());
        param.setOutRsSign(S_PRODUCT_STATE_CODE);//出站是否合格
        passingStationCollectionService.add(param);
        ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP030_J_PC_FINISH,true);
        miloService.writeToOpcUa(entity);//写PC完成
        logger.info("handleFinsh PC处理完成!");
    }
    public void handleMaterial() {
        //查询批次上料信息
        ProductionOrderBatchInfoParam productionOrderBatchInfoParam = new ProductionOrderBatchInfoParam();
        productionOrderBatchInfoParam.setWorkOrderNo(S_ORDER_CODE);
        productionOrderBatchInfoParam.setLocationCode(LOCATION_CODE);
        List<ProductionOrderBatchInfoResult> list = productionOrderBatchInfoService.findListBySpec(productionOrderBatchInfoParam);
        for(int i=0;i<list.size();i++){
            ProductionOrderBatchInfoResult productionOrderBatchInfoResult = list.get(i);
            int remainingQuantity =  productionOrderBatchInfoResult.getResidueQuantity();//剩余数量
            if(remainingQuantity>0 ){
                //新增物料追溯
                MaterialTraceabilityParam materialTraceabilityParam = new MaterialTraceabilityParam();
                materialTraceabilityParam.setWorkOrderNo(S_ORDER_CODE);
                materialTraceabilityParam.setProductCode(S_PRODUCT_CODE);
                materialTraceabilityParam.setProductNo(S_SFC_CODE);
                materialTraceabilityParam.setLineCode(PRODUCTION_LINE);
                materialTraceabilityParam.setLocationCode(LOCATION_CODE);
                materialTraceabilityParam.setAssemblyQty(1);
                materialTraceabilityParam.setAssemblyTime(DateTool.getLocalTimeForDate());
                materialTraceabilityParam.setMaterialCode(productionOrderBatchInfoResult.getMaterialCode());//物料编码
                materialTraceabilityParam.setMaterialBatchNo(productionOrderBatchInfoResult.getBatch());//物料批次
                materialTraceabilityService.add(materialTraceabilityParam);
                //更新剩余数量
                productionOrderBatchInfoParam.setId(productionOrderBatchInfoResult.getId());
                productionOrderBatchInfoParam.setResidueQuantity(remainingQuantity-1);//剩余数量
                productionOrderBatchInfoService.update(productionOrderBatchInfoParam);
            }
        }
    }
    //PC读参数信息
    public void handleInfo() throws Exception {
        logger.info("handleInfo START!");
        if(null == list){
            CollectionParamConfParam collectionParamConfParam = new CollectionParamConfParam();
            collectionParamConfParam.setLocationCode(LOCATION_CODE);
            list = collectionParamConfService.findListBySpec(collectionParamConfParam);
        }
        if(null != list && !list.isEmpty()) {
            for (int i = 0; i < list.size(); i++) {
                CollectionParamConfResult result = (CollectionParamConfResult) list.get(i);
                String value = miloService.
                        readFromOpcUa(result.getGatherAddress())
                        .getValue().toString();//读参数值
                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);
                paramCollectionParam.setParamLower(result.getParamLower());
                paramCollectionParam.setParamUpper(result.getParamUpper());
                paramCollectionParam.setParamStandard(result.getParamCentral());
                paramCollectionParam.setCollectionTime(DateTool.getLocalTimeForDate());
                paramCollectionParam.setUnit(result.getUnit());
                paramCollectionService.add(paramCollectionParam);
            }
        }
        logger.info("handleInfo END!");
    }
}
guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/OP040Callback.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,297 @@
package cn.stylefeng.guns.plcserver.callback;
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.model.params.ParamCollectionParam;
import cn.stylefeng.guns.modular.cm.paramCollection.service.ParamCollectionService;
import cn.stylefeng.guns.modular.cm.passingStationCollection.model.params.PassingStationCollectionParam;
import cn.stylefeng.guns.modular.cm.passingStationCollection.service.PassingStationCollectionService;
import cn.stylefeng.guns.modular.dq.materialTraceability.model.params.MaterialTraceabilityParam;
import cn.stylefeng.guns.modular.dq.materialTraceability.service.MaterialTraceabilityService;
import cn.stylefeng.guns.modular.em.equipmentAlarm.service.EquipmentAlarmService;
import cn.stylefeng.guns.modular.em.equipmentStatus.service.EquipmentStatusService;
import cn.stylefeng.guns.modular.gm.greaseManage.service.GreaseManageService;
import cn.stylefeng.guns.modular.om.productionOrdeInfo.service.ProductionOrdeInfoService;
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.model.params.ProductionOrderBatchInfoParam;
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.model.result.ProductionOrderBatchInfoResult;
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.service.ProductionOrderBatchInfoService;
import cn.stylefeng.guns.modular.om.productionOrderRecords.model.params.ProductionOrderRecordsParam;
import cn.stylefeng.guns.modular.om.productionOrderRecords.model.result.ProductionOrderRecordsResult;
import cn.stylefeng.guns.modular.om.productionOrderRecords.service.ProductionOrderRecordsService;
import cn.stylefeng.guns.modular.sc.repairManageInfo.service.RepairManageInfoService;
import cn.stylefeng.guns.modular.sc.serialNumbersConf.service.SerialNumbersConfService;
import cn.stylefeng.guns.plcserver.opc.GlobalVariable;
import cn.stylefeng.guns.plcserver.opc.OPCElement;
import cn.stylefeng.guns.plcserver.tool.DateTool;
import cn.stylefeng.guns.plcserver.tool.LogUtil;
import com.kangaroohy.milo.model.ReadWriteEntity;
import com.kangaroohy.milo.runner.subscription.SubscriptionCallback;
import com.kangaroohy.milo.service.MiloService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@Component
public class OP040Callback implements SubscriptionCallback {
    public MiloService miloService;
    @Autowired
    public ProductionOrdeInfoService productionOrdeInfoService;
    @Autowired
    public PassingStationCollectionService passingStationCollectionService;
    @Autowired
    public ParamCollectionService paramCollectionService;
    @Autowired
    public CollectionParamConfService collectionParamConfService;
    @Autowired
    public SerialNumbersConfService serialNumbersConfService;
    @Autowired
    private EquipmentStatusService equipmentStatusService;
    @Autowired
    private EquipmentAlarmService equipmentAlarmService;
    @Autowired
    private MaterialTraceabilityService materialTraceabilityService;
    @Autowired
    private EquipmentInfoService equipmentInfoService;
    @Autowired
    private RepairManageInfoService repairManageInfoService;
    @Autowired
    private LocationInfoService locationInfoService;
    @Autowired
    private GreaseManageService greaseManageService;
    @Autowired
    private ProductionOrderRecordsService productionOrderRecordsService;
    @Autowired
    private ProductionOrderBatchInfoService productionOrderBatchInfoService;
    private static Logger logger;
    LogUtil logUtil = new LogUtil();
    static {
        logger = Logger.getLogger(OP040Callback.class);
    }
    private static Date IN_TIME = null;
    private static String S_ORDER_CODE = "";//工单编号
    private static String S_PRODUCT_CODE = "";//产品编号
    private static String S_PRODUCT_TYPE= "";//产品类型
    private static String S_SFC_CODE = "";//总成编码
    private static String PRODUCTION_LINE  = "OP";//产线号
    private static String LOCATION_CODE  = "OP040";//工位号
    private static List list = null;
    public OP040Callback(MiloService miloService,
                         ProductionOrdeInfoService productionOrdeInfoService,
                         PassingStationCollectionService passingStationCollectionService,
                         ParamCollectionService paramCollectionService,
                         CollectionParamConfService collectionParamConfService,
                         SerialNumbersConfService serialNumbersConfService,
                         EquipmentStatusService equipmentStatusService,
                         EquipmentAlarmService equipmentAlarmService,
                         MaterialTraceabilityService materialTraceabilityService,
                         EquipmentInfoService equipmentInfoService,
                         RepairManageInfoService repairManageInfoService,
                         LocationInfoService locationInfoService,
                         GreaseManageService greaseManageService,
                         ProductionOrderRecordsService productionOrderRecordsService,
                         ProductionOrderBatchInfoService productionOrderBatchInfoService) {
        this.miloService = miloService;
        this.productionOrdeInfoService = productionOrdeInfoService;
        this.passingStationCollectionService = passingStationCollectionService;
        this.paramCollectionService = paramCollectionService;
        this.collectionParamConfService = collectionParamConfService;
        this.serialNumbersConfService = serialNumbersConfService;
        this.equipmentStatusService = equipmentStatusService;
        this.equipmentAlarmService = equipmentAlarmService;
        this.materialTraceabilityService = materialTraceabilityService;
        this.equipmentInfoService = equipmentInfoService;
        this.repairManageInfoService = repairManageInfoService;
        this.locationInfoService = locationInfoService;
        this.greaseManageService = greaseManageService;
        this.productionOrderRecordsService = productionOrderRecordsService;
        this.productionOrderBatchInfoService = productionOrderBatchInfoService;
    }
    @Override
    public void onSubscribe(String identifier, Object value) {
        String ecpStr = "";//异常记录标记
        try {
            //心跳
            if(null != value && identifier.equals(OPCElement.OP040_F_HEART_BEAT)){
                if( "false".equals(value.toString()))
                {
                    ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP040_F_HEART_BEAT,true);
                    miloService.writeToOpcUa(entity);
                }
            }
            //PLC进站
            else if(null != value && identifier.equals(OPCElement.OP040_J_PLC_START)){
                if("true".equals(value.toString())){
                    handleOrder();
                }
            }
            //PLC出站
            else if(null != value && identifier.equals(OPCElement.OP040_J_PLC_FINISH)){
                if("true".equals(value.toString())){
                    handleFinsh();
                    handleInfo();
                    handleMaterial();
                }
            }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 {
        logger.info("handleOrder PC处理开始!");
        IN_TIME = DateTool.getLocalTimeForDate();
        List<String> lists = new ArrayList<>();
        lists.add(OPCElement.OP040_S_ORDER_CODE);
        lists.add(OPCElement.OP040_S_PRODUCT_CODE);
        lists.add(OPCElement.OP040_S_SFC_CODE);
        List<ReadWriteEntity> returnLists= miloService.readFromOpcUa(lists);
        returnLists.forEach(element->{
            switch(element.getIdentifier()){
                case OPCElement.OP040_S_ORDER_CODE:
                    S_ORDER_CODE = element.getValue().toString();
                    break;
                case OPCElement.OP040_S_PRODUCT_CODE:
                    S_PRODUCT_TYPE = element.getValue().toString();
                    S_PRODUCT_CODE = GlobalVariable.PRODUCT_CODE_MAP.get(S_PRODUCT_TYPE);
                    break;
                case OPCElement.OP040_S_SFC_CODE:
                    S_SFC_CODE = element.getValue().toString();
                    break;
                default:
                    break;
            }
        });
        ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP040_J_PC_WRITE_ORDER,true);
        miloService.writeToOpcUa(entity);
        logger.info("handleOrder PC处理完成!");
    }
    public void handleFinsh() throws Exception {
        logger.info("handleFinsh PC处理开始!");
        String S_PRODUCT_STATE_CODE = miloService.
                readFromOpcUa(OPCElement.OP040_S_PRODUCT_STATE_CODE)
                .getValue().toString();
        if("2".equals(S_PRODUCT_STATE_CODE)){
            ProductionOrderRecordsParam productionOrderRecordsParam = new ProductionOrderRecordsParam();
            productionOrderRecordsParam.setWorkOrderNo(S_ORDER_CODE);
            productionOrderRecordsParam.setProductNo(S_SFC_CODE);
            List<ProductionOrderRecordsResult> list = productionOrderRecordsService.findListBySpec(productionOrderRecordsParam);
            if(!list.isEmpty()){
                ProductionOrderRecordsResult productionOrderRecordsResult = list.get(0);
                productionOrderRecordsParam.setId(productionOrderRecordsResult.getId());
                productionOrderRecordsParam.setWhetherPass(S_PRODUCT_STATE_CODE);
                productionOrderRecordsService.update(productionOrderRecordsParam);
            }
        }
        //处理过站信息
        PassingStationCollectionParam param = new PassingStationCollectionParam();
        param.setWorkOrderNo(S_ORDER_CODE);
        param.setProductCode(S_PRODUCT_CODE);
        param.setSfcCode(S_SFC_CODE);
        param.setProductionLine(PRODUCTION_LINE);
        param.setLocationCode(LOCATION_CODE);
        param.setInboundTime(IN_TIME);
        param.setOutboundTime(DateTool.getLocalTimeForDate());
        param.setOutRsSign(S_PRODUCT_STATE_CODE);//出站是否合格
        passingStationCollectionService.add(param);
        ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP040_J_PC_FINISH,true);
        miloService.writeToOpcUa(entity);//写PC完成
        logger.info("handleFinsh PC处理完成!");
    }
    public void handleMaterial() {
        //查询批次上料信息
        ProductionOrderBatchInfoParam productionOrderBatchInfoParam = new ProductionOrderBatchInfoParam();
        productionOrderBatchInfoParam.setWorkOrderNo(S_ORDER_CODE);
        productionOrderBatchInfoParam.setLocationCode(LOCATION_CODE);
        List<ProductionOrderBatchInfoResult> list = productionOrderBatchInfoService.findListBySpec(productionOrderBatchInfoParam);
        for(int i=0;i<list.size();i++){
            ProductionOrderBatchInfoResult productionOrderBatchInfoResult = list.get(i);
            int remainingQuantity =  productionOrderBatchInfoResult.getResidueQuantity();//剩余数量
            if(remainingQuantity>0 ){
                //新增物料追溯
                MaterialTraceabilityParam materialTraceabilityParam = new MaterialTraceabilityParam();
                materialTraceabilityParam.setWorkOrderNo(S_ORDER_CODE);
                materialTraceabilityParam.setProductCode(S_PRODUCT_CODE);
                materialTraceabilityParam.setProductNo(S_SFC_CODE);
                materialTraceabilityParam.setLineCode(PRODUCTION_LINE);
                materialTraceabilityParam.setLocationCode(LOCATION_CODE);
                materialTraceabilityParam.setAssemblyQty(1);
                materialTraceabilityParam.setAssemblyTime(DateTool.getLocalTimeForDate());
                materialTraceabilityParam.setMaterialCode(productionOrderBatchInfoResult.getMaterialCode());//物料编码
                materialTraceabilityParam.setMaterialBatchNo(productionOrderBatchInfoResult.getBatch());//物料批次
                materialTraceabilityService.add(materialTraceabilityParam);
                //更新剩余数量
                productionOrderBatchInfoParam.setId(productionOrderBatchInfoResult.getId());
                productionOrderBatchInfoParam.setResidueQuantity(remainingQuantity-1);//剩余数量
                productionOrderBatchInfoService.update(productionOrderBatchInfoParam);
            }
        }
    }
    //PC读参数信息
    public void handleInfo() throws Exception {
        logger.info("handleInfo START!");
        if(null == list){
            CollectionParamConfParam collectionParamConfParam = new CollectionParamConfParam();
            collectionParamConfParam.setLocationCode(LOCATION_CODE);
            list = collectionParamConfService.findListBySpec(collectionParamConfParam);
        }
        if(null != list && !list.isEmpty()) {
            for (int i = 0; i < list.size(); i++) {
                CollectionParamConfResult result = (CollectionParamConfResult) list.get(i);
                String value = miloService.
                        readFromOpcUa(result.getGatherAddress())
                        .getValue().toString();//读参数值
                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);
                paramCollectionParam.setParamLower(result.getParamLower());
                paramCollectionParam.setParamUpper(result.getParamUpper());
                paramCollectionParam.setParamStandard(result.getParamCentral());
                paramCollectionParam.setCollectionTime(DateTool.getLocalTimeForDate());
                paramCollectionParam.setUnit(result.getUnit());
                paramCollectionService.add(paramCollectionParam);
            }
        }
        logger.info("handleInfo END!");
    }
}
guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/OP050Callback.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,338 @@
package cn.stylefeng.guns.plcserver.callback;
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.model.params.ParamCollectionParam;
import cn.stylefeng.guns.modular.cm.paramCollection.service.ParamCollectionService;
import cn.stylefeng.guns.modular.cm.passingStationCollection.model.params.PassingStationCollectionParam;
import cn.stylefeng.guns.modular.cm.passingStationCollection.model.result.PassingStationCollectionResult;
import cn.stylefeng.guns.modular.cm.passingStationCollection.service.PassingStationCollectionService;
import cn.stylefeng.guns.modular.dq.materialTraceability.model.params.MaterialTraceabilityParam;
import cn.stylefeng.guns.modular.dq.materialTraceability.service.MaterialTraceabilityService;
import cn.stylefeng.guns.modular.em.equipmentAlarm.service.EquipmentAlarmService;
import cn.stylefeng.guns.modular.em.equipmentStatus.service.EquipmentStatusService;
import cn.stylefeng.guns.modular.gm.greaseManage.service.GreaseManageService;
import cn.stylefeng.guns.modular.om.productionOrdeInfo.service.ProductionOrdeInfoService;
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.model.params.ProductionOrderBatchInfoParam;
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.model.result.ProductionOrderBatchInfoResult;
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.service.ProductionOrderBatchInfoService;
import cn.stylefeng.guns.modular.om.productionOrderRecords.model.params.ProductionOrderRecordsParam;
import cn.stylefeng.guns.modular.om.productionOrderRecords.model.result.ProductionOrderRecordsResult;
import cn.stylefeng.guns.modular.om.productionOrderRecords.service.ProductionOrderRecordsService;
import cn.stylefeng.guns.modular.sc.repairManageInfo.service.RepairManageInfoService;
import cn.stylefeng.guns.modular.sc.serialNumbersConf.service.SerialNumbersConfService;
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;
import com.kangaroohy.milo.runner.subscription.SubscriptionCallback;
import com.kangaroohy.milo.service.MiloService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@Component
public class OP050Callback implements SubscriptionCallback {
    public MiloService miloService;
    @Autowired
    public ProductionOrdeInfoService productionOrdeInfoService;
    @Autowired
    public PassingStationCollectionService passingStationCollectionService;
    @Autowired
    public ParamCollectionService paramCollectionService;
    @Autowired
    public CollectionParamConfService collectionParamConfService;
    @Autowired
    public SerialNumbersConfService serialNumbersConfService;
    @Autowired
    private EquipmentStatusService equipmentStatusService;
    @Autowired
    private EquipmentAlarmService equipmentAlarmService;
    @Autowired
    private MaterialTraceabilityService materialTraceabilityService;
    @Autowired
    private EquipmentInfoService equipmentInfoService;
    @Autowired
    private RepairManageInfoService repairManageInfoService;
    @Autowired
    private LocationInfoService locationInfoService;
    @Autowired
    private GreaseManageService greaseManageService;
    @Autowired
    private ProductionOrderRecordsService productionOrderRecordsService;
    @Autowired
    private ProductionOrderBatchInfoService productionOrderBatchInfoService;
    private static Logger logger;
    LogUtil logUtil = new LogUtil();
    static {
        logger = Logger.getLogger(OP050Callback.class);
    }
    private static Date IN_TIME = null;
    private static String S_ORDER_CODE = "";//工单编号
    private static String S_PRODUCT_CODE = "";//产品编号
    private static String S_PRODUCT_TYPE= "";//产品类型
    private static String S_SFC_CODE = "";//总成编码
    private static String PRODUCTION_LINE  = "OP";//产线号
    private static String LOCATION_CODE  = "OP050";//工位号
    private static List list = null;
    public OP050Callback(MiloService miloService,
                         ProductionOrdeInfoService productionOrdeInfoService,
                         PassingStationCollectionService passingStationCollectionService,
                         ParamCollectionService paramCollectionService,
                         CollectionParamConfService collectionParamConfService,
                         SerialNumbersConfService serialNumbersConfService,
                         EquipmentStatusService equipmentStatusService,
                         EquipmentAlarmService equipmentAlarmService,
                         MaterialTraceabilityService materialTraceabilityService,
                         EquipmentInfoService equipmentInfoService,
                         RepairManageInfoService repairManageInfoService,
                         LocationInfoService locationInfoService,
                         GreaseManageService greaseManageService,
                         ProductionOrderRecordsService productionOrderRecordsService,
                         ProductionOrderBatchInfoService productionOrderBatchInfoService) {
        this.miloService = miloService;
        this.productionOrdeInfoService = productionOrdeInfoService;
        this.passingStationCollectionService = passingStationCollectionService;
        this.paramCollectionService = paramCollectionService;
        this.collectionParamConfService = collectionParamConfService;
        this.serialNumbersConfService = serialNumbersConfService;
        this.equipmentStatusService = equipmentStatusService;
        this.equipmentAlarmService = equipmentAlarmService;
        this.materialTraceabilityService = materialTraceabilityService;
        this.equipmentInfoService = equipmentInfoService;
        this.repairManageInfoService = repairManageInfoService;
        this.locationInfoService = locationInfoService;
        this.greaseManageService = greaseManageService;
        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 {
        logger.info("handleOrder PC处理开始!");
        IN_TIME = DateTool.getLocalTimeForDate();
        List<String> lists = new ArrayList<>();
        lists.add(OPCElement.OP050_S_ORDER_CODE);
        lists.add(OPCElement.OP050_S_PRODUCT_CODE);
        lists.add(OPCElement.OP050_S_SFC_CODE);
        List<ReadWriteEntity> returnLists= miloService.readFromOpcUa(lists);
        returnLists.forEach(element->{
            switch(element.getIdentifier()){
                case OPCElement.OP050_S_ORDER_CODE:
                    S_ORDER_CODE = element.getValue().toString();
                    break;
                case OPCElement.OP050_S_PRODUCT_CODE:
                    S_PRODUCT_TYPE = element.getValue().toString();
                    S_PRODUCT_CODE = GlobalVariable.PRODUCT_CODE_MAP.get(S_PRODUCT_TYPE);
                    break;
                case OPCElement.OP050_S_SFC_CODE:
                    S_SFC_CODE = element.getValue().toString();
                    break;
                default:
                    break;
            }
        });
        ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP050_J_PC_WRITE_ORDER,true);
        miloService.writeToOpcUa(entity);
        logger.info("handleOrder PC处理完成!");
    }
    public void handleFinsh() throws Exception{
        logger.info("handleFinsh PC处理开始!");
        String S_PRODUCT_STATE_CODE = miloService.
                readFromOpcUa(OPCElement.OP050_S_PRODUCT_STATE_CODE)
                .getValue().toString();
        PassingStationCollectionParam param = new PassingStationCollectionParam();
        param.setWorkOrderNo(S_ORDER_CODE);
        param.setProductCode(S_PRODUCT_CODE);
        param.setSfcCode(S_SFC_CODE);
        param.setProductionLine(PRODUCTION_LINE);
        param.setLocationCode(LOCATION_CODE);
        param.setInboundTime(IN_TIME);
        param.setOutboundTime(DateTool.getLocalTimeForDate());
        param.setOutRsSign(S_PRODUCT_STATE_CODE);//出站是否合格
        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();
        //根据分总成编码,将EOP物料数据绑定关系修改为总成编码
        materialTraceabilityService.updateSFC(S_SFC_CODE,copSfcCode);
        materialTraceabilityService.updateSFC(S_SFC_CODE,bopSfcCode);
        //根据分总成编码,将EOP过站数据绑定关系修改为总成编码
        passingStationCollectionService.updateSFC(S_SFC_CODE,copSfcCode);
        passingStationCollectionService.updateSFC(S_SFC_CODE,bopSfcCode);
        //根据分总成编码,将EOP采集数据绑定关系修改为总成编码
        paramCollectionService.updateSFC(S_SFC_CODE,copSfcCode);
        paramCollectionService.updateSFC(S_SFC_CODE,bopSfcCode);
        logger.info("S_SFC_CODE:"+S_SFC_CODE);
        logger.info("copSfcCode:"+copSfcCode);
        logger.info("bopSfcCode:"+bopSfcCode);
        //查询COP和BOP是否合格
        PassingStationCollectionParam passingStationCollectionParam = new PassingStationCollectionParam();
        passingStationCollectionParam.setSfcCode(S_SFC_CODE);
        List<PassingStationCollectionResult> passingStationCollectionResultList =
                passingStationCollectionService.findListBySpec(passingStationCollectionParam);
        String isProductState = "true";
        for(int i=0;i<passingStationCollectionResultList.size();i++){
            PassingStationCollectionResult passingStationCollectionResult = passingStationCollectionResultList.get(i);
            if("false".equals(passingStationCollectionResult.getOutRsSign())){
                isProductState = "false";
                break;
            }
        }
        //修改报工记录
        if("false".equals(S_PRODUCT_STATE_CODE) || "false".equals(isProductState)){
            ProductionOrderRecordsParam productionOrderRecordsParam = new ProductionOrderRecordsParam();
            productionOrderRecordsParam.setWorkOrderNo(S_ORDER_CODE);
            productionOrderRecordsParam.setProductNo(S_SFC_CODE);
            List<ProductionOrderRecordsResult> list = productionOrderRecordsService.findListBySpec(productionOrderRecordsParam);
            if(list.size()>0){
                ProductionOrderRecordsResult productionOrderRecordsResult = list.get(0);
                productionOrderRecordsParam.setId(productionOrderRecordsResult.getId());
                productionOrderRecordsParam.setWhetherPass("false");
                productionOrderRecordsService.update(productionOrderRecordsParam);
            }
        }
        ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP050_J_PC_FINISH,true);
        miloService.writeToOpcUa(entity);//写PC完成
        logger.info("handleFinsh PC处理完成!");
    }
    public void handleMaterial() {
        //查询批次上料信息
        ProductionOrderBatchInfoParam productionOrderBatchInfoParam = new ProductionOrderBatchInfoParam();
        productionOrderBatchInfoParam.setWorkOrderNo(S_ORDER_CODE);
        productionOrderBatchInfoParam.setLocationCode(LOCATION_CODE);
        List<ProductionOrderBatchInfoResult> list = productionOrderBatchInfoService.findListBySpec(productionOrderBatchInfoParam);
        for(int i=0;i<list.size();i++){
            ProductionOrderBatchInfoResult productionOrderBatchInfoResult = list.get(i);
            int remainingQuantity =  productionOrderBatchInfoResult.getResidueQuantity();//剩余数量
            if(remainingQuantity>0 ){
                //新增物料追溯
                MaterialTraceabilityParam materialTraceabilityParam = new MaterialTraceabilityParam();
                materialTraceabilityParam.setWorkOrderNo(S_ORDER_CODE);
                materialTraceabilityParam.setProductCode(S_PRODUCT_CODE);
                materialTraceabilityParam.setProductNo(S_SFC_CODE);
                materialTraceabilityParam.setLineCode(PRODUCTION_LINE);
                materialTraceabilityParam.setLocationCode(LOCATION_CODE);
                materialTraceabilityParam.setAssemblyQty(1);
                materialTraceabilityParam.setAssemblyTime(DateTool.getLocalTimeForDate());
                materialTraceabilityParam.setMaterialCode(productionOrderBatchInfoResult.getMaterialCode());//物料编码
                materialTraceabilityParam.setMaterialBatchNo(productionOrderBatchInfoResult.getBatch());//物料批次
                materialTraceabilityService.add(materialTraceabilityParam);
                //更新剩余数量
                productionOrderBatchInfoParam.setId(productionOrderBatchInfoResult.getId());
                productionOrderBatchInfoParam.setResidueQuantity(remainingQuantity-1);//剩余数量
                productionOrderBatchInfoService.update(productionOrderBatchInfoParam);
            }
        }
    }
    //PC读参数信息
    public void handleInfo() throws Exception {
        logger.info("handleInfo START!");
        if(null == list){
            CollectionParamConfParam collectionParamConfParam = new CollectionParamConfParam();
            collectionParamConfParam.setLocationCode(LOCATION_CODE);
            list = collectionParamConfService.findListBySpec(collectionParamConfParam);
        }
        if(null != list && !list.isEmpty()) {
            for (int i = 0; i < list.size(); i++) {
                CollectionParamConfResult result = (CollectionParamConfResult) list.get(i);
                String value = miloService.
                        readFromOpcUa(result.getGatherAddress())
                        .getValue().toString();//读参数值
                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);
                paramCollectionParam.setParamLower(result.getParamLower());
                paramCollectionParam.setParamUpper(result.getParamUpper());
                paramCollectionParam.setParamStandard(result.getParamCentral());
                paramCollectionParam.setCollectionTime(DateTool.getLocalTimeForDate());
                paramCollectionParam.setUnit(result.getUnit());
                paramCollectionService.add(paramCollectionParam);
            }
        }
        logger.info("handleInfo END!");
    }
}
guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/OP070Callback.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,298 @@
package cn.stylefeng.guns.plcserver.callback;
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.model.params.ParamCollectionParam;
import cn.stylefeng.guns.modular.cm.paramCollection.service.ParamCollectionService;
import cn.stylefeng.guns.modular.cm.passingStationCollection.model.params.PassingStationCollectionParam;
import cn.stylefeng.guns.modular.cm.passingStationCollection.service.PassingStationCollectionService;
import cn.stylefeng.guns.modular.dq.materialTraceability.model.params.MaterialTraceabilityParam;
import cn.stylefeng.guns.modular.dq.materialTraceability.service.MaterialTraceabilityService;
import cn.stylefeng.guns.modular.em.equipmentAlarm.service.EquipmentAlarmService;
import cn.stylefeng.guns.modular.em.equipmentStatus.service.EquipmentStatusService;
import cn.stylefeng.guns.modular.gm.greaseManage.service.GreaseManageService;
import cn.stylefeng.guns.modular.om.productionOrdeInfo.service.ProductionOrdeInfoService;
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.model.params.ProductionOrderBatchInfoParam;
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.model.result.ProductionOrderBatchInfoResult;
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.service.ProductionOrderBatchInfoService;
import cn.stylefeng.guns.modular.om.productionOrderRecords.model.params.ProductionOrderRecordsParam;
import cn.stylefeng.guns.modular.om.productionOrderRecords.model.result.ProductionOrderRecordsResult;
import cn.stylefeng.guns.modular.om.productionOrderRecords.service.ProductionOrderRecordsService;
import cn.stylefeng.guns.modular.sc.repairManageInfo.service.RepairManageInfoService;
import cn.stylefeng.guns.modular.sc.serialNumbersConf.service.SerialNumbersConfService;
import cn.stylefeng.guns.plcserver.opc.GlobalVariable;
import cn.stylefeng.guns.plcserver.opc.OPCElement;
import cn.stylefeng.guns.plcserver.tool.DateTool;
import cn.stylefeng.guns.plcserver.tool.LogUtil;
import com.kangaroohy.milo.model.ReadWriteEntity;
import com.kangaroohy.milo.runner.subscription.SubscriptionCallback;
import com.kangaroohy.milo.service.MiloService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@Component
public class OP070Callback implements SubscriptionCallback {
    public MiloService miloService;
    @Autowired
    public ProductionOrdeInfoService productionOrdeInfoService;
    @Autowired
    public PassingStationCollectionService passingStationCollectionService;
    @Autowired
    public ParamCollectionService paramCollectionService;
    @Autowired
    public CollectionParamConfService collectionParamConfService;
    @Autowired
    public SerialNumbersConfService serialNumbersConfService;
    @Autowired
    private EquipmentStatusService equipmentStatusService;
    @Autowired
    private EquipmentAlarmService equipmentAlarmService;
    @Autowired
    private MaterialTraceabilityService materialTraceabilityService;
    @Autowired
    private EquipmentInfoService equipmentInfoService;
    @Autowired
    private RepairManageInfoService repairManageInfoService;
    @Autowired
    private LocationInfoService locationInfoService;
    @Autowired
    private GreaseManageService greaseManageService;
    @Autowired
    private ProductionOrderRecordsService productionOrderRecordsService;
    @Autowired
    private ProductionOrderBatchInfoService productionOrderBatchInfoService;
    private static Logger logger;
    LogUtil logUtil = new LogUtil();
    static {
        logger = Logger.getLogger(OP070Callback.class);
    }
    private static Date IN_TIME = null;
    private static String S_ORDER_CODE = "";//工单编号
    private static String S_PRODUCT_CODE = "";//产品编号
    private static String S_PRODUCT_TYPE= "";//产品类型
    private static String S_SFC_CODE = "";//总成编码
    private static String PRODUCTION_LINE  = "OP";//产线号
    private static String LOCATION_CODE  = "OP070";//工位号
    private static List list = null;
    public OP070Callback(MiloService miloService,
                         ProductionOrdeInfoService productionOrdeInfoService,
                         PassingStationCollectionService passingStationCollectionService,
                         ParamCollectionService paramCollectionService,
                         CollectionParamConfService collectionParamConfService,
                         SerialNumbersConfService serialNumbersConfService,
                         EquipmentStatusService equipmentStatusService,
                         EquipmentAlarmService equipmentAlarmService,
                         MaterialTraceabilityService materialTraceabilityService,
                         EquipmentInfoService equipmentInfoService,
                         RepairManageInfoService repairManageInfoService,
                         LocationInfoService locationInfoService,
                         GreaseManageService greaseManageService,
                         ProductionOrderRecordsService productionOrderRecordsService,
                         ProductionOrderBatchInfoService productionOrderBatchInfoService) {
        this.miloService = miloService;
        this.productionOrdeInfoService = productionOrdeInfoService;
        this.passingStationCollectionService = passingStationCollectionService;
        this.paramCollectionService = paramCollectionService;
        this.collectionParamConfService = collectionParamConfService;
        this.serialNumbersConfService = serialNumbersConfService;
        this.equipmentStatusService = equipmentStatusService;
        this.equipmentAlarmService = equipmentAlarmService;
        this.materialTraceabilityService = materialTraceabilityService;
        this.equipmentInfoService = equipmentInfoService;
        this.repairManageInfoService = repairManageInfoService;
        this.locationInfoService = locationInfoService;
        this.greaseManageService = greaseManageService;
        this.productionOrderRecordsService = productionOrderRecordsService;
        this.productionOrderBatchInfoService = productionOrderBatchInfoService;
    }
    @Override
    public void onSubscribe(String identifier, Object value) {
        String ecpStr = "";//异常记录标记
        try {
            //心跳
            if(null != value && identifier.equals(OPCElement.OP070_F_HEART_BEAT)){
                if( "false".equals(value.toString()))
                {
                    ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP070_F_HEART_BEAT,true);
                    miloService.writeToOpcUa(entity);
                }
            }
            //PLC进站
            else if(null != value && identifier.equals(OPCElement.OP070_J_PLC_START)){
                if("true".equals(value.toString())){
                    handleOrder();
                }
            }
            //PLC出站
            else if(null != value && identifier.equals(OPCElement.OP070_J_PLC_FINISH)){
                if("true".equals(value.toString())){
                    handleFinsh();
                    handleInfo();
                    handleMaterial();
                }
            }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 {
        logger.info("handleOrder PC处理开始!");
        IN_TIME = DateTool.getLocalTimeForDate();
        List<String> lists = new ArrayList<>();
        lists.add(OPCElement.OP070_S_ORDER_CODE);
        lists.add(OPCElement.OP070_S_PRODUCT_CODE);
        lists.add(OPCElement.OP070_S_SFC_CODE);
        List<ReadWriteEntity> returnLists= miloService.readFromOpcUa(lists);
        returnLists.forEach(element->{
            switch(element.getIdentifier()){
                case OPCElement.OP070_S_ORDER_CODE:
                    S_ORDER_CODE = element.getValue().toString();
                    break;
                case OPCElement.OP070_S_PRODUCT_CODE:
                    S_PRODUCT_TYPE = element.getValue().toString();
                    S_PRODUCT_CODE = GlobalVariable.PRODUCT_CODE_MAP.get(S_PRODUCT_TYPE);
                    break;
                case OPCElement.OP070_S_SFC_CODE:
                    S_SFC_CODE = element.getValue().toString();
                    break;
                default:
                    break;
            }
        });
        ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP070_J_PC_WRITE_ORDER,true);
        miloService.writeToOpcUa(entity);
        logger.info("handleOrder PC处理完成!");
    }
    public void handleFinsh() throws Exception {
        logger.info("handleFinsh PC处理开始!");
        String S_PRODUCT_STATE_CODE = miloService.
                readFromOpcUa(OPCElement.OP070_S_PRODUCT_STATE_CODE)
                .getValue().toString();
        if("2".equals(S_PRODUCT_STATE_CODE)){
            ProductionOrderRecordsParam productionOrderRecordsParam = new ProductionOrderRecordsParam();
            productionOrderRecordsParam.setWorkOrderNo(S_ORDER_CODE);
            productionOrderRecordsParam.setProductNo(S_SFC_CODE);
            List<ProductionOrderRecordsResult> list = productionOrderRecordsService.findListBySpec(productionOrderRecordsParam);
            if(!list.isEmpty()){
                ProductionOrderRecordsResult productionOrderRecordsResult = list.get(0);
                productionOrderRecordsParam.setId(productionOrderRecordsResult.getId());
                productionOrderRecordsParam.setWhetherPass(S_PRODUCT_STATE_CODE);
                productionOrderRecordsService.update(productionOrderRecordsParam);
            }
        }
        //处理过站信息
        PassingStationCollectionParam param = new PassingStationCollectionParam();
        param.setWorkOrderNo(S_ORDER_CODE);
        param.setProductCode(S_PRODUCT_CODE);
        param.setSfcCode(S_SFC_CODE);
        param.setProductionLine(PRODUCTION_LINE);
        param.setLocationCode(LOCATION_CODE);
        param.setInboundTime(IN_TIME);
        param.setOutboundTime(DateTool.getLocalTimeForDate());
        param.setOutRsSign(S_PRODUCT_STATE_CODE);//出站是否合格
        passingStationCollectionService.add(param);
        ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP070_J_PC_FINISH,true);
        miloService.writeToOpcUa(entity);//写PC完成
        logger.info("handleFinsh PC处理完成!");
    }
    public void handleMaterial() {
        //查询批次上料信息
        ProductionOrderBatchInfoParam productionOrderBatchInfoParam = new ProductionOrderBatchInfoParam();
        productionOrderBatchInfoParam.setWorkOrderNo(S_ORDER_CODE);
        productionOrderBatchInfoParam.setLocationCode(LOCATION_CODE);
        List<ProductionOrderBatchInfoResult> list = productionOrderBatchInfoService.findListBySpec(productionOrderBatchInfoParam);
        for(int i=0;i<list.size();i++){
            ProductionOrderBatchInfoResult productionOrderBatchInfoResult = list.get(i);
            int remainingQuantity =  productionOrderBatchInfoResult.getResidueQuantity();//剩余数量
            if(remainingQuantity>0 ){
                //新增物料追溯
                MaterialTraceabilityParam materialTraceabilityParam = new MaterialTraceabilityParam();
                materialTraceabilityParam.setWorkOrderNo(S_ORDER_CODE);
                materialTraceabilityParam.setProductCode(S_PRODUCT_CODE);
                materialTraceabilityParam.setProductNo(S_SFC_CODE);
                materialTraceabilityParam.setLineCode(PRODUCTION_LINE);
                materialTraceabilityParam.setLocationCode(LOCATION_CODE);
                materialTraceabilityParam.setAssemblyQty(1);
                materialTraceabilityParam.setAssemblyTime(DateTool.getLocalTimeForDate());
                materialTraceabilityParam.setMaterialCode(productionOrderBatchInfoResult.getMaterialCode());//物料编码
                materialTraceabilityParam.setMaterialBatchNo(productionOrderBatchInfoResult.getBatch());//物料批次
                materialTraceabilityService.add(materialTraceabilityParam);
                //更新剩余数量
                productionOrderBatchInfoParam.setId(productionOrderBatchInfoResult.getId());
                productionOrderBatchInfoParam.setResidueQuantity(remainingQuantity-1);//剩余数量
                productionOrderBatchInfoService.update(productionOrderBatchInfoParam);
            }
        }
    }
    //PC读参数信息
    public void handleInfo() throws Exception {
        logger.info("handleInfo START!");
        if(null == list){
            CollectionParamConfParam collectionParamConfParam = new CollectionParamConfParam();
            collectionParamConfParam.setLocationCode(LOCATION_CODE);
            list = collectionParamConfService.findListBySpec(collectionParamConfParam);
        }
        if(null != list && !list.isEmpty()) {
            for (int i = 0; i < list.size(); i++) {
                CollectionParamConfResult result = (CollectionParamConfResult) list.get(i);
                String value = miloService.
                        readFromOpcUa(result.getGatherAddress())
                        .getValue().toString();//读参数值
                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);
                paramCollectionParam.setParamLower(result.getParamLower());
                paramCollectionParam.setParamUpper(result.getParamUpper());
                paramCollectionParam.setParamStandard(result.getParamCentral());
                paramCollectionParam.setCollectionTime(DateTool.getLocalTimeForDate());
                paramCollectionParam.setUnit(result.getUnit());
                paramCollectionService.add(paramCollectionParam);
            }
        }
        logger.info("handleInfo END!");
    }
}
guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/OP080Callback.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,349 @@
package cn.stylefeng.guns.plcserver.callback;
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.model.params.LocationInfoParam;
import cn.stylefeng.guns.modular.bs.locationInfo.model.result.LocationInfoResult;
import cn.stylefeng.guns.modular.bs.locationInfo.service.LocationInfoService;
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;
import cn.stylefeng.guns.modular.cm.passingStationCollection.service.PassingStationCollectionService;
import cn.stylefeng.guns.modular.dq.materialTraceability.model.params.MaterialTraceabilityParam;
import cn.stylefeng.guns.modular.dq.materialTraceability.service.MaterialTraceabilityService;
import cn.stylefeng.guns.modular.em.equipmentAlarm.service.EquipmentAlarmService;
import cn.stylefeng.guns.modular.em.equipmentStatus.service.EquipmentStatusService;
import cn.stylefeng.guns.modular.gm.greaseManage.service.GreaseManageService;
import cn.stylefeng.guns.modular.om.productionOrdeInfo.service.ProductionOrdeInfoService;
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.model.params.ProductionOrderBatchInfoParam;
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.model.result.ProductionOrderBatchInfoResult;
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.service.ProductionOrderBatchInfoService;
import cn.stylefeng.guns.modular.om.productionOrderRecords.model.params.ProductionOrderRecordsParam;
import cn.stylefeng.guns.modular.om.productionOrderRecords.model.result.ProductionOrderRecordsResult;
import cn.stylefeng.guns.modular.om.productionOrderRecords.service.ProductionOrderRecordsService;
import cn.stylefeng.guns.modular.sc.repairManageInfo.model.params.RepairManageInfoParam;
import cn.stylefeng.guns.modular.sc.repairManageInfo.model.result.RepairManageInfoResult;
import cn.stylefeng.guns.modular.sc.repairManageInfo.service.RepairManageInfoService;
import cn.stylefeng.guns.modular.sc.serialNumbersConf.service.SerialNumbersConfService;
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;
import com.kangaroohy.milo.runner.subscription.SubscriptionCallback;
import com.kangaroohy.milo.service.MiloService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@Component
public class OP080Callback implements SubscriptionCallback {
    public MiloService miloService;
    @Autowired
    public ProductionOrdeInfoService productionOrdeInfoService;
    @Autowired
    public PassingStationCollectionService passingStationCollectionService;
    @Autowired
    public ParamCollectionService paramCollectionService;
    @Autowired
    public CollectionParamConfService collectionParamConfService;
    @Autowired
    public SerialNumbersConfService serialNumbersConfService;
    @Autowired
    private EquipmentStatusService equipmentStatusService;
    @Autowired
    private EquipmentAlarmService equipmentAlarmService;
    @Autowired
    private MaterialTraceabilityService materialTraceabilityService;
    @Autowired
    private EquipmentInfoService equipmentInfoService;
    @Autowired
    private RepairManageInfoService repairManageInfoService;
    @Autowired
    private LocationInfoService locationInfoService;
    @Autowired
    private GreaseManageService greaseManageService;
    @Autowired
    private ProductionOrderRecordsService productionOrderRecordsService;
    @Autowired
    private ProductionOrderBatchInfoService productionOrderBatchInfoService;
    private static Logger logger;
    LogUtil logUtil = new LogUtil();
    static {
        logger = Logger.getLogger(OP080Callback.class);
    }
    private static Date IN_TIME = null;
    private static String S_ORDER_CODE = "";//工单编号
    private static String S_PRODUCT_CODE = "";//产品编号
    private static String S_PRODUCT_TYPE= "";//产品类型
    private static String S_SFC_CODE = "";//总成编码
    private static String PRODUCTION_LINE  = "OP";//产线号
    private static String LOCATION_CODE  = "OP080";//工位号
    private static List list = null;
    public OP080Callback(MiloService miloService,
                         ProductionOrdeInfoService productionOrdeInfoService,
                         PassingStationCollectionService passingStationCollectionService,
                         ParamCollectionService paramCollectionService,
                         CollectionParamConfService collectionParamConfService,
                         SerialNumbersConfService serialNumbersConfService,
                         EquipmentStatusService equipmentStatusService,
                         EquipmentAlarmService equipmentAlarmService,
                         MaterialTraceabilityService materialTraceabilityService,
                         EquipmentInfoService equipmentInfoService,
                         RepairManageInfoService repairManageInfoService,
                         LocationInfoService locationInfoService,
                         GreaseManageService greaseManageService,
                         ProductionOrderRecordsService productionOrderRecordsService,
                         ProductionOrderBatchInfoService productionOrderBatchInfoService) {
        this.miloService = miloService;
        this.productionOrdeInfoService = productionOrdeInfoService;
        this.passingStationCollectionService = passingStationCollectionService;
        this.paramCollectionService = paramCollectionService;
        this.collectionParamConfService = collectionParamConfService;
        this.serialNumbersConfService = serialNumbersConfService;
        this.equipmentStatusService = equipmentStatusService;
        this.equipmentAlarmService = equipmentAlarmService;
        this.materialTraceabilityService = materialTraceabilityService;
        this.equipmentInfoService = equipmentInfoService;
        this.repairManageInfoService = repairManageInfoService;
        this.locationInfoService = locationInfoService;
        this.greaseManageService = greaseManageService;
        this.productionOrderRecordsService = productionOrderRecordsService;
        this.productionOrderBatchInfoService = productionOrderBatchInfoService;
    }
    @Override
    public void onSubscribe(String identifier, Object value) {
        String ecpStr = "";//异常记录标记
        try {
            //心跳
            if(null != value && identifier.equals(OPCElement.OP080_F_HEART_BEAT)){
                if( "false".equals(value.toString()))
                {
                    ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP080_F_HEART_BEAT,true);
                    miloService.writeToOpcUa(entity);
                }
            }
            //PLC进站
            else if(null != value && identifier.equals(OPCElement.OP080_J_PLC_START)){
                if("true".equals(value.toString())){
                    handleOrder();
                }
            }
            //PLC出站
            else if(null != value && identifier.equals(OPCElement.OP080_J_PLC_FINISH)){
                if("true".equals(value.toString())){
                    handleFinsh();
                    handleInfo();
                    handleMaterial();
                }
            }else{
                System.out.println("值没有变");
            }
        } catch (Exception e) {
            ecpStr ="出现异常:" + logUtil.getTrace(e);
        }finally {
            if(!"".equals(ecpStr)){
                logger.info(ecpStr+"\r\n");
            }
        }
    }
    public void handleRepair() throws Exception{
        RepairManageInfoParam repairManageInfoParam = new RepairManageInfoParam();
        repairManageInfoParam.setLocationCode(LOCATION_CODE);
        repairManageInfoParam.setManageType("2");
        repairManageInfoParam.setUpPlc("0");
        List<RepairManageInfoResult> list = repairManageInfoService.findListBySpec(repairManageInfoParam);
        if(list.size()>0) {
            RepairManageInfoResult result = list.get(0);
            S_SFC_CODE = result.getSfc();
            S_ORDER_CODE = result.getWorkOrderNo();
            S_PRODUCT_CODE = result.getProductCode();
            S_PRODUCT_TYPE = GlobalVariable.PRODUCT_TYPE_MAP.get(S_PRODUCT_CODE);
            String  repairLocation = result.getPoorLocationCode();//
            //根据工位编码查询工位表中配置的返修工位号
            LocationInfoParam param = new LocationInfoParam();
            param.setLocationCode(repairLocation);
            List<LocationInfoResult> results = locationInfoService.findListBySpec(param);
            if(results.size()>0) {
                LocationInfoResult r = results.get(0);
                String repairLocationNo = r.getSpareField2();
                if(null != repairLocationNo && "" != repairLocationNo){
                    List<ReadWriteEntity> lists = new ArrayList<>();
                    lists.add(new ReadWriteEntity(OPCElement.OP080_S_ORDER_CODE,S_ORDER_CODE));
                    lists.add(new ReadWriteEntity(OPCElement.OP080_S_PRODUCT_CODE,S_PRODUCT_TYPE));
                    lists.add(new ReadWriteEntity(OPCElement.OP080_S_SFC_CODE,S_SFC_CODE));
                    lists.add(new ReadWriteEntity(OPCElement.OP080_P_REPAIR_LOCATION,repairLocationNo));
                    lists.add(new ReadWriteEntity(OPCElement.OP080_J_PC_WRITE_ORDER,true));
                    miloService.writeToOpcUa(lists);
                    //更新为已经返修上线
                    Long id = result.getId();
                    repairManageInfoParam.setId(id);
                    repairManageInfoParam.setUpPlc("1");
                    repairManageInfoService.update(repairManageInfoParam);
                }else{
                    logger.info("OP080工位,handleRepair è¯·æŸ¥è¯¢"+repairLocation+"工位是否配置返修工位号!");
                }
            }else{
                logger.info("OP080工位,handleRepair æ— æ³•æŸ¥è¯¢åˆ°"+repairLocation+"工位!");
            }
        }
    }
    //PC读工单
    public void handleOrder() throws Exception {
        logger.info("handleOrder PC处理开始!");
        IN_TIME = DateTool.getLocalTimeForDate();
        List<String> lists = new ArrayList<>();
        lists.add(OPCElement.OP080_S_ORDER_CODE);
        lists.add(OPCElement.OP080_S_PRODUCT_CODE);
        lists.add(OPCElement.OP080_S_SFC_CODE);
        List<ReadWriteEntity> returnLists= miloService.readFromOpcUa(lists);
        returnLists.forEach(element->{
            switch(element.getIdentifier()){
                case OPCElement.OP080_S_ORDER_CODE:
                    S_ORDER_CODE = element.getValue().toString();
                    break;
                case OPCElement.OP080_S_PRODUCT_CODE:
                    S_PRODUCT_TYPE = element.getValue().toString();
                    S_PRODUCT_CODE = GlobalVariable.PRODUCT_CODE_MAP.get(S_PRODUCT_TYPE);
                    break;
                case OPCElement.OP080_S_SFC_CODE:
                    S_SFC_CODE = element.getValue().toString();
                    break;
                default:
                    break;
            }
        });
        ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP080_J_PC_WRITE_ORDER,true);
        miloService.writeToOpcUa(entity);
        logger.info("handleOrder PC处理完成!");
    }
    public void handleFinsh() throws Exception {
        logger.info("handleFinsh PC处理开始!");
        String S_PRODUCT_STATE_CODE = miloService.
                readFromOpcUa(OPCElement.OP080_S_PRODUCT_STATE_CODE)
                .getValue().toString();
        if("2".equals(S_PRODUCT_STATE_CODE)){
            ProductionOrderRecordsParam productionOrderRecordsParam = new ProductionOrderRecordsParam();
            productionOrderRecordsParam.setWorkOrderNo(S_ORDER_CODE);
            productionOrderRecordsParam.setProductNo(S_SFC_CODE);
            List<ProductionOrderRecordsResult> list = productionOrderRecordsService.findListBySpec(productionOrderRecordsParam);
            if(!list.isEmpty()){
                ProductionOrderRecordsResult productionOrderRecordsResult = list.get(0);
                productionOrderRecordsParam.setId(productionOrderRecordsResult.getId());
                productionOrderRecordsParam.setWhetherPass(S_PRODUCT_STATE_CODE);
                productionOrderRecordsService.update(productionOrderRecordsParam);
            }
        }
        //处理过站信息
        PassingStationCollectionParam param = new PassingStationCollectionParam();
        param.setWorkOrderNo(S_ORDER_CODE);
        param.setProductCode(S_PRODUCT_CODE);
        param.setSfcCode(S_SFC_CODE);
        param.setProductionLine(PRODUCTION_LINE);
        param.setLocationCode(LOCATION_CODE);
        param.setInboundTime(IN_TIME);
        param.setOutboundTime(DateTool.getLocalTimeForDate());
        param.setOutRsSign(S_PRODUCT_STATE_CODE);//出站是否合格
        passingStationCollectionService.add(param);
        ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP080_J_PC_FINISH,true);
        miloService.writeToOpcUa(entity);//写PC完成
        logger.info("handleFinsh PC处理完成!");
    }
    public void handleMaterial() {
        //查询批次上料信息
        ProductionOrderBatchInfoParam productionOrderBatchInfoParam = new ProductionOrderBatchInfoParam();
        productionOrderBatchInfoParam.setWorkOrderNo(S_ORDER_CODE);
        productionOrderBatchInfoParam.setLocationCode(LOCATION_CODE);
        List<ProductionOrderBatchInfoResult> list = productionOrderBatchInfoService.findListBySpec(productionOrderBatchInfoParam);
        for(int i=0;i<list.size();i++){
            ProductionOrderBatchInfoResult productionOrderBatchInfoResult = list.get(i);
            int remainingQuantity =  productionOrderBatchInfoResult.getResidueQuantity();//剩余数量
            if(remainingQuantity>0 ){
                //新增物料追溯
                MaterialTraceabilityParam materialTraceabilityParam = new MaterialTraceabilityParam();
                materialTraceabilityParam.setWorkOrderNo(S_ORDER_CODE);
                materialTraceabilityParam.setProductCode(S_PRODUCT_CODE);
                materialTraceabilityParam.setProductNo(S_SFC_CODE);
                materialTraceabilityParam.setLineCode(PRODUCTION_LINE);
                materialTraceabilityParam.setLocationCode(LOCATION_CODE);
                materialTraceabilityParam.setAssemblyQty(1);
                materialTraceabilityParam.setAssemblyTime(DateTool.getLocalTimeForDate());
                materialTraceabilityParam.setMaterialCode(productionOrderBatchInfoResult.getMaterialCode());//物料编码
                materialTraceabilityParam.setMaterialBatchNo(productionOrderBatchInfoResult.getBatch());//物料批次
                materialTraceabilityService.add(materialTraceabilityParam);
                //更新剩余数量
                productionOrderBatchInfoParam.setId(productionOrderBatchInfoResult.getId());
                productionOrderBatchInfoParam.setResidueQuantity(remainingQuantity-1);//剩余数量
                productionOrderBatchInfoService.update(productionOrderBatchInfoParam);
            }
        }
    }
    //PC读参数信息
    public void handleInfo() throws Exception {
        logger.info("handleInfo START!");
        if(null == list){
            CollectionParamConfParam collectionParamConfParam = new CollectionParamConfParam();
            collectionParamConfParam.setLocationCode(LOCATION_CODE);
            list = collectionParamConfService.findListBySpec(collectionParamConfParam);
        }
        if(null != list && !list.isEmpty()) {
            for (int i = 0; i < list.size(); i++) {
                CollectionParamConfResult result = (CollectionParamConfResult) list.get(i);
                String value = miloService.
                        readFromOpcUa(result.getGatherAddress())
                        .getValue().toString();//读参数值
                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);
                paramCollectionParam.setParamLower(result.getParamLower());
                paramCollectionParam.setParamUpper(result.getParamUpper());
                paramCollectionParam.setParamStandard(result.getParamCentral());
                paramCollectionParam.setCollectionTime(DateTool.getLocalTimeForDate());
                paramCollectionParam.setUnit(result.getUnit());
                paramCollectionService.add(paramCollectionParam);
            }
        }
        logger.info("handleInfo END!");
    }
}
guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/OP090Callback.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,332 @@
package cn.stylefeng.guns.plcserver.callback;
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.model.params.ParamCollectionParam;
import cn.stylefeng.guns.modular.cm.paramCollection.service.ParamCollectionService;
import cn.stylefeng.guns.modular.cm.passingStationCollection.model.params.PassingStationCollectionParam;
import cn.stylefeng.guns.modular.cm.passingStationCollection.model.result.PassingStationCollectionResult;
import cn.stylefeng.guns.modular.cm.passingStationCollection.service.PassingStationCollectionService;
import cn.stylefeng.guns.modular.dq.materialTraceability.model.params.MaterialTraceabilityParam;
import cn.stylefeng.guns.modular.dq.materialTraceability.service.MaterialTraceabilityService;
import cn.stylefeng.guns.modular.em.equipmentAlarm.service.EquipmentAlarmService;
import cn.stylefeng.guns.modular.em.equipmentStatus.service.EquipmentStatusService;
import cn.stylefeng.guns.modular.gm.greaseManage.service.GreaseManageService;
import cn.stylefeng.guns.modular.om.productionOrdeInfo.service.ProductionOrdeInfoService;
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.model.params.ProductionOrderBatchInfoParam;
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.model.result.ProductionOrderBatchInfoResult;
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.service.ProductionOrderBatchInfoService;
import cn.stylefeng.guns.modular.om.productionOrderRecords.model.params.ProductionOrderRecordsParam;
import cn.stylefeng.guns.modular.om.productionOrderRecords.model.result.ProductionOrderRecordsResult;
import cn.stylefeng.guns.modular.om.productionOrderRecords.service.ProductionOrderRecordsService;
import cn.stylefeng.guns.modular.sc.repairManageInfo.service.RepairManageInfoService;
import cn.stylefeng.guns.modular.sc.serialNumbersConf.service.SerialNumbersConfService;
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;
import com.kangaroohy.milo.runner.subscription.SubscriptionCallback;
import com.kangaroohy.milo.service.MiloService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@Component
public class OP090Callback implements SubscriptionCallback {
    public MiloService miloService;
    @Autowired
    public ProductionOrdeInfoService productionOrdeInfoService;
    @Autowired
    public PassingStationCollectionService passingStationCollectionService;
    @Autowired
    public ParamCollectionService paramCollectionService;
    @Autowired
    public CollectionParamConfService collectionParamConfService;
    @Autowired
    public SerialNumbersConfService serialNumbersConfService;
    @Autowired
    private EquipmentStatusService equipmentStatusService;
    @Autowired
    private EquipmentAlarmService equipmentAlarmService;
    @Autowired
    private MaterialTraceabilityService materialTraceabilityService;
    @Autowired
    private EquipmentInfoService equipmentInfoService;
    @Autowired
    private RepairManageInfoService repairManageInfoService;
    @Autowired
    private LocationInfoService locationInfoService;
    @Autowired
    private GreaseManageService greaseManageService;
    @Autowired
    private ProductionOrderRecordsService productionOrderRecordsService;
    @Autowired
    private ProductionOrderBatchInfoService productionOrderBatchInfoService;
    private static Logger logger;
    LogUtil logUtil = new LogUtil();
    static {
        logger = Logger.getLogger(OP090Callback.class);
    }
    private static Date IN_TIME = null;
    private static String S_ORDER_CODE = "";//工单编号
    private static String S_PRODUCT_CODE = "";//产品编号
    private static String S_PRODUCT_TYPE= "";//产品类型
    private static String S_SFC_CODE = "";//总成编码
    private static String PRODUCTION_LINE  = "OP";//产线号
    private static String LOCATION_CODE  = "OP090";//工位号
    private static List list = null;
    public OP090Callback(MiloService miloService,
                         ProductionOrdeInfoService productionOrdeInfoService,
                         PassingStationCollectionService passingStationCollectionService,
                         ParamCollectionService paramCollectionService,
                         CollectionParamConfService collectionParamConfService,
                         SerialNumbersConfService serialNumbersConfService,
                         EquipmentStatusService equipmentStatusService,
                         EquipmentAlarmService equipmentAlarmService,
                         MaterialTraceabilityService materialTraceabilityService,
                         EquipmentInfoService equipmentInfoService,
                         RepairManageInfoService repairManageInfoService,
                         LocationInfoService locationInfoService,
                         GreaseManageService greaseManageService,
                         ProductionOrderRecordsService productionOrderRecordsService,
                         ProductionOrderBatchInfoService productionOrderBatchInfoService) {
        this.miloService = miloService;
        this.productionOrdeInfoService = productionOrdeInfoService;
        this.passingStationCollectionService = passingStationCollectionService;
        this.paramCollectionService = paramCollectionService;
        this.collectionParamConfService = collectionParamConfService;
        this.serialNumbersConfService = serialNumbersConfService;
        this.equipmentStatusService = equipmentStatusService;
        this.equipmentAlarmService = equipmentAlarmService;
        this.materialTraceabilityService = materialTraceabilityService;
        this.equipmentInfoService = equipmentInfoService;
        this.repairManageInfoService = repairManageInfoService;
        this.locationInfoService = locationInfoService;
        this.greaseManageService = greaseManageService;
        this.productionOrderRecordsService = productionOrderRecordsService;
        this.productionOrderBatchInfoService = productionOrderBatchInfoService;
    }
    @Override
    public void onSubscribe(String identifier, Object value) {
        String ecpStr = "";//异常记录标记
        try {
            //心跳
            if(null != value && identifier.equals(OPCElement.OP090_F_HEART_BEAT)){
                if( "false".equals(value.toString()))
                {
                    ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP090_F_HEART_BEAT,true);
                    miloService.writeToOpcUa(entity);
                }
            }
            //PLC进站
            else if(null != value && identifier.equals(OPCElement.OP090_J_PLC_START)){
                if("true".equals(value.toString())){
                    handleOrder();
                }
            }
            //PLC出站
            else if(null != value && identifier.equals(OPCElement.OP090_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 {
        logger.info("handleOrder PC处理开始!");
        IN_TIME = DateTool.getLocalTimeForDate();
        List<String> lists = new ArrayList<>();
        lists.add(OPCElement.OP090_S_ORDER_CODE);
        lists.add(OPCElement.OP090_S_PRODUCT_CODE);
        lists.add(OPCElement.OP090_S_SFC_CODE);
        List<ReadWriteEntity> returnLists= miloService.readFromOpcUa(lists);
        returnLists.forEach(element->{
            switch(element.getIdentifier()){
                case OPCElement.OP090_S_ORDER_CODE:
                    S_ORDER_CODE = element.getValue().toString();
                    break;
                case OPCElement.OP090_S_PRODUCT_CODE:
                    S_PRODUCT_TYPE = element.getValue().toString();
                    S_PRODUCT_CODE = GlobalVariable.PRODUCT_CODE_MAP.get(S_PRODUCT_TYPE);
                    break;
                case OPCElement.OP090_S_SFC_CODE:
                    S_SFC_CODE = element.getValue().toString();
                    break;
                default:
                    break;
            }
        });
        ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP090_J_PC_WRITE_ORDER,true);
        miloService.writeToOpcUa(entity);
        logger.info("handleOrder PC处理完成!");
    }
    public void handleFinsh() throws Exception {
        logger.info("handleFinsh PC处理开始!");
        //处理过站信息
        String S_PRODUCT_STATE_CODE = miloService.
                readFromOpcUa(OPCElement.OP090_S_PRODUCT_STATE_CODE)
                .getValue().toString();
        PassingStationCollectionParam param = new PassingStationCollectionParam();
        param.setWorkOrderNo(S_ORDER_CODE);
        param.setProductCode(S_PRODUCT_CODE);
        param.setSfcCode(S_SFC_CODE);
        param.setProductionLine(PRODUCTION_LINE);
        param.setLocationCode(LOCATION_CODE);
        param.setInboundTime(IN_TIME);
        param.setOutboundTime(DateTool.getLocalTimeForDate());
        param.setOutRsSign(S_PRODUCT_STATE_CODE);//出站是否合格
        passingStationCollectionService.add(param);
        String eopSfcCode = miloService.
                readFromOpcUa(OPCElement.OP090_S_SFC_CODE_EOP)
                .getValue().toString();
        //根据分总成编码,将EOP物料数据绑定关系修改为总成编码
        materialTraceabilityService.updateSFC(S_SFC_CODE,eopSfcCode);
        //根据分总成编码,将EOP过站数据绑定关系修改为总成编码
        passingStationCollectionService.updateSFC(S_SFC_CODE,eopSfcCode);
        //根据分总成编码,将EOP采集数据绑定关系修改为总成编码
        paramCollectionService.updateSFC(S_SFC_CODE,eopSfcCode);
        logger.info("S_SFC_CODE:"+S_SFC_CODE);
        logger.info("eopSfcCode:"+eopSfcCode);
        //查询COP和BOP是否合格
        PassingStationCollectionParam passingStationCollectionParam = new PassingStationCollectionParam();
        passingStationCollectionParam.setSfcCode(S_SFC_CODE);
        List<PassingStationCollectionResult> passingStationCollectionResultList =
                passingStationCollectionService.findListBySpec(passingStationCollectionParam);
        String isProductState = "true";
        for(int i=0;i<passingStationCollectionResultList.size();i++){
            PassingStationCollectionResult passingStationCollectionResult = passingStationCollectionResultList.get(i);
            if("false".equals(passingStationCollectionResult.getOutRsSign())){
                isProductState = "false";
                break;
            }
        }
        //修改报工记录
        if("false".equals(S_PRODUCT_STATE_CODE) || "false".equals(isProductState)){
            ProductionOrderRecordsParam productionOrderRecordsParam = new ProductionOrderRecordsParam();
            productionOrderRecordsParam.setWorkOrderNo(S_ORDER_CODE);
            productionOrderRecordsParam.setProductNo(S_SFC_CODE);
            List<ProductionOrderRecordsResult> list = productionOrderRecordsService.findListBySpec(productionOrderRecordsParam);
            if(list.size()>0){
                ProductionOrderRecordsResult productionOrderRecordsResult = list.get(0);
                productionOrderRecordsParam.setId(productionOrderRecordsResult.getId());
                productionOrderRecordsParam.setWhetherPass("false");
                productionOrderRecordsService.update(productionOrderRecordsParam);
            }
        }
        ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP090_J_PC_FINISH,true);
        miloService.writeToOpcUa(entity);//写PC完成
        logger.info("handleFinsh PC处理完成!");
    }
    public void handleMaterial() {
        //查询批次上料信息
        ProductionOrderBatchInfoParam productionOrderBatchInfoParam = new ProductionOrderBatchInfoParam();
        productionOrderBatchInfoParam.setWorkOrderNo(S_ORDER_CODE);
        productionOrderBatchInfoParam.setLocationCode(LOCATION_CODE);
        List<ProductionOrderBatchInfoResult> list = productionOrderBatchInfoService.findListBySpec(productionOrderBatchInfoParam);
        for(int i=0;i<list.size();i++){
            ProductionOrderBatchInfoResult productionOrderBatchInfoResult = list.get(i);
            int remainingQuantity =  productionOrderBatchInfoResult.getResidueQuantity();//剩余数量
            if(remainingQuantity>0 ){
                //新增物料追溯
                MaterialTraceabilityParam materialTraceabilityParam = new MaterialTraceabilityParam();
                materialTraceabilityParam.setWorkOrderNo(S_ORDER_CODE);
                materialTraceabilityParam.setProductCode(S_PRODUCT_CODE);
                materialTraceabilityParam.setProductNo(S_SFC_CODE);
                materialTraceabilityParam.setLineCode(PRODUCTION_LINE);
                materialTraceabilityParam.setLocationCode(LOCATION_CODE);
                materialTraceabilityParam.setAssemblyQty(1);
                materialTraceabilityParam.setAssemblyTime(DateTool.getLocalTimeForDate());
                materialTraceabilityParam.setMaterialCode(productionOrderBatchInfoResult.getMaterialCode());//物料编码
                materialTraceabilityParam.setMaterialBatchNo(productionOrderBatchInfoResult.getBatch());//物料批次
                materialTraceabilityService.add(materialTraceabilityParam);
                //更新剩余数量
                productionOrderBatchInfoParam.setId(productionOrderBatchInfoResult.getId());
                productionOrderBatchInfoParam.setResidueQuantity(remainingQuantity-1);//剩余数量
                productionOrderBatchInfoService.update(productionOrderBatchInfoParam);
            }
        }
    }
    //PC读参数信息
    public void handleInfo() throws Exception {
        logger.info("handleInfo START!");
        if(null == list){
            CollectionParamConfParam collectionParamConfParam = new CollectionParamConfParam();
            collectionParamConfParam.setLocationCode(LOCATION_CODE);
            list = collectionParamConfService.findListBySpec(collectionParamConfParam);
        }
        if(null != list && !list.isEmpty()) {
            for (int i = 0; i < list.size(); i++) {
                CollectionParamConfResult result = (CollectionParamConfResult) list.get(i);
                String value = miloService.
                        readFromOpcUa(result.getGatherAddress())
                        .getValue().toString();//读参数值
                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);
                paramCollectionParam.setParamLower(result.getParamLower());
                paramCollectionParam.setParamUpper(result.getParamUpper());
                paramCollectionParam.setParamStandard(result.getParamCentral());
                paramCollectionParam.setCollectionTime(DateTool.getLocalTimeForDate());
                paramCollectionParam.setUnit(result.getUnit());
                paramCollectionService.add(paramCollectionParam);
            }
        }
        logger.info("handleInfo END!");
    }
}
guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/OP100Callback.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,298 @@
package cn.stylefeng.guns.plcserver.callback;
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.model.params.ParamCollectionParam;
import cn.stylefeng.guns.modular.cm.paramCollection.service.ParamCollectionService;
import cn.stylefeng.guns.modular.cm.passingStationCollection.model.params.PassingStationCollectionParam;
import cn.stylefeng.guns.modular.cm.passingStationCollection.service.PassingStationCollectionService;
import cn.stylefeng.guns.modular.dq.materialTraceability.model.params.MaterialTraceabilityParam;
import cn.stylefeng.guns.modular.dq.materialTraceability.service.MaterialTraceabilityService;
import cn.stylefeng.guns.modular.em.equipmentAlarm.service.EquipmentAlarmService;
import cn.stylefeng.guns.modular.em.equipmentStatus.service.EquipmentStatusService;
import cn.stylefeng.guns.modular.gm.greaseManage.service.GreaseManageService;
import cn.stylefeng.guns.modular.om.productionOrdeInfo.service.ProductionOrdeInfoService;
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.model.params.ProductionOrderBatchInfoParam;
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.model.result.ProductionOrderBatchInfoResult;
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.service.ProductionOrderBatchInfoService;
import cn.stylefeng.guns.modular.om.productionOrderRecords.model.params.ProductionOrderRecordsParam;
import cn.stylefeng.guns.modular.om.productionOrderRecords.model.result.ProductionOrderRecordsResult;
import cn.stylefeng.guns.modular.om.productionOrderRecords.service.ProductionOrderRecordsService;
import cn.stylefeng.guns.modular.sc.repairManageInfo.service.RepairManageInfoService;
import cn.stylefeng.guns.modular.sc.serialNumbersConf.service.SerialNumbersConfService;
import cn.stylefeng.guns.plcserver.opc.GlobalVariable;
import cn.stylefeng.guns.plcserver.opc.OPCElement;
import cn.stylefeng.guns.plcserver.tool.DateTool;
import cn.stylefeng.guns.plcserver.tool.LogUtil;
import com.kangaroohy.milo.model.ReadWriteEntity;
import com.kangaroohy.milo.runner.subscription.SubscriptionCallback;
import com.kangaroohy.milo.service.MiloService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@Component
public class OP100Callback implements SubscriptionCallback {
    public MiloService miloService;
    @Autowired
    public ProductionOrdeInfoService productionOrdeInfoService;
    @Autowired
    public PassingStationCollectionService passingStationCollectionService;
    @Autowired
    public ParamCollectionService paramCollectionService;
    @Autowired
    public CollectionParamConfService collectionParamConfService;
    @Autowired
    public SerialNumbersConfService serialNumbersConfService;
    @Autowired
    private EquipmentStatusService equipmentStatusService;
    @Autowired
    private EquipmentAlarmService equipmentAlarmService;
    @Autowired
    private MaterialTraceabilityService materialTraceabilityService;
    @Autowired
    private EquipmentInfoService equipmentInfoService;
    @Autowired
    private RepairManageInfoService repairManageInfoService;
    @Autowired
    private LocationInfoService locationInfoService;
    @Autowired
    private GreaseManageService greaseManageService;
    @Autowired
    private ProductionOrderRecordsService productionOrderRecordsService;
    @Autowired
    private ProductionOrderBatchInfoService productionOrderBatchInfoService;
    private static Logger logger;
    LogUtil logUtil = new LogUtil();
    static {
        logger = Logger.getLogger(OP100Callback.class);
    }
    private static Date IN_TIME = null;
    private static String S_ORDER_CODE = "";//工单编号
    private static String S_PRODUCT_CODE = "";//产品编号
    private static String S_PRODUCT_TYPE= "";//产品类型
    private static String S_SFC_CODE = "";//总成编码
    private static String PRODUCTION_LINE  = "OP";//产线号
    private static String LOCATION_CODE  = "OP100";//工位号
    private static List list = null;
    public OP100Callback(MiloService miloService,
                         ProductionOrdeInfoService productionOrdeInfoService,
                         PassingStationCollectionService passingStationCollectionService,
                         ParamCollectionService paramCollectionService,
                         CollectionParamConfService collectionParamConfService,
                         SerialNumbersConfService serialNumbersConfService,
                         EquipmentStatusService equipmentStatusService,
                         EquipmentAlarmService equipmentAlarmService,
                         MaterialTraceabilityService materialTraceabilityService,
                         EquipmentInfoService equipmentInfoService,
                         RepairManageInfoService repairManageInfoService,
                         LocationInfoService locationInfoService,
                         GreaseManageService greaseManageService,
                         ProductionOrderRecordsService productionOrderRecordsService,
                         ProductionOrderBatchInfoService productionOrderBatchInfoService) {
        this.miloService = miloService;
        this.productionOrdeInfoService = productionOrdeInfoService;
        this.passingStationCollectionService = passingStationCollectionService;
        this.paramCollectionService = paramCollectionService;
        this.collectionParamConfService = collectionParamConfService;
        this.serialNumbersConfService = serialNumbersConfService;
        this.equipmentStatusService = equipmentStatusService;
        this.equipmentAlarmService = equipmentAlarmService;
        this.materialTraceabilityService = materialTraceabilityService;
        this.equipmentInfoService = equipmentInfoService;
        this.repairManageInfoService = repairManageInfoService;
        this.locationInfoService = locationInfoService;
        this.greaseManageService = greaseManageService;
        this.productionOrderRecordsService = productionOrderRecordsService;
        this.productionOrderBatchInfoService = productionOrderBatchInfoService;
    }
    @Override
    public void onSubscribe(String identifier, Object value) {
        String ecpStr = "";//异常记录标记
        try {
            //心跳
            if(null != value && identifier.equals(OPCElement.OP100_F_HEART_BEAT)){
                if( "false".equals(value.toString()))
                {
                    ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP100_F_HEART_BEAT,true);
                    miloService.writeToOpcUa(entity);
                }
            }
            //PLC进站
            else if(null != value && identifier.equals(OPCElement.OP100_J_PLC_START)){
                if("true".equals(value.toString())){
                    handleOrder();
                }
            }
            //PLC出站
            else if(null != value && identifier.equals(OPCElement.OP100_J_PLC_FINISH)){
                if("true".equals(value.toString())){
                    handleFinsh();
                    handleInfo();
                    handleMaterial();
                }
            }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 {
        logger.info("handleOrder PC处理开始!");
        IN_TIME = DateTool.getLocalTimeForDate();
        List<String> lists = new ArrayList<>();
        lists.add(OPCElement.OP100_S_ORDER_CODE);
        lists.add(OPCElement.OP100_S_PRODUCT_CODE);
        lists.add(OPCElement.OP100_S_SFC_CODE);
        List<ReadWriteEntity> returnLists= miloService.readFromOpcUa(lists);
        returnLists.forEach(element->{
            switch(element.getIdentifier()){
                case OPCElement.OP100_S_ORDER_CODE:
                    S_ORDER_CODE = element.getValue().toString();
                    break;
                case OPCElement.OP100_S_PRODUCT_CODE:
                    S_PRODUCT_TYPE = element.getValue().toString();
                    S_PRODUCT_CODE = GlobalVariable.PRODUCT_CODE_MAP.get(S_PRODUCT_TYPE);
                    break;
                case OPCElement.OP100_S_SFC_CODE:
                    S_SFC_CODE = element.getValue().toString();
                    break;
                default:
                    break;
            }
        });
        ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP100_J_PC_WRITE_ORDER,true);
        miloService.writeToOpcUa(entity);
        logger.info("handleOrder PC处理完成!");
    }
    public void handleFinsh() throws Exception {
        logger.info("handleFinsh PC处理开始!");
        String S_PRODUCT_STATE_CODE = miloService.
                readFromOpcUa(OPCElement.OP100_S_PRODUCT_STATE_CODE)
                .getValue().toString();
        if("2".equals(S_PRODUCT_STATE_CODE)){
            ProductionOrderRecordsParam productionOrderRecordsParam = new ProductionOrderRecordsParam();
            productionOrderRecordsParam.setWorkOrderNo(S_ORDER_CODE);
            productionOrderRecordsParam.setProductNo(S_SFC_CODE);
            List<ProductionOrderRecordsResult> list = productionOrderRecordsService.findListBySpec(productionOrderRecordsParam);
            if(!list.isEmpty()){
                ProductionOrderRecordsResult productionOrderRecordsResult = list.get(0);
                productionOrderRecordsParam.setId(productionOrderRecordsResult.getId());
                productionOrderRecordsParam.setWhetherPass(S_PRODUCT_STATE_CODE);
                productionOrderRecordsService.update(productionOrderRecordsParam);
            }
        }
        //处理过站信息
        PassingStationCollectionParam param = new PassingStationCollectionParam();
        param.setWorkOrderNo(S_ORDER_CODE);
        param.setProductCode(S_PRODUCT_CODE);
        param.setSfcCode(S_SFC_CODE);
        param.setProductionLine(PRODUCTION_LINE);
        param.setLocationCode(LOCATION_CODE);
        param.setInboundTime(IN_TIME);
        param.setOutboundTime(DateTool.getLocalTimeForDate());
        param.setOutRsSign(S_PRODUCT_STATE_CODE);//出站是否合格
        passingStationCollectionService.add(param);
        ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP100_J_PC_FINISH,true);
        miloService.writeToOpcUa(entity);//写PC完成
        logger.info("handleFinsh PC处理完成!");
    }
    public void handleMaterial() {
        //查询批次上料信息
        ProductionOrderBatchInfoParam productionOrderBatchInfoParam = new ProductionOrderBatchInfoParam();
        productionOrderBatchInfoParam.setWorkOrderNo(S_ORDER_CODE);
        productionOrderBatchInfoParam.setLocationCode(LOCATION_CODE);
        List<ProductionOrderBatchInfoResult> list = productionOrderBatchInfoService.findListBySpec(productionOrderBatchInfoParam);
        for(int i=0;i<list.size();i++){
            ProductionOrderBatchInfoResult productionOrderBatchInfoResult = list.get(i);
            int remainingQuantity =  productionOrderBatchInfoResult.getResidueQuantity();//剩余数量
            if(remainingQuantity>0 ){
                //新增物料追溯
                MaterialTraceabilityParam materialTraceabilityParam = new MaterialTraceabilityParam();
                materialTraceabilityParam.setWorkOrderNo(S_ORDER_CODE);
                materialTraceabilityParam.setProductCode(S_PRODUCT_CODE);
                materialTraceabilityParam.setProductNo(S_SFC_CODE);
                materialTraceabilityParam.setLineCode(PRODUCTION_LINE);
                materialTraceabilityParam.setLocationCode(LOCATION_CODE);
                materialTraceabilityParam.setAssemblyQty(1);
                materialTraceabilityParam.setAssemblyTime(DateTool.getLocalTimeForDate());
                materialTraceabilityParam.setMaterialCode(productionOrderBatchInfoResult.getMaterialCode());//物料编码
                materialTraceabilityParam.setMaterialBatchNo(productionOrderBatchInfoResult.getBatch());//物料批次
                materialTraceabilityService.add(materialTraceabilityParam);
                //更新剩余数量
                productionOrderBatchInfoParam.setId(productionOrderBatchInfoResult.getId());
                productionOrderBatchInfoParam.setResidueQuantity(remainingQuantity-1);//剩余数量
                productionOrderBatchInfoService.update(productionOrderBatchInfoParam);
            }
        }
    }
    //PC读参数信息
    public void handleInfo() throws Exception {
        logger.info("handleInfo START!");
        if(null == list){
            CollectionParamConfParam collectionParamConfParam = new CollectionParamConfParam();
            collectionParamConfParam.setLocationCode(LOCATION_CODE);
            list = collectionParamConfService.findListBySpec(collectionParamConfParam);
        }
        if(null != list && !list.isEmpty()) {
            for (int i = 0; i < list.size(); i++) {
                CollectionParamConfResult result = (CollectionParamConfResult) list.get(i);
                String value = miloService.
                        readFromOpcUa(result.getGatherAddress())
                        .getValue().toString();//读参数值
                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);
                paramCollectionParam.setParamLower(result.getParamLower());
                paramCollectionParam.setParamUpper(result.getParamUpper());
                paramCollectionParam.setParamStandard(result.getParamCentral());
                paramCollectionParam.setCollectionTime(DateTool.getLocalTimeForDate());
                paramCollectionParam.setUnit(result.getUnit());
                paramCollectionService.add(paramCollectionParam);
            }
        }
        logger.info("handleInfo END!");
    }
}
guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/OP110Callback.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,298 @@
package cn.stylefeng.guns.plcserver.callback;
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.model.params.ParamCollectionParam;
import cn.stylefeng.guns.modular.cm.paramCollection.service.ParamCollectionService;
import cn.stylefeng.guns.modular.cm.passingStationCollection.model.params.PassingStationCollectionParam;
import cn.stylefeng.guns.modular.cm.passingStationCollection.service.PassingStationCollectionService;
import cn.stylefeng.guns.modular.dq.materialTraceability.model.params.MaterialTraceabilityParam;
import cn.stylefeng.guns.modular.dq.materialTraceability.service.MaterialTraceabilityService;
import cn.stylefeng.guns.modular.em.equipmentAlarm.service.EquipmentAlarmService;
import cn.stylefeng.guns.modular.em.equipmentStatus.service.EquipmentStatusService;
import cn.stylefeng.guns.modular.gm.greaseManage.service.GreaseManageService;
import cn.stylefeng.guns.modular.om.productionOrdeInfo.service.ProductionOrdeInfoService;
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.model.params.ProductionOrderBatchInfoParam;
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.model.result.ProductionOrderBatchInfoResult;
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.service.ProductionOrderBatchInfoService;
import cn.stylefeng.guns.modular.om.productionOrderRecords.model.params.ProductionOrderRecordsParam;
import cn.stylefeng.guns.modular.om.productionOrderRecords.model.result.ProductionOrderRecordsResult;
import cn.stylefeng.guns.modular.om.productionOrderRecords.service.ProductionOrderRecordsService;
import cn.stylefeng.guns.modular.sc.repairManageInfo.service.RepairManageInfoService;
import cn.stylefeng.guns.modular.sc.serialNumbersConf.service.SerialNumbersConfService;
import cn.stylefeng.guns.plcserver.opc.GlobalVariable;
import cn.stylefeng.guns.plcserver.opc.OPCElement;
import cn.stylefeng.guns.plcserver.tool.DateTool;
import cn.stylefeng.guns.plcserver.tool.LogUtil;
import com.kangaroohy.milo.model.ReadWriteEntity;
import com.kangaroohy.milo.runner.subscription.SubscriptionCallback;
import com.kangaroohy.milo.service.MiloService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@Component
public class OP110Callback implements SubscriptionCallback {
    public MiloService miloService;
    @Autowired
    public ProductionOrdeInfoService productionOrdeInfoService;
    @Autowired
    public PassingStationCollectionService passingStationCollectionService;
    @Autowired
    public ParamCollectionService paramCollectionService;
    @Autowired
    public CollectionParamConfService collectionParamConfService;
    @Autowired
    public SerialNumbersConfService serialNumbersConfService;
    @Autowired
    private EquipmentStatusService equipmentStatusService;
    @Autowired
    private EquipmentAlarmService equipmentAlarmService;
    @Autowired
    private MaterialTraceabilityService materialTraceabilityService;
    @Autowired
    private EquipmentInfoService equipmentInfoService;
    @Autowired
    private RepairManageInfoService repairManageInfoService;
    @Autowired
    private LocationInfoService locationInfoService;
    @Autowired
    private GreaseManageService greaseManageService;
    @Autowired
    private ProductionOrderRecordsService productionOrderRecordsService;
    @Autowired
    private ProductionOrderBatchInfoService productionOrderBatchInfoService;
    private static Logger logger;
    LogUtil logUtil = new LogUtil();
    static {
        logger = Logger.getLogger(OP110Callback.class);
    }
    private static Date IN_TIME = null;
    private static String S_ORDER_CODE = "";//工单编号
    private static String S_PRODUCT_CODE = "";//产品编号
    private static String S_PRODUCT_TYPE= "";//产品类型
    private static String S_SFC_CODE = "";//总成编码
    private static String PRODUCTION_LINE  = "OP";//产线号
    private static String LOCATION_CODE  = "OP110";//工位号
    private static List list = null;
    public OP110Callback(MiloService miloService,
                         ProductionOrdeInfoService productionOrdeInfoService,
                         PassingStationCollectionService passingStationCollectionService,
                         ParamCollectionService paramCollectionService,
                         CollectionParamConfService collectionParamConfService,
                         SerialNumbersConfService serialNumbersConfService,
                         EquipmentStatusService equipmentStatusService,
                         EquipmentAlarmService equipmentAlarmService,
                         MaterialTraceabilityService materialTraceabilityService,
                         EquipmentInfoService equipmentInfoService,
                         RepairManageInfoService repairManageInfoService,
                         LocationInfoService locationInfoService,
                         GreaseManageService greaseManageService,
                         ProductionOrderRecordsService productionOrderRecordsService,
                         ProductionOrderBatchInfoService productionOrderBatchInfoService) {
        this.miloService = miloService;
        this.productionOrdeInfoService = productionOrdeInfoService;
        this.passingStationCollectionService = passingStationCollectionService;
        this.paramCollectionService = paramCollectionService;
        this.collectionParamConfService = collectionParamConfService;
        this.serialNumbersConfService = serialNumbersConfService;
        this.equipmentStatusService = equipmentStatusService;
        this.equipmentAlarmService = equipmentAlarmService;
        this.materialTraceabilityService = materialTraceabilityService;
        this.equipmentInfoService = equipmentInfoService;
        this.repairManageInfoService = repairManageInfoService;
        this.locationInfoService = locationInfoService;
        this.greaseManageService = greaseManageService;
        this.productionOrderRecordsService = productionOrderRecordsService;
        this.productionOrderBatchInfoService = productionOrderBatchInfoService;
    }
    @Override
    public void onSubscribe(String identifier, Object value) {
        String ecpStr = "";//异常记录标记
        try {
            //心跳
            if(null != value && identifier.equals(OPCElement.OP110_F_HEART_BEAT)){
                if( "false".equals(value.toString()))
                {
                    ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP110_F_HEART_BEAT,true);
                    miloService.writeToOpcUa(entity);
                }
            }
            //PLC进站
            else if(null != value && identifier.equals(OPCElement.OP110_J_PLC_START)){
                if("true".equals(value.toString())){
                    handleOrder();
                }
            }
            //PLC出站
            else if(null != value && identifier.equals(OPCElement.OP110_J_PLC_FINISH)){
                if("true".equals(value.toString())){
                    handleFinsh();
                    handleInfo();
                    handleMaterial();
                }
            }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 {
        logger.info("handleOrder PC处理开始!");
        IN_TIME = DateTool.getLocalTimeForDate();
        List<String> lists = new ArrayList<>();
        lists.add(OPCElement.OP110_S_ORDER_CODE);
        lists.add(OPCElement.OP110_S_PRODUCT_CODE);
        lists.add(OPCElement.OP110_S_SFC_CODE);
        List<ReadWriteEntity> returnLists= miloService.readFromOpcUa(lists);
        returnLists.forEach(element->{
            switch(element.getIdentifier()){
                case OPCElement.OP110_S_ORDER_CODE:
                    S_ORDER_CODE = element.getValue().toString();
                    break;
                case OPCElement.OP110_S_PRODUCT_CODE:
                    S_PRODUCT_TYPE = element.getValue().toString();
                    S_PRODUCT_CODE = GlobalVariable.PRODUCT_CODE_MAP.get(S_PRODUCT_TYPE);
                    break;
                case OPCElement.OP110_S_SFC_CODE:
                    S_SFC_CODE = element.getValue().toString();
                    break;
                default:
                    break;
            }
        });
        ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP110_J_PC_WRITE_ORDER,true);
        miloService.writeToOpcUa(entity);
        logger.info("handleOrder PC处理完成!");
    }
    public void handleFinsh() throws Exception {
        logger.info("handleFinsh PC处理开始!");
        String S_PRODUCT_STATE_CODE = miloService.
                readFromOpcUa(OPCElement.OP110_S_PRODUCT_STATE_CODE)
                .getValue().toString();
        if("2".equals(S_PRODUCT_STATE_CODE)){
            ProductionOrderRecordsParam productionOrderRecordsParam = new ProductionOrderRecordsParam();
            productionOrderRecordsParam.setWorkOrderNo(S_ORDER_CODE);
            productionOrderRecordsParam.setProductNo(S_SFC_CODE);
            List<ProductionOrderRecordsResult> list = productionOrderRecordsService.findListBySpec(productionOrderRecordsParam);
            if(!list.isEmpty()){
                ProductionOrderRecordsResult productionOrderRecordsResult = list.get(0);
                productionOrderRecordsParam.setId(productionOrderRecordsResult.getId());
                productionOrderRecordsParam.setWhetherPass(S_PRODUCT_STATE_CODE);
                productionOrderRecordsService.update(productionOrderRecordsParam);
            }
        }
        //处理过站信息
        PassingStationCollectionParam param = new PassingStationCollectionParam();
        param.setWorkOrderNo(S_ORDER_CODE);
        param.setProductCode(S_PRODUCT_CODE);
        param.setSfcCode(S_SFC_CODE);
        param.setProductionLine(PRODUCTION_LINE);
        param.setLocationCode(LOCATION_CODE);
        param.setInboundTime(IN_TIME);
        param.setOutboundTime(DateTool.getLocalTimeForDate());
        param.setOutRsSign(S_PRODUCT_STATE_CODE);//出站是否合格
        passingStationCollectionService.add(param);
        ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP110_J_PC_FINISH,true);
        miloService.writeToOpcUa(entity);//写PC完成
        logger.info("handleFinsh PC处理完成!");
    }
    public void handleMaterial() {
        //查询批次上料信息
        ProductionOrderBatchInfoParam productionOrderBatchInfoParam = new ProductionOrderBatchInfoParam();
        productionOrderBatchInfoParam.setWorkOrderNo(S_ORDER_CODE);
        productionOrderBatchInfoParam.setLocationCode(LOCATION_CODE);
        List<ProductionOrderBatchInfoResult> list = productionOrderBatchInfoService.findListBySpec(productionOrderBatchInfoParam);
        for(int i=0;i<list.size();i++){
            ProductionOrderBatchInfoResult productionOrderBatchInfoResult = list.get(i);
            int remainingQuantity =  productionOrderBatchInfoResult.getResidueQuantity();//剩余数量
            if(remainingQuantity>0 ){
                //新增物料追溯
                MaterialTraceabilityParam materialTraceabilityParam = new MaterialTraceabilityParam();
                materialTraceabilityParam.setWorkOrderNo(S_ORDER_CODE);
                materialTraceabilityParam.setProductCode(S_PRODUCT_CODE);
                materialTraceabilityParam.setProductNo(S_SFC_CODE);
                materialTraceabilityParam.setLineCode(PRODUCTION_LINE);
                materialTraceabilityParam.setLocationCode(LOCATION_CODE);
                materialTraceabilityParam.setAssemblyQty(1);
                materialTraceabilityParam.setAssemblyTime(DateTool.getLocalTimeForDate());
                materialTraceabilityParam.setMaterialCode(productionOrderBatchInfoResult.getMaterialCode());//物料编码
                materialTraceabilityParam.setMaterialBatchNo(productionOrderBatchInfoResult.getBatch());//物料批次
                materialTraceabilityService.add(materialTraceabilityParam);
                //更新剩余数量
                productionOrderBatchInfoParam.setId(productionOrderBatchInfoResult.getId());
                productionOrderBatchInfoParam.setResidueQuantity(remainingQuantity-1);//剩余数量
                productionOrderBatchInfoService.update(productionOrderBatchInfoParam);
            }
        }
    }
    //PC读参数信息
    public void handleInfo() throws Exception {
        logger.info("handleInfo START!");
        if(null == list){
            CollectionParamConfParam collectionParamConfParam = new CollectionParamConfParam();
            collectionParamConfParam.setLocationCode(LOCATION_CODE);
            list = collectionParamConfService.findListBySpec(collectionParamConfParam);
        }
        if(null != list && !list.isEmpty()) {
            for (int i = 0; i < list.size(); i++) {
                CollectionParamConfResult result = (CollectionParamConfResult) list.get(i);
                String value = miloService.
                        readFromOpcUa(result.getGatherAddress())
                        .getValue().toString();//读参数值
                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);
                paramCollectionParam.setParamLower(result.getParamLower());
                paramCollectionParam.setParamUpper(result.getParamUpper());
                paramCollectionParam.setParamStandard(result.getParamCentral());
                paramCollectionParam.setCollectionTime(DateTool.getLocalTimeForDate());
                paramCollectionParam.setUnit(result.getUnit());
                paramCollectionService.add(paramCollectionParam);
            }
        }
        logger.info("handleInfo END!");
    }
}
guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/OP120BCallback.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,298 @@
package cn.stylefeng.guns.plcserver.callback;
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.model.params.ParamCollectionParam;
import cn.stylefeng.guns.modular.cm.paramCollection.service.ParamCollectionService;
import cn.stylefeng.guns.modular.cm.passingStationCollection.model.params.PassingStationCollectionParam;
import cn.stylefeng.guns.modular.cm.passingStationCollection.service.PassingStationCollectionService;
import cn.stylefeng.guns.modular.dq.materialTraceability.model.params.MaterialTraceabilityParam;
import cn.stylefeng.guns.modular.dq.materialTraceability.service.MaterialTraceabilityService;
import cn.stylefeng.guns.modular.em.equipmentAlarm.service.EquipmentAlarmService;
import cn.stylefeng.guns.modular.em.equipmentStatus.service.EquipmentStatusService;
import cn.stylefeng.guns.modular.gm.greaseManage.service.GreaseManageService;
import cn.stylefeng.guns.modular.om.productionOrdeInfo.service.ProductionOrdeInfoService;
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.model.params.ProductionOrderBatchInfoParam;
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.model.result.ProductionOrderBatchInfoResult;
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.service.ProductionOrderBatchInfoService;
import cn.stylefeng.guns.modular.om.productionOrderRecords.model.params.ProductionOrderRecordsParam;
import cn.stylefeng.guns.modular.om.productionOrderRecords.model.result.ProductionOrderRecordsResult;
import cn.stylefeng.guns.modular.om.productionOrderRecords.service.ProductionOrderRecordsService;
import cn.stylefeng.guns.modular.sc.repairManageInfo.service.RepairManageInfoService;
import cn.stylefeng.guns.modular.sc.serialNumbersConf.service.SerialNumbersConfService;
import cn.stylefeng.guns.plcserver.opc.GlobalVariable;
import cn.stylefeng.guns.plcserver.opc.OPCElement;
import cn.stylefeng.guns.plcserver.tool.DateTool;
import cn.stylefeng.guns.plcserver.tool.LogUtil;
import com.kangaroohy.milo.model.ReadWriteEntity;
import com.kangaroohy.milo.runner.subscription.SubscriptionCallback;
import com.kangaroohy.milo.service.MiloService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@Component
public class OP120BCallback implements SubscriptionCallback {
    public MiloService miloService;
    @Autowired
    public ProductionOrdeInfoService productionOrdeInfoService;
    @Autowired
    public PassingStationCollectionService passingStationCollectionService;
    @Autowired
    public ParamCollectionService paramCollectionService;
    @Autowired
    public CollectionParamConfService collectionParamConfService;
    @Autowired
    public SerialNumbersConfService serialNumbersConfService;
    @Autowired
    private EquipmentStatusService equipmentStatusService;
    @Autowired
    private EquipmentAlarmService equipmentAlarmService;
    @Autowired
    private MaterialTraceabilityService materialTraceabilityService;
    @Autowired
    private EquipmentInfoService equipmentInfoService;
    @Autowired
    private RepairManageInfoService repairManageInfoService;
    @Autowired
    private LocationInfoService locationInfoService;
    @Autowired
    private GreaseManageService greaseManageService;
    @Autowired
    private ProductionOrderRecordsService productionOrderRecordsService;
    @Autowired
    private ProductionOrderBatchInfoService productionOrderBatchInfoService;
    private static Logger logger;
    LogUtil logUtil = new LogUtil();
    static {
        logger = Logger.getLogger(OP120BCallback.class);
    }
    private static Date IN_TIME = null;
    private static String S_ORDER_CODE = "";//工单编号
    private static String S_PRODUCT_CODE = "";//产品编号
    private static String S_PRODUCT_TYPE= "";//产品类型
    private static String S_SFC_CODE = "";//总成编码
    private static String PRODUCTION_LINE  = "OP";//产线号
    private static String LOCATION_CODE  = "OP120B";//工位号
    private static List list = null;
    public OP120BCallback(MiloService miloService,
                          ProductionOrdeInfoService productionOrdeInfoService,
                          PassingStationCollectionService passingStationCollectionService,
                          ParamCollectionService paramCollectionService,
                          CollectionParamConfService collectionParamConfService,
                          SerialNumbersConfService serialNumbersConfService,
                          EquipmentStatusService equipmentStatusService,
                          EquipmentAlarmService equipmentAlarmService,
                          MaterialTraceabilityService materialTraceabilityService,
                          EquipmentInfoService equipmentInfoService,
                          RepairManageInfoService repairManageInfoService,
                          LocationInfoService locationInfoService,
                          GreaseManageService greaseManageService,
                          ProductionOrderRecordsService productionOrderRecordsService,
                          ProductionOrderBatchInfoService productionOrderBatchInfoService) {
        this.miloService = miloService;
        this.productionOrdeInfoService = productionOrdeInfoService;
        this.passingStationCollectionService = passingStationCollectionService;
        this.paramCollectionService = paramCollectionService;
        this.collectionParamConfService = collectionParamConfService;
        this.serialNumbersConfService = serialNumbersConfService;
        this.equipmentStatusService = equipmentStatusService;
        this.equipmentAlarmService = equipmentAlarmService;
        this.materialTraceabilityService = materialTraceabilityService;
        this.equipmentInfoService = equipmentInfoService;
        this.repairManageInfoService = repairManageInfoService;
        this.locationInfoService = locationInfoService;
        this.greaseManageService = greaseManageService;
        this.productionOrderRecordsService = productionOrderRecordsService;
        this.productionOrderBatchInfoService = productionOrderBatchInfoService;
    }
    @Override
    public void onSubscribe(String identifier, Object value) {
        String ecpStr = "";//异常记录标记
        try {
            //心跳
            if(null != value && identifier.equals(OPCElement.OP120B_F_HEART_BEAT)){
                if( "false".equals(value.toString()))
                {
                    ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP120B_F_HEART_BEAT,true);
                    miloService.writeToOpcUa(entity);
                }
            }
            //PLC进站
            else if(null != value && identifier.equals(OPCElement.OP120B_J_PLC_START)){
                if("true".equals(value.toString())){
                    handleOrder();
                }
            }
            //PLC出站
            else if(null != value && identifier.equals(OPCElement.OP120B_J_PLC_FINISH)){
                if("true".equals(value.toString())){
                    handleFinsh();
                    handleInfo();
                    handleMaterial();
                }
            }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 {
        logger.info("handleOrder PC处理开始!");
        IN_TIME = DateTool.getLocalTimeForDate();
        List<String> lists = new ArrayList<>();
        lists.add(OPCElement.OP120B_S_ORDER_CODE);
        lists.add(OPCElement.OP120B_S_PRODUCT_CODE);
        lists.add(OPCElement.OP120B_S_SFC_CODE);
        List<ReadWriteEntity> returnLists= miloService.readFromOpcUa(lists);
        returnLists.forEach(element->{
            switch(element.getIdentifier()){
                case OPCElement.OP120B_S_ORDER_CODE:
                    S_ORDER_CODE = element.getValue().toString();
                    break;
                case OPCElement.OP120B_S_PRODUCT_CODE:
                    S_PRODUCT_TYPE = element.getValue().toString();
                    S_PRODUCT_CODE = GlobalVariable.PRODUCT_CODE_MAP.get(S_PRODUCT_TYPE);
                    break;
                case OPCElement.OP120B_S_SFC_CODE:
                    S_SFC_CODE = element.getValue().toString();
                    break;
                default:
                    break;
            }
        });
        ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP120B_J_PC_WRITE_ORDER,true);
        miloService.writeToOpcUa(entity);
        logger.info("handleOrder PC处理完成!");
    }
    public void handleFinsh() throws Exception {
        logger.info("handleFinsh PC处理开始!");
        String S_PRODUCT_STATE_CODE = miloService.
                readFromOpcUa(OPCElement.OP120B_S_PRODUCT_STATE_CODE)
                .getValue().toString();
        if("2".equals(S_PRODUCT_STATE_CODE)){
            ProductionOrderRecordsParam productionOrderRecordsParam = new ProductionOrderRecordsParam();
            productionOrderRecordsParam.setWorkOrderNo(S_ORDER_CODE);
            productionOrderRecordsParam.setProductNo(S_SFC_CODE);
            List<ProductionOrderRecordsResult> list = productionOrderRecordsService.findListBySpec(productionOrderRecordsParam);
            if(!list.isEmpty()){
                ProductionOrderRecordsResult productionOrderRecordsResult = list.get(0);
                productionOrderRecordsParam.setId(productionOrderRecordsResult.getId());
                productionOrderRecordsParam.setWhetherPass(S_PRODUCT_STATE_CODE);
                productionOrderRecordsService.update(productionOrderRecordsParam);
            }
        }
        //处理过站信息
        PassingStationCollectionParam param = new PassingStationCollectionParam();
        param.setWorkOrderNo(S_ORDER_CODE);
        param.setProductCode(S_PRODUCT_CODE);
        param.setSfcCode(S_SFC_CODE);
        param.setProductionLine(PRODUCTION_LINE);
        param.setLocationCode(LOCATION_CODE);
        param.setInboundTime(IN_TIME);
        param.setOutboundTime(DateTool.getLocalTimeForDate());
        param.setOutRsSign(S_PRODUCT_STATE_CODE);//出站是否合格
        passingStationCollectionService.add(param);
        ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP120B_J_PC_FINISH,true);
        miloService.writeToOpcUa(entity);//写PC完成
        logger.info("handleFinsh PC处理完成!");
    }
    public void handleMaterial() {
        //查询批次上料信息
        ProductionOrderBatchInfoParam productionOrderBatchInfoParam = new ProductionOrderBatchInfoParam();
        productionOrderBatchInfoParam.setWorkOrderNo(S_ORDER_CODE);
        productionOrderBatchInfoParam.setLocationCode(LOCATION_CODE);
        List<ProductionOrderBatchInfoResult> list = productionOrderBatchInfoService.findListBySpec(productionOrderBatchInfoParam);
        for(int i=0;i<list.size();i++){
            ProductionOrderBatchInfoResult productionOrderBatchInfoResult = list.get(i);
            int remainingQuantity =  productionOrderBatchInfoResult.getResidueQuantity();//剩余数量
            if(remainingQuantity>0 ){
                //新增物料追溯
                MaterialTraceabilityParam materialTraceabilityParam = new MaterialTraceabilityParam();
                materialTraceabilityParam.setWorkOrderNo(S_ORDER_CODE);
                materialTraceabilityParam.setProductCode(S_PRODUCT_CODE);
                materialTraceabilityParam.setProductNo(S_SFC_CODE);
                materialTraceabilityParam.setLineCode(PRODUCTION_LINE);
                materialTraceabilityParam.setLocationCode(LOCATION_CODE);
                materialTraceabilityParam.setAssemblyQty(1);
                materialTraceabilityParam.setAssemblyTime(DateTool.getLocalTimeForDate());
                materialTraceabilityParam.setMaterialCode(productionOrderBatchInfoResult.getMaterialCode());//物料编码
                materialTraceabilityParam.setMaterialBatchNo(productionOrderBatchInfoResult.getBatch());//物料批次
                materialTraceabilityService.add(materialTraceabilityParam);
                //更新剩余数量
                productionOrderBatchInfoParam.setId(productionOrderBatchInfoResult.getId());
                productionOrderBatchInfoParam.setResidueQuantity(remainingQuantity-1);//剩余数量
                productionOrderBatchInfoService.update(productionOrderBatchInfoParam);
            }
        }
    }
    //PC读参数信息
    public void handleInfo() throws Exception {
        logger.info("handleInfo START!");
        if(null == list){
            CollectionParamConfParam collectionParamConfParam = new CollectionParamConfParam();
            collectionParamConfParam.setLocationCode(LOCATION_CODE);
            list = collectionParamConfService.findListBySpec(collectionParamConfParam);
        }
        if(null != list && !list.isEmpty()) {
            for (int i = 0; i < list.size(); i++) {
                CollectionParamConfResult result = (CollectionParamConfResult) list.get(i);
                String value = miloService.
                        readFromOpcUa(result.getGatherAddress())
                        .getValue().toString();//读参数值
                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);
                paramCollectionParam.setParamLower(result.getParamLower());
                paramCollectionParam.setParamUpper(result.getParamUpper());
                paramCollectionParam.setParamStandard(result.getParamCentral());
                paramCollectionParam.setCollectionTime(DateTool.getLocalTimeForDate());
                paramCollectionParam.setUnit(result.getUnit());
                paramCollectionService.add(paramCollectionParam);
            }
        }
        logger.info("handleInfo END!");
    }
}
guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/OP120Callback.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,298 @@
package cn.stylefeng.guns.plcserver.callback;
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.model.params.ParamCollectionParam;
import cn.stylefeng.guns.modular.cm.paramCollection.service.ParamCollectionService;
import cn.stylefeng.guns.modular.cm.passingStationCollection.model.params.PassingStationCollectionParam;
import cn.stylefeng.guns.modular.cm.passingStationCollection.service.PassingStationCollectionService;
import cn.stylefeng.guns.modular.dq.materialTraceability.model.params.MaterialTraceabilityParam;
import cn.stylefeng.guns.modular.dq.materialTraceability.service.MaterialTraceabilityService;
import cn.stylefeng.guns.modular.em.equipmentAlarm.service.EquipmentAlarmService;
import cn.stylefeng.guns.modular.em.equipmentStatus.service.EquipmentStatusService;
import cn.stylefeng.guns.modular.gm.greaseManage.service.GreaseManageService;
import cn.stylefeng.guns.modular.om.productionOrdeInfo.service.ProductionOrdeInfoService;
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.model.params.ProductionOrderBatchInfoParam;
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.model.result.ProductionOrderBatchInfoResult;
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.service.ProductionOrderBatchInfoService;
import cn.stylefeng.guns.modular.om.productionOrderRecords.model.params.ProductionOrderRecordsParam;
import cn.stylefeng.guns.modular.om.productionOrderRecords.model.result.ProductionOrderRecordsResult;
import cn.stylefeng.guns.modular.om.productionOrderRecords.service.ProductionOrderRecordsService;
import cn.stylefeng.guns.modular.sc.repairManageInfo.service.RepairManageInfoService;
import cn.stylefeng.guns.modular.sc.serialNumbersConf.service.SerialNumbersConfService;
import cn.stylefeng.guns.plcserver.opc.GlobalVariable;
import cn.stylefeng.guns.plcserver.opc.OPCElement;
import cn.stylefeng.guns.plcserver.tool.DateTool;
import cn.stylefeng.guns.plcserver.tool.LogUtil;
import com.kangaroohy.milo.model.ReadWriteEntity;
import com.kangaroohy.milo.runner.subscription.SubscriptionCallback;
import com.kangaroohy.milo.service.MiloService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@Component
public class OP120Callback implements SubscriptionCallback {
    public MiloService miloService;
    @Autowired
    public ProductionOrdeInfoService productionOrdeInfoService;
    @Autowired
    public PassingStationCollectionService passingStationCollectionService;
    @Autowired
    public ParamCollectionService paramCollectionService;
    @Autowired
    public CollectionParamConfService collectionParamConfService;
    @Autowired
    public SerialNumbersConfService serialNumbersConfService;
    @Autowired
    private EquipmentStatusService equipmentStatusService;
    @Autowired
    private EquipmentAlarmService equipmentAlarmService;
    @Autowired
    private MaterialTraceabilityService materialTraceabilityService;
    @Autowired
    private EquipmentInfoService equipmentInfoService;
    @Autowired
    private RepairManageInfoService repairManageInfoService;
    @Autowired
    private LocationInfoService locationInfoService;
    @Autowired
    private GreaseManageService greaseManageService;
    @Autowired
    private ProductionOrderRecordsService productionOrderRecordsService;
    @Autowired
    private ProductionOrderBatchInfoService productionOrderBatchInfoService;
    private static Logger logger;
    LogUtil logUtil = new LogUtil();
    static {
        logger = Logger.getLogger(OP120Callback.class);
    }
    private static Date IN_TIME = null;
    private static String S_ORDER_CODE = "";//工单编号
    private static String S_PRODUCT_CODE = "";//产品编号
    private static String S_PRODUCT_TYPE= "";//产品类型
    private static String S_SFC_CODE = "";//总成编码
    private static String PRODUCTION_LINE  = "OP";//产线号
    private static String LOCATION_CODE  = "OP120";//工位号
    private static List list = null;
    public OP120Callback(MiloService miloService,
                         ProductionOrdeInfoService productionOrdeInfoService,
                         PassingStationCollectionService passingStationCollectionService,
                         ParamCollectionService paramCollectionService,
                         CollectionParamConfService collectionParamConfService,
                         SerialNumbersConfService serialNumbersConfService,
                         EquipmentStatusService equipmentStatusService,
                         EquipmentAlarmService equipmentAlarmService,
                         MaterialTraceabilityService materialTraceabilityService,
                         EquipmentInfoService equipmentInfoService,
                         RepairManageInfoService repairManageInfoService,
                         LocationInfoService locationInfoService,
                         GreaseManageService greaseManageService,
                         ProductionOrderRecordsService productionOrderRecordsService,
                         ProductionOrderBatchInfoService productionOrderBatchInfoService) {
        this.miloService = miloService;
        this.productionOrdeInfoService = productionOrdeInfoService;
        this.passingStationCollectionService = passingStationCollectionService;
        this.paramCollectionService = paramCollectionService;
        this.collectionParamConfService = collectionParamConfService;
        this.serialNumbersConfService = serialNumbersConfService;
        this.equipmentStatusService = equipmentStatusService;
        this.equipmentAlarmService = equipmentAlarmService;
        this.materialTraceabilityService = materialTraceabilityService;
        this.equipmentInfoService = equipmentInfoService;
        this.repairManageInfoService = repairManageInfoService;
        this.locationInfoService = locationInfoService;
        this.greaseManageService = greaseManageService;
        this.productionOrderRecordsService = productionOrderRecordsService;
        this.productionOrderBatchInfoService = productionOrderBatchInfoService;
    }
    @Override
    public void onSubscribe(String identifier, Object value) {
        String ecpStr = "";//异常记录标记
        try {
            //心跳
            if(null != value && identifier.equals(OPCElement.OP120_F_HEART_BEAT)){
                if( "false".equals(value.toString()))
                {
                    ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP120_F_HEART_BEAT,true);
                    miloService.writeToOpcUa(entity);
                }
            }
            //PLC进站
            else if(null != value && identifier.equals(OPCElement.OP120_J_PLC_START)){
                if("true".equals(value.toString())){
                    handleOrder();
                }
            }
            //PLC出站
            else if(null != value && identifier.equals(OPCElement.OP120_J_PLC_FINISH)){
                if("true".equals(value.toString())){
                    handleFinsh();
                    handleInfo();
                    handleMaterial();
                }
            }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 {
        logger.info("handleOrder PC处理开始!");
        IN_TIME = DateTool.getLocalTimeForDate();
        List<String> lists = new ArrayList<>();
        lists.add(OPCElement.OP120_S_ORDER_CODE);
        lists.add(OPCElement.OP120_S_PRODUCT_CODE);
        lists.add(OPCElement.OP120_S_SFC_CODE);
        List<ReadWriteEntity> returnLists= miloService.readFromOpcUa(lists);
        returnLists.forEach(element->{
            switch(element.getIdentifier()){
                case OPCElement.OP120_S_ORDER_CODE:
                    S_ORDER_CODE = element.getValue().toString();
                    break;
                case OPCElement.OP120_S_PRODUCT_CODE:
                    S_PRODUCT_TYPE = element.getValue().toString();
                    S_PRODUCT_CODE = GlobalVariable.PRODUCT_CODE_MAP.get(S_PRODUCT_TYPE);
                    break;
                case OPCElement.OP120_S_SFC_CODE:
                    S_SFC_CODE = element.getValue().toString();
                    break;
                default:
                    break;
            }
        });
        ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP120_J_PC_WRITE_ORDER,true);
        miloService.writeToOpcUa(entity);
        logger.info("handleOrder PC处理完成!");
    }
    public void handleFinsh() throws Exception {
        logger.info("handleFinsh PC处理开始!");
        String S_PRODUCT_STATE_CODE = miloService.
                readFromOpcUa(OPCElement.OP120_S_PRODUCT_STATE_CODE)
                .getValue().toString();
        if("2".equals(S_PRODUCT_STATE_CODE)){
            ProductionOrderRecordsParam productionOrderRecordsParam = new ProductionOrderRecordsParam();
            productionOrderRecordsParam.setWorkOrderNo(S_ORDER_CODE);
            productionOrderRecordsParam.setProductNo(S_SFC_CODE);
            List<ProductionOrderRecordsResult> list = productionOrderRecordsService.findListBySpec(productionOrderRecordsParam);
            if(!list.isEmpty()){
                ProductionOrderRecordsResult productionOrderRecordsResult = list.get(0);
                productionOrderRecordsParam.setId(productionOrderRecordsResult.getId());
                productionOrderRecordsParam.setWhetherPass(S_PRODUCT_STATE_CODE);
                productionOrderRecordsService.update(productionOrderRecordsParam);
            }
        }
        //处理过站信息
        PassingStationCollectionParam param = new PassingStationCollectionParam();
        param.setWorkOrderNo(S_ORDER_CODE);
        param.setProductCode(S_PRODUCT_CODE);
        param.setSfcCode(S_SFC_CODE);
        param.setProductionLine(PRODUCTION_LINE);
        param.setLocationCode(LOCATION_CODE);
        param.setInboundTime(IN_TIME);
        param.setOutboundTime(DateTool.getLocalTimeForDate());
        param.setOutRsSign(S_PRODUCT_STATE_CODE);//出站是否合格
        passingStationCollectionService.add(param);
        ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP120_J_PC_FINISH,true);
        miloService.writeToOpcUa(entity);//写PC完成
        logger.info("handleFinsh PC处理完成!");
    }
    public void handleMaterial() {
        //查询批次上料信息
        ProductionOrderBatchInfoParam productionOrderBatchInfoParam = new ProductionOrderBatchInfoParam();
        productionOrderBatchInfoParam.setWorkOrderNo(S_ORDER_CODE);
        productionOrderBatchInfoParam.setLocationCode(LOCATION_CODE);
        List<ProductionOrderBatchInfoResult> list = productionOrderBatchInfoService.findListBySpec(productionOrderBatchInfoParam);
        for(int i=0;i<list.size();i++){
            ProductionOrderBatchInfoResult productionOrderBatchInfoResult = list.get(i);
            int remainingQuantity =  productionOrderBatchInfoResult.getResidueQuantity();//剩余数量
            if(remainingQuantity>0 ){
                //新增物料追溯
                MaterialTraceabilityParam materialTraceabilityParam = new MaterialTraceabilityParam();
                materialTraceabilityParam.setWorkOrderNo(S_ORDER_CODE);
                materialTraceabilityParam.setProductCode(S_PRODUCT_CODE);
                materialTraceabilityParam.setProductNo(S_SFC_CODE);
                materialTraceabilityParam.setLineCode(PRODUCTION_LINE);
                materialTraceabilityParam.setLocationCode(LOCATION_CODE);
                materialTraceabilityParam.setAssemblyQty(1);
                materialTraceabilityParam.setAssemblyTime(DateTool.getLocalTimeForDate());
                materialTraceabilityParam.setMaterialCode(productionOrderBatchInfoResult.getMaterialCode());//物料编码
                materialTraceabilityParam.setMaterialBatchNo(productionOrderBatchInfoResult.getBatch());//物料批次
                materialTraceabilityService.add(materialTraceabilityParam);
                //更新剩余数量
                productionOrderBatchInfoParam.setId(productionOrderBatchInfoResult.getId());
                productionOrderBatchInfoParam.setResidueQuantity(remainingQuantity-1);//剩余数量
                productionOrderBatchInfoService.update(productionOrderBatchInfoParam);
            }
        }
    }
    //PC读参数信息
    public void handleInfo() throws Exception {
        logger.info("handleInfo START!");
        if(null == list){
            CollectionParamConfParam collectionParamConfParam = new CollectionParamConfParam();
            collectionParamConfParam.setLocationCode(LOCATION_CODE);
            list = collectionParamConfService.findListBySpec(collectionParamConfParam);
        }
        if(null != list && !list.isEmpty()) {
            for (int i = 0; i < list.size(); i++) {
                CollectionParamConfResult result = (CollectionParamConfResult) list.get(i);
                String value = miloService.
                        readFromOpcUa(result.getGatherAddress())
                        .getValue().toString();//读参数值
                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);
                paramCollectionParam.setParamLower(result.getParamLower());
                paramCollectionParam.setParamUpper(result.getParamUpper());
                paramCollectionParam.setParamStandard(result.getParamCentral());
                paramCollectionParam.setCollectionTime(DateTool.getLocalTimeForDate());
                paramCollectionParam.setUnit(result.getUnit());
                paramCollectionService.add(paramCollectionParam);
            }
        }
        logger.info("handleInfo END!");
    }
}
guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/OP130BCallback.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,297 @@
package cn.stylefeng.guns.plcserver.callback;
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.model.params.ParamCollectionParam;
import cn.stylefeng.guns.modular.cm.paramCollection.service.ParamCollectionService;
import cn.stylefeng.guns.modular.cm.passingStationCollection.model.params.PassingStationCollectionParam;
import cn.stylefeng.guns.modular.cm.passingStationCollection.service.PassingStationCollectionService;
import cn.stylefeng.guns.modular.dq.materialTraceability.model.params.MaterialTraceabilityParam;
import cn.stylefeng.guns.modular.dq.materialTraceability.service.MaterialTraceabilityService;
import cn.stylefeng.guns.modular.em.equipmentAlarm.service.EquipmentAlarmService;
import cn.stylefeng.guns.modular.em.equipmentStatus.service.EquipmentStatusService;
import cn.stylefeng.guns.modular.gm.greaseManage.service.GreaseManageService;
import cn.stylefeng.guns.modular.om.productionOrdeInfo.service.ProductionOrdeInfoService;
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.model.params.ProductionOrderBatchInfoParam;
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.model.result.ProductionOrderBatchInfoResult;
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.service.ProductionOrderBatchInfoService;
import cn.stylefeng.guns.modular.om.productionOrderRecords.model.params.ProductionOrderRecordsParam;
import cn.stylefeng.guns.modular.om.productionOrderRecords.model.result.ProductionOrderRecordsResult;
import cn.stylefeng.guns.modular.om.productionOrderRecords.service.ProductionOrderRecordsService;
import cn.stylefeng.guns.modular.sc.repairManageInfo.service.RepairManageInfoService;
import cn.stylefeng.guns.modular.sc.serialNumbersConf.service.SerialNumbersConfService;
import cn.stylefeng.guns.plcserver.opc.GlobalVariable;
import cn.stylefeng.guns.plcserver.opc.OPCElement;
import cn.stylefeng.guns.plcserver.tool.DateTool;
import cn.stylefeng.guns.plcserver.tool.LogUtil;
import com.kangaroohy.milo.model.ReadWriteEntity;
import com.kangaroohy.milo.runner.subscription.SubscriptionCallback;
import com.kangaroohy.milo.service.MiloService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@Component
public class OP130BCallback implements SubscriptionCallback {
    public MiloService miloService;
    @Autowired
    public ProductionOrdeInfoService productionOrdeInfoService;
    @Autowired
    public PassingStationCollectionService passingStationCollectionService;
    @Autowired
    public ParamCollectionService paramCollectionService;
    @Autowired
    public CollectionParamConfService collectionParamConfService;
    @Autowired
    public SerialNumbersConfService serialNumbersConfService;
    @Autowired
    private EquipmentStatusService equipmentStatusService;
    @Autowired
    private EquipmentAlarmService equipmentAlarmService;
    @Autowired
    private MaterialTraceabilityService materialTraceabilityService;
    @Autowired
    private EquipmentInfoService equipmentInfoService;
    @Autowired
    private RepairManageInfoService repairManageInfoService;
    @Autowired
    private LocationInfoService locationInfoService;
    @Autowired
    private GreaseManageService greaseManageService;
    @Autowired
    private ProductionOrderRecordsService productionOrderRecordsService;
    @Autowired
    private ProductionOrderBatchInfoService productionOrderBatchInfoService;
    private static Logger logger;
    LogUtil logUtil = new LogUtil();
    static {
        logger = Logger.getLogger(OP130BCallback.class);
    }
    private static Date IN_TIME = null;
    private static String S_ORDER_CODE = "";//工单编号
    private static String S_PRODUCT_CODE = "";//产品编号
    private static String S_PRODUCT_TYPE= "";//产品类型
    private static String S_SFC_CODE = "";//总成编码
    private static String PRODUCTION_LINE  = "OP";//产线号
    private static String LOCATION_CODE  = "OP130B";//工位号
    private static List list = null;
    public OP130BCallback(MiloService miloService,
                          ProductionOrdeInfoService productionOrdeInfoService,
                          PassingStationCollectionService passingStationCollectionService,
                          ParamCollectionService paramCollectionService,
                          CollectionParamConfService collectionParamConfService,
                          SerialNumbersConfService serialNumbersConfService,
                          EquipmentStatusService equipmentStatusService,
                          EquipmentAlarmService equipmentAlarmService,
                          MaterialTraceabilityService materialTraceabilityService,
                          EquipmentInfoService equipmentInfoService,
                          RepairManageInfoService repairManageInfoService,
                          LocationInfoService locationInfoService,
                          GreaseManageService greaseManageService,
                          ProductionOrderRecordsService productionOrderRecordsService,
                          ProductionOrderBatchInfoService productionOrderBatchInfoService) {
        this.miloService = miloService;
        this.productionOrdeInfoService = productionOrdeInfoService;
        this.passingStationCollectionService = passingStationCollectionService;
        this.paramCollectionService = paramCollectionService;
        this.collectionParamConfService = collectionParamConfService;
        this.serialNumbersConfService = serialNumbersConfService;
        this.equipmentStatusService = equipmentStatusService;
        this.equipmentAlarmService = equipmentAlarmService;
        this.materialTraceabilityService = materialTraceabilityService;
        this.equipmentInfoService = equipmentInfoService;
        this.repairManageInfoService = repairManageInfoService;
        this.locationInfoService = locationInfoService;
        this.greaseManageService = greaseManageService;
        this.productionOrderRecordsService = productionOrderRecordsService;
        this.productionOrderBatchInfoService = productionOrderBatchInfoService;
    }
    @Override
    public void onSubscribe(String identifier, Object value) {
        String ecpStr = "";//异常记录标记
        try {
            //心跳
            if(null != value && identifier.equals(OPCElement.OP130B_F_HEART_BEAT)){
                if( "false".equals(value.toString()))
                {
                    ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP130B_F_HEART_BEAT,true);
                    miloService.writeToOpcUa(entity);
                }
            }
            //PLC进站
            else if(null != value && identifier.equals(OPCElement.OP130B_J_PLC_START)){
                if("true".equals(value.toString())){
                    handleOrder();
                }
            }
            //PLC出站
            else if(null != value && identifier.equals(OPCElement.OP130B_J_PLC_FINISH)){
                if("true".equals(value.toString())){
                    handleFinsh();
                    handleInfo();
                    handleMaterial();
                }
            }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 {
        logger.info("handleOrder PC处理开始!");
        IN_TIME = DateTool.getLocalTimeForDate();
        List<String> lists = new ArrayList<>();
        lists.add(OPCElement.OP130B_S_ORDER_CODE);
        lists.add(OPCElement.OP130B_S_PRODUCT_CODE);
        lists.add(OPCElement.OP130B_S_SFC_CODE);
        List<ReadWriteEntity> returnLists= miloService.readFromOpcUa(lists);
        returnLists.forEach(element->{
            switch(element.getIdentifier()){
                case OPCElement.OP130B_S_ORDER_CODE:
                    S_ORDER_CODE = element.getValue().toString();
                    break;
                case OPCElement.OP130B_S_PRODUCT_CODE:
                    S_PRODUCT_TYPE = element.getValue().toString();
                    S_PRODUCT_CODE = GlobalVariable.PRODUCT_CODE_MAP.get(S_PRODUCT_TYPE);
                    break;
                case OPCElement.OP130B_S_SFC_CODE:
                    S_SFC_CODE = element.getValue().toString();
                    break;
                default:
                    break;
            }
        });
        ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP130B_J_PC_WRITE_ORDER,true);
        miloService.writeToOpcUa(entity);
        logger.info("handleOrder PC处理完成!");
    }
    public void handleFinsh() throws Exception {
        logger.info("handleFinsh PC处理开始!");
        String S_PRODUCT_STATE_CODE = miloService.
                readFromOpcUa(OPCElement.OP130B_S_PRODUCT_STATE_CODE)
                .getValue().toString();
        if("2".equals(S_PRODUCT_STATE_CODE)){
            ProductionOrderRecordsParam productionOrderRecordsParam = new ProductionOrderRecordsParam();
            productionOrderRecordsParam.setWorkOrderNo(S_ORDER_CODE);
            productionOrderRecordsParam.setProductNo(S_SFC_CODE);
            List<ProductionOrderRecordsResult> list = productionOrderRecordsService.findListBySpec(productionOrderRecordsParam);
            if(!list.isEmpty()){
                ProductionOrderRecordsResult productionOrderRecordsResult = list.get(0);
                productionOrderRecordsParam.setId(productionOrderRecordsResult.getId());
                productionOrderRecordsParam.setWhetherPass(S_PRODUCT_STATE_CODE);
                productionOrderRecordsService.update(productionOrderRecordsParam);
            }
        }
        //处理过站信息
        PassingStationCollectionParam param = new PassingStationCollectionParam();
        param.setWorkOrderNo(S_ORDER_CODE);
        param.setProductCode(S_PRODUCT_CODE);
        param.setSfcCode(S_SFC_CODE);
        param.setProductionLine(PRODUCTION_LINE);
        param.setLocationCode(LOCATION_CODE);
        param.setInboundTime(IN_TIME);
        param.setOutboundTime(DateTool.getLocalTimeForDate());
        param.setOutRsSign(S_PRODUCT_STATE_CODE);//出站是否合格
        passingStationCollectionService.add(param);
        ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP130B_J_PC_FINISH,true);
        miloService.writeToOpcUa(entity);//写PC完成
        logger.info("handleFinsh PC处理完成!");
    }
    public void handleMaterial() {
        //查询批次上料信息
        ProductionOrderBatchInfoParam productionOrderBatchInfoParam = new ProductionOrderBatchInfoParam();
        productionOrderBatchInfoParam.setWorkOrderNo(S_ORDER_CODE);
        productionOrderBatchInfoParam.setLocationCode(LOCATION_CODE);
        List<ProductionOrderBatchInfoResult> list = productionOrderBatchInfoService.findListBySpec(productionOrderBatchInfoParam);
        for(int i=0;i<list.size();i++){
            ProductionOrderBatchInfoResult productionOrderBatchInfoResult = list.get(i);
            int remainingQuantity =  productionOrderBatchInfoResult.getResidueQuantity();//剩余数量
            if(remainingQuantity>0 ){
                //新增物料追溯
                MaterialTraceabilityParam materialTraceabilityParam = new MaterialTraceabilityParam();
                materialTraceabilityParam.setWorkOrderNo(S_ORDER_CODE);
                materialTraceabilityParam.setProductCode(S_PRODUCT_CODE);
                materialTraceabilityParam.setProductNo(S_SFC_CODE);
                materialTraceabilityParam.setLineCode(PRODUCTION_LINE);
                materialTraceabilityParam.setLocationCode(LOCATION_CODE);
                materialTraceabilityParam.setAssemblyQty(1);
                materialTraceabilityParam.setAssemblyTime(DateTool.getLocalTimeForDate());
                materialTraceabilityParam.setMaterialCode(productionOrderBatchInfoResult.getMaterialCode());//物料编码
                materialTraceabilityParam.setMaterialBatchNo(productionOrderBatchInfoResult.getBatch());//物料批次
                materialTraceabilityService.add(materialTraceabilityParam);
                //更新剩余数量
                productionOrderBatchInfoParam.setId(productionOrderBatchInfoResult.getId());
                productionOrderBatchInfoParam.setResidueQuantity(remainingQuantity-1);//剩余数量
                productionOrderBatchInfoService.update(productionOrderBatchInfoParam);
            }
        }
    }
    //PC读参数信息
    public void handleInfo() throws Exception {
        logger.info("handleInfo START!");
        if(null == list){
            CollectionParamConfParam collectionParamConfParam = new CollectionParamConfParam();
            collectionParamConfParam.setLocationCode(LOCATION_CODE);
            list = collectionParamConfService.findListBySpec(collectionParamConfParam);
        }
        if(null != list && !list.isEmpty()) {
            for (int i = 0; i < list.size(); i++) {
                CollectionParamConfResult result = (CollectionParamConfResult) list.get(i);
                String value = miloService.
                        readFromOpcUa(result.getGatherAddress())
                        .getValue().toString();//读参数值
                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);
                paramCollectionParam.setParamLower(result.getParamLower());
                paramCollectionParam.setParamUpper(result.getParamUpper());
                paramCollectionParam.setParamStandard(result.getParamCentral());
                paramCollectionParam.setCollectionTime(DateTool.getLocalTimeForDate());
                paramCollectionParam.setUnit(result.getUnit());
                paramCollectionService.add(paramCollectionParam);
            }
        }
        logger.info("handleInfo END!");
    }
}
guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/OP130Callback.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,298 @@
package cn.stylefeng.guns.plcserver.callback;
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.model.params.ParamCollectionParam;
import cn.stylefeng.guns.modular.cm.paramCollection.service.ParamCollectionService;
import cn.stylefeng.guns.modular.cm.passingStationCollection.model.params.PassingStationCollectionParam;
import cn.stylefeng.guns.modular.cm.passingStationCollection.service.PassingStationCollectionService;
import cn.stylefeng.guns.modular.dq.materialTraceability.model.params.MaterialTraceabilityParam;
import cn.stylefeng.guns.modular.dq.materialTraceability.service.MaterialTraceabilityService;
import cn.stylefeng.guns.modular.em.equipmentAlarm.service.EquipmentAlarmService;
import cn.stylefeng.guns.modular.em.equipmentStatus.service.EquipmentStatusService;
import cn.stylefeng.guns.modular.gm.greaseManage.service.GreaseManageService;
import cn.stylefeng.guns.modular.om.productionOrdeInfo.service.ProductionOrdeInfoService;
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.model.params.ProductionOrderBatchInfoParam;
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.model.result.ProductionOrderBatchInfoResult;
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.service.ProductionOrderBatchInfoService;
import cn.stylefeng.guns.modular.om.productionOrderRecords.model.params.ProductionOrderRecordsParam;
import cn.stylefeng.guns.modular.om.productionOrderRecords.model.result.ProductionOrderRecordsResult;
import cn.stylefeng.guns.modular.om.productionOrderRecords.service.ProductionOrderRecordsService;
import cn.stylefeng.guns.modular.sc.repairManageInfo.service.RepairManageInfoService;
import cn.stylefeng.guns.modular.sc.serialNumbersConf.service.SerialNumbersConfService;
import cn.stylefeng.guns.plcserver.opc.GlobalVariable;
import cn.stylefeng.guns.plcserver.opc.OPCElement;
import cn.stylefeng.guns.plcserver.tool.DateTool;
import cn.stylefeng.guns.plcserver.tool.LogUtil;
import com.kangaroohy.milo.model.ReadWriteEntity;
import com.kangaroohy.milo.runner.subscription.SubscriptionCallback;
import com.kangaroohy.milo.service.MiloService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@Component
public class OP130Callback implements SubscriptionCallback {
    public MiloService miloService;
    @Autowired
    public ProductionOrdeInfoService productionOrdeInfoService;
    @Autowired
    public PassingStationCollectionService passingStationCollectionService;
    @Autowired
    public ParamCollectionService paramCollectionService;
    @Autowired
    public CollectionParamConfService collectionParamConfService;
    @Autowired
    public SerialNumbersConfService serialNumbersConfService;
    @Autowired
    private EquipmentStatusService equipmentStatusService;
    @Autowired
    private EquipmentAlarmService equipmentAlarmService;
    @Autowired
    private MaterialTraceabilityService materialTraceabilityService;
    @Autowired
    private EquipmentInfoService equipmentInfoService;
    @Autowired
    private RepairManageInfoService repairManageInfoService;
    @Autowired
    private LocationInfoService locationInfoService;
    @Autowired
    private GreaseManageService greaseManageService;
    @Autowired
    private ProductionOrderRecordsService productionOrderRecordsService;
    @Autowired
    private ProductionOrderBatchInfoService productionOrderBatchInfoService;
    private static Logger logger;
    LogUtil logUtil = new LogUtil();
    static {
        logger = Logger.getLogger(OP130Callback.class);
    }
    private static Date IN_TIME = null;
    private static String S_ORDER_CODE = "";//工单编号
    private static String S_PRODUCT_CODE = "";//产品编号
    private static String S_PRODUCT_TYPE= "";//产品类型
    private static String S_SFC_CODE = "";//总成编码
    private static String PRODUCTION_LINE  = "OP";//产线号
    private static String LOCATION_CODE  = "OP130";//工位号
    private static List list = null;
    public OP130Callback(MiloService miloService,
                         ProductionOrdeInfoService productionOrdeInfoService,
                         PassingStationCollectionService passingStationCollectionService,
                         ParamCollectionService paramCollectionService,
                         CollectionParamConfService collectionParamConfService,
                         SerialNumbersConfService serialNumbersConfService,
                         EquipmentStatusService equipmentStatusService,
                         EquipmentAlarmService equipmentAlarmService,
                         MaterialTraceabilityService materialTraceabilityService,
                         EquipmentInfoService equipmentInfoService,
                         RepairManageInfoService repairManageInfoService,
                         LocationInfoService locationInfoService,
                         GreaseManageService greaseManageService,
                         ProductionOrderRecordsService productionOrderRecordsService,
                         ProductionOrderBatchInfoService productionOrderBatchInfoService) {
        this.miloService = miloService;
        this.productionOrdeInfoService = productionOrdeInfoService;
        this.passingStationCollectionService = passingStationCollectionService;
        this.paramCollectionService = paramCollectionService;
        this.collectionParamConfService = collectionParamConfService;
        this.serialNumbersConfService = serialNumbersConfService;
        this.equipmentStatusService = equipmentStatusService;
        this.equipmentAlarmService = equipmentAlarmService;
        this.materialTraceabilityService = materialTraceabilityService;
        this.equipmentInfoService = equipmentInfoService;
        this.repairManageInfoService = repairManageInfoService;
        this.locationInfoService = locationInfoService;
        this.greaseManageService = greaseManageService;
        this.productionOrderRecordsService = productionOrderRecordsService;
        this.productionOrderBatchInfoService = productionOrderBatchInfoService;
    }
    @Override
    public void onSubscribe(String identifier, Object value) {
        String ecpStr = "";//异常记录标记
        try {
            //心跳
            if(null != value && identifier.equals(OPCElement.OP130_F_HEART_BEAT)){
                if( "false".equals(value.toString()))
                {
                    ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP130_F_HEART_BEAT,true);
                    miloService.writeToOpcUa(entity);
                }
            }
            //PLC进站
            else if(null != value && identifier.equals(OPCElement.OP130_J_PLC_START)){
                if("true".equals(value.toString())){
                    handleOrder();
                }
            }
            //PLC出站
            else if(null != value && identifier.equals(OPCElement.OP130_J_PLC_FINISH)){
                if("true".equals(value.toString())){
                    handleFinsh();
                    handleInfo();
                    handleMaterial();
                }
            }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 {
        logger.info("handleOrder PC处理开始!");
        IN_TIME = DateTool.getLocalTimeForDate();
        List<String> lists = new ArrayList<>();
        lists.add(OPCElement.OP130_S_ORDER_CODE);
        lists.add(OPCElement.OP130_S_PRODUCT_CODE);
        lists.add(OPCElement.OP130_S_SFC_CODE);
        List<ReadWriteEntity> returnLists= miloService.readFromOpcUa(lists);
        returnLists.forEach(element->{
            switch(element.getIdentifier()){
                case OPCElement.OP130_S_ORDER_CODE:
                    S_ORDER_CODE = element.getValue().toString();
                    break;
                case OPCElement.OP130_S_PRODUCT_CODE:
                    S_PRODUCT_TYPE = element.getValue().toString();
                    S_PRODUCT_CODE = GlobalVariable.PRODUCT_CODE_MAP.get(S_PRODUCT_TYPE);
                    break;
                case OPCElement.OP130_S_SFC_CODE:
                    S_SFC_CODE = element.getValue().toString();
                    break;
                default:
                    break;
            }
        });
        ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP130_J_PC_WRITE_ORDER,true);
        miloService.writeToOpcUa(entity);
        logger.info("handleOrder PC处理完成!");
    }
    public void handleFinsh() throws Exception {
        logger.info("handleFinsh PC处理开始!");
        String S_PRODUCT_STATE_CODE = miloService.
                readFromOpcUa(OPCElement.OP130_S_PRODUCT_STATE_CODE)
                .getValue().toString();
        if("2".equals(S_PRODUCT_STATE_CODE)){
            ProductionOrderRecordsParam productionOrderRecordsParam = new ProductionOrderRecordsParam();
            productionOrderRecordsParam.setWorkOrderNo(S_ORDER_CODE);
            productionOrderRecordsParam.setProductNo(S_SFC_CODE);
            List<ProductionOrderRecordsResult> list = productionOrderRecordsService.findListBySpec(productionOrderRecordsParam);
            if(!list.isEmpty()){
                ProductionOrderRecordsResult productionOrderRecordsResult = list.get(0);
                productionOrderRecordsParam.setId(productionOrderRecordsResult.getId());
                productionOrderRecordsParam.setWhetherPass(S_PRODUCT_STATE_CODE);
                productionOrderRecordsService.update(productionOrderRecordsParam);
            }
        }
        //处理过站信息
        PassingStationCollectionParam param = new PassingStationCollectionParam();
        param.setWorkOrderNo(S_ORDER_CODE);
        param.setProductCode(S_PRODUCT_CODE);
        param.setSfcCode(S_SFC_CODE);
        param.setProductionLine(PRODUCTION_LINE);
        param.setLocationCode(LOCATION_CODE);
        param.setInboundTime(IN_TIME);
        param.setOutboundTime(DateTool.getLocalTimeForDate());
        param.setOutRsSign(S_PRODUCT_STATE_CODE);//出站是否合格
        passingStationCollectionService.add(param);
        ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP130_J_PC_FINISH,true);
        miloService.writeToOpcUa(entity);//写PC完成
        logger.info("handleFinsh PC处理完成!");
    }
    public void handleMaterial() {
        //查询批次上料信息
        ProductionOrderBatchInfoParam productionOrderBatchInfoParam = new ProductionOrderBatchInfoParam();
        productionOrderBatchInfoParam.setWorkOrderNo(S_ORDER_CODE);
        productionOrderBatchInfoParam.setLocationCode(LOCATION_CODE);
        List<ProductionOrderBatchInfoResult> list = productionOrderBatchInfoService.findListBySpec(productionOrderBatchInfoParam);
        for(int i=0;i<list.size();i++){
            ProductionOrderBatchInfoResult productionOrderBatchInfoResult = list.get(i);
            int remainingQuantity =  productionOrderBatchInfoResult.getResidueQuantity();//剩余数量
            if(remainingQuantity>0 ){
                //新增物料追溯
                MaterialTraceabilityParam materialTraceabilityParam = new MaterialTraceabilityParam();
                materialTraceabilityParam.setWorkOrderNo(S_ORDER_CODE);
                materialTraceabilityParam.setProductCode(S_PRODUCT_CODE);
                materialTraceabilityParam.setProductNo(S_SFC_CODE);
                materialTraceabilityParam.setLineCode(PRODUCTION_LINE);
                materialTraceabilityParam.setLocationCode(LOCATION_CODE);
                materialTraceabilityParam.setAssemblyQty(1);
                materialTraceabilityParam.setAssemblyTime(DateTool.getLocalTimeForDate());
                materialTraceabilityParam.setMaterialCode(productionOrderBatchInfoResult.getMaterialCode());//物料编码
                materialTraceabilityParam.setMaterialBatchNo(productionOrderBatchInfoResult.getBatch());//物料批次
                materialTraceabilityService.add(materialTraceabilityParam);
                //更新剩余数量
                productionOrderBatchInfoParam.setId(productionOrderBatchInfoResult.getId());
                productionOrderBatchInfoParam.setResidueQuantity(remainingQuantity-1);//剩余数量
                productionOrderBatchInfoService.update(productionOrderBatchInfoParam);
            }
        }
    }
    //PC读参数信息
    public void handleInfo() throws Exception {
        logger.info("handleInfo START!");
        if(null == list){
            CollectionParamConfParam collectionParamConfParam = new CollectionParamConfParam();
            collectionParamConfParam.setLocationCode(LOCATION_CODE);
            list = collectionParamConfService.findListBySpec(collectionParamConfParam);
        }
        if(null != list && !list.isEmpty()) {
            for (int i = 0; i < list.size(); i++) {
                CollectionParamConfResult result = (CollectionParamConfResult) list.get(i);
                String value = miloService.
                        readFromOpcUa(result.getGatherAddress())
                        .getValue().toString();//读参数值
                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);
                paramCollectionParam.setParamLower(result.getParamLower());
                paramCollectionParam.setParamUpper(result.getParamUpper());
                paramCollectionParam.setParamStandard(result.getParamCentral());
                paramCollectionParam.setCollectionTime(DateTool.getLocalTimeForDate());
                paramCollectionParam.setUnit(result.getUnit());
                paramCollectionService.add(paramCollectionParam);
            }
        }
        logger.info("handleInfo END!");
    }
}
guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/OP140Callback.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,298 @@
package cn.stylefeng.guns.plcserver.callback;
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.model.params.ParamCollectionParam;
import cn.stylefeng.guns.modular.cm.paramCollection.service.ParamCollectionService;
import cn.stylefeng.guns.modular.cm.passingStationCollection.model.params.PassingStationCollectionParam;
import cn.stylefeng.guns.modular.cm.passingStationCollection.service.PassingStationCollectionService;
import cn.stylefeng.guns.modular.dq.materialTraceability.model.params.MaterialTraceabilityParam;
import cn.stylefeng.guns.modular.dq.materialTraceability.service.MaterialTraceabilityService;
import cn.stylefeng.guns.modular.em.equipmentAlarm.service.EquipmentAlarmService;
import cn.stylefeng.guns.modular.em.equipmentStatus.service.EquipmentStatusService;
import cn.stylefeng.guns.modular.gm.greaseManage.service.GreaseManageService;
import cn.stylefeng.guns.modular.om.productionOrdeInfo.service.ProductionOrdeInfoService;
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.model.params.ProductionOrderBatchInfoParam;
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.model.result.ProductionOrderBatchInfoResult;
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.service.ProductionOrderBatchInfoService;
import cn.stylefeng.guns.modular.om.productionOrderRecords.model.params.ProductionOrderRecordsParam;
import cn.stylefeng.guns.modular.om.productionOrderRecords.model.result.ProductionOrderRecordsResult;
import cn.stylefeng.guns.modular.om.productionOrderRecords.service.ProductionOrderRecordsService;
import cn.stylefeng.guns.modular.sc.repairManageInfo.service.RepairManageInfoService;
import cn.stylefeng.guns.modular.sc.serialNumbersConf.service.SerialNumbersConfService;
import cn.stylefeng.guns.plcserver.opc.GlobalVariable;
import cn.stylefeng.guns.plcserver.opc.OPCElement;
import cn.stylefeng.guns.plcserver.tool.DateTool;
import cn.stylefeng.guns.plcserver.tool.LogUtil;
import com.kangaroohy.milo.model.ReadWriteEntity;
import com.kangaroohy.milo.runner.subscription.SubscriptionCallback;
import com.kangaroohy.milo.service.MiloService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@Component
public class OP140Callback implements SubscriptionCallback {
    public MiloService miloService;
    @Autowired
    public ProductionOrdeInfoService productionOrdeInfoService;
    @Autowired
    public PassingStationCollectionService passingStationCollectionService;
    @Autowired
    public ParamCollectionService paramCollectionService;
    @Autowired
    public CollectionParamConfService collectionParamConfService;
    @Autowired
    public SerialNumbersConfService serialNumbersConfService;
    @Autowired
    private EquipmentStatusService equipmentStatusService;
    @Autowired
    private EquipmentAlarmService equipmentAlarmService;
    @Autowired
    private MaterialTraceabilityService materialTraceabilityService;
    @Autowired
    private EquipmentInfoService equipmentInfoService;
    @Autowired
    private RepairManageInfoService repairManageInfoService;
    @Autowired
    private LocationInfoService locationInfoService;
    @Autowired
    private GreaseManageService greaseManageService;
    @Autowired
    private ProductionOrderRecordsService productionOrderRecordsService;
    @Autowired
    private ProductionOrderBatchInfoService productionOrderBatchInfoService;
    private static Logger logger;
    LogUtil logUtil = new LogUtil();
    static {
        logger = Logger.getLogger(OP140Callback.class);
    }
    private static Date IN_TIME = null;
    private static String S_ORDER_CODE = "";//工单编号
    private static String S_PRODUCT_CODE = "";//产品编号
    private static String S_PRODUCT_TYPE= "";//产品类型
    private static String S_SFC_CODE = "";//总成编码
    private static String PRODUCTION_LINE  = "OP";//产线号
    private static String LOCATION_CODE  = "OP140";//工位号
    private static List list = null;
    public OP140Callback(MiloService miloService,
                         ProductionOrdeInfoService productionOrdeInfoService,
                         PassingStationCollectionService passingStationCollectionService,
                         ParamCollectionService paramCollectionService,
                         CollectionParamConfService collectionParamConfService,
                         SerialNumbersConfService serialNumbersConfService,
                         EquipmentStatusService equipmentStatusService,
                         EquipmentAlarmService equipmentAlarmService,
                         MaterialTraceabilityService materialTraceabilityService,
                         EquipmentInfoService equipmentInfoService,
                         RepairManageInfoService repairManageInfoService,
                         LocationInfoService locationInfoService,
                         GreaseManageService greaseManageService,
                         ProductionOrderRecordsService productionOrderRecordsService,
                         ProductionOrderBatchInfoService productionOrderBatchInfoService) {
        this.miloService = miloService;
        this.productionOrdeInfoService = productionOrdeInfoService;
        this.passingStationCollectionService = passingStationCollectionService;
        this.paramCollectionService = paramCollectionService;
        this.collectionParamConfService = collectionParamConfService;
        this.serialNumbersConfService = serialNumbersConfService;
        this.equipmentStatusService = equipmentStatusService;
        this.equipmentAlarmService = equipmentAlarmService;
        this.materialTraceabilityService = materialTraceabilityService;
        this.equipmentInfoService = equipmentInfoService;
        this.repairManageInfoService = repairManageInfoService;
        this.locationInfoService = locationInfoService;
        this.greaseManageService = greaseManageService;
        this.productionOrderRecordsService = productionOrderRecordsService;
        this.productionOrderBatchInfoService = productionOrderBatchInfoService;
    }
    @Override
    public void onSubscribe(String identifier, Object value) {
        String ecpStr = "";//异常记录标记
        try {
            //心跳
            if(null != value && identifier.equals(OPCElement.OP140_F_HEART_BEAT)){
                if( "false".equals(value.toString()))
                {
                    ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP140_F_HEART_BEAT,true);
                    miloService.writeToOpcUa(entity);
                }
            }
            //PLC进站
            else if(null != value && identifier.equals(OPCElement.OP140_J_PLC_START)){
                if("true".equals(value.toString())){
                    handleOrder();
                }
            }
            //PLC出站
            else if(null != value && identifier.equals(OPCElement.OP140_J_PLC_FINISH)){
                if("true".equals(value.toString())){
                    handleFinsh();
                    handleInfo();
                    handleMaterial();
                }
            }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 {
        logger.info("handleOrder PC处理开始!");
        IN_TIME = DateTool.getLocalTimeForDate();
        List<String> lists = new ArrayList<>();
        lists.add(OPCElement.OP140_S_ORDER_CODE);
        lists.add(OPCElement.OP140_S_PRODUCT_CODE);
        lists.add(OPCElement.OP140_S_SFC_CODE);
        List<ReadWriteEntity> returnLists= miloService.readFromOpcUa(lists);
        returnLists.forEach(element->{
            switch(element.getIdentifier()){
                case OPCElement.OP140_S_ORDER_CODE:
                    S_ORDER_CODE = element.getValue().toString();
                    break;
                case OPCElement.OP140_S_PRODUCT_CODE:
                    S_PRODUCT_TYPE = element.getValue().toString();
                    S_PRODUCT_CODE = GlobalVariable.PRODUCT_CODE_MAP.get(S_PRODUCT_TYPE);
                    break;
                case OPCElement.OP140_S_SFC_CODE:
                    S_SFC_CODE = element.getValue().toString();
                    break;
                default:
                    break;
            }
        });
        ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP140_J_PC_WRITE_ORDER,true);
        miloService.writeToOpcUa(entity);
        logger.info("handleOrder PC处理完成!");
    }
    public void handleFinsh() throws Exception {
        logger.info("handleFinsh PC处理开始!");
        String S_PRODUCT_STATE_CODE = miloService.
                readFromOpcUa(OPCElement.OP140_S_PRODUCT_STATE_CODE)
                .getValue().toString();
        if("2".equals(S_PRODUCT_STATE_CODE)){
            ProductionOrderRecordsParam productionOrderRecordsParam = new ProductionOrderRecordsParam();
            productionOrderRecordsParam.setWorkOrderNo(S_ORDER_CODE);
            productionOrderRecordsParam.setProductNo(S_SFC_CODE);
            List<ProductionOrderRecordsResult> list = productionOrderRecordsService.findListBySpec(productionOrderRecordsParam);
            if(!list.isEmpty()){
                ProductionOrderRecordsResult productionOrderRecordsResult = list.get(0);
                productionOrderRecordsParam.setId(productionOrderRecordsResult.getId());
                productionOrderRecordsParam.setWhetherPass(S_PRODUCT_STATE_CODE);
                productionOrderRecordsService.update(productionOrderRecordsParam);
            }
        }
        //处理过站信息
        PassingStationCollectionParam param = new PassingStationCollectionParam();
        param.setWorkOrderNo(S_ORDER_CODE);
        param.setProductCode(S_PRODUCT_CODE);
        param.setSfcCode(S_SFC_CODE);
        param.setProductionLine(PRODUCTION_LINE);
        param.setLocationCode(LOCATION_CODE);
        param.setInboundTime(IN_TIME);
        param.setOutboundTime(DateTool.getLocalTimeForDate());
        param.setOutRsSign(S_PRODUCT_STATE_CODE);//出站是否合格
        passingStationCollectionService.add(param);
        ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP140_J_PC_FINISH,true);
        miloService.writeToOpcUa(entity);//写PC完成
        logger.info("handleFinsh PC处理完成!");
    }
    public void handleMaterial() {
        //查询批次上料信息
        ProductionOrderBatchInfoParam productionOrderBatchInfoParam = new ProductionOrderBatchInfoParam();
        productionOrderBatchInfoParam.setWorkOrderNo(S_ORDER_CODE);
        productionOrderBatchInfoParam.setLocationCode(LOCATION_CODE);
        List<ProductionOrderBatchInfoResult> list = productionOrderBatchInfoService.findListBySpec(productionOrderBatchInfoParam);
        for(int i=0;i<list.size();i++){
            ProductionOrderBatchInfoResult productionOrderBatchInfoResult = list.get(i);
            int remainingQuantity =  productionOrderBatchInfoResult.getResidueQuantity();//剩余数量
            if(remainingQuantity>0 ){
                //新增物料追溯
                MaterialTraceabilityParam materialTraceabilityParam = new MaterialTraceabilityParam();
                materialTraceabilityParam.setWorkOrderNo(S_ORDER_CODE);
                materialTraceabilityParam.setProductCode(S_PRODUCT_CODE);
                materialTraceabilityParam.setProductNo(S_SFC_CODE);
                materialTraceabilityParam.setLineCode(PRODUCTION_LINE);
                materialTraceabilityParam.setLocationCode(LOCATION_CODE);
                materialTraceabilityParam.setAssemblyQty(1);
                materialTraceabilityParam.setAssemblyTime(DateTool.getLocalTimeForDate());
                materialTraceabilityParam.setMaterialCode(productionOrderBatchInfoResult.getMaterialCode());//物料编码
                materialTraceabilityParam.setMaterialBatchNo(productionOrderBatchInfoResult.getBatch());//物料批次
                materialTraceabilityService.add(materialTraceabilityParam);
                //更新剩余数量
                productionOrderBatchInfoParam.setId(productionOrderBatchInfoResult.getId());
                productionOrderBatchInfoParam.setResidueQuantity(remainingQuantity-1);//剩余数量
                productionOrderBatchInfoService.update(productionOrderBatchInfoParam);
            }
        }
    }
    //PC读参数信息
    public void handleInfo() throws Exception {
        logger.info("handleInfo START!");
        if(null == list){
            CollectionParamConfParam collectionParamConfParam = new CollectionParamConfParam();
            collectionParamConfParam.setLocationCode(LOCATION_CODE);
            list = collectionParamConfService.findListBySpec(collectionParamConfParam);
        }
        if(null != list && !list.isEmpty()) {
            for (int i = 0; i < list.size(); i++) {
                CollectionParamConfResult result = (CollectionParamConfResult) list.get(i);
                String value = miloService.
                        readFromOpcUa(result.getGatherAddress())
                        .getValue().toString();//读参数值
                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);
                paramCollectionParam.setParamLower(result.getParamLower());
                paramCollectionParam.setParamUpper(result.getParamUpper());
                paramCollectionParam.setParamStandard(result.getParamCentral());
                paramCollectionParam.setCollectionTime(DateTool.getLocalTimeForDate());
                paramCollectionParam.setUnit(result.getUnit());
                paramCollectionService.add(paramCollectionParam);
            }
        }
        logger.info("handleInfo END!");
    }
}
guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/OP150Callback.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,298 @@
package cn.stylefeng.guns.plcserver.callback;
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.model.params.ParamCollectionParam;
import cn.stylefeng.guns.modular.cm.paramCollection.service.ParamCollectionService;
import cn.stylefeng.guns.modular.cm.passingStationCollection.model.params.PassingStationCollectionParam;
import cn.stylefeng.guns.modular.cm.passingStationCollection.service.PassingStationCollectionService;
import cn.stylefeng.guns.modular.dq.materialTraceability.model.params.MaterialTraceabilityParam;
import cn.stylefeng.guns.modular.dq.materialTraceability.service.MaterialTraceabilityService;
import cn.stylefeng.guns.modular.em.equipmentAlarm.service.EquipmentAlarmService;
import cn.stylefeng.guns.modular.em.equipmentStatus.service.EquipmentStatusService;
import cn.stylefeng.guns.modular.gm.greaseManage.service.GreaseManageService;
import cn.stylefeng.guns.modular.om.productionOrdeInfo.service.ProductionOrdeInfoService;
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.model.params.ProductionOrderBatchInfoParam;
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.model.result.ProductionOrderBatchInfoResult;
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.service.ProductionOrderBatchInfoService;
import cn.stylefeng.guns.modular.om.productionOrderRecords.model.params.ProductionOrderRecordsParam;
import cn.stylefeng.guns.modular.om.productionOrderRecords.model.result.ProductionOrderRecordsResult;
import cn.stylefeng.guns.modular.om.productionOrderRecords.service.ProductionOrderRecordsService;
import cn.stylefeng.guns.modular.sc.repairManageInfo.service.RepairManageInfoService;
import cn.stylefeng.guns.modular.sc.serialNumbersConf.service.SerialNumbersConfService;
import cn.stylefeng.guns.plcserver.opc.GlobalVariable;
import cn.stylefeng.guns.plcserver.opc.OPCElement;
import cn.stylefeng.guns.plcserver.tool.DateTool;
import cn.stylefeng.guns.plcserver.tool.LogUtil;
import com.kangaroohy.milo.model.ReadWriteEntity;
import com.kangaroohy.milo.runner.subscription.SubscriptionCallback;
import com.kangaroohy.milo.service.MiloService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@Component
public class OP150Callback implements SubscriptionCallback {
    public MiloService miloService;
    @Autowired
    public ProductionOrdeInfoService productionOrdeInfoService;
    @Autowired
    public PassingStationCollectionService passingStationCollectionService;
    @Autowired
    public ParamCollectionService paramCollectionService;
    @Autowired
    public CollectionParamConfService collectionParamConfService;
    @Autowired
    public SerialNumbersConfService serialNumbersConfService;
    @Autowired
    private EquipmentStatusService equipmentStatusService;
    @Autowired
    private EquipmentAlarmService equipmentAlarmService;
    @Autowired
    private MaterialTraceabilityService materialTraceabilityService;
    @Autowired
    private EquipmentInfoService equipmentInfoService;
    @Autowired
    private RepairManageInfoService repairManageInfoService;
    @Autowired
    private LocationInfoService locationInfoService;
    @Autowired
    private GreaseManageService greaseManageService;
    @Autowired
    private ProductionOrderRecordsService productionOrderRecordsService;
    @Autowired
    private ProductionOrderBatchInfoService productionOrderBatchInfoService;
    private static Logger logger;
    LogUtil logUtil = new LogUtil();
    static {
        logger = Logger.getLogger(OP150Callback.class);
    }
    private static Date IN_TIME = null;
    private static String S_ORDER_CODE = "";//工单编号
    private static String S_PRODUCT_CODE = "";//产品编号
    private static String S_PRODUCT_TYPE= "";//产品类型
    private static String S_SFC_CODE = "";//总成编码
    private static String PRODUCTION_LINE  = "OP";//产线号
    private static String LOCATION_CODE  = "OP150";//工位号
    private static List list = null;
    public OP150Callback(MiloService miloService,
                         ProductionOrdeInfoService productionOrdeInfoService,
                         PassingStationCollectionService passingStationCollectionService,
                         ParamCollectionService paramCollectionService,
                         CollectionParamConfService collectionParamConfService,
                         SerialNumbersConfService serialNumbersConfService,
                         EquipmentStatusService equipmentStatusService,
                         EquipmentAlarmService equipmentAlarmService,
                         MaterialTraceabilityService materialTraceabilityService,
                         EquipmentInfoService equipmentInfoService,
                         RepairManageInfoService repairManageInfoService,
                         LocationInfoService locationInfoService,
                         GreaseManageService greaseManageService,
                         ProductionOrderRecordsService productionOrderRecordsService,
                         ProductionOrderBatchInfoService productionOrderBatchInfoService) {
        this.miloService = miloService;
        this.productionOrdeInfoService = productionOrdeInfoService;
        this.passingStationCollectionService = passingStationCollectionService;
        this.paramCollectionService = paramCollectionService;
        this.collectionParamConfService = collectionParamConfService;
        this.serialNumbersConfService = serialNumbersConfService;
        this.equipmentStatusService = equipmentStatusService;
        this.equipmentAlarmService = equipmentAlarmService;
        this.materialTraceabilityService = materialTraceabilityService;
        this.equipmentInfoService = equipmentInfoService;
        this.repairManageInfoService = repairManageInfoService;
        this.locationInfoService = locationInfoService;
        this.greaseManageService = greaseManageService;
        this.productionOrderRecordsService = productionOrderRecordsService;
        this.productionOrderBatchInfoService = productionOrderBatchInfoService;
    }
    @Override
    public void onSubscribe(String identifier, Object value) {
        String ecpStr = "";//异常记录标记
        try {
            //心跳
            if(null != value && identifier.equals(OPCElement.OP150_F_HEART_BEAT)){
                if( "false".equals(value.toString()))
                {
                    ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP150_F_HEART_BEAT,true);
                    miloService.writeToOpcUa(entity);
                }
            }
            //PLC进站
            else if(null != value && identifier.equals(OPCElement.OP150_J_PLC_START)){
                if("true".equals(value.toString())){
                    handleOrder();
                }
            }
            //PLC出站
            else if(null != value && identifier.equals(OPCElement.OP150_J_PLC_FINISH)){
                if("true".equals(value.toString())){
                    handleFinsh();
                    handleInfo();
                    handleMaterial();
                }
            }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 {
        logger.info("handleOrder PC处理开始!");
        IN_TIME = DateTool.getLocalTimeForDate();
        List<String> lists = new ArrayList<>();
        lists.add(OPCElement.OP150_S_ORDER_CODE);
        lists.add(OPCElement.OP150_S_PRODUCT_CODE);
        lists.add(OPCElement.OP150_S_SFC_CODE);
        List<ReadWriteEntity> returnLists= miloService.readFromOpcUa(lists);
        returnLists.forEach(element->{
            switch(element.getIdentifier()){
                case OPCElement.OP150_S_ORDER_CODE:
                    S_ORDER_CODE = element.getValue().toString();
                    break;
                case OPCElement.OP150_S_PRODUCT_CODE:
                    S_PRODUCT_TYPE = element.getValue().toString();
                    S_PRODUCT_CODE = GlobalVariable.PRODUCT_CODE_MAP.get(S_PRODUCT_TYPE);
                    break;
                case OPCElement.OP150_S_SFC_CODE:
                    S_SFC_CODE = element.getValue().toString();
                    break;
                default:
                    break;
            }
        });
        ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP150_J_PC_WRITE_ORDER,true);
        miloService.writeToOpcUa(entity);
        logger.info("handleOrder PC处理完成!");
    }
    public void handleFinsh() throws Exception {
        logger.info("handleFinsh PC处理开始!");
        String S_PRODUCT_STATE_CODE = miloService.
                readFromOpcUa(OPCElement.OP150_S_PRODUCT_STATE_CODE)
                .getValue().toString();
        if("2".equals(S_PRODUCT_STATE_CODE)){
            ProductionOrderRecordsParam productionOrderRecordsParam = new ProductionOrderRecordsParam();
            productionOrderRecordsParam.setWorkOrderNo(S_ORDER_CODE);
            productionOrderRecordsParam.setProductNo(S_SFC_CODE);
            List<ProductionOrderRecordsResult> list = productionOrderRecordsService.findListBySpec(productionOrderRecordsParam);
            if(!list.isEmpty()){
                ProductionOrderRecordsResult productionOrderRecordsResult = list.get(0);
                productionOrderRecordsParam.setId(productionOrderRecordsResult.getId());
                productionOrderRecordsParam.setWhetherPass(S_PRODUCT_STATE_CODE);
                productionOrderRecordsService.update(productionOrderRecordsParam);
            }
        }
        //处理过站信息
        PassingStationCollectionParam param = new PassingStationCollectionParam();
        param.setWorkOrderNo(S_ORDER_CODE);
        param.setProductCode(S_PRODUCT_CODE);
        param.setSfcCode(S_SFC_CODE);
        param.setProductionLine(PRODUCTION_LINE);
        param.setLocationCode(LOCATION_CODE);
        param.setInboundTime(IN_TIME);
        param.setOutboundTime(DateTool.getLocalTimeForDate());
        param.setOutRsSign(S_PRODUCT_STATE_CODE);//出站是否合格
        passingStationCollectionService.add(param);
        ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP150_J_PC_FINISH,true);
        miloService.writeToOpcUa(entity);//写PC完成
        logger.info("handleFinsh PC处理完成!");
    }
    public void handleMaterial() {
        //查询批次上料信息
        ProductionOrderBatchInfoParam productionOrderBatchInfoParam = new ProductionOrderBatchInfoParam();
        productionOrderBatchInfoParam.setWorkOrderNo(S_ORDER_CODE);
        productionOrderBatchInfoParam.setLocationCode(LOCATION_CODE);
        List<ProductionOrderBatchInfoResult> list = productionOrderBatchInfoService.findListBySpec(productionOrderBatchInfoParam);
        for(int i=0;i<list.size();i++){
            ProductionOrderBatchInfoResult productionOrderBatchInfoResult = list.get(i);
            int remainingQuantity =  productionOrderBatchInfoResult.getResidueQuantity();//剩余数量
            if(remainingQuantity>0 ){
                //新增物料追溯
                MaterialTraceabilityParam materialTraceabilityParam = new MaterialTraceabilityParam();
                materialTraceabilityParam.setWorkOrderNo(S_ORDER_CODE);
                materialTraceabilityParam.setProductCode(S_PRODUCT_CODE);
                materialTraceabilityParam.setProductNo(S_SFC_CODE);
                materialTraceabilityParam.setLineCode(PRODUCTION_LINE);
                materialTraceabilityParam.setLocationCode(LOCATION_CODE);
                materialTraceabilityParam.setAssemblyQty(1);
                materialTraceabilityParam.setAssemblyTime(DateTool.getLocalTimeForDate());
                materialTraceabilityParam.setMaterialCode(productionOrderBatchInfoResult.getMaterialCode());//物料编码
                materialTraceabilityParam.setMaterialBatchNo(productionOrderBatchInfoResult.getBatch());//物料批次
                materialTraceabilityService.add(materialTraceabilityParam);
                //更新剩余数量
                productionOrderBatchInfoParam.setId(productionOrderBatchInfoResult.getId());
                productionOrderBatchInfoParam.setResidueQuantity(remainingQuantity-1);//剩余数量
                productionOrderBatchInfoService.update(productionOrderBatchInfoParam);
            }
        }
    }
    //PC读参数信息
    public void handleInfo() throws Exception {
        logger.info("handleInfo START!");
        if(null == list){
            CollectionParamConfParam collectionParamConfParam = new CollectionParamConfParam();
            collectionParamConfParam.setLocationCode(LOCATION_CODE);
            list = collectionParamConfService.findListBySpec(collectionParamConfParam);
        }
        if(null != list && !list.isEmpty()) {
            for (int i = 0; i < list.size(); i++) {
                CollectionParamConfResult result = (CollectionParamConfResult) list.get(i);
                String value = miloService.
                        readFromOpcUa(result.getGatherAddress())
                        .getValue().toString();//读参数值
                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);
                paramCollectionParam.setParamLower(result.getParamLower());
                paramCollectionParam.setParamUpper(result.getParamUpper());
                paramCollectionParam.setParamStandard(result.getParamCentral());
                paramCollectionParam.setCollectionTime(DateTool.getLocalTimeForDate());
                paramCollectionParam.setUnit(result.getUnit());
                paramCollectionService.add(paramCollectionParam);
            }
        }
        logger.info("handleInfo END!");
    }
}
guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/OP160Callback.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,298 @@
package cn.stylefeng.guns.plcserver.callback;
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.model.params.ParamCollectionParam;
import cn.stylefeng.guns.modular.cm.paramCollection.service.ParamCollectionService;
import cn.stylefeng.guns.modular.cm.passingStationCollection.model.params.PassingStationCollectionParam;
import cn.stylefeng.guns.modular.cm.passingStationCollection.service.PassingStationCollectionService;
import cn.stylefeng.guns.modular.dq.materialTraceability.model.params.MaterialTraceabilityParam;
import cn.stylefeng.guns.modular.dq.materialTraceability.service.MaterialTraceabilityService;
import cn.stylefeng.guns.modular.em.equipmentAlarm.service.EquipmentAlarmService;
import cn.stylefeng.guns.modular.em.equipmentStatus.service.EquipmentStatusService;
import cn.stylefeng.guns.modular.gm.greaseManage.service.GreaseManageService;
import cn.stylefeng.guns.modular.om.productionOrdeInfo.service.ProductionOrdeInfoService;
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.model.params.ProductionOrderBatchInfoParam;
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.model.result.ProductionOrderBatchInfoResult;
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.service.ProductionOrderBatchInfoService;
import cn.stylefeng.guns.modular.om.productionOrderRecords.model.params.ProductionOrderRecordsParam;
import cn.stylefeng.guns.modular.om.productionOrderRecords.model.result.ProductionOrderRecordsResult;
import cn.stylefeng.guns.modular.om.productionOrderRecords.service.ProductionOrderRecordsService;
import cn.stylefeng.guns.modular.sc.repairManageInfo.service.RepairManageInfoService;
import cn.stylefeng.guns.modular.sc.serialNumbersConf.service.SerialNumbersConfService;
import cn.stylefeng.guns.plcserver.opc.GlobalVariable;
import cn.stylefeng.guns.plcserver.opc.OPCElement;
import cn.stylefeng.guns.plcserver.tool.DateTool;
import cn.stylefeng.guns.plcserver.tool.LogUtil;
import com.kangaroohy.milo.model.ReadWriteEntity;
import com.kangaroohy.milo.runner.subscription.SubscriptionCallback;
import com.kangaroohy.milo.service.MiloService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@Component
public class OP160Callback implements SubscriptionCallback {
    public MiloService miloService;
    @Autowired
    public ProductionOrdeInfoService productionOrdeInfoService;
    @Autowired
    public PassingStationCollectionService passingStationCollectionService;
    @Autowired
    public ParamCollectionService paramCollectionService;
    @Autowired
    public CollectionParamConfService collectionParamConfService;
    @Autowired
    public SerialNumbersConfService serialNumbersConfService;
    @Autowired
    private EquipmentStatusService equipmentStatusService;
    @Autowired
    private EquipmentAlarmService equipmentAlarmService;
    @Autowired
    private MaterialTraceabilityService materialTraceabilityService;
    @Autowired
    private EquipmentInfoService equipmentInfoService;
    @Autowired
    private RepairManageInfoService repairManageInfoService;
    @Autowired
    private LocationInfoService locationInfoService;
    @Autowired
    private GreaseManageService greaseManageService;
    @Autowired
    private ProductionOrderRecordsService productionOrderRecordsService;
    @Autowired
    private ProductionOrderBatchInfoService productionOrderBatchInfoService;
    private static Logger logger;
    LogUtil logUtil = new LogUtil();
    static {
        logger = Logger.getLogger(OP160Callback.class);
    }
    private static Date IN_TIME = null;
    private static String S_ORDER_CODE = "";//工单编号
    private static String S_PRODUCT_CODE = "";//产品编号
    private static String S_PRODUCT_TYPE= "";//产品类型
    private static String S_SFC_CODE = "";//总成编码
    private static String PRODUCTION_LINE  = "OP";//产线号
    private static String LOCATION_CODE  = "OP160";//工位号
    private static List list = null;
    public OP160Callback(MiloService miloService,
                         ProductionOrdeInfoService productionOrdeInfoService,
                         PassingStationCollectionService passingStationCollectionService,
                         ParamCollectionService paramCollectionService,
                         CollectionParamConfService collectionParamConfService,
                         SerialNumbersConfService serialNumbersConfService,
                         EquipmentStatusService equipmentStatusService,
                         EquipmentAlarmService equipmentAlarmService,
                         MaterialTraceabilityService materialTraceabilityService,
                         EquipmentInfoService equipmentInfoService,
                         RepairManageInfoService repairManageInfoService,
                         LocationInfoService locationInfoService,
                         GreaseManageService greaseManageService,
                         ProductionOrderRecordsService productionOrderRecordsService,
                         ProductionOrderBatchInfoService productionOrderBatchInfoService) {
        this.miloService = miloService;
        this.productionOrdeInfoService = productionOrdeInfoService;
        this.passingStationCollectionService = passingStationCollectionService;
        this.paramCollectionService = paramCollectionService;
        this.collectionParamConfService = collectionParamConfService;
        this.serialNumbersConfService = serialNumbersConfService;
        this.equipmentStatusService = equipmentStatusService;
        this.equipmentAlarmService = equipmentAlarmService;
        this.materialTraceabilityService = materialTraceabilityService;
        this.equipmentInfoService = equipmentInfoService;
        this.repairManageInfoService = repairManageInfoService;
        this.locationInfoService = locationInfoService;
        this.greaseManageService = greaseManageService;
        this.productionOrderRecordsService = productionOrderRecordsService;
        this.productionOrderBatchInfoService = productionOrderBatchInfoService;
    }
    @Override
    public void onSubscribe(String identifier, Object value) {
        String ecpStr = "";//异常记录标记
        try {
            //心跳
            if(null != value && identifier.equals(OPCElement.OP160_F_HEART_BEAT)){
                if( "false".equals(value.toString()))
                {
                    ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP160_F_HEART_BEAT,true);
                    miloService.writeToOpcUa(entity);
                }
            }
            //PLC进站
            else if(null != value && identifier.equals(OPCElement.OP160_J_PLC_START)){
                if("true".equals(value.toString())){
                    handleOrder();
                }
            }
            //PLC出站
            else if(null != value && identifier.equals(OPCElement.OP160_J_PLC_FINISH)){
                if("true".equals(value.toString())){
                    handleFinsh();
                    handleInfo();
                    handleMaterial();
                }
            }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 {
        logger.info("handleOrder PC处理开始!");
        IN_TIME = DateTool.getLocalTimeForDate();
        List<String> lists = new ArrayList<>();
        lists.add(OPCElement.OP160_S_ORDER_CODE);
        lists.add(OPCElement.OP160_S_PRODUCT_CODE);
        lists.add(OPCElement.OP160_S_SFC_CODE);
        List<ReadWriteEntity> returnLists= miloService.readFromOpcUa(lists);
        returnLists.forEach(element->{
            switch(element.getIdentifier()){
                case OPCElement.OP160_S_ORDER_CODE:
                    S_ORDER_CODE = element.getValue().toString();
                    break;
                case OPCElement.OP160_S_PRODUCT_CODE:
                    S_PRODUCT_TYPE = element.getValue().toString();
                    S_PRODUCT_CODE = GlobalVariable.PRODUCT_CODE_MAP.get(S_PRODUCT_TYPE);
                    break;
                case OPCElement.OP160_S_SFC_CODE:
                    S_SFC_CODE = element.getValue().toString();
                    break;
                default:
                    break;
            }
        });
        ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP160_J_PC_WRITE_ORDER,true);
        miloService.writeToOpcUa(entity);
        logger.info("handleOrder PC处理完成!");
    }
    public void handleFinsh() throws Exception {
        logger.info("handleFinsh PC处理开始!");
        String S_PRODUCT_STATE_CODE = miloService.
                readFromOpcUa(OPCElement.OP160_S_PRODUCT_STATE_CODE)
                .getValue().toString();
        if("2".equals(S_PRODUCT_STATE_CODE)){
            ProductionOrderRecordsParam productionOrderRecordsParam = new ProductionOrderRecordsParam();
            productionOrderRecordsParam.setWorkOrderNo(S_ORDER_CODE);
            productionOrderRecordsParam.setProductNo(S_SFC_CODE);
            List<ProductionOrderRecordsResult> list = productionOrderRecordsService.findListBySpec(productionOrderRecordsParam);
            if(!list.isEmpty()){
                ProductionOrderRecordsResult productionOrderRecordsResult = list.get(0);
                productionOrderRecordsParam.setId(productionOrderRecordsResult.getId());
                productionOrderRecordsParam.setWhetherPass(S_PRODUCT_STATE_CODE);
                productionOrderRecordsService.update(productionOrderRecordsParam);
            }
        }
        //处理过站信息
        PassingStationCollectionParam param = new PassingStationCollectionParam();
        param.setWorkOrderNo(S_ORDER_CODE);
        param.setProductCode(S_PRODUCT_CODE);
        param.setSfcCode(S_SFC_CODE);
        param.setProductionLine(PRODUCTION_LINE);
        param.setLocationCode(LOCATION_CODE);
        param.setInboundTime(IN_TIME);
        param.setOutboundTime(DateTool.getLocalTimeForDate());
        param.setOutRsSign(S_PRODUCT_STATE_CODE);//出站是否合格
        passingStationCollectionService.add(param);
        ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP160_J_PC_FINISH,true);
        miloService.writeToOpcUa(entity);//写PC完成
        logger.info("handleFinsh PC处理完成!");
    }
    public void handleMaterial() {
        //查询批次上料信息
        ProductionOrderBatchInfoParam productionOrderBatchInfoParam = new ProductionOrderBatchInfoParam();
        productionOrderBatchInfoParam.setWorkOrderNo(S_ORDER_CODE);
        productionOrderBatchInfoParam.setLocationCode(LOCATION_CODE);
        List<ProductionOrderBatchInfoResult> list = productionOrderBatchInfoService.findListBySpec(productionOrderBatchInfoParam);
        for(int i=0;i<list.size();i++){
            ProductionOrderBatchInfoResult productionOrderBatchInfoResult = list.get(i);
            int remainingQuantity =  productionOrderBatchInfoResult.getResidueQuantity();//剩余数量
            if(remainingQuantity>0 ){
                //新增物料追溯
                MaterialTraceabilityParam materialTraceabilityParam = new MaterialTraceabilityParam();
                materialTraceabilityParam.setWorkOrderNo(S_ORDER_CODE);
                materialTraceabilityParam.setProductCode(S_PRODUCT_CODE);
                materialTraceabilityParam.setProductNo(S_SFC_CODE);
                materialTraceabilityParam.setLineCode(PRODUCTION_LINE);
                materialTraceabilityParam.setLocationCode(LOCATION_CODE);
                materialTraceabilityParam.setAssemblyQty(1);
                materialTraceabilityParam.setAssemblyTime(DateTool.getLocalTimeForDate());
                materialTraceabilityParam.setMaterialCode(productionOrderBatchInfoResult.getMaterialCode());//物料编码
                materialTraceabilityParam.setMaterialBatchNo(productionOrderBatchInfoResult.getBatch());//物料批次
                materialTraceabilityService.add(materialTraceabilityParam);
                //更新剩余数量
                productionOrderBatchInfoParam.setId(productionOrderBatchInfoResult.getId());
                productionOrderBatchInfoParam.setResidueQuantity(remainingQuantity-1);//剩余数量
                productionOrderBatchInfoService.update(productionOrderBatchInfoParam);
            }
        }
    }
    //PC读参数信息
    public void handleInfo() throws Exception {
        logger.info("handleInfo START!");
        if(null == list){
            CollectionParamConfParam collectionParamConfParam = new CollectionParamConfParam();
            collectionParamConfParam.setLocationCode(LOCATION_CODE);
            list = collectionParamConfService.findListBySpec(collectionParamConfParam);
        }
        if(null != list && !list.isEmpty()) {
            for (int i = 0; i < list.size(); i++) {
                CollectionParamConfResult result = (CollectionParamConfResult) list.get(i);
                String value = miloService.
                        readFromOpcUa(result.getGatherAddress())
                        .getValue().toString();//读参数值
                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);
                paramCollectionParam.setParamLower(result.getParamLower());
                paramCollectionParam.setParamUpper(result.getParamUpper());
                paramCollectionParam.setParamStandard(result.getParamCentral());
                paramCollectionParam.setCollectionTime(DateTool.getLocalTimeForDate());
                paramCollectionParam.setUnit(result.getUnit());
                paramCollectionService.add(paramCollectionParam);
            }
        }
        logger.info("handleInfo END!");
    }
}
guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/OP170Callback.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,315 @@
package cn.stylefeng.guns.plcserver.callback;
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.model.params.ParamCollectionParam;
import cn.stylefeng.guns.modular.cm.paramCollection.service.ParamCollectionService;
import cn.stylefeng.guns.modular.cm.passingStationCollection.model.params.PassingStationCollectionParam;
import cn.stylefeng.guns.modular.cm.passingStationCollection.service.PassingStationCollectionService;
import cn.stylefeng.guns.modular.dq.materialTraceability.model.params.MaterialTraceabilityParam;
import cn.stylefeng.guns.modular.dq.materialTraceability.service.MaterialTraceabilityService;
import cn.stylefeng.guns.modular.em.equipmentAlarm.service.EquipmentAlarmService;
import cn.stylefeng.guns.modular.em.equipmentStatus.service.EquipmentStatusService;
import cn.stylefeng.guns.modular.gm.greaseManage.service.GreaseManageService;
import cn.stylefeng.guns.modular.om.productionOrdeInfo.model.params.ProductionOrdeInfoParam;
import cn.stylefeng.guns.modular.om.productionOrdeInfo.model.result.ProductionOrdeInfoResult;
import cn.stylefeng.guns.modular.om.productionOrdeInfo.service.ProductionOrdeInfoService;
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.model.params.ProductionOrderBatchInfoParam;
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.model.result.ProductionOrderBatchInfoResult;
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.service.ProductionOrderBatchInfoService;
import cn.stylefeng.guns.modular.om.productionOrderRecords.model.params.ProductionOrderRecordsParam;
import cn.stylefeng.guns.modular.om.productionOrderRecords.model.result.ProductionOrderRecordsResult;
import cn.stylefeng.guns.modular.om.productionOrderRecords.service.ProductionOrderRecordsService;
import cn.stylefeng.guns.modular.sc.repairManageInfo.service.RepairManageInfoService;
import cn.stylefeng.guns.modular.sc.serialNumbersConf.service.SerialNumbersConfService;
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;
import com.kangaroohy.milo.runner.subscription.SubscriptionCallback;
import com.kangaroohy.milo.service.MiloService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@Component
public class OP170Callback implements SubscriptionCallback {
    public MiloService miloService;
    @Autowired
    public ProductionOrdeInfoService productionOrdeInfoService;
    @Autowired
    public PassingStationCollectionService passingStationCollectionService;
    @Autowired
    public ParamCollectionService paramCollectionService;
    @Autowired
    public CollectionParamConfService collectionParamConfService;
    @Autowired
    public SerialNumbersConfService serialNumbersConfService;
    @Autowired
    private EquipmentStatusService equipmentStatusService;
    @Autowired
    private EquipmentAlarmService equipmentAlarmService;
    @Autowired
    private MaterialTraceabilityService materialTraceabilityService;
    @Autowired
    private EquipmentInfoService equipmentInfoService;
    @Autowired
    private RepairManageInfoService repairManageInfoService;
    @Autowired
    private LocationInfoService locationInfoService;
    @Autowired
    private GreaseManageService greaseManageService;
    @Autowired
    private ProductionOrderRecordsService productionOrderRecordsService;
    @Autowired
    private ProductionOrderBatchInfoService productionOrderBatchInfoService;
    private static Logger logger;
    LogUtil logUtil = new LogUtil();
    static {
        logger = Logger.getLogger(OP170Callback.class);
    }
    private static Date IN_TIME = null;
    private static String S_ORDER_CODE = "";//工单编号
    private static String S_PRODUCT_CODE = "";//产品编号
    private static String S_PRODUCT_TYPE= "";//产品类型
    private static String S_SFC_CODE = "";//总成编码
    private static String PRODUCTION_LINE  = "OP";//产线号
    private static String LOCATION_CODE  = "OP170";//工位号
    private static List list = null;
    public OP170Callback(MiloService miloService,
                         ProductionOrdeInfoService productionOrdeInfoService,
                         PassingStationCollectionService passingStationCollectionService,
                         ParamCollectionService paramCollectionService,
                         CollectionParamConfService collectionParamConfService,
                         SerialNumbersConfService serialNumbersConfService,
                         EquipmentStatusService equipmentStatusService,
                         EquipmentAlarmService equipmentAlarmService,
                         MaterialTraceabilityService materialTraceabilityService,
                         EquipmentInfoService equipmentInfoService,
                         RepairManageInfoService repairManageInfoService,
                         LocationInfoService locationInfoService,
                         GreaseManageService greaseManageService,
                         ProductionOrderRecordsService productionOrderRecordsService,
                         ProductionOrderBatchInfoService productionOrderBatchInfoService) {
        this.miloService = miloService;
        this.productionOrdeInfoService = productionOrdeInfoService;
        this.passingStationCollectionService = passingStationCollectionService;
        this.paramCollectionService = paramCollectionService;
        this.collectionParamConfService = collectionParamConfService;
        this.serialNumbersConfService = serialNumbersConfService;
        this.equipmentStatusService = equipmentStatusService;
        this.equipmentAlarmService = equipmentAlarmService;
        this.materialTraceabilityService = materialTraceabilityService;
        this.equipmentInfoService = equipmentInfoService;
        this.repairManageInfoService = repairManageInfoService;
        this.locationInfoService = locationInfoService;
        this.greaseManageService = greaseManageService;
        this.productionOrderRecordsService = productionOrderRecordsService;
        this.productionOrderBatchInfoService = productionOrderBatchInfoService;
    }
    @Override
    public void onSubscribe(String identifier, Object value) {
        String ecpStr = "";//异常记录标记
        try {
            //心跳
            if(null != value && identifier.equals(OPCElement.OP170_F_HEART_BEAT)){
                if( "false".equals(value.toString()))
                {
                    ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP170_F_HEART_BEAT,true);
                    miloService.writeToOpcUa(entity);
                }
            }
            //PLC进站
            else if(null != value && identifier.equals(OPCElement.OP170_J_PLC_START)){
                if("true".equals(value.toString())){
                    handleOrder();
                }
            }
            //PLC出站
            else if(null != value && identifier.equals(OPCElement.OP170_J_PLC_FINISH)){
                if("true".equals(value.toString())){
                    handleFinsh();
                    handleInfo();
                    handleMaterial();
                }
            }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 {
        logger.info("handleOrder PC处理开始!");
        IN_TIME = DateTool.getLocalTimeForDate();
        List<String> lists = new ArrayList<>();
        lists.add(OPCElement.OP170_S_ORDER_CODE);
        lists.add(OPCElement.OP170_S_PRODUCT_CODE);
        lists.add(OPCElement.OP170_S_SFC_CODE);
        List<ReadWriteEntity> returnLists= miloService.readFromOpcUa(lists);
        returnLists.forEach(element->{
            switch(element.getIdentifier()){
                case OPCElement.OP170_S_ORDER_CODE:
                    S_ORDER_CODE = element.getValue().toString();
                    break;
                case OPCElement.OP170_S_PRODUCT_CODE:
                    S_PRODUCT_TYPE = element.getValue().toString();
                    S_PRODUCT_CODE = GlobalVariable.PRODUCT_CODE_MAP.get(S_PRODUCT_TYPE);
                    break;
                case OPCElement.OP170_S_SFC_CODE:
                    S_SFC_CODE = element.getValue().toString();
                    break;
                default:
                    break;
            }
        });
        ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP170_J_PC_WRITE_ORDER,true);
        miloService.writeToOpcUa(entity);
        logger.info("handleOrder PC处理完成!");
    }
    public void handleFinsh() throws Exception {
        logger.info("handleFinsh PC处理开始!");
        String S_PRODUCT_STATE_CODE = miloService.
                readFromOpcUa(OPCElement.OP170_S_PRODUCT_STATE_CODE)
                .getValue().toString();
        //修改报工记录
        ProductionOrderRecordsParam productionOrderRecordsParam = new ProductionOrderRecordsParam();
        productionOrderRecordsParam.setWorkOrderNo(S_ORDER_CODE);
        productionOrderRecordsParam.setProductNo(S_SFC_CODE);
        List<ProductionOrderRecordsResult> list2 = productionOrderRecordsService.findListBySpec(productionOrderRecordsParam);
        if(!list2.isEmpty()){
            ProductionOrderRecordsResult productionOrderRecordsResult = list2.get(0);
            productionOrderRecordsParam.setId(productionOrderRecordsResult.getId());
            productionOrderRecordsParam.setWhetherPass(S_PRODUCT_STATE_CODE);
            productionOrderRecordsParam.setEndTime(DateTool.getLocalTimeForDate());
            productionOrderRecordsService.update(productionOrderRecordsParam);
        }
        PassingStationCollectionParam param = new PassingStationCollectionParam();
        param.setWorkOrderNo(S_ORDER_CODE);
        param.setProductCode(S_PRODUCT_CODE);
        param.setSfcCode(S_SFC_CODE);
        param.setProductionLine(PRODUCTION_LINE);
        param.setLocationCode(LOCATION_CODE);
        param.setInboundTime(IN_TIME);
        param.setOutboundTime(DateTool.getLocalTimeForDate());
        param.setOutRsSign(S_PRODUCT_STATE_CODE);//出站是否合格
        passingStationCollectionService.add(param);
        //更新工单完成数量
        ProductionOrdeInfoParam orderParam = new ProductionOrdeInfoParam();
        orderParam.setWorkOrderNo(S_ORDER_CODE);
        if(!"".equals(S_ORDER_CODE)&&null!=S_ORDER_CODE){
            List<ProductionOrdeInfoResult> list = productionOrdeInfoService.findListBySpec(orderParam);
            if(list.size()>0) {
                ProductionOrdeInfoResult result = list.get(0);
                orderParam.setId(result.getId());
                if (null == result.getActualQty() || "".equals(result.getActualQty())){
                    result.setActualQty(0);
                }
                orderParam.setActualQty(result.getActualQty()+1);
                productionOrdeInfoService.update(orderParam);
            }
        }
        ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP170_J_PC_FINISH,true);
        miloService.writeToOpcUa(entity);//写PC完成
        logger.info("OP170工位,handleFinsh PC处理完成!");
    }
    public void handleMaterial() {
        //查询批次上料信息
        ProductionOrderBatchInfoParam productionOrderBatchInfoParam = new ProductionOrderBatchInfoParam();
        productionOrderBatchInfoParam.setWorkOrderNo(S_ORDER_CODE);
        productionOrderBatchInfoParam.setLocationCode(LOCATION_CODE);
        List<ProductionOrderBatchInfoResult> list = productionOrderBatchInfoService.findListBySpec(productionOrderBatchInfoParam);
        for(int i=0;i<list.size();i++){
            ProductionOrderBatchInfoResult productionOrderBatchInfoResult = list.get(i);
            int remainingQuantity =  productionOrderBatchInfoResult.getResidueQuantity();//剩余数量
            if(remainingQuantity>0 ){
                //新增物料追溯
                MaterialTraceabilityParam materialTraceabilityParam = new MaterialTraceabilityParam();
                materialTraceabilityParam.setWorkOrderNo(S_ORDER_CODE);
                materialTraceabilityParam.setProductCode(S_PRODUCT_CODE);
                materialTraceabilityParam.setProductNo(S_SFC_CODE);
                materialTraceabilityParam.setLineCode(PRODUCTION_LINE);
                materialTraceabilityParam.setLocationCode(LOCATION_CODE);
                materialTraceabilityParam.setAssemblyQty(1);
                materialTraceabilityParam.setAssemblyTime(DateTool.getLocalTimeForDate());
                materialTraceabilityParam.setMaterialCode(productionOrderBatchInfoResult.getMaterialCode());//物料编码
                materialTraceabilityParam.setMaterialBatchNo(productionOrderBatchInfoResult.getBatch());//物料批次
                materialTraceabilityService.add(materialTraceabilityParam);
                //更新剩余数量
                productionOrderBatchInfoParam.setId(productionOrderBatchInfoResult.getId());
                productionOrderBatchInfoParam.setResidueQuantity(remainingQuantity-1);//剩余数量
                productionOrderBatchInfoService.update(productionOrderBatchInfoParam);
            }
        }
    }
    //PC读参数信息
    public void handleInfo() throws Exception {
        logger.info("handleInfo START!");
        if(null == list){
            CollectionParamConfParam collectionParamConfParam = new CollectionParamConfParam();
            collectionParamConfParam.setLocationCode(LOCATION_CODE);
            list = collectionParamConfService.findListBySpec(collectionParamConfParam);
        }
        if(null != list && !list.isEmpty()) {
            for (int i = 0; i < list.size(); i++) {
                CollectionParamConfResult result = (CollectionParamConfResult) list.get(i);
                String value = miloService.
                        readFromOpcUa(result.getGatherAddress())
                        .getValue().toString();//读参数值
                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);
                paramCollectionParam.setParamLower(result.getParamLower());
                paramCollectionParam.setParamUpper(result.getParamUpper());
                paramCollectionParam.setParamStandard(result.getParamCentral());
                paramCollectionParam.setCollectionTime(DateTool.getLocalTimeForDate());
                paramCollectionParam.setUnit(result.getUnit());
                paramCollectionService.add(paramCollectionParam);
            }
        }
        logger.info("handleInfo END!");
    }
}
guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/StateCallback.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,293 @@
package cn.stylefeng.guns.plcserver.callback;
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.model.params.EquipmentInfoParam;
import cn.stylefeng.guns.modular.bs.equipmentInfo.model.result.EquipmentInfoResult;
import cn.stylefeng.guns.modular.bs.equipmentInfo.service.EquipmentInfoService;
import cn.stylefeng.guns.modular.bs.locationInfo.model.params.LocationInfoParam;
import cn.stylefeng.guns.modular.bs.locationInfo.model.result.LocationInfoResult;
import cn.stylefeng.guns.modular.bs.locationInfo.service.LocationInfoService;
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;
import cn.stylefeng.guns.modular.cm.passingStationCollection.service.PassingStationCollectionService;
import cn.stylefeng.guns.modular.dq.materialTraceability.model.params.MaterialTraceabilityParam;
import cn.stylefeng.guns.modular.dq.materialTraceability.service.MaterialTraceabilityService;
import cn.stylefeng.guns.modular.em.equipmentAlarm.model.params.EquipmentAlarmParam;
import cn.stylefeng.guns.modular.em.equipmentAlarm.service.EquipmentAlarmService;
import cn.stylefeng.guns.modular.em.equipmentStatus.model.params.EquipmentStatusParam;
import cn.stylefeng.guns.modular.em.equipmentStatus.model.result.EquipmentStatusResult;
import cn.stylefeng.guns.modular.em.equipmentStatus.service.EquipmentStatusService;
import cn.stylefeng.guns.modular.gm.greaseManage.model.params.GreaseManageParam;
import cn.stylefeng.guns.modular.gm.greaseManage.model.result.GreaseManageResult;
import cn.stylefeng.guns.modular.gm.greaseManage.service.GreaseManageService;
import cn.stylefeng.guns.modular.om.productionOrdeInfo.model.params.ProductionOrdeInfoParam;
import cn.stylefeng.guns.modular.om.productionOrdeInfo.model.result.ProductionOrdeInfoResult;
import cn.stylefeng.guns.modular.om.productionOrdeInfo.service.ProductionOrdeInfoService;
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.model.params.ProductionOrderBatchInfoParam;
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.model.result.ProductionOrderBatchInfoResult;
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.service.ProductionOrderBatchInfoService;
import cn.stylefeng.guns.modular.om.productionOrderRecords.service.ProductionOrderRecordsService;
import cn.stylefeng.guns.modular.sc.repairManageInfo.model.params.RepairManageInfoParam;
import cn.stylefeng.guns.modular.sc.repairManageInfo.model.result.RepairManageInfoResult;
import cn.stylefeng.guns.modular.sc.repairManageInfo.service.RepairManageInfoService;
import cn.stylefeng.guns.modular.sc.serialNumbersConf.service.SerialNumbersConfService;
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;
import com.kangaroohy.milo.runner.subscription.SubscriptionCallback;
import com.kangaroohy.milo.service.MiloService;
import org.apache.log4j.Logger;
import org.openscada.opc.lib.da.Item;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Random;
@Component
public class StateCallback implements SubscriptionCallback {
    public MiloService miloService;
    @Autowired
    public ProductionOrdeInfoService productionOrdeInfoService;
    @Autowired
    public PassingStationCollectionService passingStationCollectionService;
    @Autowired
    public ParamCollectionService paramCollectionService;
    @Autowired
    public CollectionParamConfService collectionParamConfService;
    @Autowired
    public SerialNumbersConfService serialNumbersConfService;
    @Autowired
    private EquipmentStatusService equipmentStatusService;
    @Autowired
    private EquipmentAlarmService equipmentAlarmService;
    @Autowired
    private MaterialTraceabilityService materialTraceabilityService;
    @Autowired
    private EquipmentInfoService equipmentInfoService;
    @Autowired
    private RepairManageInfoService repairManageInfoService;
    @Autowired
    private LocationInfoService locationInfoService;
    @Autowired
    private GreaseManageService greaseManageService;
    @Autowired
    private ProductionOrderRecordsService productionOrderRecordsService;
    @Autowired
    private ProductionOrderBatchInfoService productionOrderBatchInfoService;
    private static Logger logger;
    LogUtil logUtil = new LogUtil();
    static {
        logger = Logger.getLogger(StateCallback.class);
    }
    private static Date IN_TIME = null;
    private static String S_ORDER_CODE = "";//工单编号
    private static String S_PRODUCT_CODE = "";//产品编号
    private static String S_PRODUCT_TYPE= "";//产品类型
    private static String S_SFC_CODE = "";//总成编码
    private static String PRODUCTION_LINE  = "BOP";//产线号
    private static String LOCATION_CODE  = "BOP010";//工位号
    private static List list = null;
    public StateCallback(MiloService miloService,
                         ProductionOrdeInfoService productionOrdeInfoService,
                         PassingStationCollectionService passingStationCollectionService,
                         ParamCollectionService paramCollectionService,
                         CollectionParamConfService collectionParamConfService,
                         SerialNumbersConfService serialNumbersConfService,
                         EquipmentStatusService equipmentStatusService,
                         EquipmentAlarmService equipmentAlarmService,
                         MaterialTraceabilityService materialTraceabilityService,
                         EquipmentInfoService equipmentInfoService,
                         RepairManageInfoService repairManageInfoService,
                         LocationInfoService locationInfoService,
                         GreaseManageService greaseManageService,
                         ProductionOrderRecordsService productionOrderRecordsService,
                         ProductionOrderBatchInfoService productionOrderBatchInfoService) {
        this.miloService = miloService;
        this.productionOrdeInfoService = productionOrdeInfoService;
        this.passingStationCollectionService = passingStationCollectionService;
        this.paramCollectionService = paramCollectionService;
        this.collectionParamConfService = collectionParamConfService;
        this.serialNumbersConfService = serialNumbersConfService;
        this.equipmentStatusService = equipmentStatusService;
        this.equipmentAlarmService = equipmentAlarmService;
        this.materialTraceabilityService = materialTraceabilityService;
        this.equipmentInfoService = equipmentInfoService;
        this.repairManageInfoService = repairManageInfoService;
        this.locationInfoService = locationInfoService;
        this.greaseManageService = greaseManageService;
        this.productionOrderRecordsService = productionOrderRecordsService;
        this.productionOrderBatchInfoService = productionOrderBatchInfoService;
    }
    @Override
    public void onSubscribe(String identifier, Object value) {
        String ecpStr = "";//异常记录标记
        try {
            handleInfo();
        } catch (Exception e) {
            ecpStr ="出现异常:" + logUtil.getTrace(e);
        }finally {
            if(!"".equals(ecpStr)){
                logger.info(ecpStr+"\r\n");
            }
        }
    }
    public void handleInfo() throws Exception {
        logger.info("OP100工位,handleInfo START!");
        if(null == list ){
            EquipmentInfoParam equipmentInfoParam = new EquipmentInfoParam();
            list = equipmentInfoService.findListBySpec(equipmentInfoParam);
        }
        if(null != list && list.size()>0) {
            for (int i = 0; i < list.size(); i++) {
                EquipmentInfoResult result = (EquipmentInfoResult) list.get(i);
                Item item = result.getItem();
                String value = OPCUnit.read(item);//读参数值  è®¾å¤‡çŠ¶æ€
                String equipmentNo = result.getEquipmentNo();
                EquipmentStatusParam equipmentStatusParam = new EquipmentStatusParam();
                equipmentStatusParam.setEquipmentNo(equipmentNo);
                List statuslist = equipmentStatusService.findListBySpec(equipmentStatusParam);
                if(statuslist.size()>0){
                    EquipmentStatusResult equipmentStatusResult = (EquipmentStatusResult) statuslist.get(0);
                    if(!value.equals(equipmentStatusResult.getStatus())){
                        equipmentStatusParam.setId(equipmentStatusResult.getId());
                        equipmentStatusParam.setStatus(value);
                        equipmentStatusParam.setUpdateTime(DateTool.getLocalTimeForDate());
                        equipmentStatusService.update(equipmentStatusParam);//更新设备状态
                        //添加设备报警
                        if("3".equals(value)){
                            EquipmentAlarmParam equipmentAlarmParam = new EquipmentAlarmParam();
                            equipmentAlarmParam.setEquipmentNo(equipmentNo);
                            equipmentAlarmParam.setEquipmentName(result.getEquipmentName());
                            equipmentAlarmParam.setWorkshopCode(result.getWorkshopCode());
                            equipmentAlarmParam.setProductionLineCode(result.getProductionLineCode());
                            equipmentAlarmParam.setLocationCode(result.getLocationCode());
                            equipmentAlarmParam.setErrorDesc(result.getEquipmentName()+"报警!");
                            equipmentAlarmParam.setAlarmTime(DateTool.getLocalTimeForDate());
                            equipmentAlarmService.add(equipmentAlarmParam);
                        }
                    }
                }else{
                    equipmentStatusParam.setEquipmentName(result.getEquipmentName());
                    equipmentStatusParam.setWorkshopCode(result.getWorkshopCode());
                    equipmentStatusParam.setProductionLineCode(result.getProductionLineCode());
                    equipmentStatusParam.setLocationCode(result.getLocationCode());
                    equipmentStatusParam.setStatus(value);
                    equipmentStatusParam.setUpdateTime(DateTool.getLocalTimeForDate());
                    equipmentStatusService.add(equipmentStatusParam);
                    //添加设备报警
                    if("3".equals(value)){
                        EquipmentAlarmParam equipmentAlarmParam = new EquipmentAlarmParam();
                        equipmentAlarmParam.setEquipmentNo(equipmentNo);
                        equipmentAlarmParam.setEquipmentName(result.getEquipmentName());
                        equipmentAlarmParam.setWorkshopCode(result.getWorkshopCode());
                        equipmentAlarmParam.setProductionLineCode(result.getProductionLineCode());
                        equipmentAlarmParam.setLocationCode(result.getLocationCode());
                        equipmentAlarmParam.setErrorDesc(result.getEquipmentName()+"报警!");
                        equipmentAlarmParam.setAlarmTime(DateTool.getLocalTimeForDate());
                        equipmentAlarmService.add(equipmentAlarmParam);
                    }
                }
            }
        }
        Thread.sleep(60*1000);
    }
    public void handleOilStateDOP020(String LOCATION_CODE) throws Exception {
        GreaseManageParam param = new GreaseManageParam();
        param.setLocationCode(LOCATION_CODE);
        List<GreaseManageResult> list = greaseManageService.findListBySpec(param);
        if(!list.isEmpty()) {
            String duaDate = list.get(0).getDuaDate();
            SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");
            String currentDate = format.format(new Date());
            long  daysBetween = getRemainder(currentDate,duaDate);
            if(daysBetween>0){
                ReadWriteEntity entity = new ReadWriteEntity(OPCElement.DOP020_OIL_STATE,false);
                miloService.writeToOpcUa(entity);//写PC完成
            }else{
                ReadWriteEntity entity = new ReadWriteEntity(OPCElement.DOP020_OIL_STATE,true);
                miloService.writeToOpcUa(entity);//写PC完成
            }
        }
    }
    public  void handleOilStateOP050(String LOCATION_CODE) throws Exception {
        GreaseManageParam param = new GreaseManageParam();
        param.setLocationCode(LOCATION_CODE);
        List<GreaseManageResult> list = greaseManageService.findListBySpec(param);
        if(!list.isEmpty()) {
            String duaDate = list.get(0).getDuaDate();
            SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");
            String currentDate = format.format(new Date());
            long  daysBetween = getRemainder(currentDate,duaDate);
            if(daysBetween>0){
                ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP050_OIL_STATE,false);
                miloService.writeToOpcUa(entity);//写PC完成
            }else{
                ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP050_OIL_STATE,true);
                miloService.writeToOpcUa(entity);//写PC完成
            }
        }
    }
    public  void handleOilStateBOP030(String LOCATION_CODE) throws Exception {
        GreaseManageParam param = new GreaseManageParam();
        param.setLocationCode(LOCATION_CODE);
        List<GreaseManageResult> list = greaseManageService.findListBySpec(param);
        if(!list.isEmpty()) {
            String duaDate = list.get(0).getDuaDate();
            SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");
            String currentDate = format.format(new Date());
            long  daysBetween = getRemainder(currentDate,duaDate);
            if(daysBetween>0){
                ReadWriteEntity entity = new ReadWriteEntity(OPCElement.BOP030_OIL_STATE,false);
                miloService.writeToOpcUa(entity);//写PC完成
            }else{
                ReadWriteEntity entity = new ReadWriteEntity(OPCElement.BOP030_OIL_STATE,true);
                miloService.writeToOpcUa(entity);//写PC完成
            }
        }
    }
    public static long getRemainder(String currentDate,String tableDate){
        DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyyMMdd");
        LocalDate localDate1 = LocalDate.parse(currentDate, dateFormatter);
        LocalDate localDate2 = LocalDate.parse(tableDate, dateFormatter);
        long days = ChronoUnit.DAYS.between(localDate1, localDate2);
        return days;
    }
}
guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/init/CustomRunner.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,817 @@
package cn.stylefeng.guns.plcserver.init;
import cn.stylefeng.guns.modular.bs.collectionParamConf.service.CollectionParamConfService;
import cn.stylefeng.guns.modular.bs.equipmentInfo.model.params.EquipmentInfoParam;
import cn.stylefeng.guns.modular.bs.equipmentInfo.model.result.EquipmentInfoResult;
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.service.ParamCollectionService;
import cn.stylefeng.guns.modular.cm.passingStationCollection.service.PassingStationCollectionService;
import cn.stylefeng.guns.modular.dq.materialTraceability.service.MaterialTraceabilityService;
import cn.stylefeng.guns.modular.em.equipmentAlarm.service.EquipmentAlarmService;
import cn.stylefeng.guns.modular.em.equipmentStatus.service.EquipmentStatusService;
import cn.stylefeng.guns.modular.gm.greaseManage.service.GreaseManageService;
import cn.stylefeng.guns.modular.om.productionOrdeInfo.service.ProductionOrdeInfoService;
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.service.ProductionOrderBatchInfoService;
import cn.stylefeng.guns.modular.om.productionOrderRecords.service.ProductionOrderRecordsService;
import cn.stylefeng.guns.modular.sc.repairManageInfo.service.RepairManageInfoService;
import cn.stylefeng.guns.modular.sc.serialNumbersConf.service.SerialNumbersConfService;
import cn.stylefeng.guns.plcserver.callback.*;
import cn.stylefeng.guns.plcserver.opc.GlobalVariable;
import cn.stylefeng.guns.plcserver.opc.OPCElement;
import cn.stylefeng.guns.plcserver.server.OP010.OP010ServerInterface;
import cn.stylefeng.guns.plcserver.server.OP010.impl.OP010ServerInterfaceImpl;
import com.kangaroohy.milo.service.MiloService;
import lombok.extern.slf4j.Slf4j;
import org.openscada.opc.lib.da.Item;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
@Component
@Slf4j
public class CustomRunner implements ApplicationRunner {
    @Autowired
    public MiloService miloService;
    @Autowired
    public ProductionOrdeInfoService productionOrdeInfoService;
    @Autowired
    public PassingStationCollectionService passingStationCollectionService;
    @Autowired
    public ParamCollectionService paramCollectionService;
    @Autowired
    public CollectionParamConfService collectionParamConfService;
    @Autowired
    public SerialNumbersConfService serialNumbersConfService;
    @Autowired
    private EquipmentStatusService equipmentStatusService;
    @Autowired
    private EquipmentAlarmService equipmentAlarmService;
    @Autowired
    private MaterialTraceabilityService materialTraceabilityService;
    @Autowired
    private EquipmentInfoService equipmentInfoService;
    @Autowired
    private RepairManageInfoService repairManageInfoService;
    @Autowired
    private LocationInfoService locationInfoService;
    @Autowired
    private GreaseManageService greaseManageService;
    @Autowired
    private ProductionOrderRecordsService productionOrderRecordsService;
    @Autowired
    private ProductionOrderBatchInfoService productionOrderBatchInfoService;
    private List stateLists = null;
    @Override
    public void run(ApplicationArguments args) throws Exception {
        GlobalVariable.PRODUCT_TYPE_MAP.put("12980500000198","1");//C1 36V
        GlobalVariable.PRODUCT_TYPE_MAP.put("12980500000174","2");//C1 48V
        GlobalVariable.PRODUCT_TYPE_MAP.put("12980500000194","3");//T1 36V
        GlobalVariable.PRODUCT_TYPE_MAP.put("12980500000201","4");//T1 48V
        GlobalVariable.PRODUCT_CODE_MAP.put("1","12980500000198");
        GlobalVariable.PRODUCT_CODE_MAP.put("2","12980500000174");
        GlobalVariable.PRODUCT_CODE_MAP.put("3","12980500000194");
        GlobalVariable.PRODUCT_CODE_MAP.put("4","12980500000201");
        EquipmentInfoParam equipmentInfoParam = new EquipmentInfoParam();
        List list = equipmentInfoService.findListBySpec(equipmentInfoParam);
      /*  state();*/
        init();
/*        COP010();
        COP020();
        COP030();
        BOP010();
        BOP020();
        BOP030();
        BOP030B();
        BOP040();
        BOP040B();
        DOP010();
        //DOP020();
        EOP010();
        EOP020();
        EOP030();
        EOP040();
        EOP050();
        EOP060();
        EOP070();
        EOP080();
        EOP090();
        EOP090B();
        OP010();
        OP020();
        OP030();
        OP040();
        OP050();
        OP070();
        OP080();
        OP090();
        OP100();
        OP110();
        OP120();
        OP120B();
        OP130();
        OP130B();
        OP140();
        //OP150();
        OP160();
        OP170();
        state();*/
    }
    private void init() throws Exception {
        InitCallback InitCallback = new InitCallback(miloService,productionOrdeInfoService,
                passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService,
                equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService,
                repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService,
                productionOrderBatchInfoService);
        List<String> lists = getList();
        miloService.subscriptionFromOpcUa(lists,InitCallback);
    }
    private void state() throws Exception {
        StateCallback StateCallback = new StateCallback(miloService,productionOrdeInfoService,
                passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService,
                equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService,
                repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService,
                productionOrderBatchInfoService);
        List<String> lists = new ArrayList<>();
        StateCallback.handleInfo();
        // handleOilState("DOP020");
        StateCallback.handleOilStateOP050("OP050");
        StateCallback.handleOilStateBOP030("BOP030");
    }
    private void COP010() throws Exception {
        COP010Callback COP010Callback = new COP010Callback(miloService,productionOrdeInfoService,
                passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService,
                equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService,
                repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService,
                productionOrderBatchInfoService);
        List<String> lists = new ArrayList<>();
        lists.add(OPCElement.COP010_F_HEART_BEAT);
        lists.add(OPCElement.COP010_J_PLC_START);
        lists.add(OPCElement.COP010_J_PLC_FINISH);
        miloService.subscriptionFromOpcUa(lists,COP010Callback);
        System.out.println("1");
    }
    private void COP020() throws Exception {
        COP020Callback COP020Callback = new COP020Callback(miloService,productionOrdeInfoService,
                passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService,
                equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService,
                repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService,
                productionOrderBatchInfoService);
        List<String> lists = new ArrayList<>();
        lists.add(OPCElement.COP020_F_HEART_BEAT);
        lists.add(OPCElement.COP020_J_PLC_START);
        lists.add(OPCElement.COP020_J_PLC_FINISH);
        miloService.subscriptionFromOpcUa(lists,COP020Callback);
    }
    private void COP030() throws Exception {
        COP030Callback COP030Callback = new COP030Callback(miloService,productionOrdeInfoService,
                passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService,
                equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService,
                repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService,
                productionOrderBatchInfoService);
        List<String> lists = new ArrayList<>();
        lists.add(OPCElement.COP030_F_HEART_BEAT);
        lists.add(OPCElement.COP030_J_PLC_START);
        lists.add(OPCElement.COP030_J_PLC_FINISH);
        miloService.subscriptionFromOpcUa(lists,COP030Callback);
    }
    private void BOP010() throws Exception {
        BOP010Callback BOP010Callback = new BOP010Callback(miloService,productionOrdeInfoService,
                passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService,
                equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService,
                repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService,
                productionOrderBatchInfoService);
        List<String> lists = new ArrayList<>();
        lists.add(OPCElement.BOP010_F_HEART_BEAT);
        lists.add(OPCElement.BOP010_J_PLC_START);
        lists.add(OPCElement.BOP010_J_PLC_FINISH);
        miloService.subscriptionFromOpcUa(lists,BOP010Callback);
    }
    private void BOP020() throws Exception {
        BOP020Callback BOP020Callback = new BOP020Callback(miloService,productionOrdeInfoService,
                passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService,
                equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService,
                repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService,
                productionOrderBatchInfoService);
        List<String> lists = new ArrayList<>();
        lists.add(OPCElement.BOP020_F_HEART_BEAT);
        lists.add(OPCElement.BOP020_J_PLC_START);
        lists.add(OPCElement.BOP020_J_PLC_FINISH);
        miloService.subscriptionFromOpcUa(lists,BOP020Callback);
    }
    private void BOP030() throws Exception {
        BOP030Callback BOP030Callback = new BOP030Callback(miloService,productionOrdeInfoService,
                passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService,
                equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService,
                repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService,
                productionOrderBatchInfoService);
        List<String> lists = new ArrayList<>();
        lists.add(OPCElement.BOP030_F_HEART_BEAT);
        lists.add(OPCElement.BOP030_J_PLC_START);
        lists.add(OPCElement.BOP030_J_PLC_FINISH);
        miloService.subscriptionFromOpcUa(lists,BOP030Callback);
    }
    private void BOP030B() throws Exception {
        BOP030BCallback BOP030BCallback = new BOP030BCallback(miloService,productionOrdeInfoService,
                passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService,
                equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService,
                repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService,
                productionOrderBatchInfoService);
        List<String> lists = new ArrayList<>();
        lists.add(OPCElement.BOP030B_F_HEART_BEAT);
        lists.add(OPCElement.BOP030B_J_PLC_START);
        lists.add(OPCElement.BOP030B_J_PLC_FINISH);
        miloService.subscriptionFromOpcUa(lists,BOP030BCallback);
    }
    private void BOP040() throws Exception {
        BOP040Callback BOP040Callback = new BOP040Callback(miloService,productionOrdeInfoService,
                passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService,
                equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService,
                repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService,
                productionOrderBatchInfoService);
        List<String> lists = new ArrayList<>();
        lists.add(OPCElement.BOP040_F_HEART_BEAT);
        lists.add(OPCElement.BOP040_J_PLC_START);
        lists.add(OPCElement.BOP040_J_PLC_FINISH);
        miloService.subscriptionFromOpcUa(lists,BOP040Callback);
    }
    private void BOP040B() throws Exception {
        BOP040BCallback BOP040BCallback = new BOP040BCallback(miloService,productionOrdeInfoService,
                passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService,
                equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService,
                repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService,
                productionOrderBatchInfoService);
        List<String> lists = new ArrayList<>();
        lists.add(OPCElement.BOP040B_F_HEART_BEAT);
        lists.add(OPCElement.BOP040B_J_PLC_START);
        lists.add(OPCElement.BOP040B_J_PLC_FINISH);
        miloService.subscriptionFromOpcUa(lists,BOP040BCallback);
    }
    private void DOP010() throws Exception {
        DOP010Callback DOP010Callback = new DOP010Callback(miloService,productionOrdeInfoService,
                passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService,
                equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService,
                repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService,
                productionOrderBatchInfoService);
        List<String> lists = new ArrayList<>();
        lists.add(OPCElement.DOP010_F_HEART_BEAT);
        lists.add(OPCElement.DOP010_J_PLC_START);
        lists.add(OPCElement.DOP010_J_PLC_FINISH);
        miloService.subscriptionFromOpcUa(lists,DOP010Callback);
    }
    private void DOP020() throws Exception {
        DOP020Callback DOP020Callback = new DOP020Callback(miloService,productionOrdeInfoService,
                passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService,
                equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService,
                repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService,
                productionOrderBatchInfoService);
        List<String> lists = new ArrayList<>();
        lists.add(OPCElement.DOP020_F_HEART_BEAT);
        lists.add(OPCElement.DOP020_J_PLC_START);
        lists.add(OPCElement.DOP020_J_PLC_FINISH);
        miloService.subscriptionFromOpcUa(lists,DOP020Callback);
    }
    private void EOP010() throws Exception {
        EOP010Callback EOP010Callback = new EOP010Callback(miloService,productionOrdeInfoService,
                passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService,
                equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService,
                repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService,
                productionOrderBatchInfoService);
        List<String> lists = new ArrayList<>();
        lists.add(OPCElement.EOP010_F_HEART_BEAT);
        lists.add(OPCElement.EOP010_J_PLC_START);
        lists.add(OPCElement.EOP010_J_PLC_FINISH);
        miloService.subscriptionFromOpcUa(lists,EOP010Callback);
    }
    private void EOP020() throws Exception {
        EOP020Callback EOP020Callback = new EOP020Callback(miloService,productionOrdeInfoService,
                passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService,
                equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService,
                repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService,
                productionOrderBatchInfoService);
        List<String> lists = new ArrayList<>();
        lists.add(OPCElement.EOP020_F_HEART_BEAT);
        lists.add(OPCElement.EOP020_J_PLC_START);
        lists.add(OPCElement.EOP020_J_PLC_FINISH);
        miloService.subscriptionFromOpcUa(lists,EOP020Callback);
    }
    private void EOP030() throws Exception {
        EOP030Callback EOP030Callback = new EOP030Callback(miloService,productionOrdeInfoService,
                passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService,
                equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService,
                repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService,
                productionOrderBatchInfoService);
        List<String> lists = new ArrayList<>();
        lists.add(OPCElement.EOP030_F_HEART_BEAT);
        lists.add(OPCElement.EOP030_J_PLC_START);
        lists.add(OPCElement.EOP030_J_PLC_FINISH);
        miloService.subscriptionFromOpcUa(lists,EOP030Callback);
    }
    private void EOP040() throws Exception {
        EOP040Callback EOP040Callback = new EOP040Callback(miloService,productionOrdeInfoService,
                passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService,
                equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService,
                repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService,
                productionOrderBatchInfoService);
        List<String> lists = new ArrayList<>();
        lists.add(OPCElement.EOP040_F_HEART_BEAT);
        lists.add(OPCElement.EOP040_J_PLC_START);
        lists.add(OPCElement.EOP040_J_PLC_FINISH);
        miloService.subscriptionFromOpcUa(lists,EOP040Callback);
    }
    private void EOP050() throws Exception {
        EOP050Callback EOP050Callback = new EOP050Callback(miloService,productionOrdeInfoService,
                passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService,
                equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService,
                repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService,
                productionOrderBatchInfoService);
        List<String> lists = new ArrayList<>();
        lists.add(OPCElement.EOP050_F_HEART_BEAT);
        lists.add(OPCElement.EOP050_J_PLC_START);
        lists.add(OPCElement.EOP050_J_PLC_FINISH);
        miloService.subscriptionFromOpcUa(lists,EOP050Callback);
    }
    private void EOP060() throws Exception {
        EOP060Callback EOP060Callback = new EOP060Callback(miloService,productionOrdeInfoService,
                passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService,
                equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService,
                repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService,
                productionOrderBatchInfoService);
        List<String> lists = new ArrayList<>();
        lists.add(OPCElement.EOP060_F_HEART_BEAT);
        lists.add(OPCElement.EOP060_J_PLC_START);
        lists.add(OPCElement.EOP060_J_PLC_FINISH);
        miloService.subscriptionFromOpcUa(lists,EOP060Callback);
    }
    private void EOP070() throws Exception {
        EOP070Callback EOP070Callback = new EOP070Callback(miloService,productionOrdeInfoService,
                passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService,
                equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService,
                repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService,
                productionOrderBatchInfoService);
        List<String> lists = new ArrayList<>();
        lists.add(OPCElement.EOP070_F_HEART_BEAT);
        lists.add(OPCElement.EOP070_J_PLC_START);
        lists.add(OPCElement.EOP070_J_PLC_FINISH);
        miloService.subscriptionFromOpcUa(lists,EOP070Callback);
    }
    private void EOP080() throws Exception {
        EOP080Callback EOP080Callback = new EOP080Callback(miloService,productionOrdeInfoService,
                passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService,
                equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService,
                repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService,
                productionOrderBatchInfoService);
        List<String> lists = new ArrayList<>();
        lists.add(OPCElement.EOP080_F_HEART_BEAT);
        lists.add(OPCElement.EOP080_J_PLC_START);
        lists.add(OPCElement.EOP080_J_PLC_FINISH);
        miloService.subscriptionFromOpcUa(lists,EOP080Callback);
    }
    private void EOP090() throws Exception {
        EOP090Callback EOP090Callback = new EOP090Callback(miloService,productionOrdeInfoService,
                passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService,
                equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService,
                repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService,
                productionOrderBatchInfoService);
        List<String> lists = new ArrayList<>();
        lists.add(OPCElement.EOP090_F_HEART_BEAT);
        lists.add(OPCElement.EOP090_J_PLC_START);
        lists.add(OPCElement.EOP090_J_PLC_FINISH);
        miloService.subscriptionFromOpcUa(lists,EOP090Callback);
    }
    private void EOP090B() throws Exception {
        EOP090BCallback EOP090BCallback = new EOP090BCallback(miloService,productionOrdeInfoService,
                passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService,
                equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService,
                repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService,
                productionOrderBatchInfoService);
        List<String> lists = new ArrayList<>();
        lists.add(OPCElement.EOP090B_F_HEART_BEAT);
        lists.add(OPCElement.EOP090B_J_PLC_START);
        lists.add(OPCElement.EOP090B_J_PLC_FINISH);
        miloService.subscriptionFromOpcUa(lists,EOP090BCallback);
    }
    private void OP010() throws Exception {
        OP010Callback OP010Callback = new OP010Callback(miloService,productionOrdeInfoService,
                passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService,
                equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService,
                repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService,
                productionOrderBatchInfoService);
        List<String> lists = new ArrayList<>();
        lists.add(OPCElement.OP010_F_HEART_BEAT);
        lists.add(OPCElement.OP010_J_PLC_START);
        lists.add(OPCElement.OP010_J_PLC_FINISH);
        miloService.subscriptionFromOpcUa(lists,OP010Callback);
    }
    private void OP020() throws Exception {
        OP020Callback OP020Callback = new OP020Callback(miloService,productionOrdeInfoService,
                passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService,
                equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService,
                repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService,
                productionOrderBatchInfoService);
        List<String> lists = new ArrayList<>();
        lists.add(OPCElement.OP020_F_HEART_BEAT);
        lists.add(OPCElement.OP020_J_PLC_START);
        lists.add(OPCElement.OP020_J_PLC_FINISH);
        miloService.subscriptionFromOpcUa(lists,OP020Callback);
    }
    private void OP030() throws Exception {
        OP030Callback OP030Callback = new OP030Callback(miloService,productionOrdeInfoService,
                passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService,
                equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService,
                repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService,
                productionOrderBatchInfoService);
        List<String> lists = new ArrayList<>();
        lists.add(OPCElement.OP030_F_HEART_BEAT);
        lists.add(OPCElement.OP030_J_PLC_START);
        lists.add(OPCElement.OP030_J_PLC_FINISH);
        miloService.subscriptionFromOpcUa(lists,OP030Callback);
    }
    private void OP040() throws Exception {
        OP040Callback OP040Callback = new OP040Callback(miloService,productionOrdeInfoService,
                passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService,
                equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService,
                repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService,
                productionOrderBatchInfoService);
        List<String> lists = new ArrayList<>();
        lists.add(OPCElement.OP040_F_HEART_BEAT);
        lists.add(OPCElement.OP040_J_PLC_START);
        lists.add(OPCElement.OP040_J_PLC_FINISH);
        miloService.subscriptionFromOpcUa(lists,OP040Callback);
    }
    private void OP050() throws Exception {
        OP050Callback OP050Callback = new OP050Callback(miloService,productionOrdeInfoService,
                passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService,
                equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService,
                repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService,
                productionOrderBatchInfoService);
        List<String> lists = new ArrayList<>();
        lists.add(OPCElement.OP050_F_HEART_BEAT);
        lists.add(OPCElement.OP050_J_PLC_START);
        lists.add(OPCElement.OP050_J_PLC_FINISH);
        miloService.subscriptionFromOpcUa(lists,OP050Callback);
    }
    private void OP070() throws Exception {
        OP070Callback OP070Callback = new OP070Callback(miloService,productionOrdeInfoService,
                passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService,
                equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService,
                repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService,
                productionOrderBatchInfoService);
        List<String> lists = new ArrayList<>();
        lists.add(OPCElement.OP070_F_HEART_BEAT);
        lists.add(OPCElement.OP070_J_PLC_START);
        lists.add(OPCElement.OP070_J_PLC_FINISH);
        miloService.subscriptionFromOpcUa(lists,OP070Callback);
    }
    private void OP080() throws Exception {
        OP080Callback OP080Callback = new OP080Callback(miloService,productionOrdeInfoService,
                passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService,
                equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService,
                repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService,
                productionOrderBatchInfoService);
        List<String> lists = new ArrayList<>();
        lists.add(OPCElement.OP080_F_HEART_BEAT);
        lists.add(OPCElement.OP080_J_PLC_START);
        lists.add(OPCElement.OP080_J_PLC_FINISH);
        miloService.subscriptionFromOpcUa(lists,OP080Callback);
    }
    private void OP090() throws Exception {
        OP090Callback OP090Callback = new OP090Callback(miloService,productionOrdeInfoService,
                passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService,
                equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService,
                repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService,
                productionOrderBatchInfoService);
        List<String> lists = new ArrayList<>();
        lists.add(OPCElement.OP090_F_HEART_BEAT);
        lists.add(OPCElement.OP090_J_PLC_START);
        lists.add(OPCElement.OP090_J_PLC_FINISH);
        miloService.subscriptionFromOpcUa(lists,OP090Callback);
    }
    private void OP100() throws Exception {
        OP100Callback OP100Callback = new OP100Callback(miloService,productionOrdeInfoService,
                passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService,
                equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService,
                repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService,
                productionOrderBatchInfoService);
        List<String> lists = new ArrayList<>();
        lists.add(OPCElement.OP100_F_HEART_BEAT);
        lists.add(OPCElement.OP100_J_PLC_START);
        lists.add(OPCElement.OP100_J_PLC_FINISH);
        miloService.subscriptionFromOpcUa(lists,OP100Callback);
    }
    private void OP110() throws Exception {
        OP110Callback OP110Callback = new OP110Callback(miloService,productionOrdeInfoService,
                passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService,
                equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService,
                repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService,
                productionOrderBatchInfoService);
        List<String> lists = new ArrayList<>();
        lists.add(OPCElement.OP110_F_HEART_BEAT);
        lists.add(OPCElement.OP110_J_PLC_START);
        lists.add(OPCElement.OP110_J_PLC_FINISH);
        miloService.subscriptionFromOpcUa(lists,OP110Callback);
    }
    private void OP120() throws Exception {
        OP120Callback OP120Callback = new OP120Callback(miloService,productionOrdeInfoService,
                passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService,
                equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService,
                repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService,
                productionOrderBatchInfoService);
        List<String> lists = new ArrayList<>();
        lists.add(OPCElement.OP120_F_HEART_BEAT);
        lists.add(OPCElement.OP120_J_PLC_START);
        lists.add(OPCElement.OP120_J_PLC_FINISH);
        miloService.subscriptionFromOpcUa(lists,OP120Callback);
    }
    private void OP120B() throws Exception {
        OP120BCallback OP120BCallback = new OP120BCallback(miloService,productionOrdeInfoService,
                passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService,
                equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService,
                repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService,
                productionOrderBatchInfoService);
        List<String> lists = new ArrayList<>();
        lists.add(OPCElement.OP120B_F_HEART_BEAT);
        lists.add(OPCElement.OP120B_J_PLC_START);
        lists.add(OPCElement.OP120B_J_PLC_FINISH);
        miloService.subscriptionFromOpcUa(lists,OP120BCallback);
    }
    private void OP130() throws Exception {
        OP130Callback OP130Callback = new OP130Callback(miloService,productionOrdeInfoService,
                passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService,
                equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService,
                repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService,
                productionOrderBatchInfoService);
        List<String> lists = new ArrayList<>();
        lists.add(OPCElement.OP130_F_HEART_BEAT);
        lists.add(OPCElement.OP130_J_PLC_START);
        lists.add(OPCElement.OP130_J_PLC_FINISH);
        miloService.subscriptionFromOpcUa(lists,OP130Callback);
    }
    private void OP130B() throws Exception {
        OP130BCallback OP130BCallback = new OP130BCallback(miloService,productionOrdeInfoService,
                passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService,
                equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService,
                repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService,
                productionOrderBatchInfoService);
        List<String> lists = new ArrayList<>();
        lists.add(OPCElement.OP130B_F_HEART_BEAT);
        lists.add(OPCElement.OP130B_J_PLC_START);
        lists.add(OPCElement.OP130B_J_PLC_FINISH);
        miloService.subscriptionFromOpcUa(lists,OP130BCallback);
    }
    private void OP140() throws Exception {
        OP140Callback OP140Callback = new OP140Callback(miloService,productionOrdeInfoService,
                passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService,
                equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService,
                repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService,
                productionOrderBatchInfoService);
        List<String> lists = new ArrayList<>();
        lists.add(OPCElement.OP140_F_HEART_BEAT);
        lists.add(OPCElement.OP140_J_PLC_START);
        lists.add(OPCElement.OP140_J_PLC_FINISH);
        miloService.subscriptionFromOpcUa(lists,OP140Callback);
    }
    private void OP150() throws Exception {
        OP150Callback OP150Callback = new OP150Callback(miloService,productionOrdeInfoService,
                passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService,
                equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService,
                repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService,
                productionOrderBatchInfoService);
        List<String> lists = new ArrayList<>();
        lists.add(OPCElement.OP150_F_HEART_BEAT);
        lists.add(OPCElement.OP150_J_PLC_START);
        lists.add(OPCElement.OP150_J_PLC_FINISH);
        miloService.subscriptionFromOpcUa(lists,OP150Callback);
    }
    private void OP160() throws Exception {
        OP160Callback OP160Callback = new OP160Callback(miloService,productionOrdeInfoService,
                passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService,
                equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService,
                repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService,
                productionOrderBatchInfoService);
        List<String> lists = new ArrayList<>();
        lists.add(OPCElement.OP160_F_HEART_BEAT);
        lists.add(OPCElement.OP160_J_PLC_START);
        lists.add(OPCElement.OP160_J_PLC_FINISH);
        miloService.subscriptionFromOpcUa(lists,OP160Callback);
    }
    private void OP170() throws Exception {
        OP170Callback OP170Callback = new OP170Callback(miloService,productionOrdeInfoService,
                passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService,
                equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService,
                repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService,
                productionOrderBatchInfoService);
        List<String> lists = new ArrayList<>();
        lists.add(OPCElement.OP170_F_HEART_BEAT);
        lists.add(OPCElement.OP170_J_PLC_START);
        lists.add(OPCElement.OP170_J_PLC_FINISH);
        miloService.subscriptionFromOpcUa(lists,OP170Callback);
    }
    public List<String> getList(){
        List<String> lists = new ArrayList<>();
        lists.add(OPCElement.COP010_F_HEART_BEAT);
        lists.add(OPCElement.COP010_J_PLC_START);
        lists.add(OPCElement.COP010_J_PLC_FINISH);
        lists.add(OPCElement.COP020_F_HEART_BEAT);
        lists.add(OPCElement.COP020_J_PLC_START);
        lists.add(OPCElement.COP020_J_PLC_FINISH);
        lists.add(OPCElement.COP030_F_HEART_BEAT);
        lists.add(OPCElement.COP030_J_PLC_START);
        lists.add(OPCElement.COP030_J_PLC_FINISH);
        lists.add(OPCElement.BOP010_F_HEART_BEAT);
        lists.add(OPCElement.BOP010_J_PLC_START);
        lists.add(OPCElement.BOP010_J_PLC_FINISH);
        lists.add(OPCElement.BOP020_F_HEART_BEAT);
        lists.add(OPCElement.BOP020_J_PLC_START);
        lists.add(OPCElement.BOP020_J_PLC_FINISH);
        lists.add(OPCElement.BOP030_F_HEART_BEAT);
        lists.add(OPCElement.BOP030_J_PLC_START);
        lists.add(OPCElement.BOP030_J_PLC_FINISH);
        lists.add(OPCElement.BOP030B_F_HEART_BEAT);
        lists.add(OPCElement.BOP030B_J_PLC_START);
        lists.add(OPCElement.BOP030B_J_PLC_FINISH);
        lists.add(OPCElement.BOP040_F_HEART_BEAT);
        lists.add(OPCElement.BOP040_J_PLC_START);
        lists.add(OPCElement.BOP040_J_PLC_FINISH);
        lists.add(OPCElement.BOP040B_F_HEART_BEAT);
        lists.add(OPCElement.BOP040B_J_PLC_START);
        lists.add(OPCElement.BOP040B_J_PLC_FINISH);
        lists.add(OPCElement.DOP010_F_HEART_BEAT);
        lists.add(OPCElement.DOP010_J_PLC_START);
        lists.add(OPCElement.DOP010_J_PLC_FINISH);
    /*    lists.add(OPCElement.DOP020_F_HEART_BEAT);
        lists.add(OPCElement.DOP020_J_PLC_START);
        lists.add(OPCElement.DOP020_J_PLC_FINISH);*/
        lists.add(OPCElement.EOP010_F_HEART_BEAT);
        lists.add(OPCElement.EOP010_J_PLC_START);
        lists.add(OPCElement.EOP010_J_PLC_FINISH);
        lists.add(OPCElement.EOP020_F_HEART_BEAT);
        lists.add(OPCElement.EOP020_J_PLC_START);
        lists.add(OPCElement.EOP020_J_PLC_FINISH);
        lists.add(OPCElement.EOP030_F_HEART_BEAT);
        lists.add(OPCElement.EOP030_J_PLC_START);
        lists.add(OPCElement.EOP030_J_PLC_FINISH);
        lists.add(OPCElement.EOP040_F_HEART_BEAT);
        lists.add(OPCElement.EOP040_J_PLC_START);
        lists.add(OPCElement.EOP040_J_PLC_FINISH);
        lists.add(OPCElement.EOP050_F_HEART_BEAT);
        lists.add(OPCElement.EOP050_J_PLC_START);
        lists.add(OPCElement.EOP050_J_PLC_FINISH);
        lists.add(OPCElement.EOP060_F_HEART_BEAT);
        lists.add(OPCElement.EOP060_J_PLC_START);
        lists.add(OPCElement.EOP060_J_PLC_FINISH);
        lists.add(OPCElement.EOP070_F_HEART_BEAT);
        lists.add(OPCElement.EOP070_J_PLC_START);
        lists.add(OPCElement.EOP070_J_PLC_FINISH);
        lists.add(OPCElement.EOP070_F_HEART_BEAT);
        lists.add(OPCElement.EOP070_J_PLC_START);
        lists.add(OPCElement.EOP070_J_PLC_FINISH);
        lists.add(OPCElement.EOP090_F_HEART_BEAT);
        lists.add(OPCElement.EOP090_J_PLC_START);
        lists.add(OPCElement.EOP090_J_PLC_FINISH);
        lists.add(OPCElement.EOP090B_F_HEART_BEAT);
        lists.add(OPCElement.EOP090B_J_PLC_START);
        lists.add(OPCElement.EOP090B_J_PLC_FINISH);
        lists.add(OPCElement.OP010_F_HEART_BEAT);
        lists.add(OPCElement.OP010_J_PLC_START);
        lists.add(OPCElement.OP010_J_PLC_FINISH);
        lists.add(OPCElement.OP020_F_HEART_BEAT);
        lists.add(OPCElement.OP020_J_PLC_START);
        lists.add(OPCElement.OP020_J_PLC_FINISH);
        lists.add(OPCElement.OP030_F_HEART_BEAT);
        lists.add(OPCElement.OP030_J_PLC_START);
        lists.add(OPCElement.OP030_J_PLC_FINISH);
        lists.add(OPCElement.OP040_F_HEART_BEAT);
        lists.add(OPCElement.OP040_J_PLC_START);
        lists.add(OPCElement.OP040_J_PLC_FINISH);
        lists.add(OPCElement.OP050_F_HEART_BEAT);
        lists.add(OPCElement.OP050_J_PLC_START);
        lists.add(OPCElement.OP050_J_PLC_FINISH);
        lists.add(OPCElement.OP070_F_HEART_BEAT);
        lists.add(OPCElement.OP070_J_PLC_START);
        lists.add(OPCElement.OP070_J_PLC_FINISH);
        lists.add(OPCElement.OP080_F_HEART_BEAT);
        lists.add(OPCElement.OP080_J_PLC_START);
        lists.add(OPCElement.OP080_J_PLC_FINISH);
        lists.add(OPCElement.OP090_F_HEART_BEAT);
        lists.add(OPCElement.OP090_J_PLC_START);
        lists.add(OPCElement.OP090_J_PLC_FINISH);
        lists.add(OPCElement.OP100_F_HEART_BEAT);
        lists.add(OPCElement.OP100_J_PLC_START);
        lists.add(OPCElement.OP100_J_PLC_FINISH);
        lists.add(OPCElement.OP110_F_HEART_BEAT);
        lists.add(OPCElement.OP110_J_PLC_START);
        lists.add(OPCElement.OP110_J_PLC_FINISH);
        lists.add(OPCElement.OP120_F_HEART_BEAT);
        lists.add(OPCElement.OP120_J_PLC_START);
        lists.add(OPCElement.OP120_J_PLC_FINISH);
        lists.add(OPCElement.OP120B_F_HEART_BEAT);
        lists.add(OPCElement.OP120B_J_PLC_START);
        lists.add(OPCElement.OP120B_J_PLC_FINISH);
        lists.add(OPCElement.OP130_F_HEART_BEAT);
        lists.add(OPCElement.OP130_J_PLC_START);
        lists.add(OPCElement.OP130_J_PLC_FINISH);
        lists.add(OPCElement.OP130B_F_HEART_BEAT);
        lists.add(OPCElement.OP130B_J_PLC_START);
        lists.add(OPCElement.OP130B_J_PLC_FINISH);
        lists.add(OPCElement.OP140_F_HEART_BEAT);
        lists.add(OPCElement.OP140_J_PLC_START);
        lists.add(OPCElement.OP140_J_PLC_FINISH);
     /*   lists.add(OPCElement.OP150_F_HEART_BEAT);
        lists.add(OPCElement.OP150_J_PLC_START);
        lists.add(OPCElement.OP150_J_PLC_FINISH);*/
        lists.add(OPCElement.OP160_F_HEART_BEAT);
        lists.add(OPCElement.OP160_J_PLC_START);
        lists.add(OPCElement.OP160_J_PLC_FINISH);
        lists.add(OPCElement.OP170_F_HEART_BEAT);
        lists.add(OPCElement.OP170_J_PLC_START);
        lists.add(OPCElement.OP170_J_PLC_FINISH);
        if(null == stateLists ){
            EquipmentInfoParam equipmentInfoParam = new EquipmentInfoParam();
            stateLists = equipmentInfoService.findListBySpec(equipmentInfoParam);
        }
        if(!stateLists.isEmpty()){
            for(int i=0;i<stateLists.size();i++) {
                EquipmentInfoResult result = (EquipmentInfoResult) stateLists.get(i);
                if(null != result.getSpareField1()){
                    lists.add(result.getSpareField1());
                }
            }
        }
        return lists;
    }
}
guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/opc/GlobalVariable.java
@@ -5,9 +5,9 @@
public class GlobalVariable {
//    public static boolean TERMINATED = false;
    public static boolean TERMINATED = false;
    public static boolean TERMINATED = true;
//    public static boolean TERMINATED = true;
    public static int SLEEP_TIME = 1000;
guns-vip-main/src/main/resources/application.yml
@@ -34,5 +34,15 @@
      id-type: assign_id
      table-underline: true
kangaroohy:
  milo:
    enabled: true
    primary: default
    config:
      default:
        endpoint: opc.tcp://127.0.0.1:49320
        security-policy: none
log:
  path: _app_logs
  path: _app_logs