twoduty/src/main/resources/mybatis/mapper/indexlib/indexLib-mapper.xml
2021-04-28 16:24:17 +08:00

447 lines
15 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.tenlion.twoduty.dao.indexlib.IIndexLibDao">
<resultMap id="indexLibDTO" type="com.tenlion.twoduty.pojo.dtos.indexlib.IndexLibDTO">
<result column="index_lib_id" property="indexLibId"/>
<result column="index_lib_name" property="indexLibName"/>
<result column="index_lib_parent_id" property="indexLibParentId"/>
<result column="index_lib_parent_name" property="indexLibParentName"/>
<result column="index_lib_sort" property="indexLibSort"/>
<result column="index_lib_remark" property="indexLibRemark"/>
<result column="index_lib_state" property="indexLibState"/>
<result column="index_template_id" property="indexTemplateId"/>
<result column="index_template_name" property="indexTemplateName"/>
<result column="index_template_save_path" property="indexTemplateSavePath"/>
<result column="index_template_upload_path" property="indexTemplateUploadPath"/>
<result column="index_template_list_path" property="indexTemplateListPath"/>
</resultMap>
<resultMap id="indexLibBO" type="com.tenlion.twoduty.pojo.bos.indexlib.IndexLibBO">
<result column="index_lib_id" property="indexLibId"/>
<result column="index_lib_name" property="indexLibName"/>
<result column="index_lib_parent_id" property="indexLibParentId"/>
<result column="index_lib_sort" property="indexLibSort"/>
<result column="index_lib_remark" property="indexLibRemark"/>
<result column="index_lib_state" property="indexLibState"/>
<result column="index_template_id" property="indexTemplateId"/>
<result column="gmt_create" property="gmtCreate"/>
<result column="creator" property="creator"/>
<result column="gmt_modified" property="gmtModified"/>
<result column="modifier" property="modifier"/>
<result column="is_delete" property="isDelete"/>
</resultMap>
<resultMap id="indexLibPO" type="com.tenlion.twoduty.pojo.pos.indexlib.IndexLibPO">
<result column="index_lib_id" property="indexLibId"/>
<result column="index_lib_name" property="indexLibName"/>
<result column="index_lib_parent_id" property="indexLibParentId"/>
<result column="index_lib_sort" property="indexLibSort"/>
<result column="index_lib_remark" property="indexLibRemark"/>
<result column="index_lib_state" property="indexLibState"/>
<result column="index_template_id" property="indexTemplateId"/>
<result column="gmt_create" property="gmtCreate"/>
<result column="creator" property="creator"/>
<result column="gmt_modified" property="gmtModified"/>
<result column="modifier" property="modifier"/>
<result column="is_delete" property="isDelete"/>
</resultMap>
<resultMap id="indexLibZTreeDTO" type="com.tenlion.twoduty.pojo.dtos.indexlib.IndexLibZTreeDTO">
<result column="index_lib_id" property="id"/>
<result column="index_lib_name" property="name"/>
<result column="index_lib_parent_id" property="pId"/>
</resultMap>
<resultMap id="indexLibCountDTO" type="com.tenlion.twoduty.pojo.dtos.indexlib.IndexLibCountDTO">
<result column="count_1" property="count1"/>
<result column="count_2" property="count2"/>
<result column="count_3" property="count3"/>
<result column="count_4" property="count4"/>
</resultMap>
<!-- 树形列表 -->
<select id="listZTreeWeb" parameterType="map" resultMap="indexLibZTreeDTO">
SELECT
t1.index_lib_id,
t1.index_lib_name,
t1.index_lib_parent_id
FROM
duty_index_lib t1
WHERE
t1.is_delete = 0
AND t1.index_lib_state = 1
AND (t1.index_template_id = '' OR t1.index_template_id IS NULL)
AND t1.index_lib_parent_id = #{indexLibParentId}
ORDER BY
t1.index_lib_sort
</select>
<!-- web页面统计根据父级ID -->
<select id="countByParentIdWeb" parameterType="map" resultType="Integer">
SELECT
COUNT(*)
FROM
duty_index_lib t1
WHERE
t1.is_delete = 0 AND t1.index_lib_parent_id = #{parentId}
AND t1.index_lib_state = 1
AND (t1.index_template_id = '' OR t1.index_template_id IS NULL)
</select>
<!-- 树形列表 -->
<select id="listZTree" parameterType="map" resultMap="indexLibZTreeDTO">
SELECT
t1.index_lib_id,
t1.index_lib_name,
t1.index_lib_parent_id
FROM
duty_index_lib t1
WHERE
t1.is_delete = 0 AND t1.index_lib_parent_id = #{indexLibParentId}
ORDER BY
t1.index_lib_sort
</select>
<!-- 统计根据父级ID -->
<select id="countByParentId" parameterType="map" resultType="Integer">
SELECT
COUNT(*)
FROM
duty_index_lib t1
WHERE
t1.is_delete = 0 AND t1.index_lib_parent_id = #{parentId}
</select>
<!-- 新增 -->
<insert id="save" parameterType="map">
INSERT INTO duty_index_lib(
index_lib_id,
index_lib_name,
index_lib_parent_id,
index_lib_sort,
index_lib_remark,
index_lib_state,
index_template_id,
gmt_create,
creator,
gmt_modified,
modifier,
is_delete
) VALUES(
#{indexLibId},
#{indexLibName},
#{indexLibParentId},
#{indexLibSort},
#{indexLibRemark},
#{indexLibState},
#{indexTemplateId},
#{gmtCreate},
#{creator},
#{gmtModified},
#{modifier},
#{isDelete}
)
</insert>
<!-- 删除 -->
<update id="remove" parameterType="map">
UPDATE
duty_index_lib
SET
gmt_modified = #{gmtModified},
modifier = #{modifier},
is_delete = 1
WHERE
index_lib_id IN
<foreach collection="indexLibIds" index="index" open="(" separator="," close=")">
#{indexLibIds[${index}]}
</foreach>
</update>
<!-- 删除(物理) -->
<update id="delete" parameterType="map">
DELETE FROM
duty_index_lib
WHERE
index_lib_id IN
<foreach collection="indexLibIds" index="index" open="(" separator="," close=")">
#{indexLibIds[${index}]}
</foreach>
</update>
<!-- 修改 -->
<update id="update" parameterType="map">
UPDATE
duty_index_lib
SET
<if test="indexLibName != null and indexLibName != ''">
index_lib_name = #{indexLibName},
</if>
<if test="indexLibParentId != null and indexLibParentId != ''">
index_lib_parent_id = #{indexLibParentId},
</if>
<if test="indexLibSort != null and indexLibSort != ''">
index_lib_sort = #{indexLibSort},
</if>
<if test="indexLibRemark != null and indexLibRemark != ''">
index_lib_remark = #{indexLibRemark},
</if>
<if test="indexLibState != null and indexLibState != ''">
index_lib_state = #{indexLibState},
</if>
index_template_id = #{indexTemplateId},
gmt_modified = #{gmtModified},
modifier = #{modifier}
WHERE
index_lib_id = #{indexLibId}
</update>
<!-- 详情 -->
<select id="get" parameterType="map" resultMap="indexLibDTO">
SELECT
t1.index_lib_id,
t1.index_lib_name,
t1.index_lib_parent_id,
t2.index_lib_name index_lib_parent_name,
t1.index_lib_sort,
t1.index_lib_remark,
t1.index_lib_state,
t1.index_template_id
FROM
duty_index_lib t1
LEFT JOIN duty_index_lib t2
ON t1.index_lib_parent_id = t2.index_lib_id
WHERE
t1.is_delete = 0
<if test="indexLibId != null and indexLibId != ''">
AND
t1.index_lib_id = #{indexLibId}
</if>
</select>
<!-- 详情 -->
<select id="getBO" parameterType="map" resultMap="indexLibBO">
SELECT
t1.index_lib_id,
t1.index_lib_name,
t1.index_lib_parent_id,
t1.index_lib_sort,
t1.index_lib_remark,
t1.index_lib_state,
t1.index_template_id,
t1.gmt_create,
t1.creator,
t1.gmt_modified,
t1.modifier,
t1.is_delete
FROM
duty_index_lib t1
WHERE
t1.is_delete = 0
<if test="indexLibId != null and indexLibId != ''">
AND
t1.index_lib_id = #{indexLibId}
</if>
</select>
<!-- 详情 -->
<select id="getPO" parameterType="map" resultMap="indexLibPO">
SELECT
t1.index_lib_id,
t1.index_lib_name,
t1.index_lib_parent_id,
t1.index_lib_sort,
t1.index_lib_remark,
t1.index_lib_state,
t1.index_template_id,
t1.gmt_create,
t1.creator,
t1.gmt_modified,
t1.modifier,
t1.is_delete
FROM
duty_index_lib t1
WHERE
t1.is_delete = 0
<if test="indexLibId != null and indexLibId != ''">
AND
t1.index_lib_id = #{indexLibId}
</if>
</select>
<!-- 列表 -->
<select id="list" parameterType="map" resultMap="indexLibDTO">
SELECT
t1.index_lib_id,
t1.index_lib_name,
t1.index_lib_parent_id,
t2.index_lib_name index_lib_parent_name,
t1.index_lib_sort,
t1.index_lib_remark,
t1.index_lib_state,
t1.index_template_id,
t3.index_template_name,
t3.index_template_save_path,
t3.index_template_upload_path,
t3.index_template_list_path
FROM
duty_index_lib t1
LEFT JOIN duty_index_lib t2
ON t1.index_lib_parent_id = t2.index_lib_id
LEFT JOIN duty_index_template t3
ON t1.index_template_id = t3.index_template_id
WHERE
t1.is_delete = 0
<if test="keywords != null and keywords != ''">
AND (
<!-- 这里添加其他条件 -->
t1.index_lib_name LIKE CONCAT('%', #{keywords}, '%')
)
</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="indexLibIds != null and indexLibIds.size > 0">
AND
t1.index_lib_id IN
<foreach collection="indexLibIds" index="index" open="(" separator="," close=")">
#{indexLibIds[${index}]}
</foreach>
</if>
<if test="indexLibParentId != null and indexLibParentId != ''">
AND t1.index_lib_parent_id = #{indexLibParentId}
</if>
<if test="indexLibState != null and indexLibState != ''">
AND t1.index_lib_state = #{indexLibState}
</if>
ORDER BY t1.index_lib_sort
</select>
<!-- 列表 -->
<select id="listBO" parameterType="map" resultMap="indexLibBO">
SELECT
t1.index_lib_id,
t1.index_lib_name,
t1.index_lib_parent_id,
t1.index_lib_sort,
t1.index_lib_remark,
t1.index_lib_state,
t1.index_template_id,
t1.gmt_create,
t1.creator,
t1.gmt_modified,
t1.modifier,
t1.is_delete
FROM
duty_index_lib t1
WHERE
t1.is_delete = 0
<if test="keywords != null and keywords != ''">
AND (
<!-- 这里添加其他条件 -->
t1.id LIKE CONCAT('%', #{keywords}, '%')
)
</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="indexLibIds != null and indexLibIds.size > 0">
AND
t1.index_lib_id IN
<foreach collection="indexLibIds" index="index" open="(" separator="," close=")">
#{indexLibIds[${index}]}
</foreach>
</if>
</select>
<!-- 列表 -->
<select id="listPO" parameterType="map" resultMap="indexLibPO">
SELECT
t1.index_lib_id,
t1.index_lib_name,
t1.index_lib_parent_id,
t1.index_lib_sort,
t1.index_lib_remark,
t1.index_lib_state,
t1.index_template_id,
t1.gmt_create,
t1.creator,
t1.gmt_modified,
t1.modifier,
t1.is_delete
FROM
duty_index_lib t1
WHERE
t1.is_delete = 0
<if test="keywords != null and keywords != ''">
AND (
<!-- 这里添加其他条件 -->
t1.id LIKE CONCAT('%', #{keywords}, '%')
)
</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="indexLibIds != null and indexLibIds.size > 0">
AND
t1.index_lib_id IN
<foreach collection="indexLibIds" index="index" open="(" separator="," close=")">
#{indexLibIds[${index}]}
</foreach>
</if>
</select>
<!-- 统计 -->
<select id="count" parameterType="map" resultType="Integer">
SELECT
COUNT(*)
FROM
duty_index_lib t1
WHERE
t1.is_delete = 0
</select>
<!-- 统计指标状态数量 -->
<select id="countIndexLibAuditStatusNum" parameterType="map" resultMap="indexLibCountDTO">
SELECT
COUNT(CASE WHEN `audit_status` = 0 THEN 1 ELSE NULL END) AS 'count_1' ,
COUNT(CASE WHEN `audit_status` = 1 THEN 1 ELSE NULL END) AS 'count_2',
COUNT(CASE WHEN `audit_status` = 2 THEN 1 ELSE NULL END) AS 'count_3',
COUNT(CASE WHEN `audit_status` = -1 THEN 1 ELSE NULL END) AS 'count_4'
FROM
${tableName}
WHERE is_delete = 0 AND duty_index_lib_id = #{indexLibId}
<if test="creator != '1'.toString()">
AND creator = #{creator}
</if>
</select>
</mapper>