feat(training): 企业培训迭代:推送深链接与签名下载、课程管理修复与收集模板调整
推送域(000155):
- 广播通知支持 link_url:demand_collect 场景自动签发教育训练需求表模板
匿名下载直链(HMAC token,20 天有效,免登录路由),企微消息尾部拼
「下载模板 + 查看更多详情」链接;站内文本保持纯文本不受影响
- 配置中心新增「推送链接基址」(notify_link_base_url,多入口/内外网部署固定
权威地址,留空跟随推送人访问地址)与「年培训计划收集推送文案」
(demand_collect_*,{year} 渲染收集年度);空标题/内容按模板回落渲染
- 迁移 000155:tr_training_notifications 增 link_url/link_token 列
课程管理:
- 修复点【发布/下线】报「不支持的操作」:动作取值兼容字面量路由(FullPath
末段)与 :action 通配两种注册形态
- 列表新增「创建人」列:creator_id 联查 users 带出姓名,导出 Excel 同步;
新增课程「所属部门」默认当前登录用户所在部门
- 导入加固:表头归一化 + 别名模糊匹配(兼容内置模板/旧口径/自定义模板变体);
导入与新增行支持按部门名兜底解析为 id(前端名册未命中时传 owner_dept_name)
年培训计划:
- 需求列表新增「创建人/创建时间」列(submitter_id 联查 users 带出姓名)
- 收集模板调整:下载时动态删除「培训费用(RMB)」列(旧版自定义模板同步归一,
右侧列/合并/下拉随删列平移);备注右侧追加「调研维度/培训策划要求」说明列
(合并至数据区末行,自动换行带边框,已带说明的自定义模板不覆盖)
开发工具:
- air 热重载适配 Windows:构建收敛到 scripts/air_build.sh(规避 air 经
PowerShell 执行不支持 bash 命令替换),产物改 .exe 后缀;CGO_CFLAGS 取
持久化值并集追加,不覆盖 go env -w 的头文件包含路径
This commit is contained in:
1 parent
242dd7e1a6
commit
4e25fce9aa
30 files changed
+1150
-143
No files matched your search
@@ -12,12 +12,15 @@ import (
|
||||
"path"
|
||||
"regexp"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"academy/internal/errors"
|
||||
"academy/internal/logger"
|
||||
"academy/internal/types"
|
||||
"academy/internal/types/interfaces"
|
||||
"academy/internal/utils"
|
||||
"github.com/xuri/excelize/v2"
|
||||
)
|
||||
|
||||
@@ -1426,16 +1429,35 @@ func (s *trainingService) Notify(ctx context.Context, tenantID uint64, targetUse
|
||||
// 运营场景),站内 + 企微外箱(调度器 dispatchPending 消费)。手动广播是离散
|
||||
// 的发送动作:ref_id 追加发送时间戳,避免与唯一索引 (tenant,target,scene,ref)
|
||||
// 冲突把已收过通知的人静默去重;返回成功入箱条数。
|
||||
func (s *trainingService) BroadcastNotification(ctx context.Context, tenantID uint64, userIDs []string, scene, title, content, refType, refID string) (int, error) {
|
||||
// linkURL 为前端 origin(可空):demand_collect 场景据此生成教育训练需求表
|
||||
// 模板的匿名下载签名 token(20 天有效)随行落库,调度器投递企微时拼尾部
|
||||
// 「下载模板/查看详情」链接;站内 content 保持纯文本不受影响。
|
||||
// demand_collect 场景空标题/内容按配置中心文案模板回落渲染(见 training_notify.go)。
|
||||
func (s *trainingService) BroadcastNotification(ctx context.Context, tenantID uint64, userIDs []string, scene, title, content, refType, refID, linkURL string) (int, error) {
|
||||
if len(userIDs) == 0 {
|
||||
return 0, errors.NewBadRequestError("请选择推送人员")
|
||||
}
|
||||
if scene == "" {
|
||||
scene = "demand_collect"
|
||||
scene = types.SceneDemandCollect
|
||||
}
|
||||
// [2026-11 需求] 年培训计划收集推送文案:配置中心「提醒推送文案」卡
|
||||
// (notify_text_templates demand_collect_*)可编辑;调用方未带标题/内容时
|
||||
// 按模板回落渲染,{year} 取 ref_id 收集年度(缺省北京时间下一年)。
|
||||
if scene == types.SceneDemandCollect {
|
||||
tpl := s.loadNotifyTextTemplates(ctx, tenantID)
|
||||
year := strconv.Itoa(demandCollectYear(refID, time.Now()))
|
||||
vars := map[string]string{"year": year}
|
||||
if strings.TrimSpace(title) == "" {
|
||||
title = renderNotifyTemplate(tpl.DemandCollectTitle, vars)
|
||||
}
|
||||
if strings.TrimSpace(content) == "" {
|
||||
content = renderNotifyTemplate(tpl.DemandCollectContent, vars)
|
||||
}
|
||||
}
|
||||
if refID != "" {
|
||||
refID = fmt.Sprintf("%s-%d", refID, time.Now().UnixNano())
|
||||
}
|
||||
linkURL, linkToken := s.broadcastDeepLink(ctx, tenantID, scene, linkURL)
|
||||
push := s.loadPushEnabled(ctx, tenantID)
|
||||
now := time.Now()
|
||||
status := ""
|
||||
@@ -1451,6 +1473,7 @@ func (s *trainingService) BroadcastNotification(ctx context.Context, tenantID ui
|
||||
ID: trainingNewID(), TenantID: tenantID,
|
||||
TargetUserID: uid, Channel: "inapp", Scene: scene,
|
||||
Title: title, Content: content, RefType: refType, RefID: refID,
|
||||
LinkURL: linkURL, LinkToken: linkToken,
|
||||
SentAt: now, PushStatus: status,
|
||||
})
|
||||
}
|
||||
@@ -1463,6 +1486,60 @@ func (s *trainingService) BroadcastNotification(ctx context.Context, tenantID ui
|
||||
return len(rows), nil
|
||||
}
|
||||
|
||||
// broadcastDeepLink 解析广播外链基址并为 demand_collect 场景签发模板匿名
|
||||
// 下载 token。基址取值优先级:配置中心 notify_link_base_url(环境级覆盖,
|
||||
// 多入口/内外网部署固定指向权威域名)> 前端推送 origin(window.location.origin,
|
||||
// 本地开发零配置可用)。仅接受 http(s) 绝对地址;非法或非收集场景一律退回
|
||||
// 空串,不阻断通知本身(链接是增强,不是前提)。
|
||||
func (s *trainingService) broadcastDeepLink(ctx context.Context, tenantID uint64, scene, linkURL string) (string, string) {
|
||||
if scene != types.SceneDemandCollect {
|
||||
return "", ""
|
||||
}
|
||||
linkURL = normalizeLinkBase(s.loadLinkBaseOverride(ctx, tenantID), linkURL)
|
||||
if linkURL == "" {
|
||||
return "", ""
|
||||
}
|
||||
token, err := utils.SignTrainingTemplateToken(&utils.TrainingTemplateTokenPayload{
|
||||
TenantID: tenantID,
|
||||
TemplateKey: types.TrainingTemplateDemandCollection,
|
||||
})
|
||||
if err != nil {
|
||||
logger.Warnf(ctx, "[TrainingBroadcast] sign template download token: %v", err)
|
||||
return "", ""
|
||||
}
|
||||
return linkURL, token
|
||||
}
|
||||
|
||||
// loadLinkBaseOverride 读配置中心 notify_link_base_url(bare string;空 = 未配置)。
|
||||
func (s *trainingService) loadLinkBaseOverride(ctx context.Context, tenantID uint64) string {
|
||||
rules, err := s.repo.ListRuleConfigs(ctx, tenantID)
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
for _, rule := range rules {
|
||||
if rule.RuleKey == ruleKeyNotifyLinkBaseURL {
|
||||
var v string
|
||||
if json.Unmarshal(rule.RuleValue, &v) == nil {
|
||||
return v
|
||||
}
|
||||
return ""
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// normalizeLinkBase 从候选(优先配置覆盖,其次调用方 origin)选出一个合法的
|
||||
// http(s) 基址:去空白与尾部斜杠;候选均非法时返回空串。
|
||||
func normalizeLinkBase(override, origin string) string {
|
||||
for _, candidate := range []string{override, origin} {
|
||||
candidate = strings.TrimRight(strings.TrimSpace(candidate), "/")
|
||||
if strings.HasPrefix(candidate, "http://") || strings.HasPrefix(candidate, "https://") {
|
||||
return candidate
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// 小工具
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
Reference in new issue
Block a user