1、模板导入接口返回结果布尔值,检查优化;2、模版名重复判定优化;

This commit is contained in:
gaoqr
2024-12-05 19:44:19 +08:00
parent 2c10f27e4d
commit e1d6c7277c
5 changed files with 39 additions and 16 deletions
@@ -15,7 +15,7 @@ public final class ErrorCodeConstants {
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, "查询参数不能为空:{}"); public static final ErrorCode TEMPLATE_PREIVEW_QUERYPARAM_EMPTY = new ErrorCode(1_003_001_004, "查询参数不能为空:{}");
public static final ErrorCode TEMPLATE_IMPORT_CONTENT_EMPTY_ERROR = new ErrorCode(1_003_001_005, "导入模板内容不能为空,请检查");
// ========== UREPORT datasource模块 1-003-002-000 ========== // ========== UREPORT datasource模块 1-003-002-000 ==========
public static final ErrorCode DATASOURCE_NOT_EXISTS = new ErrorCode(1_003_002_001, "报表数据源不存在"); public static final ErrorCode DATASOURCE_NOT_EXISTS = new ErrorCode(1_003_002_001, "报表数据源不存在");
@@ -197,7 +197,8 @@ public class ReportTemplateController {
@PutMapping("/xml") @PutMapping("/xml")
@Operation(summary = "导入模版") @Operation(summary = "导入模版")
@PreAuthorize("@ss.hasPermission('report:design')") @PreAuthorize("@ss.hasPermission('report:design')")
public void importTemplate(@RequestParam("name") @NotEmpty(message = "模版名称不能为空") String name, @RequestParam("file") MultipartFile file) { public CommonResult<Boolean> importTemplate(@RequestParam("name") @NotEmpty(message = "模版名称不能为空") String name, @RequestParam("file") MultipartFile file) {
templateService.importTemplate(name, file); templateService.importTemplate(name, file);
return success(true);
} }
} }
@@ -4,9 +4,11 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.cf.imes.framework.mybatis.core.mapper.BaseMapperX; import com.cf.imes.framework.mybatis.core.mapper.BaseMapperX;
import com.cf.imes.framework.mybatis.core.query.LambdaQueryWrapperX; import com.cf.imes.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.cf.imes.framework.organ.core.aop.OrganIgnore; import com.cf.imes.framework.organ.core.aop.OrganIgnore;
import com.cf.imes.module.report.controller.admin.template.vo.ReportTemplateSaveReqVO;
import com.cf.imes.module.report.dal.dataobject.template.ReportTemplateDO; import com.cf.imes.module.report.dal.dataobject.template.ReportTemplateDO;
import com.cf.imes.module.report.enums.template.ReportTemplateTypeEnum; import com.cf.imes.module.report.enums.template.ReportTemplateTypeEnum;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List; import java.util.List;
@@ -40,6 +42,7 @@ public interface ReportTemplateMapper extends BaseMapperX<ReportTemplateDO> {
/** /**
* 查询模板列表 * 查询模板列表
* 普通用户用:organId+type1 or type0 * 普通用户用:organId+type1 or type0
*
* @param name * @param name
* @param organId * @param organId
* @return * @return
@@ -58,4 +61,13 @@ public interface ReportTemplateMapper extends BaseMapperX<ReportTemplateDO> {
return selectList(queryWrapper); return selectList(queryWrapper);
} }
/**
* 查询模版名是否重复
*
* @param reqVO
* @param isSuperAdmin
* @param type
* @return
*/
int selectExistTemplateName(@Param("reqVO") ReportTemplateSaveReqVO reqVO, @Param("isSuperAdmin") boolean isSuperAdmin, @Param("type") Integer type);
} }
@@ -10,7 +10,6 @@ import cn.hutool.http.ContentType;
import cn.hutool.http.Header; import cn.hutool.http.Header;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.bstek.common.exception.ReportDesignException; import com.bstek.common.exception.ReportDesignException;
import com.bstek.designer.bean.PreviewParameters; import com.bstek.designer.bean.PreviewParameters;
import com.bstek.designer.bean.ReportDefinitionWrapper; import com.bstek.designer.bean.ReportDefinitionWrapper;
@@ -37,7 +36,6 @@ 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.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.security.core.LoginUser; import com.cf.imes.framework.security.core.LoginUser;
import com.cf.imes.framework.security.core.util.SecurityFrameworkUtils; import com.cf.imes.framework.security.core.util.SecurityFrameworkUtils;
import com.cf.imes.module.report.controller.admin.template.vo.ReportTemplatePreviewReqVO; import com.cf.imes.module.report.controller.admin.template.vo.ReportTemplatePreviewReqVO;
@@ -77,6 +75,7 @@ import java.util.stream.Collectors;
import static com.cf.imes.framework.common.exception.util.ServiceExceptionUtil.exception; import static com.cf.imes.framework.common.exception.util.ServiceExceptionUtil.exception;
import static com.cf.imes.module.report.enums.ErrorCodeConstants.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_IMPORT_CONTENT_EMPTY_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; import static com.cf.imes.module.report.enums.ErrorCodeConstants.TEMPLATE_PREIVEW_QUERYPARAM_EMPTY;
@@ -249,17 +248,8 @@ public class ReportTemplateServiceImpl implements ReportTemplateService {
* @param reqVO * @param reqVO
*/ */
private void validateTemplateNameUnique(ReportTemplateSaveReqVO reqVO, boolean isSuperAdmin) { private void validateTemplateNameUnique(ReportTemplateSaveReqVO reqVO, boolean isSuperAdmin) {
Long templateId = reqVO.getId(); if (templateMapper.selectExistTemplateName(reqVO, isSuperAdmin, ReportTemplateTypeEnum.SYSTEM.getType()) > 0) {
String name = reqVO.getName(); throw exception(TEMPLATE_NAME_UNIQE_ERROR, reqVO.getName());
LambdaQueryWrapper<ReportTemplateDO> wrapper = new LambdaQueryWrapperX<ReportTemplateDO>().eq(ReportTemplateDO::getName, name);
if (ObjectUtil.isNotNull(templateId)) {
wrapper.ne(ReportTemplateDO::getId, templateId);
}
if (isSuperAdmin) {
wrapper.eq(ReportTemplateDO::getType, ReportTemplateTypeEnum.SYSTEM);
}
if (templateMapper.exists(wrapper)) {
throw exception(TEMPLATE_NAME_UNIQE_ERROR, name);
} }
} }
@@ -508,7 +498,11 @@ public class ReportTemplateServiceImpl implements ReportTemplateService {
// 校验模板名唯一性 // 校验模板名唯一性
validateTemplateNameUnique(createReqVO, isSuperAdmin); validateTemplateNameUnique(createReqVO, isSuperAdmin);
// 复制信息 // 复制信息
createReqVO.setContent(jsonObject.getString("content")); String content = jsonObject.getString("content");
if(StringUtils.isEmpty(content)) {
throw new ServiceException(TEMPLATE_IMPORT_CONTENT_EMPTY_ERROR);
}
createReqVO.setContent(content);
createReqVO.setDatasetIds(jsonObject.getJSONArray(DATASETIDS_FIELD_NAME).stream().map(s -> Long.parseLong(s.toString())).collect(Collectors.toSet())); createReqVO.setDatasetIds(jsonObject.getJSONArray(DATASETIDS_FIELD_NAME).stream().map(s -> Long.parseLong(s.toString())).collect(Collectors.toSet()));
createReqVO.setDatasourceIds(jsonObject.getJSONArray(DATASOURCEIDS_FIELD_NAME).stream().map(s -> Long.parseLong(s.toString())).collect(Collectors.toSet())); createReqVO.setDatasourceIds(jsonObject.getJSONArray(DATASOURCEIDS_FIELD_NAME).stream().map(s -> Long.parseLong(s.toString())).collect(Collectors.toSet()));
// 新增模板 // 新增模板
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.cf.imes.module.report.dal.mysql.template.ReportTemplateMapper">
<select id="selectExistTemplateName" resultType="java.lang.Integer">
SELECT COUNT(1)
FROM report_template
WHERE name = #{reqVO.name}
<if test="reqVO.id != null">
id != #{reqVO.id}
</if>
<if test="isSuperAdmin">
AND type = #{type}
</if>
</select>
</mapper>