<?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.schoolkey.ISchoolKeyDao">

    <resultMap id="schoolKeyDTO" type="cn.com.tenlion.systembase.pojo.dtos.schoolkey.SchoolKeyDTO">
        <result column="school_key_id" property="schoolKeyId"/>
        <result column="school_id" property="schoolId"/>
        <result column="base_id" property="baseId"/>
        <result column="degree_of_harm" property="degreeOfHarm"/>
        <result column="degree_of_harm_name" property="degreeOfHarmName"/>
        <result column="degree_of_harm_code" property="degreeOfHarmCode"/>
        <result column="is_follow" property="isFollow"/>
        <result column="location" property="location"/>
        <result column="location_code" property="locationCode"/>
        <result column="grid" property="grid"/>
        <result column="longitude" property="longitude"/>
        <result column="latitude" property="latitude"/>
    </resultMap>

    <resultMap id="schoolKeyBO" type="cn.com.tenlion.systembase.pojo.bos.schoolkey.SchoolKeyBO">
        <result column="school_key_id" property="schoolKeyId"/>
        <result column="school_id" property="schoolId"/>
        <result column="base_id" property="baseId"/>
        <result column="degree_of_harm" property="degreeOfHarm"/>
        <result column="degree_of_harm_name" property="degreeOfHarmName"/>
        <result column="degree_of_harm_code" property="degreeOfHarmCode"/>
        <result column="is_follow" property="isFollow"/>
    </resultMap>

    <resultMap id="schoolKeyPO" type="cn.com.tenlion.systembase.pojo.pos.schoolkey.SchoolKeyPO">
        <result column="school_key_id" property="schoolKeyId"/>
        <result column="school_id" property="schoolId"/>
        <result column="base_id" property="baseId"/>
        <result column="degree_of_harm" property="degreeOfHarm"/>
        <result column="degree_of_harm_name" property="degreeOfHarmName"/>
        <result column="degree_of_harm_code" property="degreeOfHarmCode"/>
        <result column="is_follow" property="isFollow"/>
    </resultMap>

    <!-- 新增学校周边重点人员 -->
    <insert id="save" parameterType="map">
        INSERT INTO data_school_key(
            school_key_id,
            base_id,
            degree_of_harm,
            degree_of_harm_name,
            degree_of_harm_code,
            is_follow,
            school_id,
            location,
            location_code,
            grid,
            longitude,
            latitude,
            creator,
            gmt_create,
            modifier,
            gmt_modified,
            is_delete
        ) VALUES(
            #{schoolKeyId},
            #{baseId},
            #{degreeOfHarm},
            #{degreeOfHarmName},
            #{degreeOfHarmCode},
            #{isFollow},
            #{schoolId},
            #{location},
            #{locationCode},
            #{grid},
            #{longitude},
            #{latitude},
            #{creator},
            #{gmtCreate},
            #{modifier},
            #{gmtModified},
            #{isDelete}
        )
    </insert>

    <!-- 删除学校周边重点人员 -->
    <update id="remove" parameterType="map">
        UPDATE
            data_school_key
        SET
            gmt_modified = #{gmtModified},
            modifier = #{modifier},
            is_delete = 1
        WHERE
            school_key_id IN
        <foreach collection="schoolKeyIds" index="index" open="(" separator="," close=")">
            #{schoolKeyIds[${index}]}
        </foreach>
    </update>

    <!-- 删除学校周边重点人员（物理） -->
    <update id="delete" parameterType="map">
        DELETE FROM
            data_school_key
        WHERE
            school_key_id IN
        <foreach collection="schoolKeyIds" index="index" open="(" separator="," close=")">
            #{schoolKeyIds[${index}]}
        </foreach>
    </update>

    <!-- 修改学校周边重点人员 -->
    <update id="update" parameterType="map">
        UPDATE
            data_school_key
        SET
        <if test="schoolId != null and schoolId != ''">
            school_id = #{schoolId},
        </if>
        <if test="baseId != null and baseId != ''">
            base_id = #{baseId},
        </if>
        <if test="degreeOfHarm != null">
            degree_of_harm = #{degreeOfHarm},
        </if>
        <if test="degreeOfHarmName != null and degreeOfHarmName != ''">
            degree_of_harm_name = #{degreeOfHarmName},
        </if>
        <if test="degreeOfHarmCode != null and degreeOfHarmCode != ''">
            degree_of_harm_code = #{degreeOfHarmCode},
        </if>
        <if test="isFollow != null">
            is_follow = #{isFollow},
        </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>
        <if test="longitude != null">
            longitude = #{longitude},
        </if>
        <if test="latitude != null">
            latitude = #{latitude},
        </if>
            gmt_modified = #{gmtModified},
            modifier = #{modifier},
            school_key_id = school_key_id
        WHERE
            school_key_id = #{schoolKeyId}
    </update>

    <!-- 学校周边重点人员详情 -->
    <select id="get" parameterType="map" resultMap="schoolKeyDTO">
        SELECT
            t1.base_id,
            t1.school_id,
            t1.degree_of_harm,
            t1.degree_of_harm_name,
            t1.degree_of_harm_code,
            t1.is_follow,
            t1.location,
            t1.location_code,
            t1.grid,
            t1.latitude,
            t1.longitude,
            t1.school_key_id
        FROM
            data_school_key t1
        WHERE
            t1.is_delete = 0
            <if test="schoolKeyId != null and schoolKeyId != ''">
        AND
            t1.school_key_id = #{schoolKeyId}
            </if>
    </select>

    <!-- 学校周边重点人员详情 -->
    <select id="getBO" parameterType="map" resultMap="schoolKeyBO">
        SELECT
            t1.school_key_id,
            t1.school_id,
            t1.base_id,
            t1.degree_of_harm,
            t1.degree_of_harm_name,
            t1.degree_of_harm_code,
            t1.is_follow
        FROM
            data_school_key t1
        WHERE
            t1.is_delete = 0
            <if test="schoolKeyId != null and schoolKeyId != ''">
        AND
            t1.school_key_id = #{schoolKeyId}
            </if>
    </select>

    <!-- 学校周边重点人员详情 -->
    <select id="getPO" parameterType="map" resultMap="schoolKeyPO">
        SELECT
            t1.school_key_id,
            t1.school_id,
            t1.base_id,
            t1.degree_of_harm,
            t1.degree_of_harm_name,
            t1.degree_of_harm_code,
            t1.is_follow
        FROM
            data_school_key t1
        WHERE
            t1.is_delete = 0
            <if test="schoolKeyId != null and schoolKeyId != ''">
        AND
            t1.school_key_id = #{schoolKeyId}
            </if>
    </select>

    <!-- 学校周边重点人员列表 -->
    <select id="list" parameterType="map" resultMap="schoolKeyDTO">
        SELECT
            t1.school_key_id,
            t1.school_id,
            t1.base_id,
            t1.degree_of_harm,
            t1.degree_of_harm_name,
            t1.degree_of_harm_code,
            t1.is_follow,
            t1.location,
            t1.location_code,
            t1.grid,
            t1.longitude,
            t1.latitude,
            1
        FROM
            data_school_key t1
        WHERE
            t1.is_delete = 0
        <if test="keywords != null and keywords != ''">
        AND (
            <!-- 这里添加其他条件 -->
            t1.id LIKE CONCAT('%', #{keywords}, '%')
        )
        </if>
        <if test="schoolId != null and schoolId != ''">
        AND
            t1.school_id = #{schoolId}
        </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="schoolKeyIds != null and schoolKeyIds.size > 0">
        AND
            t1.school_key_id IN
            <foreach collection="schoolKeyIds" index="index" open="(" separator="," close=")">
                #{schoolKeyIds[${index}]}
            </foreach>
        </if>
    </select>

    <!-- 学校周边重点人员列表 -->
    <select id="listBO" parameterType="map" resultMap="schoolKeyBO">
        SELECT
            t1.school_key_id,
            t1.school_id,
            t1.base_id,
            t1.degree_of_harm,
            t1.degree_of_harm_name,
            t1.degree_of_harm_code,
            t1.is_follow
        FROM
            data_school_key t1
        WHERE
            t1.is_delete = 0
        <if test="keywords != null and keywords != ''">
        AND (
            <!-- 这里添加其他条件 -->
            t1.id LIKE CONCAT('%', #{keywords}, '%')
        )
        </if>
        <if test="schoolId != null and schoolId != ''">
            AND
            t1.school_id = #{schoolId}
        </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="schoolKeyIds != null and schoolKeyIds.size > 0">
        AND
            t1.school_key_id IN
            <foreach collection="schoolKeyIds" index="index" open="(" separator="," close=")">
                #{schoolKeyIds[${index}]}
            </foreach>
        </if>
    </select>

    <!-- 学校周边重点人员列表 -->
    <select id="listPO" parameterType="map" resultMap="schoolKeyPO">
        SELECT
            t1.school_key_id,
            t1.school_id,
            t1.base_id,
            t1.degree_of_harm,
            t1.degree_of_harm_name,
            t1.degree_of_harm_code,
            t1.is_follow
        FROM
            data_school_key t1
        WHERE
            t1.is_delete = 0
        <if test="keywords != null and keywords != ''">
        AND (
            <!-- 这里添加其他条件 -->
            t1.id LIKE CONCAT('%', #{keywords}, '%')
        )
        </if>
        <if test="schoolId != null and schoolId != ''">
            AND
            t1.school_id = #{schoolId}
        </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="schoolKeyIds != null and schoolKeyIds.size > 0">
        AND
            t1.school_key_id IN
            <foreach collection="schoolKeyIds" index="index" open="(" separator="," close=")">
                #{schoolKeyIds[${index}]}
            </foreach>
        </if>
    </select>

    <!-- 学校周边重点人员统计  -->
    <select id="count" parameterType="map" resultType="Integer">
        SELECT
            COUNT(*)
        FROM
            data_school_key t1
        WHERE
            t1.is_delete = 0
    </select>

</mapper>