Junjie
2024-12-03 08cd807032b661ec5061ab822ccbf53b41d7d438
zy-asrs-wms/src/main/java/com/zy/asrs/wms/asrs/service/impl/WorkServiceImpl.java
@@ -1,11 +1,14 @@
package com.zy.asrs.wms.asrs.service.impl;
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.*;
import com.zy.asrs.wms.asrs.entity.param.FieldParam;
import com.zy.asrs.wms.asrs.entity.param.GeneratePakInParam;
import com.zy.asrs.wms.asrs.entity.param.LocTransferParam;
import com.zy.asrs.wms.asrs.service.*;
import com.zy.asrs.wms.utils.LocUtils;
import com.zy.asrs.wms.utils.OrderUtils;
@@ -37,6 +40,10 @@
    private OrderDetlService orderDetlService;
    @Autowired
    private LocService locService;
    @Autowired
    private LocDetlService locDetlService;
    @Autowired
    private LocDetlFieldService locDetlFieldService;
    @Autowired
    private LocStsService locStsService;
    @Autowired
@@ -499,8 +506,35 @@
                        throw new CoolException("波次明细更新失败");
                    }
                }
                break;
            case 11://库位移转
                Loc originLoc = locService.getOne(new LambdaQueryWrapper<Loc>().eq(Loc::getLocNo, task.getOriginLoc()));
                if(originLoc == null){
                    throw new CoolException("源库位不存在");
                }
                if (originLoc.getLocStsId() != LocStsType.R.val()) {
                    throw new CoolException("源库位状态不处于R.出库预约");
                }
                loc = locService.getOne(new LambdaQueryWrapper<Loc>().eq(Loc::getLocNo, task.getTargetLoc()));
                if(loc == null){
                    throw new CoolException("目标库位不存在");
                }
                if(loc.getLocStsId() != LocStsType.S.val()){
                    throw new CoolException("目标库位状态不处于S.入库预约");
                }
                originLoc.setLocStsId(LocStsType.F.val());
                originLoc.setUpdateTime(new Date());
                if(!locService.updateById(originLoc)){
                    throw new CoolException("库位状态变更失败");
                }
                loc.setLocStsId(LocStsType.O.val());
                loc.setUpdateTime(new Date());
                if(!locService.updateById(loc)){
                    throw new CoolException("库位状态变更失败");
                }
                break;
        }
@@ -650,4 +684,111 @@
        return true;
    }
    @Override
    public boolean locTransfer(LocTransferParam param) {
        if (param == null) {
            throw new CoolException("参数不能为空");
        }
        if (Cools.isEmpty(param.getSourceLocNo())) {
            throw new CoolException("源库位不能为空");
        }
        if (Cools.isEmpty(param.getTargetLocNo())) {
            throw new CoolException("目标库位不能为空");
        }
        Loc sourceLoc = locService.getOne(new LambdaQueryWrapper<Loc>().eq(Loc::getLocNo, param.getSourceLocNo()));
        if (sourceLoc == null) {
            throw new CoolException("源库位不存在");
        }
        if (sourceLoc.getLocStsId() != LocStsType.F.val()) {
            throw new CoolException("源库位非在库状态");
        }
        Loc targetLoc = locService.getOne(new LambdaQueryWrapper<Loc>().eq(Loc::getLocNo, param.getTargetLocNo()));
        if (targetLoc == null) {
            throw new CoolException("目标库位不存在");
        }
        if(targetLoc.getLocStsId() != LocStsType.O.val()){
            throw new CoolException("目标库位非空状态");
        }
        TaskType taskType = taskTypeService.getById(11);
        if (taskType == 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.setOriginLoc(param.getSourceLocNo());
        task.setTargetLoc(param.getTargetLocNo());
        task.setOriginSite(null);
        task.setTargetSite(null);
        task.setBarcode(sourceLoc.getBarcode());//托盘码
        boolean taskSave = taskService.save(task);
        if (!taskSave) {
            throw new CoolException("任务生成失败");
        }
        List<LocDetl> locDetls = locDetlService.list(new LambdaQueryWrapper<LocDetl>().eq(LocDetl::getLocId, sourceLoc.getId()));
        if(locDetls.isEmpty()){
            throw new CoolException("源库位明细不存在");
        }
        //生成任务明细
        for (LocDetl locDetl : locDetls) {
            TaskDetl taskDetl = new TaskDetl();
            taskDetl.setTaskId(task.getId());
            taskDetl.setTaskNo(task.getTaskNo());
            taskDetl.setAnfme(locDetl.getAnfme());//数量
            taskDetl.setStock(0D);//库存
            taskDetl.setBatch(locDetl.getBatch());//批号
            taskDetl.setBarcode(sourceLoc.getBarcode());
            taskDetl.setMatId(locDetl.getMatId());
            taskDetl.setMatnr(locDetl.getMatnr());
            boolean taskDetlSave = taskDetlService.save(taskDetl);
            if(!taskDetlSave){
                throw new CoolException("任务明细生成失败");
            }
            //生成明细扩展
            List<LocDetlField> locDetlFieldList = locDetlFieldService.list(new LambdaQueryWrapper<LocDetlField>().eq(LocDetlField::getDetlId, locDetl.getId()));
            for (LocDetlField locDetlField : locDetlFieldList) {
                TaskDetlField taskDetlField = new TaskDetlField();
                taskDetlField.setName(locDetlField.getName());
                taskDetlField.setFieldId(locDetlField.getFieldId());
                taskDetlField.setDetlId(taskDetl.getId());
                taskDetlField.setValue(locDetlField.getValue());
                boolean taskDetlFieldSave = taskDetlFieldService.save(taskDetlField);
                if(!taskDetlFieldSave){
                    throw new CoolException("明细扩展生成失败");
                }
            }
        }
        //库位F => R
        sourceLoc.setLocStsId(LocStsType.R.val());
        sourceLoc.setUpdateTime(new Date());
        boolean sourceLocUpdate = locService.updateById(sourceLoc);
        if(!sourceLocUpdate){
            throw new CoolException("库位状态更新失败");
        }
        //库位O => S
        targetLoc.setLocStsId(LocStsType.S.val());
        targetLoc.setUpdateTime(new Date());
        boolean targetLocUpdate = locService.updateById(targetLoc);
        if(!targetLocUpdate){
            throw new CoolException("库位状态更新失败");
        }
        return true;
    }
}