Commit da86cb93 authored by mcb's avatar mcb

保存数据源

parent f2bd0ff0
......@@ -6,7 +6,9 @@ import com.jz.common.page.BasePageBean;
import com.jz.common.page.PageInfoResponse;
import com.jz.dmp.modules.controller.DataIntegration.bean.DataSourceListDto;
import com.jz.dmp.modules.controller.DataIntegration.bean.DataSourceListReq;
import com.jz.dmp.modules.controller.DataIntegration.bean.DmpSyncingDatasourceReq;
import com.jz.dmp.modules.controller.DataIntegration.bean.DvRuleTDto;
import com.jz.dmp.modules.model.DmpSyncingDatasource;
import com.jz.dmp.modules.service.DmpSyncingDatasourceService;
import com.jz.dmp.modules.service.OfflineSynchService;
import io.swagger.annotations.Api;
......@@ -14,6 +16,7 @@ import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
......@@ -95,4 +98,16 @@ public class DataSourceController {
JsonResult result = dmpSyncingDatasourceService.queryGroupDatasourceType();
return result;
}
/**
* 保存数据源
*
* @return
*/
@ApiOperation(value = "保存数据源", notes = "保存数据源")
@PostMapping(value = "/addDatasourceInfo")
public JsonResult addDatasourceInfo(@RequestBody @Validated DmpSyncingDatasourceReq saveBody, HttpServletRequest httpRequest) throws Exception {
JsonResult result = dmpSyncingDatasourceService.addDatasourceInfo(saveBody);
return result;
}
}
package com.jz.dmp.modules.controller.DataIntegration.bean;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
/**
* 数据源配置(DmpSyncingDatasource)实体类
*
* @author Bellamy
* @since 2020-12-21 17:47:18
*/
@ApiModel(value = "数据源配置", description = "数据源配置")
public class DmpSyncingDatasourceReq implements Serializable {
private static final long serialVersionUID = 588846270711686919L;
/**
* 数据源ID
*/
@ApiModelProperty(value = "数据源ID")
private String id;
/**
* 数据源类型ID
*/
@NotNull(message = "数据源类型ID不能为空")
@NotEmpty(message = "数据源类型ID不能为空")
@ApiModelProperty(value = "数据源类型ID")
private String datasourceType;
/**
* 数据源名称
*/
@NotNull(message = "数据源名称不能为空")
@NotEmpty(message = "数据源名称不能为空")
@ApiModelProperty(value = "数据源名称")
private String datasourceName;
/**
* 数据源描述
*/
@ApiModelProperty(value = "数据源描述")
private String datasourceDesc;
/**
* JDBC URL
*/
@ApiModelProperty(value = "JDBC URL")
private String jdbcUrl;
/**
* 数据库名
*/
@ApiModelProperty(value = "数据库名")
private String dbName;
/**
* 账号
*/
@ApiModelProperty(value = "账号")
private String userName;
/**
* 密码
*/
@ApiModelProperty(value = "密码")
private String password;
/**
* 终端信息
*/
@ApiModelProperty(value = "终端信息")
private String endpoint;
/**
* Bucket信息
*/
@ApiModelProperty(value = "Bucket信息")
private String bucket;
/**
* accessId
*/
@ApiModelProperty(value = "accessId")
private String accessId;
/**
* accessKey
*/
@ApiModelProperty(value = "accessKey")
private String accessKey;
/**
* FTP协议
*/
@ApiModelProperty(value = "FTP协议")
private String protocol;
/**
* IP
*/
@ApiModelProperty(value = "Bucket信息")
private String host;
/**
* 端口
*/
@ApiModelProperty(value = "端口")
private String port;
/**
* NameNode地址
*/
@ApiModelProperty(value = "NameNode地址")
private String defaultFs;
/**
* 表空间
*/
@ApiModelProperty(value = "表空间")
private String tableSchema;
/**
* 数据状态
*/
@ApiModelProperty(value = "数据状态")
private String dataStatus;
/**
* 创建用户ID
*/
@ApiModelProperty(value = "创建用户ID")
private String createUserId;
/**
* 数据创建时间
*/
@ApiModelProperty(value = "数据创建时间")
private String createTime;
/**
* 项目ID
*/
@NotNull(message = "项目ID不能为空")
@NotEmpty(message = "项目ID不能为空")
@ApiModelProperty(value = "项目ID")
private String projectId;
private String delimiter;
private String isHaveHeader;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getDatasourceType() {
return datasourceType;
}
public void setDatasourceType(String datasourceType) {
this.datasourceType = datasourceType;
}
public String getDatasourceName() {
return datasourceName;
}
public void setDatasourceName(String datasourceName) {
this.datasourceName = datasourceName;
}
public String getDatasourceDesc() {
return datasourceDesc;
}
public void setDatasourceDesc(String datasourceDesc) {
this.datasourceDesc = datasourceDesc;
}
public String getJdbcUrl() {
return jdbcUrl;
}
public void setJdbcUrl(String jdbcUrl) {
this.jdbcUrl = jdbcUrl;
}
public String getDbName() {
return dbName;
}
public void setDbName(String dbName) {
this.dbName = dbName;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getEndpoint() {
return endpoint;
}
public void setEndpoint(String endpoint) {
this.endpoint = endpoint;
}
public String getBucket() {
return bucket;
}
public void setBucket(String bucket) {
this.bucket = bucket;
}
public String getAccessId() {
return accessId;
}
public void setAccessId(String accessId) {
this.accessId = accessId;
}
public String getAccessKey() {
return accessKey;
}
public void setAccessKey(String accessKey) {
this.accessKey = accessKey;
}
public String getProtocol() {
return protocol;
}
public void setProtocol(String protocol) {
this.protocol = protocol;
}
public String getHost() {
return host;
}
public void setHost(String host) {
this.host = host;
}
public String getPort() {
return port;
}
public void setPort(String port) {
this.port = port;
}
public String getDefaultFs() {
return defaultFs;
}
public void setDefaultFs(String defaultFs) {
this.defaultFs = defaultFs;
}
public String getTableSchema() {
return tableSchema;
}
public void setTableSchema(String tableSchema) {
this.tableSchema = tableSchema;
}
public String getDataStatus() {
return dataStatus;
}
public void setDataStatus(String dataStatus) {
this.dataStatus = dataStatus;
}
public String getCreateUserId() {
return createUserId;
}
public void setCreateUserId(String createUserId) {
this.createUserId = createUserId;
}
public String getCreateTime() {
return createTime;
}
public void setCreateTime(String createTime) {
this.createTime = createTime;
}
public String getProjectId() {
return projectId;
}
public void setProjectId(String projectId) {
this.projectId = projectId;
}
public String getDelimiter() {
return delimiter;
}
public void setDelimiter(String delimiter) {
this.delimiter = delimiter;
}
public String getIsHaveHeader() {
return isHaveHeader;
}
public void setIsHaveHeader(String isHaveHeader) {
this.isHaveHeader = isHaveHeader;
}
}
\ No newline at end of file
......@@ -2,6 +2,7 @@ package com.jz.dmp.modules.dao;
import com.jz.dmp.modules.controller.DataIntegration.bean.DataSourceListDto;
import com.jz.dmp.modules.controller.DataIntegration.bean.DataSourceListReq;
import com.jz.dmp.modules.controller.DataIntegration.bean.DmpSyncingDatasourceReq;
import com.jz.dmp.modules.model.DmpSyncingDatasource;
import org.apache.ibatis.annotations.Param;
......@@ -94,4 +95,7 @@ public interface DmpSyncingDatasourceDao {
List<Map> queryDatasourceType() throws Exception;
List<Map> queryGroupDatasourceType() throws Exception;
int countDatasourceByName(@Param("datasourceName") String datasourceName, @Param("projectId") String projectId);
}
\ No newline at end of file
package com.jz.dmp.modules.model;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.io.Serializable;
import java.util.Date;
......@@ -9,99 +12,123 @@ import java.util.Date;
* @author Bellamy
* @since 2020-12-21 17:47:18
*/
@ApiModel(value = "数据源配置", description = "数据源配置")
public class DmpSyncingDatasource implements Serializable {
private static final long serialVersionUID = 588846270711686919L;
/**
* ID
*/
@ApiModelProperty(value = "ID")
private Integer id;
/**
* 数据源类型ID
*/
@ApiModelProperty(value = "数据源类型ID")
private Integer datasourceType;
/**
* 数据源名称
*/
@ApiModelProperty(value = "数据源名称")
private String datasourceName;
/**
* 数据源描述
*/
@ApiModelProperty(value = "数据源描述")
private String datasourceDesc;
/**
* JDBC URL
*/
@ApiModelProperty(value = "JDBC URL")
private String jdbcUrl;
/**
* 数据库名
*/
@ApiModelProperty(value = "数据库名")
private String dbName;
/**
* 账号
*/
@ApiModelProperty(value = "账号")
private String userName;
/**
* 密码
*/
@ApiModelProperty(value = "密码")
private String password;
/**
* 终端信息
*/
@ApiModelProperty(value = "终端信息")
private String endpoint;
/**
* Bucket信息
*/
@ApiModelProperty(value = "Bucket信息")
private String bucket;
/**
* accessId
*/
@ApiModelProperty(value = "accessId")
private String accessId;
/**
* accessKey
*/
@ApiModelProperty(value = "accessKey")
private String accessKey;
/**
* FTP协议
*/
@ApiModelProperty(value = "FTP协议")
private String protocol;
/**
* IP
*/
@ApiModelProperty(value = "Bucket信息")
private String host;
/**
* 端口
*/
@ApiModelProperty(value = "端口")
private String port;
/**
* NameNode地址
*/
@ApiModelProperty(value = "NameNode地址")
private String defaultFs;
/**
* 表空间
*/
@ApiModelProperty(value = "表空间")
private String tableSchema;
/**
* 数据状态
*/
@ApiModelProperty(value = "数据状态")
private String dataStatus;
/**
* 创建用户ID
*/
@ApiModelProperty(value = "创建用户ID")
private String createUserId;
/**
* 数据创建时间
*/
@ApiModelProperty(value = "数据创建时间")
private Date createTime;
/**
* 创建用户ID
*/
@ApiModelProperty(value = "创建用户ID")
private String updateUserId;
/**
* 数据更新时间
*/
@ApiModelProperty(value = "数据更新时间")
private Date updateTime;
/**
* 项目ID
*/
@ApiModelProperty(value = "项目ID")
private Integer projectId;
private String delimiter;
......
......@@ -5,6 +5,7 @@ import com.jz.common.constant.JsonResult;
import com.jz.common.page.PageInfoResponse;
import com.jz.dmp.modules.controller.DataIntegration.bean.DataSourceListDto;
import com.jz.dmp.modules.controller.DataIntegration.bean.DataSourceListReq;
import com.jz.dmp.modules.controller.DataIntegration.bean.DmpSyncingDatasourceReq;
import com.jz.dmp.modules.model.DmpSyncingDatasource;
import javax.servlet.http.HttpServletRequest;
......@@ -66,4 +67,6 @@ public interface DmpSyncingDatasourceService {
JsonResult queryDatasourceType() throws Exception;
JsonResult queryGroupDatasourceType() throws Exception;
JsonResult addDatasourceInfo(DmpSyncingDatasourceReq saveBody) throws Exception;
}
\ No newline at end of file
......@@ -9,22 +9,21 @@ import com.jz.common.constant.ResultCode;
import com.jz.common.page.PageInfoResponse;
import com.jz.dmp.modules.controller.DataIntegration.bean.DataSourceListDto;
import com.jz.dmp.modules.controller.DataIntegration.bean.DataSourceListReq;
import com.jz.dmp.modules.controller.DataIntegration.bean.DmpSyncingDatasourceReq;
import com.jz.dmp.modules.dao.DmpSyncingDatasourceDao;
import com.jz.dmp.modules.model.DmpSyncingDatasource;
import com.jz.dmp.modules.service.DmpSyncingDatasourceService;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
/**
* 数据源配置(DmpSyncingDatasource)表服务实现类
......@@ -163,4 +162,31 @@ public class DmpSyncingDatasourceServiceImpl implements DmpSyncingDatasourceServ
}
return new JsonResult(returnMap);
}
/**
* 保存数据源
*
* @return
*/
@Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRES_NEW)
@Override
public JsonResult addDatasourceInfo(DmpSyncingDatasourceReq saveBody) throws Exception {
if (StringUtils.isEmpty(saveBody.getDatasourceName())) {
return new JsonResult(ResultCode.PARAMS_ERROR, "数据源名称不能为空");
}
//通过名称查询数据源是否存在
int len = dmpSyncingDatasourceDao.countDatasourceByName(saveBody.getDatasourceName(), saveBody.getProjectId());
if (len > 0) {
return new JsonResult(ResultCode.PARAMS_ERROR, "数据源名称已存在");
}
DmpSyncingDatasource dsd = new DmpSyncingDatasource();
BeanUtils.copyProperties(saveBody, dsd);
dsd.setCreateTime(new Date());
dsd.setDatasourceType(Integer.valueOf(saveBody.getDatasourceType()));
dsd.setProjectId(Integer.valueOf(saveBody.getProjectId()));
dsd.setDataStatus("1");
dmpSyncingDatasourceDao.insert(dsd);
return new JsonResult(dsd);
}
}
\ No newline at end of file
......@@ -303,4 +303,14 @@
order by datasource_catetype
</select>
<!--通过名称查询数据源是否存在-->
<select id="countDatasourceByName" parameterType="map" resultType="java.lang.Integer">
select
count(1)
from dmp_syncing_datasource ds
where ds.data_status = '1'
and ds.datasource_name = #{datasourceName}
and ds.project_id = #{projectId}
</select>
</mapper>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment