<?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.dgtly.order.mapper.SalesOrderBaseMapper">

    <resultMap type="SalesOrderBase" id="SalesOrderBaseResult">
        <result property="id" column="id"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
        <result property="isDelete" column="is_delete"/>
        <result property="orderNumber" column="order_number"/>
        <result property="orderCreationTime" column="order_creation_time"/>
        <result property="confirmBy" column="confirm_by"/>
        <result property="expectedTime" column="expected_time"/>
        <result property="belongTo" column="belong_to"/>
        <result property="expectedTimeNotice" column="expected_time_notice"/>

    </resultMap>

    <sql id="selectSalesOrderBaseVo">
        SELECT s.id,
               s.create_by,
               s.create_time,
               s.update_by,
               s.update_time,
               s.is_delete,
               s.order_number,
               s.order_creation_time,
               s.confirm_by,
               s.expected_time,
               s.belong_to,
               s.expected_time_notice,
               CustomerCode,
               CustomerName
        FROM sales_order_base s
                 LEFT JOIN data_master_customer d ON d.CustomerCode = s.belong_to
    </sql>

    <select id="selectSalesOrderBaseList" parameterType="SalesOrderBase" resultMap="SalesOrderBaseResult">
        SELECT
        s.create_time,
        s.order_number,
        s.confirm_by,
        s.expected_time,
        s.expected_time_notice,
        CustomerCode,
        CustomerName
        FROM
        sales_order_base s
        LEFT JOIN data_master_customer d ON d.CustomerCode = s.belong_to
        <where>
            <if test="customerCode != null  and customerCode != ''">and CustomerCode like concat('%',#{customerCode},'%')</if>
            <if test="customerName != null  and customerName != ''">and CustomerName like concat('%',#{customerName},'%')</if>
            and s.is_delete = 0
            <if test="orderNumber != null  and orderNumber != ''">and order_number = #{orderNumber}</if>
            <if test="orderCreationTime != null  and orderCreationTime != ''">and order_creation_time =
                #{orderCreationTime}
            </if>
            <if test="confirmBy != null  and confirmBy != ''">and confirm_by = #{confirmBy}</if>
            <if test="expectedTime != null ">and expected_time = #{expectedTime}</if>
            <if test="belongTo != null  and belongTo != ''">and belong_to = #{belongTo}</if>
            <if test="expectedTimeNotice != null  and expectedTimeNotice != ''">and expected_time_notice =
                #{expectedTimeNotice}
            </if>
            <if test="beginCreateTime != null and beginCreateTime != ''"><!-- 开始时间检索 -->
                and date_format(s.create_time,'%y%m%d') &gt;= date_format(#{beginCreateTime},'%y%m%d')
            </if>
            <if test="endCreateTime != null and endCreateTime != ''"><!-- 结束时间检索 -->
                and date_format(s.create_time,'%y%m%d') &lt;= date_format(#{endCreateTime},'%y%m%d')
            </if>
        </where>
    </select>

    <select id="selectSalesOrderBaseById" parameterType="Long" resultMap="SalesOrderBaseResult">
        <include refid="selectSalesOrderBaseVo"/>
        where id = #{id}
    </select>


</mapper>