perf👌 : 登陆日志和操作日志功能优化

This commit is contained in:
zhangwenjian
2021-01-11 16:27:07 +08:00
parent 0db58170ee
commit abe9c42aff
6 changed files with 90 additions and 102 deletions
+28 -20
View File
@@ -13,11 +13,10 @@ import (
type SysLoginLogSearch struct {
dto.Pagination `search:"-"`
Username string `form:"username" search:"type:exact;column:username;table:sys_login_log" comment:"用户名"`
Status string `form:"status" search:"type:exact;column:status;table:sys_login_log" comment:"状态"`
Ipaddr string `form:"ipaddr" search:"type:exact;column:ipaddr;table:sys_login_log" comment:"ip地址"`
LoginLocation string `form:"loginLocation" search:"type:exact;column:login_location;table:sys_login_log" comment:"归属地"`
Username string `form:"username" search:"type:exact;column:username;table:sys_login_log" comment:"用户名"`
Status string `form:"status" search:"type:exact;column:status;table:sys_login_log" comment:"状态"`
Ipaddr string `form:"ipaddr" search:"type:exact;column:ipaddr;table:sys_login_log" comment:"ip地址"`
LoginLocation string `form:"loginLocation" search:"type:exact;column:login_location;table:sys_login_log" comment:"归属地"`
}
func (m *SysLoginLogSearch) GetNeedSearch() interface{} {
@@ -33,13 +32,8 @@ func (m *SysLoginLogSearch) Bind(ctx *gin.Context) error {
return err
}
func (m *SysLoginLogSearch) Generate() dto.Index {
o := *m
return &o
}
type SysLoginLogControl struct {
ID int `uri:"ID" comment:"主键"` // 主键
ID int `uri:"ID" comment:"主键"` // 主键
Username string `json:"username" comment:"用户名"`
Status string `json:"status" comment:"状态"`
Ipaddr string `json:"ipaddr" comment:"ip地址"`
@@ -66,12 +60,7 @@ func (s *SysLoginLogControl) Bind(ctx *gin.Context) error {
return err
}
func (s *SysLoginLogControl) Generate() dto.Control {
cp := *s
return &cp
}
func (s *SysLoginLogControl) GenerateM() (common.ActiveRecord, error) {
func (s *SysLoginLogControl) Generate() (*system.SysLoginLog, error) {
return &system.SysLoginLog{
Model: common.Model{ID: s.ID},
Username: s.Username,
@@ -92,14 +81,33 @@ func (s *SysLoginLogControl) GetId() interface{} {
}
type SysLoginLogById struct {
dto.ObjectById
Id int `uri:"id"`
Ids []int `json:"ids"`
}
func (s *SysLoginLogById) Generate() dto.Control {
func (s *SysLoginLogById) GetId() interface{} {
return s.Id
}
func (s *SysLoginLogById) Bind(ctx *gin.Context) error {
msgID := tools.GenerateMsgIDFromContext(ctx)
err := ctx.ShouldBindUri(s)
if err != nil {
log.Debugf("MsgID[%s] ShouldBindUri error: %s", msgID, err.Error())
return err
}
err = ctx.ShouldBind(s)
if err != nil {
log.Debugf("MsgID[%s] ShouldBind error: %#v", msgID, err.Error())
}
return err
}
func (s *SysLoginLogById) Generate() *SysLoginLogById {
cp := *s
return &cp
}
func (s *SysLoginLogById) GenerateM() (common.ActiveRecord, error) {
func (s *SysLoginLogById) GenerateM() (*system.SysLoginLog, error) {
return &system.SysLoginLog{}, nil
}
+26 -18
View File
@@ -34,13 +34,8 @@ func (m *SysOperaLogSearch) Bind(ctx *gin.Context) error {
return err
}
func (m *SysOperaLogSearch) Generate() dto.Index {
o := *m
return &o
}
type SysOperaLogControl struct {
ID int `uri:"ID" comment:"编码"` // 编码
ID int `uri:"ID" comment:"编码"` // 编码
Title string `json:"title" comment:"操作模块"`
BusinessType string `json:"businessType" comment:"操作类型"`
BusinessTypes string `json:"businessTypes" comment:""`
@@ -75,12 +70,7 @@ func (s *SysOperaLogControl) Bind(ctx *gin.Context) error {
return err
}
func (s *SysOperaLogControl) Generate() dto.Control {
cp := *s
return &cp
}
func (s *SysOperaLogControl) GenerateM() (common.ActiveRecord, error) {
func (s *SysOperaLogControl) Generate() (*system.SysOperaLog, error) {
return &system.SysOperaLog{
Model: common.Model{ID: s.ID},
Title: s.Title,
@@ -109,14 +99,32 @@ func (s *SysOperaLogControl) GetId() interface{} {
}
type SysOperaLogById struct {
dto.ObjectById
Id int `uri:"id"`
Ids []int `json:"ids"`
}
func (s *SysOperaLogById) Generate() dto.Control {
cp := *s
return &cp
func (s *SysOperaLogById) GetId() interface{} {
if len(s.Ids) > 0 {
s.Ids = append(s.Ids, s.Id)
return s.Ids
}
return s.Id
}
func (s *SysOperaLogById) GenerateM() (common.ActiveRecord, error) {
return &system.SysOperaLog{}, nil
func (s *SysOperaLogById) Bind(ctx *gin.Context) error {
msgID := tools.GenerateMsgIDFromContext(ctx)
err := ctx.ShouldBindUri(s)
if err != nil {
log.Debugf("MsgID[%s] ShouldBindUri error: %s", msgID, err.Error())
return err
}
err = ctx.ShouldBind(s)
if err != nil {
log.Debugf("MsgID[%s] ShouldBind error: %#v", msgID, err.Error())
}
return err
}
func (s *SysOperaLogById) SetUpdateBy(id int) {
}
+4 -3
View File
@@ -3,6 +3,7 @@ package service
import (
"errors"
"go-admin/app/admin/models/system"
"go-admin/app/admin/service/dto"
cDto "go-admin/common/dto"
"go-admin/common/log"
common "go-admin/common/models"
@@ -15,7 +16,7 @@ type SysLoginLog struct {
}
// GetSysLoginLogPage 获取SysLoginLog列表
func (e *SysLoginLog) GetSysLoginLogPage(c cDto.Index, list *[]system.SysLoginLog, count *int64) error {
func (e *SysLoginLog) GetSysLoginLogPage(c *dto.SysLoginLogSearch, list *[]system.SysLoginLog, count *int64) error {
var err error
var data system.SysLoginLog
msgID := e.MsgID
@@ -35,7 +36,7 @@ func (e *SysLoginLog) GetSysLoginLogPage(c cDto.Index, list *[]system.SysLoginLo
}
// GetSysLoginLog 获取SysLoginLog对象
func (e *SysLoginLog) GetSysLoginLog(d cDto.Control, model *system.SysLoginLog) error {
func (e *SysLoginLog) GetSysLoginLog(d *dto.SysLoginLogById, model *system.SysLoginLog) error {
var err error
var data system.SysLoginLog
msgID := e.MsgID
@@ -90,7 +91,7 @@ func (e *SysLoginLog) UpdateSysLoginLog(c common.ActiveRecord) error {
}
// RemoveSysLoginLog 删除SysLoginLog
func (e *SysLoginLog) RemoveSysLoginLog(d cDto.Control, c common.ActiveRecord) error {
func (e *SysLoginLog) RemoveSysLoginLog(d *dto.SysLoginLogById, c common.ActiveRecord) error {
var err error
var data system.SysLoginLog
msgID := e.MsgID
+8 -9
View File
@@ -3,9 +3,9 @@ package service
import (
"errors"
"go-admin/app/admin/models/system"
"go-admin/app/admin/service/dto"
cDto "go-admin/common/dto"
"go-admin/common/log"
common "go-admin/common/models"
"go-admin/common/service"
"gorm.io/gorm"
)
@@ -15,7 +15,7 @@ type SysOperaLog struct {
}
// GetSysOperaLogPage 获取SysOperaLog列表
func (e *SysOperaLog) GetSysOperaLogPage(c cDto.Index, list *[]system.SysOperaLog, count *int64) error {
func (e *SysOperaLog) GetSysOperaLogPage(c *dto.SysOperaLogSearch, list *[]system.SysOperaLog, count *int64) error {
var err error
var data system.SysOperaLog
msgID := e.MsgID
@@ -35,7 +35,7 @@ func (e *SysOperaLog) GetSysOperaLogPage(c cDto.Index, list *[]system.SysOperaLo
}
// GetSysOperaLog 获取SysOperaLog对象
func (e *SysOperaLog) GetSysOperaLog(d cDto.Control, model *system.SysOperaLog) error {
func (e *SysOperaLog) GetSysOperaLog(d *dto.SysOperaLogById, model *system.SysOperaLog) error {
var err error
var data system.SysOperaLog
msgID := e.MsgID
@@ -56,7 +56,7 @@ func (e *SysOperaLog) GetSysOperaLog(d cDto.Control, model *system.SysOperaLog)
}
// InsertSysOperaLog 创建SysOperaLog对象
func (e *SysOperaLog) InsertSysOperaLog(model common.ActiveRecord) error {
func (e *SysOperaLog) InsertSysOperaLog(model *system.SysOperaLog) error {
var err error
var data system.SysOperaLog
msgID := e.MsgID
@@ -71,7 +71,7 @@ func (e *SysOperaLog) InsertSysOperaLog(model common.ActiveRecord) error {
}
// UpdateSysOperaLog 修改SysOperaLog对象
func (e *SysOperaLog) UpdateSysOperaLog(c common.ActiveRecord) error {
func (e *SysOperaLog) UpdateSysOperaLog(c *system.SysOperaLog) error {
var err error
var data system.SysOperaLog
msgID := e.MsgID
@@ -90,13 +90,12 @@ func (e *SysOperaLog) UpdateSysOperaLog(c common.ActiveRecord) error {
}
// RemoveSysOperaLog 删除SysOperaLog
func (e *SysOperaLog) RemoveSysOperaLog(d cDto.Control, c common.ActiveRecord) error {
func (e *SysOperaLog) RemoveSysOperaLog(d *dto.SysOperaLogById) error {
var err error
var data system.SysOperaLog
msgID := e.MsgID
db := e.Orm.Model(&data).
Where(d.GetId()).Delete(c)
db := e.Orm.Model(&data).Delete(&data, d.GetId())
if db.Error != nil {
err = db.Error
log.Errorf("MsgID[%s] Delete error: %s", msgID, err)
@@ -107,4 +106,4 @@ func (e *SysOperaLog) RemoveSysOperaLog(d cDto.Control, c common.ActiveRecord) e
return err
}
return nil
}
}