Просмотр исходного кода

feat(api): Add device group for 1.3.8

lejianwen месяцев назад: 11
Родитель
Сommit
ef4af39f94

+ 2 - 1
cmd/apimain.go

@@ -166,7 +166,7 @@ func InitGlobal() {
166 166
 	global.Lock = lock.NewLocal()
167 167
 }
168 168
 func DatabaseAutoUpdate() {
169
-	version := 261
169
+	version := 262
170 170
 
171 171
 	db := global.DB
172 172
 
@@ -251,6 +251,7 @@ func Migrate(version uint) {
251 251
 		&model.AddressBookCollection{},
252 252
 		&model.AddressBookCollectionRule{},
253 253
 		&model.ServerCmd{},
254
+		&model.DeviceGroup{},
254 255
 	)
255 256
 	if err != nil {
256 257
 		global.Logger.Error("migrate err :=>", err)

+ 325 - 2
docs/admin/admin_docs.go

@@ -1407,6 +1407,280 @@ const docTemplateadmin = `{
1407 1407
                 }
1408 1408
             }
1409 1409
         },
1410
+        "/admin/device_group/create": {
1411
+            "post": {
1412
+                "security": [
1413
+                    {
1414
+                        "token": []
1415
+                    }
1416
+                ],
1417
+                "description": "创建设备群组",
1418
+                "consumes": [
1419
+                    "application/json"
1420
+                ],
1421
+                "produces": [
1422
+                    "application/json"
1423
+                ],
1424
+                "tags": [
1425
+                    "设备群组"
1426
+                ],
1427
+                "summary": "创建设备群组",
1428
+                "parameters": [
1429
+                    {
1430
+                        "description": "设备群组信息",
1431
+                        "name": "body",
1432
+                        "in": "body",
1433
+                        "required": true,
1434
+                        "schema": {
1435
+                            "$ref": "#/definitions/admin.DeviceGroupForm"
1436
+                        }
1437
+                    }
1438
+                ],
1439
+                "responses": {
1440
+                    "200": {
1441
+                        "description": "OK",
1442
+                        "schema": {
1443
+                            "allOf": [
1444
+                                {
1445
+                                    "$ref": "#/definitions/response.Response"
1446
+                                },
1447
+                                {
1448
+                                    "type": "object",
1449
+                                    "properties": {
1450
+                                        "data": {
1451
+                                            "$ref": "#/definitions/model.DeviceGroup"
1452
+                                        }
1453
+                                    }
1454
+                                }
1455
+                            ]
1456
+                        }
1457
+                    },
1458
+                    "500": {
1459
+                        "description": "Internal Server Error",
1460
+                        "schema": {
1461
+                            "$ref": "#/definitions/response.Response"
1462
+                        }
1463
+                    }
1464
+                }
1465
+            }
1466
+        },
1467
+        "/admin/device_group/delete": {
1468
+            "post": {
1469
+                "security": [
1470
+                    {
1471
+                        "token": []
1472
+                    }
1473
+                ],
1474
+                "description": "设备群组删除",
1475
+                "consumes": [
1476
+                    "application/json"
1477
+                ],
1478
+                "produces": [
1479
+                    "application/json"
1480
+                ],
1481
+                "tags": [
1482
+                    "设备群组"
1483
+                ],
1484
+                "summary": "设备群组删除",
1485
+                "parameters": [
1486
+                    {
1487
+                        "description": "群组信息",
1488
+                        "name": "body",
1489
+                        "in": "body",
1490
+                        "required": true,
1491
+                        "schema": {
1492
+                            "$ref": "#/definitions/admin.DeviceGroupForm"
1493
+                        }
1494
+                    }
1495
+                ],
1496
+                "responses": {
1497
+                    "200": {
1498
+                        "description": "OK",
1499
+                        "schema": {
1500
+                            "$ref": "#/definitions/response.Response"
1501
+                        }
1502
+                    },
1503
+                    "500": {
1504
+                        "description": "Internal Server Error",
1505
+                        "schema": {
1506
+                            "$ref": "#/definitions/response.Response"
1507
+                        }
1508
+                    }
1509
+                }
1510
+            }
1511
+        },
1512
+        "/admin/device_group/detail/{id}": {
1513
+            "get": {
1514
+                "security": [
1515
+                    {
1516
+                        "token": []
1517
+                    }
1518
+                ],
1519
+                "description": "设备群组详情",
1520
+                "consumes": [
1521
+                    "application/json"
1522
+                ],
1523
+                "produces": [
1524
+                    "application/json"
1525
+                ],
1526
+                "tags": [
1527
+                    "设备群组"
1528
+                ],
1529
+                "summary": "设备群组详情",
1530
+                "parameters": [
1531
+                    {
1532
+                        "type": "integer",
1533
+                        "description": "ID",
1534
+                        "name": "id",
1535
+                        "in": "path",
1536
+                        "required": true
1537
+                    }
1538
+                ],
1539
+                "responses": {
1540
+                    "200": {
1541
+                        "description": "OK",
1542
+                        "schema": {
1543
+                            "allOf": [
1544
+                                {
1545
+                                    "$ref": "#/definitions/response.Response"
1546
+                                },
1547
+                                {
1548
+                                    "type": "object",
1549
+                                    "properties": {
1550
+                                        "data": {
1551
+                                            "$ref": "#/definitions/model.Group"
1552
+                                        }
1553
+                                    }
1554
+                                }
1555
+                            ]
1556
+                        }
1557
+                    },
1558
+                    "500": {
1559
+                        "description": "Internal Server Error",
1560
+                        "schema": {
1561
+                            "$ref": "#/definitions/response.Response"
1562
+                        }
1563
+                    }
1564
+                }
1565
+            }
1566
+        },
1567
+        "/admin/device_group/list": {
1568
+            "get": {
1569
+                "security": [
1570
+                    {
1571
+                        "token": []
1572
+                    }
1573
+                ],
1574
+                "description": "群组列表",
1575
+                "consumes": [
1576
+                    "application/json"
1577
+                ],
1578
+                "produces": [
1579
+                    "application/json"
1580
+                ],
1581
+                "tags": [
1582
+                    "群组"
1583
+                ],
1584
+                "summary": "群组列表",
1585
+                "parameters": [
1586
+                    {
1587
+                        "type": "integer",
1588
+                        "description": "页码",
1589
+                        "name": "page",
1590
+                        "in": "query"
1591
+                    },
1592
+                    {
1593
+                        "type": "integer",
1594
+                        "description": "页大小",
1595
+                        "name": "page_size",
1596
+                        "in": "query"
1597
+                    }
1598
+                ],
1599
+                "responses": {
1600
+                    "200": {
1601
+                        "description": "OK",
1602
+                        "schema": {
1603
+                            "allOf": [
1604
+                                {
1605
+                                    "$ref": "#/definitions/response.Response"
1606
+                                },
1607
+                                {
1608
+                                    "type": "object",
1609
+                                    "properties": {
1610
+                                        "data": {
1611
+                                            "$ref": "#/definitions/model.GroupList"
1612
+                                        }
1613
+                                    }
1614
+                                }
1615
+                            ]
1616
+                        }
1617
+                    },
1618
+                    "500": {
1619
+                        "description": "Internal Server Error",
1620
+                        "schema": {
1621
+                            "$ref": "#/definitions/response.Response"
1622
+                        }
1623
+                    }
1624
+                }
1625
+            }
1626
+        },
1627
+        "/admin/device_group/update": {
1628
+            "post": {
1629
+                "security": [
1630
+                    {
1631
+                        "token": []
1632
+                    }
1633
+                ],
1634
+                "description": "设备群组编辑",
1635
+                "consumes": [
1636
+                    "application/json"
1637
+                ],
1638
+                "produces": [
1639
+                    "application/json"
1640
+                ],
1641
+                "tags": [
1642
+                    "设备群组"
1643
+                ],
1644
+                "summary": "设备群组编辑",
1645
+                "parameters": [
1646
+                    {
1647
+                        "description": "群组信息",
1648
+                        "name": "body",
1649
+                        "in": "body",
1650
+                        "required": true,
1651
+                        "schema": {
1652
+                            "$ref": "#/definitions/admin.DeviceGroupForm"
1653
+                        }
1654
+                    }
1655
+                ],
1656
+                "responses": {
1657
+                    "200": {
1658
+                        "description": "OK",
1659
+                        "schema": {
1660
+                            "allOf": [
1661
+                                {
1662
+                                    "$ref": "#/definitions/response.Response"
1663
+                                },
1664
+                                {
1665
+                                    "type": "object",
1666
+                                    "properties": {
1667
+                                        "data": {
1668
+                                            "$ref": "#/definitions/model.Group"
1669
+                                        }
1670
+                                    }
1671
+                                }
1672
+                            ]
1673
+                        }
1674
+                    },
1675
+                    "500": {
1676
+                        "description": "Internal Server Error",
1677
+                        "schema": {
1678
+                            "$ref": "#/definitions/response.Response"
1679
+                        }
1680
+                    }
1681
+                }
1682
+            }
1683
+        },
1410 1684
         "/admin/file/oss_token": {
1411 1685
             "get": {
1412 1686
                 "security": [
@@ -1783,7 +2057,7 @@ const docTemplateadmin = `{
1783 2057
                         "in": "body",
1784 2058
                         "required": true,
1785 2059
                         "schema": {
1786
-                            "$ref": "#/definitions/github_com_lejianwen_rustdesk-api_http_request_admin.Login"
2060
+                            "$ref": "#/definitions/github_com_lejianwen_rustdesk-api_v2_http_request_admin.Login"
1787 2061
                         }
1788 2062
                     }
1789 2063
                 ],
@@ -5219,6 +5493,20 @@ const docTemplateadmin = `{
5219 5493
                 }
5220 5494
             }
5221 5495
         },
5496
+        "admin.DeviceGroupForm": {
5497
+            "type": "object",
5498
+            "required": [
5499
+                "name"
5500
+            ],
5501
+            "properties": {
5502
+                "id": {
5503
+                    "type": "integer"
5504
+                },
5505
+                "name": {
5506
+                    "type": "string"
5507
+                }
5508
+            }
5509
+        },
5222 5510
         "admin.GroupForm": {
5223 5511
             "type": "object",
5224 5512
             "required": [
@@ -5306,6 +5594,12 @@ const docTemplateadmin = `{
5306 5594
                 "op": {
5307 5595
                     "type": "string"
5308 5596
                 },
5597
+                "pkce_enable": {
5598
+                    "type": "boolean"
5599
+                },
5600
+                "pkce_method": {
5601
+                    "type": "string"
5602
+                },
5309 5603
                 "redirect_url": {
5310 5604
                     "type": "string"
5311 5605
                 },
@@ -5334,6 +5628,9 @@ const docTemplateadmin = `{
5334 5628
                 "cpu": {
5335 5629
                     "type": "string"
5336 5630
                 },
5631
+                "group_id": {
5632
+                    "type": "integer"
5633
+                },
5337 5634
                 "hostname": {
5338 5635
                     "type": "string"
5339 5636
                 },
@@ -5521,7 +5818,7 @@ const docTemplateadmin = `{
5521 5818
                 }
5522 5819
             }
5523 5820
         },
