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
@@ -8,7 +8,6 @@ import (
"go-admin/app/admin/service/dto"
"go-admin/common/apis"
"go-admin/common/log"
common "go-admin/common/models"
"go-admin/tools"
"net/http"
@@ -27,10 +26,8 @@ func (e *SysLoginLog) GetSysLoginLogList(c *gin.Context) {
return
}
req := d.Generate()
//查询列表
err = req.Bind(c)
err = d.Bind(c)
if err != nil {
e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败")
return
@@ -41,13 +38,13 @@ func (e *SysLoginLog) GetSysLoginLogList(c *gin.Context) {
serviceStudent := service.SysLoginLog{}
serviceStudent.MsgID = msgID
serviceStudent.Orm = db
err = serviceStudent.GetSysLoginLogPage(req, &list, &count)
err = serviceStudent.GetSysLoginLogPage(d, &list, &count)
if err != nil {
e.Error(c, http.StatusUnprocessableEntity, err, "查询失败")
return
}
e.PageOK(c, list, int(count), req.GetPageIndex(), req.GetPageSize(), "查询成功")
e.PageOK(c, list, int(count), d.GetPageIndex(), d.GetPageSize(), "查询成功")
}
func (e *SysLoginLog) GetSysLoginLog(c *gin.Context) {
@@ -60,8 +57,7 @@ func (e *SysLoginLog) GetSysLoginLog(c *gin.Context) {
msgID := tools.GenerateMsgIDFromContext(c)
//查看详情
req := control.Generate()
err = req.Bind(c)
err = control.Bind(c)
if err != nil {
e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败")
return
@@ -71,7 +67,7 @@ func (e *SysLoginLog) GetSysLoginLog(c *gin.Context) {
serviceSysLoginLog := service.SysLoginLog{}
serviceSysLoginLog.MsgID = msgID
serviceSysLoginLog.Orm = db
err = serviceSysLoginLog.GetSysLoginLog(req, &object)
err = serviceSysLoginLog.GetSysLoginLog(control, &object)
if err != nil {
e.Error(c, http.StatusUnprocessableEntity, err, "查询失败")
return
@@ -90,14 +86,12 @@ func (e *SysLoginLog) InsertSysLoginLog(c *gin.Context) {
msgID := tools.GenerateMsgIDFromContext(c)
//新增操作
req := control.Generate()
err = req.Bind(c)
err = control.Bind(c)
if err != nil {
e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败")
return
}
var object common.ActiveRecord
object, err = req.GenerateM()
object, err := control.Generate()
if err != nil {
e.Error(c, http.StatusInternalServerError, err, "模型生成失败")
return
@@ -127,15 +121,13 @@ func (e *SysLoginLog) UpdateSysLoginLog(c *gin.Context) {
}
msgID := tools.GenerateMsgIDFromContext(c)
req := control.Generate()
//更新操作
err = req.Bind(c)
err = control.Bind(c)
if err != nil {
e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败")
return
}
var object common.ActiveRecord
object, err = req.GenerateM()
object, err := control.Generate()
if err != nil {
e.Error(c, http.StatusInternalServerError, err, "模型生成失败")
return
@@ -163,15 +155,13 @@ func (e *SysLoginLog) DeleteSysLoginLog(c *gin.Context) {
msgID := tools.GenerateMsgIDFromContext(c)
//删除操作
req := control.Generate()
err = req.Bind(c)
err = control.Bind(c)
if err != nil {
log.Errorf("MsgID[%s] Bind error: %s", msgID, err)
e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败")
return
}
var object common.ActiveRecord
object, err = req.GenerateM()
object, err := control.GenerateM()
if err != nil {
e.Error(c, http.StatusInternalServerError, err, "模型生成失败")
return
@@ -183,7 +173,7 @@ func (e *SysLoginLog) DeleteSysLoginLog(c *gin.Context) {
serviceSysLoginLog := service.SysLoginLog{}
serviceSysLoginLog.Orm = db
serviceSysLoginLog.MsgID = msgID
err = serviceSysLoginLog.RemoveSysLoginLog(req, object)
err = serviceSysLoginLog.RemoveSysLoginLog(control, object)
if err != nil {
log.Error(err)
return
@@ -8,7 +8,6 @@ import (
"go-admin/app/admin/service/dto"
"go-admin/common/apis"
"go-admin/common/log"
common "go-admin/common/models"
"go-admin/tools"
"net/http"
@@ -27,10 +26,8 @@ func (e *SysOperaLog) GetSysOperaLogList(c *gin.Context) {
return
}
req := d.Generate()
//查询列表
err = req.Bind(c)
err = d.Bind(c)
if err != nil {
e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败")
return
@@ -41,13 +38,13 @@ func (e *SysOperaLog) GetSysOperaLogList(c *gin.Context) {
serviceStudent := service.SysOperaLog{}
serviceStudent.MsgID = msgID
serviceStudent.Orm = db
err = serviceStudent.GetSysOperaLogPage(req, &list, &count)
err = serviceStudent.GetSysOperaLogPage(d, &list, &count)
if err != nil {
e.Error(c, http.StatusUnprocessableEntity, err, "查询失败")
return
}
e.PageOK(c, list, int(count), req.GetPageIndex(), req.GetPageSize(), "查询成功")
e.PageOK(c, list, int(count), d.GetPageIndex(), d.GetPageSize(), "查询成功")
}
func (e *SysOperaLog) GetSysOperaLog(c *gin.Context) {
@@ -60,8 +57,7 @@ func (e *SysOperaLog) GetSysOperaLog(c *gin.Context) {
msgID := tools.GenerateMsgIDFromContext(c)
//查看详情
req := control.Generate()
err = req.Bind(c)
err = control.Bind(c)
if err != nil {
e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败")
return
@@ -71,7 +67,7 @@ func (e *SysOperaLog) GetSysOperaLog(c *gin.Context) {
serviceSysOperlog := service.SysOperaLog{}
serviceSysOperlog.MsgID = msgID
serviceSysOperlog.Orm = db
err = serviceSysOperlog.GetSysOperaLog(req, &object)
err = serviceSysOperlog.GetSysOperaLog(control, &object)
if err != nil {
e.Error(c, http.StatusUnprocessableEntity, err, "查询失败")
return
@@ -90,14 +86,12 @@ func (e *SysOperaLog) InsertSysOperaLog(c *gin.Context) {
msgID := tools.GenerateMsgIDFromContext(c)
//新增操作
req := control.Generate()
err = req.Bind(c)
err = control.Bind(c)
if err != nil {
e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败")
return
}
var object common.ActiveRecord
object, err = req.GenerateM()
object, err := control.Generate()
if err != nil {
e.Error(c, http.StatusInternalServerError, err, "模型生成失败")
return
@@ -127,15 +121,13 @@ func (e *SysOperaLog) UpdateSysOperaLog(c *gin.Context) {
}
msgID := tools.GenerateMsgIDFromContext(c)
req := control.Generate()
//更新操作
err = req.Bind(c)
err = control.Bind(c)
if err != nil {
e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败")
return
}
var object common.ActiveRecord
object, err = req.GenerateM()
object, err := control.Generate()
if err != nil {
e.Error(c, http.StatusInternalServerError, err, "模型生成失败")
return
@@ -163,30 +155,20 @@ func (e *SysOperaLog) DeleteSysOperaLog(c *gin.Context) {
msgID := tools.GenerateMsgIDFromContext(c)
//删除操作
req := control.Generate()
err = req.Bind(c)
err = control.Bind(c)
if err != nil {
log.Errorf("MsgID[%s] Bind error: %s", msgID, err)
e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败")
return
}
var object common.ActiveRecord
object, err = req.GenerateM()
if err != nil {
e.Error(c, http.StatusInternalServerError, err, "模型生成失败")
return
}
// 设置编辑人
object.SetUpdateBy(tools.GetUserId(c))
serviceSysOperaLog := service.SysOperaLog{}
serviceSysOperaLog.Orm = db
serviceSysOperaLog.MsgID = msgID
err = serviceSysOperaLog.RemoveSysOperaLog(req, object)
err = serviceSysOperaLog.RemoveSysOperaLog(control)
if err != nil {
log.Error(err)
return
}
e.OK(c, object.GetId(), "删除成功")
e.OK(c, control.GetId(), "删除成功")
}
+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
}
}