xuhy
2023-04-03 bec9ef7332b0c0d1afc9b28918748efc63a60bcc
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
<?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.stylefeng.guns.modular.system.dao.TOrderMapper">
 
    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.stylefeng.guns.modular.system.model.TOrder">
        <id column="id" property="id" />
        <result column="code" property="code" />
        <result column="userId" property="userId" />
        <result column="driverId" property="driverId" />
        <result column="`source`" property="source" />
        <result column="agentId" property="agentId" />
        <result column="branchOfficeId" property="branchOfficeId" />
        <result column="startTime" property="startTime" />
        <result column="startAddress" property="startAddress" />
        <result column="startLat" property="startLat" />
        <result column="startLng" property="startLng" />
        <result column="endAddress" property="endAddress" />
        <result column="endLat" property="endLat" />
        <result column="endLng" property="endLng" />
        <result column="boardingTime" property="boardingTime" />
        <result column="getoffTime" property="getoffTime" />
        <result column="estimatedPrice" property="estimatedPrice" />
        <result column="orderMoney" property="orderMoney" />
        <result column="payMoney" property="payMoney" />
        <result column="discountedPrice" property="discountedPrice" />
        <result column="couponId" property="couponId" />
        <result column="payType" property="payType" />
        <result column="payTime" property="payTime" />
        <result column="`state`" property="state" />
        <result column="status" property="status" />
        <result column="createTime" property="createTime" />
        <result column="startDistance" property="startLng" />
        <result column="startPrice" property="endAddress" />
        <result column="overDriveDistance" property="endLat" />
        <result column="overDrivePrice" property="endLng" />
        <result column="longDistance" property="boardingTime" />
        <result column="longDistancePrice" property="getoffTime" />
        <result column="overLongDistance" property="estimatedPrice" />
        <result column="overLongDistancePrice" property="orderMoney" />
        <result column="waitTime" property="payMoney" />
        <result column="waitTimePrice" property="discountedPrice" />
        <result column="outWaitTime" property="couponId" />
        <result column="outWaitTimePrice" property="payType" />
        <result column="badWeatherDistance" property="payTime" />
        <result column="badWeatherPrice" property="state" />
        <result column="overBadWeatherDistance" property="status" />
        <result column="overBadWeatherPrice" property="createTime" />
    </resultMap>
 
    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id, code, userId, driverId, `source`, agentId, branchOfficeId, startTime, startAddress, startLat, startLng, endAddress, endLat, endLng,
            boardingTime, getoffTime, estimatedPrice, orderMoney, payMoney, discountedPrice, couponId, payType, payTime, `state`, status, createTime,
            startDistance,startPrice,overDriveDistance,overDrivePrice,longDistance,longDistancePrice,overLongDistance,overLongDistancePrice,
