package cn.pluss.platform.vo;

import cn.pluss.platform.entity.OperationRecord;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import lombok.EqualsAndHashCode;

@Data
@TableName("( SELECT opr.*, ua.userName, mbi.address, t.count, IF(opr.extension ->> '$.country' IS NULL, -1, IF(opr.extension ->> '$.country' = '中国', '1', '0')) isChina FROM tb_pluss_operation_record opr " +
        "LEFT JOIN tb_pluss_user_app ua ON opr.userId = ua.userId " +
        "LEFT JOIN tb_pluss_merchant_base_info mbi ON mbi.userId = opr.userId " +
        "LEFT JOIN (" +
        "    SELECT extension ->> '$.ip' ip , COUNT(DISTINCT opr.userId) count FROM tb_pluss_operation_record  opr" +
        "        LEFT JOIN tb_pluss_user_app ua ON ua.userId = opr.userId WHERE ua.userType != 'staff' GROUP BY extension ->> '$.ip'" +
        ") t ON t.ip = opr.extension ->> '$.ip' WHERE ua.userType != 'staff') t1")
@EqualsAndHashCode(callSuper = true)
public class OperationRecordVO extends OperationRecord {

    /**
     * 实名姓名
     */
    @TableField()
    private String userName;

    /**
     * 店铺详细
     */
    private String address;

    /**
     * 同IP下累计用户数量
     */
    private Integer count;

    /**
     * 是否为在中国
     */
    @TableField(select = false)
    private String isChina;

}
