feat: 实现LMS日计划持久层

This commit is contained in:
zhouz
2026-08-14 14:00:56 +08:00
parent 1edf7c06ae
commit 2dabf68b16
8 changed files with 528 additions and 0 deletions

View File

@@ -0,0 +1,38 @@
package cn.code.nl.module.lms.controller.admin.dailyplan.vo;
import cn.code.nl.framework.common.pojo.PageParam;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;
import java.time.LocalDate;
import static cn.code.nl.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY;
/**
* 管理后台 - LMS 日计划分页 Request VO。
*/
@Schema(description = "管理后台 - LMS 日计划分页 Request VO")
@Data
public class DailyPlanPageReqVO extends PageParam {
@Schema(description = "日计划编码或订单号")
private String planOrOrderCode;
@Schema(description = "计划日期开始")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY)
private LocalDate planDateStart;
@Schema(description = "计划日期结束")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY)
private LocalDate planDateEnd;
@Schema(description = "物料编码、名称或规格关键词")
private String materialKeyword;
@Schema(description = "来源类型")
private Integer sourceType;
@Schema(description = "订单状态")
private Integer orderStatus;
}

View File

@@ -0,0 +1,22 @@
package cn.code.nl.module.lms.controller.admin.dailyplan.vo;
import cn.code.nl.framework.common.pojo.PageParam;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
/**
* 管理后台 - LMS 日计划作业分页 Request VO。
*/
@Schema(description = "管理后台 - LMS 日计划作业分页 Request VO")
@Data
public class DailyPlanWorkPageReqVO extends PageParam {
@Schema(description = "订单状态,由服务层或控制层限定为 1进行中或 3已取消")
private Integer orderStatus;
@Schema(description = "日计划编码或订单号")
private String planOrOrderCode;
@Schema(description = "物料编码、名称或规格关键词")
private String materialKeyword;
}

View File

@@ -0,0 +1,117 @@
package cn.code.nl.module.lms.dal.mysql.dailyplan;
import cn.code.nl.framework.common.pojo.PageResult;
import cn.code.nl.framework.mybatis.core.mapper.BaseMapperX;
import cn.code.nl.framework.mybatis.core.util.MyBatisUtils;
import cn.code.nl.module.lms.controller.admin.dailyplan.vo.DailyPlanPageReqVO;
import cn.code.nl.module.lms.controller.admin.dailyplan.vo.DailyPlanWorkPageReqVO;
import cn.code.nl.module.lms.dal.dataobject.dailyplan.DailyPlanDO;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* LMS 日计划 Mapper。
*/
@Mapper
public interface DailyPlanMapper extends BaseMapperX<DailyPlanDO> {
/**
* 分页查询日计划管理列表。
*/
default PageResult<DailyPlanDO> selectManagementPage(DailyPlanPageReqVO reqVO) {
Page<DailyPlanDO> page = selectManagementPage(MyBatisUtils.buildPage(reqVO), reqVO);
return new PageResult<>(page.getRecords(), page.getTotal());
}
/**
* 执行日计划管理分页 SQL。
*/
Page<DailyPlanDO> selectManagementPage(Page<DailyPlanDO> page,
@Param("reqVO") DailyPlanPageReqVO reqVO);
/**
* 分页查询日计划作业列表。
*/
default PageResult<DailyPlanDO> selectWorkPage(DailyPlanWorkPageReqVO reqVO) {
Page<DailyPlanDO> page = selectWorkPage(MyBatisUtils.buildPage(reqVO), reqVO);
return new PageResult<>(page.getRecords(), page.getTotal());
}
/**
* 执行日计划作业分页 SQL。
*/
Page<DailyPlanDO> selectWorkPage(Page<DailyPlanDO> page,
@Param("reqVO") DailyPlanWorkPageReqVO reqVO);
/**
* 根据标识查询日计划。
*/
DailyPlanDO selectDailyPlanById(@Param("dailyPlanId") Long dailyPlanId);
/**
* 根据 ERP 订单号查询日计划。
*/
DailyPlanDO selectByErpOrderCode(@Param("erpOrderCode") String erpOrderCode);
/**
* 查询待备货日计划。
*/
List<DailyPlanDO> selectStockingCandidates();
/**
* 查询待套管日计划。
*/
List<DailyPlanDO> selectSleevingCandidates();
/**
* 新增日计划。
*/
int insertDailyPlan(@Param("plan") DailyPlanDO plan);
/**
* 更新未开始日计划的可编辑字段。
*/
int updateNotStartedPlan(@Param("plan") DailyPlanDO plan);
/**
* 乐观锁更新日计划状态。
*
* <p>调用方只能传入新建的更新对象,不得直接传入数据库查询得到的完整 DO避免覆盖未变更状态。</p>
*/
int updateStateWithVersion(@Param("plan") DailyPlanDO plan);
/**
* 乐观锁更新排序序号。
*/
int updateSortWithVersion(@Param("dailyPlanId") Long dailyPlanId,
@Param("sortSeq") Integer sortSeq,
@Param("version") Integer version,
@Param("updater") String updater);
/**
* 乐观锁更新调度权重。
*/
int updateWeightWithVersion(@Param("dailyPlanId") Long dailyPlanId,
@Param("weight") Integer weight,
@Param("version") Integer version,
@Param("updater") String updater);
/**
* 原子增加已备货数量,并在达到总量时完成备货。
*/
int increaseStockedQuantity(@Param("dailyPlanId") Long dailyPlanId,
@Param("incrementQty") Integer incrementQty,
@Param("version") Integer version,
@Param("updater") String updater);
/**
* 原子增加已套管数量,并在达到总量时完成套管。
*/
int increaseSleevedQuantity(@Param("dailyPlanId") Long dailyPlanId,
@Param("incrementQty") Integer incrementQty,
@Param("version") Integer version,
@Param("updater") String updater);
}

