初始化项目
This commit is contained in:
5
.gitignore
vendored
5
.gitignore
vendored
@@ -20,7 +20,7 @@ bin-release/
|
|||||||
/.idea/vcs.xml
|
/.idea/vcs.xml
|
||||||
/.idea/UniappTool.xml
|
/.idea/UniappTool.xml
|
||||||
/.idea/modules.xml
|
/.idea/modules.xml
|
||||||
/.idea/cidservice.iml
|
/.idea/cid.iml
|
||||||
/.idea/.gitignore
|
/.idea/.gitignore
|
||||||
/.idea/go.imports.xml/
|
/.idea/go.imports.xml/
|
||||||
/model/dto/dto规范.md
|
/model/dto/dto规范.md
|
||||||
@@ -28,4 +28,5 @@ bin-release/
|
|||||||
/controller/controller规范.md
|
/controller/controller规范.md
|
||||||
/service/service规范.md
|
/service/service规范.md
|
||||||
dao/dao规范.md
|
dao/dao规范.md
|
||||||
api接口文档.md
|
api接口文档.md
|
||||||
|
/.idea/cidservice.iml
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ RUN ln -sf /usr/share/zoneinfo/$TIME_ZONE /etc/localtime \
|
|||||||
COPY go.mod go.sum ./
|
COPY go.mod go.sum ./
|
||||||
# RUN chown -R golang:golang $WORKDIR
|
# RUN chown -R golang:golang $WORKDIR
|
||||||
RUN go mod download && go mod verify
|
RUN go mod download && go mod verify
|
||||||
COPY ../../cidService $WORKDIR
|
COPY ../../cid $WORKDIR
|
||||||
RUN chown -R golang:golang $WORKDIR
|
RUN chown -R golang:golang $WORKDIR
|
||||||
# Remove SetUID, SetGID
|
# Remove SetUID, SetGID
|
||||||
RUN chmod 0755 /usr/local/bin/app/api \
|
RUN chmod 0755 /usr/local/bin/app/api \
|
||||||
@@ -54,4 +54,4 @@ RUN chmod 0755 /usr/local/bin/app/api \
|
|||||||
USER golang
|
USER golang
|
||||||
RUN go build -v -o /usr/local/bin/app ./...
|
RUN go build -v -o /usr/local/bin/app ./...
|
||||||
EXPOSE 3002
|
EXPOSE 3002
|
||||||
CMD ./cidService
|
CMD ./cid
|
||||||
@@ -75,7 +75,7 @@ CID服务商项目是一个为企业提供CID(Click ID)服务的完整解决
|
|||||||
## 项目结构
|
## 项目结构
|
||||||
|
|
||||||
```
|
```
|
||||||
cidservice/
|
cid/
|
||||||
├── controller/ # 控制器层
|
├── controller/ # 控制器层
|
||||||
│ ├── cid_controller.go
|
│ ├── cid_controller.go
|
||||||
│ ├── ad_source_controller.go
|
│ ├── ad_source_controller.go
|
||||||
|
|||||||
16
config.yml
16
config.yml
@@ -1,18 +1,9 @@
|
|||||||
server:
|
server:
|
||||||
address : ":3001"
|
address : ":3001"
|
||||||
name: "cidService"
|
name: "cid"
|
||||||
jwt:
|
|
||||||
secret: "abcdefghijklmnopqrstuvwxyz"
|
|
||||||
rate:
|
rate:
|
||||||
limit: 200
|
limit: 200
|
||||||
burst: 300
|
burst: 300
|
||||||
|
|
||||||
# 租户限流配置
|
|
||||||
tenantRateLimit:
|
|
||||||
enabled: true # 是否启用租户限流
|
|
||||||
requestsPerHour: 3600 # 每小时最大请求数
|
|
||||||
window: 3600 # 时间窗口(秒)
|
|
||||||
burst: 100 # 突发请求数
|
|
||||||
mongo:
|
mongo:
|
||||||
logger:
|
logger:
|
||||||
level: "all"
|
level: "all"
|
||||||
@@ -33,10 +24,5 @@ redis:
|
|||||||
consul:
|
consul:
|
||||||
address: 192.168.3.200:8500
|
address: 192.168.3.200:8500
|
||||||
# pass: jiahui8888
|
# pass: jiahui8888
|
||||||
rabbitMQ:
|
|
||||||
host: 192.168.3.200
|
|
||||||
port: 5672
|
|
||||||
username: guest # 默认用户名
|
|
||||||
password: guest # 默认密码
|
|
||||||
jaeger: #链路追踪
|
jaeger: #链路追踪
|
||||||
addr: 192.168.3.200:4318
|
addr: 192.168.3.200:4318
|
||||||
@@ -3,8 +3,8 @@ package controller
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"cidservice/model/dto"
|
"cid/model/dto"
|
||||||
"cidservice/service"
|
"cid/service"
|
||||||
|
|
||||||
"gitee.com/red-future---jilin-g/common/http"
|
"gitee.com/red-future---jilin-g/common/http"
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"cidservice/model/dto"
|
"cid/model/dto"
|
||||||
"cidservice/service"
|
"cid/service"
|
||||||
|
|
||||||
"github.com/gogf/gf/v2/errors/gerror"
|
"github.com/gogf/gf/v2/errors/gerror"
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -3,8 +3,8 @@ package controller
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"cidservice/model/dto"
|
"cid/model/dto"
|
||||||
"cidservice/service"
|
"cid/service"
|
||||||
)
|
)
|
||||||
|
|
||||||
type adStatistics struct{}
|
type adStatistics struct{}
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
package controller
|
package controller
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"cidservice/model/dto"
|
"cid/model/dto"
|
||||||
"cidservice/service"
|
"cid/service"
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"gitee.com/red-future---jilin-g/common/http"
|
"gitee.com/red-future---jilin-g/common/http"
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
package controller
|
package controller
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"cidservice/model/dto"
|
"cid/model/dto"
|
||||||
"cidservice/service"
|
"cid/service"
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"gitee.com/red-future---jilin-g/common/http"
|
"gitee.com/red-future---jilin-g/common/http"
|
||||||
|
|||||||
@@ -3,8 +3,8 @@ package controller
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"cidservice/model/dto"
|
"cid/model/dto"
|
||||||
"cidservice/service"
|
"cid/service"
|
||||||
)
|
)
|
||||||
|
|
||||||
var Application = new(application)
|
var Application = new(application)
|
||||||
|
|||||||
@@ -3,8 +3,8 @@ package controller
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"cidservice/model/dto"
|
"cid/model/dto"
|
||||||
"cidservice/service"
|
"cid/service"
|
||||||
|
|
||||||
"github.com/gogf/gf/v2/errors/gerror"
|
"github.com/gogf/gf/v2/errors/gerror"
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -3,8 +3,8 @@ package controller
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"cidservice/model/dto"
|
"cid/model/dto"
|
||||||
"cidservice/service"
|
"cid/service"
|
||||||
)
|
)
|
||||||
|
|
||||||
var RateLimit = new(rateLimit)
|
var RateLimit = new(rateLimit)
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"cidservice/model/dto"
|
"cid/model/dto"
|
||||||
"cidservice/service"
|
"cid/service"
|
||||||
)
|
)
|
||||||
|
|
||||||
var StatReport = new(statReport)
|
var StatReport = new(statReport)
|
||||||
|
|||||||
@@ -3,8 +3,8 @@ package controller
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"cidservice/model/dto"
|
"cid/model/dto"
|
||||||
"cidservice/service"
|
"cid/service"
|
||||||
|
|
||||||
"github.com/gogf/gf/v2/errors/gerror"
|
"github.com/gogf/gf/v2/errors/gerror"
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
package dao
|
package dao
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"cidservice/model/dto"
|
"cid/model/dto"
|
||||||
"cidservice/model/entity"
|
"cid/model/entity"
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"gitee.com/red-future---jilin-g/common/http"
|
"gitee.com/red-future---jilin-g/common/http"
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package dao
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"cidservice/model/entity"
|
"cid/model/entity"
|
||||||
"github.com/gogf/gf/v2/frame/g"
|
"github.com/gogf/gf/v2/frame/g"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -3,8 +3,8 @@ package dao
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"cidservice/model/dto"
|
"cid/model/dto"
|
||||||
"cidservice/model/entity"
|
"cid/model/entity"
|
||||||
|
|
||||||
"github.com/gogf/gf/v2/frame/g"
|
"github.com/gogf/gf/v2/frame/g"
|
||||||
"go.mongodb.org/mongo-driver/v2/bson"
|
"go.mongodb.org/mongo-driver/v2/bson"
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
package dao
|
package dao
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"cidservice/model/dto"
|
"cid/model/dto"
|
||||||
"cidservice/model/entity"
|
"cid/model/entity"
|
||||||
"context"
|
"context"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
package dao
|
package dao
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"cidservice/model/dto"
|
"cid/model/dto"
|
||||||
"cidservice/model/entity"
|
"cid/model/entity"
|
||||||
"context"
|
"context"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package dao
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"cidservice/model/entity"
|
"cid/model/entity"
|
||||||
|
|
||||||
"github.com/gogf/gf/v2/database/gdb"
|
"github.com/gogf/gf/v2/database/gdb"
|
||||||
"github.com/gogf/gf/v2/frame/g"
|
"github.com/gogf/gf/v2/frame/g"
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package dao
|
package dao
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"cidservice/model/entity"
|
"cid/model/entity"
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"github.com/gogf/gf/v2/frame/g"
|
"github.com/gogf/gf/v2/frame/g"
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package dao
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"cidservice/model/entity"
|
"cid/model/entity"
|
||||||
|
|
||||||
"github.com/gogf/gf/v2/database/gdb"
|
"github.com/gogf/gf/v2/database/gdb"
|
||||||
"github.com/gogf/gf/v2/frame/g"
|
"github.com/gogf/gf/v2/frame/g"
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package dao
|
package dao
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"cidservice/model/entity"
|
"cid/model/entity"
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"github.com/gogf/gf/v2/frame/g"
|
"github.com/gogf/gf/v2/frame/g"
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package dao
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"cidservice/model/entity"
|
"cid/model/entity"
|
||||||
|
|
||||||
"github.com/gogf/gf/v2/database/gdb"
|
"github.com/gogf/gf/v2/database/gdb"
|
||||||
"github.com/gogf/gf/v2/frame/g"
|
"github.com/gogf/gf/v2/frame/g"
|
||||||
|
|||||||
4
main.go
4
main.go
@@ -1,8 +1,8 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"cidservice/controller"
|
"cid/controller"
|
||||||
"cidservice/service"
|
"cid/service"
|
||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package dto
|
package dto
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"cidservice/model/entity"
|
"cid/model/entity"
|
||||||
|
|
||||||
"gitee.com/red-future---jilin-g/common/http"
|
"gitee.com/red-future---jilin-g/common/http"
|
||||||
"github.com/gogf/gf/v2/frame/g"
|
"github.com/gogf/gf/v2/frame/g"
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package dto
|
package dto
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"cidservice/model/entity"
|
"cid/model/entity"
|
||||||
|
|
||||||
"gitee.com/red-future---jilin-g/common/http"
|
"gitee.com/red-future---jilin-g/common/http"
|
||||||
"github.com/gogf/gf/v2/frame/g"
|
"github.com/gogf/gf/v2/frame/g"
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package dto
|
package dto
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"cidservice/model/entity"
|
"cid/model/entity"
|
||||||
|
|
||||||
"gitee.com/red-future---jilin-g/common/http"
|
"gitee.com/red-future---jilin-g/common/http"
|
||||||
"github.com/gogf/gf/v2/frame/g"
|
"github.com/gogf/gf/v2/frame/g"
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package dto
|
package dto
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"cidservice/model/entity"
|
"cid/model/entity"
|
||||||
|
|
||||||
"gitee.com/red-future---jilin-g/common/http"
|
"gitee.com/red-future---jilin-g/common/http"
|
||||||
"github.com/gogf/gf/v2/frame/g"
|
"github.com/gogf/gf/v2/frame/g"
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package dto
|
package dto
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"cidservice/model/entity"
|
"cid/model/entity"
|
||||||
|
|
||||||
"gitee.com/red-future---jilin-g/common/http"
|
"gitee.com/red-future---jilin-g/common/http"
|
||||||
"github.com/gogf/gf/v2/frame/g"
|
"github.com/gogf/gf/v2/frame/g"
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
package service
|
package service
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"cidservice/dao"
|
"cid/dao"
|
||||||
"cidservice/model/dto"
|
"cid/model/dto"
|
||||||
"cidservice/model/entity"
|
"cid/model/entity"
|
||||||
"context"
|
"context"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
package service
|
package service
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"cidservice/dao"
|
"cid/dao"
|
||||||
"cidservice/model/dto"
|
"cid/model/dto"
|
||||||
"cidservice/model/entity"
|
"cid/model/entity"
|
||||||
"context"
|
"context"
|
||||||
"github.com/gogf/gf/v2/errors/gerror"
|
"github.com/gogf/gf/v2/errors/gerror"
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -6,9 +6,9 @@ import (
|
|||||||
"sort"
|
"sort"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"cidservice/dao"
|
"cid/dao"
|
||||||
"cidservice/model/dto"
|
"cid/model/dto"
|
||||||
"cidservice/model/entity"
|
"cid/model/entity"
|
||||||
)
|
)
|
||||||
|
|
||||||
var AdStatistics = new(adStatistics)
|
var AdStatistics = new(adStatistics)
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
package service
|
package service
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"cidservice/dao"
|
"cid/dao"
|
||||||
"cidservice/model/dto"
|
"cid/model/dto"
|
||||||
"cidservice/model/entity"
|
"cid/model/entity"
|
||||||
"context"
|
"context"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
|||||||
@@ -7,9 +7,9 @@ import (
|
|||||||
"github.com/gogf/gf/v2/errors/gerror"
|
"github.com/gogf/gf/v2/errors/gerror"
|
||||||
"github.com/gogf/gf/v2/util/gconv"
|
"github.com/gogf/gf/v2/util/gconv"
|
||||||
|
|
||||||
"cidservice/dao"
|
"cid/dao"
|
||||||
"cidservice/model/dto"
|
"cid/model/dto"
|
||||||
"cidservice/model/entity"
|
"cid/model/entity"
|
||||||
)
|
)
|
||||||
|
|
||||||
var Advertiser = new(advertiser)
|
var Advertiser = new(advertiser)
|
||||||
|
|||||||
@@ -5,9 +5,9 @@ import (
|
|||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
|
|
||||||
"cidservice/dao"
|
"cid/dao"
|
||||||
"cidservice/model/dto"
|
"cid/model/dto"
|
||||||
"cidservice/model/entity"
|
"cid/model/entity"
|
||||||
|
|
||||||
"github.com/gogf/gf/v2/errors/gerror"
|
"github.com/gogf/gf/v2/errors/gerror"
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
package service
|
package service
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"cidservice/dao"
|
"cid/dao"
|
||||||
"cidservice/model/dto"
|
"cid/model/dto"
|
||||||
"cidservice/model/entity"
|
"cid/model/entity"
|
||||||
"cidservice/model/types"
|
"cid/model/types"
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
@@ -19,10 +19,10 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
CID = cidService{}
|
CID = cid{}
|
||||||
)
|
)
|
||||||
|
|
||||||
type cidService struct{}
|
type cid struct{}
|
||||||
|
|
||||||
// AdMatchingStrategy 广告匹配策略
|
// AdMatchingStrategy 广告匹配策略
|
||||||
type AdMatchingStrategy struct {
|
type AdMatchingStrategy struct {
|
||||||
@@ -34,7 +34,7 @@ type AdMatchingStrategy struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// getMatchingStrategy 获取匹配策略
|
// getMatchingStrategy 获取匹配策略
|
||||||
func (s *cidService) getMatchingStrategy(ctx context.Context, tenantLevel string) (*AdMatchingStrategy, error) {
|
func (s *cid) getMatchingStrategy(ctx context.Context, tenantLevel string) (*AdMatchingStrategy, error) {
|
||||||
// 从数据库获取策略
|
// 从数据库获取策略
|
||||||
strategyEntity, err := Strategy.GetStrategyByTenantLevel(ctx, tenantLevel)
|
strategyEntity, err := Strategy.GetStrategyByTenantLevel(ctx, tenantLevel)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -72,7 +72,7 @@ func (s *cidService) getMatchingStrategy(ctx context.Context, tenantLevel string
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GenerateCID 生成CID广告
|
// GenerateCID 生成CID广告
|
||||||
func (s *cidService) GenerateCID(ctx context.Context, req *dto.GenerateCIDReq) (res *dto.GenerateCIDRes, err error) {
|
func (s *cid) GenerateCID(ctx context.Context, req *dto.GenerateCIDReq) (res *dto.GenerateCIDRes, err error) {
|
||||||
// 获取当前用户信息
|
// 获取当前用户信息
|
||||||
userInfo, err := utils.GetUserInfo(ctx)
|
userInfo, err := utils.GetUserInfo(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -123,7 +123,7 @@ func (s *cidService) GenerateCID(ctx context.Context, req *dto.GenerateCIDReq) (
|
|||||||
}
|
}
|
||||||
|
|
||||||
// getTenantByUser 根据用户获取租户信息
|
// getTenantByUser 根据用户获取租户信息
|
||||||
func (s *cidService) getTenantByUser(ctx context.Context, userId int64) (*types.Tenant, error) {
|
func (s *cid) getTenantByUser(ctx context.Context, userId int64) (*types.Tenant, error) {
|
||||||
// 通过common模块获取用户信息,包含租户ID
|
// 通过common模块获取用户信息,包含租户ID
|
||||||
userInfo, err := utils.GetUserInfo(ctx)
|
userInfo, err := utils.GetUserInfo(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -164,7 +164,7 @@ func (s *cidService) getTenantByUser(ctx context.Context, userId int64) (*types.
|
|||||||
}
|
}
|
||||||
|
|
||||||
// matchAds 根据策略匹配广告
|
// matchAds 根据策略匹配广告
|
||||||
func (s *cidService) matchAds(ctx context.Context, req *dto.GenerateCIDReq, strategy *AdMatchingStrategy) ([]*dto.AdInfo, error) {
|
func (s *cid) matchAds(ctx context.Context, req *dto.GenerateCIDReq, strategy *AdMatchingStrategy) ([]*dto.AdInfo, error) {
|
||||||
var matchedAds []*dto.AdInfo
|
var matchedAds []*dto.AdInfo
|
||||||
|
|
||||||
// 根据策略权重从不同源获取广告
|
// 根据策略权重从不同源获取广告
|
||||||
@@ -202,7 +202,7 @@ func (s *cidService) matchAds(ctx context.Context, req *dto.GenerateCIDReq, stra
|
|||||||
}
|
}
|
||||||
|
|
||||||
// getAdsFromSource 从指定广告源获取广告
|
// getAdsFromSource 从指定广告源获取广告
|
||||||
func (s *cidService) getAdsFromSource(ctx context.Context, source string, req *dto.GenerateCIDReq, strategy *AdMatchingStrategy, weight int) ([]*dto.AdInfo, error) {
|
func (s *cid) getAdsFromSource(ctx context.Context, source string, req *dto.GenerateCIDReq, strategy *AdMatchingStrategy, weight int) ([]*dto.AdInfo, error) {
|
||||||
switch source {
|
switch source {
|
||||||
case "self":
|
case "self":
|
||||||
return s.getSelfServiceAds(ctx, req, weight)
|
return s.getSelfServiceAds(ctx, req, weight)
|
||||||
@@ -216,7 +216,7 @@ func (s *cidService) getAdsFromSource(ctx context.Context, source string, req *d
|
|||||||
}
|
}
|
||||||
|
|
||||||
// getSelfServiceAds 获取自营广告
|
// getSelfServiceAds 获取自营广告
|
||||||
func (s *cidService) getSelfServiceAds(ctx context.Context, req *dto.GenerateCIDReq, count int) ([]*dto.AdInfo, error) {
|
func (s *cid) getSelfServiceAds(ctx context.Context, req *dto.GenerateCIDReq, count int) ([]*dto.AdInfo, error) {
|
||||||
// 这里应该从数据库查询自营广告
|
// 这里应该从数据库查询自营广告
|
||||||
// 暂时返回模拟数据
|
// 暂时返回模拟数据
|
||||||
ads := make([]*dto.AdInfo, 0)
|
ads := make([]*dto.AdInfo, 0)
|
||||||
@@ -236,7 +236,7 @@ func (s *cidService) getSelfServiceAds(ctx context.Context, req *dto.GenerateCID
|
|||||||
}
|
}
|
||||||
|
|
||||||
// getGoogleAds 获取Google广告
|
// getGoogleAds 获取Google广告
|
||||||
func (s *cidService) getGoogleAds(ctx context.Context, req *dto.GenerateCIDReq, count int) ([]*dto.AdInfo, error) {
|
func (s *cid) getGoogleAds(ctx context.Context, req *dto.GenerateCIDReq, count int) ([]*dto.AdInfo, error) {
|
||||||
// 这里应该调用Google Ads API
|
// 这里应该调用Google Ads API
|
||||||
// 暂时返回模拟数据
|
// 暂时返回模拟数据
|
||||||
ads := make([]*dto.AdInfo, 0)
|
ads := make([]*dto.AdInfo, 0)
|
||||||
@@ -256,7 +256,7 @@ func (s *cidService) getGoogleAds(ctx context.Context, req *dto.GenerateCIDReq,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// getFacebookAds 获取Facebook广告
|
// getFacebookAds 获取Facebook广告
|
||||||
func (s *cidService) getFacebookAds(ctx context.Context, req *dto.GenerateCIDReq, count int) ([]*dto.AdInfo, error) {
|
func (s *cid) getFacebookAds(ctx context.Context, req *dto.GenerateCIDReq, count int) ([]*dto.AdInfo, error) {
|
||||||
// 这里应该调用Facebook Ads API
|
// 这里应该调用Facebook Ads API
|
||||||
// 暂时返回模拟数据
|
// 暂时返回模拟数据
|
||||||
ads := make([]*dto.AdInfo, 0)
|
ads := make([]*dto.AdInfo, 0)
|
||||||
@@ -276,14 +276,14 @@ func (s *cidService) getFacebookAds(ctx context.Context, req *dto.GenerateCIDReq
|
|||||||
}
|
}
|
||||||
|
|
||||||
// generateUniqueCID 生成唯一CID
|
// generateUniqueCID 生成唯一CID
|
||||||
func (s *cidService) generateUniqueCID() string {
|
func (s *cid) generateUniqueCID() string {
|
||||||
timestamp := time.Now().Unix()
|
timestamp := time.Now().Unix()
|
||||||
random := rand.Intn(8999) + 1000
|
random := rand.Intn(8999) + 1000
|
||||||
return fmt.Sprintf("CID_%d_%d", timestamp, random)
|
return fmt.Sprintf("CID_%d_%d", timestamp, random)
|
||||||
}
|
}
|
||||||
|
|
||||||
// recordCIDRequest 记录CID请求
|
// recordCIDRequest 记录CID请求
|
||||||
func (s *cidService) recordCIDRequest(ctx context.Context, req *dto.GenerateCIDReq, tenant *types.Tenant, ads []*dto.AdInfo) {
|
func (s *cid) recordCIDRequest(ctx context.Context, req *dto.GenerateCIDReq, tenant *types.Tenant, ads []*dto.AdInfo) {
|
||||||
// 转换dto.AdInfo到entity.Ad
|
// 转换dto.AdInfo到entity.Ad
|
||||||
var entityAds []entity.Ad
|
var entityAds []entity.Ad
|
||||||
for _, ad := range ads {
|
for _, ad := range ads {
|
||||||
@@ -312,7 +312,7 @@ func (s *cidService) recordCIDRequest(ctx context.Context, req *dto.GenerateCIDR
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetCIDHistory 获取CID请求历史
|
// GetCIDHistory 获取CID请求历史
|
||||||
func (s *cidService) GetCIDHistory(ctx context.Context, userId int64, page, size int) (res *dto.GetCIDHistoryRes, err error) {
|
func (s *cid) GetCIDHistory(ctx context.Context, userId int64, page, size int) (res *dto.GetCIDHistoryRes, err error) {
|
||||||
history, total, err := dao.CIDRequest.GetHistory(ctx, userId, page, size)
|
history, total, err := dao.CIDRequest.GetHistory(ctx, userId, page, size)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"cidservice/consts"
|
"cid/consts"
|
||||||
|
|
||||||
"github.com/gogf/gf/v2/frame/g"
|
"github.com/gogf/gf/v2/frame/g"
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -6,8 +6,8 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"cidservice/dao"
|
"cid/dao"
|
||||||
"cidservice/model/entity"
|
"cid/model/entity"
|
||||||
|
|
||||||
"github.com/gogf/gf/v2/frame/g"
|
"github.com/gogf/gf/v2/frame/g"
|
||||||
"github.com/gogf/gf/v2/util/gconv"
|
"github.com/gogf/gf/v2/util/gconv"
|
||||||
|
|||||||
@@ -5,9 +5,9 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"cidservice/dao"
|
"cid/dao"
|
||||||
"cidservice/model/dto"
|
"cid/model/dto"
|
||||||
"cidservice/model/entity"
|
"cid/model/entity"
|
||||||
|
|
||||||
"github.com/gogf/gf/v2/frame/g"
|
"github.com/gogf/gf/v2/frame/g"
|
||||||
"github.com/gogf/gf/v2/util/gconv"
|
"github.com/gogf/gf/v2/util/gconv"
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
package service
|
package service
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"cidservice/dao"
|
"cid/dao"
|
||||||
"cidservice/model/dto"
|
"cid/model/dto"
|
||||||
"cidservice/model/entity"
|
"cid/model/entity"
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|||||||
Reference in New Issue
Block a user