data
parent
41de9a96c1
commit
4fefe37cfe
@ -0,0 +1,58 @@
|
||||
|
||||
package com.anjiplus.template.gaea.business.modules.data.dataSet.controller.dto;
|
||||
|
||||
import com.anji.plus.gaea.curd.dto.GaeaBaseDTO;
|
||||
import com.anjiplus.template.gaea.business.modules.data.dataSetParam.controller.dto.DataSetParamDto;
|
||||
import com.anjiplus.template.gaea.business.modules.data.dataSetTransform.controller.dto.DataSetTransformDto;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @description 数据集 dto
|
||||
* @author Raod
|
||||
* @date 2021-03-18 12:11:31.150755900
|
||||
**/
|
||||
@Data
|
||||
public class DataSetDto extends GaeaBaseDTO implements Serializable {
|
||||
/** 数据集编码 */
|
||||
private String setCode;
|
||||
|
||||
/** 数据集名称 */
|
||||
private String setName;
|
||||
|
||||
/** 数据集描述 */
|
||||
private String setDesc;
|
||||
|
||||
/** 数据源编码 */
|
||||
private String sourceCode;
|
||||
|
||||
/** 动态查询sql或者接口中的请求体 */
|
||||
private String dynSentence;
|
||||
|
||||
/** 结果案例 */
|
||||
private String caseResult;
|
||||
|
||||
/** 0--已禁用 1--已启用 DIC_NAME=ENABLE_FLAG */
|
||||
private Integer enableFlag;
|
||||
|
||||
/** 0--未删除 1--已删除 DIC_NAME=DELETE_FLAG */
|
||||
private Integer deleteFlag;
|
||||
|
||||
/** 请求参数集合 */
|
||||
private List<DataSetParamDto> dataSetParamDtoList;
|
||||
|
||||
/** 数据转换集合 */
|
||||
private List<DataSetTransformDto> dataSetTransformDtoList;
|
||||
|
||||
/** 传入的自定义参数*/
|
||||
private Map<String, Object> contextData;
|
||||
|
||||
private Set<String> setParamList;
|
||||
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
package com.anjiplus.template.gaea.business.modules.data.dataSet.controller.dto;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by raodeming on 2021/3/26.
|
||||
*/
|
||||
@Data
|
||||
public class OriginalDataDto implements Serializable {
|
||||
|
||||
/**总数*/
|
||||
private long total;
|
||||
|
||||
/**获取的数据详情*/
|
||||
private List<JSONObject> data;
|
||||
|
||||
public OriginalDataDto(List<JSONObject> data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public OriginalDataDto(long total, List<JSONObject> data) {
|
||||
this.total = total;
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public OriginalDataDto() {
|
||||
}
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
/**/
|
||||
package com.anjiplus.template.gaea.business.modules.data.dataSet.controller.param;
|
||||
|
||||
import com.anji.plus.gaea.annotation.Query;
|
||||
import com.anji.plus.gaea.constant.QueryEnum;
|
||||
import com.anji.plus.gaea.curd.params.PageParam;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
|
||||
/**
|
||||
* @desc DataSet 数据集查询输入类
|
||||
* @author Raod
|
||||
* @date 2021-03-18 12:11:31.150755900
|
||||
**/
|
||||
@Data
|
||||
public class DataSetParam extends PageParam implements Serializable{
|
||||
/** 数据集编码 */
|
||||
@Query(QueryEnum.LIKE)
|
||||
private String setCode;
|
||||
|
||||
/** 数据集名称 */
|
||||
@Query(QueryEnum.LIKE)
|
||||
private String setName;
|
||||
|
||||
/** 数据源编码 */
|
||||
@Query(QueryEnum.EQ)
|
||||
private String sourceCode;
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
/**/
|
||||
package com.anjiplus.template.gaea.business.modules.data.dataSet.controller.param;
|
||||
|
||||
import com.anjiplus.template.gaea.business.modules.data.dataSetParam.controller.dto.DataSetParamDto;
|
||||
import com.anjiplus.template.gaea.business.modules.data.dataSetTransform.controller.dto.DataSetTransformDto;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* @desc DataSet 数据集查询输入类
|
||||
* @author Raod
|
||||
* @date 2021-03-18 12:11:31.150755900
|
||||
**/
|
||||
@Data
|
||||
public class DataSetTestTransformParam implements Serializable{
|
||||
|
||||
/** 数据源编码 */
|
||||
@NotBlank(message = "sourceCode not empty")
|
||||
private String sourceCode;
|
||||
|
||||
/** 动态查询sql或者接口中的请求体 */
|
||||
private String dynSentence;
|
||||
|
||||
/** 请求参数集合 */
|
||||
private List<DataSetParamDto> dataSetParamDtoList;
|
||||
|
||||
/** 数据转换集合 */
|
||||
private List<DataSetTransformDto> dataSetTransformDtoList;
|
||||
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
package com.anjiplus.template.gaea.business.modules.data.dataSet.dao;
|
||||
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import com.anji.plus.gaea.curd.mapper.GaeaBaseMapper;
|
||||
import com.anjiplus.template.gaea.business.modules.data.dataSet.dao.entity.DataSet;
|
||||
|
||||
/**
|
||||
* DataSet Mapper
|
||||
* @author Raod
|
||||
* @date 2021-03-18 12:11:31.150755900
|
||||
**/
|
||||
@Mapper
|
||||
public interface DataSetMapper extends GaeaBaseMapper<DataSet> {
|
||||
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
|
||||
package com.anjiplus.template.gaea.business.modules.data.dataSet.dao.entity;
|
||||
|
||||
import com.anji.plus.gaea.annotation.Unique;
|
||||
import com.anji.plus.gaea.curd.entity.GaeaBaseEntity;
|
||||
import com.anjiplus.template.gaea.common.RespCommonCode;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @description 数据集 entity
|
||||
* @author Raod
|
||||
* @date 2021-03-18 12:11:31.150755900
|
||||
**/
|
||||
@TableName(value="gaea_report_data_set")
|
||||
@Data
|
||||
public class DataSet extends GaeaBaseEntity {
|
||||
@ApiModelProperty(value = "数据集编码")
|
||||
@Unique(code = RespCommonCode.SET_CODE_ISEXIST)
|
||||
private String setCode;
|
||||
|
||||
@ApiModelProperty(value = "数据集名称")
|
||||
private String setName;
|
||||
|
||||
@ApiModelProperty(value = "数据集描述")
|
||||
private String setDesc;
|
||||
|
||||
@ApiModelProperty(value = "数据源编码")
|
||||
private String sourceCode;
|
||||
|
||||
@ApiModelProperty(value = "动态查询sql或者接口中的请求体")
|
||||
private String dynSentence;
|
||||
|
||||
@ApiModelProperty(value = "结果案例")
|
||||
private String caseResult;
|
||||
|
||||
@ApiModelProperty(value = "0--已禁用 1--已启用 DIC_NAME=ENABLE_FLAG")
|
||||
private Integer enableFlag;
|
||||
|
||||
@ApiModelProperty(value = "0--未删除 1--已删除 DIC_NAME=DELETE_FLAG")
|
||||
private Integer deleteFlag;
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,70 @@
|
||||
|
||||
package com.anjiplus.template.gaea.business.modules.data.dataSet.service;
|
||||
|
||||
import com.anji.plus.gaea.curd.service.GaeaBaseService;
|
||||
import com.anjiplus.template.gaea.business.modules.data.dataSet.controller.dto.DataSetDto;
|
||||
import com.anjiplus.template.gaea.business.modules.data.dataSet.controller.dto.OriginalDataDto;
|
||||
import com.anjiplus.template.gaea.business.modules.data.dataSet.controller.param.DataSetParam;
|
||||
import com.anjiplus.template.gaea.business.modules.data.dataSet.dao.entity.DataSet;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @desc DataSet 数据集服务接口
|
||||
* @author Raod
|
||||
* @date 2021-03-18 12:11:31.150755900
|
||||
**/
|
||||
public interface DataSetService extends GaeaBaseService<DataSetParam, DataSet> {
|
||||
|
||||
/**
|
||||
* 单条详情
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
DataSetDto detailSet(Long id);
|
||||
|
||||
/**
|
||||
* 单条详情
|
||||
* @param setCode
|
||||
* @return
|
||||
*/
|
||||
DataSetDto detailSet(String setCode);
|
||||
|
||||
/**
|
||||
* 新增数据集、添加查询参数、数据转换
|
||||
* @param dto
|
||||
*/
|
||||
DataSetDto insertSet(DataSetDto dto);
|
||||
|
||||
/**
|
||||
* 更新数据集、添加查询参数、数据转换
|
||||
* @param dto
|
||||
*/
|
||||
void updateSet(DataSetDto dto);
|
||||
|
||||
/**
|
||||
* 删除数据集、添加查询参数、数据转换
|
||||
* @param id
|
||||
*/
|
||||
void deleteSet(Long id);
|
||||
|
||||
/**
|
||||
* 获取数据
|
||||
* @param dto
|
||||
* @return
|
||||
*/
|
||||
OriginalDataDto getData(DataSetDto dto);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param dto
|
||||
* @return
|
||||
*/
|
||||
OriginalDataDto testTransform(DataSetDto dto);
|
||||
|
||||
/**
|
||||
* 获取所有数据集
|
||||
* @return
|
||||
*/
|
||||
List<DataSet> queryAllDataSet();
|
||||
}
|
@ -0,0 +1,343 @@
|
||||
|
||||
package com.anjiplus.template.gaea.business.modules.data.dataSet.service.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.anji.plus.gaea.constant.Enabled;
|
||||
import com.anji.plus.gaea.curd.mapper.GaeaBaseMapper;
|
||||
import com.anji.plus.gaea.exception.BusinessExceptionBuilder;
|
||||
import com.anji.plus.gaea.utils.GaeaBeanUtils;
|
||||
import com.anjiplus.template.gaea.business.code.ResponseCode;
|
||||
import com.anjiplus.template.gaea.business.modules.data.dataSet.controller.dto.OriginalDataDto;
|
||||
import com.anjiplus.template.gaea.business.modules.data.dataSet.controller.dto.DataSetDto;
|
||||
import com.anjiplus.template.gaea.business.modules.data.dataSet.dao.DataSetMapper;
|
||||
import com.anjiplus.template.gaea.business.modules.data.dataSet.dao.entity.DataSet;
|
||||
import com.anjiplus.template.gaea.business.modules.data.dataSet.service.DataSetService;
|
||||
import com.anjiplus.template.gaea.business.modules.data.dataSetParam.controller.dto.DataSetParamDto;
|
||||
import com.anjiplus.template.gaea.business.modules.data.dataSetParam.dao.entity.DataSetParam;
|
||||
import com.anjiplus.template.gaea.business.modules.data.dataSetParam.service.DataSetParamService;
|
||||
import com.anjiplus.template.gaea.business.modules.data.dataSetTransform.controller.dto.DataSetTransformDto;
|
||||
import com.anjiplus.template.gaea.business.modules.data.dataSetTransform.dao.entity.DataSetTransform;
|
||||
import com.anjiplus.template.gaea.business.modules.data.dataSetTransform.service.DataSetTransformService;
|
||||
import com.anjiplus.template.gaea.business.modules.data.dataSource.controller.dto.DataSourceDto;
|
||||
import com.anjiplus.template.gaea.business.modules.data.dataSource.dao.entity.DataSource;
|
||||
import com.anjiplus.template.gaea.business.modules.data.dataSource.service.DataSourceService;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @desc DataSet 数据集服务实现
|
||||
* @author Raod
|
||||
* @date 2021-03-18 12:11:31.150755900
|
||||
**/
|
||||
@Service
|
||||
//@RequiredArgsConstructor
|
||||
public class DataSetServiceImpl implements DataSetService {
|
||||
|
||||
@Autowired
|
||||
private DataSetMapper dataSetMapper;
|
||||
|
||||
@Autowired
|
||||
private DataSetParamService dataSetParamService;
|
||||
|
||||
@Autowired
|
||||
private DataSetTransformService dataSetTransformService;
|
||||
|
||||
@Autowired
|
||||
private DataSourceService dataSourceService;
|
||||
|
||||
@Override
|
||||
public GaeaBaseMapper<DataSet> getMapper() {
|
||||
return dataSetMapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* 单条详情
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public DataSetDto detailSet(Long id) {
|
||||
DataSetDto dto = new DataSetDto();
|
||||
DataSet result = selectOne(id);
|
||||
String setCode = result.getSetCode();
|
||||
GaeaBeanUtils.copyAndFormatter(result, dto);
|
||||
return getDetailSet(dto, setCode);
|
||||
}
|
||||
|
||||
/**
|
||||
* 单条详情
|
||||
*
|
||||
* @param setCode
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public DataSetDto detailSet(String setCode) {
|
||||
DataSetDto dto = new DataSetDto();
|
||||
DataSet result = selectOne("set_code", setCode);
|
||||
GaeaBeanUtils.copyAndFormatter(result, dto);
|
||||
return getDetailSet(dto, setCode);
|
||||
}
|
||||
|
||||
public DataSetDto getDetailSet(DataSetDto dto, String setCode) {
|
||||
//查询参数
|
||||
List<DataSetParam> dataSetParamList = dataSetParamService.list(
|
||||
new QueryWrapper<DataSetParam>()
|
||||
.lambda()
|
||||
.eq(DataSetParam::getSetCode, setCode)
|
||||
);
|
||||
List<DataSetParamDto> dataSetParamDtoList = new ArrayList<>();
|
||||
dataSetParamList.forEach(dataSetParam -> {
|
||||
DataSetParamDto dataSetParamDto = new DataSetParamDto();
|
||||
GaeaBeanUtils.copyAndFormatter(dataSetParam, dataSetParamDto);
|
||||
dataSetParamDtoList.add(dataSetParamDto);
|
||||
});
|
||||
dto.setDataSetParamDtoList(dataSetParamDtoList);
|
||||
|
||||
//数据转换
|
||||
|
||||
List<DataSetTransform> dataSetTransformList = dataSetTransformService.list(
|
||||
new QueryWrapper<DataSetTransform>()
|
||||
.lambda()
|
||||
.eq(DataSetTransform::getSetCode, setCode)
|
||||
.orderByAsc(DataSetTransform::getOrderNum)
|
||||
);
|
||||
List<DataSetTransformDto> dataSetTransformDtoList = new ArrayList<>();
|
||||
dataSetTransformList.forEach(dataSetTransform -> {
|
||||
DataSetTransformDto dataSetTransformDto = new DataSetTransformDto();
|
||||
GaeaBeanUtils.copyAndFormatter(dataSetTransform, dataSetTransformDto);
|
||||
dataSetTransformDtoList.add(dataSetTransformDto);
|
||||
});
|
||||
dto.setDataSetTransformDtoList(dataSetTransformDtoList);
|
||||
|
||||
if (StringUtils.isNotBlank(dto.getCaseResult())) {
|
||||
try {
|
||||
JSONArray jsonArray = JSONArray.parseArray(dto.getCaseResult());
|
||||
JSONObject jsonObject = jsonArray.getJSONObject(0);
|
||||
dto.setSetParamList(jsonObject.keySet());
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
return dto;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 新增数据集、添加查询参数、数据转换
|
||||
*
|
||||
* @param dto
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public DataSetDto insertSet(DataSetDto dto) {
|
||||
List<DataSetParamDto> dataSetParamDtoList = dto.getDataSetParamDtoList();
|
||||
List<DataSetTransformDto> dataSetTransformDtoList = dto.getDataSetTransformDtoList();
|
||||
|
||||
//1.新增数据集
|
||||
DataSet dataSet = new DataSet();
|
||||
BeanUtils.copyProperties(dto, dataSet);
|
||||
insert(dataSet);
|
||||
//2.更新查询参数
|
||||
dataSetParamBatch(dataSetParamDtoList, dto.getSetCode());
|
||||
|
||||
//3.更新数据转换
|
||||
dataSetTransformBatch(dataSetTransformDtoList, dto.getSetCode());
|
||||
return dto;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新数据集、添加查询参数、数据转换
|
||||
*
|
||||
* @param dto
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public void updateSet(DataSetDto dto) {
|
||||
List<DataSetParamDto> dataSetParamDtoList = dto.getDataSetParamDtoList();
|
||||
List<DataSetTransformDto> dataSetTransformDtoList = dto.getDataSetTransformDtoList();
|
||||
//1.更新数据集
|
||||
DataSet dataSet = new DataSet();
|
||||
BeanUtils.copyProperties(dto, dataSet);
|
||||
update(dataSet);
|
||||
|
||||
//2.更新查询参数
|
||||
dataSetParamBatch(dataSetParamDtoList, dto.getSetCode());
|
||||
|
||||
//3.更新数据转换
|
||||
dataSetTransformBatch(dataSetTransformDtoList, dto.getSetCode());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 删除数据集、添加查询参数、数据转换
|
||||
*
|
||||
* @param id
|
||||
*/
|
||||
@Override
|
||||
public void deleteSet(Long id) {
|
||||
DataSet dataSet = selectOne(id);
|
||||
String setCode = dataSet.getSetCode();
|
||||
//1.删除数据集
|
||||
deleteById(id);
|
||||
|
||||
//2.删除查询参数
|
||||
dataSetParamService.delete(
|
||||
new QueryWrapper<DataSetParam>()
|
||||
.lambda()
|
||||
.eq(DataSetParam::getSetCode, setCode)
|
||||
);
|
||||
|
||||
//3.删除数据转换
|
||||
dataSetTransformService.delete(
|
||||
new QueryWrapper<DataSetTransform>()
|
||||
.lambda()
|
||||
.eq(DataSetTransform::getSetCode, setCode)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取数据
|
||||
*
|
||||
* @param dto
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public OriginalDataDto getData(DataSetDto dto) {
|
||||
OriginalDataDto originalDataDto = new OriginalDataDto();
|
||||
String setCode = dto.getSetCode();
|
||||
//1.获取数据集、参数替换、数据转换
|
||||
DataSetDto dataSetDto = detailSet(setCode);
|
||||
//2.获取数据源
|
||||
DataSource dataSource = dataSourceService.selectOne("source_code", dataSetDto.getSourceCode());
|
||||
//3.参数替换
|
||||
//3.1参数校验
|
||||
boolean verification = dataSetParamService.verification(dataSetDto.getDataSetParamDtoList(), dto.getContextData());
|
||||
if (!verification) {
|
||||
throw BusinessExceptionBuilder.build(ResponseCode.RULE_FIELDS_CHECK_ERROR);
|
||||
}
|
||||
String dynSentence = dataSetParamService.transform(dto.getContextData(), dataSetDto.getDynSentence());
|
||||
//4.获取数据
|
||||
DataSourceDto dataSourceDto = new DataSourceDto();
|
||||
BeanUtils.copyProperties(dataSource, dataSourceDto);
|
||||
dataSourceDto.setDynSentence(dynSentence);
|
||||
dataSourceDto.setContextData(dto.getContextData());
|
||||
//获取total,判断contextData中是否传入分页参数
|
||||
if (null != dto.getContextData()
|
||||
&& dto.getContextData().containsKey("pageNumber")
|
||||
&& dto.getContextData().containsKey("pageSize")) {
|
||||
long total = dataSourceService.total(dataSourceDto, dto);
|
||||
originalDataDto.setTotal(total);
|
||||
}
|
||||
List<JSONObject> data = dataSourceService.execute(dataSourceDto);
|
||||
//5.数据转换
|
||||
List<JSONObject> transform = dataSetTransformService.transform(dataSetDto.getDataSetTransformDtoList(), data);
|
||||
originalDataDto.setData(transform);
|
||||
return originalDataDto;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param dto
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public OriginalDataDto testTransform(DataSetDto dto) {
|
||||
OriginalDataDto originalDataDto = new OriginalDataDto();
|
||||
String sourceCode = dto.getSourceCode();
|
||||
//1.获取数据源
|
||||
DataSource dataSource = dataSourceService.selectOne("source_code", sourceCode);
|
||||
//3.参数替换
|
||||
//3.1参数校验
|
||||
boolean verification = dataSetParamService.verification(dto.getDataSetParamDtoList(), null);
|
||||
if (!verification) {
|
||||
throw BusinessExceptionBuilder.build(ResponseCode.RULE_FIELDS_CHECK_ERROR);
|
||||
}
|
||||
|
||||
String dynSentence = dataSetParamService.transform(dto.getDataSetParamDtoList(), dto.getDynSentence());
|
||||
//4.获取数据
|
||||
DataSourceDto dataSourceDto = new DataSourceDto();
|
||||
BeanUtils.copyProperties(dataSource, dataSourceDto);
|
||||
dataSourceDto.setDynSentence(dynSentence);
|
||||
dataSourceDto.setContextData(dto.getContextData());
|
||||
|
||||
//获取total,判断DataSetParamDtoList中是否传入分页参数
|
||||
Map<String, Object> collect = dto.getDataSetParamDtoList().stream().collect(Collectors.toMap(DataSetParamDto::getParamName, DataSetParamDto::getSampleItem));
|
||||
if (collect.containsKey("pageNumber") && collect.containsKey("pageSize")) {
|
||||
dto.setContextData(collect);
|
||||
long total = dataSourceService.total(dataSourceDto, dto);
|
||||
originalDataDto.setTotal(total);
|
||||
}
|
||||
|
||||
List<JSONObject> data = dataSourceService.execute(dataSourceDto);
|
||||
//5.数据转换
|
||||
List<JSONObject> transform = dataSetTransformService.transform(dto.getDataSetTransformDtoList(), data);
|
||||
originalDataDto.setData(transform);
|
||||
return originalDataDto;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取所有数据集
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<DataSet> queryAllDataSet() {
|
||||
LambdaQueryWrapper<DataSet> wrapper = Wrappers.lambdaQuery();
|
||||
wrapper.select(DataSet::getSetCode, DataSet::getSetName, DataSet::getSetDesc, DataSet::getId)
|
||||
.eq(DataSet::getEnableFlag, Enabled.YES.getValue());
|
||||
return dataSetMapper.selectList(wrapper);
|
||||
}
|
||||
|
||||
public void dataSetParamBatch(List<DataSetParamDto> dataSetParamDtoList,String setCode){
|
||||
dataSetParamService.delete(
|
||||
new QueryWrapper<DataSetParam>()
|
||||
.lambda()
|
||||
.eq(DataSetParam::getSetCode, setCode)
|
||||
);
|
||||
if (null == dataSetParamDtoList || dataSetParamDtoList.size() <= 0) {
|
||||
return;
|
||||
}
|
||||
List<DataSetParam> dataSetParamList = new ArrayList<>();
|
||||
dataSetParamDtoList.forEach(dataSetParamDto -> {
|
||||
DataSetParam dataSetParam = new DataSetParam();
|
||||
BeanUtils.copyProperties(dataSetParamDto, dataSetParam);
|
||||
dataSetParam.setSetCode(setCode);
|
||||
dataSetParamList.add(dataSetParam);
|
||||
});
|
||||
dataSetParamService.insertBatch(dataSetParamList);
|
||||
|
||||
}
|
||||
|
||||
public void dataSetTransformBatch(List<DataSetTransformDto> dataSetTransformDtoList,String setCode){
|
||||
dataSetTransformService.delete(
|
||||
new QueryWrapper<DataSetTransform>()
|
||||
.lambda()
|
||||
.eq(DataSetTransform::getSetCode, setCode)
|
||||
);
|
||||
if (null == dataSetTransformDtoList || dataSetTransformDtoList.size() <= 0) {
|
||||
return;
|
||||
}
|
||||
List<DataSetTransform> dataSetTransformList = new ArrayList<>();
|
||||
for (int i = 0; i < dataSetTransformDtoList.size(); i++) {
|
||||
DataSetTransform dataSetTransform = new DataSetTransform();
|
||||
BeanUtils.copyProperties(dataSetTransformDtoList.get(i), dataSetTransform);
|
||||
dataSetTransform.setOrderNum(i + 1);
|
||||
dataSetTransform.setSetCode(setCode);
|
||||
dataSetTransformList.add(dataSetTransform);
|
||||
}
|
||||
dataSetTransformService.insertBatch(dataSetTransformList);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,67 @@
|
||||
|
||||
package com.anjiplus.template.gaea.business.modules.data.dataSource.controller;
|
||||
|
||||
import com.anji.plus.gaea.bean.ResponseBean;
|
||||
import com.anji.plus.gaea.curd.controller.GaeaBaseController;
|
||||
import com.anji.plus.gaea.curd.service.GaeaBaseService;
|
||||
import com.anjiplus.template.gaea.business.modules.data.dataSource.controller.dto.DataSourceDto;
|
||||
import com.anjiplus.template.gaea.business.modules.data.dataSource.controller.param.ConnectionParam;
|
||||
import com.anjiplus.template.gaea.business.modules.data.dataSource.controller.param.DataSourceParam;
|
||||
import com.anjiplus.template.gaea.business.modules.data.dataSource.dao.entity.DataSource;
|
||||
import com.anjiplus.template.gaea.business.modules.data.dataSource.service.DataSourceService;
|
||||
import io.swagger.annotations.Api;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
/**
|
||||
* @desc 数据源 controller
|
||||
* @website https://gitee.com/anji-plus/gaea
|
||||
* @author Raod
|
||||
* @date 2021-03-18 12:09:57.728203200
|
||||
**/
|
||||
@RestController
|
||||
@Api(tags = "数据源管理")
|
||||
@RequestMapping("/dataSource")
|
||||
public class DataSourceController extends GaeaBaseController<DataSourceParam, DataSource, DataSourceDto> {
|
||||
|
||||
@Autowired
|
||||
private DataSourceService dataSourceService;
|
||||
|
||||
@Override
|
||||
public GaeaBaseService<DataSourceParam, DataSource> getService() {
|
||||
return dataSourceService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataSource getEntity() {
|
||||
return new DataSource();
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataSourceDto getDTO() {
|
||||
return new DataSourceDto();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有数据源
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/queryAllDataSource")
|
||||
public ResponseBean queryAllDataSource() {
|
||||
return responseSuccessWithData(dataSourceService.queryAllDataSource());
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试 连接
|
||||
* @param connectionParam
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/testConnection")
|
||||
public ResponseBean testConnection(@Validated @RequestBody ConnectionParam connectionParam) {
|
||||
return responseSuccessWithData(dataSourceService.testConnection(connectionParam));
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
package com.anjiplus.template.gaea.business.modules.data.dataSource.dao;
|
||||
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import com.anji.plus.gaea.curd.mapper.GaeaBaseMapper;
|
||||
import com.anjiplus.template.gaea.business.modules.data.dataSource.dao.entity.DataSource;
|
||||
|
||||
/**
|
||||
* DataSource Mapper
|
||||
* @author Raod
|
||||
* @date 2021-03-18 12:09:57.728203200
|
||||
**/
|
||||
@Mapper
|
||||
public interface DataSourceMapper extends GaeaBaseMapper<DataSource> {
|
||||
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
package com.anjiplus.template.gaea.business.modules.data.dataSource.pool.api;
|
||||
|
||||
/**
|
||||
* 配置接口
|
||||
* @author binbin.hou
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public interface IConfig {
|
||||
|
||||
/**
|
||||
* 设置驱动类
|
||||
*
|
||||
* @param driverClass 驱动类
|
||||
* @since 1.0.0
|
||||
*/
|
||||
void setDriverClass(final String driverClass);
|
||||
|
||||
/**
|
||||
* jdbc url
|
||||
* @param jdbcUrl url
|
||||
* @since 1.0.0
|
||||
*/
|
||||
void setJdbcUrl(final String jdbcUrl);
|
||||
|
||||
/**
|
||||
* 设置用户信息
|
||||
* @param user 用户信息
|
||||
* @since 1.0.0
|
||||
*/
|
||||
void setUser(final String user);
|
||||
|
||||
/**
|
||||
* 设置密码
|
||||
* @param password 密码
|
||||
* @since 1.0.0
|
||||
*/
|
||||
void setPassword(final String password);
|
||||
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package com.anjiplus.template.gaea.business.modules.data.dataSource.pool.api;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
/**
|
||||
* 配置接口
|
||||
* @author binbin.hou
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public interface IDataSourceConfig extends IConfig, DataSource {
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
package com.anjiplus.template.gaea.business.modules.data.dataSource.pool.api;
|
||||
|
||||
/**
|
||||
* 生命周期管理
|
||||
* @since 1.1.0
|
||||
*/
|
||||
public interface ILifeCycle {
|
||||
|
||||
/**
|
||||
* 生命的初始化
|
||||
* @since 1.1.0
|
||||
*/
|
||||
void init();
|
||||
|
||||
/**
|
||||
* 生命的销毁
|
||||
* @since 1.1.0
|
||||
*/
|
||||
void destroy();
|
||||
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
package com.anjiplus.template.gaea.business.modules.data.dataSource.pool.connection;
|
||||
|
||||
import com.anjiplus.template.gaea.business.modules.data.dataSource.pool.api.IPooledDataSourceConfig;
|
||||
|
||||
import java.sql.Connection;
|
||||
|
||||
/**
|
||||
* 池化的连接池
|
||||
* @since 1.1.0
|
||||
*/
|
||||
public interface IPooledConnection extends Connection {
|
||||
|
||||
|
||||
/**
|
||||
* 是否繁忙
|
||||
* @since 1.1.0
|
||||
* @return 状态
|
||||
*/
|
||||
boolean isBusy();
|
||||
|
||||
/**
|
||||
* 设置状态
|
||||
* @param busy 状态
|
||||
* @since 1.1.0
|
||||
*/
|
||||
void setBusy(boolean busy);
|
||||
|
||||
/**
|
||||
* 获取真正的连接
|
||||
* @return 连接
|
||||
* @since 1.1.0
|
||||
*/
|
||||
Connection getConnection();
|
||||
|
||||
/**
|
||||
* 设置连接信息
|
||||
* @param connection 连接信息
|
||||
* @since 1.1.0
|
||||
*/
|
||||
void setConnection(Connection connection);
|
||||
|
||||
/**
|
||||
* 设置对应的数据源
|
||||
* @param dataSource 数据源
|
||||
* @since 1.5.0
|
||||
*/
|
||||
void setDataSource(final IPooledDataSourceConfig dataSource);
|
||||
|
||||
/**
|
||||
* 获取对应的数据源信息
|
||||
* @return 数据源
|
||||
* @since 1.5.0
|
||||
*/
|
||||
IPooledDataSourceConfig getDataSource();
|
||||
|
||||
}
|
@ -0,0 +1,71 @@
|
||||
package com.anjiplus.template.gaea.business.modules.data.dataSource.pool.constant;
|
||||
|
||||
/**
|
||||
* Created by raodeming on 2021/3/19.
|
||||
*/
|
||||
public class JdbcConstants {
|
||||
public final static String JTDS = "jtds";
|
||||
public final static String MOCK = "mock";
|
||||
public final static String HSQL = "hsql";
|
||||
public final static String DB2 = "db2";
|
||||
public final static String DB2_DRIVER = "COM.ibm.db2.jdbc.app.DB2Driver";
|
||||
public final static String POSTGRESQL = "postgresql";
|
||||
public final static String POSTGRESQL_DRIVER = "org.postgresql.Driver";
|
||||
public final static String SYBASE = "sybase";
|
||||
public final static String SQL_SERVER = "sqlserver";
|
||||
public final static String SQL_SERVER_DRIVER = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
|
||||
public final static String SQL_SERVER_DRIVER_SQLJDBC4 = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
|
||||
public final static String SQL_SERVER_DRIVER_JTDS = "net.sourceforge.jtds.jdbc.Driver";
|
||||
public final static String ORACLE = "oracle";
|
||||
public final static String ORACLE_DRIVER = "oracle.jdbc.OracleDriver";
|
||||
public final static String ORACLE_DRIVER2 = "oracle.jdbc.driver.OracleDriver";
|
||||
public final static String ALI_ORACLE = "AliOracle";
|
||||
public final static String ALI_ORACLE_DRIVER = "com.alibaba.jdbc.AlibabaDriver";
|
||||
public final static String MYSQL = "mysql";
|
||||
public final static String MYSQL_DRIVER = "com.mysql.jdbc.Driver";
|
||||
public final static String MYSQL_DRIVER_6 = "com.mysql.cj.jdbc.Driver";
|
||||
public final static String MYSQL_DRIVER_REPLICATE = "com.mysql.jdbc.";
|
||||
public final static String MARIADB = "mariadb";
|
||||
public final static String MARIADB_DRIVER = "org.mariadb.jdbc.Driver";
|
||||
public final static String DERBY = "derby";
|
||||
public final static String HBASE = "hbase";
|
||||
public final static String HIVE = "hive";
|
||||
public final static String HIVE_DRIVER = "org.apache.hive.jdbc.HiveDriver";
|
||||
public final static String H2 = "h2";
|
||||
public final static String H2_DRIVER = "org.h2.Driver";
|
||||
public final static String DM = "dm";
|
||||
public final static String DM_DRIVER = "dm.jdbc.driver.DmDriver";
|
||||
public final static String KINGBASE = "kingbase";
|
||||
public final static String KINGBASE_DRIVER = "com.kingbase.Driver";
|
||||
public final static String GBASE = "gbase";
|
||||
public final static String GBASE_DRIVER = "com.gbase.jdbc.Driver";
|
||||
public final static String XUGU = "xugu";
|
||||
public final static String XUGU_DRIVER = "com.xugu.cloudjdbc.Driver";
|
||||
public final static String OCEANBASE = "oceanbase";
|
||||
public final static String OCEANBASE_DRIVER = "com.mysql.jdbc.Driver";
|
||||
public final static String INFORMIX = "informix";
|
||||
public final static String ODPS = "odps";
|
||||
public final static String ODPS_DRIVER = "com.aliyun.odps.jdbc.OdpsDriver";
|
||||
public final static String TERADATA = "teradata";
|
||||
public final static String TERADATA_DRIVER = "com.teradata.jdbc.TeraDriver";
|
||||
public final static String LOG4JDBC = "log4jdbc";
|
||||
public final static String LOG4JDBC_DRIVER = "net.sf.log4jdbc.DriverSpy";
|
||||
public final static String PHOENIX = "phoenix";
|
||||
public final static String PHOENIX_DRIVER = "org.apache.phoenix.jdbc.PhoenixDriver";
|
||||
public final static String ENTERPRISEDB = "edb";
|
||||
public final static String ENTERPRISEDB_DRIVER = "com.edb.Driver";
|
||||
public final static String KYLIN = "kylin";
|
||||
public final static String KYLIN_DRIVER = "org.apache.kylin.jdbc.Driver";
|
||||
public final static String SQLITE = "sqlite";
|
||||
public final static String SQLITE_DRIVER = "org.sqlite.JDBC";
|
||||
public final static String ALIYUN_ADS = "aliyun_ads";
|
||||
public final static String ALIYUN_DRDS = "aliyun_drds";
|
||||
public final static String PRESTO = "presto";
|
||||
public final static String ELASTIC_SEARCH = "elasticsearch";
|
||||
public final static String ELASTIC_SEARCH_SQL = "elasticsearch_sql";
|
||||
public final static String ELASTIC_SEARCH_DRIVER = "com.alibaba.xdriver.elastic.jdbc.ElasticDriver";
|
||||
public final static String CLICKHOUSE = "clickhouse";
|
||||
public final static String CLICKHOUSE_DRIVER = "ru.yandex.clickhouse.ClickHouseDriver";
|
||||
public final static String KUDU_IMAPLA = "kudu_impala";
|
||||
public final static String HTTP = "http";
|
||||
}
|
@ -0,0 +1,68 @@
|
||||
package com.anjiplus.template.gaea.business.modules.data.dataSource.pool.datasource;
|
||||
|
||||
/**
|
||||
* @author binbin.hou
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public class AbstractDataSourceConfig extends DataSourceConfigAdaptor {
|
||||
|
||||
/**
|
||||
* 驱动类
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected String driverClass;
|
||||
|
||||
/**
|
||||
* jdbc url
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected String jdbcUrl;
|
||||
|
||||
/**
|
||||
* 用户
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected String user;
|
||||
|
||||
/**
|
||||
* 密码
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected String password;
|
||||
|
||||
public String getDriverClass() {
|
||||
return driverClass;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDriverClass(String driverClass) {
|
||||
this.driverClass = driverClass;
|
||||
}
|
||||
|
||||
public String getJdbcUrl() {
|
||||
return jdbcUrl;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setJdbcUrl(String jdbcUrl) {
|
||||
this.jdbcUrl = jdbcUrl;
|
||||
}
|
||||
|
||||
public String getUser() {
|
||||
return user;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUser(String user) {
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
}
|
@ -0,0 +1,159 @@
|
||||
package com.anjiplus.template.gaea.business.modules.data.dataSource.pool.datasource;
|
||||
|
||||
import com.anjiplus.template.gaea.business.modules.data.dataSource.pool.api.ILifeCycle;
|
||||
import com.anjiplus.template.gaea.business.modules.data.dataSource.pool.api.IPooledDataSourceConfig;
|
||||
import com.anjiplus.template.gaea.business.modules.data.dataSource.pool.constant.PooledConst;
|
||||
|
||||
/**
|
||||
* @author binbin.hou
|
||||
* @since 1.1.0
|
||||
*/
|
||||
public abstract class AbstractPooledDataSourceConfig extends AbstractDataSourceConfig
|
||||
implements IPooledDataSourceConfig, ILifeCycle {
|
||||
|
||||
/**
|
||||
* 最小尺寸
|
||||
* @since 1.1.0
|
||||
*/
|
||||
protected int minSize = PooledConst.DEFAULT_MIN_SIZE;
|
||||
|
||||
/**
|
||||
* 最大尺寸
|
||||
* @since 1.1.0
|
||||
*/
|
||||
protected int maxSize = PooledConst.DEFAULT_MAX_SIZE;
|
||||
|
||||
/**
|
||||
* 最大的等待时间
|
||||
* @since 1.3.0
|
||||
*/
|
||||
protected long maxWaitMills = PooledConst.DEFAULT_MAX_WAIT_MILLS;
|
||||
|
||||
/**
|
||||
* 验证查询
|
||||
* @since 1.5.0
|
||||
*/
|
||||
protected String validQuery = PooledConst.DEFAULT_VALID_QUERY;
|
||||
|
||||
/**
|
||||
* 验证的超时时间
|
||||
* @since 1.5.0
|
||||
*/
|
||||
protected int validTimeOutSeconds = PooledConst.DEFAULT_VALID_TIME_OUT_SECONDS;
|
||||
|
||||
/**
|
||||
* 获取时验证
|
||||
* @since 1.5.0
|
||||
*/
|
||||
protected boolean testOnBorrow = PooledConst.DEFAULT_TEST_ON_BORROW;
|
||||
|
||||
/**
|
||||
* 归还时验证
|
||||
* @since 1.5.0
|
||||
*/
|
||||
protected boolean testOnReturn = PooledConst.DEFAULT_TEST_ON_RETURN;
|
||||
|
||||
/**
|
||||
* 闲暇时验证
|
||||
* @since 1.5.0
|
||||
*/
|
||||
protected boolean testOnIdle = PooledConst.DEFAULT_TEST_ON_IDLE;
|
||||
|
||||
/**
|
||||
* 闲暇时验证的时间间隔
|
||||
* @since 1.5.0
|
||||
*/
|
||||
protected long testOnIdleIntervalSeconds = PooledConst.DEFAULT_TEST_ON_IDLE_INTERVAL_SECONDS;
|
||||
|
||||
public int getMinSize() {
|
||||
return minSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMinSize(int minSize) {
|
||||
this.minSize = minSize;
|
||||
}
|
||||
|
||||
public int getMaxSize() {
|
||||
return maxSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMaxSize(int maxSize) {
|
||||
this.maxSize = maxSize;
|
||||
}
|
||||
|
||||
public long getMaxWaitMills() {
|
||||
return maxWaitMills;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMaxWaitMills(long maxWaitMills) {
|
||||
this.maxWaitMills = maxWaitMills;
|
||||
}
|
||||
|
||||
public String getValidQuery() {
|
||||
return validQuery;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValidQuery(String validQuery) {
|
||||
this.validQuery = validQuery;
|
||||
}
|
||||
|
||||
public int getValidTimeOutSeconds() {
|
||||
return validTimeOutSeconds;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValidTimeOutSeconds(int validTimeOutSeconds) {
|
||||
this.validTimeOutSeconds = validTimeOutSeconds;
|
||||
}
|
||||
|
||||
public boolean isTestOnBorrow() {
|
||||
return testOnBorrow;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTestOnBorrow(boolean testOnBorrow) {
|
||||
this.testOnBorrow = testOnBorrow;
|
||||
}
|
||||
|
||||
public boolean isTestOnReturn() {
|
||||
return testOnReturn;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTestOnReturn(boolean testOnReturn) {
|
||||
this.testOnReturn = testOnReturn;
|
||||
}
|
||||
|
||||
public boolean isTestOnIdle() {
|
||||
return testOnIdle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTestOnIdle(boolean testOnIdle) {
|
||||
this.testOnIdle = testOnIdle;
|
||||
}
|
||||
|
||||
public long getTestOnIdleIntervalSeconds() {
|
||||
return testOnIdleIntervalSeconds;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTestOnIdleIntervalSeconds(long testOnIdleIntervalSeconds) {
|
||||
this.testOnIdleIntervalSeconds = testOnIdleIntervalSeconds;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,82 @@
|
||||
package com.anjiplus.template.gaea.business.modules.data.dataSource.pool.datasource;
|
||||
|
||||
import com.anjiplus.template.gaea.business.modules.data.dataSource.pool.api.IDataSourceConfig;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.SQLFeatureNotSupportedException;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* @author binbin.hou
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public class DataSourceConfigAdaptor implements IDataSourceConfig {
|
||||
|
||||
@Override
|
||||
public Connection getConnection() throws SQLException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Connection getConnection(String username, String password) throws SQLException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T unwrap(Class<T> iface) throws SQLException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isWrapperFor(Class<?> iface) throws SQLException {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PrintWriter getLogWriter() throws SQLException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLogWriter(PrintWriter out) throws SQLException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLoginTimeout(int seconds) throws SQLException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLoginTimeout() throws SQLException {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Logger getParentLogger() throws SQLFeatureNotSupportedException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDriverClass(String driverClass) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setJdbcUrl(String jdbcUrl) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUser(String user) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPassword(String password) {
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
package com.anjiplus.template.gaea.business.modules.data.dataSource.pool.datasource;
|
||||
|
||||
import com.anjiplus.template.gaea.business.modules.data.dataSource.pool.util.DriverClassUtil;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.SQLException;
|
||||
|
||||
/**
|
||||
* @author binbin.hou
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public class UnPooledDataSource extends AbstractDataSourceConfig {
|
||||
|
||||
@Override
|
||||
public Connection getConnection() throws SQLException {
|
||||
DriverClassUtil.loadDriverClass(super.driverClass, super.jdbcUrl);
|
||||
if (StringUtils.isBlank(super.getUser()) && StringUtils.isBlank(super.getPassword())) {
|
||||
return DriverManager.getConnection(super.jdbcUrl);
|
||||
}
|
||||
return DriverManager.getConnection(super.getJdbcUrl(),
|
||||
super.getUser(), super.getPassword());
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
package com.anjiplus.template.gaea.business.modules.data.dataSource.pool.exception;
|
||||
|
||||
/**
|
||||
* @author binbin.hou
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public class JdbcPoolException extends RuntimeException {
|
||||
|
||||
public JdbcPoolException() {
|
||||
}
|
||||
|
||||
public JdbcPoolException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public JdbcPoolException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public JdbcPoolException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
public JdbcPoolException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
|
||||
super(message, cause, enableSuppression, writableStackTrace);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package com.anjiplus.template.gaea.business.modules.data.dataSource.pool.util;
|
||||
|
||||
/**
|
||||
* Created by raodeming on 2021/3/19.
|
||||
*/
|
||||
public class DataSourceHandleUtil {
|
||||
|
||||
|
||||
public static void mysqlConnection() {
|
||||
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,100 @@
|
||||
package com.anjiplus.template.gaea.business.modules.data.dataSource.pool.util;
|
||||
|
||||
import com.anjiplus.template.gaea.business.modules.data.dataSource.controller.dto.DataSourceDto;
|
||||
import com.anjiplus.template.gaea.business.modules.data.dataSource.pool.datasource.PooledDataSource;
|
||||
import com.anjiplus.template.gaea.business.modules.data.dataSource.pool.datasource.UnPooledDataSource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.locks.Lock;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
/**
|
||||
* Created by raodeming on 2021/3/18.
|
||||
*/
|
||||
@Slf4j
|
||||
public class JdbcUtil {
|
||||
|
||||
private static Lock lock = new ReentrantLock();
|
||||
|
||||
private static Lock deleteLock = new ReentrantLock();
|
||||
|
||||
//所有数据源的连接池存在map里
|
||||
static Map<Long, PooledDataSource> map = new HashMap<>();
|
||||
|
||||
public static PooledDataSource getJdbcConnectionPool(DataSourceDto dataSource) {
|
||||
if (map.containsKey(dataSource.getId())) {
|
||||
return map.get(dataSource.getId());
|
||||
} else {
|
||||
lock.lock();
|
||||
try {
|
||||
log.debug(Thread.currentThread().getName() + "获取锁");
|
||||
if (!map.containsKey(dataSource.getId())) {
|
||||
PooledDataSource pool = new PooledDataSource();
|
||||
pool.setJdbcUrl(dataSource.getJdbcUrl());
|
||||
pool.setUser(dataSource.getUsername());
|
||||
pool.setPassword(dataSource.getPassword());
|
||||
pool.setDriverClass(dataSource.getDriverName());
|
||||
pool.init();
|
||||
map.put(dataSource.getId(), pool);
|
||||
log.info("创建连接池成功:{}", dataSource.getJdbcUrl());
|
||||
}
|
||||
return map.get(dataSource.getId());
|
||||
} finally {
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除数据库连接池
|
||||
* @param id
|
||||
*/
|
||||
public static void removeJdbcConnectionPool(Long id) {
|
||||
deleteLock.lock();
|
||||
try {
|
||||
PooledDataSource pool = map.get(id);
|
||||
if (pool != null) {
|
||||
map.remove(id);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error(e.toString());
|
||||
} finally {
|
||||
deleteLock.unlock();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取连接
|
||||
* @param dataSource
|
||||
* @return
|
||||
* @throws SQLException
|
||||
*/
|
||||
public static Connection getPooledConnection(DataSourceDto dataSource) throws SQLException {
|
||||
PooledDataSource pool = getJdbcConnectionPool(dataSource);
|
||||
return pool.getConnection();
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试数据库连接 获取一个连接
|
||||
* @param dataSource
|
||||
* @return
|
||||
* @throws ClassNotFoundException driverName不正确
|
||||
* @throws SQLException
|
||||
*/
|
||||
public static Connection getUnPooledConnection(DataSourceDto dataSource) throws SQLException {
|
||||
UnPooledDataSource source = new UnPooledDataSource();
|
||||
source.setJdbcUrl(dataSource.getJdbcUrl());
|
||||
source.setDriverClass(dataSource.getDriverName());
|
||||
source.setUser(dataSource.getUsername());
|
||||
source.setPassword(dataSource.getPassword());
|
||||
return source.getConnection();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
|
||||
package com.anjiplus.template.gaea.business.modules.data.dataSource.service;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.anji.plus.gaea.curd.service.GaeaBaseService;
|
||||
import com.anjiplus.template.gaea.business.modules.data.dataSet.controller.dto.DataSetDto;
|
||||
import com.anjiplus.template.gaea.business.modules.data.dataSource.controller.dto.DataSourceDto;
|
||||
import com.anjiplus.template.gaea.business.modules.data.dataSource.controller.param.ConnectionParam;
|
||||
import com.anjiplus.template.gaea.business.modules.data.dataSource.controller.param.DataSourceParam;
|
||||
import com.anjiplus.template.gaea.business.modules.data.dataSource.dao.entity.DataSource;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @desc DataSource 数据集服务接口
|
||||
* @author Raod
|
||||
* @date 2021-03-18 12:09:57.728203200
|
||||
**/
|
||||
public interface DataSourceService extends GaeaBaseService<DataSourceParam, DataSource> {
|
||||
|
||||
/**
|
||||
* 获取所有数据源
|
||||
* @return
|
||||
*/
|
||||
List<DataSource> queryAllDataSource();
|
||||
|
||||
/**
|
||||
* 测试 连接
|
||||
* @param connectionParam
|
||||
* @return
|
||||
*/
|
||||
Boolean testConnection(ConnectionParam connectionParam);
|
||||
|
||||
/**
|
||||
* 执行sql
|
||||
* @param dto
|
||||
* @return
|
||||
*/
|
||||
List<JSONObject> execute(DataSourceDto dto);
|
||||
|
||||
/**
|
||||
* 执行sql,统计数据total
|
||||
* @param dataSourceDto
|
||||
* @param dto
|
||||
* @return
|
||||
*/
|
||||
long total(DataSourceDto dataSourceDto, DataSetDto dto);
|
||||
}
|
Loading…
Reference in New Issue