feat: 更新多个模块以支持新的数据结构和日志格式

This commit is contained in:
TsMask
2025-02-20 10:08:27 +08:00
parent 045a2b6b01
commit f3c33b31ac
272 changed files with 13246 additions and 15885 deletions

View File

@@ -1,24 +1,99 @@
package repository
import "be.ems/src/modules/system/model"
import (
"fmt"
"time"
// ISysLogOperate 操作日志表 数据层接口
type ISysLogOperate interface {
// SelectSysLogOperatePage 分页查询系统操作日志集合
SelectSysLogOperatePage(query map[string]any, dataScopeSQL string) map[string]any
"be.ems/src/framework/database/db"
"be.ems/src/framework/logger"
"be.ems/src/modules/system/model"
)
// SelectSysLogOperateList 查询系统操作日志集合
SelectSysLogOperateList(sysLogOperate model.SysLogOperate) []model.SysLogOperate
// NewSysLogOperate 实例化数据层
var NewSysLogOperate = &SysLogOperate{}
// SelectSysLogOperateById 查询操作日志详细
SelectSysLogOperateById(operId string) model.SysLogOperate
// SysLogOperateRepository 操作日志表 数据层处理
type SysLogOperate struct{}
// InsertSysLogOperate 新增操作日志
InsertSysLogOperate(sysLogOperate model.SysLogOperate) string
// SelectByPage 分页查询集合
func (r SysLogOperate) SelectByPage(query map[string]string, dataScopeSQL string) ([]model.SysLogOperate, int64) {
tx := db.DB("").Model(&model.SysLogOperate{})
// 查询条件拼接
if v, ok := query["title"]; ok && v != "" {
tx = tx.Where("title like concat(?, '%')", v)
}
if v, ok := query["businessType"]; ok && v != "" {
tx = tx.Where("business_type = ?", v)
}
if v, ok := query["operaBy"]; ok && v != "" {
tx = tx.Where("opera_by like concat(?, '%')", v)
}
if v, ok := query["operaIp"]; ok && v != "" {
tx = tx.Where("opera_ip like concat(?, '%')", v)
}
if v, ok := query["statusFlag"]; ok && v != "" {
tx = tx.Where("status_flag = ?", v)
}
if v, ok := query["beginTime"]; ok && v != "" {
if len(v) == 10 {
v = fmt.Sprintf("%s000", v)
tx = tx.Where("opera_time >= ?", v)
} else if len(v) == 13 {
tx = tx.Where("opera_time >= ?", v)
}
}
if v, ok := query["endTime"]; ok && v != "" {
if len(v) == 10 {
v = fmt.Sprintf("%s999", v)
tx = tx.Where("opera_time <= ?", v)
} else if len(v) == 13 {
tx = tx.Where("opera_time <= ?", v)
}
}
if dataScopeSQL != "" {
dataScopeSQL = fmt.Sprintf("select distinct user_name from sys_user where %s", dataScopeSQL)
tx = tx.Where(fmt.Sprintf("opera_by in ( %s )", dataScopeSQL))
}
// DeleteSysLogOperateByIds 批量删除系统操作日志
DeleteSysLogOperateByIds(operIds []string) int64
// 查询结果
var total int64 = 0
rows := []model.SysLogOperate{}
// CleanSysLogOperate 清空操作日志
CleanSysLogOperate() error
// 查询数量为0直接返回
if err := tx.Count(&total).Error; err != nil || total <= 0 {
return rows, total
}
// 查询数据分页
pageNum, pageSize := db.PageNumSize(query["pageNum"], query["pageSize"])
tx = tx.Limit(pageSize).Offset(pageSize * pageNum)
err := tx.Order("id desc").Find(&rows).Error
if err != nil {
logger.Errorf("query find err => %v", err.Error())
return rows, total
}
return rows, total
}
// Insert 新增信息
func (r SysLogOperate) Insert(sysLogOperate model.SysLogOperate) int64 {
if sysLogOperate.OperaBy != "" {
sysLogOperate.OperaTime = time.Now().UnixMilli()
}
// 执行插入
if err := db.DB("").Create(&sysLogOperate).Error; err != nil {
logger.Errorf("insert err => %v", err.Error())
return 0
}
return sysLogOperate.ID
}
// Clean 清空信息
func (r SysLogOperate) Clean() int64 {
tx := db.DB("").Delete(&model.SysLogOperate{})
if err := tx.Error; err != nil {
logger.Errorf("delete err => %v", err.Error())
return 0
}
return tx.RowsAffected
}