DspReportLogMapper.xml
6 KB
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
<?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.zteits.parking.module.park.dsp.dal.mysql.DspReportLogMapper">
<insert id="insert" useGeneratedKeys="true" keyProperty="id">
INSERT INTO dsp_report_log (
platform_code, object_type, biz_key, request_id, request_path, http_status,
total, success, failed, error_code, error_msg, payload, cost_ms, client_ip, create_time
) VALUES (
#{platformCode}, #{objectType}, #{bizKey}, #{requestId}, #{requestPath}, #{httpStatus},
#{total}, #{success}, #{failed}, #{errorCode}, #{errorMsg}, #{payload}, #{costMs}, #{clientIp}, #{createTime}
)
</insert>
<!-- ==================== 接收日志页 ==================== -->
<!--
展示口径:1 全部成功 / 2 部分失败 / 3 失败。
传输层拒绝(验签、限流)没有 total/success/failed,靠 error_code 判为失败。
-->
<sql id="resultStateExpr">
CASE
WHEN failed > 0 AND success > 0 THEN 2
WHEN failed > 0 THEN 3
WHEN error_code IS NOT NULL AND error_code <> '0' THEN 3
ELSE 1
END
</sql>
<sql id="logColumns">
id, platform_code, object_type, biz_key, request_id, request_path, http_status,
total, success, failed, error_code, error_msg, cost_ms, client_ip, create_time
</sql>
<sql id="logWhere">
<where>
<if test="q.platformCode != null and q.platformCode != ''">
AND platform_code = #{q.platformCode}
</if>
<if test="q.objectType != null and q.objectType != ''">
AND object_type = #{q.objectType}
</if>
<if test="q.bizKey != null and q.bizKey != ''">
AND biz_key LIKE CONCAT('%', #{q.bizKey}, '%')
</if>
<if test="q.requestId != null and q.requestId != ''">
AND request_id = #{q.requestId}
</if>
<if test="q.startTime != null">
AND create_time >= #{q.startTime}
</if>
<if test="q.endTime != null">
AND create_time < #{q.endTime}
</if>
<if test="q.resultState != null">
<choose>
<when test="q.resultState == 1">
AND failed = 0 AND (error_code IS NULL OR error_code = '0')
</when>
<when test="q.resultState == 2">
AND failed > 0 AND success > 0
</when>
<otherwise>
AND (failed > 0 OR (error_code IS NOT NULL AND error_code <> '0'))
AND NOT (failed > 0 AND success > 0)
</otherwise>
</choose>
</if>
</where>
</sql>
<select id="selectCount" resultType="java.lang.Long">
SELECT COUNT(*) FROM dsp_report_log
<include refid="logWhere"/>
</select>
<select id="selectPage" resultType="com.zteits.parking.module.park.dsp.dal.dataobject.DspReportLogDO">
SELECT <include refid="logColumns"/>,
<include refid="resultStateExpr"/> AS result_state
FROM dsp_report_log
<include refid="logWhere"/>
ORDER BY id DESC
LIMIT #{q.offset}, #{q.limit}
</select>
<select id="selectById" resultType="com.zteits.parking.module.park.dsp.dal.dataobject.DspReportLogDO">
SELECT id, platform_code, object_type, biz_key, request_id, request_path, http_status,
total, success, failed, error_code, error_msg, payload, cost_ms, client_ip, create_time,
<include refid="resultStateExpr"/> AS result_state
FROM dsp_report_log
WHERE id = #{id}
</select>
<select id="selectForExport" resultType="com.zteits.parking.module.park.dsp.dal.dataobject.DspReportLogDO">
SELECT <include refid="logColumns"/>,
<include refid="resultStateExpr"/> AS result_state
FROM dsp_report_log
<include refid="logWhere"/>
ORDER BY id DESC
LIMIT 5000
</select>
<!-- ==================== 总览页统计 ==================== -->
<select id="countByObjectType" resultType="java.util.Map">
SELECT object_type AS objectType,
COUNT(*) AS calls,
SUM(CASE WHEN failed > 0 THEN 1 ELSE 0 END) AS failed,
SUM(CASE WHEN failed = 0 AND (error_code IS NULL OR error_code = '0') THEN 1 ELSE 0 END) AS success
FROM dsp_report_log
WHERE create_time >= #{start} AND create_time < #{end}
GROUP BY object_type
ORDER BY calls DESC
</select>
<select id="countByPlatform" resultType="java.util.Map">
SELECT platform_code AS platformCode,
COUNT(*) AS calls,
SUM(CASE WHEN failed > 0 THEN 1 ELSE 0 END) AS failed
FROM dsp_report_log
WHERE create_time >= #{start} AND create_time < #{end}
GROUP BY platform_code
ORDER BY calls DESC
</select>
<select id="topErrors" resultType="java.util.Map">
SELECT error_code AS errorCode,
MAX(error_msg) AS errorMsg,
COUNT(*) AS cnt
FROM dsp_report_log
WHERE create_time >= #{start} AND create_time < #{end}
AND error_code IS NOT NULL AND error_code <> '0'
GROUP BY error_code
ORDER BY cnt DESC
LIMIT #{limit}
</select>
<select id="selectRecentFailures" resultType="com.zteits.parking.module.park.dsp.dal.dataobject.DspReportLogDO">
SELECT <include refid="logColumns"/>,
<include refid="resultStateExpr"/> AS result_state
FROM dsp_report_log
WHERE failed > 0 OR (error_code IS NOT NULL AND error_code <> '0')
ORDER BY id DESC
LIMIT #{limit}
</select>
</mapper>