Bonus-Cloud-Material-Mall/bonus-modules/bonus-material-mall/src/main/resources/mapper/material/toolLedger/ToolLedgerMapper.xml

56 lines
2.3 KiB
XML
Raw Normal View History

2025-11-12 18:23:14 +08:00
<?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="com.bonus.material.toolLedger.mapper.ToolLedgerMapper">
<select id="list" resultType="com.bonus.material.toolLedger.domain.ToolLedgerEntity">
SELECT
tt.type_id AS typeId,
tt.type_name AS typeName,
tt.unit_name AS unitName,
tt.manage_type AS manageType,
tt1.type_name AS parentTypeName, -- 1级父节点名称
tt2.type_name AS grandparentTypeName, -- 2级父节点名称
tt3.type_name AS greatGrandparentName, -- 3级父节点名称
tt4.type_name AS fourthParentName, -- 4级父节点名称
2025-11-13 19:34:13 +08:00
tl.available_num / 1000 AS availableNum,
tl.in_num / 1000 AS inNum,
tl.scrap_num / 1000 AS scrapNum,
tl.repair_num / 1000 AS repairNum,
tl.total_num / 1000 AS totalNum
2025-11-12 18:23:14 +08:00
FROM
tool_type tt
INNER JOIN tool_ledger tl ON tl.type_id = tt.type_id
-- 关联1级父节点直接父节点
INNER JOIN tool_type tt1 ON tt.parent_id = tt1.type_id
-- 关联2级父节点祖父节点
INNER JOIN tool_type tt2 ON tt1.parent_id = tt2.type_id
-- 关联3级父节点曾祖父节点
INNER JOIN tool_type tt3 ON tt2.parent_id = tt3.type_id
-- 关联4级父节点
INNER JOIN tool_type tt4 ON tt3.parent_id = tt4.type_id
WHERE
tt.del_flag = '0'
AND tt1.del_flag = '0'
AND tt2.del_flag = '0'
AND tt3.del_flag = '0'
AND tt4.del_flag = '0'
<if test="fourthParentId != null and fourthParentId != ''">
AND tt4.type_id =#{fourthParentId}
</if>
<if test="greatGrandparentId != null and greatGrandparentId != ''">
AND tt3.type_id = #{greatGrandparentId}
</if>
<if test="grandparentTypeId != null and grandparentTypeId != ''">
AND tt2.type_id = #{grandparentTypeId}
</if>
<if test="parentTypeId != null and parentTypeId != ''">
AND tt1.type_id = #{parentTypeId}
</if>
<if test="typeName != null and typeName != ''">
AND tt.type_name LIKE CONCAT('%', #{typeName}, '%')
</if>
ORDER BY
tt.create_time DESC
</select>
</mapper>