package controllers import ( "eta/eta_mini_api/models" "eta/eta_mini_api/services" "eta/eta_mini_api/utils" ) type ChartPermissionController struct { BaseAuthController } type ChartPermissionNoAuthController struct { BaseCommonController } // List // @Title 系统品种列表 // @Description 系统品种列表 // @Param chartPermissonId query int true "品种权限id" // @Success 200 {object} models.LoginResp // @router /list [get] func (this *ChartPermissionController) List() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() id, _ := this.GetInt("chartPermissonId", 0) var resp *models.ChartPermissionResp[[]*models.ChartPermission] var err error if id == 0 { resp, err = services.GetChartPermissionList() } else if id > 0 { resp, err = services.GetChartPermissionSecondList(id) } if err != nil { br.Msg = "权限列表获取失败" br.ErrMsg = "权限列表获取失败,系统错误,Err:" + err.Error() return } if resp.Ret != 200 { br.Msg = resp.Msg br.ErrMsg = resp.ErrMsg return } chartPermissionList := make([]*models.ChartPermissionView, 0) for _, item := range resp.Data { chartPermissionList = append(chartPermissionList, &models.ChartPermissionView{ ChartPermissionId: item.ChartPermissionId, PermissionName: item.PermissionName, Remark: item.Remark, ImageUrl: item.ImageUrl, ChartPermissionType: utils.PermissionTypeEta, }) } // 如果id != 0, 则只返回二级品种权限,并且需要附加pdf报告品种 if id != 0 { chartPermissionList = append(chartPermissionList, &models.ChartPermissionView{ ChartPermissionId: -1, PermissionName: utils.MINI_CUSTOM_PERMISSION_NAME, Remark: "", ImageUrl: "", ChartPermissionType: utils.PermissionTypeMini, }) } br.Ret = 200 br.Data = chartPermissionList br.Msg = "列表获取成功" br.Success = true } // ClassifyTree // @Title 获取品种下的分类权限列表 // @Description 获取研报的品种权限列表 // @Param ChartPermissionId query int true "品种权限id" // @Success 200 {object} []models.ChartPermission // @router /classify/tree [get] func (this *ChartPermissionController) ClassifyTree() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() chartPermissionId, _ := this.GetInt("ChartPermissionId") if chartPermissionId <= 0 { br.Msg = "品种权限不能为空" return } resp, err := services.GetClassifyTreeByChartPermission(chartPermissionId) if err != nil { br.Msg = "获取分类失败" br.ErrMsg = "品种权限获取失败,系统错误,Err:" + err.Error() return } if resp.Ret != 200 { br.Msg = resp.Msg br.ErrMsg = resp.ErrMsg return } classifyList := resp.Data br.Data = classifyList br.Msg = "获取成功" br.Success = true br.Ret = 200 } // ClassifyTree // @Title 获取品种下的分类权限列表 // @Description 获取研报的品种权限列表 // @Param ChartPermissionId query int true "品种权限id" // @Success 200 {object} []models.ChartPermission // @router /classify/tree [get] func (this *ChartPermissionNoAuthController) ClassifyTree() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() chartPermissionId, _ := this.GetInt("ChartPermissionId") if chartPermissionId < 0 { br.Msg = "品种权限异常" return } resp, err := services.GetClassifyTreeByChartPermission(chartPermissionId) if err != nil { br.Msg = "获取分类失败" br.ErrMsg = "品种权限获取失败,系统错误,Err:" + err.Error() return } if resp.Ret != 200 { br.Msg = resp.Msg br.ErrMsg = resp.ErrMsg return } classifyList := resp.Data br.Data = classifyList br.Msg = "获取成功" br.Success = true br.Ret = 200 } // List // @Title 系统品种列表 // @Description 系统品种列表 // @Param chartPermissonId query int true "品种权限id" // @Success 200 {object} models.LoginResp // @router /list [get] func (this *ChartPermissionNoAuthController) List() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() id, _ := this.GetInt("chartPermissonId", 0) var resp *models.ChartPermissionResp[[]*models.ChartPermission] var err error if id == 0 { resp, err = services.GetChartPermissionList() } else if id > 0 { resp, err = services.GetChartPermissionSecondList(id) } if err != nil { br.Msg = "权限列表获取失败" br.ErrMsg = "权限列表获取失败,系统错误,Err:" + err.Error() return } if resp.Ret != 200 { br.Msg = resp.Msg br.ErrMsg = resp.ErrMsg return } chartPermissionList := make([]*models.ChartPermissionView, 0) for _, item := range resp.Data { chartPermissionList = append(chartPermissionList, &models.ChartPermissionView{ ChartPermissionId: item.ChartPermissionId, PermissionName: item.PermissionName, Remark: item.Remark, ImageUrl: item.ImageUrl, ChartPermissionType: utils.PermissionTypeEta, }) } if id > 0 { chartPermissionList = append(chartPermissionList, &models.ChartPermissionView{ ChartPermissionId: id, PermissionName: utils.ZC_CUSTOM_PERMISSION_NAME, Remark: "", ImageUrl: "", ChartPermissionType: utils.PermissionTypeMini, }) } br.Ret = 200 br.Data = chartPermissionList br.Msg = "列表获取成功" br.Success = true }