All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 5m30s
主要变更: - 实现设备管理模块(创建、查询、列表、更新状态、删除) - 实现设备批量导入功能(CSV 解析、ICCID 绑定、异步任务处理) - 添加设备-SIM 卡绑定约束(部分唯一索引防止并发问题) - 修复 fee_rate 数据库字段类型(numeric -> bigint) - 修复测试数据隔离问题(基于增量断言) - 修复集成测试中间件顺序问题 - 清理无用测试文件(PersonalCustomer、Email 相关) - 归档 enterprise-card-authorization 变更
87 lines
2.5 KiB
Go
87 lines
2.5 KiB
Go
package admin
|
|
|
|
import (
|
|
"strconv"
|
|
|
|
"github.com/gofiber/fiber/v2"
|
|
|
|
"github.com/break/junhong_cmp_fiber/internal/model/dto"
|
|
deviceImportService "github.com/break/junhong_cmp_fiber/internal/service/device_import"
|
|
"github.com/break/junhong_cmp_fiber/pkg/constants"
|
|
"github.com/break/junhong_cmp_fiber/pkg/errors"
|
|
"github.com/break/junhong_cmp_fiber/pkg/middleware"
|
|
"github.com/break/junhong_cmp_fiber/pkg/response"
|
|
)
|
|
|
|
type DeviceImportHandler struct {
|
|
service *deviceImportService.Service
|
|
}
|
|
|
|
func NewDeviceImportHandler(service *deviceImportService.Service) *DeviceImportHandler {
|
|
return &DeviceImportHandler{
|
|
service: service,
|
|
}
|
|
}
|
|
|
|
func (h *DeviceImportHandler) Import(c *fiber.Ctx) error {
|
|
userType := middleware.GetUserTypeFromContext(c.UserContext())
|
|
if userType != constants.UserTypeSuperAdmin && userType != constants.UserTypePlatform {
|
|
return errors.New(errors.CodeForbidden, "仅平台用户可导入设备")
|
|
}
|
|
|
|
var req dto.ImportDeviceRequest
|
|
if err := c.BodyParser(&req); err != nil {
|
|
return errors.New(errors.CodeInvalidParam, "请求参数解析失败")
|
|
}
|
|
|
|
if req.FileKey == "" {
|
|
return errors.New(errors.CodeInvalidParam, "文件路径不能为空")
|
|
}
|
|
|
|
result, err := h.service.CreateImportTask(c.UserContext(), &req)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return response.Success(c, result)
|
|
}
|
|
|
|
func (h *DeviceImportHandler) List(c *fiber.Ctx) error {
|
|
userType := middleware.GetUserTypeFromContext(c.UserContext())
|
|
if userType != constants.UserTypeSuperAdmin && userType != constants.UserTypePlatform {
|
|
return errors.New(errors.CodeForbidden, "仅平台用户可查看导入任务")
|
|
}
|
|
|
|
var req dto.ListDeviceImportTaskRequest
|
|
if err := c.QueryParser(&req); err != nil {
|
|
return errors.New(errors.CodeInvalidParam, "请求参数解析失败")
|
|
}
|
|
|
|
result, err := h.service.List(c.UserContext(), &req)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return response.SuccessWithPagination(c, result.List, result.Total, result.Page, result.PageSize)
|
|
}
|
|
|
|
func (h *DeviceImportHandler) GetByID(c *fiber.Ctx) error {
|
|
userType := middleware.GetUserTypeFromContext(c.UserContext())
|
|
if userType != constants.UserTypeSuperAdmin && userType != constants.UserTypePlatform {
|
|
return errors.New(errors.CodeForbidden, "仅平台用户可查看导入任务详情")
|
|
}
|
|
|
|
idStr := c.Params("id")
|
|
id, err := strconv.ParseUint(idStr, 10, 64)
|
|
if err != nil {
|
|
return errors.New(errors.CodeInvalidParam, "无效的任务ID")
|
|
}
|
|
|
|
result, err := h.service.GetByID(c.UserContext(), uint(id))
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return response.Success(c, result)
|
|
}
|