---数据变更日志查询修复

This commit is contained in:
2025-12-08 15:45:58 +08:00
parent 0669ea6d4f
commit 08243b2974
3 changed files with 85 additions and 40 deletions

View File

@ -1,10 +1,12 @@
package com.xjrsoft.module.datalog.mapper;
import java.time.LocalDateTime;
import java.util.List;
import org.apache.ibatis.annotations.*;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.pictc.common.mybatis.JsonTypeHandler;
import com.xjrsoft.module.datalog.entity.DataChangeLog;
/**
@ -20,8 +22,8 @@ public interface DatalogMapper extends BaseMapper<DataChangeLog> {
" id, flow_id, pid, entity_class_name, bus_name, \r\n" +
" entity_id, field_changes, operation_type, operator_id, \r\n" +
" operator_name, operation_time, operation_ip\r\n" +
") VALUES (#{data.id},#{data.flowId},#{data.pid},#{data.entityClassName},#{data.busName},#{data.entityId},"
+ "#{data.fieldChanges},#{data.operationType},#{data.operatorId},#{data.operatorName},#{data.operationTime},#{data.operationIp});";
") VALUES (#{id},#{flowId},#{pid},#{entityClassName},#{busName},#{entityId},"
+ "#{fieldChanges},#{operationType},#{operatorId},#{operatorName},#{operationTime},#{operationIp});";
public static final String SQL_CREATE_TABLE =
"CREATE TABLE \"data_log_sit\".${TBL_NAME} (\r\n" +
@ -63,9 +65,21 @@ public interface DatalogMapper extends BaseMapper<DataChangeLog> {
@Select("select tbl_name FROM \"data_log_sit\".log_table_info")
List<String> getTableList();
// String SQL_INSERT = "INSERT INTO \"data_log_sit\".${TBL_NAME} (\r\n" +
// " id, flow_id, pid, entity_class_name, bus_name, \r\n" +
// " entity_id, field_changes, operation_type, operator_id, \r\n" +
// " operator_name, operation_time, operation_ip\r\n" +
// ") VALUES (#{id},#{flowId},#{pid},#{entityClassName},#{busName},#{entityId},"
// + "#{fieldChanges},#{operationType},#{operatorId},#{operatorName},#{operationTime},#{operationIp});";
@DS("datalog")
@Insert(SQL_INSERT)
void insertDataLog(@Param("TBL_NAME") String tableName,@Param("data") DataChangeLog data);
void insertDataLog(@Param("TBL_NAME") String tableName
,@Param("id") String id,@Param("flowId") String flowId,@Param("pid") String pid
,@Param("entityClassName") String entityClassName,@Param("busName") String busName,@Param("entityId") Long entityId
,@Param("fieldChanges") String fieldChanges,@Param("operationType") String operationType,@Param("operatorId") Long operatorId
,@Param("operatorName") String operatorName,@Param("operationTime") LocalDateTime operationTime,@Param("operationIp") String operationIp);
@DS("datalog")
@Update(SQL_CREATE_TABLE)
@ -73,6 +87,14 @@ public interface DatalogMapper extends BaseMapper<DataChangeLog> {
@DS("datalog")
@Select("SELECT * FROM \"data_log_sit\".${TBL_NAME} WHERE entity_id = #{id} ORDER BY operation_time DESC, flow_id DESC")
@Results({
// 其他字段无需显式配置MyBatis 自动下划线转驼峰),仅配置需要特殊处理的 fieldChanges
@Result(
column = "field_changes", // 数据库列名(必须与表中 JSON 列名一致,如 field_changes
property = "fieldChanges", // 实体字段名
typeHandler = JsonTypeHandler.class // 你的 JSON 类型处理器
)
})
List<DataChangeLog> selectByDataId(@Param("TBL_NAME") String tableName,@Param("id")Long id);