fix group peers

This commit is contained in:
ljw
2024-09-24 19:35:20 +08:00
parent 95a1bd6c21
commit 0a81b5b5f8
11 changed files with 133 additions and 109 deletions

View File

@@ -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": {

View File

@@ -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": {

View File

@@ -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:

4
go.mod
View File

@@ -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

View File

@@ -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]

View File

@@ -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)
}

View File

@@ -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{})
}

View File

@@ -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 {

View File

@@ -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
}

View File

@@ -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{}

View File

@@ -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
}