Roc 1 年間 前
コミット
7699208e6b
4 ファイル変更0 行追加466 行削除
  1. 0 17
      models/research_report.go
  2. 0 104
      models/variety_tag.go
  3. 0 323
      services/report.go
  4. 0 22
      services/report_sync.go

+ 0 - 17
models/research_report.go

@@ -55,23 +55,6 @@ type ResearchReportList struct {
 	LinkUrl             string    `description:"报告阅读地址"`
 }
 
-// 获取今年报告
-func GetMigrateReportList() (list []*ResearchReport, err error) {
-	o := orm.NewOrmUsingDB("weekly")
-	sql := ` SELECT
-				*
-			FROM
-				research_report AS a
-			WHERE
-				a.enabled = 1
-			AND a.status = "report"
-			AND a.research_report_date >= "2022-01-01"
-			ORDER BY a.research_report_date ASC `
-	_, err = o.Raw(sql).QueryRows(&list)
-
-	return
-}
-
 // ResearchReport 研究报告表(晨报、周报等)结构体
 type ResearchReportType struct {
 	ResearchReportTypeId    int       `orm:"column(research_report_type_id);pk" description:"报告章节ID"`

+ 0 - 104
models/variety_tag.go

@@ -45,50 +45,6 @@ func GetEnableVarietyClassifyList(hasForbidden bool) (list []*VarietyClassify, e
 	return
 }
 
-// GetVarietyClassifyPageList 获取标签分类分页列表
-func GetVarietyClassifyPageList(condition string, pars []interface{}, orderRule string, startSize, pageSize int) (total int, list []*VarietyClassify, err error) {
-	o := orm.NewOrmUsingDB("weekly")
-	sql := `SELECT * FROM variety_classify WHERE 1=1 `
-	sql += condition
-	if orderRule == "" {
-		orderRule = "modify_time DESC"
-	}
-	sql += ` ORDER BY ` + orderRule
-
-	totalSQL := `SELECT COUNT(1) total FROM (` + sql + `) z`
-	if err = o.Raw(totalSQL, pars).QueryRow(&total); err != nil {
-		return
-	}
-	sql += ` LIMIT ?,?`
-
-	_, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&list)
-	return
-}
-
-// GetVarietyClassifyById 主键获取分类
-func GetVarietyClassifyById(classifyId int) (item *VarietyClassify, err error) {
-	o := orm.NewOrmUsingDB("weekly")
-	sql := `SELECT * FROM variety_classify WHERE variety_classify_id = ? LIMIT 1`
-	err = o.Raw(sql, classifyId).QueryRow(&item)
-	return
-}
-
-// GetVarietyClassifyByName 名称获取分类
-func GetVarietyClassifyByName(classifyName string) (item *VarietyClassify, err error) {
-	o := orm.NewOrmUsingDB("weekly")
-	sql := `SELECT * FROM variety_classify WHERE classify_name = ? LIMIT 1`
-	err = o.Raw(sql, classifyName).QueryRow(&item)
-	return
-}
-
-// GetCountEnableClassifyByClassifyId 根据分类ID获取启用分类数
-func GetCountEnableClassifyByClassifyId(classifyId int) (count int, err error) {
-	o := orm.NewOrmUsingDB("weekly")
-	sql := `SELECT COUNT(1) FROM variety_classify WHERE state = 1 AND variety_classify_id != ?`
-	err = o.Raw(sql, classifyId).QueryRow(&count)
-	return
-}
-
 // VarietyTag 标签表
 type VarietyTag struct {
 	VarietyTagId                int       `orm:"column(variety_tag_id);pk" description:"标签ID"`
@@ -120,22 +76,6 @@ func (varietyTag *VarietyTag) Update(cols []string) (err error) {
 	return
 }
 
-// GetVarietyTagById 主键获取标签
-func GetVarietyTagById(tagId int) (item *VarietyTag, err error) {
-	o := orm.NewOrmUsingDB("weekly")
-	sql := `SELECT * FROM variety_tag WHERE variety_tag_id = ? LIMIT 1`
-	err = o.Raw(sql, tagId).QueryRow(&item)
-	return
-}
-
-// GetCountEnableTagByTagId 根据标签ID获取启用标签数
-func GetCountEnableTagByTagId(classifyId int) (count int, err error) {
-	o := orm.NewOrmUsingDB("weekly")
-	sql := `SELECT COUNT(1) FROM variety_tag WHERE state = 1 AND variety_tag_id != ?`
-	err = o.Raw(sql, classifyId).QueryRow(&count)
-	return
-}
-
 // GetEnableVarietyTagList 获取启用状态标签列表
 func GetEnableVarietyTagList(hasForbidden bool) (list []*VarietyTag, err error) {
 	o := orm.NewOrmUsingDB("weekly")
@@ -150,42 +90,6 @@ func GetEnableVarietyTagList(hasForbidden bool) (list []*VarietyTag, err error)
 	return
 }
 
-// GetVarietyTagList 获取标签列表
-func GetVarietyTagList() (list []*VarietyTag, err error) {
-	o := orm.NewOrmUsingDB("weekly")
-	sql := `SELECT * FROM variety_tag ORDER BY sort`
-	_, err = o.Raw(sql).QueryRows(&list)
-	return
-}
-
-// GetVarietyTagPageList 获取标签分页列表
-func GetVarietyTagPageList(condition string, pars []interface{}, orderRule string, startSize, pageSize int) (total int, list []*VarietyTag, err error) {
-	o := orm.NewOrmUsingDB("weekly")
-	sql := `SELECT * FROM variety_tag WHERE 1=1 `
-	sql += condition
-	if orderRule == "" {
-		orderRule = "modify_time DESC"
-	}
-	sql += ` ORDER BY ` + orderRule
-
-	totalSQL := `SELECT COUNT(1) total FROM (` + sql + `) z`
-	if err = o.Raw(totalSQL, pars).QueryRow(&total); err != nil {
-		return
-	}
-	sql += ` LIMIT ?,?`
-
-	_, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&list)
-	return
-}
-
-// GetVarietyTagListByClassifyId 根据分类获取标签列表
-func GetVarietyTagListByClassifyId(classifyId int) (list []*VarietyTag, err error) {
-	o := orm.NewOrmUsingDB("weekly")
-	sql := `SELECT * FROM variety_tag WHERE variety_classify_id = ? AND state = 1 ORDER BY sort`
-	_, err = o.Raw(sql).QueryRows(&list)
-	return
-}
-
 // ResearchVarietyTagRelation 研究员标签关系表
 type ResearchVarietyTagRelation struct {
 	Id           int `orm:"column(id);pk"`
@@ -193,14 +97,6 @@ type ResearchVarietyTagRelation struct {
 	AdminId      int `json:"admin_id" description:"研究员ID"`
 }
 
-// ResearchVarietyTagRelationListByAdminId 根据研究员ID获取标签关系列表
-func ResearchVarietyTagRelationListByAdminId(adminId int) (list []*ResearchVarietyTagRelation, err error) {
-	o := orm.NewOrmUsingDB("weekly")
-	sql := `SELECT * FROM research_variety_tag_relation WHERE admin_id = ?`
-	_, err = o.Raw(sql, adminId).QueryRows(&list)
-	return
-}
-
 type ResearchTagRelation struct {
 	Id              int `json:"id"`
 	ResearchGroupId int `json:"research_group_id" description:"分组ID"`

+ 0 - 323
services/report.go

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

+ 0 - 22
services/report_sync.go

@@ -487,25 +487,3 @@ func SyncOldReport(reportId int) (err error) {
 	}
 	return
 }
-
-// UpdateSyncReport (一次性)更新已同步的报告
-func UpdateSyncReport() (err error) {
-	defer func() {
-		if err != nil {
-			fmt.Println(err.Error())
-		}
-	}()
-	reportList, e := models.GetMigrateReportList()
-	if e != nil {
-		err = errors.New("获取今年报告失败, Err: " + e.Error())
-		return
-	}
-	lenReport := len(reportList)
-	for i := 0; i < lenReport; i++ {
-		if e = SyncOldReport(reportList[i].ResearchReportId); e != nil {
-			err = errors.New("同步报告失败, ResearchReportId: " + strconv.Itoa(reportList[i].ResearchReportId) + ", Err: " + e.Error())
-			return
-		}
-	}
-	return
-}