Initial commit
This commit is contained in:
@@ -0,0 +1,184 @@
|
||||
package applicationmod
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"stat/common/log"
|
||||
"stat/common/mongos"
|
||||
"stat/common/stdLog"
|
||||
"time"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
)
|
||||
|
||||
func Init(ctx context.Context) {
|
||||
// 获取数据库表
|
||||
db = mongos.New(mongos.MgoManager, Collapplication)
|
||||
|
||||
// 初始化索引
|
||||
indexes := []mongo.IndexModel{
|
||||
{
|
||||
Keys: bson.D{{Key: "parentAppId", Value: 1}},
|
||||
},
|
||||
{
|
||||
Keys: bson.D{{Key: "rank", Value: -1}},
|
||||
},
|
||||
{
|
||||
Keys: bson.D{{Key: "locId", Value: -1}},
|
||||
},
|
||||
}
|
||||
|
||||
if _, err := db.CreateIndex(ctx, indexes); err != nil {
|
||||
panic(fmt.Sprintf("Model %s InitIndex error %+v", Collapplication, err))
|
||||
}
|
||||
}
|
||||
|
||||
// InsertOneApplication 插入一个应用
|
||||
func InsertOneApplication(ctx context.Context, Application *Application) *stdLog.SrvErr {
|
||||
if _, err := db.InsertOne(ctx, Application); err != nil {
|
||||
log.Warn("media:InsertOneApplication db.InsertOne failed", log.E(err))
|
||||
return stdLog.New(stdLog.InsertDataError, "", "")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// DelOneApplication 删除一个应用tag
|
||||
func DelOneApplication(ctx context.Context, filter bson.M) (
|
||||
int64, *stdLog.SrvErr) {
|
||||
count, err := db.DeleteOne(ctx, filter)
|
||||
if err != nil {
|
||||
log.Warn("application:DelOneApplication db.DeleteOne failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return 0, stdLog.New(stdLog.DelDataError, "", "")
|
||||
}
|
||||
return count, nil
|
||||
}
|
||||
|
||||
// UpdateOneApplication 更新一个应用
|
||||
func UpdateOneApplication(ctx context.Context, filter bson.M, update bson.M) *stdLog.SrvErr {
|
||||
result, err := db.UpdateOne(ctx, filter, update)
|
||||
if err != nil {
|
||||
log.Warn("application:UpdateOneApplication db.UpdateOne failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return stdLog.New(stdLog.UpdateDataError, "", "")
|
||||
}
|
||||
if result.MatchedCount != 1 {
|
||||
log.Warn("application:UpdateOneApplication db.UpdateOne failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return stdLog.New(stdLog.ErrApplicationNotExist, "", "")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// CountApplications 统计应用数量
|
||||
func CountApplications(ctx context.Context, filter bson.M) (
|
||||
int64, *stdLog.SrvErr) {
|
||||
count, err := db.Count(ctx, filter)
|
||||
if err != nil {
|
||||
log.Warn("media:CountApplications db.Count failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return 0, stdLog.New(stdLog.QueryDataError, "", "")
|
||||
}
|
||||
return count, nil
|
||||
}
|
||||
|
||||
// FindOneApplication 查找一个应用
|
||||
func FindOneApplication(ctx context.Context, filter bson.M) (
|
||||
*Application, *stdLog.SrvErr) {
|
||||
var Application Application
|
||||
if err := db.FindOneEx(
|
||||
ctx, &Application, filter); err != nil {
|
||||
if err != mongo.ErrNoDocuments {
|
||||
log.Info("media:FindOneApplication db.FindOne failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return nil, stdLog.New(stdLog.QueryDataError, "", "")
|
||||
}
|
||||
return nil, stdLog.New(stdLog.ErrApplicationNotExist, "", "")
|
||||
}
|
||||
return &Application, nil
|
||||
}
|
||||
|
||||
// FindManyApplication 查找一批应用
|
||||
func FindManyApplication(ctx context.Context, filter bson.M,
|
||||
opts ...*options.FindOptions) (ApplicationList, *stdLog.SrvErr) {
|
||||
data := make(ApplicationList, 0)
|
||||
if err := db.Find(ctx, &data, filter, opts...); err != nil {
|
||||
log.Warn("application:FindManyApplication db.Find failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return nil, stdLog.New(stdLog.QueryDataError, "", "")
|
||||
}
|
||||
return data, nil
|
||||
}
|
||||
|
||||
// 根据appId获取配置的app
|
||||
func FindAppByAppId(ctx context.Context, appId int64) (data []Application, err error) {
|
||||
now := time.Now().Local()
|
||||
filter := bson.M{"parentAppId": appId, "status": true,
|
||||
"startTime": bson.M{"$lt": now}, "endTime": bson.M{"$gte": now}}
|
||||
|
||||
sort := bson.D{{Key: "rank", Value: -1}}
|
||||
|
||||
opts := options.Find().SetSort(sort)
|
||||
|
||||
if err = db.Find(ctx, &data, filter, opts); err != nil {
|
||||
log.Error("application FindAdsByAppId Find err", log.E(err))
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// 增加广告点击量
|
||||
func IncAppClickCount(ctx context.Context, id int64) (err error) {
|
||||
filter := bson.M{"_id": id}
|
||||
|
||||
update := bson.M{"$inc": bson.M{"clickCount": 1}}
|
||||
|
||||
if _, err = db.UpdateOne(ctx, filter, update); err != nil {
|
||||
log.Error("advertise IncAdsClickCount UpdateOne err", log.E(err))
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// GetAllAdvertiseMap 获取ads id map
|
||||
func GetAllAdvertiseMap(ctx context.Context) (map[primitive.ObjectID]*Application, error) {
|
||||
filter := bson.M{}
|
||||
dict := make(map[primitive.ObjectID]*Application)
|
||||
list := make([]*Application, 0)
|
||||
if err := db.Find(ctx, &list, filter); err != nil {
|
||||
log.Error("Advertise GetAllAdvertiseMap Find err", log.E(err))
|
||||
return dict, err
|
||||
}
|
||||
for _, ads := range list {
|
||||
dict[ads.Id] = ads
|
||||
}
|
||||
return dict, nil
|
||||
}
|
||||
|
||||
// 根据appId和locId更新位置id
|
||||
func UpdateLocInfo(ctx context.Context, appId, oldLocId, newLocID int32) (err error) {
|
||||
filter := bson.M{"appId": appId, "locId": oldLocId}
|
||||
|
||||
update := bson.M{"$set": bson.M{"locId": newLocID}}
|
||||
|
||||
if _, err = db.UpdateMany(ctx, filter, update); err != nil {
|
||||
log.Error("advertise UpdateLocInfo UpdateMany err", log.E(err))
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// UpdateManyApplication 更新满足条件的应用
|
||||
func UpdateManyApplication(ctx context.Context, filter bson.M, update bson.M) *stdLog.SrvErr {
|
||||
_, err := db.UpdateMany(ctx, filter, update)
|
||||
if err != nil {
|
||||
log.Warn("application:UpdateManyApplication db.UpdateMany failed",
|
||||
log.E(err), log.Any("filter", filter), log.Any("update", update))
|
||||
return stdLog.New(stdLog.UpdateDataError, "", "")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Executable
+80
@@ -0,0 +1,80 @@
|
||||
package applicationmod
|
||||
|
||||
type TagApplication struct {
|
||||
AndroidUrl string
|
||||
AppId string
|
||||
Avatar string
|
||||
BigImg string
|
||||
Categories string
|
||||
CreatedAt string
|
||||
CreatedId string
|
||||
Desc string
|
||||
DownloadUrl string
|
||||
EndTime string
|
||||
HighQualityType string
|
||||
HomeShow string
|
||||
Id string
|
||||
Internal string
|
||||
IosUrl string
|
||||
IsGame string
|
||||
IsHighQuality string
|
||||
IsRecommend string
|
||||
LocIds string
|
||||
LocNames string
|
||||
Name string
|
||||
NineShow string
|
||||
ParentAppId string
|
||||
Rank string
|
||||
RecreationShow string
|
||||
SmallImg string
|
||||
StartTime string
|
||||
Status string
|
||||
Tag string
|
||||
Total string
|
||||
UpdatedAt string
|
||||
UpdatedId string
|
||||
}
|
||||
|
||||
var FN struct {
|
||||
Application TagApplication
|
||||
}
|
||||
|
||||
var TN struct {
|
||||
Application string
|
||||
}
|
||||
|
||||
func init() {
|
||||
FN.Application.AndroidUrl = "androidUrl"
|
||||
FN.Application.AppId = "appId"
|
||||
FN.Application.Avatar = "avatar"
|
||||
FN.Application.BigImg = "bigImg"
|
||||
FN.Application.Categories = "categories"
|
||||
FN.Application.CreatedAt = "createdAt"
|
||||
FN.Application.CreatedId = "created_id"
|
||||
FN.Application.Desc = "desc"
|
||||
FN.Application.DownloadUrl = "download_url"
|
||||
FN.Application.EndTime = "endTime"
|
||||
FN.Application.HighQualityType = "highQualityType"
|
||||
FN.Application.HomeShow = "homeShow"
|
||||
FN.Application.Id = "_id"
|
||||
FN.Application.Internal = "internal"
|
||||
FN.Application.IosUrl = "iosUrl"
|
||||
FN.Application.IsGame = "isGame"
|
||||
FN.Application.IsHighQuality = "isHighQuality"
|
||||
FN.Application.IsRecommend = "isRecommend"
|
||||
FN.Application.LocIds = "locIds"
|
||||
FN.Application.LocNames = "-"
|
||||
FN.Application.Name = "name"
|
||||
FN.Application.NineShow = "nineShow"
|
||||
FN.Application.ParentAppId = "parentAppId"
|
||||
FN.Application.Rank = "rank"
|
||||
FN.Application.RecreationShow = "recreationShow"
|
||||
FN.Application.SmallImg = "smallImg"
|
||||
FN.Application.StartTime = "startTime"
|
||||
FN.Application.Status = "status"
|
||||
FN.Application.Tag = "tag"
|
||||
FN.Application.Total = "total"
|
||||
FN.Application.UpdatedAt = "updatedAt"
|
||||
FN.Application.UpdatedId = "updated_id"
|
||||
TN.Application = "application"
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
package applicationmod
|
||||
|
||||
import (
|
||||
"stat/common"
|
||||
"stat/common/mongos"
|
||||
"time"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
)
|
||||
|
||||
const Collapplication = "application"
|
||||
|
||||
var db *mongos.MongoTool
|
||||
|
||||
// 应用中心
|
||||
// @table:application
|
||||
type Application struct {
|
||||
Id primitive.ObjectID `json:"id" bson:"_id"`
|
||||
AppId int64 `json:"appId" bson:"appId"` //appId
|
||||
ParentAppId int64 `json:"parentAppId" bson:"parentAppId"` //所属appId
|
||||
Name string `json:"name" bson:"name"` //应用名
|
||||
DaoLiangTitle string `json:"daoLiangTitle" bson:"daoLiangTitle"` //广告导量标题
|
||||
Tag int32 `json:"tag" bson:"tag"` //标签
|
||||
Internal bool `json:"internal" bson:"internal"` //是否内部应用
|
||||
Categories []*common.CategoryRank `json:"categories" bson:"categories"` //分类排序
|
||||
Desc string `json:"desc" bson:"desc"` //描述
|
||||
DownloadUrl string `json:"download_url" bson:"download_url"` //下载地址
|
||||
IosUrl string `json:"iosUrl" bson:"iosUrl"` //ios链接
|
||||
AndroidUrl string `json:"androidUrl" bson:"androidUrl"` //安卓链接
|
||||
Avatar string `json:"avatar" bson:"avatar"` //头像图片
|
||||
Status bool `json:"status" bson:"status"` //状态
|
||||
Rank int64 `json:"rank" bson:"rank"` //默认排序
|
||||
Total int64 `json:"total" bson:"total"` //总点击
|
||||
CreatedId int64 `json:"created_id" bson:"created_id"` //创建人
|
||||
UpdatedId int64 `json:"updated_id" bson:"updated_id"` //最后更新人
|
||||
CreatedAt time.Time `json:"createdAt" bson:"createdAt"` //创建时间
|
||||
UpdatedAt time.Time `json:"updatedAt" bson:"updatedAt"` //更新时间
|
||||
NineShow bool `json:"nineShow" bson:"nineShow"` //是否九宫格
|
||||
RecreationShow bool `json:"recreationShow" bson:"recreationShow"` //是否娱乐中心显示
|
||||
IsRecommend bool `json:"isRecommend" bson:"isRecommend"` //是否推荐
|
||||
IsGame bool `json:"isGame" bson:"isGame"` //是否游戏
|
||||
HomeShow bool `json:"homeShow" bson:"homeShow"` //是否首页展示
|
||||
LocIds []int64 `json:"locIds" bson:"locIds"` //位置id
|
||||
LocNames []string `json:"locNames" bson:"-"` //位置映射
|
||||
SmallImg string `json:"smallImg" bson:"smallImg"` // 小图标(比例:360*200)
|
||||
BigImg string `json:"bigImg" bson:"bigImg"` // 大图标(比例:686*330)
|
||||
IsHighQuality bool `json:"isHighQuality" bson:"isHighQuality"` // 是否是优质APP推荐
|
||||
HighQualityType int64 `json:"highQualityType" bson:"highQualityType"` // 优质APP推荐展示方式 0:应用图标 1:展示描述文字
|
||||
StartTime time.Time `json:"startTime" bson:"startTime"` // 开始时间
|
||||
EndTime time.Time `json:"endTime" bson:"endTime"` // 结束时间
|
||||
}
|
||||
|
||||
type ApplicationList []*Application
|
||||
|
||||
type AppUpdate struct {
|
||||
Id string `json:"id" bson:"id"`
|
||||
Param AppUpdateInfo `json:"param" bson:"param"`
|
||||
}
|
||||
|
||||
type AppUpdateInfo struct {
|
||||
AppId int64 `json:"appId" bson:"appId"` //appId
|
||||
ParentAppId int64 `json:"parentAppId" bson:"parentAppId"` //所属appId
|
||||
Name string `json:"name" bson:"name"` //应用名
|
||||
DaoLiangTitle string `json:"daoLiangTitle" bson:"daoLiangTitle"` //广告导量标题
|
||||
//Tag common.AppReqType `json:"tag" bson:"tag"` //标签
|
||||
Internal bool `json:"internal" bson:"internal"` //是否内部应用
|
||||
Categories []*common.CategoryRank `json:"categories" bson:"categories"` //分类排序
|
||||
Desc string `json:"desc" bson:"desc"` //描述
|
||||
DownloadUrl string `json:"download_url" bson:"download_url"` //下载地址
|
||||
IosUrl string `json:"iosUrl" bson:"iosUrl"` //ios链接
|
||||
AndroidUrl string `json:"androidUrl" bson:"androidUrl"` //安卓链接
|
||||
Avatar string `json:"avatar" bson:"avatar"` //头像图片
|
||||
Status bool `json:"status" bson:"status"` //状态
|
||||
Rank int64 `json:"rank" bson:"rank"` //默认排序
|
||||
Total int64 `json:"total" bson:"total"` //总点击
|
||||
CreatedId int64 `json:"created_id" bson:"created_id"` //创建人
|
||||
UpdatedId int64 `json:"updated_id" bson:"updated_id"` //最后更新人
|
||||
UpdatedAt time.Time `json:"updatedAt" bson:"updatedAt"` //更新时间
|
||||
NineShow bool `json:"nineShow" bson:"nineShow"` //是否九宫格
|
||||
RecreationShow bool `json:"recreationShow" bson:"recreationShow"` //是否娱乐中心显示
|
||||
IsRecommend bool `json:"isRecommend" bson:"isRecommend"` //是否推荐
|
||||
IsGame bool `json:"isGame" bson:"isGame"` //是否游戏
|
||||
HomeShow bool `json:"homeShow" bson:"homeShow"` //是否首页展示
|
||||
LocIds []int32 `json:"locIds" bson:"locIds"` //位置id
|
||||
SmallImg string `json:"smallImg" bson:"smallImg"` // 小图标
|
||||
BigImg string `json:"bigImg" bson:"bigImg"` // 大图标
|
||||
IsHighQuality bool `json:"isHighQuality" bson:"isHighQuality"` // 是否是优质APP推荐
|
||||
HighQualityType int64 `json:"highQualityType" bson:"highQualityType"` // 优质APP推荐展示方式 0:应用图标 1:展示描述文字
|
||||
StartTime time.Time `bson:"startTime" json:"startTime"` // 开始时间
|
||||
EndTime time.Time `bson:"endTime" json:"endTime"` // 结束时间
|
||||
}
|
||||
Reference in New Issue
Block a user