|
@@ -5,6 +5,7 @@ import (
|
|
|
"eta/eta_api/models"
|
|
|
"eta/eta_api/utils"
|
|
|
"fmt"
|
|
|
+ "sort"
|
|
|
"time"
|
|
|
)
|
|
|
|
|
@@ -569,6 +570,13 @@ func GetClassifyTreeRecursive(list []*models.ClassifyItem, parentId int) []*mode
|
|
|
return res
|
|
|
}
|
|
|
|
|
|
+// GetParentClassifyListByParentIdList
|
|
|
+// @Description: 递归获取父级分类信息,正常来讲只有三次
|
|
|
+// @author: Roc
|
|
|
+// @datetime 2024-06-19 13:23:33
|
|
|
+// @param parentClassifyIdList []int
|
|
|
+// @return list []*models.ClassifyList
|
|
|
+// @return err error
|
|
|
func GetParentClassifyListByParentIdList(parentClassifyIdList []int) (list []*models.ClassifyList, err error) {
|
|
|
num := len(parentClassifyIdList)
|
|
|
if num <= 0 {
|
|
@@ -601,7 +609,13 @@ func GetParentClassifyListByParentIdList(parentClassifyIdList []int) (list []*mo
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-// GetClassifyListTreeRecursive 递归获取分类树形结构
|
|
|
+// GetClassifyListTreeRecursive
|
|
|
+// @Description: 递归获取分类树形结构
|
|
|
+// @author: Roc
|
|
|
+// @datetime 2024-06-19 13:23:28
|
|
|
+// @param list []*models.ClassifyList
|
|
|
+// @param parentId int
|
|
|
+// @return []*models.ClassifyList
|
|
|
func GetClassifyListTreeRecursive(list []*models.ClassifyList, parentId int) []*models.ClassifyList {
|
|
|
res := make([]*models.ClassifyList, 0)
|
|
|
for _, v := range list {
|
|
@@ -613,3 +627,26 @@ func GetClassifyListTreeRecursive(list []*models.ClassifyList, parentId int) []*
|
|
|
|
|
|
return res
|
|
|
}
|
|
|
+
|
|
|
+// BySortAndCreateTime 用来排序,先按Sort字段升序排序,若Sort相同,则按照CreateTime字段升序排序。
|
|
|
+type BySortAndCreateTime []*models.ClassifyList
|
|
|
+
|
|
|
+func (a BySortAndCreateTime) Len() int {
|
|
|
+ return len(a)
|
|
|
+}
|
|
|
+
|
|
|
+func (a BySortAndCreateTime) Swap(i, j int) {
|
|
|
+ a[i], a[j] = a[j], a[i]
|
|
|
+}
|
|
|
+
|
|
|
+func (a BySortAndCreateTime) Less(i, j int) bool {
|
|
|
+ if a[i].Sort == a[j].Sort {
|
|
|
+ return a[i].CreateTime.Before(a[j].CreateTime)
|
|
|
+ }
|
|
|
+ return a[i].Sort < a[j].Sort
|
|
|
+}
|
|
|
+
|
|
|
+// SortClassifyListBySortAndCreateTime sorts the ClassifyList slice by Sort and then CreateTime in ascending order.
|
|
|
+func SortClassifyListBySortAndCreateTime(classifyList []*models.ClassifyList) {
|
|
|
+ sort.Sort(BySortAndCreateTime(classifyList))
|
|
|
+}
|