<?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.boco.nbd.wios.manage.mapper.def.SettlementDetailMapper">
  
<resultMap id="BaseResultMap" type="com.boco.nbd.wios.manage.entity.settlement.po.SettlementDetail">
  <id column="id" jdbcType="INTEGER" property="id" />
  <result column="settlement_id" jdbcType="VARCHAR" property="settlementId" />
  <result column="order_id" jdbcType="VARCHAR" property="orderId" />
  <result column="user_name" jdbcType="VARCHAR" property="userName" />
  <result column="user_phone" jdbcType="VARCHAR" property="userPhone" />
  <result column="device_fee" jdbcType="DECIMAL" property="deviceFee" />
  <result column="device_fee_with_tax" jdbcType="DECIMAL" property="deviceFeeWithTax" />
  <result column="install_service_fee" jdbcType="DECIMAL" property="installServiceFee" />
  <result column="install_service_fee_with_tax" jdbcType="DECIMAL" property="installServiceFeeWithTax" />
  <result column="total_fee" jdbcType="DECIMAL" property="totalFee" />
  <result column="total_fee_with_tax" jdbcType="DECIMAL" property="totalFeeWithTax" />
  <result column="install_finish_time" jdbcType="TIMESTAMP" property="installFinishTime" />
  <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
  <result column="is_del" jdbcType="INTEGER" property="isDel" />
</resultMap>

  
<sql id="Base_Column_List">
  id, settlement_id, order_id, user_name, user_phone, device_fee, device_fee_with_tax, 
  install_service_fee, install_service_fee_with_tax, total_fee, total_fee_with_tax, 
  install_finish_time, create_time,is_del
</sql>

  
<delete id="delete" parameterType="java.lang.Integer">
  delete from t_settlement_detail
  where id = #{id,jdbcType=INTEGER}
