guohongjin
2024-05-15 5b7639f0bd9e056738ec15100ed0532e965c6cd5
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
<?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="cn.stylefeng.guns.modular.business.mapper.TotalReportMapper">
 
    <select id="courseTotalData" resultType="java.util.Map" parameterType="cn.stylefeng.guns.modular.business.dto.request.TotalRequest">
        SELECT DATE_FORMAT( tco.create_time, #{dateFormat}  ) time,IFNULL(SUM(tco.pay_amount),0) data,count(1) number FROM t_course_order tco
        WHERE
        tco.status_flag IN (1,2)
        <if test="userId != null">
            AND ( tco.course_user_id = #{userId} OR tco.tutoring_user_id = #{userId} )
        </if>
        <if test="beginTime != null and beginTime != ''">
            AND tco.create_time <![CDATA[ >= ]]> #{beginTime}
        </if>
        <if test="endTime != null and endTime != ''">
            AND  tco.create_time <![CDATA[ <= ]]> #{endTime}
        </if>
        GROUP BY time
    </select>
 
    <select id="mentalTestTotalData" resultType="java.util.Map" parameterType="cn.stylefeng.guns.modular.business.dto.request.TotalRequest">
        SELECT DATE_FORMAT( o.create_time, #{dateFormat} ) time,IFNULL(SUM(o.pay_amount),0) data,count(1) number FROM
            t_order_mental_test o
        WHERE
            o.status_flag = 1
        <if test="beginTime != null and beginTime != ''">
            AND o.create_time  <![CDATA[ >= ]]> #{beginTime}
        </if>
        <if test="endTime != null and endTime != ''">
            AND o.create_time <![CDATA[ <= ]]> #{endTime}
        </if>
        GROUP BY time
    </select>
 
    <select id="orderConsultOneTotalData" resultType="java.util.Map" parameterType="cn.stylefeng.guns.modular.business.dto.request.TotalRequest">
        SELECT DATE_FORMAT( o.create_time, #{dateFormat} ) time,IFNULL(SUM(o.pay_amount),0) data,count(1) number FROM
            t_order_consult_one o
        WHERE
            o.status_flag = 1
        <if test="userId != null">
            AND ( o.goods_id = #{userId} )
        </if>
        <if test="beginTime != null and beginTime != ''">
            AND o.create_time <![CDATA[ >= ]]> #{beginTime}
        </if>
        <if test="endTime != null and endTime != ''">
            AND o.create_time <![CDATA[ <= ]]> #{endTime}
        </if>
        GROUP BY time
    </select>
 
    <select id="counsellingTotalData" resultType="java.util.Map"
            parameterType="cn.stylefeng.guns.modular.business.dto.request.TotalRequest">
        SELECT DATE_FORMAT( tco.create_time, #{dateFormat}  ) time,IFNULL(SUM(tco.pay_amount),0) data,count(1) number FROM t_counselling_order tco
        INNER JOIN t_counselling_info tci ON tci.id = tco.counselling_info_id
        WHERE
        tco.status_flag IN (1,2)
        <if test="userId != null">
            AND (tci.user_id = #{userId} OR tco.companion_user_id = #{userId} OR tco.consultant_user_id = #{userId} )
        </if>
 
        <if test="beginTime != null and beginTime != ''">
            AND  tco.create_time <![CDATA[ >= ]]> #{beginTime}
        </if>
        <if test="endTime != null and endTime != ''">
            AND  tco.create_time <![CDATA[ <= ]]> #{endTime}
        </if>
        GROUP BY time
    </select>
    <select id="counsellingOrderTypeTotalData" resultType="java.util.Map">
        SELECT type,IFNULL(SUM(number),0) number  FROM
        (
            SELECT CASE WHEN tco.order_type =1 THEN '首次面诊' ELSE '咨询疗程'  END  type,
            COUNT(tco.id) number FROM t_counselling_order tco
            INNER JOIN t_counselling_info tci ON tci.id = tco.counselling_info_id
            WHERE
            tco.status_flag IN (1,2)
            <if test="userId != null">
                AND (tci.user_id = #{userId} OR tco.companion_user_id = #{userId} OR tco.consultant_user_id = #{userId} )
            </if>
            <if test="beginTime != null and beginTime != ''">
                AND  tco.create_time <![CDATA[ >= ]]> #{beginTime}
            </if>
            <if test="endTime != null and endTime != ''">
                AND  tco.create_time <![CDATA[ <= ]]> #{endTime}
            </if>
            GROUP BY tco.order_type
        ) total
        GROUP BY type
 
    </select>
    <select id="counsellingTypeTotalData" resultType="java.util.Map">
        SELECT CASE WHEN tci.counselling_type =1 THEN '首席咨询师' ELSE '明星咨询师'  END  type,
        COUNT(DISTINCT tco.counselling_info_id) number FROM t_counselling_order tco
        INNER JOIN t_counselling_info tci ON tci.id = tco.counselling_info_id
        WHERE
        tco.status_flag IN (1,2)
        <if test="userId != null">
            AND (tci.user_id = #{userId} OR tco.companion_user_id = #{userId} OR tco.consultant_user_id = #{userId} )
        </if>
        <if test="beginTime != null and beginTime != ''">
            AND  tco.create_time <![CDATA[ >= ]]> #{beginTime}
        </if>
        <if test="endTime != null and endTime != ''">
            AND tco.create_time <![CDATA[ <= ]]> #{endTime}
        </if>
        GROUP BY     tci.counselling_type
 
    </select>
    <select id="counsellingBuyTotal" resultType="java.lang.Long">
        SELECT count(DISTINCT tci.user_id) number FROM t_counselling_order tco
        INNER JOIN t_counselling_info tci ON tci.id = tco.counselling_info_id
        WHERE
        tco.status_flag IN (1,2)
        <if test="userId != null">
            AND (tci.user_id = #{userId} OR tco.companion_user_id = #{userId} OR tco.consultant_user_id = #{userId} )
        </if>
 
        <if test="beginTime != null and beginTime != ''">
            AND  tco.create_time <![CDATA[ >= ]]> #{beginTime}
        </if>
        <if test="endTime != null and endTime != ''">
            AND  tco.create_time <![CDATA[ <= ]]> #{endTime}
        </if>
    </select>
    <select id="courseBuyTotal" resultType="java.lang.Long">
        SELECT count(DISTINCT tco.user_id) number FROM t_course_order tco
        WHERE
        tco.status_flag IN (1,2)
        <if test="userId != null">
            AND ( tco.course_user_id = #{userId} OR tco.tutoring_user_id = #{userId} )
        </if>
        <if test="beginTime != null and beginTime != ''">
            AND tco.create_time <![CDATA[ >= ]]> #{beginTime}
        </if>
        <if test="endTime != null and endTime != ''">
            AND  tco.create_time <![CDATA[ <= ]]> #{endTime}
        </if>
 
    </select>
    <select id="courseNameTotalData" resultType="java.util.Map">
        SELECT tc.course_name courseName,COUNT(tco.id) number FROM t_course_order tco
        INNER JOIN t_course tc ON tc.id = tco.course_id
        WHERE
        tco.status_flag IN (1,2)
        <if test="userId != null">
            AND ( tco.course_user_id = #{userId} OR tco.tutoring_user_id = #{userId} )
        </if>
        <if test="beginTime != null and beginTime != ''">
            AND tco.create_time <![CDATA[ >= ]]> #{beginTime}
        </if>
        <if test="endTime != null and endTime != ''">
            AND tco.create_time <![CDATA[ <= ]]> #{endTime}
        </if>
        GROUP BY tc.course_name
    </select>
    <select id="courseTagTotalData" resultType="java.util.Map">
        SELECT tct.tag_name tagName,COUNT(tco.id) number FROM t_course_order tco
        INNER JOIN t_course tc ON tc.id = tco.course_id
        INNER JOIN t_course_tag tct ON  FIND_IN_SET(tct.id,tc.course_tag_ids)
        WHERE
        tco.status_flag IN (1,2)
        <if test="userId != null">
            AND ( tco.course_user_id = #{userId} OR tco.tutoring_user_id = #{userId} )
        </if>
        <if test="beginTime != null and beginTime != ''">
            AND  tco.create_time <![CDATA[ >= ]]> #{beginTime}
        </if>
        <if test="endTime != null and endTime != ''">
            AND tco.create_time <![CDATA[ <= ]]> #{endTime}
        </if>
        GROUP BY     tct.id
    </select>
</mapper>