Skip to content

Commit

Permalink
enh: TriggerByTimerJob 未完成也可重进 (#731)
Browse files Browse the repository at this point in the history
* enh: TriggerByTimerJob 未完成也可重进

* enh: fileName use#698

* feat: UseDbFullText

* !!!@EnableAsync

---------

Co-authored-by: devezhao <[email protected]>
  • Loading branch information
getrebuild and devezhao authored Mar 16, 2024
1 parent df03b4a commit ec222bc
Show file tree
Hide file tree
Showing 27 changed files with 119 additions and 78 deletions.
2 changes: 1 addition & 1 deletion @rbv
Submodule @rbv updated from 0cd82a to a56f9d
2 changes: 2 additions & 0 deletions src/main/java/com/rebuild/core/BootApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.springframework.boot.context.ApplicationPidFileWriter;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.context.annotation.ImportResource;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;

import javax.management.MBeanServer;
Expand Down Expand Up @@ -55,6 +56,7 @@
H2ConsoleAutoConfiguration.class})
@ImportResource("classpath:application-bean.xml")
@EnableScheduling
@EnableAsync
@Slf4j
public class BootApplication extends SpringBootServletInitializer {

Expand Down
3 changes: 1 addition & 2 deletions src/main/java/com/rebuild/core/BootConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@
public class BootConfiguration implements InstallState {

/**
* Fake instance
* FIXME 直接 `==` 比较不安全 ???
* ghost instance
*/
public static final JedisPool USE_EHCACHE = new JedisPool(
KnownJedisPool.DEFAULT_CONFIG, "127.0.0.1", 6379);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,6 @@ public static boolean checkAndWarnField(String entityName, String fieldName) {

/**
* 实体分类标签
* TODO 性能
*
* @return
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ public enum DisplayType {
BOOL(EasyBool.class, "布尔", FieldType.BOOL, FieldType.NO_NEED_LENGTH, null),
BARCODE(EasyBarCode.class, "二维码", FieldType.STRING, 300, null, false, true),
N2NREFERENCE(EasyN2NReference.class, "多引用", FieldType.REFERENCE_LIST, -1, null),
LOCATION(EasyLocation.class, "位置", FieldType.STRING, 100, null),
LOCATION(EasyLocation.class, "位置", FieldType.STRING, 200, null),
SIGN(EasySign.class, "签名", FieldType.TEXT, 32767, null, false, true),
TAG(EasyTag.class, "标签", FieldType.STRING, 100, null),
TAG(EasyTag.class, "标签", FieldType.STRING, 40, null),

// 内部

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import org.springframework.util.Assert;

/**
* TODO 暂不开放开放应注意触发器/记录转换等处的填值
* 暂不开放开放应注意触发器/记录转换等处的填值
*
* @author devezhao
* @since 2020/11/17
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,8 @@ public int delete(ID recordId) {
}

/**
* TODO 删除后转移成员到其他部门
*
* @param deptId
* @param transferTo
* @param transferTo 删除后转移成员到其他部门
*/
public void deleteAndTransfer(ID deptId, ID transferTo) {
if (ROOT_DEPT.equals(deptId)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ public boolean allow(ID user, int entity, Permission action) {
return true;
}

// FIXME v35 批量审批无权限
// 审批无权限校验
if (action == InternalPermission.APPROVAL) return true;

Boolean a = userAllow(user);
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/com/rebuild/core/privileges/RoleService.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,8 @@ public int delete(ID roleId) {
}

/**
* TODO 删除后转移成员到其他角色
*
* @param roleId
* @param transferTo
* @param transferTo 删除后转移成员到其他角色
*/
public void deleteAndTransfer(ID roleId, ID transferTo) {
if (roleId.equals(ADMIN_ROLE)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.rebuild.core.Application;
import com.rebuild.core.metadata.EntityHelper;
import com.rebuild.core.privileges.UserHelper;
import com.rebuild.core.support.integration.QiniuCloud;
import com.rebuild.utils.JSONUtils;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.map.LRUMap;
Expand Down Expand Up @@ -61,6 +62,7 @@ public static void storeFileSize(String filePath, int fileSize) {
public static Record createAttachment(String filePath, ID user) {
Record attach = EntityHelper.forNew(EntityHelper.Attachment, user);
attach.setString("filePath", filePath);
attach.setString("fileName", QiniuCloud.parseFileName(filePath));

String ext = FilenameUtils.getExtension(filePath);
if (StringUtils.isNotBlank(ext)) {
Expand All @@ -69,7 +71,7 @@ public static Record createAttachment(String filePath, ID user) {
}

if (FILESIZES.containsKey(filePath)) {
attach.setInt("fileSize", FILESIZES.remove(filePath));
attach.setInt("fileSize", FILESIZES.get(filePath));
} else {
Object[] db = Application.createQueryNoFilter(
"select fileSize from Attachment where filePath = ?")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,6 @@ public AviatorObject call(Map<String, Object> env, AviatorObject arg1, AviatorOb
log.warn("Invalid value with type : {}", $id);
}

// TODO 更多字段类型支持

return arg2;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ SmsUser, SmsPassword, SmsSign(AppName),
PortalUploadMaxSize(200),
MobileNavStyle(34),
PageMourningMode(false),

// !!! 命令行适用
DataDirectory, // 数据目录
RedisDatabase(0), // Redis DB
Expand All @@ -126,6 +126,7 @@ SmsUser, SmsPassword, SmsSign(AppName),
TrustedAllUrl(false), // 可信外部地址
LibreofficeBin, // Libreoffice 命令
UnsafeImgAccess(false), // 不安全图片访问
UseDbFullText(false), // 对支持的字段启用全文索引查询

;

Expand All @@ -145,6 +146,7 @@ public static boolean inJvmArgs(String name) {
|| TrustedAllUrl.name().equalsIgnoreCase(name)
|| LibreofficeBin.name().equalsIgnoreCase(name)
|| UnsafeImgAccess.name().equals(name)
|| UseDbFullText.name().equals(name)
|| SN.name().equalsIgnoreCase(name);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
*
* @author ZHAO
* @since 2020/4/5
* @see DistributedSupport
*/
@Slf4j
public abstract class DistributedJobLock {
Expand Down
28 changes: 28 additions & 0 deletions src/main/java/com/rebuild/core/support/setup/DatabaseFixer.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import cn.devezhao.persist4j.Field;
import cn.devezhao.persist4j.Record;
import cn.devezhao.persist4j.engine.ID;
import cn.devezhao.persist4j.util.support.QueryHelper;
import com.rebuild.core.Application;
import com.rebuild.core.metadata.EntityHelper;
import com.rebuild.core.metadata.MetadataHelper;
Expand All @@ -23,6 +24,7 @@
import com.rebuild.core.support.ConfigurationItem;
import com.rebuild.core.support.KVStorage;
import com.rebuild.core.support.RebuildConfiguration;
import com.rebuild.core.support.integration.QiniuCloud;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.BooleanUtils;

Expand All @@ -37,6 +39,7 @@ public class DatabaseFixer {

private static final String KEY_41 = "DataMigratorV41";
private static final String KEY_346 = "DatabaseFixerV346";
private static final String KEY_370 = "DatabaseFixerV370";

/**
* 辅助数据库升级
Expand Down Expand Up @@ -69,6 +72,19 @@ public static void fixIfNeed() {
}
});
}

if (dbVer <= 55 && !BooleanUtils.toBoolean(KVStorage.getCustomValue(KEY_370))) {
log.info("Database fixing `V370` ...");
ThreadPool.exec(() -> {
try {
fixV370();
KVStorage.setCustomValue(KEY_370, "true");
log.info("Database fixed `V370` all succeeded");
} catch (Exception ex) {
log.error("Database fixing `V370` failed : {}", ThrowableUtils.getRootCause(ex).getLocalizedMessage());
}
});
}
}

// #41:多引用字段改为三方表
Expand Down Expand Up @@ -130,4 +146,16 @@ private static void fixV346() {
}
}
}

// V370:补充附件文件名称
private static void fixV370() {
Object[][] atts = QueryHelper.readArray(
Application.createQueryNoFilter("select attachmentId,filePath from Attachment"));
for (Object[] o : atts) {
String fileName = QiniuCloud.parseFileName((String) o[1]);
Record record = EntityHelper.forUpdate((ID) o[0], UserService.SYSTEM_USER, false);
record.setString("fileName", fileName);
Application.getCommonsService().update(record, false);
}
}
}
11 changes: 8 additions & 3 deletions src/main/java/com/rebuild/web/admin/ApisManagerController.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import com.rebuild.core.Application;
import com.rebuild.core.configuration.RebuildApiService;
import com.rebuild.core.metadata.EntityHelper;
import com.rebuild.core.support.ConfigurationItem;
import com.rebuild.core.support.RebuildConfiguration;
import com.rebuild.core.support.i18n.I18nUtils;
import com.rebuild.utils.CommonsUtils;
import com.rebuild.web.BaseController;
Expand Down Expand Up @@ -89,9 +91,12 @@ public RespBody requestLogs(HttpServletRequest request) {
" where appId = ? and requestTime > ? and (1=1) order by requestTime desc";
if (StringUtils.isNotBlank(q)) {
q = CommonsUtils.escapeSql(q);
sql = sql.replace("(1=1)", String.format("(requestBody like '%%%s%%' or responseBody like '%%%s%%')", q, q));
// // TODO 使用全文索引搜索
// sql = sql.replace("(1=1)", String.format("(requestBody match '%s' or responseBody match '%s')", q, q));
// https://zhuanlan.zhihu.com/p/35675553
if (RebuildConfiguration.getBool(ConfigurationItem.UseDbFullText)) {
sql = sql.replace("(1=1)", String.format("(requestBody match '%s' or responseBody match '%s')", q, q));
} else {
sql = sql.replace("(1=1)", String.format("(requestBody like '%%%s%%' or responseBody like '%%%s%%')", q, q));
}
}

Object[][] array = Application.createQueryNoFilter(sql)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,8 @@ public ModelAndView pageList(HttpServletRequest request) {

@PostMapping("dept-delete")
public RespBody deptDelete(@IdParam ID deptId, HttpServletRequest request) {
ID transfer = getIdParameter(request, "transfer"); // TODO 转移到新部门

Application.getBean(DepartmentService.class).deleteAndTransfer(deptId, transfer);
ID transferTo = getIdParameter(request, "transfer"); // TODO 转移到新部门
Application.getBean(DepartmentService.class).deleteAndTransfer(deptId, transferTo);
return RespBody.ok();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@
import com.rebuild.utils.JSONUtils;
import com.rebuild.web.EntityController;
import com.rebuild.web.IdParam;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
Expand Down Expand Up @@ -115,9 +120,8 @@ public RespBody privilegesUpdate(@IdParam(name = "role") ID roleId, HttpServletR

@PostMapping("role-delete")
public RespBody roleDelete(@IdParam ID roleId, HttpServletRequest request) {
ID transfer = getIdParameter(request, "transfer"); // TODO 转移到新角色

Application.getBean(RoleService.class).deleteAndTransfer(roleId, transfer);
ID transferTo = getIdParameter(request, "transfer"); // TODO 转移到新角色
Application.getBean(RoleService.class).deleteAndTransfer(roleId, transferTo);
return RespBody.ok();
}

Expand Down
4 changes: 1 addition & 3 deletions src/main/java/com/rebuild/web/feeds/FeedsListController.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,7 @@ public RespBody fetchFeeds(HttpServletRequest request) {
if (pageNo == 1) {
count = (Long) Application.createQueryNoFilter(
"select count(feedsId) from Feeds where " + sqlWhere).unique()[0];
if (count == 0) {
return RespBody.ok();
}
if (count == 0) return RespBody.ok();
}

String sql = ITEM_SQL + sqlWhere;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public JSON listFile(HttpServletRequest request) {

List<String> sqlWhere = new ArrayList<>();
if (StringUtils.isNotBlank(q)) {
sqlWhere.add(String.format("filePath like '%%%s%%'", CommonsUtils.escapeSql(q)));
sqlWhere.add(String.format("fileName like '%%%s%%'", CommonsUtils.escapeSql(q)));
}

// 附件
Expand Down
8 changes: 5 additions & 3 deletions src/main/resources/metadata-conf.xml
Original file line number Diff line number Diff line change
Expand Up @@ -228,10 +228,11 @@
<field name="filePath" type="string" max-length="191" nullable="false" description="文件路径"/>
<field name="fileType" type="string" max-length="20" description="文件类型"/>
<field name="fileSize" type="int" default-value="0" description="文件大小"/>
<field name="fileName" type="string" max-length="100" description="文件名称"/>
<field name="inFolder" type="reference" ref-entity="AttachmentFolder" description="所在目录"/>
<field name="isDeleted" type="bool" default-value="F" description="是否删除"/>
<index field-list="belongEntity,belongField,filePath,isDeleted"/>
<index field-list="inFolder,createdOn,filePath"/>
<index field-list="belongEntity,belongField,fileName,isDeleted"/>
<index field-list="inFolder,createdOn,fileName"/>
<index field-list="relatedRecord"/>
</entity>

Expand Down Expand Up @@ -303,14 +304,14 @@
<index field-list="recordId,approvalId,node,isCanceled,isWaiting,isBacked,nodeBatch"/>
</entity>

<!--
<entity name="RobotSopConfig" type-code="070" name-field="name" description="操作流程/业务进度" queryable="false">
<field name="configId" type="primary"/>
<field name="belongEntity" type="string" max-length="100" nullable="false" updatable="false" description="应用实体"/>
<field name="name" type="string" max-length="100" nullable="false" description="流程名称"/>
<field name="sopDefinition" type="text" description="流程定义"/>
<field name="isDisabled" type="bool" default-value="F" description="是否禁用"/>
</entity>

<entity name="RobotSopStep" type-code="071" description="操作流程步骤" queryable="false">
<field name="stepId" type="primary"/>
<field name="recordId" type="any-reference" nullable="false" updatable="false" description="业务记录"/>
Expand All @@ -322,6 +323,7 @@
<field name="operationContent" type="text" updatable="false" description="操作内容"/>
<field name="state" type="small-int" default-value="1" description="状态"/>
</entity>
-->

<entity name="RebuildApi" type-code="030" description="API 密钥" queryable="false">
<field name="uniqueId" type="primary"/>
Expand Down
Loading

0 comments on commit ec222bc

Please sign in to comment.