Files
ai_academy/frontend/src/views/training/components/MemberPanel.vue
T
runny e378e8b7fd feat(training): 推送管理:学员开课通知、周一讲师汇总与企微推送闭环
[2026-11 推学员/推讲师需求] 培训提醒统一走 tr_notifications outbox(站内流水 +
企微 push_status 投递),推送文案可配置,管理端可查逐人投递明细。

后端 internal/application/service:
- training_notify.go(重写)推送管理核心:
  - 学员开课通知 scene=session_notice_student:immediate 场次在名单保存/课件上传后
    立即入队,day_before 场次由调度器 T-1 且课件就绪时入队;课件门控 +
    (tenant,target,scene,ref) 唯一索引幂等,一人一场最多一条
  - 周一讲师未完成汇总 scene=remind_monthly_lecturer:北京时间周一发送(时点可配),
    轮次键 YYYY-MM-Wn 幂等,场次全部结束自然停推
  - 提醒推送文案模板 notify_text_templates:配置中心可编辑,{占位符} 替换渲染,
    空字段回落内置默认
  - ListPushLogs 推送记录:逐人投递明细(push_status/重试/错误 + 员工姓名工号映射)
- training_scheduler.go:
  - 学员提醒收敛到 session_notice_student 单通道,讲师 T-N 授课提醒与
    课程维护提醒(临近开课仍缺课件)保持
  - 新增每周一讲师未完成汇总生成(租户开关 + 发送小时可配)
  - 企微外箱消费 dispatchPending:FOR UPDATE SKIP LOCKED 多实例安全,
    sending 超时回收,重试上限置 dead
  - PushTestNotification 推送链路自测(校验凭据与 userid 绑定)
- training_ops.go:默认规则种子追加企微推送开关键/周一讲师键/提醒文案默认模板

前端 frontend/src/views/training:
- RulePanel.vue:配置中心新增「提醒推送文案」编辑卡与「推送记录」明细表
  (场景筛选、手动触发周一讲师提醒)
- CoursePanel.vue:场次通知模式新增 immediate「名单/课件就绪后立即推送」
- CourseCatalog.vue:「我的课程」角色标记(我主讲/我参加)、最近场次排期排序、
  待维护统计改橙色(与草稿一致)
- MemberPanel.vue:员工档案支持企微账号绑定(培训提醒推送目标)

测试:training_notify_test.go(模板解析/占位符渲染)、training_scheduler_test.go
(生成幂等/课件门控/停推开关/投递结果/测试推送/文案渲染),go test 全部通过。
2026-11-16 18:12:35 +08:00

324 lines
12 KiB
Vue

