<?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.zksy.WaterSupply.WaterSourceInfo.mapper.WaterSourceInfoMapper">

    <resultMap id="BaseResultMap" type="com.zksy.WaterSupply.WaterSourceInfo.domain.WaterSourceInfo">
        <id column="id" property="id"/>
        <result column="source_id" property="sourceId"/>
        <result column="source_name" property="sourceName"/>
        <result column="source_type" property="sourceType"/>
        <result column="unit" property="unit"/>
        <result column="address" property="address"/>
        <result column="water_type" property="waterType"/>
        <result column="protection_level" property="protectionLevel"/>
        <result column="water_quality_level" property="waterQualityLevel"/>
        <result column="protection_scope" property="protectionScope"/>
        <result column="report_time" property="reportTime"/>
        <result column="status" property="status"/>
        <result column="remark" property="remark"/>
        <result column="del_flag" property="delFlag"/>
        <result column="create_by" property="createBy"/>
        <result column="create_time" property="createTime"/>
        <result column="update_by" property="updateBy"/>
        <result column="update_time" property="updateTime"/>
    </resultMap>

    <sql id="Base_Column_List">
        id, source_id, source_name, source_type, unit, address, water_type,
        protection_level, water_quality_level, protection_scope, report_time,
        status, remark, del_flag, create_by, create_time, update_by, update_time
    </sql>

    <select id="selectSourceList" resultMap="BaseResultMap">
        SELECT <include refid="Base_Column_List"/>
        FROM water_source_info
        WHERE del_flag = '0'
        <if test="sourceId != null and sourceId != ''">
            AND source_id LIKE CONCAT('%', #{sourceId}, '%')
        </if>
        <if test="sourceName != null and sourceName != ''">
            AND source_name LIKE CONCAT('%', #{sourceName}, '%')
        </if>
        <if test="status != null and status != ''">
            AND status = #{status}
        </if>
        <if test="unit != null and unit != ''">
            AND unit LIKE CONCAT('%', #{unit}, '%')
        </if>
        <if test="startTime != null">
            AND create_time &gt;= #{startTime}
        </if>
        <if test="endTime != null">
            AND create_time &lt;= #{endTime}
        </if>
        ORDER BY create_time DESC
    </select>

    <select id="selectDeletedList" resultMap="BaseResultMap">
        SELECT <include refid="Base_Column_List"/>
        FROM water_source_info
        WHERE del_flag = '2'
        <if test="sourceId != null and sourceId != ''">
            AND source_id LIKE CONCAT('%', #{sourceId}, '%')
        </if>
        <if test="sourceName != null and sourceName != ''">
            AND source_name LIKE CONCAT('%', #{sourceName}, '%')
        </if>
        <if test="status != null and status != ''">
            AND status = #{status}
        </if>
        <if test="startTime != null">
            AND update_time &gt;= #{startTime}
        </if>
        <if test="endTime != null">
            AND update_time &lt;= #{endTime}
        </if>
        ORDER BY update_time DESC
    </select>

    <update id="restoreByIds">
        UPDATE water_source_info
        SET del_flag = '0',
        update_by = #{updateBy},
        update_time = CURRENT_TIMESTAMP
        WHERE id IN
        <foreach collection="ids" item="id" open="(" separator="," close=")">
            #{id}
        </foreach>
    </update>

    <delete id="deleteByIdsPhysically">
        DELETE FROM water_source_info WHERE id IN
        <foreach collection="ids" item="id" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>

</mapper>