<?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.ware.CargoChangeRecordMapper" >
  <resultMap id="BaseResultMap" type="com.th.demo.model.ware.CargoChangeRecord" >
    <id column="id" property="id" jdbcType="VARCHAR" />
    <result column="modify_time" property="modifyTime" jdbcType="TIMESTAMP" />
    <result column="weight" property="weight" jdbcType="DOUBLE" />
    <result column="change_from" property="changeFrom" jdbcType="VARCHAR"/>
    <result column="sub_str" property="subStr" jdbcType="VARCHAR"/>
    <result column="ord_no" property="ordNo" jdbcType="VARCHAR"/>
    <result column="remark" property="remark" jdbcType="VARCHAR"/>

    <association  column="modify_id" property="modifyUser" select="com.th.demo.mapping.system.SysUserMapper.selectByPrimaryKey" />
    <association  column="uper_customer_id" property="uperCustomer" select="com.th.demo.mapping.maint.CustomerMapper.selectByPrimaryKey" />
    <association  column="customer_id" property="Customer" select="com.th.demo.mapping.maint.CustomerMapper.selectByPrimaryKey" />
  </resultMap>

  <sql id="Base_Column_List" >
    id, modify_id, modify_time, weight, change_from, sub_str, uper_customer_id, customer_id,ord_no,remark
  </sql>

  <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.String" >
    select 
    <include refid="Base_Column_List" />
    from t_ware_cargochange_record
    where id = #{id,jdbcType=VARCHAR}
  </select>

  <delete id="deleteByPrimaryKey" parameterType="java.lang.String" >
    delete from t_ware_cargochange_record
    where id = #{id,jdbcType=VARCHAR}
  </delete>

  <insert id="insert" parameterType="com.th.demo.model.ware.CargoChangeRecord" >

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

    insert into t_ware_cargochange_record (id, modify_id, modify_time,
                                           weight, change_from, sub_str,
                                           uper_customer_id, customer_id,
                                           ord_no,remark)
    values (#{id,jdbcType=VARCHAR},#{modifyUser.id,jdbcType=VARCHAR},#{modifyTime,jdbcType=TIMESTAMP},
            #{weight,jdbcType=DOUBLE},#{changeFrom,jdbcType=VARCHAR},#{subStr,jdbcType=VARCHAR},
            #{uperCustomer.id,jdbcType=VARCHAR}, #{Customer.id,jdbcType=VARCHAR},
            #{ordNo,jdbcType=VARCHAR}, #{remark,jdbcType=VARCHAR})
  </insert>

  <select id="selectByCustomer" resultMap="BaseResultMap" parameterType="java.lang.String" >
  select
  <include refid="Base_Column_List" />
  from t_ware_cargochange_record
  where uper_customer_id = #{param1,jdbcType=VARCHAR}
  and customer_id = #{param2,jdbcType=VARCHAR}
</select>

  <select id="selectRecord" resultMap="BaseResultMap" parameterType="java.lang.String" >
    select
    <include refid="Base_Column_List" />
    from t_ware_cargochange_record
    where uper_customer_id = #{param1,jdbcType=VARCHAR}
    and customer_id = #{param2,jdbcType=VARCHAR}
  </select>


</mapper>