<?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.ruoyi.powerdistribution.mapper.PdmMaintenanceProcessMapper">
    
    <resultMap type="PdmMaintenanceProcess" id="PdmMaintenanceProcessResult">
        <result property="id"    column="id"    />
        <result property="planCode"    column="plan_code"    />
        <result property="powerOutageDevices"    column="power_outage_devices"    />
        <result property="perHourHouseholdsM"    column="per_hour_households_m"    />
        <result property="perHourHouseholdsW"    column="per_hour_households_w"    />
        <result property="city"    column="city"    />
        <result property="county"    column="county"    />
        <result property="station"    column="station"    />
        <result property="lineCode"    column="line_code"    />
        <result property="lineName"    column="line_name"    />
        <result property="perHourHouseholdsArtif"    column="per_hour_households_artif"    />
        <result property="declarAgency"    column="declar_agency"    />
        <result property="isMaintenance"    column="is_maintenance"    />
        <result property="isApprove"    column="is_approve"    />
        <result property="maintenanceFilePath"    column="maintenance_file_path"    />
        <result property="approveFilePath"    column="approve_file_path"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectPdmMaintenanceProcessVo">
        select id, plan_code, power_outage_devices, per_hour_households_m, per_hour_households_w, city, county, station, line_code, line_name, per_hour_households_artif,declar_agency, is_maintenance, is_approve, maintenance_file_path, approve_file_path, create_by, create_time, update_by, update_time from pdm_maintenance_process
    </sql>

    <select id="selectPdmMaintenanceProcessList" parameterType="PdmMaintenanceProcess" resultMap="PdmMaintenanceProcessResult">
        <include refid="selectPdmMaintenanceProcessVo"/>
        <where>  
            <if test="planCode != null  and planCode != ''"> and plan_code like concat('%', #{planCode}, '%')</if>
            <if test="powerOutageDevices != null "> and power_outage_devices = #{powerOutageDevices}</if>
            <if test="perHourHouseholdsM != null "> and per_hour_households_m = #{perHourHouseholdsM}</if>
            <if test="perHourHouseholdsW != null "> and per_hour_households_w = #{perHourHouseholdsW}</if>
            <if test="city != null  and city != ''"> and city = #{city}</if>
            <if test="county != null  and county != ''"> and county like concat('%', #{county}, '%')</if>
            <if test="station != null  and station != ''"> and station like concat('%', #{station}, '%')</if>
            <if test="lineCode != null  and lineCode != ''"> and line_code = #{lineCode}</if>
            <if test="lineName != null  and lineName != ''"> and line_name like concat('%', #{lineName}, '%')</if>
            <if test="perHourHouseholdsArtif != null "> and per_hour_households_artif = #{perHourHouseholdsArtif}</if>
            <if test="declarAgency != null  and declarAgency != ''"> and declar_agency = #{declarAgency}</if>
            <if test="isMaintenance != null  and isMaintenance != ''"> and is_maintenance = #{isMaintenance}</if>
            <if test="isApprove != null  and isApprove != ''"> and is_approve = #{isApprove}</if>
            <if test="maintenanceFilePath != null  and maintenanceFilePath != ''"> and maintenance_file_path = #{maintenanceFilePath}</if>
            <if test="approveFilePath != null  and approveFilePath != ''"> and approve_file_path = #{approveFilePath}</if>
        </where>
    </select>
    
    <select id="selectPdmMaintenanceProcessById" parameterType="Long" resultMap="PdmMaintenanceProcessResult">
        <include refid="selectPdmMaintenanceProcessVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertPdmMaintenanceProcess" parameterType="PdmMaintenanceProcess" useGeneratedKeys="true" keyProperty="id">
        insert into pdm_maintenance_process
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="planCode != null">plan_code,</if>
            <if test="powerOutageDevices != null">power_outage_devices,</if>
            <if test="perHourHouseholdsM != null">per_hour_households_m,</if>
            <if test="perHourHouseholdsW != null">per_hour_households_w,</if>
            <if test="city != null">city,</if>
            <if test="county != null">county,</if>
            <if test="station != null">station,</if>
            <if test="lineCode != null">line_code,</if>
            <if test="lineName != null">line_name,</if>
            <if test="perHourHouseholdsArtif != null">per_hour_households_artif,</if>
            <if test="declarAgency != null">declar_agency,</if>
            <if test="isMaintenance != null">is_maintenance,</if>
            <if test="isApprove != null">is_approve,</if>
            <if test="maintenanceFilePath != null">maintenance_file_path,</if>
            <if test="approveFilePath != null">approve_file_path,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="planCode != null">#{planCode},</if>
            <if test="powerOutageDevices != null">#{powerOutageDevices},</if>
            <if test="perHourHouseholdsM != null">#{perHourHouseholdsM},</if>
            <if test="perHourHouseholdsW != null">#{perHourHouseholdsW},</if>
            <if test="city != null">#{city},</if>
            <if test="county != null">#{county},</if>
            <if test="station != null">#{station},</if>
            <if test="lineCode != null">#{lineCode},</if>
            <if test="lineName != null">#{lineName},</if>
            <if test="perHourHouseholdsArtif != null">#{perHourHouseholdsArtif},</if>
            <if test="declarAgency != null">#{declarAgency},</if>
            <if test="isMaintenance != null">#{isMaintenance},</if>
            <if test="isApprove != null">#{isApprove},</if>
            <if test="maintenanceFilePath != null">#{maintenanceFilePath},</if>
            <if test="approveFilePath != null">#{approveFilePath},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <update id="updatePdmMaintenanceProcess" parameterType="PdmMaintenanceProcess">
        update pdm_maintenance_process
        <trim prefix="SET" suffixOverrides=",">
            <if test="planCode != null">plan_code = #{planCode},</if>
            <if test="powerOutageDevices != null">power_outage_devices = #{powerOutageDevices},</if>
            <if test="perHourHouseholdsM != null">per_hour_households_m = #{perHourHouseholdsM},</if>
            <if test="perHourHouseholdsW != null">per_hour_households_w = #{perHourHouseholdsW},</if>
            <if test="city != null">city = #{city},</if>
            <if test="county != null">county = #{county},</if>
            <if test="station != null">station = #{station},</if>
            <if test="lineCode != null">line_code = #{lineCode},</if>
            <if test="lineName != null">line_name = #{lineName},</if>
            <if test="perHourHouseholdsArtif != null">per_hour_households_artif = #{perHourHouseholdsArtif},</if>
            <if test="declarAgency != null">declar_agency = #{declarAgency},</if>
            <if test="isMaintenance != null">is_maintenance = #{isMaintenance},</if>
            <if test="isApprove != null">is_approve = #{isApprove},</if>
            <if test="maintenanceFilePath != null">maintenance_file_path = #{maintenanceFilePath},</if>
            <if test="approveFilePath != null">approve_file_path = #{approveFilePath},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deletePdmMaintenanceProcessById" parameterType="Long">
        delete from pdm_maintenance_process where id = #{id}
    </delete>

    <delete id="deletePdmMaintenanceProcessByIds" parameterType="String">
        delete from pdm_maintenance_process where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
</mapper>