Преглед изворни кода

fix:调整报告视频关联分类列表的接口,支持返回三级

Roc пре 8 месеци
родитељ
комит
c8429c0b24
4 измењених фајлова са 115 додато и 19 уклоњено
  1. 71 19
      controllers/yb/road_video.go
  2. 3 0
      models/classify.go
  3. 7 0
      models/report.go
  4. 34 0
      services/report.go

+ 71 - 19
controllers/yb/road_video.go

@@ -506,7 +506,8 @@ func (r *RoadVideoController) SimpleReportList() {
 	classifyIdSecond, _ := r.GetInt("ClassifyIdSecond", 0)
 	if classifyIdSecond <= 0 {
 		// 2023-03-03 直接取classify表relate_video=1的二级分类下的报告
-		classifyCond := ` AND parent_id > 0 AND relate_video = 1`
+		//classifyCond := ` AND parent_id > 0 AND relate_video = 1`
+		classifyCond := ` AND relate_video = 1`
 		classifyPars := make([]interface{}, 0)
 		classifyList, e := models.GetClassifyByCondition(classifyCond, "", classifyPars)
 		if e != nil {
@@ -514,28 +515,66 @@ func (r *RoadVideoController) SimpleReportList() {
 			br.ErrMsg = "获取路演视频可选报告分类失败, Err: " + e.Error()
 			return
 		}
-		classifyIds := make([]int, 0)
+		var hasChild bool
+		firstClassifyIds := make([]int, 0)
+		secondClassifyIds := make([]int, 0)
+		thirdClassifyIds := make([]int, 0)
 		for _, c := range classifyList {
-			classifyIds = append(classifyIds, c.Id)
+			switch c.Level {
+			case 1:
+				firstClassifyIds = append(firstClassifyIds, c.Id)
+				hasChild = true
+			case 2:
+				secondClassifyIds = append(secondClassifyIds, c.Id)
+				hasChild = true
+			case 3:
+				thirdClassifyIds = append(thirdClassifyIds, c.Id)
+				hasChild = true
+			}
 		}
-		if len(classifyIds) > 0 {
-			cond += ` AND classify_id_second IN ( ` + utils.GetOrmInReplace(len(classifyIds)) + ` ) `
-			pars = append(pars, classifyIds)
+		if hasChild {
+			if len(firstClassifyIds) > 0 {
+				cond += ` AND classify_id_first IN ( ` + utils.GetOrmInReplace(len(firstClassifyIds)) + ` ) `
+				pars = append(pars, firstClassifyIds)
+			}
+			if len(secondClassifyIds) > 0 {
+				cond += ` AND classify_id_second IN ( ` + utils.GetOrmInReplace(len(secondClassifyIds)) + ` ) `
+				pars = append(pars, secondClassifyIds)
+			}
+			if len(thirdClassifyIds) > 0 {
+				cond += ` AND classify_id_third IN ( ` + utils.GetOrmInReplace(len(thirdClassifyIds)) + ` ) `
+				pars = append(pars, thirdClassifyIds)
+			}
 		} else {
 			cond += ` AND 1 = 2`
 		}
+	} else {
+		classifyItem, err := models.GetClassifyById(classifyIdSecond)
+		if err != nil {
+			br.Msg = "获取失败"
+			br.ErrMsg = "获取分类失败, Err: " + err.Error()
+			return
+		}
+		switch classifyItem.Level {
+		case 1:
+			cond += ` AND classify_id_first = ? `
+			pars = append(pars, classifyIdSecond)
+		case 2:
+			cond += ` AND classify_id_second = ? `
+			pars = append(pars, classifyIdSecond)
+		case 3:
+			cond += ` AND classify_id_third = ? `
+			pars = append(pars, classifyIdSecond)
+		}
 	}
-	if classifyIdSecond > 0 {
-		cond += ` AND classify_id_second = ? `
-		pars = append(pars, classifyIdSecond)
-	}
+
 	keyword := r.GetString("Keyword", "")
 	if keyword != "" {
 		kw := fmt.Sprint("%", keyword, "%")
 		cond += ` AND title LIKE ?`
 		pars = append(pars, kw)
 	}
-	fieldArr := []string{"id", "classify_id_second", "title", "publish_time"}
+	fieldArr := []string{"id", "classify_id_first", "classify_id_second", "classify_id_third", "title", "publish_time"}
 	orderRule := ` ORDER BY publish_time DESC, id DESC`
 	reports, e := models.GetReportByCondition(cond, pars, fieldArr, orderRule, true, 0, 5)
 	if e != nil {
@@ -549,10 +588,16 @@ func (r *RoadVideoController) SimpleReportList() {
 	{
 		classifyIds := make([]int, 0)
 		for _, v := range reports {
-			if utils.InArrayByInt(classifyIds, v.ClassifyIdSecond) {
+			minClassifyId, _, e := services.GetMinClassify(v)
+			if e != nil {
+				br.Msg = "获取失败"
+				br.ErrMsg = "获取报告的最小分类失败, Err: " + e.Error()
+				return
+			}
+			if utils.InArrayByInt(classifyIds, minClassifyId) {
 				continue
 			}
-			classifyIds = append(classifyIds, v.ClassifyIdSecond)
+			classifyIds = append(classifyIds, minClassifyId)
 		}
 		if len(classifyIds) > 0 {
 			classifyIdsPermissions, e := models.GetPermissionsByClassifyIds(classifyIds)
@@ -596,13 +641,20 @@ func (r *RoadVideoController) SimpleReportList() {
 		}
 
 		for i := range reports {
+			tmpReport := reports[i]
+			minClassifyId, _, e := services.GetMinClassify(tmpReport)
+			if e != nil {
+				br.Msg = "获取失败"
+				br.ErrMsg = "获取报告的最小分类失败, Err: " + e.Error()
+				return
+			}
 			respList = append(respList, &SimpleReportListResp{
-				ReportId:       reports[i].Id,
-				Title:          reports[i].Title,
-				PublishTime:    reports[i].PublishTime.Format(utils.FormatDateTime),
-				BindVideo:      bindMap[reports[i].Id],
-				BindVideoTitle: bindTitleMap[reports[i].Id],
-				PermissionIds:  classifyPermissions[reports[i].ClassifyIdSecond],
+				ReportId:       tmpReport.Id,
+				Title:          tmpReport.Title,
+				PublishTime:    tmpReport.PublishTime.Format(utils.FormatDateTime),
+				BindVideo:      bindMap[tmpReport.Id],
+				BindVideoTitle: bindTitleMap[tmpReport.Id],
+				PermissionIds:  classifyPermissions[minClassifyId],
 			})
 		}
 	}

+ 3 - 0
models/classify.go

@@ -39,6 +39,8 @@ type Classify struct {
 	RelateVideo       int       `description:"是否在路演视频中可选: 0-否; 1-是"`
 	IsMassSend        int       `description:"1:群发,0:非群发"`
 	Enabled           int       `description:"是否可用,1可用,0禁用"`
+	Level             int       `description:"层级"`
+	HasChild          int       `description:"是否有子级别,0:下面没有子分类,1:下面有子分类;默认:0"`
 }
 
 func GetClassifyById(classifyId int) (item *Classify, err error) {
@@ -214,6 +216,7 @@ type SimpleClassifyList struct {
 	ParentId     int       `description:"父级ID"`
 	Sort         int       `description:"排序"`
 	CreateTime   time.Time `description:"创建时间"`
+	Level        int       `description:"层级"`
 	Child        []*SimpleClassifyList
 }
 

+ 7 - 0
models/report.go

@@ -40,6 +40,13 @@ type Report struct {
 	MsgSendTime        time.Time `description:"模版消息发送时间"`
 	AdminId            int       `description:"创建者账号"`
 	AdminRealName      string    `description:"创建者姓名"`
+	ClassifyIdThird    int       `description:"三级分类id"`
+	ClassifyNameThird  string    `description:"三级分类名称"`
+	CollaborateType    int8      `description:"协作方式,1:个人,2:多人协作。默认:1"`
+	ReportLayout       int8      `description:"报告布局,1:常规布局,2:智能布局。默认:1"`
+	IsPublicPublish    int8      `description:"是否公开发布,1:是,2:否"`
+	ReportCreateTime   time.Time `description:"报告时间创建时间"`
+	InheritReportId    int       `description:"待继承的报告ID"`
 }
 
 type ReportList struct {

+ 34 - 0
services/report.go

@@ -1,8 +1,11 @@
 package services
 
 import (
+	"errors"
 	"fmt"
 	"github.com/PuerkitoBio/goquery"
+	"hongze/hz_crm_api/models"
+	"hongze/hz_crm_api/utils"
 	"html"
 	"strings"
 )
@@ -31,3 +34,34 @@ func GetReportContentSub(content string) (contentSub string, err error) {
 	})
 	return
 }
+
+// GetMinClassify
+// @Description: 获取最小分类ID
+// @author: Roc
+// @datetime 2024-06-20 09:23:19
+// @param reportInfo *models.Report
+// @return minClassifyId int
+// @return minClassifyName string
+// @return err error
+func GetMinClassify(reportInfo *models.Report) (minClassifyId int, minClassifyName string, err error) {
+	defer func() {
+		if err != nil {
+			utils.FileLog.Error("获取最小分类ID失败,报告ID:%d,Err:%s", reportInfo.Id, err.Error())
+		}
+	}()
+	minClassifyId = reportInfo.ClassifyIdThird
+	minClassifyName = reportInfo.ClassifyNameThird
+	if minClassifyId <= 0 {
+		minClassifyId = reportInfo.ClassifyIdSecond
+		minClassifyName = reportInfo.ClassifyNameSecond
+	}
+	if minClassifyId <= 0 {
+		minClassifyId = reportInfo.ClassifyIdFirst
+		minClassifyName = reportInfo.ClassifyNameFirst
+	}
+	if minClassifyId <= 0 {
+		err = errors.New("分类异常")
+	}
+
+	return
+}