feat: 迁移注册充值明细和筛选导出
This commit is contained in:
@@ -26,6 +26,7 @@ func NewGinEngine(runtime *config.Store, access *systemservice.AccessControlServ
|
||||
|
||||
func emptyHandlers() *handler.Set {
|
||||
return &handler.Set{
|
||||
Ledger: &handler.Ledger{},
|
||||
ChannelPortrait: &handler.ChannelPortrait{},
|
||||
BusinessPortrait: &handler.BusinessPortrait{},
|
||||
Channel: &handler.Channel{},
|
||||
@@ -105,7 +106,7 @@ func TestGinStartupLogsEveryRegisteredRoute(t *testing.T) {
|
||||
if got, want := strings.Count(text, `"msg":"router registered"`), len(engine.Routes()); got != want {
|
||||
t.Fatalf("registered route log count = %d, want %d", got, want)
|
||||
}
|
||||
if !strings.Contains(text, `"msg":"router register success"`) || !strings.Contains(text, `"route_count":236`) {
|
||||
if !strings.Contains(text, `"msg":"router register success"`) || !strings.Contains(text, `"route_count":241`) {
|
||||
t.Fatalf("startup route summary is missing: %s", text)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"mime"
|
||||
"net/http"
|
||||
"net/url"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/go-kratos/kratos/v3/errors"
|
||||
"kra/internal/service/business"
|
||||
"kra/internal/service/dto"
|
||||
)
|
||||
|
||||
type Ledger struct{ service *business.LedgerService }
|
||||
|
||||
func NewLedger(service *business.LedgerService) *Ledger { return &Ledger{service: service} }
|
||||
func (h *Ledger) Registrations(c *gin.Context) {
|
||||
var req dto.LedgerQuery
|
||||
if c.ShouldBindQuery(&req) != nil {
|
||||
Fail(c, "明细查询参数不正确")
|
||||
return
|
||||
}
|
||||
data, err := h.service.Registrations(c.Request.Context(), &req)
|
||||
if err != nil {
|
||||
Fail(c, errors.FromError(err).Message)
|
||||
return
|
||||
}
|
||||
OKWithData(c, data)
|
||||
}
|
||||
func (h *Ledger) Spends(c *gin.Context) {
|
||||
var req dto.LedgerQuery
|
||||
if c.ShouldBindQuery(&req) != nil {
|
||||
Fail(c, "明细查询参数不正确")
|
||||
return
|
||||
}
|
||||
data, err := h.service.Spends(c.Request.Context(), &req)
|
||||
if err != nil {
|
||||
Fail(c, errors.FromError(err).Message)
|
||||
return
|
||||
}
|
||||
OKWithData(c, data)
|
||||
}
|
||||
func (h *Ledger) Games(c *gin.Context) {
|
||||
var req dto.GameOptionQuery
|
||||
if c.ShouldBindQuery(&req) != nil {
|
||||
Fail(c, "游戏查询参数不正确")
|
||||
return
|
||||
}
|
||||
data, err := h.service.Games(c.Request.Context(), &req)
|
||||
if err != nil {
|
||||
Fail(c, errors.FromError(err).Message)
|
||||
return
|
||||
}
|
||||
OKWithData(c, data)
|
||||
}
|
||||
func (h *Ledger) Export(spend bool) gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
c.Request.Body = http.MaxBytesReader(c.Writer, c.Request.Body, 1<<20)
|
||||
var req dto.LedgerQuery
|
||||
if c.ShouldBind(&req) != nil {
|
||||
c.Header("msg", url.PathEscape("明细查询参数不正确"))
|
||||
Fail(c, "明细查询参数不正确")
|
||||
return
|
||||
}
|
||||
var data []byte
|
||||
var err error
|
||||
name := "注册明细.xlsx"
|
||||
if spend {
|
||||
name = "充值明细.xlsx"
|
||||
data, err = h.service.ExportSpends(c.Request.Context(), &req)
|
||||
} else {
|
||||
data, err = h.service.ExportRegistrations(c.Request.Context(), &req)
|
||||
}
|
||||
if err != nil {
|
||||
message := errors.FromError(err).Message
|
||||
c.Header("msg", url.PathEscape(message))
|
||||
Fail(c, message)
|
||||
return
|
||||
}
|
||||
c.Header("Content-Disposition", mime.FormatMediaType("attachment", map[string]string{"filename": name}))
|
||||
c.Header("success", "true")
|
||||
c.Data(http.StatusOK, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", data)
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,7 @@ var ProviderSet = wire.NewSet(
|
||||
NewChannel,
|
||||
NewBusinessPortrait,
|
||||
NewChannelPortrait,
|
||||
NewLedger,
|
||||
NewAuthority, NewMenu, NewAPI, NewPermission, NewOrganization,
|
||||
NewAnnouncement, NewEmail, NewPayment, NewTask, NewMedia, NewAudit,
|
||||
NewExport, NewVersion, NewDictionary, NewParameter, NewAPIToken,
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package handler
|
||||
|
||||
type Set struct {
|
||||
Ledger *Ledger
|
||||
ChannelPortrait *ChannelPortrait
|
||||
BusinessPortrait *BusinessPortrait
|
||||
Channel *Channel
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
package router
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"kra/internal/server/handler"
|
||||
)
|
||||
|
||||
func RegisterLedger(private *gin.RouterGroup, h *handler.Ledger) {
|
||||
private.GET("/sw/register/list", h.Registrations)
|
||||
private.POST("/sw/register/export", h.Export(false))
|
||||
private.GET("/sw/spend/list", h.Spends)
|
||||
private.POST("/sw/spend/export", h.Export(true))
|
||||
private.GET("/sw/serverAnalysis/games", h.Games)
|
||||
}
|
||||
@@ -20,6 +20,7 @@ func (r *Routes) RegisterRoutes(public, private *gin.RouterGroup, engine *gin.En
|
||||
return
|
||||
}
|
||||
registrations := []func(){
|
||||
func() { RegisterLedger(private, r.handlers.Ledger) },
|
||||
func() { private.GET("/sw/promote/portrait", r.handlers.ChannelPortrait.Portrait) },
|
||||
func() {
|
||||
private.GET("/sw/business/:userId/portrait", r.handlers.BusinessPortrait.ForUser)
|
||||
|
||||
Reference in New Issue
Block a user