feat: 更新多个模块以支持新的数据结构和日志格式
This commit is contained in:
@@ -4,16 +4,15 @@ import (
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
|
||||
"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/parse"
|
||||
"be.ems/src/framework/vo/result"
|
||||
"be.ems/src/modules/trace/model"
|
||||
traceService "be.ems/src/modules/trace/service"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/gin-gonic/gin/binding"
|
||||
)
|
||||
|
||||
// 实例化控制层 TraceTaskController 结构体
|
||||
@@ -33,116 +32,125 @@ type TraceTaskController struct {
|
||||
//
|
||||
// GET /list
|
||||
func (s *TraceTaskController) List(c *gin.Context) {
|
||||
query := ctx.QueryMap(c)
|
||||
|
||||
// 查询数据
|
||||
data := s.traceTaskService.SelectPage(query)
|
||||
c.JSON(200, result.Ok(data))
|
||||
query := reqctx.QueryMap(c)
|
||||
rows, total := s.traceTaskService.FindByPage(query)
|
||||
c.JSON(200, resp.OkData(map[string]any{"rows": rows, "total": total}))
|
||||
}
|
||||
|
||||
// 跟踪任务信息
|
||||
//
|
||||
// GET /:id
|
||||
func (s *TraceTaskController) Info(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
id := c.Param("id")
|
||||
if id == "" {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
id := parse.Number(c.Param("id"))
|
||||
if id <= 0 {
|
||||
c.JSON(400, resp.CodeMsg(40010, "bind err: id is empty"))
|
||||
return
|
||||
}
|
||||
|
||||
data := s.traceTaskService.SelectById(id)
|
||||
data := s.traceTaskService.FindById(id)
|
||||
if data.ID == id {
|
||||
c.JSON(200, result.OkData(data))
|
||||
c.JSON(200, resp.OkData(data))
|
||||
return
|
||||
}
|
||||
c.JSON(200, result.Err(nil))
|
||||
c.JSON(200, resp.Err(nil))
|
||||
}
|
||||
|
||||
// 跟踪任务新增
|
||||
//
|
||||
// POST /
|
||||
func (s *TraceTaskController) Add(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
language := reqctx.AcceptLanguage(c)
|
||||
var body model.TraceTask
|
||||
err := c.ShouldBindBodyWith(&body, binding.JSON)
|
||||
if err != nil || body.ID != "" {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
err := c.ShouldBindBodyWithJSON(&body)
|
||||
if err != nil {
|
||||
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
|
||||
c.JSON(422, resp.CodeMsg(40422, errMsgs))
|
||||
return
|
||||
}
|
||||
if body.ID > 0 {
|
||||
c.JSON(400, resp.CodeMsg(40010, "bind err: id not is empty"))
|
||||
return
|
||||
}
|
||||
|
||||
body.CreateBy = ctx.LoginUserToUserName(c)
|
||||
body.CreateBy = reqctx.LoginUserToUserName(c)
|
||||
if err = s.traceTaskService.Insert(body); err != nil {
|
||||
c.JSON(200, result.ErrMsg(i18n.TKey(language, err.Error())))
|
||||
c.JSON(200, resp.ErrMsg(i18n.TKey(language, err.Error())))
|
||||
return
|
||||
}
|
||||
c.JSON(200, result.Ok(nil))
|
||||
c.JSON(200, resp.Ok(nil))
|
||||
}
|
||||
|
||||
// 跟踪任务修改
|
||||
//
|
||||
// PUT /
|
||||
func (s *TraceTaskController) Edit(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
language := reqctx.AcceptLanguage(c)
|
||||
var body model.TraceTask
|
||||
err := c.ShouldBindBodyWith(&body, binding.JSON)
|
||||
if err != nil || body.ID == "" {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
err := c.ShouldBindBodyWithJSON(&body)
|
||||
if err != nil {
|
||||
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
|
||||
c.JSON(422, resp.CodeMsg(40422, errMsgs))
|
||||
return
|
||||
}
|
||||
if body.ID == 0 {
|
||||
c.JSON(400, resp.CodeMsg(40010, "bind err: id is empty"))
|
||||
return
|
||||
}
|
||||
|
||||
// 检查是否存在
|
||||
taskInfo := s.traceTaskService.SelectById(body.ID)
|
||||
taskInfo := s.traceTaskService.FindById(body.ID)
|
||||
if taskInfo.ID != body.ID {
|
||||
// 没有可访问任务信息数据!
|
||||
c.JSON(200, result.ErrMsg(i18n.TKey(language, "task.noData")))
|
||||
c.JSON(200, resp.ErrMsg(i18n.TKey(language, "task.noData")))
|
||||
return
|
||||
}
|
||||
|
||||
body.UpdateBy = ctx.LoginUserToUserName(c)
|
||||
body.UpdateBy = reqctx.LoginUserToUserName(c)
|
||||
if err = s.traceTaskService.Update(body); err != nil {
|
||||
c.JSON(200, result.ErrMsg(i18n.TKey(language, err.Error())))
|
||||
c.JSON(200, resp.ErrMsg(i18n.TKey(language, err.Error())))
|
||||
return
|
||||
}
|
||||
c.JSON(200, result.Ok(nil))
|
||||
c.JSON(200, resp.Ok(nil))
|
||||
}
|
||||
|
||||
// 跟踪任务删除
|
||||
//
|
||||
// DELETE /:ids
|
||||
// DELETE /:id
|
||||
func (s *TraceTaskController) Remove(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
rowIds := c.Param("ids")
|
||||
if rowIds == "" {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
language := reqctx.AcceptLanguage(c)
|
||||
id := c.Param("id")
|
||||
if id == "" {
|
||||
c.JSON(400, resp.CodeMsg(40010, "bind err: id is empty"))
|
||||
return
|
||||
}
|
||||
|
||||
// 处理字符转id数组后去重
|
||||
ids := strings.Split(rowIds, ",")
|
||||
uniqueIDs := parse.RemoveDuplicates(ids)
|
||||
if len(uniqueIDs) <= 0 {
|
||||
c.JSON(200, result.Err(nil))
|
||||
return
|
||||
uniqueIDs := parse.RemoveDuplicatesToArray(id, ",")
|
||||
// 转换成int64数组类型
|
||||
ids := make([]int64, 0)
|
||||
for _, v := range uniqueIDs {
|
||||
ids = append(ids, parse.Number(v))
|
||||
}
|
||||
rows, err := s.traceTaskService.DeleteByIds(uniqueIDs)
|
||||
|
||||
rows, err := s.traceTaskService.DeleteByIds(ids)
|
||||
if err != nil {
|
||||
c.JSON(200, result.ErrMsg(i18n.TKey(language, err.Error())))
|
||||
c.JSON(200, resp.ErrMsg(i18n.TKey(language, err.Error())))
|
||||
return
|
||||
}
|
||||
msg := i18n.TTemplate(language, "app.common.deleteSuccess", map[string]any{"num": rows})
|
||||
c.JSON(200, result.OkMsg(msg))
|
||||
c.JSON(200, resp.OkMsg(msg))
|
||||
}
|
||||
|
||||
// 跟踪任务文件
|
||||
//
|
||||
// GET /filePull
|
||||
func (s *TraceTaskController) FilePull(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
language := reqctx.AcceptLanguage(c)
|
||||
var querys struct {
|
||||
TraceId string `form:"traceId" binding:"required"`
|
||||
}
|
||||
if err := c.ShouldBindQuery(&querys); err != nil {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
c.JSON(400, resp.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user