<?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.PriceMapper">

    <resultMap id="BaseResultMap" type="com.shinsoft.sto.model.main.Price">
        <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_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="customer_id" property="customerId" jdbcType="VARCHAR"/>
        <result column="material_id" property="materialId" jdbcType="VARCHAR"/>
        <result column="storage_price" property="storagePrice" jdbcType="NUMERIC"/>
        <result column="transfer_price" property="transferPrice" jdbcType="NUMERIC"/>
        <result column="weight_price" property="weightPrice" jdbcType="NUMERIC"/>
        <result column="storage_type" property="storageType" jdbcType="VARCHAR"/>
        <result column="material_name" property="materialName" jdbcType="VARCHAR"/>
        <result column="keep_day" property="keepDay" jdbcType="NUMERIC"/>
        <result column="ord_price" property="ordPrice" jdbcType="NUMERIC"/>
        <result column="out_ord_price" property="outOrdPrice" jdbcType="NUMERIC"/>
        <result column="pay_way" property="payWay" jdbcType="VARCHAR"/>

        <!-- 关联客户信息 -->
        <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"/>
            <result column="contact_person" property="contactPerson"/>
            <result column="contact_info" property="contactInfo"/>
            <result column="default_address" property="defaultAddress"/>
        </association>
    </resultMap>

    <sql id="Base_Column_List">
        p.id, p.process_instance_id, p.process_instance_status, p.add_id, p.add_code, p.add_name,
        p.add_dept_code, p.add_dept_name, p.add_time, p.modify_id, p.modify_code, p.modify_name,
        p.modify_time, p.cancel_id, p.cancel_code, p.cancel_name, p.cancel_time, p.cancel_flag,
        p.belong_id, p.customer_id, p.material_id, p.storage_price, p.transfer_price, p.weight_price,
        p.storage_type, p.material_name, p.keep_day, p.ord_price, p.out_ord_price, p.pay_way,
        c.customer_nm, c.customer_short_nm, c.contact_person, c.contact_info, c.default_address
    </sql>

    <select id="selectPricePage" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from T_MAIN_PRICE p
        left join T_MAIN_CUSTOMER c on p.customer_id = c.id and c.cancel_flag = '0'
        where p.cancel_flag = '0'
        <if test="params.customerName != null and params.customerName != ''">
            and c.customer_nm like '%' || #{params.customerName} || '%'
        </if>
        <if test="params.materialName != null and params.materialName != ''">
            and p.material_name like '%' || #{params.materialName} || '%'
        </if>
        order by p.add_time desc
    </select>

</mapper>