fix: 增强日计划数量与编码校验
This commit is contained in:
@@ -58,4 +58,6 @@ public interface ErrorCodeConstants {
|
||||
ErrorCode DAILY_PLAN_WEIGHT_NOT_POSITIVE = new ErrorCode(33, "日计划权重必须为正整数");
|
||||
ErrorCode DAILY_PLAN_CANCEL_OR_RESUME_REASON_EMPTY = new ErrorCode(34, "取消或恢复原因不能为空");
|
||||
ErrorCode DAILY_PLAN_ERP_TOKEN_ERROR = new ErrorCode(35, "ERP日计划接口令牌错误");
|
||||
ErrorCode DAILY_PLAN_QTY_EXCEEDS_LIMIT = new ErrorCode(36, "日计划数量超过系统支持范围");
|
||||
ErrorCode DAILY_PLAN_CODE_GENERATE_FAILED = new ErrorCode(37, "日计划编码生成失败");
|
||||
}
|
||||
|
||||
@@ -5,14 +5,31 @@ import cn.code.nl.framework.common.pojo.CommonResult;
|
||||
import cn.code.nl.framework.common.pojo.PageResult;
|
||||
import cn.code.nl.module.base.api.codegen.CodeGenApi;
|
||||
import cn.code.nl.module.base.api.codegen.dto.CodeGenerateReqDTO;
|
||||
import cn.code.nl.module.lms.controller.admin.dailyplan.vo.*;
|
||||
import cn.code.nl.module.lms.controller.admin.dailyplan.vo.DailyPlanAppendReqVO;
|
||||
import cn.code.nl.module.lms.controller.admin.dailyplan.vo.DailyPlanCreateReqVO;
|
||||
import cn.code.nl.module.lms.controller.admin.dailyplan.vo.DailyPlanOperationLogRespVO;
|
||||
import cn.code.nl.module.lms.controller.admin.dailyplan.vo.DailyPlanPageReqVO;
|
||||
import cn.code.nl.module.lms.controller.admin.dailyplan.vo.DailyPlanReasonReqVO;
|
||||
import cn.code.nl.module.lms.controller.admin.dailyplan.vo.DailyPlanRespVO;
|
||||
import cn.code.nl.module.lms.controller.admin.dailyplan.vo.DailyPlanSortUpdateReqVO;
|
||||
import cn.code.nl.module.lms.controller.admin.dailyplan.vo.DailyPlanStartReqVO;
|
||||
import cn.code.nl.module.lms.controller.admin.dailyplan.vo.DailyPlanStrategyRespVO;
|
||||
import cn.code.nl.module.lms.controller.admin.dailyplan.vo.DailyPlanStrategyUpdateReqVO;
|
||||
import cn.code.nl.module.lms.controller.admin.dailyplan.vo.DailyPlanUpdateReqVO;
|
||||
import cn.code.nl.module.lms.controller.admin.dailyplan.vo.DailyPlanVersionReqVO;
|
||||
import cn.code.nl.module.lms.controller.admin.dailyplan.vo.DailyPlanWeightUpdateReqVO;
|
||||
import cn.code.nl.module.lms.controller.admin.dailyplan.vo.DailyPlanWorkPageReqVO;
|
||||
import cn.code.nl.module.lms.dal.dataobject.dailyplan.DailyPlanDO;
|
||||
import cn.code.nl.module.lms.dal.dataobject.dailyplan.DailyPlanOperationLogDO;
|
||||
import cn.code.nl.module.lms.dal.dataobject.dailyplan.DailyPlanStrategyDO;
|
||||
import cn.code.nl.module.lms.dal.mysql.dailyplan.DailyPlanMapper;
|
||||
import cn.code.nl.module.lms.dal.mysql.dailyplan.DailyPlanOperationLogMapper;
|
||||
import cn.code.nl.module.lms.dal.mysql.dailyplan.DailyPlanStrategyMapper;
|
||||
import cn.code.nl.module.lms.enums.*;
|
||||
import cn.code.nl.module.lms.enums.DailyPlanOrderStatusEnum;
|
||||
import cn.code.nl.module.lms.enums.DailyPlanSourceTypeEnum;
|
||||
import cn.code.nl.module.lms.enums.DailyPlanStrategyModeEnum;
|
||||
import cn.code.nl.module.lms.enums.DailyPlanStrategyTypeEnum;
|
||||
import cn.code.nl.module.lms.enums.DailyPlanWorkStatusEnum;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
||||
import jakarta.annotation.Resource;
|
||||
@@ -28,7 +45,12 @@ import java.util.Set;
|
||||
|
||||
import static cn.code.nl.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static cn.code.nl.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
|
||||
import static cn.code.nl.module.lms.enums.ErrorCodeConstants.*;
|
||||
import static cn.code.nl.module.lms.enums.ErrorCodeConstants.DAILY_PLAN_CODE_GENERATE_FAILED;
|
||||
import static cn.code.nl.module.lms.enums.ErrorCodeConstants.DAILY_PLAN_NOT_EXISTS;
|
||||
import static cn.code.nl.module.lms.enums.ErrorCodeConstants.DAILY_PLAN_QTY_EXCEEDS_LIMIT;
|
||||
import static cn.code.nl.module.lms.enums.ErrorCodeConstants.DAILY_PLAN_STATUS_OPERATION_NOT_ALLOWED;
|
||||
import static cn.code.nl.module.lms.enums.ErrorCodeConstants.DAILY_PLAN_STRATEGY_NOT_EXISTS;
|
||||
import static cn.code.nl.module.lms.enums.ErrorCodeConstants.DAILY_PLAN_VERSION_CONFLICT;
|
||||
|
||||
/** LMS 日计划服务实现。 */
|
||||
@Service
|
||||
@@ -140,9 +162,15 @@ public class DailyPlanServiceImpl implements DailyPlanService {
|
||||
CodeGenerateReqDTO codeReq = new CodeGenerateReqDTO();
|
||||
codeReq.setRuleCode("LMS_DAILY_PLAN_CODE");
|
||||
CommonResult<String> codeResult = codeGenApi.generate(codeReq);
|
||||
if (codeResult == null) {
|
||||
throw exception(DAILY_PLAN_CODE_GENERATE_FAILED);
|
||||
}
|
||||
if (!codeResult.isSuccess()) {
|
||||
throw new ServiceException(codeResult.getCode(), codeResult.getMsg());
|
||||
}
|
||||
if (StrUtil.isEmpty(codeResult.getData())) {
|
||||
throw exception(DAILY_PLAN_CODE_GENERATE_FAILED);
|
||||
}
|
||||
String userId = String.valueOf(getLoginUserId());
|
||||
DailyPlanDO plan = new DailyPlanDO();
|
||||
plan.setDailyPlanId(IdWorker.getId());
|
||||
@@ -183,7 +211,7 @@ public class DailyPlanServiceImpl implements DailyPlanService {
|
||||
DailyPlanDO update = newUpdate(current);
|
||||
update.setOrderStatus(DailyPlanOrderStatusEnum.IN_PROGRESS.getCode());
|
||||
update.setOrderStartTime(LocalDateTime.now());
|
||||
update.setAppendQty(current.getAppendQty() + reqVO.getAppendQty());
|
||||
update.setAppendQty(safeAddQuantity(current.getAppendQty(), reqVO.getAppendQty()));
|
||||
checkAffected(dailyPlanMapper.updateStateWithVersion(update));
|
||||
insertLog(current.getDailyPlanId(), TARGET_ORDER, TYPE_START, String.valueOf(current.getOrderStatus()),
|
||||
String.valueOf(update.getOrderStatus()), reqVO.getAppendQty(), null);
|
||||
@@ -196,7 +224,7 @@ public class DailyPlanServiceImpl implements DailyPlanService {
|
||||
DailyPlanDO current = validateVersion(reqVO.getId(), reqVO.getVersion());
|
||||
validateOrderStatus(current, DailyPlanOrderStatusEnum.IN_PROGRESS, "追加数量");
|
||||
DailyPlanDO update = newUpdate(current);
|
||||
update.setAppendQty(current.getAppendQty() + reqVO.getAppendQty());
|
||||
update.setAppendQty(safeAddQuantity(current.getAppendQty(), reqVO.getAppendQty()));
|
||||
checkAffected(dailyPlanMapper.updateStateWithVersion(update));
|
||||
insertLog(current.getDailyPlanId(), TARGET_QUANTITY, TYPE_APPEND, String.valueOf(current.getAppendQty()),
|
||||
String.valueOf(update.getAppendQty()), reqVO.getAppendQty(), null);
|
||||
@@ -492,6 +520,15 @@ public class DailyPlanServiceImpl implements DailyPlanService {
|
||||
}
|
||||
}
|
||||
|
||||
/** 安全相加日计划数量,避免整数溢出。 */
|
||||
private int safeAddQuantity(Integer left, Integer right) {
|
||||
long result = (long) left + right;
|
||||
if (result > Integer.MAX_VALUE) {
|
||||
throw exception(DAILY_PLAN_QTY_EXCEEDS_LIMIT);
|
||||
}
|
||||
return (int) result;
|
||||
}
|
||||
|
||||
/** 新增日计划操作日志,操作时间由数据库生成。 */
|
||||
private void insertLog(Long dailyPlanId, String target, String type, String beforeValue, String afterValue,
|
||||
Integer changeQty, String reason) {
|
||||
@@ -523,7 +560,7 @@ public class DailyPlanServiceImpl implements DailyPlanService {
|
||||
response.setMaterialSpec(plan.getMaterialSpec());
|
||||
response.setPlanQty(plan.getPlanQty());
|
||||
response.setAppendQty(plan.getAppendQty());
|
||||
response.setTotalQty(plan.getPlanQty() + plan.getAppendQty());
|
||||
response.setTotalQty(safeAddQuantity(plan.getPlanQty(), plan.getAppendQty()));
|
||||
response.setStockedQty(plan.getStockedQty());
|
||||
response.setSleevedQty(plan.getSleevedQty());
|
||||
response.setPackingInfo(plan.getPackingInfo());
|
||||
|
||||
Reference in New Issue
Block a user