92 lines
2.6 KiB
Go
92 lines
2.6 KiB
Go
package sys
|
|
|
|
import (
|
|
"context"
|
|
"strings"
|
|
|
|
"hotgo/api/admin/urlpool"
|
|
"hotgo/internal/model/input/sysin"
|
|
"hotgo/internal/service"
|
|
|
|
"github.com/gogf/gf/v2/errors/gerror"
|
|
)
|
|
|
|
var UrlPool = cUrlPool{}
|
|
|
|
type cUrlPool struct{}
|
|
|
|
func (c *cUrlPool) List(ctx context.Context, req *urlpool.ListReq) (res *urlpool.ListRes, err error) {
|
|
list, total, err := service.SysUrlPool().List(ctx, &req.UrlPoolListInp)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if list == nil {
|
|
list = []*sysin.UrlPoolListModel{}
|
|
}
|
|
res = new(urlpool.ListRes)
|
|
res.List = list
|
|
res.PageRes.Pack(req, total)
|
|
return
|
|
}
|
|
|
|
func (c *cUrlPool) View(ctx context.Context, req *urlpool.ViewReq) (*urlpool.ViewRes, error) {
|
|
data, err := service.SysUrlPool().View(ctx, &req.UrlPoolViewInp)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &urlpool.ViewRes{UrlPoolViewModel: data}, nil
|
|
}
|
|
|
|
func (c *cUrlPool) Edit(ctx context.Context, req *urlpool.EditReq) (*urlpool.EditRes, error) {
|
|
return &urlpool.EditRes{}, service.SysUrlPool().Edit(ctx, &req.UrlPoolEditInp)
|
|
}
|
|
|
|
func (c *cUrlPool) Status(ctx context.Context, req *urlpool.StatusReq) (*urlpool.StatusRes, error) {
|
|
return &urlpool.StatusRes{}, service.SysUrlPool().Status(ctx, &req.UrlPoolStatusInp)
|
|
}
|
|
|
|
func (c *cUrlPool) Import(ctx context.Context, req *urlpool.ImportReq) (*urlpool.ImportRes, error) {
|
|
if req.File == nil {
|
|
return nil, gerror.New("请选择Excel文件")
|
|
}
|
|
filename := strings.ToLower(strings.TrimSpace(req.File.Filename))
|
|
if !strings.HasSuffix(filename, ".xlsx") && !strings.HasSuffix(filename, ".xlsm") {
|
|
return nil, gerror.New("仅支持.xlsx或.xlsm格式的Excel文件")
|
|
}
|
|
if req.File.Size > 10*1024*1024 {
|
|
return nil, gerror.New("Excel文件不能超过10MB")
|
|
}
|
|
file, err := req.File.Open()
|
|
if err != nil {
|
|
return nil, gerror.Wrap(err, "读取Excel文件失败")
|
|
}
|
|
defer file.Close()
|
|
result, err := service.SysUrlPool().Import(ctx, file)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &urlpool.ImportRes{UrlPoolImportModel: result}, nil
|
|
}
|
|
|
|
func (c *cUrlPool) MemberList(ctx context.Context, req *urlpool.MemberListReq) (res *urlpool.MemberListRes, err error) {
|
|
list, total, err := service.SysUrlPool().MemberList(ctx, &req.UrlPoolMemberListInp)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if list == nil {
|
|
list = []*sysin.UrlPoolMemberListModel{}
|
|
}
|
|
res = new(urlpool.MemberListRes)
|
|
res.List = list
|
|
res.PageRes.Pack(req, total)
|
|
return
|
|
}
|
|
|
|
func (c *cUrlPool) Summary(ctx context.Context, req *urlpool.SummaryReq) (*urlpool.SummaryRes, error) {
|
|
data, err := service.SysUrlPool().Summary(ctx, &req.UrlPoolSummaryInp)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &urlpool.SummaryRes{UrlPoolSummaryModel: data}, nil
|
|
}
|