--修改数据日志接口返回类型
This commit is contained in:
@ -28,6 +28,7 @@ import java.util.ArrayList;
|
||||
|
||||
import com.xjrsoft.module.datalog.entity.DataChangeLog;
|
||||
import com.xjrsoft.module.datalog.service.DatalogService;
|
||||
import com.xjrsoft.module.datalog.vo.DataChangeLogVo;
|
||||
import com.xjrsoft.module.dev.vo.Testfrom5Vo;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
@ -111,7 +112,7 @@ public class Testfrom5Controller {
|
||||
@ApiOperation(value="根据id查询Testfrom5数据详细日志")
|
||||
@SaCheckPermission("testfrom5:datalog")
|
||||
public R datalog(@RequestParam Long id){
|
||||
List<DataChangeLog> logs = dataService.findLogsByEntityId(UpdateTestfrom5Dto.class,id);
|
||||
List<DataChangeLogVo> logs = dataService.findLogsByEntityId(UpdateTestfrom5Dto.class,id);
|
||||
return R.ok(logs);
|
||||
}
|
||||
|
||||
|
||||
@ -26,6 +26,7 @@ import java.util.ArrayList;
|
||||
|
||||
import com.xjrsoft.module.datalog.entity.DataChangeLog;
|
||||
import com.xjrsoft.module.datalog.service.DatalogService;
|
||||
import com.xjrsoft.module.datalog.vo.DataChangeLogVo;
|
||||
import com.xjrsoft.module.dev.vo.Testfrom6Vo;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
@ -109,7 +110,7 @@ public class Testfrom6Controller {
|
||||
@ApiOperation(value="根据id查询Testfrom6数据详细日志")
|
||||
@SaCheckPermission("testfrom6:datalog")
|
||||
public R datalog(@RequestParam Long id){
|
||||
List<DataChangeLog> logs = dataService.findLogsByEntityId(UpdateTestfrom6Dto.class,id);
|
||||
List<DataChangeLogVo> logs = dataService.findLogsByEntityId(UpdateTestfrom6Dto.class,id);
|
||||
return R.ok(logs);
|
||||
}
|
||||
|
||||
|
||||
@ -1,100 +0,0 @@
|
||||
package com.xjrsoft.module.datalog.vo;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.pictc.common.mybatis.JsonTypeHandler;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
* 数据变更日志实体类
|
||||
* 用于记录数据库字段修改和实体删除操作
|
||||
*/
|
||||
@ApiModel(value = "DataChangeLogDto对象", description = "数据变更日志")
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class DataChangeLogDto implements Serializable{
|
||||
|
||||
/**
|
||||
* @Fields {todo}(用一句话描述这个变量表示什么)
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 日志ID(主键)
|
||||
*/
|
||||
@ApiModelProperty("主键")
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 父表ID,根节点#
|
||||
*/
|
||||
@ApiModelProperty("父表ID")
|
||||
private String pid = "#";
|
||||
|
||||
/**
|
||||
* 实体类名称(全类名)
|
||||
*/
|
||||
@ApiModelProperty("实体类名称(全类名)")
|
||||
private String entityClassName;
|
||||
|
||||
/**
|
||||
* 实体类简称(简单类名)
|
||||
*/
|
||||
@ApiModelProperty("实体类简称(简单类名)")
|
||||
private String entitySimpleName;
|
||||
|
||||
/**
|
||||
* 操作的实体ID(主键值)
|
||||
*/
|
||||
@ApiModelProperty("操作的实体ID(主键值)")
|
||||
private Long entityId;
|
||||
|
||||
/**
|
||||
* 字段变更详情
|
||||
* key: 字段名
|
||||
* value: 包含旧值和新值的Map
|
||||
*/
|
||||
@TableField(typeHandler = JsonTypeHandler.class)
|
||||
@ApiModelProperty("属性值记录")
|
||||
private List<FieldChangeDto> fieldChanges;
|
||||
|
||||
/**
|
||||
* 操作类型:INSERT-新增,UPDATE-修改,DELETE-删除
|
||||
*/
|
||||
@ApiModelProperty("操作类型:INSERT-新增,UPDATE-修改,DELETE-删除")
|
||||
private OperationType operationType;
|
||||
|
||||
/**
|
||||
* 操作人ID
|
||||
*/
|
||||
@ApiModelProperty("操作人ID")
|
||||
private String operatorId;
|
||||
|
||||
/**
|
||||
* 操作人姓名
|
||||
*/
|
||||
@ApiModelProperty("操作人姓名")
|
||||
private String operatorName;
|
||||
|
||||
/**
|
||||
* 操作时间
|
||||
*/
|
||||
@ApiModelProperty("操作时间")
|
||||
private LocalDateTime operationTime;
|
||||
|
||||
/**
|
||||
* 操作IP地址
|
||||
*/
|
||||
@ApiModelProperty("操作IP地址")
|
||||
private String operationIp;
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -1,14 +1,72 @@
|
||||
package com.xjrsoft.module.datalog.vo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class DataChangeLogVo {
|
||||
|
||||
private Long id;
|
||||
@ApiModelProperty("ID")
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* 父表ID,根节点#
|
||||
*/
|
||||
@ApiModelProperty("父表ID")
|
||||
private String pid = "#";
|
||||
|
||||
/**
|
||||
* 操作的实体ID(主键值)
|
||||
*/
|
||||
@ApiModelProperty("操作的实体ID(主键值)")
|
||||
private Long entityId;
|
||||
|
||||
@ApiModelProperty("表名")
|
||||
private String tableName;
|
||||
|
||||
@ApiModelProperty("属性名称")
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 操作类型:INSERT-新增,UPDATE-修改,DELETE-删除
|
||||
*/
|
||||
@ApiModelProperty("操作类型:INSERT-新增,UPDATE-修改,DELETE-删除")
|
||||
private OperationType operationType;
|
||||
|
||||
/**
|
||||
* 旧值
|
||||
*/
|
||||
@ApiModelProperty("原数据")
|
||||
private String oldValue;
|
||||
|
||||
/**
|
||||
* 新值
|
||||
*/
|
||||
@ApiModelProperty("新数据")
|
||||
private String newValue;
|
||||
|
||||
/**
|
||||
* 操作人姓名
|
||||
*/
|
||||
@ApiModelProperty("操作人姓名")
|
||||
private String operatorName;
|
||||
|
||||
/**
|
||||
* 操作IP地址
|
||||
*/
|
||||
@ApiModelProperty("操作IP地址")
|
||||
private String operationIp;
|
||||
|
||||
/**
|
||||
* 操作时间
|
||||
*/
|
||||
@ApiModelProperty("操作时间")
|
||||
private String operationTime;
|
||||
|
||||
@ApiModelProperty("子对象")
|
||||
private List<DataChangeLogVo> children;
|
||||
|
||||
|
||||
|
||||
|
||||
@ -1,39 +0,0 @@
|
||||
package com.xjrsoft.module.datalog.vo;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
@ApiModel(value = "FieldChangeDto对象", description = "数据变更字段记录")
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class FieldChangeDto implements Serializable{
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
|
||||
@ApiModelProperty("属性名称")
|
||||
private String name;
|
||||
|
||||
@ApiModelProperty("属性")
|
||||
private String field;
|
||||
|
||||
/**
|
||||
* 旧值
|
||||
*/
|
||||
@ApiModelProperty("旧值")
|
||||
private Object oldValue;
|
||||
|
||||
/**
|
||||
* 新值
|
||||
*/
|
||||
@ApiModelProperty("新值")
|
||||
private Object newValue;
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@ -19,8 +19,11 @@ import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.validation.Valid;
|
||||
@ -60,6 +63,7 @@ import com.xjrsoft.common.utils.SecureUtil;
|
||||
import com.xjrsoft.module.datalog.entity.DataChangeLog;
|
||||
import com.xjrsoft.module.datalog.entity.json.FieldChange;
|
||||
import com.xjrsoft.module.datalog.service.DatalogService;
|
||||
import com.xjrsoft.module.datalog.vo.DataChangeLogVo;
|
||||
import com.xjrsoft.module.datalog.vo.OperationType;
|
||||
import com.xjrsoft.module.organization.dto.UserDto;
|
||||
|
||||
@ -791,7 +795,7 @@ public class DataLogTools {
|
||||
* @param dataId
|
||||
* @return List<DataChangeLog> 返回类型
|
||||
*/
|
||||
public static <T>List<DataChangeLog> findLogsByEntityId(Class<?> clazz,@NonNull Long dataId) {
|
||||
public static <T>List<DataChangeLogVo> findLogsByEntityId(Class<?> clazz,@NonNull Long dataId) {
|
||||
LogTableInfo tabInfo = getAnnotation(clazz);
|
||||
String tableName = parseLogTableName(tabInfo);
|
||||
return findLogsByEntityId(tableName, dataId);
|
||||
@ -804,7 +808,7 @@ public class DataLogTools {
|
||||
* @param dataId 数据id
|
||||
* @return List<DataChangeLog> 返回类型
|
||||
*/
|
||||
public static <T>List<DataChangeLog> findLogsByEntityId(String tableName,@NonNull Long dataId) {
|
||||
public static <T>List<DataChangeLogVo> findLogsByEntityId(String tableName,@NonNull Long dataId) {
|
||||
if(initTable(tableName)) {
|
||||
return null;
|
||||
}
|
||||
@ -836,7 +840,7 @@ public class DataLogTools {
|
||||
}
|
||||
result.add(log);
|
||||
}
|
||||
return result;
|
||||
return toVo(result);
|
||||
} catch (SQLException e) {
|
||||
throw context.createException(e);
|
||||
} finally {
|
||||
@ -844,6 +848,32 @@ public class DataLogTools {
|
||||
}
|
||||
}
|
||||
|
||||
private static List<DataChangeLogVo> toVo(List<DataChangeLog> list){
|
||||
List<DataChangeLogVo> result = CollectionUtils.newArrayList();
|
||||
if(CollectionUtils.isNotEmpty(list)) {
|
||||
Map<String, List<DataChangeLog>> flowGroup = list.stream().collect(Collectors.groupingBy(DataChangeLog::getFlowId));
|
||||
for (Entry<String, List<DataChangeLog>> entry : flowGroup.entrySet()) {
|
||||
Map<String, List<DataChangeLog>> pidMap = entry.getValue().stream().collect(Collectors.groupingBy(DataChangeLog::getPid));
|
||||
DataChangeLog root = pidMap.get("#").get(0);
|
||||
DataChangeLogVo vo = new DataChangeLogVo();
|
||||
result.add(vo);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static DataChangeLogVo toVo(DataChangeLog obj){
|
||||
DataChangeLogVo vo = new DataChangeLogVo();
|
||||
vo.setId(obj.getId());
|
||||
vo.setPid(obj.getPid());
|
||||
vo.setTableName(obj.getBusName());
|
||||
vo.setOperationType(obj.getOperationType());
|
||||
|
||||
return vo;
|
||||
}
|
||||
|
||||
private static String parseLogTableName(LogTableInfo tableInfo) {
|
||||
String name = tableInfo.getTableName();
|
||||
return "datalog_"+name;
|
||||
|
||||
@ -4,7 +4,7 @@ import java.util.List;
|
||||
|
||||
import javax.validation.Valid;
|
||||
|
||||
import com.xjrsoft.module.datalog.entity.DataChangeLog;
|
||||
import com.xjrsoft.module.datalog.vo.DataChangeLogVo;
|
||||
|
||||
public interface DatalogService {
|
||||
|
||||
@ -18,7 +18,7 @@ public interface DatalogService {
|
||||
|
||||
public <T>T deleteById(Class<T> klazz,long id);
|
||||
|
||||
public <T>List<DataChangeLog> findLogsByEntityId(Class<T> klazz,long id);
|
||||
public <T>List<DataChangeLogVo> findLogsByEntityId(Class<T> klazz,long id);
|
||||
|
||||
public <T>boolean deleteByIds(Class<T> class1, @Valid List<Long> ids);
|
||||
|
||||
|
||||
@ -9,8 +9,8 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import com.google.api.client.util.Lists;
|
||||
import com.pictc.utils.DataLogTools;
|
||||
import com.xjrsoft.module.datalog.entity.DataChangeLog;
|
||||
import com.xjrsoft.module.datalog.service.DatalogService;
|
||||
import com.xjrsoft.module.datalog.vo.DataChangeLogVo;
|
||||
|
||||
@Service
|
||||
public class DatalogServiceImpl implements DatalogService{
|
||||
@ -58,7 +58,7 @@ public class DatalogServiceImpl implements DatalogService{
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
@Override
|
||||
public <T> List<DataChangeLog> findLogsByEntityId(Class<T> klazz, long dataId) {
|
||||
public <T> List<DataChangeLogVo> findLogsByEntityId(Class<T> klazz, long dataId) {
|
||||
return DataLogTools.findLogsByEntityId(klazz, dataId);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user