package com.usky.data.model;

import com.usky.data.domain.DataLink;
import lombok.Data;

import javax.validation.constraints.NotBlank;

/**
 * 数据源基础表单
 */
@Data
public class DbLinkBaseForm {
    @NotBlank(message = "连接名称不能为空")
    private String fullName;
    @NotBlank(message = "数据库类型不能为空")
    private String dbType;
    @NotBlank(message = "主机地址不能为空")
    private String host;
    private Integer port;
    @NotBlank(message = "数据库用户名不能为空")
    private String dbName;
    @NotBlank(message = "密码不能为空")
    private String password;
    private String serviceName;
    private String description;
    private String dbSchema;
    private String tableSpace;
    private String oracleParam;
    private Integer oracleExtend;
    private Integer sortCode;

    /**
     * 转换为实体对象
     */
    public DataLink getDbLinkEntity(DbLinkBaseForm form) {
        DataLink dataLink = new DataLink();
        dataLink.setFullName(form.getFullName());
        dataLink.setDbType(form.getDbType());
        dataLink.setHost(form.getHost());
        dataLink.setPort(form.getPort());
        dataLink.setDbName(form.getDbName());
        dataLink.setPassword(form.getPassword());
        dataLink.setServiceName(form.getServiceName());
        dataLink.setDescription(form.getDescription());
        dataLink.setDbSchema(form.getDbSchema());
        dataLink.setTableSpace(form.getTableSpace());
        dataLink.setOracleParam(form.getOracleParam());
        dataLink.setOracleExtend(form.getOracleExtend());
        dataLink.setSortCode(form.getSortCode());
        return dataLink;
    }
}