This commit is contained in:
@@ -2,11 +2,13 @@ package admin
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
|
||||
dto "github.com/break/junhong_cmp_fiber/internal/model/dto"
|
||||
assetService "github.com/break/junhong_cmp_fiber/internal/service/asset"
|
||||
assetAuditSvc "github.com/break/junhong_cmp_fiber/internal/service/asset_audit"
|
||||
deviceService "github.com/break/junhong_cmp_fiber/internal/service/device"
|
||||
iotCardService "github.com/break/junhong_cmp_fiber/internal/service/iot_card"
|
||||
pollingSvc "github.com/break/junhong_cmp_fiber/internal/service/polling"
|
||||
@@ -20,6 +22,7 @@ import (
|
||||
// 提供统一的资产解析、实时状态、套餐查询、停复机、停用、轮询管控等接口
|
||||
type AssetHandler struct {
|
||||
assetService *assetService.Service
|
||||
assetAuditService *assetAuditSvc.Service
|
||||
deviceService *deviceService.Service
|
||||
iotCardService *iotCardService.Service
|
||||
iotCardStopResume *iotCardService.StopResumeService
|
||||
@@ -30,6 +33,7 @@ type AssetHandler struct {
|
||||
// NewAssetHandler 创建资产管理处理器
|
||||
func NewAssetHandler(
|
||||
assetSvc *assetService.Service,
|
||||
assetAuditService *assetAuditSvc.Service,
|
||||
deviceSvc *deviceService.Service,
|
||||
iotCardSvc *iotCardService.Service,
|
||||
iotCardStopResume *iotCardService.StopResumeService,
|
||||
@@ -37,6 +41,7 @@ func NewAssetHandler(
|
||||
) *AssetHandler {
|
||||
return &AssetHandler{
|
||||
assetService: assetSvc,
|
||||
assetAuditService: assetAuditService,
|
||||
deviceService: deviceSvc,
|
||||
iotCardService: iotCardSvc,
|
||||
iotCardStopResume: iotCardStopResume,
|
||||
@@ -258,6 +263,48 @@ func (h *AssetHandler) Orders(c *fiber.Ctx) error {
|
||||
return response.Success(c, result)
|
||||
}
|
||||
|
||||
// OperationLogs 查询资产操作审计日志
|
||||
// GET /api/admin/assets/:identifier/operation-logs
|
||||
func (h *AssetHandler) OperationLogs(c *fiber.Ctx) error {
|
||||
if h.assetAuditService == nil {
|
||||
return errors.New(errors.CodeInternalError, "资产审计服务未配置")
|
||||
}
|
||||
|
||||
asset, err := h.resolveByIdentifier(c)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
page := c.QueryInt("page", 1)
|
||||
pageSize := c.QueryInt("page_size", 20)
|
||||
if page <= 0 || pageSize <= 0 || pageSize > 100 {
|
||||
return errors.New(errors.CodeInvalidParam, "分页参数无效")
|
||||
}
|
||||
|
||||
operationType := strings.TrimSpace(c.Query("operation_type"))
|
||||
resultStatus := strings.TrimSpace(c.Query("result_status"))
|
||||
if resultStatus != "" &&
|
||||
resultStatus != constants.AssetAuditResultSuccess &&
|
||||
resultStatus != constants.AssetAuditResultFailed &&
|
||||
resultStatus != constants.AssetAuditResultDenied {
|
||||
return errors.New(errors.CodeInvalidParam, "无效的结果状态")
|
||||
}
|
||||
|
||||
result, err := h.assetAuditService.ListByAsset(c.UserContext(), assetAuditSvc.ListByAssetParams{
|
||||
AssetType: asset.AssetType,
|
||||
AssetID: asset.AssetID,
|
||||
Page: page,
|
||||
PageSize: pageSize,
|
||||
OperationType: operationType,
|
||||
ResultStatus: resultStatus,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return response.Success(c, result)
|
||||
}
|
||||
|
||||
// UpdatePollingStatus 更新资产轮询状态
|
||||
// PATCH /api/admin/assets/:identifier/polling-status
|
||||
func (h *AssetHandler) UpdatePollingStatus(c *fiber.Ctx) error {
|
||||
|
||||
Reference in New Issue
Block a user