Initial commit
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
package versionMod
|
||||
|
||||
import (
|
||||
"stat/common/mongos"
|
||||
"time"
|
||||
)
|
||||
|
||||
// 表名
|
||||
const CollAppVersion = "version"
|
||||
|
||||
var db *mongos.MongoTool
|
||||
|
||||
type PkgType int8
|
||||
|
||||
const (
|
||||
_ PkgType = iota
|
||||
Enterprise //企业签
|
||||
Shop //商店包
|
||||
Tf //testFight
|
||||
Super //超级签
|
||||
Light //H5
|
||||
)
|
||||
|
||||
type TfInfo struct {
|
||||
AppName string `bson:"appName" json:"appName"` //应用名称
|
||||
AppIcon string `bson:"appIcon" json:"appIcon"` //应用图标
|
||||
URL string `bson:"url" json:"url"` //URL
|
||||
}
|
||||
|
||||
type VersionModel struct {
|
||||
Id int64 `bson:"_id" json:"id"` //ID
|
||||
AppId int32 `bson:"appId" json:"appId"` //APPID
|
||||
VersionNum string `bson:"versionNum" json:"versionNum"` //版本号
|
||||
Terminal string `bson:"terminal" json:"terminal"` //终端ios android
|
||||
Link []string `bson:"link" json:"link"` //下载链接
|
||||
TfInfo []TfInfo `bson:"tfInfo" json:"tfInfo"` //TF信息
|
||||
Info string `bson:"info" json:"info"` //版本描述
|
||||
PackageType PkgType `bson:"packageType" json:"packageType"` //包类型:1-企业包、2-商店包、3-tf、4-超级签 5-H5
|
||||
IsForceUpdate bool `bson:"isForceUpdate" json:"isForceUpdate"` //是否强更
|
||||
MinVersion string `bson:"minVersion" json:"minVersion"` //最小版本
|
||||
Status bool `bson:"status" json:"status"` //是否启用
|
||||
Size string `bson:"size" json:"size"` //更新版本大小M
|
||||
Md5 string `bson:"md5" json:"md5"` //MD5验证
|
||||
BackLink string `bson:"backLink" json:"backLink"` //企业签(备用连接)
|
||||
CreatedAt time.Time `bson:"createdAt" json:"createdAt"`
|
||||
UpdatedAt time.Time `bson:"updatedAt" json:"updatedAt"`
|
||||
}
|
||||
|
||||
type VersionList []*VersionModel
|
||||
|
||||
type VersionUpdate struct {
|
||||
VersionNum *string `bson:"versionNum" json:"versionNum"` //版本号
|
||||
Terminal *string `bson:"terminal" json:"terminal"` //终端ios android
|
||||
Link *[]string `bson:"link" json:"link"` //下载链接
|
||||
Info *string `bson:"info" json:"info"` //版本描述
|
||||
PackageType *PkgType `bson:"packageType" json:"packageType"` //包类型:1-企业包、2-商店包、3-tf、4-超级签 5-H5
|
||||
IsForceUpdate *bool `bson:"isForceUpdate" json:"isForceUpdate"` //是否强更
|
||||
TfInfo *[]TfInfo `bson:"tfInfo" json:"tfInfo"` //TF信息
|
||||
MinVersion *string `bson:"minVersion" json:"minVersion"` //最小版本
|
||||
Status *bool `bson:"status" json:"status"` //是否启用
|
||||
Size *string `bson:"size" json:"size"` //更新版本大小M
|
||||
Md5 *string `bson:"md5" json:"md5"` //MD5验证
|
||||
BackLink *string `bson:"backLink" json:"backLink"` //企业签(备用连接)
|
||||
}
|
||||
@@ -0,0 +1,190 @@
|
||||
package versionMod
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"stat/common/log"
|
||||
"stat/common/mongos"
|
||||
"time"
|
||||
|
||||
"github.com/jinzhu/copier"
|
||||
"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"
|
||||
)
|
||||
|
||||
// 初始化model
|
||||
func Init() {
|
||||
// 获取数据库表
|
||||
db = mongos.New(mongos.MgoManager, CollAppVersion)
|
||||
|
||||
// 初始化索引
|
||||
indexes := []mongo.IndexModel{
|
||||
{
|
||||
Keys: bson.D{
|
||||
{Key: "_id", Value: 1},
|
||||
{Key: "appId", Value: 1},
|
||||
},
|
||||
Options: options.Index().SetUnique(true),
|
||||
},
|
||||
{
|
||||
Keys: bson.D{
|
||||
{Key: "terminal", Value: 1},
|
||||
{Key: "appId", Value: 1},
|
||||
},
|
||||
},
|
||||
{
|
||||
Keys: bson.D{
|
||||
{Key: "appId", Value: 1},
|
||||
},
|
||||
},
|
||||
{
|
||||
Keys: bson.D{
|
||||
{Key: "status", Value: 1},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
if _, err := db.CreateIndex(context.Background(), indexes); err != nil {
|
||||
panic(fmt.Sprintf("%s model set index err ==>[%+v]", CollAppVersion, err))
|
||||
}
|
||||
}
|
||||
|
||||
// GetVersionList 查询版本信息
|
||||
func GetVersionList(ctx context.Context, appId *int32, skip, limit int64) (list VersionList, count int64, err error) {
|
||||
list = make(VersionList, 0)
|
||||
filter := bson.M{}
|
||||
if appId != nil {
|
||||
filter["appId"] = *appId
|
||||
}
|
||||
sort := bson.D{{Key: "createdAt", Value: -1}}
|
||||
|
||||
opts := options.Find().SetSkip(skip).SetLimit(limit).SetSort(sort)
|
||||
|
||||
if err = db.Find(ctx, &list, filter, opts); err != nil {
|
||||
log.Error("version GetVersionList Find err", log.E(err))
|
||||
return
|
||||
}
|
||||
|
||||
count, err = db.Count(ctx, filter)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// DelVersion 删除版本
|
||||
func DelVersion(ctx context.Context, id int64) (err error) {
|
||||
_, err = db.DeleteOne(ctx, primitive.M{"_id": id})
|
||||
return err
|
||||
}
|
||||
|
||||
// AddVersion 添加一个版本
|
||||
func AddVersion(ctx context.Context, data *VersionModel) (err error) {
|
||||
_, err = db.InsertOne(ctx, data)
|
||||
return
|
||||
}
|
||||
|
||||
// 获取版本信息
|
||||
func FindVersion(ctx context.Context, id int64) (data VersionModel, err error) {
|
||||
|
||||
err = db.FindOne(ctx, &data, bson.M{"_id": id})
|
||||
return
|
||||
}
|
||||
|
||||
// 更新版本信息
|
||||
func UpdateVersion(ctx context.Context, data *VersionModel) (err error) {
|
||||
data.UpdatedAt = time.Now()
|
||||
update := &VersionUpdate{}
|
||||
err = copier.Copy(update, data)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = db.UpdateOne(ctx, primitive.M{"_id": data.Id}, bson.M{"$set": update})
|
||||
return
|
||||
}
|
||||
|
||||
// ButtonClick 查询最新下载地址ios android
|
||||
func ButtonClick(ctx context.Context, appId int32, terminal string, packageType PkgType) (data *VersionModel, err error) {
|
||||
data = &VersionModel{}
|
||||
match := bson.M{"status": true, "appId": appId}
|
||||
if terminal == "ios" {
|
||||
match["terminal"] = terminal
|
||||
match["packageType"] = packageType
|
||||
} else {
|
||||
match["terminal"] = terminal
|
||||
}
|
||||
|
||||
opts := options.FindOne().SetSort(bson.M{
|
||||
"createdAt": -1,
|
||||
})
|
||||
|
||||
err = db.FindOne(ctx, data, match, opts)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func ButtonList(ctx context.Context, appId int32) (res VersionList, err error) {
|
||||
res = make([]*VersionModel, 0)
|
||||
opt := &options.FindOptions{}
|
||||
opt.SetSort(bson.M{"packageType": 1})
|
||||
|
||||
err = db.Find(ctx, &res, primitive.M{"status": true, "appId": appId}, opt)
|
||||
return
|
||||
}
|
||||
|
||||
func FindVersByPkgTyps(ctx context.Context, appId int32, terminal string, curVersion string, packageType PkgType) (list VersionList, err error) {
|
||||
list = make(VersionList, 0)
|
||||
conf := bson.M{
|
||||
"appId": appId,
|
||||
"status": true,
|
||||
"terminal": terminal}
|
||||
if packageType != 0 {
|
||||
conf["packageType"] = packageType
|
||||
}
|
||||
opts := options.Find().SetSort(bson.M{
|
||||
"createdAt": -1,
|
||||
})
|
||||
|
||||
err = db.Find(ctx, &list, conf, opts)
|
||||
return
|
||||
}
|
||||
|
||||
func FindIosVersion(ctx context.Context, appId int32, terminal string, curVersion string, packageType []PkgType) (list VersionList, err error) {
|
||||
list = make(VersionList, 0)
|
||||
conf := bson.M{
|
||||
"appId": appId,
|
||||
"status": true,
|
||||
"terminal": terminal}
|
||||
if len(packageType) > 0 {
|
||||
conf["packageType"] = bson.M{"$in": packageType}
|
||||
}
|
||||
opts := options.Find().SetSort(bson.M{
|
||||
"createdAt": -1,
|
||||
})
|
||||
|
||||
err = db.Find(ctx, &list, conf, opts)
|
||||
return
|
||||
}
|
||||
|
||||
// GetVersionList 查询版本信息
|
||||
func GetTfUrlList(ctx context.Context, appId int32) (list VersionModel, err error) {
|
||||
filter := bson.M{"terminal": "ios", "packageType": Tf, "status": true, "appId": appId}
|
||||
|
||||
opts := options.FindOne().SetSort(bson.M{
|
||||
"createdAt": -1,
|
||||
})
|
||||
|
||||
if err = db.FindOne(ctx, &list, filter, opts); err != nil {
|
||||
log.Error("version GetVersionList Find err", log.E(err))
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user