fix: 第1批 M2、M3、M16、M23 导入与展示类缺陷
Some checks failed
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Failing after 8h37m36s
Some checks failed
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Failing after 8h37m36s
- M2 批量换绑表头改为“平台登录账号”,只认手机号,细分格式、不存在、多匹配、非平台、已禁用失败原因 - M3 后台订单列表与详情返回 C 端在线购买的交易流水号、支付渠道、商户名称,详情新增全部支付单 payments - M16 预警规则不再返回 real_data_mb,预警列表/详情新增 threshold_mb,导出末列追加“阈值流量(MB)” - M23 设备导入 IMEI 必填,空 IMEI 行记为失败 - OpenSpec Change fix-august-iteration-follow-up-gaps:13/18,导入任务、导出任务的 Worker 端到端验证与前端/运营通知待部署后完成
This commit is contained in:
@@ -195,7 +195,7 @@ type shopBusinessOwnerImportRow struct {
|
||||
ColumnCountMatched bool
|
||||
ShopCode string
|
||||
OperationType string
|
||||
OwnerUsername string
|
||||
OwnerPhone string
|
||||
Remark string
|
||||
}
|
||||
|
||||
@@ -236,7 +236,7 @@ func parseShopBusinessOwnerImportCSV(data []byte) ([]shopBusinessOwnerImportRow,
|
||||
row.ColumnCountMatched = true
|
||||
row.ShopCode = strings.TrimSpace(record[0])
|
||||
row.OperationType = strings.TrimSpace(record[1])
|
||||
row.OwnerUsername = strings.TrimSpace(record[2])
|
||||
row.OwnerPhone = strings.TrimSpace(record[2])
|
||||
row.Remark = strings.TrimSpace(record[3])
|
||||
rows = append(rows, row)
|
||||
}
|
||||
@@ -303,11 +303,11 @@ func (h *ShopBusinessOwnerImportHandler) processRow(ctx context.Context, taskRec
|
||||
clear := false
|
||||
switch row.OperationType {
|
||||
case constants.ShopBusinessOwnerImportOperationRebind:
|
||||
if row.OwnerUsername == "" {
|
||||
if row.OwnerPhone == "" {
|
||||
return failedShopBusinessOwnerImportItem(item, constants.ShopBusinessOwnerImportRowErrorOwnerRequired), nil
|
||||
}
|
||||
case constants.ShopBusinessOwnerImportOperationClear:
|
||||
if row.OwnerUsername != "" {
|
||||
if row.OwnerPhone != "" {
|
||||
return failedShopBusinessOwnerImportItem(item, constants.ShopBusinessOwnerImportRowErrorOwnerForbidden), nil
|
||||
}
|
||||
clear = true
|
||||
@@ -316,17 +316,14 @@ func (h *ShopBusinessOwnerImportHandler) processRow(ctx context.Context, taskRec
|
||||
}
|
||||
var ownerID *uint
|
||||
if !clear {
|
||||
var account model.Account
|
||||
if err := h.db.WithContext(ctx).
|
||||
Where("username = ? AND user_type = ? AND status = ?", row.OwnerUsername, constants.UserTypePlatform, constants.StatusEnabled).
|
||||
First(&account).Error; err != nil {
|
||||
if err != gorm.ErrRecordNotFound {
|
||||
return item, pkgerrors.Wrap(pkgerrors.CodeDatabaseError, err, "查询导入目标业务员失败")
|
||||
}
|
||||
return failedShopBusinessOwnerImportItem(item, constants.ShopBusinessOwnerImportRowErrorOwnerInvalid), nil
|
||||
resolved, reason, err := h.resolveImportOwner(ctx, row.OwnerPhone)
|
||||
if err != nil {
|
||||
return item, err
|
||||
}
|
||||
value := account.ID
|
||||
ownerID = &value
|
||||
if reason != "" {
|
||||
return failedShopBusinessOwnerImportItem(item, reason), nil
|
||||
}
|
||||
ownerID = &resolved
|
||||
}
|
||||
// 每行独立事务:成功行提交,失败行回滚并保留原值。
|
||||
rowErr := h.db.WithContext(ctx).Transaction(func(tx *gorm.DB) error {
|
||||
@@ -357,6 +354,46 @@ func (h *ShopBusinessOwnerImportHandler) processRow(ctx context.Context, taskRec
|
||||
return item, nil
|
||||
}
|
||||
|
||||
// resolveImportOwner 按手机号定位换绑目标平台账号;返回非空 reason 表示该行失败。
|
||||
// 先校验格式再查库;查询不按类型与状态过滤,才能区分不存在、多匹配、非平台与已禁用。
|
||||
func (h *ShopBusinessOwnerImportHandler) resolveImportOwner(ctx context.Context, phone string) (uint, string, error) {
|
||||
if !isShopBusinessOwnerImportPhone(phone) {
|
||||
return 0, constants.ShopBusinessOwnerImportRowErrorOwnerPhoneFormat, nil
|
||||
}
|
||||
var accounts []model.Account
|
||||
if err := h.db.WithContext(ctx).Select("id", "user_type", "status").
|
||||
Where("phone = ?", phone).Limit(2).Find(&accounts).Error; err != nil {
|
||||
return 0, "", pkgerrors.Wrap(pkgerrors.CodeDatabaseError, err, "查询导入目标业务员失败")
|
||||
}
|
||||
switch {
|
||||
case len(accounts) == 0:
|
||||
return 0, constants.ShopBusinessOwnerImportRowErrorOwnerNotFound, nil
|
||||
case len(accounts) > 1:
|
||||
return 0, constants.ShopBusinessOwnerImportRowErrorOwnerAmbiguous, nil
|
||||
case accounts[0].UserType != constants.UserTypePlatform:
|
||||
return 0, constants.ShopBusinessOwnerImportRowErrorOwnerNotPlatform, nil
|
||||
case accounts[0].Status != constants.StatusEnabled:
|
||||
return 0, constants.ShopBusinessOwnerImportRowErrorOwnerDisabled, nil
|
||||
}
|
||||
return accounts[0].ID, "", nil
|
||||
}
|
||||
|
||||
// isShopBusinessOwnerImportPhone 判断平台登录账号是否为 11 位数字手机号,与项目 DTO 的 len=11,numeric 口径一致。
|
||||
func isShopBusinessOwnerImportPhone(value string) bool {
|
||||
if len(value) != shopBusinessOwnerImportPhoneLength {
|
||||
return false
|
||||
}
|
||||
for i := 0; i < len(value); i++ {
|
||||
if value[i] < '0' || value[i] > '9' {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// shopBusinessOwnerImportPhoneLength 平台登录账号手机号位数。
|
||||
const shopBusinessOwnerImportPhoneLength = 11
|
||||
|
||||
// appendRowAudit 在行事务内写实际变更审计,含负责人前后值与行备注。
|
||||
// 行备注写入事件 Metadata,不进入资源前后值字段。
|
||||
func (h *ShopBusinessOwnerImportHandler) appendRowAudit(ctx context.Context, tx *gorm.DB, taskRecord *model.ShopBusinessOwnerImportTask, shop *model.Shop, before, after *uint, row shopBusinessOwnerImportRow) error {
|
||||
|
||||
Reference in New Issue
Block a user