fix: 完善日计划开始确认与取消入口
This commit is contained in:
@@ -9,6 +9,10 @@ import lombok.EqualsAndHashCode;
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class DailyPlanStartReqVO extends DailyPlanVersionReqVO {
|
||||
@NotNull(message = "确认计划数量不能为空")
|
||||
@Min(value = 1, message = "确认计划数量必须为正整数")
|
||||
private Integer planQty;
|
||||
|
||||
@NotNull(message = "追加数量不能为空")
|
||||
@Min(value = 0, message = "追加数量不能小于0")
|
||||
private Integer appendQty;
|
||||
|
||||
@@ -94,6 +94,9 @@ public interface DailyPlanMapper extends BaseMapperX<DailyPlanDO> {
|
||||
*/
|
||||
int updateStateWithVersion(@Param("plan") DailyPlanDO plan);
|
||||
|
||||
/** 原子确认数量并开始未开始订单。 */
|
||||
int startOrderWithVersion(@Param("plan") DailyPlanDO plan);
|
||||
|
||||
/**
|
||||
* 乐观锁恢复已取消的订单状态,并清空前一订单状态。
|
||||
*/
|
||||
|
||||
@@ -359,19 +359,32 @@ public class DailyPlanServiceImpl implements DailyPlanService {
|
||||
checkAffected(dailyPlanMapper.updateNotStartedPlan(update));
|
||||
}
|
||||
|
||||
/** 开始订单并写入追加数量。 */
|
||||
/** 开始订单,同时确认计划数量并写入本次追加数量。 */
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void startOrder(DailyPlanStartReqVO reqVO) {
|
||||
DailyPlanDO current = validateVersion(reqVO.getId(), reqVO.getVersion());
|
||||
validateOrderStatus(current, DailyPlanOrderStatusEnum.NOT_STARTED, "开始订单");
|
||||
DailyPlanDO update = newUpdate(current);
|
||||
int confirmedPlanQty = reqVO.getPlanQty();
|
||||
int appendQty = safeAddQuantity(current.getAppendQty(), reqVO.getAppendQty());
|
||||
safeAddQuantity(confirmedPlanQty, appendQty); // 校验开始后的需求总量不会溢出。
|
||||
update.setPlanQty(confirmedPlanQty);
|
||||
update.setOrderStatus(DailyPlanOrderStatusEnum.IN_PROGRESS.getCode());
|
||||
update.setOrderStartTime(LocalDateTime.now());
|
||||
update.setAppendQty(safeAddQuantity(current.getAppendQty(), reqVO.getAppendQty()));
|
||||
checkAffected(dailyPlanMapper.updateStateWithVersion(update));
|
||||
update.setAppendQty(appendQty);
|
||||
checkAffected(dailyPlanMapper.startOrderWithVersion(update));
|
||||
if (!current.getPlanQty().equals(confirmedPlanQty)) {
|
||||
insertLog(current.getDailyPlanId(), TARGET_QUANTITY, TYPE_UPDATE,
|
||||
String.valueOf(current.getPlanQty()), String.valueOf(confirmedPlanQty),
|
||||
confirmedPlanQty - current.getPlanQty(), null);
|
||||
}
|
||||
if (reqVO.getAppendQty() > 0) {
|
||||
insertLog(current.getDailyPlanId(), TARGET_QUANTITY, TYPE_APPEND,
|
||||
String.valueOf(current.getAppendQty()), String.valueOf(appendQty), reqVO.getAppendQty(), null);
|
||||
}
|
||||
insertLog(current.getDailyPlanId(), TARGET_ORDER, TYPE_START, String.valueOf(current.getOrderStatus()),
|
||||
String.valueOf(update.getOrderStatus()), reqVO.getAppendQty(), null);
|
||||
String.valueOf(update.getOrderStatus()), null, null);
|
||||
}
|
||||
|
||||
/** 追加进行中订单的数量。 */
|
||||
|
||||
@@ -246,6 +246,20 @@
|
||||
AND deleted = b'0'
|
||||
</update>
|
||||
|
||||
<update id="startOrderWithVersion">
|
||||
UPDATE lms_daily_plan
|
||||
SET plan_qty = #{plan.planQty},
|
||||
append_qty = #{plan.appendQty},
|
||||
order_status = 1,
|
||||
order_start_time = #{plan.orderStartTime},
|
||||
updater = #{plan.updater},
|
||||
version = version + 1
|
||||
WHERE daily_plan_id = #{plan.dailyPlanId}
|
||||
AND version = #{plan.version}
|
||||
AND order_status = 0
|
||||
AND deleted = b'0'
|
||||
</update>
|
||||
|
||||
<update id="updateSortWithVersion">
|
||||
UPDATE lms_daily_plan
|
||||
SET sort_seq = #{sortSeq}, updater = #{updater}, version = version + 1
|
||||
|
||||
Reference in New Issue
Block a user