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:
@@ -14,13 +14,19 @@ import (
|
||||
const (
|
||||
deviceExportBaseHeaderCount = 6
|
||||
deviceExportCardGroupSize = 5
|
||||
// deviceExportTailHeaderCount 是当前尾部固定列数(含新增的「关联手机号」列)。
|
||||
deviceExportTailHeaderCount = 6
|
||||
// deviceExportLegacyTailHeaderCount 是新增尾部列之前的固定列数,仅供历史任务表头反解回退使用。
|
||||
// deviceExportTailHeaderCount 是当前尾部固定列数(含「关联手机号」「设备合计(GB)」列)。
|
||||
deviceExportTailHeaderCount = 7
|
||||
// deviceExportPhoneTailHeaderCount 是新增「设备合计(GB)」之前、带「关联手机号」的尾部列数,供历史任务表头反解。
|
||||
deviceExportPhoneTailHeaderCount = 6
|
||||
// deviceExportLegacyTailHeaderCount 是新增「关联手机号」之前的尾部列数,供历史任务表头反解。
|
||||
deviceExportLegacyTailHeaderCount = 5
|
||||
deviceExportMinCardGroups = 1
|
||||
// deviceExportAssociatedPhoneHeader 是「关联手机号」列的表头,固定位于导出尾部。
|
||||
deviceExportAssociatedPhoneHeader = "关联手机号"
|
||||
// deviceExportTotalGBHeader 是「设备合计(GB)」列的表头,固定位于导出最后一列。
|
||||
deviceExportTotalGBHeader = "设备合计(GB)"
|
||||
// deviceExportMBPerGB MB 换算 GB 的进制。
|
||||
deviceExportMBPerGB = 1024
|
||||
)
|
||||
|
||||
// DeviceDataSource 设备导出数据源。
|
||||
@@ -64,6 +70,7 @@ func (s *DeviceDataSource) Fetch(ctx context.Context, params ExportParams, offse
|
||||
}
|
||||
|
||||
cardGroups := cardGroupCountFromHeaders(params.ResolvedHeaders)
|
||||
tailCount := deviceExportTailCount(params.ResolvedHeaders)
|
||||
if cardGroups <= 0 {
|
||||
resolved, err := s.resolveCardGroupCount(ctx, params)
|
||||
if err != nil {
|
||||
@@ -101,7 +108,7 @@ func (s *DeviceDataSource) Fetch(ctx context.Context, params ExportParams, offse
|
||||
|
||||
rows := make([][]string, 0, len(devices))
|
||||
for _, item := range devices {
|
||||
rows = append(rows, buildDeviceExportRow(item, cardMap[item.ID], packageMap[item.ID], associatedPhones[item.ID], cardGroups))
|
||||
rows = append(rows, buildDeviceExportRow(item, cardMap[item.ID], packageMap[item.ID], associatedPhones[item.ID], cardGroups, tailCount))
|
||||
}
|
||||
return rows, nil
|
||||
}
|
||||
@@ -375,22 +382,24 @@ func buildDeviceExportHeaders(cardGroups int) []string {
|
||||
fmt.Sprintf("ICCID%d", i),
|
||||
fmt.Sprintf("接入号%d", i),
|
||||
fmt.Sprintf("ICCID%d对应的运营商", i),
|
||||
fmt.Sprintf("ICCID%d使用的流量", i),
|
||||
fmt.Sprintf("ICCID%d使用的流量(MB)", i),
|
||||
fmt.Sprintf("卡状态%d", i),
|
||||
)
|
||||
}
|
||||
headers = append(headers,
|
||||
"设备合计",
|
||||
"设备合计(MB)",
|
||||
"套餐的生效时间",
|
||||
"套餐的到期时间",
|
||||
"当前套餐",
|
||||
"钱包余额",
|
||||
deviceExportAssociatedPhoneHeader,
|
||||
deviceExportTotalGBHeader,
|
||||
)
|
||||
return headers
|
||||
}
|
||||
|
||||
func buildDeviceExportRow(item deviceExportRow, cards []deviceExportCardRow, pkg deviceExportPackageRow, associatedPhone string, cardGroups int) []string {
|
||||
// buildDeviceExportRow 构造一行设备导出数据;tailCount 为冻结表头的尾部列数,历史表头不输出其后新增的列。
|
||||
func buildDeviceExportRow(item deviceExportRow, cards []deviceExportCardRow, pkg deviceExportPackageRow, associatedPhone string, cardGroups int, tailCount int) []string {
|
||||
if cardGroups < deviceExportMinCardGroups {
|
||||
cardGroups = deviceExportMinCardGroups
|
||||
}
|
||||
@@ -431,19 +440,35 @@ func buildDeviceExportRow(item deviceExportRow, cards []deviceExportCardRow, pkg
|
||||
formatOptionalTime(pkg.ExpiresAt),
|
||||
pkg.PackageName,
|
||||
formatMoneyYuan(item.WalletBalance),
|
||||
associatedPhone,
|
||||
)
|
||||
if tailCount >= deviceExportPhoneTailHeaderCount {
|
||||
row = append(row, associatedPhone)
|
||||
}
|
||||
if tailCount >= deviceExportTailHeaderCount {
|
||||
row = append(row, formatMB(totalUsage/deviceExportMBPerGB))
|
||||
}
|
||||
return row
|
||||
}
|
||||
|
||||
// cardGroupCountFromHeaders 从已持久化的表头反解卡组列数。
|
||||
// 先按当前尾列数判定;不整除时回退到新增尾部列之前的尾列数再判定,
|
||||
// 否则历史任务凭 ResolvedHeaders 重导出时列组数会被算成 0,缺失全部卡列。
|
||||
// 先按末列识别新旧表头的尾部列数再反解,否则历史任务凭 ResolvedHeaders 重导出时卡列组数会算错或为 0。
|
||||
func cardGroupCountFromHeaders(headers []string) int {
|
||||
if count := cardGroupCountWithTail(headers, deviceExportTailHeaderCount); count > 0 {
|
||||
return count
|
||||
return cardGroupCountWithTail(headers, deviceExportTailCount(headers))
|
||||
}
|
||||
|
||||
// deviceExportTailCount 按末列表头识别尾部固定列数:「设备合计(GB)」为当前表头,「关联手机号」为上一版,其余为最早版本。
|
||||
func deviceExportTailCount(headers []string) int {
|
||||
if len(headers) == 0 {
|
||||
return deviceExportTailHeaderCount
|
||||
}
|
||||
switch headers[len(headers)-1] {
|
||||
case deviceExportTotalGBHeader:
|
||||
return deviceExportTailHeaderCount
|
||||
case deviceExportAssociatedPhoneHeader:
|
||||
return deviceExportPhoneTailHeaderCount
|
||||
default:
|
||||
return deviceExportLegacyTailHeaderCount
|
||||
}
|
||||
return cardGroupCountWithTail(headers, deviceExportLegacyTailHeaderCount)
|
||||
}
|
||||
|
||||
// cardGroupCountWithTail 按指定尾部固定列数反解卡组列数,不整除即无法确定列组。
|
||||
|
||||
@@ -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"`
|
||||
|
||||
@@ -16,6 +16,8 @@ const (
|
||||
orderExportBaseHeaderCount = 11
|
||||
orderExportCardGroupSize = 2
|
||||
orderExportMinCardGroups = 1
|
||||
// orderExportOperatorHeader 操作人列固定追加在最后,历史任务的冻结表头没有该列。
|
||||
orderExportOperatorHeader = "操作人"
|
||||
)
|
||||
|
||||
// OrderDataSource 订单导出数据源。
|
||||
@@ -63,6 +65,7 @@ func (s *OrderDataSource) Fetch(ctx context.Context, params ExportParams, offset
|
||||
}
|
||||
|
||||
cardGroups := orderCardGroupCountFromHeaders(params.ResolvedHeaders)
|
||||
includeOperator := len(params.ResolvedHeaders) == 0 || orderHeadersIncludeOperator(params.ResolvedHeaders)
|
||||
if cardGroups <= 0 {
|
||||
resolved, err := s.resolveCardGroupCount(ctx, params)
|
||||
if err != nil {
|
||||
@@ -107,7 +110,11 @@ func (s *OrderDataSource) Fetch(ctx context.Context, params ExportParams, offset
|
||||
if item.DeviceID != nil {
|
||||
cards = cardMap[*item.DeviceID]
|
||||
}
|
||||
rows = append(rows, buildOrderExportRow(item, itemMap[item.ID], paymentMap[item.ID], cards, cardGroups))
|
||||
row := buildOrderExportRow(item, itemMap[item.ID], paymentMap[item.ID], cards, cardGroups)
|
||||
if includeOperator {
|
||||
row = append(row, item.OperatorAccountName)
|
||||
}
|
||||
rows = append(rows, row)
|
||||
}
|
||||
return rows, nil
|
||||
}
|
||||
@@ -243,6 +250,7 @@ func (s *OrderDataSource) fetchOrders(ctx context.Context, params ExportParams,
|
||||
o.payment_method,
|
||||
o.created_at,
|
||||
o.device_id,
|
||||
o.operator_account_name,
|
||||
COALESCE(sh.shop_name, '') AS shop_name
|
||||
`).
|
||||
Order("o.id DESC").
|
||||
@@ -461,6 +469,8 @@ type orderExportRow struct {
|
||||
PaymentMethod string `gorm:"column:payment_method"`
|
||||
CreatedAt time.Time `gorm:"column:created_at"`
|
||||
DeviceID *uint `gorm:"column:device_id"`
|
||||
// OperatorAccountName 订单创建时冻结的操作者名称,缺失时导出为空,不回查当前账号。
|
||||
OperatorAccountName string `gorm:"column:operator_account_name"`
|
||||
}
|
||||
|
||||
type orderExportItemRow struct {
|
||||
@@ -511,7 +521,7 @@ func buildOrderExportHeaders(cardGroups int) []string {
|
||||
fmt.Sprintf("ICCID%d", i),
|
||||
)
|
||||
}
|
||||
return headers
|
||||
return append(headers, orderExportOperatorHeader)
|
||||
}
|
||||
|
||||
func buildOrderExportRow(item orderExportRow, items []orderExportItemRow, payment orderExportPaymentRow, cards []orderExportCardRow, cardGroups int) []string {
|
||||
@@ -543,16 +553,25 @@ func buildOrderExportRow(item orderExportRow, items []orderExportItemRow, paymen
|
||||
}
|
||||
|
||||
func orderCardGroupCountFromHeaders(headers []string) int {
|
||||
if len(headers) < orderExportBaseHeaderCount {
|
||||
fixedCount := orderExportBaseHeaderCount
|
||||
if orderHeadersIncludeOperator(headers) {
|
||||
fixedCount++
|
||||
}
|
||||
if len(headers) < fixedCount {
|
||||
return 0
|
||||
}
|
||||
cardColumnCount := len(headers) - orderExportBaseHeaderCount
|
||||
cardColumnCount := len(headers) - fixedCount
|
||||
if cardColumnCount <= 0 || cardColumnCount%orderExportCardGroupSize != 0 {
|
||||
return 0
|
||||
}
|
||||
return cardColumnCount / orderExportCardGroupSize
|
||||
}
|
||||
|
||||
// orderHeadersIncludeOperator 判断冻结表头是否为带“操作人”末列的新表头。
|
||||
func orderHeadersIncludeOperator(headers []string) bool {
|
||||
return len(headers) > 0 && headers[len(headers)-1] == orderExportOperatorHeader
|
||||
}
|
||||
|
||||
func joinOrderPackageNames(items []orderExportItemRow) string {
|
||||
if len(items) == 0 {
|
||||
return ""
|
||||
|
||||
Reference in New Issue
Block a user