自动化立体仓库 - WMS系统
#
zhou zhou
15 小时以前 e5a6b55a27c9e6a58cc153331bb2e61d346812fa
src/main/java/com/zy/asrs/service/impl/MobileServiceImpl.java
@@ -136,7 +136,7 @@
    @Override
    @Transactional
    public R WarehouseOutPickMergeV1(WarehouseOutPickMergeParam param, Long hostId, Long userId) {
        //判断库位状态
        // 判断库位状态
        LocMast locMast = locMastService.selectOne(new EntityWrapper<LocMast>().eq("loc_no", param.getLocNo()));
        if (Cools.isEmpty(locMast)) {
            return R.error("该库位不存在");
@@ -205,7 +205,10 @@
                if (Cools.isEmpty(order)) {
                    continue;
                }
                OrderDetlPakin orderDetlPakin = orderDetlPakinService.selectItem(order.getId(), orderDetl.getMatnr(), orderDetl.getBatch(), orderDetl.getBrand(), orderDetl.getStandby1(), orderDetl.getStandby2(), orderDetl.getStandby3(), orderDetl.getBoxType1(), orderDetl.getBoxType2(), orderDetl.getBoxType3());
                OrderDetlPakin orderDetlPakin = orderDetlPakinService.selectItem(order.getId(), orderDetl.getMatnr(),
                        orderDetl.getBatch(), orderDetl.getBrand(), orderDetl.getStandby1(), orderDetl.getStandby2(),
                        orderDetl.getStandby3(), orderDetl.getBoxType1(), orderDetl.getBoxType2(),
                        orderDetl.getBoxType3());
                if (Cools.isEmpty(orderDetlPakin)) {
                    continue;
                }
@@ -213,8 +216,11 @@
                    throw new CoolException("并板数量出错,订单剩余出库数量小于已出库数量与将并板数量之和!!!");
                }
                // 修改订单明细作业数量
                if (!orderDetlPakinService.increaseWorkQty(orderDetlPakin.getOrderId(), orderDetlPakin.getMatnr(), orderDetlPakin.getBatch(), orderDetlPakin.getBrand(),
                        orderDetlPakin.getStandby1(), orderDetlPakin.getStandby2(), orderDetlPakin.getStandby3(), orderDetlPakin.getBoxType1(), orderDetlPakin.getBoxType2(), orderDetlPakin.getBoxType3(), orderDetl.getAnfme())) {
                if (!orderDetlPakinService.increaseWorkQty(orderDetlPakin.getOrderId(), orderDetlPakin.getMatnr(),
                        orderDetlPakin.getBatch(), orderDetlPakin.getBrand(),
                        orderDetlPakin.getStandby1(), orderDetlPakin.getStandby2(), orderDetlPakin.getStandby3(),
                        orderDetlPakin.getBoxType1(), orderDetlPakin.getBoxType2(), orderDetlPakin.getBoxType3(),
                        orderDetl.getAnfme())) {
                    throw new CoolException("修改单据明细工作数量失败");
                }
@@ -250,17 +256,17 @@
            return R.error("站点不存在");
        }
        OrderDetlPakin orderDetlPakin = null;
        //检验传参是否和订单明细匹配
        // 检验传参是否和订单明细匹配
        for (PickMatParam matParam : param.getList()) {
            orderDetlPakin = orderDetlPakinService.selectItem
                    (matParam.getOrderNo(), matParam.getMatnr(), matParam.getBatch(), matParam.getBrand(),
                            matParam.getStandby1(), matParam.getStandby2(), matParam.getStandby3(),
                            matParam.getBoxType1(), matParam.getBoxType2(), matParam.getBoxType3());
            orderDetlPakin = orderDetlPakinService.selectItem(matParam.getOrderNo(), matParam.getMatnr(),
                    matParam.getBatch(), matParam.getBrand(),
                    matParam.getStandby1(), matParam.getStandby2(), matParam.getStandby3(),
                    matParam.getBoxType1(), matParam.getBoxType2(), matParam.getBoxType3());
            if (orderDetlPakin == null) {
                return R.error("物料数据不存在");
            }
            //剩余可用数量
            // 剩余可用数量
            double count = orderDetlPakin.getAnfme() - orderDetlPakin.getWorkQty();
            if (matParam.getCount() != count) {
                return R.error("物料数据已过期");
@@ -326,14 +332,15 @@
                throw new CoolException("保存工作档明细失败");
            }
            //更新订单工作数量
            // 更新订单工作数量
            orderDetlPakinService.increaseWorkQty(orderDetlPakin.getOrderId(), matParam.getMatnr(),
                    matParam.getBatch(), matParam.getBrand(), matParam.getStandby1(), matParam.getStandby2(), matParam.getStandby3(),
                    matParam.getBatch(), matParam.getBrand(), matParam.getStandby1(), matParam.getStandby2(),
                    matParam.getStandby3(),
                    matParam.getBoxType1(), matParam.getBoxType2(), matParam.getBoxType3(), matParam.getUseCount());
            // 更新工作档状态
            orderPakinService.updateSettle(orderDetlPakin.getOrderId(), 2L, userId);
        }
        // 修改库位状态:   F.在库 ====>>> R.出库预约/P.拣料/盘点/并板出库中
        // 修改库位状态: F.在库 ====>>> R.出库预约/P.拣料/盘点/并板出库中
        locMast = locMastService.selectOne(new EntityWrapper<LocMast>().eq("loc_no", param.getLocNo()));
        if (locMast.getLocSts().equals("F")) {
            locMast.setLocSts("P");
@@ -352,7 +359,7 @@
    @Override
    @Transactional
    public R WarehouseOutV1(CombParam combParam, Long hostId, Long userId) {
        //判断库位状态
        // 判断库位状态
        LocMast locMast = locMastService.selectOne(new EntityWrapper<LocMast>().eq("loc_no", combParam.getLocNo()));
        if (Cools.isEmpty(locMast)) {
            return R.error("该库位不存在");
@@ -360,12 +367,11 @@
        if (!locMast.getLocSts().equals("P")) {
            return R.error("该库位状态为:" + locMast.getLocSts() + ",不满足并板途中拣选条件!!!");
        }
        //查询库存数据
        // 查询库存数据
        for (CombParam.CombMat combMat : combParam.getCombMats()) {
            List<LocDetl> locDetlList = locDetlService.selectList(new EntityWrapper<LocDetl>()
                    .eq("loc_no", combParam.getLocNo())
                    .eq("matnr", combMat.getMatnr())
            );
                    .eq("matnr", combMat.getMatnr()));
            if (locDetlList.isEmpty()) {
                return R.error("未查询到库存数据");
            }
@@ -384,8 +390,10 @@
                if (orderPakout.getSettle() == 1) {
                    OrderInAndOutUtil.updateOrder(false, orderPakout.getId(), 2L, 9527L);
                }
                OrderDetlPakout orderDetlPakout = orderDetlPakoutService.selectItem(orderPakout.getId(), combMat.getMatnr(), combMat.getBatch(),
                        combMat.getBrand(), combMat.getStandby1(), combMat.getStandby2(), combMat.getStandby3(), combMat.getBoxType1(), combMat.getBoxType2(), combMat.getBoxType3());
                OrderDetlPakout orderDetlPakout = orderDetlPakoutService.selectItem(orderPakout.getId(),
                        combMat.getMatnr(), combMat.getBatch(),
                        combMat.getBrand(), combMat.getStandby1(), combMat.getStandby2(), combMat.getStandby3(),
                        combMat.getBoxType1(), combMat.getBoxType2(), combMat.getBoxType3());
                if (Cools.isEmpty(orderDetlPakout)) {
                    continue;
                }
@@ -393,17 +401,22 @@
                    throw new CoolException("拣选数量出错,订单剩余出库数量小于已出库数量与将拣选数量之和!!!");
                }
                // 修改订单明细作业数量
                if (!orderDetlPakoutService.increaseWorkQty(orderDetlPakout.getOrderId(), combMat.getMatnr(), combMat.getBatch(), combMat.getBrand(),
                        combMat.getStandby1(), combMat.getStandby2(), combMat.getStandby3(), combMat.getBoxType1(), combMat.getBoxType2(), combMat.getBoxType3(), combMat.getAnfme())) {
                if (!orderDetlPakoutService.increaseWorkQty(orderDetlPakout.getOrderId(), combMat.getMatnr(),
                        combMat.getBatch(), combMat.getBrand(),
                        combMat.getStandby1(), combMat.getStandby2(), combMat.getStandby3(), combMat.getBoxType1(),
                        combMat.getBoxType2(), combMat.getBoxType3(), combMat.getAnfme())) {
                    throw new CoolException("修改单据明细工作数量失败");
                }
//                // 修改订单明细完成数量
//                if (!orderDetlPakoutService.increase(orderPakout.getId(),combMat.getMatnr(), combMat.getBatch(), combMat.getBrand(),
//                        combMat.getStandby1(), combMat.getStandby2(), combMat.getStandby3(), combMat.getBoxType1(), combMat.getBoxType2(), combMat.getBoxType3(),combMat.getAnfme())) {
//                    throw new CoolException("修改单据明细完成数量失败");
//                }
//                // 修改订单状态 作业中 ===>> 已完成
//                orderPakoutService.checkComplete(combMat.getOrderNo());
                // // 修改订单明细完成数量
                // if (!orderDetlPakoutService.increase(orderPakout.getId(),combMat.getMatnr(),
                // combMat.getBatch(), combMat.getBrand(),
                // combMat.getStandby1(), combMat.getStandby2(), combMat.getStandby3(),
                // combMat.getBoxType1(), combMat.getBoxType2(),
                // combMat.getBoxType3(),combMat.getAnfme())) {
                // throw new CoolException("修改单据明细完成数量失败");
                // }
                // // 修改订单状态 作业中 ===>> 已完成
                // orderPakoutService.checkComplete(combMat.getOrderNo());
            }
            try {
                Date now = new Date();
@@ -512,8 +525,7 @@
            List<WrkMast> wrkMasts = wrkMastService.selectList(new EntityWrapper<WrkMast>()
                    .like("barcode", barcode)
                    .eq("wrk_sts", 199L)
                    .eq("io_type", 103)
            );
                    .eq("io_type", 103));
            wrkMastArrayList.addAll(wrkMasts);
            List<WrkMast> wrkMasts1 = wrkMastService.selectList(new EntityWrapper<WrkMast>()
                    .like("barcode", barcode)
@@ -542,7 +554,7 @@
            orderIds.add(order.getId());
        }
        //搜索明细
        // 搜索明细
        Wrapper<OrderDetl> wrapper1 = new EntityWrapper<>();
        wrapper1.eq("status", 1);
        wrapper1.in("order_id", orderIds);
@@ -557,7 +569,7 @@
        ArrayList<PickMatParam> maps = new ArrayList<>();
        for (OrderDetl orderDetl : list) {
            //剩余可用数量
            // 剩余可用数量
            double count = orderDetl.getAnfme() - orderDetl.getWorkQty();
            if (count <= 0) {
                continue;
@@ -585,8 +597,7 @@
            throw new CoolException("请提取一个商品,或者刷新重新组托!");
        }
        // 判断是否有相同条码的数据
        if (waitPakinService.selectCount(new EntityWrapper<WaitPakin>().
                eq("zpallet", param.getBarcode())
        if (waitPakinService.selectCount(new EntityWrapper<WaitPakin>().eq("zpallet", param.getBarcode())
                .eq("io_status", "N")) > 0) {
            throw new CoolException(param.getBarcode() + "数据正在进行入库");
        }
@@ -594,9 +605,9 @@
        if (Objects.isNull(param.getBarcode())) {
            throw new CoolException("托盘码不能为空!!");
        }
//        if (param.getBarcode().length() != 8) {
//            throw new CoolException("条码长度不是8位===>>" + param.getBarcode());
//        }
        // if (param.getBarcode().length() != 8) {
        // throw new CoolException("条码长度不是8位===>>" + param.getBarcode());
        // }
        if (Objects.isNull(param.getType())) {
            param.setType("0");
@@ -616,8 +627,10 @@
            // 生成入库通知档
            List<DetlDto> detlDtos = new ArrayList<>();
            param.getCombMats().forEach(elem -> {
                DetlDto detlDto = new DetlDto(elem.getMatnr(), elem.getBatch(), elem.getBrand(), elem.getStandby1(), elem.getStandby2(), elem.getStandby3(),
                        elem.getBoxType1(), elem.getBoxType2(), elem.getBoxType3(), elem.getAnfme(), elem.getThreeCode());
                DetlDto detlDto = new DetlDto(elem.getMatnr(), elem.getBatch(), elem.getBrand(), elem.getStandby1(),
                        elem.getStandby2(), elem.getStandby3(),
                        elem.getBoxType1(), elem.getBoxType2(), elem.getBoxType3(), elem.getAnfme(),
                        elem.getThreeCode());
                if (DetlDto.has(detlDtos, detlDto)) {
                    DetlDto one = DetlDto.findDto(detlDtos, detlDto);
                    assert one != null;
@@ -659,7 +672,7 @@
            }
            // 关联组托
        } else {
//            Order order = orderService.selectByNo(param.getOrderNo());
            // Order order = orderService.selectByNo(param.getOrderNo());
            // 生成入库通知档
            List<DetlDto> detlDtos = new ArrayList<>();
            param.getCombMats().forEach(elem -> {
@@ -668,8 +681,10 @@
                    throw new CoolException("单据编号已过期");
                }
                // 订单明细数量校验
//                OrderDetl orderDetl = OrderInAndOutUtil.selectItem(Boolean.TRUE, order.getId(), elem.getMatnr(), elem.getBatch(), elem.getBrand(), elem.getStandby1(), elem.getStandby2(), elem.getStandby3(),
//                        elem.getBoxType1(), elem.getBoxType2(), elem.getBoxType3());
                // OrderDetl orderDetl = OrderInAndOutUtil.selectItem(Boolean.TRUE,
                // order.getId(), elem.getMatnr(), elem.getBatch(), elem.getBrand(),
                // elem.getStandby1(), elem.getStandby2(), elem.getStandby3(),
                // elem.getBoxType1(), elem.getBoxType2(), elem.getBoxType3());
                OrderDetlPakin detls = orderDetlPakinService.selectOne(new EntityWrapper<OrderDetlPakin>()
                        .eq("order_id", order.getId())
                        .eq("matnr", elem.getMatnr()));
@@ -681,10 +696,13 @@
                if (elem.getAnfme() > detls.getEnableQty()) {
                    throw new CoolException(detls.getMatnr() + "入库数量不合规则");
                }
                OrderInAndOutUtil.increaseWorkQty(Boolean.TRUE, order.getId(), elem.getMatnr(), elem.getBatch(), elem.getBrand(), elem.getStandby1(), elem.getStandby2(), elem.getStandby3(),
                OrderInAndOutUtil.increaseWorkQty(Boolean.TRUE, order.getId(), elem.getMatnr(), elem.getBatch(),
                        elem.getBrand(), elem.getStandby1(), elem.getStandby2(), elem.getStandby3(),
                        elem.getBoxType1(), elem.getBoxType2(), elem.getBoxType3(), elem.getAnfme());
                DetlDto detlDto = new DetlDto(elem.getMatnr(), elem.getBatch(), elem.getBrand(), elem.getStandby1(), elem.getStandby2(), elem.getStandby3(),
                        elem.getBoxType1(), elem.getBoxType2(), elem.getBoxType3(), elem.getAnfme(), elem.getThreeCode());
                DetlDto detlDto = new DetlDto(elem.getMatnr(), elem.getBatch(), elem.getBrand(), elem.getStandby1(),
                        elem.getStandby2(), elem.getStandby3(),
                        elem.getBoxType1(), elem.getBoxType2(), elem.getBoxType3(), elem.getAnfme(),
                        elem.getThreeCode());
                detlDto.setOrderId(order.getId());
                detlDto.setOrderNo(order.getOrderNo());
                if (DetlDto.has(detlDtos, detlDto)) {
@@ -703,45 +721,48 @@
                throw new CoolException("组托物料类型不一致,只有相同的物料分类才可以组托!!");
            }
//            BasContainer container = basContainerService.selectOne(new EntityWrapper<BasContainer>().eq("barcode", param.getBarcode()));
//            if (Objects.isNull(container)) {
//                throw new CoolException("数据错误:容器码不存在!!");
//            }
//            if (container.getMixMax() < detlDtos.size()) {
//                throw new CoolException("超出容器最大混装数量,当前容器最大数量为:" + container.getMixMax() + "!!");
//            }
            //还可以放入多少种物料
//            Integer suplus = container.getMixMax();
            // BasContainer container = basContainerService.selectOne(new
            // EntityWrapper<BasContainer>().eq("barcode", param.getBarcode()));
            // if (Objects.isNull(container)) {
            // throw new CoolException("数据错误:容器码不存在!!");
            // }
            // if (container.getMixMax() < detlDtos.size()) {
            // throw new CoolException("超出容器最大混装数量,当前容器最大数量为:" + container.getMixMax() +
            // "!!");
            // }
            // 还可以放入多少种物料
            // Integer suplus = container.getMixMax();
            for (DetlDto detlDto : detlDtos) {
                Mat mat = matService.selectByMatnr(detlDto.getMatnr());
                if (Cools.isEmpty(mat)) {
                    throw new CoolException(detlDto.getMatnr() + "商品档案不存在");
                }
//                //最多可放数量
//                Double singleMax = mat.getUpQty() * suplus;
//                if (singleMax.compareTo(detlDto.getAnfme()) < 0) {
//                    throw new CoolException("物料:" + detlDto.getMatnr() + "单次组托上限为:" + mat.getUpQty() + ",当前总量超出托盘装载上限!!");
//                }
//                BigDecimal decimal = new BigDecimal(detlDto.getAnfme() / mat.getUpQty());
//                //当前物料需要占用料箱格数
//                Integer curr = decimal.setScale(0, RoundingMode.CEILING).intValue();
//                suplus = suplus - curr;
//                if (suplus < 0) {
//                    throw new CoolException("物料:" + detlDto.getMatnr() + ", 超出当前托盘装载上限!!");
//                }
                // //最多可放数量
                // Double singleMax = mat.getUpQty() * suplus;
                // if (singleMax.compareTo(detlDto.getAnfme()) < 0) {
                // throw new CoolException("物料:" + detlDto.getMatnr() + "单次组托上限为:" +
                // mat.getUpQty() + ",当前总量超出托盘装载上限!!");
                // }
                // BigDecimal decimal = new BigDecimal(detlDto.getAnfme() / mat.getUpQty());
                // //当前物料需要占用料箱格数
                // Integer curr = decimal.setScale(0, RoundingMode.CEILING).intValue();
                // suplus = suplus - curr;
                // if (suplus < 0) {
                // throw new CoolException("物料:" + detlDto.getMatnr() + ", 超出当前托盘装载上限!!");
                // }
                WaitPakin waitPakin = new WaitPakin();
                BeanUtils.copyProperties(mat, waitPakin);
                waitPakin.setOrderNo(detlDto.getOrderNo());   // 单据编号
                waitPakin.setOrderNo(detlDto.getOrderNo()); // 单据编号
                waitPakin.setType(param.getType());
                waitPakin.setOrderId(detlDto.getOrderId());
                waitPakin.setBatch(detlDto.getBatch());     // 序列码
                waitPakin.setZpallet(param.getBarcode());   // 托盘码
                waitPakin.setBatch(detlDto.getBatch()); // 序列码
                waitPakin.setZpallet(param.getBarcode()); // 托盘码
                waitPakin.setThreeCode(detlDto.getThreeCode());
                waitPakin.setSuppCode(detlDto.getStandby1());
                waitPakin.setIoStatus("N");     // 入出状态
                waitPakin.setAnfme(detlDto.getAnfme());  // 数量
                waitPakin.setStatus("Y");    // 状态
                waitPakin.setIoStatus("N"); // 入出状态
                waitPakin.setAnfme(detlDto.getAnfme()); // 数量
                waitPakin.setStatus("Y"); // 状态
                waitPakin.setAppeUser(userId);
                waitPakin.setAppeTime(now);
                waitPakin.setModiUser(userId);
@@ -751,7 +772,8 @@
                }
            }
            Set<String> stringSet = param.getCombMats().stream().map(CombParam.CombMat::getOrderNo).collect(Collectors.toSet());
            Set<String> stringSet = param.getCombMats().stream().map(CombParam.CombMat::getOrderNo)
                    .collect(Collectors.toSet());
            stringSet.forEach(orderNo -> {
                Order order = OrderInAndOutUtil.selectByNo(Boolean.TRUE, orderNo);
                OrderInAndOutUtil.updateOrder(Boolean.TRUE, order.getId(), 2L, userId);
@@ -781,7 +803,7 @@
                throw new CoolException(combMat.getMatnr() + ":商品数量有误!");
            }
            if (Cools.isEmpty(combMat.getBatch())) {
//                throw new CoolException(combMat.getMatnr() + ":商品批号有误!");
                // throw new CoolException(combMat.getMatnr() + ":商品批号有误!");
            }
            ManLocDetl manLocDetl = new ManLocDetl();
            manLocDetl.setLocNo(locno);
@@ -815,7 +837,6 @@
    // 查找商品
    @Override
    @Transactional
    public void adjust(MobileAdjustParam param, Long userId) {
@@ -845,12 +866,15 @@
                if (wrkDetl1.getAnfme() == 0) {
                    iterator1.remove();
                }
                if (wrkDetl.getMatnr().equals(wrkDetl1.getMatnr()) && Cools.eq(wrkDetl.getBatch(), wrkDetl1.getBatch())) {
                if (wrkDetl.getMatnr().equals(wrkDetl1.getMatnr())
                        && Cools.eq(wrkDetl.getBatch(), wrkDetl1.getBatch())) {
                    if (!wrkDetl.getAnfme().equals(wrkDetl1.getAnfme())) {
                        // todo 盘点记录、保存调整记录
                        // 修改明细
                        if (!wrkDetlService.updateAnfme(wrkDetl1.getAnfme(), wrkMast.getWrkNo(), wrkDetl.getMatnr(), wrkDetl.getBatch())) {
                            throw new CoolException(wrkMast.getWrkNo() + "盘点任务," + wrkDetl.getMatnr() + "商品," + wrkDetl.getBatch() + "批号修改数量失败");
                        if (!wrkDetlService.updateAnfme(wrkDetl1.getAnfme(), wrkMast.getWrkNo(), wrkDetl.getMatnr(),
                                wrkDetl.getBatch())) {
                            throw new CoolException(wrkMast.getWrkNo() + "盘点任务," + wrkDetl.getMatnr() + "商品,"
                                    + wrkDetl.getBatch() + "批号修改数量失败");
                        }
                    }
                    iterator.remove();
@@ -863,7 +887,8 @@
        for (WrkDetl wrkDetl : wrkDetls) {
            // todo 盘点记录、保存调整记录
            if (!wrkDetlService.updateAnfme(-1.0D, wrkMast.getWrkNo(), wrkDetl.getMatnr(), wrkDetl.getBatch())) {
                throw new CoolException("删除" + wrkMast.getWrkNo() + "盘点任务," + wrkDetl.getMatnr() + "商品," + wrkDetl.getBatch() + "批号任务明细失败");
                throw new CoolException("删除" + wrkMast.getWrkNo() + "盘点任务," + wrkDetl.getMatnr() + "商品,"
                        + wrkDetl.getBatch() + "批号任务明细失败");
            }
        }
@@ -882,7 +907,8 @@
            wrkDetl.setAppeTime(now);
            wrkDetl.setAppeUser(userId);
            if (!wrkDetlService.insert(wrkDetl)) {
                throw new CoolException("添加" + wrkMast.getWrkNo() + "盘点任务," + wrkDetl.getMatnr() + "商品," + wrkDetl.getBatch() + "批号任务明细失败");
                throw new CoolException("添加" + wrkMast.getWrkNo() + "盘点任务," + wrkDetl.getMatnr() + "商品,"
                        + wrkDetl.getBatch() + "批号任务明细失败");
            }
        }
@@ -903,8 +929,8 @@
            throw new CoolException(BaseRes.PARAM);
        }
        // 判断是否有相同条码的数据
        if (waitPakinService.selectCount(new EntityWrapper<WaitPakin>().
                eq("zpallet", param.getBarcode()).eq("io_status", "N")) > 0) {
        if (waitPakinService.selectCount(
                new EntityWrapper<WaitPakin>().eq("zpallet", param.getBarcode()).eq("io_status", "N")) > 0) {
            throw new CoolException(param.getBarcode() + "数据正在进行入库");
        }
        Date now = new Date();
@@ -929,11 +955,15 @@
                }
                Mat analyse = MatUtils.analyseMat(elem.getMatnr());
                // 条码、物料代码、序列号、数量
                DetlDto detlDto = new DetlDto(elem.getMatnr(), elem.getBatch(), analyse.getBrand(), elem.getStandby1(), elem.getStandby2(), elem.getStandby3(),
                        elem.getBoxType1(), elem.getBoxType2(), elem.getBoxType3(), elem.getAnfme(), elem.getThreeCode());
                DetlDto detlDto = new DetlDto(elem.getMatnr(), elem.getBatch(), analyse.getBrand(), elem.getStandby1(),
                        elem.getStandby2(), elem.getStandby3(),
                        elem.getBoxType1(), elem.getBoxType2(), elem.getBoxType3(), elem.getAnfme(),
                        elem.getThreeCode());
//                DetlDto detlDto = new DetlDto(elem.getMatnr(), analyse.getMatnr(), analyse.getBarcode(), elem.getAnfme());
//                DetlDto detlDto = new DetlDto(elem.getMatnr(), elem.getBatch(), elem.getAnfme());
                // DetlDto detlDto = new DetlDto(elem.getMatnr(), analyse.getMatnr(),
                // analyse.getBarcode(), elem.getAnfme());
                // DetlDto detlDto = new DetlDto(elem.getMatnr(), elem.getBatch(),
                // elem.getAnfme());
                if (DetlDto.has(detlDtos, detlDto)) {
                    DetlDto one = DetlDto.findDto(detlDtos, detlDto);
                    assert one != null;
@@ -967,10 +997,12 @@
                    if (jsonObject.getInteger("code").equals(200)) {
                        success = true;
                    } else if (jsonObject.getInteger("code").equals(500)) {
                        log.error("请求接口失败!!!url:{};request:{};response:{}", MesConstant.URL + MesConstant.PACK_DOWN_URL, JSON.toJSONString(mesCombParam), response);
                        log.error("请求接口失败!!!url:{};request:{};response:{}", MesConstant.URL + MesConstant.PACK_DOWN_URL,
                                JSON.toJSONString(mesCombParam), response);
                        throw new CoolException(jsonObject.getString("msg"));
                    } else {
                        log.error("请求接口失败!!!url:{};request:{};response:{}", MesConstant.URL + MesConstant.PACK_DOWN_URL, JSON.toJSONString(mesCombParam), response);
                        log.error("请求接口失败!!!url:{};request:{};response:{}", MesConstant.URL + MesConstant.PACK_DOWN_URL,
                                JSON.toJSONString(mesCombParam), response);
                        throw new CoolException("上报mes系统失败");
                    }
                } catch (Exception e) {
@@ -986,8 +1018,7 @@
                                "127.0.0.1",
                                JSON.toJSONString(mesCombParam),
                                response,
                                success
                        );
                                success);
                    } catch (Exception e) {
                        log.error("", e);
                    }
@@ -1002,15 +1033,15 @@
            openParam.setOrderType("打包入库单");
            openParam.setOrderDetails(detlDtos);
            openService.pakinOrderCreate(openParam);
//            Order order = orderService.selectByNo(orderNo);
            // Order order = orderService.selectByNo(orderNo);
            Order order = OrderInAndOutUtil.selectByNo(Boolean.TRUE, param.getOrderNo());
            if (null == order) {
                throw new CoolException("生成单据失败");
            }
//            if (!orderService.updateSettle(order.getId(), 2L, userId)) {
//                throw new CoolException("修改单据状态失败");
//            }
            // if (!orderService.updateSettle(order.getId(), 2L, userId)) {
            // throw new CoolException("修改单据状态失败");
            // }
            OrderInAndOutUtil.updateOrder(Boolean.TRUE, order.getId(), 2L, userId);
            // 生成入库通知档
@@ -1018,18 +1049,22 @@
                // 修改作业数量 ----------------------------------------
                // 订单明细数量校验
//                OrderDetl orderDetl = orderDetlService.selectItem(order.getId(), detlDto.getMatnr(), detlDto.getBatch());
                OrderDetl orderDetl = OrderInAndOutUtil.selectItem(Boolean.TRUE, order.getId(), detlDto.getMatnr(), detlDto.getBatch(), detlDto.getBrand(), detlDto.getStandby1(), detlDto.getStandby2(), detlDto.getStandby3()
                        , detlDto.getBoxType1(), detlDto.getBoxType2(), detlDto.getBoxType3());
                // OrderDetl orderDetl = orderDetlService.selectItem(order.getId(),
                // detlDto.getMatnr(), detlDto.getBatch());
                OrderDetl orderDetl = OrderInAndOutUtil.selectItem(Boolean.TRUE, order.getId(), detlDto.getMatnr(),
                        detlDto.getBatch(), detlDto.getBrand(), detlDto.getStandby1(), detlDto.getStandby2(),
                        detlDto.getStandby3(), detlDto.getBoxType1(), detlDto.getBoxType2(), detlDto.getBoxType3());
                if (detlDto.getAnfme() > orderDetl.getEnableQty()) {
                    throw new CoolException(orderDetl.getMatnr() + "入库数量不合法");
                }
                // 修改订单作业数量
//                if (!orderDetlService.increaseWorkQty(order.getId(), detlDto.getMatnr(), detlDto.getBatch(), detlDto.getAnfme())) {
//                    throw new CoolException("修改单据作业数量失败");
//                }
                OrderInAndOutUtil.increaseWorkQty(Boolean.TRUE, order.getId(), detlDto.getMatnr(), detlDto.getBatch(), detlDto.getBrand(), detlDto.getStandby1(), detlDto.getStandby2(), detlDto.getStandby3()
                        , detlDto.getBoxType1(), detlDto.getBoxType2(), detlDto.getBoxType3(), detlDto.getAnfme());
                // if (!orderDetlService.increaseWorkQty(order.getId(), detlDto.getMatnr(),
                // detlDto.getBatch(), detlDto.getAnfme())) {
                // throw new CoolException("修改单据作业数量失败");
                // }
                OrderInAndOutUtil.increaseWorkQty(Boolean.TRUE, order.getId(), detlDto.getMatnr(), detlDto.getBatch(),
                        detlDto.getBrand(), detlDto.getStandby1(), detlDto.getStandby2(), detlDto.getStandby3(),
                        detlDto.getBoxType1(), detlDto.getBoxType2(), detlDto.getBoxType3(), detlDto.getAnfme());
                // 保存入库通知档
                Mat mat = matService.selectByMatnr(detlDto.getMatnr());
                if (Cools.isEmpty(mat)) {
@@ -1039,10 +1074,10 @@
                BeanUtils.copyProperties(mat, waitPakin);
                waitPakin.setOrderNo(orderNo);
                waitPakin.setBatch(detlDto.getBatch());
                waitPakin.setZpallet(param.getBarcode());   // 托盘码
                waitPakin.setIoStatus("N");     // 入出状态
                waitPakin.setAnfme(detlDto.getAnfme());  // 数量
                waitPakin.setStatus("Y");    // 状态
                waitPakin.setZpallet(param.getBarcode()); // 托盘码
                waitPakin.setIoStatus("N"); // 入出状态
                waitPakin.setAnfme(detlDto.getAnfme()); // 数量
                waitPakin.setStatus("Y"); // 状态
                waitPakin.setAppeUser(userId);
                waitPakin.setAppeTime(now);
                waitPakin.setModiUser(userId);
@@ -1070,25 +1105,27 @@
        String orderNo = param.containsKey("orderNo") ? param.get("orderNo").toString() : "";
        BasDevp sta = basDevpService.checkSiteStatus(staNo);
        //根据订单号生成出库任务工作档
        // 根据订单号生成出库任务工作档
        Order order = OrderInAndOutUtil.selectByNo(Boolean.FALSE, orderNo);
//        Order order = orderService.selectOne(new EntityWrapper<Order>().eq("order_no", orderNo));
        // Order order = orderService.selectOne(new
        // EntityWrapper<Order>().eq("order_no", orderNo));
        if (order.getSettle() != 1 && order.getSettle() != 2) {
            throw new CoolException("该订单已处理");
        }
//        List<OrderDetl> orderDetls = orderDetlService.selectList(new EntityWrapper<OrderDetl>().eq("order_no", orderNo));
        // List<OrderDetl> orderDetls = orderDetlService.selectList(new
        // EntityWrapper<OrderDetl>().eq("order_no", orderNo));
        List<OrderDetl> orderDetls = OrderInAndOutUtil.selectByOrderId(Boolean.FALSE, order.getId());
        Date now = new Date();
        for (OrderDetl orderDetl : orderDetls) {
            //查询所有库位状态为F的库位信息
            // 查询所有库位状态为F的库位信息
            List<LocDetl> locDetls = locDetlService.queryStock(orderDetl.getMatnr(), orderDetl.getBatch(), null, null);
            if (locDetls.size() == 0) {
                throw new CoolException("库存中没有该物料");
            }
            for (LocDetl locDetl : locDetls) {
                //如果该库位出库路线所用的堆垛机out_enable不为Y,跳过该循环
                // 如果该库位出库路线所用的堆垛机out_enable不为Y,跳过该循环
                LocMast locMast = locMastService.selectOne(new EntityWrapper<LocMast>()
                        .eq("loc_no", locDetl.getLocNo()));
                if (Cools.isEmpty(locMast)) {
@@ -1100,23 +1137,24 @@
                    continue;
                }
                //可出库数量 = 订单数量 - 作业中数量
                // 可出库数量 = 订单数量 - 作业中数量
                Double outQty = orderDetl.getAnfme() - orderDetl.getWorkQty();
                if (outQty <= 0) {
                    break;
                }
                // 判断入出库类型:101.全板出库 or 103.拣料出库
                Double sumCount = locDetlService.getLocDetlSumQty(locDetl.getLocNo());
                Double curOutQty = outQty >= locDetl.getAnfme() ? locDetl.getAnfme() : outQty;   //本次出库量
                Double curOutQty = outQty >= locDetl.getAnfme() ? locDetl.getAnfme() : outQty; // 本次出库量
                int ioType = sumCount <= curOutQty ? 101 : 103;
                stockOut(orderDetl, sta, locDetl, curOutQty, ioType, userId, now);
                order.setSettle(2L);
                order.setUpdateBy(userId);
                order.setUpdateTime(now);
//                if(!orderService.update(order, new EntityWrapper<Order>().eq("order_no", orderNo))){
//                    throw new CoolException("更新订单状态失败");
//                }
                // if(!orderService.update(order, new EntityWrapper<Order>().eq("order_no",
                // orderNo))){
                // throw new CoolException("更新订单状态失败");
                // }
                OrderInAndOutUtil.updateOrder(order.getPakinPakoutStatus$(), order.getId(), 2L, userId);
                orderDetl.setWorkQty(orderDetl.getWorkQty() + curOutQty);
                orderDetl.setUpdateBy(userId);
@@ -1126,9 +1164,9 @@
                if (!Cools.isEmpty(orderDetl.getBatch())) {
                    wrapper.eq("batch", orderDetl.getBatch());
                }
//                if(!orderDetlService.update(orderDetl, wrapper)){
//                    throw new CoolException("更新订单明细失败");
//                }
                // if(!orderDetlService.update(orderDetl, wrapper)){
                // throw new CoolException("更新订单明细失败");
                // }
                OrderInAndOutUtil.updateOrderDetl(order.getPakinPakoutStatus$(), order, orderDetl);
            }
@@ -1139,7 +1177,7 @@
    @Override
    @Transactional
    public void stockOut(OrderDetl orderDetl, BasDevp staNo, LocDetl locDetl,
                         Double curOutQty, Integer ioType, Long userId, Date now) {
            Double curOutQty, Integer ioType, Long userId, Date now) {
        // 获取库位
        LocMast locMast = locMastService.selectById(locDetl.getLocNo());
        // 获取路径
@@ -1193,7 +1231,7 @@
            throw new CoolException("保存工作档明细失败");
        }
        // 修改库位状态:   F.在库 ====>>> R.出库预约/P.拣料/盘点/并板出库中
        // 修改库位状态: F.在库 ====>>> R.出库预约/P.拣料/盘点/并板出库中
        locMast = locMastService.selectById(locDetl.getLocNo());
        if (locMast.getLocSts().equals("F")) {
            locMast.setLocSts(ioType == 101 ? "R" : "P");
@@ -1233,12 +1271,13 @@
        if (Objects.isNull(params.getOrgSite())) {
            throw new CoolException("源站点不能为空!!");
        }
        BasAreas basAreas = basAreasService.selectOne(new EntityWrapper<BasAreas>().eq("whs_type_id", LocAreaType.LOC_AREA_TYPE_IN_CACHE.type));
        BasAreas basAreas = basAreasService
                .selectOne(new EntityWrapper<BasAreas>().eq("whs_type_id", LocAreaType.LOC_AREA_TYPE_IN_CACHE.type));
        LocCache locCache = locCacheService.selectOne(new EntityWrapper<LocCache>()
                .eq("area_id",basAreas.getId())
                .eq("area_id", basAreas.getId())
                .eq("frozen", 0)
                .eq("loc_sts", LocStsType.LOC_STS_TYPE_O.type)
//                .eq("loc_no", params.getTarSite())
                // .eq("loc_no", params.getTarSite())
                .orderAsc(Arrays.asList("loc_no"))
                .last("OFFSET 0 ROWS FETCH NEXT 1 ROWS ONLY"));
        if (Objects.isNull(locCache)) {
@@ -1247,10 +1286,9 @@
        try {
            generateAgvTask("agv", locCache, params.getOrgSite(), params.getBarcode(), userId);
        }catch (Exception e) {
        } catch (Exception e) {
            throw new CoolException(e.getMessage());
        }
        return R.ok();
    }
@@ -1269,7 +1307,8 @@
        if (Objects.isNull(params.getOrderNo())) {
            throw new CoolException("单号不能为空!!");
        }
        OrderPakin orderPakin = orderPakinService.selectOne(new EntityWrapper<OrderPakin>().eq("order_no", params.getOrderNo()));
        OrderPakin orderPakin = orderPakinService
                .selectOne(new EntityWrapper<OrderPakin>().eq("order_no", params.getOrderNo()));
        if (Objects.isNull(orderPakin)) {
            throw new CoolException("数据错误:单据不存在!!");
        }
@@ -1292,10 +1331,23 @@
    @Override
    @Transactional(rollbackFor = Exception.class)
    public R OutCallAgv(AgvCallParams params, Long userId) {
        /**获取入库最早的一条数据**/
        BasStation station = basStationService.selectOne(new EntityWrapper<BasStation>()
                .eq("loc_sts", LocStsType.LOC_STS_TYPE_O.type)
                .eq("dev_no", params.getTarSite()));
        if (Objects.isNull(station)) {
            throw new CoolException("请检查站点信息!");
        }
        /** 获取入库最早的一条数据 **/
        List<LocCache> locCaches = locCacheService.selectList(new EntityWrapper<LocCache>()
                .eq("loc_sts", LocStsType.LOC_STS_TYPE_F.type)
                .eq("frozen", 0)
                .in("loc_no", new EntityWrapper<LocDetl>()
                        .setSqlSelect("DISTINCT loc_no")
                        .in("matnr", new EntityWrapper<Mat>()
                                .setSqlSelect("matnr")
                                .eq("tag_id", station.getCtnType())))
                .orderDesc(Arrays.asList("sort", "first_time")));
        if (locCaches.isEmpty()) {
@@ -1303,8 +1355,9 @@
        }
        for (LocCache locCache : locCaches) {
            //获取缓存区信息
            BasAreas basAreas = basAreasService.selectOne(new EntityWrapper<BasAreas>().eq("whs_type_id", LocAreaType.LOC_AREA_TYPE_IN_CACHE.type));
            // 获取缓存区信息
            BasAreas basAreas = basAreasService.selectOne(
                    new EntityWrapper<BasAreas>().eq("whs_type_id", LocAreaType.LOC_AREA_TYPE_IN_CACHE.type));
            if (Objects.isNull(basAreas)) {
                throw new CoolException("库区不存在!!");
            }
@@ -1328,21 +1381,22 @@
            Mat mat = matList.stream().findFirst().get();
            BasStation station = basStationService.selectOne(new EntityWrapper<BasStation>()
                    .eq("loc_sts", LocStsType.LOC_STS_TYPE_O.type)
                    .eq("ctn_type", mat.getTagId())
                    .eq("dev_no", params.getTarSite()));
            if (Objects.isNull(station)) {
//            BasStation station = basStationService.selectOne(new EntityWrapper<BasStation>()
//                    .eq("loc_sts", LocStsType.LOC_STS_TYPE_O.type)
//                    .eq("ctn_type", mat.getTagId())
//                    .eq("dev_no", params.getTarSite()));
            if (mat.getTagId() != station.getCtnType().longValue()){
                continue;
            }
            /**生成缓存区出库任务*/
            /** 生成缓存区出库任务 */
            generateCacheOutTask(station, locCache, userId);
            /**生成立库出库任务*/
            /** 生成立库出库任务 */
            generateCRNOutTask(station, locCache, userId);
           return R.ok();
            return R.ok();
        }
        return R.error("未找到与站点类型匹配的库存");
    }
@@ -1352,11 +1406,9 @@
        BasAreas basAreas = basAreasService.selectOne(new EntityWrapper<BasAreas>().eq("name", params.getOrgSite()));
        List<LocCache> locCaches = locCacheService.selectList(new EntityWrapper<LocCache>()
                .eq("loc_sts", LocStsType.LOC_STS_TYPE_D.type)
                .eq("area_id", basAreas.getId())
        );
                .eq("area_id", basAreas.getId()));
        if (locCaches.isEmpty()) {
            throw new CoolException("暂无空板库位");
        }
@@ -1369,20 +1421,20 @@
        }
        generateCacheOutTask(station, locCaches.get(0), userId);
//        HIKApiDTO hikApiDTO =new HIKApiDTO()
//                .setOrg(locCaches.get(0).getLocNo())
//                .setOrgType("05")
//                .setTar(params.getTarSite())
//                .setTarType("05")
//                .setTaskType("GT5")
//                .setPriority("1")
//                .setCtnrType("2")
//                ;
//        HIKResultDTO hikResultDTO = sendAgvTask(hikApiDTO, HIKApiConstant.AGV_CALL_IN_PATH);
//        if (!hikResultDTO.isSuccess()){
//            return R.error(hikResultDTO.getMessage());
//        }
        // HIKApiDTO hikApiDTO =new HIKApiDTO()
        // .setOrg(locCaches.get(0).getLocNo())
        // .setOrgType("05")
        // .setTar(params.getTarSite())
        // .setTarType("05")
        // .setTaskType("GT5")
        // .setPriority("1")
        // .setCtnrType("2")
        // ;
        // HIKResultDTO hikResultDTO = sendAgvTask(hikApiDTO,
        // HIKApiConstant.AGV_CALL_IN_PATH);
        // if (!hikResultDTO.isSuccess()){
        // return R.error(hikResultDTO.getMessage());
        // }
        return R.ok();
    }
@@ -1403,7 +1455,8 @@
            throw new CoolException("当前暂无空库位!!");
        }
        BasStation station = basStationService.selectOne(new EntityWrapper<BasStation>().eq("dev_no", params.getOrgSite()));
        BasStation station = basStationService
                .selectOne(new EntityWrapper<BasStation>().eq("dev_no", params.getOrgSite()));
        if (Objects.isNull(station)) {
            throw new CoolException("源站点未检索到数据!!");
        }
@@ -1415,7 +1468,8 @@
    @Transactional(rollbackFor = Exception.class)
    public void generateSOEOInTask(String type, LocCache loc, String orgSite, String barcode, Long userId) {
        List<BasStationDetl> basStationDetls = basStationDetlService.selectList(new EntityWrapper<BasStationDetl>().eq("dev_no", orgSite));
        List<BasStationDetl> basStationDetls = basStationDetlService
                .selectList(new EntityWrapper<BasStationDetl>().eq("dev_no", orgSite));
        if (Objects.isNull(basStationDetls) || basStationDetls.isEmpty()) {
            throw new CoolException("站点信息不存在!!");
        }
@@ -1468,7 +1522,7 @@
                    .setAppeTime(new Date())
                    .setModiUser(userId);
            //保存工作档明细
            // 保存工作档明细
            if (!taskDetlService.insert(wrkDetl)) {
                throw new CoolException("保存工作档明细失败");
            }
@@ -1573,8 +1627,7 @@
            throw new CoolException("组托明细不能为空!!");
        }
        // 判断是否有相同条码的数据
        if (waitPakinService.selectCount(new EntityWrapper<WaitPakin>().
                eq("zpallet", param.getBarcode())
        if (waitPakinService.selectCount(new EntityWrapper<WaitPakin>().eq("zpallet", param.getBarcode())
                .eq("io_status", "N")) > 0) {
            throw new CoolException(param.getBarcode() + "数据正在进行入库");
        }
@@ -1589,7 +1642,8 @@
        // 生成入库通知档
        List<DetlDto> detlDtos = new ArrayList<>();
        param.getCombMats().forEach(elem -> {
            DetlDto detlDto = new DetlDto(elem.getMatnr(), elem.getBatch(), elem.getBrand(), elem.getStandby1(), elem.getStandby2(), elem.getStandby3(),
            DetlDto detlDto = new DetlDto(elem.getMatnr(), elem.getBatch(), elem.getBrand(), elem.getStandby1(),
                    elem.getStandby2(), elem.getStandby3(),
                    elem.getBoxType1(), elem.getBoxType2(), elem.getBoxType3(), elem.getAnfme(), elem.getThreeCode());
            if (DetlDto.has(detlDtos, detlDto)) {
                DetlDto one = DetlDto.findDto(detlDtos, detlDto);
@@ -1599,7 +1653,8 @@
                detlDtos.add(detlDto);
            }
        });
        BasContainer container = basContainerService.selectOne(new EntityWrapper<BasContainer>().eq("barcode", param.getBarcode()));
        BasContainer container = basContainerService
                .selectOne(new EntityWrapper<BasContainer>().eq("barcode", param.getBarcode()));
        if (Objects.isNull(container)) {
            throw new CoolException("数据错误:容器码不存在!!");
        }
@@ -1612,7 +1667,7 @@
        if (tagIds.size() > 1) {
            throw new CoolException("组托物料类型不一致,只有相同的物料分类才可以组托!!");
        }
        //还可以放入多少种物料
        // 还可以放入多少种物料
        Integer suplus = container.getMixMax();
        Date now = new Date();
        for (DetlDto detlDto : detlDtos) {
@@ -1620,13 +1675,13 @@
            if (Cools.isEmpty(mat)) {
                throw new CoolException(detlDto.getMatnr() + "商品档案不存在");
            }
            //最多可放数量
            // 最多可放数量
            Double singleMax = mat.getUpQty() * suplus;
            if (singleMax.compareTo(detlDto.getAnfme()) < 0) {
                throw new CoolException("物料:" + detlDto.getMatnr() + "单次组托上限为:" + mat.getUpQty() + ",当前总量超出托盘装载上限!!");
            }
            BigDecimal decimal = new BigDecimal(detlDto.getAnfme() / mat.getUpQty());
            //当前物料需要占用料箱格数
            // 当前物料需要占用料箱格数
            Integer curr = decimal.setScale(0, RoundingMode.CEILING).intValue();
            suplus = suplus - curr;
            if (suplus < 0) {
@@ -1637,7 +1692,7 @@
            BeanUtils.copyProperties(mat, waitPakin);
            waitPakin.setBatch(detlDto.getBatch());
            waitPakin.setZpallet(param.getBarcode());
            //设置组托类型
            // 设置组托类型
            waitPakin.setType(param.getType());
            waitPakin.setIoStatus("N");
            waitPakin.setAnfme(detlDto.getAnfme());
@@ -1676,14 +1731,15 @@
        if (Objects.isNull(param.getStation())) {
            throw new CoolException("站点不能为空!!");
        }
        //TODO 修改缓存站点状态及数据
        // TODO 修改缓存站点状态及数据
        Task task = taskService.selectOne(new EntityWrapper<Task>()
                .eq("wrk_sts", 14L)
                .eq("barcode", param.getCarBarcode()));
        if (Objects.isNull(task)) {
            throw new CoolException("数据错误,任务不存在!!");
        }
        List<TaskDetl> taskDetls = taskDetlService.selectList(new EntityWrapper<TaskDetl>().eq("wrk_no", task.getWrkNo()));
        List<TaskDetl> taskDetls = taskDetlService
                .selectList(new EntityWrapper<TaskDetl>().eq("wrk_no", task.getWrkNo()));
        if (Objects.isNull(taskDetls) || taskDetls.isEmpty()) {
            throw new CoolException("数据错误,任务明细不存在!!");
        }
@@ -1700,14 +1756,15 @@
        }
        basStationDetlService.delete(new EntityWrapper<BasStationDetl>().eq("dev_no", station.getDevNo()));
        //任务完成
        // 任务完成
        task.setWrkSts(15L);
        if (!taskService.updateById(task)) {
            throw new CoolException("AGV任务完成失败!!");
        }
        List<WaitPakin> waitPakins = waitPakinService.selectList(new EntityWrapper<WaitPakin>().eq("zpallet", param.getBarcode()));
        List<WaitPakin> waitPakins = waitPakinService
                .selectList(new EntityWrapper<WaitPakin>().eq("zpallet", param.getBarcode()));
        if (Objects.isNull(waitPakins) || waitPakins.isEmpty()) {
            throw new CoolException("数据错误,组拖档已不存在!!");
        }
@@ -1718,17 +1775,18 @@
    @Override
    @Transactional(rollbackFor = Exception.class)
    public R collectionPakin(CollectionPakinParams params, Long userId) {
        List<BasStation> basStations = basStationService.selectList(new EntityWrapper<BasStation>().eq("barcode", params.getTarBarcode()));
        List<BasStation> basStations = basStationService
                .selectList(new EntityWrapper<BasStation>().eq("barcode", params.getTarBarcode()));
        if (basStations.isEmpty() && Cools.isEmpty(params.getDevNo())) {
            throw new CoolException("请输入站点号");
        }
        BasStation basStation = null;
        if (!basStations.isEmpty()) {
            basStation =  basStations.get(0);
        }else {
            basStation = basStations.get(0);
        } else {
            basStation = basStationService.selectOne(new EntityWrapper<BasStation>().eq("dev_no", params.getDevNo()));
        }
        if (Cools.isEmpty(basStation)){
        if (Cools.isEmpty(basStation)) {
            throw new CoolException("请输入正确的站点号");
        }
        for (CollectionPakinParams.CombMat combMat : params.getCombMats()) {
@@ -1741,41 +1799,39 @@
                throw new CoolException("未找到备货入库单");
            }
            UpdateDetailsOfPakin(orderPakin,combMat);
            UpdateDetailsOfPakin(orderPakin, combMat);
            BasStationDetl basStationDetl = basStationDetlService.selectOne(new EntityWrapper<BasStationDetl>()
                    .eq("dev_no", basStation.getDevNo())
                    .eq("matnr", combMat.getMatnr())
                    .eq("batch", combMat.getBatch())
                    .eq("standby1", combMat.getStandby1())
            );
                    .eq("standby1", combMat.getStandby1()));
            if (Cools.isEmpty(basStationDetl)) {
                basStationDetl = new BasStationDetl();
                Mat mat = matService.selectByMatnr(combMat.getMatnr());
                BeanUtils.copyProperties(mat,basStationDetl);
                BeanUtils.copyProperties(mat, basStationDetl);
                basStationDetl
                        .setOrderNo(orderPakin.getOrderNo())
                        .setDevNo(basStation.getDevNo())
                        .setBarcode(params.getTarBarcode())
                        .setBatch(combMat.getBatch())
                        .setStandby1(combMat.getStandby1())
                        .setAnfme(combMat.getWorkQty().doubleValue())
                ;
                if (!basStationDetlService.insert(basStationDetl)){
                        .setAnfme(combMat.getWorkQty().doubleValue());
                if (!basStationDetlService.insert(basStationDetl)) {
                    throw new CoolException("插入明细失败");
                }
            }else {
            } else {
                BigDecimal anfme = new BigDecimal(basStationDetl.getAnfme().toString()).add(combMat.getWorkQty());
                basStationDetl.setAnfme(anfme.doubleValue());
                if (!basStationDetlService.updateById(basStationDetl)){
                if (!basStationDetlService.updateById(basStationDetl)) {
                    throw new CoolException("更新明细数据失败");
                }
            }
        }
        if (basStation.getLocSts().equals(LocStsType.LOC_STS_TYPE_D.type) || basStation.getLocSts().equals(LocStsType.LOC_STS_TYPE_O.type)) {
        if (basStation.getLocSts().equals(LocStsType.LOC_STS_TYPE_D.type)
                || basStation.getLocSts().equals(LocStsType.LOC_STS_TYPE_O.type)) {
            basStation.setBarcode(params.getTarBarcode());
            basStation.setLocSts(LocStsType.LOC_STS_TYPE_F.type);
            basStationService.updateById(basStation);
@@ -1785,13 +1841,12 @@
    }
    @Transactional(rollbackFor = Exception.class)
    public void UpdateDetailsOfPakin(OrderPakin orderPakin,CollectionPakinParams.CombMat combMat){
    public void UpdateDetailsOfPakin(OrderPakin orderPakin, CollectionPakinParams.CombMat combMat) {
        OrderDetlPakin orderDetlPakin = orderDetlPakinService.selectOne(new EntityWrapper<OrderDetlPakin>()
                .eq("order_id", orderPakin.getId())
                .eq("matnr", combMat.getMatnr())
                .eq("batch", combMat.getBatch())
                .eq("standby1", combMat.getStandby1())
        );
                .eq("standby1", combMat.getStandby1()));
        if (Cools.isEmpty(orderDetlPakin)) {
            throw new CoolException("检索单据明细数据失败");
        }
@@ -1800,16 +1855,15 @@
        }
        BigDecimal workQty = new BigDecimal(orderDetlPakin.getWorkQty().toString()).add(combMat.getWorkQty());
        orderDetlPakin.setWorkQty(workQty.doubleValue());
        if (!orderDetlPakinService.updateById(orderDetlPakin)){
        if (!orderDetlPakinService.updateById(orderDetlPakin)) {
            throw new CoolException("更新单据明细数据失败");
        }
        if (!orderPakin.getSettle().equals(2L)){
        if (!orderPakin.getSettle().equals(2L)) {
            orderPakin.setSettle(2L);
            if (!orderPakinService.updateById(orderPakin)){
            if (!orderPakinService.updateById(orderPakin)) {
                throw new CoolException("更新单据状态失败");
            }
        }
    }
@@ -1821,7 +1875,8 @@
            throw new CoolException("未找到任务");
        }
        if (wrkMast.getIoType().equals(TaskIOType.ALL_OUT.type) && wrkMast.getIoType().equals(TaskIOType.PICK_OUT.type)){
        if (wrkMast.getIoType().equals(TaskIOType.ALL_OUT.type)
                && wrkMast.getIoType().equals(TaskIOType.PICK_OUT.type)) {
            throw new CoolException("人物类型错误");
        }
@@ -1829,7 +1884,6 @@
        if (Cools.isEmpty(wrkDetls)) {
            throw new CoolException("未找到任务明细");
        }
        return R.ok(wrkDetls);
    }
@@ -1944,8 +1998,9 @@
        if (Objects.isNull(locCaches)) {
            throw new CoolException("库位不能为空!!");
        }
        //获取缓存区信息
        BasAreas basAreas = basAreasService.selectOne(new EntityWrapper<BasAreas>().eq("whs_type_id", LocAreaType.LOC_AREA_TYPE_IN_CACHE.type));
        // 获取缓存区信息
        BasAreas basAreas = basAreasService
                .selectOne(new EntityWrapper<BasAreas>().eq("whs_type_id", LocAreaType.LOC_AREA_TYPE_IN_CACHE.type));
        if (Objects.isNull(basAreas)) {
            throw new CoolException("库区不存在!!");
        }
@@ -1956,31 +2011,37 @@
            throw new CoolException("库存明细不存在!!");
        }
//        Set<String> set = locDetls.stream().map(LocDetl::getMatnr).collect(Collectors.toSet());
//        List<Mat> matList = matService.selectList(new EntityWrapper<Mat>().in("matnr", set));
//
//        if (Objects.isNull(matList) || matList.isEmpty()) {
//            throw new CoolException("物料库不存在该物料!!");
//        }
//        Set<Long> longs = matList.stream().map(Mat::getTagId).collect(Collectors.toSet());
//        if (!longs.isEmpty() && longs.size() > 1) {
//            throw new CoolException("物料类型不一致,请检查数据是否正确!!");
//        }
        // Set<String> set =
        // locDetls.stream().map(LocDetl::getMatnr).collect(Collectors.toSet());
        // List<Mat> matList = matService.selectList(new
        // EntityWrapper<Mat>().in("matnr", set));
        //
        // if (Objects.isNull(matList) || matList.isEmpty()) {
        // throw new CoolException("物料库不存在该物料!!");
        // }
        // Set<Long> longs =
        // matList.stream().map(Mat::getTagId).collect(Collectors.toSet());
        // if (!longs.isEmpty() && longs.size() > 1) {
        // throw new CoolException("物料类型不一致,请检查数据是否正确!!");
        // }
        //获取立库区信息
        BasAreas one = basAreasService.selectOne(new EntityWrapper<BasAreas>().eq("whs_type_id", LocAreaType.LOC_AREA_TYPE_CRN.type));
        // 获取立库区信息
        BasAreas one = basAreasService
                .selectOne(new EntityWrapper<BasAreas>().eq("whs_type_id", LocAreaType.LOC_AREA_TYPE_CRN.type));
        if (Objects.isNull(one)) {
            throw new CoolException("数据错误:库区不存在!!");
        }
        List<StationRela> relas = stationRelaService.selectList(new EntityWrapper<StationRela>().eq("agv_sta", station.getDevNo()));
        List<StationRela> relas = stationRelaService
                .selectList(new EntityWrapper<StationRela>().eq("agv_sta", station.getDevNo()));
        if (Objects.isNull(relas) || relas.isEmpty()) {
            throw new CoolException("站点未关联堆垛机作业站点!!");
        }
        Set<String> crnStas = relas.stream().map(StationRela::getCrnSta).collect(Collectors.toSet());
        List<BasDevp> devps = basDevpService.selectList(new EntityWrapper<BasDevp>().in("dev_no", crnStas).eq("loading", CommonStation.COMMON_STATION_Y.type));
        List<BasDevp> devps = basDevpService.selectList(
                new EntityWrapper<BasDevp>().in("dev_no", crnStas).eq("loading", CommonStation.COMMON_STATION_Y.type));
        if (Objects.isNull(devps) || devps.isEmpty()) {
            throw new CoolException("无站点可用!");
        }
@@ -1988,31 +2049,34 @@
        BasDevp basDevp = devps.stream().findFirst().get();
        List<LocMast> locMasts = new ArrayList<>();
        Map<String, List<LocDetl>> listMap = locDetls.stream().collect(Collectors.groupingBy(LocDetl::getMatnr));
        AtomicReference<Double> totalOut = new AtomicReference<>(locDetls.stream().mapToDouble(LocDetl::getAnfme).sum());
        AtomicReference<Double> totalOut = new AtomicReference<>(
                locDetls.stream().mapToDouble(LocDetl::getAnfme).sum());
        listMap.forEach((matnr, detls) -> {
            //根据supId(供应商)分类,得到出库总数
            // 根据supId(供应商)分类,得到出库总数
            Map<String, List<LocDetl>> supIds = detls.stream().collect(Collectors.groupingBy(LocDetl::getStandby1));
            supIds.forEach((supId, sups) -> {
                Double sum = sups.stream().mapToDouble(LocDetl::getAnfme).sum();
                //获取当前供应商+ 物料在库
                // 获取当前供应商+ 物料在库
                List<LocDetl> detlList = locDetlService.selectList(new EntityWrapper<LocDetl>()
                        .eq("matnr", matnr)
                        .eq("area_id", one.getId())
                        .eq("standby1", supId).orderAsc(Arrays.asList("appe_time")));
                //TODO  判断是否有新库位,没有新库位,再找有空格的位置放   1. 判断当前物料是否有库存 2. 没有余料查询新库位
                // TODO 判断是否有新库位,没有新库位,再找有空格的位置放 1. 判断当前物料是否有库存 2. 没有余料查询新库位
                if (!Objects.isNull(detlList) && !detlList.isEmpty()) {
                    Map<String, List<LocDetl>> locMaps = detlList.stream().collect(Collectors.groupingBy(LocDetl::getLocNo));
                    Map<String, List<LocDetl>> locMaps = detlList.stream()
                            .collect(Collectors.groupingBy(LocDetl::getLocNo));
                    locMaps.forEach((locNo, adetls) -> {
                        LocMast locMast = locMastService.selectById(locNo);
                        if (Objects.isNull(locMast)) {
                            throw new CoolException("数据错误,库位信息不存在!!");
                        }
                        BasContainer container = basContainerService.selectOne(new EntityWrapper<BasContainer>().eq("barcode", locMast.getBarcode()));
                        BasContainer container = basContainerService
                                .selectOne(new EntityWrapper<BasContainer>().eq("barcode", locMast.getBarcode()));
                        if (Objects.isNull(container)) {
                            throw new CoolException("数据错误,容器不存在!!");
                        }
                        Set<String> sets = adetls.stream().map(LocDetl::getMatnr).collect(Collectors.toSet());
                        //判断容器是否还可混放,及当前物料可放多少
                        // 判断容器是否还可混放,及当前物料可放多少
                        if (container.getMixMax() > sets.size()) {
                            int suplus = container.getMixMax() - sets.size();
                            Mat mats = matService.selectOne(new EntityWrapper<Mat>().eq("matnr", matnr));
@@ -2020,9 +2084,9 @@
                                throw new CoolException("物料不存在!!");
                            }
                            Double v = mats.getUpQty() * suplus;
                            //小于零
                            // 小于零
                            if (sum.compareTo(v) <= 0) {
                                //可放下
                                // 可放下
                                locMasts.add(locMast);
                                totalOut.set(Math.round((totalOut.get() - sum) * 10000) / 10000.0);
                            }
@@ -2032,27 +2096,28 @@
            });
        });
        //判断根据分拣出库后,还需要出多少托盘或料箱;如果余料大于0, 出新托盘或料箱
        // 判断根据分拣出库后,还需要出多少托盘或料箱;如果余料大于0, 出新托盘或料箱
        if (totalOut.get().compareTo(0.0) > 0) {
//            Set<String> matnrs = locDetls.stream().map(LocDetl::getMatnr).collect(Collectors.toSet());
//            List<Mat> mats = matService.selectList(new EntityWrapper<Mat>().in("matnr", matnrs));
            // Set<String> matnrs =
            // locDetls.stream().map(LocDetl::getMatnr).collect(Collectors.toSet());
            // List<Mat> mats = matService.selectList(new EntityWrapper<Mat>().in("matnr",
            // matnrs));
            LocMast locMast = locMastService.selectOne(new EntityWrapper<LocMast>()
                    //todo 根据物料种类,区分库区类型
                    // todo 根据物料种类,区分库区类型
                    .eq("loc_sts", LocStsType.LOC_STS_TYPE_D.type)
                    .orderAsc(Arrays.asList("row1", "bay1", "lev1"))
                    .last("OFFSET 0 ROWS FETCH NEXT 1 ROWS ONLY"));
            locMasts.add(locMast);
            //空板出库
            // 空板出库
            generateTask(locMasts, TaskIOType.EMPTY_OUT.type, basDevp, userId);
        } else {
            //生成堆垛机出库任务
            // 生成堆垛机出库任务
            generateTask(locMasts, TaskIOType.MERGE_OUT.type, basDevp, userId);
//            if (!locMasts.isEmpty()) {
//
//            }
            // if (!locMasts.isEmpty()) {
            //
            // }
        }
    }
    /**
     * 生成堆垛机出库任务
@@ -2098,7 +2163,8 @@
                throw new CoolException("保存工作档失败,出库库位号:" + locMast.getLocNo());
            }
            List<LocDetl> locDetls = locDetlService.selectList(new EntityWrapper<LocDetl>().eq("loc_no", locMast.getLocNo()));
            List<LocDetl> locDetls = locDetlService
                    .selectList(new EntityWrapper<LocDetl>().eq("loc_no", locMast.getLocNo()));
            // 生成工作档明细
            for (LocDetl detlDto : locDetls) {
@@ -2115,9 +2181,10 @@
                    throw new CoolException("保存工作档明细失败");
                }
            }
            // 修改库位状态:   F.在库 ====>>> R.出库预约/P.拣料/盘点/并板出库中
            // 修改库位状态: F.在库 ====>>> R.出库预约/P.拣料/盘点/并板出库中
            locMast = locMastService.selectById(locMast.getLocNo());
            if (locMast.getLocSts().equals(LocStsType.LOC_STS_TYPE_F.type) || locMast.getLocSts().equals(LocStsType.LOC_STS_TYPE_D.type)) {
            if (locMast.getLocSts().equals(LocStsType.LOC_STS_TYPE_F.type)
                    || locMast.getLocSts().equals(LocStsType.LOC_STS_TYPE_D.type)) {
                locMast.setLocSts(ioType == 101 ? "R" : "P");
                locMast.setModiUser(userId);
                locMast.setModiTime(now);
@@ -2185,7 +2252,7 @@
                        .setModel(pakin.getModel())
                        .setAppeTime(new Date())
                        .setModiUser(userId);
                //保存工作档明细
                // 保存工作档明细
                if (!taskDetlService.insert(wrkDetl)) {
                    throw new CoolException("保存工作档明细失败");
                }
@@ -2256,7 +2323,7 @@
            throw new CoolException("保存工作档失败");
        }
        for (WaitPakin pakin :pakins){
        for (WaitPakin pakin : pakins) {
            TaskDetl wrkDetl = new TaskDetl();
            BeanUtils.copyProperties(pakin, wrkDetl);
            wrkDetl.setId(null).setWrkNo(workNo)
@@ -2272,21 +2339,18 @@
                    .setModel(pakin.getModel())
                    .setAppeTime(new Date())
                    .setModiUser(userId);
            if (!taskDetlService.insert(wrkDetl)){
            if (!taskDetlService.insert(wrkDetl)) {
                throw new CoolException("保存工作档明细失败");
            }
        }
        for (WaitPakin pakin : pakins){
        for (WaitPakin pakin : pakins) {
            pakin.setIoStatus("Y");
            if (!waitPakinService.updateById(pakin)) {
                throw new CoolException("更新组托信息失败");
            }
        }
        // 修改目标库位状态
        if (loc.getLocSts().equals(LocStsType.LOC_STS_TYPE_O.type)) {
@@ -2319,7 +2383,6 @@
        }
    }
    public HIKResultDTO sendAgvTask(HIKApiDTO haiKangApiDTO, String path) {
        HIKResultDTO result = new HIKResultDTO();
@@ -2330,8 +2393,10 @@
        forwardAGVTaskParam.setCtnrTyp(haiKangApiDTO.getCtnrType());
        forwardAGVTaskParam.setPriority(haiKangApiDTO.getPriority());
        List<ForwardAGVTaskDTO.PositionCodePaths> positionCodePathsList = new ArrayList<>();
        positionCodePathsList.add(new ForwardAGVTaskDTO.PositionCodePaths(haiKangApiDTO.getOrg(), haiKangApiDTO.getOrgType()));
        positionCodePathsList.add(new ForwardAGVTaskDTO.PositionCodePaths(haiKangApiDTO.getTar(), haiKangApiDTO.getTarType()));
        positionCodePathsList
                .add(new ForwardAGVTaskDTO.PositionCodePaths(haiKangApiDTO.getOrg(), haiKangApiDTO.getOrgType()));
        positionCodePathsList
                .add(new ForwardAGVTaskDTO.PositionCodePaths(haiKangApiDTO.getTar(), haiKangApiDTO.getTarType()));
        forwardAGVTaskParam.setPositionCodePath(positionCodePathsList);
        String body = JSON.toJSONString(forwardAGVTaskParam);
@@ -2350,7 +2415,7 @@
                result.setMessage(jsonObject.getString("message"));
                log.error("发送agv任务失败!!!url:{};request:{};response:{}", HIKApiConstant.AGV_IP + path, body, response);
            }
//            {"code":"1","data":"","interrupt":false,"message":"重复提交","msgErrCode":"0x3a80D012","reqCode":"fa92b49481a44627ae4d80c1400f28f6"}
            // {"code":"1","data":"","interrupt":false,"message":"重复提交","msgErrCode":"0x3a80D012","reqCode":"fa92b49481a44627ae4d80c1400f28f6"}
        } catch (Exception e) {
            result.setMessage(e.getMessage());
            log.error("发送agv任务异常", e);
@@ -2364,8 +2429,7 @@
                        "127.0.0.1",
                        body,
                        response,
                        result.isSuccess()
                );
                        result.isSuccess());
            } catch (Exception e) {
                log.error("", e);
            }