Files
smart_management_dev/src/main/resources/mybatis/information/PcdeDetailMapper.xml

353 lines
12 KiB
XML
Raw Normal View History

2025-05-30 16:13:27 +08:00
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
2025-07-10 08:40:36 +08:00
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
2025-05-30 16:13:27 +08:00
<mapper namespace="com.zg.project.information.mapper.PcdeDetailMapper">
2025-07-10 08:40:36 +08:00
2025-12-12 14:52:48 +08:00
<!-- ==================== 通用结果映射 ==================== -->
2025-05-30 16:13:27 +08:00
<resultMap type="PcdeDetail" id="PcdeDetailResult">
2025-12-12 14:52:48 +08:00
<result property="id" column="id"/>
<result property="pcode" column="pcode"/>
<result property="scene" column="scene"/>
<result property="sceneName" column="scene_name"/>
<result property="parentWarehouseCode" column="parent_warehouse_code"/>
<result property="parentWarehouseName" column="parent_warehouse_name"/>
<result property="warehouseCode" column="warehouse_code"/>
<result property="warehouseName" column="warehouse_name"/>
<result property="encodedId" column="encoded_id"/>
<result property="tag" column="tag"/>
<result property="remark" column="remark"/>
<result property="isDelete" column="is_delete"/>
<result property="createdBy" column="created_by"/>
<result property="createdAt" column="created_at"/>
<result property="updatedBy" column="updated_by"/>
<result property="updatedAt" column="updated_at"/>
2025-05-30 16:13:27 +08:00
</resultMap>
2025-12-12 14:52:48 +08:00
<!-- 公共 SELECT 片段:带场景名称 -->
2025-05-30 16:13:27 +08:00
<sql id="selectPcdeDetailVo">
2025-12-12 14:52:48 +08:00
SELECT
d.id,
d.pcode,
d.scene,
m.scene_name,
d.parent_warehouse_code,
d.parent_warehouse_name,
d.warehouse_code,
d.warehouse_name,
d.encoded_id,
d.tag,
d.remark,
d.is_delete,
d.created_by,
d.created_at,
d.updated_by,
d.updated_at
FROM pcde_detail d
LEFT JOIN scene_mapping m ON d.scene = m.scene_code
2025-05-30 16:13:27 +08:00
</sql>
2025-12-12 14:52:48 +08:00
<!-- 列表查询 -->
<select id="selectPcdeDetailList"
parameterType="PcdeDetail"
resultMap="PcdeDetailResult">
2025-05-30 16:13:27 +08:00
<include refid="selectPcdeDetailVo"/>
<where>
2025-12-12 14:52:48 +08:00
<if test="pcode != null and pcode != ''">
AND d.pcode = #{pcode}
</if>
<if test="scene != null and scene != ''">
AND d.scene = #{scene}
</if>
2025-12-09 15:54:39 +08:00
2025-12-12 14:52:48 +08:00
<!-- 按大仓 / 小仓过滤(可选) -->
<if test="parentWarehouseCode != null and parentWarehouseCode != ''">
AND d.parent_warehouse_code = #{parentWarehouseCode}
</if>
<if test="parentWarehouseName != null and parentWarehouseName != ''">
AND d.parent_warehouse_name LIKE concat('%', #{parentWarehouseName}, '%')
2025-12-09 15:54:39 +08:00
</if>
2025-12-12 14:52:48 +08:00
<if test="warehouseCode != null and warehouseCode != ''">
AND d.warehouse_code = #{warehouseCode}
2025-12-09 15:54:39 +08:00
</if>
2025-12-12 14:52:48 +08:00
<if test="warehouseName != null and warehouseName != ''">
AND d.warehouse_name LIKE concat('%', #{warehouseName}, '%')
</if>
<if test="encodedId != null and encodedId != ''">
AND d.encoded_id = #{encodedId}
</if>
<if test="tag != null and tag != ''">
AND d.tag = #{tag}
</if>
<if test="isDelete != null">
AND d.is_delete = #{isDelete}
</if>
2025-05-30 16:13:27 +08:00
</where>
</select>
2025-12-09 15:54:39 +08:00
2025-12-12 14:52:48 +08:00
<!-- 根据 ID 列表查询 -->
<select id="selectPcdeDetailListIds"
parameterType="PcdeDetail"
resultMap="PcdeDetailResult">
2025-09-15 09:56:24 +08:00
<include refid="selectPcdeDetailVo"/>
<where>
<choose>
<when test="ids != null and ids.size > 0">
AND d.id IN
<foreach collection="ids" item="val" open="(" separator="," close=")">
#{val}
</foreach>
</when>
</choose>
</where>
</select>
2025-05-30 16:13:27 +08:00
2025-12-12 14:52:48 +08:00
<!-- 根据主键查询 -->
<select id="selectPcdeDetailById"
parameterType="Long"
resultMap="PcdeDetailResult">
2025-05-30 16:13:27 +08:00
<include refid="selectPcdeDetailVo"/>
2025-12-12 14:52:48 +08:00
WHERE d.id = #{id}
2025-05-30 16:13:27 +08:00
</select>
2025-12-12 14:52:48 +08:00
<!-- 根据库位编码查询(不联表,直接取表字段) -->
<select id="selectByPcode"
resultType="com.zg.project.information.domain.PcdeDetail"
2025-05-30 16:13:27 +08:00
parameterType="java.lang.String">
2025-12-12 14:52:48 +08:00
SELECT
id,
pcode,
scene,
parent_warehouse_code AS parentWarehouseCode,
parent_warehouse_name AS parentWarehouseName,
warehouse_code AS warehouseCode,
warehouse_name AS warehouseName,
encoded_id AS encodedId,
tag,
is_delete AS isDelete,
created_by AS createdBy,
created_at AS createdAt,
updated_by AS UpdatedBy,
updated_at AS updatedAt,
remark
FROM pcde_detail
WHERE pcode = #{pcode}
2025-07-24 14:19:42 +08:00
AND is_delete = '0'
2025-05-30 16:13:27 +08:00
</select>
2025-12-12 14:52:48 +08:00
<!-- 根据库位编码查编码后ID -->
<select id="selectEncodedIdByPcode"
resultType="java.lang.String"
parameterType="java.lang.String">
SELECT encoded_id
FROM pcde_detail
WHERE pcode = #{pcode}
2025-09-16 15:23:04 +08:00
AND is_delete = '0'
</select>
2025-12-12 14:52:48 +08:00
<select id="selectByWarehouseCode" parameterType="String" resultMap="PcdeDetailResult">
SELECT
id,
pcode,
scene,
parent_warehouse_code,
parent_warehouse_name,
warehouse_code,
warehouse_name,
encoded_id,
tag,
remark,
is_delete,
created_by,
created_at,
updated_by,
updated_at
FROM pcde_detail
WHERE warehouse_code = #{warehouseCode}
AND is_delete = '0'
ORDER BY id ASC
</select>
<!-- 根据库位编码查所属小仓编码(小仓 warehouse_code -->
<select id="selectWarehouseCodeByPcode" parameterType="java.lang.String" resultType="java.lang.String">
SELECT warehouse_code
FROM pcde_detail
WHERE pcode = #{pcode}
AND is_delete = '0'
LIMIT 1
</select>
<!-- 单条插入 -->
<insert id="insertPcdeDetail"
parameterType="PcdeDetail"
useGeneratedKeys="true"
keyProperty="id">
INSERT INTO pcde_detail
2025-05-30 16:13:27 +08:00
<trim prefix="(" suffix=")" suffixOverrides=",">
2025-07-10 08:40:36 +08:00
<if test="pcode != null and pcode != ''">pcode,</if>
2025-05-30 16:13:27 +08:00
<if test="scene != null and scene != ''">scene,</if>
2025-12-12 14:52:48 +08:00
<if test="parentWarehouseCode != null and parentWarehouseCode != ''">
parent_warehouse_code,
</if>
<if test="parentWarehouseName != null and parentWarehouseName != ''">
parent_warehouse_name,
</if>
<if test="warehouseCode != null and warehouseCode != ''">
warehouse_code,
</if>
<if test="warehouseName != null and warehouseName != ''">
warehouse_name,
</if>
2025-05-30 16:13:27 +08:00
<if test="encodedId != null">encoded_id,</if>
<if test="tag != null">tag,</if>
<if test="remark != null and remark != ''">remark,</if>
<if test="isDelete != null">is_delete,</if>
<if test="createdBy != null">created_by,</if>
<if test="createdAt != null">created_at,</if>
<if test="updatedBy != null">updated_by,</if>
<if test="updatedAt != null">updated_at,</if>
2025-07-10 08:40:36 +08:00
</trim>
2025-12-12 14:52:48 +08:00
<trim prefix="VALUES (" suffix=")" suffixOverrides=",">
2025-07-10 08:40:36 +08:00
<if test="pcode != null and pcode != ''">#{pcode},</if>
2025-05-30 16:13:27 +08:00
<if test="scene != null and scene != ''">#{scene},</if>
2025-12-12 14:52:48 +08:00
<if test="parentWarehouseCode != null and parentWarehouseCode != ''">
#{parentWarehouseCode},
</if>
<if test="parentWarehouseName != null and parentWarehouseName != ''">
#{parentWarehouseName},
</if>
<if test="warehouseCode != null and warehouseCode != ''">
#{warehouseCode},
</if>
<if test="warehouseName != null and warehouseName != ''">
#{warehouseName},
</if>
2025-05-30 16:13:27 +08:00
<if test="encodedId != null">#{encodedId},</if>
<if test="tag != null">#{tag},</if>
<if test="remark != null and remark != ''">#{remark},</if>
<if test="isDelete != null">#{isDelete},</if>
<if test="createdBy != null">#{createdBy},</if>
<if test="createdAt != null">#{createdAt},</if>
<if test="updatedBy != null">#{updatedBy},</if>
<if test="updatedAt != null">#{updatedAt},</if>
2025-07-10 08:40:36 +08:00
</trim>
2025-05-30 16:13:27 +08:00
</insert>
2025-12-12 14:52:48 +08:00
<!-- 更新 -->
2025-05-30 16:13:27 +08:00
<update id="updatePcdeDetail" parameterType="PcdeDetail">
2025-12-12 14:52:48 +08:00
UPDATE pcde_detail
2025-05-30 16:13:27 +08:00
<trim prefix="SET" suffixOverrides=",">
2025-12-12 14:52:48 +08:00
<if test="pcode != null and pcode != ''">
pcode = #{pcode},
</if>
<if test="scene != null and scene != ''">
scene = #{scene},
</if>
<if test="parentWarehouseCode != null and parentWarehouseCode != ''">
parent_warehouse_code = #{parentWarehouseCode},
</if>
<if test="parentWarehouseName != null and parentWarehouseName != ''">
parent_warehouse_name = #{parentWarehouseName},
</if>
<if test="warehouseCode != null and warehouseCode != ''">
warehouse_code = #{warehouseCode},
</if>
<if test="warehouseName != null and warehouseName != ''">
warehouse_name = #{warehouseName},
</if>
<if test="encodedId != null">
encoded_id = #{encodedId},
</if>
<if test="tag != null">
tag = #{tag},
</if>
<if test="remark != null and remark != ''">
remark = #{remark},
</if>
<if test="isDelete != null">
is_delete = #{isDelete},
</if>
<if test="createdBy != null">
created_by = #{createdBy},
</if>
<if test="createdAt != null">
created_at = #{createdAt},
</if>
<if test="updatedBy != null">
updated_by = #{updatedBy},
</if>
<if test="updatedAt != null">
updated_at = #{updatedAt},
</if>
2025-05-30 16:13:27 +08:00
</trim>
2025-12-12 14:52:48 +08:00
WHERE id = #{id}
2025-05-30 16:13:27 +08:00
</update>
2025-12-12 14:52:48 +08:00
<!-- 批量插入(存在则忽略),用于导入 -->
2025-10-30 11:01:07 +08:00
<insert id="batchInsertIgnore">
INSERT IGNORE INTO pcde_detail
2025-12-12 14:52:48 +08:00
(pcode,
scene,
scene_name,
parent_warehouse_code,
parent_warehouse_name,
warehouse_code,
warehouse_name,
encoded_id,
tag,
remark,
is_delete,
created_by,
created_at,
updated_by,
updated_at)
2025-10-30 11:01:07 +08:00
VALUES
<foreach collection="list" item="item" separator=",">
(
#{item.pcode},
#{item.scene},
#{item.sceneName},
2025-12-12 14:52:48 +08:00
#{item.parentWarehouseCode},
#{item.parentWarehouseName},
#{item.warehouseCode},
2025-10-30 11:01:07 +08:00
#{item.warehouseName},
#{item.encodedId},
#{item.tag},
#{item.remark},
#{item.isDelete},
#{item.createdBy},
#{item.createdAt},
#{item.updatedBy},
#{item.updatedAt}
)
</foreach>
</insert>
2025-12-12 14:52:48 +08:00
<!-- 单条删除 -->
2025-05-30 16:13:27 +08:00
<delete id="deletePcdeDetailById" parameterType="Long">
2025-12-12 14:52:48 +08:00
DELETE FROM pcde_detail
WHERE id = #{id}
2025-05-30 16:13:27 +08:00
</delete>
2025-12-12 14:52:48 +08:00
<!-- 批量删除 -->
2025-05-30 16:13:27 +08:00
<delete id="deletePcdeDetailByIds" parameterType="String">
2025-12-12 14:52:48 +08:00
DELETE FROM pcde_detail
WHERE id IN
2025-05-30 16:13:27 +08:00
<foreach item="id" collection="array" open="(" separator="," close=")">
#{id}
</foreach>
</delete>
2025-09-16 15:23:04 +08:00
2025-07-10 08:40:36 +08:00
</mapper>