refactor(wms): 优化调拨分包打印功能

-完善打印条件验证,确保只有出库数量等于调拨数量时才能打印
- 优化覆盖模式下的任务删除逻辑
- 重构代码结构,提高可读性和可维护性
- 增加日志记录,便于问题追踪和调试
master
zangch@mesnac.com 3 months ago
parent 475a583f8f
commit 0ec5aa88a9

@ -10,7 +10,9 @@ import org.dromara.common.core.utils.StringUtils;
import org.dromara.common.mybatis.core.page.PageQuery; import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo; import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.wms.domain.WmsAllocateTask; import org.dromara.wms.domain.WmsAllocateTask;
import org.dromara.wms.domain.bo.WmsAllocateOrderDetailBo;
import org.dromara.wms.domain.bo.WmsAllocateTaskBo; import org.dromara.wms.domain.bo.WmsAllocateTaskBo;
import org.dromara.wms.domain.vo.WmsAllocateOrderDetailVo;
import org.dromara.wms.domain.vo.WmsAllocateTaskVo; import org.dromara.wms.domain.vo.WmsAllocateTaskVo;
import org.dromara.wms.mapper.WmsAllocateTaskMapper; import org.dromara.wms.mapper.WmsAllocateTaskMapper;
import org.dromara.wms.service.IBaseMaterialInfoService; import org.dromara.wms.service.IBaseMaterialInfoService;
@ -165,7 +167,7 @@ public class WmsAllocateTaskServiceImpl implements IWmsAllocateTaskService {
} }
/** /**
* * -
* *
* @param allocateCode * @param allocateCode
* @param aoDId ID * @param aoDId ID
@ -184,22 +186,25 @@ public class WmsAllocateTaskServiceImpl implements IWmsAllocateTaskService {
throw new ServiceException("调拨明细不存在"); throw new ServiceException("调拨明细不存在");
} }
// 验证打印条件:只有出库数量等于调拨数量时才能打印
BigDecimal outSum = BigDecimal.valueOf(detailVo.getOutSum());
if (outSum.compareTo(detailVo.getAllocateOrderQty()) != 0) {
throw new ServiceException("只有出库数量等于调拨数量时才能打印,当前出库数量:" + outSum + ",调拨数量:" + detailVo.getAllocateOrderQty());
}
// 获取物料信息 // 获取物料信息
org.dromara.wms.domain.vo.BaseMaterialInfoVo materialInfoVo = null; org.dromara.wms.domain.vo.BaseMaterialInfoVo materialInfoVo = null;
if (detailVo.getMaterialId() != null) { if (detailVo.getMaterialId() != null) {
materialInfoVo = baseMaterialInfoService.queryById(detailVo.getMaterialId()); materialInfoVo = baseMaterialInfoService.queryById(detailVo.getMaterialId());
} }
// Web端覆盖模式如果已有打印记录删除再新增 // 覆盖模式:如果已有打印记录,强制删除再新增
List<WmsAllocateTaskVo> existingTasks = queryTasksByDetailId(aoDId); List<WmsAllocateTaskVo> existingTasks = queryTasksByDetailId(aoDId);
if (!existingTasks.isEmpty()) { if (!existingTasks.isEmpty()) {
// 新业务规则:只有出库数量等于调拨数量时才允许重新打印 // 强制删除现有任务(覆盖模式)
BigDecimal outSum = BigDecimal.valueOf(detailVo.getOutSum()); deleteTasksByDetailIdInternal(aoDId);
if (outSum.compareTo(detailVo.getAllocateOrderQty()) != 0) { // 记录日志
throw new ServiceException("只有出库数量等于调拨数量时才能重新打印,当前出库数量:" + outSum + ",调拨数量:" + detailVo.getAllocateOrderQty()); System.out.println("覆盖模式:删除调拨明细[" + aoDId + "]的" + existingTasks.size() + "个现有任务");
}
// 删除现有任务移除inboundStatus验证
deleteTasksByDetailId(aoDId);
} }
int splitInt = splitPackageCount != null ? splitPackageCount : 1; int splitInt = splitPackageCount != null ? splitPackageCount : 1;
@ -238,7 +243,7 @@ public class WmsAllocateTaskServiceImpl implements IWmsAllocateTaskService {
totalPackaged = totalPackaged.add(currentPackageQty); totalPackaged = totalPackaged.add(currentPackageQty);
} }
} else { } else {
// 重复打印逻辑split == 1 // 单包打印逻辑split == 1
if (copiesInt < 1) { if (copiesInt < 1) {
copiesInt = 1; copiesInt = 1;
} }
@ -252,11 +257,16 @@ public class WmsAllocateTaskServiceImpl implements IWmsAllocateTaskService {
} }
// 更新调拨明细的已分包数量 // 更新调拨明细的已分包数量
org.dromara.wms.domain.bo.WmsAllocateOrderDetailBo detailBo = new org.dromara.wms.domain.bo.WmsAllocateOrderDetailBo(); WmsAllocateOrderDetailBo detailBo = new WmsAllocateOrderDetailBo();
detailBo.setAoDId(detailVo.getAoDId()); detailBo.setAoDId(detailVo.getAoDId());
detailBo.setPrintedQty(totalPackaged); detailBo.setPrintedQty(totalPackaged);
// 保持原有的出库数量不变
detailBo.setOutSum(detailVo.getOutSum());
allocateOrderDetailService.updateByBo(detailBo); allocateOrderDetailService.updateByBo(detailBo);
// 记录成功日志
System.out.println("调拨分包打印成功:调拨明细[" + aoDId + "],分包数量:" + splitInt + ",总打印数量:" + totalPackaged);
return true; return true;
} }
@ -423,9 +433,11 @@ public class WmsAllocateTaskServiceImpl implements IWmsAllocateTaskService {
// 更新调拨明细的已分包数量 // 更新调拨明细的已分包数量
if (detailVo != null) { if (detailVo != null) {
org.dromara.wms.domain.bo.WmsAllocateOrderDetailBo detailBo = new org.dromara.wms.domain.bo.WmsAllocateOrderDetailBo(); WmsAllocateOrderDetailBo detailBo = new WmsAllocateOrderDetailBo();
detailBo.setAoDId(detailVo.getAoDId()); detailBo.setAoDId(detailVo.getAoDId());
detailBo.setPrintedQty(BigDecimal.ZERO); detailBo.setPrintedQty(BigDecimal.ZERO);
WmsAllocateOrderDetailVo wmsAllocateOrderDetailVo = allocateOrderDetailService.queryById(detailVo.getAoDId());
detailBo.setOutSum(wmsAllocateOrderDetailVo.getOutSum());
allocateOrderDetailService.updateByBo(detailBo); allocateOrderDetailService.updateByBo(detailBo);
} }
@ -435,6 +447,24 @@ public class WmsAllocateTaskServiceImpl implements IWmsAllocateTaskService {
return true; return true;
} }
/**
*
*/
private Boolean deleteTasksByDetailIdInternal(Long aoDId) {
MPJLambdaWrapper<WmsAllocateTask> wrapper = JoinWrappers.lambda(WmsAllocateTask.class)
.eq(WmsAllocateTask::getAoDId, aoDId);
List<WmsAllocateTask> tasks = baseMapper.selectList(wrapper);
if (!tasks.isEmpty()) {
List<Long> taskIds = tasks.stream().map(WmsAllocateTask::getAllocateTaskId).toList();
int deleteCount = baseMapper.deleteByIds(taskIds);
return deleteCount > 0;
}
return true;
}
/** /**
* *
*/ */

Loading…
Cancel
Save