| | |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
| | | import com.vincent.rsf.framework.common.Cools; |
| | | import com.vincent.rsf.server.api.entity.enums.OrderType; |
| | | import com.vincent.rsf.server.api.entity.enums.TaskStsType; |
| | | import com.vincent.rsf.framework.common.R; |
| | | import com.vincent.rsf.framework.exception.CoolException; |
| | | import com.vincent.rsf.server.api.entity.enums.TaskType; |
| | | import com.vincent.rsf.server.api.utils.LocUtils; |
| | | import com.vincent.rsf.server.manager.controller.params.GenerateTaskParams; |
| | | import com.vincent.rsf.server.manager.entity.*; |
| | | import com.vincent.rsf.server.manager.enums.PakinIOStatus; |
| | |
| | | private StockItemService stockItemService; |
| | | @Autowired |
| | | private DeviceSiteService deviceSiteService; |
| | | |
| | | @Autowired |
| | | private OrderService orderService; |
| | | |
| | | @Autowired |
| | | private OrderItemService orderItemService; |
| | | |
| | | @Autowired |
| | | private LocItemService locItemService; |
| | | @Autowired |
| | | private DeviceBindService deviceBindService; |
| | | @Autowired |
| | | private WarehouseAreasService warehouseAreasService; |
| | | |
| | | @Autowired |
| | | private WarehouseAreasItemService warehouseAreasItemService; |
| | | |
| | | |
| | | /** |
| | |
| | | if (Objects.isNull(deviceSite)) { |
| | | throw new CoolException("站点不存在!!"); |
| | | } |
| | | DeviceBind deviceBind = deviceBindService.getById(LocUtils.getAreaType(Integer.valueOf(deviceSite.getSite()))); |
| | | if (Cools.isEmpty(deviceBind)) { |
| | | throw new CoolException("库位规则未知"); |
| | | } |
| | | WarehouseAreas warehouseArea = warehouseAreasService.getById(deviceBind.getTypeId()); |
| | | if (Cools.isEmpty(warehouseArea)) { |
| | | throw new CoolException("未找到所属库区信息"); |
| | | } |
| | | |
| | | /**获取组拖*/ |
| | | List<Long> ids = waitPakin.getWaitPakins().stream().map(WaitPakin::getId).collect(Collectors.toList()); |
| | | List<WaitPakin> waitPakins = waitPakinService.list(new LambdaQueryWrapper<WaitPakin>() |
| | |
| | | throw new CoolException("请检查组拖状态是否完成!!"); |
| | | } |
| | | waitPakins.forEach(pakin -> { |
| | | /**获取库位*/ |
| | | String targetLoc = LocManageUtil.getTargetLoc(warehouseArea.getId()); |
| | | if (Cools.isEmpty(targetLoc)) { |
| | | throw new CoolException("该站点对应库区未找到库位"); |
| | | } |
| | | |
| | | List<TaskItem> taskItems = new ArrayList<>(); |
| | | String ruleCode = SerialRuleUtils.generateRuleCode(SerialRuleCode.SYS_TASK_CODE, null); |
| | | if (StringUtils.isBlank(ruleCode)) { |
| | |
| | | task.setTaskCode(ruleCode) |
| | | .setTaskStatus(TaskStsType.GENERATE_IN.id.shortValue()) |
| | | .setTaskType(TaskType.TASK_TYPE_IN.type.shortValue()) |
| | | .setTargLoc(LocManageUtil.getTargetLoc()) |
| | | .setTargLoc(targetLoc) |
| | | .setBarcode(pakin.getBarcode()) |
| | | .setTargSite(deviceSite.getDeviceCode()) |
| | | .setOrgSite(deviceSite.getSite()) |
| | | .setTargSite(deviceSite.getDeviceSite()) |
| | | .setCreateBy(loginUserId) |
| | | .setUpdateBy(loginUserId); |
| | | |
| | | if (!Objects.isNull(waitPakin.getSiteId()) && waitPakin.getSiteId() > 0) { |
| | | DeviceSite site = deviceSiteService.getById(waitPakin.getSiteId()); |
| | | task.setTargSite(site.getSite() + ""); |
| | | } else { |
| | | task.setTargSite(LocManageUtil.getTargetSite()); |
| | | } |
| | | if (!Objects.isNull(waitPakin.getLocCode()) && StringUtils.isNotBlank(waitPakin.getLocCode())) { |
| | | List<Loc> locs = locService.list(new LambdaQueryWrapper<Loc>().eq(Loc::getCode, waitPakin.getLocCode())); |
| | | // if (!locs.isEmpty()) { |
| | | // throw new CoolException("库位错误:相同库位应只一条") |
| | | // } |
| | | Loc loc = locs.stream().findFirst().get(); |
| | | task.setTargSite(loc.getCode()); |
| | | } else { |
| | | task.setTargSite(LocManageUtil.getTargetSite()); |
| | | } |
| | | // if (!Objects.isNull(waitPakin.getSiteId()) && waitPakin.getSiteId() > 0) { |
| | | // DeviceSite site = deviceSiteService.getById(waitPakin.getSiteId()); |
| | | // task.setTargSite(site.getSite() + ""); |
| | | // } else { |
| | | // task.setTargSite(LocManageUtil.getTargetSite()); |
| | | // } |
| | | // if (!Objects.isNull(waitPakin.getLocCode()) && StringUtils.isNotBlank(waitPakin.getLocCode())) { |
| | | // List<Loc> locs = locService.list(new LambdaQueryWrapper<Loc>().eq(Loc::getCode, waitPakin.getLocCode())); |
| | | //// if (!locs.isEmpty()) { |
| | | //// throw new CoolException("库位错误:相同库位应只一条") |
| | | //// } |
| | | // Loc loc = locs.stream().findFirst().get(); |
| | | // task.setTargSite(loc.getCode()); |
| | | // } else { |
| | | // task.setTargSite(LocManageUtil.getTargetSite()); |
| | | // } |
| | | |
| | | if (!this.save(task)) { |
| | | throw new CoolException("任务保存失败!!"); |
| | |
| | | if (!taskItemService.saveBatch(taskItems)) { |
| | | throw new CoolException("任务明细保存失败!!"); |
| | | } |
| | | waitPakinItems.forEach(item -> { |
| | | if (! waitPakinItemService.update(new LambdaUpdateWrapper<WaitPakinItem>() |
| | | .set(WaitPakinItem::getWorkQty, item.getAnfme()) |
| | | .eq(WaitPakinItem::getId, item.getId()))) { |
| | | throw new CoolException("组托明细修执行数量修改失败!!"); |
| | | } |
| | | }); |
| | | }); |
| | | |
| | | if (!waitPakinService.update(new LambdaUpdateWrapper<WaitPakin>() |
| | |
| | | /**对任务明细按任务主单进行分组*/ |
| | | listMap.keySet().forEach(key -> { |
| | | List<TaskItem> items = listMap.get(key); |
| | | //更新库位明细 |
| | | try { |
| | | //更新库位明细 |
| | | saveLocItem(items, key); |
| | | } catch (Exception e) { |
| | | throw new CoolException("库位明细更新失败!!"); |
| | |
| | | throw new CoolException("数据错误:组拖数据不存在,请联系管理员!!"); |
| | | } |
| | | List<TaskItem> items = orderMap.get(key); |
| | | //保存库存明细 |
| | | try { |
| | | //保存库存明细 |
| | | saveStockItems(items, pakinItem); |
| | | //移出收货区库存, 修改组托状态 |
| | | removeReceiptStock(pakinItem); |
| | | } catch (Exception e) { |
| | | throw new CoolException("库存管理保存更新失败!!"); |
| | | } |
| | |
| | | if (!locService.update(new LambdaUpdateWrapper<Loc>().set(Loc::getUseStatus, LocStsType.LOC_STS_TYPE_F.type).in(Loc::getCode, locCodes))) { |
| | | throw new CoolException("库位状态修改失败!!"); |
| | | } |
| | | if (!this.update(new LambdaUpdateWrapper<Task>().set(Task::getTaskStatus, TaskStsType.UPDATED_IN.id))) { |
| | | if (!this.update(new LambdaUpdateWrapper<Task>().in(Task::getId, list).set(Task::getTaskStatus, TaskStsType.UPDATED_IN.id))) { |
| | | throw new CoolException("任务状态修改失败!!"); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * @author Ryan |
| | | * @description 移除收货区库存 |
| | | * @param |
| | | * @return |
| | | * @time 2025/4/30 16:32 |
| | | */ |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void removeReceiptStock(WaitPakinItem pakinItem) { |
| | | WarehouseAreasItem itemServiceOne = warehouseAreasItemService.getOne(new LambdaQueryWrapper<WarehouseAreasItem>() |
| | | .eq(WarehouseAreasItem::getTrackCode, pakinItem.getTrackCode()) |
| | | .eq(WarehouseAreasItem::getSplrBatch, pakinItem.getBatch())); |
| | | if (Objects.isNull(itemServiceOne)) { |
| | | throw new CoolException("数据错误,请查看请货区库存是否存在!!"); |
| | | } |
| | | Double workQty = itemServiceOne.getWorkQty() - pakinItem.getAnfme(); |
| | | Double qty = itemServiceOne.getQty() + pakinItem.getAnfme(); |
| | | itemServiceOne.setWorkQty(workQty).setQty(qty); |
| | | |
| | | if (!waitPakinService.update(new LambdaUpdateWrapper<WaitPakin>() |
| | | .set(WaitPakin::getIoStatus, PakinIOStatus.PAKIN_IO_STATUS_TASK_DONE.val) |
| | | .eq(WaitPakin::getId, pakinItem.getPakinId()))) { |
| | | throw new CoolException("组拖状态修改失败!!"); |
| | | } |
| | | |
| | | if (qty.compareTo(itemServiceOne.getAnfme()) == 0.00) { |
| | | if (!warehouseAreasItemService.removeById(itemServiceOne.getId())) { |
| | | throw new CoolException("收货区物料删除失败!!"); |
| | | } |
| | | } else { |
| | | if (!warehouseAreasItemService.updateById(itemServiceOne)) { |
| | | throw new CoolException("收货区库完成数量修改失败!!"); |
| | | } |
| | | } |
| | | } |
| | | |
| | |
| | | * @time 2025/4/15 15:28 |
| | | */ |
| | | @Transactional(rollbackFor = Exception.class) |
| | | void saveLocItem(List<TaskItem> items, Long taskId) throws Exception { |
| | | public void saveLocItem(List<TaskItem> items, Long taskId) throws Exception { |
| | | Task task = this.getById(taskId); |
| | | if (Objects.isNull(task)) { |
| | | throw new CoolException("任务不存在!!"); |
| | |
| | | Loc loc = locService.getOne(new LambdaQueryWrapper<Loc>().eq(Loc::getCode, task.getTargLoc()), false); |
| | | LocItem item = new LocItem(); |
| | | BeanUtils.copyProperties(taskItem, item); |
| | | item.setLocId(loc.getId()).setType(taskItem.getOrderType()); |
| | | item.setLocCode(loc.getCode()).setId(null) |
| | | .setLocId(loc.getId()) |
| | | .setWkType(taskItem.getWkType()) |
| | | .setType(taskItem.getOrderType()); |
| | | locItems.add(item); |
| | | }); |
| | | if (!locItemService.saveBatch(locItems)) { |
| | |
| | | * @return |
| | | */ |
| | | @Transactional(rollbackFor = Exception.class) |
| | | void saveStockItems(List<TaskItem> items, WaitPakinItem order) throws Exception { |
| | | public void saveStockItems(List<TaskItem> items, WaitPakinItem order) throws Exception { |
| | | Stock stock = new Stock(); |
| | | // if (!Objects.isNull(order.getPoCode()) && StringUtils.isNotBlank(order.getPoCode())) { |
| | | // Purchase purchase = purchaseService.getOne(new LambdaQueryWrapper<Purchase>().eq(Purchase::getCode, order.getPoCode())); |