<template>
<div class="member-panel">
<!-- 员工档案(名册来自组织架构)+ 职称角色 -->
<div class="panel-box member-layout__members">
<div class="panel-box__header">
<span class="panel-box__title">员工档案</span>
<div class="member-panel__hint">
员工与部门在「<a class="member-panel__link" @click="goOrgCenter">组织架构</a>」中统一维护,此处仅配置职称角色
<t-button variant="outline" theme="primary" size="small" :loading="syncing" class="oa-sync-btn" @click="onPreviewSync">
从OA同步企微账号
</t-button>
</div>
</div>
<t-table :data="members" :columns="memberColumns" row-key="id" size="small" :loading="loading">
<template #user_name="{ row }">
<t-tooltip :content="memberName(row)" :disabled="!memberName(row)">
<span class="member-name">{{ memberName(row) || '-' }}</span>
</t-tooltip>
</template>
<template #dept_name="{ row }">{{ row.dept_name || '-' }}</template>
<template #wecom_userid="{ row }">
<span :class="row.wecom_userid ? '' : 'wecom-missing'">{{ row.wecom_userid || '未绑定' }}</span>
</template>
<template #roles="{ row }">
<t-tag v-for="r in row.roles || []" :key="r" variant="light" size="small" class="role-tag">{{ roleText(r) }}</t-tag>
</template>
<template #op="{ row }">
<t-button variant="text" theme="primary" size="small" @click="openWecom(row)">企微账号</t-button>
<t-button variant="text" theme="primary" size="small" @click="openRoles(row)">设置角色</t-button>
</template>
</t-table>
</div>
<t-dialog v-model:visible="wecomVisible" header="绑定企微账号" width="460">
<t-input v-model="wecomInput" placeholder="企微 userid(管理后台→通讯录→成员详情→账号)" />
<div class="form-hint">培训提醒推送到该企微账号;留空保存即解绑。</div>
<template #footer>
<t-button theme="primary" :loading="savingWecom" @click="onSaveWecom">保存</t-button>
</template>
</t-dialog>
<!-- OA 同步预览:统计 + 冲突清单 + 待写入样本;无冲突才允许确认写入 -->
<t-dialog v-model:visible="syncVisible" header="OA 企微账号同步" width="640" :footer="false">
<template v-if="syncSummary">
<div class="sync-stats">
<span>本地员工 {{ syncSummary.local_candidates }}</span>
<span>OA 命中 {{ syncSummary.local_matched }}</span>
<span>已一致 {{ syncSummary.already_bound }}</span>
<span class="sync-stats__main">待写入 {{ syncSummary.would_update }}</span>
<span :class="syncSummary.conflict_count ? 'sync-stats__danger' : ''">冲突 {{ syncSummary.conflict_count }}</span>
<span>OA 未找到 {{ syncSummary.local_missing }}</span>
</div>
<div v-if="syncSummary.conflict_count" class="sync-section sync-section--danger">
<div class="sync-section__title">冲突({{ syncSummary.conflict_count }})——存在冲突时不写入</div>
<div v-for="(cf, i) in syncSummary.conflicts" :key="i" class="sync-row">
{{ cf.employee_no }} {{ cf.user_name || '' }}:
{{ conflictText(cf) }}
</div>
</div>
<div v-if="syncSummary.would_update" class="sync-section">
<div class="sync-section__title">将写入(最多展示 20 条)</div>
<div v-for="(p, i) in syncSummary.pending_updates" :key="i" class="sync-row">
{{ p.employee_no }} {{ p.user_name || p.name }} → 企微账号 {{ p.wecom_userid }}
</div>
</div>
<div v-if="!syncSummary.conflict_count && !syncSummary.would_update" class="sync-section">
无需更新:绑定已一致或 OA 无匹配数据。
</div>
<div class="sync-footer">
<t-button :disabled="syncSummary.conflict_count > 0 || syncSummary.would_update === 0"
theme="primary" :loading="syncing" @click="onApplySync">
确认写入
</t-button>
<t-button variant="outline" @click="syncVisible = false">关闭</t-button>
</div>
</template>
</t-dialog>
<t-dialog v-model:visible="rolesVisible" header="设置职称角色" width="460">
<!-- 选项来自配置中心角色字典(role_dict):系统角色 + 自定义角色 -->
<t-select v-model="roleSelection" multiple style="width: 100%">
<t-option v-for="r in roleDict" :key="r.key" :value="r.key" :label="r.label" />
</t-select>
<div class="form-hint">学员角色为全员默认,无需选择;角色与权限在「配置中心」维护。</div>
<template #footer>
<t-button theme="primary" :loading="saving" @click="onSaveRoles">保存</t-button>
</template>
</t-dialog>
</div>
</template>
<script setup lang="ts">
import { computed, onMounted, ref } from 'vue'
import { useRouter } from 'vue-router'
import { MessagePlugin } from 'tdesign-vue-next'
import {
fetchRoleDict,
listMembers,
listPlatformUsers,
roleLabelOf,
updateMemberRoles,
updateMemberWecomUserid,
applyWecomUseridSync,
previewWecomUseridSync,
type PlatformUser,
type TrainingMember,
type TrainingRoleDef,
type WecomSyncConflict,
type WecomSyncSummary,
unwrap,
} from '@/api/training'
const router = useRouter()
const loading = ref(false)
const saving = ref(false)
const members = ref<TrainingMember[]>([])
const platformUsers = ref<PlatformUser[]>([])
// 角色字典(配置中心 role_dict):弹窗选项与角色标签文案的来源
const roleDict = ref<TrainingRoleDef[]>([])
const rolesVisible = ref(false)
const activeMember = ref<TrainingMember | null>(null)
const roleSelection = ref<string[]>([])
// 企微账号绑定(培训提醒推送目标)
const wecomVisible = ref(false)
const activeWecomMember = ref<TrainingMember | null>(null)
const wecomInput = ref('')
const savingWecom = ref(false)
// OA 同步(工号 → 企微 userid,预览→写入两段式)
const syncVisible = ref(false)
const syncing = ref(false)
const syncSummary = ref<WecomSyncSummary | null>(null)
const conflictText = (cf: WecomSyncConflict) => {
switch (cf.reason) {
case 'duplicate_workcode_in_oa':
return `OA 中存在重复工号(企微账号 ${cf.new_wecom_userid}),请先在 OA 侧处理`
case 'bound_to_different_userid':
return `已绑定 ${cf.existing_wecom_userid},与 OA(${cf.new_wecom_userid})不一致,需人工确认`
case 'userid_occupied':
return `企微账号 ${cf.new_wecom_userid} 已被 ${cf.occupied_by_employee || '其他员工'} 占用`
default:
return cf.reason
}
}
const onPreviewSync = async () => {
syncing.value = true
try {
const res = await previewWecomUseridSync()
syncSummary.value = unwrap(res) ?? null
syncVisible.value = true
} catch (err: any) {
MessagePlugin.error(err?.response?.data?.message || 'OA 连接失败,请检查 OA_SQLSERVER_* 配置')
} finally {
syncing.value = false
}
}
const onApplySync = async () => {
syncing.value = true
try {
const res = await applyWecomUseridSync()
const summary = unwrap(res)
MessagePlugin.success(`已写入 ${summary?.updated ?? 0} 条企微绑定`)
syncVisible.value = false
loadAll()
} catch (err: any) {
MessagePlugin.error(err?.response?.data?.message || '写入失败')
} finally {
syncing.value = false
}
}
const memberColumns = [
{ colKey: 'employee_no', title: '工号', width: 100 },
{ colKey: 'user_name', title: '姓名' },
{ colKey: 'dept_name', title: '部门', width: 110 },
{ colKey: 'post', title: '岗位', width: 140 },
{ colKey: 'wecom_userid', title: '企微账号', width: 120 },
{ colKey: 'roles', title: '职称角色', width: 260 },
{ colKey: 'op', title: '操作', width: 170 },
]
// 角色 tag 文案取字典短名,字典外(trainee/已删角色)回退固定文案或 key
const roleText = (r: string) => roleLabelOf(r, roleDict.value, true)
// 跳转组织架构页(部门/员工档案的唯一维护入口)
const goOrgCenter = () => router.push('/platform/org-center')
// 姓名 = 真实姓名(来自 OIDC displayName claim):优先取后端联查的 user_name,
// 再用平台用户表的 display_name / username 兜底;都取不到展示「-」,不再回退展示用户ID。
const userNameMap = computed(() => {
const m: Record<string, string> = {}
for (const u of platformUsers.value) m[u.id] = u.display_name?.trim() || u.username
return m
})
const memberName = (row: TrainingMember) => row.user_name || userNameMap.value[row.user_id] || ''
const loadAll = async () => {
loading.value = true
try {
// 平台用户一并拉取,用于姓名兜底联查(user_id → 用户名)。
const [m, u] = await Promise.all([
listMembers({ page_size: 500 }),
listPlatformUsers().catch(() => null),
])
members.value = unwrap(m)?.items || []
platformUsers.value = unwrap(u) || []
} finally {
loading.value = false
}
}
const openRoles = (row: TrainingMember) => {
activeMember.value = row
roleSelection.value = (row.roles || []).filter((r) => r !== 'trainee')
rolesVisible.value = true
}
const openWecom = (row: TrainingMember) => {
activeWecomMember.value = row
wecomInput.value = row.wecom_userid || ''
wecomVisible.value = true
}
const onSaveWecom = async () => {
if (!activeWecomMember.value) return
savingWecom.value = true
try {
await updateMemberWecomUserid(activeWecomMember.value.id, wecomInput.value.trim())
MessagePlugin.success('企微账号已更新')
wecomVisible.value = false
loadAll()
} catch (err: any) {
MessagePlugin.error(err?.response?.data?.message || '保存失败')
} finally {
savingWecom.value = false
}
}
const onSaveRoles = async () => {
if (!activeMember.value) return
saving.value = true
try {
await updateMemberRoles(activeMember.value.id, [...roleSelection.value, 'trainee'])
MessagePlugin.success('角色已更新')
rolesVisible.value = false
loadAll()
} catch (err: any) {
MessagePlugin.error(err?.response?.data?.message || '保存失败')
} finally {
saving.value = false
}
}
onMounted(() => {
loadAll()
fetchRoleDict().then((d) => {
roleDict.value = d
})
})
</script>
<style lang="less" scoped>
@import (reference) '../training.less';
.panel-box {
.training-panel-box();
}
.member-panel__hint {
color: var(--td-text-color-placeholder);
font-size: var(--app-text-sm);
}
.member-panel__link {
color: var(--td-brand-color);
cursor: pointer;
}
.role-tag { margin-right: 4px; }
.wecom-missing { color: var(--td-text-color-placeholder); }
.oa-sync-btn { margin-left: 12px; }
.sync-stats {
display: flex;
gap: 14px;
flex-wrap: wrap;
margin-bottom: 12px;
color: var(--td-text-color-secondary);
.sync-stats__main { color: var(--td-brand-color); font-weight: 600; }
.sync-stats__danger { color: var(--td-error-color); font-weight: 600; }
}
.sync-section {
margin-bottom: 12px;
max-height: 180px;
overflow: auto;
.sync-section__title { font-weight: 600; margin-bottom: 6px; }
.sync-row { padding: 2px 0; font-size: var(--app-text-sm); color: var(--td-text-color-secondary); }
&.sync-section--danger .sync-section__title { color: var(--td-error-color); }
}
.sync-footer { display: flex; gap: 8px; justify-content: flex-end; }
.form-hint {
margin-top: 8px;
color: var(--td-text-color-placeholder);
font-size: var(--app-text-sm);
}
// 姓名列:最多展示 2 行,超出省略(悬停 tooltip 看全名)
.member-name {
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 2;
overflow: hidden;
word-break: break-all;
line-height: 1.4;
}
</style>