package com.sooka.system.domain;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.sooka.common.annotation.Excel;
import com.sooka.common.core.domain.BaseEntity;
import lombok.Getter;
import lombok.Setter;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

/**
 * 接口崩溃日志对象 t_u_interface_crash_log
 */
@Getter
@Setter
public class TUInterfaceCrashLog extends BaseEntity
{
    private static final long serialVersionUID = 1L;

    /** 主键ID */
    private String id;

    /** 状态 */
    @Excel(name = "状态")
    private String status;

    /** 删除时间 */
    private String delFlag;

    /** 登录人 */
    @Excel(name = "登录人")
    private Long loginUser;

    /** 登录名 */
    @Excel(name = "登录名")
    private String loginName;

    /** 调用接口id */
    @Excel(name = "调用接口id")
    private String interfaceinfoId;

    /** 调用接口名 */
    @Excel(name = "调用接口名")
    private String interfaceinfoName;

    /** ip地址 */
    @Excel(name = "ip地址")
    private String ipaddress;

    /** 操作系统 */
    @Excel(name = "操作系统")
    private String os;

    /** 平台接口类型 */
    @Excel(name = "平台接口类型")
    private String platformInterfacetype;

    /** 访问浏览器 */
    @Excel(name = "访问浏览器")
    private String browser;

    /** 参数条件 */
    @Excel(name = "参数条件")
    private String param;

    /** 返回结果 */
    @Excel(name = "返回结果")
    private String results;

    /** 操作数量 */
    @Excel(name = "操作数量")
    private Long operationQuantity;

    /** 操作状态 */
    @Excel(name = "操作状态")
    private Long operationStatus;

    /** 异常记录 */
    @Excel(name = "异常记录")
    private String exceptionLog;

    /** 崩溃类型 */
    @Excel(name = "崩溃类型")
    private String exceptionType;

    /** 造成原因 */
    @Excel(name = "造成原因")
    private String exceptionCause;

    /** 发生位置 */
    @Excel(name = "发生位置")
    private String exceptionExistence;

    public String getExceptionType(){
        if(exceptionLog != null && exceptionLog.contains("_@type")){
            JSONObject jsonObject = JSON.parseObject(exceptionLog);//"_@type": "org.springframework.dao.DuplicateKeyException"
            String type = jsonObject.getString("_@type");//org.springframework.dao.DuplicateKeyException
            String[] exception = type.split("\\.");
            return exception[exception.length - 1];
        }else {
            return null;
        }
    }

    public String getExceptionCause(){
        if(exceptionLog != null && exceptionLog.contains("localizedMessage")){
            if(exceptionLog.contains("DuplicateKeyException")){
                JSONObject jsonObject = JSON.parseObject(exceptionLog);
                String localizedMessage = jsonObject.getString("localizedMessage");//"Error updating database.  Cause: java.sql.SQLIntegrityConstraintViolationException: Duplicate entry '23929' for key 'PRIMARY'\n### The error may exist in class path resource [mapper/Guiji_Gas_Mapper.xml]
                String cause = localizedMessage.split(" Cause: ")[1];//: Duplicate entry '23929' for key 'PRIMARY'\n
                return cause.split(" : ")[0].split("\\n")[0].split(": ")[1];
            }else if(exceptionLog.contains("MyBatisSystemException")){
                JSONObject jsonObject = JSON.parseObject(exceptionLog);
                String localizedMessage = jsonObject.getString("localizedMessage");//"Error updating database.  Cause: java.sql.SQLIntegrityConstraintViolationException: Duplicate entry '23929' for key 'PRIMARY'\n### The error may exist in class path resource [mapper/Guiji_Gas_Mapper.xml]
                return localizedMessage.split(": ")[1].split("in ")[0];//nested exception is org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'SYQZH' in 'class com.sooka.model.bo.Guiji_City_Real_Estate7_mortgage_construction_Bean
            }else {//JSONException
                JSONObject jsonObject = JSON.parseObject(exceptionLog);
                String localizedMessage = jsonObject.getString("localizedMessage");//"Error updating database.  Cause: java.sql.SQLIntegrityConstraintViolationException: Duplicate entry '23929' for key 'PRIMARY'\n### The error may exist in class path resource [mapper/Guiji_Gas_Mapper.xml]
                return localizedMessage.split(": ")[1].split("in ")[0];//nested exception is org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'SYQZH' in 'class com.sooka.model.bo.Guiji_City_Real_Estate7_mortgage_construction_Bean
            }
        }else {
            return null;
        }
    }

