mirror of
http://192.168.1.205:9980/cf_devdept2/cf_imes_server.git
synced 2026-08-12 21:02:08 +08:00
1、报表基础内容实现,service单元测试实现,移除report微服务中没用的单元测试内容;
2、DefaultDBFieldHandler自动填充处理类中request注入改为上下文获取;
This commit is contained in:
-1
@@ -52,7 +52,6 @@ public class OrganDatabaseInterceptor implements TenantLineHandler {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean ignoreTable(String tableName) {
|
public boolean ignoreTable(String tableName) {
|
||||||
System.out.println(superAdminProdOrgIgnoreEnable);
|
|
||||||
return OrganContextHolder.isIgnore() // 情况一,全局忽略多组织
|
return OrganContextHolder.isIgnore() // 情况一,全局忽略多组织
|
||||||
|| CollUtil.contains(ignoreTables, tableName) // 情况二,忽略多组织的表
|
|| CollUtil.contains(ignoreTables, tableName) // 情况二,忽略多组织的表
|
||||||
|| (isAdmin() && superAdminProdOrgIgnoreEnable); //情况三,忽略超级管理员
|
|| (isAdmin() && superAdminProdOrgIgnoreEnable); //情况三,忽略超级管理员
|
||||||
|
|||||||
+7
-8
@@ -8,7 +8,6 @@ import com.cf.imes.framework.web.core.util.WebFrameworkUtils;
|
|||||||
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
|
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
|
||||||
import org.apache.ibatis.reflection.MetaObject;
|
import org.apache.ibatis.reflection.MetaObject;
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
@@ -30,13 +29,13 @@ public class DefaultDBFieldHandler implements MetaObjectHandler {
|
|||||||
@Resource
|
@Resource
|
||||||
private StringRedisTemplate stringRedisTemplate;
|
private StringRedisTemplate stringRedisTemplate;
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private HttpServletRequest request;
|
|
||||||
|
|
||||||
private static final String AUTHORIZATION_BEARER = "Bearer";
|
private static final String AUTHORIZATION_BEARER = "Bearer";
|
||||||
|
|
||||||
private static final String OAUTH2_ACCESS_TOKEN = "oauth2_access_token:%s";
|
private static final String OAUTH2_ACCESS_TOKEN = "oauth2_access_token:%s";
|
||||||
|
|
||||||
|
private static final String AUTHORIZATION_HEADER_NAME = "Authorization";
|
||||||
|
|
||||||
|
private static final String TOKEN_PARAM_NAME = "token";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void insertFill(MetaObject metaObject) {
|
public void insertFill(MetaObject metaObject) {
|
||||||
@@ -68,7 +67,7 @@ public class DefaultDBFieldHandler implements MetaObjectHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 从请求中获取到 Token
|
// 从请求中获取到 Token
|
||||||
String authorization = obtainAuthorization(request, "Authorization", "token");
|
String authorization = obtainAuthorization(AUTHORIZATION_HEADER_NAME, TOKEN_PARAM_NAME);
|
||||||
|
|
||||||
Long organId = null;
|
Long organId = null;
|
||||||
|
|
||||||
@@ -107,7 +106,7 @@ public class DefaultDBFieldHandler implements MetaObjectHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 从请求中获取到 Token
|
// 从请求中获取到 Token
|
||||||
String authorization = obtainAuthorization(request, "Authorization", "token");
|
String authorization = obtainAuthorization(AUTHORIZATION_HEADER_NAME, TOKEN_PARAM_NAME);
|
||||||
|
|
||||||
Long organId = null;
|
Long organId = null;
|
||||||
|
|
||||||
@@ -132,8 +131,8 @@ public class DefaultDBFieldHandler implements MetaObjectHandler {
|
|||||||
|
|
||||||
|
|
||||||
// 从请求中获取到 token
|
// 从请求中获取到 token
|
||||||
private static String obtainAuthorization(HttpServletRequest request,
|
private static String obtainAuthorization(String headerName, String parameterName) {
|
||||||
String headerName, String parameterName) {
|
HttpServletRequest request = WebFrameworkUtils.getRequest();
|
||||||
// 1. 获得 Token。优先级:Header > Parameter
|
// 1. 获得 Token。优先级:Header > Parameter
|
||||||
String token = request.getHeader(headerName);
|
String token = request.getHeader(headerName);
|
||||||
if (StrUtil.isEmpty(token)) {
|
if (StrUtil.isEmpty(token)) {
|
||||||
|
|||||||
+65
@@ -0,0 +1,65 @@
|
|||||||
|
package com.cf.imes.framework.mybatis.core.type;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
|
import com.fasterxml.jackson.databind.JavaType;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import org.apache.ibatis.type.*;
|
||||||
|
|
||||||
|
import java.sql.CallableStatement;
|
||||||
|
import java.sql.PreparedStatement;
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* mb自定义列表类型转换器
|
||||||
|
*
|
||||||
|
* @author Gqr
|
||||||
|
* @since 2024/7/8 11:15
|
||||||
|
*/
|
||||||
|
@MappedJdbcTypes(JdbcType.VARCHAR)
|
||||||
|
@MappedTypes(List.class)
|
||||||
|
public class ObjectListTypeHandler extends BaseTypeHandler<List<?>> {
|
||||||
|
private final ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setNonNullParameter(PreparedStatement ps, int i, List<?> parameter, JdbcType jdbcType) throws SQLException {
|
||||||
|
try {
|
||||||
|
String jsonString = objectMapper.writeValueAsString(parameter);
|
||||||
|
ps.setString(i, jsonString);
|
||||||
|
} catch (JsonProcessingException e) {
|
||||||
|
throw new RuntimeException("Error serializing List<Object> to JSON", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<?> getNullableResult(ResultSet rs, String columnName) throws SQLException {
|
||||||
|
String jsonStr = rs.getString(columnName);
|
||||||
|
return parseJson(jsonStr);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<?> getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
|
||||||
|
String jsonStr = rs.getString(columnIndex);
|
||||||
|
return parseJson(jsonStr);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<?> getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
|
||||||
|
String jsonStr = cs.getString(columnIndex);
|
||||||
|
return parseJson(jsonStr);
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<?> parseJson(String jsonStr) {
|
||||||
|
if (jsonStr == null || jsonStr.isEmpty()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
// Using JavaType to handle List<Object> deserialization
|
||||||
|
JavaType javaType = objectMapper.getTypeFactory().constructCollectionType(List.class, Object.class);
|
||||||
|
return objectMapper.readValue(jsonStr, javaType);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException("Error deserializing JSON to List<Object>", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+3
-1
@@ -16,5 +16,7 @@ public interface ErrorCodeConstants {
|
|||||||
// ========== UREPORT 模块 1-003-001-000 ==========
|
// ========== UREPORT 模块 1-003-001-000 ==========
|
||||||
ErrorCode UREPORT_DATA_NOT_EXISTS = new ErrorCode(1_003_001_001, "Ureport2 报表不存在");
|
ErrorCode UREPORT_DATA_NOT_EXISTS = new ErrorCode(1_003_001_001, "Ureport2 报表不存在");
|
||||||
ErrorCode UREPORT_DATABASE_NOT_EXISTS = new ErrorCode(1_003_001_002, "Ureport2 报表数据源不存在");
|
ErrorCode UREPORT_DATABASE_NOT_EXISTS = new ErrorCode(1_003_001_002, "Ureport2 报表数据源不存在");
|
||||||
|
ErrorCode TEMPLATE_NOT_EXISTS = new ErrorCode(1_003_001_003, "报表模板信息不存在");
|
||||||
|
ErrorCode DATASOURCE_NOT_EXISTS = new ErrorCode(1_003_001_004, "报表数据源不存在");
|
||||||
|
ErrorCode DATASET_NOT_EXISTS = new ErrorCode(1_003_001_005, "报表数据集不存在");
|
||||||
}
|
}
|
||||||
|
|||||||
+26
@@ -0,0 +1,26 @@
|
|||||||
|
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;
|
||||||
|
|
||||||
|
}
|
||||||
+77
@@ -0,0 +1,77 @@
|
|||||||
|
package com.cf.imes.module.report.controller.admin.template;
|
||||||
|
|
||||||
|
import com.cf.imes.framework.common.pojo.CommonResult;
|
||||||
|
import com.cf.imes.framework.common.util.object.BeanUtils;
|
||||||
|
import com.cf.imes.module.report.controller.admin.template.vo.ReportDatasetReqVO;
|
||||||
|
import com.cf.imes.module.report.controller.admin.template.vo.ReportDatasetRespVO;
|
||||||
|
import com.cf.imes.module.report.controller.admin.template.vo.ReportDatasetSaveReqVO;
|
||||||
|
import com.cf.imes.module.report.dal.dataobject.template.ReportDatasetDO;
|
||||||
|
import com.cf.imes.module.report.service.template.ReportDatasetService;
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import io.swagger.v3.oas.annotations.Parameter;
|
||||||
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import javax.validation.Valid;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static com.cf.imes.framework.common.pojo.CommonResult.success;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 报表数据集控制器
|
||||||
|
*
|
||||||
|
* @author Gqr
|
||||||
|
* @since 2024/7/8 15:22
|
||||||
|
*/
|
||||||
|
@Tag(name = "管理后台 - 报表数据集")
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/report")
|
||||||
|
@Validated
|
||||||
|
public class ReportDatasetController {
|
||||||
|
@Resource
|
||||||
|
private ReportDatasetService datasetService;
|
||||||
|
|
||||||
|
@PutMapping("/dataset")
|
||||||
|
@Operation(summary = "创建报表数据集")
|
||||||
|
@PreAuthorize("@ss.hasPermission('report:dataset:create')")
|
||||||
|
public CommonResult<Long> createDataset(@Valid @RequestBody ReportDatasetSaveReqVO createReqVO) {
|
||||||
|
return success(datasetService.createDataset(createReqVO));
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/dataset")
|
||||||
|
@Operation(summary = "更新报表数据集")
|
||||||
|
@PreAuthorize("@ss.hasPermission('report:dataset:update')")
|
||||||
|
public CommonResult<Boolean> updateDataset(@Valid @RequestBody ReportDatasetSaveReqVO updateReqVO) {
|
||||||
|
datasetService.updateDataset(updateReqVO);
|
||||||
|
return success(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@DeleteMapping("/dataset/{id}")
|
||||||
|
@Operation(summary = "删除报表数据集")
|
||||||
|
@Parameter(name = "id", description = "编号", required = true)
|
||||||
|
@PreAuthorize("@ss.hasPermission('report:dataset:delete')")
|
||||||
|
public CommonResult<Boolean> deleteDataset(@PathVariable("id") Long id) {
|
||||||
|
datasetService.deleteDataset(id);
|
||||||
|
return success(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/dataset/{id}")
|
||||||
|
@Operation(summary = "获得报表数据集")
|
||||||
|
@Parameter(name = "id", description = "编号", required = true, example = "1024")
|
||||||
|
@PreAuthorize("@ss.hasPermission('report:dataset:query')")
|
||||||
|
public CommonResult<ReportDatasetRespVO> getDataset(@PathVariable("id") Long id) {
|
||||||
|
ReportDatasetDO dataset = datasetService.getDataset(id);
|
||||||
|
return success(BeanUtils.toBean(dataset, ReportDatasetRespVO.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/datasets")
|
||||||
|
@Operation(summary = "获取数据源下的报表数据集列表")
|
||||||
|
@PreAuthorize("@ss.hasPermission('report:dataset:query')")
|
||||||
|
public CommonResult<List<ReportDatasetRespVO>> getDatasetPage(@Valid ReportDatasetReqVO pageReqVO) {
|
||||||
|
return success(BeanUtils.toBean(datasetService.getDatasetList(pageReqVO), ReportDatasetRespVO.class));
|
||||||
|
}
|
||||||
|
}
|
||||||
+77
@@ -0,0 +1,77 @@
|
|||||||
|
package com.cf.imes.module.report.controller.admin.template;
|
||||||
|
|
||||||
|
import com.cf.imes.framework.common.pojo.CommonResult;
|
||||||
|
import com.cf.imes.framework.common.util.object.BeanUtils;
|
||||||
|
import com.cf.imes.module.report.controller.admin.template.vo.ReportDatasourceReqVO;
|
||||||
|
import com.cf.imes.module.report.controller.admin.template.vo.ReportDatasourceRespVO;
|
||||||
|
import com.cf.imes.module.report.controller.admin.template.vo.ReportDatasourceSaveReqVO;
|
||||||
|
import com.cf.imes.module.report.dal.dataobject.template.ReportDatasourceDO;
|
||||||
|
import com.cf.imes.module.report.service.template.ReportDatasourceService;
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import io.swagger.v3.oas.annotations.Parameter;
|
||||||
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import javax.validation.Valid;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static com.cf.imes.framework.common.pojo.CommonResult.success;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 报表数据源控制器
|
||||||
|
*
|
||||||
|
* @author Gqr
|
||||||
|
* @since 2024/7/5 16:53
|
||||||
|
*/
|
||||||
|
@Tag(name = "管理后台 - 报表数据源")
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/report/datasource")
|
||||||
|
@Validated
|
||||||
|
public class ReportDatasourceController {
|
||||||
|
@Resource
|
||||||
|
private ReportDatasourceService datasourceService;
|
||||||
|
|
||||||
|
@PutMapping("/datasource")
|
||||||
|
@Operation(summary = "创建报表数据源")
|
||||||
|
@PreAuthorize("@ss.hasPermission('report:datasource:create')")
|
||||||
|
public CommonResult<Long> createDatasource(@Valid @RequestBody ReportDatasourceSaveReqVO createReqVO) {
|
||||||
|
return success(datasourceService.createDatasource(createReqVO));
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/datasource")
|
||||||
|
@Operation(summary = "更新报表数据源")
|
||||||
|
@PreAuthorize("@ss.hasPermission('report:datasource:update')")
|
||||||
|
public CommonResult<Boolean> updateDatasource(@Valid @RequestBody ReportDatasourceSaveReqVO updateReqVO) {
|
||||||
|
datasourceService.updateDatasource(updateReqVO);
|
||||||
|
return success(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@DeleteMapping("/datasource/{id}")
|
||||||
|
@Operation(summary = "删除报表数据源")
|
||||||
|
@Parameter(name = "id", description = "编号", required = true, example = "1")
|
||||||
|
@PreAuthorize("@ss.hasPermission('report:datasource:delete')")
|
||||||
|
public CommonResult<Boolean> deleteDatasource(@PathVariable("id") Long id) {
|
||||||
|
datasourceService.deleteDatasource(id);
|
||||||
|
return success(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/datasource/{id}")
|
||||||
|
@Operation(summary = "获得报表数据源")
|
||||||
|
@Parameter(name = "id", description = "编号", required = true, example = "1")
|
||||||
|
@PreAuthorize("@ss.hasPermission('report:datasource:query')")
|
||||||
|
public CommonResult<ReportDatasourceRespVO> getDatasource(@PathVariable("id") Long id) {
|
||||||
|
ReportDatasourceDO datasource = datasourceService.getDatasource(id);
|
||||||
|
return success(BeanUtils.toBean(datasource, ReportDatasourceRespVO.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/datasources")
|
||||||
|
@Operation(summary = "获取报表模板下的报表数据源")
|
||||||
|
@PreAuthorize("@ss.hasPermission('report:datasource:query')")
|
||||||
|
public CommonResult<List<ReportDatasourceRespVO>> getDatasourcePage(@Valid ReportDatasourceReqVO pageReqVO) {
|
||||||
|
return success(BeanUtils.toBean(datasourceService.getTemplateDatasourceList(pageReqVO), ReportDatasourceRespVO.class));
|
||||||
|
}
|
||||||
|
}
|
||||||
+82
@@ -0,0 +1,82 @@
|
|||||||
|
package com.cf.imes.module.report.controller.admin.template;
|
||||||
|
|
||||||
|
import com.cf.imes.framework.common.pojo.CommonResult;
|
||||||
|
import com.cf.imes.framework.common.util.object.BeanUtils;
|
||||||
|
import com.cf.imes.framework.organ.core.context.OrganContextHolder;
|
||||||
|
import com.cf.imes.module.report.controller.admin.template.vo.ReportTemplateReqVO;
|
||||||
|
import com.cf.imes.module.report.controller.admin.template.vo.ReportTemplateRespVO;
|
||||||
|
import com.cf.imes.module.report.controller.admin.template.vo.ReportTemplateSaveReqVO;
|
||||||
|
import com.cf.imes.module.report.dal.dataobject.template.ReportTemplateDO;
|
||||||
|
import com.cf.imes.module.report.service.template.ReportTemplateService;
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import io.swagger.v3.oas.annotations.Parameter;
|
||||||
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import javax.annotation.security.PermitAll;
|
||||||
|
import javax.validation.Valid;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static com.cf.imes.framework.common.pojo.CommonResult.success;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 报表模板信息控制器
|
||||||
|
*
|
||||||
|
* @author Gqr
|
||||||
|
* @since 2024/7/3 14:22
|
||||||
|
*/
|
||||||
|
@Tag(name = "管理后台 - 报表模板信息")
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/report")
|
||||||
|
@Validated
|
||||||
|
public class ReportTemplateController {
|
||||||
|
@Autowired
|
||||||
|
private ReportTemplateService templateService;
|
||||||
|
|
||||||
|
@PutMapping("/template")
|
||||||
|
@Operation(summary = "创建报表模板信息")
|
||||||
|
@PreAuthorize("@ss.hasPermission('report:template:create')")
|
||||||
|
@PermitAll
|
||||||
|
public CommonResult<Long> createTemplate(@Valid @RequestBody ReportTemplateSaveReqVO createReqVO) {
|
||||||
|
OrganContextHolder.setOrganId(1L);
|
||||||
|
return success(templateService.createReportTemplate(createReqVO));
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/template")
|
||||||
|
@Operation(summary = "更新报表模板信息")
|
||||||
|
@PreAuthorize("@ss.hasPermission('report:template:update')")
|
||||||
|
public CommonResult<Boolean> updateTemplate(@Valid @RequestBody ReportTemplateSaveReqVO updateReqVO) {
|
||||||
|
templateService.updateReportTemplate(updateReqVO);
|
||||||
|
return success(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@DeleteMapping("/template/{id}")
|
||||||
|
@Operation(summary = "删除报表模板信息")
|
||||||
|
@Parameter(name = "id", description = "编号", required = true)
|
||||||
|
@PreAuthorize("@ss.hasPermission('report:template:delete')")
|
||||||
|
public CommonResult<Boolean> deleteReportTemplate(@PathVariable("id") Long id) {
|
||||||
|
templateService.deleteReportTemplate(id);
|
||||||
|
return success(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/template/{id}")
|
||||||
|
@Operation(summary = "获得报表模板信息")
|
||||||
|
@Parameter(name = "id", description = "编号", required = true, example = "1")
|
||||||
|
@PreAuthorize("@ss.hasPermission('report:template:query')")
|
||||||
|
public CommonResult<ReportTemplateRespVO> getReportTemplate(@PathVariable("id") Long id) {
|
||||||
|
ReportTemplateDO template = templateService.getReportTemplate(id);
|
||||||
|
return success(BeanUtils.toBean(template, ReportTemplateRespVO.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/templates")
|
||||||
|
@Operation(summary = "获得报表模板信息列表")
|
||||||
|
@PreAuthorize("@ss.hasPermission('report:template:query')")
|
||||||
|
@PermitAll
|
||||||
|
public CommonResult<List<ReportTemplateRespVO>> getTemplatePage(@Valid ReportTemplateReqVO pageReqVO) {
|
||||||
|
return success(BeanUtils.toBean(templateService.getReportTemplateList(pageReqVO), ReportTemplateRespVO.class));
|
||||||
|
}
|
||||||
|
}
|
||||||
+29
@@ -0,0 +1,29 @@
|
|||||||
|
package com.cf.imes.module.report.controller.admin.template.vo;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Gqr
|
||||||
|
* @since 2024/7/8 11:36
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class ReportDatasetParameterVO {
|
||||||
|
/**
|
||||||
|
* 参数名称
|
||||||
|
*/
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 类型
|
||||||
|
*/
|
||||||
|
private Integer type;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 默认值
|
||||||
|
*/
|
||||||
|
private String defaultValue;
|
||||||
|
}
|
||||||
+20
@@ -0,0 +1,20 @@
|
|||||||
|
package com.cf.imes.module.report.controller.admin.template.vo;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.ToString;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Gqr
|
||||||
|
* @since 2024/7/8 10:58
|
||||||
|
*/
|
||||||
|
@Schema(description = "管理后台 - 报表数据集 Request VO")
|
||||||
|
@Data
|
||||||
|
@ToString(callSuper = true)
|
||||||
|
public class ReportDatasetReqVO {
|
||||||
|
@Schema(description = "数据集名称", example = "测试数据集")
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
@Schema(description = "数据源id", example = "1", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||||
|
private Long datasourceId;
|
||||||
|
}
|
||||||
+33
@@ -0,0 +1,33 @@
|
|||||||
|
package com.cf.imes.module.report.controller.admin.template.vo;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Gqr
|
||||||
|
* @since 2024/7/8 11:01
|
||||||
|
*/
|
||||||
|
@Schema(description = "管理后台 - 报表数据集 Response VO")
|
||||||
|
@Data
|
||||||
|
public class ReportDatasetRespVO {
|
||||||
|
@Schema(description = "数据集id", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@Schema(description = "数据集名称", example = "测试数据集")
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
@Schema(description = "数据源id", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||||
|
private Long datasourceId;
|
||||||
|
|
||||||
|
@Schema(description = "动态查询SQL")
|
||||||
|
private String dbSql;
|
||||||
|
|
||||||
|
@Schema(description = "参数列表")
|
||||||
|
private List<ReportDatasetParameterVO> params;
|
||||||
|
|
||||||
|
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||||
|
private LocalDateTime createTime;
|
||||||
|
}
|
||||||
+33
@@ -0,0 +1,33 @@
|
|||||||
|
package com.cf.imes.module.report.controller.admin.template.vo;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Gqr
|
||||||
|
* @since 2024/7/8 11:01
|
||||||
|
*/
|
||||||
|
@Schema(description = "管理后台 - 报表数据集新增/修改 Request VO")
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
public class ReportDatasetSaveReqVO {
|
||||||
|
@Schema(description = "数据集id", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@Schema(description = "数据集名称", example = "测试数据集")
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
@Schema(description = "数据源id", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||||
|
@NotNull(message = "数据源id不能为空")
|
||||||
|
private Long datasourceId;
|
||||||
|
|
||||||
|
@Schema(description = "动态查询SQL")
|
||||||
|
private String dbSql;
|
||||||
|
|
||||||
|
@Schema(description = "参数列表")
|
||||||
|
private List<ReportDatasetParameterVO> params;
|
||||||
|
}
|
||||||
+23
@@ -0,0 +1,23 @@
|
|||||||
|
package com.cf.imes.module.report.controller.admin.template.vo;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.ToString;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Gqr
|
||||||
|
* @since 2024/7/8 11:01
|
||||||
|
*/
|
||||||
|
@Schema(description = "管理后台 - 报表数据源 Request VO")
|
||||||
|
@Data
|
||||||
|
@ToString(callSuper = true)
|
||||||
|
public class ReportDatasourceReqVO {
|
||||||
|
@Schema(description = "模板id", example = "1", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||||
|
private Long reportId;
|
||||||
|
|
||||||
|
@Schema(description = "数据源名称", example = "测试库")
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
@Schema(description = "模板类型,0内置、1自定义", example = "0")
|
||||||
|
private Integer type;
|
||||||
|
}
|
||||||
+45
@@ -0,0 +1,45 @@
|
|||||||
|
package com.cf.imes.module.report.controller.admin.template.vo;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Gqr
|
||||||
|
* @since 2024/7/5 16:34
|
||||||
|
*/
|
||||||
|
@Schema(description = "管理后台 - 报表数据源 Response VO")
|
||||||
|
@Data
|
||||||
|
public class ReportDatasourceRespVO {
|
||||||
|
|
||||||
|
@Schema(description = "数据源id", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@Schema(description = "模板id", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||||
|
private Long reportId;
|
||||||
|
|
||||||
|
@Schema(description = "数据源名称", example = "测试库")
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
@Schema(description = "模板类型,0内置、1自定义", example = "0")
|
||||||
|
private Integer type;
|
||||||
|
|
||||||
|
@Schema(description = "数据源驱动类",example = "com.mysql.cj.jdbc.Driver")
|
||||||
|
private String dbDriver;
|
||||||
|
|
||||||
|
@Schema(description = "数据源地址", example = "https://www.cf.com")
|
||||||
|
private String dbUrl;
|
||||||
|
|
||||||
|
@Schema(description = "数据源用户名", example = "晨丰")
|
||||||
|
private String dbUsername;
|
||||||
|
|
||||||
|
@Schema(description = "数据源密码", example = "晨丰")
|
||||||
|
private String dbPassword;
|
||||||
|
|
||||||
|
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||||
|
private LocalDateTime createTime;
|
||||||
|
|
||||||
|
@Schema(description = "备注", example = "该模板仅供生产使用")
|
||||||
|
private String remark;
|
||||||
|
}
|
||||||
+44
@@ -0,0 +1,44 @@
|
|||||||
|
package com.cf.imes.module.report.controller.admin.template.vo;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Gqr
|
||||||
|
* @since 2024/7/8 11:01
|
||||||
|
*/
|
||||||
|
@Schema(description = "管理后台 - 报表数据源新增/修改 Request VO")
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
public class ReportDatasourceSaveReqVO {
|
||||||
|
@Schema(description = "数据源id", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@Schema(description = "模板id", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||||
|
@NotNull(message = "模板id不能为空")
|
||||||
|
private Long reportId;
|
||||||
|
|
||||||
|
@Schema(description = "数据源名称", example = "测试库")
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
@Schema(description = "模板类型,0内置、1自定义", example = "0")
|
||||||
|
private Integer type;
|
||||||
|
|
||||||
|
@Schema(description = "数据源驱动类",example = "com.mysql.cj.jdbc.Driver")
|
||||||
|
private String dbDriver;
|
||||||
|
|
||||||
|
@Schema(description = "数据源地址", example = "https://www.cf.com")
|
||||||
|
private String dbUrl;
|
||||||
|
|
||||||
|
@Schema(description = "数据源用户名", example = "晨丰")
|
||||||
|
private String dbUsername;
|
||||||
|
|
||||||
|
@Schema(description = "数据源密码", example = "晨丰")
|
||||||
|
private String dbPassword;
|
||||||
|
|
||||||
|
@Schema(description = "备注", example = "该模板仅供生产使用")
|
||||||
|
private String remark;
|
||||||
|
}
|
||||||
+20
@@ -0,0 +1,20 @@
|
|||||||
|
package com.cf.imes.module.report.controller.admin.template.vo;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.ToString;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Gqr
|
||||||
|
* @since 2024/7/3 11:49
|
||||||
|
*/
|
||||||
|
@Schema(description = "管理后台 - 报表模板信息列表 Request VO")
|
||||||
|
@Data
|
||||||
|
@ToString(callSuper = true)
|
||||||
|
public class ReportTemplateReqVO {
|
||||||
|
@Schema(description = "模板名称", example = "生产单模板")
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
@Schema(description = "模板类型,0内置、1自定义", example = "1")
|
||||||
|
private Integer type;
|
||||||
|
}
|
||||||
+32
@@ -0,0 +1,32 @@
|
|||||||
|
package com.cf.imes.module.report.controller.admin.template.vo;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Gqr
|
||||||
|
* @since 2024/7/3 11:53
|
||||||
|
*/
|
||||||
|
@Schema(description = "管理后台 - 报表模板信息 Response VO")
|
||||||
|
@Data
|
||||||
|
public class ReportTemplateRespVO {
|
||||||
|
@Schema(description = "主键", requiredMode = Schema.RequiredMode.REQUIRED, example = "15176")
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@Schema(description = "模板名称", example = "生产单模板")
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
@Schema(description = "报表模板")
|
||||||
|
private String template;
|
||||||
|
|
||||||
|
@Schema(description = "模板类型,0内置、1自定义", example = "2")
|
||||||
|
private Long type;
|
||||||
|
|
||||||
|
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||||
|
private LocalDateTime createTime;
|
||||||
|
|
||||||
|
@Schema(description = "备注", example = "该模板仅供生产使用")
|
||||||
|
private String remark;
|
||||||
|
}
|
||||||
+30
@@ -0,0 +1,30 @@
|
|||||||
|
package com.cf.imes.module.report.controller.admin.template.vo;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Gqr
|
||||||
|
* @since 2024/7/3 11:58
|
||||||
|
*/
|
||||||
|
@Schema(description = "管理后台 - 报表模板信息新增/修改 Request VO")
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
public class ReportTemplateSaveReqVO {
|
||||||
|
|
||||||
|
@Schema(description = "主键", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@Schema(description = "模板名称", example = "生产单模板")
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
@Schema(description = "报表模板")
|
||||||
|
private String template;
|
||||||
|
|
||||||
|
@Schema(description = "模板类型,0内置、1自定义", example = "1")
|
||||||
|
private Integer type;
|
||||||
|
|
||||||
|
@Schema(description = "备注", example = "该模板仅供生产使用")
|
||||||
|
private String remark;
|
||||||
|
}
|
||||||
+51
@@ -0,0 +1,51 @@
|
|||||||
|
package com.cf.imes.module.report.dal.dataobject.template;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.KeySequence;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import com.cf.imes.framework.mybatis.core.dataobject.BaseDO;
|
||||||
|
import com.cf.imes.framework.mybatis.core.type.ObjectListTypeHandler;
|
||||||
|
import com.cf.imes.module.report.controller.admin.template.vo.ReportDatasetParameterVO;
|
||||||
|
import lombok.*;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 报表数据集DO
|
||||||
|
*
|
||||||
|
* @author Gqr
|
||||||
|
* @since 2024/7/8 11:01
|
||||||
|
*/
|
||||||
|
@TableName(value = "report_dataset", autoResultMap = true)
|
||||||
|
@KeySequence("report_dataset_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
@ToString(callSuper = true)
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class ReportDatasetDO extends BaseDO {
|
||||||
|
/**
|
||||||
|
* 数据集id
|
||||||
|
*/
|
||||||
|
@TableId
|
||||||
|
private Long id;
|
||||||
|
/**
|
||||||
|
* 数据集名称
|
||||||
|
*/
|
||||||
|
private String name;
|
||||||
|
/**
|
||||||
|
* 数据源id
|
||||||
|
*/
|
||||||
|
private Long datasourceId;
|
||||||
|
/**
|
||||||
|
* 动态查询SQL
|
||||||
|
*/
|
||||||
|
private String dbSql;
|
||||||
|
/**
|
||||||
|
* 参数列表
|
||||||
|
*/
|
||||||
|
@TableField(typeHandler = ObjectListTypeHandler.class)
|
||||||
|
private List<ReportDatasetParameterVO> params;
|
||||||
|
}
|
||||||
+69
@@ -0,0 +1,69 @@
|
|||||||
|
package com.cf.imes.module.report.dal.dataobject.template;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.KeySequence;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import com.cf.imes.framework.mybatis.core.dataobject.BaseDO;
|
||||||
|
import lombok.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 报表数据源DO
|
||||||
|
*
|
||||||
|
* @author Gqr
|
||||||
|
* @since 2024/7/8 11:01
|
||||||
|
*/
|
||||||
|
@TableName("report_datasource")
|
||||||
|
@KeySequence("report_datasource_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
@ToString(callSuper = true)
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class ReportDatasourceDO extends BaseDO {
|
||||||
|
/**
|
||||||
|
* 数据源id
|
||||||
|
*/
|
||||||
|
@TableId
|
||||||
|
private Long id;
|
||||||
|
/**
|
||||||
|
* 模板id
|
||||||
|
*/
|
||||||
|
private Long reportId;
|
||||||
|
/**
|
||||||
|
* 数据源名称
|
||||||
|
*/
|
||||||
|
private String name;
|
||||||
|
/**
|
||||||
|
* 模板类型,0内置、1自定义
|
||||||
|
*/
|
||||||
|
private Long type;
|
||||||
|
/**
|
||||||
|
* 数据库类型
|
||||||
|
*/
|
||||||
|
private String dbType;
|
||||||
|
/**
|
||||||
|
* 数据源驱动类
|
||||||
|
*/
|
||||||
|
private String dbDriver;
|
||||||
|
/**
|
||||||
|
* 数据源地址
|
||||||
|
*/
|
||||||
|
private String dbUrl;
|
||||||
|
/**
|
||||||
|
* 数据源用户名
|
||||||
|
*/
|
||||||
|
private String dbUsername;
|
||||||
|
/**
|
||||||
|
* 数据源密码
|
||||||
|
*/
|
||||||
|
private String dbPassword;
|
||||||
|
/**
|
||||||
|
* 备注
|
||||||
|
*/
|
||||||
|
private String remark;
|
||||||
|
/**
|
||||||
|
* 组织id
|
||||||
|
*/
|
||||||
|
private Long organId;
|
||||||
|
}
|
||||||
+48
@@ -0,0 +1,48 @@
|
|||||||
|
package com.cf.imes.module.report.dal.dataobject.template;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.*;
|
||||||
|
import com.cf.imes.framework.mybatis.core.dataobject.BaseDO;
|
||||||
|
import lombok.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 报表模板信息DO
|
||||||
|
*
|
||||||
|
* @author Gqr
|
||||||
|
* @since 2024/7/8 11:01
|
||||||
|
*/
|
||||||
|
@TableName("report_template")
|
||||||
|
@KeySequence("report_template_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
@ToString(callSuper = true)
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class ReportTemplateDO extends BaseDO {
|
||||||
|
/**
|
||||||
|
* 主键
|
||||||
|
*/
|
||||||
|
@TableId
|
||||||
|
private Long id;
|
||||||
|
/**
|
||||||
|
* 模板名称
|
||||||
|
*/
|
||||||
|
private String name;
|
||||||
|
/**
|
||||||
|
* 报表模板
|
||||||
|
*/
|
||||||
|
private String template;
|
||||||
|
/**
|
||||||
|
* 模板类型,0内置、1自定义
|
||||||
|
*/
|
||||||
|
private Long type;
|
||||||
|
/**
|
||||||
|
* 备注
|
||||||
|
*/
|
||||||
|
private String remark;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 组织id
|
||||||
|
*/
|
||||||
|
private Long organId;
|
||||||
|
}
|
||||||
+15
@@ -0,0 +1,15 @@
|
|||||||
|
package com.cf.imes.module.report.dal.mysql.template;
|
||||||
|
|
||||||
|
import com.cf.imes.framework.mybatis.core.mapper.BaseMapperX;
|
||||||
|
import com.cf.imes.module.report.dal.dataobject.template.ReportDatasetDO;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 报表数据集 Mapper
|
||||||
|
*
|
||||||
|
* @author Gqr
|
||||||
|
* @since 2024/7/8 11:55
|
||||||
|
*/
|
||||||
|
@Mapper
|
||||||
|
public interface ReportDatasetMapper extends BaseMapperX<ReportDatasetDO> {
|
||||||
|
}
|
||||||
+15
@@ -0,0 +1,15 @@
|
|||||||
|
package com.cf.imes.module.report.dal.mysql.template;
|
||||||
|
|
||||||
|
import com.cf.imes.framework.mybatis.core.mapper.BaseMapperX;
|
||||||
|
import com.cf.imes.module.report.dal.dataobject.template.ReportDatasourceDO;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 报表数据源 Mapper
|
||||||
|
*
|
||||||
|
* @author Gqr
|
||||||
|
* @since 2024/7/8 11:01
|
||||||
|
*/
|
||||||
|
@Mapper
|
||||||
|
public interface ReportDatasourceMapper extends BaseMapperX<ReportDatasourceDO> {
|
||||||
|
}
|
||||||
+15
@@ -0,0 +1,15 @@
|
|||||||
|
package com.cf.imes.module.report.dal.mysql.template;
|
||||||
|
|
||||||
|
import com.cf.imes.framework.mybatis.core.mapper.BaseMapperX;
|
||||||
|
import com.cf.imes.module.report.dal.dataobject.template.ReportTemplateDO;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 报表模板信息 Mapper
|
||||||
|
*
|
||||||
|
* @author Gqr
|
||||||
|
* @since 2024/7/3 11:43
|
||||||
|
*/
|
||||||
|
@Mapper
|
||||||
|
public interface ReportTemplateMapper extends BaseMapperX<ReportTemplateDO> {
|
||||||
|
}
|
||||||
+55
@@ -0,0 +1,55 @@
|
|||||||
|
package com.cf.imes.module.report.service.template;
|
||||||
|
|
||||||
|
import com.cf.imes.module.report.controller.admin.template.vo.ReportDatasetReqVO;
|
||||||
|
import com.cf.imes.module.report.controller.admin.template.vo.ReportDatasetSaveReqVO;
|
||||||
|
import com.cf.imes.module.report.dal.dataobject.template.ReportDatasetDO;
|
||||||
|
|
||||||
|
import javax.validation.Valid;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 报表数据集 Service 接口
|
||||||
|
*
|
||||||
|
* @author Gqr
|
||||||
|
* @since 2024/7/8 11:51
|
||||||
|
*/
|
||||||
|
public interface ReportDatasetService {
|
||||||
|
/**
|
||||||
|
* 创建报表数据集
|
||||||
|
*
|
||||||
|
* @param createReqVO 创建信息
|
||||||
|
* @return 编号
|
||||||
|
*/
|
||||||
|
Long createDataset(@Valid ReportDatasetSaveReqVO createReqVO);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新报表数据集
|
||||||
|
*
|
||||||
|
* @param updateReqVO 更新信息
|
||||||
|
*/
|
||||||
|
void updateDataset(@Valid ReportDatasetSaveReqVO updateReqVO);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除报表数据集
|
||||||
|
*
|
||||||
|
* @param id 编号
|
||||||
|
*/
|
||||||
|
void deleteDataset(Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获得报表数据集
|
||||||
|
*
|
||||||
|
* @param id 编号
|
||||||
|
* @return 报表数据集
|
||||||
|
*/
|
||||||
|
ReportDatasetDO getDataset(Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获得报表数据集分页
|
||||||
|
*
|
||||||
|
* @param pageReqVO 分页查询
|
||||||
|
* @return 报表数据集分页
|
||||||
|
*/
|
||||||
|
List<ReportDatasetDO> getDatasetList(ReportDatasetReqVO reqVO);
|
||||||
|
|
||||||
|
}
|
||||||
+74
@@ -0,0 +1,74 @@
|
|||||||
|
package com.cf.imes.module.report.service.template;
|
||||||
|
|
||||||
|
import com.cf.imes.framework.common.util.object.BeanUtils;
|
||||||
|
import com.cf.imes.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||||
|
import com.cf.imes.module.report.controller.admin.template.vo.ReportDatasetReqVO;
|
||||||
|
import com.cf.imes.module.report.controller.admin.template.vo.ReportDatasetSaveReqVO;
|
||||||
|
import com.cf.imes.module.report.dal.dataobject.template.ReportDatasetDO;
|
||||||
|
import com.cf.imes.module.report.dal.mysql.template.ReportDatasetMapper;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static com.cf.imes.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||||
|
import static com.cf.imes.module.report.enums.ErrorCodeConstants.DATASET_NOT_EXISTS;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 报表数据集 Service 实现类
|
||||||
|
*
|
||||||
|
* @author Gqr
|
||||||
|
* @since 2024/7/8 11:01
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
@Validated
|
||||||
|
public class ReportDatasetServiceImpl implements ReportDatasetService {
|
||||||
|
@Resource
|
||||||
|
private ReportDatasetMapper datasetMapper;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Long createDataset(ReportDatasetSaveReqVO createReqVO) {
|
||||||
|
// 插入
|
||||||
|
ReportDatasetDO dataset = BeanUtils.toBean(createReqVO, ReportDatasetDO.class);
|
||||||
|
datasetMapper.insert(dataset);
|
||||||
|
// 返回
|
||||||
|
return dataset.getId();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateDataset(ReportDatasetSaveReqVO updateReqVO) {
|
||||||
|
// 校验存在
|
||||||
|
validateDatasetExists(updateReqVO.getId());
|
||||||
|
// 更新
|
||||||
|
ReportDatasetDO updateObj = BeanUtils.toBean(updateReqVO, ReportDatasetDO.class);
|
||||||
|
datasetMapper.updateById(updateObj);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void deleteDataset(Long id) {
|
||||||
|
// 校验存在
|
||||||
|
validateDatasetExists(id);
|
||||||
|
// 删除
|
||||||
|
datasetMapper.deleteById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void validateDatasetExists(Long id) {
|
||||||
|
if (datasetMapper.selectById(id) == null) {
|
||||||
|
throw exception(DATASET_NOT_EXISTS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ReportDatasetDO getDataset(Long id) {
|
||||||
|
return datasetMapper.selectById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<ReportDatasetDO> getDatasetList(ReportDatasetReqVO reqVO) {
|
||||||
|
return datasetMapper.selectList(new LambdaQueryWrapperX<ReportDatasetDO>()
|
||||||
|
.eq(ReportDatasetDO::getDatasourceId, reqVO.getDatasourceId())
|
||||||
|
.likeIfPresent(ReportDatasetDO::getName, reqVO.getName())
|
||||||
|
.orderByDesc(ReportDatasetDO::getCreateTime));
|
||||||
|
}
|
||||||
|
}
|
||||||
+54
@@ -0,0 +1,54 @@
|
|||||||
|
package com.cf.imes.module.report.service.template;
|
||||||
|
|
||||||
|
import com.cf.imes.module.report.controller.admin.template.vo.ReportDatasourceReqVO;
|
||||||
|
import com.cf.imes.module.report.controller.admin.template.vo.ReportDatasourceSaveReqVO;
|
||||||
|
import com.cf.imes.module.report.dal.dataobject.template.ReportDatasourceDO;
|
||||||
|
|
||||||
|
import javax.validation.Valid;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 报表数据源 Service 接口
|
||||||
|
*
|
||||||
|
* @author Gqr
|
||||||
|
* @since 2024/7/8 11:01
|
||||||
|
*/
|
||||||
|
public interface ReportDatasourceService {
|
||||||
|
/**
|
||||||
|
* 创建报表数据源
|
||||||
|
*
|
||||||
|
* @param createReqVO 创建信息
|
||||||
|
* @return 编号
|
||||||
|
*/
|
||||||
|
Long createDatasource(@Valid ReportDatasourceSaveReqVO createReqVO);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新报表数据源
|
||||||
|
*
|
||||||
|
* @param updateReqVO 更新信息
|
||||||
|
*/
|
||||||
|
void updateDatasource(@Valid ReportDatasourceSaveReqVO updateReqVO);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除报表数据源
|
||||||
|
*
|
||||||
|
* @param id 编号
|
||||||
|
*/
|
||||||
|
void deleteDatasource(Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获得报表数据源
|
||||||
|
*
|
||||||
|
* @param id 编号
|
||||||
|
* @return 报表数据源
|
||||||
|
*/
|
||||||
|
ReportDatasourceDO getDatasource(Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取模板下的数据源列表
|
||||||
|
*
|
||||||
|
* @param pageReqVO 分页查询
|
||||||
|
* @return 报表数据源分页
|
||||||
|
*/
|
||||||
|
List<ReportDatasourceDO> getTemplateDatasourceList(ReportDatasourceReqVO pageReqVO);
|
||||||
|
}
|
||||||
+80
@@ -0,0 +1,80 @@
|
|||||||
|
package com.cf.imes.module.report.service.template;
|
||||||
|
|
||||||
|
import com.cf.imes.framework.common.util.object.BeanUtils;
|
||||||
|
import com.cf.imes.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||||
|
import com.cf.imes.module.report.controller.admin.template.vo.ReportDatasourceReqVO;
|
||||||
|
import com.cf.imes.module.report.controller.admin.template.vo.ReportDatasourceSaveReqVO;
|
||||||
|
import com.cf.imes.module.report.dal.dataobject.template.ReportDatasourceDO;
|
||||||
|
import com.cf.imes.module.report.dal.mysql.template.ReportDatasourceMapper;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static com.cf.imes.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||||
|
import static com.cf.imes.module.report.enums.ErrorCodeConstants.DATASOURCE_NOT_EXISTS;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 报表数据源 Service 实现类
|
||||||
|
*
|
||||||
|
* @author Gqr
|
||||||
|
* @since 2024/7/8 11:01
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
@Validated
|
||||||
|
public class ReportDatasourceServiceImpl implements ReportDatasourceService {
|
||||||
|
@Resource
|
||||||
|
private ReportDatasourceMapper datasourceMapper;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Long createDatasource(ReportDatasourceSaveReqVO createReqVO) {
|
||||||
|
// 插入
|
||||||
|
ReportDatasourceDO datasource = BeanUtils.toBean(createReqVO, ReportDatasourceDO.class);
|
||||||
|
datasourceMapper.insert(datasource);
|
||||||
|
// 返回
|
||||||
|
return datasource.getId();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateDatasource(ReportDatasourceSaveReqVO updateReqVO) {
|
||||||
|
// 校验存在
|
||||||
|
validateDatasourceExists(updateReqVO.getId());
|
||||||
|
// 更新
|
||||||
|
ReportDatasourceDO updateObj = BeanUtils.toBean(updateReqVO, ReportDatasourceDO.class);
|
||||||
|
datasourceMapper.updateById(updateObj);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void deleteDatasource(Long id) {
|
||||||
|
// 校验存在
|
||||||
|
validateDatasourceExists(id);
|
||||||
|
// 删除
|
||||||
|
datasourceMapper.deleteById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 校验数据源是否存在
|
||||||
|
*
|
||||||
|
* @param id
|
||||||
|
*/
|
||||||
|
private void validateDatasourceExists(Long id) {
|
||||||
|
if (datasourceMapper.selectById(id) == null) {
|
||||||
|
throw exception(DATASOURCE_NOT_EXISTS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ReportDatasourceDO getDatasource(Long id) {
|
||||||
|
return datasourceMapper.selectById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<ReportDatasourceDO> getTemplateDatasourceList(ReportDatasourceReqVO reqVO) {
|
||||||
|
return datasourceMapper.selectList(new LambdaQueryWrapperX<ReportDatasourceDO>()
|
||||||
|
.eq(ReportDatasourceDO::getReportId, reqVO.getReportId())
|
||||||
|
.likeIfPresent(ReportDatasourceDO::getName, reqVO.getName())
|
||||||
|
.eq(ReportDatasourceDO::getType, reqVO.getType())
|
||||||
|
.orderByDesc(ReportDatasourceDO::getCreateTime));
|
||||||
|
}
|
||||||
|
}
|
||||||
+54
@@ -0,0 +1,54 @@
|
|||||||
|
package com.cf.imes.module.report.service.template;
|
||||||
|
|
||||||
|
import com.cf.imes.module.report.controller.admin.template.vo.ReportTemplateReqVO;
|
||||||
|
import com.cf.imes.module.report.controller.admin.template.vo.ReportTemplateSaveReqVO;
|
||||||
|
import com.cf.imes.module.report.dal.dataobject.template.ReportTemplateDO;
|
||||||
|
|
||||||
|
import javax.validation.Valid;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 报表模板信息 Service 接口
|
||||||
|
*
|
||||||
|
* @author Gqr
|
||||||
|
* @since 2024/7/3 11:56
|
||||||
|
*/
|
||||||
|
public interface ReportTemplateService {
|
||||||
|
/**
|
||||||
|
* 创建报表模板信息
|
||||||
|
*
|
||||||
|
* @param createReqVO 创建信息
|
||||||
|
* @return 编号
|
||||||
|
*/
|
||||||
|
Long createReportTemplate(@Valid ReportTemplateSaveReqVO createReqVO);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新报表模板信息
|
||||||
|
*
|
||||||
|
* @param updateReqVO 更新信息
|
||||||
|
*/
|
||||||
|
void updateReportTemplate(@Valid ReportTemplateSaveReqVO updateReqVO);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除报表模板信息
|
||||||
|
*
|
||||||
|
* @param id 编号
|
||||||
|
*/
|
||||||
|
void deleteReportTemplate(Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获得报表模板信息
|
||||||
|
*
|
||||||
|
* @param id 编号
|
||||||
|
* @return 报表模板信息
|
||||||
|
*/
|
||||||
|
ReportTemplateDO getReportTemplate(Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获得报表模板信息列表
|
||||||
|
*
|
||||||
|
* @param pageReqVO 查询参数
|
||||||
|
* @return 报表模板信息列表
|
||||||
|
*/
|
||||||
|
List<ReportTemplateDO> getReportTemplateList(ReportTemplateReqVO pageReqVO);
|
||||||
|
}
|
||||||
+88
@@ -0,0 +1,88 @@
|
|||||||
|
package com.cf.imes.module.report.service.template;
|
||||||
|
|
||||||
|
import com.cf.imes.framework.common.util.object.BeanUtils;
|
||||||
|
import com.cf.imes.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||||
|
import com.cf.imes.module.report.controller.admin.template.vo.ReportTemplateReqVO;
|
||||||
|
import com.cf.imes.module.report.controller.admin.template.vo.ReportTemplateSaveReqVO;
|
||||||
|
import com.cf.imes.module.report.dal.dataobject.template.ReportTemplateDO;
|
||||||
|
import com.cf.imes.module.report.dal.mysql.template.ReportTemplateMapper;
|
||||||
|
import com.cf.imes.module.report.enums.ErrorCodeConstants;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static com.cf.imes.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 报表模板信息 Service 实现类
|
||||||
|
*
|
||||||
|
* @author Gqr
|
||||||
|
* @since 2024/7/3 12:00
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
@Validated
|
||||||
|
public class ReportTemplateServiceImpl implements ReportTemplateService {
|
||||||
|
@Resource
|
||||||
|
private ReportTemplateMapper templateMapper;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Long createReportTemplate(ReportTemplateSaveReqVO createReqVO) {
|
||||||
|
String templateContent = createReqVO.getTemplate();
|
||||||
|
if(StringUtils.isNotEmpty(templateContent)) {
|
||||||
|
// todo template压缩待完善
|
||||||
|
}
|
||||||
|
// 插入
|
||||||
|
ReportTemplateDO template = BeanUtils.toBean(createReqVO, ReportTemplateDO.class);
|
||||||
|
templateMapper.insert(template);
|
||||||
|
// 返回主键
|
||||||
|
return template.getId();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateReportTemplate(ReportTemplateSaveReqVO updateReqVO) {
|
||||||
|
// 校验存在
|
||||||
|
validateTemplateExists(updateReqVO.getId());
|
||||||
|
String templateContent = updateReqVO.getTemplate();
|
||||||
|
if (StringUtils.isNotEmpty(templateContent)) {
|
||||||
|
// todo template压缩待完善
|
||||||
|
}
|
||||||
|
// 更新
|
||||||
|
ReportTemplateDO updateObj = BeanUtils.toBean(updateReqVO, ReportTemplateDO.class);
|
||||||
|
templateMapper.updateById(updateObj);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void deleteReportTemplate(Long id) {
|
||||||
|
// 校验存在
|
||||||
|
validateTemplateExists(id);
|
||||||
|
// 删除
|
||||||
|
templateMapper.deleteById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 校验模板是否存在
|
||||||
|
*
|
||||||
|
* @param id
|
||||||
|
*/
|
||||||
|
private void validateTemplateExists(Long id) {
|
||||||
|
if (templateMapper.selectById(id) == null) {
|
||||||
|
throw exception(ErrorCodeConstants.TEMPLATE_NOT_EXISTS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ReportTemplateDO getReportTemplate(Long id) {
|
||||||
|
return templateMapper.selectById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<ReportTemplateDO> getReportTemplateList(ReportTemplateReqVO reqVO) {
|
||||||
|
return templateMapper.selectList(new LambdaQueryWrapperX<ReportTemplateDO>()
|
||||||
|
.likeIfPresent(ReportTemplateDO::getName, reqVO.getName())
|
||||||
|
.eq(ReportTemplateDO::getType, reqVO.getType())
|
||||||
|
.orderByDesc(ReportTemplateDO::getCreateTime));
|
||||||
|
}
|
||||||
|
}
|
||||||
-58
@@ -1,58 +0,0 @@
|
|||||||
package com.cf.imes.module.report.service.goview;
|
|
||||||
|
|
||||||
import com.cf.imes.framework.test.core.ut.BaseDbUnitTest;
|
|
||||||
import com.cf.imes.module.report.controller.admin.goview.vo.data.GoViewDataRespVO;
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
|
||||||
import org.springframework.context.annotation.Import;
|
|
||||||
import org.springframework.jdbc.core.JdbcTemplate;
|
|
||||||
import org.springframework.jdbc.support.rowset.SqlRowSet;
|
|
||||||
import org.springframework.jdbc.support.rowset.SqlRowSetMetaData;
|
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
|
||||||
import java.util.Arrays;
|
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
||||||
import static org.mockito.ArgumentMatchers.eq;
|
|
||||||
import static org.mockito.Mockito.mock;
|
|
||||||
import static org.mockito.Mockito.when;
|
|
||||||
|
|
||||||
@Import(GoViewDataServiceImpl.class)
|
|
||||||
public class GoViewDataServiceImplTest extends BaseDbUnitTest {
|
|
||||||
|
|
||||||
@Resource
|
|
||||||
private GoViewDataServiceImpl goViewDataService;
|
|
||||||
|
|
||||||
@MockBean
|
|
||||||
private JdbcTemplate jdbcTemplate;
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testGetDataBySQL() {
|
|
||||||
// 准备参数
|
|
||||||
String sql = "SELECT id, name FROM system_users";
|
|
||||||
// mock 方法
|
|
||||||
SqlRowSet sqlRowSet = mock(SqlRowSet.class);
|
|
||||||
when(jdbcTemplate.queryForRowSet(eq(sql))).thenReturn(sqlRowSet);
|
|
||||||
// mock 元数据
|
|
||||||
SqlRowSetMetaData metaData = mock(SqlRowSetMetaData.class);
|
|
||||||
when(sqlRowSet.getMetaData()).thenReturn(metaData);
|
|
||||||
when(metaData.getColumnNames()).thenReturn(new String[]{"id", "name"});
|
|
||||||
// mock 数据明细
|
|
||||||
when(sqlRowSet.next()).thenReturn(true).thenReturn(true).thenReturn(false);
|
|
||||||
when(sqlRowSet.getObject("id")).thenReturn(1L).thenReturn(2L);
|
|
||||||
when(sqlRowSet.getObject("name")).thenReturn("晨丰科技").thenReturn("晨丰");
|
|
||||||
|
|
||||||
// 调用
|
|
||||||
GoViewDataRespVO dataBySQL = goViewDataService.getDataBySQL(sql);
|
|
||||||
// 断言
|
|
||||||
assertEquals(Arrays.asList("id", "name"), dataBySQL.getDimensions());
|
|
||||||
assertEquals(2, dataBySQL.getDimensions().size());
|
|
||||||
assertEquals(2, dataBySQL.getSource().get(0).size());
|
|
||||||
assertEquals(1L, dataBySQL.getSource().get(0).get("id"));
|
|
||||||
assertEquals("晨丰科技", dataBySQL.getSource().get(0).get("name"));
|
|
||||||
assertEquals(2, dataBySQL.getSource().get(1).size());
|
|
||||||
assertEquals(2L, dataBySQL.getSource().get(1).get("id"));
|
|
||||||
assertEquals("晨丰", dataBySQL.getSource().get(1).get("name"));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
-135
@@ -1,135 +0,0 @@
|
|||||||
package com.cf.imes.module.report.service.goview;
|
|
||||||
|
|
||||||
import com.cf.imes.framework.common.pojo.PageParam;
|
|
||||||
import com.cf.imes.framework.common.pojo.PageResult;
|
|
||||||
import com.cf.imes.framework.test.core.ut.BaseDbUnitTest;
|
|
||||||
import com.cf.imes.module.report.controller.admin.goview.vo.project.GoViewProjectCreateReqVO;
|
|
||||||
import com.cf.imes.module.report.controller.admin.goview.vo.project.GoViewProjectUpdateReqVO;
|
|
||||||
import com.cf.imes.module.report.dal.dataobject.goview.GoViewProjectDO;
|
|
||||||
import com.cf.imes.module.report.dal.mysql.goview.GoViewProjectMapper;
|
|
||||||
import com.cf.imes.module.report.enums.ErrorCodeConstants;
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
import org.springframework.context.annotation.Import;
|
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
|
||||||
|
|
||||||
import static com.cf.imes.framework.common.util.object.ObjectUtils.cloneIgnoreId;
|
|
||||||
import static com.cf.imes.framework.test.core.util.AssertUtils.assertPojoEquals;
|
|
||||||
import static com.cf.imes.framework.test.core.util.AssertUtils.assertServiceException;
|
|
||||||
import static com.cf.imes.framework.test.core.util.RandomUtils.*;
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@link GoViewProjectServiceImpl} 的单元测试类
|
|
||||||
*
|
|
||||||
* @author 晨丰科技
|
|
||||||
*/
|
|
||||||
@Import(GoViewProjectServiceImpl.class)
|
|
||||||
public class GoViewProjectServiceImplTest extends BaseDbUnitTest {
|
|
||||||
|
|
||||||
@Resource
|
|
||||||
private GoViewProjectServiceImpl goViewProjectService;
|
|
||||||
|
|
||||||
@Resource
|
|
||||||
private GoViewProjectMapper goViewProjectMapper;
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testCreateProject_success() {
|
|
||||||
// 准备参数
|
|
||||||
GoViewProjectCreateReqVO reqVO = randomPojo(GoViewProjectCreateReqVO.class);
|
|
||||||
|
|
||||||
// 调用
|
|
||||||
Long goViewProjectId = goViewProjectService.createProject(reqVO);
|
|
||||||
// 断言
|
|
||||||
assertNotNull(goViewProjectId);
|
|
||||||
// 校验记录的属性是否正确
|
|
||||||
GoViewProjectDO goViewProject = goViewProjectMapper.selectById(goViewProjectId);
|
|
||||||
assertPojoEquals(reqVO, goViewProject);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testUpdateProject_success() {
|
|
||||||
// mock 数据
|
|
||||||
GoViewProjectDO dbGoViewProject = randomPojo(GoViewProjectDO.class);
|
|
||||||
goViewProjectMapper.insert(dbGoViewProject);// @Sql: 先插入出一条存在的数据
|
|
||||||
// 准备参数
|
|
||||||
GoViewProjectUpdateReqVO reqVO = randomPojo(GoViewProjectUpdateReqVO.class, o -> {
|
|
||||||
o.setId(dbGoViewProject.getId()); // 设置更新的 ID
|
|
||||||
o.setStatus(randomCommonStatus());
|
|
||||||
});
|
|
||||||
|
|
||||||
// 调用
|
|
||||||
goViewProjectService.updateProject(reqVO);
|
|
||||||
// 校验是否更新正确
|
|
||||||
GoViewProjectDO goViewProject = goViewProjectMapper.selectById(reqVO.getId()); // 获取最新的
|
|
||||||
assertPojoEquals(reqVO, goViewProject);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testUpdateProject_notExists() {
|
|
||||||
// 准备参数
|
|
||||||
GoViewProjectUpdateReqVO reqVO = randomPojo(GoViewProjectUpdateReqVO.class);
|
|
||||||
|
|
||||||
// 调用, 并断言异常
|
|
||||||
assertServiceException(() -> goViewProjectService.updateProject(reqVO), ErrorCodeConstants.GO_VIEW_PROJECT_NOT_EXISTS);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testDeleteProject_success() {
|
|
||||||
// mock 数据
|
|
||||||
GoViewProjectDO dbGoViewProject = randomPojo(GoViewProjectDO.class);
|
|
||||||
goViewProjectMapper.insert(dbGoViewProject);// @Sql: 先插入出一条存在的数据
|
|
||||||
// 准备参数
|
|
||||||
Long id = dbGoViewProject.getId();
|
|
||||||
|
|
||||||
// 调用
|
|
||||||
goViewProjectService.deleteProject(id);
|
|
||||||
// 校验数据不存在了
|
|
||||||
assertNull(goViewProjectMapper.selectById(id));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testDeleteProject_notExists() {
|
|
||||||
// 准备参数
|
|
||||||
Long id = randomLongId();
|
|
||||||
|
|
||||||
// 调用, 并断言异常
|
|
||||||
assertServiceException(() -> goViewProjectService.deleteProject(id), ErrorCodeConstants.GO_VIEW_PROJECT_NOT_EXISTS);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testGetProject() {
|
|
||||||
// mock 数据
|
|
||||||
GoViewProjectDO dbGoViewProject = randomPojo(GoViewProjectDO.class);
|
|
||||||
goViewProjectMapper.insert(dbGoViewProject);// @Sql: 先插入出一条存在的数据
|
|
||||||
// 准备参数
|
|
||||||
Long id = dbGoViewProject.getId();
|
|
||||||
|
|
||||||
// 调用
|
|
||||||
GoViewProjectDO goViewProject = goViewProjectService.getProject(id);
|
|
||||||
// 断言
|
|
||||||
assertPojoEquals(dbGoViewProject, goViewProject);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testGetMyGoViewProjectPage() {
|
|
||||||
// mock 数据
|
|
||||||
GoViewProjectDO dbGoViewProject = randomPojo(GoViewProjectDO.class, o -> { // 等会查询到
|
|
||||||
o.setCreator("1");
|
|
||||||
});
|
|
||||||
goViewProjectMapper.insert(dbGoViewProject);
|
|
||||||
// 测试 userId 不匹配
|
|
||||||
goViewProjectMapper.insert(cloneIgnoreId(dbGoViewProject, o -> o.setCreator("2")));
|
|
||||||
// 准备参数
|
|
||||||
PageParam reqVO = new PageParam();
|
|
||||||
Long userId = 1L;
|
|
||||||
|
|
||||||
// 调用
|
|
||||||
PageResult<GoViewProjectDO> pageResult = goViewProjectService.getMyProjectPage(reqVO, userId);
|
|
||||||
// 断言
|
|
||||||
assertEquals(1, pageResult.getTotal());
|
|
||||||
assertEquals(1, pageResult.getList().size());
|
|
||||||
assertPojoEquals(dbGoViewProject, pageResult.getList().get(0));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
+146
@@ -0,0 +1,146 @@
|
|||||||
|
package com.cf.imes.module.report.service.template;
|
||||||
|
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Base64;
|
||||||
|
import java.util.zip.*;
|
||||||
|
|
||||||
|
public class JsonUtil {
|
||||||
|
|
||||||
|
|
||||||
|
public static void main(String[] args) throws IOException {
|
||||||
|
|
||||||
|
String data = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><ureport><cell expand=\"None\" name=\"A1\" row=\"1\" col=\"1\"><cell-style font-size=\"10\" align=\"center\" valign=\"middle\"></cell-style><simple-value><![CDATA[]]></simple-value></cell><cell expand=\"None\" name=\"B1\" row=\"1\" col=\"2\"><cell-style font-size=\"10\" align=\"center\" valign=\"middle\"></cell-style><simple-value><![CDATA[]]></simple-value></cell><cell expand=\"None\" name=\"C1\" row=\"1\" col=\"3\"><cell-style font-size=\"10\" align=\"center\" valign=\"middle\"></cell-style><simple-value><![CDATA[]]></simple-value></cell><cell expand=\"None\" name=\"D1\" row=\"1\" col=\"4\"><cell-style font-size=\"10\" align=\"center\" valign=\"middle\"></cell-style><simple-value><![CDATA[]]></simple-value></cell><cell expand=\"None\" name=\"A2\" row=\"2\" col=\"1\"><cell-style font-size=\"10\" align=\"center\" valign=\"middle\"></cell-style><simple-value><![CDATA[]]></simple-value></cell><cell expand=\"None\" name=\"B2\" row=\"2\" col=\"2\"><cell-style font-size=\"10\" align=\"center\" valign=\"middle\"></cell-style><simple-value><![CDATA[]]></simple-value></cell><cell expand=\"None\" name=\"C2\" row=\"2\" col=\"3\"><cell-style font-size=\"10\" align=\"center\" valign=\"middle\"></cell-style><simple-value><![CDATA[]]></simple-value></cell><cell expand=\"None\" name=\"D2\" row=\"2\" col=\"4\"><cell-style font-size=\"10\" align=\"center\" valign=\"middle\"></cell-style><simple-value><![CDATA[]]></simple-value></cell><cell expand=\"None\" name=\"A3\" row=\"3\" col=\"1\"><cell-style font-size=\"10\" align=\"center\" valign=\"middle\"></cell-style><simple-value><![CDATA[]]></simple-value></cell><cell expand=\"None\" name=\"B3\" row=\"3\" col=\"2\"><cell-style font-size=\"10\" align=\"center\" valign=\"middle\"></cell-style><simple-value><![CDATA[]]></simple-value></cell><cell expand=\"None\" name=\"C3\" row=\"3\" col=\"3\"><cell-style font-size=\"10\" align=\"center\" valign=\"middle\"></cell-style><simple-value><![CDATA[]]></simple-value></cell><cell expand=\"None\" name=\"D3\" row=\"3\" col=\"4\"><cell-style font-size=\"10\" align=\"center\" valign=\"middle\"></cell-style><simple-value><![CDATA[]]></simple-value></cell><row row-number=\"1\" height=\"18\"/><row row-number=\"2\" height=\"18\"/><row row-number=\"3\" height=\"18\"/><column col-number=\"1\" width=\"80\"/><column col-number=\"2\" width=\"80\"/><column col-number=\"3\" width=\"80\"/><column col-number=\"4\" width=\"80\"/><paper type=\"A4\" left-margin=\"90\" right-margin=\"90\" top-margin=\"72\" bottom-margin=\"72\" paging-mode=\"fitpage\" fixrows=\"0\" width=\"595\" height=\"842\" orientation=\"portrait\" html-report-align=\"left\" bg-image=\"\" html-interval-refresh-value=\"0\" column-enabled=\"false\"></paper></ureport>";
|
||||||
|
System.out.println("原始大小:" + data.length());
|
||||||
|
|
||||||
|
|
||||||
|
String zip = zipString(data);
|
||||||
|
System.out.println("zip压缩后大小:"+zip.length());
|
||||||
|
String unzip = unzipString(zip);
|
||||||
|
System.out.println(unzip);
|
||||||
|
|
||||||
|
String compress = compress(data);
|
||||||
|
System.out.println("compress压缩后大小:"+compress.length());
|
||||||
|
String unCompress = unCompress(compress);
|
||||||
|
System.out.println(unCompress);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 压缩
|
||||||
|
*/
|
||||||
|
public static String zipString(String unzipString) {
|
||||||
|
/**
|
||||||
|
* https://www.yiibai.com/javazip/javazip_deflater.html#article-start
|
||||||
|
* 0 ~ 9 压缩等级 低到高
|
||||||
|
* public static final int BEST_COMPRESSION = 9; 最佳压缩的压缩级别。
|
||||||
|
* public static final int BEST_SPEED = 1; 压缩级别最快的压缩。
|
||||||
|
* public static final int DEFAULT_COMPRESSION = -1; 默认压缩级别。
|
||||||
|
* public static final int DEFAULT_STRATEGY = 0; 默认压缩策略。
|
||||||
|
* public static final int DEFLATED = 8; 压缩算法的压缩方法(目前唯一支持的压缩方法)。
|
||||||
|
* public static final int FILTERED = 1; 压缩策略最适用于大部分数值较小且数据分布随机分布的数据。
|
||||||
|
* public static final int FULL_FLUSH = 3; 压缩刷新模式,用于清除所有待处理的输出并重置拆卸器。
|
||||||
|
* public static final int HUFFMAN_ONLY = 2; 仅用于霍夫曼编码的压缩策略。
|
||||||
|
* public static final int NO_COMPRESSION = 0; 不压缩的压缩级别。
|
||||||
|
* public static final int NO_FLUSH = 0; 用于实现最佳压缩结果的压缩刷新模式。
|
||||||
|
* public static final int SYNC_FLUSH = 2; 用于清除所有未决输出的压缩刷新模式; 可能会降低某些压缩算法的压缩率。
|
||||||
|
*/
|
||||||
|
|
||||||
|
//使用指定的压缩级别创建一个新的压缩器。
|
||||||
|
Deflater deflater = new Deflater(Deflater.BEST_COMPRESSION);
|
||||||
|
//设置压缩输入数据。
|
||||||
|
deflater.setInput(unzipString.getBytes());
|
||||||
|
//当被调用时,表示压缩应该以输入缓冲区的当前内容结束。
|
||||||
|
deflater.finish();
|
||||||
|
|
||||||
|
final byte[] bytes = new byte[256];
|
||||||
|
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(256);
|
||||||
|
|
||||||
|
while (!deflater.finished()) {
|
||||||
|
//压缩输入数据并用压缩数据填充指定的缓冲区。
|
||||||
|
int length = deflater.deflate(bytes);
|
||||||
|
outputStream.write(bytes, 0, length);
|
||||||
|
}
|
||||||
|
//关闭压缩器并丢弃任何未处理的输入。
|
||||||
|
deflater.end();
|
||||||
|
return Base64.getEncoder().encodeToString(outputStream.toByteArray());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 解压缩
|
||||||
|
*/
|
||||||
|
public static String unzipString(String zipString) {
|
||||||
|
byte[] decode = Base64.getDecoder().decode(zipString);
|
||||||
|
|
||||||
|
//创建一个新的解压缩器 https://www.yiibai.com/javazip/javazip_inflater.html
|
||||||
|
|
||||||
|
Inflater inflater = new Inflater();
|
||||||
|
//设置解压缩的输入数据。
|
||||||
|
inflater.setInput(decode);
|
||||||
|
final byte[] bytes = new byte[256];
|
||||||
|
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(256);
|
||||||
|
try {
|
||||||
|
//finished() 如果已到达压缩数据流的末尾,则返回true。
|
||||||
|
while (!inflater.finished()) {
|
||||||
|
//将字节解压缩到指定的缓冲区中。
|
||||||
|
int length = inflater.inflate(bytes);
|
||||||
|
outputStream.write(bytes, 0, length);
|
||||||
|
}
|
||||||
|
} catch (DataFormatException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return null;
|
||||||
|
} finally {
|
||||||
|
//关闭解压缩器并丢弃任何未处理的输入。
|
||||||
|
inflater.end();
|
||||||
|
}
|
||||||
|
|
||||||
|
return outputStream.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// 使用 GZIP 进行压缩
|
||||||
|
public static String compress(String str) throws IOException {
|
||||||
|
if (null == str || str.length() <= 0) {
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
// 创建一个新的输出流
|
||||||
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||||
|
// 使用默认缓冲区大小创建新的输出流
|
||||||
|
GZIPOutputStream gzip = new GZIPOutputStream(out);
|
||||||
|
// 将字节写入此输出流
|
||||||
|
gzip.write(str.getBytes("utf-8")); // 因为后台默认字符集有可能是GBK字符集,所以此处需指定一个字符集
|
||||||
|
gzip.close();
|
||||||
|
// 使用指定的 charsetName,通过解码字节将缓冲区内容转换为字符串
|
||||||
|
return out.toString("ISO-8859-1");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// 解压缩
|
||||||
|
public static String unCompress(String str) throws IOException {
|
||||||
|
if (null == str || str.length() <= 0) {
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
// 创建一个新的输出流
|
||||||
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||||
|
// 创建一个 ByteArrayInputStream,使用 buf 作为其缓冲 区数组
|
||||||
|
ByteArrayInputStream in = new ByteArrayInputStream(str.getBytes("ISO-8859-1"));
|
||||||
|
// 使用默认缓冲区大小创建新的输入流
|
||||||
|
GZIPInputStream gzip = new GZIPInputStream(in);
|
||||||
|
byte[] buffer = new byte[256];
|
||||||
|
int n = 0;
|
||||||
|
|
||||||
|
// 将未压缩数据读入字节数组
|
||||||
|
while ((n = gzip.read(buffer)) >= 0) {
|
||||||
|
out.write(buffer, 0, n);
|
||||||
|
}
|
||||||
|
// 使用指定的 charsetName,通过解码字节将缓冲区内容转换为字符串
|
||||||
|
return out.toString("utf-8");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
+66
@@ -0,0 +1,66 @@
|
|||||||
|
package com.cf.imes.module.report.service.template;
|
||||||
|
|
||||||
|
import com.cf.imes.framework.organ.core.context.OrganContextHolder;
|
||||||
|
import com.cf.imes.framework.test.core.util.RandomUtils;
|
||||||
|
import com.cf.imes.module.report.controller.admin.template.vo.ReportDatasetParameterVO;
|
||||||
|
import com.cf.imes.module.report.controller.admin.template.vo.ReportDatasetSaveReqVO;
|
||||||
|
import com.cf.imes.module.report.controller.admin.template.vo.ReportDatasourceSaveReqVO;
|
||||||
|
import com.cf.imes.module.report.controller.admin.template.vo.ReportTemplateSaveReqVO;
|
||||||
|
import com.cf.imes.module.report.enums.template.ReportTemplateTypeEnum;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Gqr
|
||||||
|
* @since 2024/7/5 17:05
|
||||||
|
*/
|
||||||
|
public abstract class ReportCommonServiceImplTest {
|
||||||
|
|
||||||
|
protected static final String TEMPLATE = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><ureport><cell expand=\"None\" name=\"A1\" row=\"1\" col=\"1\"><cell-style font-size=\"10\" align=\"center\" valign=\"middle\"></cell-style><simple-value><![CDATA[]]></simple-value></cell><cell expand=\"None\" name=\"B1\" row=\"1\" col=\"2\"><cell-style font-size=\"10\" align=\"center\" valign=\"middle\"></cell-style><simple-value><![CDATA[]]></simple-value></cell><cell expand=\"None\" name=\"C1\" row=\"1\" col=\"3\"><cell-style font-size=\"10\" align=\"center\" valign=\"middle\"></cell-style><simple-value><![CDATA[]]></simple-value></cell><cell expand=\"None\" name=\"D1\" row=\"1\" col=\"4\"><cell-style font-size=\"10\" align=\"center\" valign=\"middle\"></cell-style><simple-value><![CDATA[]]></simple-value></cell><cell expand=\"None\" name=\"A2\" row=\"2\" col=\"1\"><cell-style font-size=\"10\" align=\"center\" valign=\"middle\"></cell-style><simple-value><![CDATA[]]></simple-value></cell><cell expand=\"None\" name=\"B2\" row=\"2\" col=\"2\"><cell-style font-size=\"10\" align=\"center\" valign=\"middle\"></cell-style><simple-value><![CDATA[]]></simple-value></cell><cell expand=\"None\" name=\"C2\" row=\"2\" col=\"3\"><cell-style font-size=\"10\" align=\"center\" valign=\"middle\"></cell-style><simple-value><![CDATA[]]></simple-value></cell><cell expand=\"None\" name=\"D2\" row=\"2\" col=\"4\"><cell-style font-size=\"10\" align=\"center\" valign=\"middle\"></cell-style><simple-value><![CDATA[]]></simple-value></cell><cell expand=\"None\" name=\"A3\" row=\"3\" col=\"1\"><cell-style font-size=\"10\" align=\"center\" valign=\"middle\"></cell-style><simple-value><![CDATA[]]></simple-value></cell><cell expand=\"None\" name=\"B3\" row=\"3\" col=\"2\"><cell-style font-size=\"10\" align=\"center\" valign=\"middle\"></cell-style><simple-value><![CDATA[]]></simple-value></cell><cell expand=\"None\" name=\"C3\" row=\"3\" col=\"3\"><cell-style font-size=\"10\" align=\"center\" valign=\"middle\"></cell-style><simple-value><![CDATA[]]></simple-value></cell><cell expand=\"None\" name=\"D3\" row=\"3\" col=\"4\"><cell-style font-size=\"10\" align=\"center\" valign=\"middle\"></cell-style><simple-value><![CDATA[]]></simple-value></cell><row row-number=\"1\" height=\"18\"/><row row-number=\"2\" height=\"18\"/><row row-number=\"3\" height=\"18\"/><column col-number=\"1\" width=\"80\"/><column col-number=\"2\" width=\"80\"/><column col-number=\"3\" width=\"80\"/><column col-number=\"4\" width=\"80\"/><paper type=\"A4\" left-margin=\"90\" right-margin=\"90\" top-margin=\"72\" bottom-margin=\"72\" paging-mode=\"fitpage\" fixrows=\"0\" width=\"595\" height=\"842\" orientation=\"portrait\" html-report-align=\"left\" bg-image=\"\" html-interval-refresh-value=\"0\" column-enabled=\"false\"></paper></ureport>";
|
||||||
|
|
||||||
|
protected void setOrganId(Long... organId) {
|
||||||
|
OrganContextHolder.setOrganId(organId.length > 0 ? organId[0] : 1L);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected ReportTemplateSaveReqVO prepareTemplateReqVO(Long id) {
|
||||||
|
return ReportTemplateSaveReqVO.builder()
|
||||||
|
.id(id)
|
||||||
|
.name("单元测试模板")
|
||||||
|
.template(JsonUtil.zipString(TEMPLATE))
|
||||||
|
.type(ReportTemplateTypeEnum.SYSTEM.getType())
|
||||||
|
.remark(RandomUtils.randomString())
|
||||||
|
.build();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected ReportDatasourceSaveReqVO prepareDatasourceReqVO(Long id, Long reportId) {
|
||||||
|
return ReportDatasourceSaveReqVO.builder()
|
||||||
|
.id(id)
|
||||||
|
.name("单元测试数据源")
|
||||||
|
.reportId(reportId)
|
||||||
|
.type(ReportTemplateTypeEnum.SYSTEM.getType())
|
||||||
|
.dbDriver("com.mysql.cj.jdbc.Driver")
|
||||||
|
.dbUrl("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")
|
||||||
|
.dbUsername("root")
|
||||||
|
.dbPassword("root")
|
||||||
|
.remark(RandomUtils.randomString())
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected ReportDatasetSaveReqVO prepareDatasetReqVO(Long id, Long datasourceId) {
|
||||||
|
ReportDatasetParameterVO idvo = new ReportDatasetParameterVO("id", 1, "1");
|
||||||
|
ReportDatasetParameterVO appidvo = new ReportDatasetParameterVO("app_id", 2, "CF7526AD51");
|
||||||
|
List<ReportDatasetParameterVO> params = new ArrayList<>() {{
|
||||||
|
add(idvo);
|
||||||
|
add(appidvo);
|
||||||
|
}};
|
||||||
|
return ReportDatasetSaveReqVO.builder()
|
||||||
|
.id(id)
|
||||||
|
.name("单元测试数据集")
|
||||||
|
.dbSql("select * from application where id = \"${param(\"id\")}\" and app_id = \"${param(\"app_id\")}\"")
|
||||||
|
.datasourceId(datasourceId)
|
||||||
|
.params(params)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
}
|
||||||
+113
@@ -0,0 +1,113 @@
|
|||||||
|
package com.cf.imes.module.report.service.template;
|
||||||
|
|
||||||
|
import com.cf.imes.framework.test.core.util.RandomUtils;
|
||||||
|
import com.cf.imes.module.report.controller.admin.template.vo.*;
|
||||||
|
import com.cf.imes.module.report.dal.dataobject.template.ReportDatasetDO;
|
||||||
|
import com.cf.imes.module.report.dal.dataobject.template.ReportDatasourceDO;
|
||||||
|
import com.cf.imes.module.report.dal.dataobject.template.ReportTemplateDO;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static com.cf.imes.framework.test.core.util.AssertUtils.assertServiceException;
|
||||||
|
import static com.cf.imes.framework.test.core.util.AssertUtils.isPojoEquals;
|
||||||
|
import static com.cf.imes.module.report.enums.ErrorCodeConstants.DATASET_NOT_EXISTS;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Gqr
|
||||||
|
* @since 2024/7/8 14:22
|
||||||
|
*/
|
||||||
|
@SpringBootTest
|
||||||
|
public class ReportDatasetServiceImplTest extends ReportCommonServiceImplTest{
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private ReportDatasetService reportDatasetService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private ReportTemplateService reportTemplateService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private ReportDatasourceService reportDatasourceService;
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCreateDataset_success() {
|
||||||
|
// 1、上下文添加组织id
|
||||||
|
setOrganId();
|
||||||
|
|
||||||
|
// 1、准备template参数
|
||||||
|
// 2、插入template、断言自增id
|
||||||
|
// 3、用id查template、断言对象
|
||||||
|
ReportTemplateSaveReqVO createReqVO = prepareTemplateReqVO(null);
|
||||||
|
Long templateId = reportTemplateService.createReportTemplate(createReqVO);
|
||||||
|
assertNotNull(templateId);
|
||||||
|
ReportTemplateDO template = reportTemplateService.getReportTemplate(templateId);
|
||||||
|
assertNotNull(template);
|
||||||
|
|
||||||
|
// 1、准备datasource参数
|
||||||
|
// 2、插入datasource、断言自增id
|
||||||
|
// 3、用id查datasource、断言对象
|
||||||
|
ReportDatasourceSaveReqVO datasourceSaveReqVO = prepareDatasourceReqVO(null, templateId);
|
||||||
|
Long datasourceId = reportDatasourceService.createDatasource(datasourceSaveReqVO);
|
||||||
|
assertNotNull(datasourceId);
|
||||||
|
ReportDatasourceDO datasource = reportDatasourceService.getDatasource(datasourceId);
|
||||||
|
assertNotNull(datasource);
|
||||||
|
|
||||||
|
// 1、准备dataset参数
|
||||||
|
// 2、插入dataset、断言自增id
|
||||||
|
// 3、用id查dataset、断言对象
|
||||||
|
ReportDatasetSaveReqVO datasetSaveReqVO = prepareDatasetReqVO(null, datasourceId);
|
||||||
|
Long datasetId = reportDatasetService.createDataset(datasetSaveReqVO);
|
||||||
|
assertNotNull(datasetId);
|
||||||
|
ReportDatasetDO dataset = reportDatasetService.getDataset(datasetId);
|
||||||
|
assertNotNull(dataset);
|
||||||
|
|
||||||
|
//准备更新参数
|
||||||
|
ReportDatasetSaveReqVO updateReqVO = prepareDatasetReqVO(datasetId, datasourceId);
|
||||||
|
// 更新
|
||||||
|
reportDatasetService.updateDataset(updateReqVO);
|
||||||
|
// 校验是否更新正确
|
||||||
|
ReportDatasetDO updateDataset = reportDatasetService.getDataset(updateReqVO.getId()); // 获取最新的
|
||||||
|
isPojoEquals(updateDataset, updateReqVO);
|
||||||
|
|
||||||
|
|
||||||
|
// 列表查询参数准备
|
||||||
|
ReportDatasetReqVO reqVO = new ReportDatasetReqVO();
|
||||||
|
reqVO.setName(updateReqVO.getName());
|
||||||
|
reqVO.setDatasourceId(updateReqVO.getDatasourceId());
|
||||||
|
List<ReportDatasetDO> datasetList = reportDatasetService.getDatasetList(reqVO);
|
||||||
|
|
||||||
|
assertNotNull(datasetList);
|
||||||
|
assertNotEquals(datasetList.size(), 0);
|
||||||
|
|
||||||
|
// 删除
|
||||||
|
reportTemplateService.deleteReportTemplate(templateId);
|
||||||
|
reportDatasourceService.deleteDatasource(datasourceId);
|
||||||
|
reportDatasetService.deleteDataset(datasetId);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUpdateDataset_notExists() {
|
||||||
|
setOrganId();
|
||||||
|
// 准备参数
|
||||||
|
ReportDatasetSaveReqVO updateReqVO = prepareDatasetReqVO(RandomUtils.randomLongId(), RandomUtils.randomLongId());
|
||||||
|
// 调用, 并断言异常
|
||||||
|
assertServiceException(() -> reportDatasetService.updateDataset(updateReqVO), DATASET_NOT_EXISTS);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDeleteDataset_notExists() {
|
||||||
|
setOrganId();
|
||||||
|
// 准备参数
|
||||||
|
Long id = RandomUtils.randomLongId();
|
||||||
|
|
||||||
|
// 调用, 并断言异常
|
||||||
|
assertServiceException(() -> reportDatasetService.deleteDataset(id), DATASET_NOT_EXISTS);
|
||||||
|
}
|
||||||
|
}
|
||||||
+100
@@ -0,0 +1,100 @@
|
|||||||
|
package com.cf.imes.module.report.service.template;
|
||||||
|
|
||||||
|
import com.cf.imes.framework.test.core.util.RandomUtils;
|
||||||
|
import com.cf.imes.module.report.controller.admin.template.vo.ReportDatasourceReqVO;
|
||||||
|
import com.cf.imes.module.report.controller.admin.template.vo.ReportDatasourceSaveReqVO;
|
||||||
|
import com.cf.imes.module.report.controller.admin.template.vo.ReportTemplateSaveReqVO;
|
||||||
|
import com.cf.imes.module.report.dal.dataobject.template.ReportDatasourceDO;
|
||||||
|
import com.cf.imes.module.report.dal.dataobject.template.ReportTemplateDO;
|
||||||
|
import com.cf.imes.module.report.enums.template.ReportTemplateTypeEnum;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static com.cf.imes.framework.test.core.util.AssertUtils.assertServiceException;
|
||||||
|
import static com.cf.imes.framework.test.core.util.AssertUtils.isPojoEquals;
|
||||||
|
import static com.cf.imes.module.report.enums.ErrorCodeConstants.DATASOURCE_NOT_EXISTS;
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Gqr
|
||||||
|
* @since 2024/7/5 17:01
|
||||||
|
*/
|
||||||
|
@SpringBootTest
|
||||||
|
public class ReportDatasourceServiceImplTest extends ReportCommonServiceImplTest {
|
||||||
|
@Resource
|
||||||
|
ReportDatasourceService reportDatasourceService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
ReportTemplateService reportTemplateService;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCreateTemplate_success() {
|
||||||
|
// 1、上下文添加组织id
|
||||||
|
setOrganId();
|
||||||
|
|
||||||
|
// 1、准备template参数
|
||||||
|
// 2、插入template、断言自增id
|
||||||
|
// 3、用id查template、断言对象
|
||||||
|
ReportTemplateSaveReqVO createReqVO = prepareTemplateReqVO(null);
|
||||||
|
Long templateId = reportTemplateService.createReportTemplate(createReqVO);
|
||||||
|
assertNotNull(templateId);
|
||||||
|
ReportTemplateDO template = reportTemplateService.getReportTemplate(templateId);
|
||||||
|
assertNotNull(template);
|
||||||
|
|
||||||
|
// 1、准备datasource参数
|
||||||
|
// 2、插入datasource、断言自增id
|
||||||
|
// 3、用id查datasource、断言对象
|
||||||
|
ReportDatasourceSaveReqVO datasourceSaveReqVO = prepareDatasourceReqVO(null, templateId);
|
||||||
|
Long datasourceId = reportDatasourceService.createDatasource(datasourceSaveReqVO);
|
||||||
|
assertNotNull(datasourceId);
|
||||||
|
ReportDatasourceDO datasource = reportDatasourceService.getDatasource(datasourceId);
|
||||||
|
assertNotNull(datasource);
|
||||||
|
|
||||||
|
|
||||||
|
//准备更新参数
|
||||||
|
ReportDatasourceSaveReqVO updateReqVO = prepareDatasourceReqVO(datasourceId, templateId);
|
||||||
|
// 更新
|
||||||
|
reportDatasourceService.updateDatasource(updateReqVO);
|
||||||
|
// 校验是否更新正确
|
||||||
|
ReportDatasourceDO updateDatasouce = reportDatasourceService.getDatasource(updateReqVO.getId()); // 获取最新的
|
||||||
|
isPojoEquals(updateDatasouce, updateReqVO);
|
||||||
|
|
||||||
|
|
||||||
|
// 列表查询参数准备
|
||||||
|
ReportDatasourceReqVO reqVO = new ReportDatasourceReqVO();
|
||||||
|
reqVO.setReportId(templateId);
|
||||||
|
reqVO.setType(ReportTemplateTypeEnum.SYSTEM.getType());
|
||||||
|
reqVO.setName(updateReqVO.getName());
|
||||||
|
List<ReportDatasourceDO> templateDatasourceList = reportDatasourceService.getTemplateDatasourceList(reqVO);
|
||||||
|
|
||||||
|
assertNotNull(templateDatasourceList);
|
||||||
|
assertNotEquals(templateDatasourceList.size(),0);
|
||||||
|
|
||||||
|
// 删除
|
||||||
|
reportTemplateService.deleteReportTemplate(templateId);
|
||||||
|
reportDatasourceService.deleteDatasource(datasourceId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUpdateTemplate_notExists() {
|
||||||
|
setOrganId();
|
||||||
|
// 准备参数
|
||||||
|
ReportDatasourceSaveReqVO updateReqVO = prepareDatasourceReqVO(RandomUtils.randomLongId(), RandomUtils.randomLongId());
|
||||||
|
// 调用, 并断言异常
|
||||||
|
assertServiceException(() -> reportDatasourceService.updateDatasource(updateReqVO), DATASOURCE_NOT_EXISTS);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDeleteTemplate_notExists() {
|
||||||
|
setOrganId();
|
||||||
|
// 准备参数
|
||||||
|
Long id = RandomUtils.randomLongId();
|
||||||
|
|
||||||
|
// 调用, 并断言异常
|
||||||
|
assertServiceException(() -> reportDatasourceService.deleteDatasource(id), DATASOURCE_NOT_EXISTS);
|
||||||
|
}
|
||||||
|
}
|
||||||
+128
@@ -0,0 +1,128 @@
|
|||||||
|
package com.cf.imes.module.report.service.template;
|
||||||
|
|
||||||
|
import com.cf.imes.framework.test.core.util.RandomUtils;
|
||||||
|
import com.cf.imes.module.report.controller.admin.template.vo.ReportTemplateReqVO;
|
||||||
|
import com.cf.imes.module.report.controller.admin.template.vo.ReportTemplateSaveReqVO;
|
||||||
|
import com.cf.imes.module.report.dal.dataobject.template.ReportTemplateDO;
|
||||||
|
import com.cf.imes.module.report.enums.template.ReportTemplateTypeEnum;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static com.cf.imes.framework.test.core.util.AssertUtils.*;
|
||||||
|
import static com.cf.imes.module.report.enums.ErrorCodeConstants.TEMPLATE_NOT_EXISTS;
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@link ReportTemplateServiceImpl} 的单元测试类
|
||||||
|
*
|
||||||
|
* @author Gqr
|
||||||
|
* @since 2024/7/3 14:35
|
||||||
|
*/
|
||||||
|
@SpringBootTest
|
||||||
|
public class ReportTemplateServiceImplTest extends ReportCommonServiceImplTest {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private ReportTemplateServiceImpl reportTemplateService;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCreateTemplate_success() {
|
||||||
|
setOrganId();
|
||||||
|
// 准备参数
|
||||||
|
ReportTemplateSaveReqVO createReqVO = prepareTemplateReqVO(null);
|
||||||
|
System.out.println("template压缩后大小:" + createReqVO.getTemplate().length());
|
||||||
|
// 插入
|
||||||
|
Long templateId = reportTemplateService.createReportTemplate(createReqVO);
|
||||||
|
// 断言
|
||||||
|
assertNotNull(templateId);
|
||||||
|
// 校验是否插入
|
||||||
|
ReportTemplateDO template = reportTemplateService.getReportTemplate(templateId);
|
||||||
|
assertNotNull(template);
|
||||||
|
String templateUnZip = template.getTemplate();
|
||||||
|
System.out.println("从库中读取template大小:" + templateUnZip.length());
|
||||||
|
// 校验解压内容是否正确
|
||||||
|
assertEquals(JsonUtil.unzipString(templateUnZip),TEMPLATE);
|
||||||
|
// 删除
|
||||||
|
reportTemplateService.deleteReportTemplate(templateId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUpdateTemplate_success() {
|
||||||
|
setOrganId();
|
||||||
|
// 准备参数
|
||||||
|
ReportTemplateSaveReqVO createReqVO = prepareTemplateReqVO(null);
|
||||||
|
System.out.println("template压缩后大小:" + createReqVO.getTemplate().length());
|
||||||
|
// 插入
|
||||||
|
Long templateId = reportTemplateService.createReportTemplate(createReqVO);
|
||||||
|
|
||||||
|
//准备更新参数
|
||||||
|
ReportTemplateSaveReqVO updateReqVO = prepareTemplateReqVO(templateId);
|
||||||
|
|
||||||
|
// 更新
|
||||||
|
reportTemplateService.updateReportTemplate(updateReqVO);
|
||||||
|
// 校验是否更新正确
|
||||||
|
ReportTemplateDO template = reportTemplateService.getReportTemplate(updateReqVO.getId()); // 获取最新的
|
||||||
|
isPojoEquals(template,updateReqVO);
|
||||||
|
// 删除
|
||||||
|
reportTemplateService.deleteReportTemplate(templateId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUpdateTemplate_notExists() {
|
||||||
|
setOrganId();
|
||||||
|
// 准备参数
|
||||||
|
ReportTemplateSaveReqVO updateReqVO = prepareTemplateReqVO(RandomUtils.randomLongId());
|
||||||
|
// 调用, 并断言异常
|
||||||
|
assertServiceException(() -> reportTemplateService.updateReportTemplate(updateReqVO), TEMPLATE_NOT_EXISTS);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void deleteTemplate_success() {
|
||||||
|
setOrganId();
|
||||||
|
// 准备参数
|
||||||
|
ReportTemplateSaveReqVO createReqVO = prepareTemplateReqVO(null);
|
||||||
|
// 插入
|
||||||
|
Long templateId = reportTemplateService.createReportTemplate(createReqVO);
|
||||||
|
|
||||||
|
// 删除
|
||||||
|
reportTemplateService.deleteReportTemplate(templateId);
|
||||||
|
// 校验数据不存在了
|
||||||
|
assertNull(reportTemplateService.getReportTemplate(templateId));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDeleteTemplate_notExists() {
|
||||||
|
setOrganId();
|
||||||
|
// 准备参数
|
||||||
|
Long id = RandomUtils.randomLongId();
|
||||||
|
|
||||||
|
// 调用, 并断言异常
|
||||||
|
assertServiceException(() -> reportTemplateService.deleteReportTemplate(id), TEMPLATE_NOT_EXISTS);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getTemplateList_success() {
|
||||||
|
setOrganId(2L);
|
||||||
|
|
||||||
|
// 准备参数
|
||||||
|
ReportTemplateSaveReqVO createReqVO = prepareTemplateReqVO(null);
|
||||||
|
// 插入
|
||||||
|
Long templateId = reportTemplateService.createReportTemplate(createReqVO);
|
||||||
|
|
||||||
|
|
||||||
|
ReportTemplateReqVO reqVO = new ReportTemplateReqVO();
|
||||||
|
reqVO.setType(ReportTemplateTypeEnum.SYSTEM.getType());
|
||||||
|
reqVO.setName(createReqVO.getName());
|
||||||
|
List<ReportTemplateDO> reportTemplateList = reportTemplateService.getReportTemplateList(reqVO);
|
||||||
|
|
||||||
|
assertNotNull(reportTemplateList);
|
||||||
|
assertNotEquals(reportTemplateList.size(),0);
|
||||||
|
assertEquals(reportTemplateList.get(0).getOrganId(),2L);
|
||||||
|
|
||||||
|
// 删除
|
||||||
|
reportTemplateService.deleteReportTemplate(templateId);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user