init: web_hgdjc_server
This commit is contained in:
@@ -0,0 +1,100 @@
|
||||
package contactusmod
|
||||
|
||||
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 初始化 contactus 集合和常用查询索引
|
||||
func Init(ctx context.Context) {
|
||||
coll = mongos.Shop.Coll(TN.ContactUs)
|
||||
initIndex(ctx)
|
||||
}
|
||||
|
||||
func initIndex(ctx context.Context) {
|
||||
indexes := []mongo.IndexModel{
|
||||
{
|
||||
Keys: bson.D{
|
||||
{Key: FN.ContactUs.UserId, Value: 1},
|
||||
{Key: FN.ContactUs.CreatedAt, Value: -1},
|
||||
{Key: FN.ContactUs.Id, Value: -1},
|
||||
},
|
||||
},
|
||||
{
|
||||
Keys: bson.D{
|
||||
{Key: FN.ContactUs.Status, Value: 1},
|
||||
{Key: FN.ContactUs.CreatedAt, Value: -1},
|
||||
{Key: FN.ContactUs.Id, Value: -1},
|
||||
},
|
||||
},
|
||||
{
|
||||
Keys: bson.D{
|
||||
{Key: FN.ContactUs.QuestionType, Value: 1},
|
||||
{Key: FN.ContactUs.CreatedAt, Value: -1},
|
||||
{Key: FN.ContactUs.Id, Value: -1},
|
||||
},
|
||||
},
|
||||
{
|
||||
Keys: bson.D{
|
||||
{Key: FN.ContactUs.CreatedAt, Value: -1},
|
||||
{Key: FN.ContactUs.Id, Value: -1},
|
||||
},
|
||||
},
|
||||
}
|
||||
if _, err := coll.CreateIndex(ctx, indexes); err != nil {
|
||||
panic(fmt.Sprintf("(contactusmod:initIndex) Create Index failed! err:%+v:", err))
|
||||
}
|
||||
}
|
||||
|
||||
// InsertOneContactUs 插入一条联系我们数据
|
||||
//
|
||||
// 当 doc.Id 为空时,会使用 mongos.Lid.ContactUs 自动生成自增ID
|
||||
func InsertOneContactUs(ctx context.Context, doc *ContactUs) *srvdef.SrvErr {
|
||||
if doc.Id == 0 {
|
||||
doc.Id = mongos.Lid.ContactUs.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
|
||||
}
|
||||
|
||||
// FindManyContactUs 按条件查询多条联系我们数据
|
||||
func FindManyContactUs(ctx context.Context, filter bson.M, opts ...*options.FindOptions) (ContactUsList, *srvdef.SrvErr) {
|
||||
var data ContactUsList
|
||||
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
|
||||
}
|
||||
|
||||
// CountContactUs 统计满足条件的联系我们数量
|
||||
func CountContactUs(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
|
||||
}
|
||||
|
||||
// UpdateManyContactUsWithResult 批量更新联系我们数据,并返回命中数量和修改数量
|
||||
func UpdateManyContactUsWithResult(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,40 @@
|
||||
package contactusmod
|
||||
|
||||
// TagContactUs 保存contactus集合字段名
|
||||
type TagContactUs struct {
|
||||
Id string
|
||||
UserId string
|
||||
Email string
|
||||
QuestionType string
|
||||
Title string
|
||||
Content string
|
||||
Attachments string
|
||||
Status string
|
||||
Remark string
|
||||
CreatedAt string
|
||||
UpdatedAt string
|
||||
}
|
||||
|
||||
var FN struct {
|
||||
ContactUs TagContactUs
|
||||
}
|
||||
|
||||
var TN struct {
|
||||
ContactUs string
|
||||
}
|
||||
|
||||
func init() {
|
||||
FN.ContactUs.Id = "_id"
|
||||
FN.ContactUs.UserId = "userId"
|
||||
FN.ContactUs.Email = "email"
|
||||
FN.ContactUs.QuestionType = "questionType"
|
||||
FN.ContactUs.Title = "title"
|
||||
FN.ContactUs.Content = "content"
|
||||
FN.ContactUs.Attachments = "attachments"
|
||||
FN.ContactUs.Status = "status"
|
||||
FN.ContactUs.Remark = "remark"
|
||||
FN.ContactUs.CreatedAt = "createdAt"
|
||||
FN.ContactUs.UpdatedAt = "updatedAt"
|
||||
|
||||
TN.ContactUs = "contactus"
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package contactusmod
|
||||
|
||||
import "time"
|
||||
|
||||
// ContactUs @table: contactus
|
||||
//
|
||||
// ContactUs 联系我们集合模型
|
||||
type ContactUs struct {
|
||||
// ID
|
||||
Id int64 `json:"id" bson:"_id,omitempty"`
|
||||
// 用户ID
|
||||
UserId int64 `json:"userId" bson:"userId"`
|
||||
// 邮箱
|
||||
Email string `json:"email" bson:"email"`
|
||||
// 问题类型,1-订单问题、2-账号问题、3-功能问题、4-体验问题、5-其他
|
||||
QuestionType int32 `json:"questionType" bson:"questionType"`
|
||||
// 标题
|
||||
Title string `json:"title" bson:"title"`
|
||||
// 内容
|
||||
Content string `json:"content" bson:"content"`
|
||||
// 附件地址,可存放多张图片或文件地址
|
||||
Attachments []string `json:"attachments" bson:"attachments"`
|
||||
// 处理状态,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"`
|
||||
}
|
||||
|
||||
// ContactUsList 联系我们列表
|
||||
type ContactUsList []*ContactUs
|
||||
Reference in New Issue
Block a user