Browse Source

新增拆单创建修改逻辑

dist.1.3.0
chenlong 5 months ago
parent
commit
702748ef5b
  1. 34
      blade-biz-common/src/main/java/org/springblade/common/constant/orderpackage/OrderPackageSplitStateConstant.java
  2. 15
      blade-service-api/logpm-distribution-api/src/main/java/com/logpm/distribution/entity/DistributionSplitOrderDetailEntity.java
  3. 42
      blade-service-api/logpm-distribution-api/src/main/java/com/logpm/distribution/entity/DistributionSplitOrderTaskEntity.java
  4. 7
      blade-service/logpm-distribution/src/main/java/com/logpm/distribution/mapper/DistributionSplitOrderDetailMapper.java
  5. 8
      blade-service/logpm-distribution/src/main/java/com/logpm/distribution/mapper/DistributionSplitOrderLogMapper.java
  6. 13
      blade-service/logpm-distribution/src/main/java/com/logpm/distribution/service/IDistributionSplitOrderDetailService.java
  7. 20
      blade-service/logpm-distribution/src/main/java/com/logpm/distribution/service/IDistributionSplitOrderLogService.java
  8. 7
      blade-service/logpm-distribution/src/main/java/com/logpm/distribution/service/IDistributionSplitOrderTaskService.java
  9. 15
      blade-service/logpm-distribution/src/main/java/com/logpm/distribution/service/impl/DistributionSplitOrderDetailServiceImpl.java
  10. 17
      blade-service/logpm-distribution/src/main/java/com/logpm/distribution/service/impl/DistributionSplitOrderLogServiceImpl.java
  11. 404
      blade-service/logpm-distribution/src/main/java/com/logpm/distribution/service/impl/DistributionSplitOrderTaskServiceImpl.java

34
blade-biz-common/src/main/java/org/springblade/common/constant/orderpackage/OrderPackageSplitStateConstant.java

@ -0,0 +1,34 @@
package org.springblade.common.constant.orderpackage;
import lombok.Getter;
/**
* 包件拆单明细的状态
* 状态1=待拆单2=已拆单3=驳回拆单4=已撤回
*/
@Getter
public enum OrderPackageSplitStateConstant {
wait("待拆单",1),
finish("已拆单",2),
reject("驳回拆单",3),
cancel("已撤回",4);
private String name;
private Integer value;
private OrderPackageSplitStateConstant(String name, Integer value) {
this.name = name;
this.value = value;
}
public void setName(String name) {
this.name = name;
}
public void setValue(Integer value) {
this.value = value;
}
}

15
blade-service-api/logpm-distribution-api/src/main/java/com/logpm/distribution/entity/DistributionSplitOrderDetailEntity.java

@ -74,18 +74,33 @@ public class DistributionSplitOrderDetailEntity extends TenantEntity {
@ApiModelProperty(value = "预留5")
private String reserve5;
/**
* 任务ID
*/
@ApiModelProperty(value = "任务ID")
private Long splitOrderTaskId;
/**
* 包条
*/
@ApiModelProperty(value = "包条")
private String orderPackageCode;
/**
* 状态1=待拆单2=已拆单3=驳回拆单4=已撤回
*/
@ApiModelProperty(value = "状态:1=待拆单,2=已拆单,3=驳回拆单,4=已撤回")
private Integer state;
/**
* 撤回人员ID
*/
@ApiModelProperty(value = "撤回人员ID")
private Long cancelUser;
/**
* 撤回人员
*/
@ApiModelProperty(value = "撤回人员")
private String cancelUsername;
}

42
blade-service-api/logpm-distribution-api/src/main/java/com/logpm/distribution/entity/DistributionSplitOrderTaskEntity.java

