@@ -3,10 +3,12 @@ package com.yunhai.notice;
|
||||
import com.alibaba.fastjson.parser.ParserConfig;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||
|
||||
@SpringBootApplication(scanBasePackages = "com.yunhai.notice")
|
||||
@EnableTransactionManagement
|
||||
@EnableScheduling
|
||||
public class NoticeApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
@@ -0,0 +1,166 @@
|
||||
package com.yunhai.notice.config;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.yunhai.notice.entity.NoticeFlowReg;
|
||||
import com.yunhai.notice.repository.NoticeFlowRegRepository;
|
||||
import com.yunhai.notice.utils.ReReadableRequestWrapper;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.boot.web.servlet.FilterRegistrationBean;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import javax.crypto.Mac;
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
import javax.servlet.Filter;
|
||||
import javax.servlet.FilterChain;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.ServletRequest;
|
||||
import javax.servlet.ServletResponse;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.MessageDigest;
|
||||
import java.util.Base64;
|
||||
|
||||
/**
|
||||
* 流程中心回调验签(方案 §5.3,svc-hall FlowCallbackFilterConfiguration 同构):
|
||||
* 只拦 /callback/*(CAS url-pattern /api/*、/mobiapi/* 之外,独立于 oapi 的 appKey 签名体系)。
|
||||
* 协议对齐流程中心概览 §8.4:X-Flw-EventId / X-Flw-Timestamp(±5 分钟防重放)/
|
||||
* X-Flw-Nonce / X-Flw-Signature = Base64(HmacSHA256(secret, timestamp + "." + nonce + "." + body)),
|
||||
* secret 按 payload.flowGuid 查 notice_flow_reg;常量时间比对。
|
||||
* 注册探活 ping(事件=ping)直接 200——flow-center 探活只判连接级可达(签名是字面量 "ping" 无法验)。
|
||||
*/
|
||||
@Slf4j
|
||||
@Configuration
|
||||
@RequiredArgsConstructor
|
||||
public class FlowCallbackFilterConfiguration {
|
||||
|
||||
/** ±5 分钟防重放窗口(对齐概览 §8.4) */
|
||||
private static final long TIMESTAMP_WINDOW_MS = 5 * 60 * 1000L;
|
||||
|
||||
private final NoticeFlowRegRepository regRepository;
|
||||
private final ObjectMapper objectMapper;
|
||||
|
||||
@Bean
|
||||
public FilterRegistrationBean<FlowCallbackVerifyFilter> flowCallbackVerifyFilter() {
|
||||
FilterRegistrationBean<FlowCallbackVerifyFilter> bean = new FilterRegistrationBean<>();
|
||||
bean.setFilter(new FlowCallbackVerifyFilter());
|
||||
bean.addUrlPatterns("/callback/*");
|
||||
// 晚于 AppAuthFilter(+10)/enforce(+11),独立回调签名体系
|
||||
bean.setOrder(Ordered.HIGHEST_PRECEDENCE + 20);
|
||||
return bean;
|
||||
}
|
||||
|
||||
class FlowCallbackVerifyFilter implements Filter {
|
||||
|
||||
@Override
|
||||
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
|
||||
throws IOException, ServletException {
|
||||
HttpServletRequest req = (HttpServletRequest) request;
|
||||
HttpServletResponse res = (HttpServletResponse) response;
|
||||
if (!"POST".equalsIgnoreCase(req.getMethod())) {
|
||||
res.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED);
|
||||
return;
|
||||
}
|
||||
ReReadableRequestWrapper wrapper = new ReReadableRequestWrapper(req);
|
||||
String body = wrapper.bodyString();
|
||||
// 注册探活:只判连接级可达,直接 200(ping 无状态语义,验签不可能通过)
|
||||
if (isPing(body)) {
|
||||
byte[] ok = "{\"ok\":true}".getBytes(StandardCharsets.UTF_8);
|
||||
res.setContentType("application/json");
|
||||
res.setContentLength(ok.length);
|
||||
res.setStatus(HttpServletResponse.SC_OK);
|
||||
res.getOutputStream().write(ok);
|
||||
return;
|
||||
}
|
||||
String eventId = req.getHeader("X-Flw-EventId");
|
||||
String timestamp = req.getHeader("X-Flw-Timestamp");
|
||||
String nonce = req.getHeader("X-Flw-Nonce");
|
||||
String signature = req.getHeader("X-Flw-Signature");
|
||||
if (!StringUtils.hasText(eventId) || !StringUtils.hasText(timestamp)
|
||||
|| !StringUtils.hasText(nonce) || !StringUtils.hasText(signature)) {
|
||||
res.sendError(HttpServletResponse.SC_UNAUTHORIZED, "missing callback headers");
|
||||
return;
|
||||
}
|
||||
try {
|
||||
long ts = Long.parseLong(timestamp.trim());
|
||||
if (Math.abs(System.currentTimeMillis() - ts) > TIMESTAMP_WINDOW_MS) {
|
||||
res.sendError(HttpServletResponse.SC_UNAUTHORIZED, "timestamp out of window");
|
||||
return;
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
res.sendError(HttpServletResponse.SC_UNAUTHORIZED, "bad timestamp");
|
||||
return;
|
||||
}
|
||||
String[] reg = extractSchAndFlowGuid(body);
|
||||
String secret = reg == null ? null : secretOf(reg[0], reg[1]);
|
||||
if (secret == null) {
|
||||
log.warn("[notice-flow] 回调验签失败:无注册或无 secret,flowGuid={}", reg == null ? null : reg[1]);
|
||||
res.sendError(HttpServletResponse.SC_UNAUTHORIZED, "unknown callback registration");
|
||||
return;
|
||||
}
|
||||
String expected = hmacSha256Base64(secret, timestamp.trim() + "." + nonce.trim() + "." + body);
|
||||
if (!constantTimeEquals(expected, signature.trim())) {
|
||||
res.sendError(HttpServletResponse.SC_UNAUTHORIZED, "bad signature");
|
||||
return;
|
||||
}
|
||||
chain.doFilter(wrapper, response);
|
||||
}
|
||||
|
||||
private boolean isPing(String body) {
|
||||
try {
|
||||
JsonNode payload = objectMapper.readTree(body);
|
||||
return payload != null && "ping".equals(payload.path("event").asText(null));
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/** 从推送体提取 [schId, flowGuid](验签必需的最小解析) */
|
||||
private String[] extractSchAndFlowGuid(String body) {
|
||||
try {
|
||||
JsonNode payload = objectMapper.readTree(body);
|
||||
if (!payload.has("flowGuid") || payload.get("flowGuid").isNull()
|
||||
|| !payload.has("schId") || payload.get("schId").isNull()) {
|
||||
return null;
|
||||
}
|
||||
return new String[]{payload.get("schId").asText(), payload.get("flowGuid").asText()};
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private String secretOf(String schId, String flowGuid) {
|
||||
try {
|
||||
NoticeFlowReg reg = regRepository
|
||||
.findBySchIdAndFlowGuid(Integer.valueOf(schId), flowGuid).orElse(null);
|
||||
if (reg != null && reg.getStatus() == 0 && StringUtils.hasText(reg.getSecret())) {
|
||||
return reg.getSecret();
|
||||
}
|
||||
} catch (NumberFormatException ignored) {
|
||||
// schId 非法按无注册处理 → 401
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private String hmacSha256Base64(String secret, String content) {
|
||||
try {
|
||||
Mac mac = Mac.getInstance("HmacSHA256");
|
||||
mac.init(new SecretKeySpec(secret.getBytes(StandardCharsets.UTF_8), "HmacSHA256"));
|
||||
byte[] raw = mac.doFinal(content.getBytes(StandardCharsets.UTF_8));
|
||||
return Base64.getEncoder().encodeToString(raw);
|
||||
} catch (Exception e) {
|
||||
throw new IllegalStateException("HmacSHA256 计算失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean constantTimeEquals(String a, String b) {
|
||||
return MessageDigest.isEqual(a.getBytes(StandardCharsets.UTF_8), b.getBytes(StandardCharsets.UTF_8));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package com.yunhai.notice.controller.api;
|
||||
|
||||
import com.yunhai.notice.config.Config;
|
||||
import com.yunhai.notice.model.flow.FlowModels;
|
||||
import com.yunhai.notice.service.flow.NoticeFlowService;
|
||||
import com.yunhai.platform.utils.model.BoaUser;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 通知-流程中心接缝接口(先审后发)。
|
||||
* <ul>
|
||||
* <li>GET Flow/Options:编辑页"审核流程"选择器(代理 FlowClient.listFlows,前端不直调 oapi);</li>
|
||||
* <li>POST Flow/TrySubmit:提交/重提审核(幂等,bizId=notice.id;apply 失败保持待提交可重推);</li>
|
||||
* <li>GET Flow/Trace:审批进度(后端 getInstanceByBiz 组装,前端不直调 oapi——放行判定必须收在后端)。</li>
|
||||
* </ul>
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping(value = Config.API_PATH + "/notice/flow/")
|
||||
@RequiredArgsConstructor
|
||||
public class NoticeFlowController {
|
||||
|
||||
private final NoticeFlowService noticeFlowService;
|
||||
|
||||
/** 审核流程下拉选项(流程中心未启用时返回空列表,前端隐藏选择器) */
|
||||
@GetMapping("Options")
|
||||
public List<FlowModels.FlowSummaryVo> options(BoaUser user,
|
||||
@RequestParam(value = "schId", required = false) Integer schId) {
|
||||
return noticeFlowService.options(schId != null ? schId : currentSchId(user));
|
||||
}
|
||||
|
||||
/** 提交/重新提交审核(编辑页重提按钮;audit=10 审批中将被拒绝;BP-R5-3 补属主守卫) */
|
||||
@PostMapping("TrySubmit")
|
||||
public void trySubmit(@RequestParam("serid") Integer serid, BoaUser user) {
|
||||
noticeFlowService.trySubmitFlow(serid, user);
|
||||
}
|
||||
|
||||
/** 审批进度(详情页进度卡片;未绑流程返回 bound=false 的未接入语义;未发布仅三类人可见) */
|
||||
@GetMapping("Trace")
|
||||
public Map<String, Object> trace(@RequestParam("serid") Integer serid, BoaUser user) {
|
||||
return noticeFlowService.buildTrace(serid, user);
|
||||
}
|
||||
|
||||
private Integer currentSchId(BoaUser user) {
|
||||
if (user == null || user.getCurrentRole() == null) {
|
||||
return null;
|
||||
}
|
||||
return user.getCurrentRole().getSchId();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package com.yunhai.notice.controller.callback;
|
||||
|
||||
import com.yunhai.notice.service.flow.FlowCallbackService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
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;
|
||||
|
||||
/**
|
||||
* 流程中心回调接收端点(方案 §5.3;/callback/* 不在 CAS url-pattern 内,由
|
||||
* FlowCallbackVerifyFilter 完成 X-Flw-* 四头验签后才到达这里)。
|
||||
* <p>
|
||||
* <b>返回语义(契约冻结 D2,免对账前提)</b>:状态推进成功 / 重复投递(去重命中)/
|
||||
* 协议毒消息 / 乱序丢弃 / 办件不属本应用 → <b>200</b>(毒消息回 200 防无限重放);
|
||||
* 瞬时失败(DB 异常/锁冲突,{@link FlowCallbackService.TransientCallbackException})/
|
||||
* 意外 RuntimeException → <b>5xx</b>——flow-center 持续重试直至送达,消费方恢复自动追平。
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/callback")
|
||||
@RequiredArgsConstructor
|
||||
public class FlowCallbackController {
|
||||
|
||||
private final FlowCallbackService callbackService;
|
||||
|
||||
@PostMapping("/flow")
|
||||
public ResponseEntity<String> flow(@RequestBody byte[] body) {
|
||||
try {
|
||||
callbackService.handle(new String(body, java.nio.charset.StandardCharsets.UTF_8));
|
||||
return ResponseEntity.ok("{\"ok\":true}");
|
||||
} catch (FlowCallbackService.TransientCallbackException e) {
|
||||
log.error("[notice-flow] 回调瞬时失败(回 5xx 触发流程中心重试): {}", e.getMessage(), e);
|
||||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"ok\":false}");
|
||||
} catch (Exception e) {
|
||||
// 意外异常同样按瞬时失败处理(宁可多重试一次,不可丢事件)
|
||||
log.error("[notice-flow] 回调意外异常(回 5xx 触发流程中心重试)", e);
|
||||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"ok\":false}");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.yunhai.notice.controller.oapi;
|
||||
|
||||
import com.yunhai.notice.service.IDictService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 开放接口 demo(两级模型试点 P2.1:Notice 作为提供方开放 /oapi/**)。
|
||||
* 强制验签由 starter 提供(yml {@code yh.app-auth.server.enforce-patterns: [/oapi/*]}):
|
||||
* 浏览器/匿名直访 401,注册应用带 X-App-* 签名三件套直调通过(trusted-apps 收调用方密钥)。
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/oapi/notice")
|
||||
@RequiredArgsConstructor
|
||||
public class OapiDictController {
|
||||
|
||||
private final IDictService dictService;
|
||||
|
||||
/** 部门字典(demo:type=1 部门;调用方签名鉴权由 enforce-patterns 强制) */
|
||||
@GetMapping("/getDict")
|
||||
public List<Map<String, Object>> getDict(@RequestParam(value = "type", defaultValue = "1") Integer type) {
|
||||
return dictService.getSysDic(type);
|
||||
}
|
||||
}
|
||||
@@ -145,4 +145,34 @@ public class Notice extends BaseEntity {
|
||||
*/
|
||||
@Column(name = "sms_flag")
|
||||
private Integer smsFlag = 0;
|
||||
|
||||
/**
|
||||
* 短信实际发送时间(防重复发送的幂等标记):NULL=未发。
|
||||
* 直发/审批通过/到点补发三条链路共用(SmsSendService 原子认领);本地随 ddl-auto=update
|
||||
* 自动加列,生产执行 deploy/sql/20260913_add_sms_sent_at.sql。
|
||||
*/
|
||||
@Column(name = "sms_sent_at")
|
||||
private LocalDateTime smsSentAt;
|
||||
|
||||
// ===== 先审后发(流程中心托管):全部可空,NULL=未绑流程(原直发链路,存量零迁移) =====
|
||||
|
||||
/** 绑定的流程 GUID;NULL=直发(原链路一字不改) */
|
||||
@Column(name = "flow_guid", length = 32)
|
||||
private String flowGuid;
|
||||
|
||||
/** 流程中心办件 id(apply 成功回填) */
|
||||
@Column(name = "flow_instance_id")
|
||||
private Long flowInstanceId;
|
||||
|
||||
/** 审核镜像状态:0 待提交 / 10 审批中 / 20 通过 / 30 驳回 / 40 已撤回(FlowAuditStatusEnum) */
|
||||
@Column(name = "audit_status")
|
||||
private Integer auditStatus;
|
||||
|
||||
/** 已消费的最大回调 instanceVersion(乱序丢弃闸门) */
|
||||
@Column(name = "last_instance_version")
|
||||
private Integer lastInstanceVersion;
|
||||
|
||||
/** 终态明细快照(result/opinion/rejectNode,详情页进度卡片展示) */
|
||||
@Column(name = "flow_result_json", columnDefinition = "LONGTEXT")
|
||||
private String flowResultJson;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
package com.yunhai.notice.entity;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import com.yunhai.notice.common.listener.NoticeAuditListener;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.EntityListeners;
|
||||
import javax.persistence.Index;
|
||||
import javax.persistence.Table;
|
||||
import javax.persistence.UniqueConstraint;
|
||||
|
||||
/**
|
||||
* 流程中心回调事件去重表(照 svc-hall ServiceFlowEvent / flow-center 事件 uk 同构):
|
||||
* eventId 唯一约束兜底并发;重复投递(flow-center 持续重试语义下必然发生)命中唯一键即跳过。
|
||||
*/
|
||||
@Entity
|
||||
@Table(name = "notice_flow_event",
|
||||
uniqueConstraints = @UniqueConstraint(name = "uk_notice_flow_event", columnNames = "event_id"),
|
||||
indexes = @Index(name = "idx_notice_flow_event_inst", columnList = "instance_id"))
|
||||
@Getter
|
||||
@Setter
|
||||
@EntityListeners(NoticeAuditListener.class)
|
||||
public class NoticeFlowEvent extends BaseEntity {
|
||||
|
||||
/** 事件唯一键(32 位 uuid,flow-center 重试不变) */
|
||||
@Column(name = "event_id", length = 40, nullable = false)
|
||||
private String eventId;
|
||||
|
||||
/** 事件码:flow.submitted / task.created / task.handled / completed / rejected / withdrawn / ping */
|
||||
@Column(name = "event", length = 32)
|
||||
private String event;
|
||||
|
||||
@Column(name = "sch_id")
|
||||
private Integer schId;
|
||||
|
||||
@Column(name = "instance_id")
|
||||
private Long instanceId;
|
||||
|
||||
@Column(name = "receive_time")
|
||||
private java.time.LocalDateTime receiveTime;
|
||||
|
||||
@Column(name = "payload_json", columnDefinition = "LONGTEXT")
|
||||
private String payloadJson;
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package com.yunhai.notice.entity;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.EntityListeners;
|
||||
import javax.persistence.Table;
|
||||
import javax.persistence.UniqueConstraint;
|
||||
import com.yunhai.notice.common.listener.NoticeAuditListener;
|
||||
|
||||
/**
|
||||
* 流程中心回调注册(照 svc-hall ServiceFlowReg / flow-center FlwCallbackReg 同构):
|
||||
* sch+appKey+flowGuid 唯一;secret 为 flow-center reg 接口下发时落库的回调验签密钥。
|
||||
* 注意:flow-center 重复注册会<b>轮换 secret</b>,故仅在缺失时注册(ensureRegistered),
|
||||
* 绝不重复调用——失配恢复手段=管理端重新保存绑定。
|
||||
*/
|
||||
@Entity
|
||||
@Table(name = "notice_flow_reg",
|
||||
uniqueConstraints = @UniqueConstraint(name = "uk_notice_flow_reg", columnNames = {"sch_id", "app_key", "flow_guid"}))
|
||||
@Getter
|
||||
@Setter
|
||||
@EntityListeners(NoticeAuditListener.class)
|
||||
public class NoticeFlowReg extends BaseEntity {
|
||||
|
||||
@Column(name = "sch_id")
|
||||
private Integer schId;
|
||||
|
||||
/** 本应用在流程中心侧的 appKey(yh.app-auth.app-key,出站签名同一身份) */
|
||||
@Column(name = "app_key", length = 64)
|
||||
private String appKey;
|
||||
|
||||
@Column(name = "flow_guid", length = 32)
|
||||
private String flowGuid;
|
||||
|
||||
@Column(name = "callback_url", length = 500)
|
||||
private String callbackUrl;
|
||||
|
||||
/** 订阅事件逗号分隔,空=全部 */
|
||||
@Column(name = "event_types", length = 200)
|
||||
private String eventTypes;
|
||||
|
||||
/** flow-center reg 接口下发的回调验签密钥 */
|
||||
@Column(name = "secret", length = 64)
|
||||
private String secret;
|
||||
|
||||
/** 0 启用 / 1 停用(预留) */
|
||||
@Column(name = "status")
|
||||
private Integer status = 0;
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package com.yunhai.notice.enums;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* 通知审核状态(audit_status 列,对齐 flow-center FlwEnums.InstanceStatus 与 svc-hall ApplyFlowStatusEnum;
|
||||
* 未提交 0 为 Notice 特有——apply 尚未成功的暂态)。仅在绑定了审核流程(flow_guid 非空)时有意义。
|
||||
*/
|
||||
@Getter
|
||||
public enum FlowAuditStatusEnum {
|
||||
|
||||
PENDING_SUBMIT(0, "待提交"),
|
||||
APPROVING(10, "审批中"),
|
||||
APPROVED(20, "已通过"),
|
||||
REJECTED(30, "已驳回"),
|
||||
WITHDRAWN(40, "已撤回");
|
||||
|
||||
private final int code;
|
||||
private final String desc;
|
||||
|
||||
FlowAuditStatusEnum(int code, String desc) {
|
||||
this.code = code;
|
||||
this.desc = desc;
|
||||
}
|
||||
|
||||
public static FlowAuditStatusEnum of(Integer code) {
|
||||
if (code == null) {
|
||||
return null;
|
||||
}
|
||||
for (FlowAuditStatusEnum e : values()) {
|
||||
if (e.code == code) {
|
||||
return e;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String descOf(Integer code) {
|
||||
FlowAuditStatusEnum e = of(code);
|
||||
return e == null ? null : e.getDesc();
|
||||
}
|
||||
}
|
||||
@@ -3,13 +3,15 @@ package com.yunhai.notice.enums;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* 通知状态。无草稿态:发通知一律置为「已发布」,
|
||||
* 通知状态。status=1 已发布仍是用户端唯一可见态;
|
||||
* 先审后发引入 status=0 未发布(审核载体:绑流程通知提交后置 0,回调 completed 才置 1,
|
||||
* 审核进度独立成列 audit_status)。未绑流程的通知仍无草稿态(直发即 1),
|
||||
* 定时发送通过 timingSendTime + 查询侧「已到点」过滤控制可见性。
|
||||
* 对应原 .NET Notify_Message.status(原系统已发布=2,此处归一化为 1)。
|
||||
*/
|
||||
@Getter
|
||||
public enum NoticeStatusEnum {
|
||||
|
||||
UNPUBLISHED(0, "未发布"),
|
||||
PUBLISHED(1, "已发布");
|
||||
|
||||
private final int code;
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
package com.yunhai.notice.job;
|
||||
|
||||
import com.yunhai.notice.entity.Notice;
|
||||
import com.yunhai.notice.repository.NoticeRepository;
|
||||
import com.yunhai.notice.service.sms.SmsSendService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 短信到点补发调度(§3.2 / BP-R5-2):扫"已发布 + 要发短信 + 从未发过 + 已到定时点"的行补发。
|
||||
* 覆盖场景:定时发送的通知在定时点之前审批通过——发布链路按设计跳过短信(可见性即时生效),
|
||||
* 原实现无任何补发导致短信永久丢失。幂等由 SmsSendService 的 sms_sent_at 原子认领保证
|
||||
* (并发/重复调度不双发);单条失败不阻断批次(归还认领,下轮重试)。
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class SmsCatchupJob {
|
||||
|
||||
/** 单批上限(防御性:避免超大存量发布时一次性拉满) */
|
||||
private static final int BATCH = 200;
|
||||
|
||||
private final NoticeRepository noticeRepository;
|
||||
private final SmsSendService smsSendService;
|
||||
|
||||
@Value("${notice.sms.catchup-enabled:true}")
|
||||
private boolean enabled;
|
||||
|
||||
/** fixedDelay=5min(上一轮跑完起算,单实例内天然不重叠;跨实例由原子认领闸) */
|
||||
@Scheduled(fixedDelayString = "${notice.sms.catchup-fixed-delay-ms:300000}", initialDelay = 30_000)
|
||||
public void catchupDueSms() {
|
||||
if (!enabled) {
|
||||
return;
|
||||
}
|
||||
List<Notice> due = noticeRepository.findSmsDue(LocalDateTime.now(), PageRequest.of(0, BATCH));
|
||||
if (due.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
log.info("[notice-sms] 到点补发扫描:{} 条待发", due.size());
|
||||
int sent = 0;
|
||||
for (Notice notice : due) {
|
||||
try {
|
||||
if (smsSendService.sendOnce(notice)) {
|
||||
sent++;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.warn("[notice-sms] 补发单条失败(下轮重试)notice={}:{}", notice.getId(), e.toString());
|
||||
}
|
||||
}
|
||||
log.info("[notice-sms] 到点补发完成:本轮发送 {} 条", sent);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
package com.yunhai.notice.model.flow;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 流程中心 /oapi/flow/** 契约模型(与 flow-center OapiModels 逐字对齐,
|
||||
* 契约锚点:《流程中心设计概览方案.md》§8 / M1 开工说明 §5——两侧已编码,改动须双向同步)。
|
||||
*/
|
||||
public final class FlowModels {
|
||||
|
||||
private FlowModels() {
|
||||
}
|
||||
|
||||
/** 流程摘要(GET /oapi/flow/list 元素) */
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public static class FlowSummaryVo {
|
||||
private String flowGuid;
|
||||
private String name;
|
||||
private Integer version;
|
||||
private String nodeSummary;
|
||||
}
|
||||
|
||||
/** 代发起请求体(POST /oapi/flow/apply) */
|
||||
@Data
|
||||
public static class ApplyBody {
|
||||
private String flowGuid;
|
||||
private String bizType;
|
||||
private String bizId;
|
||||
private String bizTitle;
|
||||
private String bizUrl;
|
||||
/** 业务摘要快照(对象透传,flow-center 统一落 JSON 串) */
|
||||
private Object bizSnapshot;
|
||||
private Integer submitterId;
|
||||
private String submitterName;
|
||||
}
|
||||
|
||||
/** 代发起响应(biz uk 幂等:重复 apply 返回既有办件 duplicated=true;30/40 态 R4 重启推进) */
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public static class ApplyResultVo {
|
||||
private Long instanceId;
|
||||
private boolean duplicated;
|
||||
}
|
||||
|
||||
/** 按业务键查办件响应(GET /oapi/flow/instance;不存在为 null) */
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public static class InstanceVo {
|
||||
private Long instanceId;
|
||||
private Integer status;
|
||||
private Integer version;
|
||||
private String nodeSummary;
|
||||
/** 办理轨迹 JSON(含 assigneeId,办理人放行判定用) */
|
||||
private String traceJson;
|
||||
private List<Integer> assigneeIds;
|
||||
private String currentNodes;
|
||||
private String bizTitle;
|
||||
private Integer submitterId;
|
||||
private String submitterName;
|
||||
private String submitTime;
|
||||
private String finishTime;
|
||||
}
|
||||
|
||||
/** 回调注册请求体(POST /oapi/flow/callback/reg) */
|
||||
@Data
|
||||
public static class CallbackRegBody {
|
||||
private String flowGuid;
|
||||
private String callbackUrl;
|
||||
/** 订阅事件逗号分隔,空=全部 */
|
||||
private String eventTypes;
|
||||
}
|
||||
|
||||
/** 回调注册响应(secret 注册时生成下发;重复注册会轮换 secret,绝不重复调用) */
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public static class CallbackRegResultVo {
|
||||
private String secret;
|
||||
}
|
||||
}
|
||||
@@ -55,6 +55,23 @@ public class NoticeDetailVo {
|
||||
@JsonProperty("tlist")
|
||||
private Object tlist;
|
||||
|
||||
// ===== 先审后发(编辑页驳回/撤回态展示) =====
|
||||
|
||||
/** 绑定的审核流程 GUID(null=直发未接流程) */
|
||||
private String flowGuid;
|
||||
|
||||
/** 审核状态:0 待提交 / 10 审批中 / 20 通过 / 30 驳回 / 40 已撤回(null=未绑) */
|
||||
private Integer auditStatus;
|
||||
|
||||
/** 审核状态文案 */
|
||||
private String auditStatusDesc;
|
||||
|
||||
/** 流程中心办件 id(撤回/催办直调 flow-center 用) */
|
||||
private Long flowInstanceId;
|
||||
|
||||
/** 终态明细(result/opinion/rejectNode;null=无) */
|
||||
private Object flowResult;
|
||||
|
||||
/**
|
||||
* 附件项(旧 ChaoSend 数组元素)。
|
||||
*/
|
||||
|
||||
@@ -50,4 +50,10 @@ public class NoticeRequest {
|
||||
|
||||
/** 转发源通知ID(非空时表示转发创建,对应旧 REST 壳 forward/{sourceId}) */
|
||||
private Integer sourceId;
|
||||
|
||||
/**
|
||||
* 审核流程 GUID(可选,先审后发):非空=提交审核(status=0 待回调 completed 才发布);
|
||||
* 空=原直发链路(一字不改)。编辑时可变更绑定(变更即走新一轮审核)。
|
||||
*/
|
||||
private String flowGuid;
|
||||
}
|
||||
|
||||
@@ -50,6 +50,20 @@ public class NoticeVo {
|
||||
/** 附件ID串("1,2,3",列表页下载入口使用;对齐旧 .NET UpFile 字段) */
|
||||
private String UpFile;
|
||||
|
||||
// ===== 先审后发(流程中心托管) =====
|
||||
|
||||
/** 绑定的审核流程 GUID(null=直发,未接流程中心) */
|
||||
private String flowGuid;
|
||||
|
||||
/** 审核状态:0 待提交 / 10 审批中 / 20 通过 / 30 驳回 / 40 已撤回(null=未绑流程) */
|
||||
private Integer auditStatus;
|
||||
|
||||
/** 审核状态文案(待提交/审批中/已通过/已驳回/已撤回;null=未绑流程) */
|
||||
private String auditStatusDesc;
|
||||
|
||||
/** 流程中心办件 id(提交成功后非空;详情页撤回/催办直调 flow-center 用) */
|
||||
private Long flowInstanceId;
|
||||
|
||||
private String createBy;
|
||||
private LocalDateTime createTime;
|
||||
private String updateBy;
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.yunhai.notice.repository;
|
||||
|
||||
import com.yunhai.notice.entity.NoticeFlowEvent;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
public interface NoticeFlowEventRepository extends JpaRepository<NoticeFlowEvent, Integer> {
|
||||
|
||||
boolean existsByEventId(String eventId);
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.yunhai.notice.repository;
|
||||
|
||||
import com.yunhai.notice.entity.NoticeFlowReg;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public interface NoticeFlowRegRepository extends JpaRepository<NoticeFlowReg, Integer> {
|
||||
|
||||
Optional<NoticeFlowReg> findBySchIdAndAppKeyAndFlowGuid(Integer schId, String appKey, String flowGuid);
|
||||
|
||||
Optional<NoticeFlowReg> findBySchIdAndFlowGuid(Integer schId, String flowGuid);
|
||||
|
||||
List<NoticeFlowReg> findBySchIdAndStatusOrderByUpdateTimeDesc(Integer schId, Integer status);
|
||||
}
|
||||
@@ -2,6 +2,8 @@ package com.yunhai.notice.repository;
|
||||
|
||||
import com.yunhai.notice.entity.Notice;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
import java.util.Optional;
|
||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
@@ -20,6 +22,50 @@ public interface NoticeRepository extends JpaRepository<Notice, Integer>,
|
||||
*/
|
||||
long countByStatus(Integer status);
|
||||
|
||||
/** 回调事件处理专用:行级悲观锁读(并发推送串行化,防整实体保存互相覆盖丢更新) */
|
||||
@org.springframework.data.jpa.repository.Lock(javax.persistence.LockModeType.PESSIMISTIC_WRITE)
|
||||
@org.springframework.data.jpa.repository.Query("select n from Notice n where n.id = :id")
|
||||
Optional<Notice> findByIdForUpdate(@org.springframework.data.repository.query.Param("id") Integer id);
|
||||
|
||||
/**
|
||||
* 提交审核后的原子回填(窄列更新,防旧快照整实体覆盖并发回调的推进):
|
||||
* 置 flow_instance_id + audit=10;若回调已并发先行落定 audit=20(审核通过)则保持 20 不回退。
|
||||
*/
|
||||
@org.springframework.transaction.annotation.Transactional
|
||||
@org.springframework.data.jpa.repository.Modifying
|
||||
@org.springframework.data.jpa.repository.Query(
|
||||
"update Notice n set n.flowInstanceId = :instanceId, "
|
||||
+ "n.auditStatus = (case when n.auditStatus = 20 then n.auditStatus else 10 end) "
|
||||
+ "where n.id = :id")
|
||||
int markApproving(@org.springframework.data.repository.query.Param("id") Integer id,
|
||||
@org.springframework.data.repository.query.Param("instanceId") Long instanceId);
|
||||
|
||||
/**
|
||||
* 短信发送原子认领(§3.2 防重复核心):置 sms_sent_at,仅当当前为 NULL(未发)时生效。
|
||||
* 返回 0=已被发送过(并发/重复调度双发的闸门)。发送失败由调用方 clearSmsSent 归还。
|
||||
*/
|
||||
@org.springframework.transaction.annotation.Transactional
|
||||
@org.springframework.data.jpa.repository.Modifying
|
||||
@org.springframework.data.jpa.repository.Query(
|
||||
"update Notice n set n.smsSentAt = :sentAt where n.id = :id and n.smsSentAt is null")
|
||||
int markSmsSent(@Param("id") Integer id, @Param("sentAt") LocalDateTime sentAt);
|
||||
|
||||
/** 发送失败归还认领(下轮补发调度可重试) */
|
||||
@org.springframework.transaction.annotation.Transactional
|
||||
@org.springframework.data.jpa.repository.Modifying
|
||||
@org.springframework.data.jpa.repository.Query(
|
||||
"update Notice n set n.smsSentAt = null where n.id = :id and n.smsSentAt is not null")
|
||||
int clearSmsSent(@Param("id") Integer id);
|
||||
|
||||
/**
|
||||
* 到点待补发短信清单(§3.2 SmsCatchupJob 扫描):已发布 + 要发短信 + 从未发过 + 已到定时点
|
||||
* (无定时点即发;覆盖"审批通过早于定时点被跳过"的行——BP-R5-2 短信永久丢失缺口)。
|
||||
*/
|
||||
@Query("select n from Notice n where n.status = 1 and n.smsFlag = 1 and n.smsSentAt is null"
|
||||
+ " and (n.timingSendTime is null or n.timingSendTime <= :now) order by n.id asc")
|
||||
List<Notice> findSmsDue(@Param("now") LocalDateTime now,
|
||||
org.springframework.data.domain.Pageable pageable);
|
||||
|
||||
/**
|
||||
* 已发布且已到点(定时发送未到点不计入)的通知数,用于用户端未读数统计。
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,225 @@
|
||||
package com.yunhai.notice.service.flow;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.yunhai.notice.entity.Notice;
|
||||
import com.yunhai.notice.entity.NoticeFlowEvent;
|
||||
import com.yunhai.notice.enums.FlowAuditStatusEnum;
|
||||
import com.yunhai.notice.enums.NoticeStatusEnum;
|
||||
import com.yunhai.notice.repository.NoticeFlowEventRepository;
|
||||
import com.yunhai.notice.repository.NoticeRepository;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.dao.DataIntegrityViolationException;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Iterator;
|
||||
|
||||
/**
|
||||
* 流程中心回调事件处理(方案 §5.3,svc-hall FlowCallbackService 平移 + 5xx 语义修订 D2)。<br>
|
||||
* 返回语义(免对账核心,契约冻结):<b>瞬时失败抛 {@link TransientCallbackException} → HTTP 5xx</b>
|
||||
* (flow-center 持续重试追平);毒 JSON/缺字段/去重命中/乱序丢弃/办件不属本应用 → 正常返回(HTTP 200)。
|
||||
* 事件映射:submitted/task.created/task.handled→10;completed→20(置 status=1 + trySendSms 后置);
|
||||
* rejected→30;withdrawn→40。乱序闸门:instanceVersion 严格小于已消费版本即丢弃
|
||||
* (等于不丢——submitted 与 task.created 天然同版本,且不同事件同版本幂等安全)。
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class FlowCallbackService {
|
||||
|
||||
/** 瞬时失败标记(DB 异常/锁冲突等可重试治愈的故障)——controller 据此回 5xx */
|
||||
public static class TransientCallbackException extends RuntimeException {
|
||||
public TransientCallbackException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
}
|
||||
|
||||
private final NoticeRepository noticeRepository;
|
||||
private final NoticeFlowEventRepository eventRepository;
|
||||
private final com.yunhai.notice.service.sms.SmsSendService smsSendService;
|
||||
private final ObjectMapper objectMapper;
|
||||
|
||||
/** 处理一条回调推送体(已过验签过滤器)。 */
|
||||
@Transactional
|
||||
public void handle(String body) {
|
||||
JsonNode payload;
|
||||
try {
|
||||
payload = objectMapper.readTree(body);
|
||||
} catch (Exception e) {
|
||||
// 协议毒消息:不可重试,回 200 防无限重放
|
||||
log.warn("[notice-flow] 回调体非 JSON(丢弃):{}",
|
||||
body != null && body.length() > 200 ? body.substring(0, 200) + "..." : body);
|
||||
return;
|
||||
}
|
||||
String eventId = text(payload, "eventId");
|
||||
String event = text(payload, "event");
|
||||
String bizType = text(payload, "bizType");
|
||||
String bizId = text(payload, "bizId");
|
||||
Long instanceId = longVal(payload, "instanceId");
|
||||
Integer instanceVersion = intVal(payload, "instanceVersion");
|
||||
if (!StringUtils.hasText(eventId) || !StringUtils.hasText(event)
|
||||
|| !StringUtils.hasText(bizType) || !StringUtils.hasText(bizId)) {
|
||||
log.warn("[notice-flow] 回调缺必要字段(丢弃):event={} eventId={}", event, eventId);
|
||||
return; // 协议毒消息 → 200
|
||||
}
|
||||
if ("ping".equals(event)) {
|
||||
return; // 注册探活回声(本不应到这——过滤器已直接 200,防御性兜底)
|
||||
}
|
||||
if (!FlowCenterClient.BIZ_TYPE.equals(bizType)) {
|
||||
log.warn("[notice-flow] 回调办件不属本应用(丢弃):bizType={} eventId={}", bizType, eventId);
|
||||
return; // 不可重试事件 → 200
|
||||
}
|
||||
// eventId 去重(uk 兜底并发):重复投递在持续重试语义下必然发生,幂等跳过
|
||||
if (eventRepository.existsByEventId(eventId)) {
|
||||
log.debug("[notice-flow] 重复投递跳过:eventId={}", eventId);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
NoticeFlowEvent row = new NoticeFlowEvent();
|
||||
row.setEventId(eventId);
|
||||
row.setEvent(event);
|
||||
row.setSchId(intVal(payload, "schId"));
|
||||
row.setInstanceId(instanceId);
|
||||
row.setReceiveTime(LocalDateTime.now());
|
||||
row.setPayloadJson(body);
|
||||
eventRepository.saveAndFlush(row);
|
||||
} catch (DataIntegrityViolationException e) {
|
||||
log.debug("[notice-flow] 并发重复投递(uk 命中)跳过:eventId={}", eventId);
|
||||
return; // 事务回滚无副作用(尚未写 notice),重复投递 → 200
|
||||
}
|
||||
|
||||
Integer noticeId;
|
||||
try {
|
||||
noticeId = Integer.valueOf(bizId.trim());
|
||||
} catch (NumberFormatException e) {
|
||||
log.warn("[notice-flow] 回调 bizId 非法(丢弃):{}", bizId);
|
||||
return; // 协议毒消息 → 200
|
||||
}
|
||||
// 行锁串行化:并发推送(flow-center 推送池)对同一通知的处理排队,防丢更新
|
||||
Notice notice = noticeRepository.findByIdForUpdate(noticeId).orElse(null);
|
||||
if (notice == null || !StringUtils.hasText(notice.getFlowGuid())) {
|
||||
log.warn("[notice-flow] 回调通知不存在或未绑流程(丢弃):notice={}", bizId);
|
||||
return; // 不可重试 → 200
|
||||
}
|
||||
// 乱序闸门:早于已消费版本的迟到事件直接丢弃(重复eventId已被上一道闸拦下)
|
||||
if (instanceVersion != null && notice.getLastInstanceVersion() != null
|
||||
&& instanceVersion < notice.getLastInstanceVersion()) {
|
||||
log.info("[notice-flow] 乱序事件丢弃:notice={} eventVersion={} last={}",
|
||||
noticeId, instanceVersion, notice.getLastInstanceVersion());
|
||||
return;
|
||||
}
|
||||
try {
|
||||
advance(notice, event, instanceVersion, payload);
|
||||
} catch (TransientCallbackException e) {
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
// DB 故障/锁冲突等瞬时失败 → 5xx 让 flow-center 重试追平(免对账核心语义)
|
||||
throw new TransientCallbackException("回调状态推进失败:notice=" + noticeId + " event=" + event, e);
|
||||
}
|
||||
}
|
||||
|
||||
/** 状态推进(幂等:同一事件重放由 eventId 去重拦截,此处只需正确覆盖目标态) */
|
||||
private void advance(Notice notice, String event, Integer instanceVersion, JsonNode payload) {
|
||||
Integer target;
|
||||
switch (event) {
|
||||
case "flow.completed":
|
||||
target = FlowAuditStatusEnum.APPROVED.getCode();
|
||||
break;
|
||||
case "flow.rejected":
|
||||
target = FlowAuditStatusEnum.REJECTED.getCode();
|
||||
break;
|
||||
case "flow.withdrawn":
|
||||
target = FlowAuditStatusEnum.WITHDRAWN.getCode();
|
||||
break;
|
||||
case "flow.submitted":
|
||||
case "flow.task.created":
|
||||
case "flow.task.handled":
|
||||
target = FlowAuditStatusEnum.APPROVING.getCode();
|
||||
break;
|
||||
default:
|
||||
log.warn("[notice-flow] 未知事件(丢弃):{}", event);
|
||||
return; // 未知事件码:不可重试 → 200
|
||||
}
|
||||
// P1-3 终态不回退守卫:终态事件与最后一个 task.handled 同 instanceVersion,若 handled
|
||||
// 在 completed/rejected 之后落库(推送池并发不保序),无守卫会把 20/30 打回 10 并覆盖结果。
|
||||
// 命中守卫记 log 后正常返回(200,不触发 flow-center 重试——重试也改变不了完成顺序)。
|
||||
// R4 重提不冲突:编辑保存先本地置 audit=0,新一轮事件到达时行已非终态。
|
||||
if (isTerminal(notice.getAuditStatus())) {
|
||||
if (!isTerminal(target)) {
|
||||
log.warn("[notice-flow] 终态不回退:notice={} audit={} 拒绝非终态事件 {}(v{})",
|
||||
notice.getId(), notice.getAuditStatus(), event, instanceVersion);
|
||||
return;
|
||||
}
|
||||
if (StringUtils.hasText(notice.getFlowResultJson())) {
|
||||
log.warn("[notice-flow] 终态结果已落定:notice={} audit={} 拒绝覆盖 flow_result_json(事件 {})",
|
||||
notice.getId(), notice.getAuditStatus(), event);
|
||||
return;
|
||||
}
|
||||
}
|
||||
notice.setAuditStatus(target);
|
||||
if (instanceVersion != null) {
|
||||
notice.setLastInstanceVersion(instanceVersion);
|
||||
}
|
||||
// 终态明细快照(result/opinion/rejectNode,详情页进度卡片展示)
|
||||
if (target == FlowAuditStatusEnum.APPROVED.getCode()
|
||||
|| target == FlowAuditStatusEnum.REJECTED.getCode()
|
||||
|| target == FlowAuditStatusEnum.WITHDRAWN.getCode()) {
|
||||
JsonNode data = payload.get("data");
|
||||
String snapshot = data == null || data.isNull() ? null : data.toString();
|
||||
notice.setFlowResultJson(snapshot);
|
||||
}
|
||||
boolean justPublished = false;
|
||||
if (target == FlowAuditStatusEnum.APPROVED.getCode()) {
|
||||
// 审核通过 = 正式发布:置 status=1(用户端自此可见)+ 发布后置(短信后移到此刻)
|
||||
if (notice.getStatus() == null || notice.getStatus() != NoticeStatusEnum.PUBLISHED.getCode()) {
|
||||
notice.setStatus(NoticeStatusEnum.PUBLISHED.getCode());
|
||||
justPublished = true;
|
||||
}
|
||||
}
|
||||
noticeRepository.saveAndFlush(notice);
|
||||
if (justPublished) {
|
||||
sendSmsAfterPublish(notice);
|
||||
}
|
||||
}
|
||||
|
||||
/** 审核通过后的短信后置(绑流程通知 create 时不发,方案 §5.2 短信时机后移) */
|
||||
private void sendSmsAfterPublish(Notice notice) {
|
||||
if (notice.getSmsFlag() == null || notice.getSmsFlag() != 1) {
|
||||
return;
|
||||
}
|
||||
// 与直发链路 trySendSms 的 isImmediatePublish 语义对齐:定时未到点的通知此刻不发
|
||||
// (可见性已生效),到点由 SmsCatchupJob 补发(§3.2 修 BP-R5-2 短信永久丢失缺口)
|
||||
if (notice.getTimingSendTime() != null
|
||||
&& notice.getTimingSendTime().isAfter(LocalDateTime.now())) {
|
||||
return;
|
||||
}
|
||||
smsSendService.sendOnce(notice);
|
||||
}
|
||||
|
||||
/** 审批终态(20 通过 / 30 驳回 / 40 撤回)——终态行的状态与结果明细只允许被新一轮(本地先置 0)改写 */
|
||||
private static boolean isTerminal(Integer auditStatus) {
|
||||
return auditStatus != null
|
||||
&& (auditStatus == FlowAuditStatusEnum.APPROVED.getCode()
|
||||
|| auditStatus == FlowAuditStatusEnum.REJECTED.getCode()
|
||||
|| auditStatus == FlowAuditStatusEnum.WITHDRAWN.getCode());
|
||||
}
|
||||
|
||||
private static String text(JsonNode node, String field) {
|
||||
JsonNode v = node.get(field);
|
||||
return v == null || v.isNull() ? null : v.asText();
|
||||
}
|
||||
|
||||
private static Long longVal(JsonNode node, String field) {
|
||||
JsonNode v = node.get(field);
|
||||
return v == null || v.isNull() ? null : v.asLong();
|
||||
}
|
||||
|
||||
private static Integer intVal(JsonNode node, String field) {
|
||||
JsonNode v = node.get(field);
|
||||
return v == null || v.isNull() ? null : v.asInt();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
package com.yunhai.notice.service.flow;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.yunhai.notice.model.flow.FlowModels;
|
||||
import com.yunhai.platform.appauth.AppSignInterceptor;
|
||||
import com.yunhai.platform.appauth.LocalAppIdentityProvider;
|
||||
import com.yunhai.platform.openapi.TargetSpec;
|
||||
import com.yunhai.platform.openapi.YschOpenCall;
|
||||
import com.yunhai.platform.apistd.BizException;
|
||||
import com.yunhai.platform.utils.exception.ErrorCode;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.ObjectProvider;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* FlowClient 默认实现:直接构建在 Tier 0 {@link YschOpenCall} 之上(两级模型纪律 1"先 Tier 0",
|
||||
* 不手写 RestTemplate/签名代码)。目标地址单一事实源 = {@code notice.flow.base-url}(ad-hoc
|
||||
* TargetSpec、base-path 空=裸地址直连,与 flow-center 无 context-path 的部署一致);
|
||||
* 签名/信封解析/错误映射全部由 YschOpenCall 统一承载(401/403→DException、code!=0→DException、
|
||||
* 其他传输错→OpenApiException)。
|
||||
* {@code notice.flow.enabled=false} 时全部方法抛业务异常(文案含"流程中心未接入")供前端降级。
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class FlowCenterClient implements FlowClient {
|
||||
|
||||
/** flow-center 业务类型常量(契约冻结:bizType="notice"、bizId=notice.id) */
|
||||
public static final String BIZ_TYPE = "notice";
|
||||
|
||||
private static final String NOT_CONNECTED = "流程中心未接入,该功能不可用";
|
||||
|
||||
private final NoticeFlowProperties properties;
|
||||
private final YschOpenCall openCall;
|
||||
|
||||
public FlowCenterClient(NoticeFlowProperties properties,
|
||||
ObjectProvider<YschOpenCall> openCallProvider,
|
||||
ObjectProvider<LocalAppIdentityProvider> identityProvider,
|
||||
ObjectMapper objectMapper) {
|
||||
this.properties = properties;
|
||||
YschOpenCall call = openCallProvider.getIfAvailable();
|
||||
if (call == null) {
|
||||
// 兜底自建(正常路径由 yh-openapi-starter 装配 YschOpenCall bean);identity 缺失时
|
||||
// AppSignInterceptor 自动跳过签名(请求裸发,enforce 端会 401——配置问题尽早暴露)
|
||||
call = new YschOpenCall(new com.yunhai.platform.openapi.YschCallProperties(), objectMapper,
|
||||
(host, basePath) -> new AppSignInterceptor(identityProvider.getIfAvailable(), host, basePath));
|
||||
}
|
||||
this.openCall = call;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<FlowModels.FlowSummaryVo> listFlows(Integer schId) {
|
||||
requireEnabled();
|
||||
return openCall.getList(target(), "/oapi/flow/list", params("schId", schId),
|
||||
FlowModels.FlowSummaryVo.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FlowModels.ApplyResultVo apply(Integer schId, FlowModels.ApplyBody body) {
|
||||
requireEnabled();
|
||||
return openCall.post(target(), "/oapi/flow/apply", params("schId", schId), body,
|
||||
FlowModels.ApplyResultVo.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FlowModels.InstanceVo getInstanceByBiz(Integer schId, String bizType, String bizId) {
|
||||
requireEnabled();
|
||||
Map<String, String> query = new HashMap<>();
|
||||
query.put("schId", String.valueOf(schId));
|
||||
query.put("bizType", bizType);
|
||||
query.put("bizId", bizId);
|
||||
return openCall.get(target(), "/oapi/flow/instance", query, FlowModels.InstanceVo.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FlowModels.CallbackRegResultVo registerCallback(Integer schId, FlowModels.CallbackRegBody body) {
|
||||
requireEnabled();
|
||||
return openCall.post(target(), "/oapi/flow/callback/reg", params("schId", schId), body,
|
||||
FlowModels.CallbackRegResultVo.class);
|
||||
}
|
||||
|
||||
private TargetSpec target() {
|
||||
// base-path 空:本地/容器裸地址直连(两级模型 §2.2 对齐不变式的现行约定)
|
||||
return TargetSpec.of(properties.getBaseUrl(), "");
|
||||
}
|
||||
|
||||
private void requireEnabled() {
|
||||
if (!properties.isEnabled()) {
|
||||
throw new BizException(ErrorCode.FORBIDDEN, NOT_CONNECTED);
|
||||
}
|
||||
}
|
||||
|
||||
private static Map<String, String> params(String k, Object v) {
|
||||
Map<String, String> m = new HashMap<>();
|
||||
if (k != null && v != null) {
|
||||
m.put(k, String.valueOf(v));
|
||||
}
|
||||
return m;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.yunhai.notice.service.flow;
|
||||
|
||||
import com.yunhai.notice.model.flow.FlowModels;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 流程中心出站接缝(Notice 首接方案 §5.1,方法面与 svc-hall FlowCenterClient 一致)。
|
||||
* 接口保留三重意义:防依赖(业务层不感知 YschOpenCall)、可测试(fake 注入)、可降级(enabled 开关)。
|
||||
*/
|
||||
public interface FlowClient {
|
||||
|
||||
/** 已发布流程列表(编辑页"审核流程"选择器数据源) */
|
||||
List<FlowModels.FlowSummaryVo> listFlows(Integer schId);
|
||||
|
||||
/** 代发起(biz uk 幂等:重复 apply 同办件;30/40 态 R4 重启推进) */
|
||||
FlowModels.ApplyResultVo apply(Integer schId, FlowModels.ApplyBody body);
|
||||
|
||||
/** 按业务键查办件(进度卡片/放行判定/对账兜底;不存在返回 null) */
|
||||
FlowModels.InstanceVo getInstanceByBiz(Integer schId, String bizType, String bizId);
|
||||
|
||||
/** 回调注册(下发 secret;重复注册会轮换 secret——仅在 reg 缺失时调用) */
|
||||
FlowModels.CallbackRegResultVo registerCallback(Integer schId, FlowModels.CallbackRegBody body);
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
package com.yunhai.notice.service.flow;
|
||||
|
||||
import com.yunhai.notice.entity.Notice;
|
||||
import com.yunhai.notice.model.flow.FlowModels;
|
||||
import com.yunhai.platform.apistd.BizException;
|
||||
import com.yunhai.platform.utils.exception.ErrorCode;
|
||||
import com.yunhai.platform.utils.model.BoaUser;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* 未发布通知(status=0,审核载体)的详情放行守卫(方案 §5.5,V2.0 B.4#8 同构)。
|
||||
* 仅三类人可见:提交人本人(publisherAccount)/ 本校管理员(type=1 或 roleId∈{2,5,7})/
|
||||
* 该办件流程办理人(instance.assigneeIds 含当前用户,60s 短缓存——审批中途换人不实时,可接受)。
|
||||
* 其余用户查询即"通知不存在或未发布"(查不到语义,不泄露存在性)。
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class NoticeFlowGuard {
|
||||
|
||||
/** 管理员角色白名单(校级管理员/分管领导等,与既有菜单权限体系对齐) */
|
||||
private static final List<Integer> ADMIN_ROLE_IDS = Arrays.asList(2, 5, 7);
|
||||
|
||||
private static final long ASSIGNEE_CACHE_MS = 60_000L;
|
||||
|
||||
private final FlowClient flowClient;
|
||||
private final NoticeFlowProperties properties;
|
||||
|
||||
private final Map<Long, CachedAssignees> assigneeCache = new ConcurrentHashMap<>();
|
||||
|
||||
private static class CachedAssignees {
|
||||
final List<Integer> userIds;
|
||||
final long expireAt;
|
||||
|
||||
CachedAssignees(List<Integer> userIds) {
|
||||
this.userIds = userIds;
|
||||
this.expireAt = System.currentTimeMillis() + ASSIGNEE_CACHE_MS;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验当前用户可查看未发布通知;不可见抛 FORBIDDEN(文案=查不到语义)。
|
||||
* status=1 已发布通知不走本守卫(既有行为零变化)。
|
||||
*/
|
||||
public void requireUnpublishedVisible(Notice notice, BoaUser user) {
|
||||
if (notice == null || user == null) {
|
||||
throw notFound();
|
||||
}
|
||||
// 1) 提交人本人
|
||||
if (StringUtils.hasText(notice.getPublisherAccount())
|
||||
&& notice.getPublisherAccount().equals(user.getAccount())) {
|
||||
return;
|
||||
}
|
||||
// 2) 本校管理员(type=1 校管 或 roleId 命中白名单)
|
||||
if (isAdmin(user)) {
|
||||
return;
|
||||
}
|
||||
// 3) 该办件办理人(assigneeIds 含当前用户 id;flowInstanceId 缺失=尚未提交成功,仅前两类可见)
|
||||
if (notice.getFlowInstanceId() != null && properties.isEnabled()
|
||||
&& currentAssignees(notice).contains(user.getId())) {
|
||||
return;
|
||||
}
|
||||
throw notFound();
|
||||
}
|
||||
|
||||
private boolean isAdmin(BoaUser user) {
|
||||
if (user.getType() != null && user.getType() == 1) {
|
||||
return true;
|
||||
}
|
||||
if (user.getRoleIds() != null) {
|
||||
for (Integer roleId : user.getRoleIds()) {
|
||||
if (roleId != null && ADMIN_ROLE_IDS.contains(roleId)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private List<Integer> currentAssignees(Notice notice) {
|
||||
long now = System.currentTimeMillis();
|
||||
CachedAssignees cached = assigneeCache.get(notice.getFlowInstanceId());
|
||||
if (cached != null && cached.expireAt > now) {
|
||||
return cached.userIds == null ? java.util.Collections.emptyList() : cached.userIds;
|
||||
}
|
||||
List<Integer> assignees = null;
|
||||
try {
|
||||
FlowModels.InstanceVo instance = flowClient.getInstanceByBiz(
|
||||
notice.getSchId(), FlowCenterClient.BIZ_TYPE, String.valueOf(notice.getId()));
|
||||
if (instance != null) {
|
||||
assignees = instance.getAssigneeIds();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// 流程中心不可达:fail-closed(不放行),日志留痕
|
||||
log.warn("[notice-flow] 办理人查询失败(fail-closed):notice={} {}", notice.getId(), e.toString());
|
||||
}
|
||||
assigneeCache.put(notice.getFlowInstanceId(),
|
||||
new CachedAssignees(assignees == null ? java.util.Collections.emptyList() : assignees));
|
||||
return assignees == null ? java.util.Collections.emptyList() : assignees;
|
||||
}
|
||||
|
||||
private BizException notFound() {
|
||||
return new BizException(ErrorCode.FORBIDDEN, "通知不存在或未发布");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.yunhai.notice.service.flow;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 通知-流程中心接缝配置(notice.flow.* / notice.front.*)。
|
||||
*/
|
||||
@Data
|
||||
@Component
|
||||
@ConfigurationProperties(prefix = "notice.flow")
|
||||
public class NoticeFlowProperties {
|
||||
|
||||
/** 是否接入流程中心(false=编辑页选择器隐藏、FlowClient 全部抛业务异常降级) */
|
||||
private boolean enabled = true;
|
||||
|
||||
/** flow-center 基址(Tier 0 目标;本地 http://localhost:8085,生产由 projman 注入) */
|
||||
private String baseUrl = "http://localhost:8085";
|
||||
|
||||
/**
|
||||
* 本应用对外可达基址(回调注册用):flow-center 探活与事件推送都打这里。
|
||||
* 默认回落 baseUrl 同端口的本服务直连地址;生产经网关时由 projman 注入(如 http://notice:8070/notice)。
|
||||
*/
|
||||
private String callbackBase = "http://localhost:8101";
|
||||
|
||||
/** 回调路径(挂在本服务上,FlowCallbackVerifyFilter 只拦 /callback/*) */
|
||||
private String callbackPath = "/callback/flow";
|
||||
|
||||
/** Notice 前端基址(bizUrl 拼接:{front-base}/#/list/detail?serid={id},审批人点链接回通知详情) */
|
||||
private String frontBaseUrl = "http://localhost:8077";
|
||||
}
|
||||
@@ -0,0 +1,285 @@
|
||||
package com.yunhai.notice.service.flow;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.yunhai.notice.entity.Notice;
|
||||
import com.yunhai.notice.entity.NoticeFlowReg;
|
||||
import com.yunhai.notice.entity.UpFile;
|
||||
import com.yunhai.notice.enums.FlowAuditStatusEnum;
|
||||
import com.yunhai.notice.model.flow.FlowModels;
|
||||
import com.yunhai.notice.repository.NoticeFlowRegRepository;
|
||||
import com.yunhai.notice.repository.NoticeRepository;
|
||||
import com.yunhai.notice.repository.UpFileRepository;
|
||||
import com.yunhai.platform.appauth.AppAuthProperties;
|
||||
import com.yunhai.platform.apistd.BizException;
|
||||
import com.yunhai.platform.auth.spring.CurrentBoaUser;
|
||||
import com.yunhai.platform.utils.exception.ErrorCode;
|
||||
import com.yunhai.platform.utils.model.BoaUser;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.support.TransactionSynchronizationAdapter;
|
||||
import org.springframework.transaction.support.TransactionSynchronizationManager;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 通知-流程中心接合服务:提交/重提(D9 AFTER_COMMIT 出站)、回调注册管理、进度组装。
|
||||
* 提交语义(方案 §5.2):apply 幂等(bizId=notice.id),失败保持 0 待提交可重推;
|
||||
* 10 审批中禁止重复提交/编辑/删除(删除需先撤回)。
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class NoticeFlowService {
|
||||
|
||||
private final NoticeRepository noticeRepository;
|
||||
private final NoticeFlowRegRepository regRepository;
|
||||
private final UpFileRepository upFileRepository;
|
||||
private final FlowClient flowClient;
|
||||
private final NoticeFlowProperties properties;
|
||||
private final ObjectMapper objectMapper;
|
||||
private final AppAuthProperties appAuthProperties;
|
||||
private final CurrentBoaUser currentBoaUser;
|
||||
private final NoticeFlowGuard noticeFlowGuard;
|
||||
|
||||
/**
|
||||
* 注册后事务提交了再提交审核(D9:apply 出站不进 DB 事务,防 HTTP 长调用拖住连接);
|
||||
* 无活动事务时立即执行(测试/兜底)。
|
||||
* <p>E2E 实测教训:afterCommit 回调若留在原请求线程执行,OSIV 绑定的 EntityManager
|
||||
* 已随提交关闭,后续 repository 写会话静默丢失(有成功日志但库无行)——故提交动作
|
||||
* 一律切到独立线程(干净事务 + 无 ThreadLocal 残留),提交人身份在请求线程先捕获透传。
|
||||
*/
|
||||
public void submitAfterCommit(Integer noticeId) {
|
||||
final BoaUser user = currentUser();
|
||||
Runnable task = () -> trySubmitQuietly(noticeId, user);
|
||||
if (TransactionSynchronizationManager.isSynchronizationActive()) {
|
||||
TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronizationAdapter() {
|
||||
@Override
|
||||
public void afterCommit() {
|
||||
SUBMIT_EXECUTOR.submit(task);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
task.run();
|
||||
}
|
||||
}
|
||||
|
||||
/** 提交动作专用单线程池(串行化避免并发双 apply;uk 幂等兜底) */
|
||||
private static final java.util.concurrent.ExecutorService SUBMIT_EXECUTOR =
|
||||
java.util.concurrent.Executors.newSingleThreadExecutor(r -> {
|
||||
Thread t = new Thread(r, "notice-flow-submit");
|
||||
t.setDaemon(true);
|
||||
return t;
|
||||
});
|
||||
|
||||
/** 提交失败静默保持 0 待提交(行已落库不回滚;列表"待提交"态即提示,编辑页可重推) */
|
||||
private void trySubmitQuietly(Integer noticeId, BoaUser user) {
|
||||
try {
|
||||
trySubmitFlow(noticeId, user);
|
||||
} catch (Exception e) {
|
||||
log.warn("[notice-flow] 提交审核失败(保持待提交,可重推):notice={} {}", noticeId, e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 提交/重提审核(幂等入口:编辑页重提按钮 / create 后置共用)。
|
||||
* audit=0/30/40 可提交;10 审批中拒绝;apply 成功回填 flow_instance_id + audit=10。
|
||||
* apply 失败抛业务异常,notice 行保持 0 待提交(不回滚已落库的编辑内容)。
|
||||
*/
|
||||
public void trySubmitFlow(Integer noticeId) {
|
||||
trySubmitFlow(noticeId, currentUser());
|
||||
}
|
||||
|
||||
/** 提交/重提(带访问者——控制器直传登录人,BP-R5-3 守卫入口) */
|
||||
public void trySubmitFlow(Integer noticeId, BoaUser user) {
|
||||
Notice notice = requireNotice(noticeId);
|
||||
// BP-R5-3:Trace/TrySubmit 原先仅验存在性,任意登录用户可对他人通知触发重提——补
|
||||
// NoticeFlowGuard 三分支(提交人/管理员/办理人),与 Detail 的守卫口径对齐
|
||||
noticeFlowGuard.requireUnpublishedVisible(notice, user);
|
||||
if (!StringUtils.hasText(notice.getFlowGuid())) {
|
||||
throw new BizException(ErrorCode.PARAM_ERROR, "该通知未绑定审核流程");
|
||||
}
|
||||
Integer audit = notice.getAuditStatus();
|
||||
if (audit != null && audit == FlowAuditStatusEnum.APPROVING.getCode()) {
|
||||
throw new BizException(ErrorCode.FORBIDDEN, "审批中,不可重复提交,请先撤回");
|
||||
}
|
||||
ensureRegistered(notice);
|
||||
FlowModels.ApplyBody body = buildApplyBody(notice, user);
|
||||
FlowModels.ApplyResultVo result = flowClient.apply(notice.getSchId(), body);
|
||||
// E2E 实测教训:此处曾整实体 save——apply 出站期间回调事件可能已并发推进
|
||||
// (submitted 先行置 10 / completed 置 20),旧快照盲写会把状态打回;改为窄列原子更新,
|
||||
// 且 audit=20(已通过)不回退(apply 返回晚于 completed 送达的合法场景)
|
||||
noticeRepository.markApproving(noticeId, result.getInstanceId());
|
||||
log.info("[notice-flow] 提交审核成功:notice={} instance={} duplicated={}",
|
||||
noticeId, result.getInstanceId(), result.isDuplicated());
|
||||
}
|
||||
|
||||
/**
|
||||
* 回调注册:仅 reg 缺失时注册并落 secret。<b>绝不重复调用</b>——flow-center 重复注册会轮换
|
||||
* secret 导致已存 secret 验签失配;失配恢复手段=管理端重新保存绑定(删除 reg 行后重提)。
|
||||
*/
|
||||
void ensureRegistered(Notice notice) {
|
||||
Integer schId = notice.getSchId();
|
||||
String flowGuid = notice.getFlowGuid();
|
||||
String appKey = appAuthProperties.getAppKey();
|
||||
NoticeFlowReg reg = regRepository
|
||||
.findBySchIdAndAppKeyAndFlowGuid(schId, appKey, flowGuid)
|
||||
.orElse(null);
|
||||
if (reg != null && StringUtils.hasText(reg.getSecret()) && reg.getStatus() == 0) {
|
||||
return;
|
||||
}
|
||||
FlowModels.CallbackRegBody body = new FlowModels.CallbackRegBody();
|
||||
body.setFlowGuid(flowGuid);
|
||||
body.setCallbackUrl(callbackUrl());
|
||||
FlowModels.CallbackRegResultVo result = flowClient.registerCallback(schId, body);
|
||||
if (reg == null) {
|
||||
reg = new NoticeFlowReg();
|
||||
reg.setSchId(schId);
|
||||
reg.setAppKey(appKey);
|
||||
reg.setFlowGuid(flowGuid);
|
||||
}
|
||||
reg.setCallbackUrl(callbackUrl());
|
||||
reg.setEventTypes(null);
|
||||
reg.setSecret(result.getSecret());
|
||||
reg.setStatus(0);
|
||||
regRepository.save(reg);
|
||||
}
|
||||
|
||||
/** apply 出参组装(契约冻结:bizId=notice.id、bizUrl 前端详情、快照只收摘要不收富文本正文) */
|
||||
FlowModels.ApplyBody buildApplyBody(Notice notice, BoaUser user) {
|
||||
FlowModels.ApplyBody body = new FlowModels.ApplyBody();
|
||||
body.setFlowGuid(notice.getFlowGuid());
|
||||
body.setBizType(FlowCenterClient.BIZ_TYPE);
|
||||
body.setBizId(String.valueOf(notice.getId()));
|
||||
body.setBizTitle(notice.getTitle());
|
||||
body.setBizUrl(properties.getFrontBaseUrl() + "/#/list/detail?serid=" + notice.getId());
|
||||
body.setBizSnapshot(buildSnapshot(notice));
|
||||
if (user != null) {
|
||||
body.setSubmitterId(user.getId());
|
||||
body.setSubmitterName(StringUtils.hasText(user.getName()) ? user.getName() : user.getAccount());
|
||||
}
|
||||
return body;
|
||||
}
|
||||
|
||||
/** 业务摘要:{title, summary(纯文本截 300 字), attachmentNames[]}——富文本正文不传(概览 §十边界) */
|
||||
private Map<String, Object> buildSnapshot(Notice notice) {
|
||||
Map<String, Object> snapshot = new LinkedHashMap<>();
|
||||
snapshot.put("title", notice.getTitle());
|
||||
snapshot.put("summary", plainSummary(notice.getContent()));
|
||||
List<String> names = new ArrayList<>();
|
||||
for (UpFile f : upFileRepository.findByTopicTypeAndTopicId("notice", notice.getId())) {
|
||||
if (StringUtils.hasText(f.getFileTrueName())) {
|
||||
names.add(f.getFileTrueName());
|
||||
}
|
||||
}
|
||||
snapshot.put("attachmentNames", names);
|
||||
return snapshot;
|
||||
}
|
||||
|
||||
/** 富文本剥标签取纯文本摘要(截断 300 字) */
|
||||
private String plainSummary(String content) {
|
||||
if (!StringUtils.hasText(content)) {
|
||||
return "";
|
||||
}
|
||||
String text = content.replaceAll("<[^>]+>", "").replaceAll(" ", " ").trim();
|
||||
return text.length() > 300 ? text.substring(0, 300) : text;
|
||||
}
|
||||
|
||||
/** 进度组装(trace 接口):auditStatus/status/version/trace[]/currentNodes/nodeSummary;未绑流程返回未接入语义 */
|
||||
public Map<String, Object> buildTrace(Integer noticeId) {
|
||||
return buildTrace(noticeId, currentUser());
|
||||
}
|
||||
|
||||
/**
|
||||
* 进度组装(带访问者,BP-R5-3):未发布通知(status=0,审核载体)仅提交人/管理员/办理人
|
||||
* 可见轨迹与驳回意见(NoticeFlowGuard 三分支);已发布(status=1)内容本就公开,登录即可看。
|
||||
*/
|
||||
public Map<String, Object> buildTrace(Integer noticeId, BoaUser user) {
|
||||
Notice notice = requireNotice(noticeId);
|
||||
if (notice.getStatus() == null || notice.getStatus() != 1) {
|
||||
noticeFlowGuard.requireUnpublishedVisible(notice, user);
|
||||
}
|
||||
Map<String, Object> result = new LinkedHashMap<>();
|
||||
result.put("bound", StringUtils.hasText(notice.getFlowGuid()));
|
||||
result.put("flowGuid", notice.getFlowGuid());
|
||||
result.put("flowInstanceId", notice.getFlowInstanceId());
|
||||
result.put("auditStatus", notice.getAuditStatus());
|
||||
result.put("auditStatusDesc", FlowAuditStatusEnum.descOf(notice.getAuditStatus()));
|
||||
result.put("status", notice.getStatus());
|
||||
if (!StringUtils.hasText(notice.getFlowGuid()) || notice.getAuditStatus() == null) {
|
||||
return result; // 未接入流程中心(编辑页/详情页据此隐藏进度卡片)
|
||||
}
|
||||
result.put("flowResult", parseJson(notice.getFlowResultJson()));
|
||||
if (properties.isEnabled()) {
|
||||
try {
|
||||
FlowModels.InstanceVo instance = flowClient.getInstanceByBiz(
|
||||
notice.getSchId(), FlowCenterClient.BIZ_TYPE, String.valueOf(notice.getId()));
|
||||
if (instance != null) {
|
||||
result.put("instanceStatus", instance.getStatus());
|
||||
result.put("version", instance.getVersion());
|
||||
result.put("nodeSummary", instance.getNodeSummary());
|
||||
result.put("currentNodes", instance.getCurrentNodes());
|
||||
result.put("assigneeIds", instance.getAssigneeIds());
|
||||
result.put("submitTime", instance.getSubmitTime());
|
||||
result.put("finishTime", instance.getFinishTime());
|
||||
result.put("trace", parseJson(instance.getTraceJson()));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// 进度查询失败不阻断详情:展示本地镜像态即可(流程中心停机时详情仍可用)
|
||||
log.warn("[notice-flow] 进度查询失败:notice={} {}", noticeId, e.toString());
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/** 编辑页"审核流程"选择器数据源(未启用返回空列表由前端隐藏) */
|
||||
public List<FlowModels.FlowSummaryVo> options(Integer schId) {
|
||||
if (!properties.isEnabled()) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
try {
|
||||
return flowClient.listFlows(schId);
|
||||
} catch (BizException e) {
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
log.warn("[notice-flow] 流程列表查询失败:{}", e.toString());
|
||||
throw new BizException(ErrorCode.INTERNAL_SERVER_ERROR, "审核流程列表获取失败,请稍后重试");
|
||||
}
|
||||
}
|
||||
|
||||
private BoaUser currentUser() {
|
||||
return currentBoaUser == null ? null : currentBoaUser.get();
|
||||
}
|
||||
|
||||
private Notice requireNotice(Integer noticeId) {
|
||||
return noticeRepository.findById(noticeId)
|
||||
.orElseThrow(() -> new BizException(ErrorCode.FORBIDDEN, "通知不存在: " + noticeId));
|
||||
}
|
||||
|
||||
private String callbackUrl() {
|
||||
String base = properties.getCallbackBase();
|
||||
if (base == null) {
|
||||
base = "";
|
||||
}
|
||||
while (base.endsWith("/")) {
|
||||
base = base.substring(0, base.length() - 1);
|
||||
}
|
||||
return base + properties.getCallbackPath();
|
||||
}
|
||||
|
||||
private JsonNode parseJson(String json) {
|
||||
if (!StringUtils.hasText(json)) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return objectMapper.readTree(json);
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -46,6 +46,7 @@ public class ClassService implements IClassService {
|
||||
if (!StringUtils.hasText(userClassHost)) {
|
||||
throw new BizException(ErrorCode.INTERNAL_SERVER_ERROR, "班级管理接口未配置(yh.open.userclass)");
|
||||
}
|
||||
|
||||
String url = userClassHost + "/oapi/DbClass/GetSchteaList?Group=" + schId;
|
||||
try {
|
||||
ResponseEntity<List<SchTeaList>> resp = restTemplate.exchange(
|
||||
|
||||
@@ -71,6 +71,9 @@ public class NoticeService implements INoticeService {
|
||||
@Autowired
|
||||
private SmsSender smsSender;
|
||||
|
||||
@Autowired
|
||||
private com.yunhai.notice.service.sms.SmsSendService smsSendService;
|
||||
|
||||
@Autowired
|
||||
private IFileService fileService;
|
||||
|
||||
@@ -80,7 +83,15 @@ public class NoticeService implements INoticeService {
|
||||
@Autowired
|
||||
private CurrentBoaUser currentBoaUser;
|
||||
|
||||
@Autowired
|
||||
private com.yunhai.notice.service.flow.NoticeFlowService noticeFlowService;
|
||||
|
||||
@Autowired
|
||||
private com.yunhai.notice.service.flow.NoticeFlowGuard noticeFlowGuard;
|
||||
|
||||
private static final int PUBLISHED = NoticeStatusEnum.PUBLISHED.getCode();
|
||||
private static final int UNPUBLISHED = NoticeStatusEnum.UNPUBLISHED.getCode();
|
||||
private static final int AUDIT_APPROVING = com.yunhai.notice.enums.FlowAuditStatusEnum.APPROVING.getCode();
|
||||
|
||||
/**
|
||||
* 当前登录人账号(来自平台 UserContextHolder,无登录态时为 null)。
|
||||
@@ -120,23 +131,50 @@ public class NoticeService implements INoticeService {
|
||||
entity.setId(null);
|
||||
entity.setDeptName(resolveDeptName(request));
|
||||
normalizeReceiveList(entity, request.getReceiveList());
|
||||
// 无草稿态:一律置为「已发布」;定时发送保留 timingSendTime,由查询侧按「已到点」过滤可见性
|
||||
entity.setStatus(PUBLISHED);
|
||||
// 发布分流(先审后发):绑 flowGuid → status=0 未发布(审核载体)+ audit=0 待提交,
|
||||
// 提交动作 AFTER_COMMIT 出站(D9:apply 不进 DB 事务,失败保持 0 可幂等重推);
|
||||
// 未绑 → 原直发链路一字不改(status=1 即发布)
|
||||
boolean flowBound = StringUtils.hasText(request.getFlowGuid());
|
||||
if (flowBound) {
|
||||
entity.setStatus(UNPUBLISHED);
|
||||
entity.setAuditStatus(com.yunhai.notice.enums.FlowAuditStatusEnum.PENDING_SUBMIT.getCode());
|
||||
entity.setFlowGuid(request.getFlowGuid().trim());
|
||||
} else {
|
||||
entity.setStatus(PUBLISHED);
|
||||
}
|
||||
entity.setPublisherAccount(currentAccount());
|
||||
entity.setPublisherName(currentName());
|
||||
entity.setSchId(currentSchId());
|
||||
entity.setIsPulled(0);
|
||||
entity.setReadCount(0);
|
||||
noticeRepository.save(entity);
|
||||
// 写入接收人关联表(非全员时)
|
||||
// 写入接收人关联表(非全员时;status=0 不可见,提前绑定无害)
|
||||
saveReceivers(entity);
|
||||
// 绑定附件(前端上传后回传的 fileIds 逗号串)
|
||||
fileService.bindToTopic(parseFileIds(request.getFileIds()), entity.getId());
|
||||
// 立即发布且开启短信时预留短信发送(真实通道后续接入)
|
||||
trySendSms(entity);
|
||||
if (flowBound) {
|
||||
// 短信时机后移:绑流程的通知 create 时不发,回调 completed 才发(审核通过才发)
|
||||
noticeFlowService.submitAfterCommit(entity.getId());
|
||||
} else {
|
||||
// 立即发布且开启短信时预留短信发送(真实通道后续接入)
|
||||
trySendSms(entity);
|
||||
}
|
||||
return entity.getId();
|
||||
}
|
||||
|
||||
/**
|
||||
* 未发布通知(status=0 审核载体)详情放行:仅提交人本人/本校管理员/该办件办理人可见,
|
||||
* 其余一律"通知不存在或未发布"(查不到语义)。status=1 已发布零变化。
|
||||
*/
|
||||
private void requireVisibleIfUnpublished(Integer serid) {
|
||||
Notice notice = noticeRepository.findById(serid).orElse(null);
|
||||
if (notice == null || notice.getStatus() == null
|
||||
|| notice.getStatus() == NoticeStatusEnum.PUBLISHED.getCode()) {
|
||||
return; // 不存在(沿用后续查询的报错)或已发布(既有行为)
|
||||
}
|
||||
noticeFlowGuard.requireUnpublishedVisible(notice, currentBoaUser.get());
|
||||
}
|
||||
|
||||
// ============================ 编辑 ============================
|
||||
|
||||
@Override
|
||||
@@ -145,6 +183,12 @@ public class NoticeService implements INoticeService {
|
||||
Objects.requireNonNull(id, "通知ID不得为空");
|
||||
Notice entity = noticeRepository.findById(id)
|
||||
.orElseThrow(() -> new BizException(ErrorCode.FORBIDDEN, "通知不存在: " + id));
|
||||
// 审批中锁定:防审批做一半被抽走(删除需先撤回);驳回/撤回态允许编辑后重提
|
||||
if (entity.getAuditStatus() != null && entity.getAuditStatus() == AUDIT_APPROVING) {
|
||||
throw new BizException(ErrorCode.FORBIDDEN, "审批中不可编辑,请先撤回");
|
||||
}
|
||||
boolean wasFlowBound = StringUtils.hasText(entity.getFlowGuid());
|
||||
boolean nowFlowBound = StringUtils.hasText(request.getFlowGuid());
|
||||
entity.setTitle(request.getTitle());
|
||||
entity.setContent(request.getContent());
|
||||
entity.setType(request.getType());
|
||||
@@ -169,7 +213,25 @@ public class NoticeService implements INoticeService {
|
||||
}
|
||||
fileService.bindToTopic(parseFileIds(request.getFileIds()), entity.getId());
|
||||
}
|
||||
// 审核绑定变更:新绑/换绑 → 回到 0 待提交(提交动作 AFTER_COMMIT 出站);解绑 → 直发即发布
|
||||
if (nowFlowBound) {
|
||||
entity.setFlowGuid(request.getFlowGuid().trim());
|
||||
entity.setAuditStatus(com.yunhai.notice.enums.FlowAuditStatusEnum.PENDING_SUBMIT.getCode());
|
||||
// 清上一轮驳回意见:Notice 侧 flow_result_json 只在终态事件写入(FlowCallbackService:173),
|
||||
// 不清则重提后整段新审批期都挂着旧驳回意见(svc-hall 每事件覆盖可自愈,Notice 不能)
|
||||
entity.setFlowResultJson(null);
|
||||
} else if (wasFlowBound) {
|
||||
entity.setFlowGuid(null);
|
||||
entity.setAuditStatus(null);
|
||||
entity.setFlowInstanceId(null);
|
||||
entity.setLastInstanceVersion(null);
|
||||
entity.setFlowResultJson(null);
|
||||
}
|
||||
noticeRepository.save(entity);
|
||||
if (nowFlowBound) {
|
||||
// 编辑重提:复用同一 bizId(notice.id)→ flow-center R4 语义重启推进,轨迹连续
|
||||
noticeFlowService.submitAfterCommit(entity.getId());
|
||||
}
|
||||
}
|
||||
|
||||
/** 解析 "1,2,3" 形式的附件ID串,忽略非法片段 */
|
||||
@@ -201,9 +263,14 @@ public class NoticeService implements INoticeService {
|
||||
return;
|
||||
}
|
||||
for (Integer id : ids) {
|
||||
if (!noticeRepository.existsById(id)) {
|
||||
Notice row = noticeRepository.findById(id).orElse(null);
|
||||
if (row == null) {
|
||||
continue;
|
||||
}
|
||||
if (row.getAuditStatus() != null && row.getAuditStatus() == AUDIT_APPROVING) {
|
||||
throw new BizException(ErrorCode.FORBIDDEN,
|
||||
"通知「" + row.getTitle() + "」审批中不可删除,请先撤回");
|
||||
}
|
||||
noticeReadRepository.deleteByNoticeId(id);
|
||||
noticeReceiverRepository.deleteByNoticeId(id);
|
||||
upFileRepository.deleteByTopicTypeAndTopicId("notice", id);
|
||||
@@ -410,7 +477,9 @@ entity.setIsPulled(0);
|
||||
String account = currentAccount();
|
||||
boolean read = noticeReadRepository.existsByNoticeIdAndReaderAccount(id, account);
|
||||
NoticeVo vo = toVo(entity, read);
|
||||
if (!read) {
|
||||
// 仅已发布通知标读:审批人(NoticeFlowGuard 放行的三类人)查看未发布通知属审核动作,
|
||||
// 不得记入阅读统计污染已读名单(走查报告 §七.4)
|
||||
if (!read && entity.getStatus() != null && entity.getStatus() == PUBLISHED) {
|
||||
markRead(id);
|
||||
vo.setRead(true);
|
||||
}
|
||||
@@ -739,6 +808,7 @@ entity.setIsPulled(0);
|
||||
|
||||
@Override
|
||||
public NoticeDetailVo getDetailMap(Integer serid) {
|
||||
requireVisibleIfUnpublished(serid);
|
||||
NoticeVo vo = getDetail(serid);
|
||||
NoticeDetailVo data = new NoticeDetailVo();
|
||||
data.setSerid(serid);
|
||||
@@ -770,6 +840,20 @@ entity.setIsPulled(0);
|
||||
} else {
|
||||
data.setTlist(parseReceiveAccounts(rl));
|
||||
}
|
||||
// 先审后发镜像(编辑页驳回/撤回态展示意见;详情页进度卡片入口)
|
||||
data.setFlowGuid(vo.getFlowGuid());
|
||||
data.setAuditStatus(vo.getAuditStatus());
|
||||
data.setAuditStatusDesc(vo.getAuditStatusDesc());
|
||||
data.setFlowInstanceId(vo.getFlowInstanceId());
|
||||
Notice flowSource = noticeRepository.findById(serid).orElse(null);
|
||||
if (flowSource != null && StringUtils.hasText(flowSource.getFlowResultJson())) {
|
||||
try {
|
||||
data.setFlowResult(new com.fasterxml.jackson.databind.ObjectMapper()
|
||||
.readValue(flowSource.getFlowResultJson(), Object.class));
|
||||
} catch (Exception ignore) {
|
||||
data.setFlowResult(null);
|
||||
}
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
@@ -835,6 +919,11 @@ entity.setIsPulled(0);
|
||||
}
|
||||
vo.setRead(read);
|
||||
vo.setReadCount(noticeReadRepository.countByNoticeId(entity.getId()));
|
||||
// 先审后发镜像(未绑流程为 null,前端据此隐藏审核列/进度卡片)
|
||||
vo.setFlowGuid(entity.getFlowGuid());
|
||||
vo.setAuditStatus(entity.getAuditStatus());
|
||||
vo.setAuditStatusDesc(com.yunhai.notice.enums.FlowAuditStatusEnum.descOf(entity.getAuditStatus()));
|
||||
vo.setFlowInstanceId(entity.getFlowInstanceId());
|
||||
return vo;
|
||||
}
|
||||
|
||||
@@ -853,10 +942,10 @@ entity.setIsPulled(0);
|
||||
return;
|
||||
}
|
||||
if (!isImmediatePublish(entity)) {
|
||||
// 定时未到点:此刻不发(可见性靠查询谓词延后),到点由 SmsCatchupJob 补发(§3.2)
|
||||
return;
|
||||
}
|
||||
smsSender.sendNoticeSms(entity.getId(), entity.getTitle(),
|
||||
parseReceiveList(entity.getReceiveList()));
|
||||
smsSendService.sendOnce(entity);
|
||||
}
|
||||
|
||||
private boolean isImmediatePublish(Notice entity) {
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
package com.yunhai.notice.service.sms;
|
||||
|
||||
import com.yunhai.notice.entity.Notice;
|
||||
import com.yunhai.notice.repository.NoticeRepository;
|
||||
import com.yunhai.notice.utils.ReceiveParser;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 短信统一发送(§3.2 / BP-R5-2):直发(publish 即时)、审批通过(completed 回调后置)、
|
||||
* 到点补发(SmsCatchupJob)三条链路共用,以 sms_sent_at 原子认领防重复——
|
||||
* 认领成功才发送,失败归还标记待下轮补发。修复"审批通过时未到定时点 → 短信永久丢失"缺口。
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class SmsSendService {
|
||||
|
||||
private final NoticeRepository noticeRepository;
|
||||
private final SmsSender smsSender;
|
||||
|
||||
/**
|
||||
* 发一次短信(幂等):sms_flag!=1 或已发过(认领失败)直接跳过。
|
||||
* 发送抛异常时归还认领(下轮补发可重试)后原样上抛——发布/回调链路维持既有 5xx 语义。
|
||||
*/
|
||||
@Transactional
|
||||
public boolean sendOnce(Notice notice) {
|
||||
if (notice == null || notice.getSmsFlag() == null || notice.getSmsFlag() != 1) {
|
||||
return false;
|
||||
}
|
||||
if (noticeRepository.markSmsSent(notice.getId(), LocalDateTime.now()) == 0) {
|
||||
return false; // 已发送过(并发/重复调度/重发布轮次的闸门)
|
||||
}
|
||||
try {
|
||||
smsSender.sendNoticeSms(notice.getId(), notice.getTitle(),
|
||||
ReceiveParser.parse(notice.getReceiveList()));
|
||||
log.info("[notice-sms] 短信已发送 notice={} title={}", notice.getId(), notice.getTitle());
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
noticeRepository.clearSmsSent(notice.getId());
|
||||
log.warn("[notice-sms] 短信发送失败(归还认领,待补发重试)notice={}:{}",
|
||||
notice.getId(), e.toString());
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package com.yunhai.notice.utils;
|
||||
|
||||
import javax.servlet.ReadListener;
|
||||
import javax.servlet.ServletInputStream;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletRequestWrapper;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
/**
|
||||
* 可重读请求包装(回调验签用):FlowCallbackVerifyFilter 读 body 验签后,
|
||||
* 控制器仍需 @RequestBody 反序列化——包装类缓存原始字节供二次读取。
|
||||
*/
|
||||
public class ReReadableRequestWrapper extends HttpServletRequestWrapper {
|
||||
|
||||
private final byte[] body;
|
||||
|
||||
public ReReadableRequestWrapper(HttpServletRequest request) throws IOException {
|
||||
super(request);
|
||||
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
|
||||
try (InputStream in = request.getInputStream()) {
|
||||
byte[] chunk = new byte[4096];
|
||||
int read;
|
||||
while ((read = in.read(chunk)) > 0) {
|
||||
buffer.write(chunk, 0, read);
|
||||
}
|
||||
}
|
||||
this.body = buffer.toByteArray();
|
||||
}
|
||||
|
||||
public String bodyString() {
|
||||
return new String(body, StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServletInputStream getInputStream() {
|
||||
ByteArrayInputStream source = new ByteArrayInputStream(body);
|
||||
return new ServletInputStream() {
|
||||
@Override
|
||||
public boolean isFinished() {
|
||||
return source.available() == 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isReady() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setReadListener(ReadListener listener) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int read() {
|
||||
return source.read();
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package com.yunhai.notice.utils;
|
||||
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 接收人列表解析工具(自 NoticeService.parseReceiveAccounts 提炼为公共类):
|
||||
* "ALL"/"UserAll"/"all"=全员(返回空列表);JSON 数组串或逗号串 → 账号列表;
|
||||
* 为空或解析失败返回空列表(表示全员通知)。
|
||||
*/
|
||||
public final class ReceiveParser {
|
||||
|
||||
private ReceiveParser() {
|
||||
}
|
||||
|
||||
public static List<String> parse(String receiveList) {
|
||||
if (receiveList == null || receiveList.trim().isEmpty()) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
String rl = receiveList.trim();
|
||||
if ("ALL".equalsIgnoreCase(rl) || "UserAll".equalsIgnoreCase(rl) || "all".equalsIgnoreCase(rl)) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
List<String> result = new ArrayList<>();
|
||||
if (rl.startsWith("[")) {
|
||||
String inner = rl.substring(1, rl.length() - 1).trim();
|
||||
if (!inner.isEmpty()) {
|
||||
for (String part : inner.split(",")) {
|
||||
String account = part.trim().replace("\"", "").replace("'", "");
|
||||
if (StringUtils.hasText(account) && !result.contains(account)) {
|
||||
result.add(account);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (String part : rl.split(",")) {
|
||||
String account = part.trim();
|
||||
if (StringUtils.hasText(account) && !result.contains(account)) {
|
||||
result.add(account);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user