<?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.WaterUserInfo.mapper.WaterUserInfoMapper">

    <resultMap id="BaseResultMap" type="com.zksy.WaterSupply.WaterUserInfo.domain.WaterUserInfo">
        <id column="id" property="id"/>
        <result column="user_code" property="userCode"/>
        <result column="user_name" property="userName"/>
        <result column="user_type" property="userType"/>
        <result column="address" property="address"/>
        <result column="contact_person" property="contactPerson"/>
        <result column="contact_phone" property="contactPhone"/>
        <result column="meter_number" property="meterNumber"/>
        <result column="initial_reading" property="initialReading"/>
        <result column="current_reading" property="currentReading"/>
        <result column="annual_water_consumption" property="annualWaterConsumption"/>
        <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, user_code, user_name, user_type, address, contact_person, contact_phone,
        meter_number, initial_reading, current_reading, annual_water_consumption,
        status, remark, del_flag, create_by, create_time, update_by, update_time
    </sql>

    <select id="selectUserList" resultMap="BaseResultMap">
        SELECT <include refid="Base_Column_List"/>
        FROM water_user_info
        WHERE del_flag = '0'
        <if test="userCode != null and userCode != ''">
            AND user_code LIKE CONCAT('%', #{userCode}, '%')
        </if>
        <if test="userName != null and userName != ''">
            AND user_name LIKE CONCAT('%', #{userName}, '%')
        </if>
        <if test="status != null and status != ''">
            AND status = #{status}
        </if>
        <if test="userType != null and userType != ''">
            AND user_type = #{userType}
        </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_user_info
        WHERE del_flag = '2'
        <if test="userCode != null and userCode != ''">
            AND user_code LIKE CONCAT('%', #{userCode}, '%')
        </if>
        <if test="userName != null and userName != ''">
            AND user_name LIKE CONCAT('%', #{userName}, '%')
        </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_user_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_user_info WHERE id IN
        <foreach collection="ids" item="id" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>

</mapper>