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

@@ -3,15 +3,13 @@ package controller
import (
"fmt"
"strconv"
"strings"
"time"
"be.ems/src/framework/i18n"
"be.ems/src/framework/utils/ctx"
"be.ems/src/framework/reqctx"
"be.ems/src/framework/resp"
"be.ems/src/framework/utils/date"
"be.ems/src/framework/utils/file"
"be.ems/src/framework/utils/parse"
"be.ems/src/framework/vo/result"
"be.ems/src/modules/system/model"
"be.ems/src/modules/system/service"
@@ -20,15 +18,14 @@ import (
// 实例化控制层 SysLogOperateController 结构体
var NewSysLogOperate = &SysLogOperateController{
SysLogOperateService: service.NewSysLogOperateImpl,
sysLogOperateService: service.NewSysLogOperate,
}
// 操作日志记录信息
//
// PATH /system/log/operate
type SysLogOperateController struct {
// 操作日志服务
SysLogOperateService service.ISysLogOperate
sysLogOperateService *service.SysLogOperate // 操作日志服务
}
// 操作日志列表
@@ -47,90 +44,48 @@ type SysLogOperateController struct {
// @Description System Operation Log List
// @Router /system/log/operate/list [get]
func (s *SysLogOperateController) List(c *gin.Context) {
language := ctx.AcceptLanguage(c)
querys := ctx.QueryMap(c)
language := reqctx.AcceptLanguage(c)
query := reqctx.QueryMap(c)
// 多语言值转key查询
if v, ok := querys["title"]; ok && v != "" {
querys["title"] = i18n.TFindKeyPrefix(language, "log.operate.title", v.(string))
if v, ok := query["title"]; ok && v != "" {
query["title"] = i18n.TFindKeyPrefix(language, "log.operate.title", v)
}
dataScopeSQL := ctx.LoginUserToDataScopeSQL(c, "d", "u")
data := s.SysLogOperateService.SelectSysLogOperatePage(querys, dataScopeSQL)
rows := data["rows"].([]model.SysLogOperate)
dataScopeSQL := reqctx.LoginUserToDataScopeSQL(c, "sys_user", "sys_user")
rows, total := s.sysLogOperateService.FindByPage(query, dataScopeSQL)
// 闭包函数处理多语言
converI18n := func(language string, arr *[]model.SysLogOperate) {
for i := range *arr {
(*arr)[i].Title = i18n.TKey(language, (*arr)[i].Title)
(*arr)[i].OperLocation = i18n.TKey(language, (*arr)[i].OperLocation)
(*arr)[i].OperaLocation = i18n.TKey(language, (*arr)[i].OperaLocation)
}
}
converI18n(language, &rows)
c.JSON(200, result.Ok(data))
c.JSON(200, resp.OkData(map[string]any{"rows": rows, "total": total}))
}
// 操作日志删除
//
// DELETE /:operIds
func (s *SysLogOperateController) Remove(c *gin.Context) {
language := ctx.AcceptLanguage(c)
operIds := c.Param("operIds")
if operIds == "" {
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
return
}
// 处理字符转id数组后去重
ids := strings.Split(operIds, ",")
uniqueIDs := parse.RemoveDuplicates(ids)
if len(uniqueIDs) <= 0 {
c.JSON(200, result.Err(nil))
return
}
rows := s.SysLogOperateService.DeleteSysLogOperateByIds(uniqueIDs)
if rows > 0 {
msg := i18n.TTemplate(language, "app.common.deleteSuccess", map[string]any{"num": rows})
c.JSON(200, result.OkMsg(msg))
return
}
c.JSON(200, result.Err(nil))
}
// 操作日志清空
// Clean 操作日志清空
//
// DELETE /clean
func (s *SysLogOperateController) Clean(c *gin.Context) {
err := s.SysLogOperateService.CleanSysLogOperate()
if err != nil {
c.JSON(200, result.ErrMsg(err.Error()))
return
}
c.JSON(200, result.Ok(nil))
func (s SysLogOperateController) Clean(c *gin.Context) {
rows := s.sysLogOperateService.Clean()
c.JSON(200, resp.OkData(rows))
}
// 导出操作日志
// Export 导出操作日志
//
// POST /export
func (s *SysLogOperateController) Export(c *gin.Context) {
language := ctx.AcceptLanguage(c)
// GET /export
func (s SysLogOperateController) Export(c *gin.Context) {
language := reqctx.AcceptLanguage(c)
// 查询结果,根据查询条件结果,单页最大值限制
querys := ctx.BodyJSONMap(c)
querys["pageNum"] = 1
querys["pageSize"] = 10000
dataScopeSQL := ctx.LoginUserToDataScopeSQL(c, "d", "u")
data := s.SysLogOperateService.SelectSysLogOperatePage(querys, dataScopeSQL)
if parse.Number(data["total"]) == 0 {
// 导出数据记录为空
c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.exportEmpty")))
return
}
rows := data["rows"].([]model.SysLogOperate)
// rows := s.SysLogOperateService.SelectSysLogOperateList(model.SysLogOperate{})
if len(rows) <= 0 {
// 导出数据记录为空
c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.exportEmpty")))
query := reqctx.QueryMap(c)
dataScopeSQL := reqctx.LoginUserToDataScopeSQL(c, "sys_user", "sys_user")
rows, total := s.sysLogOperateService.FindByPage(query, dataScopeSQL)
if total == 0 {
// c.JSON(200, resp.CodeMsg(40016, "export data record as empty"))
c.JSON(200, resp.CodeMsg(40016, i18n.TKey(language, "app.common.exportEmpty")))
return
}
@@ -138,7 +93,7 @@ func (s *SysLogOperateController) Export(c *gin.Context) {
converI18n := func(language string, arr *[]model.SysLogOperate) {
for i := range *arr {
(*arr)[i].Title = i18n.TKey(language, (*arr)[i].Title)
(*arr)[i].OperLocation = i18n.TKey(language, (*arr)[i].OperLocation)
(*arr)[i].OperaLocation = i18n.TKey(language, (*arr)[i].OperaLocation)
}
}
converI18n(language, &rows)
@@ -195,18 +150,18 @@ func (s *SysLogOperateController) Export(c *gin.Context) {
// 状态
statusValue := i18n.TKey(language, "dictData.fail")
if row.Status == "1" {
if row.StatusFlag == "1" {
statusValue = i18n.TKey(language, "dictData.success")
}
dataCells = append(dataCells, map[string]any{
"A" + idx: row.OperID,
"A" + idx: row.ID,
"B" + idx: row.Title,
"C" + idx: businessType,
"D" + idx: row.OperName,
"E" + idx: row.RequestMethod,
"F" + idx: row.OperIP,
"D" + idx: row.OperaBy,
"E" + idx: row.OperaUrlMethod,
"F" + idx: row.OperaIp,
"G" + idx: statusValue,
"H" + idx: date.ParseDateToStr(row.OperTime, date.YYYY_MM_DDTHH_MM_SSZ),
"H" + idx: date.ParseDateToStr(row.OperaTime, date.YYYY_MM_DDTHH_MM_SSZ),
"I" + idx: row.CostTime,
})
}
@@ -214,7 +169,7 @@ func (s *SysLogOperateController) Export(c *gin.Context) {
// 导出数据表格
saveFilePath, err := file.WriteSheet(headerCells, dataCells, fileName, "")
if err != nil {
c.JSON(200, result.ErrMsg(err.Error()))
c.JSON(200, resp.ErrMsg(err.Error()))
return
}