sync: 同步 v1.0.4 开源代码并脱敏
This commit is contained in:
@@ -166,68 +166,99 @@ func markAtomicFailure(task *Task, reason string) {
|
||||
task.FailureReason = reason
|
||||
for _, detail := range task.Details {
|
||||
if detail != nil && strings.TrimSpace(detail.Reason) == "" {
|
||||
detail.Reason = "本批次存在失败明细,整批未执行"
|
||||
detail.Reason = atomicNotExecutedReason
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const atomicNotExecutedReason = "校验通过,但本批次存在失败明细,整批未执行划拨"
|
||||
|
||||
func allocationDetailStatus(detail *Detail) int {
|
||||
if detail.Reason == atomicNotExecutedReason {
|
||||
return consts.BatchDetailStatusNotExecuted
|
||||
}
|
||||
if detail.Success() {
|
||||
return consts.BatchDetailStatusSuccess
|
||||
}
|
||||
return consts.BatchDetailStatusFailed
|
||||
}
|
||||
|
||||
func countValidationFailures(task *Task) int {
|
||||
count := 0
|
||||
for _, detail := range task.Details {
|
||||
if detail != nil && !detail.Success() && detail.Reason != atomicNotExecutedReason {
|
||||
count++
|
||||
}
|
||||
}
|
||||
return count
|
||||
}
|
||||
|
||||
func persistedAllocationDetailStatus(task *Task, detail *Detail) int {
|
||||
status := allocationDetailStatus(detail)
|
||||
if strings.TrimSpace(task.Batch.ParentBatchNo) != "" && status == consts.BatchDetailStatusSuccess {
|
||||
return consts.BatchDetailStatusRunning
|
||||
}
|
||||
return status
|
||||
}
|
||||
|
||||
func validateDetail(task *Task, detail *Detail) {
|
||||
if detail == nil || strings.TrimSpace(detail.Reason) != "" {
|
||||
if task == nil || detail == nil {
|
||||
return
|
||||
}
|
||||
var reasons []string
|
||||
if reason := strings.TrimSpace(detail.Reason); reason != "" {
|
||||
reasons = append(reasons, reason)
|
||||
}
|
||||
defer func() { detail.Reason = strings.Join(reasons, ";") }()
|
||||
if detail.ICCID == "" {
|
||||
detail.Reason = "ICCID不能为空"
|
||||
reasons = append(reasons, "ICCID不能为空")
|
||||
return
|
||||
}
|
||||
detail.Reason = ""
|
||||
target := resolveTarget(task, detail)
|
||||
if target == nil {
|
||||
return
|
||||
}
|
||||
detail.Target = target
|
||||
detail.TargetDeptID = target.DeptID
|
||||
if detail.TargetDeptKey == "" {
|
||||
detail.TargetDeptKey = strings.TrimSpace(target.DeptKey)
|
||||
}
|
||||
if detail.TargetDeptName == "" {
|
||||
detail.TargetDeptName = strings.TrimSpace(target.DeptName)
|
||||
reasons = append(reasons, detail.Reason)
|
||||
} else {
|
||||
detail.Target = target
|
||||
detail.TargetDeptID = target.DeptID
|
||||
if detail.TargetDeptKey == "" {
|
||||
detail.TargetDeptKey = strings.TrimSpace(target.DeptKey)
|
||||
}
|
||||
if detail.TargetDeptName == "" {
|
||||
detail.TargetDeptName = strings.TrimSpace(target.DeptName)
|
||||
}
|
||||
}
|
||||
if detail.Card == nil {
|
||||
detail.Reason = "ICCID不存在或不属于当前租户"
|
||||
reasons = append(reasons, "ICCID不存在或不属于当前租户")
|
||||
return
|
||||
}
|
||||
if strings.TrimSpace(detail.ICCID) != strings.TrimSpace(detail.Card.ICCID) {
|
||||
detail.Reason = "ICCID与卡档案不一致"
|
||||
reasons = append(reasons, "ICCID与卡档案不一致")
|
||||
return
|
||||
}
|
||||
detail.MSISDN = coalesce(detail.MSISDN, detail.Card.MSISDN)
|
||||
detail.IMSI = coalesce(detail.IMSI, detail.Card.IMSI)
|
||||
if detail.Card.DeptID != task.Batch.CreatedDept {
|
||||
detail.Reason = "ICCID不在当前操作员授权范围内"
|
||||
return
|
||||
reasons = append(reasons, "ICCID不在当前操作员授权范围内")
|
||||
}
|
||||
if strings.TrimSpace(detail.MSISDN) != "" && strings.TrimSpace(detail.MSISDN) != detail.Card.MSISDN {
|
||||
detail.Reason = "MSISDN与卡档案不一致"
|
||||
return
|
||||
reasons = append(reasons, "MSISDN与卡档案不一致")
|
||||
}
|
||||
if strings.TrimSpace(detail.IMSI) != "" && strings.TrimSpace(detail.IMSI) != detail.Card.IMSI {
|
||||
detail.Reason = "IMSI与卡档案不一致"
|
||||
return
|
||||
reasons = append(reasons, "IMSI与卡档案不一致")
|
||||
}
|
||||
if detail.Card.BossCardStatus == consts.SimBossCardStatusStopped {
|
||||
detail.Reason = "卡已停机,不能划拨"
|
||||
return
|
||||
reasons = append(reasons, "卡已停机,不能划拨")
|
||||
}
|
||||
if detail.Card.BossCardStatus == consts.SimBossCardStatusCanceled {
|
||||
detail.Reason = "卡已销户,不能划拨"
|
||||
return
|
||||
reasons = append(reasons, "卡已销户,不能划拨")
|
||||
}
|
||||
if detail.Card.PackageStatus == consts.PackageStatusExpired ||
|
||||
(detail.Card.FlowPkgEndAt != nil && !detail.Card.FlowPkgEndAt.IsZero() && detail.Card.FlowPkgEndAt.Before(gtime.Now())) {
|
||||
detail.Reason = "套餐已过期,不能划拨"
|
||||
return
|
||||
reasons = append(reasons, "套餐已过期,不能划拨")
|
||||
}
|
||||
if detail.Card.DeptID == target.DeptID {
|
||||
detail.Reason = "卡已属于目标客户,无需重复划拨"
|
||||
if target != nil && detail.Card.DeptID == target.DeptID {
|
||||
reasons = append(reasons, "卡已属于目标客户,无需重复划拨")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user