Browse Source

拆单任务创建,修改,撤销,完成

dist.1.3.0
chenlong 5 months ago
parent
commit
f87c7dbec6
  1. 2
      blade-biz-common/src/main/java/org/springblade/common/constant/order/OrderSplitStateConstant.java
  2. 6
      blade-service-api/logpm-distribution-api/src/main/java/com/logpm/distribution/entity/DistributionSplitOrderLogEntity.java
  3. 18
      blade-service-api/logpm-distribution-api/src/main/java/com/logpm/distribution/entity/DistributionSplitOrderTaskEntity.java
  4. 36
      blade-service/logpm-distribution/src/main/java/com/logpm/distribution/dto/splitOrder/DistributionSplitAllTaskSearchDTO.java
  5. 46
      blade-service/logpm-distribution/src/main/java/com/logpm/distribution/dto/splitOrder/DistributionSplitTaskSearchDTO.java
  6. 2
      blade-service/logpm-distribution/src/main/java/com/logpm/distribution/service/IDistributionSplitOrderLogService.java
  7. 51
      blade-service/logpm-distribution/src/main/java/com/logpm/distribution/service/IDistributionSplitOrderTaskService.java
  8. 407
      blade-service/logpm-distribution/src/main/java/com/logpm/distribution/service/impl/DistributionSplitOrderTaskServiceImpl.java

2
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;

6
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;

18
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;
/**
* 任务拆单数量

36
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;
}

46
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;
}

2
blade-service/logpm-distribution/src/main/java/com/logpm/distribution/service/IDistributionSplitOrderLogService.java

@ -14,7 +14,9 @@ public interface IDistributionSplitOrderLogService extends BaseService<Distribut
DistributionSplitOrderLogEntity distributionSplitOrderLogEntity = new DistributionSplitOrderLogEntity();
distributionSplitOrderLogEntity.setContent(content);
distributionSplitOrderLogEntity.setCreateUsername(username);
distributionSplitOrderLogEntity.setOrderCode(taskEntity.getOrderCode());
distributionSplitOrderLogEntity.setSplitOrderTaskId(taskEntity.getId());
distributionSplitOrderLogEntity.setSplitOrderAllTaskId(taskEntity.getSplitOrderAllTaskId());
save(distributionSplitOrderLogEntity);
}
}

51
blade-service/logpm-distribution/src/main/java/com/logpm/distribution/service/IDistributionSplitOrderTaskService.java

@ -1,6 +1,10 @@
package com.logpm.distribution.service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.logpm.distribution.dto.splitOrder.DistributionSplitAllTaskSearchDTO;
import com.logpm.distribution.dto.splitOrder.DistributionSplitTaskSearchDTO;
import com.logpm.distribution.entity.DistributionSplitOrderAllTaskEntity;
import com.logpm.distribution.entity.DistributionSplitOrderTaskEntity;
import org.springblade.core.mp.base.BaseService;
import org.springblade.core.mp.support.Query;
@ -16,14 +20,23 @@ public interface IDistributionSplitOrderTaskService extends BaseService<Distribu
/**
* 拆单任务列表
* @param query
* @param distributionSplitOrderTaskEntity
* @param distributionSplitTaskSearchDTO
* @return
*/
R<List<DistributionSplitOrderTaskEntity>> taskList(Query query, DistributionSplitOrderTaskEntity distributionSplitOrderTaskEntity);
R<IPage<DistributionSplitOrderTaskEntity>> taskList(Query query, DistributionSplitTaskSearchDTO distributionSplitTaskSearchDTO);
/**
* 拆单总任务
* @param query
* @param distributionSplitAllTaskSearchDTO
* @return
*/
R<IPage<DistributionSplitOrderAllTaskEntity>> allTaskList(Query query, DistributionSplitAllTaskSearchDTO distributionSplitAllTaskSearchDTO);
/**
* 创建任务
* @param distributionSplitOrderTaskEntity
* @param packageCodeList
* @return
*/
R<String> createTask(DistributionSplitOrderTaskEntity distributionSplitOrderTaskEntity, List<String> packageCodeList);
@ -38,16 +51,25 @@ public interface IDistributionSplitOrderTaskService extends BaseService<Distribu
/**
* 更新任务
* @param distributionSplitOrderTaskEntity
* @param packageCodeList
* @return
*/
R<String> updateTask(DistributionSplitOrderTaskEntity distributionSplitOrderTaskEntity, List<String> packageCodeList);
/**
* 整单撤回任务
* 添加包码
* @param taskId
* @param packageCode
* @return
*/
R<String> cancelTask(Long taskId);
R<String> addPackageCode(Long taskId, List<String> packageCode);
/**
* 删除任务
* @param taskId
* @return
*/
R<String> deleteTask(Long taskId);
/**
* 单个包撤回任务
@ -58,16 +80,29 @@ public interface IDistributionSplitOrderTaskService extends BaseService<Distribu
R<String> cancelPackageCode(Long taskId, List<String> packageCodes);
/**
* 审核任务
* 获取任务详情
* @param taskId
* @return
*/
R<String> reviewTask(Long taskId, Integer reviewStatus, String reason);
R<Object> getTaskDetail(Long taskId);
/**
* 获取任务详情
* 完成任务
* @param taskId
* @return
*/
R<Object> getTaskDetail(Long taskId);
R<String> finishTask(Long taskId);
/**
* 撤回任务
* @param taskId
* @return
*/
R<String> cancelTask(Long taskId);
R<String> cancelAllTask(Long allTaskId);
R<String> finishAllTask(Long allTaskId);
R<String> deleteAllTask(Long allTaskId);
}

