diff --git a/cf-module-report/cf-module-report-api/src/main/java/com/cf/imes/module/report/enums/ErrorCodeConstants.java b/cf-module-report/cf-module-report-api/src/main/java/com/cf/imes/module/report/enums/ErrorCodeConstants.java index a2425150b..f63be99b0 100644 --- a/cf-module-report/cf-module-report-api/src/main/java/com/cf/imes/module/report/enums/ErrorCodeConstants.java +++ b/cf-module-report/cf-module-report-api/src/main/java/com/cf/imes/module/report/enums/ErrorCodeConstants.java @@ -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_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_IMPORT_CONTENT_EMPTY_ERROR = new ErrorCode(1_003_001_005, "导入模板内容不能为空,请检查"); // ========== UREPORT datasource模块 1-003-002-000 ========== public static final ErrorCode DATASOURCE_NOT_EXISTS = new ErrorCode(1_003_002_001, "报表数据源不存在"); diff --git a/cf-module-report/cf-module-report-biz/src/main/java/com/cf/imes/module/report/controller/admin/template/ReportTemplateController.java b/cf-module-report/cf-module-report-biz/src/main/java/com/cf/imes/module/report/controller/admin/template/ReportTemplateController.java index e7f6be641..06cf3df39 100644 --- a/cf-module-report/cf-module-report-biz/src/main/java/com/cf/imes/module/report/controller/admin/template/ReportTemplateController.java +++ b/cf-module-report/cf-module-report-biz/src/main/java/com/cf/imes/module/report/controller/admin/template/ReportTemplateController.java @@ -197,7 +197,8 @@ public class ReportTemplateController { @PutMapping("/xml") @Operation(summary = "导入模版") @PreAuthorize("@ss.hasPermission('report:design')") - public void importTemplate(@RequestParam("name") @NotEmpty(message = "模版名称不能为空") String name, @RequestParam("file") MultipartFile file) { + public CommonResult importTemplate(@RequestParam("name") @NotEmpty(message = "模版名称不能为空") String name, @RequestParam("file") MultipartFile file) { templateService.importTemplate(name, file); + return success(true); } } diff --git a/cf-module-report/cf-module-report-biz/src/main/java/com/cf/imes/module/report/dal/mysql/template/ReportTemplateMapper.java b/cf-module-report/cf-module-report-biz/src/main/java/com/cf/imes/module/report/dal/mysql/template/ReportTemplateMapper.java index b5403f7c7..2e2f9ff0d 100644 --- a/cf-module-report/cf-module-report-biz/src/main/java/com/cf/imes/module/report/dal/mysql/template/ReportTemplateMapper.java +++ b/cf-module-report/cf-module-report-biz/src/main/java/com/cf/imes/module/report/dal/mysql/template/ReportTemplateMapper.java @@ -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.query.LambdaQueryWrapperX; 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.enums.template.ReportTemplateTypeEnum; import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; import java.util.List; @@ -40,6 +42,7 @@ public interface ReportTemplateMapper extends BaseMapperX { /** * 查询模板列表 * 普通用户用:organId+type:1 or type:0 + * * @param name * @param organId * @return @@ -58,4 +61,13 @@ public interface ReportTemplateMapper extends BaseMapperX { return selectList(queryWrapper); } + /** + * 查询模版名是否重复 + * + * @param reqVO + * @param isSuperAdmin + * @param type + * @return + */ + int selectExistTemplateName(@Param("reqVO") ReportTemplateSaveReqVO reqVO, @Param("isSuperAdmin") boolean isSuperAdmin, @Param("type") Integer type); } diff --git a/cf-module-report/cf-module-report-biz/src/main/java/com/cf/imes/module/report/service/template/ReportTemplateServiceImpl.java b/cf-module-report/cf-module-report-biz/src/main/java/com/cf/imes/module/report/service/template/ReportTemplateServiceImpl.java index 908010163..47967b43c 100644 --- a/cf-module-report/cf-module-report-biz/src/main/java/com/cf/imes/module/report/service/template/ReportTemplateServiceImpl.java +++ b/cf-module-report/cf-module-report-biz/src/main/java/com/cf/imes/module/report/service/template/ReportTemplateServiceImpl.java @@ -10,7 +10,6 @@ import cn.hutool.http.ContentType; import cn.hutool.http.Header; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; -import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.bstek.common.exception.ReportDesignException; import com.bstek.designer.bean.PreviewParameters; 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.util.ServiceExceptionUtil; 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.util.SecurityFrameworkUtils; 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.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_NOT_EXISTS; import static com.cf.imes.module.report.enums.ErrorCodeConstants.TEMPLATE_PREIVEW_QUERYPARAM_EMPTY; @@ -249,17 +248,8 @@ public class ReportTemplateServiceImpl implements ReportTemplateService { * @param reqVO */ private void validateTemplateNameUnique(ReportTemplateSaveReqVO reqVO, boolean isSuperAdmin) { - Long templateId = reqVO.getId(); - String name = reqVO.getName(); - LambdaQueryWrapper wrapper = new LambdaQueryWrapperX().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); + if (templateMapper.selectExistTemplateName(reqVO, isSuperAdmin, ReportTemplateTypeEnum.SYSTEM.getType()) > 0) { + throw exception(TEMPLATE_NAME_UNIQE_ERROR, reqVO.getName()); } } @@ -508,7 +498,11 @@ public class ReportTemplateServiceImpl implements ReportTemplateService { // 校验模板名唯一性 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.setDatasourceIds(jsonObject.getJSONArray(DATASOURCEIDS_FIELD_NAME).stream().map(s -> Long.parseLong(s.toString())).collect(Collectors.toSet())); // 新增模板 diff --git a/cf-module-report/cf-module-report-biz/src/main/resources/mapper/template/ReportTemplateMapper.xml b/cf-module-report/cf-module-report-biz/src/main/resources/mapper/template/ReportTemplateMapper.xml new file mode 100644 index 000000000..a6bcd6fd5 --- /dev/null +++ b/cf-module-report/cf-module-report-biz/src/main/resources/mapper/template/ReportTemplateMapper.xml @@ -0,0 +1,16 @@ + + + + + + \ No newline at end of file