Explorar o código

fix:禁用的报告分类,不允许操作、继承

Roc hai 1 mes
pai
achega
9b95758206
Modificáronse 3 ficheiros con 86 adicións e 2 borrados
  1. 72 2
      controllers/report_v2.go
  2. 13 0
      models/classify.go
  3. 1 0
      models/report.go

+ 72 - 2
controllers/report_v2.go

@@ -175,8 +175,12 @@ func (this *ReportController) ListReport() {
 		pvMap := make(map[int]int)
 		uvMap := make(map[int]int)
 		reportIdArr := make([]int, 0)
-		syncReportIdArr := make([]string, 0)      // 同步过来的报告IDs
-		oldAndNewReportIdMap := make(map[int]int) // 旧报告和新报告的id对应关系
+		syncReportIdArr := make([]string, 0)          // 同步过来的报告IDs
+		oldAndNewReportIdMap := make(map[int]int)     // 旧报告和新报告的id对应关系
+		classifyIdList := make([]int, 0)              // 关联的指标分类id
+		classifyIdMap := make(map[int]bool)           // 分类id map
+		classifyMap := make(map[int]*models.Classify) // 分类map
+
 		for i := 0; i < listLen; i++ {
 			reportIdArr = append(reportIdArr, list[i].Id)
 			if list[i].OldReportId > 0 && list[i].ReportLayout == 1 {
@@ -185,6 +189,22 @@ func (this *ReportController) ListReport() {
 			}
 			pvMap[list[i].Id] = list[i].Pv
 			uvMap[list[i].Id] = list[i].Uv
+
+			if list[i].ClassifyIdFirst > 0 {
+				if _, ok := classifyIdMap[list[i].ClassifyIdFirst]; !ok {
+					classifyIdList = append(classifyIdList, list[i].ClassifyIdFirst)
+				}
+			}
+			if list[i].ClassifyIdSecond > 0 {
+				if _, ok := classifyIdMap[list[i].ClassifyIdSecond]; !ok {
+					classifyIdList = append(classifyIdList, list[i].ClassifyIdSecond)
+				}
+			}
+			if list[i].ClassifyIdThird > 0 {
+				if _, ok := classifyIdMap[list[i].ClassifyIdThird]; !ok {
+					classifyIdList = append(classifyIdList, list[i].ClassifyIdThird)
+				}
+			}
 		}
 
 		// 当下报告的pv,uv
@@ -203,6 +223,18 @@ func (this *ReportController) ListReport() {
 			}
 		}
 
+		if len(classifyIdList) > 0 {
+			classifyList, e := models.GetClassifyListByIdList(classifyIdList)
+			if e != nil {
+				br.Msg = "获取失败"
+				br.ErrMsg = "获取报告分类失败, Err: " + e.Error()
+				return
+			}
+			for _, v := range classifyList {
+				classifyMap[v.Id] = v
+			}
+		}
+
 		//reportIds := strings.Join(reportIdArr, ",")
 		//syncReportIds := strings.Join(syncReportIdArr, ",")
 
@@ -249,6 +281,26 @@ func (this *ReportController) ListReport() {
 			list[i].ChapterVideoList = chapterList
 			list[i].Pv = pvMap[list[i].Id]
 			list[i].Uv = uvMap[list[i].Id]
+
+			if list[i].ClassifyIdThird > 0 {
+				if classify, ok := classifyMap[list[i].ClassifyIdThird]; ok {
+					if classify.Enabled == 1 {
+						list[i].ClassifyEnabled = true
+					}
+				}
+			} else if list[i].ClassifyIdSecond > 0 {
+				if classify, ok := classifyMap[list[i].ClassifyIdSecond]; ok {
+					if classify.Enabled == 1 {
+						list[i].ClassifyEnabled = true
+					}
+				}
+			} else if list[i].ClassifyIdFirst > 0 {
+				if classify, ok := classifyMap[list[i].ClassifyIdFirst]; ok {
+					if classify.Enabled == 1 {
+						list[i].ClassifyEnabled = true
+					}
+				}
+			}
 		}
 
 		// 多人协作的协作报告,需要判断是否可编辑
@@ -918,6 +970,24 @@ func (this *ReportController) AuthorizedListReport() {
 
 	condition += orCondition
 
+	// 获取所有启用的分类
+	classifyList, err := models.GetAllEnabledClassify()
+	if err != nil {
+		br.Msg = "获取失败"
+		br.ErrMsg = "获取失败,Err:" + err.Error()
+		return
+	}
+	classifyIdNum := len(classifyList)
+	if classifyIdNum > 0 {
+		classifyIdList := make([]int, 0)
+		for _, v := range classifyList {
+			classifyIdList = append(classifyIdList, v.Id)
+		}
+
+		condition += ` AND a.classify_id_first in (` + utils.GetOrmInReplace(classifyIdNum) + `)  AND a.classify_id_second in (` + utils.GetOrmInReplace(classifyIdNum) + `)  AND a.classify_id_third in (` + utils.GetOrmInReplace(classifyIdNum) + `) `
+		pars = append(pars, classifyIdList, classifyIdList, classifyIdList)
+	}
+
 	total, err = models.GetReportListCountByAuthorized(condition, pars)
 	if err != nil {
 		br.Msg = "获取失败"

+ 13 - 0
models/classify.go

@@ -653,3 +653,16 @@ func GetClassifyListByParentId(parentId int) (items []*Classify, err error) {
 
 	return items, err
 }
+
+// GetAllEnabledClassify
+// @Description: 获取启用的指标列表
+// @author: Roc
+// @datetime 2025-01-20 11:02:23
+// @return list []*Classify
+// @return err error
+func GetAllEnabledClassify() (list []*Classify, err error) {
+	o := orm.NewOrmUsingDB("rddp")
+	sql := ` SELECT * FROM classify WHERE enabled = 1`
+	_, err = o.Raw(sql).QueryRows(&list)
+	return
+}

+ 1 - 0
models/report.go

@@ -150,6 +150,7 @@ type ReportList struct {
 	ClassifyIdThird     int       `description:"三级分类id"`
 	ClassifyNameThird   string    `description:"三级分类名称"`
 	InheritReportId     int       `description:"待继承的报告ID"`
+	ClassifyEnabled     bool      `description:"分类是否禁用"`
 }
 
 type ReportListResp struct {