From f10e46761bd398a97d2c9502ec60fdffd9c0f376 Mon Sep 17 00:00:00 2001 From: junleea <354425203@qq.com> Date: Sun, 15 Dec 2024 15:10:41 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=BE=AA=E7=8E=AF=E5=BC=95?= =?UTF-8?q?=E7=94=A8=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dao/user.go | 7 +++++++ handler/user.go | 11 ++--------- service/userService.go | 5 ++--- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/dao/user.go b/dao/user.go index 43aec3a..0bf4bec 100644 --- a/dao/user.go +++ b/dao/user.go @@ -142,3 +142,10 @@ func GetAllUser() []User { DB.Find(&users) return users } + +// 用户数据同步 +type UserSyncResp struct { + Update []User `json:"update" form:"update"` //更新用户 + Add []User `json:"add" form:"add"` //添加用户 + Delete []proto.UserDelID `json:"delete" form:"delete"` //删除用户 +} diff --git a/handler/user.go b/handler/user.go index f37993b..b54d2a3 100644 --- a/handler/user.go +++ b/handler/user.go @@ -377,13 +377,6 @@ type SyncUserReq struct { Confirm proto.UserSyncConfirm `json:"confirm" form:"confirm"` } -// 用户数据同步 -type UserSyncResp struct { - Update []dao.User `json:"update" form:"update"` //更新用户 - Add []dao.User `json:"add" form:"add"` //添加用户 - Delete []proto.UserDelID `json:"delete" form:"delete"` //删除用户 -} - func GetSyncUserInfo(c *gin.Context) { var req_data SyncUserReq if err := c.ShouldBind(&req_data); err == nil { @@ -395,7 +388,7 @@ func GetSyncUserInfo(c *gin.Context) { if proto.Config.SERVER_USER_TYPE == "master" { if req_data.Types == 1 { //1为全量同步 add_users := dao.GetAllUser() - resp := UserSyncResp{} + resp := dao.UserSyncResp{} resp.Add = add_users c.JSON(200, gin.H{"code": proto.SuccessCode, "message": "success", "data": resp}) } else if req_data.Types == 2 { //2为增量同步 @@ -413,7 +406,7 @@ func GetSyncUserInfo(c *gin.Context) { c.JSON(200, gin.H{"code": proto.OperationFailed, "message": "failed", "data": "failed"}) } } else { - c.JSON(200, gin.H{"code": proto.ParameterError, "message": "type is error", "data": UserSyncResp{}}) + c.JSON(200, gin.H{"code": proto.ParameterError, "message": "type is error", "data": dao.UserSyncResp{}}) } } else { c.JSON(200, gin.H{"code": proto.NoPermission, "message": "no permission,server is not master", "data": proto.UserSync{}}) diff --git a/service/userService.go b/service/userService.go index f4f009c..b45ea04 100644 --- a/service/userService.go +++ b/service/userService.go @@ -6,7 +6,6 @@ import ( "strconv" "time" "videoplayer/dao" - "videoplayer/handler" "videoplayer/proto" "videoplayer/worker" ) @@ -130,7 +129,7 @@ func UserSyncDataFromMaster() { } // 同步数据到主服务器-增删改数据 -func GetUserSyncData(device string) handler.UserSyncResp { +func GetUserSyncData(device string) dao.UserSyncResp { key := device + "_sync_user_ids" add_temp_key := device + "_sync_user_ids_add_confirm_temp" update_temp_key := device + "_sync_user_ids_update_confirm_temp" @@ -165,7 +164,7 @@ func GetUserSyncData(device string) handler.UserSyncResp { worker.ClearRedisSet(key + "_update") worker.SetRedisSetUnionAndStore(delete_temp_key, key+"_delete") worker.ClearRedisSet(key + "_delete") - return handler.UserSyncResp{Add: add_users, Update: update_users, Delete: delete_users} + return dao.UserSyncResp{Add: add_users, Update: update_users, Delete: delete_users} } func setSyncUserDataSet(t string, id int) error {