|
@@ -5,18 +5,13 @@ import (
|
|
"encoding/base64"
|
|
"encoding/base64"
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/google/uuid"
|
|
"github.com/google/uuid"
|
|
|
|
+ "gorm.io/gorm"
|
|
|
|
+ "iot_manager_service/app/user/dao"
|
|
"iot_manager_service/util/cache"
|
|
"iot_manager_service/util/cache"
|
|
|
|
+ "iot_manager_service/util/common"
|
|
"iot_manager_service/util/rsa"
|
|
"iot_manager_service/util/rsa"
|
|
"iot_manager_service/util/token"
|
|
"iot_manager_service/util/token"
|
|
"strconv"
|
|
"strconv"
|
|
-
|
|
|
|
- //"github.com/google/uuid"
|
|
|
|
- "gorm.io/gorm"
|
|
|
|
- "iot_manager_service/app/user/dao"
|
|
|
|
- "iot_manager_service/util/common"
|
|
|
|
- //"iot_manager_service/util/rsa"
|
|
|
|
- //"iot_manager_service/util/token"
|
|
|
|
- //"strconv"
|
|
|
|
)
|
|
)
|
|
|
|
|
|
// 用户管理服务
|
|
// 用户管理服务
|
|
@@ -26,7 +21,7 @@ type userService struct{}
|
|
|
|
|
|
func (s *userService) Login(acc string, pwd string) *common.Errors {
|
|
func (s *userService) Login(acc string, pwd string) *common.Errors {
|
|
userdao := &dao.User{}
|
|
userdao := &dao.User{}
|
|
- user, err := userdao.LoginFindAccount(acc)
|
|
|
|
|
|
+ USER, err := userdao.LoginFindAccount(acc)
|
|
if err != nil {
|
|
if err != nil {
|
|
if err == gorm.ErrRecordNotFound {
|
|
if err == gorm.ErrRecordNotFound {
|
|
return common.ParamsInvalidResponse("很抱歉,由于您的账号未完成注册或已被禁用,暂时无法使用。", nil)
|
|
return common.ParamsInvalidResponse("很抱歉,由于您的账号未完成注册或已被禁用,暂时无法使用。", nil)
|
|
@@ -42,7 +37,7 @@ func (s *userService) Login(acc string, pwd string) *common.Errors {
|
|
client := rsa.Decryption(a)
|
|
client := rsa.Decryption(a)
|
|
|
|
|
|
//解密数据库密文
|
|
//解密数据库密文
|
|
- b, _ := base64.StdEncoding.DecodeString(user.Password)
|
|
|
|
|
|
+ b, _ := base64.StdEncoding.DecodeString(USER.Password)
|
|
mysql := rsa.Decryption(b)
|
|
mysql := rsa.Decryption(b)
|
|
if !bytes.Equal(client, mysql) {
|
|
if !bytes.Equal(client, mysql) {
|
|
return common.ParamsInvalidResponse("密码错误", err)
|
|
return common.ParamsInvalidResponse("密码错误", err)
|
|
@@ -50,9 +45,9 @@ func (s *userService) Login(acc string, pwd string) *common.Errors {
|
|
|
|
|
|
//登录成功则生成token
|
|
//登录成功则生成token
|
|
UUID := uuid.New().String()
|
|
UUID := uuid.New().String()
|
|
- USERID := strconv.Itoa(user.ID)
|
|
|
|
- jwtToken, _ := token.JwtClaims.CreateJwtToken(USERID, user.UserName, UUID)
|
|
|
|
- cache.SetToken(USERID, UUID)
|
|
|
|
|
|
+ USERID := strconv.Itoa(USER.ID)
|
|
|
|
+ jwtToken, _ := token.JwtClaims.CreateJwtToken(USERID, USER.UserName, UUID)
|
|
|
|
+ cache.SetToken(USERID, UUID, USER)
|
|
return common.SuccessResponse("登录成功", gin.H{"token": jwtToken})
|
|
return common.SuccessResponse("登录成功", gin.H{"token": jwtToken})
|
|
}
|
|
}
|
|
|
|
|
|
@@ -63,3 +58,32 @@ func (s *userService) GetPublicKey() *common.Errors {
|
|
}
|
|
}
|
|
return common.SuccessResponse("获取公钥成功", gin.H{"publicKey": pub})
|
|
return common.SuccessResponse("获取公钥成功", gin.H{"publicKey": pub})
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+func (s *userService) GetDeptUsers(deptIDs []int) *common.Errors {
|
|
|
|
+ deptdao := &dao.Dept{}
|
|
|
|
+ depts, _ := deptdao.GetDepts(deptIDs)
|
|
|
|
+
|
|
|
|
+ userdao := &dao.User{}
|
|
|
|
+ users, _ := userdao.GetUsers()
|
|
|
|
+
|
|
|
|
+ deptUsersMap := make(map[int][]dao.User)
|
|
|
|
+ for _, user := range users {
|
|
|
|
+ deptUsersMap[user.DeptId] = append(deptUsersMap[user.DeptId], user)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ var deptUsers []dao.Dept
|
|
|
|
+ for _, dept := range depts {
|
|
|
|
+ users := deptUsersMap[dept.ID]
|
|
|
|
+ deptUsers = append(deptUsers, dao.Dept{
|
|
|
|
+ ID: dept.ID,
|
|
|
|
+ DeptName: dept.DeptName,
|
|
|
|
+ Users: users,
|
|
|
|
+ })
|
|
|
|
+ }
|
|
|
|
+ //for i, dept := range depts {
|
|
|
|
+ // users1, _ := userdao.GetUsers1(dept.ID)
|
|
|
|
+ // depts[i].Users = users1
|
|
|
|
+ //}
|
|
|
|
+
|
|
|
|
+ return common.SuccessResponse("获取成功", gin.H{"deptUsers": deptUsers})
|
|
|
|
+}
|