feat: 更新多个模块以支持新的数据结构和日志格式
This commit is contained in:
@@ -1,12 +1,14 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"be.ems/src/framework/i18n"
|
||||
"be.ems/src/framework/utils/ctx"
|
||||
"be.ems/src/framework/vo/result"
|
||||
"be.ems/src/framework/reqctx"
|
||||
"be.ems/src/framework/resp"
|
||||
"be.ems/src/modules/chart/service"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/gin-gonic/gin/binding"
|
||||
)
|
||||
|
||||
// 实例化控制层 ChartGraphController 结构体
|
||||
@@ -36,7 +38,7 @@ type ChartGraphController struct {
|
||||
// @Router /chart/graph/groups [get]
|
||||
func (s *ChartGraphController) GroupNames(c *gin.Context) {
|
||||
data := s.chartGraphService.SelectGroup()
|
||||
c.JSON(200, result.OkData(data))
|
||||
c.JSON(200, resp.OkData(data))
|
||||
}
|
||||
|
||||
// 获取关系图数据
|
||||
@@ -47,25 +49,25 @@ func (s *ChartGraphController) GroupNames(c *gin.Context) {
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param group query string true "Group"
|
||||
// @Param type query string true "Type" Enums(node, edge, combo)
|
||||
// @Param type query string false "Type" Enums(node, edge, combo)
|
||||
// @Success 200 {object} object "Response Results"
|
||||
// @Security TokenAuth
|
||||
// @Summary Getting Relationship Map Data
|
||||
// @Description Getting Relationship Map Data
|
||||
// @Router /chart/graph [get]
|
||||
func (s *ChartGraphController) Load(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
var querys struct {
|
||||
Group string `form:"group" binding:"required"`
|
||||
Type string `form:"type" binding:"omitempty,oneof=node edge combo"`
|
||||
}
|
||||
if err := c.ShouldBindQuery(&querys); err != nil {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
|
||||
c.JSON(422, resp.CodeMsg(40422, errMsgs))
|
||||
return
|
||||
}
|
||||
|
||||
data := s.chartGraphService.LoadData(querys.Group, querys.Type)
|
||||
c.JSON(200, result.OkData(data))
|
||||
c.JSON(200, resp.OkData(data))
|
||||
}
|
||||
|
||||
// 保存关系图数据
|
||||
@@ -80,9 +82,8 @@ func (s *ChartGraphController) Load(c *gin.Context) {
|
||||
// @Security TokenAuth
|
||||
// @Summary Saving Relationship Diagram Data
|
||||
// @Description Saving Relationship Diagram Data
|
||||
// @Router /chart/graph/ [post]
|
||||
// @Router /chart/graph [post]
|
||||
func (s *ChartGraphController) Save(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
var body struct {
|
||||
Group string `json:"group" binding:"required"`
|
||||
Data struct {
|
||||
@@ -91,9 +92,9 @@ func (s *ChartGraphController) Save(c *gin.Context) {
|
||||
Combos []map[string]any `json:"combos" binding:"required"`
|
||||
} `json:"data" binding:"required"`
|
||||
}
|
||||
err := c.ShouldBindBodyWith(&body, binding.JSON)
|
||||
if err != nil {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
if err := c.ShouldBindBodyWithJSON(&body); err != nil {
|
||||
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
|
||||
c.JSON(422, resp.CodeMsg(40422, errMsgs))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -104,10 +105,10 @@ func (s *ChartGraphController) Save(c *gin.Context) {
|
||||
}
|
||||
saveNum := s.chartGraphService.SaveData(body.Group, data)
|
||||
if saveNum > 0 {
|
||||
c.JSON(200, result.Ok(nil))
|
||||
c.JSON(200, resp.Ok(nil))
|
||||
return
|
||||
}
|
||||
c.JSON(200, result.Err(nil))
|
||||
c.JSON(200, resp.Err(nil))
|
||||
}
|
||||
|
||||
// 删除关系图数据
|
||||
@@ -124,17 +125,17 @@ func (s *ChartGraphController) Save(c *gin.Context) {
|
||||
// @Description Deleting Relationship Diagram Data
|
||||
// @Router /chart/graph/{group} [delete]
|
||||
func (s *ChartGraphController) Delete(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
language := reqctx.AcceptLanguage(c)
|
||||
group := c.Param("group")
|
||||
if group == "" {
|
||||
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
|
||||
}
|
||||
|
||||
deleteNum := s.chartGraphService.DeleteGroup(group)
|
||||
if deleteNum > 0 {
|
||||
c.JSON(200, result.Ok(nil))
|
||||
c.JSON(200, resp.Ok(nil))
|
||||
return
|
||||
}
|
||||
c.JSON(200, result.Err(nil))
|
||||
c.JSON(200, resp.Err(nil))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user