<?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.TrackRecordMapper" >
  <resultMap id="BaseResultMap" type="com.th.demo.model.ware.TrackRecord" >

    <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="VARCHAR" />
    <result column="layer_new" property="layerNew" jdbcType="VARCHAR" />
    <result column="material_name" property="materialName" jdbcType="VARCHAR" />
    <result column="standard" property="standard" jdbcType="VARCHAR" />
    <result column="model" property="model" jdbcType="VARCHAR" />

        <result column="count_old" property="countOld" jdbcType="VARCHAR" />
        <result column="count_new" property="countNew" jdbcType="VARCHAR" />
        <result column="weight_old" property="weightOld" jdbcType="VARCHAR" />
        <result column="weight_new" property="weightNew" jdbcType="VARCHAR" />
     <result column="remark" property="remark" jdbcType="VARCHAR" />
     <result column="add_time" property="addTime" jdbcType="TIMESTAMP" />
     <result column="plate_no" property="plateNo" jdbcType="VARCHAR" />
      <result column="record_type" property="recordType" jdbcType="VARCHAR" />
      <result column="truck_no" property="truckNo" jdbcType="VARCHAR" />
      <result column="customer_name_old" property="customerNameOld" jdbcType="VARCHAR" />
      <result column="customer_name_new" property="customerNameNew" jdbcType="VARCHAR" />
      <result column="receive_address_old" property="receiveAddressOld" jdbcType="VARCHAR" />
      <result column="receive_address_new" property="receiveAddressNew" jdbcType="VARCHAR" />
    <association  column="add_id" property="addUser" select="com.th.demo.mapping.system.SysUserMapper.selectByPrimaryKey" />
  </resultMap>


  <select id="select" resultMap="BaseResultMap" >
select * from (

		select  t.ware_name as ware_name_old, '' as ware_name_new ,t.stack_name as stack_name_old ,'' as stack_name_new ,
		t.layer as layer_old, '' as layer_new ,  t.material_name,t.standard, t.model,  t.customer_name as customer_name_old,'' as customer_name_new,
         t.count as count_old ,'' as count_new , t.weight as weight_old, '' as weight_new , t.remark, t.add_id, t.add_time,t.plate_no,
		case   when t.record_type ='1' then '入库' else  '取消入库' end as record_type ,t.receive_address as receive_address_old, '' as receive_address_new,
		t.belong_id ,'' as truck_no
		from t_ware_in_record t where t.cancel_flag = '0'

union all

		select  t.ware_name as ware_name_old, '' as ware_name_new ,t.stack_name as stack_name_old ,'' as stack_name_new ,
		t.layer as layer_old, '' as layer_new ,  t.material_name,t.standard, t.model, t.customer_name as customer_name_old,'' as customer_name_new,
		t.count as count_old ,'' as count_new , t.weight as weight_old, '' as weight_new,  t.remark, t.add_id, t.add_time,t.plate_no,
		case   when t.record_type ='1' then '出库' else  '取消出库' end as record_type,t.receive_address as receive_address_old, '' as receive_address_new,
		t.belong_id ,'' as truck_no
		from t_ware_out_record t where t.cancel_flag  = '0'

union all

		select  t.ware_name_old, t.ware_name_new, t.stack_name_old, t.stack_name_new,
		t.layer_old, t.layer_new, 	t.material_name,t.standard, t.model,  t.customer_name as customer_name_old,'' as customer_name_new,
		t.count as count_old ,'' as count_new , t.weight as weight_old, '' as weight_new,  t.remark, t.add_id, t.add_time,t.plate_no,
		'转移' as record_type,t.receive_address as receive_address_old, '' as receive_address_new,
		t.belong_id ,'' as truck_no
		from t_ware_move_record t where t.cancel_flag  = '0'

union all

		select  t.ware_name as ware_name_old, '' as ware_name_new,t.stack_name as stack_name_old ,'' as stack_name_new ,
		t.orignal_layer as layer_old , concat (t.split_layer, '/',	t.remain_layer) as layer_new ,t.material_name,t.standard, t.model,  t.customer_name as customer_name_old,'' as customer_name_new,
         t.orignal_count as count_old, concat (t.split_count, '/',	t.remain_count) as count_new ,  t.orignal_weight as weight_old, concat (t.split_weight, '/',	t.remain_weight) as weight_new ,
		t.remark, t.add_id, t.add_time,t.plate_no,		'拆分' as record_type,t.receive_address as receive_address_old, '' as receive_address_new,
		t.belong_id ,'' as truck_no
		from t_ware_split_record t where t.cancel_flag  = '0'

union all

		select  t.ware_name as ware_name_old, '' as ware_name_new,t.stack_name as stack_name_old ,'' as stack_name_new ,
		t.orignal_layer_one as layer_old , t.combine_layer as layer_new ,t.material_name,t.standard, t.model, t.customer_name as customer_name_old,'' as customer_name_new,
         t.orignal_count_one as count_old, t.combine_count  as count_new ,  t.orignal_weight_one  as weight_old, t.combine_weight  as weight_new ,
		t.remark, t.add_id, t.add_time,t.plate_no,'合并' as record_type,t.receive_address as receive_address_old, '' as receive_address_new,
		t.belong_id ,'' as truck_no
		from t_ware_combine_record t where t.cancel_flag  = '0'

union all

		select  t.ware_name as ware_name_old, '' as ware_name_new ,t.stack_name as stack_name_old ,'' as stack_name_new ,
		t.layer as layer_old, '' as layer_new ,  t.material_name,t.standard, t.model, t.customer_name as customer_name_old,'' as customer_name_new,
         t.count as count_old ,'' as count_new , t.weight as weight_old, '' as weight_new , t.remark, t.add_id, t.add_time,t.plate_no,
		case   when t.record_type ='1' then '配车' else  '取消配车' end as record_type ,t.receive_address as receive_address_old, '' as receive_address_new,
		t.belong_id,t.truck_no
		from t_ware_distribution_record t where t.cancel_flag = '0'

union all

		select  t.ware_name as ware_name_old, '' as ware_name_new ,t.stack_name as stack_name_old ,'' as stack_name_new ,
		t.layer as layer_old, '' as layer_new ,  t.material_name,t.standard, t.model, t.customer_name_old,t.customer_name_new,
         t.count as count_old ,'' as count_new , t.weight as weight_old, '' as weight_new , t.remark, t.add_id, t.add_time,t.plate_no,
		case   when t.record_type ='1' then '货权转移' else  '修改地址' end as record_type ,t.receive_address_old,t.receive_address_new,
		t.belong_id,'' as  truck_no
		from t_ware_change_record t where t.cancel_flag = '0'


)  a where a.belong_id = 	#{param3,jdbcType=VARCHAR}  and	a.plate_no = #{param1,jdbcType=VARCHAR} order by a.add_time asc






  </select>

</mapper>