自动化立体仓库 - WMS系统
skyouc
4 天以前 3af3b194265d37e40c8d141155bdc872781d8729
src/main/java/com/zy/asrs/service/impl/MobileServiceImpl.java
@@ -6,6 +6,7 @@
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.core.common.*;
import com.core.exception.CoolException;
import com.zy.api.enums.MatLocType;
import com.zy.asrs.entity.*;
import com.zy.asrs.entity.param.*;
import com.zy.asrs.entity.result.*;
@@ -31,12 +32,12 @@
import com.zy.common.utils.HttpHandler;
import com.zy.system.entity.Config;
import com.zy.system.service.ConfigService;
import com.zy.system.service.impl.ConfigServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import javax.annotation.Resource;
import java.math.BigDecimal;
@@ -178,7 +179,9 @@
        wrkMastService.insert(wrkMast);
        for (OrderDetl orderDetl : param.getCombMats()) {
            Mat mat = matService.selectOne(new EntityWrapper<Mat>().eq("matnr", orderDetl.getMatnr()));
            Mat mat = matService.selectOne(new EntityWrapper<Mat>()
                    .eq("supp_code", orderDetl.getStandby1())
                    .eq("matnr", orderDetl.getMatnr()));
            if (mat == null) {
                throw new CoolException("保存工作档失败,物料信息不存在:" + orderDetl.getMatnr());
            }
@@ -377,6 +380,7 @@
        for (CombParam.CombMat combMat : combParam.getCombMats()) {
            List<LocDetl> locDetlList = locDetlService.selectList(new EntityWrapper<LocDetl>()
                    .eq("loc_no", combParam.getLocNo())
                    .eq(!Cools.isEmpty(combMat.getStandby1()), "supp_code", combMat.getStandby1())
                    .eq("matnr", combMat.getMatnr()));
            if (locDetlList.isEmpty()) {
                return R.error("未查询到库存数据");
@@ -451,7 +455,9 @@
                wrkMast.setModiUser(userId);
                wrkMastService.insert(wrkMast);
                Mat mat = matService.selectOne(new EntityWrapper<Mat>().eq("matnr", combMat.getMatnr()));
                Mat mat = matService.selectOne(new EntityWrapper<Mat>()
                        .eq(!Cools.isEmpty(combMat.getStandby1()), "supp_code", combMat.getStandby1())
                        .eq("matnr", combMat.getMatnr()));
                if (mat == null) {
                    throw new CoolException("保存工作档失败,物料信息不存在:" + combMat.getMatnr());
                }
@@ -632,7 +638,7 @@
        // 无单组托
        if (Cools.isEmpty(param.getOrderNo())) {
            //空板组托
            if (!Cools.isEmpty(param.getPakinType()) &&  param.getPakinType().equals("3")) {
            if (!Cools.isEmpty(param.getPakinType()) && param.getPakinType().equals("3")) {
                WaitPakin waitPakin = new WaitPakin();
                waitPakin.setZpallet(param.getBarcode());
                waitPakin.setIoStatus("N");
@@ -713,6 +719,7 @@
                // elem.getBoxType1(), elem.getBoxType2(), elem.getBoxType3());
                OrderDetlPakin detls = orderDetlPakinService.selectOne(new EntityWrapper<OrderDetlPakin>()
                        .eq("order_id", order.getId())
                        .eq("supp_code", elem.getStandby1())
                        .eq("matnr", elem.getMatnr()));
                if (Objects.isNull(elem.getBoxType1())) {
                    throw new CoolException("格层编码不能为空!!");
@@ -743,9 +750,16 @@
                }
            });
            Set<String> matnrs = detlDtos.stream().map(DetlDto::getMatnr).collect(Collectors.toSet());
            List<Mat> mats = matService.selectList(new EntityWrapper<Mat>().in("matnr", matnrs));
            Set<Long> tagIds = mats.stream().map(Mat::getTagId).collect(Collectors.toSet());
            List<Mat> tempMats = new ArrayList<>();
            for (DetlDto detlDto : detlDtos) {
                Mat mat = matService.selectOne(new EntityWrapper<Mat>()
                        .eq("matnr", detlDto.getMatnr())
                        .eq("supp_code", detlDto.getStandby1()));
                tempMats.add(mat);
            }
//            Set<String> matnrs = tempMats.stream().map(Mat::getMatnr).collect(Collectors.toSet());
            Set<Long> tagIds = tempMats.stream().map(Mat::getTagId).collect(Collectors.toSet());
            if (tagIds.size() > 1) {
                throw new CoolException("组托物料类型不一致,只有相同的物料分类才可以组托!!");
            }
@@ -903,9 +917,9 @@
                        // todo 盘点记录、保存调整记录
                        // 修改明细
                        if (!wrkDetlService.updateAnfme(wrkDetl1.getAnfme(), wrkMast.getWrkNo(), wrkDetl.getMatnr(),
                                wrkDetl.getBatch())) {
                                wrkDetl.getSuppCode())) {
                            throw new CoolException(wrkMast.getWrkNo() + "盘点任务," + wrkDetl.getMatnr() + "商品,"
                                    + wrkDetl.getBatch() + "批号修改数量失败");
                                    + wrkDetl.getSuppCode() + "批号修改数量失败");
                        }
                    }
                    iterator.remove();
@@ -917,7 +931,7 @@
        // 删除明细
        for (WrkDetl wrkDetl : wrkDetls) {
            // todo 盘点记录、保存调整记录
            if (!wrkDetlService.updateAnfme(-1.0D, wrkMast.getWrkNo(), wrkDetl.getMatnr(), wrkDetl.getBatch())) {
            if (!wrkDetlService.updateAnfme(-1.0D, wrkMast.getWrkNo(), wrkDetl.getMatnr(), wrkDetl.getSuppCode())) {
                throw new CoolException("删除" + wrkMast.getWrkNo() + "盘点任务," + wrkDetl.getMatnr() + "商品,"
                        + wrkDetl.getBatch() + "批号任务明细失败");
            }
@@ -1191,6 +1205,7 @@
                orderDetl.setUpdateBy(userId);
                orderDetl.setUpdateTime(now);
                Wrapper wrapper = new EntityWrapper<OrderDetl>().eq("order_no", orderNo)
                        .eq(!Cools.isEmpty(orderDetl.getStandby1()), "supp_code", orderDetl.getStandby1())
                        .eq("matnr", orderDetl.getMatnr());
                if (!Cools.isEmpty(orderDetl.getBatch())) {
                    wrapper.eq("batch", orderDetl.getBatch());
@@ -1244,6 +1259,12 @@
        wrkMast.setModiUser(userId);
        wrkMast.setModiTime(now);
        wrkMast.setBarcode(locMast.getBarcode());
        WrkMast wrkMast1 = wrkMastService.selectOne(new EntityWrapper<WrkMast>().eq("source_loc_no", locDetl.getLocNo()));
        if (!Objects.isNull(wrkMast1)) {
            throw new CoolException("源库位已出库,请等待任务完成后,再执行!!");
        }
        if (!wrkMastService.insert(wrkMast)) {
            throw new CoolException("保存工作档失败,出库库位号:" + locDetl.getLocNo());
        }
@@ -1297,31 +1318,71 @@
     * @version 1.0
     */
    @Override
    @Transactional
    @Transactional(rollbackFor = Exception.class)
    public synchronized R callAgvMove(AgvCallParams params, Long userId) {
        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));
        LocCache locCache = locCacheService.selectOne(new EntityWrapper<LocCache>()
                .eq("area_id", basAreas.getId())
                .eq("frozen", 0)
                .eq("loc_sts", LocStsType.LOC_STS_TYPE_O.type)
                // .eq("loc_no", params.getTarSite())
                .orderAsc(Arrays.asList("loc_no"))
                .last("OFFSET 0 ROWS FETCH NEXT 1 ROWS ONLY"));
        if (Objects.isNull(locCache)) {
            throw new CoolException("请检查目标库位是否闲置中!!");
        }
        if (!Objects.isNull(params.getTaskType()) && params.getTaskType().equals("XM1")) {
            String taskType = params.getTaskType();
            generateXAgvTask(params.getOrgSite(), params.getTarSite(), userId, taskType);
        } else {
            String taskType = "M2";
            if (!params.getIsNewIn().isEmpty()) {
                taskType = "M1";
                int cacheCount = locCacheService.selectCount(new EntityWrapper<LocCache>().eq("barcode", params.getBarcode()));
                if (cacheCount > 0) {
                    throw new CoolException("台车已入库,不能勾选新台车!!");
                }
            }
        try {
            generateAgvTask("agv", locCache, params.getOrgSite(), params.getBarcode(), userId);
        } catch (Exception e) {
            throw new CoolException(e.getMessage());
        }
            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("frozen", 0)
                    .eq("loc_sts", LocStsType.LOC_STS_TYPE_O.type)
                    .orderAsc(Arrays.asList("loc_no"))
                    .last("OFFSET 0 ROWS FETCH NEXT 1 ROWS ONLY"));
            if (Objects.isNull(locCache)) {
                throw new CoolException("请检查目标库位是否闲置中!!");
            }
            try {
                generateAgvTask("agv", locCache, params.getOrgSite(), params.getBarcode(), userId, taskType);
            } catch (Exception e) {
                throw new CoolException(e.getMessage());
            }
        }
        return R.ok();
    }
    @Transactional(rollbackFor = Exception.class)
    public void generateXAgvTask(String orgSite, String tarSite, Long userId, String taskType) {
        // 获取工作号
        int workNo = commonService.getWorkNo(4);
        // 保存工作档
        Task task = new Task();
        task.setWrkNo(workNo)
                .setIoTime(new Date())
                .setWrkSts(201L) // 工作状态:11.生成出库ID
                .setIoType(1) // 入出库状态: 11.库格移载
                .setTaskType("agv")
                .setIoPri(10D)
                .setIsNewIn(taskType)
                .setFullPlt("Y") // 满板:Y
                .setPicking("N") // 拣料
                .setExitMk("N")// 退出
                .setSourceStaNo(orgSite)
                .setStaNo(tarSite)
                .setLinkMis("N")
                .setAppeUser(userId)
                .setAppeTime(new Date())
                .setModiUser(userId)
                .setModiTime(new Date());
        if (!taskService.insert(task)) {
            throw new CoolException("保存工作档失败");
        }
    }
    /**
@@ -1337,7 +1398,7 @@
        }
        List<OrderDetlPakin> detlPakins = orderDetlPakinService.selectList(new EntityWrapper<OrderDetlPakin>()
                .eq(!Cools.isEmpty(params.getThreeCode()), "three_code", params.getThreeCode())
                        .eq(!Cools.isEmpty(params.getThreeCode()), "three_code", params.getThreeCode())
//                .eq(!Cools.isEmpty(params.getMatnr()), "matnr", params.getMatnr())
//                .eq(!Cools.isEmpty(params.getOrderNo()), "order_no", params.getOrderNo())
        );
@@ -1492,12 +1553,12 @@
            throw new CoolException("托盘已在任务执行中..");
        }
        // 获取工作号
        int workNo = commonService.getWorkNo(WorkNoType.PICK.type);
        int workNo = commonService.getWorkNo(4);
        // 保存工作档
        Task task = new Task();
        task.setWrkNo(workNo)
                .setIoTime(new Date())
                .setWrkSts(1L) // 工作状态:11.生成出库ID
                .setWrkSts(201L) // 工作状态:11.生成入库库ID
                .setIoType(1) // 入出库状态: 11.库格移载
                .setTaskType("agv")
                .setIoPri(10D)
@@ -1546,7 +1607,7 @@
            loc.setLocSts(LocStsType.LOC_STS_TYPE_S.type); // S.入库预约
            loc.setModiTime(new Date());
            loc.setModiUser(userId);
            if (!locCacheService.updateById(loc)) {
            if (!locCacheService.update(loc, new EntityWrapper<LocCache>().eq("loc_no", loc.getLocNo()))) {
                throw new CoolException("更新目标库位状态失败");
            }
        } else {
@@ -1622,7 +1683,7 @@
    }
    /**
     * 缓存区上架组托
     * 缓存区并板上架组托
     *
     * @param param
     * @param userId
@@ -1635,140 +1696,95 @@
        if (Objects.isNull(param.getBarcode())) {
            throw new CoolException("托盘码不能为空!!");
        }
        if (Objects.isNull(param.getCombMats()) || param.getCombMats().isEmpty()) {
            throw new CoolException("组托明细不能为空!!");
        }
        // 判断是否有相同条码的数据
        if (waitPakinService.selectCount(new EntityWrapper<WaitPakin>().eq("zpallet", param.getBarcode())
                .eq("io_status", "N")) > 0) {
            throw new CoolException(param.getBarcode() + "数据正在进行入库");
        WrkMast wrkMast = wrkMastService.selectOne(new EntityWrapper<WrkMast>()
                .eq("wrk_sts", 14)
                .eq("io_type", 104)
                .eq("barcode", param.getBarcode()));
        if (Objects.isNull(wrkMast)) {
            throw new CoolException("任务档信息不存在!!");
        }
        int countLoc = locDetlService.selectCount(new EntityWrapper<LocDetl>().eq("zpallet", param.getBarcode()));
        int countWrk = wrkDetlService.selectCount(new EntityWrapper<WrkDetl>().eq("zpallet", param.getBarcode()));
        if (countWrk > 0 || countLoc > 0) {
            WrkMast wrkDetl = wrkMastService.selectOne(new EntityWrapper<WrkMast>().eq("barcode", param.getBarcode()));
            if (!wrkDetl.getIoType().equals(TaskIOType.MERGE_OUT.type)) {
                throw new CoolException("组托档/工作档/库存条码数据已存在===>>" + param.getBarcode());
            }
        }
        int countwait = waitPakinService.selectCount(new EntityWrapper<WaitPakin>().eq("zpallet", param.getBarcode()));
        if (countwait > 0) {
            throw new CoolException("组托档/工作档/库存条码数据已存在===>>" + param.getBarcode());
        }
        // 生成入库通知档
        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());
            if (DetlDto.has(detlDtos, detlDto)) {
                DetlDto one = DetlDto.findDto(detlDtos, detlDto);
                assert one != null;
                one.setAnfme(one.getAnfme() + detlDto.getAnfme());
            } else {
                detlDtos.add(detlDto);
            }
        });
        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() + "!!");
        }
        Set<String> matnrs = detlDtos.stream().map(DetlDto::getMatnr).collect(Collectors.toSet());
        List<Mat> mats = matService.selectList(new EntityWrapper<Mat>().in("matnr", matnrs));
        Set<Long> tagIds = mats.stream().map(Mat::getTagId).collect(Collectors.toSet());
        if (tagIds.size() > 1) {
            throw new CoolException("组托物料类型不一致,只有相同的物料分类才可以组托!!");
        }
        // 还可以放入多少种物料
        Double suplus = container.getMixMax();
        Date now = new Date();
        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() + ", 超出当前托盘装载上限!!");
            }
        for (CombParam.CombMat combMat : param.getCombMats()) {
            BasStationDetl stationDetl = basStationDetlService.selectOne(new EntityWrapper<BasStationDetl>()
                    .eq("zpallet", param.getCarBarcode())
                    .eq("three_code", detlDto.getThreeCode()));
                    .eq("three_code", combMat.getThreeCode()));
            if (Objects.isNull(stationDetl)) {
                throw new CoolException("明细内容不存在!!");
            }
            WrkDetl wrkDetl = wrkDetlService.selectOne(new EntityWrapper<WrkDetl>()
                    .eq("matnr", stationDetl.getMatnr())
                    .eq("wrk_no", wrkMast.getWrkNo())
                    .eq("supp_code", combMat.getSuppCode()));
            Double v = Math.round((stationDetl.getAnfme() - stationDetl.getWorkQty()) * 10000) / 10000.0;
            if (detlDto.getAnfme().compareTo(v) > 0) {
                throw new CoolException("组托上限为:" + stationDetl.getAnfme() + ", 已组托:" + stationDetl.getWorkQty() + ", 还可组托:" + v);
            }
            if (Objects.isNull(wrkDetl)) {
                //TODO 新插入
                Mat mat = matService.selectOne(new EntityWrapper<Mat>().eq("matnr", stationDetl.getMatnr())
                        .eq("supp_code", combMat.getSuppCode()));
                if (Objects.isNull(mat)) {
                    throw new CoolException("物料基础信息已不存在!!");
                }
                WrkDetl detl = new WrkDetl();
                BeanUtils.copyProperties(stationDetl, detl);
                detl.setAnfme(combMat.getAnfme());
                detl.setBarcode(wrkMast.getBarcode());
                detl.setZpallet(param.getBarcode());
                detl.setBoxType1(combMat.getBoxType1());
                detl.setStandby1(combMat.getSuppCode());
                detl.setThreeCode(combMat.getThreeCode());
                detl.setAdjustQty(combMat.getAdjustQty());
                detl.setSplusQty(combMat.getSplusQty());
                detl.setWrkNo(wrkMast.getWrkNo());
            WaitPakin waitPakin = new WaitPakin();
            BeanUtils.copyProperties(mat, waitPakin);
            waitPakin.setBatch(detlDto.getBatch());
            waitPakin.setType(param.getType());
            waitPakin.setZpallet(param.getBarcode());
            // 设置组托类型
            waitPakin.setType(param.getType());
            waitPakin.setIoStatus("N");
            waitPakin.setAnfme(detlDto.getAnfme());
            waitPakin.setThreeCode(detlDto.getThreeCode());
            waitPakin.setStatus("Y");
            waitPakin.setSuppCode(detlDto.getStandby1());
            waitPakin.setStandby1(detlDto.getStandby1());
            waitPakin.setStandby2(detlDto.getStandby2());
            waitPakin.setStandby3(detlDto.getStandby3());
            waitPakin.setBoxType1(detlDto.getBoxType1());
            waitPakin.setBoxType2(detlDto.getBoxType2());
            waitPakin.setBoxType3(detlDto.getBoxType3());
            waitPakin.setAppeUser(userId);
            waitPakin.setAppeTime(now);
            waitPakin.setModiUser(userId);
            waitPakin.setModiTime(now);
            if (!waitPakinService.insert(waitPakin)) {
                throw new CoolException("保存入库通知档失败");
            }
            Double v1 = Math.round((stationDetl.getWorkQty() + detlDto.getAnfme()) * 10000) / 10000.0;
            stationDetl.setWorkQty(v1);
            if (!basStationDetlService.updateById(stationDetl)) {
                throw new CoolException("站点明细修改失败");
            }
            if (v1.compareTo(stationDetl.getAnfme()) >= 0) {
                if (!basStationDetlService.deleteById(stationDetl)) {
                    throw new CoolException("原始数据移除失败!");
                if (!wrkDetlService.insert(detl)) {
                    throw new CoolException("任务明细保存失败!!");
                }
            } else {
                if (Objects.isNull(combMat.getAnfme())) {
                    throw new CoolException("数量不能为空!!");
                }
                double val = Math.round((combMat.getAnfme() + wrkDetl.getAnfme()) * 10000) / 10000.0;
                WrkDetl detl = new WrkDetl();
                detl.setOrderNo(stationDetl.getOrderNo());
                detl.setBoxType1(combMat.getBoxType1());
                detl.setZpallet(param.getBarcode());
                detl.setBarcode(param.getBarcode());
                detl.setThreeCode(combMat.getThreeCode());
                detl.setStandby1(combMat.getSuppCode());
                detl.setAdjustQty(combMat.getAdjustQty());
                detl.setSplusQty(combMat.getSplusQty());
                detl.setAnfme(val);
                detl.setModiTime(new Date());
                if (!wrkDetlService.update(detl, new EntityWrapper<WrkDetl>()
                        .eq("wrk_no", wrkMast.getWrkNo())
                        .eq("supp_code", stationDetl.getSuppCode())
                        .eq("matnr", stationDetl.getMatnr()))) {
                    throw new CoolException(wrkMast.getWrkNo() + "盘点任务," + wrkDetl.getMatnr() + "商品,"
                            + wrkDetl.getBatch() + "批号修改数量失败");
                }
            }
            List<BasStationDetl> stas = basStationDetlService.selectList(new EntityWrapper<BasStationDetl>()
                    .eq("dev_no", stationDetl.getDevNo()));
            if (Objects.isNull(stas) || stas.isEmpty()) {
                BasStation station = basStationService.selectOne(new EntityWrapper<BasStation>().eq("dev_no", stationDetl.getDevNo()));
                if (Objects.isNull(station)) {
                    throw new CoolException("数据错误,站点不存在!!");
                }
                station.setLocSts(LocStsType.LOC_STS_TYPE_O.type);
                station.setBarcode("");
                if (!basStationService.updateById(station)) {
                    throw new CoolException("站点状态更新失败!!");
            BasStationDetl stationDetl1 = basStationDetlService.selectOne(new EntityWrapper<BasStationDetl>()
                    .eq("zpallet", param.getCarBarcode())
                    .eq("three_code", combMat.getThreeCode()));
            if (!Objects.isNull(stationDetl1)) {
                Double v = Math.round((stationDetl1.getAnfme() - combMat.getAnfme()) * 10000) / 10000.0;
                if (v.compareTo(0.0) == 0) {
                    if (!basStationDetlService.delete(new EntityWrapper<BasStationDetl>()
                            .eq("zpallet", param.getCarBarcode())
                            .eq("three_code", combMat.getThreeCode()))) {
                        throw new CoolException("站点信息更新失败!!");
                    }
                } else {
                    stationDetl1.setAnfme(v);
                    if (!basStationDetlService.update(stationDetl1, new EntityWrapper<BasStationDetl>()
                            .eq("zpallet", param.getCarBarcode())
                            .eq("three_code", combMat.getThreeCode()))) {
                        throw new CoolException("站点信息更新失败!!");
                    }
                }
            }
        }
@@ -1801,11 +1817,13 @@
        }
        Integer whsType = 1;
        Short lcoType = 1;
        //用于判断料箱托盘,料箱,笼框
        if (container.getType().equals(ContainerType.CONTAINER_TYPE_SALVER.type)) {
            whsType = 3;
        } else if (container.getType().equals(ContainerType.CONTAINER_TYPE_CAGE.type)) {
        if (!container.getType().equals(ContainerType.CONTAINER_TYPE_BOX.type)) {
            whsType = 2;
            if (container.getType().equals(ContainerType.CONTAINER_TYPE_SALVER.type)) {
                lcoType = 2;
            }
        }
        WrkMast barcode = wrkMastService.selectOne(new EntityWrapper<WrkMast>().eq("barcode", param.getBarcode()));
@@ -1838,7 +1856,7 @@
                    throw new CoolException("数据错误,组拖档已不存在!!");
                }
                WrkMast wrkMast = generateCrnInTask(waitPakins, whsType, station, param.getLocType1(), userId);
                WrkMast wrkMast = generateCrnInTask(waitPakins, whsType, station, lcoType, userId);
                response.put("taskNo", wrkMast.getWrkNo());
                response.put("locNo", wrkMast.getLocNo());
@@ -1894,7 +1912,7 @@
                    .eq("dev_no", basStation.getDevNo())
                    .eq("matnr", combMat.getMatnr())
                    .eq("batch", combMat.getBatch())
                    .eq("standby1", combMat.getStandby1()));
                    .eq(!Cools.isEmpty(combMat.getStandby1()), "standby1", combMat.getStandby1()));
            if (Cools.isEmpty(basStationDetl)) {
                basStationDetl = new BasStationDetl();
                Mat mat = matService.selectByMatnr(combMat.getMatnr());
@@ -1935,8 +1953,8 @@
        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(!Cools.isEmpty(combMat.getBatch()), "batch", combMat.getBatch())
                .eq(!Cools.isEmpty(combMat.getStandby1()), "supp_code", combMat.getStandby1()));
        if (Cools.isEmpty(orderDetlPakin)) {
            throw new CoolException("检索单据明细数据失败");
        }
@@ -2014,6 +2032,20 @@
        if (!Objects.isNull(mast)) {
            if (mast.getIoType().equals(TaskIOType.MERGE_OUT.type) || mast.getIoType().equals(TaskIOType.PICK_OUT.type) || mast.getIoType().equals(TaskIOType.CHECK_OUT.type)) {
                int ioType = mast.getIoType() - 50;
                List<WrkDetl> wrkDetls103 = wrkDetlService
                        .selectList(new EntityWrapper<WrkDetl>().eq("wrk_no", wrkMast.getWrkNo()));
                if (wrkDetls103.isEmpty()) {
                    ioType = 10;
                }
                List<LocDetl> locDetls = locDetlService.selectList(new EntityWrapper<LocDetl>().eq("loc_no", wrkMast.getSourceLocNo()));
                if (!Objects.isNull(locDetls) && !locDetls.isEmpty()) {
                    Double sum = wrkDetls103.stream().mapToDouble(WrkDetl::getAnfme).sum();
                    Double summed = locDetls.stream().mapToDouble(LocDetl::getAnfme).sum();
                    if (summed.compareTo(sum) <= 0) {
                        ioType = 10;
                    }
                }
                mast.setIoType(ioType);
                mast.setWrkSts(2L);
                mast.setSourceStaNo(mast.getSourceStaNo());
@@ -2118,6 +2150,7 @@
        // 更新入库通知档 ioStatus ===>> Y
        Wrapper<WaitPakin> wrapper = new EntityWrapper<WaitPakin>()
                .eq("zpallet", pakin.getZpallet());
        WaitPakin setParam = new WaitPakin();
        setParam.setLocNo(locNo);
        setParam.setIoStatus("Y");
@@ -2226,7 +2259,9 @@
                        if (container.getMixMax() > sets.size()) {
                            //余下可混放种类
                            long suplus = Math.round((container.getMixMax() - sets.size()) * 10000) / 10000;
                            Mat mats = matService.selectOne(new EntityWrapper<Mat>().eq("matnr", matnr));
                            Mat mats = matService.selectOne(new EntityWrapper<Mat>()
                                    .eq("supp_code", supId)
                                    .eq("matnr", matnr));
                            if (Objects.isNull(mats)) {
                                throw new CoolException("物料不存在!!");
                            }
@@ -2258,7 +2293,7 @@
            if (Objects.isNull(locMast)) {
                throw new CoolException("未查询到可用的空板信息!!");
            }
            CrnTaskDetlDTO crnTaskDetlDTO = new CrnTaskDetlDTO().setLocNo(locMast.getLocNo()).setLocDetlList(locDetls);
            CrnTaskDetlDTO crnTaskDetlDTO = new CrnTaskDetlDTO().setLocNo(locMast.getLocNo()).setLocDetlList(new ArrayList<>());
            locMasts.add(crnTaskDetlDTO);
            // 空板出库
@@ -2278,7 +2313,7 @@
                if (Objects.isNull(locMast)) {
                    throw new CoolException("未查询到可用的空板信息!!");
                }
                CrnTaskDetlDTO crnTaskDetlDTO = new CrnTaskDetlDTO().setLocNo(locMast.getLocNo()).setLocDetlList(locDetls);
                CrnTaskDetlDTO crnTaskDetlDTO = new CrnTaskDetlDTO().setLocNo(locMast.getLocNo()).setLocDetlList(new ArrayList<>());
                locMasts.add(crnTaskDetlDTO);
                // 空板出库
@@ -2320,7 +2355,7 @@
                wrkMast.setIoType(ioType); // 入出库类型
                wrkMast.setIoPri(13D); // 优先级:13
                wrkMast.setCrnNo(locMast.getCrnNo());
                wrkMast.setSourceStaNo(staDesc.getCrnStn() + ""); // 源站
//                wrkMast.setSourceStaNo(staDesc.getCrnStn() + ""); // 源站
                wrkMast.setStaNo(staDesc.getStnNo() + ""); // 目标站
                wrkMast.setSourceLocNo(locMast.getLocNo()); // 源库位
                //小松项目,缓存出库AGV站点,用于清空缓存区库存
@@ -2360,17 +2395,17 @@
            }
            // 修改库位状态: 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);
                if (!locMastService.updateById(locMast)) {
                    throw new CoolException("预约库位状态失败,库位号:" + locMast.getLocNo());
                }
            } else {
                throw new CoolException(locMast.getLocNo() + "库位不是在库状态");
            }
//            } else {
//                throw new CoolException(locMast.getLocNo() + "库位不是在库状态");
//            }
        }
    }
@@ -2383,7 +2418,7 @@
    @Transactional(rollbackFor = Exception.class)
    public void generateCacheOutTask(BasStation station, LocCache loc, Long userId) {
        // 获取工作号
        int workNo = commonService.getWorkNo(WorkNoType.PICK.type);
        int workNo = commonService.getWorkNo(4);
        // 保存工作档
        Task task = new Task();
        task.setWrkNo(workNo)
@@ -2440,9 +2475,10 @@
        loc.setModiUser(userId);
        loc.setModiTime(new Date());
        if (!locCacheService.updateById(loc)) {
            throw new CoolException("更新库位状态信息!!");
        }
//        if (!) {
//            throw new CoolException("更新库位状态信息!!");
//        }
        locCacheService.update(loc, new EntityWrapper<LocCache>().eq("loc_no", loc.getLocNo()));
        // 修改目标站点信息
        if (station.getLocSts().equals(LocStsType.LOC_STS_TYPE_O.type)) {
@@ -2453,7 +2489,8 @@
                throw new CoolException("更新目标库位状态失败");
            }
        } else {
            throw new CoolException("移转失败,目标库位状态:" + station.getLocSts());
            log.error("移转失败,目标库位状态:" + station.getLocSts());
//            throw new CoolException("移转失败,目标库位状态:" + station.getLocSts());
        }
    }
@@ -2464,21 +2501,22 @@
     * @version 1.0
     */
    @Transactional(rollbackFor = Exception.class)
    public void generateAgvTask(String type, LocCache loc, String orgSite, String barcode, Long userId) {
    public void generateAgvTask(String type, LocCache loc, String orgSite, String barcode, Long userId, String isNewIn) {
        List<Task> tasks = taskService.selectList(new EntityWrapper<Task>().eq("barcode", barcode));
        if (!tasks.isEmpty()) {
            throw new CoolException("托盘已在任务执行中..");
        }
        // 获取工作号
        int workNo = commonService.getWorkNo(WorkNoType.PICK.type);
        int workNo = commonService.getWorkNo(4);
        // 保存工作档
        Task task = new Task();
        task.setWrkNo(workNo)
                .setIoTime(new Date())
                .setWrkSts(201L) // 工作状态:11.生成出库ID
                .setIoType(1) // 入出库状态: 11.库格移载
                .setTaskType("agv")
                .setTaskType(type)
                .setIoPri(10D)
                .setIsNewIn(isNewIn)
                .setLocNo(loc.getLocNo()) // 目标库位
                .setFullPlt("Y") // 满板:Y
                .setPicking("N") // 拣料
@@ -2491,6 +2529,7 @@
                .setAppeTime(new Date())
                .setModiUser(userId)
                .setModiTime(new Date());
        if (!taskService.insert(task)) {
            throw new CoolException("保存工作档失败");
        }
@@ -2520,7 +2559,6 @@
                if (!taskDetlService.insert(wrkDetl)) {
                    throw new CoolException("保存工作档明细失败");
                }
            }
            for (WaitPakin pakin : pakins) {
@@ -2529,28 +2567,27 @@
                    throw new CoolException("更新组托信息失败");
                }
            }
        }
        // 修改目标库位状态
        if (loc.getLocSts().equals(LocStsType.LOC_STS_TYPE_O.type)) {
            loc.setLocSts(LocStsType.LOC_STS_TYPE_S.type); // S.入库预约
            loc.setModiTime(new Date());
            loc.setModiUser(userId);
            if (!locCacheService.updateById(loc)) {
                throw new CoolException("更新目标库位状态失败");
            // 修改目标库位状态
            if (loc.getLocSts().equals(LocStsType.LOC_STS_TYPE_O.type)) {
                loc.setLocSts(LocStsType.LOC_STS_TYPE_S.type); // S.入库预约
                loc.setModiTime(new Date());
                loc.setModiUser(userId);
                if (!locCacheService.update(loc, new EntityWrapper<LocCache>().eq("loc_no", loc.getLocNo()))) {
                    throw new CoolException("更新目标库位状态失败");
                }
            } else {
                throw new CoolException("移转失败,目标库位状态:" + loc.getLocSts$());
            }
        } else {
            throw new CoolException("移转失败,目标库位状态:" + loc.getLocSts$());
        }
        // 修改目标站点信息
        BasStation station = basStationService.selectOne(new EntityWrapper<BasStation>().eq("dev_no", orgSite));
        if (Objects.isNull(station)) {
            throw new CoolException("站点不存在!!");
        }
            // 修改目标站点信息
            BasStation station = basStationService.selectOne(new EntityWrapper<BasStation>().eq("dev_no", orgSite));
            if (Objects.isNull(station)) {
                throw new CoolException("站点不存在!!");
            }
        if (station.getLocSts().equals(LocStsType.LOC_STS_TYPE_O.type) || station.getLocSts().equals(LocStsType.LOC_STS_TYPE_D.type)) {
            station.setLocSts("R"); // S.入库预约
            station.setLocSts("R"); // R.入库预约
            station.setBarcode(barcode);
            station.setModiTime(new Date());
            station.setModiUser(userId);
@@ -2558,8 +2595,30 @@
                throw new CoolException("更新目标库位状态失败");
            }
        } else {
            throw new CoolException("移转失败,目标库位状态:" + station.getLocSts());
            // 修改目标库位状态
            loc.setLocSts(LocStsType.LOC_STS_TYPE_D.type); // S.入库预约
            loc.setModiTime(new Date());
            loc.setModiUser(userId);
            if (!locCacheService.update(loc, new EntityWrapper<LocCache>().eq("loc_no", loc.getLocNo()))) {
                throw new CoolException("更新目标库位状态失败");
            }
            // 修改目标站点信息
            BasStation station = basStationService.selectOne(new EntityWrapper<BasStation>().eq("dev_no", orgSite));
            if (Objects.isNull(station)) {
                throw new CoolException("站点不存在!!");
            }
            station.setLocSts("O"); // S.入库预约
            station.setBarcode(barcode);
            station.setModiTime(new Date());
            station.setModiUser(userId);
            if (!basStationService.updateById(station)) {
                throw new CoolException("更新目标库位状态失败");
            }
        }
    }
    public HIKResultDTO sendAgvTask(HIKApiDTO haiKangApiDTO, String path) {
@@ -2646,7 +2705,7 @@
        try {
            //空台车回库
            generateAgvTask("agv_back", locCache, callAgvBackParam.getOrgSite(), station.getBarcode(), userId);
            generateAgvTask("agv_back", locCache, callAgvBackParam.getOrgSite(), station.getBarcode(), userId, "M2");
        } catch (Exception e) {
            e.printStackTrace();
            return R.error(e.getMessage());
@@ -2781,6 +2840,174 @@
    }
    /**
     * 获取缓存站点信息
     *
     * @param type
     * @return
     */
    @Override
    public R getCacheSites(String type) {
        BasAreas areas = basAreasService.selectOne(new EntityWrapper<BasAreas>().eq("whs_type_id", type));
        if (Objects.isNull(areas)) {
            return R.error("库区不存在!");
        }
        List<BasStation> stations = basStationService.selectList(new EntityWrapper<BasStation>().eq("area_id", areas.getId()));
        if (Objects.isNull(stations) || stations.isEmpty()) {
            return R.error("站点不存在!");
        }
        return R.ok("查询成功").add(stations);
    }
    /**
     * 获取捆包明细信息
     *
     * @param params
     * @return
     */
    @Override
    public R getAllBindInfo(AgvCallParams params) {
        if (Objects.isNull(params.getCarBarcode())) {
            return R.error("台车编码不能为空!");
        }
        List<TaskDetl> taskDetls = taskDetlService.selectList(new EntityWrapper<TaskDetl>()
//                .eq(!Objects.isNull(params.getMatnr()), "matnr", params.getMatnr())
                .eq("zpallet", params.getCarBarcode()));
        taskDetls.forEach(taskDetl -> {
            OrderPakout orderDetlPakout = orderPakoutService.selectOne(new EntityWrapper<OrderPakout>()
                    .eq("order_no", taskDetl.getOrderNo()));
            taskDetl.setMemo(orderDetlPakout.getShipCode());
        });
        return R.ok("查询成功").add(taskDetls);
    }
    /**
     * 确认捆包出库
     *
     * @param combParam
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public R confirmOutstock(CombParam combParam) {
        if (Objects.isNull(combParam.getCombMats()) || combParam.getCombMats().isEmpty()) {
            return R.error("捆包信息不能为空!!");
        }
        Task task = taskService.selectOne(new EntityWrapper<Task>()
                .eq("wrk_sts", 304)
                .eq("barcode", combParam.getBarcode()));
        if (Objects.isNull(task)) {
            throw new CoolException("任务信息不存在!!");
        }
        if (task.getIoType().equals(103)) {
            List<TaskDetl> taskDetls = taskDetlService.selectList(new EntityWrapper<TaskDetl>()
                    .eq("wrk_no", task.getWrkNo()));
            int workNo = commonService.getWorkNo(4);
            Task task1 = new Task();
            BeanUtils.copyProperties(task, task1);
            task1.setIoType(53);
            task1.setLocNo(task.getSourceLocNo());
            task1.setSourceStaNo(task.getStaNo());
            task1.setWrkNo(workNo);
            task1.setWrkSts(TaskStatusType.AGV_IN_START.type);
            if (!taskService.insert(task1)) {
                throw new CoolException("入库任务生成失败!!");
            }
            if (!Objects.isNull(taskDetls) && !taskDetls.isEmpty()) {
                for (CombParam.CombMat combMat : combParam.getCombMats()) {
                    taskDetls.forEach(taskDetl -> {
                        if (taskDetl.getMatnr().equals(combMat.getMatnr()) && taskDetl.getSuppCode().equals(combMat.getSuppCode())) {
                            //TODO
                            if (!taskDetl.getAnfme().equals(combMat.getAnfme())) {
                                throw new CoolException("物料--->" + combMat.getMatnr() + "未拣料完成,请确认完成后再尝试!!");
                            }
                            List<TaskDetl> taskDetls1 = taskDetlService.selectList(new EntityWrapper<TaskDetl>().eq("wrk_no", task.getWrkNo()));
                            if (!Objects.isNull(taskDetls1) && !taskDetls1.isEmpty()) {
                                taskDetls1.forEach(detl -> {
                                    detl.setWrkNo(workNo);
                                    detl.setBoxType1(combMat.getBoxType1());
                                    detl.setSupp(combMat.getSuppCode());
                                    if (!taskDetlService.update(detl, new EntityWrapper<TaskDetl>()
                                            .eq("matnr", detl.getMatnr())
                                            .eq("supp_code", detl.getSuppCode())
                                            .eq("wrk_no", task.getWrkNo()))) {
                                        throw new CoolException("任务号信息更新失败!!");
                                    }
                                });
                            }
                            task.setWrkSts(TaskStatusType.AGV_INVENTORY_UPDATED_OUT.type);
                            if (!taskService.update(task, new EntityWrapper<Task>().eq("wrk_no", taskDetl.getWrkNo()))) {
                                throw new CoolException("任务信息更新失败!!");
                            }
                        }
                    });
                }
            }
        }
        //TODO 比对实际出库数量和任务档数量是否相等,修改原任务档为53,生成新的入库任务
        return R.ok("呼叫成功!!");
    }
    /**
     * 空板出库任务
     *
     * @param params
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public R getEmptyOutStock(AgvCallParams params) {
        if (Objects.isNull(params.getOrgSite())) {
            return R.error("托盘类型不能为空!!");
        }
        if (Objects.isNull(params.getTarSite())) {
            return R.error("目标站点不能为空!!");
        }
        Wrapper<LocMast> wrapper = new EntityWrapper<LocMast>().eq("loc_sts", LocStsType.LOC_STS_TYPE_D.type);
        if (params.getOrgSite().equals(MatLocType.AUTOMATED.type)) {
            wrapper.like("barcode", "LX80");
        } else if (params.getOrgSite().equals(MatLocType.SO_HOLDING.type)) {
            wrapper.like("barcode", "TP80");
        } else {
            wrapper.like("barcode", "TP88");
        }
        wrapper.orderAsc(Arrays.asList("row1", "lev1"));
        LocMast locMast = locMastService.selectOne(wrapper);
        if (Objects.isNull(locMast)) {
            return R.error("没有可用空板!!");
        }
        //TODO 生成并板出库任务
        WrkMast wrkMast = new WrkMast();
        wrkMast.setIoType(104);
        wrkMast.setWrkSts(11L);
        wrkMast.setStaNo(params.getTarSite());
        wrkMast.setSourceLocNo(locMast.getLocNo());
        wrkMast.setBarcode(locMast.getBarcode());
        wrkMast.setIoPri(14.0);
        wrkMast.setAppeTime(new Date());
        wrkMast.setModiTime(new Date());
        wrkMast.setCrnNo(locMast.getCrnNo());
        wrkMast.setIoTime(new Date());
        wrkMast.setWrkDate(new Date());
        wrkMast.setWrkNo(commonService.getWorkNo(0));
        wrkMast.setTaskType("crn");
        if (!wrkMastService.insert(wrkMast)) {
            throw new CoolException("新建任务失败!!");
        }
        return R.ok().add(wrkMast);
    }
    /**
     * 生成移库任务
     *
     * @param result