|  |  |  | 
|---|
|  |  |  | package com.zy.asrs.wms.asrs.manage; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | 
|---|
|  |  |  | import com.zy.asrs.framework.common.Cools; | 
|---|
|  |  |  | import com.zy.asrs.framework.exception.CoolException; | 
|---|
|  |  |  | import com.zy.asrs.wms.asrs.entity.Loc; | 
|---|
|  |  |  | import com.zy.asrs.wms.asrs.entity.LocDetl; | 
|---|
|  |  |  | import com.zy.asrs.wms.asrs.entity.Task; | 
|---|
|  |  |  | import com.zy.asrs.wms.asrs.entity.TaskDetl; | 
|---|
|  |  |  | import com.zy.asrs.wms.asrs.entity.enums.LocStsType; | 
|---|
|  |  |  | import com.zy.asrs.wms.asrs.entity.enums.TaskStsType; | 
|---|
|  |  |  | import com.zy.asrs.wms.asrs.service.*; | 
|---|
|  |  |  | import org.slf4j.Logger; | 
|---|
|  |  |  | import org.slf4j.LoggerFactory; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | import org.springframework.stereotype.Service; | 
|---|
|  |  |  | import org.springframework.transaction.annotation.Transactional; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.util.List; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Service | 
|---|
|  |  |  | public class LocManage { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private static Logger logger = LoggerFactory.getLogger(LocManage.class); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private LocService locService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private LocDetlService locDetlService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private WorkService workService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private TaskService taskService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private TaskDetlService taskDetlService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 移库方法 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param sourceLocId 源库位 | 
|---|
|  |  |  | * @param locId       目标库位 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Transactional | 
|---|
|  |  |  | public void locMove(Long sourceLocId, Long locId) { | 
|---|
|  |  |  | logger.info("移库操作,源库位:{},目标库位:{}", sourceLocId, locId); | 
|---|
|  |  |  | if (Cools.isEmpty(sourceLocId) || Cools.isEmpty(locId)) { | 
|---|
|  |  |  | throw new CoolException("源库位或目标为空"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Loc sourceLoc = locService.getById(sourceLocId); | 
|---|
|  |  |  | Loc loc = locService.getById(locId); | 
|---|
|  |  |  | if (Cools.isEmpty(sourceLoc) || Cools.isEmpty(loc)) { | 
|---|
|  |  |  | throw new CoolException("源库位或目标为空"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | List<LocDetl> locDetls = locDetlService.list(new LambdaQueryWrapper<LocDetl>().eq(LocDetl::getLocId, sourceLoc.getId())); | 
|---|
|  |  |  | //TODO 根据不同的设备,可能有不同的移库规则 | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 保存工作档 | 
|---|
|  |  |  | Task task = new Task(); | 
|---|
|  |  |  | task.setTaskNo(workService.generateTaskNo(1L)); | 
|---|
|  |  |  | // 任务状态 | 
|---|
|  |  |  | task.setTaskSts(TaskStsType.GENERATE_OUT.id); | 
|---|
|  |  |  | // 任务类型 | 
|---|
|  |  |  | task.setTaskType(11L); | 
|---|
|  |  |  | // 优先级 | 
|---|
|  |  |  | task.setIoPri(1); | 
|---|
|  |  |  | // 源库位 | 
|---|
|  |  |  | task.setOriginLoc(sourceLoc.getLocNo()); | 
|---|
|  |  |  | // 目标库位 | 
|---|
|  |  |  | task.setTargetLoc(loc.getLocNo()); | 
|---|
|  |  |  | // 托盘码 | 
|---|
|  |  |  | task.setBarcode(loc.getBarcode()); | 
|---|
|  |  |  | boolean res = taskService.save(task); | 
|---|
|  |  |  | if (!res) { | 
|---|
|  |  |  | throw new CoolException("保存工作档失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 工作档明细保存 | 
|---|
|  |  |  | for (LocDetl locDetl : locDetls) { | 
|---|
|  |  |  | TaskDetl taskDetl = new TaskDetl(); | 
|---|
|  |  |  | taskDetl.sync(locDetl); | 
|---|
|  |  |  | taskDetl.setTaskId(task.getId()); | 
|---|
|  |  |  | if (!taskDetlService.save(taskDetl)) { | 
|---|
|  |  |  | throw new CoolException("保存工作档明细失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 修改源库位状态 | 
|---|
|  |  |  | if (sourceLoc.getLocStsId$().equals("D") || sourceLoc.getLocStsId$().equals("F")) { | 
|---|
|  |  |  | sourceLoc.setLocStsId(LocStsType.R.val()); // R.出库预约 | 
|---|
|  |  |  | if (!locService.updateById(sourceLoc)) { | 
|---|
|  |  |  | throw new CoolException("更新源库位状态失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | throw new CoolException("源库位出库失败,状态:" + sourceLoc.getLocStsId$()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 修改目标库位状态 | 
|---|
|  |  |  | if (loc.getLocStsId$().equals("O")) { | 
|---|
|  |  |  | loc.setLocStsId(LocStsType.S.val()); // S.入库预约 | 
|---|
|  |  |  | if (!locService.updateById(loc)) { | 
|---|
|  |  |  | throw new CoolException("更新目标库位状态失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | throw new CoolException("移转失败,目标库位状态:" + loc.getLocStsId$()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | package com.zy.asrs.wms.asrs.manage; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | 
|---|
|  |  |  | import com.zy.asrs.framework.common.Cools; | 
|---|
|  |  |  | import com.zy.asrs.framework.exception.CoolException; | 
|---|
|  |  |  | import com.zy.asrs.wms.asrs.entity.Loc; | 
|---|
|  |  |  | import com.zy.asrs.wms.asrs.entity.LocDetl; | 
|---|
|  |  |  | import com.zy.asrs.wms.asrs.entity.Task; | 
|---|
|  |  |  | import com.zy.asrs.wms.asrs.entity.TaskDetl; | 
|---|
|  |  |  | import com.zy.asrs.wms.asrs.entity.enums.LocStsType; | 
|---|
|  |  |  | import com.zy.asrs.wms.asrs.entity.enums.TaskStsType; | 
|---|
|  |  |  | import com.zy.asrs.wms.asrs.service.*; | 
|---|
|  |  |  | import org.slf4j.Logger; | 
|---|
|  |  |  | import org.slf4j.LoggerFactory; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | import org.springframework.stereotype.Service; | 
|---|
|  |  |  | import org.springframework.transaction.annotation.Transactional; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.util.List; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Service | 
|---|
|  |  |  | public class LocManage { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private static Logger logger = LoggerFactory.getLogger(LocManage.class); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private LocService locService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private LocDetlService locDetlService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private WorkService workService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private TaskService taskService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private TaskDetlService taskDetlService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 移库方法 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param sourceLocId 源库位 | 
|---|
|  |  |  | * @param locId       目标库位 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Transactional | 
|---|
|  |  |  | public void locMove(Long sourceLocId, Long locId) { | 
|---|
|  |  |  | logger.info("移库操作,源库位:{},目标库位:{}", sourceLocId, locId); | 
|---|
|  |  |  | if (Cools.isEmpty(sourceLocId) || Cools.isEmpty(locId)) { | 
|---|
|  |  |  | throw new CoolException("源库位或目标为空"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Loc sourceLoc = locService.getById(sourceLocId); | 
|---|
|  |  |  | Loc loc = locService.getById(locId); | 
|---|
|  |  |  | if (Cools.isEmpty(sourceLoc) || Cools.isEmpty(loc)) { | 
|---|
|  |  |  | throw new CoolException("源库位或目标为空"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | List<LocDetl> locDetls = locDetlService.list(new LambdaQueryWrapper<LocDetl>().eq(LocDetl::getLocId, sourceLoc.getId())); | 
|---|
|  |  |  | //TODO 根据不同的设备,可能有不同的移库规则 | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 保存工作档 | 
|---|
|  |  |  | Task task = new Task(); | 
|---|
|  |  |  | task.setTaskNo(workService.generateTaskNo(1L)); | 
|---|
|  |  |  | // 任务状态 | 
|---|
|  |  |  | task.setTaskSts(TaskStsType.GENERATE_OUT.id); | 
|---|
|  |  |  | // 任务类型 | 
|---|
|  |  |  | task.setTaskType(11L); | 
|---|
|  |  |  | // 优先级 | 
|---|
|  |  |  | task.setIoPri(1); | 
|---|
|  |  |  | // 源库位 | 
|---|
|  |  |  | task.setOriginLoc(sourceLoc.getLocNo()); | 
|---|
|  |  |  | // 目标库位 | 
|---|
|  |  |  | task.setTargetLoc(loc.getLocNo()); | 
|---|
|  |  |  | // 托盘码 | 
|---|
|  |  |  | task.setBarcode(loc.getBarcode()); | 
|---|
|  |  |  | boolean res = taskService.save(task); | 
|---|
|  |  |  | if (!res) { | 
|---|
|  |  |  | throw new CoolException("保存工作档失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 工作档明细保存 | 
|---|
|  |  |  | for (LocDetl locDetl : locDetls) { | 
|---|
|  |  |  | TaskDetl taskDetl = new TaskDetl(); | 
|---|
|  |  |  | taskDetl.sync(locDetl); | 
|---|
|  |  |  | taskDetl.setTaskId(task.getId()); | 
|---|
|  |  |  | if (!taskDetlService.save(taskDetl)) { | 
|---|
|  |  |  | throw new CoolException("保存工作档明细失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 修改源库位状态 | 
|---|
|  |  |  | if (sourceLoc.getLocStsId$().equals("D") || sourceLoc.getLocStsId$().equals("F")) { | 
|---|
|  |  |  | sourceLoc.setLocStsId(LocStsType.R.val()); // R.出库预约 | 
|---|
|  |  |  | if (!locService.updateById(sourceLoc)) { | 
|---|
|  |  |  | throw new CoolException("更新源库位状态失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | throw new CoolException("源库位出库失败,状态:" + sourceLoc.getLocStsId$()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 修改目标库位状态 | 
|---|
|  |  |  | if (loc.getLocStsId$().equals("O")) { | 
|---|
|  |  |  | loc.setLocStsId(LocStsType.S.val()); // S.入库预约 | 
|---|
|  |  |  | if (!locService.updateById(loc)) { | 
|---|
|  |  |  | throw new CoolException("更新目标库位状态失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | throw new CoolException("移转失败,目标库位状态:" + loc.getLocStsId$()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|