<?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.WaterPumpStation.mapper.WaterPumpStationMapper">

    <resultMap id="BaseResultMap" type="com.zksy.WaterSupply.WaterPumpStation.domain.WaterPumpStation">
        <id column="id" property="id" />
        <result column="station_code" property="stationCode" />
        <result column="station_name" property="stationName" />
        <result column="location" property="location" />
        <result column="pump_count" property="pumpCount" />
        <result column="design_flow" property="designFlow" />
        <result column="design_head" property="designHead" />
        <result column="power_capacity" property="powerCapacity" />
        <result column="commission_date" property="commissionDate" />
        <result column="status" property="status" />
        <result column="principal" property="principal" />
        <result column="contact_phone" property="contactPhone" />
        <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, station_code, station_name, location, pump_count, design_flow, design_head,
        power_capacity, commission_date, status, principal, contact_phone, remark,
        del_flag, create_by, create_time, update_by, update_time
    </sql>

    <!-- 条件查询泵站列表 -->
    <select id="selectStationList" resultMap="BaseResultMap">
        SELECT <include refid="Base_Column_List"/>
        FROM water_pump_station
        WHERE del_flag = '0'
        <if test="stationCode != null and stationCode != ''">
            AND station_code LIKE CONCAT('%', #{stationCode}, '%')
        </if>
        <if test="stationName != null and stationName != ''">
            AND station_name LIKE CONCAT('%', #{stationName}, '%')
        </if>
        <if test="status != null and status != ''">
            AND status = #{status}
        </if>
        <if test="principal != null and principal != ''">
            AND principal LIKE CONCAT('%', #{principal}, '%')
        </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>

    <!-- 回收站SQL -->
    <select id="selectDeletedList" resultMap="BaseResultMap">
        SELECT <include refid="Base_Column_List"/>
        FROM water_pump_station
        WHERE del_flag = '2'
        <if test="stationCode != null and stationCode != ''">
            AND station_code LIKE CONCAT('%', #{stationCode}, '%')
        </if>
        <if test="stationName != null and stationName != ''">
            AND station_name LIKE CONCAT('%', #{stationName}, '%')
        </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_pump_station
        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_pump_station WHERE id IN
        <foreach collection="ids" item="id" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>

</mapper>