mirror of
https://github.com/dataease/dataease.git
synced 2026-05-21 04:08:10 +08:00
fix: 模板不允许重名 但是可以允许覆盖
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
package io.dataease.commons.constants;
|
||||
|
||||
/**
|
||||
* Author: wangjiahao
|
||||
* Date: 2021-05-25
|
||||
* Description:
|
||||
*/
|
||||
public class CommonConstants {
|
||||
|
||||
|
||||
//操作类型
|
||||
public static final class OPT_TYPE{
|
||||
|
||||
public static final String INSERT = "insert";
|
||||
|
||||
public static final String UPDATE = "update";
|
||||
|
||||
public static final String DELETE = "delete";
|
||||
|
||||
public static final String SELECT = "select";
|
||||
|
||||
}
|
||||
|
||||
//操作类型
|
||||
public static final class CHECK_RESULT{
|
||||
|
||||
// 不存在
|
||||
public static final String NONE = "none";
|
||||
|
||||
// 全局存在
|
||||
public static final String EXIST_ALL= "exist_all";
|
||||
|
||||
// 当前用户存在
|
||||
public static final String EXIST_USER= "exist_user";
|
||||
|
||||
// 其他用户存在
|
||||
public static final String EXIST_OTHER= "exist_other";
|
||||
|
||||
}
|
||||
}
|
||||
@@ -7,14 +7,11 @@ package io.dataease.commons.constants;
|
||||
*/
|
||||
public class SystemConstants {
|
||||
|
||||
public final static String WITH_EXTEND_NOW = "now";
|
||||
public final static String WITH_EXTEND_PARENT = "parent";
|
||||
public final static String WITH_EXTEND_CHILDREN = "children";
|
||||
|
||||
|
||||
public final static int PRIVILEGE_VALUE_ON= 1;
|
||||
public final static int PRIVILEGE_VALUE_OFF = 0;
|
||||
|
||||
public static final class WITH_EXTEND{
|
||||
public final static String NOW = "now";
|
||||
public final static String PARENT = "parent";
|
||||
public final static String CHILDREN = "children";
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -49,4 +49,10 @@ public class PanelTemplateController {
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/nameCheck")
|
||||
public String nameCheck(@RequestBody PanelTemplateRequest request) {
|
||||
return panelTemplateService.nameCheck(request);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ public class BaseTreeRequest {
|
||||
private String pid;
|
||||
|
||||
//now 返回当前条件查询的数据 parent 返回当前数据查询的数据同时递归父节点数据; children 返回当前数据查询的数据同时递归子节点数据
|
||||
private String withExtend= SystemConstants.WITH_EXTEND_NOW;
|
||||
private String withExtend= SystemConstants.WITH_EXTEND.NOW;
|
||||
|
||||
private String createBy;
|
||||
|
||||
|
||||
@@ -12,6 +12,8 @@ import lombok.Data;
|
||||
public class PanelTemplateRequest extends PanelTemplateWithBLOBs {
|
||||
private String sort;
|
||||
|
||||
private String optType;
|
||||
|
||||
private Boolean withChildren = false;
|
||||
|
||||
public PanelTemplateRequest() {
|
||||
|
||||
@@ -3,15 +3,20 @@ package io.dataease.service.panel;
|
||||
import io.dataease.base.domain.*;
|
||||
import io.dataease.base.mapper.PanelTemplateMapper;
|
||||
import io.dataease.base.mapper.ext.ExtPanelTemplateMapper;
|
||||
import io.dataease.commons.constants.CommonConstants;
|
||||
import io.dataease.commons.constants.PanelConstants;
|
||||
import io.dataease.commons.utils.AuthUtils;
|
||||
import io.dataease.commons.utils.BeanUtils;
|
||||
import io.dataease.controller.request.panel.PanelTemplateRequest;
|
||||
import io.dataease.dto.panel.PanelTemplateDTO;
|
||||
import io.dataease.i18n.Translator;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
@@ -54,16 +59,30 @@ public class PanelTemplateService {
|
||||
}
|
||||
|
||||
|
||||
@Transactional
|
||||
public PanelTemplateDTO save(PanelTemplateRequest request) {
|
||||
if (StringUtils.isEmpty(request.getId())) {
|
||||
//如果level 是0(第一级)设置父级为对应的templateType
|
||||
if(request.getLevel()==0){
|
||||
request.setPid(request.getTemplateType());
|
||||
}
|
||||
request.setId(UUID.randomUUID().toString());
|
||||
request.setCreateTime(System.currentTimeMillis());
|
||||
request.setCreateBy(AuthUtils.getUser().getUsername());
|
||||
//如果level 是0(第一级)指的是分类目录 设置父级为对应的templateType
|
||||
if(request.getLevel()==0){
|
||||
request.setPid(request.getTemplateType());
|
||||
String nameCheckResult = this.nameCheck(CommonConstants.OPT_TYPE.INSERT,request.getName(),request.getPid(),null);
|
||||
if(CommonConstants.CHECK_RESULT.EXIST_ALL.equals(nameCheckResult)){
|
||||
throw new RuntimeException(Translator.get("i18n_same_folder_can_not_repeat"));
|
||||
}
|
||||
}else{//模板插入 相同文件夹同名的模板进行覆盖(先删除)
|
||||
PanelTemplateExample exampleDelete = new PanelTemplateExample();
|
||||
exampleDelete.createCriteria().andPidEqualTo(request.getPid()).andNameEqualTo(request.getName());
|
||||
panelTemplateMapper.deleteByExample(exampleDelete);
|
||||
}
|
||||
panelTemplateMapper.insert(request);
|
||||
} else {
|
||||
String nameCheckResult = this.nameCheck(CommonConstants.OPT_TYPE.UPDATE,request.getName(),request.getPid(),request.getId());
|
||||
if(CommonConstants.CHECK_RESULT.EXIST_ALL.equals(nameCheckResult)){
|
||||
throw new RuntimeException(Translator.get("i18n_same_folder_can_not_repeat"));
|
||||
}
|
||||
panelTemplateMapper.updateByPrimaryKeySelective(request);
|
||||
}
|
||||
PanelTemplateDTO panelTemplateDTO = new PanelTemplateDTO();
|
||||
@@ -73,6 +92,29 @@ public class PanelTemplateService {
|
||||
}
|
||||
|
||||
|
||||
//名称检查
|
||||
public String nameCheck(String optType,String name,String pid,String id){
|
||||
PanelTemplateExample example = new PanelTemplateExample();
|
||||
if(CommonConstants.OPT_TYPE.INSERT.equals(optType)){
|
||||
example.createCriteria().andPidEqualTo(pid).andNameEqualTo(name);
|
||||
|
||||
}else if(CommonConstants.OPT_TYPE.UPDATE.equals(optType)){
|
||||
example.createCriteria().andPidEqualTo(pid).andNameEqualTo(name).andIdNotEqualTo(id);
|
||||
}
|
||||
List<PanelTemplate> panelTemplates = panelTemplateMapper.selectByExample(example);
|
||||
if(CollectionUtils.isEmpty(panelTemplates)){
|
||||
return CommonConstants.CHECK_RESULT.NONE;
|
||||
}else{
|
||||
return CommonConstants.CHECK_RESULT.EXIST_ALL;
|
||||
}
|
||||
}
|
||||
|
||||
public String nameCheck(PanelTemplateRequest request){
|
||||
return nameCheck(request.getOptType(),request.getName(),request.getPid(),request.getId());
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void delete(String id){
|
||||
Assert.notNull(id, "id cannot be null");
|
||||
panelTemplateMapper.deleteByPrimaryKey(id);
|
||||
|
||||
@@ -103,7 +103,7 @@ public class SysAuthService {
|
||||
}
|
||||
|
||||
private List<String> getAuthModels(String id, String type) {
|
||||
List<VAuthModelDTO> vAuthModelDTOS = searchAuthModelTree(new BaseTreeRequest(id,type, SystemConstants.WITH_EXTEND_CHILDREN));
|
||||
List<VAuthModelDTO> vAuthModelDTOS = searchAuthModelTree(new BaseTreeRequest(id,type, SystemConstants.WITH_EXTEND.CHILDREN));
|
||||
List<String> authSources = Optional.ofNullable(vAuthModelDTOS).orElse(new ArrayList<>()).stream().map(VAuthModelDTO::getId)
|
||||
.collect(Collectors.toList());
|
||||
return authSources;
|
||||
|
||||
Reference in New Issue
Block a user