@@ -0,0 +1,98 @@
|
||||
package chatrobotmod
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"91porn-server/common"
|
||||
"91porn-server/common/db"
|
||||
"91porn-server/common/log"
|
||||
"91porn-server/models"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
)
|
||||
|
||||
var mdb *db.MongoDB
|
||||
|
||||
const table = models.ChatRobot
|
||||
|
||||
func coll(t *db.MongoTool) *db.MongoTool {
|
||||
if t == nil {
|
||||
return mdb.Coll(table)
|
||||
}
|
||||
return t.Coll(table)
|
||||
}
|
||||
|
||||
// initCommentIndex 设置index
|
||||
func initIndex() {
|
||||
many := []mongo.IndexModel{
|
||||
{
|
||||
Keys: bson.D{{Key: "type", Value: 1}},
|
||||
Options: options.Index().SetUnique(true),
|
||||
},
|
||||
{
|
||||
Keys: bson.D{{Key: "isActive", Value: 1}},
|
||||
},
|
||||
{
|
||||
Keys: bson.D{{Key: "updatedAt", Value: 1}},
|
||||
},
|
||||
}
|
||||
if _, err := coll(nil).CreateIndex(many); err != nil {
|
||||
panic(fmt.Sprintf("%s model set index err ==>[%+v]", table, err))
|
||||
}
|
||||
}
|
||||
|
||||
func Insert(doc ChatRobot) error {
|
||||
if _, err := coll(nil).InsertOne(doc); err != nil {
|
||||
log.Error(fmt.Sprintf("[METHOD-%s]==> Model %s %s fail error:%+v:", "Insert", table, "InsertOne", err))
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func ConfExists(rType EnumRobotType) (isExists bool, err error) {
|
||||
if isExists, err = coll(nil).Exists(bson.M{"type": rType}); err != nil {
|
||||
log.Error(fmt.Sprintf("[METHOD-%s]==> Model %s %s fail error:%+v:", "ConfExists", table, "Exists", err), log.Any("rType", rType))
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func GetRobotConfByType(rType EnumRobotType) (data ChatRobot, err error) {
|
||||
if err = coll(nil).FindOne(&data, bson.M{"type": rType}); err != nil {
|
||||
log.Error(fmt.Sprintf("[METHOD-%s]==> Model %s %s fail error:%+v:", "GetRobotConfByType", table, "FindOne", err), log.Any("rType", rType))
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func GetRobotConf(rType *EnumRobotType, skip int64, limit int64) (total int64, data []ChatRobot, err error) {
|
||||
var query = bson.M{}
|
||||
if rType != nil {
|
||||
query["type"] = *rType
|
||||
}
|
||||
var opts = options.Find()
|
||||
opts.SetSkip(skip).SetLimit(limit)
|
||||
if err = coll(nil).Find(&data, query, opts); err != nil {
|
||||
log.Error(fmt.Sprintf("[METHOD-%s]==> Model %s %s fail error:%+v:", "GetRobotConf", table, "Find", err), log.Any("rType", rType))
|
||||
return
|
||||
}
|
||||
if total, err = coll(nil).Count(query); err != nil {
|
||||
log.Error(fmt.Sprintf("[METHOD-%s]==> Model %s %s fail error:%+v:", "GetRobotConf", table, "Count", err), log.Any("rType", rType))
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func UpdateCmtRobotConf(rType EnumRobotType, doc CmtUpdateDoc) (err error) {
|
||||
var update, _ = common.ToBsonM(doc)
|
||||
if _, err = coll(nil).UpdateOne(bson.M{"type": rType}, bson.M{"$set": update}); err != nil {
|
||||
log.Error(fmt.Sprintf("[METHOD-%s]==> Model %s %s fail error:%+v:", "UpdateCmtRobotConf", table, "UpdateOne", err),
|
||||
log.Any("rType", rType),
|
||||
log.Any("update", update),
|
||||
)
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package chatrobotmod
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"91porn-server/common/db"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
)
|
||||
|
||||
type (
|
||||
ObjectID = primitive.ObjectID
|
||||
EnumRobotType = string // 机器人类型枚举
|
||||
)
|
||||
|
||||
const (
|
||||
Comment EnumRobotType = "COMMENT" // 评论机器人
|
||||
Film EnumRobotType = "FILM" // 影院机器人
|
||||
)
|
||||
|
||||
func Init() {
|
||||
mdb = db.Init(table)
|
||||
initIndex()
|
||||
}
|
||||
|
||||
type ChatRobot struct {
|
||||
ID ObjectID `bson:"_id,omitempty"`
|
||||
Type EnumRobotType `bson:"type"` // 机器人类型
|
||||
IsActive bool `bson:"isActive"` // 是否开启
|
||||
CreatedAt time.Time `bson:"createdAt"` // 创建时间
|
||||
UpdatedAt time.Time `bson:"updatedAt"` // 更新时间
|
||||
CommentRobot `bson:",inline"` // 评论机器人配置
|
||||
}
|
||||
|
||||
// 评论机器人配置
|
||||
type CommentRobot struct {
|
||||
From string `bson:"from,omitempty"` // 每天的起始时间 HH:MM:SS
|
||||
To string `bson:"to,omitempty"` // 每天的结束时间 HH:MM:SS
|
||||
TotalLimit int `bson:"totalLimit,omitempty"` // 机器人每天总评论数
|
||||
PureLimit int `bson:"pureLimit,omitempty"` // 单个机器人每天评论数
|
||||
Frequency int `bson:"frequency"` // 发表评论频率 单位:秒/条
|
||||
MaxCommentNum int `bson:"maxCommentNum"` // 视频评论最小数
|
||||
MaxFakeLikes int `bson:"maxFakeLikes"` // 视频点赞数最大值
|
||||
MinFakeLikes int `bson:"minFakeLikes"` // 视频点赞数最小值
|
||||
MaxFakePlayCount int `bson:"maxFakePlayCount"` // 视频播放量最大值
|
||||
MinFakePlayCount int `bson:"minFakePlayCount"` // 视频播放量最小值
|
||||
}
|
||||
|
||||
// 评论机器人配置更新
|
||||
type CmtUpdateDoc struct {
|
||||
From *string `bson:"from,omitempty"`
|
||||
To *string `bson:"to,omitempty"`
|
||||
TotalLimit *int `bson:"totalLimit,omitempty"`
|
||||
PureLimit *int `bson:"pureLimit,omitempty"`
|
||||
IsActive *bool `bson:"isActive,omitempty"`
|
||||
Frequency *int `bson:"frequency"`
|
||||
UpdatedAt time.Time `bson:"updatedAt"`
|
||||
MaxCommentNum *int `bson:"maxCommentNum"`
|
||||
MaxFakeLikes *int `bson:"maxFakeLikes"` // 视频点赞数最大值
|
||||
MinFakeLikes *int `bson:"minFakeLikes"` // 视频点赞数最小值
|
||||
MaxFakePlayCount *int `bson:"maxFakePlayCount"` // 视频播放量最大值
|
||||
MinFakePlayCount *int `bson:"minFakePlayCount"` // 视频播放量最小值
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
package chatrobotmod
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"91porn-server/models/commod"
|
||||
)
|
||||
|
||||
type ReqConfList struct {
|
||||
Type *string `form:"type" json:"type"`
|
||||
commod.Page
|
||||
}
|
||||
|
||||
type RespList struct {
|
||||
ID ObjectID `json:"id"`
|
||||
Type EnumRobotType `json:"type"` // 机器人类型
|
||||
IsActive bool `json:"isActive"` // 是否开启
|
||||
CreatedAt time.Time `json:"createdAt"` // 创建时间
|
||||
UpdatedAt time.Time `json:"updatedAt"` // 更新时间
|
||||
CommentRobotResp `json:",inline"`
|
||||
}
|
||||
|
||||
type CommentRobotResp struct {
|
||||
From string `json:"from"` // 每天的起始时间 HH:MM:SS
|
||||
To string `json:"to"` // 每天的结束时间 HH:MM:SS
|
||||
TotalLimit int `json:"totalLimit"` // 机器人每天总评论数
|
||||
PureLimit int `json:"pureLimit"` // 单个机器人每天评论数
|
||||
Frequency int `json:"frequency"` // 发表评论频率 单位:秒/条
|
||||
MaxCommentNum int `json:"maxCommentNum"` // 参与评论视频的最大评论数
|
||||
MaxFakeLikes int `json:"maxFakeLikes"` // 视频点赞数最大值
|
||||
MinFakeLikes int `json:"minFakeLikes"` // 视频点赞数最小值
|
||||
MaxFakePlayCount int `json:"maxFakePlayCount"` // 视频播放量最大值
|
||||
MinFakePlayCount int `json:"minFakePlayCount"` // 视频播放量最小值
|
||||
}
|
||||
|
||||
type ReqUpdate struct {
|
||||
Type EnumRobotType `json:"type" binding:"required"`
|
||||
ReqUpdateCmt // 评论机器人配置更新请求参数
|
||||
}
|
||||
|
||||
// 评论机器人配置更新请求参数
|
||||
type ReqUpdateCmt struct {
|
||||
From *string `json:"from"`
|
||||
To *string `json:"to"`
|
||||
TotalLimit *int `json:"totalLimit"`
|
||||
PureLimit *int `json:"pureLimit"`
|
||||
Frequency *int `json:"frequency"`
|
||||
IsActive *bool `json:"isActive"`
|
||||
MaxCommentNum *int `json:"maxCommentNum"`
|
||||
MaxFakeLikes *int `json:"maxFakeLikes"` // 视频点赞数最大值
|
||||
MinFakeLikes *int `json:"minFakeLikes"` // 视频点赞数最小值
|
||||
MaxFakePlayCount *int `json:"maxFakePlayCount"` // 视频播放量最大值
|
||||
MinFakePlayCount *int `json:"minFakePlayCount"` // 视频播放量最小值
|
||||
}
|
||||
|
||||
// 添加配置
|
||||
type ReqAdd struct {
|
||||
Type EnumRobotType `json:"type" binding:"required"`
|
||||
ReqAddCmt
|
||||
}
|
||||
|
||||
type ReqAddCmt struct {
|
||||
From string `json:"from"`
|
||||
To string `json:"to"`
|
||||
TotalLimit int `json:"totalLimit"`
|
||||
PureLimit int `json:"pureLimit"`
|
||||
Frequency int `json:"frequency"`
|
||||
IsActive bool `json:"isActive"`
|
||||
MaxCommentNum int `json:"maxCommentNum"`
|
||||
MaxFakeLikes int `json:"maxFakeLikes"` // 视频点赞数最大值
|
||||
MinFakeLikes int `json:"minFakeLikes"` // 视频点赞数最小值
|
||||
MaxFakePlayCount int `json:"maxFakePlayCount"` // 视频播放量最大值
|
||||
MinFakePlayCount int `json:"minFakePlayCount"` // 视频播放量最小值
|
||||
}
|
||||
Reference in New Issue
Block a user