自动化立体仓库 - WMS系统
野心家
2025-06-21 288e45a990a5abf4ab50f820ed4e870e8314468e
src/main/java/com/zy/asrs/task/handler/WorkMastHandler.java
@@ -8,11 +8,14 @@
import com.core.exception.CoolException;
import com.zy.asrs.entity.*;
import com.zy.asrs.entity.param.CombParam;
import com.zy.asrs.mapper.ReportQueryMapper;
import com.zy.asrs.service.*;
import com.zy.asrs.task.AbstractHandler;
import com.zy.asrs.task.core.ReturnT;
import com.zy.asrs.utils.PostMesDataUtils;
import com.zy.common.utils.HttpHandler;
import com.zy.system.entity.Config;
import com.zy.system.service.ConfigService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
@@ -52,6 +55,13 @@
    @Value("${mes.inPath}")
    private String inpath;
    @Autowired
    private PackQualifiedService packQualifiedService;
    @Autowired
    private ReportQueryMapper reportQueryMapper;
    @Autowired
    private ConfigService   configService;
    public ReturnT<String> start(WrkMast wrkMast) {
        // 4.入库完成
@@ -154,6 +164,10 @@
                        locMast.setIoTime(now);
                        locMast.setModiTime(now);
                        locMast.setFireStatus(0);
                        //入测试库位时给库位测试状态为1待测
                        if(!Cools.isEmpty(locMast.getChannel())){
                            locMast.setPackStatus(1);//待测
                        }
                        if (locMast.getCrnNo()==1){
                            if (locMast.getLocType1()==1){
                                locMast.setPackStatus(1);
@@ -161,21 +175,34 @@
                                locMast.setPackStatus(0);
                            }
                        }else {
                            WrkDetl wrkDetl1 = wrkDetlService.selectOne(new EntityWrapper<WrkDetl>().eq("zpallet",locMast.getBarcode()));
                            locMast.setPackStatus(5);
                            TestMast testMast = testMastService.selectOne(new EntityWrapper<TestMast>()
                                    .eq("barcode",locMast.getBarcode())
                                    .eq("barcode",wrkDetl1.getMatnr())
                                    .eq("status",4)
                            );
                            if (Cools.isEmpty(testMast)){
                                testMast = testMastService.selectOne(new EntityWrapper<TestMast>()
                                        .eq("barcode",wrkDetl1.getMatnr())
                                        .eq("status",5)
                                );
                            }
                            if (Cools.isEmpty(testMast)){
                                throw new CoolException("更改测试状态失败,查询测试档案失败");
                            }
                            testMast.setStatus(5);
                            testMast.setModiTime(new Date());
                            if (!testMastService.update(testMast,new EntityWrapper<TestMast>().eq("barcode",locMast.getBarcode()).eq("status",4))){
                            if (!testMastService.update(testMast,new EntityWrapper<TestMast>().eq("barcode",wrkDetl1.getMatnr()).eq("status",4))){
                                throw new CoolException("更改测试状态失败");
                            }
                        }
                        //入库标记
                        packQualifiedService.insertPackQualified(true,new Date(),wrkDetls.get(0).getMatnr());
                        //2.入库完成上报
                        CombParam combParam = new CombParam();
                        combParam.setPackNo(wrkMast.getBarcode());
                        combParam.setPackNo(wrkDetls.get(0).getMatnr());
                        combParam.setLocNo(wrkMast.getLocNo());
                        combParam.setBarcode(wrkMast.getBarcode());
                        if (locMast.getCrnNo()==1){
                            combParam.setPackSts(0);
                            combParam.setStepSts(2);
@@ -185,7 +212,7 @@
                        }
                        combParam.setRequestTime(DateUtils.convert(now));
                        new PostMesDataUtils().postMesData("MES系统",mesUrl,inpath,combParam);
//                        new PostMesDataUtils().postMesData("MES系统",mesUrl,inpath,combParam);
                        if (!locMastService.updateById(locMast)) {
//                            exceptionHandle("全板入库 ===>> 修改库位状态失败;[workNo={0}],[locNo={1}]", wrkMast.getWrkNo(), wrkMast.getLocNo());
                            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
@@ -332,7 +359,6 @@
                        sourceLoc.setLocSts("O");
                        sourceLoc.setModiTime(now);
                        sourceLoc.setIoTime(now);
                        sourceLoc.setFireStatus(0);
                        sourceLoc.setPackStatus(0);
                        if (!locMastService.updateById(sourceLoc)) {
//                            exceptionHandle("库位移转 ===>> 修改源库位状态失败;[workNo={0}],[sourceLoc={1}]", wrkMast.getWrkNo(), wrkMast.getSourceLocNo());
@@ -345,53 +371,64 @@
                    locMast.setBarcode(wrkMast.getBarcode());
                    locMast.setIoTime(now);
                    locMast.setModiTime(now);
                    locMast.setFireStatus(0);
                    LocDetl locDetl = locDetlService.selectOne(new EntityWrapper<LocDetl>().eq("loc_no", locMast.getLocNo()));
                    boolean sign =false;
                    if (locMast.getLocType1().equals(sourceLoc.getLocType1())){
                        locMast.setPackStatus(packStatus);
                        //待测库位转测试库位
                    }else if (locMast.getLocType1().equals((short)1) && sourceLoc.getLocType1().equals((short)3)){
                        locMast.setPackStatus(1);
                    }else {
                        if (locMast.getLocType1().equals((short)4)){
                            locMast.setPackStatus(4); //4:NG
                        }else {
                            locMast.setPackStatus(5); //5:静置中
                        }
                        sign=true;
                        if (locMast.getLocType1()==1 && sourceLoc.getLocType1()==2){
                            TestMast testMast = testMastService.selectOne(new EntityWrapper<TestMast>()
                                    .eq("loc_no",sourceLoc.getLocNo())
                                    .eq("barcode",locMast.getBarcode())
                                    .eq("status",4)
                            );
                            testMast.setStatus(5);
                        TestMast testMast = testMastService.selectOne(new EntityWrapper<TestMast>()
                                .eq("loc_no",sourceLoc.getLocNo())
                                .eq("user_id",locMast.getBarcode())
                                .eq("barcode",locDetl.getMatnr())
                        );
                        if(!Cools.isEmpty(testMast)){
                            testMast.setChannel(locMast.getChannel());
                            testMast.setLocNo(wrkMast.getLocNo());
                            testMast.setModiTime(new Date());
                            if (!testMastService.update(testMast,new EntityWrapper<TestMast>().eq("loc_no",sourceLoc.getLocNo()).eq("barcode",locMast.getBarcode()).eq("status",4))){
                            testMast.setBarcode(locDetl.getMatnr());
                            if (!testMastService.update(testMast,new EntityWrapper<TestMast>()
                                    .eq("loc_no",sourceLoc.getLocNo())
                                    .eq("user_id",locMast.getBarcode())
                                    .eq("barcode",locDetl.getMatnr()))){
                                throw new CoolException("更改测试状态失败");
                            }
                        }else {
                            throw new CoolException("待测库位无物");
                        }
                    }else {
                        //测试库位转静置库位和NG库位
                        if (locMast.getLocType1().equals((short)4)){
                            locMast.setPackStatus(4); //4:NG
//                            //入库标记
//                            packQualifiedService.insertPackQualified(true,new Date(),locDetl.getMatnr());
//                            //出库标记
//                            packQualifiedService.insertPackQualified(false,new Date(),locDetl.getMatnr());
                        }else {
                            locMast.setPackStatus(5); //5:静置中
//                            //入库标记
//                            packQualifiedService.insertPackQualified(true,new Date(),locDetl.getMatnr());
//                            //出库标记
//                            packQualifiedService.insertPackQualified(false,new Date(),locDetl.getMatnr());
                        }
                            TestMast testMast = testMastService.selectOne(new EntityWrapper<TestMast>()
                                    .eq("loc_no",sourceLoc.getLocNo())
                                    .eq("barcode",locDetl.getMatnr())
                                    .in("status",3,4)
                            );
                            testMast.setStatus(5);
                            testMast.setLocNo(locMast.getLocNo());
                            testMast.setModiTime(new Date());
                            if (!testMastService.updateById(testMast)){
                                throw new CoolException("更改测试状态失败");
                            }
                    }
                    if (!locMastService.updateById(locMast)) {
//                        exceptionHandle("库位移转 ===>> 修改目标库位状态失败;[workNo={0}],[locNo={1}]", wrkMast.getWrkNo(), wrkMast.getLocNo());
                        TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                        return FAIL.setMsg("库位移转 ===>> 修改目标库位状态失败; [workNo=" + wrkMast.getWrkNo() + "],[locNo=" + wrkMast.getLocNo() + "]");
                    }
                    if (locMast.getCrnNo()==1 && sign){
                        //5.静置库位入库完成上报
                        CombParam combParam = new CombParam();
                        combParam.setPackNo(wrkMast.getBarcode());
                        combParam.setLocNo(wrkMast.getLocNo());
                        if (locMast.getPackStatus()==4){
                            combParam.setPackSts(2);
                        }else if (locMast.getPackStatus()==5){
                            combParam.setPackSts(1);
                        }else {
                            combParam.setPackSts(0);
                        }
                        combParam.setStepSts(5);
                        combParam.setRequestTime(DateUtils.convert(now));
                        new PostMesDataUtils().postMesData("MES系统",mesUrl,inpath,combParam);
                    }
                    break;
                default:
@@ -465,12 +502,20 @@
                        locMast.setBarcode("");
                        locMast.setModiTime(now);
                        locMast.setIoTime(now);
                        locMast.setFireStatus(0);
                        locMast.setPackStatus(0);
                        if (!locMastService.updateById(locMast)) {
//                            exceptionHandle("全板出库 ===>> 修改源库位状态失败;[workNo={0}],[sourceLocNo={1}]", wrkMast.getWrkNo(), wrkMast.getSourceLocNo());
                            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                            return FAIL.setMsg("全板出库 ===>> 修改源库位状态失败; [workNo=" + wrkMast.getWrkNo() + "],[locNo=" + wrkMast.getSourceLocNo() + "]");
                        }else{
                            Config config=configService.selectOne(new EntityWrapper<Config>().eq("code","OutTask"));
                            if(config.getValue().equals("Y")){
                                // 修改工作主档状态
                                wrkMast.setWrkSts(30L);//等待上报
                            }else{
                                wrkMast.setWrkSts(15L);
                            }
                        }
                    }
                    break;
@@ -482,20 +527,21 @@
                        locMast.setBarcode("");
                        locMast.setModiTime(now);
                        locMast.setIoTime(now);
                        locMast.setFireStatus(0);
                        locMast.setPackStatus(0);
                        if (!locMastService.updateById(locMast)) {
//                            exceptionHandle("空板出库 ===>> 修改源库位状态失败;[workNo={0}],[sourceLocNo={1}]", wrkMast.getWrkNo(), wrkMast.getSourceLocNo());
                            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                            return FAIL.setMsg("空板出库 ===>> 修改源库位状态失败; [workNo=" + wrkMast.getWrkNo() + "],[locNo=" + wrkMast.getSourceLocNo() + "]");
                        }else{
                            // 修改工作主档状态
                            wrkMast.setWrkSts(15L);
                        }
                    }
                    break;
                default:
                    break;
            }
            // 修改工作主档状态
            wrkMast.setWrkSts(15L);
            wrkMast.setModiTime(now);
            if (!wrkMastService.updateById(wrkMast)) {
//                exceptionHandle("更新出库完成状态失败;[workNo={0}]", wrkMast.getWrkNo());