负载均衡基本改造,增加redis、miniio等基本中间件

This commit is contained in:
2026-02-24 11:16:03 +08:00
parent 26677972a6
commit 8d711dc3a2
13 changed files with 317 additions and 63 deletions

View File

@@ -17,6 +17,7 @@ import tech.easyflow.ai.service.DocumentCollectionService;
import tech.easyflow.ai.service.DocumentService;
import tech.easyflow.ai.service.ModelService;
import tech.easyflow.common.annotation.UsePermission;
import tech.easyflow.common.cache.RedisLockExecutor;
import tech.easyflow.common.domain.Result;
import tech.easyflow.common.tree.Tree;
import tech.easyflow.common.util.RequestUtil;
@@ -29,6 +30,7 @@ import java.io.File;
import java.io.IOException;
import java.io.Serializable;
import java.math.BigInteger;
import java.time.Duration;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@@ -44,14 +46,21 @@ import java.util.List;
@UsePermission(moduleName = "/api/v1/documentCollection")
public class DocumentController extends BaseCurdController<DocumentService, Document> {
private static final String DOCUMENT_ORDER_LOCK_KEY_PREFIX = "easyflow:lock:document:order:";
private static final Duration LOCK_WAIT_TIMEOUT = Duration.ofSeconds(2);
private static final Duration LOCK_LEASE_TIMEOUT = Duration.ofSeconds(10);
private final DocumentCollectionService knowledgeService;
@Autowired
private DocumentService documentService;
@Autowired
private RedisLockExecutor redisLockExecutor;
@Value("${easyflow.storage.local.root}")
@Value("${easyflow.storage.local.root:}")
private String fileUploadPath;
@@ -132,6 +141,7 @@ public class DocumentController extends BaseCurdController<DocumentService, Docu
@PostMapping("update")
@Override
@Transactional
@SaCheckPermission("/api/v1/documentCollection/save")
public Result<Boolean> update(@JsonBody Document entity) {
super.update(entity);
@@ -158,28 +168,41 @@ public class DocumentController extends BaseCurdController<DocumentService, Docu
Integer orderNo = entity.getOrderNo();
if (orderNo != null) {
if (orderNo <= 0) orderNo = 0;
BigInteger knowledgeId = service.getById(entity.getId()).getCollectionId();
List<Document> list = service.list(QueryWrapper.create()
.eq(Document::getCollectionId, knowledgeId)
.orderBy(getDefaultOrderBy())
Document current = service.getById(entity.getId());
if (current == null) {
throw new BusinessException("文档不存在");
}
BigInteger knowledgeId = current.getCollectionId();
Integer targetOrderNo = orderNo;
redisLockExecutor.executeWithLock(
DOCUMENT_ORDER_LOCK_KEY_PREFIX + knowledgeId,
LOCK_WAIT_TIMEOUT,
LOCK_LEASE_TIMEOUT,
() -> {
List<Document> list = service.list(QueryWrapper.create()
.eq(Document::getCollectionId, knowledgeId)
.orderBy(getDefaultOrderBy())
);
list.removeIf(item -> item.getId().equals(entity.getId()));
if (targetOrderNo >= list.size()) {
list.add(entity);
} else {
list.add(targetOrderNo, entity);
}
List<Document> updateList = new ArrayList<>();
for (int i = 0; i < list.size(); i++) {
Document updateItem = new Document();
updateItem.setId(list.get(i).getId());
updateItem.setOrderNo(i);
updateList.add(updateItem);
}
service.updateBatch(updateList);
}
);
list.removeIf(item -> item.getId().equals(entity.getId()));
if (orderNo >= list.size()) {
list.add(entity);
} else {
list.add(orderNo, entity);
}
List<Document> updateList = new ArrayList<>();
for (int i = 0; i < list.size(); i++) {
Document updateItem = new Document();
updateItem.setId(list.get(i).getId());
updateItem.setOrderNo(i);
updateList.add(updateItem);
}
service.updateBatch(updateList);
}
return true;

View File

@@ -20,7 +20,7 @@ import java.nio.file.Files;
public class FilePreviewController {
// 定义图片存储的基础路径
@Value("${easyflow.storage.local.root}")
@Value("${easyflow.storage.local.root:}")
private String fileUploadPath;
@SaIgnore
@@ -70,4 +70,4 @@ public class FilePreviewController {
throw new RuntimeException(e);
}
}
}
}