<?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.stuteasafe.IStuTeaSafeDao">

    <resultMap id="stuTeaSafeDTO" type="cn.com.tenlion.systembase.pojo.dtos.stuteasafe.StuTeaSafeDTO">
        <result column="stu_tea_safe_id" property="stuTeaSafeId"/>
        <result column="school_id" property="schoolId"/>
        <result column="case_code" property="caseCode"/>
        <result column="case_name" property="caseName"/>
        <result column="happen_time" property="happenTime"/>
        <result column="happen_location" property="happenLocation"/>
        <result column="happen_location_name" property="happenLocationName"/>
        <result column="happen_location_code" property="happenLocationCode"/>
        <result column="happen_address" property="happenAddress"/>
        <result column="case_nature" property="caseNature"/>
        <result column="case_nature_name" property="caseNatureName"/>
        <result column="case_nature_code" property="caseNatureCode"/>
        <result column="case_situation" property="caseSituation"/>
        <result column="principal_card_code" property="principalCardCode"/>
        <result column="principal_card_code_name" property="principalCardCodeName"/>
        <result column="principal_card_code_code" property="principalCardCodeCode"/>
        <result column="principal_card_num" property="principalCardNum"/>
        <result column="principal_name" property="principalName"/>
        <result column="is_solve" property="isSolve"/>
        <result column="crime_count" property="crimeCount"/>
        <result column="at_large_count" property="atLargeCount"/>
        <result column="arrest_count" property="arrestCount"/>
        <result column="case_solve" property="caseSolve"/>
        <result column="grid" property="grid"/>
        <result column="longitude" property="longitude"/>
        <result column="latitude" property="latitude"/>
    </resultMap>

    <resultMap id="stuTeaSafeBO" type="cn.com.tenlion.systembase.pojo.bos.stuteasafe.StuTeaSafeBO">
        <result column="stu_tea_safe_id" property="stuTeaSafeId"/>
        <result column="school_id" property="schoolId"/>
        <result column="case_code" property="caseCode"/>
        <result column="case_name" property="caseName"/>
        <result column="happen_time" property="happenTime"/>
        <result column="happen_location" property="happenLocation"/>
        <result column="happen_location_name" property="happenLocationName"/>
        <result column="happen_location_code" property="happenLocationCode"/>
        <result column="happen_address" property="happenAddress"/>
        <result column="case_nature" property="caseNature"/>
        <result column="case_nature_name" property="caseNatureName"/>
        <result column="case_nature_code" property="caseNatureCode"/>
        <result column="case_situation" property="caseSituation"/>
        <result column="principal_card_code" property="principalCardCode"/>
        <result column="principal_card_code_name" property="principalCardCodeName"/>
        <result column="principal_card_code_code" property="principalCardCodeCode"/>
        <result column="principal_card_num" property="principalCardNum"/>
        <result column="principal_name" property="principalName"/>
        <result column="is_solve" property="isSolve"/>
        <result column="crime_count" property="crimeCount"/>
        <result column="at_large_count" property="atLargeCount"/>
        <result column="arrest_count" property="arrestCount"/>
        <result column="case_solve" property="caseSolve"/>
    </resultMap>

    <resultMap id="stuTeaSafePO" type="cn.com.tenlion.systembase.pojo.pos.stuteasafe.StuTeaSafePO">
        <result column="stu_tea_safe_id" property="stuTeaSafeId"/>
        <result column="school_id" property="schoolId"/>
        <result column="case_code" property="caseCode"/>
        <result column="case_name" property="caseName"/>
        <result column="happen_time" property="happenTime"/>
        <result column="happen_location" property="happenLocation"/>
        <result column="happen_location_name" property="happenLocationName"/>
        <result column="happen_location_code" property="happenLocationCode"/>
        <result column="happen_address" property="happenAddress"/>
        <result column="case_nature" property="caseNature"/>
        <result column="case_nature_name" property="caseNatureName"/>
        <result column="case_nature_code" property="caseNatureCode"/>
        <result column="case_situation" property="caseSituation"/>
        <result column="principal_card_code" property="principalCardCode"/>
        <result column="principal_card_code_name" property="principalCardCodeName"/>
        <result column="principal_card_code_code" property="principalCardCodeCode"/>
        <result column="principal_card_num" property="principalCardNum"/>
        <result column="principal_name" property="principalName"/>
        <result column="is_solve" property="isSolve"/>
        <result column="crime_count" property="crimeCount"/>
        <result column="at_large_count" property="atLargeCount"/>
        <result column="arrest_count" property="arrestCount"/>
        <result column="case_solve" property="caseSolve"/>
    </resultMap>

    <!-- 新增涉及师生安全的案（事）件 -->
    <insert id="save" parameterType="map">
        INSERT INTO data_stu_tea_safe(
            stu_tea_safe_id,
            school_id,
            case_code,
            case_name,
            happen_time,
            happen_location,
            happen_location_name,
            happen_location_code,
            happen_address,
            case_nature,
            case_nature_name,
            case_nature_code,
            case_situation,
            principal_card_code,
            principal_card_code_name,
            principal_card_code_code,
            principal_card_num,
            principal_name,
            is_solve,
            crime_count,
            at_large_count,
            arrest_count,
            case_solve,
            grid,
            longitude,
            latitude,
            creator,
            gmt_create,
            modifier,
            gmt_modified,
            is_delete
        ) VALUES(
            #{stuTeaSafeId},
            #{schoolId},
            #{caseCode},
            #{caseName},
            #{happenTime},
            #{happenLocation},
            #{happenLocationName},
            #{happenLocationCode},
            #{happenAddress},
            #{caseNature},
            #{caseNatureName},
            #{caseNatureCode},
            #{caseSituation},
            #{principalCardCode},
            #{principalCardCodeName},
            #{principalCardCodeCode},
            #{principalCardNum},
            #{principalName},
            #{isSolve},
            #{crimeCount},
            #{atLargeCount},
            #{arrestCount},
            #{caseSolve},
            #{grid},
            #{longitude},
            #{latitude},
            #{creator},
            #{gmtCreate},
            #{modifier},
            #{gmtModified},
            #{isDelete}
        )
    </insert>

    <!-- 删除涉及师生安全的案（事）件 -->
    <update id="remove" parameterType="map">
        UPDATE
            data_stu_tea_safe
        SET
            gmt_modified = #{gmtModified},
            modifier = #{modifier},
            is_delete = 1
        WHERE
            stu_tea_safe_id IN
        <foreach collection="stuTeaSafeIds" index="index" open="(" separator="," close=")">
            #{stuTeaSafeIds[${index}]}
        </foreach>
    </update>

    <!-- 删除涉及师生安全的案（事）件（物理） -->
    <update id="delete" parameterType="map">
        DELETE FROM
            data_stu_tea_safe
        WHERE
            stu_tea_safe_id IN
        <foreach collection="stuTeaSafeIds" index="index" open="(" separator="," close=")">
            #{stuTeaSafeIds[${index}]}
        </foreach>
    </update>

    <!-- 修改涉及师生安全的案（事）件 -->
    <update id="update" parameterType="map">
        UPDATE
            data_stu_tea_safe
        SET
        <if test="schoolId != null and schoolId != ''">
            school_id = #{schoolId},
        </if>
        <if test="caseCode != null and caseCode != ''">
            case_code = #{caseCode},
        </if>
        <if test="caseName != null and caseName != ''">
            case_name = #{caseName},
        </if>
        <if test="happenTime != null and happenTime != ''">
            happen_time = #{happenTime},
        </if>
        <if test="happenLocation != null">
            happen_location = #{happenLocation},
        </if>
        <if test="happenLocationName != null and happenLocationName != ''">
            happen_location_name = #{happenLocationName},
        </if>
        <if test="happenLocationCode != null and happenLocationCode != ''">
            happen_location_code = #{happenLocationCode},
        </if>
        <if test="happenAddress != null and happenAddress != ''">
            happen_address = #{happenAddress},
        </if>
        <if test="caseNature != null">
            case_nature = #{caseNature},
        </if>
        <if test="caseNatureName != null and caseNatureName != ''">
            case_nature_name = #{caseNatureName},
        </if>
        <if test="caseNatureCode != null and caseNatureCode != ''">
            case_nature_code = #{caseNatureCode},
        </if>
        <if test="caseSituation != null and caseSituation != ''">
            case_situation = #{caseSituation},
        </if>
        <if test="principalCardCode != null">
            principal_card_code = #{principalCardCode},
        </if>
        <if test="principalCardCodeName != null and principalCardCodeName != ''">
            principal_card_code_name = #{principalCardCodeName},
        </if>
        <if test="principalCardCodeCode != null and principalCardCodeCode != ''">
            principal_card_code_code = #{principalCardCodeCode},
        </if>
        <if test="principalCardNum != null and principalCardNum != ''">
            principal_card_num = #{principalCardNum},
        </if>
        <if test="principalName != null and principalName != ''">
            principal_name = #{principalName},
        </if>
        <if test="isSolve != null">
            is_solve = #{isSolve},
        </if>
        <if test="crimeCount != null">
            crime_count = #{crimeCount},
        </if>
        <if test="atLargeCount != null">
            at_large_count = #{atLargeCount},
        </if>
        <if test="arrestCount != null">
            arrest_count = #{arrestCount},
        </if>
        <if test="caseSolve != null and caseSolve != ''">
            case_solve = #{caseSolve},
        </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},
            stu_tea_safe_id = stu_tea_safe_id
        WHERE
            stu_tea_safe_id = #{stuTeaSafeId}
    </update>

    <!-- 涉及师生安全的案（事）件详情 -->
    <select id="get" parameterType="map" resultMap="stuTeaSafeDTO">
        SELECT
            t1.school_id,
            t1.case_code,
            t1.case_name,
            t1.happen_time,
            t1.happen_location,
            t1.happen_location_name,
            t1.happen_location_code,
            t1.happen_address,
            t1.case_nature,
            t1.case_nature_name,
            t1.case_nature_code,
            t1.case_situation,
            t1.principal_card_code,
            t1.principal_card_code_name,
            t1.principal_card_code_code,
            t1.principal_card_num,
            t1.principal_name,
            t1.is_solve,
            t1.crime_count,
            t1.at_large_count,
            t1.arrest_count,
            t1.case_solve,
            t1.grid,
            t1.longitude,
            t1.latitude,
            t1.stu_tea_safe_id
        FROM
            data_stu_tea_safe t1
        WHERE
            t1.is_delete = 0
            <if test="stuTeaSafeId != null and stuTeaSafeId != ''">
        AND
            t1.stu_tea_safe_id = #{stuTeaSafeId}
            </if>
    </select>

    <!-- 涉及师生安全的案（事）件详情 -->
    <select id="getBO" parameterType="map" resultMap="stuTeaSafeBO">
        SELECT
            t1.stu_tea_safe_id,
            t1.school_id,
            t1.case_code,
            t1.case_name,
            t1.happen_time,
            t1.happen_location,
            t1.happen_location_name,
            t1.happen_location_code,
            t1.happen_address,
            t1.case_nature,
            t1.case_nature_name,
            t1.case_nature_code,
            t1.case_situation,
            t1.principal_card_code,
            t1.principal_card_code_name,
            t1.principal_card_code_code,
            t1.principal_card_num,
            t1.principal_name,
            t1.is_solve,
            t1.crime_count,
            t1.at_large_count,
            t1.arrest_count,
            t1.case_solve
        FROM
            data_stu_tea_safe t1
        WHERE
            t1.is_delete = 0
            <if test="stuTeaSafeId != null and stuTeaSafeId != ''">
        AND
            t1.stu_tea_safe_id = #{stuTeaSafeId}
            </if>
    </select>

    <!-- 涉及师生安全的案（事）件详情 -->
    <select id="getPO" parameterType="map" resultMap="stuTeaSafePO">
        SELECT
            t1.stu_tea_safe_id,
            t1.school_id,
            t1.case_code,
            t1.case_name,
            t1.happen_time,
            t1.happen_location,
            t1.happen_location_name,
            t1.happen_location_code,
            t1.happen_address,
            t1.case_nature,
            t1.case_nature_name,
            t1.case_nature_code,
            t1.case_situation,
            t1.principal_card_code,
            t1.principal_card_code_name,
            t1.principal_card_code_code,
            t1.principal_card_num,
            t1.principal_name,
            t1.is_solve,
            t1.crime_count,
            t1.at_large_count,
            t1.arrest_count,
            t1.case_solve
        FROM
            data_stu_tea_safe t1
        WHERE
            t1.is_delete = 0
            <if test="stuTeaSafeId != null and stuTeaSafeId != ''">
        AND
            t1.stu_tea_safe_id = #{stuTeaSafeId}
            </if>
    </select>

    <!-- 涉及师生安全的案（事）件列表 -->
    <select id="list" parameterType="map" resultMap="stuTeaSafeDTO">
        SELECT
            t1.stu_tea_safe_id,
            t1.school_id,
            t1.case_code,
            t1.case_name,
            t1.happen_time,
            t1.happen_location,
            t1.happen_location_name,
            t1.happen_location_code,
            t1.happen_address,
            t1.case_nature,
            t1.case_nature_name,
            t1.case_nature_code,
            t1.case_situation,
            t1.principal_card_code,
            t1.principal_card_code_name,
            t1.principal_card_code_code,
            t1.principal_card_num,
            t1.principal_name,
            t1.is_solve,
            t1.crime_count,
            t1.at_large_count,
            t1.arrest_count,
            t1.case_solve,
            t1.grid,
            t1.longitude,
            t1.latitude,
            1
        FROM
            data_stu_tea_safe 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="stuTeaSafeIds != null and stuTeaSafeIds.size > 0">
        AND
            t1.stu_tea_safe_id IN
            <foreach collection="stuTeaSafeIds" index="index" open="(" separator="," close=")">
                #{stuTeaSafeIds[${index}]}
            </foreach>
        </if>
    </select>

    <!-- 涉及师生安全的案（事）件列表 -->
    <select id="listBO" parameterType="map" resultMap="stuTeaSafeBO">
        SELECT
            t1.stu_tea_safe_id,
            t1.school_id,
            t1.case_code,
            t1.case_name,
            t1.happen_time,
            t1.happen_location,
            t1.happen_location_name,
            t1.happen_location_code,
            t1.happen_address,
            t1.case_nature,
            t1.case_nature_name,
            t1.case_nature_code,
            t1.case_situation,
            t1.principal_card_code,
            t1.principal_card_code_name,
            t1.principal_card_code_code,
            t1.principal_card_num,
            t1.principal_name,
            t1.is_solve,
            t1.crime_count,
            t1.at_large_count,
            t1.arrest_count,
            t1.case_solve
        FROM
            data_stu_tea_safe 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="stuTeaSafeIds != null and stuTeaSafeIds.size > 0">
        AND
            t1.stu_tea_safe_id IN
            <foreach collection="stuTeaSafeIds" index="index" open="(" separator="," close=")">
                #{stuTeaSafeIds[${index}]}
            </foreach>
        </if>
    </select>

    <!-- 涉及师生安全的案（事）件列表 -->
    <select id="listPO" parameterType="map" resultMap="stuTeaSafePO">
        SELECT
            t1.stu_tea_safe_id,
            t1.school_id,
            t1.case_code,
            t1.case_name,
            t1.happen_time,
            t1.happen_location,
            t1.happen_location_name,
            t1.happen_location_code,
            t1.happen_address,
            t1.case_nature,
            t1.case_nature_name,
            t1.case_nature_code,
            t1.case_situation,
            t1.principal_card_code,
            t1.principal_card_code_name,
            t1.principal_card_code_code,
            t1.principal_card_num,
            t1.principal_name,
            t1.is_solve,
            t1.crime_count,
            t1.at_large_count,
            t1.arrest_count,
            t1.case_solve
        FROM
            data_stu_tea_safe 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="stuTeaSafeIds != null and stuTeaSafeIds.size > 0">
        AND
            t1.stu_tea_safe_id IN
            <foreach collection="stuTeaSafeIds" index="index" open="(" separator="," close=")">
                #{stuTeaSafeIds[${index}]}
            </foreach>
        </if>
    </select>

    <!-- 涉及师生安全的案（事）件统计  -->
    <select id="count" parameterType="map" resultType="Integer">
        SELECT
            COUNT(*)
        FROM
            data_stu_tea_safe t1
        WHERE
            t1.is_delete = 0
    </select>

</mapper>