package com.sptg.statistics.api.entity;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.annotations.TableField;
import com.baomidou.mybatisplus.annotations.TableId;
import com.baomidou.mybatisplus.annotations.TableName;
import com.baomidou.mybatisplus.enums.IdType;
import com.sptg.permissions.api.entity.Account;
import lombok.Getter;
import lombok.Setter;

import java.util.Date;
import java.util.List;

/**
 * title: SysOperationLog
 * package: com.sptg.statistics.api.entity
 * description: 系统操作日志
 *
 *                
 *                
 */
@Setter
@Getter
@TableName(value = "sys_operation_log")
public class SysOperationLog {
    public SysOperationLog(){}
    public SysOperationLog(int operationEvent, String operatorIp, Account account){
        this.operator=account.getId();
        this.operatorAccountName=account.getLoginName();
        this.operationEvent=operationEvent;
        this.operatorIp=operatorIp;
        this.orgId=account.getOrgId();
        this.rootOrgId=account.getRootOrgId();
        this.orgPosition=account.getOrgPosition();
    }
    public SysOperationLog(String menu,int operationEvent,String operatorIp, Account account){
        this.menu=menu;
        this.operator=account.getId();
        this.operatorAccountName=account.getLoginName();
        this.operationEvent=operationEvent;
        this.operatorIp=operatorIp;
        this.orgId=account.getOrgId();
        this.rootOrgId=account.getRootOrgId();
        this.orgPosition=account.getOrgPosition();
    }
    public SysOperationLog(String menu,int operationEvent,String operatorIp,Object operationObject, Account account){
        this.menu=menu;
        this.operator=account.getId();
        this.operatorAccountName=account.getLoginName();
        this.operationEvent=operationEvent;
        this.operatorIp=operatorIp;
        this.operationObject=operationObject;
        this.operationObjectClass=operationObject.getClass();
        this.orgId=account.getOrgId();
        this.rootOrgId=account.getRootOrgId();
        this.orgPosition=account.getOrgPosition();
    }
    public SysOperationLog(String menu,int operationEvent,String operatorIp,Object operationObject, Account account, Object oldObj){
        this.menu=menu;
        this.operator=account.getId();
        this.operatorAccountName=account.getLoginName();
        this.operationEvent=operationEvent;
        this.operatorIp=operatorIp;
        this.operationObject=operationObject;
        this.operationObjectClass=operationObject.getClass();
        this.orgId=account.getOrgId();
        this.rootOrgId=account.getRootOrgId();
        this.orgPosition=account.getOrgPosition();
        this.oldObj = JSON.toJSONString(oldObj);
    }
    public SysOperationLog(String menu,int operationEvent,String operatorIp,Object operationObject, Account account, Object oldObj, Object newObj){
        this.menu=menu;
        this.operator=account.getId();
        this.operatorAccountName=account.getLoginName();
        this.operationEvent=operationEvent;
        this.operatorIp=operatorIp;
        this.operationObject=operationObject;
        this.operationObjectClass=operationObject.getClass();
        this.orgId=account.getOrgId();
        this.rootOrgId=account.getRootOrgId();
        this.orgPosition=account.getOrgPosition();
        this.oldObj = JSON.toJSONString(oldObj);
        this.newObj = JSON.toJSONString(newObj);

    }
    public SysOperationLog(String menu,int operationEvent,String operatorIp,String message,Object operationObject, Account account){
        this.menu=menu;
        this.operator=account.getId();
        this.operatorAccountName=account.getLoginName();
        this.operationEvent=operationEvent;
        this.operatorIp=operatorIp;
        this.operationObject=operationObject;
        this.operationObjectClass=operationObject.getClass();
        this.message=message;
        this.orgId=account.getOrgId();
        this.rootOrgId=account.getRootOrgId();
        this.orgPosition=account.getOrgPosition();
    }
    public SysOperationLog(String menu,int operationEvent,String operatorIp,String message,Object operationObject, Account account, Object oldObj){
        this.menu=menu;
        this.operator=account.getId();
        this.operatorAccountName=account.getLoginName();
        this.operationEvent=operationEvent;
        this.operatorIp=operatorIp;
        this.operationObject=operationObject;
        this.operationObjectClass=operationObject.getClass();
        this.message=message;
        this.orgId=account.getOrgId();
        this.rootOrgId=account.getRootOrgId();
        this.orgPosition=account.getOrgPosition();
        this.oldObj = JSON.toJSONString(oldObj);
    }
    public SysOperationLog(String menu,int operationEvent,String operatorIp,String message,Object operationObject, Account account, Object oldObj, Object newObj){
        this.menu=menu;
        this.operator=account.getId();
        this.operatorAccountName=account.getLoginName();
        this.operationEvent=operationEvent;
        this.operatorIp=operatorIp;
        this.operationObject=operationObject;
        this.operationObjectClass=operationObject.getClass();
        this.message=message;
        this.orgId=account.getOrgId();
        this.rootOrgId=account.getRootOrgId();
        this.orgPosition=account.getOrgPosition();
        this.oldObj = JSON.toJSONString(oldObj);
        this.newObj = JSON.toJSONString(newObj);

    }

    /**
     *主键
     */
    @TableId(value = "l_id",type= IdType.AUTO)
    private Long id;
    /**
     *操作菜单
     */
    @TableField(value="s_menu")
    private String menu;
    /**
     * 操作事件  0新增  1删除  2 修改  3登录  4退出登录
     */
    @TableField(value="i_operation_event")
    private Integer operationEvent;
    /**
     * 操作人id(account.l_id)
     */
    @TableField(value="l_operator_id")
    private Long operator;
    /**
     * 操作人名称(account.s_user_name)
     */
    @TableField(value="s_operator_account_name")
    private String operatorAccountName;
    /**
     * 操作人ip
     */
    @TableField(value="s_operator_ip")
    private String operatorIp;
    /**
     * 操作时间 (可不填，自动填充)
     */
    @TableField(value="t_operation_date")
    private Date operationDate;
    /**
     * 表名
     */
    @TableField(value="s_table_name")
    private String tableName;
    /**
     * 表id主键,多个逗号分开
     */
    @TableField(value="s_table_id")
    private String tableId;
    /**
     * 日志信息(可不填，自动填充)
     */
    @TableField(value="s_message")
    private String message;
    /**
     * 所属机构Id
     */
    @TableField(value = "l_org_id")
    private Long orgId;
    /**
     * 根机构Id
     */
    @TableField(value = "l_root_org_id")
    private Long rootOrgId;

    /**
     * 存储位置
     */
    @TableField(value = "s_org_position")
    private String orgPosition;
    /**
     * 删除标记：{ -1：已删除，0：正常 }
     */
    @TableField(value="i_status")
    private int status;

    /**
     * 旧对象
     */
    @TableField(value = "s_old_obj")
    private String oldObj;

    /**
     * 新对象
     */
    @TableField(value = "s_new_obj")
    private String newObj;

    /*---------------------------------------------------------------------------------------------*/

    /**
     * 操作对象(增删改的实体对象)
     */
    @TableField(exist = false)
    private Object operationObject;

    /**
     * 操作对象class
     */
    @TableField(exist = false)
    private Class operationObjectClass;

    /**
     * 由过去的某一时间,计算距离当前的时间
     */
    @TableField(exist = false)
    private String beforeDateMsg;

    /**
     * 用户头像路径
     */
    @TableField(exist = false)
    private String userPortraitUri;
}
