1.增加按“时间”、“标题”、“企微状态”查询 2.增加数据统计在列表顶部 3.增加分页功能
This commit is contained in:
1 parent
0c471efb9f
commit
9d4092bc7f
14 files changed
+447
-108
No files matched your search
@@ -3,6 +3,7 @@ package repository
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strings"
|
||||
|
||||
"academy/internal/types"
|
||||
"academy/internal/types/interfaces"
|
||||
@@ -10,6 +11,13 @@ import (
|
||||
"gorm.io/gorm/clause"
|
||||
)
|
||||
|
||||
// 推送记录分页口径:默认每页 15 条(与前端 TrainingPagination 默认一致),
|
||||
// 单页上限 200。
|
||||
const (
|
||||
pushLogPageSizeDefault = 15
|
||||
pushLogPageSizeMax = 200
|
||||
)
|
||||
|
||||
// trainingRepository 培训业务域数据访问。实现按域拆分在
|
||||
// training.go / training_plan_course.go / training_exam_dash.go 三个文件。
|
||||
// 所有查询都按 tenant_id 过滤,与框架租户隔离惯例保持一致。
|
||||
@@ -351,23 +359,91 @@ func (r *trainingRepository) ListNotificationsByRef(ctx context.Context, tenantI
|
||||
return items, err
|
||||
}
|
||||
|
||||
// ListPushLogs 管理端逐人推送明细(推送管理台"推送记录"):按场景集合可选过滤,
|
||||
// 时间倒序;push_status 空 = 仅站内不入企微外箱。
|
||||
func (r *trainingRepository) ListPushLogs(ctx context.Context, tenantID uint64, scenes []string, refType string, limit int) ([]*types.TrainingNotification, error) {
|
||||
if limit <= 0 || limit > 500 {
|
||||
limit = 200
|
||||
// ListPushLogs 管理端逐人推送明细(推送管理台"推送记录"):按场景/引用/标题
|
||||
// 模糊/企微状态/时间范围可选过滤,时间倒序;push_status 空 = 仅站内不入企微外箱。
|
||||
// 返回当前页行、过滤条件命中总数与全量状态统计(统计与分页无关),
|
||||
// 供配置中心「统计下列查询结果」口径。
|
||||
func (r *trainingRepository) ListPushLogs(ctx context.Context, tenantID uint64, q *types.TrainingPushLogQuery) ([]*types.TrainingNotification, int64, *types.TrainingPushLogStats, error) {
|
||||
if q == nil {
|
||||
q = &types.TrainingPushLogQuery{}
|
||||
}
|
||||
tx := r.db.WithContext(ctx).Model(&types.TrainingNotification{}).
|
||||
Where("tenant_id = ? AND deleted_at IS NULL", tenantID)
|
||||
if len(scenes) > 0 {
|
||||
tx = tx.Where("scene IN ?", scenes)
|
||||
// scoped 每次返回新鲜会话(Count/统计/取页三次独立执行,避免链式污染)。
|
||||
scoped := func() *gorm.DB {
|
||||
tx := r.db.WithContext(ctx).Model(&types.TrainingNotification{}).
|
||||
Where("tenant_id = ? AND deleted_at IS NULL", tenantID)
|
||||
if len(q.Scenes) > 0 {
|
||||
tx = tx.Where("scene IN ?", q.Scenes)
|
||||
}
|
||||
if q.RefType != "" {
|
||||
tx = tx.Where("ref_type = ?", q.RefType)
|
||||
}
|
||||
if title := strings.TrimSpace(q.Title); title != "" {
|
||||
tx = tx.Where("title LIKE ? ESCAPE '"+likeEscapeChar+"'", "%"+escapeLikeKeyword(title)+"%")
|
||||
}
|
||||
switch q.PushStatus {
|
||||
case "":
|
||||
// 全部状态
|
||||
case "pending":
|
||||
// 排队与投递中合并为一个筛选项,与统计口径一致。
|
||||
tx = tx.Where("push_status IN ?", []string{"pending", "sending"})
|
||||
case "in_site":
|
||||
tx = tx.Where("push_status = ''")
|
||||
default:
|
||||
tx = tx.Where("push_status = ?", q.PushStatus)
|
||||
}
|
||||
if q.StartTime != nil {
|
||||
tx = tx.Where("created_at >= ?", *q.StartTime)
|
||||
}
|
||||
if q.EndTime != nil {
|
||||
tx = tx.Where("created_at <= ?", *q.EndTime)
|
||||
}
|
||||
return tx
|
||||
}
|
||||
if refType != "" {
|
||||
tx = tx.Where("ref_type = ?", refType)
|
||||
|
||||
var total int64
|
||||
if err := scoped().Count(&total).Error; err != nil {
|
||||
return nil, 0, nil, err
|
||||
}
|
||||
|
||||
// 全量状态统计:一条 GROUP BY 聚合出各状态计数,再归并到六项口径。
|
||||
var statusRows []struct {
|
||||
PushStatus string
|
||||
Cnt int64
|
||||
}
|
||||
if err := scoped().Select("push_status, COUNT(*) AS cnt").Group("push_status").Scan(&statusRows).Error; err != nil {
|
||||
return nil, 0, nil, err
|
||||
}
|
||||
stats := &types.TrainingPushLogStats{}
|
||||
for _, row := range statusRows {
|
||||
switch row.PushStatus {
|
||||
case "":
|
||||
stats.InSite += row.Cnt
|
||||
case "sent":
|
||||
stats.Sent += row.Cnt
|
||||
case "dead":
|
||||
stats.Dead += row.Cnt
|
||||
case "skipped":
|
||||
stats.Skipped += row.Cnt
|
||||
default: // pending / sending
|
||||
stats.Pending += row.Cnt
|
||||
}
|
||||
stats.Total += row.Cnt
|
||||
}
|
||||
|
||||
page, pageSize := q.Page, q.PageSize
|
||||
if page <= 0 {
|
||||
page = 1
|
||||
}
|
||||
if pageSize <= 0 {
|
||||
pageSize = pushLogPageSizeDefault
|
||||
}
|
||||
if pageSize > pushLogPageSizeMax {
|
||||
pageSize = pushLogPageSizeMax
|
||||
}
|
||||
var items []*types.TrainingNotification
|
||||
err := tx.Order("created_at DESC, id DESC").Limit(limit).Find(&items).Error
|
||||
return items, err
|
||||
err := scoped().Order("created_at DESC, id DESC").
|
||||
Offset((page - 1) * pageSize).Limit(pageSize).Find(&items).Error
|
||||
return items, total, stats, err
|
||||
}
|
||||
|
||||
// ListMonthActiveSessions 返回某年月仍活跃(未取消、未删除)的场次集合,
|
||||
|
||||
@@ -646,7 +646,10 @@ func (r *trainingRepository) EvidenceRows(ctx context.Context, tenantID uint64,
|
||||
COALESCE(lu.username, '') AS lecturer_name,
|
||||
COALESCE(c.name, '') AS course_name,
|
||||
TO_CHAR(s.start_at, 'YYYY-MM-DD HH24:MI') AS session_time,
|
||||
COALESCE(TO_CHAR(er.score, 'FM999'), '') AS exam_score`).
|
||||
COALESCE(TO_CHAR(er.score, 'FM999'), '') AS exam_score,
|
||||
EXISTS (SELECT 1 FROM tr_enrollments en
|
||||
WHERE en.tenant_id = sr.tenant_id AND en.session_id = sr.session_id
|
||||
AND en.member_id = sr.member_id AND en.deleted_at IS NULL) AS in_roster`).
|
||||
Joins("JOIN tr_course_sessions s ON s.id = sr.session_id AND s.tenant_id = sr.tenant_id").
|
||||
Joins("LEFT JOIN tr_courses c ON c.id = s.course_id AND c.tenant_id = sr.tenant_id").
|
||||
Joins("LEFT JOIN org_employees m ON m.id = sr.member_id AND m.tenant_id = sr.tenant_id").
|
||||
|
||||
@@ -881,6 +881,8 @@ func (r *trainingRepository) GetSignRecordByID(ctx context.Context, tenantID uin
|
||||
// ListSignRecords returns all records of a session, earliest first.
|
||||
// 联查员工档案/账号/部门补齐学员展示字段(姓名/工号/部门):签到明细学员列
|
||||
// 不能依赖前端名册全量反查(名册分页截断或未入名册时曾回退显示 member_id)。
|
||||
// in_roster 实时联查 tr_enrollments 标注是否「参加人员」(2026-11-28 规则调整:
|
||||
// 员工档案全员可签到,明细按此标注要求/非要求培训人员)。
|
||||
func (r *trainingRepository) ListSignRecords(ctx context.Context, tenantID uint64, sessionID string) ([]*types.TrainingSignRecord, error) {
|
||||
var items []*types.TrainingSignRecord
|
||||
err := r.db.WithContext(ctx).
|
||||
@@ -892,7 +894,10 @@ func (r *trainingRepository) ListSignRecords(ctx context.Context, tenantID uint6
|
||||
// user_name 取真实姓名(display_name)优先:员工编号型 IdP(Casdoor)的
|
||||
// username 存工号,真实姓名在 display_name(与组织中心列表口径一致)。
|
||||
Select(`sr.*, COALESCE(NULLIF(u.display_name, ''), u.username, '') AS member_name,
|
||||
COALESCE(e.employee_no, '') AS employee_no, COALESCE(dp.name, '') AS dept_name`).
|
||||
COALESCE(e.employee_no, '') AS employee_no, COALESCE(dp.name, '') AS dept_name,
|
||||
EXISTS (SELECT 1 FROM tr_enrollments en
|
||||
WHERE en.tenant_id = sr.tenant_id AND en.session_id = sr.session_id
|
||||
AND en.member_id = sr.member_id AND en.deleted_at IS NULL) AS in_roster`).
|
||||
Order("sr.signed_at ASC").Scan(&items).Error
|
||||
return items, err
|
||||
}
|
||||
|
||||
@@ -883,17 +883,17 @@ func (s *trainingService) rotateSignCode(ctx context.Context, tenantID uint64, c
|
||||
}
|
||||
|
||||
// Checkin performs the scan sign-in with rule-based anti-fraud checks:
|
||||
// token/expiry, same-day, roster membership, employee-no match, nonce replay,
|
||||
// token/expiry, same-day, employee-no match, nonce replay,
|
||||
// duplicate scan, late arrival, geo fence.
|
||||
// 一期为确定性规则引擎,不调 LLM;规则参数来自 sign_policy 配置。
|
||||
// 2026-11 企微扫码需求增强:
|
||||
// - 培训当天校验:非当天扫码签到直接友好提示(提前扫/过期补扫分文案);
|
||||
// - 工号严格校验(in.EmployeeNo 非空时):须与登录账号档案工号一致,且必须在
|
||||
// 该场次「参加人员」名单中 —— 名单外直接拒绝(不再仅标记待复核);
|
||||
// - 工号严格校验(in.EmployeeNo 非空时):须与登录账号档案工号一致;
|
||||
// - nonce 防重放 + client_ts 时钟偏差校验;
|
||||
// - 轮换宽限:token 未命中当前码时接受 prev_token 在宽限期内签到。
|
||||
// 既有登录态签到(不带 employee_no/nonce)行为不变:名单外仍标记 not_in_roster
|
||||
// 进待复核,不硬拒。
|
||||
// 2026-11-28 签到规则调整:签到不再限定发布培训计划时所选「参加人员」——
|
||||
// 员工档案(org_employees)全员均可凭工号签到;是否要求培训人员不再拦截/进
|
||||
// 异常待复核,由签到明细按名册实时标注(ListSignRecords 联查 in_roster)。
|
||||
func (s *trainingService) Checkin(ctx context.Context, tenantID uint64, userID string, in *types.CheckinInput) (*types.TrainingSignRecord, error) {
|
||||
if in == nil || in.Token == "" {
|
||||
return nil, errors.NewBadRequestError("签到码无效")
|
||||
@@ -922,23 +922,10 @@ func (s *trainingService) Checkin(ctx context.Context, tenantID uint64, userID s
|
||||
return nil, errors.NewForbiddenError("未建立培训档案,无法签到")
|
||||
}
|
||||
|
||||
// 名单校验(名单外人员自动标记;严格模式下直接拒绝,见下)。
|
||||
roster, err := s.repo.ListEnrollments(ctx, tenantID, session.ID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
inRoster := false
|
||||
for _, e := range roster {
|
||||
if e.MemberID == member.ID {
|
||||
inRoster = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
now := time.Now()
|
||||
|
||||
// 严格扫码链路(employee_no 非空,即 2026-11 新签到页):当天校验/工号+名单
|
||||
// 硬拒/nonce 防重放/时钟偏差仅作用于此链路。既有路径(登录态直签、代录补签)
|
||||
// 严格扫码链路(employee_no 非空,即 2026-11 新签到页):当天校验/工号一致
|
||||
// 校验/nonce 防重放/时钟偏差仅作用于此链路。既有路径(登录态直签、代录补签)
|
||||
// 行为不变 —— 尤其代录补签常发生在非当天,当天校验不得拦截。
|
||||
strictScan := strings.TrimSpace(in.EmployeeNo) != ""
|
||||
|
||||
@@ -953,15 +940,12 @@ func (s *trainingService) Checkin(ctx context.Context, tenantID uint64, userID s
|
||||
return nil, errors.NewBadRequestError("本课程签到已结束,无法补签")
|
||||
}
|
||||
|
||||
// 工号严格校验(2026-11 需求规则 2 + 补充规则):工号须与档案一致,且必须在
|
||||
// 「参加人员」名单中,名单外直接拒绝。
|
||||
// 工号严格校验(2026-11 需求规则 2):工号须与档案一致。2026-11-28 规则调整
|
||||
// 后不再要求在「参加人员」名单中,名单外人员照常签到,由明细标注区分。
|
||||
if strictScan {
|
||||
if !strings.EqualFold(strings.TrimSpace(member.EmployeeNo), strings.TrimSpace(in.EmployeeNo)) {
|
||||
return nil, errors.NewForbiddenError("录入工号与当前账号的档案工号不一致,请确认后重试")
|
||||
}
|
||||
if !inRoster {
|
||||
return nil, errors.NewForbiddenError("您不在该课程的「参加人员」名单中,请联系讲师或人事确认")
|
||||
}
|
||||
}
|
||||
|
||||
// nonce 防重放 + 时钟偏差(仅扫码链路携带;同 nonce 二次提交直接拒绝)。
|
||||
@@ -998,12 +982,6 @@ func (s *trainingService) Checkin(ctx context.Context, tenantID uint64, userID s
|
||||
}
|
||||
}
|
||||
|
||||
// 名单外人员标记(工号严格链路已在上方硬拒,此处仅既有登录态路径可达)。
|
||||
if !inRoster {
|
||||
flags = append(flags, "not_in_roster")
|
||||
status = types.TrainingSignAbnormal
|
||||
}
|
||||
|
||||
// 重复扫码直接拒绝(唯一约束兜底)。
|
||||
if _, err := s.repo.GetSignRecord(ctx, tenantID, session.ID, member.ID); err == nil {
|
||||
return nil, errors.NewBadRequestError("您已签到,请勿重复扫码")
|
||||
@@ -1031,11 +1009,6 @@ func (s *trainingService) Checkin(ctx context.Context, tenantID uint64, userID s
|
||||
if err := s.repo.UpsertSignRecord(ctx, record); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// 软性提示:名单外人员进入待复核队列。
|
||||
if !inRoster {
|
||||
_ = s.Notify(ctx, tenantID, userID, "signin_review",
|
||||
"签到待复核", "您的签到因名单校验未通过已进入待复核队列。", "session", session.ID)
|
||||
}
|
||||
return record, nil
|
||||
}
|
||||
|
||||
@@ -1114,14 +1087,19 @@ func (s *trainingService) ExportEvidence(ctx context.Context, tenantID uint64, s
|
||||
f := excelize.NewFile()
|
||||
sheet := "佐证包"
|
||||
f.SetSheetName("Sheet1", sheet)
|
||||
headers := []string{"部门", "工号", "姓名", "签到时间", "讲师姓名", "课程名称", "上课时间", "学员考试成绩"}
|
||||
// 2026-11-28 签到规则调整配套:全员可签到,佐证包标注要求/非要求培训人员。
|
||||
headers := []string{"部门", "工号", "姓名", "签到时间", "讲师姓名", "课程名称", "上课时间", "学员考试成绩", "人员类型"}
|
||||
for i, h := range headers {
|
||||
cell, _ := excelize.CoordinatesToCellName(i+1, 1)
|
||||
_ = f.SetCellValue(sheet, cell, h)
|
||||
}
|
||||
for r, row := range rows {
|
||||
rosterLabel := "非要求培训人员"
|
||||
if row.InRoster {
|
||||
rosterLabel = "要求培训人员"
|
||||
}
|
||||
values := []string{row.DeptName, row.EmployeeNo, row.MemberName, row.SignedAt,
|
||||
row.LecturerName, row.CourseName, row.SessionTime, row.ExamScore}
|
||||
row.LecturerName, row.CourseName, row.SessionTime, row.ExamScore, rosterLabel}
|
||||
for i, v := range values {
|
||||
cell, _ := excelize.CoordinatesToCellName(i+1, r+2)
|
||||
_ = f.SetCellValue(sheet, cell, v)
|
||||
|
||||
@@ -31,11 +31,8 @@ import (
|
||||
|
||||
// 周一讲师汇总提醒的规则键(ruleKeyNotifyWeeklyLecturer* 定义在
|
||||
// training_scheduler.go,同包共享);defaultWeeklyRemindHour 与需求"每周一 09:00"
|
||||
// 一致(北京时间)。pushLogDefaultLimit 推送记录默认拉取条数。
|
||||
const (
|
||||
defaultWeeklyRemindHour = 9
|
||||
pushLogDefaultLimit = 200
|
||||
)
|
||||
// 一致(北京时间)。
|
||||
const defaultWeeklyRemindHour = 9
|
||||
|
||||
// beijingZone 需求口径统一 Asia/Shanghai(周次/发送时点不随服务器时区漂移)。
|
||||
var beijingZone = time.FixedZone("Asia/Shanghai", 8*3600)
|
||||
@@ -642,15 +639,13 @@ func wecomDispatchContent(row *claimedNotification) string {
|
||||
// 推送记录(管理台逐人明细)
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
// ListPushLogs 管理端逐人推送明细:tr_notifications 按场景/引用过滤后映射
|
||||
// 收件人姓名与工号(org_employees 联 users 展示名)。
|
||||
// ListPushLogs 管理端逐人推送明细:tr_notifications 按时间/标题/企微状态/
|
||||
// 场景过滤后分页取数,映射收件人姓名与工号(org_employees 联 users 展示名),
|
||||
// 连同命中总数与全量状态统计一起组装分页结果。
|
||||
func (s *trainingService) ListPushLogs(
|
||||
ctx context.Context, tenantID uint64, scenes []string, refType string, limit int,
|
||||
) ([]*types.TrainingPushLog, error) {
|
||||
if limit <= 0 {
|
||||
limit = pushLogDefaultLimit
|
||||
}
|
||||
rows, err := s.repo.ListPushLogs(ctx, tenantID, scenes, refType, limit)
|
||||
ctx context.Context, tenantID uint64, q *types.TrainingPushLogQuery,
|
||||
) (*types.TrainingPushLogPage, error) {
|
||||
rows, total, stats, err := s.repo.ListPushLogs(ctx, tenantID, q)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -685,5 +680,5 @@ func (s *trainingService) ListPushLogs(
|
||||
}
|
||||
out = append(out, item)
|
||||
}
|
||||
return out, nil
|
||||
return &types.TrainingPushLogPage{Items: out, Total: total, Stats: stats}, nil
|
||||
}
|
||||
@@ -29,7 +29,9 @@ func (s *trainingService) CheckinFor(ctx context.Context, tenantID uint64, opera
|
||||
return s.Checkin(ctx, tenantID, operatorUserID, &types.CheckinInput{Token: token, Lat: lat, Lng: lng, Channel: channel})
|
||||
}
|
||||
// 复用 Checkin 的规则引擎,以目标成员的 user_id 走完整校验。
|
||||
// 代录不携工号/nonce:工号严格名单硬拒与防重放仅约束学员扫码链路。
|
||||
// 代录不携工号/nonce:工号严格校验与防重放仅约束学员扫码链路。
|
||||
// 2026-11-28 规则调整:名单外成员补录照常签到(明细标注非要求培训人员),
|
||||
// 不再进异常待复核。
|
||||
record, err := s.Checkin(ctx, tenantID, target.UserID, &types.CheckinInput{Token: token, Lat: lat, Lng: lng, Channel: "proxy"})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -262,8 +262,9 @@ func (s *trainingService) buildWecomCheckinPage(ctx context.Context, code *types
|
||||
// 当天性判定与 Checkin 的 same-day 规则同一口径(北京时间)。
|
||||
CanSignToday: session.StartAt != nil && sameBeijingDay(time.Now(), *session.StartAt),
|
||||
}
|
||||
// 名单/重复标记:前端提前渲染按钮态(置灰/已签到),提交时后端仍强校验兜底。
|
||||
// 匿名模式(member 为 nil,工号未输入)无从判定,交给提交时强校验。
|
||||
// 名单/重复标记:前端提前渲染提示(2026-11-28 规则调整后名单外照常可签到,
|
||||
// InRoster 仅作「非要求培训人员」提示,不再置灰拦截);提交时后端仍兜底校验。
|
||||
// 匿名模式(member 为 nil,工号未输入)无从判定,交给提交时校验。
|
||||
if member != nil {
|
||||
if roster, rerr := s.repo.ListEnrollments(ctx, code.TenantID, session.ID); rerr == nil {
|
||||
for _, e := range roster {
|
||||
@@ -308,8 +309,9 @@ func (s *trainingService) WecomCheckinPageAnon(ctx context.Context, token, emplo
|
||||
|
||||
// WecomCheckinByEmployee implements interfaces.TrainingService.
|
||||
// POST /training/wecom/checkin-by-employee — 工号扫码签到:
|
||||
// 签到码(token/轮换宽限)→ 工号反查档案 → 复用 Checkin 规则引擎(当天性/
|
||||
// 名单硬拒/围栏/迟到/重复/nonce 防重放)→ 按规则开关签发会话(自动登录)。
|
||||
// 签到码(token/轮换宽限)→ 工号反查档案(员工档案全员可签,2026-11-28 规则
|
||||
// 调整后不再限定「参加人员」名单)→ 复用 Checkin 规则引擎(当天性/工号一致/
|
||||
// 围栏/迟到/重复/nonce 防重放)→ 按规则开关签发会话(自动登录)。
|
||||
func (s *trainingService) WecomCheckinByEmployee(ctx context.Context, token, employeeNo string, lat, lng float64, nonce string, clientTS int64) (*types.WecomCheckinByEmployee, error) {
|
||||
token = strings.TrimSpace(token)
|
||||
employeeNo = strings.TrimSpace(employeeNo)
|
||||
@@ -327,7 +329,7 @@ func (s *trainingService) WecomCheckinByEmployee(ctx context.Context, token, emp
|
||||
if err != nil || member == nil {
|
||||
return nil, errors.NewNotFoundError("工号 " + employeeNo + " 不在培训档案中,请核对后重试或联系人事")
|
||||
}
|
||||
// 复用 Checkin 规则引擎:工号严格链路(employee_no 非空)当天性/名单硬拒/
|
||||
// 复用 Checkin 规则引擎:工号严格链路(employee_no 非空)当天性/工号一致/
|
||||
// nonce/时钟偏差全部生效;档案由工号反查而来,工号一致性天然成立。
|
||||
record, err := s.Checkin(ctx, code.TenantID, member.UserID, &types.CheckinInput{
|
||||
Token: token,
|
||||
|
||||
@@ -23,13 +23,13 @@ import (
|
||||
// trimSpace is a local strings.TrimSpace alias keeping call sites short.
|
||||
func trimSpace(raw string) string { return strings.TrimSpace(raw) }
|
||||
|
||||
// parseFlexibleTime accepts RFC3339 or "2006-01-02 15:04" / "2006-01-02".
|
||||
// parseFlexibleTime accepts RFC3339 or "2006-01-02 15:04:05" / "2006-01-02 15:04" / "2006-01-02".
|
||||
func parseFlexibleTime(raw string) *time.Time {
|
||||
raw = trimSpace(raw)
|
||||
if raw == "" {
|
||||
return nil
|
||||
}
|
||||
layouts := []string{time.RFC3339, "2006-01-02 15:04", "2006-01-02T15:04", "2006-01-02"}
|
||||
layouts := []string{time.RFC3339, "2006-01-02 15:04:05", "2006-01-02 15:04", "2006-01-02T15:04", "2006-01-02"}
|
||||
for _, layout := range layouts {
|
||||
if t, err := time.ParseInLocation(layout, raw, time.Local); err == nil {
|
||||
return &t
|
||||
@@ -835,8 +835,11 @@ func (h *Handler) RunWeeklyLecturerReminders(c *gin.Context) {
|
||||
}
|
||||
|
||||
// ListPushLogs GET /training/notifications/push-logs — 推送逐人明细(人事/课长):
|
||||
// 按场景集合(逗号分隔 scene 参数)与引用类型过滤,含收件人姓名/工号与企微
|
||||
// push_status(pending/sending/sent/skipped/dead;空=仅站内)。
|
||||
// 按时间范围(start_time/end_time,含 YYYY-MM-DD 与含时分秒格式)、标题模糊
|
||||
// (title)、企微状态(push_status:pending 含 sending/sent/skipped/dead/in_site,
|
||||
// 空=全部)、场景集合(逗号分隔 scenes)与引用类型(ref_type)过滤;
|
||||
// 返回当前页(items)、命中总数(total)与全量状态统计(stats,统计不受分页影响),
|
||||
// 含收件人姓名/工号与企微 push_status(空=仅站内)。
|
||||
func (h *Handler) ListPushLogs(c *gin.Context) {
|
||||
if !h.requireRoles(c, types.TrainingRoleHR, types.TrainingRoleSupervisor) {
|
||||
return
|
||||
@@ -849,12 +852,24 @@ func (h *Handler) ListPushLogs(c *gin.Context) {
|
||||
}
|
||||
}
|
||||
}
|
||||
limit, _ := strconv.Atoi(c.Query("limit"))
|
||||
items, err := h.svc.ListPushLogs(
|
||||
c.Request.Context(), callerTenantID(c), scenes, c.Query("ref_type"), limit)
|
||||
q := &types.TrainingPushLogQuery{
|
||||
Scenes: scenes,
|
||||
RefType: c.Query("ref_type"),
|
||||
Title: c.Query("title"),
|
||||
PushStatus: strings.TrimSpace(c.Query("push_status")),
|
||||
StartTime: parseFlexibleTime(c.Query("start_time")),
|
||||
EndTime: parseFlexibleTime(c.Query("end_time")),
|
||||
}
|
||||
if v, err := strconv.Atoi(c.Query("page")); err == nil {
|
||||
q.Page = v
|
||||
}
|
||||
if v, err := strconv.Atoi(c.Query("page_size")); err == nil {
|
||||
q.PageSize = v
|
||||
}
|
||||
page, err := h.svc.ListPushLogs(c.Request.Context(), callerTenantID(c), q)
|
||||
if err != nil {
|
||||
_ = c.Error(err)
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"success": true, "data": items})
|
||||
c.JSON(http.StatusOK, gin.H{"success": true, "data": page})
|
||||
}
|
||||
@@ -291,8 +291,9 @@ type TrainingRepository interface {
|
||||
CreateNotifications(ctx context.Context, rows []*types.TrainingNotification) error
|
||||
// ListNotificationsByRef 按引用对象(场次 ID/月份周次键)取已存在通知,供幂等预检。
|
||||
ListNotificationsByRef(ctx context.Context, tenantID uint64, refType, refID string) ([]*types.TrainingNotification, error)
|
||||
// ListPushLogs 管理端逐人推送明细(推送管理台"推送记录")。
|
||||
ListPushLogs(ctx context.Context, tenantID uint64, scenes []string, refType string, limit int) ([]*types.TrainingNotification, error)
|
||||
// ListPushLogs 管理端逐人推送明细(推送管理台"推送记录"):按时间/标题/
|
||||
// 企微状态/场景过滤,返回当前页行、命中总数与全量状态统计。
|
||||
ListPushLogs(ctx context.Context, tenantID uint64, q *types.TrainingPushLogQuery) ([]*types.TrainingNotification, int64, *types.TrainingPushLogStats, error)
|
||||
// ListMonthActiveSessions 某年月仍活跃(未取消)场次,供周一讲师未完成扫描。
|
||||
ListMonthActiveSessions(ctx context.Context, tenantID uint64, year, month int) ([]*types.TrainingCourseSession, error)
|
||||
// ListMembersByUserIDs 按平台用户 ID 集合取员工档案(联 users 取展示姓名)。
|
||||
@@ -565,8 +566,9 @@ type TrainingService interface {
|
||||
// RunWeeklyLecturerReminders 手动触发一轮"周一讲师未完成汇总提醒"
|
||||
// (轮次键=当月第 N 周,与调度器共用幂等;已完成讲师自然过滤)。返回入队条数。
|
||||
RunWeeklyLecturerReminders(ctx context.Context, tenantID uint64, operatorID string) (int, error)
|
||||
// ListPushLogs 管理端逐人推送明细(收件人姓名/工号已映射),供配置中心展示。
|
||||
ListPushLogs(ctx context.Context, tenantID uint64, scenes []string, refType string, limit int) ([]*types.TrainingPushLog, error)
|
||||
// ListPushLogs 管理端逐人推送明细(收件人姓名/工号已映射),供配置中心
|
||||
// 展示;返回当前页行、命中总数与全量状态统计(统计不受分页影响)。
|
||||
ListPushLogs(ctx context.Context, tenantID uint64, q *types.TrainingPushLogQuery) (*types.TrainingPushLogPage, error)
|
||||
}
|
||||
|
||||
// TrainingNotificationPusher exposes the WeCom push plumbing for operator
|
||||
|
||||
@@ -890,11 +890,14 @@ type TrainingSignRecord struct {
|
||||
|
||||
// 联查只读展示字段(不落库,签到明细学员列由 ListSignRecords JOIN 提供):
|
||||
// MemberName 真实姓名(users.display_name 优先,回退 username 工号);
|
||||
// EmployeeNo/DeptName 来自 org_employees/org_depts 联查。
|
||||
// EmployeeNo/DeptName 来自 org_employees/org_depts 联查;
|
||||
// InRoster 是否该场次「参加人员」名单内(2026-11-28 规则调整:全员可签到,
|
||||
// 明细按此标注「要求培训人员/非要求培训人员」,实时联查 tr_enrollments)。
|
||||
// 前端不再依赖名册全量反查(名册分页截断时学员列曾回退显示 member_id)。
|
||||
MemberName string `json:"member_name" gorm:"->"`
|
||||
EmployeeNo string `json:"employee_no" gorm:"->"`
|
||||
DeptName string `json:"dept_name" gorm:"->"`
|
||||
InRoster bool `json:"in_roster" gorm:"->"`
|
||||
}
|
||||
|
||||
// TableName pins the physical table name.
|
||||
@@ -907,8 +910,8 @@ type CheckinInput struct {
|
||||
Lat float64 `json:"lat"`
|
||||
Lng float64 `json:"lng"`
|
||||
Channel string `json:"channel"`
|
||||
// EmployeeNo 录入工号:非空时启用严格校验 —— 必须与登录账号档案工号一致,
|
||||
// 且必须在该场次「参加人员」名单中(名单外直接拒绝,不再仅标记待复核)。
|
||||
// EmployeeNo 录入工号:非空时启用严格校验 —— 必须与登录账号档案工号一致。
|
||||
// 2026-11-28 规则调整:不再校验「参加人员」名单,员工档案全员可签到。
|
||||
EmployeeNo string `json:"employee_no"`
|
||||
// Nonce 随机时间戳(前端生成 Date.now()+随机段):同 nonce 二次提交拒绝(防重放)。
|
||||
Nonce string `json:"nonce"`
|
||||
@@ -939,6 +942,8 @@ type WecomCheckinPage struct {
|
||||
// SessionID 场次 id(签到接口定位/排查用)。
|
||||
SessionID string `json:"session_id"`
|
||||
// SignExpireAt 当前签到码有效期:落地页倒计时数据源(补充需求 2)。
|
||||
// InRoster 是否「参加人员」名单内:2026-11-28 规则调整后仅作展示提示
|
||||
// (名单外照常可签到,前端提示将标注为非要求培训人员),不再置灰拦截。
|
||||
SignExpireAt *time.Time `json:"sign_expire_at"`
|
||||
InRoster bool `json:"in_roster"`
|
||||
AlreadySigned bool `json:"already_signed"`
|
||||
@@ -1437,6 +1442,37 @@ type TrainingStatCard struct {
|
||||
Tone string `json:"tone,omitempty"` // normal/good/warn/bad
|
||||
}
|
||||
|
||||
// TrainingPushLogQuery 推送记录查询条件(配置中心「推送记录」):
|
||||
// 时间按 created_at 闭区间,标题模糊匹配,push_status 空 = 全部。
|
||||
type TrainingPushLogQuery struct {
|
||||
Scenes []string
|
||||
RefType string
|
||||
Title string // 标题模糊匹配
|
||||
PushStatus string // sent/dead/skipped/pending(含sending)/in_site;空 = 全部
|
||||
StartTime *time.Time
|
||||
EndTime *time.Time
|
||||
Page int
|
||||
PageSize int
|
||||
}
|
||||
|
||||
// TrainingPushLogStats 推送记录统计(当前过滤条件命中的全量口径,与分页无关):
|
||||
// pending 合并 pending+sending(排队与投递中),in_site = push_status 空(仅站内)。
|
||||
type TrainingPushLogStats struct {
|
||||
Total int64 `json:"total"`
|
||||
Sent int64 `json:"sent"`
|
||||
Dead int64 `json:"dead"`
|
||||
Skipped int64 `json:"skipped"`
|
||||
Pending int64 `json:"pending"`
|
||||
InSite int64 `json:"in_site"`
|
||||
}
|
||||
|
||||
// TrainingPushLogPage 推送记录分页结果(响应 {"items","total","stats"})。
|
||||
type TrainingPushLogPage struct {
|
||||
Items []*TrainingPushLog `json:"items"`
|
||||
Total int64 `json:"total"`
|
||||
Stats *TrainingPushLogStats `json:"stats"`
|
||||
}
|
||||
|
||||
// TrainingPushLog 推送管理台逐人明细行(tr_notifications + 收件人姓名映射):
|
||||
// 一个场景一次轮次对应一人一行,push_status 空 = 仅站内不入企微外箱。
|
||||
type TrainingPushLog struct {
|
||||
@@ -1530,6 +1566,9 @@ type TrainingEvidenceRow struct {
|
||||
CourseName string `json:"course_name"`
|
||||
SessionTime string `json:"session_time"`
|
||||
ExamScore string `json:"exam_score"`
|
||||
// InRoster 是否「参加人员」名单内(2026-11-28 规则调整配套:佐证包标注
|
||||
// 要求/非要求培训人员)。
|
||||
InRoster bool `json:"in_roster"`
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
Reference in new issue
Block a user