记录操作日志设计

表结构

create table operation_log
(
    id                         int auto_increment
        primary key,
    create_time                timestamp   default CURRENT_TIMESTAMP not null,
    update_time                timestamp   default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP,
    after_value                text                                  null comment '修改后',
    before_value               text                                  null comment '修改前',
    entity                     varchar(64)                           null comment '模块',
    entity_id                  int         default 0                 null comment '模块对应的id',
    ip                         varchar(64)                           null comment 'ip',
    operation_auth_id          varchar(64) default '0'               null comment '操作人authid',
    operation_action           varchar(64) default '0'               null comment '操作动作 自行定义方便后续展示,什么取消 提出等等',
    operation_time             timestamp                             null comment '操作时间',
    operation_type             varchar(64)                           null comment '操作类型',
    operation_user_name        varchar(64)                           null comment '操作人账号',
    operation_user_real_name   varchar(64)                           null comment '操作人姓名',
    operation_user_type        varchar(64)                           null comment '操作人类型',
    operation_user_wx_union_id varchar(64) default '0'               null comment '操作人wxUnionId',
    sno                        varchar(64)                           null comment '操作序列号,多条记录关联可用'
);

create index operation_log_entity_id_index
    on operation_log (entity_id);

获取详细信息 代码 java (减掉 list判empty等)

//  根据创建时间正序查  根据id正序查同理
        List<OperationLog> logAll = findByEntityId(id);
        List<Object> result = new ArrayList<>(logAll.size());
        // 存放 每一次变更前的信息  将 after 填充完整
        Object bak = new Object();
        ObjectMapper objectMapper = new ObjectMapper();
        objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
        for (OperationLog log : logAll){
            Object tmp = new Object();
            result.add(tmp);
            Object afterValue = objectMapper.readValue(log.getAfterValue(), Object.class);
            BeanUtils.copyProperties(afterValue,bak,getNullPropertyNames(afterValue));
            BeanUtils.copyProperties(bak,tmp);
        }
public static String[] getNullPropertyNames (Object source) {
        final BeanWrapper src = new BeanWrapperImpl(source);
        java.beans.PropertyDescriptor[] pds = src.getPropertyDescriptors();

        Set<String> emptyNames = new HashSet<String>();
        for(java.beans.PropertyDescriptor pd : pds) {
            Object srcValue = src.getPropertyValue(pd.getName());
            if (srcValue == null) emptyNames.add(pd.getName());
        }
        String[] result = new String[emptyNames.size()];
        return emptyNames.toArray(result);
    }
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值