cl
2024-01-16 cf6bff3922bbd0624b98834f6ea85c8e619e564f
guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/server/OP090/impl/OP090ServerInterfaceImpl.java
@@ -7,8 +7,16 @@
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.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.plcserver.opc.GlobalVariable;
import cn.stylefeng.guns.plcserver.opc.OPCComm;
import cn.stylefeng.guns.plcserver.opc.unit.OPCUnit;
@@ -45,10 +53,34 @@
    private static String GROUP_NAME  = "OP090_P";//组名
    private static List list = null;
    private static Group group = null;
    private int count = 0;
    /**
     * 设置心跳标志位,保存到全局变量
     */
    public void setHeartbeat(String value) {
        if ("false".equals(value)) {
            OPCUnit.write(opc.getOP090_F_HEART_BEAT(), "true");
            GlobalVariable.OP090_F_HEART_BEAT = true;
            count = 0;
        } else {
            count++;
        }
        // 循环读取频率是:500ms一次,如果超过6次,也就是3s认定超时
        if (count > GlobalVariable.HEART_MAX_COUNT) {
            GlobalVariable.OP090_F_HEART_BEAT = false;
        }
    }
    @Override
    public synchronized void monitor() {
        String ecpStr = "";//异常记录标记
        try{
            String isHeartBeat = OPCUnit.read(opc.getOP090_F_HEART_BEAT());
            setHeartbeat(isHeartBeat);
            if(GlobalVariable.OP090_F_HEART_BEAT) {
                //PC读工单
                String isPLCStart = OPCUnit.read(opc.getOP090_J_PLC_START());//PLC开始
@@ -65,6 +97,7 @@
                if(isPLCFinish.equals("true")){
                    String isFinish = OPCUnit.read(opc.getOP090_J_PC_FINISH());//PC操作完成
                    if(isFinish.equals("false")){
                        handleMaterial();
                        handleInfo();
                        handleFinsh();
                    }
@@ -92,6 +125,61 @@
        S_SFC_CODE = OPCUnit.read(opc.getOP090_S_SFC_CODE());//总成编码
        OPCUnit.write(opc.getOP090_J_PC_WRITE_ORDER(), "true"); //PC读工单完成
        logger.info("OP090工位,handleOrder PC处理完成!");
    }
    public void handleMaterial() {
        if("".equals(S_ORDER_CODE)){
            IN_TIME = DateTool.getLocalTimeForDate();
            S_ORDER_CODE = OPCUnit.read(opc.getOP090_S_ORDER_CODE());//工单编号
            S_PRODUCT_TYPE = OPCUnit.read(opc.getOP090_S_PRODUCT_CODE());//产品编号
            S_PRODUCT_CODE = GlobalVariable.PRODUCT_CODE_MAP.get(S_PRODUCT_TYPE);
            S_SFC_CODE = OPCUnit.read(opc.getOP090_S_SFC_CODE());//总成编码
        }
        //查询批次上料信息
        ProductionOrderBatchInfoParam productionOrderBatchInfoParam = new ProductionOrderBatchInfoParam();
        productionOrderBatchInfoParam.setWorkOrderNo(S_ORDER_CODE);
        productionOrderBatchInfoParam.setLocationCode(LOCATION_CODE);
        ProductionOrderBatchInfoService productionOrderBatchInfoService = opc.productionOrderBatchInfoService;
        List<ProductionOrderBatchInfoResult> list1 = productionOrderBatchInfoService.findListBySpec(productionOrderBatchInfoParam);
        for(int i=0;i<list1.size();i++){
            ProductionOrderBatchInfoResult productionOrderBatchInfoResult = list1.get(i);
            //判断是否有该工位
            String[] locationCodes = productionOrderBatchInfoResult.getLocationCode().split("/");
            logger.info("当前工位:"+locationCodes.toString());
            boolean isLocationCode = false;
            if(locationCodes.length>0)
            {
                for (int j=0;j<locationCodes.length;j++){
                    String location = locationCodes[j];
                    if(location.equals(LOCATION_CODE)){
                        isLocationCode = true;
                    }
                }
            }
            int remainingQuantity =  productionOrderBatchInfoResult.getResidueQuantity();//剩余数量
            if(remainingQuantity>0 && isLocationCode){
                //新增物料追溯
                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 materialTraceabilityService = opc.materialTraceabilityService;
                materialTraceabilityService.add(materialTraceabilityParam);
                //更新剩余数量
                productionOrderBatchInfoParam.setId(productionOrderBatchInfoResult.getId());
                productionOrderBatchInfoParam.setResidueQuantity(remainingQuantity-1);//剩余数量
                productionOrderBatchInfoService.update(productionOrderBatchInfoParam);
            }
        }
    }
    //PC读参数信息
@@ -184,6 +272,39 @@
        ParamCollectionService paramCollectionService = opc.paramCollectionService;
        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 =
                opc.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);
            ProductionOrderRecordsService productionOrderRecordsService = opc.productionOrderRecordsService;
            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);
            }
        }
        OPCUnit.write(opc.getOP090_J_PC_FINISH(), "true"); //PC完成
        logger.info("OP090工位,handleFinsh PC处理完成!");