package com.hzya.frame.sysnew.application.database.entity;

import java.util.Date;
import com.hzya.frame.web.entity.BaseEntity;
/**
 * 数据源表(SysApplicationDatabase)实体类
 *
 * @author makejava
 * @since 2024-06-16 21:49:31
 */
public class SysApplicationDatabaseEntity extends BaseEntity {
 
  /**  应用id */
   private String appId;
  /**  数据源唯一编码 */
   private String sourceCode;
  /**  数据源名称 */
   private String sourceName;
  /**  数据源类型（1、oracle 2、sqlServer3、mysql） */
   private String sourceType;
  /**  ip */
   private String sourceIp;
  /**  端口 */
   private String sourcePort;
  /**  登录名 */
   private String loginName;
  /**  密码 */
   private String password;
  /**  库名 */
   private String dbName;
  /**  选择oracle下服务名称 */
   private String serviceName;
  /**  数据源是否启用（1、开启 2、关闭） */
   private String dbStatus;


    public String getAppId() {
        return appId;
    }

    public void setAppId(String appId) {
        this.appId = appId;
    }

    public String getSourceCode() {
        return sourceCode;
    }

    public void setSourceCode(String sourceCode) {
        this.sourceCode = sourceCode;
    }

    public String getSourceName() {
        return sourceName;
    }

    public void setSourceName(String sourceName) {
        this.sourceName = sourceName;
    }

    public String getSourceType() {
        return sourceType;
    }

    public void setSourceType(String sourceType) {
        this.sourceType = sourceType;
    }

    public String getSourceIp() {
        return sourceIp;
    }

    public void setSourceIp(String sourceIp) {
        this.sourceIp = sourceIp;
    }

    public String getSourcePort() {
        return sourcePort;
    }

    public void setSourcePort(String sourcePort) {
        this.sourcePort = sourcePort;
    }

    public String getLoginName() {
        return loginName;
    }

    public void setLoginName(String loginName) {
        this.loginName = loginName;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getDbName() {
        return dbName;
    }

    public void setDbName(String dbName) {
        this.dbName = dbName;
    }

    public String getServiceName() {
        return serviceName;
    }

    public void setServiceName(String serviceName) {
        this.serviceName = serviceName;
    }

    public String getDbStatus() {
        return dbStatus;
    }

    public void setDbStatus(String dbStatus) {
        this.dbStatus = dbStatus;
    }
    public String getSourceUrl() {
        StringBuffer sourceUrl = new StringBuffer();
        if(sourceType != null){
            switch (sourceType) {
                case "1": //oracle
                    //jdbc:oracle:thin:@60.204.132.91:1521:ORCL
                    sourceUrl.append("jdbc:oracle:thin:@").append(sourceIp).append(":").append(sourcePort).append(":").append(serviceName);
                    break;
                case "2": //sqlsever
                    //jdbc:sqlserver://221.12.175.82:1433;DatabaseName=U8CLOUD;encrypt=false;trustServerCertificate=true
                    //sourceUrl.append("jdbc:jtds:sqlserver://").append(sourceIp).append(":").append(sourcePort).append("/").append(dbName).append(";encrypt=false;trustServerCertificate=true");
                    sourceUrl.append("jdbc:sqlserver://").append(sourceIp).append(":").append(sourcePort).append(";DatabaseName=").append(dbName).append(";encrypt=false;trustServerCertificate=true");
                    break;
                case "3": //mysql
                    //jdbc:mysql://hzya.ufyct.com:9096/businesscenternew?serverTimezone=UTC&useUnicode=true&characterEncoding=UTF8&serverTimezone=GMT%2B8&zeroDateTimeBehavior=convertToNull&useSSL=false&allowLoadLocalInfile=false&autoReconnect=true&failOverReadOnly=false&connectTimeout=30000&socketTimeout=30000&autoReconnectForPools=true
                    sourceUrl.append("jdbc:mysql://").append(sourceIp).append(":").append(sourcePort).append("/").append(dbName).append("?serverTimezone=UTC&useUnicode=true&characterEncoding=UTF8&serverTimezone=GMT%2B8&zeroDateTimeBehavior=convertToNull&useSSL=false&allowLoadLocalInfile=false&autoReconnect=true&failOverReadOnly=false&connectTimeout=30000&socketTimeout=30000&autoReconnectForPools=true");
                    break;
                case "4": //dm
                    //jdbc:dm://hzya.ufyct.com:9040?schema=businesscenter&characterEncoding=UTF-8
                    sourceUrl.append("jdbc:dm://").append(sourceIp).append(":").append(sourcePort).append("?schema=").append(dbName).append("&characterEncoding=UTF-8");
                    break;
                default:
            }
        }
        return sourceUrl.toString();
    }
    public String getSourceTypeName() {
        String  sourceTypeName = null;
        if(sourceType != null){
            switch (sourceType) {
                case "1": //oracle
                    sourceTypeName = "oracle";
                    break;
                case "2": //sqlsever
                    sourceTypeName = "sqlServer";
                    break;
                case "3": //mysql
                    sourceTypeName = "mysql";
                    break;
                case "4": //dm
                    sourceTypeName = "dm";
                    break;
                default:
            }
        }

        return sourceTypeName;
    }
}