@ -77,49 +77,91 @@ public class DistributionSplitOrderTaskEntity extends TenantEntity {
@ApiModelProperty(value = "预留5")
private String reserve5;
/**
* 被拆订单ID
*/
@NotBlank(message = "被拆订单ID不能为空")
@ApiModelProperty(value = "被拆订单ID")
private Long stockArticleId;
/**
* 被拆订单
*/
@ApiModelProperty(value = "被拆订单")
private String orderCode;
/**
* 商场名称
*/
@ApiModelProperty(value = "商场名称")
private String mallName;
/**
* 状态1=待审核2=同意拆单3=驳回拆单4=撤回
*/
@ApiModelProperty(value = "状态:1=待审核,2=同意拆单,3=驳回拆单,4=撤回")
private Integer state;
/**
* 原因
*/
@ApiModelProperty(value = "原因")
private String reason;
/**
* 审核人
*/
@ApiModelProperty(value = "审核人")
private Long reviewerUser;
/**
* 审核人名字
*/
@ApiModelProperty(value = "审核人名字")
private String reviewerUsername;
/**
* 审核时间
*/
@ApiModelProperty(value = "审核时间")
private String reviewTime;
/**
* 拆单数量
*/
@ApiModelProperty(value = "拆单数量")
private Integer number;
/**
* 新的客户姓名
*/
@NotBlank(message = "新的客户姓名不能为空")
@ApiModelProperty(value = "新的客户姓名")
private String customerName;
/**
* 新的客户联系方式
*/
@NotBlank(message = "新的客户联系方式不能为空")
@ApiModelProperty(value = "新的客户联系方式")
private String customerTelephone;
/**
* 新的客户地址
*/
@NotBlank(message = "新的客户地址不能为空")
@ApiModelProperty(value = "新的客户地址")
private String customerAddress;
/**
* 新的订单
*/
@ApiModelProperty(value = "新的订单")
private String newOrderCode;
/**
* 新的订单ID
*/
@ApiModelProperty(value = "新的订单ID")
private Long newStockArticleId;

7
blade-service/logpm-distribution/src/main/java/com/logpm/distribution/mapper/DistributionSplitOrderDetailMapper.java

@ -0,0 +1,7 @@
package com.logpm.distribution.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.logpm.distribution.entity.DistributionSplitOrderDetailEntity;
public interface DistributionSplitOrderDetailMapper extends BaseMapper<DistributionSplitOrderDetailEntity> {
}

8
blade-service/logpm-distribution/src/main/java/com/logpm/distribution/mapper/DistributionSplitOrderLogMapper.java

@ -0,0 +1,8 @@
package com.logpm.distribution.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.logpm.distribution.entity.DistributionSplitOrderLogEntity;
public interface DistributionSplitOrderLogMapper extends BaseMapper<DistributionSplitOrderLogEntity> {
}

13
blade-service/logpm-distribution/src/main/java/com/logpm/distribution/service/IDistributionSplitOrderDetailService.java

@ -0,0 +1,13 @@
package com.logpm.distribution.service;
import com.logpm.distribution.entity.DistributionSplitOrderDetailEntity;
import org.springblade.core.mp.base.BaseService;
/**
* 拆单任务详情接口
*/
public interface IDistributionSplitOrderDetailService extends BaseService<DistributionSplitOrderDetailEntity> {
}

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

@ -0,0 +1,20 @@
package com.logpm.distribution.service;
import com.logpm.distribution.entity.DistributionSplitOrderLogEntity;
import com.logpm.distribution.entity.DistributionSplitOrderTaskEntity;
import org.springblade.core.mp.base.BaseService;
/**
* 拆单任务详情接口
*/
public interface IDistributionSplitOrderLogService extends BaseService<DistributionSplitOrderLogEntity> {
default void record(DistributionSplitOrderTaskEntity taskEntity, String content, String username) {
DistributionSplitOrderLogEntity distributionSplitOrderLogEntity = new DistributionSplitOrderLogEntity();
distributionSplitOrderLogEntity.setContent(content);
distributionSplitOrderLogEntity.setCreateUsername(username);
distributionSplitOrderLogEntity.setSplitOrderTaskId(taskEntity.getId());
save(distributionSplitOrderLogEntity);
}
}

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

@ -2,6 +2,7 @@ package com.logpm.distribution.service;
import com.logpm.distribution.entity.DistributionSplitOrderTaskEntity;
import org.springblade.core.mp.base.BaseService;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.api.R;
@ -10,7 +11,7 @@ import java.util.List;
/**
* 拆单任务接口
*/
public interface IDistributionSplitOrderTaskService {
public interface IDistributionSplitOrderTaskService extends BaseService<DistributionSplitOrderTaskEntity> {
/**
* 拆单任务列表
@ -44,10 +45,10 @@ public interface IDistributionSplitOrderTaskService {
/**
* 单个包撤回任务
* @param taskId
* @param packageCode
* @param packageCodes
* @return
*/
R<String> cancelPackageCode(Long taskId, String packageCode);
R<String> cancelPackageCode(Long taskId, List<String> packageCodes);
/**
* 审核任务

15
blade-service/logpm-distribution/src/main/java/com/logpm/distribution/service/impl/DistributionSplitOrderDetailServiceImpl.java

@ -0,0 +1,15 @@
package com.logpm.distribution.service.impl;
import com.logpm.distribution.entity.DistributionSplitOrderDetailEntity;
import com.logpm.distribution.mapper.DistributionSplitOrderDetailMapper;
import com.logpm.distribution.service.IDistributionSplitOrderDetailService;
import groovy.util.logging.Slf4j;
import lombok.AllArgsConstructor;
import org.springblade.core.mp.base.BaseServiceImpl;
import org.springframework.stereotype.Service;
@AllArgsConstructor
@Slf4j
@Service
public class DistributionSplitOrderDetailServiceImpl extends BaseServiceImpl<DistributionSplitOrderDetailMapper, DistributionSplitOrderDetailEntity> implements IDistributionSplitOrderDetailService {
}

17
blade-service/logpm-distribution/src/main/java/com/logpm/distribution/service/impl/DistributionSplitOrderLogServiceImpl.java

@ -0,0 +1,17 @@
package com.logpm.distribution.service.impl;
import com.logpm.distribution.entity.DistributionSplitOrderLogEntity;
import com.logpm.distribution.entity.DistributionSplitOrderTaskEntity;
import com.logpm.distribution.mapper.DistributionSplitOrderLogMapper;
import com.logpm.distribution.service.IDistributionSplitOrderLogService;
import groovy.util.logging.Slf4j;
import lombok.AllArgsConstructor;
import org.springblade.core.mp.base.BaseServiceImpl;
import org.springframework.stereotype.Service;
@AllArgsConstructor
@Slf4j
@Service
public class DistributionSplitOrderLogServiceImpl extends BaseServiceImpl<DistributionSplitOrderLogMapper, DistributionSplitOrderLogEntity> implements IDistributionSplitOrderLogService {
}

404
blade-service/logpm-distribution/src/main/java/com/logpm/distribution/service/impl/DistributionSplitOrderTaskServiceImpl.java

@ -1,69 +1,441 @@
package com.logpm.distribution.service.impl;
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.mapper.DistributionSplitOrderTaskMapper;
import com.logpm.distribution.service.IDistributionSplitOrderTaskService;
import com.logpm.distribution.service.*;
import groovy.util.logging.Slf4j;
import lombok.AllArgsConstructor;
import org.springblade.common.constant.orderpackage.OrderPackageReservationStatusConstant;
import org.springblade.common.constant.orderpackage.OrderPackageSplitStateConstant;
import org.springblade.core.mp.base.BaseServiceImpl;
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.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
@Service
@AllArgsConstructor
@Slf4j
public class DistributionSplitOrderTaskServiceImpl extends BaseServiceImpl<DistributionSplitOrderTaskMapper, DistributionSplitOrderTaskEntity> implements IDistributionSplitOrderTaskService {
private DistributionStockArticleServiceImpl distributionStockArticleService;
private DistributionParcelListServiceImpl distributionParcelListService;
private final IDistributionStockArticleService distributionStockArticleService;
private final IDistributionParcelListService distributionParcelListService;
private final IDistributionSplitOrderDetailService distributionSplitOrderDetailService;
private final IDistributionSplitOrderLogService distributionSplitOrderLogService;
private final RedisLockClient redisLockClient;
@Override
public R<List<DistributionSplitOrderTaskEntity>> taskList(Query query, DistributionSplitOrderTaskEntity distributionSplitOrderTaskEntity) {
return null;
}
@Transactional
@Override
public R<String> createTask(DistributionSplitOrderTaskEntity distributionSplitOrderTaskEntity, List<String> packageCodeList) {
try {
DistributionStockArticleEntity distributionStockArticle = distributionStockArticleService.getById(distributionSplitOrderTaskEntity.getStockArticleId());
if (distributionStockArticle == null) {
return R.fail("原订单信息错误");
}
List<DistributionParcelListEntity> packageCode = distributionParcelListService.list(Wrappers.<DistributionParcelListEntity>lambdaQuery()
List<DistributionParcelListEntity> belongsToOrder = distributionParcelListService.list(Wrappers.<DistributionParcelListEntity>lambdaQuery()
.eq(DistributionParcelListEntity::getStockArticleId, distributionSplitOrderTaskEntity.getStockArticleId())
.in(DistributionParcelListEntity::getOrderPackageCode, packageCodeList)
);
if (packageCode.size() != packageCodeList.size()) {
return R.fail("订单包件信息错误");
if (belongsToOrder.size() != packageCodeList.size()) {
List<String> belongsToOrderPackage = belongsToOrder.stream().map(DistributionParcelListEntity::getOrderPackageCode).collect(Collectors.toList());
return R.fail(String.format("订单包件信息错误,选择的包件(%s)不属于该订单", packageCodeList.stream()
.filter(packageCode -> !belongsToOrderPackage.contains(packageCode))
.collect(Collectors.joining(","))
));
}
List<DistributionParcelListEntity> reservationsPackageList = belongsToOrder.stream()
.filter(distributionParcelListEntity -> OrderPackageReservationStatusConstant.yiyueyue.getValue().equals(distributionParcelListEntity.getOrderPackageReservationStatus()))
.collect(Collectors.toList());
if (!reservationsPackageList.isEmpty()) {
return R.fail(String.format("订单包件:%s,已被预约,无法拆单", reservationsPackageList.stream()
.map(DistributionParcelListEntity::getOrderPackageCode)
.collect(Collectors.joining(","))
));
}
int leaseTime = 10000;
String key = "lock:splitOrderTask:create" + distributionSplitOrderTaskEntity.getStockArticleId();
boolean lockRes = redisLockClient.tryLock(key, LockType.FAIR, 5000, leaseTime, TimeUnit.MILLISECONDS);
if (!lockRes) {
return R.fail("拆单任务繁忙,请重试");
}
long currentTimeMillis = System.currentTimeMillis();
return R.data("");
saveNewTask(distributionSplitOrderTaskEntity, distributionStockArticle, belongsToOrder);
distributionSplitOrderLogService.record(distributionSplitOrderTaskEntity, "拆单任务创建", AuthUtil.getUser().getUserName());
if (System.currentTimeMillis() - currentTimeMillis < leaseTime) {
redisLockClient.unLock(key, LockType.FAIR);
}
return R.data("success");
} catch (Exception e) {
log.error("createTask error", e);
return R.fail("createTask error");
}
}
public void saveNewTask(DistributionSplitOrderTaskEntity distributionSplitOrderTaskEntity, DistributionStockArticleEntity distributionStockArticle, List<DistributionParcelListEntity> belongsToOrder){
/*
* 避免审核期间的数据被操作且无法去其他节点修改所以第一时间分配新的订单
*/
String newOrderCode = getNewOrderCode(distributionStockArticle.getOrderCode(), distributionStockArticle.getId());
DistributionStockArticleEntity newStockArticle = SerializationUtils.clone(distributionStockArticle);
newStockArticle.setId(null);
newStockArticle.setOrderCode(newOrderCode);
newStockArticle.setTotalNumber(belongsToOrder.size());
newStockArticle.setHandQuantity(belongsToOrder.size());
distributionStockArticleService.save(newStockArticle);
distributionStockArticle.setTotalNumber(distributionStockArticle.getTotalNumber() - belongsToOrder.size());
distributionStockArticle.setHandQuantity(distributionStockArticle.getHandQuantity() - belongsToOrder.size());
if (distributionStockArticle.getTotalNumber() == 0) {
distributionStockArticleService.removeById(distributionStockArticle.getId());
}else{
distributionStockArticleService.updateById(distributionStockArticle);
}
List<Long> detailIds = belongsToOrder.stream().map(DistributionParcelListEntity::getId).collect(Collectors.toList());
distributionParcelListService.update(Wrappers.<DistributionParcelListEntity>lambdaUpdate()
.in(DistributionParcelListEntity::getId, detailIds)
.set(DistributionParcelListEntity::getStockArticleId, newStockArticle.getId())
.set(DistributionParcelListEntity::getOrderCode, newStockArticle.getOrderCode())
);
distributionSplitOrderTaskEntity.setNewOrderCode(newOrderCode);
distributionSplitOrderTaskEntity.setNewStockArticleId(newStockArticle.getId());
distributionSplitOrderTaskEntity.setNumber(belongsToOrder.size());
distributionSplitOrderTaskEntity.setMallName(newStockArticle.getMallName());
save(distributionSplitOrderTaskEntity);
List<DistributionSplitOrderDetailEntity> details = new ArrayList<>(belongsToOrder.size());
belongsToOrder.forEach(distributionParcelListEntity -> {
DistributionSplitOrderDetailEntity detail = new DistributionSplitOrderDetailEntity();
detail.setOrderPackageCode(distributionParcelListEntity.getOrderPackageCode());
detail.setSplitOrderTaskId(distributionSplitOrderTaskEntity.getId());
detail.setState(OrderPackageSplitStateConstant.wait.getValue());
details.add(detail);
});
distributionSplitOrderDetailService.saveBatch(details);
}
@Transactional
@Override
public R<String> updateTask(DistributionSplitOrderTaskEntity distributionSplitOrderTaskEntity, List<String> packageCodeList) {
return null;
try {
DistributionSplitOrderTaskEntity task = getById(distributionSplitOrderTaskEntity.getId());
if (task == null) {
return R.fail("拆单任务不存在");
}
if (!task.getStockArticleId().equals(distributionSplitOrderTaskEntity.getStockArticleId())) {
return R.fail("拆单任务订单ID不一致");
}
DistributionStockArticleEntity distributionStockArticle = distributionStockArticleService.getById(distributionSplitOrderTaskEntity.getStockArticleId());
if (distributionStockArticle == null) {
return R.fail("原订单信息错误");
}
ArrayList<Long> StockArticleIds = new ArrayList<>();
StockArticleIds.add(distributionSplitOrderTaskEntity.getStockArticleId());
StockArticleIds.add(task.getNewStockArticleId());
List<DistributionParcelListEntity> belongsToOrder = distributionParcelListService.list(Wrappers.<DistributionParcelListEntity>lambdaQuery()
.in(DistributionParcelListEntity::getStockArticleId, StockArticleIds)
.in(DistributionParcelListEntity::getOrderPackageCode, packageCodeList)
);
if (belongsToOrder.size() != packageCodeList.size()) {
List<String> belongsToOrderPackage = belongsToOrder.stream().map(DistributionParcelListEntity::getOrderPackageCode).collect(Collectors.toList());
return R.fail(String.format("订单包件信息错误,选择的包件(%s)不属于该订单", packageCodeList.stream()
.filter(packageCode -> !belongsToOrderPackage.contains(packageCode))
.collect(Collectors.joining(","))
));
}
List<DistributionParcelListEntity> reservationsPackageList = belongsToOrder.stream()
.filter(distributionParcelListEntity -> OrderPackageReservationStatusConstant.yiyueyue.getValue().equals(distributionParcelListEntity.getOrderPackageReservationStatus()))
.collect(Collectors.toList());
if (!reservationsPackageList.isEmpty()) {
return R.fail(String.format("订单包件:%s,已被预约,无法拆单", reservationsPackageList.stream()
.map(DistributionParcelListEntity::getOrderPackageCode)
.collect(Collectors.joining(","))
));
}
DistributionStockArticleEntity newStockArticle = distributionStockArticleService.getById(distributionSplitOrderTaskEntity.getNewStockArticleId());
if (newStockArticle == null) {
return R.fail("新订单信息错误");
}
updateTask(distributionSplitOrderTaskEntity, distributionStockArticle, belongsToOrder, newStockArticle);
distributionSplitOrderLogService.record(distributionSplitOrderTaskEntity, "拆单任务修改", AuthUtil.getUser().getUserName());
return R.data("success");
} catch (Exception e) {
log.error("updateTask error", e);
return R.fail("修改失败");
}
}
private void updateTask(DistributionSplitOrderTaskEntity distributionSplitOrderTaskEntity, DistributionStockArticleEntity distributionStockArticle, List<DistributionParcelListEntity> belongsToOrder, DistributionStockArticleEntity newStockArticle){
distributionSplitOrderTaskEntity.setNumber(belongsToOrder.size());
updateById(distributionSplitOrderTaskEntity);
newStockArticle.setTotalNumber(belongsToOrder.size());
newStockArticle.setHandQuantity(belongsToOrder.size());
distributionStockArticleService.save(newStockArticle);
packageUpdate(distributionSplitOrderTaskEntity, distributionStockArticle, belongsToOrder);
distributionStockArticle.setTotalNumber(distributionStockArticle.getTotalNumber() - belongsToOrder.size());
distributionStockArticle.setHandQuantity(distributionStockArticle.getHandQuantity() - belongsToOrder.size());
if (distributionStockArticle.getTotalNumber() == 0) {
distributionStockArticleService.removeById(distributionStockArticle.getId());
}else{
distributionStockArticleService.updateById(distributionStockArticle);
}
}
private void packageUpdate(DistributionSplitOrderTaskEntity distributionSplitOrderTaskEntity, DistributionStockArticleEntity distributionStockArticle, List<DistributionParcelListEntity> belongsToOrder) {
List<DistributionSplitOrderDetailEntity> taskJoinPackage = distributionSplitOrderDetailService.list(Wrappers.<DistributionSplitOrderDetailEntity>lambdaQuery()
.eq(DistributionSplitOrderDetailEntity::getSplitOrderTaskId, distributionSplitOrderTaskEntity.getId())
);
List<String> taskJoinPackageList = taskJoinPackage.stream().map(DistributionSplitOrderDetailEntity::getOrderPackageCode).collect(Collectors.toList());
List<DistributionParcelListEntity> add = belongsToOrder.stream().filter(distributionParcelListEntity ->
distributionParcelListEntity.getOrderCode().equals(distributionStockArticle.getOrderCode())
&& !taskJoinPackageList.contains(distributionParcelListEntity.getOrderPackageCode())
).collect(Collectors.toList());
if (!add.isEmpty()) {
List<Long> ids = add.stream().map(DistributionParcelListEntity::getId).collect(Collectors.toList());
distributionParcelListService.update(Wrappers.<DistributionParcelListEntity>lambdaUpdate()
.in(DistributionParcelListEntity::getId, ids)
.set(DistributionParcelListEntity::getStockArticleId, distributionSplitOrderTaskEntity.getNewStockArticleId())
.set(DistributionParcelListEntity::getOrderCode, distributionSplitOrderTaskEntity.getNewOrderCode())
);
List<DistributionSplitOrderDetailEntity> details = new ArrayList<>(add.size());
add.forEach(distributionParcelListEntity -> {
DistributionSplitOrderDetailEntity detail = new DistributionSplitOrderDetailEntity();
detail.setOrderPackageCode(distributionParcelListEntity.getOrderPackageCode());
detail.setSplitOrderTaskId(distributionSplitOrderTaskEntity.getId());
detail.setState(OrderPackageSplitStateConstant.wait.getValue());
details.add(detail);
});
distributionSplitOrderDetailService.saveBatch(details);
}
List<DistributionParcelListEntity> recover = belongsToOrder.stream().filter(distributionParcelListEntity ->
distributionParcelListEntity.getOrderCode().equals(distributionStockArticle.getOrderCode())
&& taskJoinPackageList.contains(distributionParcelListEntity.getOrderPackageCode())
).collect(Collectors.toList());
if (!recover.isEmpty()) {
List<Long> ids = recover.stream().map(DistributionParcelListEntity::getId).collect(Collectors.toList());
distributionParcelListService.update(Wrappers.<DistributionParcelListEntity>lambdaUpdate()
.in(DistributionParcelListEntity::getId, ids)
.set(DistributionParcelListEntity::getStockArticleId, distributionSplitOrderTaskEntity.getStockArticleId())
.set(DistributionParcelListEntity::getOrderCode, distributionSplitOrderTaskEntity.getOrderCode())
);
distributionSplitOrderDetailService.update(Wrappers.<DistributionSplitOrderDetailEntity>lambdaUpdate()
.eq(DistributionSplitOrderDetailEntity::getSplitOrderTaskId, distributionSplitOrderTaskEntity.getId())
.in(DistributionSplitOrderDetailEntity::getOrderPackageCode, recover.stream().map(DistributionParcelListEntity::getOrderPackageCode).collect(Collectors.toList()))
.set(DistributionSplitOrderDetailEntity::getState, OrderPackageSplitStateConstant.wait.getValue())
);
}
List<String> currentPackage = belongsToOrder.stream().map(DistributionParcelListEntity::getOrderPackageCode).collect(Collectors.toList());
List<DistributionSplitOrderDetailEntity> remove = taskJoinPackage.stream().filter(distributionSplitOrderDetailEntity ->
!currentPackage.contains(distributionSplitOrderDetailEntity.getOrderPackageCode())
&& !OrderPackageSplitStateConstant.wait.getValue().equals(distributionSplitOrderDetailEntity.getState())
).collect(Collectors.toList());
if (!remove.isEmpty()) {
List<Long> ids = remove.stream().map(DistributionSplitOrderDetailEntity::getId).collect(Collectors.toList());
distributionSplitOrderDetailService.update(Wrappers.<DistributionSplitOrderDetailEntity>lambdaUpdate().in(
DistributionSplitOrderDetailEntity::getId, ids
).set(DistributionSplitOrderDetailEntity::getState, OrderPackageSplitStateConstant.cancel.getValue()));
}
}
@Transactional
@Override
public R<String> cancelTask(Long taskId) {
return null;
try {
DistributionSplitOrderTaskEntity task = getById(taskId);
if (task == 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("订单错误,无法取消");
}
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("新的订单包件已预约,无法取消");
}
distributionParcelListService.update(Wrappers.<DistributionParcelListEntity>lambdaUpdate()
.eq(DistributionParcelListEntity::getStockArticleId, task.getNewStockArticleId())
.set(DistributionParcelListEntity::getStockArticleId, task.getStockArticleId())
.set(DistributionParcelListEntity::getOrderCode, task.getOrderCode())
);
newStockArticle.setTotalNumber(0);
newStockArticle.setHandQuantity(0);
newStockArticle.setHandQuantity(1);
distributionStockArticleService.updateById(newStockArticle);
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())
.set(DistributionSplitOrderDetailEntity::getCancelUser, AuthUtil.getUser().getUserId())
.set(DistributionSplitOrderDetailEntity::getCancelUsername, AuthUtil.getUser().getUserName())
);
distributionSplitOrderLogService.record(task, "取消拆单任务", AuthUtil.getUser().getUserName());
return R.success("success");
} catch (Exception e) {
log.error("取消拆单任务失败", e);
return R.fail("取消拆单任务失败");
}
}
@Transactional
@Override
public R<String> cancelPackageCode(Long taskId, String packageCode) {
return null;
public R<String> cancelPackageCode(Long taskId, List<String> packageCodes) {
try {
DistributionSplitOrderTaskEntity task = getById(taskId);
if (task == null) {
return R.fail("拆单任务不存在");
}
if (task.getNumber() == packageCodes.size()) {
return cancelTask(taskId);
}
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("新的订单包件已预约,无法取消");
}
List<DistributionSplitOrderDetailEntity> detail = distributionSplitOrderDetailService.list(Wrappers.<DistributionSplitOrderDetailEntity>lambdaQuery()
.eq(DistributionSplitOrderDetailEntity::getSplitOrderTaskId, taskId)
.in(DistributionSplitOrderDetailEntity::getOrderPackageCode, packageCodes)
);
long cancelCount = detail.stream().filter(distributionSplitOrderDetailEntity ->
OrderPackageSplitStateConstant.cancel.getValue().equals(distributionSplitOrderDetailEntity.getState())
|| OrderPackageSplitStateConstant.reject.getValue().equals(distributionSplitOrderDetailEntity.getState())
).count();
if (cancelCount > 0) {
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("订单错误,无法取消");
}
oldStockArticle.setIsDeleted(0);
}
distributionParcelListService.update(Wrappers.<DistributionParcelListEntity>lambdaUpdate()
.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())
);
task.setNumber(task.getNumber() - packageCodes.size());
updateById(task);
newStockArticle.setTotalNumber(newStockArticle.getTotalNumber() - packageCodes.size());
newStockArticle.setHandQuantity(newStockArticle.getHandQuantity() - packageCodes.size());
distributionStockArticleService.updateById(newStockArticle);
oldStockArticle.setTotalNumber(oldStockArticle.getTotalNumber() + newStockArticle.getTotalNumber());
oldStockArticle.setHandQuantity(oldStockArticle.getHandQuantity() + newStockArticle.getHandQuantity());
distributionStockArticleService.updateById(oldStockArticle);
distributionSplitOrderLogService.record(task, String.format("取消包件:%s", String.join(",", packageCodes)), AuthUtil.getUser().getUserName());
return R.success("success");
} catch (Exception e) {
log.error("拆单任务不存在", e);
return R.fail("系统错误");
}
}
@Override
@ -75,4 +447,14 @@ public class DistributionSplitOrderTaskServiceImpl extends BaseServiceImpl<Distr
public R<Object> getTaskDetail(Long taskId) {
return null;
}
private String getNewOrderCode(String oldOrderCode, Long oldStockArticleId) {
long count = count(Wrappers.<DistributionSplitOrderTaskEntity>lambdaQuery().eq(
DistributionSplitOrderTaskEntity::getStockArticleId, oldStockArticleId
));
return oldOrderCode + "-拆" + (count + 1);
}
}

Loading…
Cancel
Save