</delete>


    <insert id="insert" parameterType="com.boco.nbd.wios.manage.entity.settlement.po.SettlementDetail">
  insert into t_settlement_detail (id, settlement_id, order_id, 
    user_name, user_phone, device_fee, 
    device_fee_with_tax, install_service_fee, install_service_fee_with_tax, 
    total_fee, total_fee_with_tax, install_finish_time, 
    create_time)
  values (#{id,jdbcType=INTEGER}, #{settlementId,jdbcType=VARCHAR}, #{orderId,jdbcType=VARCHAR}, 
    #{userName,jdbcType=VARCHAR}, #{userPhone,jdbcType=VARCHAR}, #{deviceFee,jdbcType=DECIMAL}, 
    #{deviceFeeWithTax,jdbcType=DECIMAL}, #{installServiceFee,jdbcType=DECIMAL}, #{installServiceFeeWithTax,jdbcType=DECIMAL}, 
    #{totalFee,jdbcType=DECIMAL}, #{totalFeeWithTax,jdbcType=DECIMAL}, #{installFinishTime,jdbcType=TIMESTAMP}, 
    #{createTime,jdbcType=TIMESTAMP})
</insert>

  
<insert id="insertDynamic" parameterType="com.boco.nbd.wios.manage.entity.settlement.po.SettlementDetail">
  insert into t_settlement_detail
  <trim prefix="(" suffix=")" suffixOverrides=",">
    <if test="id != null">
      id,
    </if>
    <if test="settlementId != null">
      settlement_id,
    </if>
    <if test="orderId != null">
      order_id,
    </if>
    <if test="userName != null">
      user_name,
    </if>
    <if test="userPhone != null">
      user_phone,
    </if>
    <if test="deviceFee != null">
      device_fee,
    </if>
    <if test="deviceFeeWithTax != null">
      device_fee_with_tax,
    </if>
    <if test="installServiceFee != null">
      install_service_fee,
    </if>
    <if test="installServiceFeeWithTax != null">
      install_service_fee_with_tax,
    </if>
    <if test="totalFee != null">
      total_fee,
    </if>
    <if test="totalFeeWithTax != null">
      total_fee_with_tax,
    </if>
    <if test="installFinishTime != null">
      install_finish_time,
    </if>
    <if test="createTime != null">
      create_time,
    </if>
  </trim>
  <trim prefix="values (" suffix=")" suffixOverrides=",">
    <if test="id != null">
      #{id,jdbcType=INTEGER},
    </if>
    <if test="settlementId != null">
      #{settlementId,jdbcType=VARCHAR},
    </if>
    <if test="orderId != null">
      #{orderId,jdbcType=VARCHAR},
    </if>
    <if test="userName != null">
      #{userName,jdbcType=VARCHAR},
    </if>
    <if test="userPhone != null">
      #{userPhone,jdbcType=VARCHAR},
    </if>
    <if test="deviceFee != null">
      #{deviceFee,jdbcType=DECIMAL},
    </if>
    <if test="deviceFeeWithTax != null">
      #{deviceFeeWithTax,jdbcType=DECIMAL},
    </if>
    <if test="installServiceFee != null">
      #{installServiceFee,jdbcType=DECIMAL},
    </if>
    <if test="installServiceFeeWithTax != null">
      #{installServiceFeeWithTax,jdbcType=DECIMAL},
    </if>
    <if test="totalFee != null">
      #{totalFee,jdbcType=DECIMAL},
    </if>
    <if test="totalFeeWithTax != null">
      #{totalFeeWithTax,jdbcType=DECIMAL},
    </if>
    <if test="installFinishTime != null">
      #{installFinishTime,jdbcType=TIMESTAMP},
    </if>
    <if test="createTime != null">
      #{createTime,jdbcType=TIMESTAMP},
    </if>
  </trim>
</insert>

  
<update id="updateDynamic" parameterType="com.boco.nbd.wios.manage.entity.settlement.po.SettlementDetail">
  update t_settlement_detail
  <set>
    <if test="settlementId != null">
      settlement_id = #{settlementId,jdbcType=VARCHAR},
    </if>
    <if test="orderId != null">
      order_id = #{orderId,jdbcType=VARCHAR},
    </if>
    <if test="userName != null">
      user_name = #{userName,jdbcType=VARCHAR},
    </if>
    <if test="userPhone != null">
      user_phone = #{userPhone,jdbcType=VARCHAR},
    </if>
    <if test="deviceFee != null">
      device_fee = #{deviceFee,jdbcType=DECIMAL},
    </if>
    <if test="deviceFeeWithTax != null">
      device_fee_with_tax = #{deviceFeeWithTax,jdbcType=DECIMAL},
    </if>
    <if test="installServiceFee != null">
      install_service_fee = #{installServiceFee,jdbcType=DECIMAL},
    </if>
    <if test="installServiceFeeWithTax != null">
      install_service_fee_with_tax = #{installServiceFeeWithTax,jdbcType=DECIMAL},
    </if>
    <if test="totalFee != null">
      total_fee = #{totalFee,jdbcType=DECIMAL},
    </if>
    <if test="totalFeeWithTax != null">
      total_fee_with_tax = #{totalFeeWithTax,jdbcType=DECIMAL},
    </if>
    <if test="installFinishTime != null">
      install_finish_time = #{installFinishTime,jdbcType=TIMESTAMP},
    </if>
    <if test="createTime != null">
      create_time = #{createTime,jdbcType=TIMESTAMP},
    </if>
  </set>
  where id = #{id,jdbcType=INTEGER}
</update>

<update id="deleteByOrderId">
    UPDATE t_settlement_detail
    SET is_del = 1
    WHERE
        order_id = #{orderId,jdbcType=VARCHAR}
</update>
  
<update id="update" parameterType="com.boco.nbd.wios.manage.entity.settlement.po.SettlementDetail">
  update t_settlement_detail
  set settlement_id = #{settlementId,jdbcType=VARCHAR},
    order_id = #{orderId,jdbcType=VARCHAR},
    user_name = #{userName,jdbcType=VARCHAR},
    user_phone = #{userPhone,jdbcType=VARCHAR},
    device_fee = #{deviceFee,jdbcType=DECIMAL},
    device_fee_with_tax = #{deviceFeeWithTax,jdbcType=DECIMAL},
    install_service_fee = #{installServiceFee,jdbcType=DECIMAL},
    install_service_fee_with_tax = #{installServiceFeeWithTax,jdbcType=DECIMAL},
    total_fee = #{totalFee,jdbcType=DECIMAL},
    total_fee_with_tax = #{totalFeeWithTax,jdbcType=DECIMAL},
    install_finish_time = #{installFinishTime,jdbcType=TIMESTAMP},
    create_time = #{createTime,jdbcType=TIMESTAMP}
  where id = #{id,jdbcType=INTEGER}
</update>

  
<select id="selectById" parameterType="java.lang.Integer" resultMap="BaseResultMap">
  select
	<include refid="Base_Column_List" />
  from  t_settlement_detail
  where id = #{id,jdbcType=INTEGER}
</select>

<select id="selectByOemId" resultMap="BaseResultMap">
  select t.*
  from  t_settlement_detail t
  left join t_order o on o.id=t.order_id
  where 
  o.oem_id = #{oemId,jdbcType=INTEGER} 
  and
  t.install_finish_time &gt; #{installFinishStartTime,jdbcType=VARCHAR}
  and
  t.install_finish_time &lt; #{installFinishEndTime,jdbcType=VARCHAR}
</select>

<select id="selectBySettlementId" resultMap="BaseResultMap">
  select t.*
  from  t_settlement_detail t
  where 
  t.settlement_id=#{settlementId}
</select>

<update id="batchUpdateSettlementId">
  update t_settlement_detail
  set settlement_id = #{settlementId,jdbcType=VARCHAR}
  where id in
    <foreach collection="idList" index="index" item="item" separator="," open="(" close=")">
        #{item}
    </foreach>
</update>
</mapper>