自动化立体仓库 - WMS系统
#
LSH
2024-03-25 f6796dda5fb7e269482f0cc92a898fe7ffc203d4
src/main/java/com/zy/asrs/task/handler/WorkMastHandler.java
@@ -8,9 +8,11 @@
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 lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
@@ -43,12 +45,19 @@
    @Autowired
    private OrderDetlService orderDetlService;
    @Autowired
    private WaitPakinService waitPakinService;
    @Autowired
    private ApiLogService apiLogService;
    @Value("${mes.url}")
    private String mesUrl;
    @Value("${mes.inPath}")
    private String inpath;
    @Autowired
    private PackQualifiedService packQualifiedService;
    @Autowired
    private ReportQueryMapper reportQueryMapper;
    public ReturnT<String> start(WrkMast wrkMast) {
        // 4.入库完成
@@ -129,19 +138,19 @@
                            }
                        }
                        // 更新订单完成数量
                        OrderDetl orderDetl = orderDetlService.selectItem(wrkDetl.getOrderNo(), wrkDetl.getMatnr(), wrkDetl.getBatch());
                        try {
                            if(!Cools.isEmpty(orderDetl)){
                                if(!orderDetlService.increaseQtyByOrderNo(wrkDetl.getOrderNo(), wrkDetl.getMatnr(),
                                        wrkDetl.getBatch(),wrkDetl.getAnfme())){
//                                    exceptionHandle("全板入库 ===>> 更新订单完成数量失败;[workNo={0}],[locNo={1}]",
//                                            wrkMast.getWrkNo(), wrkMast.getLocNo());
                                    TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                                    return FAIL.setMsg("全板入库 ===>> 更新订单完成数量失败; [workNo=" + wrkMast.getWrkNo() + "],[locNo=" + wrkMast.getLocNo() + "]");
                                }
                            }
                        } catch (Exception ignore){}
//                        // 更新订单完成数量
//                        OrderDetl orderDetl = orderDetlService.selectItem(wrkDetl.getOrderNo(), wrkDetl.getMatnr(), wrkDetl.getBatch());
//                        try {
//                            if(!Cools.isEmpty(orderDetl)){
//                                if(!orderDetlService.increaseQtyByOrderNo(wrkDetl.getOrderNo(), wrkDetl.getMatnr(),
//                                        wrkDetl.getBatch(),wrkDetl.getAnfme())){
////                                    exceptionHandle("全板入库 ===>> 更新订单完成数量失败;[workNo={0}],[locNo={1}]",
////                                            wrkMast.getWrkNo(), wrkMast.getLocNo());
//                                    TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
//                                    return FAIL.setMsg("全板入库 ===>> 更新订单完成数量失败; [workNo=" + wrkMast.getWrkNo() + "],[locNo=" + wrkMast.getLocNo() + "]");
//                                }
//                            }
//                        } catch (Exception ignore){}
                    }
                    // 修改库位状态 S ====>> F
