自动化立体仓库 - WMS系统
pang.jiabao
2024-10-24 ef19ce2bc384c00b590ebdbd4e8c14ebfa9f0188
src/main/java/com/zy/asrs/task/handler/WorkMastHandler.java
@@ -3,7 +3,9 @@
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.core.common.Cools;
import com.zy.asrs.entity.*;
import com.zy.asrs.mapper.LocDetlMapper;
import com.zy.asrs.mapper.OrderDetlMapper;
import com.zy.asrs.mapper.OrderMapper;
import com.zy.asrs.service.*;
import com.zy.asrs.task.AbstractHandler;
import com.zy.asrs.task.core.ReturnT;
@@ -16,6 +18,8 @@
import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
/**
 * Created by vincent on 2020/7/4
@@ -39,6 +43,12 @@
    private OrderDetlService orderDetlService;
    @Resource
    private OrderDetlMapper orderDetlMapper;
    @Resource
    private LocDetlMapper locDetlMapper;
    @Resource
    private OrderMapper orderMapper;
    public ReturnT<String> start(WrkMast wrkMast) {
        // 4.入库完成
        if (wrkMast.getWrkSts() == 4) {
@@ -107,7 +117,8 @@
                            locDetl.sync(wrkDetl);
                            locDetl.setLocNo(wrkMast.getLocNo()); // 库位号
                            locDetl.setAnfme(wrkDetl.getAnfme()); // 数量
                            locDetl.setZpallet(wrkDetl.getZpallet()); // 托盘条码
                            locDetl.setZpallet(wrkMast.getBarcode()); // 托盘条码
                            locDetl.setBarcode(wrkMast.getBarcode());
                            locDetl.setModiTime(now);
                            locDetl.setAppeTime(now);
                            locDetl.setBatch("");
@@ -193,6 +204,10 @@
//                        } catch (Exception ignore){}
                    }
                    // 修改捡料入库的库存明细的理货状态为待理货
                    locDetlMapper.updateLhStsByLocNo(wrkMast.getLocNo(),0);
                    // 修改库位状态 Q ====>> F
                    if (locMast.getLocSts().equals("Q")) {
                        locMast.setLocSts("F");
@@ -313,6 +328,26 @@
                            return FAIL.setMsg("库位移转 ===>> 转移库存明细数据失败; [workNo=" + wrkMast.getWrkNo() + "],[locNo=" + wrkMast.getLocNo() + "]");
                        }
                    }
                    // 备货,更新订单明细及订单状态
                    List<WrkDetl> wrkDetlList = wrkDetlService.selectList(new EntityWrapper<WrkDetl>().eq("wrk_no", wrkMast.getWrkNo()));
                    if (!wrkDetlList.isEmpty()) {
                        List<String> brands = wrkDetlList.stream().map(WrkDetl::getBrand).distinct().collect(Collectors.toList());
                        // 查询订单明细
                        List<OrderDetl> orderDetlList = orderDetlMapper.selectList(new EntityWrapper<OrderDetl>().in("brand", brands));
                        if (!orderDetlList.isEmpty()) {
                            // 更新明细为已备货
                            orderDetlMapper.updateOrderDetlStatusByPackageNo(brands,2);
                            // 获取订单号
                            String orderNo = orderDetlList.get(0).getOrderNo();
                            // 判断该订单明细是否全部已备货
                            Integer selectCount = orderDetlMapper.selectCount(new EntityWrapper<OrderDetl>().eq("order_no", orderNo).ne("inspect", 2));
                            if (selectCount == 0) {
                                // 更新订单为备货完成
                                orderMapper.updateStatusByOrderNo(orderNo,2,29);
                            }
                        }
                    }
                    // 修改源库位状态 ==> O
                    LocMast sourceLoc = locMastService.selectById(wrkMast.getSourceLocNo());
                    if (null != sourceLoc) {
@@ -339,6 +374,107 @@
                        return FAIL.setMsg("库位移转 ===>> 修改目标库位状态失败; [workNo=" + wrkMast.getWrkNo() + "],[locNo=" + wrkMast.getLocNo() + "]");
                    }
                    break;
                // 跨巷道库位移转完成
                case 12:
                    // 默认目标库位是空板
                    String locSts2 = "D";
                    // 库位移转判断是否为空板移转
                    if (wrkMast.getEmptyMk().equals("N")) {
                        locSts2 = "F";
                        // 转移库存明细数据: 库存号 由工作档源库位变为目标库位
                        if (!locDetlService.updateLocNo(wrkMast.getLocNo(), wrkMast.getSourceLocNo())) {
//                            exceptionHandle("库位移转 ===>> 转移库存明细数据失败;[源库位={0}],[目标库位={1}]", wrkMast.getSourceLocNo(), wrkMast.getLocNo());
                            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                            return FAIL.setMsg("库位移转 ===>> 转移库存明细数据失败; [workNo=" + wrkMast.getWrkNo() + "],[locNo=" + wrkMast.getLocNo() + "]");
                        }
                    }
                    // 跨巷道移库,更新订单明细及订单状态
                    List<WrkDetl> wrkDetlList2 = wrkDetlService.selectList(new EntityWrapper<WrkDetl>().eq("wrk_no", wrkMast.getWrkNo()));
                    if (!wrkDetlList2.isEmpty()) {
                        // 判断有无单据编号
                        Optional<WrkDetl> any = wrkDetlList2.stream().filter(wrkDetl -> wrkDetl.getOrderNo() != null).findAny();
                        if (any.isPresent()) {
                            String orderNo = any.get().getOrderNo();
                            // 根据单据编号和库位号查询单据明细
                            List<OrderDetl> orderDetlList = orderDetlMapper.selectList(new EntityWrapper<OrderDetl>().in("order_no",orderNo).eq("specs",wrkMast.getSourceLocNo()));
                            // 更新单据明细的移库状态
                            for(OrderDetl orderDetl: orderDetlList) {
                                orderDetl.setDanger(2);
                                orderDetl.setUpdateTime(now);
                                orderDetlMapper.updateById(orderDetl);
                            }
                            // 判断单据明细是不是全部移库完成
                            Integer count = orderDetlMapper.selectCount(new EntityWrapper<OrderDetl>().lt("danger", 2).eq("order_no", orderNo));
                            if (count == 0) {
                                // 更新单据为已完成
                                orderMapper.updateSettleByOrderNo(orderNo,4,null);
                            }
                        }
                    } else { // 空板转移没有工作明细,但是要更新单据明细状态
                        // 只有一条作业中的移库单据
                        List<Order> orderList = orderMapper.selectList(new EntityWrapper<Order>().eq("doc_type", 24).le("settle", 3));
                        if(orderList.isEmpty()) {
                            log.error("没有获取到正在执行中的移库单据");
                        } else {
                            Order order = orderList.get(0);
                            // 根据单据编号和库位号查询单据明细
                            List<OrderDetl> orderDetlList = orderDetlMapper.selectList(new EntityWrapper<OrderDetl>().in("order_no",order.getOrderNo()).eq("specs",wrkMast.getSourceLocNo()));
                            // 更新单据明细的移库状态
                            for(OrderDetl orderDetl: orderDetlList) {
                                orderDetl.setDanger(2);
                                orderDetl.setUpdateTime(now);
                                orderDetlMapper.updateById(orderDetl);
                            }
                            // 判断单据明细是不是全部移库完成
                            Integer count = orderDetlMapper.selectCount(new EntityWrapper<OrderDetl>().lt("danger", 2).eq("order_no", order.getOrderNo()));
                            if (count == 0) {
                                // 更新单据为已完成
                                orderMapper.updateSettleByOrderNo(order.getOrderNo(),4,null);
                            }
                        }
                    }
                    // 修改源库位状态 ==> O
                    LocMast sourceLoc2 = locMastService.selectById(wrkMast.getSourceLocNo());
                    if (null != sourceLoc2) {
                        sourceLoc2.setBarcode("");
                        sourceLoc2.setLocSts("O");
                        sourceLoc2.setSheetNo("0");
                        sourceLoc2.setModiTime(now);
                        sourceLoc2.setIoTime(now);
                        if (!locMastService.updateById(sourceLoc2)) {
//                            exceptionHandle("库位移转 ===>> 修改源库位状态失败;[workNo={0}],[sourceLoc={1}]", wrkMast.getWrkNo(), wrkMast.getSourceLocNo());
                            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                            return FAIL.setMsg("库位移转 ===>> 修改源库位状态失败; [workNo=" + wrkMast.getWrkNo() + "],[locNo=" + wrkMast.getLocNo() + "]");
                        }
                    }
                    // 修改目标库位状态 ==> .locSts
                    locMast.setLocSts(locSts2);
                    locMast.setBarcode(wrkMast.getBarcode());
                    locMast.setSheetNo("0");
                    locMast.setIoTime(now);
                    locMast.setModiTime(now);
                    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() + "]");
                    }
                    break;
                // 空闲理货入库
                case 59:
                    // 修改库位状态 S ====>> F
                    if (locMast.getLocSts().equals("S")) {
                        locMast.setLocSts("F");
                        locMast.setModiTime(now);
                        locMastService.updateById(locMast);
                    }
                    // 修改空闲理货入库的库存明细的理货状态为待理货
                    locDetlMapper.updateLhStsByLocNo(wrkMast.getLocNo(),0);
                    break;
                default:
                    break;
            }