123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255 |
- package services
- import (
- "eta/eta_api/models"
- "eta/eta_api/models/report_approve"
- "eta/eta_api/utils"
- "fmt"
- "time"
- )
- func MoveEnglishReportClassify(req models.EnglishClassifyMoveReq) (err error, errMsg string) {
- classifyId := req.ClassifyId
- prevClassifyId := req.PrevClassifyId
- nextClassifyId := req.NextClassifyId
-
- var (
- classifyInfo *models.EnglishClassify
- prevClassify *models.EnglishClassify
- nextClassify *models.EnglishClassify
- prevSort int
- nextSort int
- )
-
- classifyInfo, err = models.GetEnglishReportClassifyById(classifyId)
- if err != nil {
- if err.Error() == utils.ErrNoRow() {
- errMsg = "分类不存在, 请刷新页面"
- err = fmt.Errorf("获取分类信息失败,Err:" + err.Error())
- return
- }
- errMsg = "移动失败"
- err = fmt.Errorf("获取分类信息失败,Err:" + err.Error())
- return
- } else if classifyInfo.Id == 0 {
- errMsg = "分类不存在, 请刷新页面"
- err = fmt.Errorf("获取分类信息失败,Err:" + err.Error())
- return
- }
- parentClassifyId := classifyInfo.ParentId
- if prevClassifyId > 0 {
- prevClassify, err = models.GetEnglishReportClassifyById(prevClassifyId)
- if err != nil {
- if err.Error() == utils.ErrNoRow() {
- errMsg = "上一个分类不存在, 请刷新页面"
- err = fmt.Errorf("获取分类信息失败,Err:" + err.Error())
- return
- }
- errMsg = "移动失败"
- err = fmt.Errorf("获取上一个兄弟节点分类信息失败,Err:" + err.Error())
- return
- }
- prevSort = prevClassify.Sort
- }
- if nextClassifyId > 0 {
-
- nextClassify, err = models.GetEnglishReportClassifyById(nextClassifyId)
- if err != nil {
- if err.Error() == utils.ErrNoRow() {
- errMsg = "下一个分类不存在, 请刷新页面"
- err = fmt.Errorf("获取分类信息失败,Err:" + err.Error())
- return
- }
- errMsg = "移动失败"
- err = fmt.Errorf("获取下一个兄弟节点分类信息失败,Err:" + err.Error())
- return
- }
- nextSort = nextClassify.Sort
- }
- err, errMsg = moveEnglishReportClassify(classifyInfo, prevClassify, nextClassify, parentClassifyId, prevSort, nextSort)
- return
- }
- func moveEnglishReportClassify(classifyInfo, prevClassify, nextClassify *models.EnglishClassify, parentId, prevSort, nextSort int) (err error, errMsg string) {
- ob := new(models.EnglishClassify)
- updateCol := make([]string, 0)
-
- if classifyInfo.ParentId != parentId {
- errMsg = "移动失败"
- err = fmt.Errorf("不支持目录层级变更")
- return
- }
- if prevSort > 0 {
-
- if nextSort > 0 {
-
-
- if prevSort == nextSort || prevSort == classifyInfo.Sort {
-
- updateSortStr := `sort + 2`
-
- if prevClassify != nil {
- _ = models.UpdateEnglishClassifySortByParentId(parentId, prevClassify.Id, prevClassify.Sort, updateSortStr)
- } else {
- _ = models.UpdateEnglishClassifySortByParentId(parentId, 0, prevSort, updateSortStr)
- }
- } else {
-
- if nextSort-prevSort == 1 {
-
- updateSortStr := `sort + 1`
-
- if prevClassify != nil {
- _ = models.UpdateEnglishClassifySortByParentId(parentId, prevClassify.Id, prevSort, updateSortStr)
- } else {
- _ = models.UpdateEnglishClassifySortByParentId(parentId, 0, prevSort, updateSortStr)
- }
- }
- }
- }
- classifyInfo.Sort = prevSort + 1
- classifyInfo.ModifyTime = time.Now()
- updateCol = append(updateCol, "Sort", "ModifyTime")
- } else if prevClassify == nil && nextClassify == nil && parentId > 0 {
-
- var maxSort int
- maxSort, err = ob.GetMaxSortByParentId(parentId)
- if err != nil {
- errMsg = "移动失败"
- err = fmt.Errorf("查询组内排序信息失败,Err:" + err.Error())
- return
- }
- classifyInfo.Sort = maxSort + 1
- classifyInfo.ModifyTime = time.Now()
- updateCol = append(updateCol, "Sort", "ModifyTime")
- } else {
-
- firstPermission, tmpErr := ob.GetFirstClassifyByParentId(parentId)
- if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
- errMsg = "移动失败"
- err = fmt.Errorf("获取获取当前父级分类下的排序第一条的分类信息失败,Err:" + tmpErr.Error())
- return
- }
-
- if firstPermission != nil && firstPermission.Id != 0 && firstPermission.Sort == 0 {
- updateSortStr := ` sort + 1 `
- _ = models.UpdateEnglishClassifySortByParentId(parentId, firstPermission.Id-1, 0, updateSortStr)
- }
- classifyInfo.Sort = 0
- classifyInfo.ModifyTime = time.Now()
- updateCol = append(updateCol, "Sort", "ModifyTime")
- }
-
- if len(updateCol) > 0 {
- err = classifyInfo.UpdateEnglishClassify(updateCol)
- if err != nil {
- errMsg = "移动失败"
- err = fmt.Errorf("修改失败,Err:" + err.Error())
- return
- }
- }
- return
- }
- func MarkEnableDeleteEnlishClassify(rootClassifyList, childClassifyList []*models.EnglishClassifyList) (err error) {
- if len(rootClassifyList) == 0 && len(childClassifyList) == 0 {
- return
- }
-
- allClassifyList := append(rootClassifyList, childClassifyList...)
- classifyIds := make([]int, len(allClassifyList))
- rootClassifyMap := make(map[int]*models.EnglishClassifyList)
- for i, v := range allClassifyList {
- classifyIds[i] = v.Id
- if v.RootId == v.Id {
- rootClassifyMap[v.Id] = v
- }
- }
-
- reportList, err := models.GetExistEnglishReportClassifyIdByClassifyIds(classifyIds)
- if err != nil {
- return
- }
-
- flowOb := new(report_approve.ReportApproveFlow)
- flowCond := fmt.Sprintf(` AND %s = ? `, report_approve.ReportApproveFlowCols.ReportType)
- flowPars := make([]interface{}, 0)
- flowPars = append(flowPars, report_approve.FlowReportTypeEnglish)
- flowList, err := flowOb.GetItemsByCondition(flowCond, flowPars, []string{"classify_first_id", "classify_second_id", "classify_third_id"}, "")
- if err != nil {
- return
- }
-
- videoClassify, err := models.GetAllEnglishVideoClassify()
- if err != nil {
- return
- }
- disableDeleteClassifyMap := make(map[int]struct{})
-
- for _, v := range reportList {
- if v.ClassifyIdFirst > 0 {
- disableDeleteClassifyMap[v.ClassifyIdFirst] = struct{}{}
- }
- if v.ClassifyIdSecond > 0 {
- disableDeleteClassifyMap[v.ClassifyIdSecond] = struct{}{}
- }
- }
-
- for _, v := range flowList {
- if v.ClassifyFirstId > 0 {
- disableDeleteClassifyMap[v.ClassifyFirstId] = struct{}{}
- }
- if v.ClassifySecondId > 0 {
- disableDeleteClassifyMap[v.ClassifySecondId] = struct{}{}
- }
- if v.ClassifyThirdId > 0 {
- disableDeleteClassifyMap[v.ClassifyThirdId] = struct{}{}
- }
- }
- for _, v := range videoClassify {
- if v.ClassifyIdFirst > 0 {
- disableDeleteClassifyMap[v.Id] = struct{}{}
- }
- if v.ClassifyIdSecond > 0 {
- disableDeleteClassifyMap[v.Id] = struct{}{}
- }
- }
- markedClassifyMap := make(map[int]struct{})
- for _, v := range allClassifyList {
- if _, ok := markedClassifyMap[v.Id]; ok {
- continue
- }
- if _, ok := disableDeleteClassifyMap[v.Id]; !ok {
- v.IsEnableDelete = 1
- } else {
- rootClassifyMap[v.RootId].IsEnableDelete = 0
- markedClassifyMap[v.RootId] = struct{}{}
- }
- markedClassifyMap[v.Id] = struct{}{}
- }
- return
- }
|