diff --git a/docs/admin/admin_docs.go b/docs/admin/admin_docs.go index e1e407a..a9aaa58 100644 --- a/docs/admin/admin_docs.go +++ b/docs/admin/admin_docs.go @@ -1185,7 +1185,7 @@ const docTemplateadmin = `{ "token": [] } ], - "description": "创建机器", + "description": "创建设备", "consumes": [ "application/json" ], @@ -1193,12 +1193,12 @@ const docTemplateadmin = `{ "application/json" ], "tags": [ - "机器" + "设备" ], - "summary": "创建机器", + "summary": "创建设备", "parameters": [ { - "description": "机器信息", + "description": "设备信息", "name": "body", "in": "body", "required": true, @@ -1242,7 +1242,7 @@ const docTemplateadmin = `{ "token": [] } ], - "description": "机器删除", + "description": "设备删除", "consumes": [ "application/json" ], @@ -1250,12 +1250,12 @@ const docTemplateadmin = `{ "application/json" ], "tags": [ - "机器" + "设备" ], - "summary": "机器删除", + "summary": "设备删除", "parameters": [ { - "description": "机器信息", + "description": "设备信息", "name": "body", "in": "body", "required": true, @@ -1287,7 +1287,7 @@ const docTemplateadmin = `{ "token": [] } ], - "description": "机器详情", + "description": "设备详情", "consumes": [ "application/json" ], @@ -1295,9 +1295,9 @@ const docTemplateadmin = `{ "application/json" ], "tags": [ - "机器" + "设备" ], - "summary": "机器详情", + "summary": "设备详情", "parameters": [ { "type": "integer", @@ -1342,7 +1342,7 @@ const docTemplateadmin = `{ "token": [] } ], - "description": "机器列表", + "description": "设备列表", "consumes": [ "application/json" ], @@ -1350,9 +1350,9 @@ const docTemplateadmin = `{ "application/json" ], "tags": [ - "机器" + "设备" ], - "summary": "机器列表", + "summary": "设备列表", "parameters": [ { "type": "integer", @@ -1402,7 +1402,7 @@ const docTemplateadmin = `{ "token": [] } ], - "description": "机器编辑", + "description": "设备编辑", "consumes": [ "application/json" ], @@ -1410,12 +1410,12 @@ const docTemplateadmin = `{ "application/json" ], "tags": [ - "机器" + "设备" ], - "summary": "机器编辑", + "summary": "设备编辑", "parameters": [ { - "description": "机器信息", + "description": "设备信息", "name": "body", "in": "body", "required": true, @@ -2278,7 +2278,7 @@ const docTemplateadmin = `{ "id": { "type": "string" }, - "login_name": { + "loginName": { "type": "string" }, "online": { @@ -2290,16 +2290,16 @@ const docTemplateadmin = `{ "platform": { "type": "string" }, - "rdp_port": { + "rdpPort": { "type": "string" }, - "rdp_username": { + "rdpUsername": { "type": "string" }, "row_id": { "type": "integer" }, - "same_server": { + "sameServer": { "type": "boolean" }, "tags": { diff --git a/docs/admin/admin_swagger.json b/docs/admin/admin_swagger.json index c1cf17a..face353 100644 --- a/docs/admin/admin_swagger.json +++ b/docs/admin/admin_swagger.json @@ -1178,7 +1178,7 @@ "token": [] } ], - "description": "创建机器", + "description": "创建设备", "consumes": [ "application/json" ], @@ -1186,12 +1186,12 @@ "application/json" ], "tags": [ - "机器" + "设备" ], - "summary": "创建机器", + "summary": "创建设备", "parameters": [ { - "description": "机器信息", + "description": "设备信息", "name": "body", "in": "body", "required": true, @@ -1235,7 +1235,7 @@ "token": [] } ], - "description": "机器删除", + "description": "设备删除", "consumes": [ "application/json" ], @@ -1243,12 +1243,12 @@ "application/json" ], "tags": [ - "机器" + "设备" ], - "summary": "机器删除", + "summary": "设备删除", "parameters": [ { - "description": "机器信息", + "description": "设备信息", "name": "body", "in": "body", "required": true, @@ -1280,7 +1280,7 @@ "token": [] } ], - "description": "机器详情", + "description": "设备详情", "consumes": [ "application/json" ], @@ -1288,9 +1288,9 @@ "application/json" ], "tags": [ - "机器" + "设备" ], - "summary": "机器详情", + "summary": "设备详情", "parameters": [ { "type": "integer", @@ -1335,7 +1335,7 @@ "token": [] } ], - "description": "机器列表", + "description": "设备列表", "consumes": [ "application/json" ], @@ -1343,9 +1343,9 @@ "application/json" ], "tags": [ - "机器" + "设备" ], - "summary": "机器列表", + "summary": "设备列表", "parameters": [ { "type": "integer", @@ -1395,7 +1395,7 @@ "token": [] } ], - "description": "机器编辑", + "description": "设备编辑", "consumes": [ "application/json" ], @@ -1403,12 +1403,12 @@ "application/json" ], "tags": [ - "机器" + "设备" ], - "summary": "机器编辑", + "summary": "设备编辑", "parameters": [ { - "description": "机器信息", + "description": "设备信息", "name": "body", "in": "body", "required": true, @@ -2271,7 +2271,7 @@ "id": { "type": "string" }, - "login_name": { + "loginName": { "type": "string" }, "online": { @@ -2283,16 +2283,16 @@ "platform": { "type": "string" }, - "rdp_port": { + "rdpPort": { "type": "string" }, - "rdp_username": { + "rdpUsername": { "type": "string" }, "row_id": { "type": "integer" }, - "same_server": { + "sameServer": { "type": "boolean" }, "tags": { diff --git a/docs/admin/admin_swagger.yaml b/docs/admin/admin_swagger.yaml index 4145945..4facc11 100644 --- a/docs/admin/admin_swagger.yaml +++ b/docs/admin/admin_swagger.yaml @@ -24,7 +24,7 @@ definitions: type: string id: type: string - login_name: + loginName: type: string online: type: boolean @@ -32,13 +32,13 @@ definitions: type: string platform: type: string - rdp_port: + rdpPort: type: string - rdp_username: + rdpUsername: type: string row_id: type: integer - same_server: + sameServer: type: boolean tags: items: @@ -1162,9 +1162,9 @@ paths: post: consumes: - application/json - description: 创建机器 + description: 创建设备 parameters: - - description: 机器信息 + - description: 设备信息 in: body name: body required: true @@ -1188,16 +1188,16 @@ paths: $ref: '#/definitions/response.Response' security: - token: [] - summary: 创建机器 + summary: 创建设备 tags: - - 机器 + - 设备 /admin/peer/delete: post: consumes: - application/json - description: 机器删除 + description: 设备删除 parameters: - - description: 机器信息 + - description: 设备信息 in: body name: body required: true @@ -1216,14 +1216,14 @@ paths: $ref: '#/definitions/response.Response' security: - token: [] - summary: 机器删除 + summary: 设备删除 tags: - - 机器 + - 设备 /admin/peer/detail/{id}: get: consumes: - application/json - description: 机器详情 + description: 设备详情 parameters: - description: ID in: path @@ -1248,14 +1248,14 @@ paths: $ref: '#/definitions/response.Response' security: - token: [] - summary: 机器详情 + summary: 设备详情 tags: - - 机器 + - 设备 /admin/peer/list: get: consumes: - application/json - description: 机器列表 + description: 设备列表 parameters: - description: 页码 in: query @@ -1283,16 +1283,16 @@ paths: $ref: '#/definitions/response.Response' security: - token: [] - summary: 机器列表 + summary: 设备列表 tags: - - 机器 + - 设备 /admin/peer/update: post: consumes: - application/json - description: 机器编辑 + description: 设备编辑 parameters: - - description: 机器信息 + - description: 设备信息 in: body name: body required: true @@ -1316,9 +1316,9 @@ paths: $ref: '#/definitions/response.Response' security: - token: [] - summary: 机器编辑 + summary: 设备编辑 tags: - - 机器 + - 设备 /admin/server-config: get: consumes: diff --git a/go.mod b/go.mod index ccde1dd..e0ba8fc 100644 --- a/go.mod +++ b/go.mod @@ -3,6 +3,7 @@ module Gwen go 1.22 require ( + github.com/BurntSushi/toml v1.3.2 github.com/antonfisher/nested-logrus-formatter v1.3.1 github.com/fsnotify/fsnotify v1.5.1 github.com/fvbock/endless v0.0.0-20170109170031-447134032cb6 @@ -12,12 +13,14 @@ require ( github.com/go-playground/validator/v10 v10.11.2 github.com/go-redis/redis/v8 v8.11.4 github.com/golang-jwt/jwt/v5 v5.2.1 + github.com/nicksnyder/go-i18n/v2 v2.4.0 github.com/sirupsen/logrus v1.8.1 github.com/spf13/viper v1.9.0 github.com/swaggo/files v1.0.1 github.com/swaggo/gin-swagger v1.6.0 github.com/swaggo/swag v1.16.3 golang.org/x/oauth2 v0.23.0 + golang.org/x/text v0.15.0 gorm.io/driver/mysql v1.5.7 gorm.io/driver/sqlite v1.5.6 gorm.io/gorm v1.25.7 @@ -66,7 +69,6 @@ require ( golang.org/x/crypto v0.23.0 // indirect golang.org/x/net v0.21.0 // indirect golang.org/x/sys v0.25.0 // indirect - golang.org/x/text v0.15.0 // indirect golang.org/x/tools v0.7.0 // indirect google.golang.org/protobuf v1.33.0 // indirect gopkg.in/ini.v1 v1.63.2 // indirect diff --git a/http/controller/admin/peer.go b/http/controller/admin/peer.go index 5ab048d..8a1994d 100644 --- a/http/controller/admin/peer.go +++ b/http/controller/admin/peer.go @@ -12,10 +12,10 @@ import ( type Peer struct { } -// Detail 机器 -// @Tags 机器 -// @Summary 机器详情 -// @Description 机器详情 +// Detail 设备 +// @Tags 设备 +// @Summary 设备详情 +// @Description 设备详情 // @Accept json // @Produce json // @Param id path int true "ID" @@ -35,13 +35,13 @@ func (ct *Peer) Detail(c *gin.Context) { return } -// Create 创建机器 -// @Tags 机器 -// @Summary 创建机器 -// @Description 创建机器 +// Create 创建设备 +// @Tags 设备 +// @Summary 创建设备 +// @Description 创建设备 // @Accept json // @Produce json -// @Param body body admin.PeerForm true "机器信息" +// @Param body body admin.PeerForm true "设备信息" // @Success 200 {object} response.Response{data=model.Peer} // @Failure 500 {object} response.Response // @Router /admin/peer/create [post] @@ -67,9 +67,9 @@ func (ct *Peer) Create(c *gin.Context) { } // List 列表 -// @Tags 机器 -// @Summary 机器列表 -// @Description 机器列表 +// @Tags 设备 +// @Summary 设备列表 +// @Description 设备列表 // @Accept json // @Produce json // @Param page query int false "页码" @@ -89,12 +89,12 @@ func (ct *Peer) List(c *gin.Context) { } // Update 编辑 -// @Tags 机器 -// @Summary 机器编辑 -// @Description 机器编辑 +// @Tags 设备 +// @Summary 设备编辑 +// @Description 设备编辑 // @Accept json // @Produce json -// @Param body body admin.PeerForm true "机器信息" +// @Param body body admin.PeerForm true "设备信息" // @Success 200 {object} response.Response{data=model.Peer} // @Failure 500 {object} response.Response // @Router /admin/peer/update [post] @@ -124,12 +124,12 @@ func (ct *Peer) Update(c *gin.Context) { } // Delete 删除 -// @Tags 机器 -// @Summary 机器删除 -// @Description 机器删除 +// @Tags 设备 +// @Summary 设备删除 +// @Description 设备删除 // @Accept json // @Produce json -// @Param body body admin.PeerForm true "机器信息" +// @Param body body admin.PeerForm true "设备信息" // @Success 200 {object} response.Response // @Failure 500 {object} response.Response // @Router /admin/peer/delete [post] diff --git a/http/controller/api/group.go b/http/controller/api/group.go index 31c3c0f..4965d29 100644 --- a/http/controller/api/group.go +++ b/http/controller/api/group.go @@ -96,15 +96,15 @@ func (g *Group) Peers(c *gin.Context) { namesById[user.Id] = user.Username userIds = append(userIds, user.Id) } - peerList := service.AllService.AddressBookService.ListByUserIds(userIds, q.Page, q.PageSize) + peerList := service.AllService.PeerService.ListByUserIds(userIds, q.Page, q.PageSize) var data []*apiResp.GroupPeerPayload - for _, ab := range peerList.AddressBooks { - uname, ok := namesById[ab.UserId] + for _, peer := range peerList.Peers { + uname, ok := namesById[peer.UserId] if !ok { uname = "" } pp := &apiResp.GroupPeerPayload{} - pp.FromAddressBook(ab, uname) + pp.FromPeer(peer, uname) data = append(data, pp) } diff --git a/http/controller/api/index.go b/http/controller/api/index.go index e58f2bc..bb0ff08 100644 --- a/http/controller/api/index.go +++ b/http/controller/api/index.go @@ -35,5 +35,10 @@ func (i *Index) Index(c *gin.Context) { // @Failure 500 {object} response.Response // @Router /heartbeat [post] func (i *Index) Heartbeat(c *gin.Context) { + //b := &gin.H{} + //err := c.BindJSON(b) + //body : &map[id:ljwzhuwo modified_at:0 uuid:NGIxZTZjM2YtNmNkMy00YTMwLWFiNjQtMzQ0MTA0NGE5ZDgz ver:1.003e+06] + //fmt.Println(b, err, c.Request.Header) + //header : map[Accept:[*/*] Accept-Encoding:[gzip] Content-Length:[105] Content-Type:[application/json]] c.JSON(http.StatusOK, gin.H{}) } diff --git a/http/request/admin/addressBook.go b/http/request/admin/addressBook.go index 546495f..a6f85e9 100644 --- a/http/request/admin/addressBook.go +++ b/http/request/admin/addressBook.go @@ -17,11 +17,11 @@ type AddressBookForm struct { Hash string `json:"hash"` UserId uint `json:"user_id"` ForceAlwaysRelay bool `json:"forceAlwaysRelay"` - RdpPort string `json:"rdp_port"` - RdpUsername string `json:"rdp_username"` + RdpPort string `json:"rdpPort"` + RdpUsername string `json:"rdpUsername"` Online bool `json:"online"` - LoginName string `json:"login_name" ` - SameServer bool `json:"same_server"` + LoginName string `json:"loginName" ` + SameServer bool `json:"sameServer"` } func (a AddressBookForm) ToAddressBook() *model.AddressBook { diff --git a/http/response/api/peer.go b/http/response/api/peer.go index 92cf623..875aacb 100644 --- a/http/response/api/peer.go +++ b/http/response/api/peer.go @@ -59,7 +59,7 @@ func (gpp *GroupPeerPayload) FromAddressBook(a *model.AddressBook, username stri gpp.UserName = username } -func (gpp *GroupPeerPayload) FromPeer(p *model.Peer) { +func (gpp *GroupPeerPayload) FromPeer(p *model.Peer, username string) { gpp.Id = p.Id gpp.Info = &PeerPayloadInfo{ DeviceName: p.Hostname, @@ -67,5 +67,5 @@ func (gpp *GroupPeerPayload) FromPeer(p *model.Peer) { Username: p.Username, } gpp.Note = "" - gpp.UserName = p.User.Username + gpp.UserName = username } diff --git a/service/peer.go b/service/peer.go index f654dc4..558afcc 100644 --- a/service/peer.go +++ b/service/peer.go @@ -15,24 +15,38 @@ func (ps *PeerService) FindById(id string) *model.Peer { global.DB.Where("id = ?", id).First(p) return p } +func (ps *PeerService) FindByUuid(uuid string) *model.Peer { + p := &model.Peer{} + global.DB.Where("uuid = ?", uuid).First(p) + return p +} func (ps *PeerService) InfoByRowId(id uint) *model.Peer { p := &model.Peer{} global.DB.Where("row_id = ?", id).First(p) return p } -//// ListByUserIds 根据用户id取列表 -//func (ps *PeerService) ListByUserIds(userIds []uint, page, pageSize uint) (res *model.PeerList) { -// res = &model.PeerList{} -// res.Page = int64(page) -// res.PageSize = int64(pageSize) -// tx := global.DB.Model(&model.Peer{}).Preload("User") -// tx.Where("user_id in (?)", userIds) -// tx.Count(&res.Total) -// tx.Scopes(Paginate(page, pageSize)) -// tx.Find(&res.Peers) -// return -//} +// UuidBindUserId 绑定用户id +func (ps *PeerService) UuidBindUserId(uuid string, userId uint) { + peer := ps.FindByUuid(uuid) + if peer.RowId > 0 { + peer.UserId = userId + ps.Update(peer) + } +} + +// ListByUserIds 根据用户id取列表 +func (ps *PeerService) ListByUserIds(userIds []uint, page, pageSize uint) (res *model.PeerList) { + res = &model.PeerList{} + res.Page = int64(page) + res.PageSize = int64(pageSize) + tx := global.DB.Model(&model.Peer{}) + tx.Where("user_id in (?)", userIds) + tx.Count(&res.Total) + tx.Scopes(Paginate(page, pageSize)) + tx.Find(&res.Peers) + return +} func (ps *PeerService) List(page, pageSize uint, where func(tx *gorm.DB)) (res *model.PeerList) { res = &model.PeerList{} diff --git a/service/user.go b/service/user.go index 86d1cae..d93797b 100644 --- a/service/user.go +++ b/service/user.go @@ -66,6 +66,9 @@ func (us *UserService) Login(u *model.User, llog *model.LoginLog) *model.UserTok } global.DB.Create(ut) global.DB.Create(llog) + if llog.Uuid != "" { + AllService.PeerService.UuidBindUserId(llog.Uuid, u.Id) + } return ut }