515 lines
22 KiB
XML
515 lines
22 KiB
XML
<?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"/>
|
|
<result column="this_order_profit" property="thisOrderProfit"/>
|
|
<result column="custom_money" property="customMoney"/>
|
|
<result column="purchase_decimal" property="purchaseDecimal"/>
|
|
<result column="total_purchase_price" property="totalPurchasePrice"/>
|
|
<result column="shipping_fee" property="shippingFee"/>
|
|
<result column="lease_start_time" property="leaseStartTime"/>
|
|
<result column="lease_end_time" property="leaseEndTime"/>
|
|
<result column="is_lease" property="isLease"/>
|
|
<result column="purchase_status" property="purchaseStatus"/>
|
|
|
|
</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"/>
|
|
<result column="this_order_profit" property="thisOrderProfit"/>
|
|
<result column="custom_money" property="customMoney"/>
|
|
<result column="purchase_decimal" property="purchaseDecimal"/>
|
|
<result column="total_purchase_price" property="totalPurchasePrice"/>
|
|
<result column="shipping_fee" property="shippingFee"/>
|
|
<result column="lease_start_time" property="leaseStartTime"/>
|
|
<result column="lease_end_time" property="leaseEndTime"/>
|
|
<result column="is_lease" property="isLease"/>
|
|
<result column="purchase_status" property="purchaseStatus"/>
|
|
<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,
|
|
o.this_order_profit,
|
|
o.custom_money,
|
|
o.purchase_decimal,
|
|
o.total_purchase_price,
|
|
o.shipping_fee,
|
|
o.lease_start_time,
|
|
o.lease_end_time,
|
|
o.is_lease,
|
|
o.purchase_status
|
|
FROM tbl_sale_order AS o
|
|
</sql>
|
|
|
|
<sql id="SaleOrderFullDto_sql">
|
|
SELECT
|
|
o.id,
|
|
o.code,
|
|
d.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,
|
|
o.this_order_profit,
|
|
o.custom_money,
|
|
d.purchase_decimal as 'purchaseDecimal',
|
|
d.total_purchase_price as 'totalPurchasePrice',
|
|
o.shipping_fee,
|
|
o.lease_start_time,
|
|
o.lease_end_time,
|
|
o.is_lease,
|
|
o.purchase_status,
|
|
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,
|
|
bp.price as 'purchaseDecimal'
|
|
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
|
|
LEFT JOIN base_data_product_purchase as bp ON g.id= bp.id
|
|
</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.isLease != null">
|
|
AND o.is_lease = #{vo.isLease}
|
|
</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.leaseStartTime != null">
|
|
AND o.lease_start_time >= #{vo.leaseStartTime}
|
|
</if>
|
|
<if test="vo.leaseEndTime != null">
|
|
<![CDATA[
|
|
AND o.lease_end_time <= #{vo.leaseEndTime}
|
|
]]>
|
|
</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>
|
|
|
|
<if test="orderIds != null and !orderIds.isEmpty()">
|
|
AND o.id IN
|
|
<foreach item="id" collection="orderIds" open="(" separator="," close=")">
|
|
#{id}
|
|
</foreach>
|
|
</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.purchaseStatus != null">
|
|
AND o.purchase_status = #{vo.purchaseStatus}
|
|
</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.leaseStartTime != null">
|
|
AND o.lease_start_time >= #{vo.leaseStartTime}
|
|
</if>
|
|
<if test="vo.leaseEndTime != null">
|
|
<![CDATA[
|
|
AND o.lease_end_time <= #{vo.leaseEndTime}
|
|
]]>
|
|
</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,d.sc_id AS sc_id
|
|
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>
|
|
<if test="vo.purchaseStatus != null">
|
|
AND o.purchase_status = #{vo.purchaseStatus}
|
|
</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>
|
|
|
|
<select id="CheckTodysSaleOrderLits" resultType="com.lframework.xingyun.sc.vo.chart.SaleOrderVo">
|
|
SELECT * FROM tbl_sale_order ts WHERE DATE(ts.create_time) = CURDATE() AND status=3
|
|
</select>
|
|
|
|
<select id="CheckThisMonthSaleOrderList" resultType="com.lframework.xingyun.sc.vo.chart.SaleOrderVo">
|
|
SELECT * FROM tbl_sale_order ts
|
|
WHERE DATE_FORMAT(ts.create_time, '%Y-%m') = DATE_FORMAT(CURDATE(), '%Y-%m')
|
|
AND status = 3
|
|
</select>
|
|
|
|
|
|
<select id="orderMonthContrastSaleOrder" resultType="map">
|
|
SELECT
|
|
DATE_FORMAT(create_time, '%Y-%m') AS month,
|
|
SUM(total_amount) AS sale_amount
|
|
FROM tbl_sale_order
|
|
WHERE
|
|
create_time >= DATE_SUB(NOW(), INTERVAL 11 MONTH)
|
|
AND create_time < DATE_ADD(NOW(), INTERVAL 1 MONTH)
|
|
AND status = 3
|
|
GROUP BY DATE_FORMAT(create_time, '%Y-%m')
|
|
ORDER BY month
|
|
</select>
|
|
|
|
<select id="orderTodaysContrastSaleOrder" resultType="map">
|
|
SELECT
|
|
DATE_FORMAT(create_time, '%Y-%m-%d') AS date,
|
|
SUM(total_amount) AS sale_amount
|
|
FROM tbl_sale_order
|
|
WHERE
|
|
create_time >= DATE_SUB(NOW(), INTERVAL 30 DAY)
|
|
AND create_time <= NOW()
|
|
AND status = 3
|
|
GROUP BY DATE_FORMAT(create_time, '%Y-%m-%d')
|
|
ORDER BY date ASC
|
|
</select>
|
|
<select id="getSaleAmountByMonth" resultType="BigDecimal">
|
|
SELECT
|
|
COALESCE(SUM(total_amount), 0) AS sale_amount
|
|
FROM tbl_sale_order
|
|
WHERE
|
|
YEAR(create_time) = #{year}
|
|
AND MONTH(create_time) = #{month}
|
|
AND status = 3
|
|
</select>
|
|
|
|
<select id="saleSalerMonthRank" resultType="com.lframework.xingyun.sc.vo.chart.SaleOrderVo">
|
|
SELECT * FROM tbl_sale_order ts
|
|
WHERE DATE_FORMAT(ts.create_time, '%Y-%m') = DATE_FORMAT(CURDATE(), '%Y-%m')
|
|
AND status = 3
|
|
</select>
|
|
|
|
<select id="saleSalerWeekRank" resultType="com.lframework.xingyun.sc.vo.chart.SaleOrderVo">
|
|
SELECT *
|
|
FROM tbl_sale_order ts
|
|
WHERE
|
|
ts.create_time >= #{startDate}
|
|
AND ts.create_time < #{endDate}
|
|
AND status = 3
|
|
</select>
|
|
|
|
<select id="latelyDecemberSaleOrderProfit" resultType="com.lframework.xingyun.sc.vo.chart.SaleOrderVo">
|
|
SELECT * FROM tbl_sale_order ts
|
|
WHERE ts.create_time >= DATE_FORMAT(DATE_SUB(CURDATE(), INTERVAL 11 MONTH), '%Y-%m-01')
|
|
AND ts.create_time < DATE_FORMAT(DATE_ADD(CURDATE(), INTERVAL 1 MONTH), '%Y-%m-01')
|
|
AND status = 3
|
|
</select>
|
|
|
|
<select id="lastYearSaleOrderProfit" resultType="com.lframework.xingyun.sc.vo.chart.SaleOrderVo">
|
|
SELECT * FROM tbl_sale_order ts
|
|
WHERE YEAR(ts.create_time) = YEAR(CURDATE()) - 1
|
|
AND status = 3
|
|
</select>
|
|
|
|
<select id="getYearlyComparisonData" resultType="map">
|
|
SELECT
|
|
year,
|
|
COALESCE(SUM(total_amount), 0) AS total_amount,
|
|
COALESCE(SUM(total_num), 0) AS total_num,
|
|
COALESCE(SUM(total_purchase_price), 0) AS total_purchase_price
|
|
FROM (
|
|
SELECT YEAR(CURDATE()) AS year
|
|
UNION ALL
|
|
SELECT YEAR(CURDATE()) - 1 AS year
|
|
) years
|
|
LEFT JOIN tbl_sale_order
|
|
ON YEAR(create_time) = years.year
|
|
AND status = 3
|
|
GROUP BY year
|
|
ORDER BY year DESC;
|
|
</select>
|
|
|
|
</mapper>
|