package com.tashow.cloud.app.model;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.tashow.cloud.app.mq.message.BuriedMessages;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import java.util.Date;

/**
 * 埋点数据实体类
 */
@Data
@NoArgsConstructor
@Accessors(chain = true)
@TableName(value = "app_burying")
public class BuriedPoint {
    /**
     * 主键ID
     */
    @TableId(value = "id", type = IdType.AUTO)
    private Integer id;
    /**
     * 事件唯一ID
     */
    @TableField(value = "event_id")
    private Integer eventId;
    
    /**
     * 事件时间戳
     */
    @TableField(value = "event_time")
    private Long eventTime;

    /**
     * 服务名称
     */
    @TableField(value = "service")
    private String service;
    
    /**
     * 方法/接口
     */
    @TableField(value = "method")
    private String method;
    
    /**
     * 用户标识
     */
    @TableField(value = "user_id")
    private String userId;
    
    /**
     * 会话标识
     */
    @TableField(value = "session_id")
    private String sessionId;
    
    /**
     * 客户端IP
     */
    @TableField(value = "client_ip")
    private String clientIp;
    
    /**
     * 服务器IP
     */
    @TableField(value = "server_ip")
    private String serverIp;
    
    /**
     * 事件类型
     */
    @TableField(value = "event_type")
    private String eventType;
    
    /**
     * 页面路径/功能模块
     */
    @TableField(value = "page_path")
    private String pagePath;
    
    /**
     * 元素标识
     */
    @TableField(value = "element_id")
    private String elementId;
    
    /**
     * 操作时长(毫秒)
     */
    @TableField(value = "duration")
    private Long duration;
    
    /**
     * 创建时间
     */
    @TableField(value = "create_time")
    private Date createTime;


    @TableField(value = "update_time")
    private Date updateTime;

    @TableField(value = "status")
    private Integer status;
    

    public BuriedPoint(BuriedMessages message) {
        this.eventId = message.getId();
        this.eventTime = System.currentTimeMillis();
        this.userId = message.getUserId();
        this.eventType = message.getEventType();
        this.service = message.getService();
        this.method = message.getMethod();
        this.sessionId = message.getSessionId();
        this.clientIp = message.getClientIp();
        this.serverIp = message.getServerIp();
        this.status = message.getStatusCode();
        this.pagePath = message.getPagePath();
        this.elementId = message.getElementId();
        this.createTime = new Date();
        this.updateTime = new Date();
    }
} 

