This commit is contained in:
@@ -1,235 +0,0 @@
|
||||
package iot_card
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/break/junhong_cmp_fiber/internal/model"
|
||||
assetAuditSvc "github.com/break/junhong_cmp_fiber/internal/service/asset_audit"
|
||||
"github.com/break/junhong_cmp_fiber/pkg/constants"
|
||||
)
|
||||
|
||||
// AssetAuditService 资产审计服务接口。
|
||||
type AssetAuditService interface {
|
||||
LogOperation(ctx context.Context, log *model.AssetOperationLog)
|
||||
}
|
||||
|
||||
func (s *Service) logCardAudit(ctx context.Context, p assetAuditSvc.BuildLogParams) {
|
||||
if s == nil || s.assetAuditService == nil {
|
||||
return
|
||||
}
|
||||
if p.Operator.Type == "" {
|
||||
p.Operator = assetAuditSvc.OperatorFromContext(ctx)
|
||||
}
|
||||
if p.AssetType == "" {
|
||||
p.AssetType = constants.AssetTypeIotCard
|
||||
}
|
||||
p.BeforeData, p.AfterData = normalizeCardAuditPayload(p.BeforeData, p.AfterData)
|
||||
s.assetAuditService.LogOperation(ctx, assetAuditSvc.BuildLog(ctx, p))
|
||||
}
|
||||
|
||||
func (s *StopResumeService) logCardAudit(ctx context.Context, p assetAuditSvc.BuildLogParams) {
|
||||
if s == nil || s.assetAuditService == nil {
|
||||
return
|
||||
}
|
||||
if p.Operator.Type == "" {
|
||||
p.Operator = assetAuditSvc.OperatorFromContext(ctx)
|
||||
}
|
||||
if p.AssetType == "" {
|
||||
p.AssetType = constants.AssetTypeIotCard
|
||||
}
|
||||
p.BeforeData, p.AfterData = normalizeCardAuditPayload(p.BeforeData, p.AfterData)
|
||||
s.assetAuditService.LogOperation(ctx, assetAuditSvc.BuildLog(ctx, p))
|
||||
}
|
||||
|
||||
func normalizeCardAuditPayload(beforeData, afterData map[string]any) (map[string]any, map[string]any) {
|
||||
snapshot := map[string]any(nil)
|
||||
if raw, ok := beforeData["card"]; ok {
|
||||
if m, ok := raw.(map[string]any); ok {
|
||||
snapshot = m
|
||||
}
|
||||
}
|
||||
if snapshot == nil {
|
||||
if raw, ok := afterData["card"]; ok {
|
||||
if m, ok := raw.(map[string]any); ok {
|
||||
snapshot = m
|
||||
}
|
||||
}
|
||||
}
|
||||
beforeContent := stripCardOperationMeta(beforeData)
|
||||
afterContent := stripCardOperationMeta(afterData)
|
||||
beforeContent = ensureCardOperationContentMap(beforeContent, beforeData)
|
||||
afterContent = ensureCardOperationContentMap(afterContent, afterData)
|
||||
enrichCardOperationContent(beforeContent, beforeData)
|
||||
enrichCardOperationContent(afterContent, afterData)
|
||||
return assetAuditSvc.WrapOperationContent(beforeContent, afterContent, snapshot)
|
||||
}
|
||||
|
||||
func stripCardOperationMeta(data map[string]any) map[string]any {
|
||||
if len(data) == 0 {
|
||||
return nil
|
||||
}
|
||||
out := make(map[string]any, len(data))
|
||||
for k, v := range data {
|
||||
if k == "device" || k == "card" || k == "cards" || k == "asset_snapshot" || k == "operation_content" {
|
||||
continue
|
||||
}
|
||||
out[k] = v
|
||||
}
|
||||
if len(out) == 0 {
|
||||
return nil
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func ensureCardOperationContentMap(content map[string]any, raw map[string]any) map[string]any {
|
||||
if content != nil || len(raw) == 0 {
|
||||
return content
|
||||
}
|
||||
if _, ok := raw["card"].(map[string]any); ok {
|
||||
return make(map[string]any)
|
||||
}
|
||||
if _, ok := raw["device"].(map[string]any); ok {
|
||||
return make(map[string]any)
|
||||
}
|
||||
switch raw["cards"].(type) {
|
||||
case []map[string]any, []any:
|
||||
return make(map[string]any)
|
||||
default:
|
||||
return content
|
||||
}
|
||||
}
|
||||
|
||||
func enrichCardOperationContent(content map[string]any, raw map[string]any) {
|
||||
if len(raw) == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
if cardRaw, ok := raw["card"].(map[string]any); ok {
|
||||
mergeReadableCardFields(content, cardRaw)
|
||||
}
|
||||
if deviceRaw, ok := raw["device"].(map[string]any); ok {
|
||||
mergeReadableDeviceFields(content, deviceRaw)
|
||||
}
|
||||
|
||||
switch cardsRaw := raw["cards"].(type) {
|
||||
case []map[string]any:
|
||||
cardIDs, iccids := collectCardReadableLists(cardsRaw)
|
||||
if len(cardIDs) > 0 && content["card_ids"] == nil {
|
||||
content["card_ids"] = cardIDs
|
||||
}
|
||||
if len(iccids) > 0 && content["iccids"] == nil {
|
||||
content["iccids"] = iccids
|
||||
}
|
||||
case []any:
|
||||
cards := make([]map[string]any, 0, len(cardsRaw))
|
||||
for _, item := range cardsRaw {
|
||||
cardMap, ok := item.(map[string]any)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
cards = append(cards, cardMap)
|
||||
}
|
||||
cardIDs, iccids := collectCardReadableLists(cards)
|
||||
if len(cardIDs) > 0 && content["card_ids"] == nil {
|
||||
content["card_ids"] = cardIDs
|
||||
}
|
||||
if len(iccids) > 0 && content["iccids"] == nil {
|
||||
content["iccids"] = iccids
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func mergeReadableCardFields(content map[string]any, card map[string]any) {
|
||||
if len(card) == 0 {
|
||||
return
|
||||
}
|
||||
if _, ok := content["card_id"]; !ok {
|
||||
if v, exists := card["id"]; exists {
|
||||
content["card_id"] = v
|
||||
}
|
||||
}
|
||||
if _, ok := content["iccid"]; !ok {
|
||||
if v := stringifyCardAuditValue(card["iccid"]); v != "" {
|
||||
content["iccid"] = v
|
||||
}
|
||||
}
|
||||
if _, ok := content["device_virtual_no"]; !ok {
|
||||
if v := stringifyCardAuditValue(card["device_virtual_no"]); v != "" {
|
||||
content["device_virtual_no"] = v
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func mergeReadableDeviceFields(content map[string]any, device map[string]any) {
|
||||
if len(device) == 0 {
|
||||
return
|
||||
}
|
||||
if _, ok := content["device_id"]; !ok {
|
||||
if v, exists := device["id"]; exists {
|
||||
content["device_id"] = v
|
||||
}
|
||||
}
|
||||
if _, ok := content["device_virtual_no"]; !ok {
|
||||
if v := stringifyCardAuditValue(device["virtual_no"]); v != "" {
|
||||
content["device_virtual_no"] = v
|
||||
}
|
||||
}
|
||||
if _, ok := content["device_imei"]; !ok {
|
||||
if v := stringifyCardAuditValue(device["imei"]); v != "" {
|
||||
content["device_imei"] = v
|
||||
}
|
||||
}
|
||||
if _, ok := content["device_sn"]; !ok {
|
||||
if v := stringifyCardAuditValue(device["sn"]); v != "" {
|
||||
content["device_sn"] = v
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func collectCardReadableLists(cards []map[string]any) ([]any, []string) {
|
||||
cardIDs := make([]any, 0, len(cards))
|
||||
iccids := make([]string, 0, len(cards))
|
||||
for _, card := range cards {
|
||||
if id, ok := card["id"]; ok {
|
||||
cardIDs = append(cardIDs, id)
|
||||
}
|
||||
if iccid := stringifyCardAuditValue(card["iccid"]); iccid != "" {
|
||||
iccids = append(iccids, iccid)
|
||||
}
|
||||
}
|
||||
return cardIDs, iccids
|
||||
}
|
||||
|
||||
func stringifyCardAuditValue(v any) string {
|
||||
switch vv := v.(type) {
|
||||
case string:
|
||||
return vv
|
||||
case fmt.Stringer:
|
||||
return vv.String()
|
||||
default:
|
||||
if vv == nil {
|
||||
return ""
|
||||
}
|
||||
return fmt.Sprint(vv)
|
||||
}
|
||||
}
|
||||
|
||||
func cardSnapshot(card *model.IotCard) map[string]any {
|
||||
if card == nil {
|
||||
return nil
|
||||
}
|
||||
return map[string]any{
|
||||
"id": card.ID,
|
||||
"iccid": card.ICCID,
|
||||
"device_virtual_no": card.DeviceVirtualNo,
|
||||
"shop_id": card.ShopID,
|
||||
"status": card.Status,
|
||||
"series_id": card.SeriesID,
|
||||
"enable_polling": card.EnablePolling,
|
||||
"realname_policy": card.RealnamePolicy,
|
||||
"real_name_status": card.RealNameStatus,
|
||||
"network_status": card.NetworkStatus,
|
||||
"stop_reason": card.StopReason,
|
||||
}
|
||||
}
|
||||
16
internal/service/iot_card/card_snapshot.go
Normal file
16
internal/service/iot_card/card_snapshot.go
Normal file
@@ -0,0 +1,16 @@
|
||||
package iot_card
|
||||
|
||||
import "github.com/break/junhong_cmp_fiber/internal/model"
|
||||
|
||||
func cardSnapshot(card *model.IotCard) map[string]any {
|
||||
if card == nil {
|
||||
return nil
|
||||
}
|
||||
return map[string]any{
|
||||
"id": card.ID, "iccid": card.ICCID, "device_virtual_no": card.DeviceVirtualNo,
|
||||
"shop_id": card.ShopID, "status": card.Status, "series_id": card.SeriesID,
|
||||
"enable_polling": card.EnablePolling, "realname_policy": card.RealnamePolicy,
|
||||
"real_name_status": card.RealNameStatus, "network_status": card.NetworkStatus,
|
||||
"stop_reason": card.StopReason,
|
||||
}
|
||||
}
|
||||
85
internal/service/iot_card/polling_audit.go
Normal file
85
internal/service/iot_card/polling_audit.go
Normal file
@@ -0,0 +1,85 @@
|
||||
package iot_card
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strconv"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"gorm.io/gorm"
|
||||
|
||||
infraAudit "github.com/break/junhong_cmp_fiber/internal/infrastructure/audit"
|
||||
"github.com/break/junhong_cmp_fiber/internal/model"
|
||||
assetAuditSvc "github.com/break/junhong_cmp_fiber/internal/service/asset_audit"
|
||||
"github.com/break/junhong_cmp_fiber/pkg/auditcontext"
|
||||
"github.com/break/junhong_cmp_fiber/pkg/auditfailure"
|
||||
"github.com/break/junhong_cmp_fiber/pkg/constants"
|
||||
"github.com/break/junhong_cmp_fiber/pkg/errors"
|
||||
)
|
||||
|
||||
func (s *Service) appendPollingStatusAudit(ctx context.Context, tx *gorm.DB, card *model.IotCard, before, after bool) error {
|
||||
return s.appendCardLifecycleAudit(ctx, tx, constants.AuditActionIotCardPollingStatusUpdated, "更新 IoT 卡轮询开关", constants.AuditResultSuccess, card,
|
||||
map[string]any{"enable_polling": before}, map[string]any{"enable_polling": after}, nil)
|
||||
}
|
||||
|
||||
func (s *Service) appendBatchPollingStatusAudit(ctx context.Context, tx *gorm.DB, cards []*model.IotCard, enablePolling bool) error {
|
||||
if s.auditWriter == nil {
|
||||
return errors.New(errors.CodeInvalidStatus, "IoT 卡统一审计接缝未配置")
|
||||
}
|
||||
linkage := auditcontext.From(ctx)
|
||||
batchKey := linkage.RequestID
|
||||
if batchKey == "" {
|
||||
batchKey = uuid.NewString()
|
||||
}
|
||||
rootEventID := "evt_" + uuid.NewSHA1(uuid.NameSpaceOID, []byte("iot-card-polling-status:"+batchKey)).String()
|
||||
children := make([]infraAudit.AppendInput, 0, len(cards))
|
||||
for _, card := range cards {
|
||||
if card == nil || card.ID == 0 {
|
||||
continue
|
||||
}
|
||||
id := strconv.FormatUint(uint64(card.ID), 10)
|
||||
children = append(children, infraAudit.AppendInput{
|
||||
EventID: "evt_" + uuid.NewSHA1(uuid.NameSpaceOID, []byte(rootEventID+":"+id)).String(),
|
||||
ActionCode: constants.AuditActionIotCardPollingStatusUpdated,
|
||||
Summary: "批量更新 IoT 卡轮询开关",
|
||||
Result: constants.AuditResultSuccess,
|
||||
Resources: []infraAudit.ResourceInput{{
|
||||
Type: constants.AuditResourceIotCard, ID: &id, Key: infraAudit.IotCardResourceKey(card), DisplayName: card.ICCID,
|
||||
Relation: constants.AuditResourceRelationPrimary, Role: constants.AuditResourceRoleIotCardTarget,
|
||||
IdentitySnapshot: infraAudit.IotCardIdentitySnapshot(card),
|
||||
BeforeData: map[string]any{"enable_polling": card.EnablePolling}, AfterData: map[string]any{"enable_polling": enablePolling},
|
||||
SubjectVisibility: constants.AuditSubjectResult, SubjectSummary: "IoT 卡轮询开关已更新",
|
||||
}},
|
||||
})
|
||||
}
|
||||
return s.auditWriter.AppendBatch(ctx, tx, infraAudit.BatchInput{
|
||||
Root: infraAudit.AppendInput{
|
||||
EventID: rootEventID,
|
||||
ActionCode: constants.AuditActionIotCardPollingStatusBatchUpdated,
|
||||
Summary: "批量更新 IoT 卡轮询开关", Result: constants.AuditResultSuccess,
|
||||
BatchTotal: len(children), SuccessCount: len(children),
|
||||
Resources: []infraAudit.ResourceInput{{
|
||||
Type: constants.AuditResourceIotCardBatch, Key: batchKey, DisplayName: batchKey,
|
||||
Relation: constants.AuditResourceRelationPrimary, Role: constants.AuditResourceRoleIotCardBatch,
|
||||
IdentitySnapshot: map[string]any{"card_count": len(children), "enable_polling": enablePolling},
|
||||
SubjectVisibility: constants.AuditSubjectInternalOnly,
|
||||
}},
|
||||
},
|
||||
Children: children,
|
||||
})
|
||||
}
|
||||
|
||||
func (s *Service) recordPollingStatusFailure(ctx context.Context, actionCode, result string, card *model.IotCard, enablePolling bool, businessErr error) {
|
||||
if card == nil || card.ID == 0 || s.db == nil || s.auditWriter == nil {
|
||||
return
|
||||
}
|
||||
err := s.db.WithContext(ctx).Transaction(func(tx *gorm.DB) error {
|
||||
return s.appendCardLifecycleAudit(ctx, tx, actionCode, "更新 IoT 卡轮询开关失败", result, card, nil,
|
||||
map[string]any{"enable_polling": enablePolling}, businessErr)
|
||||
})
|
||||
if err == nil {
|
||||
return
|
||||
}
|
||||
linkage := auditcontext.From(ctx)
|
||||
errorCode, _ := assetAuditSvc.BuildErrorInfo(businessErr)
|
||||
auditfailure.RecordSecondaryWriteFailure(actionCode, strconv.FormatUint(uint64(card.ID), 10), linkage.RequestID, linkage.CorrelationID, errorCode, err)
|
||||
}
|
||||
@@ -14,7 +14,6 @@ import (
|
||||
"github.com/break/junhong_cmp_fiber/internal/model"
|
||||
"github.com/break/junhong_cmp_fiber/internal/model/dto"
|
||||
packageexpiry "github.com/break/junhong_cmp_fiber/internal/query/packageexpiry"
|
||||
assetAuditSvc "github.com/break/junhong_cmp_fiber/internal/service/asset_audit"
|
||||
"github.com/break/junhong_cmp_fiber/internal/store"
|
||||
"github.com/break/junhong_cmp_fiber/internal/store/postgres"
|
||||
"github.com/break/junhong_cmp_fiber/pkg/auditcontext"
|
||||
@@ -68,7 +67,6 @@ type Service struct {
|
||||
deviceSimBindingStore *postgres.DeviceSimBindingStore
|
||||
redis *redis.Client
|
||||
assetIdentifierStore *postgres.AssetIdentifierStore
|
||||
assetAuditService AssetAuditService
|
||||
enterpriseCardAuthStore *postgres.EnterpriseCardAuthorizationStore
|
||||
enterpriseStore *postgres.EnterpriseStore
|
||||
packageExpiryQuery *packageexpiry.Query
|
||||
@@ -109,7 +107,6 @@ func New(
|
||||
packageSeriesStore *postgres.PackageSeriesStore,
|
||||
gatewayClient *gateway.Client,
|
||||
logger *zap.Logger,
|
||||
assetAuditService AssetAuditService,
|
||||
) *Service {
|
||||
return &Service{
|
||||
db: db,
|
||||
@@ -121,7 +118,6 @@ func New(
|
||||
packageSeriesStore: packageSeriesStore,
|
||||
gatewayClient: gatewayClient,
|
||||
logger: logger,
|
||||
assetAuditService: assetAuditService,
|
||||
packageExpiryQuery: packageexpiry.NewQuery(db),
|
||||
}
|
||||
}
|
||||
@@ -1696,77 +1692,33 @@ func parseGatewayRealnameStatus(realStatus bool) int {
|
||||
func (s *Service) UpdatePollingStatus(ctx context.Context, cardID uint, enablePolling bool) error {
|
||||
card, err := s.iotCardStore.GetByID(ctx, cardID)
|
||||
if err != nil {
|
||||
appErr := errors.Wrap(errors.CodeDatabaseError, err, "查询 IoT 卡失败")
|
||||
result := constants.AuditResultFailed
|
||||
if err == gorm.ErrRecordNotFound {
|
||||
denyErr := errors.New(errors.CodeNotFound, "IoT卡不存在")
|
||||
errorCode, errorMsg := assetAuditSvc.BuildErrorInfo(denyErr)
|
||||
s.logCardAudit(ctx, assetAuditSvc.BuildLogParams{
|
||||
OperationType: constants.AssetAuditOpCardPollingStatus,
|
||||
OperationDesc: "更新卡轮询状态被拒绝",
|
||||
ResultStatus: constants.AssetAuditResultDenied,
|
||||
ErrorCode: errorCode,
|
||||
ErrorMsg: errorMsg,
|
||||
AssetID: cardID,
|
||||
AssetIdentifier: "",
|
||||
AfterData: map[string]any{
|
||||
"enable_polling": enablePolling,
|
||||
},
|
||||
})
|
||||
return denyErr
|
||||
appErr = errors.New(errors.CodeNotFound, "IoT卡不存在")
|
||||
result = constants.AuditResultDenied
|
||||
}
|
||||
errorCode, errorMsg := assetAuditSvc.BuildErrorInfo(err)
|
||||
s.logCardAudit(ctx, assetAuditSvc.BuildLogParams{
|
||||
OperationType: constants.AssetAuditOpCardPollingStatus,
|
||||
OperationDesc: "更新卡轮询状态执行失败",
|
||||
ResultStatus: constants.AssetAuditResultFailed,
|
||||
ErrorCode: errorCode,
|
||||
ErrorMsg: errorMsg,
|
||||
AssetID: cardID,
|
||||
AfterData: map[string]any{
|
||||
"enable_polling": enablePolling,
|
||||
},
|
||||
})
|
||||
s.recordPollingStatusFailure(ctx, constants.AuditActionIotCardPollingStatusUpdated, result, &model.IotCard{Model: gorm.Model{ID: cardID}}, enablePolling, appErr)
|
||||
return appErr
|
||||
}
|
||||
beforePolling := card.EnablePolling
|
||||
err = s.db.WithContext(ctx).Transaction(func(tx *gorm.DB) error {
|
||||
if beforePolling != enablePolling {
|
||||
result := tx.Model(&model.IotCard{}).Where("id = ? AND enable_polling = ?", card.ID, beforePolling).Update("enable_polling", enablePolling)
|
||||
if result.Error != nil {
|
||||
return errors.Wrap(errors.CodeDatabaseError, result.Error, "更新 IoT 卡轮询状态失败")
|
||||
}
|
||||
if result.RowsAffected == 0 {
|
||||
return errors.New(errors.CodeConflict, "轮询状态已变更,请刷新后重试")
|
||||
}
|
||||
}
|
||||
return s.appendPollingStatusAudit(ctx, tx, card, beforePolling, enablePolling)
|
||||
})
|
||||
if err != nil {
|
||||
s.recordPollingStatusFailure(ctx, constants.AuditActionIotCardPollingStatusUpdated, constants.AuditResultFailed, card, enablePolling, err)
|
||||
return err
|
||||
}
|
||||
|
||||
// 检查是否需要更新
|
||||
if card.EnablePolling == enablePolling {
|
||||
s.logCardAudit(ctx, assetAuditSvc.BuildLogParams{
|
||||
OperationType: constants.AssetAuditOpCardPollingStatus,
|
||||
OperationDesc: "更新卡轮询状态",
|
||||
ResultStatus: constants.AssetAuditResultSuccess,
|
||||
AssetID: card.ID,
|
||||
AssetIdentifier: card.ICCID,
|
||||
BeforeData: map[string]any{
|
||||
"enable_polling": card.EnablePolling,
|
||||
},
|
||||
AfterData: map[string]any{
|
||||
"enable_polling": enablePolling,
|
||||
},
|
||||
})
|
||||
return nil // 状态未变化
|
||||
}
|
||||
|
||||
// 更新数据库
|
||||
card.EnablePolling = enablePolling
|
||||
if err := s.iotCardStore.Update(ctx, card); err != nil {
|
||||
errorCode, errorMsg := assetAuditSvc.BuildErrorInfo(err)
|
||||
s.logCardAudit(ctx, assetAuditSvc.BuildLogParams{
|
||||
OperationType: constants.AssetAuditOpCardPollingStatus,
|
||||
OperationDesc: "更新卡轮询状态执行失败",
|
||||
ResultStatus: constants.AssetAuditResultFailed,
|
||||
ErrorCode: errorCode,
|
||||
ErrorMsg: errorMsg,
|
||||
AssetID: card.ID,
|
||||
AssetIdentifier: card.ICCID,
|
||||
BeforeData: map[string]any{
|
||||
"enable_polling": !enablePolling,
|
||||
},
|
||||
AfterData: map[string]any{
|
||||
"enable_polling": enablePolling,
|
||||
},
|
||||
})
|
||||
return err
|
||||
}
|
||||
|
||||
s.logger.Info("更新卡轮询状态",
|
||||
zap.Uint("card_id", cardID),
|
||||
@@ -1782,20 +1734,6 @@ func (s *Service) UpdatePollingStatus(ctx context.Context, cardID uint, enablePo
|
||||
}
|
||||
}
|
||||
|
||||
s.logCardAudit(ctx, assetAuditSvc.BuildLogParams{
|
||||
OperationType: constants.AssetAuditOpCardPollingStatus,
|
||||
OperationDesc: "更新卡轮询状态",
|
||||
ResultStatus: constants.AssetAuditResultSuccess,
|
||||
AssetID: card.ID,
|
||||
AssetIdentifier: card.ICCID,
|
||||
BeforeData: map[string]any{
|
||||
"enable_polling": !enablePolling,
|
||||
},
|
||||
AfterData: map[string]any{
|
||||
"enable_polling": enablePolling,
|
||||
},
|
||||
})
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -1805,23 +1743,17 @@ func (s *Service) BatchUpdatePollingStatus(ctx context.Context, cardIDs []uint,
|
||||
return nil
|
||||
}
|
||||
|
||||
// 批量更新数据库
|
||||
if err := s.iotCardStore.BatchUpdatePollingStatus(ctx, cardIDs, enablePolling); err != nil {
|
||||
errorCode, errorMsg := assetAuditSvc.BuildErrorInfo(err)
|
||||
s.logCardAudit(ctx, assetAuditSvc.BuildLogParams{
|
||||
OperationType: constants.AssetAuditOpCardPollingStatus,
|
||||
OperationDesc: "批量更新卡轮询状态执行失败",
|
||||
ResultStatus: constants.AssetAuditResultFailed,
|
||||
ErrorCode: errorCode,
|
||||
ErrorMsg: errorMsg,
|
||||
BatchTotal: len(cardIDs),
|
||||
FailCount: len(cardIDs),
|
||||
AfterData: map[string]any{
|
||||
"card_ids": cardIDs,
|
||||
"enable_polling": enablePolling,
|
||||
"trigger_source": "batch",
|
||||
},
|
||||
})
|
||||
cards, err := s.iotCardStore.GetByIDs(ctx, cardIDs)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = s.db.WithContext(ctx).Transaction(func(tx *gorm.DB) error {
|
||||
if updateErr := tx.Model(&model.IotCard{}).Where("id IN ?", cardIDs).Update("enable_polling", enablePolling).Error; updateErr != nil {
|
||||
return errors.Wrap(errors.CodeDatabaseError, updateErr, "批量更新 IoT 卡轮询状态失败")
|
||||
}
|
||||
return s.appendBatchPollingStatusAudit(ctx, tx, cards, enablePolling)
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -1841,19 +1773,6 @@ func (s *Service) BatchUpdatePollingStatus(ctx context.Context, cardIDs []uint,
|
||||
}
|
||||
}
|
||||
|
||||
s.logCardAudit(ctx, assetAuditSvc.BuildLogParams{
|
||||
OperationType: constants.AssetAuditOpCardPollingStatus,
|
||||
OperationDesc: "批量更新卡轮询状态",
|
||||
ResultStatus: constants.AssetAuditResultSuccess,
|
||||
BatchTotal: len(cardIDs),
|
||||
SuccessCount: len(cardIDs),
|
||||
AfterData: map[string]any{
|
||||
"card_ids": cardIDs,
|
||||
"enable_polling": enablePolling,
|
||||
"trigger_source": "batch",
|
||||
},
|
||||
})
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -45,7 +45,6 @@ type StopResumeService struct {
|
||||
deviceSimBindingStore *postgres.DeviceSimBindingStore
|
||||
gatewayClient *gateway.Client
|
||||
logger *zap.Logger
|
||||
assetAuditService AssetAuditService
|
||||
pollingCallback PollingCallback
|
||||
observationSeriesEvents cardObservationApp.SeriesEventWriter
|
||||
auditWriter *audit.Writer
|
||||
@@ -75,7 +74,6 @@ func NewStopResumeService(
|
||||
deviceSimBindingStore *postgres.DeviceSimBindingStore,
|
||||
gatewayClient *gateway.Client,
|
||||
logger *zap.Logger,
|
||||
assetAuditService AssetAuditService,
|
||||
) *StopResumeService {
|
||||
return &StopResumeService{
|
||||
redis: redis,
|
||||
@@ -84,7 +82,6 @@ func NewStopResumeService(
|
||||
deviceSimBindingStore: deviceSimBindingStore,
|
||||
gatewayClient: gatewayClient,
|
||||
logger: logger,
|
||||
assetAuditService: assetAuditService,
|
||||
maxRetries: 3,
|
||||
retryInterval: 2 * time.Second,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user