fix: 第1批 M1、M4~M6 登录密码统一规则与三类导出补列
Some checks failed
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Has been cancelled
Some checks failed
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Has been cancelled
- 七个设置登录密码入口统一 8~12 位、四类字符至少三类(1001/1016),修改密码与建店铺返回字段级提示 - 订单导出末列“操作人”、IoT 卡导出末列“套餐到期时间”、设备导出流量标 MB 并新增“设备合计(GB)” - 历史导出任务按冻结表头识别新旧尾列,行宽不变 - OpenSpec Change fix-august-iteration-export-and-password-hints:10/12,5.3 前端同步与 5.4 测试部署导出验证待完成
This commit is contained in:
@@ -7,17 +7,19 @@ import (
|
||||
|
||||
"gorm.io/gorm"
|
||||
|
||||
packageexpiryquery "github.com/break/junhong_cmp_fiber/internal/query/packageexpiry"
|
||||
"github.com/break/junhong_cmp_fiber/pkg/constants"
|
||||
)
|
||||
|
||||
// IotCardDataSource IoT 卡导出数据源。
|
||||
type IotCardDataSource struct {
|
||||
db *gorm.DB
|
||||
db *gorm.DB
|
||||
expiryQ *packageexpiryquery.Query
|
||||
}
|
||||
|
||||
// NewIotCardDataSource 创建 IoT 卡导出数据源。
|
||||
func NewIotCardDataSource(db *gorm.DB) *IotCardDataSource {
|
||||
return &IotCardDataSource{db: db}
|
||||
return &IotCardDataSource{db: db, expiryQ: packageexpiryquery.NewQuery(db)}
|
||||
}
|
||||
|
||||
// Scene 返回导出场景编码。
|
||||
@@ -37,8 +39,8 @@ func (s *IotCardDataSource) Count(ctx context.Context, params ExportParams) (int
|
||||
|
||||
// Headers 返回 IoT 卡导出表头。
|
||||
func (s *IotCardDataSource) Headers(ctx context.Context, params ExportParams) ([]string, error) {
|
||||
// 「关联手机号」固定追加在尾部:导出表头在 dispatch 阶段落库,历史任务重导出沿用同一列序。
|
||||
return []string{"ICCID", "MSISDN", "绑定设备虚拟号", "运营商", "店铺名称", "绑定设备名称", "是否实名", "实名时间", "网络状态", "套餐名称", "使用流量(MB)", "剩余流量(MB)", iotCardExportAssociatedPhoneHeader}, nil
|
||||
// 「关联手机号」「套餐到期时间」依次固定追加在尾部:导出表头在 dispatch 阶段落库,历史任务重导出沿用同一列序。
|
||||
return []string{"ICCID", "MSISDN", "绑定设备虚拟号", "运营商", "店铺名称", "绑定设备名称", "是否实名", "实名时间", "网络状态", "套餐名称", "使用流量(MB)", "剩余流量(MB)", iotCardExportAssociatedPhoneHeader, iotCardExportFinalExpiryHeader}, nil
|
||||
}
|
||||
|
||||
// Fetch 按 offset/limit 查询 IoT 卡导出数据。
|
||||
@@ -79,10 +81,18 @@ func (s *IotCardDataSource) Fetch(ctx context.Context, params ExportParams, offs
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
includeExpiry := len(params.ResolvedHeaders) == 0 || iotCardHeadersIncludeFinalExpiry(params.ResolvedHeaders)
|
||||
var finalExpiries map[uint]string
|
||||
if includeExpiry {
|
||||
finalExpiries, err = s.loadFinalExpiries(ctx, cardIDs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
rows := make([][]string, 0, len(items))
|
||||
for _, item := range items {
|
||||
rows = append(rows, []string{
|
||||
row := []string{
|
||||
item.ICCID,
|
||||
item.MSISDN,
|
||||
item.DeviceVirtualNo,
|
||||
@@ -96,11 +106,36 @@ func (s *IotCardDataSource) Fetch(ctx context.Context, params ExportParams, offs
|
||||
strconv.FormatInt(item.DataUsageMB, 10),
|
||||
strconv.FormatInt(remainingPackageDataMB(item.DataLimitMB, item.DataUsageMB), 10),
|
||||
associatedPhones[item.ID],
|
||||
})
|
||||
}
|
||||
if includeExpiry {
|
||||
row = append(row, finalExpiries[item.ID])
|
||||
}
|
||||
rows = append(rows, row)
|
||||
}
|
||||
return rows, nil
|
||||
}
|
||||
|
||||
// loadFinalExpiries 按分页批量推算卡的最终套餐到期时间,只有可精确推算时输出。
|
||||
func (s *IotCardDataSource) loadFinalExpiries(ctx context.Context, cardIDs []uint) (map[uint]string, error) {
|
||||
estimates, err := s.expiryQ.ResolveBatch(ctx, constants.AssetTypeIotCard, cardIDs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
result := make(map[uint]string, len(estimates))
|
||||
for cardID, estimate := range estimates {
|
||||
if estimate.ExpiryEstimateStatus != constants.PackageExpiryEstimateStatusExact {
|
||||
continue
|
||||
}
|
||||
result[cardID] = formatOptionalTime(estimate.EstimatedFinalExpiresAt)
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// iotCardHeadersIncludeFinalExpiry 判断冻结表头是否为带“套餐到期时间”末列的新表头。
|
||||
func iotCardHeadersIncludeFinalExpiry(headers []string) bool {
|
||||
return len(headers) > 0 && headers[len(headers)-1] == iotCardExportFinalExpiryHeader
|
||||
}
|
||||
|
||||
// baseQuery 构造卡导出的基础查询。
|
||||
// 绑定设备名称从当前有效绑定中取一条,避免多绑定历史记录放大导出行数。
|
||||
func (s *IotCardDataSource) baseQuery(ctx context.Context) *gorm.DB {
|
||||
@@ -234,6 +269,9 @@ func (s *IotCardDataSource) applyFilters(ctx context.Context, query *gorm.DB, pa
|
||||
// iotCardExportAssociatedPhoneHeader 是「关联手机号」列的表头,固定位于导出尾部。
|
||||
const iotCardExportAssociatedPhoneHeader = "关联手机号"
|
||||
|
||||
// iotCardExportFinalExpiryHeader 是「套餐到期时间」列的表头,固定位于导出最后一列。
|
||||
const iotCardExportFinalExpiryHeader = "套餐到期时间"
|
||||
|
||||
type iotCardExportRow struct {
|
||||
ID uint `gorm:"column:id"`
|
||||
ICCID string `gorm:"column:iccid"`
|
||||
|
||||
Reference in New Issue
Block a user