mirror of
https://github.com/getrebuild/rebuild.git
synced 2025-02-25 06:45:20 +08:00
batch better
This commit is contained in:
parent
717d76e20d
commit
f4e3bf212c
6 changed files with 56 additions and 7 deletions
45
src/main/java/com/rebuild/server/SecurityException.java
Normal file
45
src/main/java/com/rebuild/server/SecurityException.java
Normal file
|
@ -0,0 +1,45 @@
|
|||
/*
|
||||
rebuild - Building your business-systems freely.
|
||||
Copyright (C) 2018-2019 devezhao <zhaofang123@gmail.com>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.rebuild.server;
|
||||
|
||||
/**
|
||||
* 业务安全异常
|
||||
*
|
||||
* @author ZHAO
|
||||
* @since 2019/12/3
|
||||
*/
|
||||
public class SecurityException extends RebuildException {
|
||||
private static final long serialVersionUID = 8786241299394987035L;
|
||||
|
||||
public SecurityException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public SecurityException(String msg, Throwable cause) {
|
||||
super(msg, cause);
|
||||
}
|
||||
|
||||
public SecurityException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
|
||||
public SecurityException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
|
@ -223,7 +223,7 @@ public class EasyMeta implements BaseMeta {
|
|||
}
|
||||
|
||||
/**
|
||||
* 此方法除了判断元实体,还会判断其他业务规则
|
||||
* 此方法除了判断元数据,还会判断其他业务规则
|
||||
*
|
||||
* @return
|
||||
* @see Field#isUpdatable()
|
||||
|
|
|
@ -49,6 +49,7 @@ public class BulkContext {
|
|||
private String[] cascades;
|
||||
|
||||
// [特定数据] 默认为高级查询表达式
|
||||
// 如果为查询条件,其必须含有查询项,否则将抛出异常
|
||||
private JSONObject customData;
|
||||
|
||||
final private Entity mainEntity;
|
||||
|
|
|
@ -24,7 +24,6 @@ import cn.devezhao.persist4j.engine.ID;
|
|||
import cn.devezhao.persist4j.util.support.QueryHelper;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.rebuild.server.Application;
|
||||
import com.rebuild.server.RebuildException;
|
||||
import com.rebuild.server.helper.task.HeavyTask;
|
||||
import com.rebuild.server.metadata.MetadataHelper;
|
||||
import com.rebuild.server.service.query.AdvFilterParser;
|
||||
|
@ -67,7 +66,7 @@ public abstract class BulkOperator extends HeavyTask<Integer> {
|
|||
/**
|
||||
* @return
|
||||
*/
|
||||
protected int getSucceeded() {
|
||||
public int getSucceeded() {
|
||||
return succeeded;
|
||||
}
|
||||
|
||||
|
@ -96,8 +95,9 @@ public abstract class BulkOperator extends HeavyTask<Integer> {
|
|||
JSONObject asFilterExp = context.getCustomData();
|
||||
AdvFilterParser filterParser = new AdvFilterParser(asFilterExp);
|
||||
String sqlWhere = filterParser.toSqlWhere();
|
||||
// `(1=1)`.length < 10
|
||||
if (sqlWhere.length() < 10) {
|
||||
throw new RebuildException("Must have some filters : " + sqlWhere);
|
||||
throw new SecurityException("Must specify filter items : " + sqlWhere);
|
||||
}
|
||||
|
||||
Entity entity = MetadataHelper.getEntity(asFilterExp.getString("entity"));
|
||||
|
|
|
@ -21,6 +21,7 @@ package com.rebuild.web.base;
|
|||
import com.alibaba.fastjson.JSON;
|
||||
import com.rebuild.server.helper.task.HeavyTask;
|
||||
import com.rebuild.server.helper.task.TaskExecutors;
|
||||
import com.rebuild.server.service.base.BulkOperator;
|
||||
import com.rebuild.utils.JSONUtils;
|
||||
import com.rebuild.web.BaseControll;
|
||||
import org.springframework.stereotype.Controller;
|
||||
|
@ -42,9 +43,11 @@ public class HeavyTaskControll extends BaseControll {
|
|||
public void checkState(HttpServletRequest request, HttpServletResponse response) {
|
||||
String taskid = getParameterNotNull(request, "taskid");
|
||||
HeavyTask<?> task = TaskExecutors.getTask(taskid);
|
||||
|
||||
int succeeded = task instanceof BulkOperator ? ((BulkOperator) task).getSucceeded() : task.getCompleted();
|
||||
JSON ret = JSONUtils.toJSONObject(
|
||||
new String[] { "taskid", "progress", "hasError", "completed" },
|
||||
new Object[] { taskid, task.getCompletedPercent(), task.getErrorMessage(), task.getCompleted() });
|
||||
new String[] { "taskid", "progress", "hasError", "completed", "succeeded" },
|
||||
new Object[] { taskid, task.getCompletedPercent(), task.getErrorMessage(), task.getCompleted(), "succeeded" });
|
||||
writeSuccess(response, ret);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1156,7 +1156,7 @@ class BatchUpdate extends BatchOperator {
|
|||
if (cp >= 1) {
|
||||
mp && mp.end()
|
||||
$(this._btns).find('.btn-primary').text('修改成功')
|
||||
RbHighbar.success(`成功修改 ${res.data.completed} 条记录`)
|
||||
RbHighbar.success(`成功修改 ${res.data.succeeded} 条记录`)
|
||||
setTimeout(() => {
|
||||
this.hide()
|
||||
window.RbListPage && window.RbListPage.reload()
|
||||
|
|
Loading…
Reference in a new issue