|
@@ -2,12 +2,12 @@ package english_report
|
|
|
|
|
|
import (
|
|
|
"encoding/json"
|
|
|
- "fmt"
|
|
|
- "github.com/rdlucklib/rdluck_tools/paging"
|
|
|
"eta/eta_api/controllers"
|
|
|
"eta/eta_api/models"
|
|
|
"eta/eta_api/services"
|
|
|
"eta/eta_api/utils"
|
|
|
+ "fmt"
|
|
|
+ "github.com/rdlucklib/rdluck_tools/paging"
|
|
|
"sort"
|
|
|
"time"
|
|
|
)
|
|
@@ -35,7 +35,6 @@ func (this *EnglishReportController) ListClassify() {
|
|
|
pageSize, _ := this.GetInt("PageSize")
|
|
|
currentIndex, _ := this.GetInt("CurrentIndex")
|
|
|
keyWord := this.GetString("KeyWord")
|
|
|
- classifyType, _ := this.GetInt("ClassifyType", 0)
|
|
|
|
|
|
var startSize int
|
|
|
if pageSize <= 0 {
|
|
@@ -50,13 +49,21 @@ func (this *EnglishReportController) ListClassify() {
|
|
|
page := paging.GetPaging(currentIndex, pageSize, 0)
|
|
|
resp := new(models.EnglishClassifyListResp)
|
|
|
|
|
|
- list, err := models.GetEnglishClassifyList(startSize, pageSize, keyWord, classifyType)
|
|
|
+ // 处理一级分类分页的情况
|
|
|
+ rootList, err := models.GetEnglishClassifyRootId(startSize, pageSize, keyWord)
|
|
|
if err != nil {
|
|
|
br.Msg = "获取失败"
|
|
|
br.ErrMsg = "获取失败,Err:" + err.Error()
|
|
|
return
|
|
|
}
|
|
|
- total, err := models.GetEnglishClassifyListCount(keyWord, classifyType)
|
|
|
+ var ids []int
|
|
|
+ var rootIds []int
|
|
|
+ rootMap := make(map[int]struct{}, 0)
|
|
|
+ for _, v := range rootList {
|
|
|
+ rootIds = append(rootIds, v.Id)
|
|
|
+ rootMap[v.Id] = struct{}{}
|
|
|
+ }
|
|
|
+ total, err := models.GetEnglishClassifyListCount(keyWord)
|
|
|
if err != nil {
|
|
|
br.Msg = "获取失败"
|
|
|
br.ErrMsg = "获取失败,Err:" + err.Error()
|
|
@@ -72,65 +79,100 @@ func (this *EnglishReportController) ListClassify() {
|
|
|
br.Msg = "获取成功"
|
|
|
return
|
|
|
}
|
|
|
- var parentIds []int
|
|
|
- for _, v := range list {
|
|
|
- parentIds = append(parentIds, v.Id)
|
|
|
- }
|
|
|
+ page = paging.GetPaging(currentIndex, pageSize, total)
|
|
|
|
|
|
- childMap := make(map[int][]*models.EnglishClassifyList)
|
|
|
- tmpList, err := models.GetEnglishClassifyChildByParentIds(parentIds, keyWord, classifyType)
|
|
|
+ //获取相关的分类ID
|
|
|
+ idList, err := models.GetEnglishClassifyListByRootId(rootIds, keyWord)
|
|
|
if err != nil {
|
|
|
- br.Msg = "获取二级分类失败"
|
|
|
- br.ErrMsg = "获取二级分类失败,Err:" + err.Error()
|
|
|
+ br.Msg = "获取失败"
|
|
|
+ br.ErrMsg = "获取失败,Err:" + err.Error()
|
|
|
return
|
|
|
}
|
|
|
-
|
|
|
- // 二级分类-品种权限
|
|
|
+ secondListMap := make(map[int][]*models.EnglishClassifyList)
|
|
|
+ thirdListMap := make(map[int][]*models.EnglishClassifyList)
|
|
|
+ var thirdIds []int
|
|
|
+ var sortChildList models.RSChildClassifyList
|
|
|
+ // 三级分类-品种权限
|
|
|
permissionMap := make(map[int][]int)
|
|
|
- {
|
|
|
- classifyIds := make([]int, 0)
|
|
|
+
|
|
|
+ if len(idList) > 0 {
|
|
|
+ childIdMap := make(map[int]struct{}, 0)
|
|
|
+ for _, v := range idList {
|
|
|
+ if _, ok := childIdMap[v.ParentId]; !ok {
|
|
|
+ ids = append(ids, v.ParentId)
|
|
|
+ }
|
|
|
+ if _, ok := childIdMap[v.Id]; !ok {
|
|
|
+ ids = append(ids, v.Id)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ tmpList, err := models.GetEnglishClassifyChildByIds(ids)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "获取二级分类失败"
|
|
|
+ br.ErrMsg = "获取二级分类失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
for _, v := range tmpList {
|
|
|
- classifyIds = append(classifyIds, v.Id)
|
|
|
+ if _, ok := rootMap[v.ParentId]; !ok {
|
|
|
+ thirdIds = append(thirdIds, v.Id)
|
|
|
+ }
|
|
|
}
|
|
|
- if len(classifyIds) > 0 {
|
|
|
- cond := fmt.Sprintf(` AND %s IN (%s)`, models.EnClassifyPermissionColumns.EnClassifyId, utils.GetOrmInReplace(len(classifyIds)))
|
|
|
- pars := make([]interface{}, 0)
|
|
|
- pars = append(pars, classifyIds)
|
|
|
- ob := new(models.EnClassifyPermission)
|
|
|
- items, e := ob.GetItemsByCondition(cond, pars, []string{}, "")
|
|
|
- if e != nil {
|
|
|
- br.Msg = "获取失败"
|
|
|
- br.ErrMsg = "获取客户权限列表失败, Err: " + e.Error()
|
|
|
- return
|
|
|
+ {
|
|
|
+ classifyIds := thirdIds
|
|
|
+ if len(classifyIds) > 0 {
|
|
|
+ cond := fmt.Sprintf(` AND %s IN (%s)`, models.EnClassifyPermissionColumns.EnClassifyId, utils.GetOrmInReplace(len(classifyIds)))
|
|
|
+ pars := make([]interface{}, 0)
|
|
|
+ pars = append(pars, classifyIds)
|
|
|
+ ob := new(models.EnClassifyPermission)
|
|
|
+ items, e := ob.GetItemsByCondition(cond, pars, []string{}, "")
|
|
|
+ if e != nil {
|
|
|
+ br.Msg = "获取失败"
|
|
|
+ br.ErrMsg = "获取客户权限列表失败, Err: " + e.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ for _, v := range items {
|
|
|
+ if permissionMap[v.EnClassifyId] == nil {
|
|
|
+ permissionMap[v.EnClassifyId] = make([]int, 0)
|
|
|
+ }
|
|
|
+ permissionMap[v.EnClassifyId] = append(permissionMap[v.EnClassifyId], v.EnPermissionId)
|
|
|
+ }
|
|
|
}
|
|
|
- for _, v := range items {
|
|
|
- if permissionMap[v.EnClassifyId] == nil {
|
|
|
- permissionMap[v.EnClassifyId] = make([]int, 0)
|
|
|
+ }
|
|
|
+ // 处理三级分类
|
|
|
+ for _, v := range tmpList {
|
|
|
+ if _, ok := rootMap[v.ParentId]; !ok {
|
|
|
+ if p, ok1 := permissionMap[v.Id]; ok1 {
|
|
|
+ v.EnPermissions = p
|
|
|
}
|
|
|
- permissionMap[v.EnClassifyId] = append(permissionMap[v.EnClassifyId], v.EnPermissionId)
|
|
|
+ thirdListMap[v.ParentId] = append(thirdListMap[v.ParentId], v)
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- for _, v := range tmpList {
|
|
|
- v.EnPermissions = permissionMap[v.Id]
|
|
|
- childMap[v.ParentId] = append(childMap[v.ParentId], v)
|
|
|
- }
|
|
|
- for _, v := range list {
|
|
|
- if child, ok := childMap[v.Id]; ok {
|
|
|
- v.Child = child
|
|
|
+ //处理二级分类
|
|
|
+ for _, v := range tmpList {
|
|
|
+ if _, ok := rootMap[v.ParentId]; ok {
|
|
|
+ if child, ok1 := thirdListMap[v.Id]; ok1 {
|
|
|
+ sortChildList = child
|
|
|
+ sort.Sort(sortChildList)
|
|
|
+ v.Child = sortChildList
|
|
|
+ }
|
|
|
+ secondListMap[v.ParentId] = append(secondListMap[v.ParentId], v)
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ //处理一级分类
|
|
|
var sortList models.RSClassifyList
|
|
|
- sortList = list
|
|
|
+ for _, v := range rootList {
|
|
|
+ if child, ok := secondListMap[v.Id]; ok {
|
|
|
+ sortChildList = child
|
|
|
+ sort.Sort(sortChildList)
|
|
|
+ v.Child = sortChildList
|
|
|
+ }
|
|
|
+ sortList = append(sortList, v)
|
|
|
+ }
|
|
|
+
|
|
|
sort.Sort(sortList)
|
|
|
|
|
|
- for _, item := range sortList {
|
|
|
- var sortChildList models.RSChildClassifyList
|
|
|
- sortChildList = item.Child
|
|
|
- sort.Sort(sortChildList)
|
|
|
- item.Child = sortChildList
|
|
|
- }
|
|
|
resp.List = sortList
|
|
|
resp.Paging = page
|
|
|
|