123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205 |
- 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
- }
|