<?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="cn.com.tenlion.systembase.dao.lrs.ILrsDao">

    <resultMap id="lrsDTO" type="cn.com.tenlion.systembase.pojo.dtos.lrs.LrsDTO">
        <result column="lrs_id" property="lrsId"/>
        <result column="lrs_area_name" property="lrsAreaName"/>
        <result column="lrs_area_level_id" property="lrsAreaLevelId"/>
        <result column="lrs_area_level_text" property="lrsAreaLevelText"/>
        <result column="lrs_subject_name" property="lrsSubjectName"/>
        <result column="lrs_subject_level_id" property="lrsSubjectLevelId"/>
        <result column="lrs_subject_level_text" property="lrsSubjectLevelText"/>
        <result column="lrs_policy_type_id" property="lrsPolicyTypeId"/>
        <result column="lrs_policy_type_text" property="lrsPolicyTypeText"/>
        <result column="creator" property="creator"/>
        <result column="gmt_create" property="gmtCreate"/>
        <result column="modifier" property="modifier"/>
        <result column="gmt_modified" property="gmtModified"/>
        <result column="is_delete" property="isDelete"/>
        <result column="location" property="location"/>
        <result column="location_code" property="locationCode"/>
        <result column="grid" property="grid"/>
    </resultMap>

    <resultMap id="lrsBO" type="cn.com.tenlion.systembase.pojo.bos.lrs.LrsBO">
        <result column="lrs_id" property="lrsId"/>
        <result column="lrs_area_name" property="lrsAreaName"/>
        <result column="lrs_area_level_id" property="lrsAreaLevelId"/>
        <result column="lrs_area_level_text" property="lrsAreaLevelText"/>
        <result column="lrs_subject_name" property="lrsSubjectName"/>
        <result column="lrs_subject_level_id" property="lrsSubjectLevelId"/>
        <result column="lrs_subject_level_text" property="lrsSubjectLevelText"/>
        <result column="lrs_policy_type_id" property="lrsPolicyTypeId"/>
        <result column="lrs_policy_type_text" property="lrsPolicyTypeText"/>
        <result column="creator" property="creator"/>
        <result column="gmt_create" property="gmtCreate"/>
        <result column="modifier" property="modifier"/>
        <result column="gmt_modified" property="gmtModified"/>
        <result column="is_delete" property="isDelete"/>
    </resultMap>

    <resultMap id="lrsPO" type="cn.com.tenlion.systembase.pojo.pos.lrs.LrsPO">
        <result column="lrs_id" property="lrsId"/>
        <result column="lrs_area_name" property="lrsAreaName"/>
        <result column="lrs_area_level_id" property="lrsAreaLevelId"/>
        <result column="lrs_area_level_text" property="lrsAreaLevelText"/>
        <result column="lrs_subject_name" property="lrsSubjectName"/>
        <result column="lrs_subject_level_id" property="lrsSubjectLevelId"/>
        <result column="lrs_subject_level_text" property="lrsSubjectLevelText"/>
        <result column="lrs_policy_type_id" property="lrsPolicyTypeId"/>
        <result column="lrs_policy_type_text" property="lrsPolicyTypeText"/>
        <result column="creator" property="creator"/>
        <result column="gmt_create" property="gmtCreate"/>
        <result column="modifier" property="modifier"/>
        <result column="gmt_modified" property="gmtModified"/>
        <result column="is_delete" property="isDelete"/>
    </resultMap>

    <!-- 新增综治领导责任制 -->
    <insert id="save" parameterType="map">
        INSERT INTO cg_lrs(
            lrs_id,
            lrs_area_name,
            lrs_area_level_id,
            lrs_area_level_text,
            lrs_subject_name,
            lrs_subject_level_id,
            lrs_subject_level_text,
            lrs_policy_type_id,
            lrs_policy_type_text,
            location,
            location_code,
            grid,
            creator,
            gmt_create,
            modifier,
            gmt_modified,
            is_delete
        ) VALUES(
            #{lrsId},
            #{lrsAreaName},
            #{lrsAreaLevelId},
            #{lrsAreaLevelText},
            #{lrsSubjectName},
            #{lrsSubjectLevelId},
            #{lrsSubjectLevelText},
            #{lrsPolicyTypeId},
            #{lrsPolicyTypeText},
            #{location},
            #{locationCode},
            #{grid},
            #{creator},
            #{gmtCreate},
            #{modifier},
            #{gmtModified},
            #{isDelete}
        )
    </insert>

    <!-- 删除综治领导责任制 -->
    <update id="remove" parameterType="map">
        UPDATE
            cg_lrs
        SET
            gmt_modified = #{gmtModified},
            modifier = #{modifier},
            is_delete = 1
        WHERE
            lrs_id IN
        <foreach collection="lrsIds" index="index" open="(" separator="," close=")">
            #{lrsIds[${index}]}
        </foreach>
    </update>

    <!-- 删除综治领导责任制（物理） -->
    <update id="delete" parameterType="map">
        DELETE FROM
            cg_lrs
        WHERE
            lrs_id IN
        <foreach collection="lrsIds" index="index" open="(" separator="," close=")">
            #{lrsIds[${index}]}
        </foreach>
    </update>

    <!-- 修改综治领导责任制 -->
    <update id="update" parameterType="map">
        UPDATE
            cg_lrs
        SET
        <if test="lrsAreaName != null and lrsAreaName != ''">
            lrs_area_name = #{lrsAreaName},
        </if>
        <if test="lrsAreaLevelId != null">
            lrs_area_level_id = #{lrsAreaLevelId},
        </if>
        <if test="lrsAreaLevelText != null and lrsAreaLevelText != ''">
            lrs_area_level_text = #{lrsAreaLevelText},
        </if>
        <if test="lrsSubjectName != null and lrsSubjectName != ''">
            lrs_subject_name = #{lrsSubjectName},
        </if>
        <if test="lrsSubjectLevelId != null">
            lrs_subject_level_id = #{lrsSubjectLevelId},
        </if>
        <if test="lrsSubjectLevelText != null and lrsSubjectLevelText != ''">
            lrs_subject_level_text = #{lrsSubjectLevelText},
        </if>
        <if test="lrsPolicyTypeId != null">
            lrs_policy_type_id = #{lrsPolicyTypeId},
        </if>
        <if test="lrsPolicyTypeText != null and lrsPolicyTypeText != ''">
            lrs_policy_type_text = #{lrsPolicyTypeText},
        </if>
        <if test="location != null and location != ''">
            location = #{location},
        </if>
        <if test="locationCode != null and locationCode != ''">
            location_code = #{locationCode},
        </if>
        <if test="grid != null and grid != ''">
            grid = #{grid},
        </if>
            gmt_modified = #{gmtModified},
            modifier = #{modifier}
        WHERE
            lrs_id = #{lrsId}
    </update>

    <!-- 综治领导责任制详情 -->
    <select id="get" parameterType="map" resultMap="lrsDTO">
        SELECT
            t1.lrs_area_name,
            t1.lrs_area_level_id,
            t1.lrs_area_level_text,
            t1.lrs_subject_name,
            t1.lrs_subject_level_id,
            t1.lrs_subject_level_text,
            t1.lrs_policy_type_id,
            t1.lrs_policy_type_text,
            t1.location,
            t1.location_code,
            t1.grid,
            t1.lrs_id
        FROM
            cg_lrs t1
        WHERE
            t1.is_delete = 0
        AND
            t1.lrs_id = #{lrsId}
    </select>

    <!-- 综治领导责任制详情 -->
    <select id="getBO" parameterType="map" resultMap="lrsBO">
        SELECT
            t1.lrs_id,
            t1.lrs_area_name,
            t1.lrs_area_level_id,
            t1.lrs_area_level_text,
            t1.lrs_subject_name,
            t1.lrs_subject_level_id,
            t1.lrs_subject_level_text,
            t1.lrs_policy_type_id,
            t1.lrs_policy_type_text,
            t1.creator,
            t1.gmt_create,
            t1.modifier,
            t1.gmt_modified,
            t1.is_delete
        FROM
            cg_lrs t1
        WHERE
            t1.is_delete = 0
        AND
            t1.lrs_id = #{lrsId}
    </select>

    <!-- 综治领导责任制详情 -->
    <select id="getPO" parameterType="map" resultMap="lrsPO">
        SELECT
            t1.lrs_id,
            t1.lrs_area_name,
            t1.lrs_area_level_id,
            t1.lrs_area_level_text,
            t1.lrs_subject_name,
            t1.lrs_subject_level_id,
            t1.lrs_subject_level_text,
            t1.lrs_policy_type_id,
            t1.lrs_policy_type_text,
            t1.creator,
            t1.gmt_create,
            t1.modifier,
            t1.gmt_modified,
            t1.is_delete
        FROM
            cg_lrs t1
        WHERE
            t1.is_delete = 0
        AND
            t1.lrs_id = #{lrsId}
    </select>

    <!-- 综治领导责任制列表 -->
    <select id="list" parameterType="map" resultMap="lrsDTO">
        SELECT
            t1.lrs_id,
            t1.lrs_area_name,
            t1.lrs_area_level_id,
            t1.lrs_area_level_text,
            t1.lrs_subject_name,
            t1.lrs_subject_level_id,
            t1.lrs_subject_level_text,
            t1.lrs_policy_type_id,
            t1.lrs_policy_type_text,
            t1.location,
            t1.location_code,
            t1.grid,
            t1.creator,
            t1.gmt_create,
            t1.modifier,
            t1.gmt_modified
        FROM
            cg_lrs t1
        WHERE
            t1.is_delete = 0
        <if test="keywords != null and keywords != ''">
        AND (
            t1.lrs_area_name LIKE CONCAT('%', #{keywords}, '%')
            OR
            t1.lrs_subject_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="lrsAreaLevelId != null and lrsAreaLevelId != ''">
            AND t1.lrs_area_level_id = #{lrsAreaLevelId}
        </if>
        <if test="lrsSubjectLevelId != null and lrsSubjectLevelId != ''">
            AND t1.lrs_subject_level_id = #{lrsSubjectLevelId}
        </if>
        <if test="lrsPolicyTypeId != null and lrsPolicyTypeId != ''">
            AND t1.lrs_policy_type_id = #{lrsPolicyTypeId}
        </if>
        ORDER BY t1.gmt_create DESC
    </select>

    <!-- 综治领导责任制列表 -->
    <select id="listBO" parameterType="map" resultMap="lrsBO">
        SELECT
            t1.lrs_id,
            t1.lrs_area_name,
            t1.lrs_area_level_id,
            t1.lrs_area_level_text,
            t1.lrs_subject_name,
            t1.lrs_subject_level_id,
            t1.lrs_subject_level_text,
            t1.lrs_policy_type_id,
            t1.lrs_policy_type_text,
            t1.creator,
            t1.gmt_create,
            t1.modifier,
            t1.gmt_modified,
            t1.is_delete
        FROM
            cg_lrs 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="lrsIds != null and lrsIds.size > 0">
        AND
            t1.lrs_id IN
            <foreach collection="lrsIds" index="index" open="(" separator="," close=")">
                #{lrsIds[${index}]}
            </foreach>
        </if>
        ORDER BY t1.gmt_create DESC
    </select>

    <!-- 综治领导责任制列表 -->
    <select id="listPO" parameterType="map" resultMap="lrsPO">
        SELECT
            t1.lrs_id,
            t1.lrs_area_name,
            t1.lrs_area_level_id,
            t1.lrs_area_level_text,
            t1.lrs_subject_name,
            t1.lrs_subject_level_id,
            t1.lrs_subject_level_text,
            t1.lrs_policy_type_id,
            t1.lrs_policy_type_text,
            t1.creator,
            t1.gmt_create,
            t1.modifier,
            t1.gmt_modified,
            t1.is_delete
        FROM
            cg_lrs 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="lrsIds != null and lrsIds.size > 0">
        AND
            t1.lrs_id IN
            <foreach collection="lrsIds" index="index" open="(" separator="," close=")">
                #{lrsIds[${index}]}
            </foreach>
        </if>
        ORDER BY t1.gmt_create DESC
    </select>

    <!-- 综治领导责任制统计  -->
    <select id="count" parameterType="map" resultType="Integer">
        SELECT
            COUNT(*)
        FROM
            cg_lrs t1
        WHERE
            t1.is_delete = 0
    </select>

</mapper>