    public String getExceptionExistence(){
        if(exceptionLog != null && exceptionLog.contains("localizedMessage")){
            if(exceptionLog.contains("DuplicateKeyException")){
                JSONObject jsonObject = JSON.parseObject(exceptionLog);
                String localizedMessage = jsonObject.getString("localizedMessage");//"Error updating database.  Cause: java.sql.SQLIntegrityConstraintViolationException: Duplicate entry '23929' for key 'PRIMARY'\n### The error may exist in class path resource [mapper/Guiji_Gas_Mapper.xml]
                String cause = localizedMessage.split(" Cause: ")[1];//mapper/Guiji_Gas_Mapper.xml
                return cause.split(" : ")[0].split("\\[")[1].split("\\]")[0];
            }else if(exceptionLog.contains("MyBatisSystemException")){
                JSONObject jsonObject = JSON.parseObject(exceptionLog);
                String localizedMessage = jsonObject.getString("localizedMessage");//"Error updating database.  Cause: java.sql.SQLIntegrityConstraintViolationException: Duplicate entry '23929' for key 'PRIMARY'\n### The error may exist in class path resource [mapper/Guiji_Gas_Mapper.xml]
                String cause =  localizedMessage.split(": ")[1].split("in ")[1];//There is no getter for property named 'SYQZH' in 'class com.sooka.model.bo.Guiji_City_Real_Estate7_mortgage_construction_Bean
                String[] exists = cause.split("\\.");
                String exist = exists[exists.length -1];
                return exist.substring(0, exist.length() - 1);
            }else {//JSONException
                JSONObject jsonObject = JSON.parseObject(exceptionLog);
                String localizedMessage = jsonObject.getString("localizedMessage");//syntax error, pos 1, json : %7B&%22Data%22%3A%2C&%22Key%22%3A%226573fead622f43d7bd5b690dbb8b992a%22%2C&%22iNumber%22%3A%22
                return localizedMessage;
            }
        }else {
            return null;
        }
    }

    public void setId(String id)
    {
        this.id = id;
    }

    public String getId()
    {
        return id;
    }
    public void setStatus(String status)
    {
        this.status = status;
    }

    public String getStatus()
    {
        return status;
    }
    public void setDelFlag(String delFlag)
    {
        this.delFlag = delFlag;
    }

    public String getDelFlag()
    {
        return delFlag;
    }
    public void setLoginUser(Long loginUser)
    {
        this.loginUser = loginUser;
    }

    public Long getLoginUser()
    {
        return loginUser;
    }
    public void setLoginName(String loginName)
    {
        this.loginName = loginName;
    }

    public String getLoginName()
    {
        return loginName;
    }
    public void setInterfaceinfoId(String interfaceinfoId)
    {
        this.interfaceinfoId = interfaceinfoId;
    }

    public String getInterfaceinfoId()
    {
        return interfaceinfoId;
    }
    public void setInterfaceinfoName(String interfaceinfoName)
    {
        this.interfaceinfoName = interfaceinfoName;
    }

    public String getInterfaceinfoName()
    {
        return interfaceinfoName;
    }
    public void setIpaddress(String ipaddress)
    {
        this.ipaddress = ipaddress;
    }

    public String getIpaddress()
    {
        return ipaddress;
    }
    public void setOs(String os)
    {
        this.os = os;
    }

    public String getOs()
    {
        return os;
    }
    public void setPlatformInterfacetype(String platformInterfacetype)
    {
        this.platformInterfacetype = platformInterfacetype;
    }

    public String getPlatformInterfacetype()
    {
        return platformInterfacetype;
    }
    public void setBrowser(String browser)
    {
        this.browser = browser;
    }

    public String getBrowser()
    {
        return browser;
    }
    public void setParam(String params)
    {
        this.param = params;
    }

    public String getParam()
    {
        return param;
    }
    public void setResults(String results)
    {
        this.results = results;
    }

    public String getResults()
    {
        return results;
    }
    public void setOperationQuantity(Long operationQuantity)
    {
        this.operationQuantity = operationQuantity;
    }

    public Long getOperationQuantity()
    {
        return operationQuantity;
    }
    public void setOperationStatus(Long operationStatus)
    {
        this.operationStatus = operationStatus;
    }

    public Long getOperationStatus()
    {
        return operationStatus;
    }
    public void setExceptionLog(String exceptionLog)
    {
        this.exceptionLog = exceptionLog;
    }

    public String getExceptionLog()
    {
        return exceptionLog;
    }

    @Override
    public String toString() {
        return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
            .append("id", getId())
            .append("status", getStatus())
            .append("remark", getRemark())
            .append("delFlag", getDelFlag())
            .append("createBy", getCreateBy())
            .append("createTime", getCreateTime())
            .append("updateBy", getUpdateBy())
            .append("updateTime", getUpdateTime())
            .append("loginUser", getLoginUser())
            .append("loginName", getLoginName())
            .append("interfaceinfoId", getInterfaceinfoId())
            .append("interfaceinfoName", getInterfaceinfoName())
            .append("ipaddress", getIpaddress())
            .append("os", getOs())
            .append("platformInterfacetype", getPlatformInterfacetype())
            .append("browser", getBrowser())
            .append("param", getParam())
            .append("results", getResults())
            .append("operationQuantity", getOperationQuantity())
            .append("operationStatus", getOperationStatus())
            .append("exceptionLog", getExceptionLog())
            .toString();
    }
}
