mirror of
http://192.168.1.205:9980/cf_devdept2/cf_imes_server.git
synced 2026-08-12 21:02:08 +08:00
报表基础模块:1、规范模板、数据源类型type入参;2、新增数据源字段ds_type,规范入参;3、完善数据源接口,包括:新增内置数据源查询接口,数据源查询时附带数据集,内置数据源增改权限限制为超管,新增修改数据源同时新增修改数据集;
This commit is contained in:
+13
@@ -14,6 +14,7 @@ import com.cf.imes.framework.common.util.json.JsonUtils;
|
||||
import com.cf.imes.framework.common.util.servlet.ServletUtils;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.dao.DuplicateKeyException;
|
||||
import org.springframework.security.access.AccessDeniedException;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.validation.BindException;
|
||||
@@ -212,6 +213,18 @@ public class GlobalExceptionHandler {
|
||||
return CommonResult.error(ex.getCode(), ex.getMessage());
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理数据库DuplicateKeyException,违反唯一约束异常
|
||||
*
|
||||
* @param ex
|
||||
* @return
|
||||
*/
|
||||
@ExceptionHandler(value = DuplicateKeyException.class)
|
||||
public CommonResult<?> duplicateKeyExceptionHandler(DuplicateKeyException ex) {
|
||||
log.info("[duplicateKeyExceptionHandler]", ex);
|
||||
return CommonResult.error(INTERNAL_SERVER_ERROR.getCode(), "请求数据已存在,请检查");
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理系统异常,兜底处理所有的一切
|
||||
*/
|
||||
|
||||
+3
-1
@@ -15,7 +15,9 @@ public final class ErrorCodeConstants {
|
||||
|
||||
// ========== UREPORT datasource模块 1-003-002-000 ==========
|
||||
public static final ErrorCode DATASOURCE_NOT_EXISTS = new ErrorCode(1_003_002_001, "报表数据源不存在");
|
||||
public static final ErrorCode DATASOURCE_CONNECT_FAIL = new ErrorCode(1_003_002_001, "报表数据源连接失败");
|
||||
public static final ErrorCode DATASOURCE_CONNECT_FAIL = new ErrorCode(1_003_002_002, "报表数据源连接失败");
|
||||
public static final ErrorCode DATASOURCE_BUILDIN_OPERATION_PERMISSION_ERROR = new ErrorCode(1_003_002_003, "内置报表数据源只能由超级管理员操作");
|
||||
|
||||
|
||||
// ========== UREPORT dataset模块 1-003-003-000 ==========
|
||||
public static final ErrorCode DATASET_NOT_EXISTS = new ErrorCode(1_003_003_001, "报表数据集不存在");
|
||||
|
||||
-26
@@ -1,26 +0,0 @@
|
||||
package com.cf.imes.module.report.enums.template;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* 报表模板类型
|
||||
*
|
||||
* @author Gqr
|
||||
* @since 2024/7/5 9:25
|
||||
*/
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum ReportTemplateTypeEnum {
|
||||
/**
|
||||
* 内置
|
||||
*/
|
||||
SYSTEM(1),
|
||||
/**
|
||||
* 自定义
|
||||
*/
|
||||
CUSTOM(2);
|
||||
|
||||
private final Integer type;
|
||||
|
||||
}
|
||||
+1
-1
@@ -30,7 +30,7 @@ public class ReportDatasetSaveReqVO implements Serializable {
|
||||
@Schema(description = "数据集名称", example = "测试数据集")
|
||||
private String name;
|
||||
|
||||
@Schema(description = "数据源id", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||
@Schema(description = "数据源id", example = "1")
|
||||
private Long datasourceId;
|
||||
|
||||
@Schema(description = "动态查询SQL")
|
||||
|
||||
+7
@@ -95,6 +95,13 @@ public class ReportDatasourceController {
|
||||
return success(datasourceService.loadBeanMethods(beanId));
|
||||
}
|
||||
|
||||
@GetMapping("/buildin/datasources")
|
||||
@Operation(summary = "获取内置数据源")
|
||||
@PreAuthorize("@ss.hasPermission('report:datasource:query')")
|
||||
public CommonResult<List<ReportDatasourceRespVO>> getBuildinDatasources() {
|
||||
return success(BeanUtils.toBean(datasourceService.getBuildinDatasources(), ReportDatasourceRespVO.class));
|
||||
}
|
||||
|
||||
@PostMapping("/datasource/connect")
|
||||
@Operation(summary = "测试数据源连接")
|
||||
@PreAuthorize("@ss.hasPermission('report:datasource:query')")
|
||||
|
||||
+1
-1
@@ -30,6 +30,6 @@ public class ReportDatasourceReqVO implements Serializable {
|
||||
@Schema(description = "数据源名称", example = "测试库")
|
||||
private String name;
|
||||
|
||||
@Schema(description = "数据源类型,0 jdbc、1 buildin、2 spring", example = "jdbc")
|
||||
@Schema(description = "类型,0 内置、1 自定义", example = "1")
|
||||
private Integer type;
|
||||
}
|
||||
|
||||
+5
-2
@@ -28,8 +28,11 @@ public class ReportDatasourceRespVO {
|
||||
@Schema(description = "数据源名称", example = "测试库")
|
||||
private String name;
|
||||
|
||||
@Schema(description = "数据源类型,jdbc、buildin、spring", example = "jdbc")
|
||||
private ReportDatasourceTypeEnum type;
|
||||
@Schema(description = "数据源类型,jdbc、spring", example = "jdbc")
|
||||
private ReportDatasourceTypeEnum dsType;
|
||||
|
||||
@Schema(description = "模板类型,0内置、1自定义", example = "0")
|
||||
private Integer type;
|
||||
|
||||
@Schema(description = "数据源驱动类",example = "com.mysql.cj.jdbc.Driver")
|
||||
private String driver;
|
||||
|
||||
+8
-4
@@ -2,13 +2,13 @@ package com.cf.imes.module.report.controller.admin.datasource.vo;
|
||||
|
||||
import com.cf.imes.module.report.controller.admin.dataset.vo.ReportDatasetSaveReqVO;
|
||||
import com.cf.imes.module.report.validation.datasource.ReportDatasourceTypeInEnum;
|
||||
import com.cf.imes.module.report.validation.template.ReportTemplateTypeInEnum;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
@@ -30,15 +30,19 @@ public class ReportDatasourceSaveReqVO implements Serializable {
|
||||
@Schema(description = "数据源id", example = "1")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "模板id", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||
@Schema(description = "模板id", example = "1")
|
||||
private Long templateId;
|
||||
|
||||
@Schema(description = "数据源名称", example = "测试库")
|
||||
private String name;
|
||||
|
||||
@Schema(description = "数据源类型,jdbc、buildin、spring", example = "jdbc")
|
||||
@Schema(description = "模板类型,0内置、1自定义", example = "1")
|
||||
@ReportTemplateTypeInEnum
|
||||
private Integer type;
|
||||
|
||||
@Schema(description = "数据源类型,jdbc、spring", example = "jdbc")
|
||||
@ReportDatasourceTypeInEnum
|
||||
private String type;
|
||||
private String dsType;
|
||||
|
||||
@Schema(description = "spring型数据源id")
|
||||
private String beanId;
|
||||
|
||||
+1
-1
@@ -28,7 +28,7 @@ public class ReportTemplateRespVO {
|
||||
private String content;
|
||||
|
||||
@Schema(description = "模板类型,0内置、1自定义", example = "0")
|
||||
private Long type;
|
||||
private Integer type;
|
||||
|
||||
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
private LocalDateTime createTime;
|
||||
|
||||
+2
@@ -1,6 +1,7 @@
|
||||
package com.cf.imes.module.report.controller.admin.template.vo;
|
||||
|
||||
import com.cf.imes.module.report.controller.admin.datasource.vo.ReportDatasourceSaveReqVO;
|
||||
import com.cf.imes.module.report.validation.template.ReportTemplateTypeInEnum;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
@@ -34,6 +35,7 @@ public class ReportTemplateSaveReqVO {
|
||||
private List<ReportDatasourceSaveReqVO> datasource = new ArrayList<>();
|
||||
|
||||
@Schema(description = "模板类型,0内置、1自定义", example = "1")
|
||||
@ReportTemplateTypeInEnum
|
||||
private Integer type;
|
||||
|
||||
@Schema(description = "备注", example = "该模板仅供生产使用")
|
||||
|
||||
+9
-2
@@ -7,6 +7,7 @@ import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.cf.imes.framework.mybatis.core.dataobject.BaseDO;
|
||||
import com.cf.imes.module.report.dal.dataobject.dataset.ReportDatasetDO;
|
||||
import com.cf.imes.module.report.enums.datasource.ReportDatasourceTypeEnum;
|
||||
import com.cf.imes.module.report.enums.template.ReportTemplateTypeEnum;
|
||||
import lombok.*;
|
||||
|
||||
import java.util.List;
|
||||
@@ -40,9 +41,15 @@ public class ReportDatasourceDO extends BaseDO {
|
||||
*/
|
||||
private String name;
|
||||
/**
|
||||
* 模板类型,jdbc、buildin、spring
|
||||
* 模板类型,jdbc、spring
|
||||
*/
|
||||
private ReportDatasourceTypeEnum type;
|
||||
private ReportDatasourceTypeEnum dsType;
|
||||
|
||||
/**
|
||||
* 模板类型,0内置、1自定义
|
||||
*/
|
||||
private ReportTemplateTypeEnum type;
|
||||
|
||||
/**
|
||||
* spring型数据源id
|
||||
*/
|
||||
|
||||
+2
-1
@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.annotation.*;
|
||||
import com.cf.imes.framework.mybatis.core.dataobject.BaseDO;
|
||||
import com.cf.imes.framework.mybatis.core.type.CompressStringTypeHandler;
|
||||
import com.cf.imes.module.report.dal.dataobject.datasource.ReportDatasourceDO;
|
||||
import com.cf.imes.module.report.enums.template.ReportTemplateTypeEnum;
|
||||
import lombok.*;
|
||||
|
||||
import java.util.List;
|
||||
@@ -40,7 +41,7 @@ public class ReportTemplateDO extends BaseDO {
|
||||
/**
|
||||
* 模板类型,0内置、1自定义
|
||||
*/
|
||||
private Integer type;
|
||||
private ReportTemplateTypeEnum type;
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
|
||||
+1
-2
@@ -14,8 +14,7 @@ import lombok.Getter;
|
||||
@AllArgsConstructor
|
||||
public enum ReportDatasourceTypeEnum {
|
||||
JDBC(0,"jdbc"),
|
||||
BUILDIN(1,"buildin"),
|
||||
SPRING(2,"spring");
|
||||
SPRING(1,"spring");
|
||||
|
||||
@EnumValue
|
||||
private final Integer code;
|
||||
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
package com.cf.imes.module.report.enums.template;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.EnumValue;
|
||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* 报表模板类型
|
||||
*
|
||||
* @author Gqr
|
||||
* @since 2024/7/5 9:25
|
||||
*/
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum ReportTemplateTypeEnum {
|
||||
/**
|
||||
* 内置
|
||||
*/
|
||||
SYSTEM(0),
|
||||
/**
|
||||
* 自定义
|
||||
*/
|
||||
CUSTOM(1);
|
||||
|
||||
@EnumValue
|
||||
private final Integer type;
|
||||
|
||||
@JsonCreator
|
||||
public static ReportTemplateTypeEnum fromType(Integer type) {
|
||||
for (ReportTemplateTypeEnum value : values()) {
|
||||
if (value.getType().equals(type)) {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
+6
@@ -63,6 +63,12 @@ public interface ReportDatasourceService {
|
||||
*/
|
||||
List<ReportBeanDatasourceRespVO> getBeanDatasourceList();
|
||||
|
||||
/**
|
||||
* 获取内置数据源列表
|
||||
* @return
|
||||
*/
|
||||
List<ReportDatasourceDO> getBuildinDatasources();
|
||||
|
||||
/**
|
||||
* 获取bean方法
|
||||
*
|
||||
|
||||
+106
-4
@@ -1,6 +1,7 @@
|
||||
package com.cf.imes.module.report.service.datasource;
|
||||
|
||||
import cn.hutool.core.annotation.AnnotationUtil;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.baomidou.mybatisplus.core.toolkit.sql.SqlInjectionUtils;
|
||||
import com.bstek.ureport.definition.dataset.Field;
|
||||
@@ -10,15 +11,23 @@ import com.bstek.ureport.utils.ProcedureUtils;
|
||||
import com.cf.imes.framework.common.exception.ServiceException;
|
||||
import com.cf.imes.framework.common.util.object.BeanUtils;
|
||||
import com.cf.imes.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import com.cf.imes.framework.organ.core.aop.OrganIgnore;
|
||||
import com.cf.imes.framework.security.core.LoginUser;
|
||||
import com.cf.imes.framework.security.core.util.SecurityFrameworkUtils;
|
||||
import com.cf.imes.module.report.controller.admin.dataset.vo.ReportDatasetFieldVO;
|
||||
import com.cf.imes.module.report.controller.admin.dataset.vo.ReportDatasetParameterVO;
|
||||
import com.cf.imes.module.report.controller.admin.dataset.vo.ReportDatasetReqVO;
|
||||
import com.cf.imes.module.report.controller.admin.datasource.vo.ReportBeanDatasourceRespVO;
|
||||
import com.cf.imes.module.report.controller.admin.datasource.vo.ReportDatasourceReqVO;
|
||||
import com.cf.imes.module.report.controller.admin.datasource.vo.ReportDatasourceSaveReqVO;
|
||||
import com.cf.imes.module.report.controller.admin.datasource.vo.ReportDatasourceTestConnReqVO;
|
||||
import com.cf.imes.module.report.dal.dataobject.dataset.ReportDatasetDO;
|
||||
import com.cf.imes.module.report.dal.dataobject.datasource.ReportDatasourceDO;
|
||||
import com.cf.imes.module.report.dal.mysql.dataset.ReportDatasetMapper;
|
||||
import com.cf.imes.module.report.dal.mysql.datasource.ReportDatasourceMapper;
|
||||
import com.cf.imes.module.report.enums.template.ReportTemplateTypeEnum;
|
||||
import com.cf.imes.module.report.framework.ureport.annotation.CfReportSpringbeanDatasource;
|
||||
import com.cf.imes.module.report.service.dataset.ReportDatasetService;
|
||||
import com.cf.imes.module.report.util.SqlInjectionUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@@ -49,6 +58,7 @@ import static com.cf.imes.module.report.enums.ErrorCodeConstants.DATASET_GET_FIE
|
||||
import static com.cf.imes.module.report.enums.ErrorCodeConstants.DATASET_SQL_ILLEGAL;
|
||||
import static com.cf.imes.module.report.enums.ErrorCodeConstants.DATASET_SQL_INJECTION_RISK;
|
||||
import static com.cf.imes.module.report.enums.ErrorCodeConstants.DATASET_SQL_REQUIRED;
|
||||
import static com.cf.imes.module.report.enums.ErrorCodeConstants.DATASOURCE_BUILDIN_OPERATION_PERMISSION_ERROR;
|
||||
import static com.cf.imes.module.report.enums.ErrorCodeConstants.DATASOURCE_NOT_EXISTS;
|
||||
|
||||
/**
|
||||
@@ -64,6 +74,12 @@ public class ReportDatasourceServiceImpl implements ReportDatasourceService {
|
||||
@Resource
|
||||
private ReportDatasourceMapper datasourceMapper;
|
||||
|
||||
@Resource
|
||||
private ReportDatasetService datasetService;
|
||||
|
||||
@Resource
|
||||
private ReportDatasetMapper datasetMapper;
|
||||
|
||||
private final ApplicationContext applicationContext;
|
||||
|
||||
public ReportDatasourceServiceImpl(ApplicationContext applicationContext) {
|
||||
@@ -72,9 +88,13 @@ public class ReportDatasourceServiceImpl implements ReportDatasourceService {
|
||||
|
||||
@Override
|
||||
public Long createDatasource(ReportDatasourceSaveReqVO createReqVO) {
|
||||
// 插入
|
||||
ReportDatasourceDO datasource = BeanUtils.toBean(createReqVO, ReportDatasourceDO.class);
|
||||
// 校验内置数据源操作权限
|
||||
validateBuildinsource(datasource);
|
||||
// 插入
|
||||
datasourceMapper.insert(datasource);
|
||||
// 解析数据集
|
||||
analyzeDataset(datasource);
|
||||
// 返回
|
||||
return datasource.getId();
|
||||
}
|
||||
@@ -83,9 +103,54 @@ public class ReportDatasourceServiceImpl implements ReportDatasourceService {
|
||||
public void updateDatasource(ReportDatasourceSaveReqVO updateReqVO) {
|
||||
// 校验存在
|
||||
validateDatasourceExists(updateReqVO.getId());
|
||||
// 更新
|
||||
ReportDatasourceDO updateObj = BeanUtils.toBean(updateReqVO, ReportDatasourceDO.class);
|
||||
// 校验内置数据源操作权限
|
||||
validateBuildinsource(updateObj);
|
||||
// 更新
|
||||
datasourceMapper.updateById(updateObj);
|
||||
// 解析数据集
|
||||
analyzeDataset(updateObj);
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验只有超管可以操作内置数据源
|
||||
*/
|
||||
private void validateBuildinsource(ReportDatasourceDO datasource) {
|
||||
LoginUser loginUser = SecurityFrameworkUtils.getLoginUser();
|
||||
boolean isSuperAdmin = loginUser != null && loginUser.getIsSupAdmin();
|
||||
// 非超管不能操作内置数据源
|
||||
if (ReportTemplateTypeEnum.SYSTEM.equals(datasource.getType()) && !isSuperAdmin) {
|
||||
throw exception(DATASOURCE_BUILDIN_OPERATION_PERMISSION_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析数据源下的数据集
|
||||
*
|
||||
* @param datasource
|
||||
*/
|
||||
private void analyzeDataset(ReportDatasourceDO datasource) {
|
||||
List<ReportDatasetDO> datasets = datasource.getDatasets();
|
||||
List<ReportDatasetDO> batchInsertDataset = new ArrayList<>();
|
||||
List<ReportDatasetDO> batchupdateDataset = new ArrayList<>();
|
||||
datasets.forEach(dataset -> {
|
||||
// 更新/新增数据集
|
||||
if (ObjectUtil.isNotNull(dataset.getId())) {
|
||||
batchupdateDataset.add(dataset);
|
||||
} else {
|
||||
dataset.setDatasourceId(datasource.getId());
|
||||
batchInsertDataset.add(dataset);
|
||||
}
|
||||
});
|
||||
|
||||
// 批量插入数据集
|
||||
if (CollUtil.isNotEmpty(batchInsertDataset)) {
|
||||
datasetMapper.insertBatch(batchInsertDataset);
|
||||
}
|
||||
// 批量更新数据集
|
||||
if (CollUtil.isNotEmpty(batchupdateDataset)) {
|
||||
datasetMapper.updateBatch(batchupdateDataset);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -109,7 +174,10 @@ public class ReportDatasourceServiceImpl implements ReportDatasourceService {
|
||||
|
||||
@Override
|
||||
public ReportDatasourceDO getDatasource(Long id) {
|
||||
return datasourceMapper.selectById(id);
|
||||
ReportDatasourceDO reportDatasourceDO = datasourceMapper.selectById(id);
|
||||
// 查询数据集
|
||||
queryDatasetInSource(reportDatasourceDO);
|
||||
return reportDatasourceDO;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -117,8 +185,14 @@ public class ReportDatasourceServiceImpl implements ReportDatasourceService {
|
||||
List<ReportDatasourceDO> reportDatasourceDOS = datasourceMapper.selectList(new LambdaQueryWrapperX<ReportDatasourceDO>()
|
||||
.eqIfPresent(ReportDatasourceDO::getTemplateId, reqVO.getTemplateId())
|
||||
.likeIfPresent(ReportDatasourceDO::getName, reqVO.getName())
|
||||
.eqIfPresent(ReportDatasourceDO::getType, reqVO.getType())
|
||||
.eqIfPresent(ReportDatasourceDO::getDsType, reqVO.getType())
|
||||
.orderByDesc(ReportDatasourceDO::getCreateTime));
|
||||
// 查询数据集
|
||||
if (CollUtil.isNotEmpty(reportDatasourceDOS)) {
|
||||
reportDatasourceDOS.forEach(reportDatasourceDO -> {
|
||||
queryDatasetInSource(reportDatasourceDO);
|
||||
});
|
||||
}
|
||||
return reportDatasourceDOS;
|
||||
}
|
||||
|
||||
@@ -136,6 +210,21 @@ public class ReportDatasourceServiceImpl implements ReportDatasourceService {
|
||||
return beanDatasourceRespVOList;
|
||||
}
|
||||
|
||||
@Override
|
||||
@OrganIgnore
|
||||
public List<ReportDatasourceDO> getBuildinDatasources() {
|
||||
List<ReportDatasourceDO> reportDatasourceDOS = datasourceMapper.selectList(new LambdaQueryWrapperX<ReportDatasourceDO>()
|
||||
.eqIfPresent(ReportDatasourceDO::getType, ReportTemplateTypeEnum.SYSTEM)
|
||||
.orderByDesc(ReportDatasourceDO::getCreateTime));
|
||||
// 查询数据集
|
||||
if (CollUtil.isNotEmpty(reportDatasourceDOS)) {
|
||||
reportDatasourceDOS.forEach(reportDatasourceDO -> {
|
||||
queryDatasetInSource(reportDatasourceDO);
|
||||
});
|
||||
}
|
||||
return reportDatasourceDOS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> loadBeanMethods(String beanId) {
|
||||
Object obj = applicationContext.getBean(beanId);
|
||||
@@ -294,4 +383,17 @@ public class ReportDatasourceServiceImpl implements ReportDatasourceService {
|
||||
}
|
||||
return conn;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询数据源下的数据集
|
||||
*
|
||||
* @param reportDatasourceDO
|
||||
*/
|
||||
private void queryDatasetInSource(ReportDatasourceDO reportDatasourceDO) {
|
||||
if (ObjectUtil.isNotNull(reportDatasourceDO)) {
|
||||
// 查询数据集
|
||||
List<ReportDatasetDO> datasetList = datasetService.getDatasetList(ReportDatasetReqVO.builder().datasourceId(reportDatasourceDO.getId()).build());
|
||||
reportDatasourceDO.setDatasets(datasetList);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -217,8 +217,8 @@ public class ReportTemplateServiceImpl implements ReportTemplateService {
|
||||
// 查询数据集
|
||||
List<ReportDatasetDO> datasetList = datasetService.getDatasetList(ReportDatasetReqVO.builder().datasourceId(ds.getId()).build());
|
||||
List<DatasetDefinition> datasetDefinitions = new ArrayList<>();
|
||||
switch (ds.getType()) {
|
||||
case JDBC, BUILDIN -> {
|
||||
switch (ds.getDsType()) {
|
||||
case JDBC -> {
|
||||
// 转换对应的ureport对象
|
||||
JdbcDatasourceDefinition jdbcDatasourceDefinition = BeanUtils.toBean(ds, JdbcDatasourceDefinition.class);
|
||||
datasetDefinitions.addAll(BeanUtils.toBean(datasetList, SqlDatasetDefinition.class));
|
||||
|
||||
+1
-2
@@ -28,10 +28,9 @@ import java.lang.annotation.Target;
|
||||
validatedBy = {ReportDatasourceTypeInEnumValidator.class}
|
||||
)
|
||||
public @interface ReportDatasourceTypeInEnum {
|
||||
String message() default "数据源类型[type]错误,请检查是否jdbc/buildin/spring";
|
||||
String message() default "数据源类型[dsType]错误,请检查是否jdbc/spring";
|
||||
|
||||
Class<?>[] groups() default {};
|
||||
|
||||
Class<? extends Payload>[] payload() default {};
|
||||
|
||||
}
|
||||
|
||||
+3
-8
@@ -2,7 +2,6 @@ package com.cf.imes.module.report.validation.datasource;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.cf.imes.module.report.enums.datasource.ReportDatasourceTypeEnum;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import javax.validation.ConstraintValidator;
|
||||
import javax.validation.ConstraintValidatorContext;
|
||||
@@ -22,15 +21,11 @@ public class ReportDatasourceTypeInEnumValidator implements ConstraintValidator<
|
||||
|
||||
@Override
|
||||
public boolean isValid(String value, ConstraintValidatorContext context) {
|
||||
if (StringUtils.isEmpty(value)) {
|
||||
ReportDatasourceTypeEnum byType = ReportDatasourceTypeEnum.fromDesc(value);
|
||||
if (ObjectUtil.isNotNull(byType)) {
|
||||
return true;
|
||||
} else {
|
||||
ReportDatasourceTypeEnum byType = ReportDatasourceTypeEnum.fromDesc(value);
|
||||
if (ObjectUtil.isNotNull(byType)) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
package com.cf.imes.module.report.validation.template;
|
||||
|
||||
import javax.validation.Constraint;
|
||||
import javax.validation.Payload;
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* 自定义报表模板类型入参校验注解
|
||||
*
|
||||
* @author Gqr
|
||||
* @since 2024/7/17 9:33
|
||||
*/
|
||||
@Target({
|
||||
ElementType.METHOD,
|
||||
ElementType.FIELD,
|
||||
ElementType.ANNOTATION_TYPE,
|
||||
ElementType.CONSTRUCTOR,
|
||||
ElementType.PARAMETER,
|
||||
ElementType.TYPE_USE
|
||||
})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
@Constraint(
|
||||
validatedBy = {ReportTemplateTypeInEnumValidator.class}
|
||||
)
|
||||
public @interface ReportTemplateTypeInEnum {
|
||||
String message() default "类型[type]错误,请检查是否0(内置)/1(自定义)";
|
||||
|
||||
Class<?>[] groups() default {};
|
||||
|
||||
Class<? extends Payload>[] payload() default {};
|
||||
}
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
package com.cf.imes.module.report.validation.template;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.cf.imes.module.report.enums.template.ReportTemplateTypeEnum;
|
||||
|
||||
import javax.validation.ConstraintValidator;
|
||||
import javax.validation.ConstraintValidatorContext;
|
||||
|
||||
/**
|
||||
* 自定义报表模板类型入参校验器
|
||||
*
|
||||
* @author Gqr
|
||||
* @since 2024/7/17 9:33
|
||||
*/
|
||||
public class ReportTemplateTypeInEnumValidator implements ConstraintValidator<ReportTemplateTypeInEnum, Integer> {
|
||||
|
||||
@Override
|
||||
public void initialize(ReportTemplateTypeInEnum constraintAnnotation) {
|
||||
ConstraintValidator.super.initialize(constraintAnnotation);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid(Integer value, ConstraintValidatorContext context) {
|
||||
ReportTemplateTypeEnum byType = ReportTemplateTypeEnum.fromType(value);
|
||||
if (ObjectUtil.isNotNull(byType)) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+2
-1
@@ -42,7 +42,8 @@ public abstract class ReportCommonServiceImplTest {
|
||||
.id(id)
|
||||
.name("单元测试数据源")
|
||||
.templateId(reportId)
|
||||
.type(ReportDatasourceTypeEnum.SPRING.getDesc())
|
||||
.dsType(ReportDatasourceTypeEnum.SPRING.getDesc())
|
||||
.type(ReportTemplateTypeEnum.SYSTEM.getType())
|
||||
.driver("com.mysql.cj.jdbc.Driver")
|
||||
.url("jdbc:mysql://192.168.1.205:3307/imes_base?allowMultiQueries=true&useUnicode=true&useSSL=false&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&autoReconnect=true&nullCatalogMeansCurrent=true")
|
||||
.username("root")
|
||||
|
||||
Reference in New Issue
Block a user