|
@@ -3,6 +3,7 @@ package services
|
|
|
import (
|
|
|
"errors"
|
|
|
"eta/eta_task/models"
|
|
|
+ "eta/eta_task/models/report"
|
|
|
"eta/eta_task/services/alarm_msg"
|
|
|
"eta/eta_task/utils"
|
|
|
"fmt"
|
|
@@ -30,45 +31,17 @@ func UpdateReportEs(reportId int, publishState int) (err error) {
|
|
|
return
|
|
|
}
|
|
|
if len(chapterList) > 0 {
|
|
|
- for i := 0; i < len(chapterList); i++ {
|
|
|
- // 章节对应的品种
|
|
|
- permissionList, tmpErr := models.GetChapterTypePermissionByTypeIdAndResearchType(chapterList[i].TypeId, chapterList[i].ReportType)
|
|
|
- if tmpErr != nil {
|
|
|
- return
|
|
|
- }
|
|
|
- categoryArr := make([]string, 0)
|
|
|
- if len(permissionList) > 0 {
|
|
|
- for ii := 0; ii < len(permissionList); ii++ {
|
|
|
- categoryArr = append(categoryArr, permissionList[ii].PermissionName)
|
|
|
- }
|
|
|
- }
|
|
|
- aliasArr, _ := addCategoryAliasToArr(categoryArr)
|
|
|
- chapterCategories := strings.Join(aliasArr, ",")
|
|
|
-
|
|
|
- esChapter := &models.ElasticReportDetail{
|
|
|
- ReportId: chapterList[i].ReportId,
|
|
|
- ReportChapterId: chapterList[i].ReportChapterId,
|
|
|
- Title: chapterList[i].Title,
|
|
|
- Abstract: chapterList[i].Abstract,
|
|
|
- BodyContent: utils.TrimHtml(html.UnescapeString(chapterList[i].Content)),
|
|
|
- PublishTime: chapterList[i].PublishTime.Format(utils.FormatDateTime),
|
|
|
- PublishState: chapterList[i].PublishState,
|
|
|
- Author: chapterList[i].Author,
|
|
|
- ClassifyIdFirst: chapterList[i].ClassifyIdFirst,
|
|
|
- ClassifyNameFirst: chapterList[i].ClassifyNameFirst,
|
|
|
- ClassifyIdSecond: 0,
|
|
|
- ClassifyNameSecond: "",
|
|
|
- Categories: chapterCategories,
|
|
|
- StageStr: strconv.Itoa(chapterList[i].Stage),
|
|
|
- }
|
|
|
- chapterDocId := fmt.Sprintf("%d-%d", reportInfo.Id, chapterList[i].ReportChapterId)
|
|
|
- if err = EsAddOrEditReport(utils.EsReportIndexName, chapterDocId, esChapter); err != nil {
|
|
|
+ // 更新章节的es数据
|
|
|
+ for _, chapterInfo := range chapterList {
|
|
|
+ err = updateReportChapterEsByChapter(chapterInfo)
|
|
|
+ if err != nil {
|
|
|
return
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
} else {
|
|
|
- permissionList, tmpErr := models.GetChartPermissionNameFromMappingByKeyword(reportInfo.ClassifyNameSecond, "rddp")
|
|
|
+ //if utils.BusinessCode == utils.BusinessCodeRelease || utils.BusinessCode == utils.BusinessCodeSandbox {
|
|
|
+ permissionList, tmpErr := models.GetChartPermissionNameFromMappingByKeyword("rddp", reportInfo.ClassifyIdSecond)
|
|
|
if tmpErr != nil {
|
|
|
return
|
|
|
}
|
|
@@ -78,6 +51,13 @@ func UpdateReportEs(reportId int, publishState int) (err error) {
|
|
|
}
|
|
|
aliasArr, _ := addCategoryAliasToArr(categoryArr)
|
|
|
categories = strings.Join(aliasArr, ",")
|
|
|
+ //}
|
|
|
+ }
|
|
|
+
|
|
|
+ // 最小单位的分类id
|
|
|
+ minClassifyId, minClassifyName, err := getMinClassify(reportInfo)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
}
|
|
|
|
|
|
// 新增报告ES
|
|
@@ -94,6 +74,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),
|
|
|
}
|
|
@@ -139,8 +121,58 @@ func addCategoryAliasToArr(categoryArr []string) (aliasArr []string, err error)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
+// updateReportChapterEsByChapter
|
|
|
+// @Description: 通过章节详情更新报告章节ES
|
|
|
+// @author: Roc
|
|
|
+// @datetime 2024-06-20 13:16:11
|
|
|
+// @param chapterInfo *models.ReportChapter
|
|
|
+// @return err error
|
|
|
+func updateReportChapterEsByChapter(chapterInfo *models.ReportChapter) (err error) {
|
|
|
+ // 章节对应的品种
|
|
|
+ obj := report.ReportChapterPermissionMapping{}
|
|
|
+ permissionList, tmpErr := obj.GetPermissionItemListById(chapterInfo.ReportChapterId)
|
|
|
+ if tmpErr != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ categoryArr := make([]string, 0)
|
|
|
+ if len(permissionList) > 0 {
|
|
|
+ for ii := 0; ii < len(permissionList); ii++ {
|
|
|
+ categoryArr = append(categoryArr, permissionList[ii].ChartPermissionName)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ aliasArr, _ := addCategoryAliasToArr(categoryArr)
|
|
|
+ categories := strings.Join(aliasArr, ",")
|
|
|
+ // 新增/编辑ES
|
|
|
+
|
|
|
+ esChapter := &models.ElasticReportDetail{
|
|
|
+ ReportId: chapterInfo.ReportId,
|
|
|
+ ReportChapterId: chapterInfo.ReportChapterId,
|
|
|
+ Title: chapterInfo.Title,
|
|
|
+ Abstract: chapterInfo.Abstract,
|
|
|
+ BodyContent: utils.TrimHtml(html.UnescapeString(chapterInfo.Content)),
|
|
|
+ PublishTime: chapterInfo.PublishTime.Format(utils.FormatDateTime),
|
|
|
+ PublishState: chapterInfo.PublishState,
|
|
|
+ Author: chapterInfo.Author,
|
|
|
+ ClassifyIdFirst: chapterInfo.ClassifyIdFirst,
|
|
|
+ ClassifyNameFirst: chapterInfo.ClassifyNameFirst,
|
|
|
+ ClassifyIdSecond: 0,
|
|
|
+ ClassifyNameSecond: "",
|
|
|
+ ClassifyId: chapterInfo.ClassifyIdFirst,
|
|
|
+ ClassifyName: chapterInfo.ClassifyNameFirst,
|
|
|
+ Categories: categories,
|
|
|
+ StageStr: strconv.Itoa(chapterInfo.Stage),
|
|
|
+ }
|
|
|
+ chapterDocId := fmt.Sprintf("%d-%d", chapterInfo.ReportId, chapterInfo.ReportChapterId)
|
|
|
+ if err = EsAddOrEditReport(utils.EsReportIndexName, chapterDocId, esChapter); err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
// PublishReport 定时发布研报-每秒
|
|
|
func PublishReport(cont context.Context) (err error) {
|
|
|
+ errMsgList := make([]string, 0)
|
|
|
defer func() {
|
|
|
if err != nil {
|
|
|
go alarm_msg.SendAlarmMsg("PublishReport-定时发布研报失败, ErrMsg:\n"+err.Error(), 3)
|
|
@@ -168,44 +200,75 @@ func PublishReport(cont context.Context) (err error) {
|
|
|
} else {
|
|
|
publishTime = time.Now()
|
|
|
}
|
|
|
- if item.HasChapter == 1 && (item.ChapterType == utils.REPORT_TYPE_DAY || item.ChapterType == utils.REPORT_TYPE_WEEK) {
|
|
|
- continue
|
|
|
+ //if item.HasChapter == 1 && (item.ChapterType == utils.REPORT_TYPE_DAY || item.ChapterType == utils.REPORT_TYPE_WEEK) {
|
|
|
+ // continue
|
|
|
+ //}
|
|
|
+
|
|
|
+ var tmpErr error
|
|
|
+ if item.HasChapter == 1 { // 章节类型的报告
|
|
|
+ // 发布报告和章节
|
|
|
+ item.State = 2
|
|
|
+ item.PublishTime = publishTime
|
|
|
+ item.ModifyTime = time.Now().Local()
|
|
|
+ updateCols := make([]string, 0)
|
|
|
+ updateCols = append(updateCols, "PublishTime", "State", "ModifyTime")
|
|
|
+ tmpErr = models.PublishReportAndChapter(item, true, updateCols)
|
|
|
+ } else {
|
|
|
+ tmpErr = models.PublishReportById(item.Id, publishTime)
|
|
|
}
|
|
|
- if err = models.PublishReportById(item.Id, publishTime); err != nil {
|
|
|
- return
|
|
|
+ if tmpErr != nil {
|
|
|
+ errMsgList = append(errMsgList, fmt.Sprint("报告发布失败,ID:", item.Id, ",ErrMsg:", tmpErr.Error()))
|
|
|
+ } else {
|
|
|
+ go handleByPublishReport(item)
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- go func() {
|
|
|
- // 生成音频
|
|
|
- if item.VideoUrl == "" {
|
|
|
- _ = CreateVideo(item)
|
|
|
- }
|
|
|
- //// 推送找钢网
|
|
|
- //if utils.RunMode == "release" && (report.ClassifyNameSecond == "知白守黑日评" || report.ClassifyNameSecond == "股债日评") {
|
|
|
- // _ = services.ZhaoGangSend(report)
|
|
|
- //}
|
|
|
- // 更新报告Es
|
|
|
- _ = UpdateReportEs(item.Id, 2)
|
|
|
-
|
|
|
- // 判断是否未发送模版消息,并且配置了立即推送模版消息的报告需要推送
|
|
|
- if utils.SendWxTemplateEnable == "1" {
|
|
|
- if item.MsgIsSend == 0 && item.PreMsgSend == 1 {
|
|
|
- _ = ReportSendTemplateMsg(item.Id)
|
|
|
- }
|
|
|
- }
|
|
|
- }()
|
|
|
- recordItem := &models.ReportStateRecord{
|
|
|
- ReportId: item.Id,
|
|
|
- ReportType: 1,
|
|
|
- State: 2,
|
|
|
- AdminId: item.AdminId,
|
|
|
- AdminName: item.AdminName,
|
|
|
- CreateTime: time.Now(),
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+// handleByPublishReport
|
|
|
+// @Description: 报告发布
|
|
|
+// @author: Roc
|
|
|
+// @datetime 2024-06-28 13:26:51
|
|
|
+// @param item *models.Report
|
|
|
+// @param publishTime time.Time
|
|
|
+// @return err error
|
|
|
+func handleByPublishReport(item *models.Report) {
|
|
|
+ recordItem := &models.ReportStateRecord{
|
|
|
+ ReportId: item.Id,
|
|
|
+ ReportType: 1,
|
|
|
+ State: 2,
|
|
|
+ AdminId: item.AdminId,
|
|
|
+ AdminName: item.AdminName,
|
|
|
+ CreateTime: time.Now(),
|
|
|
+ }
|
|
|
+
|
|
|
+ // 添加记录
|
|
|
+ _, _ = models.AddReportStateRecord(recordItem)
|
|
|
+
|
|
|
+ if item.HasChapter == 1 {
|
|
|
+ // 生产报告章节音频
|
|
|
+ _ = UpdateChaptersVideoByReportId(item.Id)
|
|
|
+ } else {
|
|
|
+ // 生成音频
|
|
|
+ if item.VideoUrl == "" {
|
|
|
+ _ = CreateVideo(item)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 更新报告Es
|
|
|
+ err := UpdateReportEs(item.Id, 2)
|
|
|
+ if err != nil {
|
|
|
+ utils.FileLog.Error("UpdateReportEs, 更新报告Es失败, ReportId:%s, Err:%s", item.Id, err.Error())
|
|
|
+ }
|
|
|
+
|
|
|
+ // 判断是否未发送模版消息,并且配置了立即推送模版消息的报告需要推送
|
|
|
+ if utils.SendWxTemplateEnable == "1" {
|
|
|
+ if item.MsgIsSend == 0 && item.PreMsgSend == 1 {
|
|
|
+ _ = ReportSendTemplateMsg(item.Id)
|
|
|
}
|
|
|
- go func() {
|
|
|
- _, _ = models.AddReportStateRecord(recordItem)
|
|
|
- }()
|
|
|
}
|
|
|
+
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -239,12 +302,12 @@ func ReportSendTemplateMsg(reportId int) (err error) {
|
|
|
}
|
|
|
}()
|
|
|
|
|
|
- report, err := models.GetReportById(reportId)
|
|
|
+ reportInfo, err := models.GetReportByReportId(reportId)
|
|
|
if err != nil {
|
|
|
err = errors.New("查询报告失败 Err:" + err.Error())
|
|
|
return
|
|
|
}
|
|
|
- if report.MsgIsSend == 1 {
|
|
|
+ if reportInfo.MsgIsSend == 1 {
|
|
|
err = errors.New("模板消息已推送,请勿重复操作")
|
|
|
return
|
|
|
}
|
|
@@ -255,7 +318,7 @@ func ReportSendTemplateMsg(reportId int) (err error) {
|
|
|
err = errors.New("修改发布时间失败,Err:" + err.Error())
|
|
|
return
|
|
|
}
|
|
|
- if report.HasChapter > 0 {
|
|
|
+ if reportInfo.HasChapter > 0 {
|
|
|
err = models.UpdateReportChapterPublishTime(reportId, videoNameDate)
|
|
|
if err != nil {
|
|
|
err = errors.New("修改发布时间失败,Err:" + err.Error())
|
|
@@ -263,7 +326,7 @@ func ReportSendTemplateMsg(reportId int) (err error) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- err = sendMiniProgramReportWxMsg(report)
|
|
|
+ err = sendMiniProgramReportWxMsg(reportInfo)
|
|
|
if err != nil {
|
|
|
err = errors.New("发送失败,Err:" + err.Error())
|
|
|
return
|
|
@@ -277,7 +340,7 @@ func ReportSendTemplateMsg(reportId int) (err error) {
|
|
|
}
|
|
|
|
|
|
// sendMiniProgramReportWxMsg 推送报告微信模板消息-小程序链接
|
|
|
-func sendMiniProgramReportWxMsg(report *models.ReportDetail) (err error) {
|
|
|
+func sendMiniProgramReportWxMsg(report *models.Report) (err error) {
|
|
|
reportId := report.Id
|
|
|
var msg string
|
|
|
reportIdStr := strconv.Itoa(reportId)
|
|
@@ -297,33 +360,36 @@ func sendMiniProgramReportWxMsg(report *models.ReportDetail) (err error) {
|
|
|
}
|
|
|
|
|
|
var openIdArr []string
|
|
|
- if report.ClassifyIdSecond <= 0 {
|
|
|
+ // 如果是弘则,且报告分类是晨报,那么就所有人推送
|
|
|
+ if (utils.BusinessCode == utils.BusinessCodeRelease || utils.BusinessCode == utils.BusinessCodeSandbox || utils.BusinessCode == utils.BusinessCodeDebug) && report.ClassifyNameFirst == "晨报" {
|
|
|
+ // 如果是章节,那就推送所有用户
|
|
|
openIdArr, err = models.GetOpenIdArr()
|
|
|
if err != nil {
|
|
|
msg = "get GetOpenIdArr err:" + err.Error()
|
|
|
return
|
|
|
}
|
|
|
} else {
|
|
|
- classify, err := models.GetClassifyById(report.ClassifyIdSecond)
|
|
|
+ minClassifyId, _, err := getMinClassify(report)
|
|
|
+ if err != nil {
|
|
|
+ msg = "获取报告的最小分类失败 err:" + err.Error()
|
|
|
+ return err
|
|
|
+ }
|
|
|
+
|
|
|
+ // 判断分类是否存在
|
|
|
+ _, err = models.GetClassifyById(minClassifyId)
|
|
|
if err != nil {
|
|
|
msg = "获取报告分类失败 err:" + err.Error()
|
|
|
return err
|
|
|
}
|
|
|
- if classify.IsMassSend == 1 {
|
|
|
- openIdArr, err = models.GetOpenIdArr()
|
|
|
- if err != nil {
|
|
|
- msg = "get GetOpenIdArr err:" + err.Error()
|
|
|
- return err
|
|
|
- }
|
|
|
- } else {
|
|
|
- openIdArr, err = models.GetOpenIdArrByClassifyNameSecond(report.ClassifyNameSecond)
|
|
|
- if err != nil {
|
|
|
- msg = "GetOpenIdArrByClassifyNameSecond err:" + err.Error()
|
|
|
- return err
|
|
|
- }
|
|
|
+ // 获取该分类关联的openid列表
|
|
|
+ openIdArr, err = models.GetOpenIdArrByClassifyId(minClassifyId)
|
|
|
+ if err != nil {
|
|
|
+ msg = "GetOpenIdArrByClassifyNameSecond err:" + err.Error()
|
|
|
+ return err
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ // TODO 弘则的文案是不是要去掉
|
|
|
title := fmt.Sprintf("弘则%s", report.ClassifyNameFirst)
|
|
|
if CheckTwoWeekOrMonthReport(report.ClassifyIdFirst, report.ClassifyNameFirst) {
|
|
|
title = fmt.Sprintf("弘则%s", report.ClassifyNameSecond)
|
|
@@ -332,7 +398,7 @@ func sendMiniProgramReportWxMsg(report *models.ReportDetail) (err error) {
|
|
|
first := fmt.Sprintf("Hi,最新一期%s已上线,欢迎查看", report.ClassifyNameFirst)
|
|
|
keyword1 := title
|
|
|
keyword2 := report.Title
|
|
|
- keyword3 := report.PublishTime
|
|
|
+ keyword3 := report.PublishTime.Format(utils.FormatDateTime)
|
|
|
keyword4 := report.Abstract
|
|
|
|
|
|
var wxAppPath string
|
|
@@ -397,3 +463,78 @@ func ClearReportSaveLog(cont context.Context) (err error) {
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
+
|
|
|
+// UpdateChaptersVideoByReportId
|
|
|
+// @Description: 更新报告章节音频
|
|
|
+// @author: Roc
|
|
|
+// @datetime 2024-06-28 13:52:56
|
|
|
+// @param reportId int
|
|
|
+// @return err error
|
|
|
+func UpdateChaptersVideoByReportId(reportId int) (err error) {
|
|
|
+ defer func() {
|
|
|
+ if err != nil {
|
|
|
+ utils.FileLog.Error("UpdateChaptersVideo, reportId:%v, Err:%s", reportId, err.Error())
|
|
|
+ go alarm_msg.SendAlarmMsg(fmt.Sprintf("更新章节音频失败, 报告ID: %v; Err: "+err.Error(), reportId), 3)
|
|
|
+ }
|
|
|
+ }()
|
|
|
+ chapterList, err := models.GetChapterListByReportId(reportId)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ // 生成video
|
|
|
+ nowTime := time.Now()
|
|
|
+ updateCols := make([]string, 0)
|
|
|
+ updateCols = append(updateCols, "VideoUrl", "VideoName", "VideoSize", "VideoPlaySeconds")
|
|
|
+ for i := 0; i < len(chapterList); i++ {
|
|
|
+ item := chapterList[i]
|
|
|
+ // 忽略已有音频的章节
|
|
|
+ if item.VideoUrl != "" && item.VideoName != "" && item.VideoSize != "" && item.VideoPlaySeconds != "" {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ videoUrl, videoName, videoSize, videoPlaySeconds, e := CreateReportVideo(item.Title, html.UnescapeString(item.Content), nowTime.Format(utils.FormatDateTime))
|
|
|
+ if e != nil {
|
|
|
+ err = e
|
|
|
+ return
|
|
|
+ }
|
|
|
+ item.VideoUrl = videoUrl
|
|
|
+ item.VideoName = videoName
|
|
|
+ item.VideoSize = videoSize
|
|
|
+ item.VideoPlaySeconds = fmt.Sprintf("%.2f", videoPlaySeconds)
|
|
|
+ if e = item.UpdateChapter(updateCols); e != nil {
|
|
|
+ err = e
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ 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
|
|
|
+}
|