btyjj-inspection/src/main/resources/mybatis/mapper/checkitem/checkitem-mapper.xml

190 lines
5.7 KiB
XML

<?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.cm.inspection.dao.checkitem.ICheckItemDao">
<resultMap id="checkItemDTO" type="com.cm.inspection.pojo.dtos.checkitem.CheckItemDTO">
<id column="check_item_id" property="checkItemId"/>
<result column="check_item_parent_id" property="checkItemParentId"/>
<result column="type" property="type"/>
<result column="name" property="name"/>
<result column="parent_name" property="parentName"/>
<result column="summary" property="summary"/>
<result column="icon" property="icon"/>
<result column="icon_press" property="iconPress"/>
</resultMap>
<resultMap id="checkItemZTreeDTO" type="com.cm.common.pojo.dtos.ZTreeDTO">
<id property="id" column="check_item_id"/>
<result property="pId" column="check_item_parent_id"/>
<result property="name" column="name"/>
</resultMap>
<!-- 新增检查项 -->
<insert id="saveCheckItem" parameterType="map">
INSERT INTO gen_check_item(
check_item_id,
check_item_parent_id,
type,
name,
summary,
icon,
icon_press,
creator,
gmt_create,
modifier,
gmt_modified,
is_delete
) VALUES(
#{checkItemId},
#{checkItemParentId},
#{type},
#{name},
#{summary},
#{icon},
#{iconPress},
#{creator},
#{gmtCreate},
#{modifier},
#{gmtModified},
#{isDelete}
)
</insert>
<!-- 删除检查项 -->
<update id="removeCheckItem" parameterType="map">
UPDATE
gen_check_item
SET
is_delete = 1,
modifier = #{modifier},
gmt_modified = #{gmtModified}
WHERE
check_item_id IN
<foreach collection="checkItemIds" index="index" open="(" separator="," close=")">
#{checkItemIds[${index}]}
</foreach>
</update>
<!-- 修改检查项 -->
<update id="updateCheckItem" parameterType="map">
UPDATE
gen_check_item
SET
<if test="checkItemParentId != null and checkItemParentId != ''">
check_item_parent_id = #{checkItemParentId},
</if>
<if test="type != null and type != ''">
type = #{type},
</if>
<if test="name != null and name != ''">
name = #{name},
</if>
<if test="summary != null and summary != ''">
summary = #{summary},
</if>
<if test="icon != null and icon != ''">
icon = #{icon},
</if>
<if test="iconPress != null and iconPress != ''">
icon_press = #{iconPress},
</if>
modifier = #{modifier},
gmt_modified = #{gmtModified}
WHERE
check_item_id = #{checkItemId}
</update>
<!-- 检查项详情 -->
<select id="getCheckItem" parameterType="map" resultMap="checkItemDTO">
SELECT
t1.name,
t2.name parent_name,
t1.summary,
t1.type,
t1.icon,
t1.icon_press,
t1.check_item_parent_id,
t1.check_item_id
FROM
gen_check_item t1
LEFT JOIN
gen_check_item t2
ON
t1.check_item_parent_id = t2.check_item_id
WHERE
t1.is_delete = 0
<if test="checkItemId != null and checkItemId != ''">
AND
t1.check_item_id = #{checkItemId}
</if>
</select>
<!-- 检查项列表 -->
<select id="listCheckItem" parameterType="map" resultMap="checkItemDTO">
SELECT
t1.name,
t1.summary,
t1.type,
t1.icon,
t1.icon_press,
t1.check_item_parent_id,
t1.check_item_id
FROM
gen_check_item t1
WHERE
t1.is_delete = 0
<if test="keywords != null and keywords != ''">
<!-- 这里添加检索关键字 -->
</if>
<if test="checkItemParentId != null and checkItemParentId != ''">
AND
check_item_parent_id = #{checkItemParentId}
</if>
<if test="type != null">
AND
type = #{type}
</if>
<if test="startTime != null and startTime != ''">
AND
LEFT(t1.gmt_create, 10) <![CDATA[ >= ]]> #{startTime}
</if>
<if test="endTime != null and endTime != ''">
AND
LEFT(t1.gmt_create, 10) <![CDATA[ <= ]]> #{endTime}
</if>
<if test="checkItemIds != null and checkItemIds.size > 0">
AND
t1.check_item_id IN
<foreach collection="checkItemIds" index="index" open="(" separator="," close=")">
#{checkItemIds[${index}]}
</foreach>
</if>
</select>
<!-- ztree列表 -->
<select id="listZTreeCheckItem" parameterType="map" resultMap="checkItemZTreeDTO">
SELECT
*
FROM
gen_check_item
WHERE
is_delete = 0
<if test="checkItemParentId != null and checkItemParentId != ''">
AND
check_item_parent_id = #{checkItemParentId}
</if>
</select>
<!-- 通过上级ID统计下级数量 -->
<select id="countByParentId" parameterType="String" resultType="Integer">
SELECT
COUNT(*)
FROM
gen_check_item
WHERE
is_delete = 0
AND
check_item_parent_id = #{_parameter}
</select>
</mapper>