|
|
|
@ -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 |
|
|
|
|