du_liany
du_liany
2019-03-25 11:36

关于操作日志如何设计,让用户能看懂的日志(留痕操作)

  • spring

框架:springboot(微服务)
需求:需要建一个日志服务,专门记录客户的操作日志(留痕),银行业务,对于数据非常敏感。

我得设计模式:
利用自定义注解,Aop来记录日志

注解:

/**
 * 操作日志注解
 * @author dulianyong 2019/3/24
 */
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface OperationLogAnno {
    // 操作模块
    String module();
    // 操作类型
    String type();
    // 被修改对象
    String id() default "";
    // 具体操作
    String operate1() default "";
    String operate2() default "";
    String operate3() default "";
    String operate4() default "";
    String operate5() default "";
    String operate6() default "";
    String operate7() default "";
}

加注解的controller:

@PostMapping(path = "/add", produces = MediaType.APPLICATION_JSON_VALUE)
    @OperationLogAnno(module = "角色管理", type = "add", operate1 = "#{role}")
    public ObjectRestResponse add(@RequestBody Role role) throws BaseException {
        //logInfoService.logSaveToDb("角色管理:新增");
        roleService.add(role);
        return new ObjectRestResponse().rel(true);
    }

角色实体

/**
 * 角色信息表
 *
 * @author minliangqin
 * @since 2018-03-12 15:02:10
 */
@MappedSuperclass
@Data
@Table(name = "t_base_role")
@ApiModel(value="角色信息表参数", description = "角色信息表参数描述")
public class Role extends OracleEntity implements Serializable,UniqueVerifiableVO {
    private static final long serialVersionUID = 1L;

    @Id
    @KeySql(genId = UUIDGenerator.class)
    @Column(name = "fid")
    private String id;

    /**
     * 角色名称
     */
    @Column(name = "frole_name")
    @ApiModelProperty(value="角色名称", required = true)
    private String name;


    /**
     * 备注
     */
    @Column(name = "fremark")
    @ApiModelProperty(value="备注", required = true)
    private String description;


    /**
     * 归属机构ID
     */
    @Column(name = "forg_id")
    @ApiModelProperty(value="归属机构ID", required = true)
    private Integer orgId;


    /**
     * 角色编码
     */
    @Column(name = "fcode")
    @ApiModelProperty(value="角色编码", required = true)
    private String code;

    /**
     * 创建时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @Column(name = "fcreate_time")
    private Date createTime;

    /**
     * 归属系统编码
     */
    @Column(name = "fsys_id")
    @ApiModelProperty(value="归属系统编码", required = true)
    private Integer sysId;


    /**
     * 用户类型
     */
    @Column(name = "ftype")
    @ApiModelProperty(value="用户类型", required = true)
    private Integer type;

    /**
     * 是否审核  0未审核|1已审核
     */
    @Column(name = "fchecked")
    private Integer checked;


    /**
     * 审核人id
     */
    @Column(name = "fchecker_id")
    private String checkerId;


    /**
     * 审核时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @Column(name = "fchecker_time")
    private Date checkerTime;

    @Override
    public String fetchUniqueProperty() {
        return "name&description";
    }
}

获取插入的role实体

if (type.equals("add")){
                // 具体操作
                Object operate1 = annotationResolver.resolver(joinPoint, controllerLog.operate1());
                message = "新增:" + JSON.toJSONString(operate1);
            }

我现在为了简便,直接把它转换成json对象扔到数据库了,

新增:{"checked":0,"createTime":1553418453029,"creatorId":"d101468acaf34ddabac9646d2d920113","deleteTime":-28800000,"deleted":0,"deletorId":"0","description":"111","id":"28751ed9ab554b559737216b77584631","lastEditTime":1553418453029,"lastEditorId":"d101468acaf34ddabac9646d2d920113","name":"111","orgId":0,"type":2}

问题是:我如何把checked,createTime等属性转换成汉字形式,让客户看懂,或者有什么更好的存储日志的方法,求好的思路。,没有c币了,谢谢大家!

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

2条回答

为你推荐