| | |
| | | import com.vincent.rsf.server.system.constant.SerialRuleCode; |
| | | import com.vincent.rsf.server.system.utils.SerialRuleUtils; |
| | | import lombok.Synchronized; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | |
| | | |
| | | /** |
| | | * 库存出库生成出库任务 |
| | | * type: check 盘点, stock: 库存出库 |
| | | * |
| | | * @param map |
| | | * @return |
| | |
| | | @Synchronized |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public R generateTask(Map<String, Object> map) { |
| | | String type; |
| | | if (!Objects.isNull(map.get("type")) && StringUtils.isNotBlank(map.get("type").toString())) { |
| | | type = map.get("type").toString(); |
| | | } else { |
| | | type = "stock"; |
| | | } |
| | | if (Objects.isNull(map.get("siteNo"))) { |
| | | throw new CoolException("站点不能为空!"); |
| | | } |
| | |
| | | List<LocItem> locItemList = listMap.get(key); |
| | | Double outQty = locItemList.stream().mapToDouble(LocItem::getOutQty).sum(); |
| | | |
| | | |
| | | Task serviceOne = taskService.getOne(new LambdaQueryWrapper<Task>().eq(Task::getBarcode, loc.getBarcode())); |
| | | if (!Objects.isNull(serviceOne)) { |
| | | throw new CoolException("托盘任务执行中,不能重复创建!"); |
| | | } |
| | | Double useQty = Math.round((outQty + workQty) * 10000) / 10000.0; |
| | | if (orgQty.compareTo(useQty) > 0) { |
| | | //拣料出库 |
| | | task.setTaskType(TaskType.TASK_TYPE_PICK_AGAIN_IN.type); |
| | | } else { |
| | | //全板出库 |
| | | task.setTaskType(TaskType.TASK_TYPE_OUT.type); |
| | | |
| | | if (type.equals("stock")) { |
| | | Double useQty = Math.round((outQty + workQty) * 10000) / 10000.0; |
| | | if (orgQty.compareTo(useQty) > 0) { |
| | | //拣料出库 |
| | | task.setTaskType(TaskType.TASK_TYPE_PICK_AGAIN_OUT.type); |
| | | } else { |
| | | //全板出库 |
| | | task.setTaskType(TaskType.TASK_TYPE_OUT.type); |
| | | } |
| | | } else if (type.equals("check")) { |
| | | //盘点出库 |
| | | task.setTaskType(TaskType.TASK_TYPE_CHECK_OUT.type); |
| | | } |
| | | |
| | | if (!taskService.save(task)) { |
| | | throw new CoolException("任务创建失败!!"); |
| | | } |
| | |
| | | } else { |
| | | item.setWorkQty(qty); |
| | | } |
| | | if (! locItemService.updateById(item)) { |
| | | if (!locItemService.updateById(item)) { |
| | | throw new CoolException("库存信息修改失败!!"); |
| | | } |
| | | }); |
| | |
| | | |
| | | return R.ok("任务生成完成!!"); |
| | | } |
| | | |
| | | /** |
| | | * 生成移库任务 |
| | | * @param map |
| | | * @return |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public R genMoveTask(Map<String, Object> map) { |
| | | if (Objects.isNull(map.get("tarLoc")) || StringUtils.isBlank(map.get("tarLoc").toString())) { |
| | | throw new CoolException("目标库位不能为空!"); |
| | | } |
| | | if (Objects.isNull(map.get("orgLoc")) || StringUtils.isBlank(map.get("orgLoc").toString())) { |
| | | throw new CoolException("源库位不能为空!"); |
| | | } |
| | | |
| | | Loc orgLoc = locService.getOne(new LambdaQueryWrapper<Loc>().eq(Loc::getCode, map.get("orgLoc"))); |
| | | if (Objects.isNull(orgLoc)) { |
| | | throw new CoolException("源库位不存在!!"); |
| | | } |
| | | |
| | | orgLoc.setUseStatus(LocStsType.LOC_STS_TYPE_R.type); |
| | | |
| | | if (!locService.updateById(orgLoc)) { |
| | | throw new CoolException("目标库位预约失败!!"); |
| | | } |
| | | |
| | | |
| | | Loc targetLoc = locService.getOne(new LambdaQueryWrapper<Loc>().eq(Loc::getCode, map.get("tarLoc").toString())); |
| | | if (Objects.isNull(targetLoc)) { |
| | | throw new CoolException("目标库位不存在!!"); |
| | | } |
| | | |
| | | targetLoc.setUseStatus(LocStsType.LOC_STS_TYPE_S.type); |
| | | |
| | | if (!locService.updateById(targetLoc)) { |
| | | throw new CoolException("目标库位预约失败!!"); |
| | | } |
| | | |
| | | String ruleCode = SerialRuleUtils.generateRuleCode(SerialRuleCode.SYS_TASK_CODE, null); |
| | | Task task = new Task(); |
| | | task.setOrgLoc(orgLoc.getCode()) |
| | | .setTaskCode(ruleCode) |
| | | .setTaskType(TaskType.TASK_TYPE_LOC_MOVE.type) |
| | | .setTargLoc(targetLoc.getCode()) |
| | | .setTaskStatus(TaskStsType.GENERATE_IN.id) |
| | | .setBarcode(orgLoc.getBarcode()); |
| | | |
| | | if (!taskService.save(task)) { |
| | | throw new CoolException("新建移库任务失败!!"); |
| | | } |
| | | |
| | | List<LocItem> locItems = locItemService.list(new LambdaQueryWrapper<LocItem>().eq(LocItem::getLocId, orgLoc.getId())); |
| | | if (locItems.isEmpty()) { |
| | | throw new CoolException("库位明细不存在!!"); |
| | | } |
| | | |
| | | List<TaskItem> taskItems = new ArrayList<>(); |
| | | for (LocItem item : locItems) { |
| | | TaskItem taskItem = new TaskItem(); |
| | | BeanUtils.copyProperties(item, taskItem); |
| | | taskItem.setTaskId(task.getId()) |
| | | .setAnfme(item.getAnfme()) |
| | | .setBatch(item.getBatch()) |
| | | .setOrderType(OrderType.ORDER_IN.type) |
| | | .setWkType(Short.parseShort(OrderWorkType.ORDER_WORK_TYPE_OTHER_IN.type)); |
| | | taskItems.add(taskItem); |
| | | } |
| | | if (!taskItemService.saveBatch(taskItems)) { |
| | | throw new CoolException("任务明细生成失败!!"); |
| | | } |
| | | |
| | | return R.ok(task); |
| | | } |
| | | |
| | | } |