<?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.main.CargoMapper">

    <resultMap id="BaseResultMap" type="com.shinsoft.sto.model.main.Cargo">
        <id column="id" property="id" jdbcType="VARCHAR"/>
        <result column="process_instance_id" property="processInstanceId" jdbcType="VARCHAR"/>
        <result column="process_instance_status" property="processInstanceStatus" jdbcType="VARCHAR"/>
        <result column="add_id" property="addId" jdbcType="VARCHAR"/>
        <result column="add_code" property="addCode" jdbcType="VARCHAR"/>
        <result column="add_name" property="addName" jdbcType="VARCHAR"/>
        <result column="add_dept_id" property="addDeptId" jdbcType="VARCHAR"/>
        <result column="add_dept_code" property="addDeptCode" jdbcType="VARCHAR"/>
        <result column="add_dept_name" property="addDeptName" jdbcType="VARCHAR"/>
        <result column="add_time" property="addTime" jdbcType="TIMESTAMP"/>
        <result column="modify_id" property="modifyId" jdbcType="VARCHAR"/>
        <result column="modify_code" property="modifyCode" jdbcType="VARCHAR"/>
        <result column="modify_name" property="modifyName" jdbcType="VARCHAR"/>
        <result column="modify_time" property="modifyTime" jdbcType="TIMESTAMP"/>
        <result column="cancel_id" property="cancelId" jdbcType="VARCHAR"/>
        <result column="cancel_code" property="cancelCode" jdbcType="VARCHAR"/>
        <result column="cancel_name" property="cancelName" 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="uper_customer_id" property="uperCustomerId" jdbcType="VARCHAR"/>
        <result column="customer_id" property="customerId" jdbcType="VARCHAR"/>
        <result column="sum_weight" property="sumWeight" jdbcType="NUMERIC"/>
        <result column="use_weight" property="useWeight" jdbcType="NUMERIC"/>
        <result column="enable_status" property="enableStatus" jdbcType="VARCHAR"/>

        <!-- 关联上游客户信息 -->
        <association property="uperCustomer" javaType="com.shinsoft.sto.model.main.Customer">
            <id column="uper_customer_id" property="id"/>
            <result column="uper_customer_nm" property="customerNm"/>
            <result column="uper_customer_short_nm" property="customerShortNm"/>
        </association>

        <!-- 关联客户信息 -->
        <association property="customer" javaType="com.shinsoft.sto.model.main.Customer">
            <id column="customer_id" property="id"/>
            <result column="customer_nm" property="customerNm"/>
            <result column="customer_short_nm" property="customerShortNm"/>
        </association>
    </resultMap>

    <sql id="Base_Column_List">
        c.id, c.process_instance_id, c.process_instance_status, c.add_id, c.add_code, c.add_name,
        c.add_dept_id, c.add_dept_code, c.add_dept_name, c.add_time, c.modify_id, c.modify_code, c.modify_name,
        c.modify_time, c.cancel_id, c.cancel_code, c.cancel_name, c.cancel_time, c.cancel_flag,
        c.belong_id, c.uper_customer_id, c.customer_id, c.sum_weight, c.use_weight, c.enable_status,
        uper.customer_nm as uper_customer_nm, uper.customer_short_nm as uper_customer_short_nm,
        cust.customer_nm as customer_nm, cust.customer_short_nm as customer_short_nm
    </sql>

    <select id="selectCargoPage" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from T_MAIN_CARGO c
        left join T_MAIN_CUSTOMER uper on c.uper_customer_id = uper.id and uper.cancel_flag = '0'
        left join T_MAIN_CUSTOMER cust on c.customer_id = cust.id and cust.cancel_flag = '0'
        where c.cancel_flag = '0'
        <if test="params.uperCustomerId != null and params.uperCustomerId != ''">
            and c.uper_customer_id = #{params.uperCustomerId}
        </if>
        <if test="params.customerId != null and params.customerId != ''">
            and c.customer_id = #{params.customerId}
        </if>
        order by c.add_time desc
    </select>

</mapper>