fix: 模板不允许重名 但是可以允许覆盖
This commit is contained in:
parent
45eb0acbfa
commit
00b8e2d4a5
@ -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;
|
||||
|
||||
@ -36,3 +36,11 @@ export function find(data) {
|
||||
method: 'post'
|
||||
})
|
||||
}
|
||||
|
||||
export function nameCheck(data) {
|
||||
return request({
|
||||
url: '/template/nameCheck',
|
||||
data: data,
|
||||
method: 'post'
|
||||
})
|
||||
}
|
||||
|
||||
@ -960,5 +960,11 @@ export default {
|
||||
enterprise: 'Enterprise',
|
||||
suport: 'Get technical support',
|
||||
update_success: 'Update Success'
|
||||
},
|
||||
template: {
|
||||
exit_same_template_check: 'The Same Name Exists In Now Class. Do You Want To Override It?',
|
||||
override: 'Override',
|
||||
cancel: '取消',
|
||||
confirm_upload: 'Upload Confirm'
|
||||
}
|
||||
}
|
||||
|
||||
@ -959,5 +959,12 @@ export default {
|
||||
enterprise: '企業版',
|
||||
suport: '獲取技術支持',
|
||||
update_success: '更新成功'
|
||||
},
|
||||
template: {
|
||||
exit_same_template_check: '当前存在相同名称模板,是否覆盖?',
|
||||
override: '覆盖',
|
||||
cancel: '取消',
|
||||
confirm_upload: '上传确认'
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -962,5 +962,11 @@ export default {
|
||||
enterprise: '企业版',
|
||||
suport: '获取技术支持',
|
||||
update_success: '更新成功'
|
||||
},
|
||||
template: {
|
||||
exit_same_template_check: '当前分类存在相同名称模板,是否覆盖?',
|
||||
override: '覆盖',
|
||||
cancel: '取消',
|
||||
confirm_upload: '上传确认'
|
||||
}
|
||||
}
|
||||
|
||||
@ -17,7 +17,7 @@
|
||||
</el-tabs>
|
||||
</de-aside-container>
|
||||
<de-main-container>
|
||||
<PanelViewShow />
|
||||
<PanelViewShow v-if="mainActiveName==='PanelMain'" />
|
||||
</de-main-container>
|
||||
</de-container>
|
||||
</template>
|
||||
@ -41,6 +41,14 @@ export default {
|
||||
showEnshrine: false
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
mainActiveName() {
|
||||
return this.$store.state.panel.mainActiveName
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
this.$store.dispatch('panel/setMainActiveName', 'PanelMain')
|
||||
},
|
||||
methods: {
|
||||
handleClick(tab, event) {
|
||||
// 点击分析面板需要刷新分享内容
|
||||
|
||||
@ -40,7 +40,7 @@
|
||||
<!--TODO 仪表盘预览区域-->
|
||||
<el-row class="panel-design-preview">
|
||||
<div ref="imageWrapper" style="width: 100%;height: 100%">
|
||||
<Preview v-if="mainActiveName==='PanelMain'&&showMain" />
|
||||
<Preview v-if="showMain" />
|
||||
</div>
|
||||
</el-row>
|
||||
</el-col>
|
||||
@ -74,7 +74,7 @@ export default {
|
||||
data() {
|
||||
return {
|
||||
showMain: true,
|
||||
templateInfo: '',
|
||||
templateInfo: {},
|
||||
templateSaveTitle: '保存为模板',
|
||||
templateSaveShow: false,
|
||||
hasStar: false
|
||||
@ -84,9 +84,6 @@ export default {
|
||||
panelInfo() {
|
||||
return this.$store.state.panel.panelInfo
|
||||
},
|
||||
mainActiveName() {
|
||||
return this.$store.state.panel.mainActiveName
|
||||
},
|
||||
...mapState([
|
||||
'componentData',
|
||||
'canvasStyleData'
|
||||
@ -146,7 +143,7 @@ export default {
|
||||
})
|
||||
},
|
||||
refreshTemplateInfo() {
|
||||
this.templateInfo = ''
|
||||
this.templateInfo = {}
|
||||
html2canvas(this.$refs.imageWrapper).then(canvas => {
|
||||
const snapshot = canvas.toDataURL('image/jpeg', 0.2) // 0.2是图片质量
|
||||
if (snapshot !== '') {
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
<template>
|
||||
<el-row>
|
||||
<el-row>
|
||||
<el-col :span="4"> {{ $t('panel.template_nale')}}</el-col>
|
||||
<el-col :span="4"> {{ $t('panel.template_nale') }}</el-col>
|
||||
<el-col :span="20">
|
||||
<el-input v-model="templateInfo.name" clearable size="mini" />
|
||||
</el-col>
|
||||
@ -26,21 +26,20 @@
|
||||
</div>
|
||||
</el-row>
|
||||
<el-row class="root-class">
|
||||
<el-button @click="cancel()">{{ $t('commons.cancel')}}</el-button>
|
||||
<el-button type="primary" @click="save()">{{ $t('commons.save')}}</el-button>
|
||||
<el-button @click="cancel()">{{ $t('commons.cancel') }}</el-button>
|
||||
<el-button type="primary" @click="save()">{{ $t('commons.save') }}</el-button>
|
||||
</el-row>
|
||||
</el-row>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { post } from '@/api/panel/panel'
|
||||
import { save, nameCheck, showTemplateList } from '@/api/system/template'
|
||||
|
||||
export default {
|
||||
name: 'SaveToTemplate',
|
||||
props: {
|
||||
templateInfo: {
|
||||
type: Object,
|
||||
require: true
|
||||
type: Object
|
||||
}
|
||||
},
|
||||
data() {
|
||||
@ -61,7 +60,7 @@ export default {
|
||||
templateType: 'self',
|
||||
level: '0'
|
||||
}
|
||||
post('/template/templateList', param).then(response => {
|
||||
showTemplateList(param).then(response => {
|
||||
this.data = response.data
|
||||
})
|
||||
},
|
||||
@ -81,13 +80,41 @@ export default {
|
||||
this.$warning(this.$t('panel.template_name_cannot_be_empty'))
|
||||
return false
|
||||
}
|
||||
post('/template/save', this.templateInfo).then(response => {
|
||||
this.$message({
|
||||
message: this.$t('commons.save_success'),
|
||||
type: 'success',
|
||||
showClose: true
|
||||
})
|
||||
this.$emit('closeSaveDialog')
|
||||
|
||||
const nameCheckRequest = {
|
||||
pid: this.templateInfo.pid,
|
||||
name: this.templateInfo.name,
|
||||
optType: 'insert'
|
||||
}
|
||||
nameCheck(nameCheckRequest).then(response => {
|
||||
if (response.data.indexOf('exist') > -1) {
|
||||
this.$confirm(this.$t('template.exit_same_template_check'), this.$t('template.confirm_upload'), {
|
||||
confirmButtonText: this.$t('template.override'),
|
||||
cancelButtonText: this.$t('template.cancel'),
|
||||
type: 'warning'
|
||||
}).then(() => {
|
||||
save(this.templateInfo).then(response => {
|
||||
this.$message({
|
||||
message: this.$t('commons.save_success'),
|
||||
type: 'success',
|
||||
showClose: true
|
||||
})
|
||||
debugger
|
||||
this.$emit('closeSaveDialog')
|
||||
})
|
||||
}).catch(() => {
|
||||
})
|
||||
} else {
|
||||
save(this.templateInfo).then(response => {
|
||||
this.$message({
|
||||
message: this.$t('commons.save_success'),
|
||||
type: 'success',
|
||||
showClose: true
|
||||
})
|
||||
debugger
|
||||
this.$emit('closeSaveDialog')
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@ -19,7 +19,7 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { save } from '@/api/system/template'
|
||||
import { save, nameCheck } from '@/api/system/template'
|
||||
|
||||
export default {
|
||||
|
||||
@ -70,14 +70,40 @@ export default {
|
||||
this.$warning(this.$t('chart.name_can_not_empty'))
|
||||
return false
|
||||
}
|
||||
save(this.templateInfo).then(response => {
|
||||
this.$message({
|
||||
message: this.$t('commons.save_success'),
|
||||
type: 'success',
|
||||
showClose: true
|
||||
})
|
||||
debugger
|
||||
this.$emit('closeEditTemplateDialog')
|
||||
const nameCheckRequest = {
|
||||
pid: this.templateInfo.pid,
|
||||
name: this.templateInfo.name,
|
||||
optType: 'insert'
|
||||
}
|
||||
nameCheck(nameCheckRequest).then(response => {
|
||||
if (response.data.indexOf('exist') > -1) {
|
||||
this.$confirm(this.$t('template.exit_same_template_check'), this.$t('template.confirm_upload'), {
|
||||
confirmButtonText: this.$t('template.override'),
|
||||
cancelButtonText: this.$t('template.cancel'),
|
||||
type: 'warning'
|
||||
}).then(() => {
|
||||
save(this.templateInfo).then(response => {
|
||||
this.$message({
|
||||
message: this.$t('commons.save_success'),
|
||||
type: 'success',
|
||||
showClose: true
|
||||
})
|
||||
debugger
|
||||
this.$emit('closeEditTemplateDialog')
|
||||
})
|
||||
}).catch(() => {
|
||||
})
|
||||
} else {
|
||||
save(this.templateInfo).then(response => {
|
||||
this.$message({
|
||||
message: this.$t('commons.save_success'),
|
||||
type: 'success',
|
||||
showClose: true
|
||||
})
|
||||
debugger
|
||||
this.$emit('closeEditTemplateDialog')
|
||||
})
|
||||
}
|
||||
})
|
||||
},
|
||||
handleFileChange(e) {
|
||||
|
||||
@ -12,6 +12,7 @@
|
||||
@templateEdit="templateEdit"
|
||||
@showCurrentTemplate="showCurrentTemplate"
|
||||
@templateImport="templateImport"
|
||||
@showTemplateEditDialog="showTemplateEditDialog"
|
||||
/>
|
||||
</el-tab-pane>
|
||||
<el-tab-pane name="self">
|
||||
@ -25,6 +26,7 @@
|
||||
@templateEdit="templateEdit"
|
||||
@showCurrentTemplate="showCurrentTemplate"
|
||||
@templateImport="templateImport"
|
||||
@showTemplateEditDialog="showTemplateEditDialog"
|
||||
/>
|
||||
</el-tab-pane>
|
||||
</el-tabs>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user