<?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.MoveRecordMapper" >
  <resultMap id="BaseResultMap" type="com.th.demo.model.ware.MoveRecord" >
    <id column="id" property="id" jdbcType="VARCHAR" />
    <result column="ware_name_old" property="wareNameOld" jdbcType="VARCHAR" />
    <result column="ware_name_new" property="wareNameNew" jdbcType="VARCHAR" />
    <result column="stack_name_old" property="stackNameOld" jdbcType="VARCHAR" />
    <result column="stack_name_new" property="stackNameNew" jdbcType="VARCHAR" />
    <result column="layer_old" property="layerOld" jdbcType="INTEGER" />
    <result column="layer_new" property="layerNew" 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="count" property="count" jdbcType="DOUBLE" />
    <result column="weight" property="weight" 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="receive_address" property="receiveAddress" 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>
  <resultMap id="TotalResultMap" type="com.th.demo.model.ware.TotalRecord">
    <result column="total_amount" property="totalAmount" jdbcType="DOUBLE" />
    <result column="total_weight" property="totalWeight" jdbcType="DOUBLE" />
  </resultMap>
  <sql id="Base_Column_List" >
    id, ware_name_old, ware_name_new, stack_name_old, stack_name_new, layer_old, layer_new, 
    material_name, material_no, standard, model, customer_name, customer_no, count, weight, 
    remark, add_id, add_time, modify_id, modify_time, cancel_id, cancel_time, cancel_flag, 
    belong_id, plate_no,receive_address,wgt_dcn_mtc_cd,edge_ty,production_place
  </sql>
  <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.String" >
    select 
    <include refid="Base_Column_List" />
    from t_ware_move_record
    where id = #{id,jdbcType=VARCHAR}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.String" >
    delete from t_ware_move_record
    where id = #{id,jdbcType=VARCHAR}
  </delete>
  <insert id="insert" parameterType="com.th.demo.model.ware.MoveRecord" >

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

    insert into t_ware_move_record (id, ware_name_old, ware_name_new, 
      stack_name_old, stack_name_new, layer_old, 
      layer_new, material_name, material_no, 
      standard, model, customer_name, 
      customer_no, count, weight, 
      remark, add_id, add_time, 
      modify_id, modify_time, cancel_id, 
      cancel_time, cancel_flag, belong_id, 
      plate_no,receive_address
    ,wgt_dcn_mtc_cd,edge_ty,production_place)
    values (#{id,jdbcType=VARCHAR}, #{wareNameOld,jdbcType=VARCHAR}, #{wareNameNew,jdbcType=VARCHAR}, 
      #{stackNameOld,jdbcType=VARCHAR}, #{stackNameNew,jdbcType=VARCHAR}, #{layerOld,jdbcType=INTEGER}, 
      #{layerNew,jdbcType=INTEGER}, #{materialName,jdbcType=VARCHAR}, #{materialNo,jdbcType=VARCHAR}, 
      #{standard,jdbcType=VARCHAR}, #{model,jdbcType=VARCHAR}, #{customerName,jdbcType=VARCHAR}, 
      #{customerNo,jdbcType=VARCHAR}, #{count,jdbcType=DOUBLE}, #{weight,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}, #{receiveAddress,jdbcType=VARCHAR}
    ,#{wgtDcnMtcCd,jdbcType=VARCHAR},#{edgeTy,jdbcType=VARCHAR},#{productionPlace,jdbcType=VARCHAR})
  </insert>
  <insert id="insertSelective" parameterType="com.th.demo.model.ware.MoveRecord" >
    insert into t_ware_move_record
    <trim prefix="(" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        id,
      </if>
      <if test="wareNameOld != null" >
        ware_name_old,
      </if>
      <if test="wareNameNew != null" >
        ware_name_new,
      </if>
      <if test="stackNameOld != null" >
        stack_name_old,
      </if>
      <if test="stackNameNew != null" >
        stack_name_new,
      </if>
      <if test="layerOld != null" >
        layer_old,
      </if>
      <if test="layerNew != null" >
        layer_new,
      </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="count != null" >
        count,
      </if>
      <if test="weight != null" >
        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>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        #{id,jdbcType=VARCHAR},
      </if>
      <if test="wareNameOld != null" >
        #{wareNameOld,jdbcType=VARCHAR},
      </if>
      <if test="wareNameNew != null" >
        #{wareNameNew,jdbcType=VARCHAR},
      </if>
      <if test="stackNameOld != null" >
        #{stackNameOld,jdbcType=VARCHAR},
      </if>
      <if test="stackNameNew != null" >
        #{stackNameNew,jdbcType=VARCHAR},
      </if>
      <if test="layerOld != null" >
        #{layerOld,jdbcType=INTEGER},
      </if>
      <if test="layerNew != null" >
        #{layerNew,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="count != null" >
        #{count,jdbcType=DOUBLE},
      </if>
      <if test="weight != null" >
        #{weight,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>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.th.demo.model.ware.MoveRecord" >
    update t_ware_move_record
    <set >
      <if test="wareNameOld != null" >
        ware_name_old = #{wareNameOld,jdbcType=VARCHAR},
      </if>
      <if test="wareNameNew != null" >
        ware_name_new = #{wareNameNew,jdbcType=VARCHAR},
      </if>
      <if test="stackNameOld != null" >
        stack_name_old = #{stackNameOld,jdbcType=VARCHAR},
      </if>
      <if test="stackNameNew != null" >
        stack_name_new = #{stackNameNew,jdbcType=VARCHAR},
      </if>
      <if test="layerOld != null" >
        layer_old = #{layerOld,jdbcType=INTEGER},
      </if>
      <if test="layerNew != null" >
        layer_new = #{layerNew,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="count != null" >
        count = #{count,jdbcType=DOUBLE},
      </if>
      <if test="weight != null" >
        weight = #{weight,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>
    </set>
    where id = #{id,jdbcType=VARCHAR}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.th.demo.model.ware.MoveRecord" >
    update t_ware_move_record
    set ware_name_old = #{wareNameOld,jdbcType=VARCHAR},
      ware_name_new = #{wareNameNew,jdbcType=VARCHAR},
      stack_name_old = #{stackNameOld,jdbcType=VARCHAR},
      stack_name_new = #{stackNameNew,jdbcType=VARCHAR},
      layer_old = #{layerOld,jdbcType=INTEGER},
      layer_new = #{layerNew,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},
      count = #{count,jdbcType=DOUBLE},
      weight = #{weight,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},
    receive_address = #{receiveAddress,jdbcType=VARCHAR}
    where id = #{id,jdbcType=VARCHAR}
  </update>

  <select id="select" resultMap="BaseResultMap" >

     select    t.*    from t_ware_move_record t
      where t.ware_name_old like concat('%',#{param1,jdbcType=VARCHAR},'%')
    and t.ware_name_new like concat('%',#{param2,jdbcType=VARCHAR},'%')
    and t.stack_name_old like concat('%',#{param3,jdbcType=VARCHAR},'%')
    and t.stack_name_new like concat('%',#{param4,jdbcType=VARCHAR},'%')

    and t.model like concat('%',#{param5,jdbcType=INTEGER},'%')
    and t.material_name like concat('%',#{param6,jdbcType=VARCHAR},'%')
    and t.standard like concat('%',#{param7,jdbcType=VARCHAR},'%')
    and t.customer_name like concat('%',#{param8,jdbcType=VARCHAR},'%')
    and t.plate_no like concat('%',#{param9,jdbcType=VARCHAR},'%')
    and t.add_time between #{param10,jdbcType=TIMESTAMP} and #{param11,jdbcType=TIMESTAMP}
    and  t.ware_name_new in (
    select b.name from t_maint_userware a ,t_maint_ware b  where a.ware_id = b.id
    and  a.user_id = #{param12,jdbcType=VARCHAR}  )
         and  t.ware_name_old in (
    select b.name from t_maint_userware a ,t_maint_ware b  where a.ware_id = b.id
    and  a.user_id = #{param12,jdbcType=VARCHAR}  )
    and t.belong_id=#{param13,jdbcType=VARCHAR}
and t.cancel_flag = '0'
    order by t.add_time desc
  </select>
  <select id="selectTotal" resultMap="TotalResultMap" >

     select    sum(t.count) as total_amount
				,sum(t.weight) as total_weight
	from t_ware_move_record t
    where t.ware_name_old like concat('%',#{param1,jdbcType=VARCHAR},'%')
      and t.ware_name_new like concat('%',#{param2,jdbcType=VARCHAR},'%')
      and t.stack_name_old like concat('%',#{param3,jdbcType=VARCHAR},'%')
      and t.stack_name_new like concat('%',#{param4,jdbcType=VARCHAR},'%')
      and t.model like concat('%',#{param5,jdbcType=INTEGER},'%')
      and t.material_name like concat('%',#{param6,jdbcType=VARCHAR},'%')
      and t.standard like concat('%',#{param7,jdbcType=VARCHAR},'%')
      and t.customer_name like concat('%',#{param8,jdbcType=VARCHAR},'%')
      and t.plate_no like concat('%',#{param9,jdbcType=VARCHAR},'%')
      and t.add_time between #{param10,jdbcType=TIMESTAMP} and #{param11,jdbcType=TIMESTAMP}
      and  t.ware_name_new in (
            select b.name from t_maint_userware a ,t_maint_ware b  where a.ware_id = b.id
            and  a.user_id = #{param12,jdbcType=VARCHAR}  )
      and  t.ware_name_old in (
            select b.name from t_maint_userware a ,t_maint_ware b  where a.ware_id = b.id
            and  a.user_id = #{param12,jdbcType=VARCHAR}  )
      and t.belong_id=#{param13,jdbcType=VARCHAR}
      and t.cancel_flag = '0'
    order by t.add_time desc
  </select>
</mapper>