fixs: 实体删除检查引用关系

This commit is contained in:
devezhao 2019-05-13 14:05:56 +08:00
parent 1782da2229
commit 71054556b6
8 changed files with 66 additions and 31 deletions

View file

@ -333,7 +333,7 @@ public class MetadataHelper {
* @param fieldPath
* @return
*/
public static Field getLastField(Entity entity, String fieldPath) {
public static Field getLastJoinField(Entity entity, String fieldPath) {
String[] paths = fieldPath.split(".");
Field lastField = null;
Entity father = entity;

View file

@ -214,10 +214,16 @@ public class Entity2Schema extends Field2Schema {
throw new ModifiyMetadataException("不能删除主实体");
}
for (Field whoRef : entity.getReferenceToFields()) {
if (!whoRef.getOwnEntity().equals(entity)) {
throw new ModifiyMetadataException("实体已被引用 (引用实体: " + EasyMeta.getLabel(whoRef.getOwnEntity()) + ")");
}
}
if (!force) {
long count = 0;
if ((count = checkRecordCount(entity)) > 0) {
throw new ModifiyMetadataException("不能删除有记录的实体 (" + entity.getName() + "=" + count + ")");
throw new ModifiyMetadataException("不能删除有数据的实体 (数量: " + count + ")");
}
}

View file

@ -90,7 +90,7 @@ public class Field2Schema {
public String create(Entity entity, String fieldLabel, DisplayType type, String comments, String refEntity, JSON extConfig) {
long count = 0;
if ((count = checkRecordCount(entity)) > 50000) {
throw new ModifiyMetadataException("本实体记录过大,增加字段可能导致表损坏 (" + entity.getName() + "=" + count + ")");
throw new ModifiyMetadataException("本实体记录过大,增加字段可能导致表损坏 (记录数: " + count + ")");
}
String fieldName = toPinyinName(fieldLabel);
@ -108,7 +108,7 @@ public class Field2Schema {
boolean schemaReady = schema2Database(entity, field);
if (!schemaReady) {
Application.getCommonService().delete(tempMetaId.toArray(new ID[tempMetaId.size()]));
return null;
throw new ModifiyMetadataException("无法创建字段到数据库");
}
Application.getMetadataFactory().refresh(false);

View file

@ -185,6 +185,7 @@ public class MetaEntityControll extends BasePageControll {
public void entityDrop(HttpServletRequest request, HttpServletResponse response) throws IOException {
ID user = getRequestUser(request);
ID entityId = getIdParameterNotNull(request, "id");
boolean force = getBoolParameter(request, "force", false);
Object[] entityRecord = Application.createQueryNoFilter(
"select entityName from MetaEntity where entityId = ?")
@ -192,7 +193,7 @@ public class MetaEntityControll extends BasePageControll {
.unique();
Entity entity = MetadataHelper.getEntity((String) entityRecord[0]);
boolean drop = new Entity2Schema(user).drop(entity);
boolean drop = new Entity2Schema(user).drop(entity, force);
if (drop) {
writeSuccess(response);
} else {

View file

@ -52,6 +52,9 @@ a#entityIcon:hover{opacity:0.8}
<label class="custom-control custom-control-sm custom-checkbox custom-control-inline mb-2">
<input class="custom-control-input J_drop-check" type="checkbox"><span class="custom-control-label"> 我已知晓风险</span>
</label>
<label class="custom-control custom-control-sm custom-checkbox custom-control-inline mb-2 bosskey-show">
<input class="custom-control-input J_drop-force" type="checkbox"><span class="custom-control-label"> 强制删除</span>
</label>
</div>
<div class="mb-1">
<button type="button" class="btn btn-danger J_drop-confirm" disabled="disabled" data-loading-text="删除中"><i class="zmdi zmdi-delete icon"></i> 确认删除</button>
@ -84,11 +87,12 @@ $(document).ready(function(){
})
let sbtn = $('.J_drop-confirm').click(() => {
if ($('.J_drop-check').prop('checked') == false) return
if (!window.__PageConfig.isSuperAdmin){ rb.hberror('仅超级管理员可删除实体'); return }
rb.alert('实体删除后将无法恢复,请务必谨慎操作!确认删除吗?', '删除实体', { type: 'danger', confirmText: '删除', confirm: function(){
rb.alert('实体删除后将无法恢复,请务必谨慎操作!确认删除吗?', '删除实体', { type: 'danger', confirmText: '删除', confirm: function () {
sbtn.button('loading')
this.disabled(true)
$.post('../entity-drop?id=' + metaId, (res) => {
$.post('../entity-drop?id=' + metaId + '&force=' + $('.J_drop-force').prop('checked'), (res) => {
if (res.error_code == 0) {
rb.hbsuccess('实体已删除')
setTimeout(function() { location.replace('../../entities') }, 1500)

View file

@ -1,15 +1,10 @@
.dev-show {
display: none;
}
html.dev .dev-show {
display: block;
}
.admin-show {
.dev-show,
.admin-show,
.bosskey-show {
display: none;
}
html.dev .dev-show,
html.admin .admin-show {
display: block;
}

View file

@ -10,8 +10,8 @@ $(function () {
}, 500, 'rb-scroller-update')
})
if (window.lessIE11) {
$('.left-sidebar-scroll').height($('.left-sidebar-spacer').height())
$('html').addClass('ie10')
$('.left-sidebar-scroll').height($('.left-sidebar-spacer').height())
$('html').addClass('ie10')
}
// tooltip
@ -44,9 +44,12 @@ $(function () {
$('.J_notifications-top').on('shown.bs.dropdown', __loadMessages)
}
var keydown_times = 0
var bkeydown_times = 0
$(document.body).keydown(function (e) {
if (e.ctrlKey && e.altKey && e.which === 88) command_exec(++keydown_times)
if (e.ctrlKey && e.altKey && e.which === 88) {
if (++bkeydown_times === 6) $('.bosskey-show').show()
command_exec(bkeydown_times)
}
})
})
// Trigger on Ctrl+Alt+X
@ -196,7 +199,9 @@ var $fileExtName = function (fileName) {
}
var $gotoSection = function (top, target) {
$(target || 'body').animate({ scrollTop: top || 0 }, 600)
$(target || 'body').animate({
scrollTop: top || 0
}, 600)
}
// Use H5 or Qiuniu
@ -206,12 +211,16 @@ var $createUploader = function (input, next, complete, error) {
if (window.qiniu && rb.storageUrl) {
input.on('change', function () {
var file = this.files[0]
var putExtra = imgOnly ? { mimeType: ['image/png', 'image/jpeg', 'image/gif', 'image/bmp', 'image/tiff'] } : null
var putExtra = imgOnly ? {
mimeType: ['image/png', 'image/jpeg', 'image/gif', 'image/bmp', 'image/tiff']
} : null
$.get(rb.baseUrl + '/filex/qiniu/upload-keys?file=' + $encode(file.name), function (res) {
var o = qiniu.upload(file, res.data.key, res.data.token, putExtra)
o.subscribe({
next: function (res) {
typeof next === 'function' && next({ percent: res.total.percent })
typeof next === 'function' && next({
percent: res.total.percent
})
},
error: function (err) {
var msg = (err.message || 'UnknowError').toUpperCase()
@ -222,17 +231,20 @@ var $createUploader = function (input, next, complete, error) {
rb.highbar('超出文件大小限制')
return false
}
if (error) error({ error: msg })
if (error) error({
error: msg
})
else rb.hberror('上传失败: ' + msg)
},
complete: function (res) {
typeof complete === 'function' && complete({ key: res.key })
typeof complete === 'function' && complete({
key: res.key
})
}
})
})
})
}
else {
} else {
input.html5Uploader({
name: input.attr('id') || input.attr('name') || 'H5Upload',
postUrl: rb.baseUrl + '/filex/upload?type=' + (imgOnly ? 'image' : 'file'),
@ -247,21 +259,29 @@ var $createUploader = function (input, next, complete, error) {
},
onClientLoad: function (e, file) {},
onClientProgress: function (e, file) {
typeof next === 'function' && next({ percent: e.loaded * 100 / e.total })
typeof next === 'function' && next({
percent: e.loaded * 100 / e.total
})
},
onSuccess: function (d) {
d = $.parseJSON(d.currentTarget.response)
if (d.error_code === 0) {
complete({ key: d.data })
complete({
key: d.data
})
} else {
var msg = d.error_msg || '上传失败请稍后重试'
if (error) error({ error: msg })
if (error) error({
error: msg
})
else rb.hberror(msg)
}
},
onClientError: function (e, file) {
var msg = '上传失败请稍后重试'
if (error) error({ error: msg })
if (error) error({
error: msg
})
else rb.hberror(msg)
}
})

View file

@ -59,4 +59,13 @@ public class Meta2SchemaTest extends TestSupport {
drop = new Entity2Schema(UserService.ADMIN_USER).drop(newEntity);
System.out.println("New Entity (for Field) is dropped : " + newEntityName + " > " + drop);
}
@Test
public void testForceDropEntity() throws Exception {
String entityName = "dingdan";
if (!MetadataHelper.containsEntity(entityName)) {
return;
}
new Entity2Schema(UserService.ADMIN_USER).drop(MetadataHelper.getEntity("kehu"), true);
}
}