btxtgxq-system-city/src/main/resources/mybatis/mapper/dict/dict-mapper.xml
2024-01-08 17:31:16 +08:00

260 lines
7.7 KiB
XML
Executable File

<?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.systemcity.dao.dict.IDictDao">
<resultMap id="dictDTO" type="com.cm.systemcity.pojo.dtos.dict.DictDTO">
<id property="dictId" column="dict_id"/>
<result property="dictParentId" column="dict_parent_id"/>
<result property="dictParentName" column="dict_parent_name"/>
<result property="dictName" column="dict_name"/>
<result property="dictSummary" column="dict_summary"/>
<result property="dictCode" column="dict_code"/>
<result property="dictOrder" column="dict_order"/>
<result property="industryCode" column="industry_code"/>
<result property="isHide" column="is_hide"/>
</resultMap>
<resultMap id="dictZTreeDTO" type="com.cm.common.pojo.dtos.ZTreeDTO">
<id property="id" column="dict_id"/>
<result property="pId" column="dict_parent_id"/>
<result property="name" column="dict_name"/>
</resultMap>
<!-- 新增字典 -->
<insert id="saveDict" parameterType="map">
INSERT INTO city_dict(
dict_id,
dict_parent_id,
dict_name,
dict_summary,
dict_code,
dict_order,
industry_code,
is_hide,
creator,
gmt_create,
modifier,
gmt_modified,
is_delete
) VALUES(
#{dictId},
#{dictParentId},
#{dictName},
#{dictSummary},
#{dictCode},
#{dictOrder},
#{industryCode},
#{isHide},
#{creator},
#{gmtCreate},
#{modifier},
#{gmtModified},
#{isDelete}
)
</insert>
<!-- 删除字典 -->
<update id="removeDict" parameterType="map">
UPDATE
city_dict
SET
is_delete = 1,
modifier = #{modifier},
gmt_modified = #{gmtModified}
WHERE
dict_id IN
<foreach collection="dictIds" index="index" open="(" separator="," close=")">
#{dictIds[${index}]}
</foreach>
</update>
<!-- 修改字典 -->
<update id="updateDict" parameterType="map">
UPDATE
city_dict
SET
<if test="dictName != null and dictName != ''">
dict_name = #{dictName},
</if>
<if test="dictCode != null and dictCode != ''">
dict_code = #{dictCode},
</if>
<if test="dictSummary != null">
dict_summary = #{dictSummary},
</if>
<if test="dictOrder != null">
dict_order = #{dictOrder},
</if>
<if test="industryCode != null">
industry_code = #{industryCode},
</if>
<if test="isHide != null">
is_hide = #{isHide},
</if>
modifier = #{modifier},
gmt_modified = #{gmtModified}
WHERE
dict_id = #{dictId}
</update>
<!-- ztree列表 -->
<select id="listZTreeDict" parameterType="map" resultMap="dictZTreeDTO">
SELECT
*
FROM
city_dict
WHERE
is_delete = 0
<if test="isHide != null">
AND
is_hide = #{isHide}
</if>
<if test="dictParentId != null and dictParentId != ''">
AND
dict_parent_id = #{dictParentId}
</if>
</select>
<!-- 字典列表 -->
<select id="listDict" parameterType="map" resultMap="dictDTO">
SELECT
t1.*
FROM
city_dict t1
WHERE
t1.is_delete = 0
<if test="dictParentId != null and dictParentId != ''">
AND
t1.dict_parent_id = #{dictParentId}
</if>
<if test="keywords != null and keywords != ''">
AND
t1.dict_name LIKE CONCAT('%', #{keywords}, '%')
</if>
<if test="startTime != null and startTime != ''">
AND
t1.gmt_create <![CDATA[ >= ]]> #{startTime}
</if>
<if test="isHide != null">
AND
t1.is_hide = #{isHide}
</if>
<if test="endTime != null and endTime != ''">
AND
t1.gmt_create <![CDATA[ <= ]]> #{endTime}
</if>
<if test="dictIds != null and dictIds.size > 0">
AND
t1.dict_id IN
<foreach collection="dictIds" index="index" open="(" separator="," close=")">
#{dictIds[${index}]}
</foreach>
</if>
<if test="isHide != null">
AND
t1.is_hide = #{isHide}
</if>
<choose>
<when test="sort != null and (sort == 'dictName' or sort == 'dictCode' or sort == 'dictOrder')">
ORDER BY
<if test="sort == 'dictName'">
t1.dict_name ${order}
</if>
<if test="sort == 'dictCode'">
t1.dict_code ${order}
</if>
<if test="sort == 'dictOrder'">
t1.dict_order ${order}
</if>
</when>
<otherwise>
ORDER BY
t1.dict_order, t1.gmt_create desc
</otherwise>
</choose>
</select>
<!-- 字典详情 -->
<select id="getDict" parameterType="map" resultMap="dictDTO">
SELECT
t1.*,
t2.dict_name dict_parent_name
FROM
city_dict t1
LEFT JOIN
city_dict t2
ON
t1.dict_parent_id = t2.dict_id
AND
t2.is_delete = 0
WHERE
t1.is_delete = 0
<if test="dictId != null and dictId != ''">
AND
t1.dict_id = #{dictId}
</if>
</select>
<!-- 子节点数量 -->
<select id="countByParentId" parameterType="String" resultType="Integer">
SELECT
COUNT(*)
FROM
city_dict
WHERE
is_delete = 0
AND
dict_parent_id = #{_parameter}
</select>
<!-- 获取最后一个子字典,实际数据,包含已删除,方式编码重复 -->
<select id="getLastByParentId" parameterType="String" resultMap="dictDTO">
SELECT
*
FROM
city_dict
WHERE
dict_parent_id = #{_parameter}
ORDER BY
dict_code desc
LIMIT 0, 1
</select>
<!--根据父级ID和名称查询-->
<select id="getDictByNameAndParentId" parameterType="map" resultMap="dictDTO">
SELECT
*
FROM
city_dict
WHERE
is_delete = 0
AND
dict_parent_id = #{dictParentId}
AND
dict_name = #{dictName}
LIMIT 1;
</select>
<!-- 查询案件类型绑定的职能部门ID -->
<select id="listBindDept" parameterType="map" resultType="map">
select * from city_binding_department
where is_delete = '0'
AND FIND_IN_SET(case_type, #{caseTypeIds})
</select>
<!-- 查询部门集合中是否有专管员 -->
<!-- t3.role_id = 'bc405346-8714-4ded-89ac-9cc4d755f66a' 关联专管员角色-->
<select id="listBindDeptUser" parameterType="map" resultType="map">
SELECT
t1.*,
t2.user_name
FROM
sys_department_user t1
LEFT JOIN sys_user t2 ON t1.user_id = t2.user_id AND is_delete = '0'
LEFT JOIN sys_role_user t3 ON t3.user_id = t2.user_id
WHERE
FIND_IN_SET(t1.department_id, #{deptIds})
AND t2.user_name IS NOT NULL
AND t3.role_id = 'bc405346-8714-4ded-89ac-9cc4d755f66a'
</select>
</mapper>