package data import ( "eta_gn/eta_api/models/data_manage" "strconv" "strings" ) // GetAllShareChartListByFromUserId // @Description: 根据共享人id获取所有的指标列表 // @author: Roc // @datetime 2024-12-03 10:01:49 // @param sysUserId int // @return item []*data_manage.ShareChartInfoQuery // @return err error func GetAllShareChartListByFromUserId(sysUserId int) (item []*data_manage.ShareChartInfoQuery, err error) { obj := data_manage.ChartInfoShare{} item, err = obj.GetAllSharedChartInfoListByFromUserId(sysUserId) if err != nil { return } return } // GetAllShareChartListByReceivedUserId // @Description: 根据接收人id获取所有的指标列表 // @author: Roc // @datetime 2024-12-03 10:01:49 // @param sysUserId int // @return item []*data_manage.ShareChartInfoQuery // @return err error func GetAllShareChartListByReceivedUserId(sysUserId int) (item []*data_manage.ShareChartInfoQuery, err error) { obj := data_manage.ChartInfoShare{} item, err = obj.GetAllSharedChartInfoListByReceivedUserId(sysUserId) if err != nil { return } return } // GetChartClassifyItemListByShareChartInfoQueryList // @Description: 根据共享的指标来获取分类和指标的树形结构 // @author: Roc // @datetime 2024-12-03 11:12:26 // @param items []*data_manage.ShareChartInfoQuery // @return item data_manage.ChartClassifyItemList // @return err error func GetChartClassifyItemListByShareChartInfoQueryList(items []*data_manage.ShareChartInfoQuery) (item []*data_manage.UserShareChartClassifyItem, err error) { // 所有分类 chartClassifyItemListMap := make(map[int][]*data_manage.ChartClassifyItems) classifyIdList := make([]int, 0) for _, v := range items { chartClassifyItem := &data_manage.ChartClassifyItems{ ChartClassifyId: v.ChartClassifyId, ChartInfoId: v.ChartInfoId, ChartClassifyName: v.ChartName, ChartClassifyNameEn: v.ChartNameEn, //ParentId: 0, //Level: 0, Sort: v.Sort, UniqueCode: v.UniqueCode, Source: v.Source, //SourceName: "", SysUserId: v.SysUserId, SysUserRealName: v.SysUserRealName, DateType: v.DateType, StartDate: v.StartDate, EndDate: v.EndDate, ChartType: v.ChartType, Calendar: v.Calendar, SeasonStartDate: v.SeasonStartDate, SeasonEndDate: v.SeasonEndDate, //Children: nil, Button: data_manage.ChartClassifyItemsButton{}, IsJoinPermission: v.IsJoinPermission, HaveOperaAuth: true, //ChartClassifyIdPath: "", } chartClassifyItemList, ok := chartClassifyItemListMap[v.ChartClassifyId] if !ok { chartClassifyItemList = make([]*data_manage.ChartClassifyItems, 0) } chartClassifyItemListMap[v.ChartClassifyId] = append(chartClassifyItemList, chartClassifyItem) classifyIdList = append(classifyIdList, v.ChartClassifyId) } // 组成一个分类树形结构 { // 根据分类id获取分类 classifyItemsList, tmpErr := data_manage.GetChartClassifyItemsByIdList(classifyIdList) if tmpErr != nil { err = tmpErr return } allClassifyIdList := make([]int, 0) // 获取分类的完整路径id集合(子级、父级、顶级) allClassifyIdStrList := make([]string, 0) for _, v := range classifyItemsList { allClassifyIdStrList = append(allClassifyIdStrList, v.ChartClassifyIdPath) } if len(allClassifyIdStrList) > 0 { allClassifyIdStrList = strings.Split(strings.Join(allClassifyIdStrList, ","), ",") } for _, v := range allClassifyIdStrList { classifyId, tmpErr := strconv.Atoi(v) if tmpErr != nil { err = tmpErr return } allClassifyIdList = append(allClassifyIdList, classifyId) } classifyItemsList, err = data_manage.GetChartClassifyItemsByIdList(allClassifyIdList) if err != nil { return } tmpList := GetChartClassifyTreeRecursiveAndInsert(classifyItemsList, 0, chartClassifyItemListMap) // 再转一下就好了 obj := data_manage.ChartClassifyItems{} item = obj.ToUserShareChartClassifyItemByList(tmpList) //根据sort值排序 //sort.Sort(item) } return }