From da9e1cf29ca18f3317bb9e7ed762561692d2c3b4 Mon Sep 17 00:00:00 2001 From: PandaGoAdmin <18610165312@163.com> Date: Fri, 17 Dec 2021 11:55:49 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=B4=E6=98=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- go.mod | 6 +++- go.sum | 12 ++++++++ initialize/router.go | 16 ++++++---- main.go | 2 ++ {base/middleware => middleware}/cors.go | 0 middleware/oper.go | 41 +++++++++++++++++++++++++ system/api/log_login.go | 30 ++++++++---------- system/api/log_oper.go | 18 +++++++++-- system/api/user.go | 2 ++ system/entity/log_oper.go | 4 +-- system/router/log.go | 19 +++++++----- system/services/log_login.go | 12 ++++++-- system/services/log_oper.go | 19 +++++++----- 13 files changed, 134 insertions(+), 47 deletions(-) rename {base/middleware => middleware}/cors.go (100%) create mode 100644 middleware/oper.go diff --git a/go.mod b/go.mod index a30be87..e7fc86d 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module pandax go 1.16 require ( - github.com/gin-gonic/gin v1.7.2 + github.com/gin-gonic/gin v1.7.4 github.com/go-redis/redis v6.15.9+incompatible github.com/gorilla/websocket v1.4.2 // ssh @@ -26,10 +26,14 @@ require ( github.com/mssola/user_agent v0.5.3 github.com/onsi/ginkgo v1.16.4 // indirect github.com/sirupsen/logrus v1.8.1 + github.com/swaggo/gin-swagger v1.3.3 // indirect github.com/swaggo/swag v1.7.6 + github.com/urfave/cli v1.20.0 // indirect github.com/xuri/excelize/v2 v2.4.1 golang.org/x/net v0.0.0-20211116231205-47ca1ff31462 // indirect golang.org/x/sys v0.0.0-20211117180635-dee7805ff2e1 // indirect + gopkg.in/go-playground/assert.v1 v1.2.1 // indirect + gopkg.in/go-playground/validator.v8 v8.18.2 // indirect gorm.io/driver/mysql v1.2.0 gorm.io/driver/postgres v1.2.3 ) diff --git a/go.sum b/go.sum index 5690a25..8ca78ec 100644 --- a/go.sum +++ b/go.sum @@ -37,10 +37,14 @@ github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMo github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4= github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= +github.com/gin-contrib/gzip v0.0.3/go.mod h1:YxxswVZIqOvcHEQpsSn+QF5guQtO1dCfy0shBPy4jFc= github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE= github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= +github.com/gin-gonic/gin v1.6.3/go.mod h1:75u5sXoLsGZoRN5Sgbi1eraJ4GU3++wFwWzhwvtwp4M= github.com/gin-gonic/gin v1.7.2 h1:Tg03T9yM2xa8j6I3Z3oqLaQRSmKvxPd6g/2HJ6zICFA= github.com/gin-gonic/gin v1.7.2/go.mod h1:jD2toBW3GZUr5UMcdrwQA10I7RuaFOl/SGeDjXkfUtY= +github.com/gin-gonic/gin v1.7.4 h1:QmUZXrvJ9qZ3GfWvQ+2wnW/1ePrTEJqPKMYEU3lD/DM= +github.com/gin-gonic/gin v1.7.4/go.mod h1:jD2toBW3GZUr5UMcdrwQA10I7RuaFOl/SGeDjXkfUtY= github.com/go-kit/log v0.1.0/go.mod h1:zbhenjAZHb184qTLMA9ZjW7ThYL0H2mk7Q6pNt4vbaY= github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG1KdI/P7A= github.com/go-ole/go-ole v1.2.5 h1:t4MGB5xEDZvXI+0rMjjsfBsD7yAgp/s9ZDkL1JndXwY= @@ -61,6 +65,7 @@ github.com/go-playground/locales v0.13.0 h1:HyWk6mgj5qFqCT5fjGBuRArbVDfE4hi8+e8c github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8= github.com/go-playground/universal-translator v0.17.0 h1:icxd5fm+REJzpZx7ZfpaD876Lmtgy7VtROAbHHXk8no= github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA= +github.com/go-playground/validator/v10 v10.2.0/go.mod h1:uOYAAleCW8F/7oMFd6aG0GOhaH6EGOAJShg8Id5JGkI= github.com/go-playground/validator/v10 v10.4.1 h1:pH2c5ADXtd66mxoE0Zm9SUhxE20r7aM3F26W0hOn+GE= github.com/go-playground/validator/v10 v10.4.1/go.mod h1:nlOn6nFhuKACm19sB/8EGNn9GlaMV7XkbRSipzJ0Ii4= github.com/go-redis/redis v6.15.9+incompatible h1:K0pv1D7EQUjfyoMql+r/jZqCLizCGKFlFgcHWWmHQjg= @@ -257,12 +262,17 @@ github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5 github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/swaggo/files v0.0.0-20190704085106-630677cd5c14/go.mod h1:gxQT6pBGRuIGunNf/+tSOB5OHvguWi8Tbt82WOkf35E= +github.com/swaggo/gin-swagger v1.3.3 h1:XHyYmeNVFG5PbyWHG4jXtxOm2P4kiZapDCWsyDDiQ/I= +github.com/swaggo/gin-swagger v1.3.3/go.mod h1:ymsZuGpbbu+S7ZoQ49QPpZoDBj6uqhb8WizgQPVgWl0= +github.com/swaggo/swag v1.7.4/go.mod h1:zD8h6h4SPv7t3l+4BKdRquqW1ASWjKZgT6Qv9z3kNqI= github.com/swaggo/swag v1.7.6 h1:UbAqHyXkW2J+cDjs5S43MkuYR7a6stB7Am7SK8NBmRg= github.com/swaggo/swag v1.7.6/go.mod h1:7vLqNYEtYoIsD14wXgy9oDS65MNiDANrPtbk9rnLuj0= github.com/ugorji/go v1.1.7 h1:/68gy2h+1mWMrwZFeD1kQialdSzAb432dtpeJ42ovdo= github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw= github.com/ugorji/go/codec v1.1.7 h1:2SvQaVZ1ouYrrKKwoSk2pzd4A9evlKJb9oTL+OaLUSs= github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY= +github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA= github.com/urfave/cli/v2 v2.3.0/go.mod h1:LJmUH05zAU44vOAcrfzZQKsZbVcdbOG8rtL3/XcUArI= github.com/xuri/efp v0.0.0-20210322160811-ab561f5b45e3 h1:EpI0bqf/eX9SdZDwlMmahKM+CDBgNbsXMhsN28XrM8o= github.com/xuri/efp v0.0.0-20210322160811-ab561f5b45e3/go.mod h1:ybY/Jr0T0GTCnYjKqmdwxyxn2BQf2RcQIIvex5QldPI= @@ -389,6 +399,8 @@ gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8X gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= +gopkg.in/go-playground/assert.v1 v1.2.1/go.mod h1:9RXL0bg/zibRAgZUYszZSwO/z8Y/a8bDuhia5mkpMnE= +gopkg.in/go-playground/validator.v8 v8.18.2/go.mod h1:RX2a/7Ha8BgOhfk7j780h4/u/RRjR0eouCJSH80/M2Y= gopkg.in/inconshreveable/log15.v2 v2.0.0-20180818164646-67afb5ed74ec/go.mod h1:aPpfJ7XW+gOuirDoZ8gHhLh3kZ1B08FtV2bbmy7Jv3s= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= diff --git a/initialize/router.go b/initialize/router.go index f9284de..3ce5759 100644 --- a/initialize/router.go +++ b/initialize/router.go @@ -2,10 +2,14 @@ package initialize import ( "fmt" + ginSwagger "github.com/swaggo/gin-swagger" + "github.com/swaggo/gin-swagger/swaggerFiles" "pandax/base/config" - "pandax/base/middleware" + "pandax/middleware" sysRouter "pandax/system/router" + _ "pandax/docs" + "net/http" "github.com/gin-gonic/gin" @@ -41,7 +45,8 @@ func InitRouter() *gin.Engine { if serverConfig.Cors { router.Use(middleware.Cors()) } - + // api接口 + router.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler)) // 设置路由组 sys := router.Group("system") { @@ -50,20 +55,19 @@ func InitRouter() *gin.Engine { sysRouter.InitConfigRouter(sys) sysRouter.InitApiRouter(sys) sysRouter.InitDictRouter(sys) - sysRouter.InitLogRouter(sys) sysRouter.InitMenuRouter(sys) sysRouter.InitRoleRouter(sys) sysRouter.InitPostRouter(sys) sysRouter.InitUserRouter(sys) - } router.Group("job") { } - router.Group("log") + //日志系统 + log := router.Group("log") { - + sysRouter.InitLogRouter(log) } return router } diff --git a/main.go b/main.go index 0920fa3..6018c9d 100644 --- a/main.go +++ b/main.go @@ -6,11 +6,13 @@ import ( "pandax/base/global" "pandax/base/starter" "pandax/initialize" + "pandax/middleware" ) func main() { global.Db = starter.GormInit(config.Conf.Server.DbType) initialize.InitTable() + ctx.UseAfterHandlerInterceptor(middleware.OperationHandler) ctx.UseBeforeHandlerInterceptor(ctx.PermissionHandler) ctx.UseAfterHandlerInterceptor(ctx.LogHandler) starter.RunWebServer(initialize.InitRouter()) diff --git a/base/middleware/cors.go b/middleware/cors.go similarity index 100% rename from base/middleware/cors.go rename to middleware/cors.go diff --git a/middleware/oper.go b/middleware/oper.go new file mode 100644 index 0000000..84a95bb --- /dev/null +++ b/middleware/oper.go @@ -0,0 +1,41 @@ +package middleware + +import ( + "net/http" + "pandax/base/ctx" + "pandax/base/utils" + "pandax/system/entity" + "pandax/system/services" +) + +func OperationHandler(rc *ctx.ReqCtx) error { + c := rc.GinCtx + // 请求操作不做记录 + if c.Request.Method == http.MethodGet || rc.LoginAccount == nil { + return nil + } + if rc.RequiredPermission == nil || !rc.RequiredPermission.NeedToken { + return nil + } + oper := entity.LogOper{ + Title: rc.LogInfo.Description, + BusinessType: "0", + Method: c.Request.Method, + OperName: rc.LoginAccount.UserName, + OperUrl: c.Request.URL.Path, + OperIp: c.ClientIP(), + OperLocation: utils.GetRealAddressByIP(c.ClientIP()), + OperParam: "", + Status: "0", + } + if c.Request.Method == "POST" { + oper.BusinessType = "1" + } else if c.Request.Method == "PUT" { + oper.BusinessType = "2" + } else if c.Request.Method == "DELETE" { + oper.BusinessType = "3" + } + services.LogOperModelDao.Insert(oper) + + return nil +} diff --git a/system/api/log_login.go b/system/api/log_login.go index 9492f20..1504905 100644 --- a/system/api/log_login.go +++ b/system/api/log_login.go @@ -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() +} diff --git a/system/api/log_oper.go b/system/api/log_oper.go index efe7f25..ed266ec 100644 --- a/system/api/log_oper.go +++ b/system/api/log_oper.go @@ -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() +} diff --git a/system/api/user.go b/system/api/user.go index e338ff6..e7f33b5 100644 --- a/system/api/user.go +++ b/system/api/user.go @@ -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) } diff --git a/system/entity/log_oper.go b/system/entity/log_oper.go index 1c23e4b..d240f92 100644 --- a/system/entity/log_oper.go +++ b/system/entity/log_oper.go @@ -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=异常"` diff --git a/system/router/log.go b/system/router/log.go index d41653e..63883a6 100644 --- a/system/router/log.go +++ b/system/router/log.go @@ -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) diff --git a/system/services/log_login.go b/system/services/log_login.go index c28d7d1..01aa02e 100644 --- a/system/services/log_login.go +++ b/system/services/log_login.go @@ -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") +} diff --git a/system/services/log_oper.go b/system/services/log_oper.go index ee328ec..dcc956e 100644 --- a/system/services/log_oper.go +++ b/system/services/log_oper.go @@ -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") +}