package cn.pluss.platform.entity;

import cn.pluss.platform.config.mybatis.SqlConditionExtra;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.annotation.*;
import lombok.Data;
import lombok.experimental.Accessors;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;

@Data
@Accessors(chain = true)
@TableName(value = "tb_pluss_operation_record")
public class OperationRecord {
    private Integer id;
    //来自tb_pluss_dict
    @TableField(exist = false)
    private String dictName;
    //来自tb_pluss_role_info

    private String operator;
    private String dictValue;
    private String userId;

    @TableField(condition = SqlCondition.LIKE_RIGHT)
    private String remark;

    @TableField("extension")
    private JSONObject extension;

    @TableField(fill = FieldFill.INSERT)
    private Date createTime;

    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @TableField(select = false, value = "createTime", condition = SqlConditionExtra.GT)
    private Date createTimeStart;

    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @TableField(select = false, value = "createTime", condition = SqlConditionExtra.LT)
    private Date createTimeEnd;

    @TableField(exist = false)
    private String status;

    @TableField(exist = false)
    private String merchantName;

    @TableField(exist = false)
    private String loginName;

    /**
     * 不需要插入或更新
     */
    @TableField(insertStrategy = FieldStrategy.NEVER, updateStrategy = FieldStrategy.NEVER
            , value = "ip")
    private String ip;

    @TableField(insertStrategy = FieldStrategy.NEVER, updateStrategy = FieldStrategy.NEVER
            , value = "extension ->> '$.isp'")
    private String isp;

    @TableField(insertStrategy = FieldStrategy.NEVER, updateStrategy = FieldStrategy.NEVER
            , value = "extension ->> '$.city'")
    private String city;

    @TableField(insertStrategy = FieldStrategy.NEVER, updateStrategy = FieldStrategy.NEVER
            , value = "extension ->> '$.province'")
    private String province;

    @TableField(insertStrategy = FieldStrategy.NEVER, updateStrategy = FieldStrategy.NEVER
            , value = "extension ->> '$.country'")
    private String country;

    @TableField(insertStrategy = FieldStrategy.NEVER, updateStrategy = FieldStrategy.NEVER
            , value = "extension ->> '$.county'")
    private String county;
}
