<?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.ho.filecenter.mapper.PowerDetailMapper">

    <resultMap id="BaseResultMap" type="com.ho.filecenter.entity.PowerDetail">
        <id property="id" column="id" jdbcType="INTEGER"/>
        <id property="powerEndF" column="power_end_f" jdbcType="DECIMAL"/>
        <result property="pid" column="pid" jdbcType="INTEGER"/>
        <result property="groupId" column="group_id" jdbcType="INTEGER"/>
        <result property="tno" column="tno" jdbcType="VARCHAR"/>
        <result property="multiFactor" column="multi_factor" jdbcType="DECIMAL"/>
        <result property="powerStartJ" column="power_start_j" jdbcType="DECIMAL"/>
        <result property="powerStartF" column="power_start_f" jdbcType="DECIMAL"/>
        <result property="powerStartP" column="power_start_p" jdbcType="DECIMAL"/>
        <result property="powerStartG" column="power_start_g" jdbcType="DECIMAL"/>
        <result property="powerEndJ" column="power_end_j" jdbcType="DECIMAL"/>
        <result property="powerEndP" column="power_end_p" jdbcType="DECIMAL"/>
        <result property="powerEndG" column="power_end_g" jdbcType="DECIMAL"/>
        <result property="powerJ" column="power_j" jdbcType="DECIMAL"/>
        <result property="powerF" column="power_f" jdbcType="DECIMAL"/>
        <result property="powerP" column="power_p" jdbcType="DECIMAL"/>
        <result property="powerG" column="power_g" jdbcType="DECIMAL"/>
    </resultMap>

    <sql id="Base_Column_List">
        id,group_id
        ,power_end_f,pid, meter_point,
        tno,multi_factor,power_start_j,
        power_start_f,power_start_p,power_start_g,
        power_end_j,power_end_p,power_end_g,
        power_j,power_f,power_p,
        power_g,
        total_power_start,total_power_end,total_amount
    </sql>

    <insert id="addBatch" keyColumn="id" keyProperty="id" useGeneratedKeys="true">
        insert into power_detail (<include refid="Base_Column_List"/>)
        values
        <foreach item="item" collection="list" index="index" separator=",">
            (
            #{item.id},#{item.groupId},
            #{item.powerEndF},#{item.pid}, #{item.MeterPoint},
            #{item.tno},#{item.multiFactor},#{item.powerStartJ},
            #{item.powerStartF},#{item.powerStartP},#{item.powerStartG},
            #{item.powerEndJ},#{item.powerEndP},#{item.powerEndG},
            #{item.powerJ},#{item.powerF},#{item.powerP},
            #{item.powerG},
            #{item.totalPowerStart},#{item.totalPowerEnd},#{item.totalAmount}
            )
        </foreach>
    </insert>

    <insert id="insertSelective" keyColumn="id" keyProperty="id" useGeneratedKeys="true">
        insert into power_detail
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="groupId != null">group_id,</if>
            <if test="powerEndF != null">power_end_f,</if>
            <if test="pid != null">pid,</if>
            <if test="MeterPoint != null">meter_point,</if>
            <if test="tno != null">tno,</if>
            <if test="multiFactor != null">multi_factor,</if>
            <if test="powerStartJ != null">power_start_j,</if>
            <if test="powerStartF != null">power_start_f,</if>
            <if test="powerStartP != null">power_start_p,</if>
            <if test="powerStartG != null">power_start_g,</if>
            <if test="powerEndJ != null">power_end_j</if>
            <if test="powerEndF != null">power_end_f</if>
            <if test="powerEndP != null">power_end_p</if>
            <if test="powerEndG != null">power_end_g</if>
            <if test="powerJ != null">power_j</if>
            <if test="powerF != null">power_f</if>
            <if test="powerP != null">power_p</if>
            <if test="powerG != null">power_g</if>
            <if test="totalPowerStart != null">total_power_start</if>
            <if test="totalPowerEnd != null">total_power_end</if>
            <if test="totalAmount != null">total_amount</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="groupId != null">#{groupId},</if>
            <if test="powerEndF != null">#{powerEndF},</if>
            <if test="pid != null">#{pid},</if>
            <if test="MeterPoint != null">#{MeterPoint},</if>
            <if test="tno != null">#{tno},</if>
            <if test="multiFactor != null">#{multiFactor},</if>
            <if test="powerStartJ != null">#{powerStartJ},</if>
            <if test="powerStartF != null">#{powerStartF},</if>
            <if test="powerStartP != null">#{powerStartP},</if>
            <if test="powerStartG != null">#{powerStartG},</if>
            <if test="powerEndJ != null">#{powerEndJ},</if>
            <if test="powerEndF != null">#{powerEndF},</if>
            <if test="powerEndP != null">#{powerEndP},</if>
            <if test="powerEndG != null">#{powerEndG},</if>
            <if test="powerJ != null">#{powerJ},</if>
            <if test="powerF != null">#{powerF},</if>
            <if test="powerP != null">#{powerP},</if>
            <if test="powerG != null">#{powerG}</if>
            <if test="totalPowerStart != null">#{totalPowerStart}</if>
            <if test="totalPowerEnd != null">#{totalPowerEnd}</if>
            <if test="totalAmount != null">#{totalAmount}</if>
        </trim>
    </insert>

    <update id="updateByPrimaryKeySelective">
        update power_detail
        <set>
            <if test="powerEndF != null">
                power_end_f = #{powerEndF},
            </if>
            <if test="pid != null">
                pid = #{pid},
            </if>
            <if test="groupId != null">
                group_id = #{groupId},
            </if>
            <if test="MeterPoint != null">
                meter_point = #{MeterPoint},
            </if>
            <if test="tno != null">
                tno = #{tno},
            </if>
            <if test="multiFactor != null">
                multi_factor = #{multiFactor},
            </if>
            <if test="powerStartJ != null">
                power_start_j = #{powerStartJ},
            </if>
            <if test="powerStartF != null">
                power_start_f = #{powerStartF},
            </if>
            <if test="powerStartP != null">
                power_start_p = #{powerStartP},
            </if>
            <if test="powerStartG != null">
                power_start_g = #{powerStartG},
            </if>
            <if test="powerEndJ!= null">
                power_end_j= #{powerEndJ},
            </if>
            <if test="powerEndF!= null">
                power_end_f= #{powerEndF},
            </if>
            <if test="powerEndP!= null">
                power_end_P= #{powerEndP},
            </if>
            <if test="powerEndG!= null">
                power_end_g= #{powerEndG},
            </if>

            <if test="powerJ!= null">
                power_j = #{powerJ},
            </if>
            <if test="powerF!= null">
                power_f= #{powerF},
            </if>
            <if test="powerP!= null">
                power_p= #{powerP},
            </if>
            <if test="powerG!= null">
                power_g= #{powerG},
            </if>
            <if test="totalPowerStart != null">
                total_power_start = #{totalPowerStart},
            </if>
            <if test="totalPowerEnd != null">
                total_power_end = #{totalPowerEnd},
            </if>
            <if test="totalAmount != null">
                total_amount = #{totalAmount}
            </if>
        </set>
        where id = #{id,jdbcType=INTEGER}
    </update>


    <delete id="deleteByPrimaryKey">
        delete
        from power_detail
        where id = #{id,jdbcType=INTEGER}
    </delete>

    <select id="selectByPid" resultType="com.ho.filecenter.entity.PowerDetail">
        select
        <include refid="Base_Column_List"/>
        from power_detail
        where pid= #{id}
    </select>

    <select id="selectDetails" resultType="com.ho.filecenter.entity.PowerDetail">
        select
        <include refid="Base_Column_List"/>
        from power_detail
        where id= #{id}
    </select>

    <delete id="deleteBatch">
        delete
        from power_detail
        <where>
            <if test="ids != null and ids.size !=0">
                and id in
                <foreach collection="ids" open="(" close=")" separator="," item="item">
                    #{item}
                </foreach>
            </if>
            <if test="pids != null and pids.size !=0">
                and pid in
                <foreach collection="pids" open="(" close=")" separator="," item="item">
                    #{item}
                </foreach>
            </if>
        </where>
    </delete>


</mapper>
