All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 5m33s
主要改动: - 新增交互式环境配置脚本 (scripts/setup-env.sh) - 新增本地启动快捷脚本 (scripts/run-local.sh) - 新增环境变量模板文件 (.env.example) - 部署模式改版:使用嵌入式配置 + 环境变量覆盖 - 添加对象存储功能支持 - 改进 IoT 卡片导入任务 - 优化 OpenAPI 文档生成 - 删除旧的配置文件,改用嵌入式默认配置
70 lines
1.7 KiB
Go
70 lines
1.7 KiB
Go
package admin
|
|
|
|
import (
|
|
"strconv"
|
|
|
|
"github.com/gofiber/fiber/v2"
|
|
|
|
"github.com/break/junhong_cmp_fiber/internal/model/dto"
|
|
iotCardImportService "github.com/break/junhong_cmp_fiber/internal/service/iot_card_import"
|
|
"github.com/break/junhong_cmp_fiber/pkg/errors"
|
|
"github.com/break/junhong_cmp_fiber/pkg/response"
|
|
)
|
|
|
|
type IotCardImportHandler struct {
|
|
service *iotCardImportService.Service
|
|
}
|
|
|
|
func NewIotCardImportHandler(service *iotCardImportService.Service) *IotCardImportHandler {
|
|
return &IotCardImportHandler{
|
|
service: service,
|
|
}
|
|
}
|
|
|
|
func (h *IotCardImportHandler) Import(c *fiber.Ctx) error {
|
|
var req dto.ImportIotCardRequest
|
|
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 *IotCardImportHandler) List(c *fiber.Ctx) error {
|
|
var req dto.ListImportTaskRequest
|
|
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 *IotCardImportHandler) GetByID(c *fiber.Ctx) error {
|
|
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)
|
|
}
|