| | |
| | | import java.math.BigDecimal; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | import java.util.Date; |
| | | |
| | | @Service |
| | | public class PdaOutStockServiceImpl implements PdaOutStockService { |
| | |
| | | if (null == task) { |
| | | throw new CoolException("未找到容器号对应任务"); |
| | | } |
| | | if (!task.getTaskStatus().equals(TaskStsType.AWAIT.id)) { |
| | | if (!task.getTaskStatus().equals(TaskStsType.WAVE_SEED.id)) { |
| | | return R.error("任务状态不是等待确认"); |
| | | } |
| | | List<TaskItem> taskItems = taskItemService.list(new LambdaQueryWrapper<TaskItem>().eq(TaskItem::getTaskId, task.getId())); |
| | |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public R wavePickItems(WavePickItemsParams params) { |
| | | public synchronized R wavePickItems(WavePickItemsParams params) { |
| | | if (Objects.isNull(params.getBarcode())) { |
| | | return R.error("托盘码不能为空!!"); |
| | | } |
| | |
| | | //taskItems为拣货明细,作参数上报 |
| | | Double summed = items.stream().mapToDouble(TaskItem::getAnfme).sum(); |
| | | //加上历史拣料数量 |
| | | Double pickQty = Math.round((orderItem.getQty() + summed) * 100) / 100.0; |
| | | Double pickQty = Math.round((orderItem.getQty() + summed) * 1000000) / 1000000.0; |
| | | Config config = configService.getOne(new LambdaQueryWrapper<Config>().eq(Config::getFlag, GlobalConfigCode.ALLOW_OVER_CHANGE)); |
| | | //判断是否允许超收,不允许超收添加拒收判断 |
| | | if (!Objects.isNull(config)) { |
| | |
| | | TaskItem item = taskItemService.getById(taskItem.getId()); |
| | | //判断是否允许超收,不允许超收添加拒收判断 |
| | | if (!Objects.isNull(config)) { |
| | | LocItemWorking serviceOne = locItemWorkingService.getOne(new LambdaQueryWrapper<LocItemWorking>().eq(LocItemWorking::getFieldsIndex, item.getFieldsIndex())); |
| | | TaskItem serviceOne = taskItemService.getOne(new LambdaQueryWrapper<TaskItem>() |
| | | .eq(TaskItem::getTaskId, task.getId()) |
| | | .eq(TaskItem::getFieldsIndex, item.getFieldsIndex())); |
| | | if (Objects.isNull(serviceOne)) { |
| | | throw new CoolException("缓存数据丢失!!"); |
| | | } |
| | | LocItemWorking workItem = locItemWorkingService.getOne(new LambdaQueryWrapper<LocItemWorking>() |
| | | .eq(LocItemWorking::getTaskId, task.getId()) |
| | | .eq(LocItemWorking::getFieldsIndex, item.getFieldsIndex())); |
| | | if (Objects.isNull(workItem)) { |
| | | throw new CoolException("缓存数据丢失!!"); |
| | | } |
| | | Double v1 = Math.round((workItem.getAnfme() - serviceOne.getQty()) * 1000000) / 1000000.0; |
| | | //不管是否允许超收,都需判断是否超出库存范围 |
| | | if (taskItem.getAnfme().compareTo(serviceOne.getAnfme()) > 0) { |
| | | if (taskItem.getAnfme().compareTo(v1) > 0) { |
| | | throw new CoolException("拣货数量超出当前票号库存数量!!"); |
| | | } |
| | | if (!Boolean.parseBoolean(config.getVal())) { |
| | | if (item.getAnfme().compareTo(item.getQty() + taskItem.getAnfme()) < 0.0) { |
| | | Double v = Math.round((item.getQty() + taskItem.getAnfme()) * 1000000) / 1000000.0; |
| | | if (item.getAnfme().compareTo(v) < 0.0) { |
| | | throw new CoolException("前当物料已超出可拣范围,请核对后再操作!!"); |
| | | } |
| | | } |
| | | } |
| | | |
| | | Double picQty = Math.round((item.getQty() + taskItem.getAnfme()) * 100) / 100.0; |
| | | Double picQty = Math.round((item.getQty() + taskItem.getAnfme()) * 1000000) / 1000000.0; |
| | | item.setQty(picQty).setOrderId(order.getId()).setOrderItemId(orderItem.getId()); |
| | | if (!taskItemService.updateById(item)) { |
| | | throw new CoolException("状态完成失败!!"); |
| | | } |
| | | |
| | | // 扣减库位明细库存(与出库完成逻辑保持一致) |
| | | if (StringUtils.isNotBlank(task.getOrgLoc())) { |
| | | LocItem locItem = locItemService.getOne(new LambdaQueryWrapper<LocItem>() |
| | | .eq(LocItem::getLocCode, task.getOrgLoc()) |
| | | .eq(LocItem::getMatnrId, item.getMatnrId()) |
| | | .eq(StringUtils.isNotBlank(item.getBatch()), LocItem::getBatch, item.getBatch()) |
| | | .eq(StringUtils.isNotBlank(item.getFieldsIndex()), LocItem::getFieldsIndex, item.getFieldsIndex())); |
| | | |
| | | if (Objects.nonNull(locItem)) { |
| | | // 使用实际拣货数量(taskItem.getAnfme())扣减库位明细 |
| | | Double newAnfme = Math.round((locItem.getAnfme() - taskItem.getAnfme()) * 1000000) / 1000000.0; |
| | | |
| | | if (newAnfme.compareTo(0.0) <= 0) { |
| | | // 数量小于等于0,删除库位明细 |
| | | locItemService.removeById(locItem.getId()); |
| | | } else { |
| | | // 更新库位明细数量 |
| | | locItem.setAnfme(newAnfme) |
| | | .setUpdateBy(SystemAuthUtils.getLoginUserId()) |
| | | .setUpdateTime(new Date()); |
| | | if (!locItemService.updateById(locItem)) { |
| | | throw new CoolException("库位明细数量扣减失败!!"); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | StockItem stockItem = new StockItem(); |
| | | BeanUtils.copyProperties(item, stockItem); |
| | | //taskItem为上报数据 |
| | |
| | | List<WkOrderItem> orderItems = asnOrderItemService.list(new LambdaQueryWrapper<WkOrderItem>().eq(WkOrderItem::getOrderId, params.getOrderId())); |
| | | Double total = orderItems.stream().mapToDouble(WkOrderItem::getQty).sum(); |
| | | Double wkQty = orderItems.stream().mapToDouble(WkOrderItem::getWorkQty).sum(); |
| | | double v = order.getWorkQty().compareTo(wkQty) < 0 ? 0.0 : Math.round((total - wkQty) * 100) / 100.0; |
| | | double v = order.getWorkQty().compareTo(wkQty) < 0 ? 0.0 : Math.round((total - wkQty) * 1000000) / 1000000.0; |
| | | order.setQty(total).setWorkQty(v); |
| | | if (!asnOrderService.updateById(order)) { |
| | | throw new CoolException("订单数量更新失败!!"); |
| | |
| | | throw new CoolException("任务明细修改失败"); |
| | | } |
| | | LocItemWorking oldOne = locItemWorkingService.getOne(new LambdaQueryWrapper<LocItemWorking>() |
| | | .eq(LocItemWorking::getTaskId, byId.getTaskId()) |
| | | .eq(LocItemWorking::getMatnrCode, byId.getMatnrCode()) |
| | | .eq(LocItemWorking::getFieldsIndex, byId.getFieldsIndex())); |
| | | if (Objects.isNull(oldOne)) { |
| | | throw new CoolException("明细不存在或已出库!!"); |
| | | } |
| | | LocItemWorking one = locItemWorkingService.getOne(new LambdaQueryWrapper<LocItemWorking>() |
| | | .eq(LocItemWorking::getMatnrCode, byId.getMatnrCode()) |
| | | .eq(LocItemWorking::getTaskId, byId.getTaskId()) |
| | | .eq(LocItemWorking::getMatnrCode, byId.getMatnrCode()) |
| | | .eq(LocItemWorking::getFieldsIndex, uuid)); |
| | | if (Objects.isNull(one)) { |
| | | throw new CoolException("明细不存在或已出库!!"); |