From 5fac03fb857cf9a160e1736a25de2c5f95f5e44f Mon Sep 17 00:00:00 2001
From: wangpengfei <274878379@qq.com>
Date: 星期二, 18 七月 2023 17:18:18 +0800
Subject: [PATCH] add
---
service/user.go | 4
model/user.go | 78 ++--------
api/v1/user.go | 53 ++-----
source/user.go | 4
model/request/user.go | 27 ++-
docs/swagger.yaml | 48 +++---
docs/docs.go | 74 ++++-----
docs/swagger.json | 74 ++++-----
service/container_docker.go | 29 ++--
9 files changed, 158 insertions(+), 233 deletions(-)
diff --git a/api/v1/user.go b/api/v1/user.go
index bd53901..a791a7d 100644
--- a/api/v1/user.go
+++ b/api/v1/user.go
@@ -58,13 +58,6 @@
ctx.Fail(errCode)
return
}
- if !user.Enable {
- logx.Errorf("鐧婚檰澶辫触! 鐢ㄦ埛琚姝㈢櫥褰�!")
- // 楠岃瘉鐮佹鏁�+1
- _ = constvar.BlackCache.Increment(key, 1)
- ctx.Fail(ecode.UserForbidden)
- return
- }
// 璧嬪�艰彍鍗旾D鍒楄〃
//user.MenuIds, _ = menuService.GetUserMenuIds(user.ID, user.UserType)
slf.TokenNext(ctx, *user)
@@ -83,7 +76,6 @@
claims := j.CreateClaims(request.BaseClaims{
UserId: user.ID,
Username: user.Username,
- ParentId: user.ParentName,
UserType: user.UserType,
AuthorityId: user.AuthorityId,
})
@@ -156,7 +148,7 @@
return
}
- if len(params.Username) == 0 || len(params.Password) == 0 || len(params.Phone) == 0 || len(params.NickName) == 0 {
+ if len(params.Username) == 0 || len(params.Password) == 0 || len(params.NickName) == 0 || params.AuthorityId == 0 || len(params.RePassword) == 0 || params.DepartmentId == 0 {
ctx.Fail(ecode.ParamsErr)
return
}
@@ -164,41 +156,28 @@
var userId = fmt.Sprintf("u%v", snowflake.GenerateId())
var passWord = encrypt.BcryptHash(params.Password)
var userType constvar.UserType
- var parentId string
- var parentName string
- if userInfo.UserType == constvar.UserTypeSuper {
- userType = constvar.UserTypePrimary //銆�涓昏处鎴风殑鐖剁敤鎴稩D鏄嚜宸�
- parentId = userId
- parentName = params.Username
- } else if userInfo.UserType == constvar.UserTypePrimary {
- userType = constvar.UserTypeSub
- parentId = userInfo.UserId
- parentName = userInfo.ParentId
- } else {
- ctx.Fail(ecode.NoPowerErr)
- return
- }
- user := &model.User{ID: userId, Username: params.Username, UserType: userType, NickName: params.NickName, Password: passWord, HeaderImg: params.HeaderImg, Enable: true, ParentId: parentId, ParentName: parentName, Phone: params.Phone, Email: params.Email}
+ user := &model.User{ID: userId, Username: params.Username, UserType: userType, NickName: params.NickName, Password: passWord, HeaderImg: params.HeaderImg, Phone: params.Phone, Email: params.Email, DepartmentId: params.DepartmentId, AuthorityId: params.AuthorityId}
userReturn, errCode := userService.Register(user)
if errCode != ecode.OK {
ctx.Fail(errCode)
return
}
- if user.UserType == constvar.UserTypePrimary { // 涓昏处鎴峰垱寤哄搴旂殑鏁版嵁搴撶敤鎴峰拰鎺掔▼鏁版嵁搴�
- err := model.NewMysql().CreateDatabase(user.Username)
- if err != nil {
- ctx.Fail(ecode.CreateDatabaseErr)
- return
- }
- defaultPwd := fmt.Sprintf("%v@Basic2023", user.Username)
- err = model.NewMysql().CreateUser(user.Username, defaultPwd, user.Username)
- if err != nil {
- ctx.Fail(ecode.CreateDatabaseUserErr)
- return
- }
- }
+ //if user.UserType == constvar.UserTypePrimary { // 涓昏处鎴峰垱寤哄搴旂殑鏁版嵁搴撶敤鎴峰拰鎺掔▼鏁版嵁搴�
+ // err := model.NewMysql().CreateDatabase(user.Username)
+ // if err != nil {
+ // ctx.Fail(ecode.CreateDatabaseErr)
+ // return
+ // }
+ //
+ // defaultPwd := fmt.Sprintf("%v@Basic2023", user.Username)
+ // err = model.NewMysql().CreateUser(user.Username, defaultPwd, user.Username)
+ // if err != nil {
+ // ctx.Fail(ecode.CreateDatabaseUserErr)
+ // return
+ // }
+ //}
ctx.OkWithDetailed(response.UserResponse{User: *userReturn})
}
diff --git a/docs/docs.go b/docs/docs.go
index 3dd7099..85c7809 100644
--- a/docs/docs.go
+++ b/docs/docs.go
@@ -6292,26 +6292,16 @@
"description": "鐢ㄦ埛瑙掕壊ID",
"type": "integer"
},
- "companyName": {
- "type": "string"
- },
- "createAt": {
- "description": "鍒涘缓鏃堕棿",
- "type": "string"
+ "departmentId": {
+ "type": "integer"
},
"email": {
"type": "string"
- },
- "enable": {
- "type": "boolean"
},
"headerImg": {
"type": "string"
},
"id": {
- "type": "string"
- },
- "ip": {
"type": "string"
},
"menuIds": {
@@ -6324,26 +6314,13 @@
"nickName": {
"type": "string"
},
- "parentId": {
- "type": "string"
- },
- "parentName": {
- "type": "string"
- },
"phone": {
- "type": "string"
- },
- "port": {
"type": "string"
},
"pos": {
"type": "string"
},
- "status": {
- "type": "integer"
- },
- "updateAt": {
- "description": "鏇存柊鏃堕棿",
+ "realName": {
"type": "string"
},
"userType": {
@@ -7526,29 +7503,46 @@
"request.Register": {
"type": "object",
"properties": {
+ "authorityId": {
+ "description": "鐢ㄦ埛瑙掕壊ID",
+ "type": "integer"
+ },
+ "departmentId": {
+ "type": "integer"
+ },
"email": {
- "type": "string",
- "example": "鐢靛瓙閭"
+ "type": "string"
},
"headerImg": {
- "type": "string",
- "example": "澶村儚閾炬帴"
+ "type": "string"
+ },
+ "id": {
+ "type": "string"
},
"nickName": {
- "type": "string",
- "example": "鏄电О"
+ "type": "string"
},
- "passWord": {
- "type": "string",
- "example": "瀵嗙爜"
+ "password": {
+ "type": "string"
},
"phone": {
- "type": "string",
- "example": "鐢佃瘽鍙风爜"
+ "type": "string"
},
- "userName": {
- "type": "string",
- "example": "鐢ㄦ埛鍚�"
+ "pos": {
+ "type": "string"
+ },
+ "rePassword": {
+ "description": "纭瀵嗙爜",
+ "type": "string"
+ },
+ "realName": {
+ "type": "string"
+ },
+ "userType": {
+ "$ref": "#/definitions/constvar.UserType"
+ },
+ "username": {
+ "type": "string"
}
}
},
diff --git a/docs/swagger.json b/docs/swagger.json
index 8ab6e77..31447c4 100644
--- a/docs/swagger.json
+++ b/docs/swagger.json
@@ -6280,26 +6280,16 @@
"description": "鐢ㄦ埛瑙掕壊ID",
"type": "integer"
},
- "companyName": {
- "type": "string"
- },
- "createAt": {
- "description": "鍒涘缓鏃堕棿",
- "type": "string"
+ "departmentId": {
+ "type": "integer"
},
"email": {
"type": "string"
- },
- "enable": {
- "type": "boolean"
},
"headerImg": {
"type": "string"
},
"id": {
- "type": "string"
- },
- "ip": {
"type": "string"
},
"menuIds": {
@@ -6312,26 +6302,13 @@
"nickName": {
"type": "string"
},
- "parentId": {
- "type": "string"
- },
- "parentName": {
- "type": "string"
- },
"phone": {
- "type": "string"
- },
- "port": {
"type": "string"
},
"pos": {
"type": "string"
},
- "status": {
- "type": "integer"
- },
- "updateAt": {
- "description": "鏇存柊鏃堕棿",
+ "realName": {
"type": "string"
},
"userType": {
@@ -7514,29 +7491,46 @@
"request.Register": {
"type": "object",
"properties": {
+ "authorityId": {
+ "description": "鐢ㄦ埛瑙掕壊ID",
+ "type": "integer"
+ },
+ "departmentId": {
+ "type": "integer"
+ },
"email": {
- "type": "string",
- "example": "鐢靛瓙閭"
+ "type": "string"
},
"headerImg": {
- "type": "string",
- "example": "澶村儚閾炬帴"
+ "type": "string"
+ },
+ "id": {
+ "type": "string"
},
"nickName": {
- "type": "string",
- "example": "鏄电О"
+ "type": "string"
},
- "passWord": {
- "type": "string",
- "example": "瀵嗙爜"
+ "password": {
+ "type": "string"
},
"phone": {
- "type": "string",
- "example": "鐢佃瘽鍙风爜"
+ "type": "string"
},
- "userName": {
- "type": "string",
- "example": "鐢ㄦ埛鍚�"
+ "pos": {
+ "type": "string"
+ },
+ "rePassword": {
+ "description": "纭瀵嗙爜",
+ "type": "string"
+ },
+ "realName": {
+ "type": "string"
+ },
+ "userType": {
+ "$ref": "#/definitions/constvar.UserType"
+ },
+ "username": {
+ "type": "string"
}
}
},
diff --git a/docs/swagger.yaml b/docs/swagger.yaml
index 085ec75..b9f4ea0 100644
--- a/docs/swagger.yaml
+++ b/docs/swagger.yaml
@@ -867,20 +867,13 @@
authorityId:
description: 鐢ㄦ埛瑙掕壊ID
type: integer
- companyName:
- type: string
- createAt:
- description: 鍒涘缓鏃堕棿
- type: string
+ departmentId:
+ type: integer
email:
type: string
- enable:
- type: boolean
headerImg:
type: string
id:
- type: string
- ip:
type: string
menuIds:
description: 鑿滃崟ID鍒楄〃
@@ -889,20 +882,11 @@
type: array
nickName:
type: string
- parentId:
- type: string
- parentName:
- type: string
phone:
- type: string
- port:
type: string
pos:
type: string
- status:
- type: integer
- updateAt:
- description: 鏇存柊鏃堕棿
+ realName:
type: string
userType:
$ref: '#/definitions/constvar.UserType'
@@ -1708,23 +1692,33 @@
type: object
request.Register:
properties:
+ authorityId:
+ description: 鐢ㄦ埛瑙掕壊ID
+ type: integer
+ departmentId:
+ type: integer
email:
- example: 鐢靛瓙閭
type: string
headerImg:
- example: 澶村儚閾炬帴
+ type: string
+ id:
type: string
nickName:
- example: 鏄电О
type: string
- passWord:
- example: 瀵嗙爜
+ password:
type: string
phone:
- example: 鐢佃瘽鍙风爜
type: string
- userName:
- example: 鐢ㄦ埛鍚�
+ pos:
+ type: string
+ rePassword:
+ description: 纭瀵嗙爜
+ type: string
+ realName:
+ type: string
+ userType:
+ $ref: '#/definitions/constvar.UserType'
+ username:
type: string
type: object
request.SalesDetails:
diff --git a/model/request/user.go b/model/request/user.go
index 35660db..6211e5e 100644
--- a/model/request/user.go
+++ b/model/request/user.go
@@ -1,6 +1,8 @@
package request
-import "aps_crm/constvar"
+import (
+ "aps_crm/constvar"
+)
type (
Login struct {
@@ -11,12 +13,23 @@
}
Register struct {
- Username string `json:"userName" example:"鐢ㄦ埛鍚�"`
- Password string `json:"passWord" example:"瀵嗙爜"`
- NickName string `json:"nickName" example:"鏄电О"`
- HeaderImg string `json:"headerImg" example:"澶村儚閾炬帴"`
- Phone string `json:"phone" example:"鐢佃瘽鍙风爜"`
- Email string `json:"email" example:"鐢靛瓙閭"`
+ User
+ RePassword string `json:"rePassword"` // 纭瀵嗙爜
+ }
+
+ User struct {
+ ID string `json:"id"`
+ Username string `json:"username"`
+ UserType constvar.UserType `json:"userType"`
+ Password string `json:"password"`
+ NickName string `json:"nickName"`
+ RealName string `json:"realName"`
+ DepartmentId int `json:"departmentId"`
+ HeaderImg string `json:"headerImg"`
+ Phone string `json:"phone" `
+ Email string `json:"email" `
+ Pos string `json:"pos"`
+ AuthorityId uint `json:"authorityId"` // 鐢ㄦ埛瑙掕壊ID
}
ChangePasswordReq struct {
diff --git a/model/user.go b/model/user.go
index 529e9bd..69cfc0c 100644
--- a/model/user.go
+++ b/model/user.go
@@ -5,37 +5,27 @@
"aps_crm/pkg/mysqlx"
"fmt"
"gorm.io/gorm"
- "time"
)
type (
// User token閲岃竟鎶婄敤鎴稩D銆佺埗鐢ㄦ埛ID銆佽鑹查兘甯︿笂
User struct {
- ID string `json:"id" gorm:"primaryKey;type:varchar(255);comment:鐢ㄦ埛ID"`
- Username string `json:"username" gorm:"index;type:varchar(255);comment:鐢ㄦ埛鐧诲綍鍚�"`
- UserType constvar.UserType `json:"userType" gorm:"type:int(11);comment:鐢ㄦ埛绫诲瀷 1瓒呯骇绠$悊鍛� 2涓昏处鎴� 3瀛愯处鎴�"`
- Password string `json:"-" gorm:"type:varchar(255);comment:鐢ㄦ埛鐧诲綍瀵嗙爜"`
- NickName string `json:"nickName" gorm:"type:varchar(255);default:绯荤粺鐢ㄦ埛;comment:鐢ㄦ埛鏄电О"`
- HeaderImg string `json:"headerImg" gorm:"type:varchar(255);comment:鐢ㄦ埛澶村儚"`
- Phone string `json:"phone" gorm:"type:varchar(255);comment:鐢ㄦ埛鎵嬫満鍙�"`
- Email string `json:"email" gorm:"type:varchar(255);comment:鐢ㄦ埛閭"`
- Enable bool `json:"enable" gorm:"type:tinyint(1);comment:鐢ㄦ埛鏄惁琚喕缁�"`
- ParentId string `json:"parentId" gorm:"type:varchar(255);comment:鐖剁敤鎴稩D"`
- ParentName string `json:"parentName" gorm:"type:varchar(255);comment:鐖剁敤鎴峰悕绉�"`
- CompanyName string `json:"companyName" gorm:"type:varchar(255);comment:鍏徃鍚嶇О"`
- Pos string `json:"pos" gorm:"type:varchar(255);comment:宀椾綅"`
- ModifiedPwd bool `json:"-" gorm:"type:tinyint(1);comment:鏄惁鏀硅繃瀵嗙爜"`
- CreateTime int64 `json:"-" gorm:"type:bigint(20);comment:鍒涘缓鏃堕棿"`
- UpdateTime int64 `json:"-" gorm:"type:bigint(20);comment:鏇存柊鏃堕棿"`
- Menus []Menu `json:"-" gorm:"many2many:user_menu;"` // 鐢ㄦ埛鑿滃崟
- CreateAt string `json:"createAt" gorm:"-"` // 鍒涘缓鏃堕棿
- UpdateAt string `json:"updateAt" gorm:"-"` // 鏇存柊鏃堕棿
- MenuIds []uint `json:"menuIds" gorm:"-"` // 鑿滃崟ID鍒楄〃
- Ip string `json:"ip" gorm:"type:varchar(255);comment:闆嗙兢Ip"`
- Port string `json:"port" gorm:"type:varchar(255);comment:绔彛鍙�"`
- Status int `json:"status" gorm:"type:int(11);comment:鐢ㄦ埛瀹℃牳鐘舵�� 0:绂佺敤; 1:姝e父; 2:瀹℃牳涓�"`
- AuthorityId uint `json:"authorityId" gorm:"default:888;comment:鐢ㄦ埛瑙掕壊ID"` // 鐢ㄦ埛瑙掕壊ID
- Authority Authority `json:"authority" gorm:"foreignKey:AuthorityId"`
+ ID string `json:"id" gorm:"primaryKey;type:varchar(255);comment:鐢ㄦ埛ID"`
+ Username string `json:"username" gorm:"index;type:varchar(255);comment:鐢ㄦ埛鐧诲綍鍚�"`
+ UserType constvar.UserType `json:"userType" gorm:"type:int(11);comment:鐢ㄦ埛绫诲瀷 1瓒呯骇绠$悊鍛� 2涓昏处鎴� 3瀛愯处鎴�"`
+ Password string `json:"-" gorm:"type:varchar(255);comment:鐢ㄦ埛鐧诲綍瀵嗙爜"`
+ NickName string `json:"nickName" gorm:"type:varchar(255);default:绯荤粺鐢ㄦ埛;comment:鐢ㄦ埛鏄电О"`
+ RealName string `json:"realName" gorm:"type:varchar(255);comment:鐢ㄦ埛鐪熷疄濮撳悕"`
+ DepartmentId int `json:"departmentId" gorm:"type:int(11);comment:鐢ㄦ埛閮ㄩ棬ID"`
+ HeaderImg string `json:"headerImg" gorm:"type:varchar(255);comment:鐢ㄦ埛澶村儚"`
+ Phone string `json:"phone" gorm:"type:varchar(255);comment:鐢ㄦ埛鎵嬫満鍙�"`
+ Email string `json:"email" gorm:"type:varchar(255);comment:鐢ㄦ埛閭"`
+ Pos string `json:"pos" gorm:"type:varchar(255);comment:宀椾綅"`
+ Menus []Menu `json:"-" gorm:"many2many:user_menu;"` // 鐢ㄦ埛鑿滃崟
+ MenuIds []uint `json:"menuIds" gorm:"-"` // 鑿滃崟ID鍒楄〃
+ AuthorityId uint `json:"authorityId" gorm:"default:888;comment:鐢ㄦ埛瑙掕壊ID"` // 鐢ㄦ埛瑙掕壊ID
+ Authority Authority `json:"authority" gorm:"foreignKey:AuthorityId"`
+ gorm.Model `json:"-"`
}
UserSearch struct {
@@ -50,28 +40,6 @@
func (slf User) TableName() string {
return "user"
-}
-
-func (slf *User) BeforeCreate(tx *gorm.DB) error {
- slf.CreateTime = time.Now().Unix()
- slf.UpdateTime = slf.CreateTime
- return nil
-}
-
-func (slf *User) BeforeSave(tx *gorm.DB) error {
- slf.UpdateTime = time.Now().Unix()
- return nil
-}
-
-func (slf *User) BeforeUpdate(tx *gorm.DB) error {
- slf.UpdateTime = time.Now().Unix()
- return nil
-}
-
-func (slf *User) AfterFind(tx *gorm.DB) error {
- slf.CreateAt = time.Unix(slf.CreateTime, 0).Format("2006-01-02 15:04:05")
- slf.UpdateAt = time.Unix(slf.UpdateTime, 0).Format("2006-01-02 15:04:05")
- return nil
}
func NewUserSearch(db *gorm.DB) *UserSearch {
@@ -101,16 +69,6 @@
return slf
}
-func (slf *UserSearch) SetParentId(parentId string) *UserSearch {
- slf.ParentId = parentId
- return slf
-}
-
-func (slf *UserSearch) SetParentName(parentName string) *UserSearch {
- slf.ParentName = parentName
- return slf
-}
-
func (slf *UserSearch) SetUserName(username string) *UserSearch {
slf.Username = username
return slf
@@ -130,10 +88,6 @@
if slf.Username != "" {
db = db.Where("username = ?", slf.Username)
- }
-
- if slf.ParentName != "" {
- db = db.Where("parent_name = ?", slf.ParentName)
}
if slf.Keyword != "" {
diff --git a/service/container_docker.go b/service/container_docker.go
index 949b21e..f456597 100644
--- a/service/container_docker.go
+++ b/service/container_docker.go
@@ -2,7 +2,6 @@
import (
"aps_crm/conf"
- "aps_crm/model"
"aps_crm/pkg/logx"
"aps_crm/utils"
"context"
@@ -232,18 +231,18 @@
}
func (slf *DockerImpl) initContainerNotFound() {
- users, _ := model.NewUserSearch(nil).FindNotTotal()
- for _, u := range users {
- if u.ParentId == "" { //鏄富璐﹀彿
- //鍒ゆ柇瀹瑰櫒鏄惁瀛樺湪鏃舵槸鍚﹂渶瑕佸姞閿侊紵鐢ㄦ埛娉ㄥ唽涓昏处鍙锋椂鏄紓姝ヨ姹傦紝鍒涘缓docker瀹瑰櫒娌℃湁鍐茬獊锛屽洜涓哄鍣ㄧ殑id涓嶅悓銆�
- //鎷夎捣瀹瑰櫒鍜岀敤鎴蜂富鍔ㄥ惎鍔ㄥ鍣ㄤ篃娌℃湁鏃堕棿鍐茬獊
- _, e := slf.Exist(u.ID)
- if e != ContainerNotFound {
- continue
- }
- if err := slf.Init(u.ID); err != nil {
- logx.Errorf("init ContainerNotFound err:", err)
- }
- }
- }
+ //users, _ := model.NewUserSearch(nil).FindNotTotal()
+ //for _, u := range users {
+ // if u.ParentId == "" { //鏄富璐﹀彿
+ // //鍒ゆ柇瀹瑰櫒鏄惁瀛樺湪鏃舵槸鍚﹂渶瑕佸姞閿侊紵鐢ㄦ埛娉ㄥ唽涓昏处鍙锋椂鏄紓姝ヨ姹傦紝鍒涘缓docker瀹瑰櫒娌℃湁鍐茬獊锛屽洜涓哄鍣ㄧ殑id涓嶅悓銆�
+ // //鎷夎捣瀹瑰櫒鍜岀敤鎴蜂富鍔ㄥ惎鍔ㄥ鍣ㄤ篃娌℃湁鏃堕棿鍐茬獊
+ // _, e := slf.Exist(u.ID)
+ // if e != ContainerNotFound {
+ // continue
+ // }
+ // if err := slf.Init(u.ID); err != nil {
+ // logx.Errorf("init ContainerNotFound err:", err)
+ // }
+ // }
+ //}
}
diff --git a/service/user.go b/service/user.go
index 7edac32..2adb136 100644
--- a/service/user.go
+++ b/service/user.go
@@ -57,9 +57,7 @@
if err != nil {
return err
}
- if user.Ip != "" {
- return errors.New("璇ョ敤鎴峰凡閰嶇疆闆嗙兢锛屾棤娉曞垹闄�")
- }
+
if user.UserType != constvar.UserTypeSub {
return errors.New("璇ョ敤鎴烽潪瀛愯处鎴凤紝鏃犳硶鍒犻櫎")
}
diff --git a/source/user.go b/source/user.go
index 6a901e0..a527b29 100644
--- a/source/user.go
+++ b/source/user.go
@@ -38,8 +38,8 @@
Password: adminPassword,
NickName: "admin",
UserType: constvar.UserTypeSuper,
- ParentId: "basic", // 瓒呯骇绠$悊鍛樿处鎴风殑鐖朵翰涓虹┖瀛楃涓诧紝鎴栬�呰捣涓悕瀛�
- Enable: true,
+ //ParentId: "basic", // 瓒呯骇绠$悊鍛樿处鎴风殑鐖朵翰涓虹┖瀛楃涓诧紝鎴栬�呰捣涓悕瀛�
+ //Enable: true,
},
}
if err = model.NewUserSearch(nil).CreateBatch(entities); err != nil {
--
Gitblit v1.8.0