admin
2024-07-01 768498719683f85e5ed19c73eb3d14cdbf420df4
jcdm-main/src/main/java/com/jcdm/main/bs/formulaChild/service/impl/BsFormulaChildInfoServiceImpl.java
@@ -11,6 +11,7 @@
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jcdm.common.core.domain.AjaxResult;
import com.jcdm.common.utils.DateUtils;
@@ -180,10 +181,13 @@
                .eq(BsFormulaChildInfo::getProductCode, bsFormulaChildInfo.getProductCode())
                .eq(BsFormulaChildInfo::getOperationType, "2")
        );
        List<String> newResultsList = infos.stream().map(s -> s.getCollectData()).collect(Collectors.toList());
        if(newResultsList.stream().noneMatch(results -> results.equals(bsFormulaChildInfo.getScanBarcode()))){
        for (BsFormulaChildInfo formulaChildInfo : infos) {
            if(bsFormulaChildInfo.getScanBarcode().contains(formulaChildInfo.getMaterialCode())){
                bsFormulaChildInfos.add(formulaChildInfo);
                break;
                }
            }
        }
        if(bsFormulaChildInfos.size()>0){
@@ -225,42 +229,44 @@
////                return AjaxResult.success("扫描未完成,禁止拧紧操作!");
//            }
//        }
        BsFormulaChildInfo listQuery = new BsFormulaChildInfo();
        listQuery.setParamCode(bsFormulaChildInfo.getParamCode());
        listQuery.setProcessesCode(bsFormulaChildInfo.getLocationCode());
        String paramCode = bsFormulaChildInfo.getTightenTheArray();
        if(paramCode.contains("N")){
//        BsFormulaChildInfo listQuery = new BsFormulaChildInfo();
//        listQuery.setParamCode(bsFormulaChildInfo.getParamCode());
//        listQuery.setProcessesCode(bsFormulaChildInfo.getLocationCode());
        String paramData = bsFormulaChildInfo.getTightenTheArray();
        if(paramData.contains("N")){
            result = "3";
            List<BsFormulaChildInfo> bsFormulaChildInfos = bsFormulaChildInfoMapper.selectBsFormulaChildInfoList(listQuery);
            bsFormulaChildInfos.get(0).setResults("NG");
            bsFormulaChildInfos.get(0).setCollectData(bsFormulaChildInfo.getTightenTheArray());
            bsFormulaChildInfoMapper.updateBsFormulaChildInfo(bsFormulaChildInfos.get(0));
//            List<BsFormulaChildInfo> bsFormulaChildInfos = bsFormulaChildInfoMapper.selectBsFormulaChildInfoList(listQuery);
//            bsFormulaChildInfos.get(0).setResults("NG");
//            bsFormulaChildInfos.get(0).setCollectData(bsFormulaChildInfo.getTightenTheArray());
//            bsFormulaChildInfoMapper.updateBsFormulaChildInfo(bsFormulaChildInfos.get(0));
            this.updateTighteningData(bsFormulaChildInfo,"NG",paramData);
//            return AjaxResult.success("扫描结果NG,请重新扫描!");
        }else {
            List<BsFormulaChildInfo> bsFormulaChildInfos = bsFormulaChildInfoMapper.selectBsFormulaChildInfoList(listQuery);
            if(bsFormulaChildInfos.get(0).getSpareField2()!=null&&bsFormulaChildInfos.get(0).getSpareField3()!=null){
//            List<BsFormulaChildInfo> bsFormulaChildInfos = bsFormulaChildInfoMapper.selectBsFormulaChildInfoList(listQuery);
            if(bsFormulaChildInfo.getSpareField2()!=null&&bsFormulaChildInfo.getSpareField3()!=null){
                String tightenArray = bsFormulaChildInfo.getTightenTheArray().replace("[", "").replace("]", "").replace(" ", "");
                String[] tightenDataParts = tightenArray.split(",");
                b = TimeUtil.isNumberInRange(Double.parseDouble(tightenDataParts[0]),Double.parseDouble(bsFormulaChildInfos.get(0).getSpareField2()),Double.parseDouble(bsFormulaChildInfos.get(0).getSpareField3()));
                b = TimeUtil.isNumberInRange(Double.parseDouble(tightenDataParts[0]),Double.parseDouble(bsFormulaChildInfo.getSpareField2()),Double.parseDouble(bsFormulaChildInfo.getSpareField3()));
            }
            if(b){
                result = "3";
                bsFormulaChildInfos.get(0).setResults("OK");
                bsFormulaChildInfos.get(0).setCollectData(bsFormulaChildInfo.getTightenTheArray());
                bsFormulaChildInfoMapper.updateBsFormulaChildInfo(bsFormulaChildInfos.get(0));
                logger.info("yzUpdateTighteningFormula--查询条件参数:"+listQuery);
                logger.info("yzUpdateTighteningFormula--查询结果:"+bsFormulaChildInfos.get(0));
                Integer stepNumber = Integer.valueOf(bsFormulaChildInfos.get(0).getStepSort());
//                bsFormulaChildInfos.get(0).setResults("OK");
//                bsFormulaChildInfos.get(0).setCollectData(bsFormulaChildInfo.getTightenTheArray());
//                bsFormulaChildInfoMapper.updateBsFormulaChildInfo(bsFormulaChildInfos.get(0));
                this.updateTighteningData(bsFormulaChildInfo,"OK",paramData);
//                logger.info("yzUpdateTighteningFormula--查询条件参数:"+listQuery);
//                logger.info("yzUpdateTighteningFormula--查询结果:"+bsFormulaChildInfos.get(0));
                Integer stepNumber = Integer.valueOf(bsFormulaChildInfo.getStepSort());
                try {
                    miloService.writeToOpcShort(ReadWriteEntity.builder().identifier("PACK."+bsFormulaChildInfo.getLocationCode()+".MStepNumber").value(stepNumber+1).build());
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
                String spareField4 = bsFormulaChildInfos.get(0).getSpareField4();
                String spareField4 = bsFormulaChildInfo.getSpareField4();
                if (spareField4 != null && !spareField4.isEmpty()) {
                    // 执行操作
                    if(bsFormulaChildInfos.get(0).getSpareField4().equals("1")){
                    if(bsFormulaChildInfo.getSpareField4().equals("1")){
                        try {
//                        WebSocketUsers.sendMessageToUserByText(map.get(bsFormulaChildInfo.getLocationCode()), "OUT");
                            result = "2";
@@ -271,16 +277,28 @@
                }
            }else {
                result = "3";
                List<BsFormulaChildInfo> bsFormulaChildInfos1 = bsFormulaChildInfoMapper.selectBsFormulaChildInfoList(listQuery);
                bsFormulaChildInfos1.get(0).setResults("NG");
                String originalString = bsFormulaChildInfo.getTightenTheArray();
                String modifiedString = originalString.replaceFirst("OK", "NG");
                bsFormulaChildInfos1.get(0).setCollectData(modifiedString);
                bsFormulaChildInfoMapper.updateBsFormulaChildInfo(bsFormulaChildInfos1.get(0));
//                List<BsFormulaChildInfo> bsFormulaChildInfos1 = bsFormulaChildInfoMapper.selectBsFormulaChildInfoList(listQuery);
//                bsFormulaChildInfos1.get(0).setResults("NG");
//                String originalString = bsFormulaChildInfo.getTightenTheArray();
                String modifiedString = paramData.replaceFirst("OK", "NG");
//                bsFormulaChildInfos1.get(0).setCollectData(modifiedString);
//                bsFormulaChildInfoMapper.updateBsFormulaChildInfo(bsFormulaChildInfos1.get(0));
                this.updateTighteningData(bsFormulaChildInfo,"NG",modifiedString);
//                return AjaxResult.success("扫描结果NG,请重新扫描!");
            }
        }
        return AjaxResult.success(result);
    }
    @Override
    public AjaxResult updateTighteningData(BsFormulaChildInfo bsFormulaChildInfo,String result,String data) {
        LambdaUpdateWrapper<BsFormulaChildInfo> updateWrapper = new LambdaUpdateWrapper();
        updateWrapper.set(BsFormulaChildInfo::getCollectData, data);
        updateWrapper.set(BsFormulaChildInfo::getResults, result);
        updateWrapper.eq(BsFormulaChildInfo::getProcessesCode, bsFormulaChildInfo.getLocationCode());
        updateWrapper.eq(BsFormulaChildInfo::getParamCode, bsFormulaChildInfo.getParamCode());
        boolean update = bsFormulaChildInfoService.update(new BsFormulaChildInfo(), updateWrapper);
        return AjaxResult.success(update);
    }
    @Override
@@ -334,14 +352,15 @@
    @Override
    public AjaxResult jrmWorkpieceRelease(BsFormulaChildInfo bsFormulaChildInfo) {
        List<BsFormulaChildInfo> list = bsFormulaChildInfoService.list(new LambdaQueryWrapper<BsFormulaChildInfo>()
                .eq(BsFormulaChildInfo::getProcessesCode, bsFormulaChildInfo.getLocationCode())
                .eq(BsFormulaChildInfo::getProductCode, bsFormulaChildInfo.getProductCode()));
        for (BsFormulaChildInfo info : list) {
            info.setCollectData("");
            info.setResults("");
            bsFormulaChildInfoService.saveOrUpdate(info);
        }
        this.clearCollectDataAndResultsByProcessesCode(bsFormulaChildInfo);
//        List<BsFormulaChildInfo> list = bsFormulaChildInfoService.list(new LambdaQueryWrapper<BsFormulaChildInfo>()
//                .eq(BsFormulaChildInfo::getProcessesCode, bsFormulaChildInfo.getLocationCode())
//                .eq(BsFormulaChildInfo::getProductCode, bsFormulaChildInfo.getProductCode()));
//        for (BsFormulaChildInfo info : list) {
//            info.setCollectData("");
//            info.setResults("");
//            bsFormulaChildInfoService.saveOrUpdate(info);
//        }
        String[] split = bsFormulaChildInfo.getProductBarcode().split(",");
        try {
            for (int i = 0; i < split.length; i++) {
@@ -374,14 +393,15 @@
    @Override
    public AjaxResult clearWorkpieceRelease(BsFormulaChildInfo bsFormulaChildInfo) {
        List<BsFormulaChildInfo> list = bsFormulaChildInfoService.list(new LambdaQueryWrapper<BsFormulaChildInfo>()
                .eq(BsFormulaChildInfo::getProcessesCode, bsFormulaChildInfo.getLocationCode())
                .eq(BsFormulaChildInfo::getProductCode, bsFormulaChildInfo.getProductCode()));
        for (BsFormulaChildInfo info : list) {
            info.setCollectData("");
            info.setResults("");
            bsFormulaChildInfoService.saveOrUpdate(info);
        }
//        List<BsFormulaChildInfo> list = bsFormulaChildInfoService.list(new LambdaQueryWrapper<BsFormulaChildInfo>()
//                .eq(BsFormulaChildInfo::getProcessesCode, bsFormulaChildInfo.getLocationCode())
//                .eq(BsFormulaChildInfo::getProductCode, bsFormulaChildInfo.getProductCode()));
//        for (BsFormulaChildInfo info : list) {
//            info.setCollectData("");
//            info.setResults("");
//            bsFormulaChildInfoService.saveOrUpdate(info);
//        }
        this.clearCollectDataAndResultsByProcessesCode(bsFormulaChildInfo);
        return AjaxResult.success();
    }
@@ -399,6 +419,17 @@
            }
        }
        return AjaxResult.success(result);
    }
    @Override
    public AjaxResult clearCollectDataAndResultsByProcessesCode(BsFormulaChildInfo bsFormulaChildInfo) {
        LambdaUpdateWrapper<BsFormulaChildInfo> updateWrapper = new LambdaUpdateWrapper();
        updateWrapper.set(BsFormulaChildInfo::getCollectData, "");
        updateWrapper.set(BsFormulaChildInfo::getResults,"");
        updateWrapper.eq(BsFormulaChildInfo::getProcessesCode, bsFormulaChildInfo.getLocationCode());
        BsFormulaChildInfo info = new BsFormulaChildInfo();
        boolean update = this.update(info,updateWrapper);
        return AjaxResult.success(update);
    }
    @Override
@@ -522,28 +553,29 @@
    @Override
    public AjaxResult workpieceRelease(BsFormulaChildInfo bsFormulaChildInfo) {
        List<BsFormulaChildInfo> list = bsFormulaChildInfoService.list(new LambdaQueryWrapper<BsFormulaChildInfo>()
                .eq(BsFormulaChildInfo::getProcessesCode, bsFormulaChildInfo.getLocationCode())
                .eq(BsFormulaChildInfo::getProductCode, bsFormulaChildInfo.getProductCode()));
        for (BsFormulaChildInfo info : list) {
            info.setCollectData("");
            info.setResults("");
            bsFormulaChildInfoService.saveOrUpdate(info);
        }
        this.clearCollectDataAndResultsByProcessesCode(bsFormulaChildInfo);
//        List<BsFormulaChildInfo> list = bsFormulaChildInfoService.list(new LambdaQueryWrapper<BsFormulaChildInfo>()
//                .eq(BsFormulaChildInfo::getProcessesCode, bsFormulaChildInfo.getLocationCode())
//                .eq(BsFormulaChildInfo::getProductCode, bsFormulaChildInfo.getProductCode()));
//        for (BsFormulaChildInfo info : list) {
//            info.setCollectData("");
//            info.setResults("");
//            bsFormulaChildInfoService.saveOrUpdate(info);
//        }
        try {
            daParamCollectionService.pushGeelycvMesFeedback(bsFormulaChildInfo.getProductBarcode(), bsFormulaChildInfo.getLocationCode());
            String barCode = bsFormulaChildInfo.getProductBarcode();
            String locationCode = bsFormulaChildInfo.getLocationCode();
            if(StringUtils.isNotBlank(locationCode)&&StringUtils.isNotBlank(barCode)){
                DaPassingStationCollection daPassingStationCollection = new DaPassingStationCollection();
                daPassingStationCollection.setOutRsSign("1");
                daPassingStationCollection.setOutboundTime(new Date());
                daPassingStationCollection.setSfcCode(barCode);
                daPassingStationCollection.setLocationCode(locationCode);
                int updateDaPassingStation = daPassingStationCollectionService.updateDaPassingStationCollectionBySfcCodeAndLocationCode(daPassingStationCollection);
                logger.info("普通人工工位更新过站记录updateDaPassingStationCollectionBySfcCodeAndLocationCode:更新了{}条数据-更新条件pack码{}-工位{}",updateDaPassingStation,barCode,locationCode);
            }
//            String barCode = bsFormulaChildInfo.getProductBarcode();
//            String locationCode = bsFormulaChildInfo.getLocationCode();
//
//            if(StringUtils.isNotBlank(locationCode)&&StringUtils.isNotBlank(barCode)){
//                DaPassingStationCollection daPassingStationCollection = new DaPassingStationCollection();
//                daPassingStationCollection.setOutRsSign("1");
//                daPassingStationCollection.setOutboundTime(new Date());
//                daPassingStationCollection.setSfcCode(barCode);
//                daPassingStationCollection.setLocationCode(locationCode);
//                int updateDaPassingStation = daPassingStationCollectionService.updateDaPassingStationCollectionBySfcCodeAndLocationCode(daPassingStationCollection);
//                logger.info("普通人工工位更新过站记录updateDaPassingStationCollectionBySfcCodeAndLocationCode:更新了{}条数据-更新条件pack码{}-工位{}",updateDaPassingStation,barCode,locationCode);
//            }
//            DaPassingStationCollection passingStationCollectionOne = daPassingStationCollectionService.getOne(new LambdaQueryWrapper<DaPassingStationCollection>().eq(DaPassingStationCollection::getSfcCode, barCode).eq(DaPassingStationCollection::getLocationCode, locationCode));
//            if (passingStationCollectionOne != null) {