<?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.th.demo.mapping.maint.PriceMapper" >
  <resultMap id="BaseResultMap" type="com.th.demo.model.maint.Price" >
    <id column="id" property="id" jdbcType="VARCHAR" />

    <result column="storage_price" property="storagePrice" jdbcType="DOUBLE" />
    <result column="transfer_price" property="transferPrice" jdbcType="DOUBLE" />
    <result column="weight_price" property="weightPrice" jdbcType="DOUBLE" />
    <result column="storage_type" property="storageType" jdbcType="VARCHAR" />

    <result column="add_time" property="addTime" jdbcType="TIMESTAMP" />
    <result column="modify_time" property="modifyTime" jdbcType="TIMESTAMP" />
    <result column="cancel_id" property="cancelId" jdbcType="VARCHAR" />
    <result column="cancel_time" property="cancelTime" jdbcType="TIMESTAMP" />
    <result column="cancel_flag" property="cancelFlag" jdbcType="VARCHAR" />
    <result column="belong_id" property="belongId" jdbcType="VARCHAR" />

      <association  column="material_id" property="material" select="com.th.demo.mapping.maint.MaterialMapper.selectByPrimaryKey" />
      <association  column="add_id" property="addUser" select="com.th.demo.mapping.system.SysUserMapper.selectByPrimaryKey" />
    <association  column="modify_id" property="modifyUser" select="com.th.demo.mapping.system.SysUserMapper.selectByPrimaryKey" />

  </resultMap>
  <sql id="Base_Column_List" >
    id, material_id, storage_price,transfer_price, weight_price, add_id, add_time,
    modify_id, modify_time, cancel_id, cancel_time, cancel_flag, belong_id,storage_type
  </sql>
  <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.String" >
    select 
    <include refid="Base_Column_List" />
    from t_maint_price
    where id = #{id,jdbcType=VARCHAR}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.String" >
    delete from t_maint_price
    where id = #{id,jdbcType=VARCHAR}
  </delete>
  <insert id="insert" parameterType="com.th.demo.model.maint.Price" >

    <selectKey keyProperty="id" order="BEFORE" resultType="java.lang.String">
      SELECT  REPLACE(UUID(),'-','') as id from dual
    </selectKey>

    insert into t_maint_price (id, material_id, storage_price,
      transfer_price, weight_price, add_id,
      add_time, modify_id, modify_time, 
      cancel_id, cancel_time, cancel_flag, 
      belong_id,storage_type)
    values (#{id,jdbcType=VARCHAR}, #{material.id,jdbcType=VARCHAR}, #{storagePrice,jdbcType=DOUBLE},
      #{transferPrice,jdbcType=DOUBLE}, #{weightPrice,jdbcType=DOUBLE}, #{addUser.id,jdbcType=VARCHAR},
      #{addTime,jdbcType=TIMESTAMP}, #{modifyUser.id,jdbcType=VARCHAR}, #{modifyTime,jdbcType=TIMESTAMP},
      #{cancelId,jdbcType=VARCHAR}, #{cancelTime,jdbcType=TIMESTAMP}, #{cancelFlag,jdbcType=VARCHAR}, 
      #{belongId,jdbcType=VARCHAR},#{storageType,jdbcType=VARCHAR})
  </insert>
  <insert id="insertSelective" parameterType="com.th.demo.model.maint.Price" >
    insert into t_maint_price
    <trim prefix="(" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        id,
      </if>
      <if test="materialId != null" >
        material_id,
      </if>
      <if test="storagePrice != null" >
        storage_price,
      </if>
      <if test="transferPrice != null" >
transfer_price,
      </if>
      <if test="weightPrice != null" >
        weight_price,
      </if>
      <if test="addId != null" >
        add_id,
      </if>
      <if test="addTime != null" >
        add_time,
      </if>
      <if test="modifyId != null" >
        modify_id,
      </if>
      <if test="modifyTime != null" >
        modify_time,
      </if>
      <if test="cancelId != null" >
        cancel_id,
      </if>
      <if test="cancelTime != null" >
        cancel_time,
      </if>
      <if test="cancelFlag != null" >
        cancel_flag,
      </if>
      <if test="belongId != null" >
        belong_id,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        #{id,jdbcType=VARCHAR},
      </if>
      <if test="materialId != null" >
        #{materialId,jdbcType=VARCHAR},
      </if>
      <if test="storagePrice != null" >
        #{storagePrice,jdbcType=DOUBLE},
      </if>
      <if test="transferPrice != null" >
        #{transferPrice,jdbcType=DOUBLE},
      </if>
      <if test="weightPrice != null" >
        #{weightPrice,jdbcType=DOUBLE},
      </if>
      <if test="addId != null" >
        #{addId,jdbcType=VARCHAR},
      </if>
      <if test="addTime != null" >
        #{addTime,jdbcType=TIMESTAMP},
      </if>
      <if test="modifyId != null" >
        #{modifyId,jdbcType=VARCHAR},
      </if>
      <if test="modifyTime != null" >
        #{modifyTime,jdbcType=TIMESTAMP},
      </if>
      <if test="cancelId != null" >
        #{cancelId,jdbcType=VARCHAR},
      </if>
      <if test="cancelTime != null" >
        #{cancelTime,jdbcType=TIMESTAMP},
      </if>
      <if test="cancelFlag != null" >
        #{cancelFlag,jdbcType=VARCHAR},
      </if>
      <if test="belongId != null" >
        #{belongId,jdbcType=VARCHAR},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.th.demo.model.maint.Price" >
    update t_maint_price
    <set >
      <if test="materialId != null" >
        material_id = #{materialId,jdbcType=VARCHAR},
      </if>
      <if test="storagePrice != null" >
        storage_price = #{storagePrice,jdbcType=DOUBLE},
      </if>
      <if test="transferPrice != null" >
        transfer_price = #{transferPrice,jdbcType=DOUBLE},
      </if>
      <if test="weightPrice != null" >
        weight_price = #{weightPrice,jdbcType=DOUBLE},
      </if>
      <if test="addId != null" >
        add_id = #{addId,jdbcType=VARCHAR},
      </if>
      <if test="addTime != null" >
        add_time = #{addTime,jdbcType=TIMESTAMP},
      </if>
      <if test="modifyId != null" >
        modify_id = #{modifyId,jdbcType=VARCHAR},
      </if>
      <if test="modifyTime != null" >
        modify_time = #{modifyTime,jdbcType=TIMESTAMP},
      </if>
      <if test="cancelId != null" >
        cancel_id = #{cancelId,jdbcType=VARCHAR},
      </if>
      <if test="cancelTime != null" >
        cancel_time = #{cancelTime,jdbcType=TIMESTAMP},
      </if>
      <if test="cancelFlag != null" >
        cancel_flag = #{cancelFlag,jdbcType=VARCHAR},
      </if>
      <if test="belongId != null" >
        belong_id = #{belongId,jdbcType=VARCHAR},
      </if>
    </set>
    where id = #{id,jdbcType=VARCHAR}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.th.demo.model.maint.Price" >
    update t_maint_price
    set material_id = #{material.id,jdbcType=VARCHAR},
      storage_price = #{storagePrice,jdbcType=DOUBLE},
      transfer_price = #{transferPrice,jdbcType=DOUBLE},
      weight_price = #{weightPrice,jdbcType=DOUBLE},
      add_id = #{addUser.id,jdbcType=VARCHAR},
      add_time = #{addTime,jdbcType=TIMESTAMP},
      modify_id = #{modifyUser.id,jdbcType=VARCHAR},
      modify_time = #{modifyTime,jdbcType=TIMESTAMP},
      cancel_id = #{cancelId,jdbcType=VARCHAR},
      cancel_time = #{cancelTime,jdbcType=TIMESTAMP},
      cancel_flag = #{cancelFlag,jdbcType=VARCHAR},
      belong_id =  #{belongId,jdbcType=VARCHAR},
     storage_type = #{storageType,jdbcType=VARCHAR}
    where id = #{id,jdbcType=VARCHAR}
  </update>

  <select id="selectByMaterialChangeTime" resultMap="BaseResultMap" >
    select *   from t_maint_price
    where material_id = #{param1,jdbcType=VARCHAR}
      and storage_type = #{param2,jdbcType=VARCHAR}
     and belong_id = #{param3,jdbcType=VARCHAR}
     and cancel_flag = '0'
  </select>


  <select id="select" resultMap="BaseResultMap" >
    select  t.*   from t_maint_price t ,t_maint_material d
    where t.material_id = d.id
    and d.name like concat('%',#{param1,jdbcType=VARCHAR},'%')
      and d.standard like concat('%',#{param2,jdbcType=VARCHAR},'%')
     and t.belong_id=#{param3,jdbcType=VARCHAR}
      and t.cancel_flag = '0'
  </select>


  <select id="selectCntByMaterialChangeTime" resultType="java.lang.Integer" >
    select count(*)  from t_maint_price
    where material_id = #{param1,jdbcType=VARCHAR}
      and storage_type = #{param2,jdbcType=VARCHAR}
     and belong_id = #{param3,jdbcType=VARCHAR}
     and cancel_flag = '0'
  </select>
</mapper>