|
|
@@ -10,6 +10,7 @@ import (
|
|
10
|
10
|
"github.com/gin-gonic/gin"
|
|
11
|
11
|
"gorm.io/gorm"
|
|
12
|
12
|
"strconv"
|
|
|
13
|
+ "time"
|
|
13
|
14
|
)
|
|
14
|
15
|
|
|
15
|
16
|
type User struct {
|
|
|
@@ -299,6 +300,51 @@ func (ct *User) MyOauth(c *gin.Context) {
|
|
299
|
300
|
response.Success(c, res)
|
|
300
|
301
|
}
|
|
301
|
302
|
|
|
|
303
|
+// List 列表
|
|
|
304
|
+// @Tags 设备
|
|
|
305
|
+// @Summary 设备列表
|
|
|
306
|
+// @Description 设备列表
|
|
|
307
|
+// @Accept json
|
|
|
308
|
+// @Produce json
|
|
|
309
|
+// @Param page query int false "页码"
|
|
|
310
|
+// @Param page_size query int false "页大小"
|
|
|
311
|
+// @Param time_ago query int false "时间"
|
|
|
312
|
+// @Param id query string false "ID"
|
|
|
313
|
+// @Param hostname query string false "主机名"
|
|
|
314
|
+// @Param uuids query string false "uuids 用逗号分隔"
|
|
|
315
|
+// @Success 200 {object} response.Response{data=model.PeerList}
|
|
|
316
|
+// @Failure 500 {object} response.Response
|
|
|
317
|
+// @Router /admin/user/myPeer [get]
|
|
|
318
|
+// @Security token
|
|
|
319
|
+func (ct *User) MyPeer(c *gin.Context) {
|
|
|
320
|
+ query := &admin.PeerQuery{}
|
|
|
321
|
+ if err := c.ShouldBindQuery(query); err != nil {
|
|
|
322
|
+ response.Fail(c, 101, response.TranslateMsg(c, "ParamsError")+err.Error())
|
|
|
323
|
+ return
|
|
|
324
|
+ }
|
|
|
325
|
+ u := service.AllService.UserService.CurUser(c)
|
|
|
326
|
+ res := service.AllService.PeerService.ListFilterByUserId(query.Page, query.PageSize, func(tx *gorm.DB) {
|
|
|
327
|
+ if query.TimeAgo > 0 {
|
|
|
328
|
+ lt := time.Now().Unix() - int64(query.TimeAgo)
|
|
|
329
|
+ tx.Where("last_online_time < ?", lt)
|
|
|
330
|
+ }
|
|
|
331
|
+ if query.TimeAgo < 0 {
|
|
|
332
|
+ lt := time.Now().Unix() + int64(query.TimeAgo)
|
|
|
333
|
+ tx.Where("last_online_time > ?", lt)
|
|
|
334
|
+ }
|
|
|
335
|
+ if query.Id != "" {
|
|
|
336
|
+ tx.Where("id like ?", "%"+query.Id+"%")
|
|
|
337
|
+ }
|
|
|
338
|
+ if query.Hostname != "" {
|
|
|
339
|
+ tx.Where("hostname like ?", "%"+query.Hostname+"%")
|
|
|
340
|
+ }
|
|
|
341
|
+ if query.Uuids != "" {
|
|
|
342
|
+ tx.Where("uuid in (?)", query.Uuids)
|
|
|
343
|
+ }
|
|
|
344
|
+ }, u.Id)
|
|
|
345
|
+ response.Success(c, res)
|
|
|
346
|
+}
|
|
|
347
|
+
|
|
302
|
348
|
// groupUsers
|
|
303
|
349
|
func (ct *User) GroupUsers(c *gin.Context) {
|
|
304
|
350
|
q := &admin.GroupUsersQuery{}
|