<?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="jnpf.bizcommon.audit.mapper.AuditQueryMapper">
|
|
<!-- 自定义 SQL 手写结果映射(L007:@Select/XML 自定义 SQL 不读 MyBatis-Plus @TableField 注解,
|
需显式列出 column->property,此处不用 SELECT * 隐式依赖大小写/下划线自动转换)。 -->
|
<resultMap id="AuditEventResultMap" type="jnpf.bizcommon.audit.entity.AuditEventEntity">
|
<id column="id" property="id"/>
|
<result column="client_event_id" property="clientEventId"/>
|
<result column="operation_id" property="operationId"/>
|
<result column="event_time" property="eventTime"/>
|
<result column="tenant_id" property="tenantId"/>
|
<result column="operator_id" property="operatorId"/>
|
<result column="operator_name" property="operatorName"/>
|
<result column="operator_org_id" property="operatorOrgId"/>
|
<result column="app_name" property="appName"/>
|
<result column="biz_module" property="bizModule"/>
|
<result column="ip" property="ip"/>
|
<result column="ip_region" property="ipRegion"/>
|
<result column="browser" property="browser"/>
|
<result column="os" property="os"/>
|
<result column="request_uri" property="requestUri"/>
|
<result column="event_type" property="eventType"/>
|
<result column="event_category" property="eventCategory"/>
|
<result column="action_code" property="actionCode"/>
|
<result column="action_label" property="actionLabel"/>
|
<result column="source_layer" property="sourceLayer"/>
|
<result column="target_table" property="targetTable"/>
|
<result column="target_id" property="targetId"/>
|
<result column="biz_type" property="bizType"/>
|
<result column="biz_code" property="bizCode"/>
|
<result column="field_diffs" property="fieldDiffs"/>
|
<result column="extra" property="extra"/>
|
<result column="data_snapshot" property="dataSnapshot"/>
|
<result column="reason" property="reason"/>
|
<result column="record_title" property="recordTitle"/>
|
<result column="entry_type" property="entryType"/>
|
<result column="entry_id" property="entryId"/>
|
<result column="entry_name" property="entryName"/>
|
<result column="prev_hash" property="prevHash"/>
|
<result column="created_at" property="createdAt"/>
|
</resultMap>
|
|
<resultMap id="OperationGroupRowMap" type="jnpf.bizcommon.audit.entity.model.AuditOperationGroupRow">
|
<result column="gid" property="gid"/>
|
<result column="grp_time" property="grpTime"/>
|
</resultMap>
|
|
<select id="selectOperationPage" resultMap="OperationGroupRowMap">
|
SELECT matched.gid, matched.grp_time
|
FROM (
|
SELECT COALESCE(operation_id, client_event_id) AS gid,
|
MAX(event_time) AS grp_time
|
FROM audit_events
|
${ew.customSqlSegment}
|
GROUP BY gid
|
) matched
|
WHERE EXISTS (
|
SELECT 1 FROM audit_events business
|
WHERE COALESCE(business.operation_id, business.client_event_id) = matched.gid
|
AND business.event_category = 'BUSINESS'
|
)
|
ORDER BY matched.grp_time DESC
|
LIMIT #{size} OFFSET #{offset}
|
</select>
|
|
<select id="countOperations" resultType="long">
|
SELECT COUNT(*)
|
FROM (
|
SELECT COALESCE(operation_id, client_event_id) AS gid
|
FROM audit_events
|
${ew.customSqlSegment}
|
GROUP BY gid
|
) matched
|
WHERE EXISTS (
|
SELECT 1 FROM audit_events business
|
WHERE COALESCE(business.operation_id, business.client_event_id) = matched.gid
|
AND business.event_category = 'BUSINESS'
|
)
|
</select>
|
|
<select id="selectByOperationGids" resultMap="AuditEventResultMap">
|
SELECT id, client_event_id, operation_id, event_time, tenant_id,
|
operator_id, operator_name, operator_org_id, app_name, biz_module,
|
ip, ip_region, browser, os, request_uri,
|
event_type, event_category, action_code, action_label, source_layer,
|
target_table, target_id, biz_type, biz_code,
|
field_diffs, extra, data_snapshot, reason, prev_hash, created_at,
|
record_title, entry_type, entry_id, entry_name
|
FROM audit_events
|
WHERE COALESCE(operation_id, client_event_id) IN
|
<foreach collection="gids" item="gid" open="(" separator="," close=")">
|
#{gid}
|
</foreach>
|
ORDER BY event_time ASC, id ASC
|
</select>
|
|
<select id="selectTimeline" resultMap="AuditEventResultMap">
|
SELECT id, client_event_id, operation_id, event_time, tenant_id,
|
operator_id, operator_name, operator_org_id, app_name, biz_module,
|
ip, ip_region, browser, os, request_uri,
|
event_type, event_category, action_code, action_label, source_layer,
|
target_table, target_id, biz_type, biz_code,
|
field_diffs, extra, data_snapshot, reason, prev_hash, created_at,
|
record_title, entry_type, entry_id, entry_name
|
FROM audit_events
|
WHERE target_id = #{targetId}
|
ORDER BY id ASC
|
LIMIT #{limit}
|
</select>
|
|
</mapper>
|