Dockerfile
This commit is contained in:
@@ -1,65 +0,0 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"cid/model/dto"
|
||||
"cid/service"
|
||||
|
||||
"gitea.com/red-future/common/beans"
|
||||
)
|
||||
|
||||
type adPosition struct{}
|
||||
|
||||
var AdPosition = new(adPosition)
|
||||
|
||||
// Add 添加广告位
|
||||
func (c *adPosition) Add(ctx context.Context, req *dto.AddAdPositionReq) (res *dto.AddAdPositionRes, err error) {
|
||||
return service.AdPosition.Add(ctx, req)
|
||||
}
|
||||
|
||||
// Update 更新广告位
|
||||
func (c *adPosition) Update(ctx context.Context, req *dto.UpdateAdPositionReq) (res *beans.ResponseEmpty, err error) {
|
||||
err = service.AdPosition.Update(ctx, req)
|
||||
return
|
||||
}
|
||||
|
||||
// UpdateStatus 更新广告位状态
|
||||
func (c *adPosition) UpdateStatus(ctx context.Context, req *dto.UpdateAdPositionStatusReq) (res *beans.ResponseEmpty, err error) {
|
||||
err = service.AdPosition.UpdateStatus(ctx, req)
|
||||
return
|
||||
}
|
||||
|
||||
// GetOne 获取广告位详情
|
||||
func (c *adPosition) GetOne(ctx context.Context, req *dto.GetAdPositionReq) (res *dto.GetAdPositionRes, err error) {
|
||||
return service.AdPosition.GetOne(ctx, req)
|
||||
}
|
||||
|
||||
// List 获取广告位列表
|
||||
func (c *adPosition) List(ctx context.Context, req *dto.ListAdPositionReq) (res *dto.ListAdPositionRes, err error) {
|
||||
return service.AdPosition.List(ctx, req)
|
||||
}
|
||||
|
||||
// GetAvailableAdPositions 获取可用的广告位列表
|
||||
func (c *adPosition) GetAvailableAdPositions(ctx context.Context, _ *dto.GetAvailableAdPositionsReq) (res *dto.GetAvailableAdPositionsRes, err error) {
|
||||
list, err := service.AdPosition.GetAvailableAdPositions(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &dto.GetAvailableAdPositionsRes{
|
||||
List: list,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// MatchAd 匹配广告
|
||||
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
|
||||
}
|
||||
|
||||
return &dto.MatchAdRes{
|
||||
Advertisement: ad,
|
||||
}, nil
|
||||
}
|
||||
@@ -1,94 +0,0 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"cid/model/dto"
|
||||
"cid/service"
|
||||
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
)
|
||||
|
||||
var AdSource = new(adSource)
|
||||
|
||||
type adSource struct{}
|
||||
|
||||
// Create 创建广告源
|
||||
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
|
||||
}
|
||||
|
||||
adSource, err := service.AdSource.GetAdSourceByID(ctx, id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &dto.GetAdSourceRes{
|
||||
AdSource: adSource,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// Update 更新广告源
|
||||
func (c *adSource) Update(ctx context.Context, req *dto.UpdateAdSourceReq) (res *dto.GetAdSourceRes, err error) {
|
||||
affected, err := service.AdSource.UpdateAdSource(ctx, req.Id, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if affected == 0 {
|
||||
return nil, gerror.New("广告源更新失败")
|
||||
}
|
||||
|
||||
adSource, err := service.AdSource.GetAdSourceByID(ctx, req.Id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &dto.GetAdSourceRes{
|
||||
AdSource: adSource,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// Delete 删除广告源
|
||||
func (c *adSource) Delete(ctx context.Context, req *dto.DeleteAdSourceReq) (res *dto.DeleteAdSourceRes, err error) {
|
||||
affected, err := service.AdSource.DeleteAdSource(ctx, req.Id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if affected == 0 {
|
||||
return nil, gerror.New("广告源删除失败")
|
||||
}
|
||||
|
||||
return &dto.DeleteAdSourceRes{
|
||||
Success: true,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// GetByID 根据ID获取广告源
|
||||
func (c *adSource) GetByID(ctx context.Context, req *dto.GetAdSourceReq) (res *dto.GetAdSourceRes, err error) {
|
||||
adSource, err := service.AdSource.GetAdSourceByID(ctx, req.Id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if adSource == nil {
|
||||
return nil, gerror.New("广告源不存在")
|
||||
}
|
||||
|
||||
return &dto.GetAdSourceRes{
|
||||
AdSource: adSource,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// List 获取广告源列表
|
||||
func (c *adSource) List(ctx context.Context, req *dto.ListAdSourceReq) (res *dto.ListAdSourceRes, err error) {
|
||||
adSources, err := service.AdSource.GetAvailableSources(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &dto.ListAdSourceRes{
|
||||
List: adSources,
|
||||
Total: len(adSources),
|
||||
}, nil
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"cid/model/dto"
|
||||
"cid/service"
|
||||
"context"
|
||||
|
||||
"gitea.com/red-future/common/beans"
|
||||
)
|
||||
|
||||
type advertisement struct{}
|
||||
|
||||
var Advertisement = new(advertisement)
|
||||
|
||||
// Add 添加广告
|
||||
func (c *advertisement) Add(ctx context.Context, req *dto.AddAdvertisementReq) (res *dto.AddAdvertisementRes, err error) {
|
||||
return service.Advertisement.Add(ctx, req)
|
||||
}
|
||||
|
||||
// Update 更新广告
|
||||
func (c *advertisement) Update(ctx context.Context, req *dto.UpdateAdvertisementReq) (res *beans.ResponseEmpty, err error) {
|
||||
err = service.Advertisement.Update(ctx, req)
|
||||
return
|
||||
}
|
||||
|
||||
// UpdateStatus 更新广告状态
|
||||
func (c *advertisement) UpdateStatus(ctx context.Context, req *dto.UpdateAdStatusReq) (res *beans.ResponseEmpty, err error) {
|
||||
err = service.Advertisement.UpdateStatus(ctx, req)
|
||||
return
|
||||
}
|
||||
|
||||
// Audit 审核广告
|
||||
func (c *advertisement) Audit(ctx context.Context, req *dto.AuditAdvertisementReq) (res *beans.ResponseEmpty, err error) {
|
||||
err = service.Advertisement.Audit(ctx, req)
|
||||
return
|
||||
}
|
||||
|
||||
// GetOne 获取广告详情
|
||||
func (c *advertisement) GetOne(ctx context.Context, req *dto.GetAdvertisementReq) (res *dto.GetAdvertisementRes, err error) {
|
||||
return service.Advertisement.GetOne(ctx, req)
|
||||
}
|
||||
|
||||
// List 获取广告列表
|
||||
func (c *advertisement) List(ctx context.Context, req *dto.ListAdvertisementReq) (res *dto.ListAdvertisementRes, err error) {
|
||||
return service.Advertisement.List(ctx, req)
|
||||
}
|
||||
@@ -1,71 +0,0 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"cid/model/dto"
|
||||
"cid/service"
|
||||
"context"
|
||||
|
||||
"gitea.com/red-future/common/beans"
|
||||
)
|
||||
|
||||
type advertiser struct{}
|
||||
|
||||
var Advertiser = new(advertiser)
|
||||
|
||||
// Add 添加广告主
|
||||
func (c *advertiser) Add(ctx context.Context, req *dto.AddAdvertiserReq) (res *dto.AddAdvertiserRes, err error) {
|
||||
return service.Advertiser.Add(ctx, req)
|
||||
}
|
||||
|
||||
// Update 更新广告主
|
||||
func (c *advertiser) Update(ctx context.Context, req *dto.UpdateAdvertiserReq) (res *beans.ResponseEmpty, err error) {
|
||||
err = service.Advertiser.Update(ctx, req)
|
||||
return
|
||||
}
|
||||
|
||||
// UpdateStatus 更新广告主状态
|
||||
func (c *advertiser) UpdateStatus(ctx context.Context, req *dto.UpdateAdvertiserStatusReq) (res *beans.ResponseEmpty, err error) {
|
||||
err = service.Advertiser.UpdateStatus(ctx, req)
|
||||
return
|
||||
}
|
||||
|
||||
// Audit 审核广告主
|
||||
func (c *advertiser) Audit(ctx context.Context, req *dto.AuditAdvertiserReq) (res *beans.ResponseEmpty, err error) {
|
||||
err = service.Advertiser.Audit(ctx, req)
|
||||
return
|
||||
}
|
||||
|
||||
// Recharge 充值
|
||||
func (c *advertiser) Recharge(ctx context.Context, req *dto.RechargeAdvertiserReq) (res *beans.ResponseEmpty, err error) {
|
||||
err = service.Advertiser.Recharge(ctx, req)
|
||||
return
|
||||
}
|
||||
|
||||
// UpdateCreditLimit 更新授信额度
|
||||
func (c *advertiser) UpdateCreditLimit(ctx context.Context, req *dto.UpdateCreditLimitReq) (res *beans.ResponseEmpty, err error) {
|
||||
err = service.Advertiser.UpdateCreditLimit(ctx, req)
|
||||
return
|
||||
}
|
||||
|
||||
// GetOne 获取广告主详情
|
||||
func (c *advertiser) GetOne(ctx context.Context, req *dto.GetAdvertiserReq) (res *dto.GetAdvertiserRes, err error) {
|
||||
return service.Advertiser.GetOne(ctx, req)
|
||||
}
|
||||
|
||||
// List 获取广告主列表
|
||||
func (c *advertiser) List(ctx context.Context, req *dto.ListAdvertiserReq) (res *dto.ListAdvertiserRes, err error) {
|
||||
return service.Advertiser.List(ctx, req)
|
||||
}
|
||||
|
||||
// GetBalance 获取广告主余额
|
||||
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
|
||||
}
|
||||
|
||||
return &dto.GetAdvertiserBalanceRes{
|
||||
Balance: balance,
|
||||
CreditLimit: creditLimit,
|
||||
}, nil
|
||||
}
|
||||
47
controller/app/application_controller.go
Normal file
47
controller/app/application_controller.go
Normal file
@@ -0,0 +1,47 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
dto "cid/model/dto/app"
|
||||
service "cid/service/app"
|
||||
"context"
|
||||
|
||||
"gitea.com/red-future/common/beans"
|
||||
)
|
||||
|
||||
type applicationController struct{}
|
||||
|
||||
// Application 应用控制器
|
||||
var Application = new(applicationController)
|
||||
|
||||
// CreateApplication 创建应用
|
||||
func (c *applicationController) CreateApplication(ctx context.Context, req *dto.CreateApplicationReq) (res *dto.CreateApplicationRes, err error) {
|
||||
return service.Application.Create(ctx, req)
|
||||
}
|
||||
|
||||
// ListApplication 获取应用列表
|
||||
func (c *applicationController) ListApplication(ctx context.Context, req *dto.ListApplicationReq) (res *dto.ListApplicationRes, err error) {
|
||||
return service.Application.List(ctx, req)
|
||||
}
|
||||
|
||||
// GetApplication 获取应用详情
|
||||
func (c *applicationController) GetApplication(ctx context.Context, req *dto.GetApplicationReq) (res *dto.GetApplicationRes, err error) {
|
||||
return service.Application.GetOne(ctx, req)
|
||||
}
|
||||
|
||||
// UpdateApplication 更新应用
|
||||
func (c *applicationController) UpdateApplication(ctx context.Context, req *dto.UpdateApplicationReq) (res *beans.ResponseEmpty, err error) {
|
||||
err = service.Application.Update(ctx, req)
|
||||
return
|
||||
}
|
||||
|
||||
// UpdateApplicationStatus 更新应用状态
|
||||
func (c *applicationController) UpdateApplicationStatus(ctx context.Context, req *dto.UpdateApplicationStatusReq) (res *beans.ResponseEmpty, err error) {
|
||||
err = service.Application.UpdateStatus(ctx, req)
|
||||
return
|
||||
}
|
||||
|
||||
// DeleteApplication 删除应用
|
||||
func (c *applicationController) DeleteApplication(ctx context.Context, req *dto.DeleteApplicationReq) (res *beans.ResponseEmpty, err error) {
|
||||
err = service.Application.Delete(ctx, req)
|
||||
return
|
||||
}
|
||||
@@ -1,159 +0,0 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strconv"
|
||||
|
||||
"cid/model/dto"
|
||||
"cid/service"
|
||||
)
|
||||
|
||||
var Application = new(application)
|
||||
|
||||
type application struct{}
|
||||
|
||||
// CreateApplication 创建应用
|
||||
func (c *application) CreateApplication(ctx context.Context, req *dto.CreateApplicationReq) (res *dto.CreateApplicationRes, err error) {
|
||||
idStr, err := service.Application.CreateApplication(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 将字符串ID转换为int64
|
||||
id, _ := strconv.ParseInt(idStr, 10, 64)
|
||||
|
||||
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, strconv.FormatInt(req.ID, 10), 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, strconv.FormatInt(req.ID, 10))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 将ObjectId的十六进制字符串转换为int64,如果失败则使用0
|
||||
id, _ := strconv.ParseInt(app.Id.Hex(), 16, 64)
|
||||
// Application实体中没有TenantId字段,暂时设为0
|
||||
tenantID := int64(0)
|
||||
|
||||
return &dto.GetApplicationRes{
|
||||
ID: id,
|
||||
TenantID: 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, strconv.FormatInt(req.TenantID, 10), 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 {
|
||||
id, _ := strconv.ParseInt(app.Id.Hex(), 16, 64)
|
||||
appItems[i] = dto.ApplicationItem{
|
||||
ID: 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, strconv.FormatInt(req.ID, 10))
|
||||
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
|
||||
}
|
||||
|
||||
// 将ObjectId的十六进制字符串转换为int64,如果失败则使用0
|
||||
appID, _ := strconv.ParseInt(app.Id.Hex(), 16, 64)
|
||||
// Application实体中没有TenantId字段,暂时设为0
|
||||
tenantID := int64(0)
|
||||
tentantName := ""
|
||||
|
||||
return &dto.ValidateApplicationRes{
|
||||
Valid: true,
|
||||
AppID: appID,
|
||||
AppName: app.Name,
|
||||
TenantID: 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, strconv.FormatInt(req.ID, 10))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &dto.DeleteApplicationRes{
|
||||
Success: affected > 0,
|
||||
}, nil
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"cid/model/dto"
|
||||
"cid/service"
|
||||
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
)
|
||||
|
||||
var CID = new(cid)
|
||||
|
||||
type cid struct{}
|
||||
|
||||
// GenerateCID 生成CID广告
|
||||
func (c *cid) GenerateCID(ctx context.Context, req *dto.GenerateCIDReq) (res *dto.GenerateCIDRes, err error) {
|
||||
if req == nil {
|
||||
return nil, gerror.New("请求参数不能为空")
|
||||
}
|
||||
|
||||
if req.RequestType == "" {
|
||||
req.RequestType = "default" // 默认请求类型
|
||||
}
|
||||
|
||||
result, err := service.CID.GenerateCID(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// GetCIDHistory 获取CID历史记录
|
||||
func (c *cid) GetCIDHistory(ctx context.Context, req *dto.GetCIDHistoryReq) (res *dto.GetCIDHistoryRes, err error) {
|
||||
if req == nil {
|
||||
return nil, gerror.New("请求参数不能为空")
|
||||
}
|
||||
|
||||
// 查询历史记录
|
||||
history, err := service.CID.GetCIDHistory(ctx, 1, req.Page, req.Size) // 临时使用固定用户ID
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return history, nil
|
||||
}
|
||||
47
controller/data/api_interface_controller.go
Normal file
47
controller/data/api_interface_controller.go
Normal file
@@ -0,0 +1,47 @@
|
||||
package data
|
||||
|
||||
import (
|
||||
dto "cid/model/dto/data"
|
||||
service "cid/service/data"
|
||||
"context"
|
||||
|
||||
"gitea.com/red-future/common/beans"
|
||||
)
|
||||
|
||||
type apiInterfaceController struct{}
|
||||
|
||||
// ApiInterface 接口控制器
|
||||
var ApiInterface = new(apiInterfaceController)
|
||||
|
||||
// CreateApiInterface 创建接口
|
||||
func (c *apiInterfaceController) CreateApiInterface(ctx context.Context, req *dto.CreateApiInterfaceReq) (res *dto.CreateApiInterfaceRes, err error) {
|
||||
return service.ApiInterface.Create(ctx, req)
|
||||
}
|
||||
|
||||
// ListApiInterface 获取接口列表
|
||||
func (c *apiInterfaceController) ListApiInterface(ctx context.Context, req *dto.ListApiInterfaceReq) (res *dto.ListApiInterfaceRes, err error) {
|
||||
return service.ApiInterface.List(ctx, req)
|
||||
}
|
||||
|
||||
// GetApiInterface 获取接口详情
|
||||
func (c *apiInterfaceController) GetApiInterface(ctx context.Context, req *dto.GetApiInterfaceReq) (res *dto.GetApiInterfaceRes, err error) {
|
||||
return service.ApiInterface.GetOne(ctx, req)
|
||||
}
|
||||
|
||||
// UpdateApiInterface 更新接口
|
||||
func (c *apiInterfaceController) UpdateApiInterface(ctx context.Context, req *dto.UpdateApiInterfaceReq) (res *beans.ResponseEmpty, err error) {
|
||||
err = service.ApiInterface.Update(ctx, req)
|
||||
return
|
||||
}
|
||||
|
||||
// UpdateApiInterfaceStatus 更新接口状态
|
||||
func (c *apiInterfaceController) UpdateApiInterfaceStatus(ctx context.Context, req *dto.UpdateApiInterfaceStatusReq) (res *beans.ResponseEmpty, err error) {
|
||||
err = service.ApiInterface.UpdateStatus(ctx, req)
|
||||
return
|
||||
}
|
||||
|
||||
// DeleteApiInterface 删除接口
|
||||
func (c *apiInterfaceController) DeleteApiInterface(ctx context.Context, req *dto.DeleteApiInterfaceReq) (res *beans.ResponseEmpty, err error) {
|
||||
err = service.ApiInterface.Delete(ctx, req)
|
||||
return
|
||||
}
|
||||
37
controller/data/data_fetch_controller.go
Normal file
37
controller/data/data_fetch_controller.go
Normal file
@@ -0,0 +1,37 @@
|
||||
package data
|
||||
|
||||
import (
|
||||
dto "cid/model/dto/data"
|
||||
service "cid/service/data"
|
||||
"context"
|
||||
)
|
||||
|
||||
type dataFetchController struct{}
|
||||
|
||||
// DataFetch 数据获取控制器
|
||||
var DataFetch = new(dataFetchController)
|
||||
|
||||
// ExecuteDataFetch 执行数据获取
|
||||
func (c *dataFetchController) ExecuteDataFetch(ctx context.Context, req *dto.ExecuteDataFetchReq) (res *dto.ExecuteDataFetchRes, err error) {
|
||||
return service.DataFetch.Execute(ctx, req)
|
||||
}
|
||||
|
||||
// BatchExecuteDataFetch 批量执行数据获取
|
||||
func (c *dataFetchController) BatchExecuteDataFetch(ctx context.Context, req *dto.BatchExecuteDataFetchReq) (res *dto.BatchExecuteDataFetchRes, err error) {
|
||||
return service.DataFetch.BatchExecute(ctx, req)
|
||||
}
|
||||
|
||||
// ListDataFetchLog 获取数据获取日志列表
|
||||
func (c *dataFetchController) ListDataFetchLog(ctx context.Context, req *dto.ListDataFetchLogReq) (res *dto.ListDataFetchLogRes, err error) {
|
||||
return service.DataFetch.List(ctx, req)
|
||||
}
|
||||
|
||||
// GetDataFetchLog 获取数据获取日志详情
|
||||
func (c *dataFetchController) GetDataFetchLog(ctx context.Context, req *dto.GetDataFetchLogReq) (res *dto.GetDataFetchLogRes, err error) {
|
||||
return service.DataFetch.GetOne(ctx, req)
|
||||
}
|
||||
|
||||
// ReExecuteDataFetch 重新执行数据获取
|
||||
func (c *dataFetchController) ReExecuteDataFetch(ctx context.Context, req *dto.ReExecuteDataFetchReq) (res *dto.ReExecuteDataFetchRes, err error) {
|
||||
return service.DataFetch.ReExecute(ctx, req)
|
||||
}
|
||||
47
controller/data/platform_controller.go
Normal file
47
controller/data/platform_controller.go
Normal file
@@ -0,0 +1,47 @@
|
||||
package data
|
||||
|
||||
import (
|
||||
dto "cid/model/dto/data"
|
||||
service "cid/service/data"
|
||||
"context"
|
||||
|
||||
"gitea.com/red-future/common/beans"
|
||||
)
|
||||
|
||||
type platformController struct{}
|
||||
|
||||
// Platform 平台控制器
|
||||
var Platform = new(platformController)
|
||||
|
||||
// CreatePlatform 创建平台
|
||||
func (c *platformController) CreatePlatform(ctx context.Context, req *dto.CreatePlatformReq) (res *dto.CreatePlatformRes, err error) {
|
||||
return service.Platform.Create(ctx, req)
|
||||
}
|
||||
|
||||
// ListPlatform 获取平台列表
|
||||
func (c *platformController) ListPlatform(ctx context.Context, req *dto.ListPlatformReq) (res *dto.ListPlatformRes, err error) {
|
||||
return service.Platform.List(ctx, req)
|
||||
}
|
||||
|
||||
// GetPlatform 获取平台详情
|
||||
func (c *platformController) GetPlatform(ctx context.Context, req *dto.GetPlatformReq) (res *dto.GetPlatformRes, err error) {
|
||||
return service.Platform.GetOne(ctx, req)
|
||||
}
|
||||
|
||||
// UpdatePlatform 更新平台
|
||||
func (c *platformController) UpdatePlatform(ctx context.Context, req *dto.UpdatePlatformReq) (res *beans.ResponseEmpty, err error) {
|
||||
err = service.Platform.Update(ctx, req)
|
||||
return
|
||||
}
|
||||
|
||||
// UpdatePlatformStatus 更新平台状态
|
||||
func (c *platformController) UpdatePlatformStatus(ctx context.Context, req *dto.UpdatePlatformStatusReq) (res *beans.ResponseEmpty, err error) {
|
||||
err = service.Platform.UpdateStatus(ctx, req)
|
||||
return
|
||||
}
|
||||
|
||||
// DeletePlatform 删除平台
|
||||
func (c *platformController) DeletePlatform(ctx context.Context, req *dto.DeletePlatformReq) (res *beans.ResponseEmpty, err error) {
|
||||
err = service.Platform.Delete(ctx, req)
|
||||
return
|
||||
}
|
||||
51
controller/mapping/data_mapping_controller.go
Normal file
51
controller/mapping/data_mapping_controller.go
Normal file
@@ -0,0 +1,51 @@
|
||||
package mapping
|
||||
|
||||
import (
|
||||
dto "cid/model/dto/mapping"
|
||||
service "cid/service/mapping"
|
||||
"context"
|
||||
|
||||
"gitea.com/red-future/common/beans"
|
||||
)
|
||||
|
||||
type dataMappingController struct{}
|
||||
|
||||
// DataMapping 数据映射控制器
|
||||
var DataMapping = new(dataMappingController)
|
||||
|
||||
// CreateDataMapping 创建数据映射
|
||||
func (c *dataMappingController) CreateDataMapping(ctx context.Context, req *dto.CreateDataMappingReq) (res *dto.CreateDataMappingRes, err error) {
|
||||
return service.DataMapping.Create(ctx, req)
|
||||
}
|
||||
|
||||
// BatchCreateDataMappings 批量创建数据映射
|
||||
func (c *dataMappingController) BatchCreateDataMappings(ctx context.Context, req *dto.BatchCreateDataMappingReq) (res *dto.BatchCreateDataMappingRes, err error) {
|
||||
return service.DataMapping.BatchCreate(ctx, req)
|
||||
}
|
||||
|
||||
// ListDataMapping 获取数据映射列表
|
||||
func (c *dataMappingController) ListDataMapping(ctx context.Context, req *dto.ListDataMappingReq) (res *dto.ListDataMappingRes, err error) {
|
||||
return service.DataMapping.List(ctx, req)
|
||||
}
|
||||
|
||||
// GetDataMapping 获取数据映射详情
|
||||
func (c *dataMappingController) GetDataMapping(ctx context.Context, req *dto.GetDataMappingReq) (res *dto.GetDataMappingRes, err error) {
|
||||
return service.DataMapping.GetOne(ctx, req)
|
||||
}
|
||||
|
||||
// UpdateDataMapping 更新数据映射
|
||||
func (c *dataMappingController) UpdateDataMapping(ctx context.Context, req *dto.UpdateDataMappingReq) (res *beans.ResponseEmpty, err error) {
|
||||
err = service.DataMapping.Update(ctx, req)
|
||||
return
|
||||
}
|
||||
|
||||
// DeleteDataMapping 删除数据映射
|
||||
func (c *dataMappingController) DeleteDataMapping(ctx context.Context, req *dto.DeleteDataMappingReq) (res *beans.ResponseEmpty, err error) {
|
||||
err = service.DataMapping.Delete(ctx, req)
|
||||
return
|
||||
}
|
||||
|
||||
// ExecuteDataMapping 执行数据映射
|
||||
func (c *dataMappingController) ExecuteDataMapping(ctx context.Context, req *dto.ExecuteDataMappingReq) (res *dto.ExecuteDataMappingRes, err error) {
|
||||
return service.DataMapping.Execute(ctx, req)
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"cid/model/dto"
|
||||
"cid/service"
|
||||
)
|
||||
|
||||
var RateLimit = new(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
|
||||
}
|
||||
@@ -1,77 +0,0 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"cid/model/dto"
|
||||
"cid/service"
|
||||
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
)
|
||||
|
||||
var Strategy = new(strategy)
|
||||
|
||||
type strategy struct{}
|
||||
|
||||
// Create 创建策略
|
||||
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
|
||||
}
|
||||
|
||||
strategy, err := service.Strategy.GetStrategyByID(ctx, id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return strategy, nil
|
||||
}
|
||||
|
||||
// Update 更新策略
|
||||
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
|
||||
}
|
||||
if affected == 0 {
|
||||
return nil, gerror.New("策略更新失败")
|
||||
}
|
||||
|
||||
strategy, err := service.Strategy.GetStrategyByID(ctx, req.Id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return strategy, nil
|
||||
}
|
||||
|
||||
// Delete 删除策略
|
||||
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
|
||||
}
|
||||
if affected == 0 {
|
||||
return nil, gerror.New("策略删除失败")
|
||||
}
|
||||
|
||||
return &dto.DeleteStrategyRes{
|
||||
Success: true,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// GetByID 根据ID获取策略
|
||||
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
|
||||
}
|
||||
|
||||
return strategy, nil
|
||||
}
|
||||
|
||||
// GetList 获取策略列表
|
||||
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