sync: 同步 v1.0.4 并脱敏配置与镜像
This commit is contained in:
@@ -16,14 +16,23 @@ func notifyCutoffBatch(ctx context.Context, key cutoffBatchGroupKey, items []loc
|
||||
return
|
||||
}
|
||||
|
||||
deptName := cutoffDeptName(ctx, key.CreatedDept)
|
||||
deptNames := make(map[int64]string)
|
||||
events := make([]warningnotify.Event, 0, len(items))
|
||||
for _, item := range items {
|
||||
card := item.Card
|
||||
deptID := cutoffNotificationDeptID(card, key.CreatedDept)
|
||||
if card.DeptId <= 0 {
|
||||
g.Log().Warningf(ctx, "TrafficCutoff notify fallback to created dept because card dept is empty, cardId:%d, iccid:%s, createdDept:%d", card.Id, card.Iccid, key.CreatedDept)
|
||||
}
|
||||
deptName, ok := deptNames[deptID]
|
||||
if !ok {
|
||||
deptName = cutoffDeptName(ctx, deptID)
|
||||
deptNames[deptID] = deptName
|
||||
}
|
||||
events = append(events, warningnotify.Event{
|
||||
Business: warningnotify.BusinessTrafficCutoff,
|
||||
TenantID: key.TenantId,
|
||||
DeptID: key.CreatedDept,
|
||||
DeptID: deptID,
|
||||
DeptName: deptName,
|
||||
CreatedBy: key.CreatedBy,
|
||||
Category: "达量断网",
|
||||
@@ -51,6 +60,13 @@ func notifyCutoffBatch(ctx context.Context, key cutoffBatchGroupKey, items []loc
|
||||
}
|
||||
}
|
||||
|
||||
func cutoffNotificationDeptID(card cutoffCard, fallbackDeptID int64) int64 {
|
||||
if card.DeptId > 0 {
|
||||
return card.DeptId
|
||||
}
|
||||
return fallbackDeptID
|
||||
}
|
||||
|
||||
func cutoffDeptName(ctx context.Context, deptID int64) string {
|
||||
if deptID <= 0 {
|
||||
return ""
|
||||
|
||||
@@ -103,6 +103,7 @@ func (s *sTrafficCutoff) queryCandidates(ctx context.Context, lastID int64, runT
|
||||
triggeredAtField,
|
||||
field(columns.ChanKey),
|
||||
field(columns.TenantId),
|
||||
field(columns.DeptId),
|
||||
field(columns.CreatedDept),
|
||||
field(columns.CreatedBy),
|
||||
cardflow.TotalFlowExpr(cardTable, packageAlias)+" AS total_flow_mb",
|
||||
|
||||
@@ -2,6 +2,7 @@ package trafficcutoff
|
||||
|
||||
import (
|
||||
"git.5iot.com/iotlcm-public/iotlcm-admin-svr/internal/consts"
|
||||
"git.5iot.com/iotlcm-public/iotlcm-admin-svr/internal/logic/warningnotify"
|
||||
"git.5iot.com/iotlcm-public/iotlcm-admin-svr/internal/model/entity"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -93,3 +94,58 @@ func TestMonthStart(t *testing.T) {
|
||||
t.Fatalf("monthStart() = %v, want %v", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCutoffNotificationDeptIDUsesCardCurrentDept(t *testing.T) {
|
||||
card := cutoffCard{TSimCardInfo: entity.TSimCardInfo{DeptId: 172, CreatedDept: 1, CreatedBy: 1}}
|
||||
if got := cutoffNotificationDeptID(card, card.CreatedDept); got != 172 {
|
||||
t.Fatalf("cutoffNotificationDeptID() = %d, want current card dept 172", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCutoffNotificationDeptIDFallsBackAndDoesNotSilentlyDrop(t *testing.T) {
|
||||
card := cutoffCard{TSimCardInfo: entity.TSimCardInfo{CreatedDept: 1, CreatedBy: 1}}
|
||||
if got := cutoffNotificationDeptID(card, card.CreatedDept); got != 1 {
|
||||
t.Fatalf("cutoffNotificationDeptID() = %d, want fallback created dept 1", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCutoffNotificationsSplitByCurrentCardDept(t *testing.T) {
|
||||
events := []warningnotify.Event{
|
||||
{
|
||||
Business: warningnotify.BusinessTrafficCutoff,
|
||||
TenantID: "000000",
|
||||
DeptID: 172,
|
||||
CreatedBy: 1,
|
||||
Category: "达量断网",
|
||||
ItemType: 1,
|
||||
ItemCode: "card-for-172",
|
||||
},
|
||||
{
|
||||
Business: warningnotify.BusinessTrafficCutoff,
|
||||
TenantID: "000000",
|
||||
DeptID: 206,
|
||||
CreatedBy: 1,
|
||||
Category: "达量断网",
|
||||
ItemType: 1,
|
||||
ItemCode: "card-for-206",
|
||||
},
|
||||
}
|
||||
|
||||
batches := warningnotify.BuildBatches(events)
|
||||
if len(batches) != 2 {
|
||||
t.Fatalf("BuildBatches() returned %d batches, want 2", len(batches))
|
||||
}
|
||||
|
||||
want := map[int64]string{172: "card-for-172", 206: "card-for-206"}
|
||||
for _, batch := range batches {
|
||||
if batch.Method != warningnotify.MethodPlatform {
|
||||
t.Fatalf("batch method = %s, want platform", batch.Method)
|
||||
}
|
||||
if len(batch.Items) != 1 {
|
||||
t.Fatalf("dept %d has %d items, want 1", batch.DeptID, len(batch.Items))
|
||||
}
|
||||
if wantCode, ok := want[batch.DeptID]; !ok || batch.Items[0].ItemCode != wantCode {
|
||||
t.Fatalf("batch dept=%d item=%s, want one matching current-dept card", batch.DeptID, batch.Items[0].ItemCode)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user