407
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<Distr
@Override
public R<List<DistributionSplitOrderTaskEntity>> taskList(Query query, DistributionSplitOrderTaskEntity distributionSplitOrderTaskEntity) {
public R<IPage<DistributionSplitOrderTaskEntity>> taskList(Query query, DistributionSplitTaskSearchDTO distributionSplitTaskSearchDTO) {
return null;
}
@ -70,15 +76,7 @@ public class DistributionSplitOrderTaskServiceImpl extends BaseServiceImpl<Distr
for (DistributionSplitOrderTaskEntity distributionSplitOrderTaskEntity : distributionSplitOrderTaskList) {
String newOrderCode = getNewOrderCode(distributionSplitOrderTaskEntity.getOrderCode(), currentNumber++);
DistributionStockArticleEntity newStockArticle = SerializationUtils.clone(distributionStockArticle);
newStockArticle.setId(null);
newStockArticle.setOrderCode(newOrderCode);
newStockArticle.setTotalNumber(0);
newStockArticle.setHandQuantity(0);
distributionStockArticleService.save(newStockArticle);
distributionSplitOrderTaskEntity.setNewOrderCode(newOrderCode);
distributionSplitOrderTaskEntity.setNewStockArticleId(newStockArticle.getId());
save(distributionSplitOrderTaskEntity);
distributionSplitOrderLogService.record(distributionSplitOrderTaskEntity, "创建拆单任务", AuthUtil.getUser().getUserName());
}
@ -95,6 +93,83 @@ public class DistributionSplitOrderTaskServiceImpl extends BaseServiceImpl<Distr
return R.success("success");
}
@Transactional
@Override
public R<String> addPackageCode(Long taskId, List<String> packageCodes) {
DistributionSplitOrderTaskEntity task = getById(taskId);
if (task == null) {
return R.fail("拆单任务不存在");
}
if (!task.getState().equals(OrderSplitTaskStateConstant.InProgress.getValue())) {
return R.fail("拆单任务已完成,无法添加");
}
try {
List<DistributionSplitOrderDetailEntity> existsList = distributionSplitOrderDetailService.list(Wrappers.<DistributionSplitOrderDetailEntity>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<Long> 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.<DistributionSplitOrderDetailEntity>lambdaUpdate()
.in(DistributionSplitOrderDetailEntity::getId, cancelIds)
.set(DistributionSplitOrderDetailEntity::getState, OrderPackageSplitStateConstant.finish.getValue())
.set(DistributionSplitOrderDetailEntity::getSplitOrderTaskId, task.getId())
.set(DistributionSplitOrderDetailEntity::getSplitOrderAllTaskId, task.getSplitOrderAllTaskId())
);
}
ArrayList<DistributionSplitOrderDetailEntity> details = new ArrayList<>();
List<String> 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<String> createTask(DistributionSplitOrderTaskEntity distributionSplitOrderTaskEntity, List<String> packageCodeList) {
@ -361,35 +436,35 @@ public class DistributionSplitOrderTaskServiceImpl extends BaseServiceImpl<Distr
@Transactional
@Override
public R<String> cancelTask(Long taskId) {
public R<String> 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.<DistributionStockArticleEntity>lambdaQuery()
.eq(DistributionStockArticleEntity::getId, task.getStockArticleId())
.eq(DistributionStockArticleEntity::getIsDeleted, 1)
);
if (oldStockArticle == null) {
return R.fail("订单错误,无法取消");
return R.fail("订单错误,无法删除");
}
oldStockArticle.setIsDeleted(0);
}
List<DistributionParcelListEntity> packageList = distributionParcelListService.list(Wrappers.<DistributionParcelListEntity>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 BaseServiceImpl<Distr
.set(DistributionParcelListEntity::getOrderCode, task.getOrderCode())
);
newStockArticle.setTotalNumber(0);
newStockArticle.setHandQuantity(0);
newStockArticle.setHandQuantity(1);
distributionStockArticleService.updateById(newStockArticle);
if (newStockArticle != null) {
newStockArticle.setTotalNumber(0);
newStockArticle.setHandQuantity(0);
distributionStockArticleService.updateById(newStockArticle);
oldStockArticle.setTotalNumber(oldStockArticle.getTotalNumber() + newStockArticle.getTotalNumber());
oldStockArticle.setHandQuantity(oldStockArticle.getHandQuantity() + newStockArticle.getHandQuantity());
}
oldStockArticle.setTotalNumber(oldStockArticle.getTotalNumber() + newStockArticle.getTotalNumber());
oldStockArticle.setHandQuantity(oldStockArticle.getHandQuantity() + newStockArticle.getHandQuantity());
distributionStockArticleService.updateById(oldStockArticle);
task.setState(OrderPackageSplitStateConstant.cancel.getValue());
updateById(task);
distributionSplitOrderDetailService.update(Wrappers.<DistributionSplitOrderDetailEntity>lambdaUpdate()
.eq(DistributionSplitOrderDetailEntity::getSplitOrderTaskId, taskId)
.set(DistributionSplitOrderDetailEntity::getState, OrderPackageSplitStateConstant.cancel.getValue())
@ -420,6 +493,14 @@ public class DistributionSplitOrderTaskServiceImpl extends BaseServiceImpl<Distr
);
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);
return R.success("success");
} catch (Exception e) {
log.error("取消拆单任务系统错误", e);
@ -435,89 +516,255 @@ public class DistributionSplitOrderTaskServiceImpl extends BaseServiceImpl<Distr
return R.fail("拆单任务不存在");
}
if (task.getNumber() == packageCodes.size()) {
distributionSplitOrderLogService.record(task, String.format("取消包件:%s", String.join(",", packageCodes)), AuthUtil.getUser().getUserName());
return cancelTask(taskId);
long count = distributionSplitOrderDetailService.count(Wrappers.<DistributionSplitOrderDetailEntity>lambdaQuery()
.in(DistributionSplitOrderDetailEntity::getOrderPackageCode, packageCodes)
.eq(DistributionSplitOrderDetailEntity::getSplitOrderTaskId, taskId)
);
if (count != packageCodes.size()) {
return R.fail("包件信息错误,包含错误的包件,无法取消");
}
List<DistributionParcelListEntity> packageList = distributionParcelListService.list(Wrappers.<DistributionParcelListEntity>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<DistributionSplitOrderDetailEntity> detail = distributionSplitOrderDetailService.list(Wrappers.<DistributionSplitOrderDetailEntity>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.<DistributionSplitOrderDetailEntity>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<String> finishTask(Long taskId) {
DistributionSplitOrderTaskEntity task = getById(taskId);
if (!task.getState().equals(OrderSplitStateConstant.InProgress.getValue())) {
return R.fail("任务已完成或已取消,无法操作");
}
if (oldStockArticle == null) {
oldStockArticle = distributionStockArticleService.getOne(Wrappers.<DistributionStockArticleEntity>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<DistributionSplitOrderDetailEntity> packageList = distributionSplitOrderDetailService.list(Wrappers.<DistributionSplitOrderDetailEntity>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.<DistributionParcelListEntity>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<String> 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<DistributionSplitOrderDetailEntity> packageList = distributionSplitOrderDetailService.list(Wrappers.<DistributionSplitOrderDetailEntity>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.<DistributionParcelListEntity>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.<DistributionSplitOrderDetailEntity>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<String> 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<String> 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<String> deleteAllTask(Long allTaskId) {
DistributionSplitOrderAllTaskEntity allTask = distributionSplitOrderAllTaskService.getById(allTaskId);
if (!allTask.getState().equals(OrderSplitStateConstant.InProgress.getValue())) {
return R.fail("拆单总任务已完成或已取消,无法操作");
}
try {
List<DistributionSplitOrderTaskEntity> list = list(Wrappers.<DistributionSplitOrderTaskEntity>lambdaQuery()
.eq(DistributionSplitOrderTaskEntity::getSplitOrderAllTaskId, allTaskId)
);
for (DistributionSplitOrderTaskEntity task : list) {
R<String> 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<String> reviewTask(Long taskId, Integer reviewStatus, String reason) {
public R<IPage<DistributionSplitOrderAllTaskEntity>> allTaskList(Query query, DistributionSplitAllTaskSearchDTO distributionSplitAllTaskSearchDTO) {
IPage<DistributionSplitOrderAllTaskEntity> page = Condition.getPage(query);
LambdaQueryWrapper<DistributionSplitOrderAllTaskEntity> 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.<DistributionSplitOrderDetailEntity>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

Loading…
Cancel
Save