初始化项目
This commit is contained in:
@@ -3,50 +3,50 @@ package controller
|
||||
import (
|
||||
"context"
|
||||
|
||||
"cidService/model/dto"
|
||||
"cidService/service"
|
||||
"cidservice/model/dto"
|
||||
"cidservice/service"
|
||||
|
||||
"gitee.com/red-future---jilin-g/common/http"
|
||||
)
|
||||
|
||||
type cAdPosition struct{}
|
||||
type adPosition struct{}
|
||||
|
||||
var AdPosition = &cAdPosition{}
|
||||
var AdPosition = &adPosition{}
|
||||
|
||||
// Add 添加广告位
|
||||
func (c *cAdPosition) Add(ctx context.Context, req *dto.AddAdPositionReq) (res *dto.AddAdPositionRes, err error) {
|
||||
func (c *adPosition) Add(ctx context.Context, req *dto.AddAdPositionReq) (res *dto.AddAdPositionRes, err error) {
|
||||
return service.AdPosition.Add(ctx, req)
|
||||
}
|
||||
|
||||
// Update 更新广告位
|
||||
func (c *cAdPosition) Update(ctx context.Context, req *dto.UpdateAdPositionReq) (res *http.ResponseEmpty, err error) {
|
||||
func (c *adPosition) Update(ctx context.Context, req *dto.UpdateAdPositionReq) (res *http.ResponseEmpty, err error) {
|
||||
err = service.AdPosition.Update(ctx, req)
|
||||
return
|
||||
}
|
||||
|
||||
// UpdateStatus 更新广告位状态
|
||||
func (c *cAdPosition) UpdateStatus(ctx context.Context, req *dto.UpdateAdPositionStatusReq) (res *http.ResponseEmpty, err error) {
|
||||
func (c *adPosition) UpdateStatus(ctx context.Context, req *dto.UpdateAdPositionStatusReq) (res *http.ResponseEmpty, err error) {
|
||||
err = service.AdPosition.UpdateStatus(ctx, req)
|
||||
return
|
||||
}
|
||||
|
||||
// GetOne 获取广告位详情
|
||||
func (c *cAdPosition) GetOne(ctx context.Context, req *dto.GetAdPositionReq) (res *dto.GetAdPositionRes, err error) {
|
||||
func (c *adPosition) GetOne(ctx context.Context, req *dto.GetAdPositionReq) (res *dto.GetAdPositionRes, err error) {
|
||||
return service.AdPosition.GetOne(ctx, req)
|
||||
}
|
||||
|
||||
// List 获取广告位列表
|
||||
func (c *cAdPosition) List(ctx context.Context, req *dto.ListAdPositionReq) (res *dto.ListAdPositionRes, err error) {
|
||||
func (c *adPosition) List(ctx context.Context, req *dto.ListAdPositionReq) (res *dto.ListAdPositionRes, err error) {
|
||||
return service.AdPosition.List(ctx, req)
|
||||
}
|
||||
|
||||
// GetStatistics 获取广告位统计数据
|
||||
func (c *cAdPosition) GetStatistics(ctx context.Context, req *dto.GetAdPositionStatisticsReq) (res *dto.GetAdPositionStatisticsRes, err error) {
|
||||
func (c *adPosition) GetStatistics(ctx context.Context, req *dto.GetAdPositionStatisticsReq) (res *dto.GetAdPositionStatisticsRes, err error) {
|
||||
return service.AdPosition.GetStatistics(ctx, req)
|
||||
}
|
||||
|
||||
// GetAvailableAdPositions 获取可用的广告位列表
|
||||
func (c *cAdPosition) GetAvailableAdPositions(ctx context.Context, req *dto.GetAvailableAdPositionsReq) (res *dto.GetAvailableAdPositionsRes, err error) {
|
||||
func (c *adPosition) GetAvailableAdPositions(ctx context.Context, req *dto.GetAvailableAdPositionsReq) (res *dto.GetAvailableAdPositionsRes, err error) {
|
||||
list, err := service.AdPosition.GetAvailableAdPositions(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -58,7 +58,7 @@ func (c *cAdPosition) GetAvailableAdPositions(ctx context.Context, req *dto.GetA
|
||||
}
|
||||
|
||||
// MatchAd 匹配广告
|
||||
func (c *cAdPosition) MatchAd(ctx context.Context, req *dto.MatchAdReq) (res *dto.MatchAdRes, err error) {
|
||||
func (c *adPosition) MatchAd(ctx context.Context, req *dto.MatchAdReq) (res *dto.MatchAdRes, err error) {
|
||||
ad, err := service.AdPosition.MatchAd(ctx, req.PositionCode, req.UserInfo)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -4,19 +4,20 @@ import (
|
||||
"context"
|
||||
"strconv"
|
||||
|
||||
"cidService/model/dto"
|
||||
"cidService/service"
|
||||
"cidservice/model/dto"
|
||||
"cidservice/service"
|
||||
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
)
|
||||
|
||||
var (
|
||||
AdSource = cAdSource{}
|
||||
AdSource = adSource{}
|
||||
)
|
||||
|
||||
type cAdSource struct{}
|
||||
type adSource struct{}
|
||||
|
||||
// Create 创建广告源
|
||||
func (c *cAdSource) Create(ctx context.Context, req *dto.CreateAdSourceReq) (res *dto.GetAdSourceRes, err error) {
|
||||
func (c *adSource) Create(ctx context.Context, req *dto.CreateAdSourceReq) (res *dto.GetAdSourceRes, err error) {
|
||||
id, err := service.AdSource.CreateAdSource(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -33,7 +34,7 @@ func (c *cAdSource) Create(ctx context.Context, req *dto.CreateAdSourceReq) (res
|
||||
}
|
||||
|
||||
// Update 更新广告源
|
||||
func (c *cAdSource) Update(ctx context.Context, req *dto.UpdateAdSourceReq) (res *dto.GetAdSourceRes, err error) {
|
||||
func (c *adSource) Update(ctx context.Context, req *dto.UpdateAdSourceReq) (res *dto.GetAdSourceRes, err error) {
|
||||
id, err := strconv.ParseInt(req.Id, 10, 64)
|
||||
if err != nil {
|
||||
return nil, gerror.New("无效的广告源ID")
|
||||
@@ -58,7 +59,7 @@ func (c *cAdSource) Update(ctx context.Context, req *dto.UpdateAdSourceReq) (res
|
||||
}
|
||||
|
||||
// Delete 删除广告源
|
||||
func (c *cAdSource) Delete(ctx context.Context, req *dto.DeleteAdSourceReq) (res *dto.DeleteAdSourceRes, err error) {
|
||||
func (c *adSource) Delete(ctx context.Context, req *dto.DeleteAdSourceReq) (res *dto.DeleteAdSourceRes, err error) {
|
||||
id, err := strconv.ParseInt(req.Id, 10, 64)
|
||||
if err != nil {
|
||||
return nil, gerror.New("无效的广告源ID")
|
||||
@@ -78,7 +79,7 @@ func (c *cAdSource) Delete(ctx context.Context, req *dto.DeleteAdSourceReq) (res
|
||||
}
|
||||
|
||||
// GetByID 根据ID获取广告源
|
||||
func (c *cAdSource) GetByID(ctx context.Context, req *dto.GetAdSourceReq) (res *dto.GetAdSourceRes, err error) {
|
||||
func (c *adSource) GetByID(ctx context.Context, req *dto.GetAdSourceReq) (res *dto.GetAdSourceRes, err error) {
|
||||
id, err := strconv.ParseInt(req.Id, 10, 64)
|
||||
if err != nil {
|
||||
return nil, gerror.New("无效的广告源ID")
|
||||
@@ -98,7 +99,7 @@ func (c *cAdSource) GetByID(ctx context.Context, req *dto.GetAdSourceReq) (res *
|
||||
}
|
||||
|
||||
// GetList 获取广告源列表
|
||||
func (c *cAdSource) GetList(ctx context.Context, req *dto.ListAdSourceReq) (res *dto.ListAdSourceRes, err error) {
|
||||
func (c *adSource) GetList(ctx context.Context, req *dto.ListAdSourceReq) (res *dto.ListAdSourceRes, err error) {
|
||||
adSources, err := service.AdSource.GetAvailableSources(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -3,26 +3,26 @@ package controller
|
||||
import (
|
||||
"context"
|
||||
|
||||
"cidService/model/dto"
|
||||
"cidService/service"
|
||||
"cidservice/model/dto"
|
||||
"cidservice/service"
|
||||
)
|
||||
|
||||
type cAdStatistics struct{}
|
||||
type adStatistics struct{}
|
||||
|
||||
var AdStatistics = &cAdStatistics{}
|
||||
var AdStatistics = &adStatistics{}
|
||||
|
||||
// GetStatistics 获取统计数据
|
||||
func (c *cAdStatistics) GetStatistics(ctx context.Context, req *dto.GetAdStatisticsReq) (res *dto.GetAdStatisticsRes, err error) {
|
||||
func (c *adStatistics) GetStatistics(ctx context.Context, req *dto.GetAdStatisticsReq) (res *dto.GetAdStatisticsRes, err error) {
|
||||
return service.AdStatistics.GetStatistics(ctx, req)
|
||||
}
|
||||
|
||||
// GetDashboard 获取仪表盘数据
|
||||
func (c *cAdStatistics) GetDashboard(ctx context.Context, req *dto.GetDashboardReq) (res *dto.GetDashboardRes, err error) {
|
||||
func (c *adStatistics) GetDashboard(ctx context.Context, req *dto.GetDashboardReq) (res *dto.GetDashboardRes, err error) {
|
||||
return service.AdStatistics.GetDashboard(ctx, req)
|
||||
}
|
||||
|
||||
// GenerateDailyStatistics 生成每日统计数据
|
||||
func (c *cAdStatistics) GenerateDailyStatistics(ctx context.Context, req *dto.GenerateDailyStatisticsReq) (res *dto.GenerateDailyStatisticsRes, err error) {
|
||||
func (c *adStatistics) GenerateDailyStatistics(ctx context.Context, req *dto.GenerateDailyStatisticsReq) (res *dto.GenerateDailyStatisticsRes, err error) {
|
||||
err = service.AdStatistics.GenerateDailyStatistics(ctx, req.Date)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -1,51 +1,51 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"cidService/model/dto"
|
||||
"cidService/service"
|
||||
"cidservice/model/dto"
|
||||
"cidservice/service"
|
||||
"context"
|
||||
|
||||
"gitee.com/red-future---jilin-g/common/http"
|
||||
)
|
||||
|
||||
type cAdvertisement struct{}
|
||||
type advertisement struct{}
|
||||
|
||||
var Advertisement = &cAdvertisement{}
|
||||
var Advertisement = &advertisement{}
|
||||
|
||||
// Add 添加广告
|
||||
func (c *cAdvertisement) Add(ctx context.Context, req *dto.AddAdvertisementReq) (res *dto.AddAdvertisementRes, err error) {
|
||||
func (c *advertisement) Add(ctx context.Context, req *dto.AddAdvertisementReq) (res *dto.AddAdvertisementRes, err error) {
|
||||
return service.Advertisement.Add(ctx, req)
|
||||
}
|
||||
|
||||
// Update 更新广告
|
||||
func (c *cAdvertisement) Update(ctx context.Context, req *dto.UpdateAdvertisementReq) (res *http.ResponseEmpty, err error) {
|
||||
func (c *advertisement) Update(ctx context.Context, req *dto.UpdateAdvertisementReq) (res *http.ResponseEmpty, err error) {
|
||||
err = service.Advertisement.Update(ctx, req)
|
||||
return
|
||||
}
|
||||
|
||||
// UpdateStatus 更新广告状态
|
||||
func (c *cAdvertisement) UpdateStatus(ctx context.Context, req *dto.UpdateAdStatusReq) (res *http.ResponseEmpty, err error) {
|
||||
func (c *advertisement) UpdateStatus(ctx context.Context, req *dto.UpdateAdStatusReq) (res *http.ResponseEmpty, err error) {
|
||||
err = service.Advertisement.UpdateStatus(ctx, req)
|
||||
return
|
||||
}
|
||||
|
||||
// Audit 审核广告
|
||||
func (c *cAdvertisement) Audit(ctx context.Context, req *dto.AuditAdvertisementReq) (res *http.ResponseEmpty, err error) {
|
||||
func (c *advertisement) Audit(ctx context.Context, req *dto.AuditAdvertisementReq) (res *http.ResponseEmpty, err error) {
|
||||
err = service.Advertisement.Audit(ctx, req)
|
||||
return
|
||||
}
|
||||
|
||||
// GetOne 获取广告详情
|
||||
func (c *cAdvertisement) GetOne(ctx context.Context, req *dto.GetAdvertisementReq) (res *dto.GetAdvertisementRes, err error) {
|
||||
func (c *advertisement) GetOne(ctx context.Context, req *dto.GetAdvertisementReq) (res *dto.GetAdvertisementRes, err error) {
|
||||
return service.Advertisement.GetOne(ctx, req)
|
||||
}
|
||||
|
||||
// List 获取广告列表
|
||||
func (c *cAdvertisement) List(ctx context.Context, req *dto.ListAdvertisementReq) (res *dto.ListAdvertisementRes, err error) {
|
||||
func (c *advertisement) List(ctx context.Context, req *dto.ListAdvertisementReq) (res *dto.ListAdvertisementRes, err error) {
|
||||
return service.Advertisement.List(ctx, req)
|
||||
}
|
||||
|
||||
// GetStatistics 获取广告统计数据
|
||||
func (c *cAdvertisement) GetStatistics(ctx context.Context, req *dto.GetAdStatisticsForAdvertisementReq) (res *dto.GetAdStatisticsForAdvertisementRes, err error) {
|
||||
func (c *advertisement) GetStatistics(ctx context.Context, req *dto.GetAdStatisticsForAdvertisementReq) (res *dto.GetAdStatisticsForAdvertisementRes, err error) {
|
||||
return service.Advertisement.GetStatistics(ctx, req)
|
||||
}
|
||||
|
||||
@@ -1,64 +1,64 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"cidService/model/dto"
|
||||
"cidService/service"
|
||||
"cidservice/model/dto"
|
||||
"cidservice/service"
|
||||
"context"
|
||||
|
||||
"gitee.com/red-future---jilin-g/common/http"
|
||||
)
|
||||
|
||||
type cAdvertiser struct{}
|
||||
type advertiser struct{}
|
||||
|
||||
var Advertiser = &cAdvertiser{}
|
||||
var Advertiser = &advertiser{}
|
||||
|
||||
// Add 添加广告主
|
||||
func (c *cAdvertiser) Add(ctx context.Context, req *dto.AddAdvertiserReq) (res *dto.AddAdvertiserRes, err error) {
|
||||
func (c *advertiser) Add(ctx context.Context, req *dto.AddAdvertiserReq) (res *dto.AddAdvertiserRes, err error) {
|
||||
return service.Advertiser.Add(ctx, req)
|
||||
}
|
||||
|
||||
// Update 更新广告主
|
||||
func (c *cAdvertiser) Update(ctx context.Context, req *dto.UpdateAdvertiserReq) (res *http.ResponseEmpty, err error) {
|
||||
func (c *advertiser) Update(ctx context.Context, req *dto.UpdateAdvertiserReq) (res *http.ResponseEmpty, err error) {
|
||||
err = service.Advertiser.Update(ctx, req)
|
||||
return
|
||||
}
|
||||
|
||||
// UpdateStatus 更新广告主状态
|
||||
func (c *cAdvertiser) UpdateStatus(ctx context.Context, req *dto.UpdateAdvertiserStatusReq) (res *http.ResponseEmpty, err error) {
|
||||
func (c *advertiser) UpdateStatus(ctx context.Context, req *dto.UpdateAdvertiserStatusReq) (res *http.ResponseEmpty, err error) {
|
||||
err = service.Advertiser.UpdateStatus(ctx, req)
|
||||
return
|
||||
}
|
||||
|
||||
// Audit 审核广告主
|
||||
func (c *cAdvertiser) Audit(ctx context.Context, req *dto.AuditAdvertiserReq) (res *http.ResponseEmpty, err error) {
|
||||
func (c *advertiser) Audit(ctx context.Context, req *dto.AuditAdvertiserReq) (res *http.ResponseEmpty, err error) {
|
||||
err = service.Advertiser.Audit(ctx, req)
|
||||
return
|
||||
}
|
||||
|
||||
// Recharge 充值
|
||||
func (c *cAdvertiser) Recharge(ctx context.Context, req *dto.RechargeAdvertiserReq) (res *http.ResponseEmpty, err error) {
|
||||
func (c *advertiser) Recharge(ctx context.Context, req *dto.RechargeAdvertiserReq) (res *http.ResponseEmpty, err error) {
|
||||
err = service.Advertiser.Recharge(ctx, req)
|
||||
return
|
||||
}
|
||||
|
||||
// UpdateCreditLimit 更新授信额度
|
||||
func (c *cAdvertiser) UpdateCreditLimit(ctx context.Context, req *dto.UpdateCreditLimitReq) (res *http.ResponseEmpty, err error) {
|
||||
func (c *advertiser) UpdateCreditLimit(ctx context.Context, req *dto.UpdateCreditLimitReq) (res *http.ResponseEmpty, err error) {
|
||||
err = service.Advertiser.UpdateCreditLimit(ctx, req)
|
||||
return
|
||||
}
|
||||
|
||||
// GetOne 获取广告主详情
|
||||
func (c *cAdvertiser) GetOne(ctx context.Context, req *dto.GetAdvertiserReq) (res *dto.GetAdvertiserRes, err error) {
|
||||
func (c *advertiser) GetOne(ctx context.Context, req *dto.GetAdvertiserReq) (res *dto.GetAdvertiserRes, err error) {
|
||||
return service.Advertiser.GetOne(ctx, req)
|
||||
}
|
||||
|
||||
// List 获取广告主列表
|
||||
func (c *cAdvertiser) List(ctx context.Context, req *dto.ListAdvertiserReq) (res *dto.ListAdvertiserRes, err error) {
|
||||
func (c *advertiser) List(ctx context.Context, req *dto.ListAdvertiserReq) (res *dto.ListAdvertiserRes, err error) {
|
||||
return service.Advertiser.List(ctx, req)
|
||||
}
|
||||
|
||||
// GetBalance 获取广告主余额
|
||||
func (c *cAdvertiser) GetBalance(ctx context.Context, req *dto.GetAdvertiserBalanceReq) (res *dto.GetAdvertiserBalanceRes, err error) {
|
||||
func (c *advertiser) GetBalance(ctx context.Context, req *dto.GetAdvertiserBalanceReq) (res *dto.GetAdvertiserBalanceRes, err error) {
|
||||
balance, creditLimit, err := service.Advertiser.GetBalance(ctx, req.Id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
147
controller/application_controller.go
Normal file
147
controller/application_controller.go
Normal file
@@ -0,0 +1,147 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"cidservice/model/dto"
|
||||
"cidservice/service"
|
||||
)
|
||||
|
||||
var (
|
||||
Application = application{}
|
||||
)
|
||||
|
||||
type application struct{}
|
||||
|
||||
// CreateApplication 创建应用
|
||||
func (c *application) CreateApplication(ctx context.Context, req *dto.CreateApplicationReq) (res *dto.CreateApplicationRes, err error) {
|
||||
id, err := service.Application.CreateApplication(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &dto.CreateApplicationRes{
|
||||
ID: id,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// UpdateApplication 更新应用
|
||||
func (c *application) UpdateApplication(ctx context.Context, req *dto.UpdateApplicationReq) (res *dto.UpdateApplicationRes, err error) {
|
||||
affected, err := service.Application.UpdateApplication(ctx, req.ID, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &dto.UpdateApplicationRes{
|
||||
Success: affected > 0,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// GetApplication 获取应用信息
|
||||
func (c *application) GetApplication(ctx context.Context, req *dto.GetApplicationReq) (res *dto.GetApplicationRes, err error) {
|
||||
app, err := service.Application.GetApplicationByID(ctx, req.ID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &dto.GetApplicationRes{
|
||||
ID: app.Id,
|
||||
TenantID: app.TenantId,
|
||||
Name: app.Name,
|
||||
Code: app.Code,
|
||||
Description: app.Description,
|
||||
Platform: app.Platform,
|
||||
PackageName: app.PackageName,
|
||||
AppStoreURL: app.AppStoreURL,
|
||||
Categories: app.Categories,
|
||||
Tags: app.Tags,
|
||||
AdTypes: app.AdTypes,
|
||||
Status: app.Status,
|
||||
AppKey: app.AppKey,
|
||||
CallbackURL: app.CallbackURL,
|
||||
CreatedAt: app.CreatedAt.Unix(),
|
||||
UpdatedAt: app.UpdatedAt.Unix(),
|
||||
}, nil
|
||||
}
|
||||
|
||||
// ListApplications 获取应用列表
|
||||
func (c *application) ListApplications(ctx context.Context, req *dto.ListApplicationsReq) (res *dto.ListApplicationsRes, err error) {
|
||||
list, total, err := service.Application.GetApplicationsByTenant(ctx, req.TenantID, req.Platform, req.Status, req.Page, req.Size)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 转换为响应格式
|
||||
appItems := make([]dto.ApplicationItem, len(list))
|
||||
for i, app := range list {
|
||||
appItems[i] = dto.ApplicationItem{
|
||||
ID: app.Id,
|
||||
Name: app.Name,
|
||||
Code: app.Code,
|
||||
Description: app.Description,
|
||||
Platform: app.Platform,
|
||||
PackageName: app.PackageName,
|
||||
Categories: app.Categories,
|
||||
Tags: app.Tags,
|
||||
AdTypes: app.AdTypes,
|
||||
Status: app.Status,
|
||||
DailyRequests: app.DailyRequests,
|
||||
MonthlyRequests: app.MonthlyRequests,
|
||||
CreatedAt: app.CreatedAt.Unix(),
|
||||
}
|
||||
}
|
||||
|
||||
return &dto.ListApplicationsRes{
|
||||
List: appItems,
|
||||
Total: total,
|
||||
Page: req.Page,
|
||||
Size: req.Size,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// ResetAPIKeys 重置API密钥
|
||||
func (c *application) ResetAPIKeys(ctx context.Context, req *dto.ResetAPIKeysReq) (res *dto.ResetAPIKeysRes, err error) {
|
||||
appKey, appSecret, err := service.Application.ResetAPIKeys(ctx, req.ID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &dto.ResetAPIKeysRes{
|
||||
AppKey: appKey,
|
||||
AppSecret: appSecret,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// ValidateApplication 验证应用权限
|
||||
func (c *application) ValidateApplication(ctx context.Context, req *dto.ValidateApplicationReq) (res *dto.ValidateApplicationRes, err error) {
|
||||
app, err := service.Application.ValidateApplication(ctx, req.AppKey, req.AppSecret)
|
||||
if err != nil {
|
||||
return &dto.ValidateApplicationRes{
|
||||
Valid: false,
|
||||
}, nil
|
||||
}
|
||||
|
||||
tentantName := ""
|
||||
|
||||
return &dto.ValidateApplicationRes{
|
||||
Valid: true,
|
||||
AppID: app.Id,
|
||||
AppName: app.Name,
|
||||
TenantID: app.TenantId,
|
||||
TenantName: tentantName,
|
||||
Platform: app.Platform,
|
||||
AdTypes: app.AdTypes,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// DeleteApplication 删除应用
|
||||
func (c *application) DeleteApplication(ctx context.Context, req *dto.DeleteApplicationReq) (res *dto.DeleteApplicationRes, err error) {
|
||||
affected, err := service.Application.DeleteApplication(ctx, req.ID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &dto.DeleteApplicationRes{
|
||||
Success: affected > 0,
|
||||
}, nil
|
||||
}
|
||||
@@ -3,19 +3,20 @@ package controller
|
||||
import (
|
||||
"context"
|
||||
|
||||
"cidService/model/dto"
|
||||
"cidService/service"
|
||||
"cidservice/model/dto"
|
||||
"cidservice/service"
|
||||
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
)
|
||||
|
||||
var (
|
||||
CID = cCID{}
|
||||
CID = cid{}
|
||||
)
|
||||
|
||||
type cCID struct{}
|
||||
type cid struct{}
|
||||
|
||||
// GenerateCID 生成CID广告
|
||||
func (c *cCID) GenerateCID(ctx context.Context, req *dto.GenerateCIDReq) (res *dto.GenerateCIDRes, err error) {
|
||||
func (c *cid) GenerateCID(ctx context.Context, req *dto.GenerateCIDReq) (res *dto.GenerateCIDRes, err error) {
|
||||
if req == nil {
|
||||
return nil, gerror.New("请求参数不能为空")
|
||||
}
|
||||
@@ -33,7 +34,7 @@ func (c *cCID) GenerateCID(ctx context.Context, req *dto.GenerateCIDReq) (res *d
|
||||
}
|
||||
|
||||
// GetStatistics 获取CID统计信息
|
||||
func (c *cCID) GetStatistics(ctx context.Context, req *dto.GetCIDStatisticsReq) (res *dto.GetCIDStatisticsRes, err error) {
|
||||
func (c *cid) GetStatistics(ctx context.Context, req *dto.GetCIDStatisticsReq) (res *dto.GetCIDStatisticsRes, err error) {
|
||||
if req == nil {
|
||||
return nil, gerror.New("请求参数不能为空")
|
||||
}
|
||||
@@ -47,7 +48,7 @@ func (c *cCID) GetStatistics(ctx context.Context, req *dto.GetCIDStatisticsReq)
|
||||
}
|
||||
|
||||
// GetCIDHistory 获取CID历史记录
|
||||
func (c *cCID) GetCIDHistory(ctx context.Context, req *dto.GetCIDHistoryReq) (res *dto.GetCIDHistoryRes, err error) {
|
||||
func (c *cid) GetCIDHistory(ctx context.Context, req *dto.GetCIDHistoryReq) (res *dto.GetCIDHistoryRes, err error) {
|
||||
if req == nil {
|
||||
return nil, gerror.New("请求参数不能为空")
|
||||
}
|
||||
|
||||
39
controller/rate_limit_controller.go
Normal file
39
controller/rate_limit_controller.go
Normal file
@@ -0,0 +1,39 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"cidservice/model/dto"
|
||||
"cidservice/service"
|
||||
)
|
||||
|
||||
var (
|
||||
RateLimit = rateLimit{}
|
||||
)
|
||||
|
||||
type rateLimit struct{}
|
||||
|
||||
// SetTenantRateLimit 设置租户限流配置
|
||||
func (c *rateLimit) SetTenantRateLimit(ctx context.Context, req *dto.SetTenantRateLimitReq) (res *dto.SetTenantRateLimitRes, err error) {
|
||||
// 注意:实际使用的是config.yml中的全局配置,此接口仅用于兼容旧API
|
||||
// 实际限流参数请修改config.yml中的tenantRateLimit部分
|
||||
|
||||
return &dto.SetTenantRateLimitRes{
|
||||
Success: true,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// GetTenantRateLimitUsage 获取租户限流使用情况
|
||||
func (c *rateLimit) GetTenantRateLimitUsage(ctx context.Context, req *dto.GetTenantRateLimitUsageReq) (res *dto.GetTenantRateLimitUsageRes, err error) {
|
||||
current, max, err := service.RateLimit.GetTenantCurrentUsage(ctx, req.TenantID, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &dto.GetTenantRateLimitUsageRes{
|
||||
TenantID: req.TenantID,
|
||||
CurrentUsed: current,
|
||||
MaxAllowed: max,
|
||||
UsagePercent: float64(current) / float64(max) * 100,
|
||||
}, nil
|
||||
}
|
||||
@@ -5,8 +5,8 @@ import (
|
||||
|
||||
"gitee.com/red-future---jilin-g/common/http"
|
||||
|
||||
"cidService/model/dto"
|
||||
"cidService/service"
|
||||
"cidservice/model/dto"
|
||||
"cidservice/service"
|
||||
)
|
||||
|
||||
type report struct{}
|
||||
@@ -31,12 +31,14 @@ func (c *report) List(ctx context.Context, req *dto.ListReportReq) (res *dto.Lis
|
||||
// Update 更新报表
|
||||
func (c *report) Update(ctx context.Context, req *dto.UpdateReportReq) (res *http.ResponseEmpty, err error) {
|
||||
err = service.Report.Update(ctx, req)
|
||||
res = &http.ResponseEmpty{}
|
||||
return
|
||||
}
|
||||
|
||||
// Delete 删除报表
|
||||
func (c *report) Delete(ctx context.Context, req *dto.DeleteReportReq) (res *http.ResponseEmpty, err error) {
|
||||
err = service.Report.Delete(ctx, req)
|
||||
res = &http.ResponseEmpty{}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -48,5 +50,6 @@ func (c *report) Download(ctx context.Context, req *dto.DownloadReportReq) (res
|
||||
// Generate 生成报表
|
||||
func (c *report) Generate(ctx context.Context, req *dto.GenerateReportReq) (res *http.ResponseEmpty, err error) {
|
||||
err = service.Report.Generate(ctx, req)
|
||||
res = &http.ResponseEmpty{}
|
||||
return
|
||||
}
|
||||
|
||||
147
controller/stat_report_controller.go
Normal file
147
controller/stat_report_controller.go
Normal file
@@ -0,0 +1,147 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"cidservice/model/dto"
|
||||
"cidservice/service"
|
||||
)
|
||||
|
||||
var (
|
||||
StatReport = &statReport{}
|
||||
)
|
||||
|
||||
type statReport struct{}
|
||||
|
||||
// GenerateReport 生成报表
|
||||
func (c *statReport) GenerateReport(ctx context.Context, req *dto.ReportGenerateReq) (res *dto.ReportGenerateRes, err error) {
|
||||
var resp *dto.ReportGenerateResp
|
||||
|
||||
switch req.ReportType {
|
||||
case "daily":
|
||||
resp, err = service.StatReport.GenerateDailyReport(ctx, req)
|
||||
case "monthly":
|
||||
resp, err = service.StatReport.GenerateMonthlyReport(ctx, req)
|
||||
case "quarterly":
|
||||
resp, err = service.StatReport.GenerateQuarterlyReport(ctx, req)
|
||||
case "yearly":
|
||||
resp, err = service.StatReport.GenerateYearlyReport(ctx, req)
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &dto.ReportGenerateRes{
|
||||
Data: resp,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// GetReportList 获取报表列表
|
||||
func (c *statReport) GetReportList(ctx context.Context, req *dto.ReportListReq) (res *dto.ReportListRes, err error) {
|
||||
resp, err := service.StatReport.GetReportList(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &dto.ReportListRes{
|
||||
Data: resp,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// GetReportDetail 获取报表详情
|
||||
func (c *statReport) GetReportDetail(ctx context.Context, req *dto.ReportDetailReq) (res *dto.ReportDetailRes, err error) {
|
||||
resp, err := service.StatReport.GetReportDetail(ctx, req.ReportID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &dto.ReportDetailRes{
|
||||
Data: resp,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// QueryStats 统计查询
|
||||
func (c *statReport) QueryStats(ctx context.Context, req *dto.StatQueryReq) (res *dto.StatQueryRes, err error) {
|
||||
// 这里调用统计查询服务
|
||||
// resp, err := service.StatReport.QueryStats(ctx, req)
|
||||
// 暂时返回示例数据
|
||||
resp := &dto.StatQueryResp{
|
||||
Data: []*dto.StatDataPoint{
|
||||
{
|
||||
Date: "2024-01-01",
|
||||
Impressions: 1000,
|
||||
Clicks: 50,
|
||||
Revenue: 500.0,
|
||||
CTR: 5.0,
|
||||
AvgDuration: 30.5,
|
||||
},
|
||||
},
|
||||
Summary: &dto.StatSummary{
|
||||
TotalImpressions: 1000,
|
||||
TotalClicks: 50,
|
||||
TotalRevenue: 500.0,
|
||||
AvgCTR: 5.0,
|
||||
AvgDuration: 30.5,
|
||||
GrowthRate: &dto.GrowthRate{
|
||||
Impressions: 10.5,
|
||||
Clicks: 8.2,
|
||||
Revenue: 12.3,
|
||||
CTR: -1.2,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
return &dto.StatQueryRes{
|
||||
Data: resp,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// RealTimeStats 实时统计
|
||||
func (c *statReport) RealTimeStats(ctx context.Context, req *dto.RealTimeStatReq) (res *dto.RealTimeStatRes, err error) {
|
||||
// 这里调用实时统计服务
|
||||
// resp, err := service.StatReport.GetRealTimeStats(ctx, req)
|
||||
// 暂时返回示例数据
|
||||
resp := &dto.RealTimeStatResp{
|
||||
CurrentHour: &dto.HourlyStat{
|
||||
Hour: "14:00",
|
||||
Impressions: 120,
|
||||
Clicks: 6,
|
||||
Revenue: 60.0,
|
||||
},
|
||||
Last24Hours: []*dto.HourlyStat{
|
||||
{
|
||||
Hour: "13:00",
|
||||
Impressions: 110,
|
||||
Clicks: 5,
|
||||
Revenue: 55.0,
|
||||
},
|
||||
{
|
||||
Hour: "12:00",
|
||||
Impressions: 100,
|
||||
Clicks: 4,
|
||||
Revenue: 50.0,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
return &dto.RealTimeStatRes{
|
||||
Data: resp,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// ExportReport 导出报表
|
||||
func (c *statReport) ExportReport(ctx context.Context, req *dto.ReportDetailReq) (res *dto.ExportReportRes, err error) {
|
||||
// 获取报表详情
|
||||
resp, err := service.StatReport.GetReportDetail(ctx, req.ReportID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 返回导出数据,由上层处理HTTP响应
|
||||
return &dto.ExportReportRes{
|
||||
ReportData: resp,
|
||||
}, nil
|
||||
}
|
||||
@@ -3,19 +3,20 @@ package controller
|
||||
import (
|
||||
"context"
|
||||
|
||||
"cidService/model/dto"
|
||||
"cidService/service"
|
||||
"cidservice/model/dto"
|
||||
"cidservice/service"
|
||||
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
)
|
||||
|
||||
var (
|
||||
Strategy = cStrategy{}
|
||||
Strategy = strategy{}
|
||||
)
|
||||
|
||||
type cStrategy struct{}
|
||||
type strategy struct{}
|
||||
|
||||
// Create 创建策略
|
||||
func (c *cStrategy) Create(ctx context.Context, req *dto.CreateStrategyReq) (res *dto.StrategyRes, err error) {
|
||||
func (c *strategy) Create(ctx context.Context, req *dto.CreateStrategyReq) (res *dto.StrategyRes, err error) {
|
||||
id, err := service.Strategy.CreateStrategy(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -30,7 +31,7 @@ func (c *cStrategy) Create(ctx context.Context, req *dto.CreateStrategyReq) (res
|
||||
}
|
||||
|
||||
// Update 更新策略
|
||||
func (c *cStrategy) Update(ctx context.Context, req *dto.UpdateStrategyReq) (res *dto.StrategyRes, err error) {
|
||||
func (c *strategy) Update(ctx context.Context, req *dto.UpdateStrategyReq) (res *dto.StrategyRes, err error) {
|
||||
affected, err := service.Strategy.UpdateStrategy(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -48,7 +49,7 @@ func (c *cStrategy) Update(ctx context.Context, req *dto.UpdateStrategyReq) (res
|
||||
}
|
||||
|
||||
// Delete 删除策略
|
||||
func (c *cStrategy) Delete(ctx context.Context, req *dto.DeleteStrategyReq) (res *dto.DeleteStrategyRes, err error) {
|
||||
func (c *strategy) Delete(ctx context.Context, req *dto.DeleteStrategyReq) (res *dto.DeleteStrategyRes, err error) {
|
||||
affected, err := service.Strategy.DeleteStrategy(ctx, req.Id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -63,7 +64,7 @@ func (c *cStrategy) Delete(ctx context.Context, req *dto.DeleteStrategyReq) (res
|
||||
}
|
||||
|
||||
// GetByID 根据ID获取策略
|
||||
func (c *cStrategy) GetByID(ctx context.Context, req *dto.GetStrategyReq) (res *dto.StrategyRes, err error) {
|
||||
func (c *strategy) GetByID(ctx context.Context, req *dto.GetStrategyReq) (res *dto.StrategyRes, err error) {
|
||||
strategy, err := service.Strategy.GetStrategyByID(ctx, req.Id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -73,6 +74,6 @@ func (c *cStrategy) GetByID(ctx context.Context, req *dto.GetStrategyReq) (res *
|
||||
}
|
||||
|
||||
// GetList 获取策略列表
|
||||
func (c *cStrategy) GetList(ctx context.Context, req *dto.GetStrategyListReq) (res *dto.GetStrategyListRes, err error) {
|
||||
func (c *strategy) GetList(ctx context.Context, req *dto.GetStrategyListReq) (res *dto.GetStrategyListRes, err error) {
|
||||
return service.Strategy.GetStrategyList(ctx, req)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user