pjb
2025-03-08 83b51a5a0774ea8ecb9a06304af3b956a21307c8
zy-asrs-wms/src/main/java/com/zy/asrs/wms/asrs/service/impl/WorkServiceImpl.java
@@ -3,7 +3,6 @@
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zy.asrs.framework.common.Cools;
import com.zy.asrs.framework.common.R;
import com.zy.asrs.framework.exception.CoolException;
import com.zy.asrs.wms.asrs.entity.*;
import com.zy.asrs.wms.asrs.entity.enums.*;
@@ -90,7 +89,7 @@
    @Override
    public Loc generateEmptyLoc(Long taskType, Integer locTypeHeight) {
        List<ShelvesRule> shelvesRules = shelvesRuleService.list(new LambdaQueryWrapper<ShelvesRule>().eq(ShelvesRule::getStatus, 1).orderByDesc(ShelvesRule::getCreateTime));
        if(shelvesRules.isEmpty()) {
        if (shelvesRules.isEmpty()) {
            throw new CoolException("未配置上架规则");
        }
        ShelvesRule shelvesRule = shelvesRules.get(0);
@@ -114,7 +113,7 @@
        }
        List<ShelvesRuleDetl> ruleDetls = shelvesRule.getRuleDetl$();
        if(ruleDetls.isEmpty()) {
        if (ruleDetls.isEmpty()) {
            throw new CoolException("未配置上架规则明细");
        }
@@ -135,22 +134,23 @@
                //获取库位
                if (!suggestLoc.isEmpty()) {
                    defaultLoc = locUtils.filterLoc(taskType, suggestLoc);
                    if(defaultLoc != null) {
                    if (defaultLoc != null) {
                        return defaultLoc;
                    }
                }
            }
            if (ruleDetl.getDetlType().equals(ShelvesRuleDetlType.COMPLETE.id)) {
                return locUtils.getGlobalEmptyLocToCtu(locTypeHeight);
                //从全局库位中获取(完整巷道)
                List<Loc> globalLoc = locUtils.getGlobalEmptyLoc(taskType, locTypeHeight, laneRowList, currentLev);
                //获取库位
                if (!globalLoc.isEmpty()) {
                    defaultLoc = locUtils.filterAllLoc(globalLoc);
                    if(defaultLoc != null) {
                        return defaultLoc;
                    }
                }
//                List<Loc> globalLoc = locUtils.getGlobalEmptyLoc(taskType, locTypeHeight, laneRowList, currentLev);
//                //获取库位
//                if (!globalLoc.isEmpty()) {
//                    defaultLoc = locUtils.filterAllLoc(globalLoc);
//                    if (defaultLoc != null) {
//                        return defaultLoc;
//                    }
//                }
            }
        }
@@ -240,22 +240,23 @@
            }
            if (ruleDetl.getDetlType().equals(ShelvesRuleDetlType.COMPLETE.id)) {
                return locUtils.getGlobalEmptyLocToCtu(locTypeHeight);
                //从全局库位中获取(完整巷道)
                List<Loc> globalLoc = locUtils.getGlobalLoc(taskType, locTypeHeight, laneRowList, currentLev);
                //获取库位
                if (!globalLoc.isEmpty()) {
                    defaultLoc = locUtils.filterAllLoc(globalLoc);
                    if (defaultLoc != null) {
                        return defaultLoc;
                    }
                }
//                List<Loc> globalLoc = locUtils.getGlobalLoc(taskType, locTypeHeight, laneRowList, currentLev);
//                //获取库位
//                if (!globalLoc.isEmpty()) {
//                    defaultLoc = locUtils.filterAllLoc(globalLoc);
//                    if (defaultLoc != null) {
//                        return defaultLoc;
//                    }
//                }
            }
        }
        return defaultLoc;
    }
    @Override
    @Transactional
    @Transactional(rollbackFor = Exception.class)
    public boolean generatePakIn(GeneratePakInParam param) {
        List<WaitPakin> waitPakins = waitPakinService.list(new LambdaQueryWrapper<WaitPakin>().eq(WaitPakin::getBarcode, param.getBarcode()));
        if (param.getTaskType() != 10 && waitPakins.isEmpty()) {
@@ -274,20 +275,25 @@
        //生成库位
        Loc loc = this.generateLoc(param.getTaskType(), param.getBarcode(), param.getLocTypeHeight());
        if(loc == null) {
        if (loc == null) {
            throw new CoolException("没有空库位");
        }
        Task task = new Task();
        task.setTaskNo(this.generateTaskNo(taskType.getId()));//任务号
        task.setTaskSts(TaskStsType.GENERATE_IN.id);//1.生成入库任务
        task.setTaskType(taskType.getId());//任务类型
        task.setIoPri(this.generateIoPri(taskType.getId()));//优先级
        //任务号
        task.setTaskNo(this.generateTaskNo(taskType.getId()));
        //1.生成入库任务
        task.setTaskSts(TaskStsType.GENERATE_IN.id);
        //任务类型
        task.setTaskType(taskType.getId());
        //优先级
        task.setIoPri(this.generateIoPri(taskType.getId()));
        task.setOriginLoc(null);
        task.setTargetLoc(loc.getLocNo());
        task.setOriginSite(param.getOriginSite());
        task.setTargetSite(null);
        task.setBarcode(param.getBarcode());//托盘码
        //托盘码
        task.setBarcode(param.getBarcode());
        boolean taskSave = taskService.save(task);
        if (!taskSave) {
            throw new CoolException("任务生成失败");
@@ -298,9 +304,12 @@
            TaskDetl taskDetl = new TaskDetl();
            taskDetl.setTaskId(task.getId());
            taskDetl.setTaskNo(task.getTaskNo());
            taskDetl.setAnfme(waitPakin.getAnfme());//数量
            taskDetl.setStock(0D);//库存
            taskDetl.setBatch(waitPakin.getDetl$().getBatch());//批号
            //数量
            taskDetl.setAnfme(waitPakin.getAnfme());
            //库存
            taskDetl.setStock(0D);
            //批号
            taskDetl.setBatch(waitPakin.getDetl$().getBatch());
            taskDetl.setBarcode(waitPakin.getBarcode());
            taskDetl.setOrderId(waitPakin.getOrderId());
            taskDetl.setOrderNo(waitPakin.getOrderNo());
@@ -308,7 +317,7 @@
            taskDetl.setMatId(waitPakin.getDetl$().getMatId());
            taskDetl.setMatnr(waitPakin.getDetl$().getMat$().getMatnr());
            boolean taskDetlSave = taskDetlService.save(taskDetl);
            if(!taskDetlSave){
            if (!taskDetlSave) {
                throw new CoolException("任务明细生成失败");
            }
@@ -321,7 +330,7 @@
                taskDetlField.setDetlId(taskDetl.getId());
                taskDetlField.setValue(orderDetlField.getValue());
                boolean taskDetlFieldSave = taskDetlFieldService.save(taskDetlField);
                if(!taskDetlFieldSave){
                if (!taskDetlFieldSave) {
                    throw new CoolException("明细扩展生成失败");
                }
            }
@@ -330,26 +339,26 @@
            waitPakin.setIoStatus(1);
            waitPakin.setUpdateTime(new Date());
            boolean waitPakinUpdate = waitPakinService.updateById(waitPakin);
            if(!waitPakinUpdate){
            if (!waitPakinUpdate) {
                throw new CoolException("组托通知档更新失败");
            }
            //更新订单明细数据
            OrderDetl orderDetl = orderDetlService.getById(taskDetl.getDetlId());
            if(orderDetl == null){
            if (orderDetl == null) {
                throw new CoolException("订单明细不存在");
            }
            orderDetl.setWorkQty(orderDetl.getWorkQty() + taskDetl.getAnfme());
            orderDetl.setUpdateTime(new Date());
            boolean orderDetlUpdate = orderDetlService.updateById(orderDetl);
            if(!orderDetlUpdate){
            if (!orderDetlUpdate) {
                throw new CoolException("订单明细更新失败");
            }
            //获取订单
            Order order = orderService.getById(taskDetl.getOrderId());
            if(order == null){
            if (order == null) {
                throw new CoolException("订单不存在");
            }
@@ -367,7 +376,7 @@
        loc.setLocStsId(LocStsType.S.val());
        loc.setUpdateTime(new Date());
        boolean locUpdate = locService.updateById(loc);
        if(!locUpdate){
        if (!locUpdate) {
            throw new CoolException("库位状态更新失败");
        }
@@ -383,7 +392,7 @@
        //生成库位
        Loc loc = this.generateEmptyLoc(param.getTaskType(), param.getLocTypeHeight());
        if(loc == null) {
        if (loc == null) {
            throw new CoolException("没有空库位");
        }
@@ -406,7 +415,7 @@
        loc.setLocStsId(LocStsType.S.val());
        loc.setUpdateTime(new Date());
        boolean locUpdate = locService.updateById(loc);
        if(!locUpdate){
        if (!locUpdate) {
            throw new CoolException("库位状态更新失败");
        }
@@ -416,7 +425,7 @@
    @Override
    public boolean completeTask(Long taskId) {
        Task task = taskService.getById(taskId);
        if(task == null){
        if (task == null) {
            throw new CoolException("任务不存在");
        }
@@ -428,12 +437,12 @@
        if (task.getTaskType() < 100) {
            //入库
            task.setTaskSts(TaskStsType.COMPLETE_IN.id);//99.入库完成
        }else {
        } else {
            //出库
            TaskDetl taskDetl = taskDetls.get(0);
            TaskDetl taskDetl = taskDetls.get(0); //TODO  出库流程待确认,ESS取货后,输送线流转到扫码处状态
            if (taskDetl.getWaveId() == null) {
                task.setTaskSts(TaskStsType.COMPLETE_OUT.id);//199.出库完成
            }else {
            } else {
                task.setTaskSts(TaskStsType.WAVE_SEED.id);//198.播种中
            }
        }
@@ -450,7 +459,7 @@
    @Transactional(rollbackFor = Exception.class)
    public boolean cancelTask(Long taskId) {
        Task task = taskService.getById(taskId);
        if(task == null){
        if (task == null) {
            throw new CoolException("任务不存在");
        }
@@ -463,15 +472,15 @@
            case 54://并板
            case 57://盘点
                loc = locService.getOne(new LambdaQueryWrapper<Loc>().eq(Loc::getLocNo, task.getTargetLoc()));
                if(loc == null){
                if (loc == null) {
                    throw new CoolException("库位不存在");
                }
                if(loc.getLocStsId() != LocStsType.S.val()){
                if (loc.getLocStsId() != LocStsType.S.val()) {
                    throw new CoolException("库位状态不处于S.入库预约");
                }
                loc.setLocStsId(LocStsType.O.val());
                loc.setUpdateTime(new Date());
                if(!locService.updateById(loc)){
                if (!locService.updateById(loc)) {
                    throw new CoolException("库位状态变更失败");
                }
                break;
@@ -481,15 +490,15 @@
            case 107://盘点
            case 110://空板
                loc = locService.getOne(new LambdaQueryWrapper<Loc>().eq(Loc::getLocNo, task.getOriginLoc()));
                if(loc == null){
                if (loc == null) {
                    throw new CoolException("库位不存在");
                }
                if(loc.getLocStsId() != LocStsType.R.val()){
                if (loc.getLocStsId() != LocStsType.R.val()) {
                    throw new CoolException("库位状态不处于R.出库预约");
                }
                loc.setLocStsId(LocStsType.F.val());
                loc.setUpdateTime(new Date());
                if(!locService.updateById(loc)){
                if (!locService.updateById(loc)) {
                    throw new CoolException("库位状态变更失败");
                }
@@ -501,7 +510,7 @@
                    String matUniqueKey = Utils.getMatUniqueKey(taskDetl.getMatnr(), taskDetl.getBatch(), taskDetl.getUniqueField());
                    WaveDetl waveDetl = waveDetlService.getOne(new LambdaQueryWrapper<WaveDetl>().eq(WaveDetl::getStockIndex, matUniqueKey).eq(WaveDetl::getWaveId, taskDetl.getWaveId()));
                    if(waveDetl == null){
                    if (waveDetl == null) {
                        continue;
                    }
                    waveDetl.setWorkQty(waveDetl.getWorkQty() - taskDetl.getAnfme());
@@ -513,7 +522,7 @@
                break;
            case 11://库位移转
                Loc originLoc = locService.getOne(new LambdaQueryWrapper<Loc>().eq(Loc::getLocNo, task.getOriginLoc()));
                if(originLoc == null){
                if (originLoc == null) {
                    throw new CoolException("源库位不存在");
                }
                if (originLoc.getLocStsId() != LocStsType.R.val()) {
@@ -521,22 +530,22 @@
                }
                loc = locService.getOne(new LambdaQueryWrapper<Loc>().eq(Loc::getLocNo, task.getTargetLoc()));
                if(loc == null){
                if (loc == null) {
                    throw new CoolException("目标库位不存在");
                }
                if(loc.getLocStsId() != LocStsType.S.val()){
                if (loc.getLocStsId() != LocStsType.S.val()) {
                    throw new CoolException("目标库位状态不处于S.入库预约");
                }
                originLoc.setLocStsId(LocStsType.F.val());
                originLoc.setUpdateTime(new Date());
                if(!locService.updateById(originLoc)){
                if (!locService.updateById(originLoc)) {
                    throw new CoolException("库位状态变更失败");
                }
                loc.setLocStsId(LocStsType.O.val());
                loc.setUpdateTime(new Date());
                if(!locService.updateById(loc)){
                if (!locService.updateById(loc)) {
                    throw new CoolException("库位状态变更失败");
                }
                break;
@@ -552,7 +561,7 @@
        //删除任务
        boolean removeTask = taskService.removeById(taskId);
        if(!removeTask){
        if (!removeTask) {
            throw new CoolException("回滚任务失败");
        }
@@ -571,14 +580,14 @@
                //入库回滚组托通知档
                if (task.getTaskType() == 1) {
                    WaitPakin waitPakin = waitPakinService.getOne(new LambdaQueryWrapper<WaitPakin>().eq(WaitPakin::getDetlId, taskDetl.getDetlId()).eq(WaitPakin::getBarcode, task.getBarcode()));
                    if(waitPakin == null){
                    if (waitPakin == null) {
                        throw new CoolException("组托通知档不存在");
                    }
                    waitPakin.setIoStatus(0);
                    waitPakin.setUpdateTime(new Date());
                    boolean updateWaitPakin = waitPakinService.updateById(waitPakin);
                    if(!updateWaitPakin){
                    if (!updateWaitPakin) {
                        throw new CoolException("组托通知档回滚失败");
                    }
                }
@@ -594,7 +603,7 @@
                //删除明细
                boolean removeDetl = taskDetlService.removeById(taskDetl.getId());
                if(!removeDetl){
                if (!removeDetl) {
                    throw new CoolException("回滚明细失败");
                }
@@ -611,7 +620,7 @@
                    //删除明细扩展
                    boolean removeField = taskDetlFieldService.removeById(detlField.getId());
                    if(!removeField){
                    if (!removeField) {
                        throw new CoolException("回滚扩展明细失败");
                    }
                }
@@ -622,9 +631,10 @@
    }
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean pickTask(Long taskId) {
        Task task = taskService.getById(taskId);
        if(task == null){
        if (task == null) {
            throw new CoolException("任务不存在");
        }
@@ -632,27 +642,29 @@
            throw new CoolException("任务类型不可拣料");
        }
        if (task.getTaskSts() != 200) {
        if (task.getTaskSts() != 198) {
            throw new CoolException("当前状态不可拣料");
        }
        //获取源库位
        Loc originLoc = locService.getOne(new LambdaQueryWrapper<Loc>().eq(Loc::getLocNo, task.getOriginLoc()));
        if(originLoc == null){
        if (originLoc == null) {
            throw new CoolException("源库位不存在");
        }
        //获取源库位高度
        LocTypeBind locTypeBind = locTypeBindService.getOne(new LambdaQueryWrapper<LocTypeBind>().eq(LocTypeBind::getLocId, originLoc.getId()).in(LocTypeBind::getTypeId, LocBindType.HEIGHT.list()));
        if(locTypeBind == null){
        if (locTypeBind == null) {
            throw new CoolException("库位类型不存在");
        }
        LocType locType = locTypeService.getById(locTypeBind.getTypeId());
        if(locType == null){
        if (locType == null) {
            throw new CoolException("库位类型不存在");
        }
        LocTypeHeightType locTypeHeightType = LocTypeHeightType.get(locType.getFlag());
        if(locTypeHeightType == null){
        if (locTypeHeightType == null) {
            throw new CoolException("高低库位类型不存在");
        }
@@ -663,26 +675,30 @@
            throw new CoolException("任务明细不存在");
        }
        TaskDetl taskDetl = taskDetls.get(0);
        //生成库位
        Loc loc = this.generateLoc(taskType, taskDetl.getMatId(), taskDetl.getBatch(), taskDetl.getUniqueField(), locTypeHeightType.id);
        if(loc == null) {
        //生成新的库位 !important
//        Loc loc = this.generateLoc(taskType, taskDetl.getMatId(), taskDetl.getBatch(), taskDetl.getUniqueField(), locTypeHeightType.id);
//        if(loc == null) {
//            throw new CoolException("没有空库位");
//        }
        Loc loc = locService.getOne(new LambdaQueryWrapper<Loc>().eq(Loc::getLocNo, task.getOriginLoc()));
        if (loc == null) {
            throw new CoolException("没有空库位");
        }
        task.setTaskSts(TaskStsType.GENERATE_IN.id);//1.生成入库任务
        //102拣料此处需修改为WCS_CONTAINER_RECEIVE,定时任务查询后,自动下发入库任务至ESS
        task.setTaskSts(TaskStsType.WCS_CONTAINER_RECEIVE.id);//1.生成入库任务
        task.setTaskType(taskType);
        task.setTargetLoc(loc.getLocNo());
        //原库位变目标库位, 原站点变目标站点
        //todo 需确认原站点为空,该怎么处理
        task.setTargetLoc(task.getOriginLoc());
        task.setUpdateTime(new Date());
        if (!taskService.updateById(task)) {
            throw new CoolException("拣料失败");
        }
        //库位O => S
        //库位状态改为预约入库 R => S
        loc.setLocStsId(LocStsType.S.val());
        loc.setUpdateTime(new Date());
        boolean locUpdate = locService.updateById(loc);
        if(!locUpdate){
        if (!locUpdate) {
            throw new CoolException("库位状态更新失败");
        }
@@ -690,7 +706,7 @@
    }
    @Override
    @Transactional
    @Transactional(rollbackFor = Exception.class)
    public boolean locAdjust(LocAdjustParam param) {
        if (param == null) {
            throw new CoolException("参数不能为空");
@@ -782,7 +798,7 @@
            throw new CoolException("目标库位不存在");
        }
        if(targetLoc.getLocStsId() != LocStsType.O.val()){
        if (targetLoc.getLocStsId() != LocStsType.O.val()) {
            throw new CoolException("目标库位非空状态");
        }
@@ -807,7 +823,7 @@
        }
        List<LocDetl> locDetls = locDetlService.list(new LambdaQueryWrapper<LocDetl>().eq(LocDetl::getLocId, sourceLoc.getId()));
        if(locDetls.isEmpty()){
        if (locDetls.isEmpty()) {
            throw new CoolException("源库位明细不存在");
        }
@@ -823,7 +839,7 @@
            taskDetl.setMatId(locDetl.getMatId());
            taskDetl.setMatnr(locDetl.getMatnr());
            boolean taskDetlSave = taskDetlService.save(taskDetl);
            if(!taskDetlSave){
            if (!taskDetlSave) {
                throw new CoolException("任务明细生成失败");
            }
@@ -836,7 +852,7 @@
                taskDetlField.setDetlId(taskDetl.getId());
                taskDetlField.setValue(locDetlField.getValue());
                boolean taskDetlFieldSave = taskDetlFieldService.save(taskDetlField);
                if(!taskDetlFieldSave){
                if (!taskDetlFieldSave) {
                    throw new CoolException("明细扩展生成失败");
                }
            }
@@ -846,7 +862,7 @@
        sourceLoc.setLocStsId(LocStsType.R.val());
        sourceLoc.setUpdateTime(new Date());
        boolean sourceLocUpdate = locService.updateById(sourceLoc);
        if(!sourceLocUpdate){
        if (!sourceLocUpdate) {
            throw new CoolException("库位状态更新失败");
        }
@@ -854,7 +870,7 @@
        targetLoc.setLocStsId(LocStsType.S.val());
        targetLoc.setUpdateTime(new Date());
        boolean targetLocUpdate = locService.updateById(targetLoc);
        if(!targetLocUpdate){
        if (!targetLocUpdate) {
            throw new CoolException("库位状态更新失败");
        }