123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- package controllers
- import (
- "encoding/json"
- "eta/eta_mini_bridge/models"
- "eta/eta_mini_bridge/models/request"
- "eta/eta_mini_bridge/models/response"
- "eta/eta_mini_bridge/utils"
- )
- type ClassifyController struct {
- BaseAuthController
- }
- // @Title 根据分类id获取一级品种
- // @Description 根据分类id获取一级品种
- // @Param request body request.ClassifyReq true "type json string"
- // @Success 200 {object} response.ReportDetailResp
- // @router /chart_permission/first [post]
- func (this *ClassifyController) FirstChartPermission() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req request.ClassifyReq
- if err := json.Unmarshal(this.Ctx.Input.RequestBody, &req); err != nil {
- br.Msg = "参数错误"
- br.ErrMsg = "参数错误,Err:" + err.Error()
- return
- }
- if len(req.ClassifyIds) == 0 {
- br.Msg = "分类id错误,获取失败"
- return
- }
- permissionClassifyMap, err := models.GetChartPermissionListByClassifyIds(req.ClassifyIds)
- if err != nil {
- br.Msg = "品种获取失败"
- br.ErrMsg = "获取品种和分类的映射失败,系统错误,Err:" + err.Error()
- return
- }
- classifyToPermissionMap2 := make(map[int][]int)
- chartPermissionIds := make([]int, 0)
- for _, v := range permissionClassifyMap {
- classifyToPermissionMap2[v.ClassifyId] = append(classifyToPermissionMap2[v.ClassifyId], v.ChartPermissionId)
- chartPermissionIds = append(chartPermissionIds, v.ChartPermissionId)
- }
- // 获取二级品种的权限,并建立映射
- chartPermissionList2, err := models.GetChartPermissionListByIds(chartPermissionIds)
- if err != nil {
- br.Msg = "二级品种获取失败"
- br.ErrMsg = "二级品种获取失败,系统错误,Err:" + err.Error()
- return
- }
- chartPermissionViewMap2 := make(map[int]*models.ChartPermission)
- for _, v := range chartPermissionList2 {
- chartPermissionViewMap2[v.ChartPermissionId] = v
- }
- // 获取一级品种的权限,并建立映射
- chartPermissionList1, err := models.GetChildChartPermissionListById(0)
- if err != nil {
- br.Msg = "获取研报一级品种权限失败"
- br.ErrMsg = "获取研报一级品种权限失败,Err:" + err.Error()
- return
- }
- chartPermissionMap1 := make(map[int]*models.ChartPermission)
- for _, v := range chartPermissionList1 {
- chartPermissionMap1[v.ChartPermissionId] = v
- }
- var resp []*response.ClassifyPermissionItemResp
- for _, v := range req.ClassifyIds {
- t := new(response.ClassifyPermissionItemResp)
- t.ClassifyId = v
- for _, vv := range classifyToPermissionMap2[v] {
- if item, ok := chartPermissionViewMap2[vv]; ok {
- parent2 := item.ParentId
- t.PermissionNames = append(t.PermissionNames, chartPermissionMap1[parent2].PermissionName)
- }
- }
- t.PermissionNames = utils.Unique(t.PermissionNames)
- resp = append(resp, t)
- }
- br.Data = resp
- br.Success = true
- br.Ret = 200
- br.Msg = "获取成功"
- }
- // @Title 获取所有分类
- // @Description 获取所有分类
- // @Success 200 {object} []models.ClassifyView
- // @router /list [get]
- func (this *ClassifyController) AllClassify() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- classifyList, err := models.GetClassifyList()
- if err != nil {
- br.Msg = "获取分类失败"
- br.ErrMsg = "获取分类失败,系统错误,Err:" + err.Error()
- return
- }
- br.Data = classifyList
- br.Success = true
- br.Ret = 200
- br.Msg = "获取成功"
- }
|