This commit is contained in:
PandaGoAdmin
2021-12-17 11:55:49 +08:00
parent b6b95566e3
commit da9e1cf29c
13 changed files with 134 additions and 47 deletions

View File

@@ -25,10 +25,10 @@ type LogLoginApi struct {
func (l LogLoginApi) GetLoginLogList(rc *ctx.ReqCtx) {
pageNum := ginx.QueryInt(rc.GinCtx, "pageNum", 1)
pageSize := ginx.QueryInt(rc.GinCtx, "pageSize", 10)
status := rc.GinCtx.Query("status")
loginLocation := rc.GinCtx.Query("loginLocation")
username := rc.GinCtx.Query("username")
list, total := l.LogLoginApp.FindListPage(pageNum, pageSize, entity.LogLogin{Status: status, Username: username})
list, total := l.LogLoginApp.FindListPage(pageNum, pageSize, entity.LogLogin{LoginLocation: loginLocation, Username: username})
rc.ResData = map[string]interface{}{
"data": list,
"total": total,
@@ -49,22 +49,6 @@ func (l LogLoginApi) GetLoginLog(rc *ctx.ReqCtx) {
rc.ResData = l.LogLoginApp.FindOne(int64(infoId))
}
// @Summary 添加登录日志
// @Description 获取JSON
// @Tags 登录日志
// @Accept application/json
// @Product application/json
// @Param data body entity.LogLogin true "data"
// @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
// @Success 200 {string} string "{"code": 400, "message": "添加失败"}"
// @Router /system/log/logLogin [post]
// @Security X-TOKEN
func (l LogLoginApi) InsertLoginLog(rc *ctx.ReqCtx) {
var log entity.LogLogin
ginx.BindJsonAndValid(rc.GinCtx, &log)
l.LogLoginApp.Insert(log)
}
// @Summary 修改登录日志
// @Description 获取JSON
// @Tags 登录日志
@@ -93,3 +77,13 @@ func (l LogLoginApi) DeleteLoginLog(rc *ctx.ReqCtx) {
group := utils.IdsStrToIdsIntGroup(infoIds)
l.LogLoginApp.Delete(group)
}
// @Summary 清空登录日志
// @Description 删除数据
// @Tags 登录日志
// @Success 200 {string} string "{"code": 200, "message": "删除成功"}"
// @Success 200 {string} string "{"code": 400, "message": "删除失败"}"
// @Router /system/log/logLogin/all [delete]
func (l LogLoginApi) DeleteAll(rc *ctx.ReqCtx) {
l.LogLoginApp.DeleteAll()
}

View File

@@ -1,6 +1,7 @@
package api
import (
"log"
"pandax/base/ctx"
"pandax/base/ginx"
"pandax/base/utils"
@@ -25,11 +26,11 @@ type LogOperApi struct {
func (l LogOperApi) GetOperLogList(rc *ctx.ReqCtx) {
pageNum := ginx.QueryInt(rc.GinCtx, "pageNum", 1)
pageSize := ginx.QueryInt(rc.GinCtx, "pageSize", 10)
status := rc.GinCtx.Query("status")
businessType := rc.GinCtx.Query("businessType")
operName := rc.GinCtx.Query("operName")
title := rc.GinCtx.Query("title")
list, total := l.LogOperApp.FindListPage(pageNum, pageSize, entity.LogOper{Status: status, OperName: operName, Title: title})
list, total := l.LogOperApp.FindListPage(pageNum, pageSize, entity.LogOper{BusinessType: businessType, OperName: operName, Title: title})
rc.ResData = map[string]interface{}{
"data": list,
"total": total,
@@ -60,5 +61,16 @@ func (l LogOperApi) GetOperLog(rc *ctx.ReqCtx) {
func (l LogOperApi) DeleteOperLog(rc *ctx.ReqCtx) {
operIds := rc.GinCtx.Param("operId")
group := utils.IdsStrToIdsIntGroup(operIds)
log.Println("group", group)
l.LogOperApp.Delete(group)
}
// @Summary 清空操作日志
// @Description 删除数据
// @Tags 操作日志
// @Success 200 {string} string "{"code": 200, "message": "删除成功"}"
// @Success 200 {string} string "{"code": 400, "message": "删除失败"}"
// @Router /system/log/logOper/all [delete]
func (l LogOperApi) DeleteAll(rc *ctx.ReqCtx) {
l.LogOperApp.DeleteAll()
}

View File

@@ -99,6 +99,7 @@ func (u *UserApi) Login(rc *ctx.ReqCtx) {
var loginLog entity.LogLogin
ua := user_agent.New(rc.GinCtx.Request.UserAgent())
loginLog.Ipaddr = rc.GinCtx.ClientIP()
loginLog.LoginLocation = utils.GetRealAddressByIP(rc.GinCtx.ClientIP())
loginLog.LoginTime = time.Now()
loginLog.Status = "0"
loginLog.Remark = rc.GinCtx.Request.UserAgent()
@@ -108,6 +109,7 @@ func (u *UserApi) Login(rc *ctx.ReqCtx) {
loginLog.Platform = ua.Platform()
loginLog.Username = login.Username
loginLog.Msg = "登录成功"
loginLog.CreateBy = login.Username
u.LogLogin.Insert(loginLog)
}

View File

@@ -7,11 +7,11 @@ import (
type LogOper struct {
OperId int64 `json:"operId" gorm:"primary_key;AUTO_INCREMENT"` //主键
Title string `json:"title" gorm:"type:varchar(128);comment:操作的模块"`
BusinessType int64 `json:"businessType" gorm:"type:int(1);comment:0其它 1新增 2修改 3删除"`
BusinessType string `json:"businessType" gorm:"type:varchar(1);comment:0其它 1新增 2修改 3删除"`
Method string `json:"method" gorm:"type:varchar(255);comment:请求方法"`
OperName string `json:"operName" gorm:"type:varchar(255);comment:操作人员"`
OperUrl string `json:"operUrl" gorm:"type:varchar(255);comment:操作url"`
OperIp string `json:"platform" gorm:"type:varchar(255);comment:操作IP"`
OperIp string `json:"operIp" gorm:"type:varchar(255);comment:操作IP"`
OperLocation string `json:"operLocation" gorm:"type:varchar(255);comment:操作地点"`
OperParam string `json:"operParam" gorm:"type:varchar(255);comment:请求参数"` //
Status string `json:"status" gorm:"type:varchar(1);comment:0=正常,1=异常"`

View File

@@ -15,7 +15,7 @@ func InitLogRouter(router *gin.RouterGroup) {
logLogin := router.Group("logLogin")
logLoginListLog := ctx.NewLogInfo("获取登录日志列表")
logLogin.GET("logLoginList", func(c *gin.Context) {
logLogin.GET("list", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).WithLog(logLoginListLog).Handle(login.GetLoginLogList)
})
@@ -24,16 +24,16 @@ func InitLogRouter(router *gin.RouterGroup) {
ctx.NewReqCtxWithGin(c).WithLog(getLogLoginLog).Handle(login.GetLoginLog)
})
inserLogLoginLog := ctx.NewLogInfo("添加登录日志信息")
logLogin.POST("", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).WithLog(inserLogLoginLog).Handle(login.InsertLoginLog)
})
updateLogLoginLog := ctx.NewLogInfo("修改登录日志信息")
logLogin.PUT("", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).WithLog(updateLogLoginLog).Handle(login.UpdateLoginLog)
})
deleteLogLoginAllLog := ctx.NewLogInfo("删除登录日志信息")
logLogin.DELETE("all", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).WithLog(deleteLogLoginAllLog).Handle(login.DeleteAll)
})
deleteLogLoginLog := ctx.NewLogInfo("删除登录日志信息")
logLogin.DELETE(":infoId", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).WithLog(deleteLogLoginLog).Handle(login.DeleteLoginLog)
@@ -46,7 +46,7 @@ func InitLogRouter(router *gin.RouterGroup) {
logOper := router.Group("logOper")
logOperListLog := ctx.NewLogInfo("获取操作日志列表")
logOper.GET("logOperList", func(c *gin.Context) {
logOper.GET("list", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).WithLog(logOperListLog).Handle(oper.GetOperLogList)
})
@@ -55,6 +55,11 @@ func InitLogRouter(router *gin.RouterGroup) {
ctx.NewReqCtxWithGin(c).WithLog(getLogOperLog).Handle(oper.GetOperLog)
})
deleteLogOperAllLog := ctx.NewLogInfo("删除操作日志信息")
logOper.DELETE("all", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).WithLog(deleteLogOperAllLog).Handle(oper.DeleteAll)
})
deleteLogOperLog := ctx.NewLogInfo("删除操作日志信息")
logOper.DELETE(":operId", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).WithLog(deleteLogOperLog).Handle(oper.DeleteOperLog)

View File

@@ -13,6 +13,7 @@ type (
FindListPage(page, pageSize int, data entity.LogLogin) (*[]entity.LogLogin, int64)
Update(data entity.LogLogin) *entity.LogLogin
Delete(infoId []int64)
DeleteAll()
}
logLoginModelImpl struct {
@@ -27,9 +28,7 @@ var LogLoginModelDao LogLoginModel = &logLoginModelImpl{
func (m *logLoginModelImpl) Insert(data entity.LogLogin) *entity.LogLogin {
data.CreateBy = "0"
data.UpdateBy = "0"
err := global.Db.Table(m.table).Create(&data).Error
biz.ErrIsNil(err, "添加登录日志信息失败")
global.Db.Table(m.table).Create(&data)
return &data
}
@@ -49,6 +48,9 @@ func (m *logLoginModelImpl) FindListPage(page, pageSize int, data entity.LogLogi
if data.Status != "" {
db = db.Where("status = ?", data.Status)
}
if data.LoginLocation != "" {
db = db.Where("login_location like ?", "%"+data.LoginLocation+"%")
}
if data.Username != "" {
db = db.Where("username like ?", "%"+data.Username+"%")
}
@@ -70,3 +72,7 @@ func (m *logLoginModelImpl) Delete(infoIds []int64) {
biz.ErrIsNil(err, "删除登录日志信息失败")
return
}
func (m *logLoginModelImpl) DeleteAll() {
global.Db.Exec("DELETE FROM log_logins")
}

View File

@@ -12,6 +12,7 @@ type (
FindOne(infoId int64) *entity.LogOper
FindListPage(page, pageSize int, data entity.LogOper) (*[]entity.LogOper, int64)
Delete(infoId []int64)
DeleteAll()
}
logLogOperModelImpl struct {
@@ -20,14 +21,11 @@ type (
)
var LogOperModelDao LogOperModel = &logLogOperModelImpl{
table: `log_logins`,
table: `log_opers`,
}
func (m *logLogOperModelImpl) Insert(data entity.LogOper) *entity.LogOper {
data.BusinessType = 1
err := global.Db.Table(m.table).Create(&data).Error
biz.ErrIsNil(err, "添加操作日志信息失败")
global.Db.Table(m.table).Create(&data)
return &data
}
@@ -44,8 +42,11 @@ func (m *logLogOperModelImpl) FindListPage(page, pageSize int, data entity.LogOp
offset := pageSize * (page - 1)
db := global.Db.Table(m.table)
// 此处填写 where参数判断
if data.Status != "" {
db = db.Where("status = ?", data.Status)
if data.BusinessType != "" {
db = db.Where("business_type = ?", data.BusinessType)
}
if data.OperLocation != "" {
db = db.Where("oper_location like ?", "%"+data.OperLocation+"%")
}
if data.Title != "" {
db = db.Where("title like ?", "%"+data.Title+"%")
@@ -65,3 +66,7 @@ func (m *logLogOperModelImpl) Delete(operIds []int64) {
biz.ErrIsNil(err, "删除操作日志信息失败")
return
}
func (m *logLogOperModelImpl) DeleteAll() {
global.Db.Exec("DELETE FROM log_opers")
}