cloudroam
3 天以前 3a819e4f668c15e8b77b188b322470da12bb7a43
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<?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.mzl.flower.mapper.statisticsAnalysis.SalesStatisticsAnalysisMapper">
 
    <select id="getFlowerSaleStatistics"
            resultType="com.mzl.flower.dto.response.statisticAnalysis.FlowerSaleStatisticVO">
        select sum(t.total) as saleAmount,
        sum(t.num) as saleNum,
        count(t.flower_id) as goodsNum,
        sum(t.lackNum) as lackNum,
        sum(t.replaceNum) as replaceNum,
        sum(t.reduceNum) as reduceNum
        from ( <include refid="flowerSalePageSql"></include>) t
    </select>
 
    <select id="getFlowerSalePage" resultType="com.mzl.flower.dto.response.statisticAnalysis.FlowerSaleVO">
        <include refid="flowerSalePageSql"></include>
    </select>
 
    <select id="getFlowerSaleSList" resultType="com.mzl.flower.dto.response.statisticAnalysis.FlowerSaleVO">
        <include refid="flowerSalePageSql"></include>
    </select>
    <sql id="flowerSalePageSql">
        SELECT
        oi.*,
        s.NAME stationName,
        si.contact_tel registerTel,
        si.contact_tel customerTel,
        si.id supplierId,
        si.name supplierName,
        o.id orderId,
        o.order_no,
        o.payment_time,
        c.parent_name flowerCategoryName,
        CONCAT(o.customer_province, ' ', o.customer_city, ' ', o.customer_region, ' ', o.customer_address) AS address,
        COALESCE((SELECT oic.num FROM t_order_item_check oic WHERE oic.order_item_id = oi.id AND oic.type = 'replace'),
        0) replaceNum,
        COALESCE((SELECT oic.num FROM t_order_item_check oic WHERE oic.order_item_id = oi.id AND oic.type = 'reduce'),
        0) reduceNum,
        COALESCE((SELECT oic.num FROM t_order_item_check oic WHERE oic.order_item_id = oi.id AND oic.type = 'lack'), 0)
        lackNum
        FROM
        t_order_item oi
        LEFT JOIN t_station s ON s.id = oi.station_id
        LEFT JOIN t_supplier_info si ON si.id = oi.supplier_id
        LEFT JOIN t_order o ON oi.order_id = o.id
        LEFT JOIN t_flower f on oi.flower_id = f.id
        LEFT JOIN t_flower_category c on c.id = f.category
        <include refid="flowerSaleWhere"></include>
    </sql>
 
    <sql id="flowerSaleWhere">
        WHERE oi.deleted = 0
        and o.payment_time is not null
        and o.status_backend not in ('PENDING','CANCEL','REFUND')
        <if test="dto.supplierId != null">
            and si.id = #{dto.supplierId}
        </if>
        <if test="dto.supplierName != null and dto.supplierName != ''">
            AND si.name LIKE concat('%', #{dto.supplierName},'%')
        </if>
        <if test="dto.registerTel!=null and dto.registerTel!=''">
            AND si.contact_tel LIKE CONCAT('%',#{dto.registerTel}, '%')
        </if>
        <if test="dto.contactTel!=null and dto.contactTel!=''">
            AND si.contact_tel LIKE CONCAT('%',#{dto.contactTel}, '%')
        </if>
        <if test="dto.stationId != null">
            AND oi.station_id = #{dto.stationId}
        </if>
        <if test="dto.flowerCategory != null">
            AND ( f.category = #{dto.flowerCategory} or f.category in (
            select id from t_flower_category where parent_id = #{dto.flowerCategory}
            ))
        </if>
        <if test="dto.flowerLevel != null and dto.flowerLevel != ''">
            AND oi.flower_level = #{dto.flowerLevel}
        </if>
        <if test="dto.customerProvince!=null and dto.customerProvince!=''">
            AND o.customer_province like CONCAT('%',#{dto.customerProvince}, '%')
        </if>
        <if test="dto.customerCity!=null and dto.customerCity!=''">
            AND o.customer_city like CONCAT('%',#{dto.customerCity}, '%')
        </if>
        <if test="dto.customerRegion!=null and dto.customerRegion!=''">
            AND o.customer_region like CONCAT('%',#{dto.customerRegion}, '%')
        </if>
        <if test="dto.orderNo != null and dto.orderNo != ''">
            AND o.order_no LIKE concat('%', #{dto.orderNo},'%')
        </if>
        <!-- 修改查询日期对应的的创建时间为支付时间 2024-10-12-->
        <if test="dto.createStartDate != null">
            AND o.payment_time &gt;= #{dto.createStartDate}
        </if>
        <if test="dto.createEndDate != null">
            AND o.payment_time &lt; #{dto.createEndDate}
        </if>
        <if test="dto.orderField !=null and dto.orderField !=''">
            order by ${dto.orderField} ${dto.orderType}
        </if>
</sql>
 
 
</mapper>