SysLogMapper.xml
4.54 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
<?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="org.thingsboard.server.dao.yunteng.mapper.SysLogMapper">
<resultMap id="logDto" type="org.thingsboard.server.common.data.yunteng.dto.SysLogDTO">
<result property="id" column="id"/>
<result property="entityType" column="entity_type" typeHandler="org.apache.ibatis.type.EnumTypeHandler"/>
<result property="entityId" column="entity_id" typeHandler="org.thingsboard.server.dao.yunteng.mapper.UUIDTypeHandler"/>
<result property="entityName" column="entity_name" />
<result property="tenantId" column="tenant_id" typeHandler="org.thingsboard.server.dao.yunteng.mapper.UUIDTypeHandler"/>
<result property="tenantName" column="tenant_name"/>
<result property="customerId" column="customer_id" typeHandler="org.thingsboard.server.dao.yunteng.mapper.UUIDTypeHandler"/>
<result property="customerName" column="customer_name"/>
<result property="userId" column="user_id" typeHandler="org.thingsboard.server.dao.yunteng.mapper.UUIDTypeHandler"/>
<result property="userName" column="user_name" />
<result property="actionData" column="action_data" typeHandler="com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler"/>
<result property="actionType" column="action_type" typeHandler="org.apache.ibatis.type.EnumTypeHandler"/>
<result property="actionStatus" column="action_status" typeHandler="org.apache.ibatis.type.EnumTypeHandler"/>
<result property="actionFailureDetails" column="action_failure_details"/>
<result property="createdTime" column="created_time"/>
</resultMap>
<sql id="baseColumn">
base.id, base.tenant_id, base.created_time, base.customer_id, base.entity_type, base.entity_id, base.entity_name, base.user_id, base.user_name, base.action_type, base.action_status
,ten.title tenant_name,cus.title customer_name
</sql>
<sql id="detailColumn">
<include refid="baseColumn"></include>
, base.action_data,base.action_failure_details
</sql>
<select id="getPageDatasMatched" resultMap="logDto">
SELECT <include refid="baseColumn"/>
FROM audit_log base
LEFT JOIN tenant ten ON base.tenant_id = ten.id
LEFT JOIN customer cus ON base.customer_id = cus.id
<where>
base.entity_type = #{entityType}
<if test="tenantId !=null and tenantId !=''">
AND base.tenant_id = #{tenantId}::uuid
</if>
<if test="customerId !=null ">
AND base.customer_id = #{customerId}::uuid
</if>
<if test="startTime !=null">
AND base.created_time >= #{startTime}
</if>
<if test="endTime !=null">
AND base.created_time < #{endTime}
</if>
<if test="actionType !=null">
AND base.action_type = #{actionType}
</if>
</where>
</select>
<select id="getPageDatasNot" resultMap="logDto">
SELECT <include refid="baseColumn"/>
FROM audit_log base
LEFT JOIN tenant ten ON base.tenant_id = ten.id
LEFT JOIN customer cus ON base.customer_id = cus.id
<where>
base.entity_type
NOT IN
<foreach collection="entityType" item="item" open="(" separator="," close=")">
#{item}
</foreach>
<if test="entityFilter !=null">
AND base.entity_type = #{entityFilter}
</if>
<if test="tenantId !=null and tenantId !=''">
AND base.tenant_id = #{tenantId}::uuid
</if>
<if test="customerId !=null ">
AND base.customer_id = #{customerId}::uuid
</if>
<if test="startTime !=null">
AND base.created_time >= #{startTime}
</if>
<if test="endTime !=null">
AND base.created_time < #{endTime}
</if>
<if test="actionType !=null">
AND base.action_type = #{actionType}
</if>
</where>
</select>
<select id="detailById" resultMap="logDto">
SELECT <include refid="detailColumn"/>
FROM audit_log base
LEFT JOIN tenant ten ON base.tenant_id = ten.id
LEFT JOIN customer cus ON base.customer_id = cus.id
<where>
base.id = #{entityId}::uuid
</where>
</select>
</mapper>