feat(企微签到):逻辑:员工使用企微扫码后直接跳出签到页面,在签到页面对该课程进行点击签到!
deploy-hxtesting / build-and-deploy (push) Successful in 1m14s

规则:1.签到要校验是否为培训当天签到,如果不是当天扫码签到则进行友好提示;2. 签到需提供员工工号及随机时间戳(超过签到二维码有效期后需重新扫码签到);3.签到二维码每5分钟自动更新一次(更新后之前扫码签到自动作废需重新扫码);
补充说明:1.签到页面需展示该签到课程相关信息;2.展示签到倒计时还有多久过期,过期后需重新扫码进行优化提示;3.签到后提示签到成功!自动登录进入平台系统并进入该课程详情页面
This commit is contained in:
runny committed 2026-11-25 11:02:48 +08:00
1 parent 9950a28346
commit f43fbef5db
24 files changed
+1336 -67

No files matched your search

@@ -48,6 +48,17 @@ func (r *trainingRepository) GetMemberByUserID(ctx context.Context, tenantID uin
return &m, nil
}
// GetMemberByWecomUserid 企微免登反查(2026-11 扫码签到):按绑定定位培训档案。
func (r *trainingRepository) GetMemberByWecomUserid(ctx context.Context, tenantID uint64, wecomUserid string) (*types.TrainingMember, error) {
var m types.TrainingMember
if err := r.db.WithContext(ctx).
Where("tenant_id = ? AND wecom_userid = ?", tenantID, wecomUserid).
First(&m).Error; err != nil {
return nil, err
}
return &m, nil
}
// FindArchiveTenantID 跨租户查找用户最早的在职员工档案所属租户(000160):
// 企业培训按「员工档案归属」解析数据空间 —— 用户当前所在工作区没有培训档案、
// 但组织中心(共享 org_employees)有在职档案时,培训域回落到档案所在租户,
@@ -751,18 +751,22 @@ func (r *trainingRepository) UpdateMaterial(ctx context.Context, material *types
// ---------------------------------------------------------------------------
// UpsertSignCode creates or refreshes the session's sign-in code.
// 2026-11 轮换需求:轮换时新行携带 prev_token/prev_expire_at(旧码宽限用),
// 一并覆盖,旧 token 即时退出当前码位。
func (r *trainingRepository) UpsertSignCode(ctx context.Context, code *types.TrainingSignCode) error {
return r.db.WithContext(ctx).
Clauses(clause.OnConflict{
Columns: []clause.Column{{Name: "tenant_id"}, {Name: "session_id"}},
DoUpdates: clause.Assignments(map[string]interface{}{
"token": gorm.Expr("EXCLUDED.token"),
"expire_at": gorm.Expr("EXCLUDED.expire_at"),
"geo_lat": gorm.Expr("EXCLUDED.geo_lat"),
"geo_lng": gorm.Expr("EXCLUDED.geo_lng"),
"geo_radius": gorm.Expr("EXCLUDED.geo_radius"),
"created_by": gorm.Expr("EXCLUDED.created_by"),
"updated_at": gorm.Expr("CURRENT_TIMESTAMP"),
"token": gorm.Expr("EXCLUDED.token"),
"expire_at": gorm.Expr("EXCLUDED.expire_at"),
"prev_token": gorm.Expr("EXCLUDED.prev_token"),
"prev_expire_at": gorm.Expr("EXCLUDED.prev_expire_at"),
"geo_lat": gorm.Expr("EXCLUDED.geo_lat"),
"geo_lng": gorm.Expr("EXCLUDED.geo_lng"),
"geo_radius": gorm.Expr("EXCLUDED.geo_radius"),
"created_by": gorm.Expr("EXCLUDED.created_by"),
"updated_at": gorm.Expr("CURRENT_TIMESTAMP"),
}),
}).
Create(code).Error
@@ -790,6 +794,19 @@ func (r *trainingRepository) GetSignCodeByToken(ctx context.Context, tenantID ui
return &c, nil
}
// GetSignCodeByTokenGlobal 匿名扫码入口按 token 全局定位签到码(不带租户条件,
// 租户由码行反解):命中当前码或轮换宽限中的前码(prev_token)。表按
// (tenant, session) 唯一,行数极小,OR 扫描无性能顾虑。
func (r *trainingRepository) GetSignCodeByTokenGlobal(ctx context.Context, token string) (*types.TrainingSignCode, error) {
var c types.TrainingSignCode
if err := r.db.WithContext(ctx).
Where("(token = ? OR prev_token = ?) AND deleted_at IS NULL", token, token).
Order("created_at DESC").First(&c).Error; err != nil {
return nil, err
}
return &c, nil
}
// UpsertSignRecord stores one sign-in (unique per session+member).
func (r *trainingRepository) UpsertSignRecord(ctx context.Context, record *types.TrainingSignRecord) error {
return r.db.WithContext(ctx).
@@ -808,6 +825,18 @@ func (r *trainingRepository) GetSignRecord(ctx context.Context, tenantID uint64,
return &rec, nil
}
// GetSignRecordByNonce 防重放(2026-11 扫码签到):nonce 已用过则拒绝。
// 调用方保证 nonce 非空(空 nonce 不查,避免命中历史空值行)。
func (r *trainingRepository) GetSignRecordByNonce(ctx context.Context, tenantID uint64, nonce string) (*types.TrainingSignRecord, error) {
var rec types.TrainingSignRecord
if err := r.db.WithContext(ctx).
Where("tenant_id = ? AND nonce = ? AND deleted_at IS NULL", tenantID, nonce).
First(&rec).Error; err != nil {
return nil, err
}
return &rec, nil
}
// GetSignRecordByID fetches one record by ID (复核入口)。
func (r *trainingRepository) GetSignRecordByID(ctx context.Context, tenantID uint64, id string) (*types.TrainingSignRecord, error) {
var rec types.TrainingSignRecord