Skip to content

Commit c0c57c7

Browse files
committed
fix user status
1 parent 3c918d9 commit c0c57c7

File tree

8 files changed

+55
-11
lines changed

8 files changed

+55
-11
lines changed

admins/services/userservice.go

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ import (
44
"context"
55
"time"
66

7+
juggleimsdk "github.com/juggleim/imserver-sdk-go"
78
apimodels "github.com/juggleim/jugglechat-server/admins/apis/models"
89
"github.com/juggleim/jugglechat-server/commons/errs"
10+
"github.com/juggleim/jugglechat-server/commons/imsdk"
911
"github.com/juggleim/jugglechat-server/commons/tools"
1012
"github.com/juggleim/jugglechat-server/storages"
1113
"github.com/juggleim/jugglechat-server/storages/models"
@@ -74,28 +76,44 @@ func QryUserInfo(appkey, userId string) *apimodels.User {
7476
}
7577

7678
func BanUsers(ctx context.Context, req *apimodels.BanUsersReq) errs.AdminErrorCode {
77-
storage := storages.NewBanUserStorage()
79+
userStorage := storages.NewUserStorage()
7880
appkey := req.AppKey
81+
banUsers := &juggleimsdk.BanUsers{
82+
Items: []*juggleimsdk.BanUser{},
83+
}
7984
for _, user := range req.Items {
8085
var endTime int64 = user.EndTime
8186
if endTime == 0 && user.EndTimeOffset > 0 {
8287
endTime = time.Now().UnixMilli() + user.EndTimeOffset
8388
}
84-
storage.Upsert(models.BanUser{
85-
UserId: user.UserId,
86-
CreatedTime: time.Now(),
87-
EndTime: endTime,
88-
AppKey: appkey,
89+
banUsers.Items = append(banUsers.Items, &juggleimsdk.BanUser{
90+
UserId: user.UserId,
91+
EndTime: endTime,
8992
})
93+
userStorage.UpdateStatus(appkey, user.UserId, models.UserStatus_Ban)
94+
}
95+
sdk := imsdk.GetImSdk(appkey)
96+
if sdk != nil {
97+
sdk.BanUsers(banUsers)
9098
}
9199
return errs.AdminErrorCode_Success
92100
}
93101

94102
func UnBanUsers(ctx context.Context, req *apimodels.BanUsersReq) errs.AdminErrorCode {
95-
storage := storages.NewBanUserStorage()
103+
userStorage := storages.NewUserStorage()
104+
banUsers := &juggleimsdk.BanUsers{
105+
Items: []*juggleimsdk.BanUser{},
106+
}
96107
appkey := req.AppKey
97108
for _, user := range req.Items {
98-
storage.DelBanUser(appkey, user.UserId, "")
109+
banUsers.Items = append(banUsers.Items, &juggleimsdk.BanUser{
110+
UserId: user.UserId,
111+
})
112+
userStorage.UpdateStatus(appkey, user.UserId, models.UserStatus_Normal)
113+
}
114+
sdk := imsdk.GetImSdk(appkey)
115+
if sdk != nil {
116+
sdk.UnBanUsers(banUsers)
99117
}
100118
return errs.AdminErrorCode_Success
101119
}

commons/dbcommons/sqls/20250201.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,4 +357,4 @@ CREATE TABLE IF NOT EXISTS `banusers` (
357357
UNIQUE KEY `uniq_appkey_userid` (`app_key`,`user_id`,`scope_key`)
358358
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
359359

360-
INSERT IGNORE INTO `globalconfs` (`conf_key`,`conf_value`)VALUES('jchatdb_version','20250201');
360+
INSERT INTO `globalconfs` (`conf_key`,`conf_value`)VALUES('jchatdb_version','20250201');
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
ALTER TABLE `users` ADD COLUMN `status` TINYINT NULL DEFAULT 0;
2+
3+
INSERT INTO `globalconfs` (`conf_key`,`conf_value`)VALUES('jchatdb_version','20251115');

docs/appbusiness.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ CREATE TABLE IF NOT EXISTS `users` (
143143
`email` varchar(100) DEFAULT NULL,
144144
`login_account` varchar(50) DEFAULT NULL,
145145
`login_pass` varchar(50) DEFAULT NULL,
146+
`status` tinyint default '0',
146147
`created_time` datetime(3) DEFAULT CURRENT_TIMESTAMP(3),
147148
`app_key` varchar(20) DEFAULT NULL,
148149
`updated_time` datetime(3) DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3),
@@ -357,4 +358,4 @@ CREATE TABLE IF NOT EXISTS `banusers` (
357358
UNIQUE KEY `uniq_appkey_userid` (`app_key`,`user_id`,`scope_key`)
358359
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
359360

360-
INSERT IGNORE INTO `globalconfs` (`conf_key`,`conf_value`)VALUES('jchatdb_version','20250201');
361+
INSERT IGNORE INTO `globalconfs` (`conf_key`,`conf_value`)VALUES('jchatdb_version','20251115');

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ require (
88
github.com/alibabacloud-go/tea v1.2.2
99
github.com/alibabacloud-go/tea-utils/v2 v2.0.6
1010
github.com/aliyun/credentials-go v1.4.6
11-
github.com/juggleim/imserver-sdk-go v1.0.10
11+
github.com/juggleim/imserver-sdk-go v1.0.11
1212
)
1313

1414
require (

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,8 @@ github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHm
192192
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
193193
github.com/juggleim/imserver-sdk-go v1.0.10 h1:H9YpARzy7xnjiAETAZcetDEQJ1va+9SmrjTZ7C1OLoE=
194194
github.com/juggleim/imserver-sdk-go v1.0.10/go.mod h1:xdxsGeW0b4GOYJvKJwnaU04Z+jGaUSrBvzeSbNvNOFk=
195+
github.com/juggleim/imserver-sdk-go v1.0.11 h1:EnNfkLDS6U+zYGwJ+Uim/sEyiIILEqHoP+kcO8IW4Oo=
196+
github.com/juggleim/imserver-sdk-go v1.0.11/go.mod h1:xdxsGeW0b4GOYJvKJwnaU04Z+jGaUSrBvzeSbNvNOFk=
195197
github.com/klauspost/compress v1.18.0 h1:c/Cqfb0r+Yi+JtIEq73FWXVkRonBlf0CRNYc8Zttxdo=
196198
github.com/klauspost/compress v1.18.0/go.mod h1:2Pp+KzxcywXVXMr50+X0Q/Lsb43OQHYWRCY2AiWywWQ=
197199
github.com/klauspost/cpuid/v2 v2.0.1/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=

storages/dbs/userdao.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ type UserDao struct {
2222
Email string `gorm:"email"`
2323
LoginAccount string `gorm:"login_account"`
2424
LoginPass string `gorm:"login_pass"`
25+
Status int `gorm:"status"`
2526
CreatedTime time.Time `gorm:"created_time"`
2627
UpdatedTime time.Time `gorm:"updated_time"`
2728
AppKey string `gorm:"app_key"`
@@ -51,6 +52,7 @@ func (user UserDao) FindByUserId(appkey, userId string) (*models.User, error) {
5152
Email: item.Email,
5253
LoginAccount: item.LoginAccount,
5354
LoginPass: item.LoginPass,
55+
Status: item.Status,
5456
CreatedTime: item.CreatedTime,
5557
UpdatedTime: item.UpdatedTime,
5658
AppKey: item.AppKey,
@@ -71,6 +73,7 @@ func (user UserDao) FindByUserIds(appkey string, userIds []string) (map[string]*
7173
UserType: item.UserType,
7274
Phone: item.Phone,
7375
Email: item.Email,
76+
Status: item.Status,
7477
CreatedTime: item.CreatedTime,
7578
UpdatedTime: item.UpdatedTime,
7679
AppKey: item.AppKey,
@@ -98,6 +101,7 @@ func (user UserDao) SearchByKeyword(appkey string, userId, keyword string) ([]*m
98101
Phone: item.Phone,
99102
Email: item.Email,
100103
LoginAccount: item.LoginAccount,
104+
Status: item.Status,
101105
CreatedTime: item.CreatedTime,
102106
UpdatedTime: item.UpdatedTime,
103107
AppKey: item.AppKey,
@@ -126,6 +130,7 @@ func (user UserDao) FindByPhone(appkey, phone string) (*models.User, error) {
126130
Email: item.Email,
127131
LoginAccount: item.LoginAccount,
128132
LoginPass: item.LoginPass,
133+
Status: item.Status,
129134
CreatedTime: item.CreatedTime,
130135
UpdatedTime: item.UpdatedTime,
131136
AppKey: item.AppKey,
@@ -152,6 +157,7 @@ func (user UserDao) FindByEmail(appkey, email string) (*models.User, error) {
152157
Email: item.Email,
153158
LoginAccount: item.LoginAccount,
154159
LoginPass: item.LoginPass,
160+
Status: item.Status,
155161
CreatedTime: item.CreatedTime,
156162
UpdatedTime: item.UpdatedTime,
157163
AppKey: item.AppKey,
@@ -178,6 +184,7 @@ func (user UserDao) FindByAccount(appkey, account string) (*models.User, error)
178184
Email: item.Email,
179185
LoginAccount: item.LoginAccount,
180186
LoginPass: item.LoginPass,
187+
Status: item.Status,
181188
CreatedTime: item.CreatedTime,
182189
UpdatedTime: item.UpdatedTime,
183190
AppKey: item.AppKey,
@@ -259,6 +266,10 @@ func (user UserDao) UpdateEmail(appkey, userId, email string) error {
259266
return dbcommons.GetDb().Model(&UserDao{}).Where("app_key=? and user_id=?", appkey, userId).Update("email", email).Error
260267
}
261268

269+
func (user UserDao) UpdateStatus(appkey, userId string, status models.UserStatus) error {
270+
return dbcommons.GetDb().Model(&UserDao{}).Where("app_key=? and user_id=?", appkey, userId).Update("status", status).Error
271+
}
272+
262273
func (user UserDao) Count(appkey string) int {
263274
var count int
264275
err := dbcommons.GetDb().Model(&UserDao{}).Where("app_key=?", appkey).Count(&count).Error
@@ -311,6 +322,7 @@ func (user UserDao) QryUsers(appkey, name string, startId, limit int64, isPositi
311322
Email: item.Email,
312323
LoginAccount: item.LoginAccount,
313324
LoginPass: item.LoginPass,
325+
Status: item.Status,
314326
CreatedTime: item.CreatedTime,
315327
UpdatedTime: item.UpdatedTime,
316328
AppKey: item.AppKey,

storages/models/user.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@ package models
22

33
import "time"
44

5+
type UserStatus int32
6+
7+
const (
8+
UserStatus_Normal UserStatus = 0
9+
UserStatus_Ban UserStatus = 1
10+
)
11+
512
type User struct {
613
ID int64
714
UserId string
@@ -33,6 +40,7 @@ type IUserStorage interface {
3340
UpdatePass(appkey, userId, pass string) error
3441
UpdatePhone(appkey, userId, phone string) error
3542
UpdateEmail(appkey, userId, email string) error
43+
UpdateStatus(appkey, userId string, status UserStatus) error
3644
Count(appkey string) int
3745
CountByTime(appkey string, start, end int64) int64
3846
QryUsers(appkey, name string, startId, limit int64, isPositiveOrder bool) ([]*User, error)

0 commit comments

Comments
 (0)