package com.chushang.common.log.entity;

import cn.hutool.core.date.DatePattern;
import com.baomidou.mybatisplus.annotation.*;
import com.chushang.common.log.enums.BusinessType;
import com.chushang.common.log.enums.LogTypeEnum;
import com.chushang.common.mybatis.base.BaseEntity;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
import lombok.*;

import java.time.LocalDateTime;

/**
 * 系统日志
 */
@Data
@ToString
@AllArgsConstructor
@NoArgsConstructor
@TableName(value = "sys_log")
public class SysLogEntity {
    /**
     * 主键id
     */
    @TableId(value = "id", type = IdType.AUTO)
    private Long id;

    /**
     * 日志类型
     */
    @TableField(value = "type")
    private LogTypeEnum type;
    /**
     * 操作ip 地址
     */
    @TableField(value = "remote_addr")
    private String remoteAddr;
    /**
     * 用户代理
     */
    @TableField(value = "user_agent")
    private String userAgent;
    /**
     * 请求URI
     */
    @TableField(value = "request_uri")
    private String requestUri;
    /**
     * 请求方法
     */
    @TableField(value = "method")
    private String method;
    /**
     * 请求参数
     */
    @TableField(value = "params")
    private String params;
    /**
     * 执行时间 毫秒
     */
    @TableField(value = "time")
    private Long time;
    /**
     * 异常信息
     */
    @TableField(value = "exception")
    private String exception;
    /**
    * 操作用户id
    */
    @TableField(value = "user_id")
    private Long userId;
    /**
     * 操作用户账号
     */
    @TableField(value = "username")
    private String username;
    /**
    * 用户操作
    */
    @TableField(value = "operation")
    private String operation;
    /**
     * 用户操作 类型
     */
    @TableField(value = "operation_type")
    private Integer operationType;

    /**
     * 创建时间
     */
    @JsonInclude(JsonInclude.Include.NON_NULL)
    @JsonSerialize(using = LocalDateTimeSerializer.class)
    @JsonDeserialize(using = LocalDateTimeDeserializer.class)
    @TableField(value = "create_time",fill = FieldFill.INSERT, updateStrategy = FieldStrategy.NEVER)
    @JsonFormat(pattern = DatePattern.NORM_DATETIME_PATTERN)
    private LocalDateTime createTime;
    /**
     * 更新时间
     */
    @JsonInclude(JsonInclude.Include.NON_NULL)
    @JsonSerialize(using = LocalDateTimeSerializer.class)
    @JsonDeserialize(using = LocalDateTimeDeserializer.class)
    @TableField(value = "update_time",fill = FieldFill.INSERT_UPDATE, updateStrategy = FieldStrategy.NOT_NULL)
    @JsonFormat(pattern = DatePattern.NORM_DATETIME_PATTERN)
    private LocalDateTime updateTime;
    /**
     * 服务名称
     */
    @TableField(value = "application_name")
    private String applicationName;
    /**
     * 部门id -- 根据部门划分不同的数据?
     */
    private Integer deptId;
}
