mirror of
http://192.168.1.205:9980/cf_devdept2/cf_imes_server.git
synced 2026-08-12 21:02:08 +08:00
1、模板和数据源查询过滤修复,超管可看的内容和普通用户相同,但是可以通过组织树看其他组织;2、打印和文件下载同步租户优化;3、ureport-core包同步(修复页眉页脚保存、开源项目bug修复同步);
This commit is contained in:
+1
@@ -14,6 +14,7 @@ public final class ErrorCodeConstants {
|
|||||||
public static final ErrorCode TEMPLATE_NOT_EXISTS = new ErrorCode(1_003_001_001, "报表模板信息不存在");
|
public static final ErrorCode TEMPLATE_NOT_EXISTS = new ErrorCode(1_003_001_001, "报表模板信息不存在");
|
||||||
public static final ErrorCode TEMPLATE_BUILDIN_OPERATION_PERMISSION_ERROR = new ErrorCode(1_003_001_002, "内置模板操作权限不足");
|
public static final ErrorCode TEMPLATE_BUILDIN_OPERATION_PERMISSION_ERROR = new ErrorCode(1_003_001_002, "内置模板操作权限不足");
|
||||||
public static final ErrorCode TEMPLATE_NAME_UNIQE_ERROR = new ErrorCode(1_003_001_003, "模板名【{}】已存在,请编辑模板名后重试");
|
public static final ErrorCode TEMPLATE_NAME_UNIQE_ERROR = new ErrorCode(1_003_001_003, "模板名【{}】已存在,请编辑模板名后重试");
|
||||||
|
public static final ErrorCode TEMPLATE_PREIVEW_QUERYPARAM_EMPTY = new ErrorCode(1_003_001_004, "查询参数不能为空:{}");
|
||||||
|
|
||||||
|
|
||||||
// ========== UREPORT datasource模块 1-003-002-000 ==========
|
// ========== UREPORT datasource模块 1-003-002-000 ==========
|
||||||
|
|||||||
+2
-2
@@ -87,8 +87,8 @@ public class ReportDatasourceController {
|
|||||||
@GetMapping("/datasources")
|
@GetMapping("/datasources")
|
||||||
@Operation(summary = "获取报表数据源列表")
|
@Operation(summary = "获取报表数据源列表")
|
||||||
@PreAuthorize("@ss.hasPermission('report:design')")
|
@PreAuthorize("@ss.hasPermission('report:design')")
|
||||||
public CommonResult<List<ReportDatasourceRespVO>> getDatasourcePage() {
|
public CommonResult<List<ReportDatasourceRespVO>> getDatasourcePage(@RequestParam(value = "organId", required = false) Long organId) {
|
||||||
return success(BeanUtils.toBean(datasourceService.getDatasourceList(), ReportDatasourceRespVO.class));
|
return success(BeanUtils.toBean(datasourceService.getDatasourceList(organId), ReportDatasourceRespVO.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/datasource/beans")
|
@GetMapping("/datasource/beans")
|
||||||
|
|||||||
+4
-2
@@ -101,8 +101,10 @@ public class ReportTemplateController {
|
|||||||
@GetMapping("/templates")
|
@GetMapping("/templates")
|
||||||
@Operation(summary = "获取报表模板信息列表")
|
@Operation(summary = "获取报表模板信息列表")
|
||||||
@PreAuthorize("@ss.hasPermission('report:design')")
|
@PreAuthorize("@ss.hasPermission('report:design')")
|
||||||
public CommonResult<List<ReportTemplateRespVO>> getTemplatePage(@RequestParam(value = "name", required = false) @Size(max = 64, message = "模板名称长度不能超过64个字符") String name) {
|
public CommonResult<List<ReportTemplateRespVO>> getTemplatePage(
|
||||||
ReportTemplateReqVO reqVO = new ReportTemplateReqVO(name, null);
|
@RequestParam(value = "name", required = false) @Size(max = 64, message = "模板名称长度不能超过64个字符") String name,
|
||||||
|
@RequestParam(value = "organId", required = false) Long organId) {
|
||||||
|
ReportTemplateReqVO reqVO = new ReportTemplateReqVO(name, null, organId);
|
||||||
return success(BeanUtils.toBean(templateService.getReportTemplateList(reqVO), ReportTemplateRespVO.class));
|
return success(BeanUtils.toBean(templateService.getReportTemplateList(reqVO), ReportTemplateRespVO.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+3
@@ -21,4 +21,7 @@ public class ReportTemplateReqVO {
|
|||||||
|
|
||||||
@Schema(description = "模板类型,0内置、1自定义", example = "1")
|
@Schema(description = "模板类型,0内置、1自定义", example = "1")
|
||||||
private Integer type;
|
private Integer type;
|
||||||
|
|
||||||
|
@Schema(description = "组织id")
|
||||||
|
private Long organId;
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -49,10 +49,10 @@ public interface ReportDatasourceService {
|
|||||||
/**
|
/**
|
||||||
* 获取模板下的数据源列表
|
* 获取模板下的数据源列表
|
||||||
*
|
*
|
||||||
* @param reqVO 查询参数
|
* @param organId 组织id
|
||||||
* @return 报表数据源分页
|
* @return 报表数据源分页
|
||||||
*/
|
*/
|
||||||
List<ReportDatasourceDO> getDatasourceList();
|
List<ReportDatasourceDO> getDatasourceList(Long organId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取springbean数据源列表
|
* 获取springbean数据源列表
|
||||||
|
|||||||
+10
-6
@@ -133,16 +133,21 @@ public class ReportDatasourceServiceImpl implements ReportDatasourceService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
@OrganIgnore
|
@OrganIgnore
|
||||||
public List<ReportDatasourceDO> getDatasourceList() {
|
public List<ReportDatasourceDO> getDatasourceList(Long organId) {
|
||||||
LoginUser loginUser = SecurityFrameworkUtils.getLoginUser();
|
LoginUser loginUser = SecurityFrameworkUtils.getLoginUser();
|
||||||
LambdaQueryWrapper<ReportDatasourceDO> queryWrapper = new LambdaQueryWrapperX<ReportDatasourceDO>().orderByDesc(ReportDatasourceDO::getCreateTime);
|
LambdaQueryWrapper<ReportDatasourceDO> queryWrapper = new LambdaQueryWrapperX<ReportDatasourceDO>().orderByDesc(ReportDatasourceDO::getCreateTime);
|
||||||
if (ObjectUtil.isNotNull(loginUser) && Boolean.FALSE.equals(loginUser.getIsSupAdmin())) {
|
// 当前登录人机构id
|
||||||
// 普通用户查看机构下的和system数据源
|
Long currentOrganId = loginUser.getOrganId();
|
||||||
|
// 超管查看不同组织数据源
|
||||||
|
if (ObjectUtil.isNotNull(loginUser) && Boolean.TRUE.equals(loginUser.getIsSupAdmin()) && ObjectUtil.isNotNull(organId)) {
|
||||||
|
currentOrganId = organId;
|
||||||
|
}
|
||||||
|
Long finalCurrentOrganId = currentOrganId;
|
||||||
queryWrapper.or(wrapper -> wrapper
|
queryWrapper.or(wrapper -> wrapper
|
||||||
.eq(ReportDatasourceDO::getOrganId, loginUser.getOrganId())
|
.eq(ReportDatasourceDO::getOrganId, finalCurrentOrganId)
|
||||||
.eq(ReportDatasourceDO::getBuildinType, ReportTemplateTypeEnum.CUSTOM))
|
.eq(ReportDatasourceDO::getBuildinType, ReportTemplateTypeEnum.CUSTOM))
|
||||||
.or(wrapper -> wrapper.eq(ReportDatasourceDO::getBuildinType, ReportTemplateTypeEnum.SYSTEM));
|
.or(wrapper -> wrapper.eq(ReportDatasourceDO::getBuildinType, ReportTemplateTypeEnum.SYSTEM));
|
||||||
}
|
|
||||||
List<ReportDatasourceDO> reportDatasourceDOS = datasourceMapper.selectList(queryWrapper);
|
List<ReportDatasourceDO> reportDatasourceDOS = datasourceMapper.selectList(queryWrapper);
|
||||||
// 查询数据集
|
// 查询数据集
|
||||||
if (CollUtil.isNotEmpty(reportDatasourceDOS)) {
|
if (CollUtil.isNotEmpty(reportDatasourceDOS)) {
|
||||||
@@ -150,7 +155,6 @@ public class ReportDatasourceServiceImpl implements ReportDatasourceService {
|
|||||||
queryDatasetInSource(reportDatasourceDO);
|
queryDatasetInSource(reportDatasourceDO);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
// 超管查看全部
|
|
||||||
return reportDatasourceDOS;
|
return reportDatasourceDOS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+50
-15
@@ -30,6 +30,7 @@ import com.bstek.ureport.parser.ReportParser;
|
|||||||
import com.bstek.ureport.utils.ToolUtils;
|
import com.bstek.ureport.utils.ToolUtils;
|
||||||
import com.cf.imes.framework.common.exception.ServiceException;
|
import com.cf.imes.framework.common.exception.ServiceException;
|
||||||
import com.cf.imes.framework.common.exception.enums.GlobalErrorCodeConstants;
|
import com.cf.imes.framework.common.exception.enums.GlobalErrorCodeConstants;
|
||||||
|
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.framework.security.core.LoginUser;
|
import com.cf.imes.framework.security.core.LoginUser;
|
||||||
@@ -49,6 +50,7 @@ import com.cf.imes.module.report.enums.template.ReportTemplateTypeEnum;
|
|||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import org.springframework.util.ObjectUtils;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
@@ -70,6 +72,7 @@ import static com.cf.imes.framework.common.exception.util.ServiceExceptionUtil.e
|
|||||||
import static com.cf.imes.module.report.enums.ErrorCodeConstants.TEMPLATE_BUILDIN_OPERATION_PERMISSION_ERROR;
|
import static com.cf.imes.module.report.enums.ErrorCodeConstants.TEMPLATE_BUILDIN_OPERATION_PERMISSION_ERROR;
|
||||||
import static com.cf.imes.module.report.enums.ErrorCodeConstants.TEMPLATE_NAME_UNIQE_ERROR;
|
import static com.cf.imes.module.report.enums.ErrorCodeConstants.TEMPLATE_NAME_UNIQE_ERROR;
|
||||||
import static com.cf.imes.module.report.enums.ErrorCodeConstants.TEMPLATE_NOT_EXISTS;
|
import static com.cf.imes.module.report.enums.ErrorCodeConstants.TEMPLATE_NOT_EXISTS;
|
||||||
|
import static com.cf.imes.module.report.enums.ErrorCodeConstants.TEMPLATE_PREIVEW_QUERYPARAM_EMPTY;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 报表模板信息 Service 实现类
|
* 报表模板信息 Service 实现类
|
||||||
@@ -340,28 +343,56 @@ public class ReportTemplateServiceImpl implements ReportTemplateService {
|
|||||||
@Override
|
@Override
|
||||||
public List<ReportTemplateDO> getReportTemplateList(ReportTemplateReqVO reqVO) {
|
public List<ReportTemplateDO> getReportTemplateList(ReportTemplateReqVO reqVO) {
|
||||||
LoginUser loginUser = SecurityFrameworkUtils.getLoginUser();
|
LoginUser loginUser = SecurityFrameworkUtils.getLoginUser();
|
||||||
LambdaQueryWrapper<ReportTemplateDO> queryWrapper = new LambdaQueryWrapperX<ReportTemplateDO>().likeIfPresent(ReportTemplateDO::getName, reqVO.getName())
|
// 当前登录人机构id
|
||||||
.orderByDesc(ReportTemplateDO::getCreateTime)
|
Long organId = loginUser.getOrganId();
|
||||||
// 不返回content xml,点击具体的模板中返回xml
|
// 超管查看不同组织模板
|
||||||
.select(ReportTemplateDO::getId, ReportTemplateDO::getName, ReportTemplateDO::getCreateTime, ReportTemplateDO::getRemark, ReportTemplateDO::getType);
|
if (ObjectUtil.isNotNull(loginUser) && Boolean.TRUE.equals(loginUser.getIsSupAdmin()) && ObjectUtil.isNotNull(reqVO.getOrganId())) {
|
||||||
if (ObjectUtil.isNotNull(loginUser) && Boolean.FALSE.equals(loginUser.getIsSupAdmin())) {
|
organId = reqVO.getOrganId();
|
||||||
return templateMapper.selectNormalTemplateList(reqVO.getName(), loginUser.getOrganId());
|
}
|
||||||
} else {
|
return templateMapper.selectNormalTemplateList(reqVO.getName(), organId);
|
||||||
// 超管查看全部
|
}
|
||||||
return templateMapper.selectList(queryWrapper);
|
|
||||||
|
/**
|
||||||
|
* 检查查询参数不为空
|
||||||
|
*
|
||||||
|
* @param queryMap
|
||||||
|
*/
|
||||||
|
private void checkQueryNotEmpty(Map<String, Object> queryMap) {
|
||||||
|
if (ObjectUtil.isNotNull(queryMap)) {
|
||||||
|
for (Map.Entry<String, Object> entry : queryMap.entrySet()) {
|
||||||
|
String key = entry.getKey();
|
||||||
|
if (ObjectUtils.isEmpty(entry.getValue()) && (ObjectUtil.notEqual(key, "datasetIds") || ObjectUtil.notEqual(key, "datasourceIds "))) {
|
||||||
|
throw ServiceExceptionUtil.exception(TEMPLATE_PREIVEW_QUERYPARAM_EMPTY, key);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public HtmlReport preview(ReportTemplatePreviewReqVO reqVO) {
|
public HtmlReport preview(ReportTemplatePreviewReqVO reqVO) {
|
||||||
|
// 检查查询参数中的空值
|
||||||
|
checkQueryNotEmpty(reqVO.getQuery());
|
||||||
// 自定义请求vo转ureport对象
|
// 自定义请求vo转ureport对象
|
||||||
PreviewParameters params = BeanUtils.toBean(reqVO, PreviewParameters.class);
|
PreviewParameters params = BeanUtils.toBean(reqVO, PreviewParameters.class);
|
||||||
Long userOrganId = SecurityFrameworkUtils.getUserOrganId();
|
|
||||||
|
|
||||||
HtmlProducer htmlProducer = new HtmlProducer();
|
HtmlProducer htmlProducer = new HtmlProducer();
|
||||||
ReportRender reportRender = new ReportRender();
|
ReportRender reportRender = new ReportRender();
|
||||||
ReportDefinition reportDefinition = getReportDefinition(reportRender, params);
|
ReportDefinition reportDefinition = getReportDefinition(reportRender, params);
|
||||||
Map<String, Object> parameters = params.getQuery();
|
Map<String, Object> parameters = params.getQuery();
|
||||||
|
// 增加多租户参数
|
||||||
|
prepareTenantParam(parameters);
|
||||||
|
Report report = reportRender.render(reportDefinition, parameters);
|
||||||
|
return htmlProducer.produce(reportDefinition, report);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 往parameters中增加租户相关参数
|
||||||
|
*
|
||||||
|
* @param parameters
|
||||||
|
*/
|
||||||
|
private void prepareTenantParam(Map<String, Object> parameters) {
|
||||||
|
Long userOrganId = SecurityFrameworkUtils.getUserOrganId();
|
||||||
if (Boolean.FALSE.equals(SecurityFrameworkUtils.isSuperAdmin())) {
|
if (Boolean.FALSE.equals(SecurityFrameworkUtils.isSuperAdmin())) {
|
||||||
// 根据前端传递的数据集id,判断是不是内置数据源下的,是就把name传给ureport
|
// 根据前端传递的数据集id,判断是不是内置数据源下的,是就把name传给ureport
|
||||||
List<Long> datasetIds = (List) parameters.get("datasetIds");
|
List<Long> datasetIds = (List) parameters.get("datasetIds");
|
||||||
@@ -375,7 +406,7 @@ public class ReportTemplateServiceImpl implements ReportTemplateService {
|
|||||||
// 查询数据源,如果是内置数据源则把数据集的name传给ureport
|
// 查询数据源,如果是内置数据源则把数据集的name传给ureport
|
||||||
// 机构下 + 内置数据源查询
|
// 机构下 + 内置数据源查询
|
||||||
ReportDatasourceDO datasourceDO = datasourceMapper.selectNormalDatasourceById(datasourceId, userOrganId);
|
ReportDatasourceDO datasourceDO = datasourceMapper.selectNormalDatasourceById(datasourceId, userOrganId);
|
||||||
if (ObjectUtil.equal(datasourceDO.getBuildinType(), ReportTemplateTypeEnum.SYSTEM)) {
|
if (ObjectUtil.isNotNull(datasourceDO) && ObjectUtil.equal(datasourceDO.getBuildinType(), ReportTemplateTypeEnum.SYSTEM)) {
|
||||||
buildinDsNames.add(datasetDO.getName());
|
buildinDsNames.add(datasetDO.getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -388,8 +419,6 @@ public class ReportTemplateServiceImpl implements ReportTemplateService {
|
|||||||
// 用户组织id
|
// 用户组织id
|
||||||
parameters.put("organId", userOrganId);
|
parameters.put("organId", userOrganId);
|
||||||
}
|
}
|
||||||
Report report = reportRender.render(reportDefinition, parameters);
|
|
||||||
return htmlProducer.produce(reportDefinition, report);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -400,7 +429,10 @@ public class ReportTemplateServiceImpl implements ReportTemplateService {
|
|||||||
long start = System.currentTimeMillis();
|
long start = System.currentTimeMillis();
|
||||||
ReportRender reportRender = new ReportRender();
|
ReportRender reportRender = new ReportRender();
|
||||||
ReportDefinition reportDefinition = getReportDefinition(reportRender, params);
|
ReportDefinition reportDefinition = getReportDefinition(reportRender, params);
|
||||||
Report report = reportRender.render(reportDefinition, params.getQuery());
|
Map<String, Object> query = params.getQuery();
|
||||||
|
// 增加多租户参数
|
||||||
|
prepareTenantParam(query);
|
||||||
|
Report report = reportRender.render(reportDefinition, query);
|
||||||
Map<String, String> chartImages = params.getChartImages();
|
Map<String, String> chartImages = params.getChartImages();
|
||||||
report.setChartImages(chartImages);
|
report.setChartImages(chartImages);
|
||||||
try {
|
try {
|
||||||
@@ -427,7 +459,10 @@ public class ReportTemplateServiceImpl implements ReportTemplateService {
|
|||||||
|
|
||||||
ReportRender reportRender = new ReportRender();
|
ReportRender reportRender = new ReportRender();
|
||||||
ReportDefinition reportDefinition = getReportDefinition(reportRender, params);
|
ReportDefinition reportDefinition = getReportDefinition(reportRender, params);
|
||||||
Report report = reportRender.render(reportDefinition, params.getQuery());
|
Map<String, Object> query = params.getQuery();
|
||||||
|
// 增加多租户参数
|
||||||
|
prepareTenantParam(query);
|
||||||
|
Report report = reportRender.render(reportDefinition, query);
|
||||||
Map<String, String> chartImages = params.getChartImages();
|
Map<String, String> chartImages = params.getChartImages();
|
||||||
report.setChartImages(chartImages);
|
report.setChartImages(chartImages);
|
||||||
try {
|
try {
|
||||||
|
|||||||
+1
-1
@@ -72,7 +72,7 @@ public class ReportDatasourceServiceImplTest extends ReportCommonServiceImplTest
|
|||||||
reqVO.setTemplateId(templateId);
|
reqVO.setTemplateId(templateId);
|
||||||
reqVO.setType(ReportDatasourceTypeEnum.JDBC.getCode());
|
reqVO.setType(ReportDatasourceTypeEnum.JDBC.getCode());
|
||||||
reqVO.setName(updateReqVO.getName());
|
reqVO.setName(updateReqVO.getName());
|
||||||
List<ReportDatasourceDO> templateDatasourceList = reportDatasourceService.getDatasourceList();
|
List<ReportDatasourceDO> templateDatasourceList = reportDatasourceService.getDatasourceList(null);
|
||||||
|
|
||||||
assertNotNull(templateDatasourceList);
|
assertNotNull(templateDatasourceList);
|
||||||
assertNotEquals(0, templateDatasourceList.size());
|
assertNotEquals(0, templateDatasourceList.size());
|
||||||
|
|||||||
Reference in New Issue
Block a user