cl
2024-07-04 ef58b9f5268fb32189123bc39d8c69e41612befb
jcdm-main/src/main/java/com/jcdm/main/da/paramCollection/service/impl/DaParamCollectionServiceImpl.java
@@ -265,15 +265,12 @@
    @Override
    public void saveCampaignTimeParameters(DaParamCollection daParamCollection) {
//        List<BsFormulaChildInfo> list = bsFormulaChildInfoService.list(new LambdaQueryWrapper<BsFormulaChildInfo>()
//                .eq(BsFormulaChildInfo::getProcessesCode, daParamCollection.getLocationCode())
//                .eq(BsFormulaChildInfo::getSpareField4, "1")
//        );
        BsFormulaChildInfo childInfo = daParamCollection.getFormulaChildEntity();
        if(StringUtils.isNotBlank(childInfo.getResults())){
            if(!childInfo.getResults().equals("OK")){
                try {
                    miloService.writeToOpcShort(ReadWriteEntity.builder().identifier("PACK."+daParamCollection.getLocationCode()+".RecordDataDone").value(22).build());
                    miloService.writeToOpcShort(ReadWriteEntity.builder().identifier("MOZU1."+daParamCollection.getLocationCode()+".RecordDataDone").value(22).build());
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
@@ -281,35 +278,16 @@
            }
        }else {
            try {
                miloService.writeToOpcShort(ReadWriteEntity.builder().identifier("PACK."+daParamCollection.getLocationCode()+".RecordDataDone").value(22).build());
                miloService.writeToOpcShort(ReadWriteEntity.builder().identifier("MOZU1."+daParamCollection.getLocationCode()+".RecordDataDone").value(22).build());
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
            return;
        }
//        BsFormulaChildInfo bsFormulaChildInfo = new BsFormulaChildInfo();
//        bsFormulaChildInfo.setProcessesCode(daParamCollection.getLocationCode());
//        bsFormulaChildInfo.setProductCode(daParamCollection.getProductCode());
//        bsFormulaChildInfo.setSpareField4("1");
//        List<BsFormulaChildInfo> bsFormulaChildInfos = bsFormulaChildInfoMapper.selectBsFormulaChildInfoList(bsFormulaChildInfo);
        String result = childInfo.getResults();
        if(result != null && !result.isEmpty()){
            try {
//                //更新参数采集配置表
//                DaCollectionParamConf daCollectionParamConf = new DaCollectionParamConf();
//                daCollectionParamConf.setProcessesCode(daParamCollection.getLocationCode());
//                daCollectionParamConf.setCollectParameterId("OUTT");
//                List<DaCollectionParamConf> daCollectionParamConfs = daCollectionParamConfMapper.selectDaCollectionParamConfList(daCollectionParamConf);
//                DaParamCollection saveData = new DaParamCollection();
//                saveData.setWorkOrderNo(daParamCollection.getWorkOrderNo());
//                saveData.setProductCode(daParamCollection.getProductCode());
//                saveData.setLocationCode(daParamCollection.getLocationCode());
//                saveData.setSfcCode(daParamCollection.getProductBarcode());
//                saveData.setParamCode(daCollectionParamConfs.get(0).getCollectParameterId());
//                saveData.setParamName(daCollectionParamConfs.get(0).getCollectParameterName());
//                saveData.setCollectionTime(new Date());
//                saveData.setParamValue(DateUtil.formatDateTime(new Date()));
//                daParamCollectionMapper.insertDaParamCollection(saveData);
                //增加过站记录
                DaPassingStationCollection daPassingStationCollection = new DaPassingStationCollection();
@@ -326,38 +304,31 @@
                //添加基础参数
                this.manualWorkstationsAddBasicParameters(daParamCollection);
//                //更新过站记录表出站时间
//                DaPassingStationCollection daPassingStationCollection = new DaPassingStationCollection();
//                daPassingStationCollection.setWorkOrderNo(daParamCollection.getWorkOrderNo());
//                daPassingStationCollection.setLocationCode(daParamCollection.getLocationCode());
//                List<DaPassingStationCollection> daPassingStationCollections = daPassingStationCollectionMapper.selectDaPassingStationCollectionList(daPassingStationCollection);
//                daPassingStationCollections.get(0).setOutboundTime(new Date());
//                int i = daPassingStationCollectionMapper.updateDaPassingStationCollection(daPassingStationCollections.get(0));
//                OPCUaSubscription.SaveParamData(daParamCollection.getProductBarcode(),"OP",daParamCollection.getLocationCode(),daParamCollection.getWorkOrderNo(),daParamCollection.getProductCode());
                //半自动工位,先将自动数据保存到数据库
                this.saveParameters(daParamCollection);
                //给opc发21
                miloService.writeToOpcShort(ReadWriteEntity.builder().identifier("PACK."+daParamCollection.getLocationCode()+".RecordDataDone").value(21).build());
                if(daParamCollection.getLocationCode().equals("OP240")){
                miloService.writeToOpcShort(ReadWriteEntity.builder().identifier("MOZU1."+daParamCollection.getLocationCode()+".RecordDataDone").value(21).build());
                if(daParamCollection.getLocationCode().equals("M1OP100-1") || daParamCollection.getLocationCode().equals("M1OP100-2") ){
                    try{
                        CompletableFuture<Void> cp1 = CompletableFuture.runAsync(() -> {
                            logger.info("OP230报工开始-工厂MES异步方法");
                            String reportResult = RestfulService.getWorkReportResultFeedback(daParamCollection.getProductBarcode(), "OP230", format.format(new Date()));
                            logger.info("OP100报工开始-工厂MES异步方法");
                            String reportResult = RestfulService.getWorkReportResultFeedback(daParamCollection.getProductBarcode(), daParamCollection.getLocationCode(), format.format(new Date()));
                            JSONObject jsonObject = new JSONObject(reportResult);
                            String code = jsonObject.getStr("code");
                            if("success".equals(code)){
                                //如果成功,执行报工成功方法,修改是否报工为1,添加报工时间
                                omProductionOrdeInfoService.updateOrderByProductNum("1",daParamCollection.getProductBarcode(),"OP230");
                                omProductionOrdeInfoService.updateOrderByProductNum("1",daParamCollection.getProductBarcode(),daParamCollection.getLocationCode());
                            }else{
                                //解析工厂mes返回结果,如果失败,执行报工失败方法,修改是否报工为2,添加报工时间
                                omProductionOrdeInfoService.updateOrderByProductNum("2",daParamCollection.getProductBarcode(),"OP230");
                                omProductionOrdeInfoService.updateOrderByProductNum("2",daParamCollection.getProductBarcode(),daParamCollection.getLocationCode());
                            }
                            logger.info("OP230报工结束-工厂MES异步方法{}"+reportResult);
                            logger.info("OP100报工结束-工厂MES异步方法{}"+reportResult);
                        });
                    }catch (Exception e){
                        System.out.println(e.getMessage());
                    }
//                    RestfulService.getWorkReportResultFeedback(daParamCollection.getProductBarcode(),"OP230",format.format(new Date()));
                }
@@ -367,6 +338,62 @@
        }
    }
    //半自动工位,先将自动数据保存到数据库
    public void saveParameters(DaParamCollection daParamCollection) {
        //添加自动工位参数数据
        //查询参数配置表
        List<DaCollectionParamConf> list = daCollectionParamConfService.list(new LambdaQueryWrapper<DaCollectionParamConf>()
                .eq(DaCollectionParamConf::getProcessesCode, daParamCollection.getLocationCode())//工位
                .eq(DaCollectionParamConf::getWhetherToCollect, Constants.ONE)//是否采集
        );//类型
        List<String> collectAddressList = list.stream()
                .map(DaCollectionParamConf::getGatherAddress).collect(Collectors.toList());
        List<ReadWriteEntity> paramCollectionList = null;//模组 参数值
        try {
            paramCollectionList = miloService.readFromOpcUa(collectAddressList);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        if (CollUtil.isNotEmpty(paramCollectionList)) {
            List<DaParamCollection> saveParamList = new ArrayList<>();//封装参数采集list
            List<DaParamCollectionTemp> saveParamListTemp = new ArrayList<>();//封装参数采集list
            for (int i = 0; i < paramCollectionList.size(); i++) {
                DaParamCollection collection = new DaParamCollection();
                collection.setSfcCode(daParamCollection.getProductBarcode());//模组码
                collection.setParamCode(list.get(i).getCollectParameterId());//参数编码
                collection.setParamName(list.get(i).getCollectParameterName());//参数名称
                String paramValue = "";
                if (ObjectUtil.isNotNull(paramCollectionList.get(i).getValue())) {
                    paramValue = paramCollectionList.get(i).getValue().toString();//参数值
                }
                collection.setParamValue(paramValue);//参数值
                collection.setLocationCode(daParamCollection.getLocationCode());//工位
                collection.setCollectionTime(new Date());//采集时间
                saveParamList.add(collection);//封装参数采集list
                DaParamCollectionTemp collectionTemp = new DaParamCollectionTemp();
                collectionTemp.setSfcCode(daParamCollection.getProductBarcode());//模组码
                collectionTemp.setParamCode(list.get(i).getCollectParameterId());//参数编码
                collectionTemp.setParamName(list.get(i).getCollectParameterName());//参数名称
                if (ObjectUtil.isNotNull(paramCollectionList.get(i).getValue())) {
                    paramValue = paramCollectionList.get(i).getValue().toString();//参数值
                }
                collectionTemp.setParamValue(paramValue);//参数值
                collectionTemp.setLocationCode(daParamCollection.getLocationCode());//工位
                collectionTemp.setCollectionTime(new Date());//采集时间
                saveParamListTemp.add(collectionTemp);//封装参数采集list
            }
            //插入参数采集表
            daParamCollectionService.insertBatch(saveParamList);
            //插入参数采集表
            daParamCollectionTempService.insertBatch(saveParamListTemp);
        }
    }
    @Override
    public void insertBatch(List<DaParamCollection> confList){
        try{
@@ -446,11 +473,7 @@
        daPassingStationCollections.get(0).setOutboundTime(new Date());
        int i = daPassingStationCollectionMapper.updateDaPassingStationCollection(daPassingStationCollections.get(0));
//                OPCUaSubscription.SaveParamData(daParamCollection.getProductBarcode(),"OP",daParamCollection.getLocationCode(),daParamCollection.getWorkOrderNo(),daParamCollection.getProductCode());
        //给opc发21
        try {
//            miloService.writeToOpcShort(ReadWriteEntity.builder().identifier("PACK."+daParamCollection.getLocationCode()+".RecordDataDone").value(21).build());
            String strA = daParamCollection.getLocationCode();
            miloService.writeToOpcShort(ReadWriteEntity.builder().identifier("PACK."+strA+".RecordDataDone").value(21).build());
        } catch (Exception e) {