@@ -151,7 +160,55 @@
                        locMast.setIoTime(now);
                        locMast.setModiTime(now);
                        locMast.setFireStatus(0);
                        locMast.setPackStatus(1);
                        //入测试库位时给库位测试状态为1待测
                        if(!Cools.isEmpty(locMast.getChannel())){
                            locMast.setPackStatus(1);//待测
                        }
                        if (locMast.getCrnNo()==1){
                            if (locMast.getLocType1()==1){
                                locMast.setPackStatus(1);
                            }else {
                                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",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",wrkDetl1.getMatnr()).eq("status",4))){
                                throw new CoolException("更改测试状态失败");
                            }
                        }
                        //入库标记
                        packQualifiedService.insertPackQualified(true,new Date(),wrkDetls.get(0).getMatnr());
                        //2.入库完成上报
                        CombParam combParam = new CombParam();
                        combParam.setPackNo(wrkDetls.get(0).getMatnr());
                        combParam.setLocNo(wrkMast.getLocNo());
                        combParam.setBarcode(wrkMast.getBarcode());
                        if (locMast.getCrnNo()==1){
                            combParam.setPackSts(0);
                            combParam.setStepSts(2);
                        }else{
                            combParam.setPackSts(1);
                            combParam.setStepSts(5);
                        }
                        combParam.setRequestTime(DateUtils.convert(now));
                        new PostMesDataUtils().postMesData("MES系统",mesUrl,inpath,combParam);
                        if (!locMastService.updateById(locMast)) {
//                            exceptionHandle("全板入库 ===>> 修改库位状态失败;[workNo={0}],[locNo={1}]", wrkMast.getWrkNo(), wrkMast.getLocNo());
                            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
@@ -298,7 +355,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());
@@ -311,34 +367,100 @@
                    locMast.setBarcode(wrkMast.getBarcode());
                    locMast.setIoTime(now);
                    locMast.setModiTime(now);
                    locMast.setFireStatus(0);
                    if (locMast.getLocType1()==sourceLoc.getLocType1()){
                    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);
                        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());
                            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 {
                        locMast.setPackStatus(5); //5:静置中
                        if (locMast.getLocType1()==1 && sourceLoc.getLocType1()==2){
                        //测试库位转静置库位和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());
                        }
                        sign=true;
                            TestMast testMast = testMastService.selectOne(new EntityWrapper<TestMast>()
                                    .eq("loc_no",sourceLoc.getLocNo())
                                    .eq("barcode",locMast.getBarcode())
                                    .eq("barcode",locDetl.getMatnr())
                                    .eq("status",4)
                            );
                            testMast.setStatus(5);
                            testMast.setLocNo(locMast.getLocNo());
                            testMast.setModiTime(new Date());
                            if (!testMastService.update(testMast,new EntityWrapper<TestMast>().eq("loc_no",sourceLoc.getLocNo()).eq("barcode",locMast.getBarcode()).eq("status",4))){
                            if (!testMastService.update(testMast,new EntityWrapper<TestMast>()
                                    .eq("loc_no",sourceLoc.getLocNo())
                                    .eq("barcode",locDetl.getMatnr())
                                    .eq("status",4))){
                                throw new CoolException("更改测试状态失败");
                            }
                        }
                        CombParam combParam = new CombParam();
                        combParam.setPackNo(locMast.getBarcode());
                        combParam.setLocNo(locMast.getLocNo());
                        combParam.setPackSts(5);
                        combParam.setRequestTime(DateUtils.convert(new Date()));
                        postMesData(inpath,combParam);
                    }
                    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){
                        //7.测试库位转静置库位出库完成上报
                        CombParam combParam = new CombParam();
                        combParam.setPackNo(locDetl.getMatnr());
                        combParam.setLocNo(wrkMast.getSourceLocNo());
                        combParam.setStepSts(7);
                        if (locMast.getPackStatus()==4){
                            combParam.setPackSts(2);
                        }else if (locMast.getPackStatus()==5){
                            combParam.setPackSts(1);
                        }
                        combParam.setRequestTime(DateUtils.convert(now));
                        new PostMesDataUtils().postMesData("MES系统",mesUrl,inpath,combParam);
                        //5.测试库位转静置库位入库完成上报
                        combParam.setPackNo(locDetl.getMatnr());
                        combParam.setLocNo(wrkMast.getLocNo());
                        if (locMast.getPackStatus()==4){
                            combParam.setPackSts(2);
                            combParam.setStepSts(5);
                        }else if (locMast.getPackStatus()==5){
                            combParam.setPackSts(1);
                            combParam.setStepSts(8);
                        }else {
                            combParam.setPackSts(0);
                        }
                        combParam.setRequestTime(DateUtils.convert(now));
                        new PostMesDataUtils().postMesData("MES系统",mesUrl,inpath,combParam);
                    }
                    break;
                default:
@@ -385,21 +507,21 @@
                        TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                        return FAIL.setMsg("全板出库 ===>> 工作明细档为空; [workNo=" + wrkMast.getWrkNo() + "],[locNo=" + wrkMast.getSourceLocNo() + "]");
                    }
                    for (WrkDetl wrkDetl : wrkDetls101) {
                        // 更新订单完成数量
                        OrderDetl orderDetl = orderDetlService.selectItem(wrkDetl.getOrderNo(), wrkDetl.getMatnr(), wrkDetl.getBatch());
                        try {
                            if(!Cools.isEmpty(orderDetl)){
                                if(!orderDetlService.increaseQtyByOrderNo(wrkDetl.getOrderNo(), wrkDetl.getMatnr(),
                                        wrkDetl.getBatch(),wrkDetl.getAnfme())){
//                                    exceptionHandle("全板出库 ===>> 更新订单完成数量失败;[workNo={0}],[locNo={1}]",
//                                            wrkMast.getWrkNo(), wrkMast.getLocNo());
                                    TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                                    return FAIL.setMsg("全板出库 ===>> 更新订单完成数量失败; [workNo=" + wrkMast.getWrkNo() + "],[locNo=" + wrkMast.getSourceLocNo() + "]");
                                }
                            }
                        } catch (Exception ignore){}
                    }
