浏览代码

修改研报显示时间格式

kobe6258 7 月之前
父节点
当前提交
3ef7a448f3
共有 4 个文件被更改,包括 68 次插入79 次删除
  1. 1 1
      domian/report/eta_report_service.go
  2. 1 1
      domian/report/report_service.go
  3. 34 42
      models/eta/eta_report.go
  4. 32 35
      models/report/report.go

+ 1 - 1
domian/report/eta_report_service.go

@@ -118,7 +118,7 @@ func convertToETAReportDTO(report eta.ETAReport) (dto ETAReportDTO) {
 		Title:            report.Title,
 		Abstract:         report.Abstract,
 		Author:           report.Author,
-		PublishTime:      report.PublishedTime.Format(time.DateTime),
+		PublishTime:      report.PublishTime.Format(time.DateTime),
 		Content:          html.UnescapeString(report.Content),
 		ReportLayout:     report.ReportLayout,
 		VideoUrl:         report.VideoUrl,

+ 1 - 1
domian/report/report_service.go

@@ -589,7 +589,7 @@ func convertEtaReport(etaRp eta.ETAReport) reportDao.Report {
 		Abstract:      etaRp.Abstract,
 		Author:        etaRp.Author,
 		CoverSrc:      0,
-		PublishedTime: etaRp.PublishedTime.Format(time.DateTime),
+		PublishedTime: etaRp.PublishTime.Format(time.DateTime),
 		Source:        reportDao.SourceETA,
 		SendStatus:    reportDao.UNSEND,
 		Status:        reportDao.StatusInit,

+ 34 - 42
models/eta/eta_report.go

@@ -26,26 +26,25 @@ func (ETAReport) TableName() string {
 }
 
 type ETAReport struct {
-	ID               int    `gorm:"primary_key;auto_increment"`
-	ClassifyID       int    `gorm:"_"`
-	ClassifyIDFirst  int    `gorm:"column:classify_id_first;default:0"`
-	ClassifyIDSecond int    `gorm:"column:classify_id_second;default:0"`
-	ClassifyIDThird  int    `gorm:"column:classify_id_third;default:0"`
-	Title            string `gorm:"column:title;size:125;"`
-	Abstract         string `gorm:"column:abstract;size:255;"`
-	Author           string `gorm:"column:author;size:50;"`
-	PublishTime      string `gorm:"column:publish_time"`
-	PublishedTime    time.Time
-	Content          string `gorm:"column:content"`
-	CollaborateType  int    `gorm:"column:collaborate_type"`
-	ReportLayout     int    `gorm:"column:report_layout"`
-	VideoUrl         string `gorm:"column:video_url"`
-	VideoName        string `gorm:"column:video_name"`
-	VideoPlaySeconds string `gorm:"column:video_play_seconds"`
-	HeadResourceId   int    `gorm:"column:head_resource_id"`
-	EndResourceId    int    `gorm:"column:end_resource_id"`
-	HasChapter       bool   `gorm:"column:has_chapter"`
-	NeedSplice       bool   `gorm:"column:need_splice"`
+	ID               int       `gorm:"primary_key;auto_increment"`
+	ClassifyID       int       `gorm:"_"`
+	ClassifyIDFirst  int       `gorm:"column:classify_id_first;default:0"`
+	ClassifyIDSecond int       `gorm:"column:classify_id_second;default:0"`
+	ClassifyIDThird  int       `gorm:"column:classify_id_third;default:0"`
+	Title            string    `gorm:"column:title;size:125;"`
+	Abstract         string    `gorm:"column:abstract;size:255;"`
+	Author           string    `gorm:"column:author;size:50;"`
+	PublishTime      time.Time `gorm:"column:publish_time"`
+	Content          string    `gorm:"column:content"`
+	CollaborateType  int       `gorm:"column:collaborate_type"`
+	ReportLayout     int       `gorm:"column:report_layout"`
+	VideoUrl         string    `gorm:"column:video_url"`
+	VideoName        string    `gorm:"column:video_name"`
+	VideoPlaySeconds string    `gorm:"column:video_play_seconds"`
+	HeadResourceId   int       `gorm:"column:head_resource_id"`
+	EndResourceId    int       `gorm:"column:end_resource_id"`
+	HasChapter       bool      `gorm:"column:has_chapter"`
+	NeedSplice       bool      `gorm:"column:need_splice"`
 }
 
 //type ReportClassify struct {
@@ -62,13 +61,6 @@ func GetETAReports(id int) (reports []ETAReport, err error) {
 	err = models.ETA().Table("report").Select(colunms+strings.Join(classifyIds, ",")).Where("state =? or state=?", published, passed).Where("id > ?", id).Order("id asc").Limit(limit).Find(&reports).Error
 	if reports != nil {
 		for i := 0; i < len(reports); i++ {
-			var date time.Time
-			date, err = time.Parse(time.DateTime, reports[i].PublishTime)
-			if err != nil {
-				logger.Error("时间转换错误:%v", err)
-			} else {
-				reports[i].PublishedTime = date
-			}
 			setClassifyIdValue(&reports[i])
 		}
 	}
@@ -84,13 +76,13 @@ func GetUpdateETAReports() (reports []ETAReport, err error) {
 	}
 	if reports != nil {
 		for i := 0; i < len(reports); i++ {
-			var date time.Time
-			date, err = time.Parse(time.DateTime, reports[i].PublishTime)
-			if err != nil {
-				logger.Error("时间转换错误:%v", err)
-			} else {
-				reports[i].PublishedTime = date
-			}
+			//var date time.Time
+			//date, err = time.Parse(time.DateTime, reports[i].PublishTime)
+			//if err != nil {
+			//	logger.Error("时间转换错误:%v", err)
+			//} else {
+			//	reports[i].PublishedTime = date
+			//}
 			setClassifyIdValue(&reports[i])
 		}
 	}
@@ -102,14 +94,14 @@ func GetETAReportById(id int) (report ETAReport, err error) {
 	if err != nil {
 		return
 	}
-	var date time.Time
-	date, err = time.Parse(time.DateTime, report.PublishTime)
-	if err != nil {
-		logger.Error("时间转换错误:%v", err)
-		err = nil
-	} else {
-		report.PublishedTime = date
-	}
+	//var date time.Time
+	//date, err = time.Parse(time.DateTime, report.PublishTime)
+	//if err != nil {
+	//	logger.Error("时间转换错误:%v", err)
+	//	err = nil
+	//} else {
+	//	report.PublishedTime = date
+	//}
 	return
 }
 func DoSql(sql string, result interface{}, values ...interface{}) (err error) {

+ 32 - 35
models/report/report.go

@@ -68,53 +68,50 @@ func BatchInsertReport(list *[]Report) (err error) {
 func InsertOrUpdateReport(list *[]Report, source string) (ids []int, err error) {
 	var orgIds []int
 	//现有的作者名字
-	var authorNames []string
-	for _, report := range *list {
-		orgIds = append(orgIds, report.OrgID)
-		authorNames = append(authorNames, report.Author)
-	}
+	//var authorNames []string
+	//for _, report := range *list {
+	//	orgIds = append(orgIds, report.OrgID)
+	//	authorNames = append(authorNames, report.Author)
+	//}
 	orgIds = silce_utils.RemoveDuplicates(orgIds)
-	if orgIds == nil || len(orgIds) == 0 {
-		return
-	}
 	db := models.Main()
 	//数据库找到作者的名字
-	var dbAuthors []string
-	err = db.Model(&Report{}).Select("distinct author").Where("org_id in ? and source =? ", orgIds, source).Scan(&dbAuthors).Error
+	//var dbAuthors []string
+	//err = db.Model(&Report{}).Select("distinct author").Where("org_id in ? and source =? ", orgIds, source).Scan(&dbAuthors).Error
 	if err != nil {
 		logger.Error("查询研报失败:%v", err)
 	}
-	var deleteAuthors []string
-	for _, dbAuthor := range dbAuthors {
-		found := false
-		for _, insertAuthor := range authorNames {
-			if dbAuthor == insertAuthor {
-				found = true
-				break
-			}
-		}
-		if !found {
-			deleteAuthors = append(deleteAuthors, dbAuthor)
-		}
-	}
+	//var deleteAuthors []string
+	//for _, dbAuthor := range dbAuthors {
+	//	found := false
+	//	for _, insertAuthor := range authorNames {
+	//		if dbAuthor == insertAuthor {
+	//			found = true
+	//			break
+	//		}
+	//	}
+	//	if !found {
+	//		deleteAuthors = append(deleteAuthors, dbAuthor)
+	//	}
+	//}
 	//手动事务
 	tx := db.Begin()
 	OnConflictFunc := clause.OnConflict{
-		Columns:   []clause.Column{{Name: "org_id"}, {Name: "author"}, {Name: "source"}},
-		DoUpdates: clause.AssignmentColumns([]string{"abstract", "title", "published_time"}),
+		Columns:   []clause.Column{{Name: "org_id"}, {Name: "source"}},
+		DoUpdates: clause.AssignmentColumns([]string{"abstract", "title", "author", "published_time"}),
 	}
 	// 执行批量插入或更新操作
 	err = tx.Clauses(OnConflictFunc).Create(&list).Error
-	if deleteAuthors != nil {
-		for _, deleteAuthor := range deleteAuthors {
-			err = tx.Where("org_id in ? and source =? and author=?", orgIds, source, deleteAuthor).Delete(&Report{}).Error
-			if err != nil {
-				logger.Error("批量删除研报失败:%v", err)
-				tx.Rollback()
-				return
-			}
-		}
-	}
+	//if deleteAuthors != nil {
+	//	for _, deleteAuthor := range deleteAuthors {
+	//		err = tx.Where("org_id in ? and source =? and author=?", orgIds, source, deleteAuthor).Delete(&Report{}).Error
+	//		if err != nil {
+	//			logger.Error("批量删除研报失败:%v", err)
+	//			tx.Rollback()
+	//			return
+	//		}
+	//	}
+	//}
 	tx.Commit()
 	return
 }