service/vendor/app/mix/dao/mongo_idseq.go

294 lines
8.9 KiB
Go
Raw Normal View History

2023-12-21 22:17:40 +08:00
package dao
import (
"service/dbstruct"
"service/library/logger"
"github.com/gin-gonic/gin"
"github.com/qiniu/qmgo"
)
const (
DBUserIdSeq = "user_id_seq"
COLUserIdSeq = "user_id_seq"
COLUserIdMap = "user_id_map"
DBAccountIdSeq = "account_id_seq"
COLAccountIdSeq = "account_id_seq"
DBMomentIdSeq = "moment_id_seq"
COLMomentIdSeq = "moment_id_seq"
DBStreamerAuthApprovalIdSeq = "streamer_auth_approval_id_seq"
COLStreamerAuthApprovalIdSeq = "streamer_auth_approval_id_seq"
DBAccountRelationIdSeq = "account_relation_id_seq"
COLAccountRelationIdSeq = "account_relation_id_seq"
DBMediaIdSeq = "media_id_seq"
COLMediaIdSeq = "media_id_seq"
DBStreamerLinkIdSeq = "streamer_link_id_seq"
COLStreamerLinkIdSeq = "streamer_link_id_seq"
DBUserWxAddCheckIdSeq = "user_wx_add_check_id_seq"
COLUserWxAddCheckIdSeq = "user_wx_add_check_id_seq"
DBRealNameAuthenticationIdSeq = "realname_authentication_id_seq"
COLRealNameAuthenticationIdSeq = "realname_authentication_id_seq"
DBContactCustomerServiceIdSeq = "contact_customer_service_id_seq"
COLContactCustomerServiceIdSeq = "contact_customer_service_id_seq"
)
// UserIdSeq序列表
func (m *Mongo) getColUserIdSeq() *qmgo.Collection {
return m.clientMix.Database(DBUserIdSeq).Collection(COLUserIdSeq)
}
// UserIdMap映射表
func (m *Mongo) getColUserIdMap() *qmgo.Collection {
return m.clientMix.Database(DBUserIdSeq).Collection(COLUserIdMap)
}
// AccountIdSeq序列表
func (m *Mongo) getColAccountIdSeq() *qmgo.Collection {
return m.clientMix.Database(DBAccountIdSeq).Collection(COLAccountIdSeq)
}
// MomentIdSeq序列表
func (m *Mongo) getColMomentIdSeq() *qmgo.Collection {
return m.clientMix.Database(DBMomentIdSeq).Collection(COLMomentIdSeq)
}
// StreamerAuthApprovalIdSeq序列表
func (m *Mongo) getColStreamerAuthApprovalIdSeq() *qmgo.Collection {
return m.clientMix.Database(DBStreamerAuthApprovalIdSeq).Collection(COLStreamerAuthApprovalIdSeq)
}
// AccountRelationIdSeq序列表
func (m *Mongo) getAccountRelationIdSeq() *qmgo.Collection {
return m.clientMix.Database(DBAccountRelationIdSeq).Collection(COLAccountRelationIdSeq)
}
// StreamerLinkIdSeq序列表
func (m *Mongo) getStreamerLinkIdSeq() *qmgo.Collection {
return m.clientMix.Database(DBStreamerLinkIdSeq).Collection(COLStreamerLinkIdSeq)
}
// UserWxAddCheckIdSeq序列表
func (m *Mongo) getUserWxAddCheckIdSeq() *qmgo.Collection {
return m.clientMix.Database(DBUserWxAddCheckIdSeq).Collection(COLUserWxAddCheckIdSeq)
}
// RealNameAuthenticationIdSeq序列表
func (m *Mongo) getColRealNameAuthenticationIdSeq() *qmgo.Collection {
return m.clientMix.Database(DBRealNameAuthenticationIdSeq).Collection(COLRealNameAuthenticationIdSeq)
}
// ContactCustomerServiceIdSeq序列表
func (m *Mongo) getColContactCustomerServiceIdSeq() *qmgo.Collection {
return m.clientMix.Database(DBContactCustomerServiceIdSeq).Collection(COLContactCustomerServiceIdSeq)
}
// account_id发号器
func (m *Mongo) GetAndUpdateAccountIdSeq(ctx *gin.Context) (accountIdSeq *dbstruct.AccountIdSeq, err error) {
col := m.getColAccountIdSeq()
change := qmgo.Change{
Update: qmgo.M{"$inc": qmgo.M{"seq": 1}},
Upsert: true,
ReturnNew: false,
}
accountIdSeqInstance := dbstruct.AccountIdSeq{}
if err = col.Find(ctx, qmgo.M{"_id": "account_id_seq_id"}).Apply(change, &accountIdSeqInstance); err != nil {
logger.Error("change error : %v", err)
return
}
return &accountIdSeqInstance, err
}
// user_id发号器
func (m *Mongo) GetAndUpdateUserIdSeq(ctx *gin.Context) (userIdSeq *dbstruct.UserIdSeq, err error) {
col := m.getColUserIdSeq()
change := qmgo.Change{
Update: qmgo.M{"$inc": qmgo.M{"seq": 1}},
Upsert: true,
ReturnNew: false,
}
userIdSeqInstance := dbstruct.UserIdSeq{}
if err = col.Find(ctx, qmgo.M{"_id": "user_id_seq_id"}).Apply(change, &userIdSeqInstance); err != nil {
logger.Error("change error : %v", err)
return
}
return &userIdSeqInstance, err
}
// user_id映射
func (m *Mongo) GetMappedUserId(ctx *gin.Context, userIdSeq int64) (*dbstruct.UserIdMap, error) {
userIdMap := &dbstruct.UserIdMap{}
col := m.getColUserIdMap()
query := qmgo.M{
"_id": userIdSeq,
}
err := col.Find(ctx, query).One(&userIdMap)
return userIdMap, err
}
// moment_id发号器
func (m *Mongo) GetAndUpdateMomentIdSeq(ctx *gin.Context) (momentIdSeq *dbstruct.MomentIdSeq, err error) {
col := m.getColMomentIdSeq()
change := qmgo.Change{
Update: qmgo.M{"$inc": qmgo.M{"seq": 1}},
Upsert: true,
ReturnNew: false,
}
momentIdSeqInstance := dbstruct.MomentIdSeq{}
if err = col.Find(ctx, qmgo.M{"_id": "moment_id_seq_id"}).Apply(change, &momentIdSeqInstance); err != nil {
logger.Error("change error : %v", err)
return
}
return &momentIdSeqInstance, err
}
// streamer_auth_approval_id发号器
func (m *Mongo) GetAndUpdateStreamerAuthApprovalIdSeq(ctx *gin.Context) (streamer_auth_approvalIdSeq *dbstruct.StreamerAuthApprovalIdSeq, err error) {
col := m.getColStreamerAuthApprovalIdSeq()
change := qmgo.Change{
Update: qmgo.M{"$inc": qmgo.M{"seq": 1}},
Upsert: true,
ReturnNew: false,
}
streamerAuthApprovalIdSeqInstance := dbstruct.StreamerAuthApprovalIdSeq{}
if err = col.Find(ctx, qmgo.M{"_id": "streamer_auth_approval_id_seq_id"}).Apply(change, &streamerAuthApprovalIdSeqInstance); err != nil {
logger.Error("change error : %v", err)
return
}
return &streamerAuthApprovalIdSeqInstance, err
}
// account_relation_id发号器
func (m *Mongo) GetAndUpdateAccountRelationIdSeq(ctx *gin.Context) (accountRelationIdSeq *dbstruct.AccountRelationIdSeq, err error) {
col := m.getAccountRelationIdSeq()
change := qmgo.Change{
Update: qmgo.M{"$inc": qmgo.M{"seq": 1}},
Upsert: true,
ReturnNew: false,
}
accountRelationIdSeqInstance := dbstruct.AccountRelationIdSeq{}
if err = col.Find(ctx, qmgo.M{"_id": "account_relation_id_seq_id"}).Apply(change, &accountRelationIdSeqInstance); err != nil {
logger.Error("change error : %v", err)
return
}
return &accountRelationIdSeqInstance, err
}
// streamer_link_id发号器
func (m *Mongo) GetAndUpdateStreamerLinkIdSeq(ctx *gin.Context) (streamerLinkIdSeq *dbstruct.StreamerLinkIdSeq, err error) {
col := m.getStreamerLinkIdSeq()
change := qmgo.Change{
Update: qmgo.M{"$inc": qmgo.M{"seq": 1}},
Upsert: true,
ReturnNew: false,
}
streamerLinkIdSeqInstance := dbstruct.StreamerLinkIdSeq{}
if err = col.Find(ctx, qmgo.M{"_id": "streamer_link_id_seq_id"}).Apply(change, &streamerLinkIdSeqInstance); err != nil {
logger.Error("change error : %v", err)
return
}
return &streamerLinkIdSeqInstance, err
}
// user_wx_add_check_id发号器
func (m *Mongo) GetAndUpdateUserWxAddCheckIdSeq(ctx *gin.Context) (userWxAddCheckIdSeq *dbstruct.UserWxAddCheckIdSeq, err error) {
col := m.getUserWxAddCheckIdSeq()
change := qmgo.Change{
Update: qmgo.M{"$inc": qmgo.M{"seq": 1}},
Upsert: true,
ReturnNew: false,
}
userWxAddCheckIdSeqInstance := dbstruct.UserWxAddCheckIdSeq{}
if err = col.Find(ctx, qmgo.M{"_id": "user_wx_add_check_id_seq_id"}).Apply(change, &userWxAddCheckIdSeqInstance); err != nil {
logger.Error("change error : %v", err)
return
}
return &userWxAddCheckIdSeqInstance, err
}
// realname_authentication_id发号器
func (m *Mongo) GetAndUpdateRealNameAuthenticationIdSeq(ctx *gin.Context) (realname_authenticationIdSeq *dbstruct.RealNameAuthenticationIdSeq, err error) {
col := m.getColRealNameAuthenticationIdSeq()
change := qmgo.Change{
Update: qmgo.M{"$inc": qmgo.M{"seq": 1}},
Upsert: true,
ReturnNew: false,
}
realNameAuthenticationIdSeqInstance := dbstruct.RealNameAuthenticationIdSeq{}
if err = col.Find(ctx, qmgo.M{"_id": "realname_authentication_id_seq_id"}).Apply(change, &realNameAuthenticationIdSeqInstance); err != nil {
logger.Error("change error : %v", err)
return
}
return &realNameAuthenticationIdSeqInstance, err
}
// contact_customer_service_id发号器
func (m *Mongo) GetAndUpdateContactCustomerServiceIdSeq(ctx *gin.Context) (contact_customer_serviceIdSeq *dbstruct.ContactCustomerServiceIdSeq, err error) {
col := m.getColContactCustomerServiceIdSeq()
change := qmgo.Change{
Update: qmgo.M{"$inc": qmgo.M{"seq": 1}},
Upsert: true,
ReturnNew: false,
}
contactCustomerServiceIdSeqInstance := dbstruct.ContactCustomerServiceIdSeq{}
if err = col.Find(ctx, qmgo.M{"_id": "contact_customer_service_id_seq_id"}).Apply(change, &contactCustomerServiceIdSeqInstance); err != nil {
logger.Error("change error : %v", err)
return
}
return &contactCustomerServiceIdSeqInstance, err
}
// media_id发号器
func (m *Mongo) GetAndUpdateMediaSeq(ctx *gin.Context) (mediaIdSeq *dbstruct.MediaIdSeq, err error) {
col := m.getColMomentIdSeq()
change := qmgo.Change{
Update: qmgo.M{"$inc": qmgo.M{"seq": 1}},
Upsert: true,
ReturnNew: false,
}
mediaIdSeqInstance := dbstruct.MediaIdSeq{}
if err = col.Find(ctx, qmgo.M{"_id": "media_id_seq_id"}).Apply(change, &mediaIdSeqInstance); err != nil {
logger.Error("change error : %v", err)
return
}
return &mediaIdSeqInstance, err
}