View File

@@ -0,0 +1,25 @@
package cn.code.nl.module.lms.dal.mysql.dailyplan;
import cn.code.nl.framework.mybatis.core.mapper.BaseMapperX;
import cn.code.nl.module.lms.dal.dataobject.dailyplan.DailyPlanOperationLogDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* LMS 日计划操作日志 Mapper。
*/
@Mapper
public interface DailyPlanOperationLogMapper extends BaseMapperX<DailyPlanOperationLogDO> {
/**
* 新增操作日志;自定义新增不会生成主键,调用方必须预先设置 operationLogId。
*/
int insertOperationLog(@Param("operationLog") DailyPlanOperationLogDO operationLog);
/**
* 查询日计划的操作日志。
*/
List<DailyPlanOperationLogDO> selectListByDailyPlanId(@Param("dailyPlanId") Long dailyPlanId);
}

View File

@@ -0,0 +1,34 @@
package cn.code.nl.module.lms.dal.mysql.dailyplan;
import cn.code.nl.framework.mybatis.core.mapper.BaseMapperX;
import cn.code.nl.module.lms.dal.dataobject.dailyplan.DailyPlanStrategyDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
/**
* LMS 日计划调度策略 Mapper。
*/
@Mapper
public interface DailyPlanStrategyMapper extends BaseMapperX<DailyPlanStrategyDO> {
/**
* 根据策略类型查询策略。
*/
DailyPlanStrategyDO selectByStrategyType(@Param("strategyType") Integer strategyType);
/**
* 乐观锁更新策略模式并清空游标。
*/
int updateModeWithVersion(@Param("strategyId") Long strategyId,
@Param("strategyMode") Integer strategyMode,
@Param("version") Integer version,
@Param("updater") String updater);
/**
* 乐观锁更新策略游标。
*/
int updateCursorWithVersion(@Param("strategyId") Long strategyId,
@Param("cursorDailyPlanId") Long cursorDailyPlanId,
@Param("version") Integer version,
@Param("updater") String updater);
}

View File

