|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+package my
|
|
|
2
|
+
|
|
|
3
|
+import (
|
|
|
4
|
+ "Gwen/global"
|
|
|
5
|
+ "Gwen/http/request/admin"
|
|
|
6
|
+ "Gwen/http/response"
|
|
|
7
|
+ "Gwen/model"
|
|
|
8
|
+ "Gwen/service"
|
|
|
9
|
+ "github.com/gin-gonic/gin"
|
|
|
10
|
+ "gorm.io/gorm"
|
|
|
11
|
+)
|
|
|
12
|
+
|
|
|
13
|
+type LoginLog struct {
|
|
|
14
|
+}
|
|
|
15
|
+
|
|
|
16
|
+// List 列表
|
|
|
17
|
+// @Tags 我的登录日志
|
|
|
18
|
+// @Summary 登录日志列表
|
|
|
19
|
+// @Description 登录日志列表
|
|
|
20
|
+// @Accept json
|
|
|
21
|
+// @Produce json
|
|
|
22
|
+// @Param page query int false "页码"
|
|
|
23
|
+// @Param page_size query int false "页大小"
|
|
|
24
|
+// @Param user_id query int false "用户ID"
|
|
|
25
|
+// @Success 200 {object} response.Response{data=model.LoginLogList}
|
|
|
26
|
+// @Failure 500 {object} response.Response
|
|
|
27
|
+// @Router /admin/my/login_log/list [get]
|
|
|
28
|
+// @Security token
|
|
|
29
|
+func (ct *LoginLog) List(c *gin.Context) {
|
|
|
30
|
+ query := &admin.LoginLogQuery{}
|
|
|
31
|
+ if err := c.ShouldBindQuery(query); err != nil {
|
|
|
32
|
+ response.Fail(c, 101, response.TranslateMsg(c, "ParamsError")+err.Error())
|
|
|
33
|
+ return
|
|
|
34
|
+ }
|
|
|
35
|
+ u := service.AllService.UserService.CurUser(c)
|
|
|
36
|
+ res := service.AllService.LoginLogService.List(query.Page, query.PageSize, func(tx *gorm.DB) {
|
|
|
37
|
+ tx.Where("user_id = ? and is_deleted = ?", u.Id, model.IsDeletedNo)
|
|
|
38
|
+ tx.Order("id desc")
|
|
|
39
|
+ })
|
|
|
40
|
+ response.Success(c, res)
|
|
|
41
|
+}
|
|
|
42
|
+
|
|
|
43
|
+// Delete 删除
|
|
|
44
|
+// @Tags 我的登录日志
|
|
|
45
|
+// @Summary 登录日志删除
|
|
|
46
|
+// @Description 登录日志删除
|
|
|
47
|
+// @Accept json
|
|
|
48
|
+// @Produce json
|
|
|
49
|
+// @Param body body model.LoginLog true "登录日志信息"
|
|
|
50
|
+// @Success 200 {object} response.Response
|
|
|
51
|
+// @Failure 500 {object} response.Response
|
|
|
52
|
+// @Router /admin/my/login_log/delete [post]
|
|
|
53
|
+// @Security token
|
|
|
54
|
+func (ct *LoginLog) Delete(c *gin.Context) {
|
|
|
55
|
+ f := &model.LoginLog{}
|
|
|
56
|
+ if err := c.ShouldBindJSON(f); err != nil {
|
|
|
57
|
+ response.Fail(c, 101, response.TranslateMsg(c, "ParamsError")+err.Error())
|
|
|
58
|
+ return
|
|
|
59
|
+ }
|
|
|
60
|
+ id := f.Id
|
|
|
61
|
+ errList := global.Validator.ValidVar(c, id, "required,gt=0")
|
|
|
62
|
+ if len(errList) > 0 {
|
|
|
63
|
+ response.Fail(c, 101, errList[0])
|
|
|
64
|
+ return
|
|
|
65
|
+ }
|
|
|
66
|
+ l := service.AllService.LoginLogService.InfoById(f.Id)
|
|
|
67
|
+ if l.Id == 0 || l.IsDeleted == model.IsDeletedYes {
|
|
|
68
|
+ response.Fail(c, 101, response.TranslateMsg(c, "ItemNotFound"))
|
|
|
69
|
+ return
|
|
|
70
|
+ }
|
|
|
71
|
+ u := service.AllService.UserService.CurUser(c)
|
|
|
72
|
+ if l.UserId != u.Id {
|
|
|
73
|
+ response.Fail(c, 101, response.TranslateMsg(c, "ItemNotFound"))
|
|
|
74
|
+ return
|
|
|
75
|
+ }
|
|
|
76
|
+ err := service.AllService.LoginLogService.SoftDelete(l)
|
|
|
77
|
+ if err == nil {
|
|
|
78
|
+ response.Success(c, nil)
|
|
|
79
|
+ return
|
|
|
80
|
+ }
|
|
|
81
|
+ response.Fail(c, 101, err.Error())
|
|
|
82
|
+}
|
|
|
83
|
+
|
|
|
84
|
+// BatchDelete 删除
|
|
|
85
|
+// @Tags 我的登录日志
|
|
|
86
|
+// @Summary 登录日志批量删除
|
|
|
87
|
+// @Description 登录日志批量删除
|
|
|
88
|
+// @Accept json
|
|
|
89
|
+// @Produce json
|
|
|
90
|
+// @Param body body admin.LoginLogIds true "登录日志"
|
|
|
91
|
+// @Success 200 {object} response.Response
|
|
|
92
|
+// @Failure 500 {object} response.Response
|
|
|
93
|
+// @Router /admin/my/login_log/batchDelete [post]
|
|
|
94
|
+// @Security token
|
|
|
95
|
+func (ct *LoginLog) BatchDelete(c *gin.Context) {
|
|
|
96
|
+ f := &admin.LoginLogIds{}
|
|
|
97
|
+ if err := c.ShouldBindJSON(f); err != nil {
|
|
|
98
|
+ response.Fail(c, 101, response.TranslateMsg(c, "ParamsError")+err.Error())
|
|
|
99
|
+ return
|
|
|
100
|
+ }
|
|
|
101
|
+ if len(f.Ids) == 0 {
|
|
|
102
|
+ response.Fail(c, 101, response.TranslateMsg(c, "ParamsError"))
|
|
|
103
|
+ return
|
|
|
104
|
+ }
|
|
|
105
|
+ u := service.AllService.UserService.CurUser(c)
|
|
|
106
|
+ err := service.AllService.LoginLogService.BatchSoftDelete(u.Id, f.Ids)
|
|
|
107
|
+ if err == nil {
|
|
|
108
|
+ response.Success(c, nil)
|
|
|
109
|
+ return
|
|
|
110
|
+ }
|
|
|
111
|
+ response.Fail(c, 101, err.Error())
|
|
|
112
|
+ return
|
|
|
113
|
+}
|