diff --git a/blade-service/logpm-distribution/src/main/java/com/logpm/distribution/service/impl/DistributionSplitOrderTaskServiceImpl.java b/blade-service/logpm-distribution/src/main/java/com/logpm/distribution/service/impl/DistributionSplitOrderTaskServiceImpl.java index 6cee439d7..e2e5a3896 100644 --- a/blade-service/logpm-distribution/src/main/java/com/logpm/distribution/service/impl/DistributionSplitOrderTaskServiceImpl.java +++ b/blade-service/logpm-distribution/src/main/java/com/logpm/distribution/service/impl/DistributionSplitOrderTaskServiceImpl.java @@ -24,6 +24,7 @@ import com.logpm.distribution.service.IDistributionSplitOrderLogService; import com.logpm.distribution.service.IDistributionSplitOrderTaskService; import com.logpm.distribution.service.IDistributionStockArticleService; import com.logpm.distribution.vo.DistributionSplitOrderAllTaskVO; +import com.logpm.distribution.vo.DistributionSplitOrderTaskVO; import com.logpm.distribution.vo.SplitPackageOrderVO; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -33,6 +34,7 @@ import org.springblade.common.constant.order.OrderSplitStateConstant; import org.springblade.common.constant.order.OrderStatusConstant; import org.springblade.common.constant.orderpackage.*; import org.springblade.common.exception.CustomerException; +import org.springblade.core.mp.base.BaseEntity; import org.springblade.core.mp.base.BaseServiceImpl; import org.springblade.core.mp.support.Condition; import org.springblade.core.mp.support.Query; @@ -87,12 +89,29 @@ public class DistributionSplitOrderTaskServiceImpl extends BaseServiceImpl page = Condition.getPage(query); - List list = list(page, queryWrapper); - page.setRecords(list); + IPage pageRes = Condition.getPage(query); + List list = list(page, queryWrapper); + + Map userIdNameMap = getUserIdNameMap(list.stream().map(DistributionSplitOrderTaskEntity::getCreateUser).collect(Collectors.toList())); + + pageRes.setRecords(list.stream().map(item -> { + DistributionSplitOrderTaskVO distributionSplitOrderTaskVO = new DistributionSplitOrderTaskVO(); + BeanUtil.copyProperties(item, distributionSplitOrderTaskVO); + distributionSplitOrderTaskVO.setCreateUserName(userIdNameMap.get(item.getCreateUser())); + return distributionSplitOrderTaskVO; + }).collect(Collectors.toList())); + pageRes.setPages(page.getPages()); + pageRes.setTotal(page.getTotal()); return R.data(page); } + private Map getUserIdNameMap(List list) { + String createUserIds = list.stream().map((d) -> d + "").collect(Collectors.joining(",")); + List users = iUserClient.userInfoByIds(AuthUtil.getTenantId(), String.join(",", createUserIds)).getData(); + return users.stream().collect(Collectors.toMap(User::getId, User::getName)); + } + @Transactional @Override public R batchCreateTask(List distributionSplitOrderTaskList) { @@ -132,6 +151,15 @@ public class DistributionSplitOrderTaskServiceImpl extends BaseServiceImpl { String allTaskNo = getAllTaskNo(); DistributionSplitOrderAllTaskEntity allTask = new DistributionSplitOrderAllTaskEntity(); @@ -141,10 +169,7 @@ public class DistributionSplitOrderTaskServiceImpl extends BaseServiceImpllambdaQuery() - .eq(DistributionStockArticleEntity::getId, task.getStockArticleId()) - .eq(DistributionStockArticleEntity::getIsDeleted, 1) - ); - if (oldStockArticle == null) { - return R.fail("订单错误,无法删除"); - } - oldStockArticle.setIsDeleted(0); - } - - List packageList = distributionParcelListService.list(Wrappers.lambdaQuery() - .eq(DistributionParcelListEntity::getStockArticleId, task.getNewStockArticleId())); - - if (packageList.stream().anyMatch(distributionParcelListEntity -> OrderPackageReservationStatusConstant.yiyueyue.getValue().equals(distributionParcelListEntity.getOrderPackageReservationStatus()))) { - return R.fail("新的订单包件已预约,无法删除"); + long count = count( + Wrappers.lambdaQuery() + .eq(DistributionSplitOrderTaskEntity::getSplitOrderAllTaskId, task.getSplitOrderAllTaskId()) + .in(DistributionSplitOrderTaskEntity::getState, Arrays.asList(OrderSplitStateConstant.InProgress.getValue(), OrderSplitStateConstant.finish.getValue())) + ); + if (count == 1) { + return R.fail("总任务下只有一条任务,无法撤销"); } try { - - distributionParcelListService.update(Wrappers.lambdaUpdate() - .eq(DistributionParcelListEntity::getStockArticleId, task.getNewStockArticleId()) - .set(DistributionParcelListEntity::getStockArticleId, task.getStockArticleId()) - .set(DistributionParcelListEntity::getOrderCode, task.getOrderCode()) - ); - - if (newStockArticle != null) { - newStockArticle.setTotalNumber(0); - newStockArticle.setHandQuantity(0); - distributionStockArticleService.updateById(newStockArticle); - oldStockArticle.setTotalNumber(oldStockArticle.getTotalNumber() + newStockArticle.getTotalNumber()); - oldStockArticle.setHandQuantity(oldStockArticle.getHandQuantity() + newStockArticle.getHandQuantity()); - } - - distributionStockArticleService.updateById(oldStockArticle); - - distributionSplitOrderDetailService.update(Wrappers.lambdaUpdate() - .eq(DistributionSplitOrderDetailEntity::getSplitOrderTaskId, taskId) - .set(DistributionSplitOrderDetailEntity::getState, OrderPackageSplitStateConstant.cancel.getValue()) - .set(DistributionSplitOrderDetailEntity::getCancelUser, AuthUtil.getUser().getUserId()) - .set(DistributionSplitOrderDetailEntity::getCancelUsername, AuthUtil.getUser().getUserName()) - ); - distributionSplitOrderLogService.record(task, "取消拆单任务", AuthUtil.getUser().getUserName()); - - allTask.setNumber(allTask.getNumber() - 1); - allTask.setOrderPackageNumber(allTask.getOrderPackageNumber() - task.getTaskNumber()); - distributionSplitOrderAllTaskService.updateById(allTask); - - task.setIsDeleted(1); - task.setNumber(0); - updateById(task); - + cancelTask(task); return R.success("success"); } catch (Exception e) { log.error("取消拆单任务系统错误", e); @@ -607,6 +591,9 @@ public class DistributionSplitOrderTaskServiceImpl extends BaseServiceImpllambdaQuery() .in(DistributionSplitOrderDetailEntity::getOrderPackageCode, packageCodes) @@ -621,11 +608,6 @@ public class DistributionSplitOrderTaskServiceImpl extends BaseServiceImpllambdaUpdate() @@ -702,6 +684,10 @@ public class DistributionSplitOrderTaskServiceImpl extends BaseServiceImpl list = distributionSplitOrderAllTaskService.list(page, queryWrapper); - String createUserIds = list.stream().map((d) -> d.getCreateUser() + "").collect(Collectors.joining(",")); - List users = iUserClient.userInfoByIds(AuthUtil.getTenantId(), String.join(",", createUserIds)).getData(); - Map userMap = users.stream().collect(Collectors.toMap(User::getId, u -> u)); + Map userMap = getUserIdNameMap(list.stream().map(DistributionSplitOrderAllTaskEntity::getCreateUser).collect(Collectors.toList())); + Map allTaskIdPackageNumber = getAllTaskIdPackageNumber(list.stream().map(DistributionSplitOrderAllTaskEntity::getId).collect(Collectors.toList())); List listVo = list.stream().map(d -> { DistributionSplitOrderAllTaskVO vo = new DistributionSplitOrderAllTaskVO(); BeanUtil.copyProperties(d, vo); - vo.setCreateUserName(userMap.get(d.getCreateUser()).getName()); + vo.setCreateUserName(userMap.get(d.getCreateUser())); + vo.setSplitPackageNumber(allTaskIdPackageNumber.get(d.getId())); return vo; }).collect(Collectors.toList()); @@ -932,6 +921,22 @@ public class DistributionSplitOrderTaskServiceImpl extends BaseServiceImpl getAllTaskIdPackageNumber(List taskIds){ + List> maps = baseMapper.selectMaps( + Wrappers.query() + .select("split_order_all_task_id", "SUM(number) as number") + .eq("split_order_all_task_id", taskIds) + .in("state", OrderSplitStateConstant.InProgress.getValue(), OrderSplitStateConstant.finish.getValue()) + .groupBy("split_order_all_task_id") + ); + + return maps.stream().collect(Collectors.toMap( + m -> Long.valueOf(m.get("split_order_all_task_id").toString()), + m -> Long.valueOf(m.get("number").toString()) + )); + } + + @Override public R getTaskDetail(Long taskId) { R> PackageOrderList = getPackageCodeByTaskId(taskId); diff --git a/blade-service/logpm-distribution/src/main/java/com/logpm/distribution/vo/DistributionSplitOrderAllTaskVO.java b/blade-service/logpm-distribution/src/main/java/com/logpm/distribution/vo/DistributionSplitOrderAllTaskVO.java index 88844757c..b0400f11b 100644 --- a/blade-service/logpm-distribution/src/main/java/com/logpm/distribution/vo/DistributionSplitOrderAllTaskVO.java +++ b/blade-service/logpm-distribution/src/main/java/com/logpm/distribution/vo/DistributionSplitOrderAllTaskVO.java @@ -7,5 +7,10 @@ import lombok.EqualsAndHashCode; @EqualsAndHashCode(callSuper = true) @Data public class DistributionSplitOrderAllTaskVO extends DistributionSplitOrderAllTaskEntity { + private String createUserName; + /** + * 已拆单包件数量 + */ + private Long splitPackageNumber; }