/* * SIM Card Manage API List * /simCardManage/info - GET 查询SIM卡信息 * /simCardManage/monthly - GET 查询SIM卡月数据 */ package controllers import ( "fwh-toolbox-server/services" "regexp" "strconv" "github.com/gofiber/fiber/v2" "go.uber.org/zap" ) // 兼容两个平台的月份格式: // - SmartHub: yyyy-MM(如 2026-09) // - Acceleronix: yyyyMM (如 202609) // 连字符可选,月份固定两位且限定 01~12。 var yearMonthRegexp = regexp.MustCompile(`^\d{4}-?(0[1-9]|1[0-2])$`) // 查询SIM卡信息 // /simCardManage/info func GetSimCardBatchInfo(c *fiber.Ctx) error { search := c.Query("search", "") pageStr := c.Query("page", "1") page, err := strconv.ParseUint(pageStr, 10, 64) if err != nil { zap.L().Warn("Invalid request parameter", zap.String("err", err.Error()), zap.String("page", pageStr)) return Fail(c, "Invalid request parameter (page)") } sizeStr := c.Query("size", "20") size, err := strconv.ParseUint(sizeStr, 10, 64) if err != nil { zap.L().Warn("Invalid request parameter", zap.String("err", err.Error()), zap.String("size", sizeStr)) return Fail(c, "Invalid request parameter (size)") } status := c.Query("status", "") var statusPtr *string if status != "" { statusPtr = &status } platform := c.Query("platform", "") var platformPtr *string if platform != "" { platformPtr = &platform } date, err := services.GetSimCardBatchInfo(uint(page), uint(size), search, statusPtr, platformPtr) if err != nil { return Error(c, "Get SIM card info failed.") } return Success(c, date) } // 查询SIM卡月数据 // /simCardManage/monthly func GetSimCardMonthlyData(c *fiber.Ctx) error { id := c.Query("id", "") month := c.Query("month", "") if id == "" { zap.L().Warn("id parameter is empty") return Fail(c, "id parameter is empty") } if !yearMonthRegexp.MatchString(month) { zap.L().Warn("month parameter is in the wrong format", zap.String("month", month)) return Fail(c, "month parameter is in the wrong format") } date, err := services.GetSimCardMonthlyData(month, id) if err != nil { return Error(c, "Get SIM card monthly data failed.") } return Success(c, date) }