diff --git a/core/core-backend/src/main/java/io/dataease/template/dao/ext/ExtVisualizationTemplateMapper.java b/core/core-backend/src/main/java/io/dataease/template/dao/ext/ExtVisualizationTemplateMapper.java index aab0d1be59..2aaf531330 100644 --- a/core/core-backend/src/main/java/io/dataease/template/dao/ext/ExtVisualizationTemplateMapper.java +++ b/core/core-backend/src/main/java/io/dataease/template/dao/ext/ExtVisualizationTemplateMapper.java @@ -17,4 +17,14 @@ public interface ExtVisualizationTemplateMapper{ List findBaseTemplateList(); + Long checkCategoryMap(@Param("categoryId") String categoryId); + + Long checkRepeatTemplateId(@Param("categoryId") String categoryId, @Param("templateId") String templateId); + + void deleteCategoryMapByTemplate(@Param("templateName") String templateName, @Param("templateId") String templateId); + + Long checkCategoryTemplateName(@Param("templateName") String templateName,@Param("categories") List categories); + + List findTemplateCategories(@Param("templateId") String templateId); + } diff --git a/core/core-backend/src/main/java/io/dataease/template/service/TemplateManageService.java b/core/core-backend/src/main/java/io/dataease/template/service/TemplateManageService.java index 295f0ff262..1bcbedd637 100644 --- a/core/core-backend/src/main/java/io/dataease/template/service/TemplateManageService.java +++ b/core/core-backend/src/main/java/io/dataease/template/service/TemplateManageService.java @@ -17,6 +17,7 @@ import io.dataease.template.dao.ext.ExtVisualizationTemplateMapper; import io.dataease.utils.AuthUtils; import io.dataease.utils.BeanUtils; import io.dataease.visualization.server.StaticResourceServer; +import io.dataease.xpack.base.settings.dao.entity.BaseSetting; import jakarta.annotation.Resource; import org.apache.commons.lang3.StringUtils; import org.springframework.transaction.annotation.Transactional; @@ -56,16 +57,16 @@ public class TemplateManageService implements TemplateManageApi { request.setWithBlobs("N"); List templateList = extTemplateMapper.findTemplateList(request); if (request.getWithChildren()) { - getTreeChildren(templateList,request.getLeafDvType()); + getTreeChildren(templateList, request.getLeafDvType()); } return templateList; } - public void getTreeChildren(List parentTemplateList,String dvType) { + public void getTreeChildren(List parentTemplateList, String dvType) { Optional.ofNullable(parentTemplateList).ifPresent(parent -> parent.forEach(parentTemplate -> { - List panelTemplateDTOChildren = extTemplateMapper.findTemplateList(new TemplateManageRequest(parentTemplate.getId(),dvType)); + List panelTemplateDTOChildren = extTemplateMapper.findTemplateList(new TemplateManageRequest(parentTemplate.getId(), dvType)); parentTemplate.setChildren(panelTemplateDTOChildren); - getTreeChildren(panelTemplateDTOChildren,dvType); + getTreeChildren(panelTemplateDTOChildren, dvType); })); } @@ -96,17 +97,21 @@ public class TemplateManageService implements TemplateManageApi { DEException.throwException("名称已存在"); } VisualizationTemplateCategory templateCategory = new VisualizationTemplateCategory(); - BeanUtils.copyBean(templateCategory,request); + BeanUtils.copyBean(templateCategory, request); templateCategoryMapper.insert(templateCategory); } else {//模板插入 同名的模板进行覆盖(先删除) + // 分类映射删除 + extTemplateMapper.deleteCategoryMapByTemplate(request.getName(),null); + // 模版删除 QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.eq("name",request.getName()); + wrapper.eq("name", request.getName()); templateMapper.delete(wrapper); + VisualizationTemplate template = new VisualizationTemplate(); - BeanUtils.copyBean(template,request); + BeanUtils.copyBean(template, request); templateMapper.insert(template); // 插入分类关系 - request.getCategories().forEach(categoryId ->{ + request.getCategories().forEach(categoryId -> { VisualizationTemplateCategoryMap categoryMap = new VisualizationTemplateCategoryMap(); categoryMap.setId(UUID.randomUUID().toString()); categoryMap.setCategoryId(categoryId); @@ -122,16 +127,27 @@ public class TemplateManageService implements TemplateManageApi { DEException.throwException("名称已存在"); } VisualizationTemplateCategory templateCategory = new VisualizationTemplateCategory(); - BeanUtils.copyBean(templateCategory,request); + BeanUtils.copyBean(templateCategory, request); templateCategoryMapper.updateById(templateCategory); - }else{ + } else { String nameCheckResult = this.nameCheck(CommonConstants.OPT_TYPE.UPDATE, request.getName(), request.getId()); if (CommonConstants.CHECK_RESULT.EXIST_ALL.equals(nameCheckResult)) { DEException.throwException("名称已存在"); } VisualizationTemplate template = new VisualizationTemplate(); - BeanUtils.copyBean(template,request); + BeanUtils.copyBean(template, request); templateMapper.updateById(template); + //更新分类 + // 分类映射删除 + extTemplateMapper.deleteCategoryMapByTemplate(null,request.getId()); + // 插入分类关系 + request.getCategories().forEach(categoryId -> { + VisualizationTemplateCategoryMap categoryMap = new VisualizationTemplateCategoryMap(); + categoryMap.setId(UUID.randomUUID().toString()); + categoryMap.setCategoryId(categoryId); + categoryMap.setTemplateId(request.getId()); + categoryMapMapper.insert(categoryMap); + }); } } @@ -141,14 +157,14 @@ public class TemplateManageService implements TemplateManageApi { return templateManageDTO; } - //名称检查 - public String nameCheck(String optType, String name,String id) { + //模版名称检查 + public String nameCheck(String optType, String name, String id) { QueryWrapper wrapper = new QueryWrapper<>(); if (CommonConstants.OPT_TYPE.INSERT.equals(optType)) { - wrapper.eq("name",name); + wrapper.eq("name", name); } else if (CommonConstants.OPT_TYPE.UPDATE.equals(optType)) { - wrapper.eq("name",name); - wrapper.ne("id",id); + wrapper.eq("name", name); + wrapper.ne("id", id); } List templateList = templateMapper.selectList(wrapper); if (CollectionUtils.isEmpty(templateList)) { @@ -158,14 +174,25 @@ public class TemplateManageService implements TemplateManageApi { } } - //名称检查 + //分类下模版名称检查 + @Override + public String categoryTemplateNameCheck(TemplateManageRequest request) { + Long result = extTemplateMapper.checkCategoryTemplateName(request.getName(), request.getCategories()); + if (result == 0) { + return CommonConstants.CHECK_RESULT.NONE; + } else { + return CommonConstants.CHECK_RESULT.EXIST_ALL; + } + } + + //分类名称检查 public String categoryNameCheck(String optType, String name, String id) { QueryWrapper wrapper = new QueryWrapper<>(); if (CommonConstants.OPT_TYPE.INSERT.equals(optType)) { - wrapper.eq("name",name); + wrapper.eq("name", name); } else if (CommonConstants.OPT_TYPE.UPDATE.equals(optType)) { - wrapper.eq("name",name); - wrapper.ne("id",id); + wrapper.eq("name", name); + wrapper.ne("id", id); } List templateList = templateCategoryMapper.selectList(wrapper); if (CollectionUtils.isEmpty(templateList)) { @@ -174,31 +201,59 @@ public class TemplateManageService implements TemplateManageApi { return CommonConstants.CHECK_RESULT.EXIST_ALL; } } + @Override public String nameCheck(TemplateManageRequest request) { return nameCheck(request.getOptType(), request.getName(), request.getId()); } + @Override - public void delete(String id) { + public void delete(String id, String categoryId) { Assert.notNull(id, "id cannot be null"); - templateMapper.deleteById(id); + Assert.notNull(categoryId, "categoryId cannot be null"); + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("template_id", id); + queryWrapper.eq("category_id", categoryId); + categoryMapMapper.delete(queryWrapper); + // 如何是最后一个 则实际模版需要删除 + Long result = extTemplateMapper.checkRepeatTemplateId(categoryId, id); + if (result == 0) { + templateMapper.deleteById(id); + } } + @Override - public void deleteCategory(String id) { + public String deleteCategory(String id) { Assert.notNull(id, "id cannot be null"); - templateCategoryMapper.deleteById(id); + // 该分类下是否有其他分类公用的模版 + + Long checkResult = extTemplateMapper.checkCategoryMap(id); + if (checkResult == 0) { + templateCategoryMapper.deleteById(id); + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("category_id", id); + categoryMapMapper.delete(queryWrapper); + return "success"; + } else { + return "repeat"; + } } + @Override public VisualizationTemplateVO findOne(String templateId) { VisualizationTemplate template = templateMapper.selectById(templateId); - if(template != null){ + if (template != null) { VisualizationTemplateVO templateVO = new VisualizationTemplateVO(); - BeanUtils.copyBean(templateVO,template); + BeanUtils.copyBean(templateVO, template); + //查找分类 + List categories = extTemplateMapper.findTemplateCategories(templateId); + templateVO.setCategories(categories); return templateVO; - }else{ + } else { return null; } } + @Override public List find(TemplateManageRequest request) { return extTemplateMapper.findTemplateList(request); diff --git a/core/core-backend/src/main/resources/mybatis/ExtVisualizationTemplateMapper.xml b/core/core-backend/src/main/resources/mybatis/ExtVisualizationTemplateMapper.xml index 1746fdfea4..2c0591a1f6 100644 --- a/core/core-backend/src/main/resources/mybatis/ExtVisualizationTemplateMapper.xml +++ b/core/core-backend/src/main/resources/mybatis/ExtVisualizationTemplateMapper.xml @@ -3,24 +3,24 @@ - - - - - - - - - - - - - + + + + + + + + + + + + + - + @@ -33,57 +33,55 @@ - vt.id, vt.`name`, vt.pid, vt.`level`,vt.`dv_type`, vt.node_type, vt.create_by, vt.create_time, vt.template_type, vt.snapshot - + vt + . + id + , vt.`name`, vt.pid, vt.`level`,vt.`dv_type`, vt.node_type, vt.create_by, vt.create_time, vt.template_type, vt.snapshot + - ,vt.template_style, vt.template_data, vt.dynamic_data - + ,vt.template_style, vt.template_data, vt.dynamic_data + + + + + + + + + + delete from visualization_template_category_map tcm where tcm.template_id in ( + select id from visualization_template vt + + + and vt.name = #{templateName} + + + and vt.template_id = #{templateId} + + + + ) + + + diff --git a/core/core-frontend/src/api/template.ts b/core/core-frontend/src/api/template.ts index a9f48b0fe9..d1b0033400 100644 --- a/core/core-frontend/src/api/template.ts +++ b/core/core-frontend/src/api/template.ts @@ -7,9 +7,9 @@ export function save(data) { loading: true }) } -export function templateDelete(id) { +export function templateDelete(id, categoryId) { return request.post({ - url: '/templateManage/delete/' + id + url: '/templateManage/delete/' + id + '/' + categoryId }) } @@ -54,3 +54,10 @@ export function nameCheck(data) { data: data }) } + +export function categoryTemplateNameCheck(data) { + return request.post({ + url: '/templateManage/categoryTemplateNameCheck', + data: data + }) +} diff --git a/core/core-frontend/src/components/data-visualization/canvas/Shape.vue b/core/core-frontend/src/components/data-visualization/canvas/Shape.vue index 9f3a7e84c7..17f32fea59 100644 --- a/core/core-frontend/src/components/data-visualization/canvas/Shape.vue +++ b/core/core-frontend/src/components/data-visualization/canvas/Shape.vue @@ -49,6 +49,7 @@ :style="getPointStyle(item)" @mousedown="handleMouseDownOnPoint(item, $event)" > +