pull/218/head
wenxu12345 3 years ago
parent ad4c9fcc83
commit 42225dd35e

@ -33,7 +33,7 @@ func ResetPassword(account, password string) error {
Password: password,
}
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
dbConn.LogMode(true)
dbConn.LogMode(false)
if err != nil {
return err
}

@ -71,7 +71,7 @@ func GetGroupMemberIDListByGroupID(groupID string) ([]string, error) {
if err != nil {
return nil, err
}
dbConn.LogMode(true)
dbConn.LogMode(false)
var groupMembers []db.GroupMember
err = dbConn.Table("group_members").Select("user_id").Where("group_id=?", groupID).Find(&groupMembers).Error
if err != nil {
@ -279,7 +279,7 @@ func GetGroupMembersCount(groupId, userName string) (int32, error) {
if err != nil {
return count, err
}
dbConn.LogMode(true)
dbConn.LogMode(false)
if err := dbConn.Table("group_members").Where("group_id=?", groupId).Where(fmt.Sprintf(" nickname like '%%%s%%' ", userName)).Count(&count).Error; err != nil {
return count, err
}

@ -123,7 +123,7 @@ func GetUserReqGroupByUserID(userID string) ([]db.GroupRequest, error) {
if err != nil {
return nil, err
}
dbConn.LogMode(true)
dbConn.LogMode(false)
err = dbConn.Table("group_requests").Where("user_id=?", userID).Find(&groupRequestList).Error
return groupRequestList, err
}

@ -13,7 +13,7 @@ func GetChatLog(chatLog db.ChatLog, pageNumber, showNumber int32) ([]db.ChatLog,
if err != nil {
return chatLogs, err
}
dbConn.LogMode(true)
dbConn.LogMode(false)
db := dbConn.Table("chat_logs").
Where(fmt.Sprintf(" content like '%%%s%%'", chatLog.Content)).
Limit(showNumber).Offset(showNumber * (pageNumber - 1))
@ -43,7 +43,7 @@ func GetChatLogCount(chatLog db.ChatLog) (int64, error) {
if err != nil {
return count, err
}
dbConn.LogMode(true)
dbConn.LogMode(false)
db := dbConn.Table("chat_logs").
Where(fmt.Sprintf(" content like '%%%s%%'", chatLog.Content))
if chatLog.SessionType != 0 {

@ -10,7 +10,7 @@ func GetActiveUserNum(from, to time.Time) (int32, error) {
if err != nil {
return 0, err
}
dbConn.LogMode(true)
dbConn.LogMode(false)
var num int32
err = dbConn.Table("chat_logs").Select("count(distinct(send_id))").Where("create_time >= ? and create_time <= ?", from, to).Count(&num).Error
return num, err
@ -21,7 +21,7 @@ func GetIncreaseUserNum(from, to time.Time) (int32, error) {
if err != nil {
return 0, err
}
dbConn.LogMode(true)
dbConn.LogMode(false)
var num int32
err = dbConn.Table("users").Where("create_time >= ? and create_time <= ?", from, to).Count(&num).Error
return num, err
@ -32,7 +32,7 @@ func GetTotalUserNum() (int32, error) {
if err != nil {
return 0, err
}
dbConn.LogMode(true)
dbConn.LogMode(false)
var num int32
err = dbConn.Table("users").Count(&num).Error
return num, err
@ -43,7 +43,7 @@ func GetTotalUserNumByDate(to time.Time) (int32, error) {
if err != nil {
return 0, err
}
dbConn.LogMode(true)
dbConn.LogMode(false)
var num int32
err = dbConn.Table("users").Where("create_time <= ?", to).Count(&num).Error
return num, err
@ -54,7 +54,7 @@ func GetPrivateMessageNum(from, to time.Time) (int32, error) {
if err != nil {
return 0, err
}
dbConn.LogMode(true)
dbConn.LogMode(false)
var num int32
err = dbConn.Table("chat_logs").Where("create_time >= ? and create_time <= ? and session_type = ?", from, to, 1).Count(&num).Error
return num, err
@ -65,7 +65,7 @@ func GetGroupMessageNum(from, to time.Time) (int32, error) {
if err != nil {
return 0, err
}
dbConn.LogMode(true)
dbConn.LogMode(false)
var num int32
err = dbConn.Table("chat_logs").Where("create_time >= ? and create_time <= ? and session_type = ?", from, to, 2).Count(&num).Error
return num, err
@ -76,7 +76,7 @@ func GetIncreaseGroupNum(from, to time.Time) (int32, error) {
if err != nil {
return 0, err
}
dbConn.LogMode(true)
dbConn.LogMode(false)
var num int32
err = dbConn.Table("groups").Where("create_time >= ? and create_time <= ?", from, to).Count(&num).Error
return num, err
@ -87,7 +87,7 @@ func GetTotalGroupNum() (int32, error) {
if err != nil {
return 0, err
}
dbConn.LogMode(true)
dbConn.LogMode(false)
var num int32
err = dbConn.Table("groups").Count(&num).Error
return num, err
@ -98,7 +98,7 @@ func GetGroupNum(to time.Time) (int32, error) {
if err != nil {
return 0, err
}
dbConn.LogMode(true)
dbConn.LogMode(false)
var num int32
err = dbConn.Table("groups").Where("create_time <= ?", to).Count(&num).Error
return num, err
@ -116,7 +116,7 @@ func GetActiveGroups(from, to time.Time, limit int) ([]*activeGroup, error) {
if err != nil {
return activeGroups, err
}
dbConn.LogMode(true)
dbConn.LogMode(false)
err = dbConn.Table("chat_logs").Select("recv_id, count(*) as message_num").Where("create_time >= ? and create_time <= ? and session_type = ?", from, to, 2).Group("recv_id").Limit(limit).Order("message_num DESC").Find(&activeGroups).Error
for _, activeGroup := range activeGroups {
group := db.Group{
@ -140,7 +140,7 @@ func GetActiveUsers(from, to time.Time, limit int) ([]*activeUser, error) {
if err != nil {
return activeUsers, err
}
dbConn.LogMode(true)
dbConn.LogMode(false)
err = dbConn.Table("chat_logs").Select("send_id, count(*) as message_num").Where("create_time >= ? and create_time <= ? and session_type = ?", from, to, 1).Group("send_id").Limit(limit).Order("message_num DESC").Find(&activeUsers).Error
for _, activeUser := range activeUsers {
user := db.User{

@ -92,7 +92,7 @@ func UpdateUserInfo(user db.User) error {
if err != nil {
return err
}
dbConn.LogMode(true)
dbConn.LogMode(false)
err = dbConn.Table("users").Where("user_id=?", user.UserID).Update(&user).Error
return err
}
@ -112,7 +112,7 @@ func SelectAllUserID() ([]string, error) {
func SelectSomeUserID(userIDList []string) ([]string, error) {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
dbConn.LogMode(true)
dbConn.LogMode(false)
if err != nil {
return nil, err
}
@ -131,7 +131,7 @@ func GetUsers(showNumber, pageNumber int32) ([]db.User, error) {
if err != nil {
return users, err
}
dbConn.LogMode(true)
dbConn.LogMode(false)
err = dbConn.Table("users").Limit(showNumber).Offset(showNumber * (pageNumber - 1)).Find(&users).Error
if err != nil {
return users, err
@ -204,7 +204,7 @@ func UnBlockUser(userId string) error {
if err != nil {
return err
}
dbConn.LogMode(true)
dbConn.LogMode(false)
result := dbConn.Where("uid=?", userId).Delete(&db.BlackList{})
return result.Error
}
@ -248,7 +248,7 @@ func GetBlockUsers(showNumber, pageNumber int32) ([]BlockUserInfo, error) {
if err != nil {
return blockUserInfos, err
}
dbConn.LogMode(true)
dbConn.LogMode(false)
if err = dbConn.Limit(showNumber).Offset(showNumber * (pageNumber - 1)).Find(&blockUsers).Error; err != nil {
return blockUserInfos, err
}
@ -275,7 +275,7 @@ func GetUserByName(userName string, showNumber, pageNumber int32) ([]db.User, er
if err != nil {
return users, err
}
dbConn.LogMode(true)
dbConn.LogMode(false)
err = dbConn.Table("users").Where(fmt.Sprintf(" name like '%%%s%%' ", userName)).Limit(showNumber).Offset(showNumber * (pageNumber - 1)).Find(&users).Error
return users, err
}
@ -285,7 +285,7 @@ func GetUsersCount(user db.User) (int32, error) {
if err != nil {
return 0, err
}
dbConn.LogMode(true)
dbConn.LogMode(false)
var count int32
if err := dbConn.Table("users").Where(fmt.Sprintf(" name like '%%%s%%' ", user.Nickname)).Count(&count).Error; err != nil {
return 0, err
@ -298,7 +298,7 @@ func GetBlockUsersNumCount() (int32, error) {
if err != nil {
return 0, err
}
dbConn.LogMode(true)
dbConn.LogMode(false)
var count int32
if err := dbConn.Model(&db.BlackList{}).Count(&count).Error; err != nil {
return 0, err
@ -311,7 +311,7 @@ func SetConversation(conversation db.Conversation) error {
if err != nil {
return err
}
dbConn.LogMode(true)
dbConn.LogMode(false)
newConversation := conversation
if dbConn.Model(&db.Conversation{}).Find(&newConversation).RowsAffected == 0 {
log.NewDebug("", utils.GetSelfFuncName(), "conversation", conversation, "not exist in db, create")
@ -330,7 +330,7 @@ func PeerUserSetConversation(conversation db.Conversation) error {
if err != nil {
return err
}
dbConn.LogMode(true)
dbConn.LogMode(false)
newConversation := conversation
if dbConn.Model(&db.Conversation{}).Find(&newConversation).RowsAffected == 0 {
log.NewDebug("", utils.GetSelfFuncName(), "conversation", conversation, "not exist in db, create")
@ -349,7 +349,7 @@ func SetRecvMsgOpt(conversation db.Conversation) error {
if err != nil {
return err
}
dbConn.LogMode(true)
dbConn.LogMode(false)
newConversation := conversation
if dbConn.Model(&db.Conversation{}).Find(&newConversation).RowsAffected == 0 {
log.NewDebug("", utils.GetSelfFuncName(), "conversation", conversation, "not exist in db, create")
@ -369,7 +369,7 @@ func GetUserAllConversations(ownerUserID string) ([]db.Conversation, error) {
if err != nil {
return conversations, err
}
dbConn.LogMode(true)
dbConn.LogMode(false)
err = dbConn.Model(&db.Conversation{}).Where("owner_user_id=?", ownerUserID).Find(&conversations).Error
return conversations, err
}

Loading…
Cancel
Save