feat(portal): 我要办理深链带 from 回跳参数(T4)——新增 SvcHallLinks 纯函数构造器(base 尾斜杠裁剪+UTF-8 urlencode+from 缺省不追加),PortalController 自动生成分支改走它并补 from=指南页绝对 URL(hall 显示返回门户);urlEncodeValue 私有方法随唯一调用点替换删除;ServicePortalIT 断言同步新契约

This commit is contained in:
chenxing
2026-10-03 13:26:30 +08:00
parent f591d06c35
commit 84224b31bb
4 changed files with 93 additions and 16 deletions
@@ -19,6 +19,7 @@ import com.yunhai.cms.svcitem.model.vo.PortalServiceItem;
import com.yunhai.cms.svcitem.model.vo.PortalServiceListData;
import com.yunhai.cms.svcitem.service.SvcItemQuery;
import com.yunhai.cms.utils.PortalUrlHelper;
import com.yunhai.cms.utils.SvcHallLinks;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
@@ -491,18 +492,15 @@ public class PortalController {
// "我要办理"三态(§5.3):① ext_json.apply_url 手填外链(最高优先)
// ② 未填且站点配了 svc_hall_base 且事项开通在线办理(onlineFlag=1 且绑流程,§3.7——
// 与 svc-hall 侧 submit 校验"未开通在线办理"口径对齐,线下/纯指南事项不再渲染按钮)
// ——深链带 from=指南页回跳地址,hall 据此显示"返回门户"按钮(T4 闭环)
// ③ 其余 → 不注入(模板不渲染按钮)
String applyUrl = item.getApplyUrl();
boolean onlineHandlable = item.getOnlineFlag() != null && item.getOnlineFlag() == 1
&& StringUtils.hasText(item.getFlowGuid());
if ((applyUrl == null || applyUrl.trim().isEmpty()) && onlineHandlable
&& site.getSvcHallBase() != null && !site.getSvcHallBase().trim().isEmpty()) {
String base = site.getSvcHallBase().trim();
while (base.endsWith("/")) {
base = base.substring(0, base.length() - 1);
}
applyUrl = base + "/#/apply?siteCode=" + urlEncodeValue(site.getCode())
+ "&itemCode=" + urlEncodeValue(item.getItemCode());
applyUrl = SvcHallLinks.build(site.getSvcHallBase(), site.getCode(),
item.getItemCode(), url.serviceItem(itemId));
}
if (applyUrl != null && !applyUrl.trim().isEmpty()) {
model.addAttribute("applyUrl", applyUrl);
@@ -687,14 +685,6 @@ public class PortalController {
return trimmed.isEmpty() ? null : trimmed;
}
private static String urlEncodeValue(String value) {
try {
return java.net.URLEncoder.encode(value == null ? "" : value, "UTF-8");
} catch (java.io.UnsupportedEncodingException e) {
return value;
}
}
/**
* 站点身份解析(W4):优先按门户 path(siteSnapshotByPath);
@@ -0,0 +1,44 @@
package com.yunhai.cms.utils;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
/**
* 「我要办理」深链构造器(T4 回跳闭环,2026-10-03 执行方案)。
* 纯函数无状态:base 尾斜杠裁剪、参数 UTF-8 urlencode、from 缺省不追加。
*/
public final class SvcHallLinks {
private SvcHallLinks() {
}
/**
* 「我要办理」深链(双端契约:hall/src/router/routes.ts 依赖此形态,改参数名两侧同步)。
*
* @param base svc-hall hall 部署基地址(站点 svc_hall_base,尾斜杠容忍)
* @param siteCode 站点编码
* @param itemCode 事项编码
* @param fromUrl 指南页绝对 URL(回跳地址;null/空=不追加 from 段,hall 不显示返回门户)
*/
public static String build(String base, String siteCode, String itemCode, String fromUrl) {
String url = trimTail(base) + "/#/apply?siteCode=" + enc(siteCode)
+ "&itemCode=" + enc(itemCode);
return fromUrl == null || fromUrl.isEmpty() ? url : url + "&from=" + enc(fromUrl);
}
private static String trimTail(String url) {
String s = url == null ? "" : url.trim();
while (s.endsWith("/")) {
s = s.substring(0, s.length() - 1);
}
return s;
}
private static String enc(String value) {
try {
return URLEncoder.encode(value, "UTF-8");
} catch (UnsupportedEncodingException e) {
return value;
}
}
}