123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- package data
- import (
- "eta_gn/eta_api/models/data_manage"
- "eta_gn/eta_api/utils"
- "sort"
- "strconv"
- "strings"
- )
- // GetAllShareEdbListByFromUserId
- // @Description: 根据共享人id获取所有的指标列表
- // @author: Roc
- // @datetime 2024-12-03 10:01:49
- // @param sysUserId int
- // @return item []*data_manage.ShareEdbInfoQuery
- // @return err error
- func GetAllShareEdbListByFromUserId(sysUserId int) (item []*data_manage.ShareEdbInfoQuery, err error) {
- obj := data_manage.EdbInfoShare{}
- item, err = obj.GetAllSharedEdbInfoListByFromUserId(sysUserId)
- if err != nil {
- return
- }
- return
- }
- // GetAllShareEdbListByReceivedUserId
- // @Description: 根据接收人id获取所有的指标列表
- // @author: Roc
- // @datetime 2024-12-03 10:01:49
- // @param sysUserId int
- // @return item []*data_manage.ShareEdbInfoQuery
- // @return err error
- func GetAllShareEdbListByReceivedUserId(sysUserId int) (item []*data_manage.ShareEdbInfoQuery, err error) {
- obj := data_manage.EdbInfoShare{}
- item, err = obj.GetAllSharedEdbInfoListByReceivedUserId(sysUserId)
- if err != nil {
- return
- }
- return
- }
- // GetEdbClassifyItemListByShareEdbInfoQueryList
- // @Description: 根据共享的指标来获取分类和指标的树形结构
- // @author: Roc
- // @datetime 2024-12-03 11:12:26
- // @param items []*data_manage.ShareEdbInfoQuery
- // @return item data_manage.EdbClassifyItemList
- // @return err error
- func GetEdbClassifyItemListByShareEdbInfoQueryList(items []*data_manage.ShareEdbInfoQuery) (item data_manage.UserShareEdbClassifyItemList, err error) {
- // 所有分类
- edbClassifyItemListMap := make(map[int][]*data_manage.EdbClassifyItems)
- classifyIdList := make([]int, 0)
- for _, v := range items {
- edbClassifyItem := &data_manage.EdbClassifyItems{
- ClassifyId: v.ClassifyId,
- EdbInfoId: v.EdbInfoId,
- //ParentId: v.ClassifyId,
- //ClassifyType: v.ClassifyT,
- ClassifyName: v.EdbName,
- ClassifyNameEn: v.EdbNameEn,
- Sort: v.Sort,
- UniqueCode: v.UniqueCode,
- Source: v.Source,
- SourceName: v.SourceName,
- SysUserId: v.SysUserId,
- SysUserRealName: v.SysUserRealName,
- StartDate: v.StartDate.Format(utils.FormatDate),
- EdbCode: v.EdbCode,
- EdbType: v.EdbType,
- //Children: nil,
- Button: data_manage.EdbClassifyItemsButton{},
- IsJoinPermission: v.IsJoinPermission,
- HaveOperaAuth: true,
- ClassifyIdPath: "",
- }
- edbClassifyItemList, ok := edbClassifyItemListMap[v.ClassifyId]
- if !ok {
- edbClassifyItemList = make([]*data_manage.EdbClassifyItems, 0)
- }
- edbClassifyItemListMap[v.ClassifyId] = append(edbClassifyItemList, edbClassifyItem)
- classifyIdList = append(classifyIdList, v.ClassifyId)
- }
- // 组成一个分类树形结构
- {
- // 根据分类id获取分类
- classifyItemsList, tmpErr := data_manage.GetEdbClassifyItemsByIdList(classifyIdList)
- if tmpErr != nil {
- err = tmpErr
- return
- }
- allClassifyIdList := make([]int, 0)
- // 获取分类的完整路径id集合(子级、父级、顶级)
- allClassifyIdStrList := make([]string, 0)
- for _, v := range classifyItemsList {
- allClassifyIdStrList = append(allClassifyIdStrList, v.ClassifyIdPath)
- }
- 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.GetEdbClassifyItemsByIdList(allClassifyIdList)
- if err != nil {
- return
- }
- tmpItem := GetClassifyTreeRecursiveAndInsert(classifyItemsList, 0, edbClassifyItemListMap)
- // 再转一下就好了
- obj := data_manage.EdbClassifyItems{}
- item = obj.ToUserShareEdbClassifyItemByList(tmpItem)
- //根据sort值排序
- sort.Sort(item)
- }
- return
- }
|