<?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.OemContractPriceMapper">
  
<resultMap id="BaseResultMap" type="com.boco.nbd.wios.manage.entity.bo.OemContractPrice">
  <id column="id" jdbcType="INTEGER" property="id" />
  <result column="contract_id" jdbcType="INTEGER" property="contractId" />
  <result column="region_id" jdbcType="VARCHAR" property="regionId" />
  <result column="tax_rate" jdbcType="DECIMAL" property="taxRate" />
  <result column="survey_price" jdbcType="DECIMAL" property="surveyPrice" />
  <result column="survey_rate_price" jdbcType="DECIMAL" property="surveyRatePrice" />
  <result column="installation_price" jdbcType="DECIMAL" property="installationPrice" />
  <result column="installation_rate_price" jdbcType="DECIMAL" property="installationRatePrice" />
  <result column="expand_price" jdbcType="DECIMAL" property="expandPrice" />
  <result column="expand_rate_price" jdbcType="DECIMAL" property="expandRatePrice" />
  <result column="description" jdbcType="VARCHAR" property="description" />
  <result column="create_account" jdbcType="VARCHAR" property="createAccount" />
  <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
  <result column="modify_account" jdbcType="VARCHAR" property="modifyAccount" />
  <result column="modify_time" jdbcType="TIMESTAMP" property="modifyTime" />
</resultMap>

  
<sql id="Base_Column_List">
  id, contract_id, region_id, tax_rate, survey_price, survey_rate_price, installation_price, 
  installation_rate_price, expand_price, expand_rate_price, description, create_account, 
  create_time, modify_account, modify_time
