|
|
|
@ -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); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|