更新jdk17

This commit is contained in:
guoshengxiong 2025-08-19 16:15:06 +08:00
parent d01f5cd1ec
commit 5797e54a2b
11 changed files with 109 additions and 84 deletions

77
pom.xml
View File

@ -3,82 +3,96 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>wflow-server</artifactId>
<version>1.0-SNAPSHOT</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.3.RELEASE</version>
<version>3.5.4</version>
<relativePath/>
</parent>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<java.version>1.8</java.version>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<java.version>17</java.version>
<skipTests>true</skipTests>
<!--项目编码-->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<flowable.version>6.7.2</flowable.version>
</properties>
<dependencies>
<dependency>
<groupId>org.graalvm.js</groupId>
<artifactId>js</artifactId>
<version>23.0.0</version> </dependency>
<dependency>
<groupId>org.graalvm.js</groupId>
<artifactId>js-scriptengine</artifactId>
<version>23.0.0</version> </dependency>
<dependency>
<groupId>jakarta.annotation</groupId>
<artifactId>jakarta.annotation-api</artifactId>
<version>2.1.1</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.20</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.alibaba.fastjson2/fastjson2 -->
<dependency>
<groupId>com.alibaba.fastjson2</groupId>
<artifactId>fastjson2</artifactId>
<version>2.0.40</version>
<version>2.0.42</version>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.4.2</version>
<version>3.5.3.2</version>
</dependency>
<!-- MySQL 连接驱动依赖 -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.49</version>
</dependency>
<!-- Sa-Token 权限认证, 在线文档http://sa-token.dev33.cn/ -->
<dependency>
<groupId>cn.dev33</groupId>
<artifactId>sa-token-spring-boot-starter</artifactId>
<version>1.30.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- spring mail -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
</dependency>
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.8.16</version>
</dependency>
<dependency>
<groupId>com.belerweb</groupId>
<artifactId>pinyin4j</artifactId>
@ -90,7 +104,7 @@
<artifactId>spring-file-storage</artifactId>
<version>0.5.0</version>
</dependency>
<dependency>
<groupId>org.flowable</groupId>
<artifactId>flowable-spring-boot-starter-actuator</artifactId>
@ -102,35 +116,35 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.googlecode.aviator</groupId>
<artifactId>aviator</artifactId>
<version>5.3.1</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
</dependency>
<!--js沙箱环境资源保护-->
<dependency>
<groupId>org.javadelight</groupId>
<artifactId>delight-nashorn-sandbox</artifactId>
<version>0.3.2</version>
</dependency>
<!-- <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
@ -149,7 +163,7 @@
<version>2.11.4</version>
</dependency>
</dependencies>
<build>
<!--<plugins>
<plugin>
@ -164,9 +178,14 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.11.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<source>17</source>
<target>17</target>
<!-- 如果使用模块化 -->
<compilerArgs>
<arg>--enable-preview</arg>
</compilerArgs>
</configuration>
</plugin>
</plugins>

View File

