| | |
| | | import com.vincent.rsf.server.system.service.impl.FieldsItemServiceImpl; |
| | | import com.vincent.rsf.server.system.service.impl.UserServiceImpl; |
| | | import com.vincent.rsf.server.system.utils.SerialRuleUtils; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @Service |
| | | public class PdaCheckOrderServiceImpl implements PdaCheckOrderService { |
| | |
| | | @Autowired |
| | | private UserService userService; |
| | | |
| | | @Autowired |
| | | private CheckOrderItemService checkOrderItemService; |
| | | |
| | | @Autowired |
| | | private CheckOrderService checkOrderService; |
| | | |
| | | |
| | | @Override |
| | | public R getCheckList(String code) { |
| | |
| | | lambdaQueryWrapper.eq(Task::getBarcode, barcode); |
| | | Task task = taskService.getOne(lambdaQueryWrapper); |
| | | if (null == task) { |
| | | throw new CoolException("未找到容器号对应任务"); |
| | | throw new CoolException("未找到料箱码对应任务"); |
| | | } |
| | | if (!task.getTaskStatus().equals(TaskStsType.AWAIT.id)) { |
| | | return R.error("任务状态不是等待确认"); |
| | |
| | | } |
| | | Task task = taskService.getOne(new LambdaQueryWrapper<Task>().eq(Task::getBarcode, params.getContainer())); |
| | | if (null == task) { |
| | | throw new CoolException("数据错误,未找到容器码对应盘点任务"); |
| | | throw new CoolException("数据错误,未找到料箱码对应盘点任务"); |
| | | } |
| | | for (CheckDiffItem ckDiffItem : params.getCheckDiffItems()) { |
| | | CheckDiffItem diffItem = new CheckDiffItem(); |
| | |
| | | throw new CoolException("更新差异单失败"); |
| | | } |
| | | |
| | | // 按盘点单明细汇总实盘数量并回写 |
| | | Set<Long> taskItemIds = diffItems.stream().map(CheckDiffItem::getTaskItemId).filter(Objects::nonNull).collect(Collectors.toSet()); |
| | | if (!taskItemIds.isEmpty()) { |
| | | List<TaskItem> taskItems = taskItemService.listByIds(taskItemIds); |
| | | Map<Long, BigDecimal> orderItemIdToCheckQty = new HashMap<>(); |
| | | for (CheckDiffItem di : diffItems) { |
| | | if (di.getTaskItemId() == null) { |
| | | continue; |
| | | } |
| | | TaskItem ti = taskItems.stream().filter(t -> t.getId().equals(di.getTaskItemId())).findFirst().orElse(null); |
| | | if (ti == null || ti.getOrderItemId() == null) { |
| | | continue; |
| | | } |
| | | Double cq = di.getCheckQty() != null ? di.getCheckQty() : 0.0; |
| | | orderItemIdToCheckQty.merge(ti.getOrderItemId(), BigDecimal.valueOf(cq), BigDecimal::add); |
| | | } |
| | | for (Map.Entry<Long, BigDecimal> e : orderItemIdToCheckQty.entrySet()) { |
| | | double workQty = e.getValue().setScale(6, RoundingMode.HALF_UP).doubleValue(); |
| | | if (!checkOrderItemService.update(new LambdaUpdateWrapper<WkOrderItem>() |
| | | .eq(WkOrderItem::getId, e.getKey()) |
| | | .set(WkOrderItem::getWorkQty, workQty))) { |
| | | throw new CoolException("盘点单明细实盘数量更新失败"); |
| | | } |
| | | } |
| | | if (checkDiff.getOrderId() != null) { |
| | | List<WkOrderItem> orderItems = checkOrderItemService.list(new LambdaQueryWrapper<WkOrderItem>().eq(WkOrderItem::getOrderId, checkDiff.getOrderId())); |
| | | BigDecimal orderWorkQty = orderItems.stream() |
| | | .map(oi -> oi.getWorkQty() != null ? BigDecimal.valueOf(oi.getWorkQty()) : BigDecimal.ZERO) |
| | | .reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | if (!checkOrderService.update(new LambdaUpdateWrapper<WkOrder>() |
| | | .eq(WkOrder::getId, checkDiff.getOrderId()) |
| | | .set(WkOrder::getWorkQty, orderWorkQty.setScale(6, RoundingMode.HALF_UP).doubleValue()))) { |
| | | throw new CoolException("盘点单主表实盘数量更新失败"); |
| | | } |
| | | } |
| | | } |
| | | |
| | | task.setTaskStatus(TaskStsType.COMPLETE_OUT.id); |
| | | task.setUpdateBy(loginUserId); |
| | | task.setUpdateTime(new Date()); |
| | |
| | | lambdaQueryWrapper.eq(Task::getBarcode, barcode); |
| | | Task task = taskService.getOne(lambdaQueryWrapper); |
| | | if (null == task) { |
| | | throw new CoolException("未找到容器号对应任务"); |
| | | throw new CoolException("未找到料箱码对应任务"); |
| | | } |
| | | if (!task.getTaskStatus().equals(TaskStsType.AWAIT.id)) { |
| | | return R.error("任务状态不是等待确认"); |
| | | } |
| | | List<TaskItem> taskItems = taskItemService.list(new LambdaQueryWrapper<TaskItem>().eq(TaskItem::getTaskId, task.getId())); |
| | | if (Cools.isEmpty(taskItems)) { |
| | | throw new CoolException("未找到该容器码对应的任务明细"); |
| | | throw new CoolException("未找到该料箱码对应的任务明细"); |
| | | } |
| | | String sourceCode = taskItems.stream().findFirst().map(TaskItem::getSourceCode).orElse(null); |
| | | CheckDiff checkDiff = checkDiffService.getOne(new LambdaQueryWrapper<CheckDiff>().eq(CheckDiff::getOrderCode, sourceCode)); |
| | |
| | | lambdaQueryWrapper.eq(Task::getBarcode, barcode); |
| | | Task task = taskService.getOne(lambdaQueryWrapper); |
| | | if (null == task) { |
| | | throw new CoolException("未找到容器号对应任务"); |
| | | throw new CoolException("未找到料箱码对应任务"); |
| | | } |
| | | // 允许WAVE_SEED(199,等待确认/盘点中)和AWAIT(196,等待确认)两种状态 |
| | | if (!task.getTaskStatus().equals(TaskStsType.WAVE_SEED.id) |
| | |
| | | } |
| | | List<TaskItem> taskItems = taskItemService.list(new LambdaQueryWrapper<TaskItem>().eq(TaskItem::getTaskId, task.getId())); |
| | | if (Cools.isEmpty(taskItems)) { |
| | | throw new CoolException("未找到该容器码对应的任务明细"); |
| | | throw new CoolException("未找到该料箱码对应的任务明细"); |
| | | } |
| | | taskItems.forEach(taskItem -> { |
| | | if (!Objects.isNull(taskItem.getFieldsIndex())) { |
| | |
| | | lambdaQueryWrapper.eq(Task::getBarcode, barcode); |
| | | Task task = taskService.getOne(lambdaQueryWrapper); |
| | | if (null == task) { |
| | | throw new CoolException("未找到容器号对应任务"); |
| | | throw new CoolException("未找到料箱码对应任务"); |
| | | } |
| | | if (!task.getTaskStatus().equals(TaskStsType.AWAIT.id)) { |
| | | return R.error("任务状态不是等待确认"); |
| | |
| | | .setMaktx(matnr.getName()) |
| | | .setAnfme(item.getCheckQty()); |
| | | |
| | | FieldsItem fieldsItem = fieldsItemService.getOne(new LambdaQueryWrapper<FieldsItem>().eq(FieldsItem::getValue, item.getFieldsIndex()).last("limit 1")); |
| | | if (Objects.isNull(fieldsItem)) { |
| | | throw new CoolException("当前票号不存在库存中,请拿出后重新入库!!"); |
| | | // 票号暂不使用,不校验票号是否存在 |
| | | FieldsItem fieldsItem = null; |
| | | if (StringUtils.isNotBlank(item.getFieldsIndex())) { |
| | | fieldsItem = fieldsItemService.getOne(new LambdaQueryWrapper<FieldsItem>().eq(FieldsItem::getValue, item.getFieldsIndex()).last("limit 1")); |
| | | // if (Objects.isNull(fieldsItem)) { |
| | | // throw new CoolException("当前票号不存在库存中,请拿出后重新入库!!"); |
| | | // } |
| | | } |
| | | taskItem.setFieldsIndex(fieldsItem.getUuid()); |
| | | if (fieldsItem != null) { |
| | | taskItem.setFieldsIndex(fieldsItem.getUuid()); |
| | | } |
| | | |
| | | taskItems.add(taskItem); |
| | | }); |
| | |
| | | lambdaQueryWrapper.eq(Task::getBarcode, barcode); |
| | | Task task = taskService.getOne(lambdaQueryWrapper); |
| | | if (null == task) { |
| | | throw new CoolException("未找到容器号对应任务"); |
| | | throw new CoolException("未找到料箱码对应任务"); |
| | | } |
| | | // 允许WAVE_SEED(199,等待确认/盘点中)和AWAIT(196,等待确认)两种状态 |
| | | if (!task.getTaskStatus().equals(TaskStsType.WAVE_SEED.id) |
| | |
| | | .setPDQty(taskItem.getAnfme()) |
| | | .setEditUser(nickName) |
| | | .setEditDate(taskItem.getUpdateTime()) |
| | | .setGoodsNO(fields.get("crushNo")) |
| | | // .setGoodsNO(fields.get("crushNo")) // 票号暂不使用 |
| | | .setIsBad(0 + "") |
| | | .setMemoDtl(taskItem.getMemo()); |
| | | |