ferry/apis/log/loginLog.go

175 lines
4.2 KiB
Go
Raw Normal View History

2020-07-13 20:33:20 +08:00
package log
import (
2020-08-26 22:03:33 +08:00
"ferry/global/orm"
2020-07-14 14:07:44 +08:00
"ferry/models/system"
2020-07-13 20:33:20 +08:00
"ferry/tools"
"ferry/tools/app"
"net/http"
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin/binding"
)
// @Summary 登录日志列表
// @Description 获取JSON
// @Tags 登录日志
// @Param status query string false "status"
// @Param dictCode query string false "dictCode"
// @Param dictType query string false "dictType"
// @Param pageSize query int false "页条数"
// @Param pageIndex query int false "页码"
// @Success 200 {object} app.Response "{"code": 200, "data": [...]}"
// @Router /api/v1/loginloglist [get]
// @Security
func GetLoginLogList(c *gin.Context) {
2020-07-16 01:22:01 +08:00
var (
err error
pageSize = 10
pageIndex = 1
data system.LoginLog
)
2020-07-13 20:33:20 +08:00
size := c.Request.FormValue("pageSize")
if size != "" {
pageSize = tools.StrToInt(err, size)
}
index := c.Request.FormValue("pageIndex")
if index != "" {
pageIndex = tools.StrToInt(err, index)
}
data.Username = c.Request.FormValue("username")
data.Status = c.Request.FormValue("status")
data.Ipaddr = c.Request.FormValue("ipaddr")
result, count, err := data.GetPage(pageSize, pageIndex)
2020-07-16 01:22:01 +08:00
if err != nil {
app.Error(c, -1, err, "")
return
}
2020-07-13 20:33:20 +08:00
var mp = make(map[string]interface{}, 3)
mp["list"] = result
mp["count"] = count
mp["pageIndex"] = pageIndex
mp["pageSize"] = pageSize
var res app.Response
res.Data = mp
c.JSON(http.StatusOK, res.ReturnOK())
}
// @Summary 通过编码获取登录日志
// @Description 获取JSON
// @Tags 登录日志
// @Param infoId path int true "infoId"
// @Success 200 {object} app.Response "{"code": 200, "data": [...]}"
// @Router /api/v1/loginlog/{infoId} [get]
// @Security
func GetLoginLog(c *gin.Context) {
2020-07-16 01:22:01 +08:00
var (
res app.Response
LoginLog system.LoginLog
)
2020-07-13 20:33:20 +08:00
LoginLog.InfoId, _ = tools.StringToInt(c.Param("infoId"))
result, err := LoginLog.Get()
2020-07-16 01:22:01 +08:00
if err != nil {
app.Error(c, -1, err, "")
return
}
2020-07-13 20:33:20 +08:00
res.Data = result
c.JSON(http.StatusOK, res.ReturnOK())
}
// @Summary 添加登录日志
// @Description 获取JSON
// @Tags 登录日志
// @Accept application/json
// @Product application/json
2022-10-25 18:16:04 +08:00
// @Param data body system.LoginLog true "data"
2020-07-13 20:33:20 +08:00
// @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
// @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
// @Router /api/v1/loginlog [post]
// @Security Bearer
func InsertLoginLog(c *gin.Context) {
2020-07-14 14:07:44 +08:00
var data system.LoginLog
2020-07-13 20:33:20 +08:00
err := c.BindWith(&data, binding.JSON)
2020-07-16 01:22:01 +08:00
if err != nil {
app.Error(c, -1, err, "")
return
}
2020-07-13 20:33:20 +08:00
result, err := data.Create()
2020-07-16 01:22:01 +08:00
if err != nil {
app.Error(c, -1, err, "")
return
}
2020-07-13 20:33:20 +08:00
var res app.Response
res.Data = result
c.JSON(http.StatusOK, res.ReturnOK())
}
// @Summary 修改登录日志
// @Description 获取JSON
// @Tags 登录日志
// @Accept application/json
// @Product application/json
2022-10-25 18:16:04 +08:00
// @Param data body system.LoginLog true "body"
2020-07-13 20:33:20 +08:00
// @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
// @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
// @Router /api/v1/loginlog [put]
// @Security Bearer
func UpdateLoginLog(c *gin.Context) {
2020-07-16 01:22:01 +08:00
var (
res app.Response
data system.LoginLog
)
2020-07-13 20:33:20 +08:00
err := c.BindWith(&data, binding.JSON)
2020-07-16 01:22:01 +08:00
if err != nil {
app.Error(c, -1, err, "")
return
}
2020-07-13 20:33:20 +08:00
result, err := data.Update(data.InfoId)
2020-07-16 01:22:01 +08:00
if err != nil {
app.Error(c, -1, err, "")
return
}
2020-07-13 20:33:20 +08:00
res.Data = result
c.JSON(http.StatusOK, res.ReturnOK())
}
// @Summary 批量删除登录日志
// @Description 删除数据
// @Tags 登录日志
// @Param infoId path string true "以逗号(,分割的infoId"
// @Success 200 {string} string "{"code": 200, "message": "删除成功"}"
// @Success 200 {string} string "{"code": -1, "message": "删除失败"}"
// @Router /api/v1/loginlog/{infoId} [delete]
func DeleteLoginLog(c *gin.Context) {
2020-07-16 01:22:01 +08:00
var (
res app.Response
data system.LoginLog
)
2020-07-13 20:33:20 +08:00
data.UpdateBy = tools.GetUserIdStr(c)
IDS := tools.IdsStrToIdsIntGroup("infoId", c)
_, err := data.BatchDelete(IDS)
2020-07-16 01:22:01 +08:00
if err != nil {
app.Error(c, -1, err, "")
return
}
2020-07-13 20:33:20 +08:00
res.Msg = "删除成功"
c.JSON(http.StatusOK, res.ReturnOK())
}
2020-08-26 22:03:33 +08:00
func CleanLoginLog(c *gin.Context) {
err := orm.Eloquent.Delete(&system.LoginLog{}).Error
if err != nil {
app.Error(c, -1, err, "")
return
}
app.OK(c, "", "已清空")
}