mirror of
http://192.168.1.205:9980/cf_devdept2/cf_imes_server.git
synced 2026-08-12 21:02:08 +08:00
报表基础模块:1、新增支持api数据源;2、新增超管模板操作权限;3、新增导入excel模板接口;4、移除数据源dsType,直接使用type类型;
This commit is contained in:
+3
-2
@@ -20,10 +20,11 @@ public class CompressStringTypeHandler extends StringTypeHandler {
|
|||||||
@Override
|
@Override
|
||||||
public void setNonNullParameter(PreparedStatement ps, int i, String parameter, JdbcType jdbcType)
|
public void setNonNullParameter(PreparedStatement ps, int i, String parameter, JdbcType jdbcType)
|
||||||
throws SQLException {
|
throws SQLException {
|
||||||
|
String compressString = null;
|
||||||
if (StringUtils.isNotEmpty(parameter)) {
|
if (StringUtils.isNotEmpty(parameter)) {
|
||||||
String compressString = JsonUtils.zipString(parameter);
|
compressString = JsonUtils.zipString(parameter);
|
||||||
ps.setString(i, compressString);
|
|
||||||
}
|
}
|
||||||
|
ps.setString(i, compressString);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
+2
-5
@@ -63,7 +63,7 @@ public class SecurityFrameworkUtils {
|
|||||||
public static Authentication getAuthentication() {
|
public static Authentication getAuthentication() {
|
||||||
SecurityContext context = SecurityContextHolder.getContext();
|
SecurityContext context = SecurityContextHolder.getContext();
|
||||||
if (context == null) {
|
if (context == null) {
|
||||||
return null;
|
throw new ServiceException(GlobalErrorCodeConstants.UNAUTHORIZED);
|
||||||
}
|
}
|
||||||
return context.getAuthentication();
|
return context.getAuthentication();
|
||||||
}
|
}
|
||||||
@@ -90,10 +90,7 @@ public class SecurityFrameworkUtils {
|
|||||||
@Nullable
|
@Nullable
|
||||||
public static Long getLoginUserId() {
|
public static Long getLoginUserId() {
|
||||||
LoginUser loginUser = getLoginUser();
|
LoginUser loginUser = getLoginUser();
|
||||||
if (loginUser == null) {
|
return loginUser != null ? loginUser.getId() : null;
|
||||||
throw new ServiceException(GlobalErrorCodeConstants.UNAUTHORIZED);
|
|
||||||
}
|
|
||||||
return loginUser.getId();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+1
-1
@@ -12,11 +12,11 @@ public final class ErrorCodeConstants {
|
|||||||
|
|
||||||
// ========== UREPORT template模块 1-003-001-000 ==========
|
// ========== UREPORT template模块 1-003-001-000 ==========
|
||||||
public static final ErrorCode TEMPLATE_NOT_EXISTS = new ErrorCode(1_003_001_001, "报表模板信息不存在");
|
public static final ErrorCode TEMPLATE_NOT_EXISTS = new ErrorCode(1_003_001_001, "报表模板信息不存在");
|
||||||
|
public static final ErrorCode DATATEMPLATE_BUILDIN_OPERATION_PERMISSION_ERROR = new ErrorCode(1_003_001_002, "内置模板操作权限不足");
|
||||||
|
|
||||||
// ========== UREPORT datasource模块 1-003-002-000 ==========
|
// ========== UREPORT datasource模块 1-003-002-000 ==========
|
||||||
public static final ErrorCode DATASOURCE_NOT_EXISTS = new ErrorCode(1_003_002_001, "报表数据源不存在");
|
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_002, "报表数据源连接失败");
|
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 ==========
|
// ========== UREPORT dataset模块 1-003-003-000 ==========
|
||||||
|
|||||||
+5
-5
@@ -37,14 +37,14 @@ public class ReportDatasetController {
|
|||||||
|
|
||||||
@PutMapping("/dataset")
|
@PutMapping("/dataset")
|
||||||
@Operation(summary = "创建报表数据集")
|
@Operation(summary = "创建报表数据集")
|
||||||
@PreAuthorize("@ss.hasPermission('report:dataset:create')")
|
// @PreAuthorize("@ss.hasPermission('report:dataset:create')")
|
||||||
public CommonResult<Long> createDataset(@Valid @RequestBody ReportDatasetSaveReqVO createReqVO) {
|
public CommonResult<Long> createDataset(@Valid @RequestBody ReportDatasetSaveReqVO createReqVO) {
|
||||||
return success(datasetService.createDataset(createReqVO));
|
return success(datasetService.createDataset(createReqVO));
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/dataset")
|
@PostMapping("/dataset")
|
||||||
@Operation(summary = "更新报表数据集")
|
@Operation(summary = "更新报表数据集")
|
||||||
@PreAuthorize("@ss.hasPermission('report:dataset:update')")
|
// @PreAuthorize("@ss.hasPermission('report:dataset:update')")
|
||||||
public CommonResult<Boolean> updateDataset(@Valid @RequestBody ReportDatasetSaveReqVO updateReqVO) {
|
public CommonResult<Boolean> updateDataset(@Valid @RequestBody ReportDatasetSaveReqVO updateReqVO) {
|
||||||
datasetService.updateDataset(updateReqVO);
|
datasetService.updateDataset(updateReqVO);
|
||||||
return success(true);
|
return success(true);
|
||||||
@@ -53,7 +53,7 @@ public class ReportDatasetController {
|
|||||||
@DeleteMapping("/dataset/{id}")
|
@DeleteMapping("/dataset/{id}")
|
||||||
@Operation(summary = "删除报表数据集")
|
@Operation(summary = "删除报表数据集")
|
||||||
@Parameter(name = "id", description = "编号", required = true)
|
@Parameter(name = "id", description = "编号", required = true)
|
||||||
@PreAuthorize("@ss.hasPermission('report:dataset:delete')")
|
// @PreAuthorize("@ss.hasPermission('report:dataset:delete')")
|
||||||
public CommonResult<Boolean> deleteDataset(@PathVariable("id") Long id) {
|
public CommonResult<Boolean> deleteDataset(@PathVariable("id") Long id) {
|
||||||
datasetService.deleteDataset(id);
|
datasetService.deleteDataset(id);
|
||||||
return success(true);
|
return success(true);
|
||||||
@@ -62,7 +62,7 @@ public class ReportDatasetController {
|
|||||||
@GetMapping("/dataset/{id}")
|
@GetMapping("/dataset/{id}")
|
||||||
@Operation(summary = "获得报表数据集")
|
@Operation(summary = "获得报表数据集")
|
||||||
@Parameter(name = "id", description = "编号", required = true, example = "1")
|
@Parameter(name = "id", description = "编号", required = true, example = "1")
|
||||||
@PreAuthorize("@ss.hasPermission('report:dataset:query')")
|
// @PreAuthorize("@ss.hasPermission('report:dataset:query')")
|
||||||
public CommonResult<ReportDatasetRespVO> getDataset(@PathVariable("id") Long id) {
|
public CommonResult<ReportDatasetRespVO> getDataset(@PathVariable("id") Long id) {
|
||||||
ReportDatasetDO dataset = datasetService.getDataset(id);
|
ReportDatasetDO dataset = datasetService.getDataset(id);
|
||||||
return success(BeanUtils.toBean(dataset, ReportDatasetRespVO.class));
|
return success(BeanUtils.toBean(dataset, ReportDatasetRespVO.class));
|
||||||
@@ -70,7 +70,7 @@ public class ReportDatasetController {
|
|||||||
|
|
||||||
@GetMapping("/datasets")
|
@GetMapping("/datasets")
|
||||||
@Operation(summary = "获取数据源下的报表数据集列表")
|
@Operation(summary = "获取数据源下的报表数据集列表")
|
||||||
@PreAuthorize("@ss.hasPermission('report:dataset:query')")
|
// @PreAuthorize("@ss.hasPermission('report:dataset:query')")
|
||||||
public CommonResult<List<ReportDatasetRespVO>> getDatasetPage(@RequestParam(value = "datasourceId") Long datasourceId,
|
public CommonResult<List<ReportDatasetRespVO>> getDatasetPage(@RequestParam(value = "datasourceId") Long datasourceId,
|
||||||
@RequestParam(value = "name", required = false) String name) {
|
@RequestParam(value = "name", required = false) String name) {
|
||||||
ReportDatasetReqVO reqVO = new ReportDatasetReqVO(name, datasourceId);
|
ReportDatasetReqVO reqVO = new ReportDatasetReqVO(name, datasourceId);
|
||||||
|
|||||||
+11
-11
@@ -43,14 +43,14 @@ public class ReportDatasourceController {
|
|||||||
|
|
||||||
@PutMapping("/datasource")
|
@PutMapping("/datasource")
|
||||||
@Operation(summary = "创建报表数据源")
|
@Operation(summary = "创建报表数据源")
|
||||||
@PreAuthorize("@ss.hasPermission('report:datasource:create')")
|
// @PreAuthorize("@ss.hasPermission('report:datasource:create')")
|
||||||
public CommonResult<Long> createDatasource(@Valid @RequestBody ReportDatasourceSaveReqVO createReqVO) {
|
public CommonResult<Long> createDatasource(@Valid @RequestBody ReportDatasourceSaveReqVO createReqVO) {
|
||||||
return success(datasourceService.createDatasource(createReqVO));
|
return success(datasourceService.createDatasource(createReqVO));
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/datasource")
|
@PostMapping("/datasource")
|
||||||
@Operation(summary = "更新报表数据源")
|
@Operation(summary = "更新报表数据源")
|
||||||
@PreAuthorize("@ss.hasPermission('report:datasource:update')")
|
// @PreAuthorize("@ss.hasPermission('report:datasource:update')")
|
||||||
public CommonResult<Boolean> updateDatasource(@Valid @RequestBody ReportDatasourceSaveReqVO updateReqVO) {
|
public CommonResult<Boolean> updateDatasource(@Valid @RequestBody ReportDatasourceSaveReqVO updateReqVO) {
|
||||||
datasourceService.updateDatasource(updateReqVO);
|
datasourceService.updateDatasource(updateReqVO);
|
||||||
return success(true);
|
return success(true);
|
||||||
@@ -59,7 +59,7 @@ public class ReportDatasourceController {
|
|||||||
@DeleteMapping("/datasource/{id}")
|
@DeleteMapping("/datasource/{id}")
|
||||||
@Operation(summary = "删除报表数据源")
|
@Operation(summary = "删除报表数据源")
|
||||||
@Parameter(name = "id", description = "编号", required = true, example = "1")
|
@Parameter(name = "id", description = "编号", required = true, example = "1")
|
||||||
@PreAuthorize("@ss.hasPermission('report:datasource:delete')")
|
// @PreAuthorize("@ss.hasPermission('report:datasource:delete')")
|
||||||
public CommonResult<Boolean> deleteDatasource(@PathVariable("id") Long id) {
|
public CommonResult<Boolean> deleteDatasource(@PathVariable("id") Long id) {
|
||||||
datasourceService.deleteDatasource(id);
|
datasourceService.deleteDatasource(id);
|
||||||
return success(true);
|
return success(true);
|
||||||
@@ -68,7 +68,7 @@ public class ReportDatasourceController {
|
|||||||
@GetMapping("/datasource/{id}")
|
@GetMapping("/datasource/{id}")
|
||||||
@Operation(summary = "获取报表数据源")
|
@Operation(summary = "获取报表数据源")
|
||||||
@Parameter(name = "id", description = "编号", required = true, example = "1")
|
@Parameter(name = "id", description = "编号", required = true, example = "1")
|
||||||
@PreAuthorize("@ss.hasPermission('report:datasource:query')")
|
// @PreAuthorize("@ss.hasPermission('report:datasource:query')")
|
||||||
public CommonResult<ReportDatasourceRespVO> getDatasource(@PathVariable("id") Long id) {
|
public CommonResult<ReportDatasourceRespVO> getDatasource(@PathVariable("id") Long id) {
|
||||||
ReportDatasourceDO datasource = datasourceService.getDatasource(id);
|
ReportDatasourceDO datasource = datasourceService.getDatasource(id);
|
||||||
return success(BeanUtils.toBean(datasource, ReportDatasourceRespVO.class));
|
return success(BeanUtils.toBean(datasource, ReportDatasourceRespVO.class));
|
||||||
@@ -76,35 +76,35 @@ public class ReportDatasourceController {
|
|||||||
|
|
||||||
@GetMapping("/{templateId}/datasources")
|
@GetMapping("/{templateId}/datasources")
|
||||||
@Operation(summary = "获取报表模板下的报表数据源")
|
@Operation(summary = "获取报表模板下的报表数据源")
|
||||||
@PreAuthorize("@ss.hasPermission('report:datasource:query')")
|
// @PreAuthorize("@ss.hasPermission('report:datasource:query')")
|
||||||
public CommonResult<List<ReportDatasourceRespVO>> getDatasourcePage(@PathVariable(value = "templateId") Long templateId) {
|
public CommonResult<List<ReportDatasourceRespVO>> getDatasourcePage(@PathVariable(value = "templateId") Long templateId) {
|
||||||
return success(BeanUtils.toBean(datasourceService.getTemplateDatasourceList(ReportDatasourceReqVO.builder().templateId(templateId).build()), ReportDatasourceRespVO.class));
|
return success(BeanUtils.toBean(datasourceService.getTemplateDatasourceList(ReportDatasourceReqVO.builder().templateId(templateId).build()), ReportDatasourceRespVO.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/datasource/beans")
|
@GetMapping("/datasource/beans")
|
||||||
@Operation(summary = "获取springbean数据源列表")
|
@Operation(summary = "获取springbean数据源列表")
|
||||||
@PreAuthorize("@ss.hasPermission('report:datasource:query')")
|
// @PreAuthorize("@ss.hasPermission('report:datasource:query')")
|
||||||
public CommonResult<List<ReportBeanDatasourceRespVO>> getBeanDatasourceList() {
|
public CommonResult<List<ReportBeanDatasourceRespVO>> getBeanDatasourceList() {
|
||||||
return success(datasourceService.getBeanDatasourceList());
|
return success(datasourceService.getBeanDatasourceList());
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/datasource/bean/methods")
|
@GetMapping("/datasource/bean/methods")
|
||||||
@Operation(summary = "获取springbean数据源方法类表")
|
@Operation(summary = "获取springbean数据源方法类表")
|
||||||
@PreAuthorize("@ss.hasPermission('report:datasource:query')")
|
// @PreAuthorize("@ss.hasPermission('report:datasource:query')")
|
||||||
public CommonResult<List<String>> getBeanDatasourceList(@RequestParam(value = "beanId") String beanId) {
|
public CommonResult<List<String>> getBeanDatasourceList(@RequestParam(value = "beanId") String beanId) {
|
||||||
return success(datasourceService.loadBeanMethods(beanId));
|
return success(datasourceService.loadBeanMethods(beanId));
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/buildin/datasources")
|
@GetMapping("/buildin/datasources")
|
||||||
@Operation(summary = "获取内置数据源")
|
@Operation(summary = "获取内置数据源")
|
||||||
@PreAuthorize("@ss.hasPermission('report:datasource:query')")
|
// @PreAuthorize("@ss.hasPermission('report:datasource:query')")
|
||||||
public CommonResult<List<ReportDatasourceRespVO>> getBuildinDatasources() {
|
public CommonResult<List<ReportDatasourceRespVO>> getBuildinDatasources() {
|
||||||
return success(BeanUtils.toBean(datasourceService.getBuildinDatasources(), ReportDatasourceRespVO.class));
|
return success(BeanUtils.toBean(datasourceService.getBuildinDatasources(), ReportDatasourceRespVO.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/datasource/connect")
|
@PostMapping("/datasource/connect")
|
||||||
@Operation(summary = "测试数据源连接")
|
@Operation(summary = "测试数据源连接")
|
||||||
@PreAuthorize("@ss.hasPermission('report:datasource:query')")
|
// @PreAuthorize("@ss.hasPermission('report:datasource:query')")
|
||||||
public CommonResult<Boolean> testDatasourceConnect(@RequestBody ReportDatasourceTestConnReqVO reqVO) {
|
public CommonResult<Boolean> testDatasourceConnect(@RequestBody ReportDatasourceTestConnReqVO reqVO) {
|
||||||
boolean connResult = datasourceService.testConnect(reqVO);
|
boolean connResult = datasourceService.testConnect(reqVO);
|
||||||
return connResult ? success(true) : error(DATASOURCE_CONNECT_FAIL);
|
return connResult ? success(true) : error(DATASOURCE_CONNECT_FAIL);
|
||||||
@@ -112,14 +112,14 @@ public class ReportDatasourceController {
|
|||||||
|
|
||||||
@PostMapping("/datasource/tables")
|
@PostMapping("/datasource/tables")
|
||||||
@Operation(summary = "获取数据源表列表")
|
@Operation(summary = "获取数据源表列表")
|
||||||
@PreAuthorize("@ss.hasPermission('report:datasource:query')")
|
// @PreAuthorize("@ss.hasPermission('report:datasource:query')")
|
||||||
public CommonResult<List<Map<String, String>>> getDatasourceTables(@RequestBody ReportDatasourceTestConnReqVO reqVO) {
|
public CommonResult<List<Map<String, String>>> getDatasourceTables(@RequestBody ReportDatasourceTestConnReqVO reqVO) {
|
||||||
return success(datasourceService.getDatasourceTables(reqVO));
|
return success(datasourceService.getDatasourceTables(reqVO));
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/datasource/table/fields")
|
@PostMapping("/datasource/table/fields")
|
||||||
@Operation(summary = "获取数据源表字段")
|
@Operation(summary = "获取数据源表字段")
|
||||||
@PreAuthorize("@ss.hasPermission('report:datasource:query')")
|
// @PreAuthorize("@ss.hasPermission('report:datasource:query')")
|
||||||
public CommonResult<List<ReportDatasetFieldVO>> getDatasourceTableFields(@RequestBody ReportDatasourceTestConnReqVO reqVO) {
|
public CommonResult<List<ReportDatasetFieldVO>> getDatasourceTableFields(@RequestBody ReportDatasourceTestConnReqVO reqVO) {
|
||||||
return success(datasourceService.getTableFields(reqVO));
|
return success(datasourceService.getTableFields(reqVO));
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-5
@@ -1,13 +1,13 @@
|
|||||||
package com.cf.imes.module.report.controller.admin.datasource.vo;
|
package com.cf.imes.module.report.controller.admin.datasource.vo;
|
||||||
|
|
||||||
import com.cf.imes.module.report.controller.admin.dataset.vo.ReportDatasetRespVO;
|
import com.cf.imes.module.report.controller.admin.dataset.vo.ReportDatasetRespVO;
|
||||||
import com.cf.imes.module.report.enums.datasource.ReportDatasourceTypeEnum;
|
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Gqr
|
* @author Gqr
|
||||||
@@ -28,10 +28,7 @@ public class ReportDatasourceRespVO {
|
|||||||
@Schema(description = "数据源名称", example = "测试库")
|
@Schema(description = "数据源名称", example = "测试库")
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
@Schema(description = "数据源类型,jdbc、spring", example = "jdbc")
|
@Schema(description = "数据源类型,0jdbc、1spring、2buildin、3api", example = "0")
|
||||||
private ReportDatasourceTypeEnum dsType;
|
|
||||||
|
|
||||||
@Schema(description = "模板类型,0内置、1自定义", example = "0")
|
|
||||||
private Integer type;
|
private Integer type;
|
||||||
|
|
||||||
@Schema(description = "数据源驱动类",example = "com.mysql.cj.jdbc.Driver")
|
@Schema(description = "数据源驱动类",example = "com.mysql.cj.jdbc.Driver")
|
||||||
@@ -51,4 +48,7 @@ public class ReportDatasourceRespVO {
|
|||||||
|
|
||||||
@Schema(description = "数据集")
|
@Schema(description = "数据集")
|
||||||
private List<ReportDatasetRespVO> datasets;
|
private List<ReportDatasetRespVO> datasets;
|
||||||
|
|
||||||
|
@Schema(description = "请求头参数")
|
||||||
|
private List<Map<String, String>> headers;
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-7
@@ -2,7 +2,6 @@ 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.controller.admin.dataset.vo.ReportDatasetSaveReqVO;
|
||||||
import com.cf.imes.module.report.validation.datasource.ReportDatasourceTypeInEnum;
|
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 io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
@@ -13,6 +12,7 @@ import java.io.Serial;
|
|||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Gqr
|
* @author Gqr
|
||||||
@@ -36,13 +36,9 @@ public class ReportDatasourceSaveReqVO implements Serializable {
|
|||||||
@Schema(description = "数据源名称", example = "测试库")
|
@Schema(description = "数据源名称", example = "测试库")
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
@Schema(description = "模板类型,0内置、1自定义", example = "1")
|
@Schema(description = "数据源类型,0jdbc、1spring、2buildin、3api", example = "1")
|
||||||
@ReportTemplateTypeInEnum
|
|
||||||
private Integer type;
|
|
||||||
|
|
||||||
@Schema(description = "数据源类型,jdbc、spring", example = "jdbc")
|
|
||||||
@ReportDatasourceTypeInEnum
|
@ReportDatasourceTypeInEnum
|
||||||
private String dsType;
|
private String type;
|
||||||
|
|
||||||
@Schema(description = "spring型数据源id")
|
@Schema(description = "spring型数据源id")
|
||||||
private String beanId;
|
private String beanId;
|
||||||
@@ -64,4 +60,7 @@ public class ReportDatasourceSaveReqVO implements Serializable {
|
|||||||
|
|
||||||
@Schema(description = "数据集")
|
@Schema(description = "数据集")
|
||||||
private List<ReportDatasetSaveReqVO> datasets = new ArrayList<>();
|
private List<ReportDatasetSaveReqVO> datasets = new ArrayList<>();
|
||||||
|
|
||||||
|
@Schema(description = "请求头参数")
|
||||||
|
private List<Map<String, String>> headers;
|
||||||
}
|
}
|
||||||
|
|||||||
+24
-7
@@ -1,10 +1,13 @@
|
|||||||
package com.cf.imes.module.report.controller.admin.template;
|
package com.cf.imes.module.report.controller.admin.template;
|
||||||
|
|
||||||
import com.bstek.designer.bean.ReportDefinitionWrapper;
|
import com.bstek.designer.bean.ReportDefinitionWrapper;
|
||||||
|
import com.bstek.designer.excel.ExcelParserUtils;
|
||||||
|
import com.bstek.ureport.definition.ReportDefinition;
|
||||||
import com.bstek.ureport.export.ExportUtils;
|
import com.bstek.ureport.export.ExportUtils;
|
||||||
import com.bstek.ureport.export.ProducerEnum;
|
import com.bstek.ureport.export.ProducerEnum;
|
||||||
import com.bstek.ureport.export.html.HtmlReport;
|
import com.bstek.ureport.export.html.HtmlReport;
|
||||||
import com.bstek.ureport.model.Report;
|
import com.bstek.ureport.model.Report;
|
||||||
|
import com.cf.imes.framework.common.exception.ServiceException;
|
||||||
import com.cf.imes.framework.common.pojo.CommonResult;
|
import com.cf.imes.framework.common.pojo.CommonResult;
|
||||||
import com.cf.imes.framework.common.util.object.BeanUtils;
|
import com.cf.imes.framework.common.util.object.BeanUtils;
|
||||||
import com.cf.imes.module.report.api.template.dto.ReportTemplateGenerateReqDTO;
|
import com.cf.imes.module.report.api.template.dto.ReportTemplateGenerateReqDTO;
|
||||||
@@ -18,9 +21,11 @@ import io.swagger.v3.oas.annotations.Parameter;
|
|||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.io.IOUtils;
|
import org.apache.commons.io.IOUtils;
|
||||||
|
import org.apache.http.HttpStatus;
|
||||||
import org.springframework.security.access.prepost.PreAuthorize;
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
@@ -48,14 +53,14 @@ public class ReportTemplateController {
|
|||||||
|
|
||||||
@PutMapping("/template")
|
@PutMapping("/template")
|
||||||
@Operation(summary = "创建报表模板信息")
|
@Operation(summary = "创建报表模板信息")
|
||||||
@PreAuthorize("@ss.hasPermission('report:template:create')")
|
// @PreAuthorize("@ss.hasPermission('report:template:create')")
|
||||||
public CommonResult<Long> createTemplate(@Valid @RequestBody ReportTemplateSaveReqVO createReqVO) {
|
public CommonResult<Long> createTemplate(@Valid @RequestBody ReportTemplateSaveReqVO createReqVO) {
|
||||||
return success(templateService.createReportTemplate(createReqVO));
|
return success(templateService.createReportTemplate(createReqVO));
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/template")
|
@PostMapping("/template")
|
||||||
@Operation(summary = "更新报表模板信息")
|
@Operation(summary = "更新报表模板信息")
|
||||||
@PreAuthorize("@ss.hasPermission('report:template:update')")
|
// @PreAuthorize("@ss.hasPermission('report:template:update')")
|
||||||
public CommonResult<Boolean> updateTemplate(@Valid @RequestBody ReportTemplateSaveReqVO updateReqVO) {
|
public CommonResult<Boolean> updateTemplate(@Valid @RequestBody ReportTemplateSaveReqVO updateReqVO) {
|
||||||
templateService.updateReportTemplate(updateReqVO);
|
templateService.updateReportTemplate(updateReqVO);
|
||||||
return success(true);
|
return success(true);
|
||||||
@@ -64,7 +69,7 @@ public class ReportTemplateController {
|
|||||||
@DeleteMapping("/template/{id}")
|
@DeleteMapping("/template/{id}")
|
||||||
@Operation(summary = "删除报表模板信息")
|
@Operation(summary = "删除报表模板信息")
|
||||||
@Parameter(name = "id", description = "编号", required = true)
|
@Parameter(name = "id", description = "编号", required = true)
|
||||||
@PreAuthorize("@ss.hasPermission('report:template:delete')")
|
// @PreAuthorize("@ss.hasPermission('report:template:delete')")
|
||||||
public CommonResult<Boolean> deleteReportTemplate(@PathVariable("id") Long id) {
|
public CommonResult<Boolean> deleteReportTemplate(@PathVariable("id") Long id) {
|
||||||
templateService.deleteReportTemplate(id);
|
templateService.deleteReportTemplate(id);
|
||||||
return success(true);
|
return success(true);
|
||||||
@@ -73,14 +78,14 @@ public class ReportTemplateController {
|
|||||||
@GetMapping("/template/{id}")
|
@GetMapping("/template/{id}")
|
||||||
@Operation(summary = "获取报表模板信息")
|
@Operation(summary = "获取报表模板信息")
|
||||||
@Parameter(name = "id", description = "编号", required = true, example = "1")
|
@Parameter(name = "id", description = "编号", required = true, example = "1")
|
||||||
@PreAuthorize("@ss.hasPermission('report:template:query')")
|
// @PreAuthorize("@ss.hasPermission('report:template:query')")
|
||||||
public CommonResult<ReportDefinitionWrapper> getReportTemplate(@PathVariable("id") Long id) {
|
public CommonResult<ReportDefinitionWrapper> getReportTemplate(@PathVariable("id") Long id) {
|
||||||
return success(templateService.getReportTemplateDefinition(id));
|
return success(templateService.getReportTemplateDefinition(id));
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/templates")
|
@GetMapping("/templates")
|
||||||
@Operation(summary = "获取报表模板信息列表")
|
@Operation(summary = "获取报表模板信息列表")
|
||||||
@PreAuthorize("@ss.hasPermission('report:template:query')")
|
// @PreAuthorize("@ss.hasPermission('report:template:query')")
|
||||||
public CommonResult<List<ReportTemplateRespVO>> getTemplatePage(@RequestParam(value = "name", required = false) String name) {
|
public CommonResult<List<ReportTemplateRespVO>> getTemplatePage(@RequestParam(value = "name", required = false) String name) {
|
||||||
ReportTemplateReqVO reqVO = new ReportTemplateReqVO(name, null);
|
ReportTemplateReqVO reqVO = new ReportTemplateReqVO(name, null);
|
||||||
return success(BeanUtils.toBean(templateService.getReportTemplateList(reqVO), ReportTemplateRespVO.class));
|
return success(BeanUtils.toBean(templateService.getReportTemplateList(reqVO), ReportTemplateRespVO.class));
|
||||||
@@ -88,14 +93,14 @@ public class ReportTemplateController {
|
|||||||
|
|
||||||
@PostMapping("/template/preview")
|
@PostMapping("/template/preview")
|
||||||
@Operation(summary = "模板预览")
|
@Operation(summary = "模板预览")
|
||||||
@PreAuthorize("@ss.hasPermission('report:template:query')")
|
// @PreAuthorize("@ss.hasPermission('report:template:query')")
|
||||||
public CommonResult<HtmlReport> preview(@Valid @RequestBody ReportTemplatePreviewPageParametersVO pageParametersVO) {
|
public CommonResult<HtmlReport> preview(@Valid @RequestBody ReportTemplatePreviewPageParametersVO pageParametersVO) {
|
||||||
return success(templateService.preview(pageParametersVO));
|
return success(templateService.preview(pageParametersVO));
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/template/export")
|
@PostMapping("/template/export")
|
||||||
@Operation(summary = "模板导出")
|
@Operation(summary = "模板导出")
|
||||||
@PreAuthorize("@ss.hasPermission('report:template:query')")
|
// @PreAuthorize("@ss.hasPermission('report:template:query')")
|
||||||
public void generateTemplate(@Valid @RequestBody ReportTemplateGenerateReqDTO reqDTO, HttpServletResponse response) {
|
public void generateTemplate(@Valid @RequestBody ReportTemplateGenerateReqDTO reqDTO, HttpServletResponse response) {
|
||||||
OutputStream out = null;
|
OutputStream out = null;
|
||||||
try {
|
try {
|
||||||
@@ -109,4 +114,16 @@ public class ReportTemplateController {
|
|||||||
IOUtils.closeQuietly(out);
|
IOUtils.closeQuietly(out);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("/template/excel/import")
|
||||||
|
@Operation(summary = "导入excel模板")
|
||||||
|
// @PreAuthorize("@ss.hasPermission('report:template:import')")
|
||||||
|
public ReportDefinitionWrapper importExcel(@RequestParam("file") MultipartFile file) {
|
||||||
|
ReportDefinition report = ExcelParserUtils.parser(file);
|
||||||
|
if (report != null) {
|
||||||
|
report.setReportFullName("");
|
||||||
|
return new ReportDefinitionWrapper(report);
|
||||||
|
}
|
||||||
|
throw new ServiceException(HttpStatus.SC_INTERNAL_SERVER_ERROR, "文件未识别");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+13
-8
@@ -5,12 +5,18 @@ import com.baomidou.mybatisplus.annotation.TableField;
|
|||||||
import com.baomidou.mybatisplus.annotation.TableId;
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
import com.cf.imes.framework.mybatis.core.dataobject.BaseDO;
|
import com.cf.imes.framework.mybatis.core.dataobject.BaseDO;
|
||||||
|
import com.cf.imes.framework.mybatis.core.type.CompressObjectListTypeHandler;
|
||||||
import com.cf.imes.module.report.dal.dataobject.dataset.ReportDatasetDO;
|
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.datasource.ReportDatasourceTypeEnum;
|
||||||
import com.cf.imes.module.report.enums.template.ReportTemplateTypeEnum;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.*;
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.ToString;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 报表数据源DO
|
* 报表数据源DO
|
||||||
@@ -18,7 +24,7 @@ import java.util.List;
|
|||||||
* @author Gqr
|
* @author Gqr
|
||||||
* @since 2024/7/8 11:01
|
* @since 2024/7/8 11:01
|
||||||
*/
|
*/
|
||||||
@TableName("report_datasource")
|
@TableName(value = "report_datasource", autoResultMap = true)
|
||||||
@KeySequence("report_datasource_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
|
@KeySequence("report_datasource_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
|
||||||
@Data
|
@Data
|
||||||
@EqualsAndHashCode(callSuper = true)
|
@EqualsAndHashCode(callSuper = true)
|
||||||
@@ -40,15 +46,11 @@ public class ReportDatasourceDO extends BaseDO {
|
|||||||
* 数据源名称
|
* 数据源名称
|
||||||
*/
|
*/
|
||||||
private String name;
|
private String name;
|
||||||
/**
|
|
||||||
* 模板类型,jdbc、spring
|
|
||||||
*/
|
|
||||||
private ReportDatasourceTypeEnum dsType;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 模板类型,0内置、1自定义
|
* 模板类型,0内置、1自定义
|
||||||
*/
|
*/
|
||||||
private ReportTemplateTypeEnum type;
|
private ReportDatasourceTypeEnum type;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* spring型数据源id
|
* spring型数据源id
|
||||||
@@ -84,4 +86,7 @@ public class ReportDatasourceDO extends BaseDO {
|
|||||||
*/
|
*/
|
||||||
@TableField(exist = false)
|
@TableField(exist = false)
|
||||||
private List<ReportDatasetDO> datasets;
|
private List<ReportDatasetDO> datasets;
|
||||||
|
|
||||||
|
@TableField(typeHandler = CompressObjectListTypeHandler.class)
|
||||||
|
private List<Map<String, String>> headers;
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-2
@@ -13,8 +13,10 @@ import lombok.Getter;
|
|||||||
@Getter
|
@Getter
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public enum ReportDatasourceTypeEnum {
|
public enum ReportDatasourceTypeEnum {
|
||||||
JDBC(0,"jdbc"),
|
JDBC(0, "jdbc"),
|
||||||
SPRING(1,"spring");
|
SPRING(1, "spring"),
|
||||||
|
BUILDIN(2, "buildin"),
|
||||||
|
API(3, "api");
|
||||||
|
|
||||||
@EnumValue
|
@EnumValue
|
||||||
private final Integer code;
|
private final Integer code;
|
||||||
|
|||||||
+2
-52
@@ -12,8 +12,6 @@ import com.cf.imes.framework.common.exception.ServiceException;
|
|||||||
import com.cf.imes.framework.common.util.object.BeanUtils;
|
import com.cf.imes.framework.common.util.object.BeanUtils;
|
||||||
import com.cf.imes.framework.mybatis.core.query.LambdaQueryWrapperX;
|
import com.cf.imes.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||||
import com.cf.imes.framework.organ.core.aop.OrganIgnore;
|
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.ReportDatasetFieldVO;
|
||||||
import com.cf.imes.module.report.controller.admin.dataset.vo.ReportDatasetParameterVO;
|
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.dataset.vo.ReportDatasetReqVO;
|
||||||
@@ -58,7 +56,6 @@ 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_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_INJECTION_RISK;
|
||||||
import static com.cf.imes.module.report.enums.ErrorCodeConstants.DATASET_SQL_REQUIRED;
|
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;
|
import static com.cf.imes.module.report.enums.ErrorCodeConstants.DATASOURCE_NOT_EXISTS;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -89,12 +86,8 @@ public class ReportDatasourceServiceImpl implements ReportDatasourceService {
|
|||||||
@Override
|
@Override
|
||||||
public Long createDatasource(ReportDatasourceSaveReqVO createReqVO) {
|
public Long createDatasource(ReportDatasourceSaveReqVO createReqVO) {
|
||||||
ReportDatasourceDO datasource = BeanUtils.toBean(createReqVO, ReportDatasourceDO.class);
|
ReportDatasourceDO datasource = BeanUtils.toBean(createReqVO, ReportDatasourceDO.class);
|
||||||
// 校验内置数据源操作权限
|
|
||||||
validateBuildinsource(datasource);
|
|
||||||
// 插入
|
// 插入
|
||||||
datasourceMapper.insert(datasource);
|
datasourceMapper.insert(datasource);
|
||||||
// 解析数据集
|
|
||||||
analyzeDataset(datasource);
|
|
||||||
// 返回
|
// 返回
|
||||||
return datasource.getId();
|
return datasource.getId();
|
||||||
}
|
}
|
||||||
@@ -104,54 +97,10 @@ public class ReportDatasourceServiceImpl implements ReportDatasourceService {
|
|||||||
// 校验存在
|
// 校验存在
|
||||||
validateDatasourceExists(updateReqVO.getId());
|
validateDatasourceExists(updateReqVO.getId());
|
||||||
ReportDatasourceDO updateObj = BeanUtils.toBean(updateReqVO, ReportDatasourceDO.class);
|
ReportDatasourceDO updateObj = BeanUtils.toBean(updateReqVO, ReportDatasourceDO.class);
|
||||||
// 校验内置数据源操作权限
|
|
||||||
validateBuildinsource(updateObj);
|
|
||||||
// 更新
|
// 更新
|
||||||
datasourceMapper.updateById(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
|
@Override
|
||||||
public void deleteDatasource(Long id) {
|
public void deleteDatasource(Long id) {
|
||||||
@@ -159,6 +108,8 @@ public class ReportDatasourceServiceImpl implements ReportDatasourceService {
|
|||||||
validateDatasourceExists(id);
|
validateDatasourceExists(id);
|
||||||
// 删除
|
// 删除
|
||||||
datasourceMapper.deleteById(id);
|
datasourceMapper.deleteById(id);
|
||||||
|
// 删除关联数据集
|
||||||
|
datasetMapper.delete(new LambdaQueryWrapperX<ReportDatasetDO>().eq(ReportDatasetDO::getDatasourceId, id));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -185,7 +136,6 @@ public class ReportDatasourceServiceImpl implements ReportDatasourceService {
|
|||||||
List<ReportDatasourceDO> reportDatasourceDOS = datasourceMapper.selectList(new LambdaQueryWrapperX<ReportDatasourceDO>()
|
List<ReportDatasourceDO> reportDatasourceDOS = datasourceMapper.selectList(new LambdaQueryWrapperX<ReportDatasourceDO>()
|
||||||
.eqIfPresent(ReportDatasourceDO::getTemplateId, reqVO.getTemplateId())
|
.eqIfPresent(ReportDatasourceDO::getTemplateId, reqVO.getTemplateId())
|
||||||
.likeIfPresent(ReportDatasourceDO::getName, reqVO.getName())
|
.likeIfPresent(ReportDatasourceDO::getName, reqVO.getName())
|
||||||
.eqIfPresent(ReportDatasourceDO::getDsType, reqVO.getType())
|
|
||||||
.orderByDesc(ReportDatasourceDO::getCreateTime));
|
.orderByDesc(ReportDatasourceDO::getCreateTime));
|
||||||
// 查询数据集
|
// 查询数据集
|
||||||
if (CollUtil.isNotEmpty(reportDatasourceDOS)) {
|
if (CollUtil.isNotEmpty(reportDatasourceDOS)) {
|
||||||
|
|||||||
+80
-10
@@ -5,15 +5,18 @@ import cn.hutool.core.collection.CollUtil;
|
|||||||
import cn.hutool.core.util.CharsetUtil;
|
import cn.hutool.core.util.CharsetUtil;
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
import cn.hutool.core.util.URLUtil;
|
import cn.hutool.core.util.URLUtil;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.bstek.designer.bean.PreviewPageParameters;
|
import com.bstek.designer.bean.PreviewPageParameters;
|
||||||
import com.bstek.designer.bean.PreviewParameters;
|
import com.bstek.designer.bean.PreviewParameters;
|
||||||
import com.bstek.designer.bean.ReportDefinitionWrapper;
|
import com.bstek.designer.bean.ReportDefinitionWrapper;
|
||||||
import com.bstek.ureport.build.paging.Page;
|
import com.bstek.ureport.build.paging.Page;
|
||||||
import com.bstek.ureport.definition.Paper;
|
import com.bstek.ureport.definition.Paper;
|
||||||
import com.bstek.ureport.definition.ReportDefinition;
|
import com.bstek.ureport.definition.ReportDefinition;
|
||||||
|
import com.bstek.ureport.definition.dataset.ApiDatasetDefinition;
|
||||||
import com.bstek.ureport.definition.dataset.BeanDatasetDefinition;
|
import com.bstek.ureport.definition.dataset.BeanDatasetDefinition;
|
||||||
import com.bstek.ureport.definition.dataset.DatasetDefinition;
|
import com.bstek.ureport.definition.dataset.DatasetDefinition;
|
||||||
import com.bstek.ureport.definition.dataset.SqlDatasetDefinition;
|
import com.bstek.ureport.definition.dataset.SqlDatasetDefinition;
|
||||||
|
import com.bstek.ureport.definition.datasource.ApiDatasourceDefinition;
|
||||||
import com.bstek.ureport.definition.datasource.DatasourceDefinition;
|
import com.bstek.ureport.definition.datasource.DatasourceDefinition;
|
||||||
import com.bstek.ureport.definition.datasource.JdbcDatasourceDefinition;
|
import com.bstek.ureport.definition.datasource.JdbcDatasourceDefinition;
|
||||||
import com.bstek.ureport.definition.datasource.SpringBeanDatasourceDefinition;
|
import com.bstek.ureport.definition.datasource.SpringBeanDatasourceDefinition;
|
||||||
@@ -27,6 +30,9 @@ import com.bstek.ureport.model.Report;
|
|||||||
import com.bstek.ureport.parser.ReportParser;
|
import com.bstek.ureport.parser.ReportParser;
|
||||||
import com.cf.imes.framework.common.util.object.BeanUtils;
|
import com.cf.imes.framework.common.util.object.BeanUtils;
|
||||||
import com.cf.imes.framework.mybatis.core.query.LambdaQueryWrapperX;
|
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.api.template.dto.ReportTemplateGenerateReqDTO;
|
import com.cf.imes.module.report.api.template.dto.ReportTemplateGenerateReqDTO;
|
||||||
import com.cf.imes.module.report.controller.admin.dataset.vo.ReportDatasetReqVO;
|
import com.cf.imes.module.report.controller.admin.dataset.vo.ReportDatasetReqVO;
|
||||||
import com.cf.imes.module.report.controller.admin.dataset.vo.ReportDatasetSaveReqVO;
|
import com.cf.imes.module.report.controller.admin.dataset.vo.ReportDatasetSaveReqVO;
|
||||||
@@ -38,7 +44,10 @@ import com.cf.imes.module.report.controller.admin.template.vo.ReportTemplateSave
|
|||||||
import com.cf.imes.module.report.dal.dataobject.dataset.ReportDatasetDO;
|
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.dataobject.datasource.ReportDatasourceDO;
|
||||||
import com.cf.imes.module.report.dal.dataobject.template.ReportTemplateDO;
|
import com.cf.imes.module.report.dal.dataobject.template.ReportTemplateDO;
|
||||||
|
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.dal.mysql.template.ReportTemplateMapper;
|
import com.cf.imes.module.report.dal.mysql.template.ReportTemplateMapper;
|
||||||
|
import com.cf.imes.module.report.enums.template.ReportTemplateTypeEnum;
|
||||||
import com.cf.imes.module.report.service.dataset.ReportDatasetService;
|
import com.cf.imes.module.report.service.dataset.ReportDatasetService;
|
||||||
import com.cf.imes.module.report.service.datasource.ReportDatasourceService;
|
import com.cf.imes.module.report.service.datasource.ReportDatasourceService;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
@@ -54,6 +63,7 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import static com.cf.imes.framework.common.exception.util.ServiceExceptionUtil.exception;
|
import static com.cf.imes.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||||
|
import static com.cf.imes.module.report.enums.ErrorCodeConstants.DATATEMPLATE_BUILDIN_OPERATION_PERMISSION_ERROR;
|
||||||
import static com.cf.imes.module.report.enums.ErrorCodeConstants.TEMPLATE_NOT_EXISTS;
|
import static com.cf.imes.module.report.enums.ErrorCodeConstants.TEMPLATE_NOT_EXISTS;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -74,6 +84,12 @@ public class ReportTemplateServiceImpl implements ReportTemplateService {
|
|||||||
@Resource
|
@Resource
|
||||||
private ReportDatasetService datasetService;
|
private ReportDatasetService datasetService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private ReportDatasourceMapper datasourceMapper;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private ReportDatasetMapper datasetMapper;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public Long createReportTemplate(ReportTemplateSaveReqVO createReqVO) {
|
public Long createReportTemplate(ReportTemplateSaveReqVO createReqVO) {
|
||||||
@@ -84,6 +100,12 @@ public class ReportTemplateServiceImpl implements ReportTemplateService {
|
|||||||
}
|
}
|
||||||
// 新增模板
|
// 新增模板
|
||||||
ReportTemplateDO template = BeanUtils.toBean(createReqVO, ReportTemplateDO.class);
|
ReportTemplateDO template = BeanUtils.toBean(createReqVO, ReportTemplateDO.class);
|
||||||
|
// 超管创建的作为内置模板
|
||||||
|
LoginUser loginUser = SecurityFrameworkUtils.getLoginUser();
|
||||||
|
boolean isSuperAdmin = loginUser != null && loginUser.getIsSupAdmin();
|
||||||
|
if (isSuperAdmin) {
|
||||||
|
template.setType(ReportTemplateTypeEnum.SYSTEM);
|
||||||
|
}
|
||||||
templateMapper.insert(template);
|
templateMapper.insert(template);
|
||||||
Long templateId = template.getId();
|
Long templateId = template.getId();
|
||||||
// 解析数据源
|
// 解析数据源
|
||||||
@@ -134,10 +156,13 @@ public class ReportTemplateServiceImpl implements ReportTemplateService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void updateReportTemplate(ReportTemplateSaveReqVO updateReqVO) {
|
public void updateReportTemplate(ReportTemplateSaveReqVO updateReqVO) {
|
||||||
Long templateId = updateReqVO.getId();
|
Long templateId = updateReqVO.getId();
|
||||||
// 校验存在
|
// 校验存在
|
||||||
validateTemplateExists(templateId);
|
ReportTemplateDO reportTemplateDO = validateTemplateExists(templateId);
|
||||||
|
// 校验内置模板操作权限
|
||||||
|
validateSystemTemplate(reportTemplateDO);
|
||||||
// url解码xml
|
// url解码xml
|
||||||
String content = updateReqVO.getContent();
|
String content = updateReqVO.getContent();
|
||||||
if (StringUtils.isNotEmpty(content)) {
|
if (StringUtils.isNotEmpty(content)) {
|
||||||
@@ -152,11 +177,36 @@ public class ReportTemplateServiceImpl implements ReportTemplateService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void deleteReportTemplate(Long id) {
|
public void deleteReportTemplate(Long id) {
|
||||||
// 校验存在
|
// 校验存在
|
||||||
validateTemplateExists(id);
|
ReportTemplateDO reportTemplateDO = validateTemplateExists(id);
|
||||||
|
// 校验内置模板操作权限
|
||||||
|
validateSystemTemplate(reportTemplateDO);
|
||||||
// 删除
|
// 删除
|
||||||
templateMapper.deleteById(id);
|
templateMapper.deleteById(id);
|
||||||
|
// 删除关联数据源
|
||||||
|
List<ReportDatasourceDO> reportDatasourceDOS = datasourceMapper.selectList(new LambdaQueryWrapperX<ReportDatasourceDO>().eq(ReportDatasourceDO::getTemplateId, id));
|
||||||
|
if (CollUtil.isNotEmpty(reportDatasourceDOS)) {
|
||||||
|
// 模板下的数据源id
|
||||||
|
List<Long> datasourceIds = reportDatasourceDOS.stream().map(ReportDatasourceDO::getId).toList();
|
||||||
|
datasourceMapper.deleteBatchIds(datasourceIds);
|
||||||
|
// 删除关联数据集
|
||||||
|
datasetMapper.delete(new LambdaQueryWrapperX<ReportDatasetDO>().in(ReportDatasetDO::getDatasourceId, datasourceIds));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 校验只有超管可以操作内置模板
|
||||||
|
*/
|
||||||
|
private void validateSystemTemplate(ReportTemplateDO templateDO) {
|
||||||
|
LoginUser loginUser = SecurityFrameworkUtils.getLoginUser();
|
||||||
|
boolean isSuperAdmin = loginUser != null && loginUser.getIsSupAdmin();
|
||||||
|
// 非超管不能操作内置模板
|
||||||
|
if (ReportTemplateTypeEnum.SYSTEM.equals(templateDO.getType()) && !isSuperAdmin) {
|
||||||
|
throw exception(DATATEMPLATE_BUILDIN_OPERATION_PERMISSION_ERROR);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -164,9 +214,12 @@ public class ReportTemplateServiceImpl implements ReportTemplateService {
|
|||||||
*
|
*
|
||||||
* @param id
|
* @param id
|
||||||
*/
|
*/
|
||||||
private void validateTemplateExists(Long id) {
|
private ReportTemplateDO validateTemplateExists(Long id) {
|
||||||
if (templateMapper.selectById(id) == null) {
|
ReportTemplateDO reportTemplateDO = templateMapper.selectById(id);
|
||||||
|
if (reportTemplateDO == null) {
|
||||||
throw exception(TEMPLATE_NOT_EXISTS);
|
throw exception(TEMPLATE_NOT_EXISTS);
|
||||||
|
} else {
|
||||||
|
return reportTemplateDO;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -218,8 +271,8 @@ public class ReportTemplateServiceImpl implements ReportTemplateService {
|
|||||||
// 查询数据集
|
// 查询数据集
|
||||||
List<ReportDatasetDO> datasetList = datasetService.getDatasetList(ReportDatasetReqVO.builder().datasourceId(ds.getId()).build());
|
List<ReportDatasetDO> datasetList = datasetService.getDatasetList(ReportDatasetReqVO.builder().datasourceId(ds.getId()).build());
|
||||||
List<DatasetDefinition> datasetDefinitions = new ArrayList<>();
|
List<DatasetDefinition> datasetDefinitions = new ArrayList<>();
|
||||||
switch (ds.getDsType()) {
|
switch (ds.getType()) {
|
||||||
case JDBC -> {
|
case JDBC, BUILDIN -> {
|
||||||
// 转换对应的ureport对象
|
// 转换对应的ureport对象
|
||||||
JdbcDatasourceDefinition jdbcDatasourceDefinition = BeanUtil.copyProperties(ds, JdbcDatasourceDefinition.class, "datasets");
|
JdbcDatasourceDefinition jdbcDatasourceDefinition = BeanUtil.copyProperties(ds, JdbcDatasourceDefinition.class, "datasets");
|
||||||
datasetDefinitions.addAll(BeanUtils.toBean(datasetList, SqlDatasetDefinition.class));
|
datasetDefinitions.addAll(BeanUtils.toBean(datasetList, SqlDatasetDefinition.class));
|
||||||
@@ -233,19 +286,36 @@ public class ReportTemplateServiceImpl implements ReportTemplateService {
|
|||||||
springBeanDatasourceDefinition.setDatasets(datasetDefinitions);
|
springBeanDatasourceDefinition.setDatasets(datasetDefinitions);
|
||||||
datasourceDefinitions.add(springBeanDatasourceDefinition);
|
datasourceDefinitions.add(springBeanDatasourceDefinition);
|
||||||
}
|
}
|
||||||
|
case API -> {
|
||||||
|
// 转换对应的ureport对象
|
||||||
|
ApiDatasourceDefinition apiDatasourceDefinition = BeanUtil.copyProperties(ds, ApiDatasourceDefinition.class, "datasets");
|
||||||
|
datasetDefinitions.addAll(BeanUtils.toBean(datasetList, ApiDatasetDefinition.class));
|
||||||
|
apiDatasourceDefinition.setDatasets(datasetDefinitions);
|
||||||
|
datasourceDefinitions.add(apiDatasourceDefinition);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
reportDefinition.setDatasources(datasourceDefinitions);
|
reportDefinition.setDatasources(datasourceDefinitions);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@OrganIgnore
|
||||||
public List<ReportTemplateDO> getReportTemplateList(ReportTemplateReqVO reqVO) {
|
public List<ReportTemplateDO> getReportTemplateList(ReportTemplateReqVO reqVO) {
|
||||||
return templateMapper.selectList(new LambdaQueryWrapperX<ReportTemplateDO>()
|
LoginUser loginUser = SecurityFrameworkUtils.getLoginUser();
|
||||||
.likeIfPresent(ReportTemplateDO::getName, reqVO.getName())
|
LambdaQueryWrapper<ReportTemplateDO> queryWrapper = new LambdaQueryWrapperX<ReportTemplateDO>().likeIfPresent(ReportTemplateDO::getName, reqVO.getName())
|
||||||
.eqIfPresent(ReportTemplateDO::getType, reqVO.getType())
|
|
||||||
.orderByDesc(ReportTemplateDO::getCreateTime)
|
.orderByDesc(ReportTemplateDO::getCreateTime)
|
||||||
// 不返回content xml,点击具体的模板中返回xml
|
// 不返回content xml,点击具体的模板中返回xml
|
||||||
.select(ReportTemplateDO::getId, ReportTemplateDO::getName, ReportTemplateDO::getCreateTime, ReportTemplateDO::getRemark));
|
.select(ReportTemplateDO::getId, ReportTemplateDO::getName, ReportTemplateDO::getCreateTime, ReportTemplateDO::getRemark);
|
||||||
|
if(!loginUser.getIsSupAdmin()) {
|
||||||
|
// 普通用户查看机构下的和system模板
|
||||||
|
queryWrapper.or(wrapper -> {
|
||||||
|
wrapper.eq(ReportTemplateDO::getOrganId, loginUser.getOrganId()).eq(ReportTemplateDO::getType, ReportTemplateTypeEnum.CUSTOM);
|
||||||
|
}).or(wrapper -> {
|
||||||
|
wrapper.eq(ReportTemplateDO::getType, ReportTemplateTypeEnum.SYSTEM);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
// 超管查看全部
|
||||||
|
return templateMapper.selectList(queryWrapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
+1
-1
@@ -28,7 +28,7 @@ import java.lang.annotation.Target;
|
|||||||
validatedBy = {ReportDatasourceTypeInEnumValidator.class}
|
validatedBy = {ReportDatasourceTypeInEnumValidator.class}
|
||||||
)
|
)
|
||||||
public @interface ReportDatasourceTypeInEnum {
|
public @interface ReportDatasourceTypeInEnum {
|
||||||
String message() default "数据源类型[dsType]错误,请检查是否jdbc/spring";
|
String message() default "数据源类型[type]错误,请检查是否jdbc/spring/buildin/api";
|
||||||
|
|
||||||
Class<?>[] groups() default {};
|
Class<?>[] groups() default {};
|
||||||
|
|
||||||
|
|||||||
+1
-2
@@ -42,8 +42,7 @@ public abstract class ReportCommonServiceImplTest {
|
|||||||
.id(id)
|
.id(id)
|
||||||
.name("单元测试数据源")
|
.name("单元测试数据源")
|
||||||
.templateId(reportId)
|
.templateId(reportId)
|
||||||
.dsType(ReportDatasourceTypeEnum.SPRING.getDesc())
|
.type(ReportDatasourceTypeEnum.SPRING.getDesc())
|
||||||
.type(ReportTemplateTypeEnum.SYSTEM.getType())
|
|
||||||
.driver("com.mysql.cj.jdbc.Driver")
|
.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")
|
.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")
|
.username("root")
|
||||||
|
|||||||
Reference in New Issue
Block a user