From e1d6c7277c225f482bcab88913a4ad1466094fe5 Mon Sep 17 00:00:00 2001 From: gaoqr <13665037151@163.com> Date: Thu, 5 Dec 2024 19:43:24 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E6=A8=A1=E6=9D=BF=E5=AF=BC=E5=85=A5?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E8=BF=94=E5=9B=9E=E7=BB=93=E6=9E=9C=E5=B8=83?= =?UTF-8?q?=E5=B0=94=E5=80=BC=EF=BC=8C=E6=A3=80=E6=9F=A5=E4=BC=98=E5=8C=96?= =?UTF-8?q?=EF=BC=9B2=E3=80=81=E6=A8=A1=E7=89=88=E5=90=8D=E9=87=8D?= =?UTF-8?q?=E5=A4=8D=E5=88=A4=E5=AE=9A=E4=BC=98=E5=8C=96=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../report/enums/ErrorCodeConstants.java | 2 +- .../template/ReportTemplateController.java | 3 ++- .../mysql/template/ReportTemplateMapper.java | 12 ++++++++++ .../template/ReportTemplateServiceImpl.java | 22 +++++++------------ .../mapper/template/ReportTemplateMapper.xml | 16 ++++++++++++++ 5 files changed, 39 insertions(+), 16 deletions(-) create mode 100644 cf-module-report/cf-module-report-biz/src/main/resources/mapper/template/ReportTemplateMapper.xml 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