SaleOrderMapper.xml 15 KB
<?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.lframework.xingyun.sc.mappers.SaleOrderMapper">

    <resultMap id="SaleOrder" type="com.lframework.xingyun.sc.entity.SaleOrder">
        <id column="id" property="id"/>
        <result column="code" property="code"/>
        <result column="sc_id" property="scId"/>
        <result column="customer_id" property="customerId"/>
        <result column="saler_id" property="salerId"/>
        <result column="total_num" property="totalNum"/>
        <result column="total_gift_num" property="totalGiftNum"/>
        <result column="total_amount" property="totalAmount"/>
        <result column="description" property="description"/>
        <result column="create_by" property="createBy"/>
        <result column="create_time" property="createTime"/>
        <result column="update_by" property="updateBy"/>
        <result column="update_time" property="updateTime"/>
        <result column="approve_by" property="approveBy"/>
        <result column="approve_time" property="approveTime"/>
        <result column="status" property="status"/>
        <result column="refuse_reason" property="refuseReason"/>
    </resultMap>

    <resultMap id="SaleOrderFullDto" type="com.lframework.xingyun.sc.dto.sale.SaleOrderFullDto">
        <id column="id" property="id"/>
        <result column="code" property="code"/>
        <result column="sc_id" property="scId"/>
        <result column="customer_id" property="customerId"/>
        <result column="saler_id" property="salerId"/>
        <result column="total_num" property="totalNum"/>
        <result column="total_gift_num" property="totalGiftNum"/>
        <result column="total_amount" property="totalAmount"/>
        <result column="description" property="description"/>
        <result column="create_by" property="createBy"/>
        <result column="create_time" property="createTime"/>
        <result column="update_by" property="updateBy"/>
        <result column="update_time" property="updateTime"/>
        <result column="approve_by" property="approveBy"/>
        <result column="approve_time" property="approveTime"/>
        <result column="status" property="status"/>
        <result column="refuse_reason" property="refuseReason"/>
        <collection property="details" javaType="java.util.ArrayList" ofType="com.lframework.xingyun.sc.dto.sale.SaleOrderFullDto$OrderDetailDto">
            <id column="detail_id" property="id"/>
            <result column="detail_main_product_id" property="mainProductId"/>
            <result column="detail_product_id" property="productId"/>
            <result column="detail_order_num" property="orderNum"/>
            <result column="detail_ori_price" property="oriPrice"/>
            <result column="detail_tax_price" property="taxPrice"/>
            <result column="detail_discount_rate" property="discountRate"/>
            <result column="detail_is_gift" property="isGift"/>
            <result column="detail_tax_rate" property="taxRate"/>
            <result column="detail_description" property="description"/>
            <result column="detail_order_no" property="orderNo"/>
        </collection>
    </resultMap>

    <resultMap id="SaleOrderWithOutDto" type="com.lframework.xingyun.sc.dto.sale.SaleOrderWithOutDto">
        <id column="id" property="id"/>
        <result column="sc_id" property="scId"/>
        <result column="customer_id" property="customerId"/>
        <result column="saler_id" property="salerId"/>
        <collection property="details" ofType="com.lframework.xingyun.sc.dto.sale.SaleOrderWithOutDto$DetailDto" javaType="java.util.ArrayList">
            <id column="detail_id" property="id"/>
            <result column="detail_main_product_id" property="mainProductId"/>
            <result column="detail_product_id" property="productId"/>
            <result column="detail_order_num" property="orderNum"/>
            <result column="detail_ori_price" property="oriPrice"/>
            <result column="detail_tax_price" property="taxPrice"/>
            <result column="detail_discount_rate" property="discountRate"/>
            <result column="detail_is_gift" property="isGift"/>
            <result column="detail_tax_rate" property="taxRate"/>
            <result column="detail_description" property="description"/>
            <result column="detail_order_no" property="orderNo"/>
            <result column="detail_out_num" property="outNum"/>
        </collection>
    </resultMap>

    <resultMap id="SaleProductDto" type="com.lframework.xingyun.sc.dto.sale.SaleProductDto">
        <id column="id" property="id"/>
        <result column="code" property="code"/>
        <result column="name" property="name"/>
        <result column="category_id" property="categoryId"/>
        <result column="category_name" property="categoryName"/>
        <result column="brand_id" property="brandId"/>
        <result column="brand_name" property="brandName"/>
        <result column="sku_code" property="skuCode"/>
        <result column="external_code" property="externalCode"/>
        <result column="spec" property="spec"/>
        <result column="unit" property="unit"/>
        <result column="sale_price" property="salePrice"/>
        <result column="sale_tax_rate" property="taxRate"/>
        <result column="available" property="available"/>
    </resultMap>

    <sql id="SaleOrderDto_sql">
        SELECT
            o.id,
            o.code,
            o.sc_id,
            o.customer_id,
            o.saler_id,
            o.total_num,
            o.total_gift_num,
            o.total_amount,
            o.description,
            o.create_by,
            o.create_time,
            o.update_by,
            o.update_time,
            o.approve_by,
            o.approve_time,
            o.status,
            o.refuse_reason
        FROM tbl_sale_order AS o
    </sql>

    <sql id="SaleOrderFullDto_sql">
        SELECT
            o.id,
            o.code,
            o.sc_id,
            o.customer_id,
            o.saler_id,
            o.total_num,
            o.total_gift_num,
            o.total_amount,
            o.description,
            o.create_by,
            o.create_time,
            o.update_by,
            o.update_time,
            o.approve_by,
            o.approve_time,
            o.status,
            o.refuse_reason,
            d.id AS detail_id,
            b.main_product_id AS detail_main_product_id,
            d.product_id AS detail_product_id,
            d.order_num AS detail_order_num,
            d.ori_price AS detail_ori_price,
            d.tax_price AS detail_tax_price,
            d.discount_rate AS detail_discount_rate,
            d.is_gift AS detail_is_gift,
            d.tax_rate AS detail_tax_rate,
            d.description AS detail_description,
            d.order_no AS detail_order_no
        FROM tbl_sale_order AS o
        LEFT JOIN tbl_sale_order_detail AS d ON d.order_id = o.id
        LEFT JOIN tbl_sale_order_detail_bundle AS b ON b.order_id = o.id AND b.product_detail_id = d.id
    </sql>

    <sql id="SaleProductDto_sql">
        SELECT
            g.id,
            g.code,
            g.name,
            c.id AS category_id,
            c.name AS category_name,
            b.id AS brand_id,
            b.name AS brand_name,
            g.sku_code,
            g.external_code,
            g.spec,
            g.unit,
            sale.price AS sale_price,
            g.sale_tax_rate,
            g.available
        FROM base_data_product AS g
        INNER JOIN base_data_product_sale AS sale ON sale.id = g.id
        LEFT JOIN base_data_product_category AS c ON c.id = g.category_id
        LEFT JOIN base_data_product_brand AS b ON b.id = g.brand_id
        LEFT JOIN recursion_mapping AS rm ON rm.node_id = c.id and rm.node_type = 2
    </sql>

    <select id="query" resultMap="SaleOrder">
        <include refid="SaleOrderDto_sql"/>
        <where>
            <if test="vo != null">
                <if test="vo.code != null and vo.code != ''">
                    AND o.code = #{vo.code}
                </if>
                <if test="vo.customerId != null and vo.customerId != ''">
                    AND o.customer_id = #{vo.customerId}
                </if>
                <if test="vo.scId != null and vo.scId != ''">
                    AND o.sc_id = #{vo.scId}
                </if>
                <if test="vo.salerId != null and vo.salerId != ''">
                    AND o.saler_id = #{vo.salerId}
                </if>
                <if test="vo.status != null">
                    AND o.status = #{vo.status}
                </if>
                <if test="vo.createBy != null and vo.createBy != ''">
                    AND o.create_by_id = #{vo.createBy}
                </if>
                <if test="vo.approveBy != null and vo.approveBy != ''">
                    AND o.approve_by = #{vo.approveBy}
                </if>
                <if test="vo.createStartTime != null">
                    AND o.create_time >= #{vo.createStartTime}
                </if>
                <if test="vo.createEndTime != null">
                    <![CDATA[
                    AND o.create_time <= #{vo.createEndTime}
                    ]]>
                </if>
                <if test="vo.approveStartTime != null">
                    AND o.approve_time >= #{vo.approveStartTime}
                </if>
                <if test="vo.approveEndTime != null">
                    <![CDATA[
                    AND o.approve_time <= #{vo.approveEndTime}
                    ]]>
                </if>
            </if>
        </where>
        ORDER BY o.create_time DESC
    </select>
    <select id="getDetail" resultMap="SaleOrderFullDto">
        <include refid="SaleOrderFullDto_sql"/>
        WHERE o.id = #{id}
        ORDER BY d.order_no
    </select>
    <select id="selector" resultMap="SaleOrder">
        <include refid="SaleOrderDto_sql"/>
        <where>
            <if test="vo != null">
                <if test="vo.code != null and vo.code != ''">
                    AND o.code = #{vo.code}
                </if>
                <if test="vo.supplierId != null and vo.supplierId != ''">
                    AND o.supplier_id = #{vo.supplierId}
                </if>
                <if test="vo.scId != null and vo.scId != ''">
                    AND o.sc_id = #{vo.scId}
                </if>
                <if test="vo.status != null">
                    AND o.status = #{vo.status}
                </if>
                <if test="vo.createBy != null and vo.createBy != ''">
                    AND o.create_by_id = #{vo.createBy}
                </if>
                <if test="vo.createStartTime != null">
                    AND o.create_time >= #{vo.createStartTime}
                </if>
                <if test="vo.createEndTime != null">
                    <![CDATA[
                    AND o.create_time <= #{vo.createEndTime}
                    ]]>
                </if>
            </if>
        </where>
        ORDER BY o.create_time DESC
    </select>
    <select id="getWithOut" resultMap="SaleOrderWithOutDto">
        SELECT
        o.id, o.sc_id, o.customer_id, o.saler_id, d.id AS detail_id, b.main_product_id AS detail_main_product_id, d.product_id AS detail_product_id,
        d.order_num AS detail_order_num, d.ori_price AS detail_ori_price, d.tax_price AS detail_tax_price,
        d.discount_rate AS detail_discount_rate,
        d.is_gift AS detail_is_gift, d.tax_rate AS detail_tax_rate, d.description AS detail_description, d.order_no AS
        detail_order_no,
        d.out_num AS detail_out_num
        FROM tbl_sale_order AS o
        LEFT JOIN tbl_sale_order_detail AS d ON d.order_id = o.id
        <if test="requireSale">AND d.order_num > d.out_num</if>
        LEFT JOIN tbl_sale_order_detail_bundle AS b ON b.order_id = o.id AND b.product_detail_id = d.id
        WHERE o.id = #{id}
    </select>
    <select id="queryWithOut" resultMap="SaleOrder">
        <include refid="SaleOrderDto_sql"/>
        <if test="!multipleRelate">LEFT JOIN tbl_sale_out_sheet AS s ON s.sale_order_id = o.id</if>
        <where>
            <if test="vo != null">
                <if test="vo.code != null and vo.code != ''">
                    AND o.code = #{vo.code}
                </if>
                <if test="vo.customerId != null and vo.customerId != ''">
                    AND o.customer_id = #{vo.customerId}
                </if>
                <if test="vo.scId != null and vo.scId != ''">
                    AND o.sc_id = #{vo.scId}
                </if>
                AND o.status = 3
                <if test="vo.createBy != null and vo.createBy != ''">
                    AND o.create_by_id = #{vo.createBy}
                </if>
                <if test="vo.createStartTime != null">
                    AND o.create_time >= #{vo.createStartTime}
                </if>
                <if test="vo.createEndTime != null">
                    <![CDATA[
                    AND o.create_time <= #{vo.createEndTime}
                    ]]>
                </if>
            </if>
            <if test="!multipleRelate">AND s.id IS NULL</if>
        </where>
        <if test="!multipleRelate">GROUP BY o.id</if>
        ORDER BY o.create_time DESC
    </select>

    <select id="querySaleByCondition" resultMap="SaleProductDto">
        <include refid="SaleProductDto_sql"/>
        <where>
            AND (
            g.code LIKE CONCAT('%', #{condition}, '%')
            OR g.name LIKE CONCAT('%', #{condition}, '%')
            OR g.sku_code LIKE CONCAT('%', #{condition}, '%')
            OR g.external_code LIKE CONCAT('%', #{condition}, '%')
            )
            <if test="isReturn != null and isReturn">
                AND g.product_type = 1
            </if>
            AND g.available = TRUE
        </where>
        ORDER BY g.code
    </select>
    <select id="querySaleList" resultMap="SaleProductDto">
        <include refid="SaleProductDto_sql"/>
        <where>
            <if test="vo != null">
                <if test="vo.condition != null and vo.condition != ''">
                    AND (
                    g.code LIKE CONCAT('%', #{vo.condition}, '%')
                    OR g.name LIKE CONCAT('%', #{vo.condition}, '%')
                    OR g.sku_code LIKE CONCAT('%', #{vo.condition}, '%')
                    OR g.external_code LIKE CONCAT('%', #{vo.condition}, '%')
                    )
                </if>
                <if test="vo.brandId != null and vo.brandId != ''">
                    AND b.id = #{vo.brandId}
                </if>
                <if test="vo.categoryId != null and vo.categoryId != ''">
                    AND (c.id = #{vo.categoryId} OR FIND_IN_SET(#{vo.categoryId}, rm.path))
                </if>
                <if test="vo.isReturn != null and vo.isReturn">
                    AND g.product_type = 1
                </if>
            </if>
            AND g.available = TRUE
        </where>
        ORDER BY g.code
    </select>
    <select id="getSaleById" resultMap="SaleProductDto">
        <include refid="SaleProductDto_sql"/>
        WHERE g.id = #{id}
    </select>
</mapper>