Skip to content

Commit

Permalink
update starter/src: mod 3 del 1 files
Browse files Browse the repository at this point in the history
  • Loading branch information
pengjinning committed Feb 14, 2025
1 parent 4fc6b16 commit 200e679
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @Author: jackning 270580156@qq.com
* @Date: 2025-01-23 14:52:45
* @LastEditors: jackning 270580156@qq.com
* @LastEditTime: 2025-02-14 11:33:02
* @LastEditTime: 2025-02-14 12:34:14
* @Description: bytedesk.com https://github.com/Bytedesk/bytedesk
* Please be aware of the BSL license restrictions before installing Bytedesk IM –
* selling, reselling, or hosting Bytedesk IM as a service is a breach of the terms and automatically terminates your rights under the license.
Expand All @@ -20,9 +20,12 @@
import org.flowable.engine.RuntimeService;
import org.flowable.engine.runtime.ProcessInstance;
import org.springframework.context.event.EventListener;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import com.alibaba.fastjson2.JSON;
import com.bytedesk.core.rbac.organization.OrganizationCreateEvent;
import com.bytedesk.core.rbac.organization.OrganizationEntity;
import com.bytedesk.core.rbac.user.UserProtobuf;
import com.bytedesk.kbase.upload.UploadEntity;
import com.bytedesk.kbase.upload.UploadTypeEnum;
Expand All @@ -46,6 +49,18 @@ public class TicketEventListener {

private final TicketRestService ticketRestService;

@Order(5)
@EventListener
public void onOrganizationCreateEvent(OrganizationCreateEvent event) {
OrganizationEntity organization = (OrganizationEntity) event.getSource();
String orgUid = organization.getUid();
log.info("ticket - organization created: {}", orgUid);
// 为每个组织加载自己的流程文件
// 1. 查询流程文件
// 2. 加载流程文件
// 3. 部署流程
}

@EventListener
public void handleTicketCreateEvent(TicketCreateEvent event) {
log.info("TicketEventListener handleTicketCreateEvent: {}", event);
Expand Down
2 changes: 1 addition & 1 deletion starter/src/main/resources/templates/ftl/index.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ Listed course START -->
</div>
<!-- Title -->
<h5 class="mb-1"><a href="#" class="stretched-link">AI助手</a></h5>
<span class="mb-0">对接各种大模型,支持私有部署大模型,支持私有知识库问答.</span>
<span class="mb-0">对接Ollama/DeepSeek/智谱等大模型,支持私有部署/Api调用大模型.</span>
</div>
</div>

Expand Down
102 changes: 91 additions & 11 deletions starter/src/test/java/com/bytedesk/starter/FlowableTests.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/*
* @Author: jackning 270580156@qq.com
* @Date: 2025-02-02 11:21:45
* @LastEditors: jackning 270580156@qq.com
* @LastEditTime: 2025-02-14 12:06:33
* @LastEditors: jack ning github@bytedesk.com
* @LastEditTime: 2025-02-14 12:25:12
* @Description: bytedesk.com https://github.com/Bytedesk/bytedesk
* Please be aware of the BSL license restrictions before installing Bytedesk IM –
* selling, reselling, or hosting Bytedesk IM as a service is a breach of the terms and automatically terminates your rights under the license.
Expand All @@ -14,6 +14,7 @@
package com.bytedesk.starter;

import java.io.InputStream;
import java.net.URL;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -52,15 +53,38 @@ public class FlowableTests {
@Autowired
private HistoryService historyService;

/**
* 查询流程定义列表, 涉及到 act_re_procdef表,部署成功会新增记录
*/
// 查询全部流程定义列表, 涉及到 act_re_procdef表,部署成功会新增记录
@Test
public void testProcessDefinition() {
List<ProcessDefinition> processList = repositoryService.createProcessDefinitionQuery().list();
for (ProcessDefinition processDefinition : processList) {
log.info("ProcessDefinition name = {},deploymentId = {}", processDefinition.getName(),
processDefinition.getDeploymentId());
log.info("流程定义 name={}, key={}, version={}, deploymentId={}",
processDefinition.getName(),
processDefinition.getKey(),
processDefinition.getVersion(),
processDefinition.getDeploymentId());
}
}

/**
* 自定义过滤条件查询流程定义列表, 涉及到 act_re_procdef表,部署成功会新增记录
*/
@Test
public void testFilterProcessDefinition() {
List<ProcessDefinition> processList = repositoryService.createProcessDefinitionQuery()
.processDefinitionKey("StudentLeave") // 按流程定义key过滤
.processDefinitionName("请假流程") // 按流程定义名称过滤
.latestVersion() // 只查询最新版本
.active() // 查询激活的流程
.orderByProcessDefinitionVersion().desc() // 按版本降序排序
.list();

for (ProcessDefinition processDefinition : processList) {
log.info("流程定义 name={}, key={}, version={}, deploymentId={}",
processDefinition.getName(),
processDefinition.getKey(),
processDefinition.getVersion(),
processDefinition.getDeploymentId());
}
}

Expand All @@ -77,16 +101,16 @@ public void testAddProcessDefinition() {

// 通过上传文件部署流程
@Test
public void testAddProcessDefinitionByUploadFile() {
public void testAddProcessDefinitionByUploadFile() throws Exception {
// 上传文件
UploadEntity upload = UploadEntity.builder()
.fileName("请假流程")
.type(UploadTypeEnum.BPMN.name())
.fileUrl("")
.fileUrl("https://example.com/processes/StudentLeave.bpmn20.xml")
.build();

// 将文件URL转换为InputStream
InputStream inputStream = getClass().getResourceAsStream("/processes/StudentLeave.bpmn20.xml");
// 从URL获取InputStream
InputStream inputStream = new URL(upload.getFileUrl()).openStream();

// 部署流程
Deployment deployment = repositoryService.createDeployment()
Expand Down Expand Up @@ -133,4 +157,60 @@ public void testStudentLeaveFlow() {
System.out.println(activity.getActivityName());
}
}

// 按租户ID查询流程定义列表
@Test
public void testProcessDefinitionByTenant() {
String orgUid = "df_org_uid";
List<ProcessDefinition> processList = repositoryService.createProcessDefinitionQuery()
.processDefinitionTenantId(orgUid) // 按租户ID过滤
.latestVersion() // 只查询最新版本
.active() // 查询激活的流程
.orderByProcessDefinitionVersion().desc() // 按版本降序排序
.list();

for (ProcessDefinition processDefinition : processList) {
log.info("租户流程定义 tenantId={}, name={}, key={}, version={}",
processDefinition.getTenantId(),
processDefinition.getName(),
processDefinition.getKey(),
processDefinition.getVersion());
}
}

// 部署带租户ID的流程定义
@Test
public void testAddProcessDefinitionWithTenant() {
String orgUid = "df_org_uid";
// 部署流程
Deployment deployment = repositoryService.createDeployment()
.name("请假流程")
.addClasspathResource("processes/StudentLeave.bpmn20.xml")
.tenantId(orgUid) // 设置租户ID
.deploy();
log.info("部署租户流程成功: deploymentId={}, tenantId={}", deployment.getId(), deployment.getTenantId());
}

// 通过上传文件部署带租户ID的流程
@Test
public void testAddProcessDefinitionByUploadFileWithTenant() throws Exception {
String orgUid = "df_org_uid";
// 上传文件
UploadEntity upload = UploadEntity.builder()
.fileName("请假流程")
.type(UploadTypeEnum.BPMN.name())
.fileUrl("https://example.com/processes/StudentLeave.bpmn20.xml")
.build();

// 从URL获取InputStream
InputStream inputStream = new URL(upload.getFileUrl()).openStream();

// 部署流程
Deployment deployment = repositoryService.createDeployment()
.name(upload.getFileName())
.addInputStream(upload.getFileName(), inputStream)
.tenantId(orgUid) // 设置租户ID
.deploy();
log.info("部署租户流程成功: deploymentId={}, tenantId={}", deployment.getId(), deployment.getTenantId());
}
}

0 comments on commit 200e679

Please sign in to comment.