|
@@ -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 != "" {
|