waitTime,waitTimePrice,outWaitTime,outWaitTimePrice,badWeatherDistance,badWeatherPrice,overBadWeatherDistance,overBadWeatherPrice
    </sql>
 
    <sql id="Base_Column_Order">
        o.id, o.code, o.userId, o.driverId, o.`source`, o.agentId, o.branchOfficeId, o.startTime, o.startAddress, o.startLat, o.startLng, o.endAddress, o.endLat, o.endLng,
        o.boardingTime, o.getoffTime, o.estimatedPrice, o.orderMoney, o.payMoney, o.discountedPrice, o.couponId, o.payType, o.payTime, o.`state`, o.status, o.createTime,
        o.startDistance,o.startPrice,o.overDriveDistance,o.overDrivePrice,o.longDistance,o.longDistancePrice,o.overLongDistance,o.overLongDistancePrice,
        o.waitTime,o.waitTimePrice,o.outWaitTime,o.outWaitTimePrice,o.badWeatherDistance,o.badWeatherPrice,o.overBadWeatherDistance,o.overBadWeatherPrice,a.nickname AS userName,
        a.phone AS userPhone,a.cancelCount,a.status AS userStatus,d.name AS driverName,d.phone AS driverPhone
    </sql>
 
    <sql id="Base_Column_Server_Order">
        o.id, o.code, o.userId, o.driverId, o.`source`, o.agentId, o.branchOfficeId, o.startTime, o.startAddress, o.startLat, o.startLng, o.endAddress, o.endLat, o.endLng,
        o.boardingTime, o.getoffTime, o.estimatedPrice, o.orderMoney, o.payMoney, o.discountedPrice, o.couponId, o.payType, o.payTime, o.`state`, o.status, o.createTime,
        o.startDistance,o.startPrice,o.overDriveDistance,o.overDrivePrice,o.longDistance,o.longDistancePrice,o.overLongDistance,o.overLongDistancePrice,
        o.waitTime,o.waitTimePrice,o.outWaitTime,o.outWaitTimePrice,o.badWeatherDistance,o.badWeatherPrice,o.overBadWeatherDistance,o.overBadWeatherPrice,
        d.name AS driverName,d.phone AS driverPhone
    </sql>
 
    <select id="getOrderList" resultType="com.stylefeng.guns.modular.system.controller.resp.TOrderResp">
        select <include refid="Base_Column_Order"></include>
        from t_order o
        left join t_app_user a on o.userId = a.id
        left join t_driver d on o.driverId = d.id
        <where>
            <if test="startTime != null and startTime != '' and endTime != null and endTime != ''">
                AND o.createTime between #{startTime} and #{endTime}
            </if>
            <if test="code != null and code != ''">
                AND o.code LIKE concat('%',#{code},'%')
            </if>
            <if test="source != null">
                AND o.source = #{source}
            </if>
            <if test="userName != null and userName != ''">
                AND a.nickname LIKE concat('%',#{userName},'%')
            </if>
            <if test="userPhone != null and userPhone != ''">
                AND a.phone LIKE concat('%',#{userPhone},'%')
            </if>
            <if test="state != null">
                AND o.state = #{state}
            </if>
            <if test="driverName != null and driverName != ''">
                AND d.name LIKE concat('%',#{driverName},'%')
            </if>
            <if test="isException != null">
                AND a.is_exception = #{isException}
            </if>
            <if test="roleType != null and roleType == 2">
                AND o.branchOfficeId = #{objectId}
            </if>
            <if test="roleType != null and roleType == 3">
                AND o.agentId = #{objectId}
            </if>
        </where>
        ORDER BY o.createTime
    </select>
    <select id="getDataStatisticsByYear" resultType="com.stylefeng.guns.modular.system.controller.resp.DataStatisticsOrderYearResp">
        SELECT createTime AS `month`,COUNT(id) AS orderCount
        FROM t_order
        <where>
            <if test="agentId != null">
                AND agentId = #{agentId}
            </if>
            <if test="yearDate != null and yearDate != ''">
                AND date_format(createTime, '%Y') LIKE concat('',#{yearDate},'%')
            </if>
        </where>
        GROUP BY date_format(createTime, '%Y-%m')
    </select>
    <select id="getDataStatisticsOrderCount" resultType="com.stylefeng.guns.modular.system.controller.resp.PerformanceTableResp">
        SELECT date_format(o.createTime, '%Y-%m') AS monthTime,COUNT(o.id) AS amount,d.name AS userName
        FROM t_order o
        LEFT JOIN t_driver d ON o.driverId = d.id
        <where>
            <if test="agentId != null">
                AND o.agentId = #{agentId}
            </if>
            <if test="monthDate != null and monthDate != ''">
                AND date_format(o.createTime, '%Y-%m') LIKE concat('',#{monthDate},'%')
            </if>
            AND (o.`state` = 108 OR o.`state` = 109)
        </where>
        GROUP BY monthTime,userName
        ORDER BY amount DESC
    </select>
    <select id="getDataStatisticsCount" resultType="java.lang.Integer">
        SELECT COUNT(id)
        FROM t_order
        <where>
            <if test="agentId != null">
                AND agentId = #{agentId}
            </if>
            <if test="type != null">
                AND `state` = #{type}
            </if>
            <if test="localDate != null">
                AND date_format(createTime, '%Y-%m-%d') LIKE concat('',#{localDate},'%')
            </if>
        </where>
    </select>
    <select id="getDataStatisticsServerCount" resultType="java.lang.Integer">
        SELECT COUNT(id)
        FROM t_order
        <where>
            <if test="agentId != null">
                AND agentId = #{agentId}
            </if>
            <if test="localDate != null">
                AND date_format(createTime, '%Y-%m-%d') LIKE concat('',#{localDate},'%')
            </if>
            AND (`state` = 102
                OR `state` = 103
                OR `state` = 104
                OR `state` = 105
                OR `state` = 106
                OR `state` = 107
            )
        </where>
    </select>
    <select id="getDataStatisticsServerList" resultType="com.stylefeng.guns.modular.system.controller.resp.TOrderServerResp">
        select <include refid="Base_Column_Server_Order"></include>
        FROM t_order o
        LEFT JOIN t_driver d ON o.driverId = d.id
        <where>
            <if test="agentId != null">
                AND o.agentId = #{agentId}
            </if>
            <if test="localDate != null">
                AND date_format(o.createTime, '%Y-%m-%d') LIKE concat('',#{localDate},'%')
            </if>
            AND (o.`state` = 102
            OR o.`state` = 103
            OR o.`state` = 104
            OR o.`state` = 105
            OR o.`state` = 106
            OR o.`state` = 107
            )
        </where>
    </select>
    <select id="getDataStatisticsAllList" resultType="com.stylefeng.guns.modular.system.model.TOrder">
        select <include refid="Base_Column_List"></include>
        FROM t_order
        <where>
            <if test="agentId != null">
                AND agentId = #{agentId}
            </if>
            <if test="localDate != null">
                AND date_format(createTime, '%Y-%m-%d') LIKE concat('',#{localDate},'%')
            </if>
        </where>
    </select>
 
</mapper>