Browse Source

文档管理-新增分类须移动报告逻辑处理

gmy 5 months ago
parent
commit
c15c73366d
3 changed files with 75 additions and 0 deletions
  1. 12 0
      models/document_manage_model/outside_report.go
  2. 19 0
      models/report.go
  3. 44 0
      services/classify.go

+ 12 - 0
models/document_manage_model/outside_report.go

@@ -106,3 +106,15 @@ func DeleteOutsideReport(id int) (err error) {
 	_, err = o.QueryTable("outside_report").Filter("outside_report_id", id).Delete()
 	return
 }
+
+// GetOutsideReportListByClassifyId 根据分类id查询报告列表
+func GetOutsideReportListByClassifyId(classifyId int) (list []OutsideReport, err error) {
+	o := orm.NewOrmUsingDB("rddp")
+	sql := `select * from outside_report where classify_id = ?`
+	_, err = o.Raw(sql, classifyId).QueryRows(&list)
+	if err != nil {
+		return nil, err
+	}
+
+	return list, err
+}

+ 19 - 0
models/report.go

@@ -1518,3 +1518,22 @@ func GetReportFieldsByIds(ids []int, fields []string) (items []*Report, err erro
 	_, err = o.Raw(sql, ids).QueryRows(&items)
 	return
 }
+
+// GetReportListByClassifyId 根据分类id 获取报告列表
+func GetReportListByClassifyId(classifyId int) (items []*Report, err error) {
+	o := orm.NewOrmUsingDB("rddp")
+	sql := `SELECT * FROM report WHERE classify_id_first = ? classify_id_second = ? or classify_id_third = ?`
+	_, err = o.Raw(sql, classifyId, classifyId, classifyId).QueryRows(&items)
+	return items, err
+}
+
+// UpdateReportInfo 修改报告
+func UpdateReportInfo(reports *Report) (err error) {
+	o := orm.NewOrmUsingDB("rddp")
+	_, err = o.Update(reports)
+	if err != nil {
+		return err
+	}
+
+	return
+}

+ 44 - 0
services/classify.go

@@ -3,6 +3,7 @@ package services
 import (
 	"errors"
 	"eta/eta_api/models"
+	"eta/eta_api/models/document_manage_model"
 	"eta/eta_api/models/report_approve"
 	"eta/eta_api/utils"
 	"fmt"
@@ -275,6 +276,49 @@ func AddReportClassify(classifyName string, parentId int, chartPermissionIdList
 		return
 	}
 
+	// 如果父级分类下有报告,修改报告到子级分类下
+	reports, err := models.GetReportListByClassifyId(parentId)
+	if err != nil {
+		return err, "查询报告列表失败", false
+	}
+	if len(reports) > 0 {
+		for _, report := range reports {
+			if report.ClassifyIdFirst == 0 {
+				report.ClassifyIdFirst = classify.Id
+				report.ClassifyNameFirst = classifyName
+			} else if report.ClassifyIdSecond == 0 {
+				report.ClassifyIdSecond = classify.Id
+				report.ClassifyNameSecond = classifyName
+			} else {
+				report.ClassifyIdThird = classify.Id
+				report.ClassifyNameThird = classifyName
+			}
+
+			// beego orm 不支持批量修改,所以只能一个一个修改
+			err := models.UpdateReportInfo(report)
+			if err != nil {
+				return err, "修改报告分类失败", false
+			}
+		}
+	}
+	outsideReports, err := document_manage_model.GetOutsideReportListByClassifyId(parentId)
+	if err != nil {
+		return err, "查询外部报告列表失败", false
+	}
+	if len(outsideReports) > 0 {
+		for _, report := range outsideReports {
+			tempReport := report
+
+			report.ClassifyId = classify.Id
+			report.ClassifyName = classifyName
+			// 修改报告
+			err := document_manage_model.UpdateOutsideReport(&tempReport)
+			if err != nil {
+				return err, "修改外部报告分类失败", false
+			}
+		}
+	}
+
 	//获取报告分类权限列表
 	err = models.EditChartPermissionSearchKeyWordMappingMulti(classifyName, chartPermissionIdList, classify.Id)
 	if err != nil {