feat: 卡实名时间以上游 archiveTime 为准并记录实名时间历史,新增二次实名批次
Some checks failed
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Has been cancelled
Some checks failed
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Has been cancelled
This commit is contained in:
42
internal/query/cardrealname/current.go
Normal file
42
internal/query/cardrealname/current.go
Normal file
@@ -0,0 +1,42 @@
|
||||
// Package cardrealname 提供卡当前实名时间与实名时间历史的只读查询。
|
||||
package cardrealname
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/break/junhong_cmp_fiber/internal/model"
|
||||
"github.com/break/junhong_cmp_fiber/pkg/errors"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// Current 是卡当前实名时间及来源。
|
||||
type Current struct {
|
||||
RealnameAt *time.Time
|
||||
Source string
|
||||
}
|
||||
|
||||
// LoadCurrent 批量读取卡当前实名记录;没有记录的卡不在返回结果中。
|
||||
func LoadCurrent(ctx context.Context, db *gorm.DB, cardIDs []uint) (map[uint]Current, error) {
|
||||
result := make(map[uint]Current, len(cardIDs))
|
||||
if db == nil || len(cardIDs) == 0 {
|
||||
return result, nil
|
||||
}
|
||||
var rows []model.IotCardRealname
|
||||
if err := db.WithContext(ctx).Select("card_id", "realname_at", "realname_at_source").
|
||||
Where("card_id IN ?", cardIDs).Find(&rows).Error; err != nil {
|
||||
return nil, errors.Wrap(errors.CodeDatabaseError, err, "查询卡当前实名时间失败")
|
||||
}
|
||||
for _, row := range rows {
|
||||
result[row.CardID] = Current{RealnameAt: row.RealnameAt, Source: row.RealnameAtSource}
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// ResolveRealnameAt 返回卡的实名时间:有当前实名记录用记录(可能为空,如等待二次实名),没有记录回退 first_realname_at。
|
||||
func ResolveRealnameAt(current map[uint]Current, cardID uint, fallback *time.Time) (*time.Time, string) {
|
||||
if value, ok := current[cardID]; ok {
|
||||
return value.RealnameAt, value.Source
|
||||
}
|
||||
return fallback, ""
|
||||
}
|
||||
Reference in New Issue
Block a user