<?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.CombineRecordMapper" >
  <resultMap id="BaseResultMap" type="com.th.demo.model.ware.CombineRecord" >
    <id column="id" property="id" jdbcType="VARCHAR" />
    <result column="ware_name" property="wareName" jdbcType="VARCHAR" />
    <result column="stack_name" property="stackName" jdbcType="VARCHAR" />
    <result column="orignal_layer_one" property="orignalLayerOne" jdbcType="INTEGER" />
    <result column="orignal_layer_two" property="orignalLayerTwo" jdbcType="INTEGER" />
    <result column="combine_layer" property="combineLayer" jdbcType="INTEGER" />
    <result column="material_name" property="materialName" jdbcType="VARCHAR" />
    <result column="material_no" property="materialNo" jdbcType="VARCHAR" />
    <result column="standard" property="standard" jdbcType="VARCHAR" />
    <result column="model" property="model" jdbcType="VARCHAR" />
    <result column="customer_name" property="customerName" jdbcType="VARCHAR" />
    <result column="customer_no" property="customerNo" jdbcType="VARCHAR" />
    <result column="orignal_count_one" property="orignalCountOne" jdbcType="DOUBLE" />
    <result column="orignal_count_two" property="orignalCountTwo" jdbcType="DOUBLE" />
    <result column="combine_count" property="combineCount" jdbcType="DOUBLE" />
    <result column="orignal_weight_one" property="orignalWeightOne" jdbcType="DOUBLE" />
    <result column="orignal_weight_two" property="orignalWeightTwo" jdbcType="DOUBLE" />
    <result column="combine_weight" property="combineWeight" jdbcType="DOUBLE" />
    <result column="remark" property="remark" jdbcType="VARCHAR" />

    <result column="add_time" property="addTime" jdbcType="TIMESTAMP" />
    <result column="modify_id" property="modifyId" jdbcType="VARCHAR" />
    <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" />
    <result column="plate_no" property="plateNo" jdbcType="VARCHAR" />
    <result column="in_id" property="inId" jdbcType="VARCHAR" />
    <result column="orignal_store_id_one" property="orignalStoreIdOne" jdbcType="VARCHAR" />
    <result column="orignal_store_id_two" property="orignalStoreIdTwo" jdbcType="VARCHAR" />
    <result column="receive_address" property="receiveAddress" jdbcType="VARCHAR" />
    <result column="combine_store_id" property="combineStoreId" jdbcType="VARCHAR" />

    <result column="wgt_dcn_mtc_cd" property="wgtDcnMtcCd" jdbcType="VARCHAR" />
    <result column="edge_ty" property="edgeTy" jdbcType="VARCHAR" />
    <result column="production_place" property="productionPlace" jdbcType="VARCHAR" />

    <association  column="add_id" property="addUser" select="com.th.demo.mapping.system.SysUserMapper.selectByPrimaryKey" />
  </resultMap>
  <sql id="Base_Column_List" >
    id, ware_name, stack_name, orignal_layer_one, orignal_layer_two, combine_layer, material_name,
    material_no, standard, model, customer_name, customer_no, orignal_count_one, orignal_count_two,
    combine_count, orignal_weight_one, orignal_weight_two, combine_weight, remark, add_id,
    add_time, modify_id, modify_time, cancel_id, cancel_time, cancel_flag, belong_id,
    plate_no, in_id, orignal_store_id_one, orignal_store_id_two, receive_address, combine_store_id
  </sql>
  <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.String" >
    select 
    <include refid="Base_Column_List" />
    from t_ware_combine_record
    where id = #{id,jdbcType=VARCHAR}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.String" >
    delete from t_ware_combine_record
    where id = #{id,jdbcType=VARCHAR}
  </delete>
  <insert id="insert" parameterType="com.th.demo.model.ware.CombineRecord" >

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

    insert into t_ware_combine_record (id, ware_name, stack_name,
    orignal_layer_one, orignal_layer_two, combine_layer,
    material_name, material_no, standard,
    model, customer_name, customer_no,
    orignal_count_one, orignal_count_two, combine_count,
    orignal_weight_one, orignal_weight_two, combine_weight,
    remark, add_id, add_time,
    modify_id, modify_time, cancel_id,
    cancel_time, cancel_flag, belong_id,
    plate_no, in_id, orignal_store_id_one,
    orignal_store_id_two, receive_address, combine_store_id
    ,wgt_dcn_mtc_cd,edge_ty,production_place
    )
    values (#{id,jdbcType=VARCHAR}, #{wareName,jdbcType=VARCHAR}, #{stackName,jdbcType=VARCHAR},
    #{orignalLayerOne,jdbcType=INTEGER}, #{orignalLayerTwo,jdbcType=INTEGER}, #{combineLayer,jdbcType=INTEGER},
    #{materialName,jdbcType=VARCHAR}, #{materialNo,jdbcType=VARCHAR}, #{standard,jdbcType=VARCHAR},
    #{model,jdbcType=VARCHAR}, #{customerName,jdbcType=VARCHAR}, #{customerNo,jdbcType=VARCHAR},
    #{orignalCountOne,jdbcType=DOUBLE}, #{orignalCountTwo,jdbcType=DOUBLE}, #{combineCount,jdbcType=DOUBLE},
    #{orignalWeightOne,jdbcType=DOUBLE}, #{orignalWeightTwo,jdbcType=DOUBLE}, #{combineWeight,jdbcType=DOUBLE},
    #{remark,jdbcType=VARCHAR}, #{addUser.id,jdbcType=VARCHAR}, #{addTime,jdbcType=TIMESTAMP},
    #{modifyId,jdbcType=VARCHAR}, #{modifyTime,jdbcType=TIMESTAMP}, #{cancelId,jdbcType=VARCHAR},
    #{cancelTime,jdbcType=TIMESTAMP}, #{cancelFlag,jdbcType=VARCHAR}, #{belongId,jdbcType=VARCHAR},
    #{plateNo,jdbcType=VARCHAR}, #{inId,jdbcType=VARCHAR}, #{orignalStoreIdOne,jdbcType=VARCHAR},
    #{orignalStoreIdTwo,jdbcType=VARCHAR}, #{receiveAddress,jdbcType=VARCHAR}, #{combineStoreId,jdbcType=VARCHAR}
    ,#{wgtDcnMtcCd,jdbcType=VARCHAR},#{edgeTy,jdbcType=VARCHAR},#{productionPlace,jdbcType=VARCHAR}
    )
  </insert>
  <insert id="insertSelective" parameterType="com.th.demo.model.ware.CombineRecord" >
    insert into t_ware_combine_record
    <trim prefix="(" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        id,
      </if>
      <if test="wareName != null" >
        ware_name,
      </if>
      <if test="stackName != null" >
        stack_name,
      </if>
      <if test="layer != null" >
        layer,
      </if>
      <if test="materialName != null" >
        material_name,
      </if>
      <if test="materialNo != null" >
        material_no,
      </if>
      <if test="standard != null" >
        standard,
      </if>
      <if test="model != null" >
        model,
      </if>
      <if test="customerName != null" >
        customer_name,
      </if>
      <if test="customerNo != null" >
        customer_no,
      </if>
      <if test="orignalCount != null" >
        orignal_count,
      </if>
      <if test="combineCount != null" >
        combine_count,
      </if>
      <if test="orignalWeight != null" >
        orignal_weight,
      </if>
      <if test="combineWeight != null" >
        combine_weight,
      </if>
      <if test="remark != null" >
        remark,
      </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>
      <if test="plateNo != null" >
        plate_no,
      </if>
      <if test="inId != null" >
        in_id,
      </if>
      <if test="storeIdOld != null" >
        store_id_old,
      </if>
      <if test="storeIdNew != null" >
        store_id_new,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        #{id,jdbcType=VARCHAR},
      </if>
      <if test="wareName != null" >
        #{wareName,jdbcType=VARCHAR},
      </if>
      <if test="stackName != null" >
        #{stackName,jdbcType=VARCHAR},
      </if>
      <if test="layer != null" >
        #{layer,jdbcType=INTEGER},
      </if>
      <if test="materialName != null" >
        #{materialName,jdbcType=VARCHAR},
      </if>
      <if test="materialNo != null" >
        #{materialNo,jdbcType=VARCHAR},
      </if>
      <if test="standard != null" >
        #{standard,jdbcType=VARCHAR},
      </if>
      <if test="model != null" >
        #{model,jdbcType=VARCHAR},
      </if>
      <if test="customerName != null" >
        #{customerName,jdbcType=VARCHAR},
      </if>
      <if test="customerNo != null" >
        #{customerNo,jdbcType=VARCHAR},
      </if>
      <if test="orignalCount != null" >
        #{orignalCount,jdbcType=DOUBLE},
      </if>
      <if test="combineCount != null" >
        #{combineCount,jdbcType=DOUBLE},
      </if>
      <if test="orignalWeight != null" >
        #{orignalWeight,jdbcType=DOUBLE},
      </if>
      <if test="combineWeight != null" >
        #{combineWeight,jdbcType=DOUBLE},
      </if>
      <if test="remark != null" >
        #{remark,jdbcType=VARCHAR},
      </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>
      <if test="plateNo != null" >
        #{plateNo,jdbcType=VARCHAR},
      </if>
      <if test="inId != null" >
        #{inId,jdbcType=VARCHAR},
      </if>
      <if test="storeIdOld != null" >
        #{storeIdOld,jdbcType=VARCHAR},
      </if>
      <if test="storeIdNew != null" >
        #{storeIdNew,jdbcType=VARCHAR},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.th.demo.model.ware.CombineRecord" >
    update t_ware_combine_record
    <set >
      <if test="wareName != null" >
        ware_name = #{wareName,jdbcType=VARCHAR},
      </if>
      <if test="stackName != null" >
        stack_name = #{stackName,jdbcType=VARCHAR},
      </if>
      <if test="layer != null" >
        layer = #{layer,jdbcType=INTEGER},
      </if>
      <if test="materialName != null" >
        material_name = #{materialName,jdbcType=VARCHAR},
      </if>
      <if test="materialNo != null" >
        material_no = #{materialNo,jdbcType=VARCHAR},
      </if>
      <if test="standard != null" >
        standard = #{standard,jdbcType=VARCHAR},
      </if>
      <if test="model != null" >
        model = #{model,jdbcType=VARCHAR},
      </if>
      <if test="customerName != null" >
        customer_name = #{customerName,jdbcType=VARCHAR},
      </if>
      <if test="customerNo != null" >
        customer_no = #{customerNo,jdbcType=VARCHAR},
      </if>
      <if test="orignalCount != null" >
        orignal_count = #{orignalCount,jdbcType=DOUBLE},
      </if>
      <if test="combineCount != null" >
        combine_count = #{combineCount,jdbcType=DOUBLE},
      </if>
      <if test="orignalWeight != null" >
        orignal_weight = #{orignalWeight,jdbcType=DOUBLE},
      </if>
      <if test="combineWeight != null" >
        combine_weight = #{combineWeight,jdbcType=DOUBLE},
      </if>
      <if test="remark != null" >
        remark = #{remark,jdbcType=VARCHAR},
      </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>
      <if test="plateNo != null" >
        plate_no = #{plateNo,jdbcType=VARCHAR},
      </if>
      <if test="inId != null" >
        in_id = #{inId,jdbcType=VARCHAR},
      </if>
      <if test="storeIdOld != null" >
        store_id_old = #{storeIdOld,jdbcType=VARCHAR},
      </if>
      <if test="storeIdNew != null" >
        store_id_new = #{storeIdNew,jdbcType=VARCHAR},
      </if>
    </set>
    where id = #{id,jdbcType=VARCHAR}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.th.demo.model.ware.CombineRecord" >
   update t_ware_combine_record
    set ware_name = #{wareName,jdbcType=VARCHAR},
      stack_name = #{stackName,jdbcType=VARCHAR},
      orignal_layer_one = #{orignalLayerOne,jdbcType=INTEGER},
      orignal_layer_two = #{orignalLayerTwo,jdbcType=INTEGER},
      combine_layer = #{combineLayer,jdbcType=INTEGER},
      material_name = #{materialName,jdbcType=VARCHAR},
      material_no = #{materialNo,jdbcType=VARCHAR},
      standard = #{standard,jdbcType=VARCHAR},
      model = #{model,jdbcType=VARCHAR},
      customer_name = #{customerName,jdbcType=VARCHAR},
      customer_no = #{customerNo,jdbcType=VARCHAR},
      orignal_count_one = #{orignalCountOne,jdbcType=DOUBLE},
      orignal_count_two = #{orignalCountTwo,jdbcType=DOUBLE},
      combine_count = #{combineCount,jdbcType=DOUBLE},
      orignal_weight_one = #{orignalWeightOne,jdbcType=DOUBLE},
      orignal_weight_two = #{orignalWeightTwo,jdbcType=DOUBLE},
      combine_weight = #{combineWeight,jdbcType=DOUBLE},
      remark = #{remark,jdbcType=VARCHAR},
      add_id = #{addUser.id,jdbcType=VARCHAR},
      add_time = #{addTime,jdbcType=TIMESTAMP},
      modify_id = #{modifyId,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},
      plate_no = #{plateNo,jdbcType=VARCHAR},
      in_id = #{inId,jdbcType=VARCHAR},
      orignal_store_id_one = #{orignalStoreIdOne,jdbcType=VARCHAR},
      orignal_store_id_two = #{orignalStoreIdTwo,jdbcType=VARCHAR},
      receive_address = #{receiveAddress,jdbcType=VARCHAR},
      combine_store_id = #{combineStoreId,jdbcType=VARCHAR}
    where id = #{id,jdbcType=VARCHAR}
  </update>



  <select id="select" resultMap="BaseResultMap" >
    select   t.*    from t_ware_combine_record t
    where t.ware_name  like concat('%',#{param1,jdbcType=VARCHAR},'%')
    and t.stack_name like concat('%',#{param2,jdbcType=VARCHAR},'%')
    and t.model like concat('%',#{param3,jdbcType=INTEGER},'%')
    and t.material_name like concat('%',#{param4,jdbcType=VARCHAR},'%')
    and t.standard like concat('%',#{param5,jdbcType=VARCHAR},'%')
    and t.customer_name like concat('%',#{param6,jdbcType=VARCHAR},'%')
    and t.plate_no like concat('%',#{param7,jdbcType=VARCHAR},'%')
    and t.add_time between #{param8,jdbcType=TIMESTAMP} and #{param9,jdbcType=TIMESTAMP}
    and  t.ware_name in (
    select b.name from t_maint_userware a ,t_maint_ware b  where a.ware_id = b.id
    and  a.user_id = #{param10,jdbcType=VARCHAR}  )
    and t.belong_id=#{param11,jdbcType=VARCHAR}
    and t.cancel_flag = '0'
    order by t.add_time desc
  </select>
</mapper>