Initial commit: web_hghl_server
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,88 @@
|
||||
package questionnairemod
|
||||
|
||||
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 db *mongos.Collection
|
||||
|
||||
func Init(ctx context.Context) {
|
||||
db = mongos.Shop.Coll(TN.Questionnaire)
|
||||
indexes := []mongo.IndexModel{
|
||||
{
|
||||
Keys: bson.D{
|
||||
{Key: FN.Questionnaire.Status, Value: 1},
|
||||
{Key: FN.Questionnaire.CreatedAt, Value: -1},
|
||||
},
|
||||
},
|
||||
{
|
||||
Keys: bson.D{
|
||||
{Key: FN.Questionnaire.CreatedAt, Value: -1},
|
||||
},
|
||||
},
|
||||
}
|
||||
if _, err := db.CreateIndex(ctx, indexes); err != nil {
|
||||
panic(fmt.Sprintf("(questionnaire:Init) Create Index failed! err:%+v", err))
|
||||
}
|
||||
}
|
||||
|
||||
// InsertOne 插入一条问卷
|
||||
func InsertOne(ctx context.Context, doc *QuestionnaireModel) *srvdef.SrvErr {
|
||||
if _, err := db.InsertOne(ctx, doc); err != nil {
|
||||
log.Warn("questionnairemod:InsertOne failed", log.E(err))
|
||||
return srvdef.New(srvdef.ErrDbInsertError, "", "")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// FindOne 查找一条问卷
|
||||
func FindOne(ctx context.Context, filter bson.M, opts ...*options.FindOneOptions) (*QuestionnaireModel, *srvdef.SrvErr) {
|
||||
var doc QuestionnaireModel
|
||||
if err := db.FindOneEx(ctx, &doc, filter, opts...); err != nil {
|
||||
if err == mongo.ErrNoDocuments {
|
||||
return nil, srvdef.New(srvdef.ErrNoData, "", "")
|
||||
}
|
||||
log.Warn("questionnairemod:FindOne failed", log.E(err), log.Any("filter", filter))
|
||||
return nil, srvdef.New(srvdef.ErrDbQueryError, "", "")
|
||||
}
|
||||
return &doc, nil
|
||||
}
|
||||
|
||||
// FindMany 查找多条问卷
|
||||
func FindMany(ctx context.Context, filter bson.M, opts ...*options.FindOptions) (QuestionnaireModelList, *srvdef.SrvErr) {
|
||||
data := make(QuestionnaireModelList, 0)
|
||||
if err := db.Find(ctx, &data, filter, opts...); err != nil {
|
||||
log.Warn("questionnairemod:FindMany failed", log.E(err), log.Any("filter", filter))
|
||||
return nil, srvdef.New(srvdef.ErrDbQueryError, "", "")
|
||||
}
|
||||
return data, nil
|
||||
}
|
||||
|
||||
// Count 统计问卷数量
|
||||
func Count(ctx context.Context, filter bson.M) (int64, *srvdef.SrvErr) {
|
||||
count, err := db.Count(ctx, filter)
|
||||
if err != nil {
|
||||
log.Warn("questionnairemod:Count failed", log.E(err), log.Any("filter", filter))
|
||||
return 0, srvdef.New(srvdef.ErrDbQueryError, "", "")
|
||||
}
|
||||
return count, nil
|
||||
}
|
||||
|
||||
// UpdateOne 更新一条问卷,返回 MatchedCount
|
||||
func UpdateOne(ctx context.Context, filter bson.M, update bson.M) (int64, *srvdef.SrvErr) {
|
||||
result, err := db.UpdateOne(ctx, filter, update)
|
||||
if err != nil {
|
||||
log.Warn("questionnairemod:UpdateOne failed", log.E(err), log.Any("filter", filter))
|
||||
return 0, srvdef.New(srvdef.ErrDbUpdateError, "", "")
|
||||
}
|
||||
return result.MatchedCount, nil
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
package questionnairemod
|
||||
|
||||
// 问卷状态枚举
|
||||
const (
|
||||
StatusPending = "pending" //待处理
|
||||
StatusHandled = "processed" //已处理
|
||||
StatusRejected = "reject" //拒绝
|
||||
)
|
||||
|
||||
// 附件类型枚举
|
||||
const (
|
||||
AttachTypeImage = "图片"
|
||||
AttachTypeVideo = "视频"
|
||||
)
|
||||
|
||||
type TagQuestionnaire struct {
|
||||
Id string
|
||||
UserId string
|
||||
QuestionType string
|
||||
Frequency string
|
||||
Province string
|
||||
City string
|
||||
Operator string
|
||||
NetworkType string
|
||||
DeviceType string
|
||||
DeviceModel string
|
||||
Description string
|
||||
Contact string
|
||||
Status string
|
||||
Remark string
|
||||
Attachments string
|
||||
CreatedAt string
|
||||
UpdatedAt string
|
||||
}
|
||||
|
||||
var FN struct {
|
||||
Questionnaire TagQuestionnaire
|
||||
}
|
||||
|
||||
var TN struct {
|
||||
Questionnaire string
|
||||
}
|
||||
|
||||
func init() {
|
||||
FN.Questionnaire.Id = "_id"
|
||||
FN.Questionnaire.UserId = "userId"
|
||||
FN.Questionnaire.QuestionType = "questionType"
|
||||
FN.Questionnaire.Frequency = "frequency"
|
||||
FN.Questionnaire.Province = "province"
|
||||
FN.Questionnaire.City = "city"
|
||||
FN.Questionnaire.Operator = "operator"
|
||||
FN.Questionnaire.NetworkType = "networkType"
|
||||
FN.Questionnaire.DeviceType = "deviceType"
|
||||
FN.Questionnaire.DeviceModel = "deviceModel"
|
||||
FN.Questionnaire.Description = "description"
|
||||
FN.Questionnaire.Contact = "contact"
|
||||
FN.Questionnaire.Status = "status"
|
||||
FN.Questionnaire.Remark = "remark"
|
||||
FN.Questionnaire.Attachments = "attachments"
|
||||
FN.Questionnaire.CreatedAt = "createdAt"
|
||||
FN.Questionnaire.UpdatedAt = "updatedAt"
|
||||
|
||||
TN.Questionnaire = "questionnaires"
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package questionnairemod
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
)
|
||||
|
||||
// Attachment 内嵌附件文档
|
||||
type Attachment struct {
|
||||
FileType string `json:"fileType" bson:"fileType"` // 附件类型(img / video)
|
||||
Url string `json:"url" bson:"url"` // 附件URL地址
|
||||
}
|
||||
|
||||
// QuestionnaireModel 问卷调查主文档
|
||||
// @table: questionnaires
|
||||
type QuestionnaireModel struct {
|
||||
Id primitive.ObjectID `json:"id" bson:"_id,omitempty"` // 唯一标识(MongoDB自动生成)
|
||||
UserId int64 `json:"userId" bson:"userId"` // App端登录用户ID,0表示匿名
|
||||
QuestionType string `json:"questionType" bson:"questionType"` // 问题类型:播放卡顿/缓冲、无法播放、画质模糊、音画不同步、加载失败、闪退/崩溃、登录异常、其他问题
|
||||
Frequency string `json:"frequency" bson:"frequency"` // 出现频率:每次都会、经常出现、偶尔出现、仅现一次
|
||||
Province string `json:"province" bson:"province"` // 所在省份(必填)
|
||||
City string `json:"city" bson:"city"` // 所在城市(选填)
|
||||
Operator string `json:"operator" bson:"operator"` // 运营商:电信、联通、移动、广电
|
||||
NetworkType string `json:"networkType" bson:"networkType"` // 网络类型:WI-FI、5G、4G、其他
|
||||
DeviceType string `json:"deviceType" bson:"deviceType"` // 设备类型:iPhone、Android、iPad、其他
|
||||
DeviceModel string `json:"deviceModel" bson:"deviceModel"` // 设备型号(选填)
|
||||
Description string `json:"description" bson:"description"` // 问题描述(必填)
|
||||
Contact string `json:"contact" bson:"contact"` // 联系方式(选填)
|
||||
Status string `json:"status" bson:"status"` // 处理状态:待处理、已处理、拒绝
|
||||
Remark string `json:"remark" bson:"remark"` // 备注,处理问卷时填写(选填)
|
||||
Attachments []Attachment `json:"attachments" bson:"attachments"` // 附件列表,最多3个
|
||||
CreatedAt time.Time `json:"createdAt" bson:"createdAt"` // 创建时间(自动生成)
|
||||
UpdatedAt time.Time `json:"updatedAt" bson:"updatedAt"` // 更新时间(自动更新)
|
||||
}
|
||||
|
||||
type QuestionnaireModelList []*QuestionnaireModel
|
||||
Reference in New Issue
Block a user