@ -6,8 +6,8 @@ import com.wflow.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.io.IOException;
/**

View File

@ -2,8 +2,9 @@ package com.wflow.service;
import com.wflow.bean.vo.UserLoginVo;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.io.IOException;
/**

View File

@ -14,8 +14,8 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.io.IOException;
/**

View File

@ -62,9 +62,9 @@ public class SubModelGroupServiceImpl implements SubModelGroupService {
@Override
public void addGroup(String name) {
Integer count = subGroupsMapper.selectCount(
Integer count = Math.toIntExact(subGroupsMapper.selectCount(
new LambdaQueryWrapper<WflowSubGroups>()
.eq(WflowSubGroups::getGroupName, name));
.eq(WflowSubGroups::getGroupName, name)));
if (count > 0) {
throw new BusinessException("分组名称不能重复");
}
@ -78,9 +78,9 @@ public class SubModelGroupServiceImpl implements SubModelGroupService {
if (id.equals(0) || id.equals(1)){
throw new BusinessException("不允许删除系统内置分组");
}
Integer count = subProcessMapper.selectCount(
Integer count = Math.toIntExact(subProcessMapper.selectCount(
new LambdaQueryWrapper<WflowSubProcess>()
.eq(WflowSubProcess::getGroupId, id));
.eq(WflowSubProcess::getGroupId, id)));
if (count > 0) {
throw new BusinessException("请先删除分组内的流程");
}

View File

@ -7,8 +7,8 @@ import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.stereotype.Component;
import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;
import jakarta.mail.MessagingException;
import jakarta.mail.internet.MimeMessage;
/**
* @author : willian fu

View File

@ -6,7 +6,7 @@ import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletRequest;
import java.util.Optional;
/**

View File

@ -1,14 +1,10 @@
package com.wflow.workflow.execute;
import cn.hutool.http.HttpRequest;
import com.wflow.exception.BusinessException;
import delight.nashornsandbox.NashornSandbox;
import delight.nashornsandbox.NashornSandboxes;
import jdk.nashorn.api.scripting.ScriptObjectMirror;
import lombok.extern.slf4j.Slf4j;
import org.graalvm.polyglot.Context;
import org.graalvm.polyglot.HostAccess;
import org.graalvm.polyglot.Value;
import javax.script.Invocable;
import javax.script.ScriptException;
import java.util.Objects;
import java.util.concurrent.ExecutorService;
@ -19,49 +15,58 @@ import java.util.concurrent.ExecutorService;
@Slf4j
public class JsExecute {
//创建执行沙箱环境
private static NashornSandbox sandbox;
//TODO 这里配置允许暴露给的java类可以在js里面直接调用
private static final Class[] alowJsCallJavaClass = new Class[]{
HttpRequest.class, System.class
//HttpRequest.class, System.class
// GraalVM的HostAccess默认允许访问一些常见的类例如System
// 如果你需要访问自定义的类你需要在这里配置
};
private static Context context;
// 使用 Context.Builder 来创建和配置沙箱环境
public JsExecute(ExecutorService executorService) {
if (Objects.isNull(sandbox)) {
sandbox = NashornSandboxes.create();
//沙箱资源限制
sandbox.setMaxCPUTime(20000);
sandbox.setMaxMemory(10 * 1024 * 1024);
sandbox.allowNoBraces(false);
sandbox.setMaxPreparedStatements(30);
sandbox.setExecutor(executorService);
sandbox.allowGlobalsObjects(true);
sandbox.allowPrintFunctions(true);
sandbox.disallowAllClasses();
//这里配置允许暴露的java类可以在js里面直接调用
for (Class clazz : alowJsCallJavaClass) {
sandbox.allow(clazz);
}
if (Objects.isNull(context)) {
// 使用 Context.Builder 来创建和配置 GraalVM 沙箱
context = Context.newBuilder("js")
.allowHostAccess(HostAccess.ALL) // 允许访问所有Java对象
// 如果只想允许特定类可以使用HostAccess.newBuilder()
.allowHostClassLookup(s -> true) // 允许查找所有Java类
// 如果只想允许特定类可以配置如下
// .allowHostClassLookup(className -> {
// return className.equals("com.yourpackage.HttpRequest") || className.equals("java.lang.System");
// })
.allowAllAccess(true) // 允许所有访问包括I/O线程等
.option("engine.WarnInterpreterOnly", "false") // 忽略解释器模式警告
.build();
// GraalVM的资源限制配置有所不同通常是在创建context时设置或者通过线程池等外部方式管理
// 例如CPU时间限制等需要通过更复杂的机制实现Context.Builder不直接支持MaxCPUTime等
// 内存限制通常通过JVM的-Xmx参数来控制
// 你可以继续使用你传入的ExecutorService来控制并发
}
}
public <T> T execute(String func, String script, Class<T> resultType, Object... args) {
Invocable invocable = sandbox.getSandboxedInvocable();
try {
sandbox.eval(script);
Object result = invocable.invokeFunction(func, args);
log.debug("资源服务执行js解码结果[{}]", result);
if (result instanceof ScriptObjectMirror) {
//返回的是js对象 = Map<String, Object>
return ((ScriptObjectMirror) result).to(resultType);
} else {
//返回普通类型数据
return resultType.cast(result);
// 注意GraalVM Context.eval() 有两种重载
// 一种是直接执行另一种是带源文件名的这里简化使用
context.eval("js", script);
// 获取 JavaScript 函数
Value function = context.getBindings("js").getMember(func);
if (function == null || !function.canExecute()) {
throw new NoSuchMethodException("Function " + func + " not found or not executable.");
}
} catch (ScriptException | NoSuchMethodException e) {
// 执行函数并获取结果
Value result = function.execute(args);
// 使用 Value.as() 方法进行类型转换这是 GraalVM 推荐的方式
return result.as(resultType);
} catch (Exception e) {
log.error("js 函数[{}] [{}]执行异常: [{}]", func, script, e.getMessage());
throw new BusinessException("js函数解析执行异常:" + e.getMessage());
throw new RuntimeException("js函数解析执行异常:" + e.getMessage(), e);
}
}

View File

@ -8,11 +8,11 @@ import com.wflow.bean.vo.DeptVo;
import com.wflow.service.OrgRepositoryService;
import com.wflow.service.OrgUserAndDeptService;
import com.wflow.workflow.service.OrgOwnershipService;
import jakarta.annotation.PostConstruct;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.PostConstruct;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;

View File

@ -600,7 +600,7 @@ public class ProcessInstanceServiceImpl implements ProcessInstanceService {
@Override
public InstanceCountVo getProcessInstanceCount() {
String userId = UserUtil.getLoginUserId();
Integer cc = ccTasksMapper.selectCount(new LambdaQueryWrapper<WflowCcTasks>().eq(WflowCcTasks::getUserId, userId));
Integer cc = Math.toIntExact(ccTasksMapper.selectCount(new LambdaQueryWrapper<WflowCcTasks>().eq(WflowCcTasks::getUserId, userId)));
Long todo = taskService.createTaskQuery().taskCandidateOrAssigned(userId).count();
Long mySubmited = historyService.createHistoricProcessInstanceQuery().startedBy(userId).unfinished().count();
return InstanceCountVo.builder().todo(todo).mySubmited(mySubmited).cc(cc.intValue()).build();

View File

@ -15,7 +15,7 @@ import org.flowable.engine.RuntimeService;
import org.flowable.engine.delegate.DelegateExecution;
import org.flowable.engine.delegate.JavaDelegate;
import javax.mail.MessagingException;
import jakarta.mail.MessagingException;
import java.util.List;
import java.util.Map;
import java.util.Optional;