Sfoglia il codice sorgente

分类修复脚本、PPT接口优化

hsun 4 mesi fa
parent
commit
4daf02d6e1
3 ha cambiato i file con 74 aggiunte e 4 eliminazioni
  1. 3 3
      controllers/ppt_report.go
  2. 5 1
      models/ppt_v2.go
  3. 66 0
      services/task.go

+ 3 - 3
controllers/ppt_report.go

@@ -49,7 +49,7 @@ func (this *PptV2Controller) ReportClassify() {
 			cond += ` AND admin_id = ?`
 			pars = append(pars, sysUser.AdminId)
 		case 2:
-			cond += ` AND collaborate_type = ? AND FIND_IN_SET(?, collaborate_users) `
+			cond += ` AND collaborate_type = ? AND (admin_id = ? OR FIND_IN_SET(?, collaborate_users)) `
 			pars = append(pars, utils.ReportWriteTypeGroup, sysUser.AdminId)
 		case 3:
 			cond += ` AND report_source = ?`
@@ -174,8 +174,8 @@ func (this *PptV2Controller) ReportList() {
 			cond += ` AND admin_id = ?`
 			pars = append(pars, sysUser.AdminId)
 		case 2:
-			cond += ` AND collaborate_type = ? AND FIND_IN_SET(?, collaborate_users) `
-			pars = append(pars, utils.ReportWriteTypeGroup, sysUser.AdminId)
+			cond += ` AND collaborate_type = ? AND (admin_id = ? OR FIND_IN_SET(?, collaborate_users)) `
+			pars = append(pars, utils.ReportWriteTypeGroup, sysUser.AdminId, sysUser.AdminId)
 		case 3:
 			cond += ` AND report_source = ?`
 			pars = append(pars, utils.ReportSourceOuter)

+ 5 - 1
models/ppt_v2.go

@@ -355,7 +355,7 @@ func (m *PptV2) GetCountByCondition(condition string, pars []interface{}) (count
 
 // PptReportQueryFields 除富文本的常用查询字段
 var PptReportQueryFields = []string{
-	"ppt_id", "title", "classify_id", "ppt_version", "pptx_url", "ppt_page", "title_setting", "state", "report_source", "publish_time", "submit_time", "approve_time", "create_time", "modify_time", "admin_id", "collaborate_type", "collaborate_users",
+	"ppt_id", "title", "classify_id", "ppt_version", "pptx_url", "ppt_page", "title_setting", "state", "report_source", "publish_time", "submit_time", "approve_time", "create_time", "modify_time", "admin_id", "admin_real_name", "collaborate_type", "collaborate_users",
 }
 
 type PptReportItem struct {
@@ -378,6 +378,8 @@ type PptReportItem struct {
 	CollaborateUsers []PptReportCollaborateUser `description:"协作人信息"`
 	HasAuth          bool                       `description:"是否创建人/协作人"`
 	Editor           PPTEditingCache            `description:"编辑人信息"`
+	AdminId          int                        `description:"创建人ID"`
+	AdminRealName    string                     `description:"创建人姓名"`
 }
 
 type PptReportCollaborateUser struct {
@@ -405,6 +407,8 @@ func (m *PptV2) Format2ReportItem(origin *PptV2) (item *PptReportItem) {
 	item.ApproveTime = utils.TimeTransferString(utils.FormatDateTime, origin.ApproveTime)
 	item.CreateTime = utils.TimeTransferString(utils.FormatDateTime, origin.CreateTime)
 	item.ModifyTime = utils.TimeTransferString(utils.FormatDateTime, origin.ModifyTime)
+	item.AdminId = origin.AdminId
+	item.AdminRealName = origin.AdminRealName
 	return
 }
 

+ 66 - 0
services/task.go

@@ -1,9 +1,11 @@
 package services
 
 import (
+	"eta_gn/eta_api/models"
 	"eta_gn/eta_api/services/data"
 	"eta_gn/eta_api/utils"
 	"fmt"
+	"strconv"
 	"strings"
 )
 
@@ -19,6 +21,9 @@ func Task() {
 	// 进行指标替换操作
 	go DealReplaceEdbCache()
 
+	// 修复分类LevelPath
+	//FixClassifyLevelPath()
+
 	fmt.Println("task end")
 }
 
@@ -39,3 +44,64 @@ func ImportManualDataRefresh() {
 		})
 	}
 }
+
+func FixClassifyLevelPath() {
+	var err error
+	defer func() {
+		if err != nil {
+			fmt.Println(err)
+		}
+	}()
+	classifyOb := new(models.Classify)
+	classifies, e := classifyOb.GetItemsByCondition("", []interface{}{}, []string{}, "")
+	if e != nil {
+		err = fmt.Errorf("获取分类列表失败, %v", e)
+		return
+	}
+	fmt.Println("开始修复")
+
+	// 先更新所有一级分类
+	for _, v := range classifies {
+		if v.ParentId > 0 {
+			continue
+		}
+		v.LevelPath = strconv.Itoa(v.Id)
+		if e = v.UpdateClassify([]string{"LevelPath"}); e != nil {
+			err = fmt.Errorf("更新LevelPath失败, ID: %d", v.Id)
+			return
+		}
+	}
+
+	// 再更新二级
+	parentMap := make(map[int]string)
+	for _, v := range classifies {
+		if v.Level != 2 {
+			continue
+		}
+		v.LevelPath = fmt.Sprintf("%d,%d", v.ParentId, v.Id)
+		if e = v.UpdateClassify([]string{"LevelPath"}); e != nil {
+			err = fmt.Errorf("更新二级LevelPath失败, ID: %d", v.Id)
+			return
+		}
+		parentMap[v.Id] = v.LevelPath
+	}
+
+	// 再更新三级,没四级了
+	for _, v := range classifies {
+		if v.Level != 3 {
+			continue
+		}
+		str := parentMap[v.ParentId]
+		if str == "" {
+			err = fmt.Errorf("二级LevelPath为空, ID: %d", v.ParentId)
+			return
+		}
+
+		v.LevelPath = fmt.Sprintf("%s,%d", str, v.Id)
+		if e = v.UpdateClassify([]string{"LevelPath"}); e != nil {
+			err = fmt.Errorf("更新三级LevelPath失败, ID: %d", v.Id)
+			return
+		}
+	}
+	fmt.Println("修复成功")
+}