Re-migrate code

This commit is contained in:
2026-03-02 10:31:45 +08:00
parent f80f2b43ce
commit 1cc3097d9b
3 changed files with 32 additions and 14 deletions

View File

@@ -4,6 +4,7 @@ import (
"net/http"
"net/url"
"strconv"
"time"
"github.com/gin-gonic/gin"
@@ -47,11 +48,22 @@ func (c *CompaniesController) FindAll(ctx *gin.Context) {
}
items := make([]gin.H, 0, len(companies))
now := time.Now()
for _, company := range companies {
serialCount := len(company.Serials)
activeCount := 0
for _, serial := range company.Serials {
if serial.IsActive && (serial.ValidUntil == nil || serial.ValidUntil.After(now)) {
activeCount++
}
}
items = append(items, gin.H{
"companyName": company.CompanyName,
"firstCreated": company.CreatedAt,
"lastCreated": company.UpdatedAt,
"serialCount": serialCount,
"activeCount": activeCount,
"status": map[bool]string{
true: "active",
false: "disabled",
@@ -99,7 +111,10 @@ func (c *CompaniesController) FindOne(ctx *gin.Context) {
return
}
SuccessResponse(ctx, "获取企业详情成功", data)
ctx.JSON(http.StatusOK, gin.H{
"message": "获取企业详情成功",
"data": data,
})
}
// Create 创建企业
@@ -298,5 +313,8 @@ func (c *CompaniesController) StatsOverview(ctx *gin.Context) {
return
}
SuccessResponse(ctx, "获取统计数据成功", stats)
ctx.JSON(http.StatusOK, gin.H{
"message": "获取统计数据成功",
"data": stats,
})
}