@@ -0,0 +1,93 @@
|
||||
package feedbackmod
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"videoweb/pub/common/log"
|
||||
"videoweb/pub/common/srvdef"
|
||||
"videoweb/pub/mongos"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
)
|
||||
|
||||
var coll *mongos.Collection
|
||||
|
||||
// Init 初始化 feedback 集合和常用查询索引
|
||||
func Init(ctx context.Context) {
|
||||
coll = mongos.Shop.Coll(TN.Feedback)
|
||||
initIndex(ctx)
|
||||
}
|
||||
|
||||
func initIndex(ctx context.Context) {
|
||||
indexes := []mongo.IndexModel{
|
||||
{
|
||||
Keys: bson.D{
|
||||
{Key: FN.Feedback.UserId, Value: 1},
|
||||
{Key: FN.Feedback.CreatedAt, Value: -1},
|
||||
{Key: FN.Feedback.Id, Value: -1},
|
||||
},
|
||||
},
|
||||
{
|
||||
Keys: bson.D{
|
||||
{Key: FN.Feedback.Status, Value: 1},
|
||||
{Key: FN.Feedback.CreatedAt, Value: -1},
|
||||
{Key: FN.Feedback.Id, Value: -1},
|
||||
},
|
||||
},
|
||||
{
|
||||
Keys: bson.D{
|
||||
{Key: FN.Feedback.CreatedAt, Value: -1},
|
||||
{Key: FN.Feedback.Id, Value: -1},
|
||||
},
|
||||
},
|
||||
}
|
||||
if _, err := coll.CreateIndex(ctx, indexes); err != nil {
|
||||
panic(fmt.Sprintf("(feedbackmod:initIndex) Create Index failed! err:%+v:", err))
|
||||
}
|
||||
}
|
||||
|
||||
// InsertOneFeedback 插入一条用户意见反馈数据
|
||||
//
|
||||
// 当 doc.Id 为空时,会使用 mongos.Lid.Feedback 自动生成自增ID
|
||||
func InsertOneFeedback(ctx context.Context, doc *Feedback) *srvdef.SrvErr {
|
||||
if doc.Id == 0 {
|
||||
doc.Id = mongos.Lid.Feedback.Get()
|
||||
}
|
||||
if _, err := coll.InsertOne(ctx, doc); err != nil {
|
||||
log.Warn("用户意见反馈写入失败", log.Any("doc", doc), log.E(err))
|
||||
return srvdef.New(srvdef.ErrDbInsertError, "", "")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// FindManyFeedback 按条件查询多条用户意见反馈数据
|
||||
func FindManyFeedback(ctx context.Context, filter bson.M, opts ...*options.FindOptions) (FeedbackList, *srvdef.SrvErr) {
|
||||
var data FeedbackList
|
||||
if err := coll.Find(ctx, &data, filter, opts...); err != nil {
|
||||
log.Warn("用户意见反馈列表查询失败", log.E(err), log.Any("filter", filter))
|
||||
return nil, srvdef.New(srvdef.ErrDbQueryError, "", "")
|
||||
}
|
||||
return data, nil
|
||||
}
|
||||
|
||||
// CountFeedback 统计满足条件的用户意见反馈数量
|
||||
func CountFeedback(ctx context.Context, filter bson.M, opts ...*options.CountOptions) (int64, *srvdef.SrvErr) {
|
||||
count, err := coll.Count(ctx, filter, opts...)
|
||||
if err != nil {
|
||||
log.Warn("用户意见反馈数量统计失败", log.E(err), log.Any("filter", filter))
|
||||
return 0, srvdef.New(srvdef.ErrDbQueryError, "", "")
|
||||
}
|
||||
return count, nil
|
||||
}
|
||||
|
||||
// UpdateManyFeedbackWithResult 批量更新用户意见反馈数据,并返回命中数量和修改数量
|
||||
func UpdateManyFeedbackWithResult(ctx context.Context, filter bson.M, update bson.M) (matchedCount int64, modifiedCount int64, serr *srvdef.SrvErr) {
|
||||
result, err := coll.UpdateMany(ctx, filter, update)
|
||||
if err != nil {
|
||||
log.Warn("用户意见反馈批量更新失败", log.E(err), log.Any("filter", filter))
|
||||
return 0, 0, srvdef.New(srvdef.ErrDbUpdateError, "", "")
|
||||
}
|
||||
return result.MatchedCount, result.ModifiedCount, nil
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package feedbackmod
|
||||
|
||||
// TagFeedback 保存feedback集合字段名
|
||||
type TagFeedback struct {
|
||||
Id string
|
||||
UserId string
|
||||
FeedbackType string
|
||||
Content string
|
||||
Screenshots string
|
||||
Contact string
|
||||
Status string
|
||||
Remark string
|
||||
CreatedAt string
|
||||
UpdatedAt string
|
||||
}
|
||||
|
||||
var FN struct {
|
||||
Feedback TagFeedback
|
||||
}
|
||||
|
||||
var TN struct {
|
||||
Feedback string
|
||||
}
|
||||
|
||||
func init() {
|
||||
FN.Feedback.Id = "_id"
|
||||
FN.Feedback.UserId = "userId"
|
||||
FN.Feedback.FeedbackType = "feedbackType"
|
||||
FN.Feedback.Content = "content"
|
||||
FN.Feedback.Screenshots = "screenshots"
|
||||
FN.Feedback.Contact = "contact"
|
||||
FN.Feedback.Status = "status"
|
||||
FN.Feedback.Remark = "remark"
|
||||
FN.Feedback.CreatedAt = "createdAt"
|
||||
FN.Feedback.UpdatedAt = "updatedAt"
|
||||
|
||||
TN.Feedback = "feedback"
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package feedbackmod
|
||||
|
||||
import "time"
|
||||
|
||||
// Feedback @table: feedback
|
||||
//
|
||||
// Feedback 用户意见反馈集合模型
|
||||
type Feedback struct {
|
||||
// ID
|
||||
Id int64 `json:"id" bson:"_id,omitempty"`
|
||||
// 用户ID
|
||||
UserId int64 `json:"userId" bson:"userId"`
|
||||
// 问题类型,1-功能建议、2-播放问题、3-账号问题、4-其他
|
||||
FeedbackType int32 `json:"feedbackType" bson:"feedbackType"`
|
||||
// 描述内容
|
||||
Content string `json:"content" bson:"content"`
|
||||
// 问题截图,可存放多张图片地址
|
||||
Screenshots []string `json:"screenshots" bson:"screenshots"`
|
||||
// 联系方式,可为空
|
||||
Contact string `json:"contact" bson:"contact,omitempty"`
|
||||
// 处理状态,0-待处理、1-已处理
|
||||
Status int32 `json:"status" bson:"status"`
|
||||
// 处理备注
|
||||
Remark string `json:"remark" bson:"remark,omitempty"`
|
||||
// 创建时间
|
||||
CreatedAt time.Time `json:"createdAt" bson:"createdAt"`
|
||||
// 更新时间
|
||||
UpdatedAt time.Time `json:"updatedAt" bson:"updatedAt"`
|
||||
}
|
||||
|
||||
// FeedbackList 用户意见反馈列表
|
||||
type FeedbackList []*Feedback
|
||||
Reference in New Issue
Block a user