@@ -0,0 +1,219 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.code.nl.module.lms.dal.mysql.dailyplan.DailyPlanMapper">
<sql id="dailyPlanColumns">
daily_plan_id, plan_code, source_type, erp_order_code, manual_order_code,
plan_date, material_id, material_code, material_name, material_spec,
plan_qty, append_qty, stocked_qty, sleeved_qty, packing_info, sort_seq, weight,
order_status, stocking_status, sleeving_status,
previous_order_status, previous_stocking_status, previous_sleeving_status,
order_start_time, order_end_time, stocking_start_time, stocking_complete_time,
sleeving_start_time, sleeving_complete_time, version,
creator, create_time, updater, update_time, deleted, tenant_id
</sql>
<sql id="planOrOrderCodeCondition">
<if test="reqVO.planOrOrderCode != null and reqVO.planOrOrderCode != ''">
AND (plan_code LIKE CONCAT('%', #{reqVO.planOrOrderCode}, '%')
OR erp_order_code LIKE CONCAT('%', #{reqVO.planOrOrderCode}, '%')
OR manual_order_code LIKE CONCAT('%', #{reqVO.planOrOrderCode}, '%'))
</if>
</sql>
<sql id="materialKeywordCondition">
<if test="reqVO.materialKeyword != null and reqVO.materialKeyword != ''">
AND (material_code LIKE CONCAT('%', #{reqVO.materialKeyword}, '%')
OR material_name LIKE CONCAT('%', #{reqVO.materialKeyword}, '%')
OR material_spec LIKE CONCAT('%', #{reqVO.materialKeyword}, '%'))
</if>
</sql>
<select id="selectManagementPage"
resultType="cn.code.nl.module.lms.dal.dataobject.dailyplan.DailyPlanDO">
SELECT <include refid="dailyPlanColumns"/>
FROM lms_daily_plan
WHERE deleted = b'0'
<include refid="planOrOrderCodeCondition"/>
<if test="reqVO.planDateStart != null">
AND plan_date &gt;= #{reqVO.planDateStart}
</if>
<if test="reqVO.planDateEnd != null">
AND plan_date &lt;= #{reqVO.planDateEnd}
</if>
<include refid="materialKeywordCondition"/>
<if test="reqVO.sourceType != null">
AND source_type = #{reqVO.sourceType}
</if>
<if test="reqVO.orderStatus != null">
AND order_status = #{reqVO.orderStatus}
</if>
ORDER BY plan_date DESC, sort_seq ASC, daily_plan_id DESC
</select>
<select id="selectWorkPage"
resultType="cn.code.nl.module.lms.dal.dataobject.dailyplan.DailyPlanDO">
SELECT <include refid="dailyPlanColumns"/>
FROM lms_daily_plan
WHERE deleted = b'0'
AND order_status = #{reqVO.orderStatus}
<include refid="planOrOrderCodeCondition"/>
<include refid="materialKeywordCondition"/>
ORDER BY sort_seq ASC, daily_plan_id ASC
</select>
<select id="selectDailyPlanById"
resultType="cn.code.nl.module.lms.dal.dataobject.dailyplan.DailyPlanDO">
SELECT <include refid="dailyPlanColumns"/>
FROM lms_daily_plan
WHERE daily_plan_id = #{dailyPlanId}
AND deleted = b'0'
</select>
<select id="selectByErpOrderCode"
resultType="cn.code.nl.module.lms.dal.dataobject.dailyplan.DailyPlanDO">
SELECT <include refid="dailyPlanColumns"/>
FROM lms_daily_plan
WHERE erp_order_code = #{erpOrderCode}
AND deleted = b'0'
</select>
<select id="selectStockingCandidates"
resultType="cn.code.nl.module.lms.dal.dataobject.dailyplan.DailyPlanDO">
SELECT <include refid="dailyPlanColumns"/>
FROM lms_daily_plan
WHERE order_status = 1
AND stocking_status = 1
AND stocked_qty &lt; plan_qty + append_qty
AND deleted = b'0'
ORDER BY sort_seq ASC, daily_plan_id ASC
</select>
<select id="selectSleevingCandidates"
resultType="cn.code.nl.module.lms.dal.dataobject.dailyplan.DailyPlanDO">
SELECT <include refid="dailyPlanColumns"/>
FROM lms_daily_plan
WHERE order_status = 1
AND sleeving_status = 1
AND sleeved_qty &lt; plan_qty + append_qty
AND deleted = b'0'
ORDER BY sort_seq ASC, daily_plan_id ASC
</select>
<insert id="insertDailyPlan">
INSERT INTO lms_daily_plan
(daily_plan_id, plan_code, source_type, erp_order_code, manual_order_code,
plan_date, material_id, material_code, material_name, material_spec,
plan_qty, append_qty, stocked_qty, sleeved_qty, packing_info, sort_seq, weight,
order_status, stocking_status, sleeving_status,
previous_order_status, previous_stocking_status, previous_sleeving_status,
order_start_time, order_end_time, stocking_start_time, stocking_complete_time,
sleeving_start_time, sleeving_complete_time, version,
creator, create_time, updater, update_time, deleted, tenant_id)
VALUES
(#{plan.dailyPlanId}, #{plan.planCode}, #{plan.sourceType}, #{plan.erpOrderCode}, #{plan.manualOrderCode},
#{plan.planDate}, #{plan.materialId}, #{plan.materialCode}, #{plan.materialName}, #{plan.materialSpec},
#{plan.planQty}, #{plan.appendQty}, #{plan.stockedQty}, #{plan.sleevedQty}, #{plan.packingInfo},
#{plan.sortSeq}, #{plan.weight}, #{plan.orderStatus}, #{plan.stockingStatus}, #{plan.sleevingStatus},
#{plan.previousOrderStatus}, #{plan.previousStockingStatus}, #{plan.previousSleevingStatus},
#{plan.orderStartTime}, #{plan.orderEndTime}, #{plan.stockingStartTime}, #{plan.stockingCompleteTime},
#{plan.sleevingStartTime}, #{plan.sleevingCompleteTime}, #{plan.version},
#{plan.creator}, #{plan.createTime}, #{plan.updater}, #{plan.updateTime}, #{plan.deleted}, #{plan.tenantId})
</insert>
<update id="updateNotStartedPlan">
UPDATE lms_daily_plan
SET erp_order_code = #{plan.erpOrderCode},
manual_order_code = #{plan.manualOrderCode},
plan_date = #{plan.planDate},
material_id = #{plan.materialId},
material_code = #{plan.materialCode},
material_name = #{plan.materialName},
material_spec = #{plan.materialSpec},
plan_qty = #{plan.planQty},
packing_info = #{plan.packingInfo},
sort_seq = #{plan.sortSeq},
weight = #{plan.weight},
updater = #{plan.updater},
version = version + 1
WHERE daily_plan_id = #{plan.dailyPlanId}
AND version = #{plan.version}
AND deleted = b'0'
AND order_status = 0
</update>
<update id="updateStateWithVersion">
UPDATE lms_daily_plan
<set>
<if test="plan.orderStatus != null">order_status = #{plan.orderStatus},</if>
<if test="plan.stockingStatus != null">stocking_status = #{plan.stockingStatus},</if>
<if test="plan.sleevingStatus != null">sleeving_status = #{plan.sleevingStatus},</if>
<if test="plan.previousOrderStatus != null">previous_order_status = #{plan.previousOrderStatus},</if>
<if test="plan.previousStockingStatus != null">previous_stocking_status = #{plan.previousStockingStatus},</if>
<if test="plan.previousSleevingStatus != null">previous_sleeving_status = #{plan.previousSleevingStatus},</if>
<if test="plan.orderStartTime != null">order_start_time = #{plan.orderStartTime},</if>
<if test="plan.orderEndTime != null">order_end_time = #{plan.orderEndTime},</if>
<if test="plan.stockingStartTime != null">stocking_start_time = #{plan.stockingStartTime},</if>
<if test="plan.stockingCompleteTime != null">stocking_complete_time = #{plan.stockingCompleteTime},</if>
<if test="plan.sleevingStartTime != null">sleeving_start_time = #{plan.sleevingStartTime},</if>
<if test="plan.sleevingCompleteTime != null">sleeving_complete_time = #{plan.sleevingCompleteTime},</if>
<if test="plan.appendQty != null">append_qty = #{plan.appendQty},</if>
updater = #{plan.updater},
version = version + 1
</set>
WHERE daily_plan_id = #{plan.dailyPlanId}
AND version = #{plan.version}
AND deleted = b'0'
</update>
<update id="updateSortWithVersion">
UPDATE lms_daily_plan
SET sort_seq = #{sortSeq}, updater = #{updater}, version = version + 1
WHERE daily_plan_id = #{dailyPlanId} AND version = #{version} AND deleted = b'0'
</update>
<update id="updateWeightWithVersion">
UPDATE lms_daily_plan
SET weight = #{weight}, updater = #{updater}, version = version + 1
WHERE daily_plan_id = #{dailyPlanId} AND version = #{version} AND deleted = b'0'
</update>
<update id="increaseStockedQuantity">
UPDATE lms_daily_plan
SET stocking_status = CASE
WHEN stocked_qty + #{incrementQty} = plan_qty + append_qty THEN 2
ELSE stocking_status END,
stocking_complete_time = CASE
WHEN stocked_qty + #{incrementQty} = plan_qty + append_qty THEN NOW()
ELSE stocking_complete_time END,
stocked_qty = stocked_qty + #{incrementQty},
updater = #{updater},
version = version + 1
WHERE daily_plan_id = #{dailyPlanId}
AND version = #{version}
AND deleted = b'0'
AND order_status = 1
AND stocking_status = 1
AND stocked_qty + #{incrementQty} &lt;= plan_qty + append_qty
</update>
<update id="increaseSleevedQuantity">
UPDATE lms_daily_plan
SET sleeving_status = CASE
WHEN sleeved_qty + #{incrementQty} = plan_qty + append_qty THEN 2
ELSE sleeving_status END,
sleeving_complete_time = CASE
WHEN sleeved_qty + #{incrementQty} = plan_qty + append_qty THEN NOW()
ELSE sleeving_complete_time END,
sleeved_qty = sleeved_qty + #{incrementQty},
updater = #{updater},
version = version + 1
WHERE daily_plan_id = #{dailyPlanId}
AND version = #{version}
AND deleted = b'0'
AND order_status = 1
AND sleeving_status = 1
AND sleeved_qty + #{incrementQty} &lt;= plan_qty + append_qty
</update>
</mapper>

View File

@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.code.nl.module.lms.dal.mysql.dailyplan.DailyPlanOperationLogMapper">
<sql id="operationLogColumns">
operation_log_id, daily_plan_id, operation_target, operation_type,
before_value, after_value, change_qty, operation_reason,
operator, operation_time, deleted, tenant_id
</sql>
<insert id="insertOperationLog">
INSERT INTO lms_daily_plan_operation_log
(operation_log_id, daily_plan_id, operation_target, operation_type,
before_value, after_value, change_qty, operation_reason,
operator, operation_time, deleted, tenant_id)
VALUES
(#{operationLog.operationLogId}, #{operationLog.dailyPlanId},
#{operationLog.operationTarget}, #{operationLog.operationType},
#{operationLog.beforeValue}, #{operationLog.afterValue},
#{operationLog.changeQty}, #{operationLog.operationReason},
#{operationLog.operator}, #{operationLog.operationTime},
#{operationLog.deleted}, #{operationLog.tenantId})
</insert>
<select id="selectListByDailyPlanId"
resultType="cn.code.nl.module.lms.dal.dataobject.dailyplan.DailyPlanOperationLogDO">
SELECT <include refid="operationLogColumns"/>
FROM lms_daily_plan_operation_log
WHERE daily_plan_id = #{dailyPlanId}
AND deleted = b'0'
ORDER BY operation_time DESC, operation_log_id DESC
</select>
</mapper>

View File

@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.code.nl.module.lms.dal.mysql.dailyplan.DailyPlanStrategyMapper">
<sql id="strategyColumns">
strategy_id, strategy_type, strategy_mode, cursor_daily_plan_id, version,
creator, create_time, updater, update_time, deleted, tenant_id
</sql>
<select id="selectByStrategyType"
resultType="cn.code.nl.module.lms.dal.dataobject.dailyplan.DailyPlanStrategyDO">
SELECT <include refid="strategyColumns"/>
FROM lms_daily_plan_strategy
WHERE strategy_type = #{strategyType}
AND deleted = b'0'
</select>
<update id="updateModeWithVersion">
UPDATE lms_daily_plan_strategy
SET strategy_mode = #{strategyMode},
cursor_daily_plan_id = NULL,
updater = #{updater},
version = version + 1
WHERE strategy_id = #{strategyId}
AND version = #{version}
AND deleted = b'0'
</update>
<update id="updateCursorWithVersion">
UPDATE lms_daily_plan_strategy
SET cursor_daily_plan_id = #{cursorDailyPlanId},
updater = #{updater},
version = version + 1
WHERE strategy_id = #{strategyId}
AND version = #{version}
AND deleted = b'0'
</update>
</mapper>