//                    for (WrkDetl wrkDetl : wrkDetls101) {
//                        // 更新订单完成数量
//                        OrderDetl orderDetl = orderDetlService.selectItem(wrkDetl.getOrderNo(), wrkDetl.getMatnr(), wrkDetl.getBatch());
//                        try {
//                            if(!Cools.isEmpty(orderDetl)){
//                                if(!orderDetlService.increaseQtyByOrderNo(wrkDetl.getOrderNo(), wrkDetl.getMatnr(),
//                                        wrkDetl.getBatch(),wrkDetl.getAnfme())){
////                                    exceptionHandle("全板出库 ===>> 更新订单完成数量失败;[workNo={0}],[locNo={1}]",
////                                            wrkMast.getWrkNo(), wrkMast.getLocNo());
//                                    TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
//                                    return FAIL.setMsg("全板出库 ===>> 更新订单完成数量失败; [workNo=" + wrkMast.getWrkNo() + "],[locNo=" + wrkMast.getSourceLocNo() + "]");
//                                }
//                            }
//                        } catch (Exception ignore){}
//                    }
                    // 删除工作档源库位的库存明细
                    if (!locDetlService.delete(new EntityWrapper<LocDetl>().eq("loc_no", wrkMast.getSourceLocNo()))) {
//                        exceptionHandle("全板出库 ===>> 删除库存明细失败;[workNo={0}],[sourceLocNo={1}]", wrkMast.getWrkNo(), wrkMast.getSourceLocNo());
@@ -412,12 +534,43 @@
                        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{
                            //出库标记
                            packQualifiedService.insertPackQualified(false,new Date(),wrkDetls101.get(0).getMatnr());
                            //2.出库完成上报
                           CombParam combParam = new CombParam();
                            combParam.setPackNo(wrkDetls101.get(0).getMatnr());
                            combParam.setLocNo(wrkMast.getLocNo());
                            combParam.setBarcode(wrkMast.getBarcode());
                            //目标站206出库
                            if(wrkMast.getStaNo()==206){
                                combParam.setPackSts(1);//OK
                                combParam.setStepSts(7);//测试库出库完成
                            }else if(wrkMast.getStaNo()==204){//NG 出库
                                //NG出库修改测试档的状态为5.已移库
                                TestMast testMast=testMastService.selectOne(new EntityWrapper<TestMast>()
                                        .eq("user_id",wrkMast.getBarcode())
                                        .eq("barcode",wrkDetls101.get(0).getMatnr()));
                                combParam.setPackSts(2);//NG
                                combParam.setStepSts(8);//NG出库完成
                                testMast.setStatus(5);
                                if(!testMastService.update(testMast,new EntityWrapper<TestMast>()
                                        .eq("user_id",wrkMast.getBarcode())
                                        .eq("barcode",wrkDetls101.get(0).getMatnr()))){
                                    TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                                    return FAIL.setMsg("全板出库 ===>> 修改测试表状态为5失败; [workNo=" + wrkMast.getWrkNo() + "],[locNo=" + wrkMast.getSourceLocNo() + "]");
                                }
                            }else if(wrkMast.getStaNo()==103){//目标站103出库
                                combParam.setPackSts(1);//OK
                                combParam.setStepSts(6);//静置库出库完成
                            }
                            combParam.setRequestTime(DateUtils.convert(now));
                            new PostMesDataUtils().postMesData("MES系统",mesUrl,inpath,combParam);
                        }
                    }
                    break;
@@ -429,6 +582,7 @@
                        locMast.setBarcode("");
                        locMast.setModiTime(now);
                        locMast.setIoTime(now);
                        locMast.setPackStatus(0);
                        if (!locMastService.updateById(locMast)) {
//                            exceptionHandle("空板出库 ===>> 修改源库位状态失败;[workNo={0}],[sourceLocNo={1}]", wrkMast.getWrkNo(), wrkMast.getSourceLocNo());
                            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
@@ -452,45 +606,6 @@
            e.printStackTrace();
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return FAIL.setMsg(e.getMessage());
        }
        return SUCCESS;
    }
    private ReturnT<String> postMesData(String mesPath,Object combParam){
        if(combParam != null){
            String response = "";
            boolean success = false;
            try {
                response = new HttpHandler.Builder()
                        .setUri(mesUrl)
                        .setPath(mesPath)
                        .setJson(JSON.toJSONString(combParam))
                        .build()
                        .doPost();
                JSONObject jsonObject = JSON.parseObject(response);
                if (jsonObject.getInteger("code").equals(200)) {
                    success = true;
                } else {
                    log.error("请求接口失败!!!url:{};request:{};response:{}", mesUrl+mesPath, JSON.toJSONString(combParam), response);
                    throw new CoolException("上报mes系统失败");
                }
            } catch (Exception e) {
                log.error("fail", e);
//                      TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                return FAIL.setMsg(e.getMessage());
            } finally {
                try {
                    // 保存接口日志
                    apiLogService.save(
                            "上报mes系统",
                            mesUrl + mesPath,
                            null,
                            "127.0.0.1",
                            JSON.toJSONString(combParam),
                            response,
                            success
                    );
                } catch (Exception e) { log.error("", e); }
            }
        }
        return SUCCESS;
    }