5524
-        "github_com_lejianwen_rustdesk-api_http_request_admin.Login": {
5821
+        "github_com_lejianwen_rustdesk-api_v2_http_request_admin.Login": {
5525 5822
             "type": "object",
5526 5823
             "required": [
5527 5824
                 "password",
@@ -5842,6 +6139,23 @@ const docTemplateadmin = `{
5842 6139
                 }
5843 6140
             }
5844 6141
         },
6142
+        "model.DeviceGroup": {
6143
+            "type": "object",
6144
+            "properties": {
6145
+                "created_at": {
6146
+                    "type": "string"
6147
+                },
6148
+                "id": {
6149
+                    "type": "integer"
6150
+                },
6151
+                "name": {
6152
+                    "type": "string"
6153
+                },
6154
+                "updated_at": {
6155
+                    "type": "string"
6156
+                }
6157
+            }
6158
+        },
5845 6159
         "model.Group": {
5846 6160
             "type": "object",
5847 6161
             "properties": {
@@ -5973,6 +6287,12 @@ const docTemplateadmin = `{
5973 6287
                 "op": {
5974 6288
                     "type": "string"
5975 6289
                 },
6290
+                "pkce_enable": {
6291
+                    "type": "boolean"
6292
+                },
6293
+                "pkce_method": {
6294
+                    "type": "string"
6295
+                },
5976 6296
                 "redirect_url": {
5977 6297
                     "type": "string"
5978 6298
                 },
@@ -6013,6 +6333,9 @@ const docTemplateadmin = `{
6013 6333
                 "created_at": {
6014 6334
                     "type": "string"
6015 6335
                 },
6336
+                "group_id": {
6337
+                    "type": "integer"
6338
+                },
6016 6339
                 "hostname": {
6017 6340
                     "type": "string"
6018 6341
                 },

+ 325 - 2
docs/admin/admin_swagger.json

@@ -1400,6 +1400,280 @@
1400 1400
                 }
1401 1401
             }
1402 1402
         },
1403
+        "/admin/device_group/create": {
1404
+            "post": {
1405
+                "security": [
1406
+                    {
1407
+                        "token": []
1408
+                    }
1409
+                ],
1410
+                "description": "创建设备群组",
1411
+                "consumes": [
1412
+                    "application/json"
1413
+                ],
1414
+                "produces": [
1415
+                    "application/json"
1416
+                ],
1417
+                "tags": [
1418
+                    "设备群组"
1419
+                ],
1420
+                "summary": "创建设备群组",
1421
+                "parameters": [
1422
+                    {
1423
+                        "description": "设备群组信息",
1424
+                        "name": "body",
1425
+                        "in": "body",
1426
+                        "required": true,
1427
+                        "schema": {
1428
+                            "$ref": "#/definitions/admin.DeviceGroupForm"
1429
+                        }
1430
+                    }
1431
+                ],
1432
+                "responses": {
1433
+                    "200": {
1434
+                        "description": "OK",
1435
+                        "schema": {
1436
+                            "allOf": [
1437
+                                {
1438
+                                    "$ref": "#/definitions/response.Response"
1439
+                                },
1440
+                                {
1441
+                                    "type": "object",
1442
+                                    "properties": {
1443
+                                        "data": {
1444
+                                            "$ref": "#/definitions/model.DeviceGroup"
1445
+                                        }
1446
+                                    }
1447
+                                }
1448
+                            ]
1449
+                        }
1450
+                    },
1451
+                    "500": {
1452
+                        "description": "Internal Server Error",
1453
+                        "schema": {
1454
+                            "$ref": "#/definitions/response.Response"
1455
+                        }
1456
+                    }
1457
+                }
1458
+            }
1459
+        },
1460
+        "/admin/device_group/delete": {
1461
+            "post": {
1462
+                "security": [
1463
+                    {
1464
+                        "token": []
1465
+                    }
1466
+                ],
1467
+                "description": "设备群组删除",
1468
+                "consumes": [
1469
+                    "application/json"
1470
+                ],
1471
+                "produces": [
1472
+                    "application/json"
1473
+                ],
1474
+                "tags": [
1475
+                    "设备群组"
1476
+                ],
1477
+                "summary": "设备群组删除",
1478
+                "parameters": [
1479
+                    {
1480
+                        "description": "群组信息",
1481
+                        "name": "body",
1482
+                        "in": "body",
1483
+                        "required": true,
1484
+                        "schema": {
1485
+                            "$ref": "#/definitions/admin.DeviceGroupForm"
1486
+                        }
1487
+                    }
1488
+                ],
1489
+                "responses": {
1490
+                    "200": {
1491
+                        "description": "OK",
1492
+                        "schema": {
1493
+                            "$ref": "#/definitions/response.Response"
1494
+                        }
1495
+                    },
1496
+                    "500": {
1497
+                        "description": "Internal Server Error",
1498
+                        "schema": {
1499
+                            "$ref": "#/definitions/response.Response"
1500
+                        }
1501
+                    }
1502
+                }
1503
+            }
1504
+        },
1505
+        "/admin/device_group/detail/{id}": {
1506
+            "get": {
1507
+                "security": [
1508
+                    {
1509
+                        "token": []
1510
+                    }
1511
+                ],
1512
+                "description": "设备群组详情",
1513
+                "consumes": [
1514
+                    "application/json"
1515
+                ],
1516
+                "produces": [
1517
+                    "application/json"
1518
+                ],
1519
+                "tags": [
1520
+                    "设备群组"
1521
+                ],
1522
+                "summary": "设备群组详情",
1523
+                "parameters": [
1524
+                    {
1525
+                        "type": "integer",
1526
+                        "description": "ID",
1527
+                        "name": "id",
1528
+                        "in": "path",
1529
+                        "required": true
1530
+                    }
1531
+                ],
1532
+                "responses": {
1533
+                    "200": {
1534
+                        "description": "OK",
1535
+                        "schema": {
1536
+                            "allOf": [
1537
+                                {
1538
+                                    "$ref": "#/definitions/response.Response"
1539
+                                },
1540
+                                {
1541
+                                    "type": "object",
1542
+                                    "properties": {
1543
+                                        "data": {
1544
+                                            "$ref": "#/definitions/model.Group"
1545
+                                        }
1546
+                                    }
1547
+                                }
1548
+                            ]
1549
+                        }
1550
+                    },
1551
+                    "500": {
1552
+                        "description": "Internal Server Error",
1553
+                        "schema": {
1554
+                            "$ref": "#/definitions/response.Response"
1555
+                        }
1556
+                    }
1557
+                }
1558
+            }
1559
+        },
1560
+        "/admin/device_group/list": {
1561
+            "get": {
1562
+                "security": [
1563
+                    {
1564
+                        "token": []
1565
+                    }
1566
+                ],
1567
+                "description": "群组列表",
1568
+                "consumes": [
1569
+                    "application/json"
1570
+                ],
1571
+                "produces": [
1572
+                    "application/json"
1573
+                ],
1574
+                "tags": [
1575
+                    "群组"
1576
+                ],
1577
+                "summary": "群组列表",
1578
+                "parameters": [
1579
+                    {
1580
+                        "type": "integer",
1581
+                        "description": "页码",
1582
+                        "name": "page",
1583
+                        "in": "query"
1584
+                    },
1585
+                    {
1586
+                        "type": "integer",
1587
+                        "description": "页大小",
1588
+                        "name": "page_size",
1589
+                        "in": "query"
1590
+                    }
1591
+                ],
1592
+                "responses": {
1593
+                    "200": {
1594
+                        "description": "OK",
1595
+                        "schema": {
1596
+                            "allOf": [
1597
+                                {
1598
+                                    "$ref": "#/definitions/response.Response"
1599
+                                },
1600
+                                {
1601
+                                    "type": "object",
1602
+                                    "properties": {
1603
+                                        "data": {
1604
+                                            "$ref": "#/definitions/model.GroupList"
1605
+                                        }
1606
+                                    }
1607
+                                }
1608
+                            ]
1609
+                        }
1610
+                    },
1611
+                    "500": {
1612
+                        "description": "Internal Server Error",
1613
+                        "schema": {
1614
+                            "$ref": "#/definitions/response.Response"
1615
+                        }
1616
+                    }
1617
+                }
1618
+            }
1619
+        },
1620
+        "/admin/device_group/update": {
1621
+            "post": {
1622
+                "security": [
1623
+                    {
1624
+                        "token": []
1625
+                    }
1626
+                ],
1627
+                "description": "设备群组编辑",
1628
+                "consumes": [
1629
+                    "application/json"
1630
+                ],
1631
+                "produces": [
1632
+                    "application/json"
1633
+                ],
1634
+                "tags": [
1635
+                    "设备群组"
1636
+                ],
1637
+                "summary": "设备群组编辑",
1638
+                "parameters": [
1639
+                    {
1640
+                        "description": "群组信息",
1641
+                        "name": "body",
1642
+                        "in": "body",
1643
+                        "required": true,
1644
+                        "schema": {
1645
+                            "$ref": "#/definitions/admin.DeviceGroupForm"
1646
+                        }
1647
+                    }
1648
+                ],
1649
+                "responses": {
1650
+                    "200": {
1651
+                        "description": "OK",
1652
+                        "schema": {
1653
+                            "allOf": [
1654
+                                {
1655
+                                    "$ref": "#/definitions/response.Response"
1656
+                                },
1657
+                                {
1658
+                                    "type": "object",
1659
+                                    "properties": {
1660
+                                        "data": {
1661
+                                            "$ref": "#/definitions/model.Group"
1662
+                                        }
1663
+                                    }
1664
+                                }
1665
+                            ]
1666
+                        }
1667
+                    },
1668
+                    "500": {
1669
+                        "description": "Internal Server Error",
1670
+                        "schema": {
1671
+                            "$ref": "#/definitions/response.Response"
1672
+                        }
1673
+                    }
1674
+                }
1675
+            }
1676
+        },
1403 1677
         "/admin/file/oss_token": {
1404 1678
             "get": {
1405 1679
                 "security": [
@@ -1776,7 +2050,7 @@
1776 2050
                         "in": "body",
1777 2051
                         "required": true,
1778 2052
                         "schema": {
1779
-                            "$ref": "#/definitions/github_com_lejianwen_rustdesk-api_http_request_admin.Login"
2053
+                            "$ref": "#/definitions/github_com_lejianwen_rustdesk-api_v2_http_request_admin.Login"
1780 2054
                         }
1781 2055
                     }
1782 2056
                 ],
@@ -5212,6 +5486,20 @@
5212 5486
                 }
5213 5487
             }
5214 5488
         },
5489
+        "admin.DeviceGroupForm": {
5490
+            "type": "object",
5491
+            "required": [
5492
+                "name"
5493
+            ],
5494
+            "properties": {
5495
+                "id": {
5496
+                    "type": "integer"
5497
+                },
5498
+                "name": {
5499
+                    "type": "string"
5500
+                }
5501
+            }
5502
+        },
5215 5503
         "admin.GroupForm": {
5216 5504
             "type": "object",
5217 5505
             "required": [
@@ -5299,6 +5587,12 @@
5299 5587
                 "op": {
5300 5588
                     "type": "string"
5301 5589
                 },
5590
+                "pkce_enable": {
5591
+                    "type": "boolean"
5592
+                },
5593
+                "pkce_method": {
5594
+                    "type": "string"
5595
+                },
5302 5596
                 "redirect_url": {
5303 5597
                     "type": "string"
5304 5598
                 },
@@ -5327,6 +5621,9 @@
5327 5621
                 "cpu": {
5328 5622
                     "type": "string"
5329 5623
                 },
5624
+                "group_id": {
5625
+                    "type": "integer"
5626
+                },
5330 5627
                 "hostname": {
5331 5628
                     "type": "string"
5332 5629
                 },
@@ -5514,7 +5811,7 @@
5514 5811
                 }
5515 5812
             }
5516 5813
         },
5517
-        "github_com_lejianwen_rustdesk-api_http_request_admin.Login": {
5814
+        "github_com_lejianwen_rustdesk-api_v2_http_request_admin.Login": {
5518 5815
             "type": "object",
5519 5816
             "required": [
5520 5817
                 "password",
@@ -5835,6 +6132,23 @@
5835 6132
                 }
5836 6133
             }
5837 6134
         },
6135
+        "model.DeviceGroup": {
6136
+            "type": "object",
6137
+            "properties": {
6138
+                "created_at": {
6139
+                    "type": "string"
6140
+                },
6141
+                "id": {
6142
+                    "type": "integer"
6143
+                },
6144
+                "name": {
6145
+                    "type": "string"
6146
+                },
6147
+                "updated_at": {
6148
+                    "type": "string"
6149
+                }
6150
+            }
6151
+        },
5838 6152
         "model.Group": {
5839 6153
             "type": "object",
5840 6154
             "properties": {
@@ -5966,6 +6280,12 @@
5966 6280
                 "op": {
5967 6281
                     "type": "string"
5968 6282
                 },
6283
+                "pkce_enable": {
6284
+                    "type": "boolean"
6285
+                },
6286
+                "pkce_method": {
6287
+                    "type": "string"
6288
+                },
5969 6289
                 "redirect_url": {
5970 6290
                     "type": "string"
5971 6291
                 },
@@ -6006,6 +6326,9 @@
6006 6326
                 "created_at": {
6007 6327
                     "type": "string"
6008 6328
                 },
6329
+                "group_id": {
6330
+                    "type": "integer"
6331
+                },
6009 6332
                 "hostname": {
6010 6333
                     "type": "string"
6011 6334
                 },

+ 195 - 2
docs/admin/admin_swagger.yaml

@@ -77,6 +77,15 @@ definitions:
77 77
     - new_password
78 78
     - old_password
79 79
     type: object
80
+  admin.DeviceGroupForm:
81
+    properties:
82
+      id:
83
+        type: integer
84
+      name:
85
+        type: string
86
+    required:
87
+    - name
88
+    type: object
80 89
   admin.GroupForm:
81 90
     properties:
82 91
       id:
@@ -130,6 +139,10 @@ definitions:
130 139
         type: string
131 140
       op:
132 141
         type: string
142
+      pkce_enable:
143
+        type: boolean
144
+      pkce_method:
145
+        type: string
133 146
       redirect_url:
134 147
         type: string
135 148
       scopes:
@@ -153,6 +166,8 @@ definitions:
153 166
     properties:
154 167
       cpu:
155 168
         type: string
169
+      group_id:
170
+        type: integer
156 171
       hostname:
157 172
         type: string
158 173
       id:
@@ -278,7 +293,7 @@ definitions:
278 293
     required:
279 294
     - ids
280 295
     type: object
281
-  github_com_lejianwen_rustdesk-api_http_request_admin.Login:
296
+  github_com_lejianwen_rustdesk-api_v2_http_request_admin.Login:
282 297
     properties:
283 298
       captcha:
284 299
         type: string
@@ -492,6 +507,17 @@ definitions:
492 507
       total:
493 508
         type: integer
494 509
     type: object
510
+  model.DeviceGroup:
511
+    properties:
512
+      created_at:
513
+        type: string
514
+      id:
515
+        type: integer
516
+      name:
517
+        type: string
518
+      updated_at:
519
+        type: string
520
+    type: object
495 521
   model.Group:
496 522
     properties:
497 523
       created_at:
@@ -579,6 +605,10 @@ definitions:
579 605
         type: string
580 606
       op:
581 607
         type: string
608
+      pkce_enable:
609
+        type: boolean
610
+      pkce_method:
611
+        type: string
582 612
       redirect_url:
583 613
         type: string
584 614
       scopes:
@@ -605,6 +635,8 @@ definitions:
605 635
         type: string
606 636
       created_at:
607 637
         type: string
638
+      group_id:
639
+        type: integer
608 640
       hostname:
609 641
         type: string
610 642
       id:
@@ -1610,6 +1642,167 @@ paths:
1610 1642
       summary: RUSTDESK服务配置
1611 1643
       tags:
1612 1644
       - ADMIN
1645
+  /admin/device_group/create:
1646
+    post:
1647
+      consumes:
1648
+      - application/json
1649
+      description: 创建设备群组
1650
+      parameters:
1651
+      - description: 设备群组信息
1652
+        in: body
1653
+        name: body
1654
+        required: true
1655
+        schema:
1656
+          $ref: '#/definitions/admin.DeviceGroupForm'
1657
+      produces:
1658
+      - application/json
1659
+      responses:
1660
+        "200":
1661
+          description: OK
1662
+          schema:
1663
+            allOf:
1664
+            - $ref: '#/definitions/response.Response'
1665
+            - properties:
1666
+                data:
1667
+                  $ref: '#/definitions/model.DeviceGroup'
1668
+              type: object
1669
+        "500":
1670
+          description: Internal Server Error
1671
+          schema:
1672
+            $ref: '#/definitions/response.Response'
1673
+      security:
1674
+      - token: []
1675
+      summary: 创建设备群组
1676
+      tags:
1677
+      - 设备群组
1678
+  /admin/device_group/delete:
1679
+    post:
1680
+      consumes:
1681
+      - application/json
1682
+      description: 设备群组删除
1683
+      parameters:
1684
+      - description: 群组信息
1685
+        in: body
1686
+        name: body
1687
+        required: true
1688
+        schema:
1689
+          $ref: '#/definitions/admin.DeviceGroupForm'
1690
+      produces:
1691
+      - application/json
1692
+      responses:
1693
+        "200":
1694
+          description: OK
1695
+          schema:
1696
+            $ref: '#/definitions/response.Response'
1697
+        "500":
1698
+          description: Internal Server Error
1699
+          schema:
1700
+            $ref: '#/definitions/response.Response'
1701
+      security:
1702
+      - token: []
1703
+      summary: 设备群组删除
1704
+      tags:
1705
+      - 设备群组
1706
+  /admin/device_group/detail/{id}:
1707
+    get:
1708
+      consumes:
1709
+      - application/json
1710
+      description: 设备群组详情
1711
+      parameters:
1712
+      - description: ID
1713
+        in: path
1714
+        name: id
1715
+        required: true
1716
+        type: integer
1717
+      produces:
1718
+      - application/json
1719
+      responses:
1720
+        "200":
1721
+          description: OK
1722
+          schema:
1723
+            allOf:
1724
+            - $ref: '#/definitions/response.Response'
1725
+            - properties:
1726
+                data:
1727
+                  $ref: '#/definitions/model.Group'
1728
+              type: object
1729
+        "500":
1730
+          description: Internal Server Error
1731
+          schema:
1732
+            $ref: '#/definitions/response.Response'
1733
+      security:
1734
+      - token: []
1735
+      summary: 设备群组详情
1736
+      tags:
1737
+      - 设备群组
1738
+  /admin/device_group/list:
1739
+    get:
1740
+      consumes:
1741
+      - application/json
1742
+      description: 群组列表
1743
+      parameters:
1744
+      - description: 页码
1745
+        in: query
1746
+        name: page
1747
+        type: integer
1748
+      - description: 页大小
1749
+        in: query
1750
+        name: page_size
1751
+        type: integer
1752
+      produces:
1753
+      - application/json
1754
+      responses:
1755
+        "200":
1756
+          description: OK
1757
+          schema:
1758
+            allOf:
1759
+            - $ref: '#/definitions/response.Response'
1760
+            - properties:
1761
+                data:
1762
+                  $ref: '#/definitions/model.GroupList'
1763
+              type: object
1764
+        "500":
1765
+          description: Internal Server Error
1766
+          schema:
1767
+            $ref: '#/definitions/response.Response'
1768
+      security:
1769
+      - token: []
1770
+      summary: 群组列表
1771
+      tags:
1772
+      - 群组
1773
+  /admin/device_group/update:
1774
+    post:
1775
+      consumes:
1776
+      - application/json
1777
+      description: 设备群组编辑
1778
+      parameters:
1779
+      - description: 群组信息
1780
+        in: body
1781
+        name: body
1782
+        required: true
1783
+        schema:
1784
+          $ref: '#/definitions/admin.DeviceGroupForm'
1785
+      produces:
1786
+      - application/json
1787
+      responses:
1788
+        "200":
1789
+          description: OK
1790
+          schema:
1791
+            allOf:
1792
+            - $ref: '#/definitions/response.Response'
1793
+            - properties:
1794
+                data:
1795
+                  $ref: '#/definitions/model.Group'
1796
+              type: object
1797
+        "500":
1798
+          description: Internal Server Error
1799
+          schema:
1800
+            $ref: '#/definitions/response.Response'
1801
+      security:
1802
+      - token: []
1803
+      summary: 设备群组编辑
1804
+      tags:
1805
+      - 设备群组
1613 1806
   /admin/file/oss_token:
1614 1807
     get:
1615 1808
       consumes:
@@ -1830,7 +2023,7 @@ paths:
1830 2023
         name: body
1831 2024
         required: true
1832 2025
         schema:
1833
-          $ref: '#/definitions/github_com_lejianwen_rustdesk-api_http_request_admin.Login'
2026
+          $ref: '#/definitions/github_com_lejianwen_rustdesk-api_v2_http_request_admin.Login'
1834 2027
       produces:
1835 2028
       - application/json
1836 2029
       responses:

+ 60 - 0
docs/api/api_docs.go

@@ -767,6 +767,66 @@ const docTemplateapi = `{
767 767
                 }
768 768
             }
769 769
         },
770
+        "/device-group/accessible": {
771
+            "get": {
772
+                "security": [
773
+                    {
774
+                        "BearerAuth": []
775
+                    }
776
+                ],
777
+                "description": "机器",
778
+                "consumes": [
779
+                    "application/json"
780
+                ],
781
+                "produces": [
782
+                    "application/json"
783
+                ],
784
+                "tags": [
785
+                    "群组"
786
+                ],
787
+                "summary": "设备",
788
+                "parameters": [
789
+                    {
790
+                        "type": "integer",
791
+                        "description": "页码",
792
+                        "name": "page",
793
+                        "in": "query"
794
+                    },
795
+                    {
796
+                        "type": "integer",
797
+                        "description": "每页数量",
798
+                        "name": "pageSize",
799
+                        "in": "query"
800
+                    },
801
+                    {
802
+                        "type": "integer",
803
+                        "description": "状态",
804
+                        "name": "status",
805
+                        "in": "query"
806
+                    },
807
+                    {
808
+                        "type": "string",
809
+                        "description": "accessible",
810
+                        "name": "accessible",
811
+                        "in": "query"
812
+                    }
813
+                ],
814
+                "responses": {
815
+                    "200": {
816
+                        "description": "OK",
817
+                        "schema": {
818
+                            "$ref": "#/definitions/response.DataResponse"
819
+                        }
820
+                    },
821
+                    "500": {
822
+                        "description": "Internal Server Error",
823
+                        "schema": {
824
+                            "$ref": "#/definitions/response.Response"
825
+                        }
826
+                    }
827
+                }
828
+            }
829
+        },
770 830
         "/heartbeat": {
771 831
             "post": {
772 832
                 "description": "心跳",

+ 60 - 0
docs/api/api_swagger.json

@@ -760,6 +760,66 @@
760 760
                 }
761 761
             }
762 762
         },
763
+        "/device-group/accessible": {
764
+            "get": {
765
+                "security": [
766
+                    {
767
+                        "BearerAuth": []
768
+                    }
769
+                ],
770
+                "description": "机器",
771
+                "consumes": [
772
+                    "application/json"
773
+                ],
774
+                "produces": [
775
+                    "application/json"
776
+                ],
777
+                "tags": [
778
+                    "群组"
779
+                ],
780
+                "summary": "设备",
781
+                "parameters": [
782
+                    {
783
+                        "type": "integer",
784
+                        "description": "页码",
785
+                        "name": "page",
786
+                        "in": "query"
787
+                    },
788
+                    {
789
+                        "type": "integer",
790
+                        "description": "每页数量",
791
+                        "name": "pageSize",
792
+                        "in": "query"
793
+                    },
794
+                    {
795
+                        "type": "integer",
796
+                        "description": "状态",
797
+                        "name": "status",
798
+                        "in": "query"
799
+                    },
800
+                    {
801
+                        "type": "string",
802
+                        "description": "accessible",
803
+                        "name": "accessible",
804
+                        "in": "query"
805
+                    }
806
+                ],
807
+                "responses": {
808
+                    "200": {
809
+                        "description": "OK",
810
+                        "schema": {
811
+                            "$ref": "#/definitions/response.DataResponse"
812
+                        }
813
+                    },
814
+                    "500": {
815
+                        "description": "Internal Server Error",
816
+                        "schema": {
817
+                            "$ref": "#/definitions/response.Response"
818
+                        }
819
+                    }
820
+                }
821
+            }
822
+        },
763 823
         "/heartbeat": {
764 824
             "post": {
765 825
                 "description": "心跳",

+ 38 - 0
docs/api/api_swagger.yaml

@@ -671,6 +671,44 @@ paths:
671 671
       summary: 用户信息
672 672
       tags:
673 673
       - 用户
674
+  /device-group/accessible:
675
+    get:
676
+      consumes:
677
+      - application/json
678
+      description: 机器
679
+      parameters:
680
+      - description: 页码
681
+        in: query
682
+        name: page
683
+        type: integer
684
+      - description: 每页数量
685
+        in: query
686
+        name: pageSize
687
+        type: integer
688
+      - description: 状态
689
+        in: query
690
+        name: status
691
+        type: integer
692
+      - description: accessible
693
+        in: query
694
+        name: accessible
695
+        type: string
696
+      produces:
697
+      - application/json
698
+      responses:
699
+        "200":
700
+          description: OK
701
+          schema:
702
+            $ref: '#/definitions/response.DataResponse'
703
+        "500":
704
+          description: Internal Server Error
705
+          schema:
706
+            $ref: '#/definitions/response.Response'
707
+      security:
708
+      - BearerAuth: []
709
+      summary: 设备
710
+      tags:
711
+      - 群组
674 712
   /heartbeat:
675 713
     post:
676 714
       consumes:

+ 160 - 0
http/controller/admin/deviceGroup.go

@@ -0,0 +1,160 @@
1
+package admin
2
+
3
+import (
4
+	"github.com/gin-gonic/gin"
5
+	"github.com/lejianwen/rustdesk-api/v2/global"
6
+	"github.com/lejianwen/rustdesk-api/v2/http/request/admin"
7
+	"github.com/lejianwen/rustdesk-api/v2/http/response"
8
+	"github.com/lejianwen/rustdesk-api/v2/service"
9
+	"strconv"
10
+)
11
+
12
+type DeviceGroup struct {
13
+}
14
+
15
+// Detail 设备群组
16
+// @Tags 设备群组
17
+// @Summary 设备群组详情
18
+// @Description 设备群组详情
19
+// @Accept  json
20
+// @Produce  json
21
+// @Param id path int true "ID"
22
+// @Success 200 {object} response.Response{data=model.Group}
23
+// @Failure 500 {object} response.Response
24
+// @Router /admin/device_group/detail/{id} [get]
25
+// @Security token
26
+func (ct *DeviceGroup) Detail(c *gin.Context) {
27
+	id := c.Param("id")
28
+	iid, _ := strconv.Atoi(id)
29
+	u := service.AllService.GroupService.DeviceGroupInfoById(uint(iid))
30
+	if u.Id > 0 {
31
+		response.Success(c, u)
32
+		return
33
+	}
34
+	response.Fail(c, 101, response.TranslateMsg(c, "ItemNotFound"))
35
+	return
36
+}
37
+
38
+// Create 创建设备群组
39
+// @Tags 设备群组
40
+// @Summary 创建设备群组
41
+// @Description 创建设备群组
42
+// @Accept  json
43
+// @Produce  json
44
+// @Param body body admin.DeviceGroupForm true "设备群组信息"
45
+// @Success 200 {object} response.Response{data=model.DeviceGroup}
46
+// @Failure 500 {object} response.Response
47
+// @Router /admin/device_group/create [post]
48
+// @Security token
49
+func (ct *DeviceGroup) Create(c *gin.Context) {
50
+	f := &admin.DeviceGroupForm{}
51
+	if err := c.ShouldBindJSON(f); err != nil {
52
+		response.Fail(c, 101, response.TranslateMsg(c, "ParamsError")+err.Error())
53
+		return
54
+	}
55
+	errList := global.Validator.ValidStruct(c, f)
56
+	if len(errList) > 0 {
57
+		response.Fail(c, 101, errList[0])
58
+		return
59
+	}
60
+	u := f.ToDeviceGroup()
61
+	err := service.AllService.GroupService.DeviceGroupCreate(u)
62
+	if err != nil {
63
+		response.Fail(c, 101, response.TranslateMsg(c, "OperationFailed")+err.Error())
64
+		return
65
+	}
66
+	response.Success(c, nil)
67
+}
68
+
69
+// List 列表
70
+// @Tags 群组
71
+// @Summary 群组列表
72
+// @Description 群组列表
73
+// @Accept  json
74
+// @Produce  json
75
+// @Param page query int false "页码"
76
+// @Param page_size query int false "页大小"
77
+// @Success 200 {object} response.Response{data=model.GroupList}
78
+// @Failure 500 {object} response.Response
79
+// @Router /admin/device_group/list [get]
80
+// @Security token
81
+func (ct *DeviceGroup) List(c *gin.Context) {
82
+	query := &admin.PageQuery{}
83
+	if err := c.ShouldBindQuery(query); err != nil {
84
+		response.Fail(c, 101, response.TranslateMsg(c, "ParamsError")+err.Error())
85
+		return
86
+	}
87
+	res := service.AllService.GroupService.DeviceGroupList(query.Page, query.PageSize, nil)
88
+	response.Success(c, res)
89
+}
90
+
91
+// Update 编辑
92
+// @Tags 设备群组
93
+// @Summary 设备群组编辑
94
+// @Description 设备群组编辑
95
+// @Accept  json
96
+// @Produce  json
97
+// @Param body body admin.DeviceGroupForm true "群组信息"
98
+// @Success 200 {object} response.Response{data=model.Group}
99
+// @Failure 500 {object} response.Response
100
+// @Router /admin/device_group/update [post]
101
+// @Security token
102
+func (ct *DeviceGroup) Update(c *gin.Context) {
103
+	f := &admin.DeviceGroupForm{}
104
+	if err := c.ShouldBindJSON(f); err != nil {
105
+		response.Fail(c, 101, response.TranslateMsg(c, "ParamsError")+err.Error())
106
+		return
107
+	}
108
+	if f.Id == 0 {
109
+		response.Fail(c, 101, response.TranslateMsg(c, "ParamsError"))
110
+		return
111
+	}
112
+	errList := global.Validator.ValidStruct(c, f)
113
+	if len(errList) > 0 {
114
+		response.Fail(c, 101, errList[0])
115
+		return
116
+	}
117
+	u := f.ToDeviceGroup()
118
+	err := service.AllService.GroupService.DeviceGroupUpdate(u)
119
+	if err != nil {
120
+		response.Fail(c, 101, response.TranslateMsg(c, "OperationFailed")+err.Error())
121
+		return
122
+	}
123
+	response.Success(c, nil)
124
+}
125
+
126
+// Delete 删除
127
+// @Tags 设备群组
128
+// @Summary 设备群组删除
129
+// @Description 设备群组删除
130
+// @Accept  json
131
+// @Produce  json
132
+// @Param body body admin.DeviceGroupForm true "群组信息"
133
+// @Success 200 {object} response.Response
134
+// @Failure 500 {object} response.Response
135
+// @Router /admin/device_group/delete [post]
136
+// @Security token
137
+func (ct *DeviceGroup) Delete(c *gin.Context) {
138
+	f := &admin.DeviceGroupForm{}
139
+	if err := c.ShouldBindJSON(f); err != nil {
140
+		response.Fail(c, 101, response.TranslateMsg(c, "ParamsError")+err.Error())
141
+		return
142
+	}
143
+	id := f.Id
144
+	errList := global.Validator.ValidVar(c, id, "required,gt=0")
145
+	if len(errList) > 0 {
146
+		response.Fail(c, 101, errList[0])
147
+		return
148
+	}
149
+	u := service.AllService.GroupService.DeviceGroupInfoById(f.Id)
150
+	if u.Id > 0 {
151
+		err := service.AllService.GroupService.DeviceGroupDelete(u)
152
+		if err == nil {
153
+			response.Success(c, nil)
154
+			return
155
+		}
156
+		response.Fail(c, 101, response.TranslateMsg(c, "OperationFailed")+err.Error())
157
+		return
158
+	}
159
+	response.Fail(c, 101, response.TranslateMsg(c, "ItemNotFound"))
160
+}

+ 18 - 3
http/controller/api/group.go

@@ -94,6 +94,11 @@ func (g *Group) Peers(c *gin.Context) {
94 94
 		namesById[user.Id] = user.Username
95 95
 		userIds = append(userIds, user.Id)
96 96
 	}
97
+	dGroupNameById := make(map[uint]string)
98
+	allGroup := service.AllService.GroupService.DeviceGroupList(1, 999, nil)
99
+	for _, group := range allGroup.DeviceGroups {
100
+		dGroupNameById[group.Id] = group.Name
101
+	}
97 102
 	peerList := service.AllService.PeerService.ListByUserIds(userIds, q.Page, q.PageSize)
98 103
 	data := make([]*apiResp.GroupPeerPayload, 0, len(peerList.Peers))
99 104
 	for _, peer := range peerList.Peers {
@@ -101,9 +106,12 @@ func (g *Group) Peers(c *gin.Context) {
101 106
 		if !ok {
102 107
 			uname = ""
103 108
 		}
109
+		dGroupName, ok2 := dGroupNameById[peer.GroupId]
110
+		if !ok2 {
111
+			dGroupName = ""
112
+		}
104 113
 		pp := &apiResp.GroupPeerPayload{}
105
-		pp.FromPeer(peer, uname)
106
-		//pp.DeviceGroupName = uname
114
+		pp.FromPeer(peer, uname, dGroupName)
107 115
 		data = append(data, pp)
108 116
 
109 117
 	}
@@ -128,8 +136,15 @@ func (g *Group) Peers(c *gin.Context) {
128 136
 // @Router /device-group/accessible [get]
129 137
 // @Security BearerAuth
130 138
 func (g *Group) Device(c *gin.Context) {
139
+	u := service.AllService.UserService.CurUser(c)
140
+	if !service.AllService.UserService.IsAdmin(u) {
141
+		response.Error(c, "Permission denied")
142
+		return
143
+	}
144
+	allGroup := service.AllService.GroupService.DeviceGroupList(1, 999, nil)
145
+
131 146
 	c.JSON(http.StatusOK, response.DataResponse{
132 147
 		Total: 0,
133
-		Data:  nil,
148
+		Data:  allGroup.DeviceGroups,
134 149
 	})
135 150
 }

+ 12 - 0
http/request/admin/group.go

@@ -22,3 +22,15 @@ func (gf *GroupForm) ToGroup() *model.Group {
22 22
 	group.Type = gf.Type
23 23
 	return group
24 24
 }
25
+
26
+type DeviceGroupForm struct {
27
+	Id   uint   `json:"id"`
28
+	Name string `json:"name" validate:"required"`
29
+}
30
+
31
+func (gf *DeviceGroupForm) ToDeviceGroup() *model.DeviceGroup {
32
+	group := &model.DeviceGroup{}
33
+	group.Id = gf.Id
34
+	group.Name = gf.Name
35
+	return group
36
+}

+ 2 - 0
http/request/admin/peer.go

@@ -12,6 +12,7 @@ type PeerForm struct {
12 12
 	Username string `json:"username"`
13 13
 	Uuid     string `json:"uuid"`
14 14
 	Version  string `json:"version"`
15
+	GroupId  uint   `json:"group_id"`
15 16
 }
16 17
 
17 18
 type PeerBatchDeleteForm struct {
@@ -30,6 +31,7 @@ func (f *PeerForm) ToPeer() *model.Peer {
30 31
 		Username: f.Username,
31 32
 		Uuid:     f.Uuid,
32 33
 		Version:  f.Version,
34
+		GroupId:  f.GroupId,
33 35
 	}
34 36
 }
35 37
 

+ 2 - 1
http/response/api/peer.go

@@ -60,7 +60,7 @@ func (gpp *GroupPeerPayload) FromAddressBook(a *model.AddressBook, username stri
60 60
 	gpp.UserName = username
61 61
 }
62 62
 
63
-func (gpp *GroupPeerPayload) FromPeer(p *model.Peer, username string) {
63
+func (gpp *GroupPeerPayload) FromPeer(p *model.Peer, username string, dGroupName string) {
64 64
 	gpp.Id = p.Id
65 65
 	gpp.Info = &PeerPayloadInfo{
66 66
 		DeviceName: p.Hostname,
@@ -69,4 +69,5 @@ func (gpp *GroupPeerPayload) FromPeer(p *model.Peer, username string) {
69 69
 	}
70 70
 	gpp.Note = ""
71 71
 	gpp.UserName = username
72
+	gpp.DeviceGroupName = dGroupName
72 73
 }

+ 13 - 1
http/router/admin.go

@@ -49,7 +49,7 @@ func Init(g *gin.Engine) {
49 49
 	MyBind(adg)
50 50
 
51 51
 	RustdeskCmdBind(adg)
52
-
52
+	DeviceGroupBind(adg)
53 53
 	//访问静态文件
54 54
 	//g.StaticFS("/upload", http.Dir(global.Config.Gin.ResourcesPath+"/upload"))
55 55
 }
@@ -106,6 +106,18 @@ func GroupBind(rg *gin.RouterGroup) {
106 106
 	}
107 107
 }
108 108
 
109
+func DeviceGroupBind(rg *gin.RouterGroup) {
110
+	aR := rg.Group("/device_group").Use(middleware.AdminPrivilege())
111
+	{
112
+		cont := &admin.DeviceGroup{}
113
+		aR.GET("/list", cont.List)
114
+		aR.GET("/detail/:id", cont.Detail)
115
+		aR.POST("/create", cont.Create)
116
+		aR.POST("/update", cont.Update)
117
+		aR.POST("/delete", cont.Delete)
118
+	}
119
+}
120
+
109 121
 func TagBind(rg *gin.RouterGroup) {
110 122
 	aR := rg.Group("/tag").Use(middleware.AdminPrivilege())
111 123
 	{

+ 11 - 0
model/group.go

@@ -16,3 +16,14 @@ type GroupList struct {
16 16
 	Groups []*Group `json:"list"`
17 17
 	Pagination
18 18
 }
19
+
20
+type DeviceGroup struct {
21
+	IdModel
22
+	Name string `json:"name" gorm:"default:'';not null;"`
23
+	TimeModel
24
+}
25
+
26
+type DeviceGroupList struct {
27
+	DeviceGroups []*DeviceGroup `json:"list"`
28
+	Pagination
29
+}

+ 1 - 0
model/peer.go

@@ -14,6 +14,7 @@ type Peer struct {
14 14
 	User           *User  `json:"user,omitempty"`
15 15
 	LastOnlineTime int64  `json:"last_online_time"  gorm:"default:0;not null;"`
16 16
 	LastOnlineIp   string `json:"last_online_ip"  gorm:"default:'';not null;"`
17
+	GroupId        uint   `json:"group_id"  gorm:"default:0;not null;index"`
17 18
 	TimeModel
18 19
 }
19 20
 

+ 33 - 0
service/group.go

@@ -43,3 +43,36 @@ func (us *GroupService) Delete(u *model.Group) error {
43 43
 func (us *GroupService) Update(u *model.Group) error {
44 44
 	return global.DB.Model(u).Updates(u).Error
45 45
 }
46
+
47
+// DeviceGroupInfoById 根据用户id取用户信息
48
+func (us *GroupService) DeviceGroupInfoById(id uint) *model.DeviceGroup {
49
+	u := &model.DeviceGroup{}
50
+	global.DB.Where("id = ?", id).First(u)
51
+	return u
52
+}
53
+
54
+func (us *GroupService) DeviceGroupList(page, pageSize uint, where func(tx *gorm.DB)) (res *model.DeviceGroupList) {
55
+	res = &model.DeviceGroupList{}
56
+	res.Page = int64(page)
57
+	res.PageSize = int64(pageSize)
58
+	tx := global.DB.Model(&model.DeviceGroup{})
59
+	if where != nil {
60
+		where(tx)
61
+	}
62
+	tx.Count(&res.Total)
63
+	tx.Scopes(Paginate(page, pageSize))
64
+	tx.Find(&res.DeviceGroups)
65
+	return
66
+}
67
+
68
+func (us *GroupService) DeviceGroupCreate(u *model.DeviceGroup) error {
69
+	res := global.DB.Create(u).Error
70
+	return res
71
+}
72
+func (us *GroupService) DeviceGroupDelete(u *model.DeviceGroup) error {
73
+	return global.DB.Delete(u).Error
74
+}
75
+
76
+func (us *GroupService) DeviceGroupUpdate(u *model.DeviceGroup) error {
77
+	return global.DB.Model(u).Updates(u).Error
78
+}