package controller import ( "errors" "github.com/gin-gonic/gin" "github.com/spf13/cast" "gitlab.wodcloud.com/smart-operation/so-operation-api/src/bean/vo/request" "gitlab.wodcloud.com/smart-operation/so-operation-api/src/pkg/beagle/resp" "gitlab.wodcloud.com/smart-operation/so-operation-api/src/router/middleware/header" "gitlab.wodcloud.com/smart-operation/so-operation-api/src/service" ) type ComponentDict struct{} // List 组件列表 func (d ComponentDict) List(c *gin.Context) { var ( err error req request.ComponentDictReq ) if err = c.ShouldBind(&req); err != nil { SendJsonResponse(c, resp.InvalidParam.WithError(err), "") return } //user, _ := header.GetUserContext(c) svc := new(service.ComponentDict) svc.Ctx = c svc.User = header.GetUser(c) componentDict, err := svc.List(req) if err != nil { SendJsonResponse(c, resp.InvalidParam.WithError(err), "") return } SendJsonResponse(c, resp.OK, componentDict) } // DictTree 字典列表-树结构 func (d ComponentDict) DictTree(c *gin.Context) { var ( err error req request.ComponentDictTreeReq ) if err = c.ShouldBind(&req); err != nil { SendJsonResponse(c, resp.InvalidParam.WithError(err), "") return } //user, _ := header.GetUserContext(c) svc := new(service.ComponentDict) svc.Ctx = c componentDictTreeRes, err := svc.DictTree(req) if err != nil { SendJsonResponse(c, resp.FAIL.WithError(err), "") return } SendJsonResponse(c, resp.OK, componentDictTreeRes) } // Add 新增字典 func (d ComponentDict) Add(c *gin.Context) { var ( err error req request.AddComponentDictReq ) if err = c.ShouldBind(&req); err != nil { SendJsonResponse(c, resp.InvalidParam.WithError(err), "") return } svc := new(service.ComponentDict) svc.Ctx = c svc.User = header.GetUser(c) err = svc.Add(req) if err != nil { SendJsonResponse(c, resp.FAIL.WithError(err), "") return } SendJsonResponse(c, resp.OK, nil) } // Update 修改字典 func (d ComponentDict) Update(c *gin.Context) { var ( err error req request.UpdateComponentDictReq ) if err = c.ShouldBind(&req); err != nil { SendJsonResponse(c, resp.InvalidParam.WithError(err), "") return } svc := new(service.ComponentDict) svc.Ctx = c svc.User = header.GetUser(c) err = svc.Update(req) if err != nil { SendJsonResponse(c, resp.FAIL.WithError(err), "") return } SendJsonResponse(c, resp.OK, nil) } // Del 删除字典 func (d ComponentDict) Del(c *gin.Context) { var ( err error id string ) if id = c.Query("id"); id == "" { id = c.Param("id") } if id == "" { SendJsonResponse(c, resp.InvalidParam.WithError(errors.New("参数为空或不正确")), "") return } svc := new(service.ComponentDict) svc.Ctx = c //svc.User = &user err = svc.Del(cast.ToInt(id)) if err != nil { SendJsonResponse(c, resp.FAIL.WithError(err), "") return } SendJsonResponse(c, resp.OK, nil) } // List 组件列表 func (d ComponentDict) ClassList(c *gin.Context) { var ( err error className string ) if className = c.Query("class_name"); className == "" { className = c.Param("class_name") } svc := new(service.ComponentDict) svc.Ctx = c //svc.User = &user classList, err := svc.ClassList(className) if err != nil { SendJsonResponse(c, resp.FAIL.WithError(err), "") return } SendJsonResponse(c, resp.OK, classList) } // List 组件列表 func (d ComponentDict) ManageList(c *gin.Context) { var ( err error req request.DictManageListReq ) if err = c.ShouldBind(&req); err != nil { SendJsonResponse(c, resp.InvalidParam.WithError(err), "") return } //svc := new(service.ComponentDict) //svc.Ctx = c ////svc.User = &user //manageList, err := svc.ManageList(req) //if err != nil { // resp.Json(c, resp.FAIL.WithMsg(err.Error())) // return //} // //resp.Json(c, resp.OK.WithData(manageList)) SendJsonResponse(c, resp.OK, nil) }