fix(workflow): 修复驳回无法退回发起人

- 新增发起申请节点
- 发起表单改挂该节点
- 首次发起跳过发起人
- 驳回目标包含发起人
- 审批接口新增表单数据入参
- 新增表单数据更新逻辑
- 模型模板加入发起人节点
- AI 与流程引擎默认值移入公共配置
This commit is contained in:
Ray.Hao committed 2026-11-02 07:38:24 +08:00
1 parent e77d0b1f4f
commit 538153a4f0
74 files changed
+1582 -1183

No files matched your search

@@ -20,24 +20,27 @@ import org.springframework.validation.annotation.Validated;
@ConfigurationProperties(prefix = "security.oidc")
public class OidcProperties {
/** 是否启用 OIDC 统一认证;启用后必须配置认证中心、客户端凭据和回跳地址 */
private boolean enabled = false;
// 身份表中的稳定标识;更换认证中心时使用新值或迁移关联
/** 身份关联使用的稳定标识;更换认证中心时使用新值或迁移已有关联 */
@NotBlank
@Pattern(regexp = "[a-z][a-z0-9-]{0,63}")
private String provider = "oidc-main";
// 必须与认证中心公布的 issuer 完全一致
/** 认证中心地址,必须与其公布的 issuer 完全一致 */
@NotBlank
private String issuer;
/** 认证中心注册的客户端 ID,启用时必填 */
@NotBlank
private String clientId;
/** 客户端密钥,启用时必填;当前使用 client_secret_basic 认证 */
@NotBlank
private String clientSecret;
// 认证成功后的前端回调地址
/** 认证成功后的前端回跳地址,启用时必填 */
@NotBlank
private String frontendCallbackUri;
}
@@ -5,7 +5,7 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
/**
* 验证码配置属性
* 验证码配置属性;默认使用圆圈干扰的算术验证码,可按需覆盖
*
* @author Ray.Hao
* @since 2023/11/24
@@ -15,38 +15,38 @@ import org.springframework.stereotype.Component;
@Data
public class CaptchaProperties {
// 验证码类型 circle-圆圈干扰验证码|gif-Gif验证码|line-干扰线验证码|shear-扭曲干扰验证码
private String type;
/** 验证码类型 circle-圆圈干扰验证码|gif-Gif验证码|line-干扰线验证码|shear-扭曲干扰验证码 */
private String type = "circle";
// 验证码图片宽度
private int width;
// 验证码图片高度
private int height;
/** 验证码图片宽度 */
private int width = 120;
/** 验证码图片高度 */
private int height = 40;
// 干扰线数量
private int interfereCount;
/** 干扰线数量 */
private int interfereCount = 2;
// 文本透明度
private Float textAlpha;
/** 文本透明度 */
private Float textAlpha = 0.8F;
// 验证码过期时间,单位:秒
private Long expireSeconds;
/** 验证码过期时间,单位:秒 */
private Long expireSeconds = 120L;
// 验证码字符配置
private CodeProperties code;
/** 验证码字符配置 */
private CodeProperties code = new CodeProperties();
// 验证码字体
private FontProperties font;
/** 验证码字体 */
private FontProperties font = new FontProperties();
/**
* 验证码字符配置
*/
@Data
public static class CodeProperties {
// 验证码字符类型 math-算术|random-随机字符串
private String type;
// 验证码字符长度,type=算术时,表示运算位数(1:个位数 2:十位数);type=随机字符时,表示字符个数
private int length;
/** 验证码字符类型 math-算术|random-随机字符串 */
private String type = "math";
/** 验证码字符长度,type=算术时,表示运算位数(1:个位数 2:十位数);type=随机字符时,表示字符个数 */
private int length = 1;
}
/**
@@ -54,12 +54,12 @@ public class CaptchaProperties {
*/
@Data
public static class FontProperties {
// 字体名称
private String name;
// 字体样式 0-普通|1-粗体|2-斜体
private int weight;
// 字体大小
private int size;
/** 字体名称 */
private String name = "SansSerif";
/** 字体样式 0-普通|1-粗体|2-斜体 */
private int weight = 1;
/** 字体大小 */
private int size = 24;
}
@@ -4,7 +4,7 @@ import com.youlai.boot.common.result.ResultCode;
import lombok.Getter;
/**
* 图形验证码校验失败时抛出的异常。
* 图形验证码校验失败时抛出的异常
*
* @author Ray.Hao
* @since 3.1.0
@@ -8,7 +8,7 @@ import java.io.Serial;
import java.util.Collection;
/**
* 短信验证码认证 Token。
* 短信验证码认证 Token
*
* @author Ray.Hao
* @since 2.20.0
@@ -26,9 +26,9 @@ public class WxMaProperties {
@Pattern(regexp = "[a-z][a-z0-9-]{0,63}")
private String provider = "wechat-mini-main";
// 小程序 appid
/** 小程序 appid */
private String appid;
// 小程序 appsecret
/** 小程序 appsecret */
private String secret;
}
@@ -8,7 +8,7 @@ import java.io.Serial;
import java.util.Collection;
/**
* 微信小程序认证 Token。
* 微信小程序认证 Token
*
* @author Ray.Hao
* @since 4.0.0
@@ -23,7 +23,8 @@ public enum JavaTypeEnum {
TINYINT("tinyint", "Integer", "number"),
SMALLINT("smallint", "Integer", "number"),
MEDIUMINT("mediumint", "Integer", "number"),
BIGINT("bigint", "Long", "number"),
// Long 与 BigInteger 由 Jackson 全局配置序列化为字符串,前端类型保持一致
BIGINT("bigint", "Long", "string"),
FLOAT("float", "Float", "number"),
DOUBLE("double", "Double", "number"),
DECIMAL("decimal", "BigDecimal", "number"),
@@ -21,22 +21,22 @@ import java.util.Map;
public class CodegenProperties {
// 默认配置
/** 默认配置 */
private DefaultConfig defaultConfig ;
// 模板配置
/** 模板配置 */
private Map<String, TemplateConfig> templateConfigs = MapUtil.newHashMap(true);
// 后端应用名
/** 后端应用名 */
private String backendAppName;
// 前端应用名
/** 前端应用名 */
private String frontendAppName;
// 下载文件名
/** 下载文件名 */
private String downloadFileName;
// 排除数据表
/** 排除数据表 */
private List<String> excludeTables;
/**
@@ -45,13 +45,13 @@ public class CodegenProperties {
@Data
public static class TemplateConfig {
// 模板路径,相对模板根 classpath:codegen (e.g. backend/controller.java.vm)
/** 模板路径,相对模板根 classpath:codegen (e.g. backend/controller.java.vm) */
private String templatePath;
// 子包名 (e.g. controller/service/mapper/model)
/** 子包名 (e.g. controller/service/mapper/model) */
private String subpackageName;
// 文件扩展名,如 .java
/** 文件扩展名,如 .java */
private String extension = FileNameUtil.EXT_JAVA;
}
@@ -62,10 +62,10 @@ public class CodegenProperties {
@Data
public static class DefaultConfig {
// 作者 (e.g. Ray)
/** 作者 (e.g. Ray) */
private String author;
// 默认模块名(e.g. system)
/** 默认模块名(e.g. system) */
private String moduleName;
}
@@ -19,7 +19,7 @@ import java.lang.annotation.*;
public @interface ValidField {
/**
* 验证失败时的错误信息。
* 验证失败时的错误信息
*/
String message() default "非法字段";
@@ -28,7 +28,7 @@ public @interface ValidField {
Class<? extends Payload>[] payload() default {};
/**
* 允许的合法值列表。
* 允许的合法值列表
*/
String[] allowedValues();
@@ -4,7 +4,7 @@ import com.youlai.boot.common.result.ResultCode;
import lombok.Getter;
/**
* 接口限流异常:请求超出限流阈值时抛出,由全局异常处理器统一映射为 HTTP 429。
* 接口限流异常:请求超出限流阈值时抛出,由全局异常处理器统一映射为 HTTP 429
*
* @author Ray.Hao
* @since 4.4.0
@@ -23,7 +23,7 @@ public class PageResult<T> implements Serializable {
private PageData<T> data;
/**
* 构建分页结果(MyBatis-Plus {@link IPage})。
* 构建分页结果(MyBatis-Plus {@link IPage})
*/
public static <T> PageResult<T> success(IPage<T> page) {
PageResult<T> result = new PageResult<>();
@@ -43,7 +43,7 @@ public class PageResult<T> implements Serializable {
}
/**
* 构建列表结果(无分页)。
* 构建列表结果(无分页)
*/
public static <T> PageResult<T> success(List<T> list) {
PageResult<T> result = new PageResult<>();
@@ -0,0 +1,13 @@
package com.youlai.boot.config;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Configuration;
/**
* 启用缓存注解,由 Spring Boot 根据 spring.cache.type 选择唯一的缓存管理器
* none 使用空操作管理器,不缓存结果,也不影响登录会话等直接使用 Redis 的功能
*/
@EnableCaching
@Configuration(proxyBeanMethods = false)
public class CacheConfig {
}
@@ -1,37 +0,0 @@
package com.youlai.boot.config;
import com.github.benmanes.caffeine.cache.Caffeine;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cache.CacheManager;
import org.springframework.cache.caffeine.CaffeineCacheManager;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* caffeine缓存配置
*
* @author Theo
* @since 2025-01-22 17:40:23
*/
@Slf4j
@Configuration
public class CaffeineConfig {
@Value("${spring.cache.caffeine.spec}")
private String caffeineSpec;
/**
* 缓存管理器
*
* @return CacheManager 缓存管理器
*/
@Bean
public CacheManager cacheManager() {
CaffeineCacheManager caffeineCacheManager = new CaffeineCacheManager();
Caffeine<Object, Object> caffeineBuilder = Caffeine.from(caffeineSpec);
caffeineCacheManager.setCaffeine(caffeineBuilder);
return caffeineCacheManager;
}
}
@@ -3,42 +3,23 @@ package com.youlai.boot.config;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.cache.autoconfigure.CacheProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.cache.RedisCacheConfiguration;
import org.springframework.data.redis.cache.RedisCacheManager;
import org.springframework.data.redis.cache.RedisCacheWriter;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.serializer.RedisSerializationContext;
import org.springframework.data.redis.serializer.RedisSerializer;
/**
* Redis 缓存配置
* Redis 缓存的序列化与过期策略,缓存管理器由 Spring Boot 自动装配
*
* @author Ray.Hao
* @since 2023/12/4
*/
@EnableCaching
@EnableConfigurationProperties(CacheProperties.class)
@Configuration
@ConditionalOnProperty(name = "spring.cache.enabled") // 未配置视为关闭
@Configuration(proxyBeanMethods = false)
@ConditionalOnProperty(prefix = "spring.cache", name = "type", havingValue = "redis")
public class RedisCacheConfig {
/**
* 自定义 RedisCacheManager
*
* @param redisConnectionFactory {@link RedisConnectionFactory}
* @param cacheProperties {@link CacheProperties}
* @return {@link RedisCacheManager}
*/
@Bean
public RedisCacheManager redisCacheManager(RedisConnectionFactory redisConnectionFactory, CacheProperties cacheProperties){
return RedisCacheManager.builder(RedisCacheWriter.nonLockingRedisCacheWriter(redisConnectionFactory))
.cacheDefaults(redisCacheConfiguration(cacheProperties))
.build();
}
/**
* 自定义 RedisCacheConfiguration
*
@@ -61,11 +42,12 @@ public class RedisCacheConfig {
if (!redisProperties.isCacheNullValues()) {
config = config.disableCachingNullValues();
}
// 保留现有 cacheName: 前缀格式,并支持 spring.cache.redis.key-prefix
String keyPrefix = redisProperties.getKeyPrefix();
config = config.computePrefixWith(name -> (keyPrefix != null ? keyPrefix : "") + name + ":");
if (!redisProperties.isUseKeyPrefix()) {
config = config.disableKeyPrefix();
}
// 覆盖默认key双冒号 CacheKeyPrefix#prefixed
config = config.computePrefixWith(name -> name + ":");
return config;
}
@@ -36,7 +36,6 @@ import org.springframework.security.web.SecurityFilterChain;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
import jakarta.servlet.DispatcherType;
import org.springframework.http.HttpMethod;
/**
* Spring Security 配置类
@@ -63,8 +62,6 @@ public class SecurityConfig {
.authorizeHttpRequests(requestMatcherRegistry -> {
// 异步响应的后续分发复用首次请求认证结果
requestMatcherRegistry.dispatcherTypeMatchers(DispatcherType.ASYNC).permitAll();
// 握手使用一次性票据;其余实时接口仍需 Bearer 认证
requestMatcherRegistry.requestMatchers(HttpMethod.GET, "/api/v1/realtime/ws").permitAll();
String[] permitAllUrls = securityProperties.getPermitAllUrls();
if (ArrayUtil.isNotEmpty(permitAllUrls)) {
requestMatcherRegistry.requestMatchers(permitAllUrls).permitAll();
@@ -8,11 +8,12 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* XXL-JOB 执行器配置;地址和 IP 默认自动获取,端口和日志策略可按需覆盖
*
* @author xuxueli 2017-04-28
*/
@Configuration
@ConditionalOnProperty(name = "xxl.job.enabled") // xxl.job.enabled = true 才会自动装配
@ConditionalOnProperty(name = "xxl.job.enabled", havingValue = "true")
@Slf4j
public class XxlJobConfig {
@@ -25,19 +26,19 @@ public class XxlJobConfig {
@Value("${xxl.job.executor.appname}")
private String appname;
@Value("${xxl.job.executor.address}")
@Value("${xxl.job.executor.address:}")
private String address;
@Value("${xxl.job.executor.ip}")
@Value("${xxl.job.executor.ip:}")
private String ip;
@Value("${xxl.job.executor.port}")
@Value("${xxl.job.executor.port:9999}")
private int port;
@Value("${xxl.job.executor.logpath}")
@Value("${xxl.job.executor.logpath:/data/applogs/xxl-job/jobhandler}")
private String logPath;
@Value("${xxl.job.executor.logretentiondays}")
@Value("${xxl.job.executor.logretentiondays:30}")
private int logRetentionDays;
@@ -25,11 +25,12 @@ import java.time.Duration;
@ConfigurationProperties(prefix = "security")
public class SecurityProperties {
/** 访问令牌格式与登录会话配置 */
@Valid
@NotNull
private TokenConfig token = new TokenConfig();
// 匿名路径仍经过安全过滤器链
/** 免登录路径,仍经过安全过滤器链 */
@NotEmpty
private String[] permitAllUrls;
@@ -39,18 +40,23 @@ public class SecurityProperties {
@Data
public static class TokenConfig {
/** 访问令牌格式:jwt 或 redis-token,两种格式共用 Redis 登录会话 */
@NotNull
@Pattern(regexp = "jwt|redis-token", message = "令牌类型只能是 jwt 或 redis-token")
private String type = "jwt";
/** 访问令牌有效期,须为正整数秒且不超过会话最长有效期,如 2h */
@NotNull
private Duration accessTokenTimeToLive = Duration.ofHours(2);
/** 登录会话最长有效期,刷新令牌不延长该期限,如 7d */
@NotNull
private Duration refreshTokenTimeToLive = Duration.ofDays(7);
/** 是否允许多设备同时登录,false 时新登录会撤销已有会话 */
private boolean allowMultiLogin = true;
/** JWT 签名配置,仅 jwt 模式需要 */
private JwtConfig jwt;
/**
@@ -79,6 +85,7 @@ public class SecurityProperties {
*/
@Data
public static class JwtConfig {
/** JWT 签名密钥,jwt 模式必填,至少 32 字节 UTF-8 */
private String secretKey;
}
}
@@ -3,14 +3,14 @@ package com.youlai.boot.framework.security.port;
import java.util.Set;
/**
* 权限查询端口。
* 权限查询端口
*
* @see com.youlai.boot.system.adapter.security.PermissionAdapter
*/
public interface PermissionPort {
/**
* 根据角色编码集合查询权限标识集合。
* 根据角色编码集合查询权限标识集合
*
* @param roleCodes 角色编码集合
* @return 权限标识集合,如 "sys:user:create"
@@ -12,7 +12,7 @@ import org.springframework.util.PatternMatchUtils;
import java.util.Set;
/**
* Spring Security 权限校验组件。
* Spring Security 权限校验组件
*
* @author Ray.Hao
* @since 0.0.1
@@ -25,7 +25,7 @@ public class PermissionService {
private final PermissionPort permissionPort;
/**
* 判断当前用户是否拥有操作权限,支持通配符匹配。
* 判断当前用户是否拥有操作权限,支持通配符匹配
*/
public boolean hasPerm(String requiredPerm) {
if (StrUtil.isBlank(requiredPerm)) {
@@ -11,7 +11,7 @@ import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;
/**
* 系统用户认证 DetailsService。
* 系统用户认证 DetailsService
*
* @author Ray.Hao
* @since 2021/10/19
@@ -70,8 +70,8 @@ public class IpRateLimitFilter extends OncePerRequestFilter {
}
/**
* 设置渐进式限流响应头(X-RateLimit-Limit / Remaining / Reset)。
* 超限时额外返回 Retry-After。
* 设置渐进式限流响应头(X-RateLimit-Limit / Remaining / Reset)
* 超限时额外返回 Retry-After
*/
private void setRateLimitHeaders(HttpServletResponse response,
int limit,
@@ -1,4 +1,4 @@
package com.youlai.boot.config;
package com.youlai.boot.framework.web.log;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -18,12 +18,12 @@ import java.lang.annotation.Target;
public @interface RateLimit {
/**
* 窗口内允许的最大请求数。
* 窗口内允许的最大请求数
*/
int limit() default 0;
/**
* 滑动窗口大小(秒)。
* 滑动窗口大小(秒)
*/
int window() default 0;
}
@@ -17,25 +17,25 @@ import java.time.Duration;
@ConfigurationProperties(prefix = "rate-limit")
public class RateLimitProperties {
// /
/** 接口限流注解未指定 limit 时,窗口内允许的最大请求数 */
private int defaultLimit = 5;
// /
/** 接口限流注解未指定 window 时使用的滑动窗口时长 */
private Duration defaultWindow = Duration.ofSeconds(60);
// IP 全局限流配置
/** IP 全局限流配置 */
private Ip ip = new Ip();
@Data
public static class Ip {
// 是否启用 IP 全局限流。
/** 是否启用 IP 全局限流 */
private boolean enabled = true;
// 窗口内最大请求数(默认 1000)
/** 窗口内最大请求数(默认 1000) */
private int limit = 1000;
// 滑动窗口大小,支持 60s / 1m / 500ms 等 Duration 写法(默认 60s)
/** 滑动窗口大小,支持 60s / 1m / 500ms 等 Duration 写法(默认 60s) */
private Duration window = Duration.ofSeconds(60);
}
@@ -60,6 +60,14 @@ public interface FormDataService {
*/
FormDataVO getFormDataDetail(Long dataId);
/**
* 更新已提交的表单数据(发起人节点重新提交)
*
* @param dataId 数据ID
* @param data 表单数据(field -> value 映射)
*/
void updateFormData(Long dataId, Map<String, Object> data);
/**
* 按表单标识删除全部提交数据(演示数据重置用)
*
@@ -206,6 +206,22 @@ public class FormDataServiceImpl extends ServiceImpl<FormDataMapper, FormData> i
this.removeByIds(ids);
}
/**
* 更新已提交的表单数据(发起人节点重新提交)
*
* @param dataId 数据ID
* @param data 表单数据(field -> value 映射)
*/
@Override
public void updateFormData(Long dataId, Map<String, Object> data) {
FormData entity = this.getById(dataId);
if (entity == null) {
throw new BusinessException("表单数据不存在");
}
entity.setDataJson(JSONUtil.toJsonStr(data));
this.updateById(entity);
}
/**
* 按表单标识删除全部提交数据(演示数据重置用)
*
@@ -17,6 +17,6 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnBooleanProp
@Target({ElementType.TYPE, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@ConditionalOnBooleanProperty(prefix = "workflow", name = "enabled")
@ConditionalOnBooleanProperty(prefix = "flowable.process", name = "enabled")
public @interface ConditionalOnWorkflowEnabled {
}
@@ -23,4 +23,7 @@ public class CompleteTaskForm {
@Schema(description = "流程变量(驱动后续网关条件)")
private Map<String, Object> variables;
@Schema(description = "发起表单数据(发起人节点重新提交时填写)")
private Map<String, Object> formData;
}
@@ -1,30 +0,0 @@
package com.youlai.boot.module.workflow.runner;
import com.youlai.boot.module.workflow.service.WorkflowDemoService;
import com.youlai.boot.module.workflow.config.ConditionalOnWorkflowEnabled;
import lombok.RequiredArgsConstructor;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Component;
/**
* 演示流程启动初始化器
*
* @author Ray.Hao
* @since 4.9.0
*/
@ConditionalOnWorkflowEnabled
@Component
@ConditionalOnProperty(name = "workflow.demo.enabled", havingValue = "true")
@RequiredArgsConstructor
public class WorkflowDemoInitializer implements ApplicationRunner {
private final WorkflowDemoService workflowDemoService;
@Override
public void run(ApplicationArguments args) {
workflowDemoService.initIfAbsent();
}
}
@@ -71,6 +71,10 @@ public class WorkflowInstanceServiceImpl implements WorkflowInstanceService {
Assert.isTrue(!definition.isSuspended(), "流程定义已挂起,无法发起");
Map<String, Object> variables = new HashMap<>();
// 发起人节点按发起人办理;首次发起用跳过表达式直达审批,驳回时才停在发起人
variables.put("initiator", SecurityUtils.getUsername());
variables.put("_FLOWABLE_SKIP_EXPRESSION_ENABLED", true);
variables.put("_SKIP_INITIATOR", true);
String businessKey = null;
String formKey = bpmnModelHelper.getStartFormKey(definition.getId());
if (StrUtil.isNotBlank(formKey)) {
@@ -97,6 +101,8 @@ public class WorkflowInstanceServiceImpl implements WorkflowInstanceService {
.name(instanceName)
.variables(variables)
.start();
// 首轮已跳过发起人,关闭跳过标记,后续驳回到发起人才会生成待办
runtimeService.setVariable(instance.getId(), "_SKIP_INITIATOR", false);
return instance.getId();
} finally {
Authentication.setAuthenticatedUserId(null);
@@ -71,14 +71,20 @@ public class WorkflowModelServiceImpl implements WorkflowModelService {
<bpmn:startEvent id="startEvent" name="开始">
<bpmn:outgoing>flow1</bpmn:outgoing>
</bpmn:startEvent>
<bpmn:userTask id="activity1" name="审批">
<bpmn:userTask id="initiator" name="发起申请" flowable:assignee="${initiator}"
flowable:skipExpression="${_SKIP_INITIATOR == true}">
<bpmn:incoming>flow1</bpmn:incoming>
<bpmn:outgoing>flowInitiator</bpmn:outgoing>
</bpmn:userTask>
<bpmn:userTask id="activity1" name="审批">
<bpmn:incoming>flowInitiator</bpmn:incoming>
<bpmn:outgoing>flow2</bpmn:outgoing>
</bpmn:userTask>
<bpmn:endEvent id="endEvent" name="结束">
<bpmn:incoming>flow2</bpmn:incoming>
</bpmn:endEvent>
<bpmn:sequenceFlow id="flow1" sourceRef="startEvent" targetRef="activity1"/>
<bpmn:sequenceFlow id="flow1" sourceRef="startEvent" targetRef="initiator"/>
<bpmn:sequenceFlow id="flowInitiator" sourceRef="initiator" targetRef="activity1"/>
<bpmn:sequenceFlow id="flow2" sourceRef="activity1" targetRef="endEvent"/>
</bpmn:process>
<bpmndi:BPMNDiagram id="BPMNDiagram_%1$s">
@@ -86,19 +92,26 @@ public class WorkflowModelServiceImpl implements WorkflowModelService {
<bpmndi:BPMNShape id="startEvent_di" bpmnElement="startEvent">
<dc:Bounds x="152" y="102" width="36" height="36"/>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="activity1_di" bpmnElement="activity1">
<bpmndi:BPMNShape id="initiator_di" bpmnElement="initiator">
<dc:Bounds x="240" y="80" width="100" height="80"/>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="activity1_di" bpmnElement="activity1">
<dc:Bounds x="350" y="80" width="100" height="80"/>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="endEvent_di" bpmnElement="endEvent">
<dc:Bounds x="392" y="102" width="36" height="36"/>
<dc:Bounds x="502" y="102" width="36" height="36"/>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="flow1_di" bpmnElement="flow1">
<di:waypoint x="188" y="120"/>
<di:waypoint x="240" y="120"/>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="flow2_di" bpmnElement="flow2">
<bpmndi:BPMNEdge id="flowInitiator_di" bpmnElement="flowInitiator">
<di:waypoint x="340" y="120"/>
<di:waypoint x="392" y="120"/>
<di:waypoint x="350" y="120"/>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="flow2_di" bpmnElement="flow2">
<di:waypoint x="450" y="120"/>
<di:waypoint x="502" y="120"/>
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
@@ -241,7 +241,19 @@ public class WorkflowTaskServiceImpl implements WorkflowTaskService {
Task task = getCurrentUserTask(taskId);
this.addComment(task, formData.getComment());
this.claimIfCandidate(task);
taskService.complete(taskId, formData.getVariables() == null ? Map.of() : formData.getVariables());
Map<String, Object> variables = formData.getVariables() == null
? new HashMap<>() : new HashMap<>(formData.getVariables());
if (formData.getFormData() != null && !formData.getFormData().isEmpty()) {
// 发起人节点重新提交:更新发起表单数据,字段同时作为流程变量驱动网关
ProcessInstance instance = runtimeService.createProcessInstanceQuery()
.processInstanceId(task.getProcessInstanceId())
.singleResult();
Assert.isTrue(instance != null && StrUtil.isNotBlank(instance.getBusinessKey()),
"当前任务无关联的发起表单数据");
formDataService.updateFormData(Long.valueOf(instance.getBusinessKey()), formData.getFormData());
variables.putAll(formData.getFormData());
}
taskService.complete(taskId, variables);
}
/**
@@ -74,9 +74,19 @@ public class BpmnModelHelper {
if (process == null) {
return null;
}
return process.findFlowElementsOfType(StartEvent.class).stream()
String startFormKey = process.findFlowElementsOfType(StartEvent.class).stream()
.findFirst()
.map(StartEvent::getFormKey)
.filter(StrUtil::isNotBlank)
.orElse(null);
if (startFormKey != null) {
return startFormKey;
}
// 发起表单挂在发起人节点时,回退取首个用户任务的表单
return process.findFlowElementsOfType(UserTask.class).stream()
.map(UserTask::getFormKey)
.filter(StrUtil::isNotBlank)
.findFirst()
.orElse(null);
}
@@ -20,10 +20,10 @@ import java.util.stream.Collectors;
@ConfigurationProperties(prefix = "storage")
public class StorageProperties {
// 存储类型,决定激活哪个 FileService 实现类
/** 文件存储类型:s3、aliyun 或 local */
private String type;
// 上传限制
/** 上传限制 */
private Upload upload = new Upload();
/**
@@ -32,15 +32,12 @@ public class StorageProperties {
@Data
public static class Upload {
// 单文件大小上限,如 50MB
private String maxFileSize;
// 允许上传的文件扩展名白名单
/** 允许上传的文件扩展名白名单,留空不限制 */
private List<String> allowedExtensions;
}
/**
* 获取规范化后的扩展名白名单
* 从 upload.allowed-extensions 计算规范化后的扩展名白名单,不是独立配置项
*
* @return 小写、不含点的扩展名集合;空集合表示不限制
*/
@@ -55,4 +52,4 @@ public class StorageProperties {
.map(String::toLowerCase)
.collect(Collectors.toUnmodifiableSet());
}
}
}
@@ -13,9 +13,11 @@ import com.youlai.boot.common.exception.BusinessException;
import com.youlai.boot.support.file.model.FileInfo;
import com.youlai.boot.support.file.service.FileService;
import jakarta.annotation.PostConstruct;
import lombok.AccessLevel;
import lombok.Data;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.ConfigurationProperties;
@@ -26,7 +28,7 @@ import java.io.InputStream;
import java.time.LocalDateTime;
/**
* 阿里云 OSS 文件存储服务。
* 阿里云 OSS 文件存储服务
*/
@Component
@Slf4j
@@ -36,15 +38,16 @@ import java.time.LocalDateTime;
@Data
public class AliyunFileServiceImpl implements FileService {
// OSS 地域节点,如 {@code oss-cn-hangzhou.aliyuncs.com},兼容带 {@code http(s)://} 前缀写法
/** OSS 地域节点,如 oss-cn-hangzhou.aliyuncs.com,兼容带 http(s):// 前缀写法 */
private String endpoint;
// 访问密钥 ID
/** 访问密钥 ID */
private String accessKeyId;
// 访问密钥 Secret
/** 访问密钥 Secret */
private String accessKeySecret;
// 存储空间名称
/** 存储空间名称 */
private String bucket;
@Setter(AccessLevel.NONE)
private OSS aliyunOssClient;
@PostConstruct
@@ -53,7 +56,7 @@ public class AliyunFileServiceImpl implements FileService {
}
/**
* 上传文件到阿里云 OSS,按日期分目录,返回 {@code 协议://bucket.endpoint/path} 格式的 URL。
* 上传文件到阿里云 OSS,按日期分目录,返回 {@code 协议://bucket.endpoint/path} 格式的 URL
*/
@Override
@SneakyThrows
@@ -79,7 +82,7 @@ public class AliyunFileServiceImpl implements FileService {
}
/**
* 从完整 URL 中提取文件名后调用 OSS 删除。
* 从完整 URL 中提取文件名后调用 OSS 删除
*
* @param filePath 文件完整 URL
* @return 删除成功返回 true
@@ -94,7 +97,7 @@ public class AliyunFileServiceImpl implements FileService {
/**
* 补全 endpoint 协议前缀:已带 {@code http://} 或 {@code https://} 的仅去除尾部 {@code /},
* 纯域名写法默认补 {@code https://},避免 OSS 客户端对无协议 endpoint 默认走 http 明文传输。
* 纯域名写法默认补 {@code https://},避免 OSS 客户端对无协议 endpoint 默认走 http 明文传输
*/
private String endpointWithProtocol() {
String trimmed = StrUtil.trim(endpoint);
@@ -105,7 +108,7 @@ public class AliyunFileServiceImpl implements FileService {
}
/**
* 获取文件访问主机地址(含协议),如 {@code https://bucket.oss-cn-hangzhou.aliyuncs.com}。
* 获取文件访问主机地址(含协议),如 {@code https://bucket.oss-cn-hangzhou.aliyuncs.com}
*/
private String getFileHost() {
String endpointWithProtocol = endpointWithProtocol();
@@ -20,7 +20,7 @@ import java.io.InputStream;
import java.time.LocalDateTime;
/**
* 本地文件存储服务。
* 本地文件存储服务
*/
@Data
@Slf4j
@@ -30,11 +30,11 @@ import java.time.LocalDateTime;
@RequiredArgsConstructor
public class LocalFileServiceImpl implements FileService {
// 本地存储根目录,来自 {@code storage.local.path}
/** 本地存储根目录,来自 storage.local.path */
private String path;
/**
* 上传文件到本地磁盘,按日期分目录,返回相对于存储根目录的路径。
* 上传文件到本地磁盘,按日期分目录,返回相对于存储根目录的路径
*/
@Override
public FileInfo uploadFile(MultipartFile file) {
@@ -57,7 +57,7 @@ public class LocalFileServiceImpl implements FileService {
}
/**
* 删除本地文件。路径是目录或不存在时返回 false。
* 删除本地文件。路径是目录或不存在时返回 false
*
* @param filePath 相对于存储根目录的文件路径
* @return 删除成功返回 true
@@ -10,9 +10,11 @@ import com.youlai.boot.common.result.ResultCode;
import com.youlai.boot.support.file.model.FileInfo;
import com.youlai.boot.support.file.service.FileService;
import jakarta.annotation.PostConstruct;
import lombok.AccessLevel;
import lombok.Data;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.ConfigurationProperties;
@@ -52,18 +54,20 @@ import java.time.LocalDateTime;
@Slf4j
public class S3FileServiceImpl implements FileService {
// S3 对象存储服务端点,如 {@code http://localhost:9000}
/** S3 对象存储服务端点,如 http://localhost:9000 */
private String endpoint;
// 访问密钥
/** 访问密钥 */
private String accessKey;
// 秘密密钥
/** 秘密密钥 */
private String secretKey;
// 存储桶名称
/** 存储桶名称 */
private String bucket;
// 自定义域名(可选),配置后不再使用预签名 URL
/** 文件访问域名,留空时使用对象存储端点生成访问地址 */
private String domain;
@Setter(AccessLevel.NONE)
private S3Client s3Client;
@Setter(AccessLevel.NONE)
private S3Presigner presigner;
@PostConstruct
@@ -90,7 +94,7 @@ public class S3FileServiceImpl implements FileService {
}
/**
* 上传文件到 S3(RustFS),按日期分目录,自动创建存储桶,返回文件访问 URL。
* 上传文件到 S3(RustFS),按日期分目录,自动创建存储桶,返回文件访问 URL
*/
@Override
@SneakyThrows
@@ -129,8 +133,8 @@ public class S3FileServiceImpl implements FileService {
}
/**
* 生成预签名 GET URL 并去掉 query 参数,路径直达对象。
* 依赖桶已开匿名只读(详见 createBucketIfAbsent 的策略),签名参数在 URL 中无实际作用。
* 生成预签名 GET URL 并去掉 query 参数,路径直达对象
* 依赖桶已开匿名只读(详见 createBucketIfAbsent 的策略),签名参数在 URL 中无实际作用
*/
private String presignedUrl(String dateFolder, String fileName) {
GetObjectRequest getObjectRequest = GetObjectRequest.builder()
@@ -146,7 +150,7 @@ public class S3FileServiceImpl implements FileService {
}
/**
* 删除文件。
* 删除文件
*
* @param filePath 文件完整 URL
* @return 删除成功返回 true
@@ -182,7 +186,7 @@ public class S3FileServiceImpl implements FileService {
}
/**
* 存储桶不存在时自动创建,并设置为公开只读策略。
* 存储桶不存在时自动创建,并设置为公开只读策略
*/
@SneakyThrows
private void createBucketIfAbsent(String bucket) {
@@ -199,4 +203,4 @@ public class S3FileServiceImpl implements FileService {
}
}
}
}
}
@@ -5,7 +5,7 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
/**
* 邮件配置属性
* 邮件配置属性;默认使用 587 端口、SMTP 认证和 STARTTLS
*
* @author Ray
* @since 2024/8/17
@@ -15,22 +15,22 @@ import org.springframework.stereotype.Component;
@Data
public class MailProperties {
// SMTP 服务器地址
/** SMTP 服务器地址 */
private String host;
// SMTP 端口
private int port;
/** SMTP 端口 */
private int port = 587;
// 发件人账号
/** 发件人账号 */
private String username;
// 发件人密码
/** 发件人密码 */
private String password;
// 发件人地址
/** 发件人地址 */
private String from;
// SMTP 扩展属性
/** SMTP 扩展属性 */
private Properties properties = new Properties();
@Data
@@ -39,16 +39,16 @@ public class MailProperties {
@Data
public static class Smtp {
// 启用 SMTP 认证
private boolean auth;
/** 启用 SMTP 认证 */
private boolean auth = true;
private StartTls starttls = new StartTls();
@Data
public static class StartTls {
// 启用 STARTTLS
private boolean enable;
/** 启用 STARTTLS */
private boolean enable = true;
}
}
}
}
}
@@ -1,7 +1,7 @@
package com.youlai.boot.support.mail.service;
/**
* 邮件发送服务接口。
* 邮件发送服务接口
*
* @author Ray.Hao
* @since 3.1.0
@@ -9,7 +9,7 @@ package com.youlai.boot.support.mail.service;
public interface EmailService {
/**
* 发送纯文本邮件。
* 发送纯文本邮件
*
* @param to 收件人邮箱
* @param subject 邮件主题
@@ -18,7 +18,7 @@ public interface EmailService {
void send(String to, String subject, String text);
/**
* 发送HTML格式的邮件。
* 发送HTML格式的邮件
*
* @param to 收件人邮箱
* @param subject 邮件主题
@@ -27,7 +27,7 @@ public interface EmailService {
void sendHtmlMail(String to, String subject, String html);
/**
* 发送带附件的邮件。
* 发送带附件的邮件
*
* @param to 收件人邮箱
* @param subject 邮件主题
@@ -19,7 +19,7 @@ import java.io.File;
import java.nio.charset.StandardCharsets;
/**
* SMTP 邮件服务。
* SMTP 邮件服务
*
* @author Ray.Hao
* @since 3.1.0
@@ -31,11 +31,11 @@ import java.nio.charset.StandardCharsets;
public class SmtpEmailServiceImpl implements EmailService {
private final JavaMailSender mailSender;
// 发件人地址等邮件配置,来自 {@code mail.*}
// 发件人地址等邮件配置,绑定 spring.mail.*
private final MailProperties mailProperties;
/**
* 发送纯文本邮件,发件人取自 {@code mail.from} 配置。
* 发送纯文本邮件,发件人取自 {@code spring.mail.from} 配置
*/
@Override
public void send(String to, String subject, String text) {
@@ -57,7 +57,6 @@ public class SmtpEmailServiceImpl implements EmailService {
* @param to 收件人地址
* @param subject 邮件主题
* @param html html格式的内容
* @return 是否发送成功
*/
@Override
public void sendHtmlMail(String to, String subject, String html) {
@@ -82,7 +81,7 @@ public class SmtpEmailServiceImpl implements EmailService {
}
/**
* 发送带附件的 HTML 邮件。
* 发送带附件的 HTML 邮件
*/
@Override
public void sendWithAttachment(String to, String subject, String text, String filePath) {
@@ -102,4 +101,4 @@ public class SmtpEmailServiceImpl implements EmailService {
log.error("发送带附件邮件失败: {}", e.getMessage());
}
}
}
}
@@ -15,6 +15,8 @@ import java.util.List;
@Setter
@ConfigurationProperties("realtime")
public class RealtimeProperties {
/** 是否启用实时通信接口 */
private boolean enabled = true;
/** 额外允许的浏览器来源,如 https://admin.example.com */
private List<String> allowedOrigins = List.of();
}
@@ -17,22 +17,22 @@ import java.util.Map;
@ConfigurationProperties(prefix = "sms.aliyun")
public class AliyunSmsProperties {
// 访问密钥 ID
/** 访问密钥 ID */
private String accessKeyId;
// 访问密钥 Secret
/** 访问密钥 Secret */
private String accessKeySecret;
// API 域名,如 dysmsapi.aliyuncs.com
private String domain;
/** API 域名,默认使用阿里云短信公共端点 */
private String domain = "dysmsapi.aliyuncs.com";
// 区域,如 cn-shanghai
private String regionId;
/** 区域,默认 cn-shanghai */
private String regionId = "cn-shanghai";
// 短信签名
/** 短信签名 */
private String signName;
// 短信模板集合,key 为模板用途(login/register),value 为模板CODE
/** 短信模板集合,key 为模板用途(login/register),value 为模板CODE */
private Map<String, String> templates;
}
}
@@ -5,7 +5,7 @@ import com.youlai.boot.support.sms.SmsTypeEnum;
import java.util.Map;
/**
* 短信发送服务接口。
* 短信发送服务接口
*
* @author Ray.Hao
* @since 2024/8/17
@@ -13,7 +13,7 @@ import java.util.Map;
public interface SmsService {
/**
* 发送短信。
* 发送短信
*
* @param mobile 手机号
* @param smsType 短信类型,对应 {@code sms.templates.*} 配置中的模板
@@ -8,7 +8,7 @@ import org.springframework.stereotype.Component;
import java.util.Set;
/**
* 权限查询适配器。
* 权限查询适配器
*
* @author Ray.Hao
* @since 3.1.0
@@ -63,7 +63,7 @@ public class FileController {
}
/**
* 文件扩展名白名单校验:{@code allowed-extensions} 为空时不限制。
* 文件扩展名白名单校验:{@code allowed-extensions} 为空时不限制
*/
private void validateFileExtension(MultipartFile file) {
Set<String> allowedExtensions = storageProperties.getAllowedExtensions();
@@ -9,8 +9,8 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* 系统健康检查接口,返回 ok。
* 不标注 @RateLimit,仅受 IP 全局限流层约束,用作该层的验证端点。
* 系统健康检查接口,返回 ok
* 不标注 @RateLimit,仅受 IP 全局限流层约束,用作该层的验证端点
*/
@Tag(name = "00.系统健康检查")
@RestController
@@ -1,7 +1,6 @@
package com.youlai.boot.system.controller;
import cn.idev.excel.EasyExcel;
import cn.idev.excel.ExcelWriter;
import com.youlai.boot.common.annotation.Log;
import com.youlai.boot.framework.web.repeatsubmit.RepeatSubmit;
import com.youlai.boot.common.enums.ActionTypeEnum;
@@ -51,11 +50,10 @@ import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.Collections;
import java.util.List;
/**
@@ -166,18 +164,16 @@ public class UserController {
@Operation(summary = "用户导入模板下载")
@GetMapping("/template")
public void downloadTemplate(HttpServletResponse response) {
public void downloadTemplate(HttpServletResponse response) {
String fileName = "用户导入模板.xlsx";
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
response.setHeader("Content-Disposition", "attachment; filename=" + URLEncoder.encode(fileName, StandardCharsets.UTF_8));
// ClassLoader 只认 / 分隔,用 File.separator 打 jar 后(Linux)会取不到资源
String fileClassPath = "excel/" + fileName;
InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream(fileClassPath);
try (ServletOutputStream outputStream = response.getOutputStream();
ExcelWriter excelWriter = EasyExcel.write(outputStream).withTemplate(inputStream).build()) {
excelWriter.finish();
// 表头取自 UserImportForm 的 @ExcelProperty,写入空列表即只产出表头
try (ServletOutputStream outputStream = response.getOutputStream()) {
EasyExcel.write(outputStream, UserImportForm.class)
.sheet("用户导入")
.doWrite(Collections.emptyList());
} catch (IOException e) {
throw new BusinessException("用户导入模板下载失败", e);
}
@@ -5,7 +5,7 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
/**
* XXL-JOB 示例任务。
* XXL-JOB 示例任务
*
* @author Ray.Hao
* @since 3.1.0
@@ -27,7 +27,7 @@ import java.util.List;
import java.util.stream.Collectors;
/**
* 用户导入读取器。
* 用户导入读取器
*
* @author Ray
* @since 2022/4/10