</sql>

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

  
<insert id="insert" parameterType="com.boco.nbd.wios.manage.entity.bo.OemContractPrice">
  insert into t_oem_contract_price (id, contract_id, region_id, 
    tax_rate, survey_price, survey_rate_price, 
    installation_price, installation_rate_price, 
    expand_price, expand_rate_price, description, 
    create_account, create_time, modify_account, 
    modify_time)
  values (#{id,jdbcType=INTEGER}, #{contractId,jdbcType=INTEGER}, #{regionId,jdbcType=VARCHAR}, 
    #{taxRate,jdbcType=DECIMAL}, #{surveyPrice,jdbcType=DECIMAL}, #{surveyRatePrice,jdbcType=DECIMAL}, 
    #{installationPrice,jdbcType=DECIMAL}, #{installationRatePrice,jdbcType=DECIMAL}, 
    #{expandPrice,jdbcType=DECIMAL}, #{expandRatePrice,jdbcType=DECIMAL}, #{description,jdbcType=VARCHAR}, 
    #{createAccount,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP}, #{modifyAccount,jdbcType=VARCHAR}, 
    #{modifyTime,jdbcType=TIMESTAMP})
</insert>

  
<insert id="insertDynamic" parameterType="com.boco.nbd.wios.manage.entity.bo.OemContractPrice">
  insert into t_oem_contract_price
  <trim prefix="(" suffix=")" suffixOverrides=",">
    <if test="id != null">
      id,
    </if>
    <if test="contractId != null">
      contract_id,
    </if>
    <if test="regionId != null">
      region_id,
    </if>
    <if test="taxRate != null">
      tax_rate,
    </if>
    <if test="surveyPrice != null">
      survey_price,
    </if>
    <if test="surveyRatePrice != null">
      survey_rate_price,
    </if>
    <if test="installationPrice != null">
      installation_price,
    </if>
    <if test="installationRatePrice != null">
      installation_rate_price,
    </if>
    <if test="expandPrice != null">
      expand_price,
    </if>
    <if test="expandRatePrice != null">
      expand_rate_price,
    </if>
    <if test="description != null">
      description,
    </if>
    <if test="createAccount != null">
      create_account,
    </if>
    <if test="createTime != null">
      create_time,
    </if>
    <if test="modifyAccount != null">
      modify_account,
    </if>
    <if test="modifyTime != null">
      modify_time,
    </if>
  </trim>
  <trim prefix="values (" suffix=")" suffixOverrides=",">
    <if test="id != null">
      #{id,jdbcType=INTEGER},
    </if>
    <if test="contractId != null">
      #{contractId,jdbcType=INTEGER},
    </if>
    <if test="regionId != null">
      #{regionId,jdbcType=VARCHAR},
    </if>
    <if test="taxRate != null">
      #{taxRate,jdbcType=DECIMAL},
    </if>
    <if test="surveyPrice != null">
      #{surveyPrice,jdbcType=DECIMAL},
    </if>
    <if test="surveyRatePrice != null">
      #{surveyRatePrice,jdbcType=DECIMAL},
    </if>
    <if test="installationPrice != null">
      #{installationPrice,jdbcType=DECIMAL},
    </if>
    <if test="installationRatePrice != null">
      #{installationRatePrice,jdbcType=DECIMAL},
    </if>
    <if test="expandPrice != null">
      #{expandPrice,jdbcType=DECIMAL},
    </if>
    <if test="expandRatePrice != null">
      #{expandRatePrice,jdbcType=DECIMAL},
    </if>
    <if test="description != null">
      #{description,jdbcType=VARCHAR},
    </if>
    <if test="createAccount != null">
      #{createAccount,jdbcType=VARCHAR},
    </if>
    <if test="createTime != null">
      #{createTime,jdbcType=TIMESTAMP},
    </if>
    <if test="modifyAccount != null">
      #{modifyAccount,jdbcType=VARCHAR},
    </if>
    <if test="modifyTime != null">
      #{modifyTime,jdbcType=TIMESTAMP},
    </if>
  </trim>
</insert>

  
<update id="updateDynamic" parameterType="com.boco.nbd.wios.manage.entity.bo.OemContractPrice">
  update t_oem_contract_price
  <set>
    <if test="contractId != null">
      contract_id = #{contractId,jdbcType=INTEGER},
    </if>
    <if test="regionId != null">
      region_id = #{regionId,jdbcType=VARCHAR},
    </if>
    <if test="taxRate != null">
      tax_rate = #{taxRate,jdbcType=DECIMAL},
    </if>
    <if test="surveyPrice != null">
      survey_price = #{surveyPrice,jdbcType=DECIMAL},
    </if>
    <if test="surveyRatePrice != null">
      survey_rate_price = #{surveyRatePrice,jdbcType=DECIMAL},
    </if>
    <if test="installationPrice != null">
      installation_price = #{installationPrice,jdbcType=DECIMAL},
    </if>
    <if test="installationRatePrice != null">
      installation_rate_price = #{installationRatePrice,jdbcType=DECIMAL},
    </if>
    <if test="expandPrice != null">
      expand_price = #{expandPrice,jdbcType=DECIMAL},
    </if>
    <if test="expandRatePrice != null">
      expand_rate_price = #{expandRatePrice,jdbcType=DECIMAL},
    </if>
    <if test="description != null">
      description = #{description,jdbcType=VARCHAR},
    </if>
    <if test="createAccount != null">
      create_account = #{createAccount,jdbcType=VARCHAR},
    </if>
    <if test="createTime != null">
      create_time = #{createTime,jdbcType=TIMESTAMP},
    </if>
    <if test="modifyAccount != null">
      modify_account = #{modifyAccount,jdbcType=VARCHAR},
    </if>
    <if test="modifyTime != null">
      modify_time = #{modifyTime,jdbcType=TIMESTAMP},
    </if>
  </set>
  where id = #{id,jdbcType=INTEGER}
</update>

  
<update id="update" parameterType="com.boco.nbd.wios.manage.entity.bo.OemContractPrice">
  update t_oem_contract_price
  set contract_id = #{contractId,jdbcType=INTEGER},
    region_id = #{regionId,jdbcType=VARCHAR},
    tax_rate = #{taxRate,jdbcType=DECIMAL},
    survey_price = #{surveyPrice,jdbcType=DECIMAL},
    survey_rate_price = #{surveyRatePrice,jdbcType=DECIMAL},
    installation_price = #{installationPrice,jdbcType=DECIMAL},
    installation_rate_price = #{installationRatePrice,jdbcType=DECIMAL},
    expand_price = #{expandPrice,jdbcType=DECIMAL},
    expand_rate_price = #{expandRatePrice,jdbcType=DECIMAL},
    description = #{description,jdbcType=VARCHAR},
    create_account = #{createAccount,jdbcType=VARCHAR},
    create_time = #{createTime,jdbcType=TIMESTAMP},
    modify_account = #{modifyAccount,jdbcType=VARCHAR},
    modify_time = #{modifyTime,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_oem_contract_price
  where id = #{id,jdbcType=INTEGER}
</select>

<select id="selectByContractId" parameterType="java.lang.Integer" resultType="com.boco.nbd.wios.manage.entity.bo.OemContractPriceVo">
  	SELECT
		t.*, r. NAME AS regionName,
		r.id_tree AS regionIdTree,
        a.name packTypeName
	FROM
	t_oem_contract_price t
	LEFT JOIN t_region r ON r.id = t.region_id
    left join t_oem_cascade a on t.pack_type=a.id
	WHERE
		t.contract_id = #{contractId}
</select>

<select id="selectPureByContractId" parameterType="java.lang.Integer" resultMap="BaseResultMap">
  select t.*
  from  t_oem_contract_price t
  where t.contract_id = #{contractId,jdbcType=INTEGER}
</select>

<insert id="batchInsert" parameterType="java.util.List">
    insert into t_oem_contract_price (id, contract_id, region_id, pack_type,
    tax_rate, survey_price, survey_rate_price, 
    installation_price, installation_rate_price, 
    expand_price, expand_rate_price, description, 
    create_account, create_time, modify_account, 
    modify_time)
  	values
  	<foreach collection="list" item="item" separator=",">
  	 (#{item.id,jdbcType=INTEGER}, #{item.contractId,jdbcType=INTEGER}, #{item.regionId,jdbcType=VARCHAR}, #{item.packType,jdbcType=VARCHAR},
    #{item.taxRate,jdbcType=DECIMAL}, #{item.surveyPrice,jdbcType=DECIMAL}, #{item.surveyRatePrice,jdbcType=DECIMAL}, 
    #{item.installationPrice,jdbcType=DECIMAL}, #{item.installationRatePrice,jdbcType=DECIMAL}, 
    #{item.expandPrice,jdbcType=DECIMAL}, #{item.expandRatePrice,jdbcType=DECIMAL}, #{item.description,jdbcType=VARCHAR}, 
    #{item.createAccount,jdbcType=VARCHAR}, #{item.createTime,jdbcType=TIMESTAMP}, #{item.modifyAccount,jdbcType=VARCHAR}, 
    #{item.modifyTime,jdbcType=TIMESTAMP})
    </foreach>
</insert>

<delete id="deleteByContractId" parameterType="java.lang.Integer">
  delete from t_oem_contract_price
  where contract_id = #{contractId}
</delete>
  
</mapper>