Roc 8 mesiacov pred
rodič
commit
3f21f7087a

+ 1 - 1
controllers/report.go

@@ -1859,7 +1859,7 @@ func (this *ReportController) PublishDayWeekReport() {
 		return
 	}
 
-	tips, err := services.PublishDayWeekReport(reportId)
+	tips, err := services.PublishDayWeekReport(reportInfo)
 	if err != nil {
 		br.Msg = "发布失败"
 		br.ErrMsg = "发布晨/周报失败, Err: " + err.Error()

+ 2 - 0
controllers/report_v2.go

@@ -1141,6 +1141,8 @@ func fixApproveRecord() {
 	fmt.Println("审批数据修复完成")
 }
 
+// TODO 审批列表,分类三级展示
+
 // fixChapterPermission
 // @Description: 修复章节关联的品种权限
 // @author: Roc

+ 20 - 10
models/report.go

@@ -871,6 +871,8 @@ type ElasticReportDetail struct {
 	ClassifyNameFirst  string `description:"一级分类名称"`
 	ClassifyIdSecond   int    `description:"二级分类ID"`
 	ClassifyNameSecond string `description:"二级分类名称"`
+	ClassifyId         int    `description:"最小单元的分类ID"`
+	ClassifyName       string `description:"最小单元的分类名称"`
 	Categories         string `description:"关联的品种名称(包括品种别名)"`
 	StageStr           string `description:"报告期数"`
 }
@@ -894,7 +896,7 @@ func GetNewReportExist(oldReportId int) (item *Report, err error) {
 }
 
 // PublishReportAndChapter 发布报告及章节
-func PublishReportAndChapter(reportInfo *Report, publishIds, unPublishIds []int, isPublishReport bool, cols []string) (err error) {
+func PublishReportAndChapter(reportInfo *Report, isPublishReport bool, cols []string) (err error) {
 	o := orm.NewOrmUsingDB("rddp")
 	to, err := o.Begin()
 	if err != nil {
@@ -909,19 +911,27 @@ func PublishReportAndChapter(reportInfo *Report, publishIds, unPublishIds []int,
 	}()
 	// 更新报告
 	if isPublishReport {
-		if _, err = to.Update(reportInfo, cols...); err != nil {
+		_, err = to.Update(reportInfo, cols...)
+		if err != nil {
 			return
 		}
 	}
+
+	// 发布该报告的所有章节
+	sql := ` UPDATE report_chapter SET publish_state = 2, publish_time = ? WHERE report_id = ?  `
+	_, err = to.Raw(sql, reportInfo.PublishTime, reportInfo.Id).Exec()
+
 	// 发布章节
-	if len(publishIds) > 0 {
-		sql := ` UPDATE report_chapter SET publish_state = 2, publish_time = ? WHERE report_id = ? AND report_chapter_id IN (` + utils.GetOrmInReplace(len(publishIds)) + `) `
-		_, err = to.Raw(sql, reportInfo.PublishTime, reportInfo.Id, publishIds).Exec()
-	}
-	if len(unPublishIds) > 0 {
-		sql := ` UPDATE report_chapter SET publish_state = 1, publish_time = NULL, is_edit = 0 WHERE report_id = ? AND report_chapter_id IN (` + utils.GetOrmInReplace(len(unPublishIds)) + `) `
-		_, err = to.Raw(sql, reportInfo.Id, unPublishIds).Exec()
-	}
+	//if len(publishIds) > 0 {
+	//	sql := ` UPDATE report_chapter SET publish_state = 2, publish_time = ? WHERE report_id = ? AND report_chapter_id IN (` + utils.GetOrmInReplace(len(publishIds)) + `) `
+	//	_, err = to.Raw(sql, reportInfo.PublishTime, reportInfo.Id, publishIds).Exec()
+	//}
+
+	//if len(unPublishIds) > 0 {
+	//	sql := ` UPDATE report_chapter SET publish_state = 1, publish_time = NULL, is_edit = 0 WHERE report_id = ? AND report_chapter_id IN (` + utils.GetOrmInReplace(len(unPublishIds)) + `) `
+	//	_, err = to.Raw(sql, reportInfo.Id, unPublishIds).Exec()
+	//}
+
 	return
 }
 

+ 2 - 0
services/elastic.go

@@ -107,6 +107,8 @@ func EsAddOrEditReport(indexName, docId string, item *models.ElasticReportDetail
 			"ClassifyNameFirst":  item.ClassifyNameFirst,
 			"ClassifyIdSecond":   item.ClassifyIdSecond,
 			"ClassifyNameSecond": item.ClassifyNameSecond,
+			"ClassifyId":         item.ClassifyId,
+			"ClassifyName":       item.ClassifyName,
 			"Categories":         item.Categories,
 			"StageStr":           item.StageStr,
 		}).Do(context.Background())

+ 88 - 66
services/report.go

@@ -6,6 +6,7 @@ import (
 	"eta/eta_api/models"
 	"eta/eta_api/models/company"
 	"eta/eta_api/models/report"
+	"eta/eta_api/models/report_approve"
 	"eta/eta_api/models/system"
 	"eta/eta_api/services/alarm_msg"
 	"eta/eta_api/services/public_api"
@@ -46,109 +47,121 @@ func GetReportContentSub(content string) (contentSub string, err error) {
 }
 
 // PublishDayWeekReport 发布晨周报
-func PublishDayWeekReport(reportId int) (tips string, err error) {
-	report, err := models.GetReportByReportId(reportId)
-	if err != nil {
-		return
-	}
-	if report.State == 2 {
+func PublishDayWeekReport(reportInfo *models.Report) (tips string, err error) {
+	reportId := reportInfo.Id
+	if reportInfo.State == 2 {
 		return
 	}
+
+	// 获取所有章节列表
 	chapters, err := models.GetChapterListByReportId(reportId)
 	if err != nil {
 		return
 	}
 	chapterLen := len(chapters)
 	if chapterLen <= 0 {
-		err = errors.New("报告章节为空,不可发布")
+		tips = "报告章节为空,不可发布"
+		err = errors.New(tips)
 		return
 	}
-	reportType := chapters[0].ReportType
-	// 校验章节
-	publishReport, tips, publishIdArr, unPublishIdArr, err := checkDayWeekChapterWrite(chapters, reportType)
+
+	reportChapterIdList := make([]int, 0)
+	// 获取报告中的所有章节列表
+	chapterList, err := models.GetChapterListByReportId(reportId)
 	if err != nil {
 		return
 	}
-	publishLen := len(publishIdArr)
-	if publishLen <= 0 {
-		err = errors.New("报告章节均不可发布")
+	for _, chapter := range chapterList {
+		if chapter.PublishState == 1 {
+			tips = "还存在未发布的章节"
+			err = errors.New(tips)
+			return
+		}
+		reportChapterIdList = append(reportChapterIdList, chapter.ReportChapterId)
+	}
+
+	// 根据审批开关及审批流判断当前报告状态
+	state, e := CheckReportCurrState(report_approve.FlowReportTypeChinese, reportInfo.ClassifyIdFirst, reportInfo.ClassifyIdSecond, reportInfo.ClassifyIdThird, models.ReportOperatePublish)
+	if e != nil {
+		//errMsg = "操作失败"
+		err = errors.New("校验报告当前状态失败, Err: " + e.Error())
+		return
+	}
+
+	// 如果状态不是已发布,那么就重置状态
+	if state != models.ReportStatePublished {
+		// 从无审批切换为有审批, 状态重置
+		if e = models.ResetReportById(reportId, state); e != nil {
+			//errMsg = "操作失败"
+			err = fmt.Errorf("重置报告状态失败, Err: %s, ReportId: %d", e.Error(), reportId)
+			return
+		}
 		return
 	}
 
 	// 需发布整期
 	updateCols := make([]string, 0)
-	if publishReport {
-		updateCols = append(updateCols, "Title", "State", "ModifyTime")
-
-		// 发布后标题调整
-		//title := report.Title
-		//title = strings.ReplaceAll(title, "【弘则FICC晨报】", "")
-		//title = strings.ReplaceAll(title, "【弘则FICC周报】", "")
-		//if title == "" {
-		//	// 取第一个需发布章节的标题
-		//	firstId := publishIdArr[0]
-		//	firstTitle := ""
-		//	for i := 0; i < chapterLen; i++ {
-		//		if chapters[i].ReportChapterId == firstId {
-		//			firstTitle = chapters[i].Title
-		//			break
-		//		}
-		//	}
-		//	title = firstTitle
-		//}
-		//report.Title = title
-		report.State = 2
+	updateCols = append(updateCols, "Title", "State", "ModifyTime")
+
+	// 发布后标题调整
+	//title := report.Title
+	//title = strings.ReplaceAll(title, "【弘则FICC晨报】", "")
+	//title = strings.ReplaceAll(title, "【弘则FICC周报】", "")
+	//if title == "" {
+	//	// 取第一个需发布章节的标题
+	//	firstId := publishIdArr[0]
+	//	firstTitle := ""
+	//	for i := 0; i < chapterLen; i++ {
+	//		if chapters[i].ReportChapterId == firstId {
+	//			firstTitle = chapters[i].Title
+	//			break
+	//		}
+	//	}
+	//	title = firstTitle
+	//}
+	//report.Title = title
+	reportInfo.State = models.ReportStatePublished
 
-		// 研报后台4.4 只在没有发布过时更新发布时间,其余均按模版消息发送时间当作发布时间
-		if report.MsgIsSend == 0 || report.PublishTime.IsZero() {
-			report.PublishTime = time.Now().Local()
-			updateCols = append(updateCols, "PublishTime")
+	// 研报后台4.4 只在没有发布过时更新发布时间,其余均按模版消息发送时间当作发布时间
+	if reportInfo.MsgIsSend == 0 || reportInfo.PublishTime.IsZero() {
+		reportInfo.PublishTime = time.Now().Local()
+		updateCols = append(updateCols, "PublishTime")
 
-		}
-		report.ModifyTime = time.Now().Local()
 	}
-	publishIdStr := utils.IntArr2joinString(publishIdArr, ",")
-	//unPublishIdStr := utils.IntArr2joinString(unPublishIdArr, ",")
+	reportInfo.ModifyTime = time.Now().Local()
 
-	if e := models.PublishReportAndChapter(report, publishIdArr, unPublishIdArr, publishReport, updateCols); e != nil {
+	if e := models.PublishReportAndChapter(reportInfo, true, updateCols); e != nil {
 		err = errors.New("发布报告及章节失败")
 		return
 	}
 	// 生成章节音频
-	go func() {
-		_ = UpdateChaptersVideo(publishIdStr)
-	}()
+	if len(reportChapterIdList) > 0 {
+		go func() {
+			_ = UpdateChaptersVideo(reportChapterIdList)
+		}()
+	}
 	// 更新报告ES
 	go func() {
-		_ = UpdateReportEs(report.Id, 2)
+		_ = UpdateReportEs(reportInfo.Id, 2)
 	}()
 
 	// 发布时备份内容
-	go SaveReportLogs(report, chapters, report.AdminId, report.AdminRealName)
+	go SaveReportLogs(reportInfo, chapters, reportInfo.AdminId, reportInfo.AdminRealName)
 
 	return
 }
 
 // UpdateChaptersVideo 更新章节音频
-func UpdateChaptersVideo(chapterIds string) (err error) {
+func UpdateChaptersVideo(ids []int) (err error) {
 	defer func() {
 		if err != nil {
-			utils.FileLog.Error("UpdateChaptersVideo, chapterIds:%s, Err:%s", chapterIds, err.Error())
-			go alarm_msg.SendAlarmMsg("更新章节音频失败, 章节ID: "+chapterIds+", Err: "+err.Error(), 3)
+			utils.FileLog.Error("UpdateChaptersVideo, chapterIds:%v, Err:%s", ids, err.Error())
+			go alarm_msg.SendAlarmMsg(fmt.Sprintf("更新章节音频失败, 章节ID: %v; Err: "+err.Error(), ids), 3)
 		}
 	}()
-	if chapterIds == "" {
+	if len(ids) <= 0 {
 		return
 	}
-	ids := make([]int, 0)
-	chapterIdArr := strings.Split(chapterIds, ",")
-	for _, v := range chapterIdArr {
-		id, e := strconv.Atoi(v)
-		if e != nil {
-			return
-		}
-		ids = append(ids, id)
-	}
 
 	chapterList, err := models.GetChapterListByChapterIds(ids)
 	if err != nil {
@@ -193,7 +206,7 @@ func PublishTodayDayReport() (err error) {
 		return
 	}
 	if todayReport != nil {
-		if _, tmpErr := PublishDayWeekReport(todayReport.Id); tmpErr != nil {
+		if _, tmpErr := PublishDayWeekReport(todayReport); tmpErr != nil {
 			err = tmpErr
 			return
 		}
@@ -257,6 +270,12 @@ func UpdateReportEs(reportId int, publishState int) (err error) {
 		//}
 	}
 
+	// 最小单位的分类id
+	minClassifyId, minClassifyName, err := getMinClassify(reportInfo)
+	if err != nil {
+		return
+	}
+
 	// 新增报告ES
 	esReport := &models.ElasticReportDetail{
 		ReportId:           reportInfo.Id,
@@ -271,6 +290,8 @@ func UpdateReportEs(reportId int, publishState int) (err error) {
 		ClassifyNameFirst:  reportInfo.ClassifyNameFirst,
 		ClassifyIdSecond:   reportInfo.ClassifyIdSecond,
 		ClassifyNameSecond: reportInfo.ClassifyNameSecond,
+		ClassifyId:         minClassifyId,
+		ClassifyName:       minClassifyName,
 		Categories:         categories,
 		StageStr:           strconv.Itoa(reportInfo.Stage),
 	}
@@ -381,6 +402,8 @@ func updateReportChapterEsByChapter(chapterInfo *models.ReportChapter) (err erro
 		ClassifyNameFirst:  chapterInfo.ClassifyNameFirst,
 		ClassifyIdSecond:   0,
 		ClassifyNameSecond: "",
+		ClassifyId:         chapterInfo.ClassifyIdFirst,
+		ClassifyName:       chapterInfo.ClassifyNameFirst,
 		Categories:         categories,
 		StageStr:           strconv.Itoa(chapterInfo.Stage),
 	}
@@ -542,13 +565,12 @@ func UpdateReportVideo(reportId int) (err error) {
 			err = tmpErr
 			return
 		}
-		chapterIdArr := make([]string, 0)
+		chapterIdArr := make([]int, 0)
 		for i := 0; i < len(chapterList); i++ {
-			chapterIdArr = append(chapterIdArr, strconv.Itoa(chapterList[i].ReportChapterId))
+			chapterIdArr = append(chapterIdArr, chapterList[i].ReportChapterId)
 		}
-		chapterIds := strings.Join(chapterIdArr, ",")
 		//go UpdateChaptersVideo(chapterIds)
-		err = UpdateChaptersVideo(chapterIds)
+		err = UpdateChaptersVideo(chapterIdArr)
 	} else {
 		// 更新报告音频
 		if reportInfo.VideoUrl != "" {

+ 10 - 6
services/report_v2.go

@@ -225,7 +225,7 @@ func EditReport(reportInfo *models.Report, req models.EditReq, sysUser *system.A
 
 	// 报告权限处理
 	{
-		minClassifyId, tmpErr := getMinClassifyId(reportInfo)
+		minClassifyId, _, tmpErr := getMinClassify(reportInfo)
 		if tmpErr != nil {
 			return
 		}
@@ -1040,7 +1040,7 @@ func PublishReport(reportId int, reportUrl string, sysUser *system.Admin) (tips
 
 	// 章节类型的报告(原来的晨周报)
 	if reportInfo.HasChapter == 1 {
-		tips, tmpErr = PublishDayWeekReport(reportId)
+		tips, tmpErr = PublishDayWeekReport(reportInfo)
 		if tmpErr != nil {
 			err = errors.New("晨周报发布失败, Err:" + tmpErr.Error() + ", report_id:" + strconv.Itoa(reportId))
 		}
@@ -1078,7 +1078,7 @@ func PublishReport(reportId int, reportUrl string, sysUser *system.Admin) (tips
 		}()
 	} else {
 		// 从无审批切换为有审批, 状态重置
-		if e = models.ResetReportById(reportId, state); tmpErr != nil {
+		if e = models.ResetReportById(reportId, state); e != nil {
 			errMsg = "操作失败"
 			err = fmt.Errorf("重置报告状态失败, Err: %s, ReportId: %d", e.Error(), reportId)
 			return
@@ -1105,7 +1105,7 @@ func PublishReport(reportId int, reportUrl string, sysUser *system.Admin) (tips
 
 	// 报告权限处理
 	{
-		minClassifyId, tmpErr := getMinClassifyId(reportInfo)
+		minClassifyId, _, tmpErr := getMinClassify(reportInfo)
 		if tmpErr != nil {
 			return
 		}
@@ -1115,25 +1115,29 @@ func PublishReport(reportId int, reportUrl string, sysUser *system.Admin) (tips
 	return
 }
 
-// getMinClassifyId
+// 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 getMinClassifyId(reportInfo *models.Report) (minClassifyId int, 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("分类异常")

+ 1 - 1
services/wechat_send_msg.go

@@ -69,7 +69,7 @@ func SendMiniProgramReportWxMsg(reportId int) (err error) {
 			return
 		}
 	} else {
-		minClassifyId, err := getMinClassifyId(report)
+		minClassifyId, _, err := getMinClassify(report)
 		if err != nil {
 			msg = "获取报告的最小分类失败 err:" + err.Error()
 			return err