package controllers import ( "eta/eta_hub/models" "eta/eta_hub/models/sandbox" sandboxService "eta/eta_hub/services/sandbox" "eta/eta_hub/utils" "github.com/rdlucklib/rdluck_tools/paging" ) // SandboxController 逻辑导图 type SandboxController struct { BaseAuthController } // SandboxClassifyItems // @Title 获取所有沙盘分类接口-包含沙盘 // @Description 获取所有沙盘分类接口-包含沙盘 // @Param IsShowMe query bool true "是否只看我的,true、false" // @Success 200 {object} data_manage.ChartClassifyListResp // @router /classify/list [get] func (this *SandboxController) SandboxClassifyItems() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() resp := new(sandbox.SandboxClassifyListResp) sandboxClassifyId, _ := this.GetInt("SandboxClassifyId") rootList, err := sandbox.GetSandboxClassifyAndInfoByParentId(sandboxClassifyId) if err != nil && err.Error() != utils.ErrNoRow() { br.Msg = "获取失败" br.ErrMsg = "获取数据失败,Err:" + err.Error() return } classifyAll, err := sandbox.GetSandboxClassifyAndInfoByParentId(sandboxClassifyId) if err != nil && err.Error() != utils.ErrNoRow() { br.Msg = "获取失败" br.ErrMsg = "获取数据失败,Err:" + err.Error() return } nodeAll := make([]*sandbox.SandboxClassifyItems, 0) for k := range rootList { rootNode := rootList[k] sandboxService.SandboxClassifyItemsMakeTreeV2(classifyAll, rootNode) nodeAll = append(nodeAll, rootNode) } resp.AllNodes = nodeAll br.Ret = 200 br.Msg = "获取成功" br.Data = resp } // @Title ETA图表列表接口 // @Description ETA图表列表接口 // @Param PageSize query int true "每页数据条数" // @Param CurrentIndex query int true "当前页页码,从1开始" // @Param ChartClassifyId query int true "分类id" // @Param KeyWord query string true "搜索关键词" // @Param IsShowMe query bool true "是否只看我的,true、false" // @Success 200 {object} data_manage.ChartListResp // @router /list [get] func (this *SandboxController) List() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() sandboxClassifyId, _ := this.GetInt("SandboxClassifyId") pageSize, _ := this.GetInt("PageSize") currentIndex, _ := this.GetInt("CurrentIndex") keyWord := this.GetString("KeyWord") var total int page := paging.GetPaging(currentIndex, pageSize, total) var startSize int if pageSize <= 0 { pageSize = utils.PageSize20 } if currentIndex <= 0 { currentIndex = 1 } startSize = paging.StartIndex(currentIndex, pageSize) var condition string var pars []interface{} if sandboxClassifyId > 0 { sandboxClassifyId, err := sandbox.GetSandboxClassify(sandboxClassifyId) if err != nil && err.Error() != utils.ErrNoRow() { br.Msg = "获取图表信息失败" br.ErrMsg = "获取信息失败,GetChartClassify,Err:" + err.Error() return } condition += " AND sandbox_classify_id IN(" + sandboxClassifyId + ") " //pars = append(pars, chartClassifyId) } if keyWord != "" { condition += ` AND ( name LIKE '%` + keyWord + `%' )` } //获取图表信息 condition += ` AND is_delete = 0 ` list, err := sandbox.GetSandboxListByCondition(condition, pars, startSize, pageSize) if err != nil && err.Error() != utils.ErrNoRow() { br.Msg = "获取沙盘信息失败" br.ErrMsg = "获取沙盘信息失败,Err:" + err.Error() return } for i, v := range list { ids, err := sandbox.GetSandboxAllParentByClassifyId(v.SandboxClassifyId) if err != nil { br.Msg = "获取父级信息错误!" br.ErrMsg = "获取父级信息错误,Err:" + err.Error() return } list[i].ParentIds = ids } resp := new(sandbox.SandboxListResp) if list == nil || len(list) <= 0 || (err != nil && err.Error() == utils.ErrNoRow()) { items := make([]*sandbox.SandboxListItems, 0) resp.Paging = page resp.List = items br.Ret = 200 br.Msg = "获取成功" return } dataCount, err := sandbox.GetSandboxListCountByCondition(condition, pars) if err != nil && err.Error() != utils.ErrNoRow() { br.Msg = "获取指标信息失败" br.ErrMsg = "获取指标数据总数失败,Err:" + err.Error() return } page = paging.GetPaging(currentIndex, pageSize, dataCount) resp.Paging = page resp.List = list br.Ret = 200 br.Msg = "获取成功" br.Data = resp } // GetSandboxVersionDetail // @Title 获取沙盘版本数据详情(已保存的) // @Description 获取沙盘版本数据详情接口(已保存的) // @Param SandboxVersionCode query string true "沙盘版本code" // @Success 200 {object} sandbox.SandboxVersion // @router /detail [get] func (this *SandboxController) GetSandboxDetail() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() sandboxId, _ := this.GetInt("SandboxId") if sandboxId == 0 { br.Msg = "缺少沙盘Id" return } //获取沙盘数据详情(已保存的) sandboxInfo, err := sandbox.GetSandboxById(sandboxId) if err != nil { br.Msg = "获取失败" br.ErrMsg = "获取失败,Err:" + err.Error() return } msg := "获取成功" br.Ret = 200 br.Msg = msg br.Data = sandboxInfo } // SandboxClassifyItems // @Title 获取所有沙盘分类接口-不包含沙盘 // @Description 获取所有沙盘分类接口-不包含沙盘 // @Param IsShowMe query bool true "是否只看我的,true、false" // @Success 200 {object} data_manage.ChartClassifyListResp // @router /classifyList [get] func (this *SandboxController) SandboxClassifyList() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() resp := new(sandbox.SandboxClassifyListResp) rootList, err := sandbox.GetSandboxClassifyByParentId(0) if err != nil && err.Error() != utils.ErrNoRow() { br.Msg = "获取失败" br.ErrMsg = "获取数据失败,Err:" + err.Error() return } classifyAll, err := sandbox.GetSandboxClassifyAll() if err != nil && err.Error() != utils.ErrNoRow() { br.Msg = "获取失败" br.ErrMsg = "获取数据失败,Err:" + err.Error() return } nodeAll := make([]*sandbox.SandboxClassifyItems, 0) for k := range rootList { rootNode := rootList[k] sandboxService.SandboxClassifyItemsMakeTree(classifyAll, rootNode) nodeAll = append(nodeAll, rootNode) } resp.AllNodes = nodeAll br.Ret = 200 br.Msg = "获取成功" br.Data = resp }