| | |
| | | import com.vincent.rsf.server.manager.enums.LocStsType; |
| | | import com.vincent.rsf.server.system.utils.SerialRuleUtils; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import lombok.val; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | |
| | | log.warn("[RCS入库申请-自动组托] 入库单编码规则未配置"); |
| | | return; |
| | | } |
| | | // val orderWorkTypeOtherIn = OrderWorkType.ORDER_WORK_TYPE_OTHER_IN.type; |
| | | // .setWkType(orderWorkTypeOtherIn) |
| | | WkOrder order = new WkOrder(); |
| | | order.setCode(ruleCode) |
| | | .setType(OrderType.ORDER_IN.type) |
| | |
| | | */ |
| | | private Task createTask(String ruleCode, String targetLoc, String barcode, |
| | | String targetSite, String sourceSiteNo, Long loginUserId) { |
| | | return createTask(ruleCode, targetLoc, barcode, targetSite, sourceSiteNo, loginUserId, TaskType.TASK_TYPE_IN.type); |
| | | } |
| | | |
| | | /** |
| | | * 创建并保存任务(支持指定任务类型,如空板入库) |
| | | */ |
| | | private Task createTask(String ruleCode, String targetLoc, String barcode, |
| | | String targetSite, String sourceSiteNo, Long loginUserId, Integer taskType) { |
| | | Task task = new Task(); |
| | | task.setTaskCode(ruleCode) |
| | | .setTaskStatus(TaskStsType.GENERATE_IN.id) |
| | | .setTaskType(TaskType.TASK_TYPE_IN.type) |
| | | .setTaskType(taskType != null ? taskType : TaskType.TASK_TYPE_IN.type) |
| | | .setWarehType(WarehType.WAREHOUSE_TYPE_CRN.val) |
| | | .setTargLoc(targetLoc) |
| | | .setBarcode(barcode) |
| | |
| | | if (!updated) { |
| | | throw new CoolException("库位预约失败!!"); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 空板入库:RCS 申请时 full=true,无需组托,分配库位并创建 TASK_TYPE_EMPITY_IN 任务。 |
| | | * 需在设备站点中配置 type=10(空板入库)的站点路径。 |
| | | */ |
| | | private InTaskMsgDto createInTaskForEmptyPallet(String barcode, String staNo, Integer type) { |
| | | TaskInParam param = new TaskInParam(); |
| | | param.setBarcode(barcode); |
| | | param.setSourceStaNo(staNo); |
| | | param.setLocType1(type != null ? type : 1); |
| | | param.setIoType(TaskType.TASK_TYPE_EMPITY_IN.type); |
| | | param.setUser(1L); |
| | | |
| | | // 校验设备站点(需配置 type=10 空板入库的站点) |
| | | DeviceSite deviceSite = validateDeviceSite(param); |
| | | |
| | | // 检查该托盘号是否已有空板入库任务,有则复用 |
| | | Task existingInTask = taskService.getOne(new LambdaQueryWrapper<Task>() |
| | | .eq(Task::getBarcode, barcode) |
| | | .eq(Task::getTaskType, TaskType.TASK_TYPE_EMPITY_IN.type) |
| | | .orderByDesc(Task::getCreateTime) |
| | | .last("LIMIT 1")); |
| | | if (existingInTask != null) { |
| | | log.info("找到该托盘号已有空板入库任务,复用 - 任务编码:{},箱号:{}", existingInTask.getTaskCode(), barcode); |
| | | if (StringUtils.isNotBlank(staNo) && !staNo.equals(existingInTask.getOrgSite())) { |
| | | existingInTask.setOrgSite(staNo); |
| | | taskService.updateById(existingInTask); |
| | | } |
| | | InTaskMsgDto msgDto = new InTaskMsgDto(); |
| | | msgDto.setWorkNo(existingInTask.getTaskCode()); |
| | | msgDto.setTaskId(existingInTask.getId()); |
| | | msgDto.setLocNo(existingInTask.getTargLoc()); |
| | | msgDto.setSourceStaNo(existingInTask.getOrgSite()); |
| | | msgDto.setStaNo(existingInTask.getTargSite()); |
| | | return msgDto; |
| | | } |
| | | |
| | | // 该托盘已在库或出库中,不可重复申请空板入库 |
| | | List<Loc> inStock = locService.list(new LambdaQueryWrapper<Loc>().eq(Loc::getBarcode, barcode)); |
| | | if (!inStock.isEmpty()) { |
| | | throw new CoolException("barcode=" + barcode + ": 该托盘已在库,不可重复申请入库"); |
| | | } |
| | | Task outboundTask = taskService.getOne(new LambdaQueryWrapper<Task>() |
| | | .eq(Task::getBarcode, barcode) |
| | | .in(Task::getTaskType, Arrays.asList(TaskType.TASK_TYPE_OUT.type, TaskType.TASK_TYPE_EMPITY_OUT.type, |
| | | TaskType.TASK_TYPE_PICK_AGAIN_OUT.type, TaskType.TASK_TYPE_CHECK_OUT.type)) |
| | | .lt(Task::getTaskStatus, TaskStsType.COMPLETE_OUT.id)); |
| | | if (outboundTask != null) { |
| | | throw new CoolException("barcode=" + barcode + ": 该托盘出库中未完成,不可申请入库"); |
| | | } |
| | | |
| | | InTaskMsgDto locNo; |
| | | try { |
| | | locNo = getLocNo(param); |
| | | } catch (Exception e) { |
| | | throw new CoolException("获取空板入库库位失败:" + e.getMessage()); |
| | | } |
| | | if (locNo == null || StringUtils.isBlank(locNo.getLocNo())) { |
| | | throw new CoolException("未找到可用的空库位,请检查库区与设备站点配置(空板入库需配置 type=10 的站点)"); |
| | | } |
| | | String ruleCode = generateTaskCode(); |
| | | String targetSite = StringUtils.isNotBlank(deviceSite.getDeviceSite()) ? deviceSite.getDeviceSite() : staNo; |
| | | Task task = createTask(ruleCode, locNo.getLocNo(), barcode, targetSite, staNo, param.getUser(), TaskType.TASK_TYPE_EMPITY_IN.type); |
| | | updateLocStatus(task.getTargLoc(), barcode); |
| | | locNo.setWorkNo(ruleCode); |
| | | locNo.setTaskId(task.getId()); |
| | | log.info("[空板入库] 已创建任务: {}, 库位: {}, 料箱: {}", ruleCode, locNo.getLocNo(), barcode); |
| | | return locNo; |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public R allocateLocation(String barcode, String staNo, Integer type) { |
| | | public R allocateLocation(String barcode, String staNo, Integer type, Boolean full) { |
| | | log.info("========== 开始申请入库任务,分配库位 =========="); |
| | | log.info("料箱码:{},入库站点:{},入库类型:{}", barcode, staNo, type); |
| | | log.info("料箱码:{},入库站点:{},入库类型:{},空板:{}", barcode, staNo, type, full); |
| | | |
| | | // full=true 时走空板入库(无需组托);否则走普通入库(需组托或自动组托) |
| | | if (Boolean.TRUE.equals(full)) { |
| | | InTaskMsgDto msgDto = createInTaskForEmptyPallet(barcode, staNo, type); |
| | | JSONObject result = new JSONObject(); |
| | | result.put("locNo", msgDto.getLocNo()); |
| | | result.put("batchNo", msgDto.getWorkNo()); |
| | | result.put("taskNo", msgDto.getWorkNo()); |
| | | return R.ok(result); |
| | | } |
| | | |
| | | // 构建 TaskInParam 参数,与 /wcs/create/in/task 接口参数一致 |
| | | TaskInParam param = new TaskInParam(); |