<?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.homicide.IHomicideDao">

    <resultMap id="homicideDTO" type="cn.com.tenlion.systembase.pojo.dtos.homicide.HomicideDTO">
        <result column="homicide_id" property="homicideId"/>
        <result column="homicide_name" property="homicideName"/>
        <result column="homicide_code" property="homicideCode"/>
        <result column="homicide_start_time" property="homicideStartTime"/>
        <result column="homicide_end_time" property="homicideEndTime"/>
        <result column="brief_information" property="briefInformation"/>
        <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="grid" property="grid"/>
    </resultMap>

    <resultMap id="homicideBO" type="cn.com.tenlion.systembase.pojo.bos.homicide.HomicideBO">
        <result column="homicide_id" property="homicideId"/>
        <result column="homicide_name" property="homicideName"/>
        <result column="homicide_code" property="homicideCode"/>
        <result column="homicide_start_time" property="homicideStartTime"/>
        <result column="homicide_end_time" property="homicideEndTime"/>
        <result column="brief_information" property="briefInformation"/>
        <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"/>
    </resultMap>

    <resultMap id="homicidePO" type="cn.com.tenlion.systembase.pojo.pos.homicide.HomicidePO">
        <result column="homicide_id" property="homicideId"/>
        <result column="homicide_name" property="homicideName"/>
        <result column="homicide_code" property="homicideCode"/>
        <result column="homicide_start_time" property="homicideStartTime"/>
        <result column="homicide_end_time" property="homicideEndTime"/>
        <result column="brief_information" property="briefInformation"/>
        <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"/>
    </resultMap>

    <!-- 新增命案基本信息 -->
    <insert id="save" parameterType="map">
        INSERT INTO data_homicide(
            homicide_id,
            homicide_name,
            homicide_code,
            homicide_start_time,
            homicide_end_time,
            brief_information,
            happen_location,
            happen_location_name,
            happen_location_code,
            happen_address,
            grid,
            creator,
            gmt_create,
            modifier,
            gmt_modified,
            is_delete
        ) VALUES(
            #{homicideId},
            #{homicideName},
            #{homicideCode},
            #{homicideStartTime},
            #{homicideEndTime},
            #{briefInformation},
            #{happenLocation},
            #{happenLocationName},
            #{happenLocationCode},
            #{happenAddress},
            #{grid},
            #{creator},
            #{gmtCreate},
            #{modifier},
            #{gmtModified},
            #{isDelete}
        )
    </insert>

    <!-- 删除命案基本信息 -->
    <update id="remove" parameterType="map">
        UPDATE
            data_homicide
        SET
            gmt_modified = #{gmtModified},
            modifier = #{modifier},
            is_delete = 1
        WHERE
            homicide_id IN
        <foreach collection="homicideIds" index="index" open="(" separator="," close=")">
            #{homicideIds[${index}]}
        </foreach>
    </update>

    <!-- 删除命案基本信息（物理） -->
    <update id="delete" parameterType="map">
        DELETE FROM
            data_homicide
        WHERE
            homicide_id IN
        <foreach collection="homicideIds" index="index" open="(" separator="," close=")">
            #{homicideIds[${index}]}
        </foreach>
    </update>

    <!-- 修改命案基本信息 -->
    <update id="update" parameterType="map">
        UPDATE
            data_homicide
        SET
        <if test="homicideName != null and homicideName != ''">
            homicide_name = #{homicideName},
        </if>
        <if test="homicideCode != null and homicideCode != ''">
            homicide_code = #{homicideCode},
        </if>
        <if test="homicideStartTime != null and homicideStartTime != ''">
            homicide_start_time = #{homicideStartTime},
        </if>
        <if test="homicideEndTime != null and homicideEndTime != ''">
            homicide_end_time = #{homicideEndTime},
        </if>
        <if test="briefInformation != null and briefInformation != ''">
            brief_information = #{briefInformation},
        </if>
        <if test="happenLocation != null and happenLocation != ''">
            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="grid != null and grid != ''">
            grid = #{grid},
        </if>
            gmt_modified = #{gmtModified},
            modifier = #{modifier},
            homicide_id = homicide_id
        WHERE
            homicide_id = #{homicideId}
    </update>

    <!-- 命案基本信息详情 -->
    <select id="get" parameterType="map" resultMap="homicideDTO">
        SELECT
            t1.homicide_name,
            t1.homicide_code,
            t1.homicide_start_time,
            t1.homicide_end_time,
            t1.brief_information,
            t1.happen_location,
            t1.happen_location_name,
            t1.happen_location_code,
            t1.happen_address,
            t1.grid,
            t1.homicide_id
        FROM
            data_homicide t1
        WHERE
            t1.is_delete = 0
            <if test="homicideId != null and homicideId != ''">
        AND
            t1.homicide_id = #{homicideId}
            </if>
    </select>

    <!-- 命案基本信息详情 -->
    <select id="getBO" parameterType="map" resultMap="homicideBO">
        SELECT
            t1.homicide_id,
            t1.homicide_name,
            t1.homicide_code,
            t1.homicide_start_time,
            t1.homicide_end_time,
            t1.brief_information,
            t1.happen_location,
            t1.happen_location_name,
            t1.happen_location_code,
            t1.happen_address
        FROM
            data_homicide t1
        WHERE
            t1.is_delete = 0
            <if test="homicideId != null and homicideId != ''">
        AND
            t1.homicide_id = #{homicideId}
            </if>
    </select>

    <!-- 命案基本信息详情 -->
    <select id="getPO" parameterType="map" resultMap="homicidePO">
        SELECT
            t1.homicide_id,
            t1.homicide_name,
            t1.homicide_code,
            t1.homicide_start_time,
            t1.homicide_end_time,
            t1.brief_information,
            t1.happen_location,
            t1.happen_location_name,
            t1.happen_location_code,
            t1.happen_address
        FROM
            data_homicide t1
        WHERE
            t1.is_delete = 0
            <if test="homicideId != null and homicideId != ''">
        AND
            t1.homicide_id = #{homicideId}
            </if>
    </select>

    <!-- 命案基本信息列表 -->
    <select id="list" parameterType="map" resultMap="homicideDTO">
        SELECT
            t1.homicide_id,
            t1.homicide_name,
            t1.homicide_code,
            t1.homicide_start_time,
            t1.homicide_end_time,
            t1.brief_information,
            t1.happen_location,
            t1.happen_location_name,
            t1.happen_location_code,
            t1.happen_address,
            t1.grid,
            1
        FROM
            data_homicide t1
        WHERE
            t1.is_delete = 0
        <if test="keywords != null and keywords != ''">
        AND (
            t1.homicide_name LIKE CONCAT('%', #{keywords}, '%')
            OR
            t1.homicide_code 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="areaCode != null and areaCode != ''">
            AND t1.happen_location_code = #{areaCode}
        </if>
        <if test="areaCodeLike != null and areaCodeLike != ''">
            AND t1.happen_location_code LIKE CONCAT(#{areaCodeLike}, '%')
        </if>
        <if test="grid != null and grid != ''">
            AND t1.grid = #{grid}
        </if>
        <if test="homicideIds != null and homicideIds.size > 0">
        AND
            t1.homicide_id IN
            <foreach collection="homicideIds" index="index" open="(" separator="," close=")">
                #{homicideIds[${index}]}
            </foreach>
        </if>
    </select>

    <!-- 命案基本信息列表 -->
    <select id="listBO" parameterType="map" resultMap="homicideBO">
        SELECT
            t1.homicide_id,
            t1.homicide_name,
            t1.homicide_code,
            t1.homicide_start_time,
            t1.homicide_end_time,
            t1.brief_information,
            t1.happen_location,
            t1.happen_location_name,
            t1.happen_location_code,
            t1.happen_address
        FROM
            data_homicide 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="homicideIds != null and homicideIds.size > 0">
        AND
            t1.homicide_id IN
            <foreach collection="homicideIds" index="index" open="(" separator="," close=")">
                #{homicideIds[${index}]}
            </foreach>
        </if>
    </select>

    <!-- 命案基本信息列表 -->
    <select id="listPO" parameterType="map" resultMap="homicidePO">
        SELECT
            t1.homicide_id,
            t1.homicide_name,
            t1.homicide_code,
            t1.homicide_start_time,
            t1.homicide_end_time,
            t1.brief_information,
            t1.happen_location,
            t1.happen_location_name,
            t1.happen_location_code,
            t1.happen_address
        FROM
            data_homicide 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="homicideIds != null and homicideIds.size > 0">
        AND
            t1.homicide_id IN
            <foreach collection="homicideIds" index="index" open="(" separator="," close=")">
                #{homicideIds[${index}]}
            </foreach>
        </if>
    </select>

    <!-- 命案基本信息统计  -->
    <select id="count" parameterType="map" resultType="Integer">
        SELECT
            COUNT(*)
        FROM
            data_homicide t1
        WHERE
            t1.is_delete = 0
    </select>

</mapper>