<?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.SplitRecordMapper">
    <resultMap id="BaseResultMap" type="com.th.demo.model.ware.SplitRecord">
        <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" property="orignalLayer" jdbcType="INTEGER"/>
        <result column="split_layer" property="splitLayer" jdbcType="INTEGER"/>
        <result column="remain_layer" property="remainLayer" 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" property="orignalCount" jdbcType="DOUBLE"/>
        <result column="split_count" property="splitCount" jdbcType="DOUBLE"/>
        <result column="remain_count" property="remainCount" jdbcType="DOUBLE"/>
        <result column="orignal_weight" property="orignalWeight" jdbcType="DOUBLE"/>
        <result column="split_weight" property="splitWeight" jdbcType="DOUBLE"/>
        <result column="remain_weight" property="remainWeight" 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" property="orignalStoreId" jdbcType="VARCHAR"/>
        <result column="split_store_id" property="splitStoreId" jdbcType="VARCHAR"/>
        <result column="remain_store_id" property="remainStoreId" 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, stack_name, orignal_layer,split_layer,remain_layer, material_name, material_no, standard, model, customer_name,
    customer_no, orignal_count, split_count, remain_count, orignal_weight, split_weight, 
    remain_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,split_store_id,remain_store_id,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_split_record
        where id = #{id,jdbcType=VARCHAR}
    </select>
    <delete id="deleteByPrimaryKey" parameterType="java.lang.String">
    delete from t_ware_split_record
    where id = #{id,jdbcType=VARCHAR}
  </delete>
    <insert id="insert" parameterType="com.th.demo.model.ware.SplitRecord">
        <selectKey keyProperty="id" order="BEFORE" resultType="java.lang.String">
            SELECT REPLACE(UUID(),'-','') as id from dual
        </selectKey>
        insert into t_ware_split_record (id, ware_name, stack_name,
        orignal_layer,split_layer,remain_layer, material_name, material_no,
        standard, model, customer_name,
        customer_no, orignal_count, split_count,
        remain_count, orignal_weight, split_weight,
        remain_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,split_store_id,remain_store_id, receive_address
        ,wgt_dcn_mtc_cd,edge_ty,production_place
        )
        values (#{id,jdbcType=VARCHAR}, #{wareName,jdbcType=VARCHAR}, #{stackName,jdbcType=VARCHAR},
        #{orignalLayer,jdbcType=INTEGER},  #{splitLayer,jdbcType=INTEGER},  #{remainLayer,jdbcType=INTEGER},
        #{materialName,jdbcType=VARCHAR}, #{materialNo,jdbcType=VARCHAR},
        #{standard,jdbcType=VARCHAR}, #{model,jdbcType=VARCHAR}, #{customerName,jdbcType=VARCHAR},
        #{customerNo,jdbcType=VARCHAR}, #{orignalCount,jdbcType=DOUBLE}, #{splitCount,jdbcType=DOUBLE},
        #{remainCount,jdbcType=DOUBLE}, #{orignalWeight,jdbcType=DOUBLE}, #{splitWeight,jdbcType=DOUBLE},
        #{remainWeight,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},
        #{orignalStoreId,jdbcType=VARCHAR},#{splitStoreId,jdbcType=VARCHAR},
        #{remainStoreId,jdbcType=VARCHAR}, #{receiveAddress,jdbcType=VARCHAR}
        ,#{wgtDcnMtcCd,jdbcType=VARCHAR},#{edgeTy,jdbcType=VARCHAR},#{productionPlace,jdbcType=VARCHAR})

    </insert>
    <insert id="insertSelective" parameterType="com.th.demo.model.ware.SplitRecord">
        insert into t_ware_split_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="splitCount != null">
                split_count,
            </if>
            <if test="remainCount != null">
                remain_count,
            </if>
            <if test="orignalWeight != null">
                orignal_weight,
            </if>
            <if test="splitWeight != null">
                split_weight,
            </if>
            <if test="remainWeight != null">
                remain_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="storeId != null">
                store_id,
            </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="splitCount != null">
                #{splitCount,jdbcType=DOUBLE},
            </if>
            <if test="remainCount != null">
                #{remainCount,jdbcType=DOUBLE},
            </if>
            <if test="orignalWeight != null">
                #{orignalWeight,jdbcType=DOUBLE},
            </if>
            <if test="splitWeight != null">
                #{splitWeight,jdbcType=DOUBLE},
            </if>
            <if test="remainWeight != null">
                #{remainWeight,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="storeId != null">
                #{storeId,jdbcType=VARCHAR},
            </if>
        </trim>
    </insert>
    <update id="updateByPrimaryKeySelective" parameterType="com.th.demo.model.ware.SplitRecord">
        update t_ware_split_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="splitCount != null">
                split_count = #{splitCount,jdbcType=DOUBLE},
            </if>
            <if test="remainCount != null">
                remain_count = #{remainCount,jdbcType=DOUBLE},
            </if>
            <if test="orignalWeight != null">
                orignal_weight = #{orignalWeight,jdbcType=DOUBLE},
            </if>
            <if test="splitWeight != null">
                split_weight = #{splitWeight,jdbcType=DOUBLE},
            </if>
            <if test="remainWeight != null">
                remain_weight = #{remainWeight,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="storeId != null">
                store_id = #{storeId,jdbcType=VARCHAR},
            </if>
        </set>
        where id = #{id,jdbcType=VARCHAR}
    </update>
    <update id="updateByPrimaryKey" parameterType="com.th.demo.model.ware.SplitRecord">
        update t_ware_split_record
    set ware_name = #{wareName,jdbcType=VARCHAR},
      stack_name = #{stackName,jdbcType=VARCHAR},
        orignal_layer = #{orignalLayer,jdbcType=INTEGER},
        split_layer = #{splitLayer,jdbcType=INTEGER},
        remain_layer = #{remainLayer,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 = #{orignalCount,jdbcType=DOUBLE},
      split_count = #{splitCount,jdbcType=DOUBLE},
      remain_count = #{remainCount,jdbcType=DOUBLE},
      orignal_weight = #{orignalWeight,jdbcType=DOUBLE},
      split_weight = #{splitWeight,jdbcType=DOUBLE},
      remain_weight = #{remainWeight,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 = #{orignalStoreId,jdbcType=VARCHAR},
      split_store_id = #{splitStoreId,jdbcType=VARCHAR},
      remain_store_id = #{remainStoreId,jdbcType=VARCHAR},
    receive_address = #{receiveAddress,jdbcType=VARCHAR}
    where id = #{id,jdbcType=VARCHAR}
  </update>


    <select id="select" resultMap="BaseResultMap">
   select
    t.*
    from t_ware_split_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>
    <select id="selectTotal" resultMap="TotalResultMap">
   select
    sum(t.split_count) as total_amount
		,sum(t.split_weight) as total_weight
    from t_ware_split_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>