<?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.jsowell.pile.mapper.OrderAbnormalRecordMapper">

  <resultMap type="com.jsowell.pile.domain.OrderAbnormalRecord" id="OrderAbnormalRecordResult">
    <result property="id"    column="id"    />
    <result property="orderCode"    column="order_code"    />
    <result property="pileSn"    column="pile_sn"    />
    <result property="connectorCode"    column="connector_code"    />
    <result property="startTime"    column="start_time"    />
    <result property="endTime"    column="end_time"    />
    <result property="sharpPrice"    column="sharp_price"    />
    <result property="sharpUsedElectricity"    column="sharp_used_electricity"    />
    <result property="sharpPlanLossElectricity"    column="sharp_plan_loss_electricity"    />
    <result property="sharpAmount"    column="sharp_amount"    />
    <result property="peakPrice"    column="peak_price"    />
    <result property="peakUsedElectricity"    column="peak_used_electricity"    />
    <result property="peakPlanLossElectricity"    column="peak_plan_loss_electricity"    />
    <result property="peakAmount"    column="peak_amount"    />
    <result property="flatPrice"    column="flat_price"    />
    <result property="flatUsedElectricity"    column="flat_used_electricity"    />
    <result property="flatPlanLossElectricity"    column="flat_plan_loss_electricity"    />
    <result property="flatAmount"    column="flat_amount"    />
    <result property="valleyPrice"    column="valley_price"    />
    <result property="valleyUsedElectricity"    column="valley_used_electricity"    />
    <result property="valleyPlanLossElectricity"    column="valley_plan_loss_electricity"    />
    <result property="valleyAmount"    column="valley_amount"    />
    <result property="ammeterTotalStart"    column="ammeter_total_start"    />
    <result property="ammeterTotalEnd"    column="ammeter_total_end"    />
    <result property="totalElectricity"    column="total_electricity"    />
    <result property="planLossTotalElectricity"    column="plan_loss_total_electricity"    />
    <result property="consumptionAmount"    column="consumption_amount"    />
    <result property="vinCode"    column="vin_code"    />
    <result property="transactionIdentifier"    column="transaction_identifier"    />
    <result property="transactionTime"    column="transaction_time"    />
    <result property="stopReasonMsg"    column="stop_reason_msg"    />
    <result property="logicCard"    column="logic_card"    />
    <result property="createTime"    column="create_time"    />
  </resultMap>

  <sql id="selectOrderAbnormalRecordVo">
    select id, order_code, pile_sn, connector_code, start_time, end_time, sharp_price, sharp_used_electricity, sharp_plan_loss_electricity, sharp_amount, peak_price, peak_used_electricity, peak_plan_loss_electricity, peak_amount, flat_price, flat_used_electricity, flat_plan_loss_electricity, flat_amount, valley_price, valley_used_electricity, valley_plan_loss_electricity, valley_amount, ammeter_total_start, ammeter_total_end, total_electricity, plan_loss_total_electricity, consumption_amount, vin_code, transaction_identifier, transaction_time, stop_reason_msg, logic_card, create_time from order_abnormal_record
  </sql>

  <select id="selectOrderAbnormalRecordList" parameterType="com.jsowell.pile.domain.OrderAbnormalRecord" resultMap="OrderAbnormalRecordResult">
    <include refid="selectOrderAbnormalRecordVo"/>
    <where>
      <if test="orderCode != null  and orderCode != ''"> and order_code = #{orderCode}</if>
      <if test="pileSn != null  and pileSn != ''"> and pile_sn = #{pileSn}</if>
      <if test="startTime != null  and startTime != ''"> and start_time = #{startTime}</if>
      <if test="endTime != null  and endTime != ''"> and end_time = #{endTime}</if>
    </where>
    order by create_time desc
  </select>

  <select id="selectOrderAbnormalRecordById" parameterType="Integer" resultMap="OrderAbnormalRecordResult">
    <include refid="selectOrderAbnormalRecordVo"/>
    where id = #{id}
  </select>

  <insert id="insertOrderAbnormalRecord" parameterType="com.jsowell.pile.domain.OrderAbnormalRecord" useGeneratedKeys="true" keyProperty="id">
    insert into order_abnormal_record
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="orderCode != null">order_code,</if>
      <if test="pileSn != null">pile_sn,</if>
      <if test="connectorCode != null">connector_code,</if>
      <if test="startTime != null">start_time,</if>
      <if test="endTime != null">end_time,</if>
      <if test="sharpPrice != null">sharp_price,</if>
      <if test="sharpUsedElectricity != null">sharp_used_electricity,</if>
      <if test="sharpPlanLossElectricity != null">sharp_plan_loss_electricity,</if>
      <if test="sharpAmount != null">sharp_amount,</if>
      <if test="peakPrice != null">peak_price,</if>
      <if test="peakUsedElectricity != null">peak_used_electricity,</if>
      <if test="peakPlanLossElectricity != null">peak_plan_loss_electricity,</if>
      <if test="peakAmount != null">peak_amount,</if>
      <if test="flatPrice != null">flat_price,</if>
      <if test="flatUsedElectricity != null">flat_used_electricity,</if>
      <if test="flatPlanLossElectricity != null">flat_plan_loss_electricity,</if>
      <if test="flatAmount != null">flat_amount,</if>
      <if test="valleyPrice != null">valley_price,</if>
      <if test="valleyUsedElectricity != null">valley_used_electricity,</if>
      <if test="valleyPlanLossElectricity != null">valley_plan_loss_electricity,</if>
      <if test="valleyAmount != null">valley_amount,</if>
      <if test="ammeterTotalStart != null">ammeter_total_start,</if>
      <if test="ammeterTotalEnd != null">ammeter_total_end,</if>
      <if test="totalElectricity != null">total_electricity,</if>
      <if test="planLossTotalElectricity != null">plan_loss_total_electricity,</if>
      <if test="consumptionAmount != null">consumption_amount,</if>
      <if test="vinCode != null">vin_code,</if>
      <if test="transactionIdentifier != null">transaction_identifier,</if>
      <if test="transactionTime != null">transaction_time,</if>
      <if test="stopReasonMsg != null">stop_reason_msg,</if>
      <if test="logicCard != null">logic_card,</if>
      <if test="createTime != null">create_time,</if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="orderCode != null">#{orderCode},</if>
      <if test="pileSn != null">#{pileSn},</if>
      <if test="connectorCode != null">#{connectorCode},</if>
      <if test="startTime != null">#{startTime},</if>
      <if test="endTime != null">#{endTime},</if>
      <if test="sharpPrice != null">#{sharpPrice},</if>
      <if test="sharpUsedElectricity != null">#{sharpUsedElectricity},</if>
      <if test="sharpPlanLossElectricity != null">#{sharpPlanLossElectricity},</if>
      <if test="sharpAmount != null">#{sharpAmount},</if>
      <if test="peakPrice != null">#{peakPrice},</if>
      <if test="peakUsedElectricity != null">#{peakUsedElectricity},</if>
      <if test="peakPlanLossElectricity != null">#{peakPlanLossElectricity},</if>
      <if test="peakAmount != null">#{peakAmount},</if>
      <if test="flatPrice != null">#{flatPrice},</if>
      <if test="flatUsedElectricity != null">#{flatUsedElectricity},</if>
      <if test="flatPlanLossElectricity != null">#{flatPlanLossElectricity},</if>
      <if test="flatAmount != null">#{flatAmount},</if>
      <if test="valleyPrice != null">#{valleyPrice},</if>
      <if test="valleyUsedElectricity != null">#{valleyUsedElectricity},</if>
      <if test="valleyPlanLossElectricity != null">#{valleyPlanLossElectricity},</if>
      <if test="valleyAmount != null">#{valleyAmount},</if>
      <if test="ammeterTotalStart != null">#{ammeterTotalStart},</if>
      <if test="ammeterTotalEnd != null">#{ammeterTotalEnd},</if>
      <if test="totalElectricity != null">#{totalElectricity},</if>
      <if test="planLossTotalElectricity != null">#{planLossTotalElectricity},</if>
      <if test="consumptionAmount != null">#{consumptionAmount},</if>
      <if test="vinCode != null">#{vinCode},</if>
      <if test="transactionIdentifier != null">#{transactionIdentifier},</if>
      <if test="transactionTime != null">#{transactionTime},</if>
      <if test="stopReasonMsg != null">#{stopReasonMsg},</if>
      <if test="logicCard != null">#{logicCard},</if>
      <if test="createTime != null">#{createTime},</if>
    </trim>
  </insert>

  <update id="updateOrderAbnormalRecord" parameterType="com.jsowell.pile.domain.OrderAbnormalRecord">
    update order_abnormal_record
    <trim prefix="SET" suffixOverrides=",">
      <if test="orderCode != null">order_code = #{orderCode},</if>
      <if test="pileSn != null">pile_sn = #{pileSn},</if>
      <if test="connectorCode != null">connector_code = #{connectorCode},</if>
      <if test="startTime != null">start_time = #{startTime},</if>
      <if test="endTime != null">end_time = #{endTime},</if>
      <if test="sharpPrice != null">sharp_price = #{sharpPrice},</if>
      <if test="sharpUsedElectricity != null">sharp_used_electricity = #{sharpUsedElectricity},</if>
      <if test="sharpPlanLossElectricity != null">sharp_plan_loss_electricity = #{sharpPlanLossElectricity},</if>
      <if test="sharpAmount != null">sharp_amount = #{sharpAmount},</if>
      <if test="peakPrice != null">peak_price = #{peakPrice},</if>
      <if test="peakUsedElectricity != null">peak_used_electricity = #{peakUsedElectricity},</if>
      <if test="peakPlanLossElectricity != null">peak_plan_loss_electricity = #{peakPlanLossElectricity},</if>
      <if test="peakAmount != null">peak_amount = #{peakAmount},</if>
      <if test="flatPrice != null">flat_price = #{flatPrice},</if>
      <if test="flatUsedElectricity != null">flat_used_electricity = #{flatUsedElectricity},</if>
      <if test="flatPlanLossElectricity != null">flat_plan_loss_electricity = #{flatPlanLossElectricity},</if>
      <if test="flatAmount != null">flat_amount = #{flatAmount},</if>
      <if test="valleyPrice != null">valley_price = #{valleyPrice},</if>
      <if test="valleyUsedElectricity != null">valley_used_electricity = #{valleyUsedElectricity},</if>
      <if test="valleyPlanLossElectricity != null">valley_plan_loss_electricity = #{valleyPlanLossElectricity},</if>
      <if test="valleyAmount != null">valley_amount = #{valleyAmount},</if>
      <if test="ammeterTotalStart != null">ammeter_total_start = #{ammeterTotalStart},</if>
      <if test="ammeterTotalEnd != null">ammeter_total_end = #{ammeterTotalEnd},</if>
      <if test="totalElectricity != null">total_electricity = #{totalElectricity},</if>
      <if test="planLossTotalElectricity != null">plan_loss_total_electricity = #{planLossTotalElectricity},</if>
      <if test="consumptionAmount != null">consumption_amount = #{consumptionAmount},</if>
      <if test="vinCode != null">vin_code = #{vinCode},</if>
      <if test="transactionIdentifier != null">transaction_identifier = #{transactionIdentifier},</if>
      <if test="transactionTime != null">transaction_time = #{transactionTime},</if>
      <if test="stopReasonMsg != null">stop_reason_msg = #{stopReasonMsg},</if>
      <if test="logicCard != null">logic_card = #{logicCard},</if>
      <if test="createTime != null">create_time = #{createTime},</if>
    </trim>
    where id = #{id}
  </update>

  <delete id="deleteOrderAbnormalRecordById" parameterType="Integer">
    delete from order_abnormal_record where id = #{id}
  </delete>

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