<?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.shinsoft.sto.mapper.ware.DistributionMapper" >
  <resultMap id="BaseResultMap" type="com.shinsoft.sto.model.ware.Distribution" >
    <id column="id" property="id" jdbcType="VARCHAR" />
    <result column="belong_id" property="belongId" jdbcType="VARCHAR" />
    <result column="distrb_no" property="distrbNo" jdbcType="VARCHAR" />
    <result column="truck_no" property="truckNo" jdbcType="VARCHAR" />
    <result column="driver_name" property="driverName" jdbcType="VARCHAR" />
    <result column="driver_phone" property="driverPhone" jdbcType="VARCHAR" />
    <result column="sum_weight" property="sumWeight" jdbcType="DECIMAL" />
    <result column="sum_count" property="sumCount" jdbcType="DECIMAL" />
    <result column="suttle" property="suttle" jdbcType="DECIMAL" />
    <result column="out_flag" property="outFlag" jdbcType="VARCHAR" />
    <result column="delivery_company" property="deliveryCompany" jdbcType="VARCHAR" />
    <result column="fk_company" property="fkCompany" jdbcType="VARCHAR" />
    <result column="toatal_amount" property="toatalAmount" jdbcType="DECIMAL" />
    <result column="discount_amount" property="discountAmount" jdbcType="DECIMAL" />
    <result column="pay_type" property="payType" jdbcType="VARCHAR" />
    <result column="is_settle" property="isSettle" jdbcType="VARCHAR" />
    <result column="delivery_address" property="deliveryAddress" jdbcType="VARCHAR" />
    <result column="tally_people" property="tallyPeople" jdbcType="VARCHAR" />
    <result column="add_id" property="addId" 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" />
  </resultMap>

    <sql id="QueryWhere">
        where 1=1
        <if test="parms.distrbNo != null and parms.distrbNo != ''">
            and dl.distrb_no like '%' || #{parms.distrbNo} || '%'
        </if>
        <if test="parms.truckNo != null and parms.truckNo != ''">
            and dl.truck_no like '%' || #{parms.truckNo} || '%'
        </if>
        <if test="parms.driverName != null and parms.driverName != ''">
            and dl.driver_name like '%' || #{parms.driverName} || '%'
        </if>
        <if test="parms.driverPhone != null and parms.driverPhone != ''">
            and dl.driver_phone like '%' || #{parms.driverPhone} || '%'
        </if>
        <if test="parms.outFlag != null and parms.outFlag != ''">
            and dl.out_flag = #{parms.outFlag}
        </if>
        <if test="parms.deliveryCompany != null and parms.deliveryCompany != ''">
            and dl.delivery_company like '%' || #{parms.deliveryCompany} || '%'
        </if>
        <if test="parms.fkCompany != null and parms.fkCompany != ''">
            and dl.fk_company like '%' || #{parms.fkCompany} || '%'
        </if>
        <if test="parms.payType != null and parms.payType != ''">
            and dl.pay_type = #{parms.payType}
        </if>
        <if test="parms.isSettle != null and parms.isSettle != ''">
            and dl.is_settle = #{parms.isSettle}
        </if>
        <if test="parms.tallyPeople != null and parms.tallyPeople != ''">
            and dl.tally_people like '%' || #{parms.tallyPeople} || '%'
        </if>
        and dl.cancel_flag = '0'
    </sql>

    <select id="selectDistributionPage" resultMap="BaseResultMap" parameterType="map">
        select
            dl.id,
            dl.belong_id,
            dl.distrb_no,
            dl.truck_no,
            dl.driver_name,
            dl.driver_phone,
            dl.sum_weight,
            dl.sum_count,
            dl.suttle,
            dl.out_flag,
            dl.delivery_company,
            dl.fk_company,
            dl.toatal_amount,
            dl.discount_amount,
            dl.pay_type,
            dl.is_settle,
            dl.delivery_address,
            dl.tally_people,
            dl.add_id,
            dl.add_time,
            dl.modify_id,
            dl.modify_time,
            dl.cancel_id,
            dl.cancel_time,
            dl.cancel_flag
        from T_DISTRIBUTION_LIST dl
        <include refid="QueryWhere"/>
        order by dl.add_time desc
    </select>
</mapper>

