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 }