mirror of
http://192.168.1.205:9980/cf_devdept2/cf_imes_server.git
synced 2026-08-14 21:52:07 +08:00
报表基础模块:1、ureport对象新增id属性映射;2、新增springbean返回对象接口;3、接口异常处理、入参规范;
This commit is contained in:
+2
@@ -17,6 +17,8 @@ public final class ErrorCodeConstants {
|
|||||||
// ========== 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_SPRINGBEAN_GET_FAIL = new ErrorCode(1_003_002_003, "无法获取springbean【{}】");
|
||||||
|
public static final ErrorCode DATASOURCE_SPRINGBEAN_METHODS_GET_FAIL = new ErrorCode(1_003_002_004, "获取springbean方法列表失败,请检查】");
|
||||||
|
|
||||||
|
|
||||||
// ========== UREPORT dataset模块 1-003-003-000 ==========
|
// ========== UREPORT dataset模块 1-003-003-000 ==========
|
||||||
|
|||||||
+2
-2
@@ -52,7 +52,7 @@ public class ReportDatasetController {
|
|||||||
|
|
||||||
@DeleteMapping("/dataset/{id}")
|
@DeleteMapping("/dataset/{id}")
|
||||||
@Operation(summary = "删除报表数据集")
|
@Operation(summary = "删除报表数据集")
|
||||||
@Parameter(name = "id", description = "编号", required = true)
|
@Parameter(name = "id", description = "数据集id", 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);
|
||||||
@@ -61,7 +61,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 = "数据集id", 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);
|
||||||
|
|||||||
+13
-3
@@ -23,6 +23,7 @@ import org.springframework.web.bind.annotation.*;
|
|||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import javax.validation.Valid;
|
import javax.validation.Valid;
|
||||||
|
import javax.validation.constraints.NotEmpty;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -69,7 +70,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 = "数据源id", 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);
|
||||||
@@ -78,7 +79,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 = "数据源id", 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);
|
||||||
@@ -88,6 +89,7 @@ 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')")
|
||||||
|
@Parameter(name = "templateId", description = "模版id", required = true)
|
||||||
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));
|
||||||
}
|
}
|
||||||
@@ -99,10 +101,18 @@ public class ReportDatasourceController {
|
|||||||
return success(datasourceService.getBeanDatasourceList());
|
return success(datasourceService.getBeanDatasourceList());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("/springbean/result/clazz")
|
||||||
|
@Operation(summary = "获取springbean数据源返回对象")
|
||||||
|
@Parameter(name = "clazz", description = "返回对象类路径全名不能为空", required = true)
|
||||||
|
public List<Field> springbeanFieldList(@RequestParam(value = "clazz") @NotEmpty(message = "类路径全名不能为空") String clazz) {
|
||||||
|
return datasourceService.getSpringBeanResultFieldList(clazz);
|
||||||
|
}
|
||||||
|
|
||||||
@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) {
|
@Parameter(name = "beanId", description = "springbeanId", required = true)
|
||||||
|
public CommonResult<List<String>> getBeanDatasourceList(@RequestParam(value = "beanId") @NotEmpty(message = "beanId不能为空") String beanId) {
|
||||||
return success(datasourceService.loadBeanMethods(beanId));
|
return success(datasourceService.loadBeanMethods(beanId));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+5
-4
@@ -39,6 +39,7 @@ import org.springframework.web.multipart.MultipartFile;
|
|||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import javax.validation.Valid;
|
import javax.validation.Valid;
|
||||||
|
import javax.validation.constraints.NotEmpty;
|
||||||
|
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@@ -79,7 +80,7 @@ public class ReportTemplateController {
|
|||||||
|
|
||||||
@DeleteMapping("/template/{id}")
|
@DeleteMapping("/template/{id}")
|
||||||
@Operation(summary = "删除报表模板信息")
|
@Operation(summary = "删除报表模板信息")
|
||||||
@Parameter(name = "id", description = "编号", required = true)
|
@Parameter(name = "id", description = "模板id", 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);
|
||||||
@@ -88,7 +89,7 @@ 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 = "模板id", 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));
|
||||||
@@ -141,7 +142,7 @@ public class ReportTemplateController {
|
|||||||
@GetMapping("/scriptValidation")
|
@GetMapping("/scriptValidation")
|
||||||
@Operation(summary = "校验表达式")
|
@Operation(summary = "校验表达式")
|
||||||
@Parameter(name = "content", description = "表达式", required = true)
|
@Parameter(name = "content", description = "表达式", required = true)
|
||||||
public List<ErrorInfo> scriptValidation(@Param("content") String content) {
|
public List<ErrorInfo> scriptValidation(@Param("content") @NotEmpty(message = "表达式不能为空") String content) {
|
||||||
content = StringUtils.decode(content);
|
content = StringUtils.decode(content);
|
||||||
ANTLRInputStream antlrInputStream = new ANTLRInputStream(content);
|
ANTLRInputStream antlrInputStream = new ANTLRInputStream(content);
|
||||||
ReportParserLexer lexer = new ReportParserLexer(antlrInputStream);
|
ReportParserLexer lexer = new ReportParserLexer(antlrInputStream);
|
||||||
@@ -163,7 +164,7 @@ public class ReportTemplateController {
|
|||||||
@GetMapping("/parseDataSet")
|
@GetMapping("/parseDataSet")
|
||||||
@Operation(summary = "解析表达式中的数据集")
|
@Operation(summary = "解析表达式中的数据集")
|
||||||
@Parameter(name = "expr", description = "表达式", required = true)
|
@Parameter(name = "expr", description = "表达式", required = true)
|
||||||
public Map<String, String> parseDatasetName(@Param("expr") String expr) {
|
public Map<String, String> parseDatasetName(@Param("expr") @NotEmpty(message = "表达式不能为空") String expr) {
|
||||||
ANTLRInputStream antlrInputStream = new ANTLRInputStream(expr);
|
ANTLRInputStream antlrInputStream = new ANTLRInputStream(expr);
|
||||||
ReportParserLexer lexer = new ReportParserLexer(antlrInputStream);
|
ReportParserLexer lexer = new ReportParserLexer(antlrInputStream);
|
||||||
CommonTokenStream tokenStream = new CommonTokenStream(lexer);
|
CommonTokenStream tokenStream = new CommonTokenStream(lexer);
|
||||||
|
|||||||
+16
@@ -0,0 +1,16 @@
|
|||||||
|
package com.cf.imes.module.report.framework.ureport.bean;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Gqr
|
||||||
|
* @since 2024/8/30 11:21
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
@Data
|
||||||
|
public class MockSpringBeanDatasourceResult {
|
||||||
|
private String key;
|
||||||
|
|
||||||
|
private String value;
|
||||||
|
}
|
||||||
+7
-1
@@ -78,5 +78,11 @@ public interface ReportDatasourceService {
|
|||||||
*/
|
*/
|
||||||
List<Field> getTableFields(PreviewParams previewParams);
|
List<Field> getTableFields(PreviewParams previewParams);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取数据源
|
||||||
|
*
|
||||||
|
* @param clazz
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
List<Field> getSpringBeanResultFieldList(String clazz);
|
||||||
}
|
}
|
||||||
|
|||||||
+39
-2
@@ -1,9 +1,11 @@
|
|||||||
package com.cf.imes.module.report.service.datasource;
|
package com.cf.imes.module.report.service.datasource;
|
||||||
|
|
||||||
import cn.hutool.core.annotation.AnnotationUtil;
|
import cn.hutool.core.annotation.AnnotationUtil;
|
||||||
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
import cn.hutool.core.collection.CollUtil;
|
import cn.hutool.core.collection.CollUtil;
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.sql.SqlInjectionUtils;
|
import com.baomidou.mybatisplus.core.toolkit.sql.SqlInjectionUtils;
|
||||||
|
import com.bstek.common.exception.ReportDesignException;
|
||||||
import com.bstek.common.utils.MultipleJdbcTemplate;
|
import com.bstek.common.utils.MultipleJdbcTemplate;
|
||||||
import com.bstek.datasource.bean.DataSourceInfo;
|
import com.bstek.datasource.bean.DataSourceInfo;
|
||||||
import com.bstek.datasource.bean.PreviewParams;
|
import com.bstek.datasource.bean.PreviewParams;
|
||||||
@@ -12,6 +14,7 @@ import com.bstek.ureport.definition.dataset.Parameter;
|
|||||||
import com.bstek.ureport.definition.dataset.SqlDatasetDefinition;
|
import com.bstek.ureport.definition.dataset.SqlDatasetDefinition;
|
||||||
import com.bstek.ureport.utils.ProcedureUtils;
|
import com.bstek.ureport.utils.ProcedureUtils;
|
||||||
import com.cf.imes.framework.common.exception.ServiceException;
|
import com.cf.imes.framework.common.exception.ServiceException;
|
||||||
|
import com.cf.imes.framework.common.exception.util.ServiceExceptionUtil;
|
||||||
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.module.report.controller.admin.dataset.vo.ReportDatasetReqVO;
|
import com.cf.imes.module.report.controller.admin.dataset.vo.ReportDatasetReqVO;
|
||||||
@@ -27,6 +30,7 @@ import com.cf.imes.module.report.service.dataset.ReportDatasetService;
|
|||||||
import com.cf.imes.module.report.util.SqlInjectionUtil;
|
import com.cf.imes.module.report.util.SqlInjectionUtil;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.springframework.beans.BeansException;
|
||||||
import org.springframework.context.ApplicationContext;
|
import org.springframework.context.ApplicationContext;
|
||||||
import org.springframework.jdbc.core.ResultSetExtractor;
|
import org.springframework.jdbc.core.ResultSetExtractor;
|
||||||
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
|
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
|
||||||
@@ -37,6 +41,7 @@ import org.springframework.validation.annotation.Validated;
|
|||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
|
import java.beans.PropertyDescriptor;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.ResultSetMetaData;
|
import java.sql.ResultSetMetaData;
|
||||||
@@ -51,6 +56,8 @@ import static com.cf.imes.module.report.enums.ErrorCodeConstants.DATASET_SQL_ILL
|
|||||||
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_NOT_EXISTS;
|
import static com.cf.imes.module.report.enums.ErrorCodeConstants.DATASOURCE_NOT_EXISTS;
|
||||||
|
import static com.cf.imes.module.report.enums.ErrorCodeConstants.DATASOURCE_SPRINGBEAN_GET_FAIL;
|
||||||
|
import static com.cf.imes.module.report.enums.ErrorCodeConstants.DATASOURCE_SPRINGBEAN_METHODS_GET_FAIL;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 报表数据源 Service 实现类
|
* 报表数据源 Service 实现类
|
||||||
@@ -156,10 +163,13 @@ public class ReportDatasourceServiceImpl implements ReportDatasourceService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<String> loadBeanMethods(String beanId) {
|
public List<String> loadBeanMethods(String beanId) {
|
||||||
Object obj = applicationContext.getBean(beanId);
|
Object obj;
|
||||||
|
List<String> result = new ArrayList<String>();
|
||||||
|
try {
|
||||||
|
obj = applicationContext.getBean(beanId);
|
||||||
Class<?> clazz = obj.getClass();
|
Class<?> clazz = obj.getClass();
|
||||||
Method[] methods = clazz.getMethods();
|
Method[] methods = clazz.getMethods();
|
||||||
List<String> result = new ArrayList<String>();
|
|
||||||
// ureport的springbean方法必须满足(String dsName, String datasetName, Map<String, Object> parameters)
|
// ureport的springbean方法必须满足(String dsName, String datasetName, Map<String, Object> parameters)
|
||||||
for (Method method : methods) {
|
for (Method method : methods) {
|
||||||
Class<?>[] types = method.getParameterTypes();
|
Class<?>[] types = method.getParameterTypes();
|
||||||
@@ -180,6 +190,13 @@ public class ReportDatasourceServiceImpl implements ReportDatasourceService {
|
|||||||
}
|
}
|
||||||
result.add(method.getName());
|
result.add(method.getName());
|
||||||
}
|
}
|
||||||
|
} catch (BeansException e) {
|
||||||
|
log.error("[ReportDatasourceService][loadBeanMethods]获取bean失败", e);
|
||||||
|
throw ServiceExceptionUtil.exception(DATASOURCE_SPRINGBEAN_GET_FAIL, beanId);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("[ReportDatasourceService][loadBeanMethods]方法列表获取异常", e);
|
||||||
|
throw ServiceExceptionUtil.exception(DATASOURCE_SPRINGBEAN_METHODS_GET_FAIL);
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -241,6 +258,26 @@ public class ReportDatasourceServiceImpl implements ReportDatasourceService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Field> getSpringBeanResultFieldList(String clazz) {
|
||||||
|
List<Field> result = new ArrayList<Field>();
|
||||||
|
try {
|
||||||
|
Class<?> targetClass = Class.forName(clazz);
|
||||||
|
PropertyDescriptor[] propertyDescriptors = BeanUtil.getPropertyDescriptors(targetClass);
|
||||||
|
for (PropertyDescriptor pd : propertyDescriptors) {
|
||||||
|
String name = pd.getName();
|
||||||
|
if ("class".equals(name)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
result.add(new Field(name));
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
|
||||||
|
} catch (Exception ex) {
|
||||||
|
throw new ReportDesignException(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询数据源下的数据集
|
* 查询数据源下的数据集
|
||||||
*
|
*
|
||||||
|
|||||||
BIN
Binary file not shown.
Reference in New Issue
Block a user