From f87c7dbec6ffbbe853e5e19b6c440e3a0590e53a Mon Sep 17 00:00:00 2001 From: chenlong Date: Wed, 14 Aug 2024 18:37:50 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8B=86=E5=8D=95=E4=BB=BB=E5=8A=A1=E5=88=9B?= =?UTF-8?q?=E5=BB=BA=EF=BC=8C=E4=BF=AE=E6=94=B9=EF=BC=8C=E6=92=A4=E9=94=80?= =?UTF-8?q?=EF=BC=8C=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../order/OrderSplitStateConstant.java | 2 +- .../DistributionSplitOrderLogEntity.java | 6 + .../DistributionSplitOrderTaskEntity.java | 18 +- .../DistributionSplitAllTaskSearchDTO.java | 36 ++ .../DistributionSplitTaskSearchDTO.java | 46 ++ .../IDistributionSplitOrderLogService.java | 2 + .../IDistributionSplitOrderTaskService.java | 51 ++- ...DistributionSplitOrderTaskServiceImpl.java | 407 ++++++++++++++---- 8 files changed, 470 insertions(+), 98 deletions(-) create mode 100644 blade-service/logpm-distribution/src/main/java/com/logpm/distribution/dto/splitOrder/DistributionSplitAllTaskSearchDTO.java create mode 100644 blade-service/logpm-distribution/src/main/java/com/logpm/distribution/dto/splitOrder/DistributionSplitTaskSearchDTO.java diff --git a/blade-biz-common/src/main/java/org/springblade/common/constant/order/OrderSplitStateConstant.java b/blade-biz-common/src/main/java/org/springblade/common/constant/order/OrderSplitStateConstant.java index acd5d3291..6b3cbbc08 100644 --- a/blade-biz-common/src/main/java/org/springblade/common/constant/order/OrderSplitStateConstant.java +++ b/blade-biz-common/src/main/java/org/springblade/common/constant/order/OrderSplitStateConstant.java @@ -12,7 +12,7 @@ public enum OrderSplitStateConstant { InProgress("未完成",1), finish("已完成",2), - revoke("已撤回",3); + cancel("已撤回",3); private final String name; private final Integer value; diff --git a/blade-service-api/logpm-distribution-api/src/main/java/com/logpm/distribution/entity/DistributionSplitOrderLogEntity.java b/blade-service-api/logpm-distribution-api/src/main/java/com/logpm/distribution/entity/DistributionSplitOrderLogEntity.java index f89323395..2779b8e38 100644 --- a/blade-service-api/logpm-distribution-api/src/main/java/com/logpm/distribution/entity/DistributionSplitOrderLogEntity.java +++ b/blade-service-api/logpm-distribution-api/src/main/java/com/logpm/distribution/entity/DistributionSplitOrderLogEntity.java @@ -74,9 +74,15 @@ public class DistributionSplitOrderLogEntity extends TenantEntity { @ApiModelProperty(value = "预留5") private String reserve5; + @ApiModelProperty(value = "总任务ID") + private Long splitOrderAllTaskId; + @ApiModelProperty(value = "任务ID") private Long splitOrderTaskId; + @ApiModelProperty(value = "新的拆单订单号") + private String orderCode; + @ApiModelProperty(value = "日志内容") private String content; diff --git a/blade-service-api/logpm-distribution-api/src/main/java/com/logpm/distribution/entity/DistributionSplitOrderTaskEntity.java b/blade-service-api/logpm-distribution-api/src/main/java/com/logpm/distribution/entity/DistributionSplitOrderTaskEntity.java index dcab2da63..85094ffd5 100644 --- a/blade-service-api/logpm-distribution-api/src/main/java/com/logpm/distribution/entity/DistributionSplitOrderTaskEntity.java +++ b/blade-service-api/logpm-distribution-api/src/main/java/com/logpm/distribution/entity/DistributionSplitOrderTaskEntity.java @@ -121,22 +121,22 @@ public class DistributionSplitOrderTaskEntity extends TenantEntity { private String reason; /** - * 审核人 + * 完成人 */ - @ApiModelProperty(value = "审核人") - private Long reviewerUser; + @ApiModelProperty(value = "完成人") + private Long finishUser; /** - * 审核人名字 + * 完成人名字 */ - @ApiModelProperty(value = "审核人名字") - private String reviewerUsername; + @ApiModelProperty(value = "完成人名字") + private String finishUsername; /** - * 审核时间 + * 完成时间 */ - @ApiModelProperty(value = "审核时间") - private String reviewTime; + @ApiModelProperty(value = "完成时间") + private String finishTime; /** * 任务拆单数量 diff --git a/blade-service/logpm-distribution/src/main/java/com/logpm/distribution/dto/splitOrder/DistributionSplitAllTaskSearchDTO.java b/blade-service/logpm-distribution/src/main/java/com/logpm/distribution/dto/splitOrder/DistributionSplitAllTaskSearchDTO.java new file mode 100644 index 000000000..944bb37c0 --- /dev/null +++ b/blade-service/logpm-distribution/src/main/java/com/logpm/distribution/dto/splitOrder/DistributionSplitAllTaskSearchDTO.java @@ -0,0 +1,36 @@ +package com.logpm.distribution.dto.splitOrder; + + +import lombok.Data; + +/** + * 拆单总任务搜索DTO + */ +@Data +public class DistributionSplitAllTaskSearchDTO { + + /** + * 订单编号 + */ + private String no; + + /** + * 订单自编号 + */ + private String orderCode; + + /** + * 创建时间 + */ + private String[] createTime; + + /** + * 状态 + */ + private Integer state; + + /** + * 包条码 + */ + private String orderPackageCode; +} diff --git a/blade-service/logpm-distribution/src/main/java/com/logpm/distribution/dto/splitOrder/DistributionSplitTaskSearchDTO.java b/blade-service/logpm-distribution/src/main/java/com/logpm/distribution/dto/splitOrder/DistributionSplitTaskSearchDTO.java new file mode 100644 index 000000000..79c225260 --- /dev/null +++ b/blade-service/logpm-distribution/src/main/java/com/logpm/distribution/dto/splitOrder/DistributionSplitTaskSearchDTO.java @@ -0,0 +1,46 @@ +package com.logpm.distribution.dto.splitOrder; + + +import lombok.Data; + +/** + * 拆单任务搜索DTO + */ +@Data +public class DistributionSplitTaskSearchDTO { + + /** + * 总任务ID + */ + private Long splitOrderAllTaskId; + + /** + * 总任务编号 + */ + private Long splitOrderAllTaskNo; + + /** + * 订单自编号 + */ + private String orderCode; + + /** + * 创建时间 + */ + private String[] createTime; + + /** + * 状态 + */ + private Integer state; + + /** + * 客户名称 + */ + private String customerName; + + /** + * 客户电话 + */ + private String customerTelephone; +} diff --git a/blade-service/logpm-distribution/src/main/java/com/logpm/distribution/service/IDistributionSplitOrderLogService.java b/blade-service/logpm-distribution/src/main/java/com/logpm/distribution/service/IDistributionSplitOrderLogService.java index b91512d94..2da3b266d 100644 --- a/blade-service/logpm-distribution/src/main/java/com/logpm/distribution/service/IDistributionSplitOrderLogService.java +++ b/blade-service/logpm-distribution/src/main/java/com/logpm/distribution/service/IDistributionSplitOrderLogService.java @@ -14,7 +14,9 @@ public interface IDistributionSplitOrderLogService extends BaseService> taskList(Query query, DistributionSplitOrderTaskEntity distributionSplitOrderTaskEntity); + R> taskList(Query query, DistributionSplitTaskSearchDTO distributionSplitTaskSearchDTO); + + /** + * 拆单总任务 + * @param query + * @param distributionSplitAllTaskSearchDTO + * @return + */ + R> allTaskList(Query query, DistributionSplitAllTaskSearchDTO distributionSplitAllTaskSearchDTO); /** * 创建任务 * @param distributionSplitOrderTaskEntity + * @param packageCodeList * @return */ R createTask(DistributionSplitOrderTaskEntity distributionSplitOrderTaskEntity, List packageCodeList); @@ -38,16 +51,25 @@ public interface IDistributionSplitOrderTaskService extends BaseService updateTask(DistributionSplitOrderTaskEntity distributionSplitOrderTaskEntity, List packageCodeList); /** - * 整单撤回任务 + * 添加包码 * @param taskId + * @param packageCode * @return */ - R cancelTask(Long taskId); + R addPackageCode(Long taskId, List packageCode); + + /** + * 删除任务 + * @param taskId + * @return + */ + R deleteTask(Long taskId); /** * 单个包撤回任务 @@ -58,16 +80,29 @@ public interface IDistributionSplitOrderTaskService extends BaseService cancelPackageCode(Long taskId, List packageCodes); /** - * 审核任务 + * 获取任务详情 * @param taskId * @return */ - R reviewTask(Long taskId, Integer reviewStatus, String reason); + R getTaskDetail(Long taskId); /** - * 获取任务详情 + * 完成任务 * @param taskId * @return */ - R getTaskDetail(Long taskId); + R finishTask(Long taskId); + + /** + * 撤回任务 + * @param taskId + * @return + */ + R cancelTask(Long taskId); + + R cancelAllTask(Long allTaskId); + + R finishAllTask(Long allTaskId); + + R deleteAllTask(Long allTaskId); } 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 6b04b3d1d..0de4f19e6 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 @@ -1,24 +1,30 @@ package com.logpm.distribution.service.impl; +import cn.hutool.core.date.DateUtil; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.toolkit.SerializationUtils; import com.baomidou.mybatisplus.core.toolkit.Wrappers; -import com.logpm.distribution.entity.DistributionParcelListEntity; -import com.logpm.distribution.entity.DistributionSplitOrderDetailEntity; -import com.logpm.distribution.entity.DistributionSplitOrderTaskEntity; -import com.logpm.distribution.entity.DistributionStockArticleEntity; +import com.logpm.distribution.dto.splitOrder.DistributionSplitAllTaskSearchDTO; +import com.logpm.distribution.dto.splitOrder.DistributionSplitTaskSearchDTO; +import com.logpm.distribution.entity.*; import com.logpm.distribution.mapper.DistributionSplitOrderTaskMapper; import com.logpm.distribution.service.*; import groovy.util.logging.Slf4j; import lombok.AllArgsConstructor; +import org.springblade.common.constant.order.OrderSplitStateConstant; +import org.springblade.common.constant.order.OrderSplitTaskStateConstant; import org.springblade.common.constant.orderpackage.OrderPackageReservationStatusConstant; import org.springblade.common.constant.orderpackage.OrderPackageSplitStateConstant; import org.springblade.common.exception.CustomerException; import org.springblade.core.mp.base.BaseServiceImpl; +import org.springblade.core.mp.support.Condition; import org.springblade.core.mp.support.Query; import org.springblade.core.redis.lock.LockType; import org.springblade.core.redis.lock.RedisLockClient; import org.springblade.core.secure.utils.AuthUtil; import org.springblade.core.tool.api.R; +import org.springframework.data.domain.Page; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -41,7 +47,7 @@ public class DistributionSplitOrderTaskServiceImpl extends BaseServiceImpl> taskList(Query query, DistributionSplitOrderTaskEntity distributionSplitOrderTaskEntity) { + public R> taskList(Query query, DistributionSplitTaskSearchDTO distributionSplitTaskSearchDTO) { return null; } @@ -70,15 +76,7 @@ public class DistributionSplitOrderTaskServiceImpl extends BaseServiceImpl addPackageCode(Long taskId, List packageCodes) { + DistributionSplitOrderTaskEntity task = getById(taskId); + if (task == null) { + return R.fail("拆单任务不存在"); + } + if (!task.getState().equals(OrderSplitTaskStateConstant.InProgress.getValue())) { + return R.fail("拆单任务已完成,无法添加"); + } + + try { + List existsList = distributionSplitOrderDetailService.list(Wrappers.lambdaQuery() + .in(DistributionSplitOrderDetailEntity::getOrderPackageCode, packageCodes) + ); + + int addNumber = packageCodes.size(); + if (!existsList.isEmpty()) { + if (existsList.stream().anyMatch(detail -> !detail.getSplitOrderTaskId().equals(taskId) && detail.getState().equals(OrderPackageSplitStateConstant.finish.getValue()))) { + return R.fail("提交包件包含其他拆单任务的包件"); + } + + List cancelIds = existsList.stream() + .filter(detail -> detail.getState().equals(OrderPackageSplitStateConstant.cancel.getValue())) + .map(DistributionSplitOrderDetailEntity::getId) + .collect(Collectors.toList()); + + int finishNumber = existsList.size() - cancelIds.size(); + addNumber -= finishNumber; + + distributionSplitOrderDetailService.update(Wrappers.lambdaUpdate() + .in(DistributionSplitOrderDetailEntity::getId, cancelIds) + .set(DistributionSplitOrderDetailEntity::getState, OrderPackageSplitStateConstant.finish.getValue()) + .set(DistributionSplitOrderDetailEntity::getSplitOrderTaskId, task.getId()) + .set(DistributionSplitOrderDetailEntity::getSplitOrderAllTaskId, task.getSplitOrderAllTaskId()) + ); + } + + ArrayList details = new ArrayList<>(); + List existsPackageList = existsList.stream().map(DistributionSplitOrderDetailEntity::getOrderPackageCode).collect(Collectors.toList()); + for (String packageCode : packageCodes) { + if (existsPackageList.contains(packageCode)){ + continue; + } + + DistributionSplitOrderDetailEntity detail = new DistributionSplitOrderDetailEntity(); + detail.setOrderPackageCode(packageCode); + detail.setSplitOrderTaskId(taskId); + detail.setSplitOrderAllTaskId(task.getSplitOrderAllTaskId()); + detail.setState(OrderPackageSplitStateConstant.finish.getValue()); + details.add(detail); + } + distributionSplitOrderDetailService.saveBatch(details); + + String msg = packageCodes.stream().limit(30).collect(Collectors.joining(",")); + if (packageCodes.size() > 30) { + msg += "等" + (packageCodes.size()) + "个包件"; + } + distributionSplitOrderLogService.record(task, "拆单任务添加包件:" + msg, AuthUtil.getUser().getUserName()); + + task.setNumber(task.getNumber() + addNumber); + if (task.getNumber() > task.getTaskNumber()) { + throw new CustomerException("拆单数量不能大于任务拆单数量"); + } + updateById(task); + + } catch (Exception e) { + if (e instanceof CustomerException) { + throw new CustomerException(e.getMessage()); + } + log.error("添加包件系统错误", e); + throw new CustomerException("系统错误"); + } + return R.success("success"); + } + + @Deprecated @Transactional @Override public R createTask(DistributionSplitOrderTaskEntity distributionSplitOrderTaskEntity, List packageCodeList) { @@ -361,35 +436,35 @@ public class DistributionSplitOrderTaskServiceImpl extends BaseServiceImpl cancelTask(Long taskId) { + public R deleteTask(Long taskId) { DistributionSplitOrderTaskEntity task = getById(taskId); if (task == null) { return R.fail("任务不存在"); } + DistributionSplitOrderAllTaskEntity allTask = distributionSplitOrderAllTaskService.getById(task.getSplitOrderAllTaskId()); + if (allTask == null) { + return R.fail("总任务不存在"); + } DistributionStockArticleEntity oldStockArticle = distributionStockArticleService.getById(task.getStockArticleId()); DistributionStockArticleEntity newStockArticle = distributionStockArticleService.getById(task.getNewStockArticleId()); - if (newStockArticle == null) { - return R.fail("订单错误,无法取消"); - } + if (oldStockArticle == null) { oldStockArticle = distributionStockArticleService.getOne(Wrappers.lambdaQuery() .eq(DistributionStockArticleEntity::getId, task.getStockArticleId()) .eq(DistributionStockArticleEntity::getIsDeleted, 1) ); if (oldStockArticle == null) { - return R.fail("订单错误,无法取消"); + return R.fail("订单错误,无法删除"); } oldStockArticle.setIsDeleted(0); } List packageList = distributionParcelListService.list(Wrappers.lambdaQuery() .eq(DistributionParcelListEntity::getStockArticleId, task.getNewStockArticleId())); - if (packageList.isEmpty()) { - return R.fail("无可取消包件,无法取消"); - } + if (packageList.stream().anyMatch(distributionParcelListEntity -> OrderPackageReservationStatusConstant.yiyueyue.getValue().equals(distributionParcelListEntity.getOrderPackageReservationStatus()))) { - return R.fail("新的订单包件已预约,无法取消"); + return R.fail("新的订单包件已预约,无法删除"); } try { @@ -400,18 +475,16 @@ public class DistributionSplitOrderTaskServiceImpl extends BaseServiceImpllambdaUpdate() .eq(DistributionSplitOrderDetailEntity::getSplitOrderTaskId, taskId) .set(DistributionSplitOrderDetailEntity::getState, OrderPackageSplitStateConstant.cancel.getValue()) @@ -420,6 +493,14 @@ public class DistributionSplitOrderTaskServiceImpl extends BaseServiceImpllambdaQuery() + .in(DistributionSplitOrderDetailEntity::getOrderPackageCode, packageCodes) + .eq(DistributionSplitOrderDetailEntity::getSplitOrderTaskId, taskId) + ); + if (count != packageCodes.size()) { + return R.fail("包件信息错误,包含错误的包件,无法取消"); } - List packageList = distributionParcelListService.list(Wrappers.lambdaQuery() - .eq(DistributionParcelListEntity::getStockArticleId, task.getNewStockArticleId()) - .in(DistributionParcelListEntity::getOrderPackageCode, packageCodes) - ); - if (packageList.stream().anyMatch(distributionParcelListEntity -> OrderPackageReservationStatusConstant.yiyueyue.getValue().equals(distributionParcelListEntity.getOrderPackageReservationStatus()))) { - return R.fail("新的订单包件已预约,无法取消"); + String msg = packageCodes.stream().limit(30).collect(Collectors.joining(",")); + if (packageCodes.size() > 30) { + msg += "等" + packageCodes.size() + "个包件"; } - List detail = distributionSplitOrderDetailService.list(Wrappers.lambdaQuery() - .eq(DistributionSplitOrderDetailEntity::getSplitOrderTaskId, taskId) - .in(DistributionSplitOrderDetailEntity::getOrderPackageCode, packageCodes) - ); + if (task.getNumber() == packageCodes.size()) { + distributionSplitOrderLogService.record(task, String.format("取消包件:%s", msg), AuthUtil.getUser().getUserName()); + return deleteTask(taskId); + } + + try{ + + distributionSplitOrderDetailService.update(Wrappers.lambdaUpdate() + .in(DistributionSplitOrderDetailEntity::getOrderPackageCode, packageCodes) + .set(DistributionSplitOrderDetailEntity::getState, OrderPackageSplitStateConstant.cancel.getValue()) + .set(DistributionSplitOrderDetailEntity::getCancelUser, AuthUtil.getUser().getUserId()) + .set(DistributionSplitOrderDetailEntity::getCancelUsername, AuthUtil.getUser().getUserName()) + ); + + task.setNumber(task.getNumber() - packageCodes.size()); + updateById(task); + + distributionSplitOrderLogService.record(task, String.format("取消包件:%s", msg), AuthUtil.getUser().getUserName()); - long cancelCount = detail.stream().filter(distributionSplitOrderDetailEntity -> - OrderPackageSplitStateConstant.cancel.getValue().equals(distributionSplitOrderDetailEntity.getState()) - ).count(); - if (cancelCount > 0) { - return R.fail("选择部分包件已取消,请重新选择"); + return R.success("success"); + } catch (Exception e) { + log.error("撤销包件系统错误", e); + throw new CustomerException("系统错误"); } + } - DistributionStockArticleEntity oldStockArticle = distributionStockArticleService.getById(task.getStockArticleId()); - DistributionStockArticleEntity newStockArticle = distributionStockArticleService.getById(task.getNewStockArticleId()); - if (newStockArticle == null) { - return R.fail("订单错误,无法取消"); + @Override + public R finishTask(Long taskId) { + DistributionSplitOrderTaskEntity task = getById(taskId); + if (!task.getState().equals(OrderSplitStateConstant.InProgress.getValue())) { + return R.fail("任务已完成或已取消,无法操作"); } - if (oldStockArticle == null) { - oldStockArticle = distributionStockArticleService.getOne(Wrappers.lambdaQuery() - .eq(DistributionStockArticleEntity::getId, task.getStockArticleId()) - .eq(DistributionStockArticleEntity::getIsDeleted, 1) + if (task.getNumber() == 0) { + return R.fail("任务没有包件,无法完成"); + } + + DistributionSplitOrderAllTaskEntity allTask = distributionSplitOrderAllTaskService.getById(task.getSplitOrderAllTaskId()); + if (!allTask.getState().equals(OrderSplitStateConstant.InProgress.getValue())) { + return R.fail("拆单总任务已完成或已取消,无法操作"); + } + + try { + + List packageList = distributionSplitOrderDetailService.list(Wrappers.lambdaQuery() + .eq(DistributionSplitOrderDetailEntity::getSplitOrderTaskId, taskId) + .eq(DistributionSplitOrderDetailEntity::getState, OrderPackageSplitStateConstant.finish.getValue()) ); - if (oldStockArticle == null) { - return R.fail("订单错误,无法取消"); + + DistributionStockArticleEntity originalOrder = distributionStockArticleService.getById(task.getStockArticleId()); + originalOrder.setTotalNumber(originalOrder.getTotalNumber() - packageList.size()); + originalOrder.setHandQuantity(originalOrder.getHandQuantity() - packageList.size()); + distributionStockArticleService.updateById(originalOrder); + + DistributionStockArticleEntity newOrder = distributionStockArticleService.getById(task.getNewStockArticleId()); + if (newOrder == null) { + newOrder = SerializationUtils.clone(originalOrder); + newOrder.setId(null); + newOrder.setOrderCode(task.getNewOrderCode()); } - oldStockArticle.setIsDeleted(0); + newOrder.setTotalNumber(packageList.size()); + newOrder.setHandQuantity(packageList.size()); + if (newOrder.getId() != null) { + distributionStockArticleService.updateById(newOrder); + }else{ + distributionStockArticleService.save(newOrder); + } + + task.setNewStockArticleId(newOrder.getId()); + task.setState(OrderSplitStateConstant.finish.getValue()); + task.setFinishTime(DateUtil.now()); + task.setFinishUsername(AuthUtil.getUser().getUserName()); + task.setFinishUser(AuthUtil.getUser().getUserId()); + updateById(task); + + distributionParcelListService.update(Wrappers.lambdaUpdate() + .in(DistributionParcelListEntity::getOrderPackageCode, packageList.stream().map(DistributionSplitOrderDetailEntity::getOrderPackageCode).collect(Collectors.toList())) + .eq(DistributionParcelListEntity::getStockArticleId, task.getStockArticleId()) + .set(DistributionParcelListEntity::getStockArticleId, task.getNewStockArticleId()) + .set(DistributionParcelListEntity::getOrderCode, task.getNewOrderCode()) + ); + + distributionSplitOrderLogService.record(task, "完成拆单任务", AuthUtil.getUser().getUserName()); + + } catch (Exception e) { + if (e instanceof CustomerException) { + throw new CustomerException(e.getMessage()); + } + log.error("完成拆单任务系统错误", e); + throw new CustomerException("系统错误"); + } + + return R.success("success"); + } + + @Override + public R cancelTask(Long taskId) { + DistributionSplitOrderTaskEntity task = getById(taskId); + if (!task.getState().equals(OrderSplitStateConstant.finish.getValue())) { + return R.fail("任务未已完成或已取消,无法操作"); + } + DistributionSplitOrderAllTaskEntity allTask = distributionSplitOrderAllTaskService.getById(task.getSplitOrderAllTaskId()); + if (!allTask.getState().equals(OrderSplitStateConstant.InProgress.getValue())) { + return R.fail("拆单总任务已完成或已取消,无法操作"); } try { + + List packageList = distributionSplitOrderDetailService.list(Wrappers.lambdaQuery() + .eq(DistributionSplitOrderDetailEntity::getSplitOrderTaskId, taskId) + .eq(DistributionSplitOrderDetailEntity::getState, OrderPackageSplitStateConstant.finish.getValue()) + ); + + DistributionStockArticleEntity originalOrder = distributionStockArticleService.getById(task.getStockArticleId()); + originalOrder.setTotalNumber(originalOrder.getTotalNumber() + packageList.size()); + originalOrder.setHandQuantity(originalOrder.getHandQuantity() + packageList.size()); + distributionStockArticleService.updateById(originalOrder); + + DistributionStockArticleEntity newOrder = distributionStockArticleService.getById(task.getNewStockArticleId()); + newOrder.setTotalNumber(0); + newOrder.setHandQuantity(0); + distributionStockArticleService.updateById(newOrder); + + task.setNumber(0); + task.setState(OrderSplitStateConstant.cancel.getValue()); + updateById(task); + distributionParcelListService.update(Wrappers.lambdaUpdate() + .in(DistributionParcelListEntity::getOrderPackageCode, packageList.stream().map(DistributionSplitOrderDetailEntity::getOrderPackageCode).collect(Collectors.toList())) .eq(DistributionParcelListEntity::getStockArticleId, task.getNewStockArticleId()) - .in(DistributionParcelListEntity::getOrderPackageCode, packageCodes) .set(DistributionParcelListEntity::getStockArticleId, task.getStockArticleId()) .set(DistributionParcelListEntity::getOrderCode, task.getOrderCode()) ); - distributionSplitOrderDetailService.update(Wrappers.lambdaUpdate() - .eq(DistributionSplitOrderDetailEntity::getId, detail.stream().map(DistributionSplitOrderDetailEntity::getId).collect(Collectors.toList())) - .set(DistributionSplitOrderDetailEntity::getState, OrderPackageSplitStateConstant.cancel.getValue()) - ); + distributionSplitOrderLogService.record(task, "撤消拆单任务", AuthUtil.getUser().getUserName()); - task.setNumber(task.getNumber() - packageCodes.size()); - updateById(task); + } catch (Exception e) { + if (e instanceof CustomerException) { + throw new CustomerException(e.getMessage()); + } + log.error("撤消拆单任务系统错误", e); + throw new CustomerException("系统错误"); + } - newStockArticle.setTotalNumber(newStockArticle.getTotalNumber() - packageCodes.size()); - newStockArticle.setHandQuantity(newStockArticle.getHandQuantity() - packageCodes.size()); - distributionStockArticleService.updateById(newStockArticle); + return R.success("success"); + } - oldStockArticle.setTotalNumber(oldStockArticle.getTotalNumber() + newStockArticle.getTotalNumber()); - oldStockArticle.setHandQuantity(oldStockArticle.getHandQuantity() + newStockArticle.getHandQuantity()); - distributionStockArticleService.updateById(oldStockArticle); + @Override + public R cancelAllTask(Long allTaskId) { + DistributionSplitOrderAllTaskEntity allTask = distributionSplitOrderAllTaskService.getById(allTaskId); + if (!allTask.getState().equals(OrderSplitStateConstant.finish.getValue())) { + return R.fail("拆单总任务未完成或已取消,无法操作"); + } - distributionSplitOrderLogService.record(task, String.format("取消包件:%s", String.join(",", packageCodes)), AuthUtil.getUser().getUserName()); + allTask.setState(OrderSplitTaskStateConstant.InProgress.getValue()); + distributionSplitOrderAllTaskService.updateById(allTask); - return R.success("success"); + return R.success("success"); + } + + @Override + public R finishAllTask(Long allTaskId) { + DistributionSplitOrderAllTaskEntity allTask = distributionSplitOrderAllTaskService.getById(allTaskId); + if (!allTask.getState().equals(OrderSplitStateConstant.InProgress.getValue())) { + return R.fail("拆单总任务已完成或已取消,无法操作"); + } + + allTask.setState(OrderSplitTaskStateConstant.finish.getValue()); + distributionSplitOrderAllTaskService.updateById(allTask); + + return R.success("success"); + } + + @Transactional + @Override + public R deleteAllTask(Long allTaskId) { + DistributionSplitOrderAllTaskEntity allTask = distributionSplitOrderAllTaskService.getById(allTaskId); + if (!allTask.getState().equals(OrderSplitStateConstant.InProgress.getValue())) { + return R.fail("拆单总任务已完成或已取消,无法操作"); + } + + try { + List list = list(Wrappers.lambdaQuery() + .eq(DistributionSplitOrderTaskEntity::getSplitOrderAllTaskId, allTaskId) + ); + + for (DistributionSplitOrderTaskEntity task : list) { + R res = deleteTask(task.getId()); + if (res.getCode() != 200) { + throw new CustomerException(res.getMsg()); + } + } + + allTask.setIsDeleted(1); + distributionSplitOrderAllTaskService.updateById(allTask); } catch (Exception e) { - log.error("撤销包件系统错误", e); + if (e instanceof CustomerException) { + throw new CustomerException(e.getMessage()); + } + log.error("删除拆单总任务系统错误", e); throw new CustomerException("系统错误"); } + + return R.success("success"); } - @Deprecated - @Transactional @Override - public R reviewTask(Long taskId, Integer reviewStatus, String reason) { + public R> allTaskList(Query query, DistributionSplitAllTaskSearchDTO distributionSplitAllTaskSearchDTO) { + IPage page = Condition.getPage(query); + LambdaQueryWrapper queryWrapper = Wrappers.lambdaQuery(); + if (distributionSplitAllTaskSearchDTO.getState() != null) { + queryWrapper.eq(DistributionSplitOrderAllTaskEntity::getState, distributionSplitAllTaskSearchDTO.getState()); + } + if (distributionSplitAllTaskSearchDTO.getNo() != null) { + queryWrapper.likeLeft(DistributionSplitOrderAllTaskEntity::getNo, distributionSplitAllTaskSearchDTO.getNo()); + } + if (distributionSplitAllTaskSearchDTO.getOrderCode() != null) { + queryWrapper.likeLeft(DistributionSplitOrderAllTaskEntity::getOrderCode, distributionSplitAllTaskSearchDTO.getOrderCode()); + } + if (distributionSplitAllTaskSearchDTO.getCreateTime() != null) { + queryWrapper.between(DistributionSplitOrderAllTaskEntity::getCreateTime, distributionSplitAllTaskSearchDTO.getCreateTime()[0], distributionSplitAllTaskSearchDTO.getCreateTime()[1]); + } + if (distributionSplitAllTaskSearchDTO.getOrderPackageCode() != null) { + DistributionSplitOrderDetailEntity detail = distributionSplitOrderDetailService.getOne(Wrappers.lambdaQuery() + .eq(DistributionSplitOrderDetailEntity::getOrderPackageCode, distributionSplitAllTaskSearchDTO.getOrderPackageCode()) + ); + if (detail == null) { + return R.data(page); + } + queryWrapper.eq(DistributionSplitOrderAllTaskEntity::getId, detail.getSplitOrderAllTaskId()); + } + distributionSplitOrderAllTaskService.list(page, queryWrapper); - return null; + return R.data(page); } @Override