sync: 同步 v1.0.4 开源代码并脱敏

This commit is contained in:
MiFaZhan
2026-10-29 14:52:43 +08:00
parent 32e4316ee4
commit 6893e21f07
136 changed files with 9851 additions and 436 deletions
+40 -3
View File
@@ -22,7 +22,7 @@ import (
)
const (
cascadeFailureReason = "同批存在校验失败,本次整批未入库"
cascadeFailureReason = "校验通过,但本批次存在失败明细,整批未执行入库"
maxIdentifierLength = 32
minICCIDLength = 19
minIMSILength = 15
@@ -237,6 +237,9 @@ func (e *executor) populateExcelRows(ctx context.Context, task *Task) error {
if err != nil {
return gerror.Wrap(err, "read inbound Excel rows failed")
}
if len(lines) == 0 || !hasInboundIdentifierHeader(headerIndex(lines[0])) {
return gerror.New("入库文件表头无效:缺少 ICCID、MSISDN 或 IMSI 列")
}
task.Rows = parseTableRows(lines)
return nil
}
@@ -281,9 +284,19 @@ func (e *executor) validate(ctx context.Context, task *Task) error {
}
syncInboundOptionsFromRows(task)
markSameBatchDuplicates(task.Rows)
if hasFailedRows(task.Rows) {
markIncompleteRows(task.Rows)
task.ValidCount = countValidRows(task.Rows)
return nil
}
if err := e.markStockDuplicates(ctx, task); err != nil {
return err
}
if hasFailedRows(task.Rows) {
markIncompleteRows(task.Rows)
task.ValidCount = countValidRows(task.Rows)
return nil
}
task.Options.ValidateUpstreamBasicInfo = normalizeUpstreamBasicInfoValidationOption(task.Options.ValidateUpstreamBasicInfo)
if e.upstream != nil && task.Options.ValidateUpstreamBasicInfo == "1" {
if err := e.validateUpstreamBasicInfo(ctx, task); err != nil {
@@ -350,6 +363,15 @@ func parseTableRows(lines [][]string) []*Row {
return rows
}
func hasInboundIdentifierHeader(header map[string]int) bool {
for _, key := range []string{"iccid", "msisdn", "imsi"} {
if _, ok := header[key]; ok {
return true
}
}
return false
}
func rowFromHeader(rowNo int, fields []string, header map[string]int) *Row {
raw := make(map[string]string, len(header))
for key, index := range header {
@@ -447,7 +469,7 @@ func headerIndex(fields []string) map[string]int {
indexes[key] = index
}
}
if _, ok := indexes["iccid"]; !ok {
if !hasInboundIdentifierHeader(indexes) {
return nil
}
return indexes
@@ -1382,13 +1404,27 @@ func countValidRows(rows []*Row) int {
func countFailedRows(rows []*Row) int {
count := 0
for _, row := range rows {
if row != nil && row.Reason != "" {
if row != nil && row.Reason != "" && row.Reason != cascadeFailureReason {
count++
}
}
return count
}
func inboundRowStatus(row *Row) string {
if IsCascadeFailure(row) {
return "未执行"
}
if row.Reason != "" {
return "失败"
}
return "成功"
}
func IsCascadeFailure(row *Row) bool {
return row != nil && row.Reason == cascadeFailureReason
}
func rowKeys(rows []*Row) ([]string, []string, []string) {
iccidSet := make(map[string]struct{}, len(rows))
msisdnSet := make(map[string]struct{}, len(rows))
@@ -1541,6 +1577,7 @@ func resultRequest(task *Task) batchresult.Request {
MSISDN: row.MSISDN,
IMSI: row.IMSI,
Success: row.Reason == "",
Status: inboundRowStatus(row),
Reason: row.Reason,
})
}