|
@@ -566,329 +566,6 @@ func UpdatePublishedReportToEs() (err error) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-// MigrateOldReport 迁移今年旧数据
|
|
|
-func MigrateOldReport() (err error) {
|
|
|
- // 查询本年度报告
|
|
|
- // 20220616查询本年度周报
|
|
|
- reportList, err := models.GetMigrateReportList()
|
|
|
- if err != nil {
|
|
|
- fmt.Println("获取今年报告失败, Err: " + err.Error())
|
|
|
- return
|
|
|
- }
|
|
|
- lenReport := len(reportList)
|
|
|
-
|
|
|
- frequencyMap := map[string]string{
|
|
|
- "day": "日度",
|
|
|
- "week": "周度",
|
|
|
- "two_week": "双周度",
|
|
|
- "month": "月度",
|
|
|
- "other": "不定时",
|
|
|
- }
|
|
|
- classifyList, err := models.GetAllClassify()
|
|
|
- if err != nil {
|
|
|
- fmt.Println("获取分类失败, Err: " + err.Error())
|
|
|
- return
|
|
|
- }
|
|
|
- classifyIdName := make(map[int]string, 0)
|
|
|
- classifyNameId := make(map[string]int, 0)
|
|
|
- classifyIdParentId := make(map[int]int, 0)
|
|
|
- for i := 0; i < len(classifyList); i++ {
|
|
|
- classifyIdName[classifyList[i].Id] = classifyList[i].ClassifyName
|
|
|
- classifyNameId[classifyList[i].ClassifyName] = classifyList[i].Id
|
|
|
- classifyIdParentId[classifyList[i].Id] = classifyList[i].ParentId
|
|
|
- }
|
|
|
- typeList, err := models.GetReportChapterTypeList()
|
|
|
- if err != nil {
|
|
|
- fmt.Println("获取章节类型失败, Err: " + err.Error())
|
|
|
- return
|
|
|
- }
|
|
|
- typeIdName := make(map[int]string, 0)
|
|
|
- typeIdSort := make(map[int]int, 0)
|
|
|
- for i := 0; i < len(typeList); i++ {
|
|
|
- typeIdName[typeList[i].ReportChapterTypeId] = typeList[i].ReportChapterTypeName
|
|
|
- typeIdSort[typeList[i].ReportChapterTypeId] = typeList[i].Sort
|
|
|
- }
|
|
|
-
|
|
|
- // 报告ID集合
|
|
|
- idArr := make([]string, 0)
|
|
|
- for i := 0; i < lenReport; i++ {
|
|
|
- idArr = append(idArr, strconv.Itoa(reportList[i].ResearchReportId))
|
|
|
- }
|
|
|
- idStr := strings.Join(idArr, ",")
|
|
|
-
|
|
|
- // 获取报告章节
|
|
|
- reportTypeList, err := models.GetResearchReportTypeListByReportIds(idStr)
|
|
|
- if err != nil {
|
|
|
- fmt.Println("获取报告章节失败, Err: " + err.Error())
|
|
|
- return
|
|
|
- }
|
|
|
- // 获取非晨周报权限mapping
|
|
|
- reportPermissionList, err := models.GetChapterPermissionMappingByResearchReportIds(idStr)
|
|
|
- if err != nil {
|
|
|
- fmt.Println("获取报告权限失败, Err: " + err.Error())
|
|
|
- return
|
|
|
- }
|
|
|
- reportTypeListMap := make(map[int][]*models.ResearchReportType, 0)
|
|
|
- reportPermissionListMap := make(map[int][]*models.ChartPermissionChapterMapping, 0)
|
|
|
- for i := 0; i < lenReport; i++ {
|
|
|
- // 报告章节map
|
|
|
- rid := reportList[i].ResearchReportId
|
|
|
- reportTypeMap := make([]*models.ResearchReportType, 0)
|
|
|
- for ii := 0; ii < len(reportTypeList); ii++ {
|
|
|
- if rid == reportTypeList[ii].ResearchReportId {
|
|
|
- reportTypeMap = append(reportTypeMap, reportTypeList[ii])
|
|
|
- }
|
|
|
- }
|
|
|
- reportTypeListMap[rid] = reportTypeMap
|
|
|
- // 报告权限map
|
|
|
- reportPermissionMap := make([]*models.ChartPermissionChapterMapping, 0)
|
|
|
- for iii := 0; iii < len(reportPermissionList); iii++ {
|
|
|
- if rid == reportPermissionList[iii].ReportChapterTypeId {
|
|
|
- reportPermissionMap = append(reportPermissionMap, reportPermissionList[iii])
|
|
|
- }
|
|
|
- }
|
|
|
- reportPermissionListMap[rid] = reportPermissionMap
|
|
|
- }
|
|
|
-
|
|
|
- // 获取章节内容
|
|
|
- typeIdArr := make([]string, 0)
|
|
|
- for i := 0; i < len(reportTypeList); i++ {
|
|
|
- typeIdArr = append(typeIdArr, strconv.Itoa(reportTypeList[i].ResearchReportTypeId))
|
|
|
- }
|
|
|
- typeIdStr := strings.Join(typeIdArr, ",")
|
|
|
- reportContentList, err := models.GetResearchReportTypeContentListByReportTypeIds(typeIdStr)
|
|
|
- if err != nil {
|
|
|
- fmt.Println("获取报告内容失败, Err: " + err.Error())
|
|
|
- return
|
|
|
- }
|
|
|
- // 获取章节ticker
|
|
|
- reportTickerList, err := models.GetResearchReportTypeTickerListByReportTypeIds(typeIdStr)
|
|
|
- if err != nil {
|
|
|
- fmt.Println("获取报告ticker失败, Err: " + err.Error())
|
|
|
- return
|
|
|
- }
|
|
|
- reportContentListMap := make(map[int][]*models.ResearchReportTypeContent, 0)
|
|
|
- reportTickerListMap := make(map[int][]*models.ResearchReportTypeTicker, 0)
|
|
|
- for i := 0; i < len(reportTypeList); i++ {
|
|
|
- // 报告章节map
|
|
|
- rtid := reportTypeList[i].ResearchReportTypeId
|
|
|
- reportContentMap := make([]*models.ResearchReportTypeContent, 0)
|
|
|
- for ii := 0; ii < len(reportContentList); ii++ {
|
|
|
- if rtid == reportContentList[ii].ResearchReportTypeId {
|
|
|
- reportContentMap = append(reportContentMap, reportContentList[ii])
|
|
|
- }
|
|
|
- }
|
|
|
- reportContentListMap[rtid] = reportContentMap
|
|
|
- // 报告ticker
|
|
|
- reportTickerMap := make([]*models.ResearchReportTypeTicker, 0)
|
|
|
- for iii := 0; iii < len(reportTickerList); iii++ {
|
|
|
- if rtid == reportTickerList[iii].ResearchReportTypeId {
|
|
|
- reportTickerMap = append(reportTickerMap, reportTickerList[iii])
|
|
|
- }
|
|
|
- }
|
|
|
- reportTickerListMap[rtid] = reportTickerMap
|
|
|
- }
|
|
|
-
|
|
|
- fmt.Printf("开始写入, 总数:%d\n", lenReport)
|
|
|
- countSuccess := 0
|
|
|
- countIgnore := 0
|
|
|
- for i := 0; i < lenReport; i++ {
|
|
|
- fmt.Printf("正在写入报告:%d\n", reportList[i].ResearchReportId)
|
|
|
- // 报告去重
|
|
|
- exist, tmpErr := models.GetNewReportExist(reportList[i].ResearchReportId)
|
|
|
- if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
|
|
|
- fmt.Println("查询是否迁移过该报告失败: ", reportList[i].ResearchReportId)
|
|
|
- return
|
|
|
- }
|
|
|
- if exist != nil {
|
|
|
- countIgnore += 1
|
|
|
- fmt.Println("跳过报告: ", reportList[i].ResearchReportId)
|
|
|
- continue
|
|
|
- }
|
|
|
-
|
|
|
- newReportId := 0
|
|
|
- item := reportList[i]
|
|
|
- reportTypeList = reportTypeListMap[item.ResearchReportId]
|
|
|
- isIgnore := false
|
|
|
- // 报告内容、章节
|
|
|
- if len(reportTypeList) > 0 {
|
|
|
- newReport := new(models.Report)
|
|
|
- newReport.AddType = 1
|
|
|
- // 标题去掉【】
|
|
|
- re, _ := regexp.Compile("^【[^】]*】")
|
|
|
- newTitle := re.ReplaceAllString(item.ResearchReportName, "")
|
|
|
- prefix := ""
|
|
|
- newReport.Title = prefix + newTitle
|
|
|
- newReport.Author = item.Author
|
|
|
- newReport.Frequency = frequencyMap[item.Type]
|
|
|
- newReport.CreateTime = item.CreatedTime
|
|
|
- modifyTime, _ := time.ParseInLocation(utils.FormatDateTime, item.CreatedTime, time.Local)
|
|
|
- newReport.ModifyTime = modifyTime
|
|
|
- newReport.State = 2
|
|
|
- newReport.PublishTime = item.ResearchReportDate
|
|
|
- newReport.Stage = item.Periods
|
|
|
- newReport.MsgIsSend = 1
|
|
|
- newReport.ThsMsgIsSend = 1
|
|
|
- newReport.ReportVersion = 1
|
|
|
- newReport.OldReportId = item.ResearchReportId
|
|
|
-
|
|
|
- if item.Type == utils.REPORT_TYPE_DAY || item.Type == utils.REPORT_TYPE_WEEK {
|
|
|
- // 晨周报
|
|
|
- newReport.HasChapter = 1
|
|
|
- newReport.ChapterType = item.Type
|
|
|
- classifyIdFirst := 0
|
|
|
- classifyNameFirst := ""
|
|
|
- if item.Type == utils.REPORT_TYPE_DAY {
|
|
|
- newReport.ClassifyIdFirst = classifyNameId["晨报"]
|
|
|
- newReport.ClassifyNameFirst = "晨报"
|
|
|
- classifyIdFirst = classifyNameId["晨报"]
|
|
|
- classifyNameFirst = "晨报"
|
|
|
- } else {
|
|
|
- newReport.ClassifyIdFirst = classifyNameId["周报"]
|
|
|
- newReport.ClassifyNameFirst = "周报"
|
|
|
- classifyIdFirst = classifyNameId["周报"]
|
|
|
- classifyNameFirst = "周报"
|
|
|
- }
|
|
|
-
|
|
|
- newDayWeekReport := new(models.CreateDayWeekReport)
|
|
|
- newChapterList := make([]*models.CreateDayWeekReportChapter, 0)
|
|
|
- for _, chapter := range reportTypeList {
|
|
|
- chapterAndTicker := new(models.CreateDayWeekReportChapter)
|
|
|
- tmpTickerList := make([]*models.ReportChapterTicker, 0)
|
|
|
- chapterContents := ""
|
|
|
- // 章节内容列表
|
|
|
- contentList := reportContentListMap[chapter.ResearchReportTypeId]
|
|
|
- for _, contents := range contentList {
|
|
|
- chapterContents += contents.Content
|
|
|
- }
|
|
|
- chapterContents, tmpErr := replaceReportBase64ToImg(chapterContents)
|
|
|
- if tmpErr != nil {
|
|
|
- fmt.Println("转换章节base64图片失败, Err: " + tmpErr.Error())
|
|
|
- return
|
|
|
- }
|
|
|
- state := 2
|
|
|
- if chapterContents == "" {
|
|
|
- state = 1
|
|
|
- }
|
|
|
- contentSub, tmpErr := GetReportContentSub(chapterContents)
|
|
|
- if tmpErr != nil {
|
|
|
- fmt.Println("解析 ContentSub 失败, Err: " + tmpErr.Error())
|
|
|
- return
|
|
|
- }
|
|
|
- chapterContents = html.EscapeString(chapterContents)
|
|
|
- contentSub = html.EscapeString(contentSub)
|
|
|
-
|
|
|
- chapterAndTicker.Chapter = &models.ReportChapter{
|
|
|
- ReportType: item.Type,
|
|
|
- ClassifyIdFirst: classifyIdFirst,
|
|
|
- ClassifyNameFirst: classifyNameFirst,
|
|
|
- TypeId: chapter.TypeId,
|
|
|
- TypeName: typeIdName[chapter.TypeId],
|
|
|
- Sort: typeIdSort[chapter.TypeId],
|
|
|
- Title: chapter.ResearchReportTypeTitle,
|
|
|
- AddType: 1,
|
|
|
- Author: item.Author,
|
|
|
- Content: chapterContents,
|
|
|
- ContentSub: contentSub,
|
|
|
- Stage: item.Periods,
|
|
|
- Trend: chapter.Trend,
|
|
|
- IsEdit: 1,
|
|
|
- PublishState: state,
|
|
|
- PublishTime: chapter.LastUpdatedTime,
|
|
|
- CreateTime: chapter.CreatedTime,
|
|
|
- ModifyTime: chapter.LastUpdatedTime,
|
|
|
- }
|
|
|
- // 晨报数据指标
|
|
|
- if item.Type == utils.REPORT_TYPE_DAY {
|
|
|
- tickerList := reportTickerListMap[chapter.ResearchReportTypeId]
|
|
|
- for _, ticker := range tickerList {
|
|
|
- tmpTickerList = append(tmpTickerList, &models.ReportChapterTicker{
|
|
|
- Sort: ticker.Sort,
|
|
|
- Ticker: ticker.Ticker,
|
|
|
- CreateTime: ticker.CreatedTime,
|
|
|
- UpdateTime: ticker.LastUpdatedTime,
|
|
|
- })
|
|
|
- }
|
|
|
- }
|
|
|
- chapterAndTicker.TickerList = tmpTickerList
|
|
|
- newChapterList = append(newChapterList, chapterAndTicker)
|
|
|
- }
|
|
|
-
|
|
|
- newDayWeekReport.Report = newReport
|
|
|
- newDayWeekReport.ChapterList = newChapterList
|
|
|
- // 新增晨周报
|
|
|
- newId, newErr := models.CreateMigrateNewDayWeekReport(newDayWeekReport)
|
|
|
- if newErr != nil {
|
|
|
- fmt.Println("新增晨周报失败, Err: " + newErr.Error())
|
|
|
- return
|
|
|
- }
|
|
|
- newReportId = newId
|
|
|
- } else {
|
|
|
- // 非晨周报
|
|
|
- if item.ReportVariety == "铁矿库存点评" {
|
|
|
- item.ReportVariety = "铁矿库存数据点评"
|
|
|
- }
|
|
|
- //newReport.Abstract = newTitle
|
|
|
- newReport.ClassifyIdSecond = classifyNameId[item.ReportVariety]
|
|
|
- newReport.ClassifyNameSecond = item.ReportVariety
|
|
|
- newReport.ClassifyIdFirst = classifyIdParentId[newReport.ClassifyIdSecond]
|
|
|
- newReport.ClassifyNameFirst = classifyIdName[newReport.ClassifyIdFirst]
|
|
|
- // 忽略分类不完整的
|
|
|
- if newReport.ClassifyIdFirst == 0 || newReport.ClassifyIdSecond == 0 || newReport.ClassifyNameFirst == "" || newReport.ClassifyNameSecond == "" {
|
|
|
- isIgnore = true
|
|
|
- countIgnore += 1
|
|
|
- continue
|
|
|
- }
|
|
|
-
|
|
|
- reportContents := ""
|
|
|
- for _, chapter := range reportTypeList {
|
|
|
- // 章节内容列表
|
|
|
- contentList := reportContentListMap[chapter.ResearchReportTypeId]
|
|
|
- for _, contents := range contentList {
|
|
|
- reportContents += contents.Content
|
|
|
- }
|
|
|
- }
|
|
|
- reportContents, tmpErr := replaceReportBase64ToImg(reportContents)
|
|
|
- if tmpErr != nil {
|
|
|
- fmt.Println("转换报告base64图片失败, Err: " + tmpErr.Error())
|
|
|
- return
|
|
|
- }
|
|
|
- newReport.State = 2
|
|
|
- if reportContents == "" {
|
|
|
- newReport.State = 1
|
|
|
- }
|
|
|
- reportContentSub, tmpErr := GetReportContentSub(reportContents)
|
|
|
- if tmpErr != nil {
|
|
|
- fmt.Println("解析 ContentSub 失败, Err: " + tmpErr.Error())
|
|
|
- return
|
|
|
- }
|
|
|
- newReport.Content = html.EscapeString(reportContents)
|
|
|
- newReport.ContentSub = html.EscapeString(reportContentSub)
|
|
|
-
|
|
|
- // 报告权限列表
|
|
|
- oldMapping := reportPermissionListMap[item.ResearchReportId]
|
|
|
- // 新增非晨周报
|
|
|
- newId, newErr := models.CreateMigrateNewOtherReport(newReport, oldMapping)
|
|
|
- if newErr != nil {
|
|
|
- fmt.Println("新增非晨周报失败, Err: " + newErr.Error())
|
|
|
- return
|
|
|
- }
|
|
|
- newReportId = newId
|
|
|
- }
|
|
|
- }
|
|
|
- // 更新音频
|
|
|
- if !isIgnore {
|
|
|
- countSuccess += 1
|
|
|
- fmt.Printf("写入报告%d成功, 新ID%d\n", reportList[i].ResearchReportId, newReportId)
|
|
|
- //go UpdateReportVideo(newReportId)
|
|
|
- UpdateReportVideo(newReportId)
|
|
|
- }
|
|
|
- }
|
|
|
- fmt.Printf("结束写入, 总数:%d, 忽略:%d, 成功:%d\n", lenReport, countIgnore, countSuccess)
|
|
|
-
|
|
|
- return
|
|
|
-}
|
|
|
-
|
|
|
// 替换报告内容中的base64图片
|
|
|
func replaceReportBase64ToImg(content string) (newContent string, err error) {
|
|
|
if content == "" {
|