|
@@ -17,13 +17,12 @@ type ReportSource string
|
|
|
type SendStatus string
|
|
|
|
|
|
const (
|
|
|
- SEND SendStatus = "SEND"
|
|
|
- UNSEND SendStatus = "UNSEND"
|
|
|
- SourceETA ReportSource = "ETA"
|
|
|
- SourceHT ReportSource = "HT"
|
|
|
- StatusInit ReportStatus = "INIT"
|
|
|
- StatusPending ReportStatus = "PENDING"
|
|
|
- StatusDone ReportStatus = "DONE"
|
|
|
+ SEND SendStatus = "SEND"
|
|
|
+ UNSEND SendStatus = "UNSEND"
|
|
|
+ SourceETA ReportSource = "ETA"
|
|
|
+ SourceHT ReportSource = "HT"
|
|
|
+ StatusPublish = "PUBLISH"
|
|
|
+ StatusUnPublish ReportStatus = "UNPUBLISH"
|
|
|
|
|
|
MaxBatchNum = 1000
|
|
|
CommonColumns = "id,org_id,author,abstract,title,source,cover_src,published_time"
|
|
@@ -39,7 +38,7 @@ type Report struct {
|
|
|
PlateName string `gorm:"column:plate_name;comment:'板块'" json:"plate_name"`
|
|
|
Author string `gorm:"column:author;comment:'作者'" json:"author"`
|
|
|
CoverSrc int `gorm:"column:cover_src;comment:'封面图片'" json:"cover_src"`
|
|
|
- Status ReportStatus `gorm:"column:status;comment:'报告状态 init:初始化 pending:同步中 done:完成同步'" json:"status"`
|
|
|
+ Status ReportStatus `gorm:"column:status;comment:'报告状态 publish:发布 unpublish:未发布" json:"status"`
|
|
|
SendStatus SendStatus `gorm:"column:send_status;comment:'发送状态'" json:"send_status"`
|
|
|
PublishedTime string `gorm:"column:published_time;comment:'发布时间'" json:"published_time"`
|
|
|
CreatedTime time.Time `gorm:"column:created_time;comment:'创建时间'" json:"created_time"`
|
|
@@ -166,9 +165,9 @@ func GetListOrderByCondition(week bool, column string, limit int, order models.O
|
|
|
if week {
|
|
|
end := time.Now()
|
|
|
begin := date.GetBeginOfTheWeek(end, time.Monday)
|
|
|
- err = db.Select(CommonColumns).Where("DATE(published_time) BETWEEN ? AND ?", begin, end).Order(fmt.Sprintf("%s %s", column, order)).Limit(limit).Find(&reports).Error
|
|
|
+ err = db.Select(CommonColumns).Where("status = ?", StatusPublish).Where("DATE(published_time) BETWEEN ? AND ?", begin, end).Order(fmt.Sprintf("%s %s", column, order)).Limit(limit).Find(&reports).Error
|
|
|
} else {
|
|
|
- err = db.Select(CommonColumns).Order(fmt.Sprintf("%s %s", column, order)).Limit(limit).Find(&reports).Error
|
|
|
+ err = db.Select(CommonColumns).Where("status = ?", StatusPublish).Order(fmt.Sprintf("%s %s", column, order)).Limit(limit).Find(&reports).Error
|
|
|
}
|
|
|
if err != nil {
|
|
|
logger.Error("查询报告列表失败:%v", err)
|
|
@@ -197,7 +196,7 @@ func GetListByCondition[T any](column string, values []T) (reports []Report, err
|
|
|
func GetMaxIdByPermissionIds(orgIds map[string][]int) (maxId int64) {
|
|
|
db := models.Main()
|
|
|
if len(orgIds["ETA"]) == 0 && len(orgIds["HT"]) == 0 {
|
|
|
- err := db.Model(&Report{}).Select("MAX(id) id").Scan(&maxId).Error
|
|
|
+ err := db.Model(&Report{}).Select("MAX(id) id").Where("status = ?", StatusPublish).Scan(&maxId).Error
|
|
|
if err != nil {
|
|
|
logger.Error("获取报告最大ID失败:%v", err)
|
|
|
return 0
|
|
@@ -205,7 +204,7 @@ func GetMaxIdByPermissionIds(orgIds map[string][]int) (maxId int64) {
|
|
|
return
|
|
|
}
|
|
|
if len(orgIds["ETA"]) == 0 {
|
|
|
- err := db.Model(&Report{}).Select("MAX(id) id").Where(" source='HT' and org_id in ?", orgIds["HT"]).Scan(&maxId).Error
|
|
|
+ err := db.Model(&Report{}).Select("MAX(id) id").Where("status = ?", StatusPublish).Where(" source='HT' and org_id in ?", orgIds["HT"]).Scan(&maxId).Error
|
|
|
if err != nil {
|
|
|
logger.Error("获取报告最大ID失败:%v", err)
|
|
|
return 0
|
|
@@ -213,14 +212,14 @@ func GetMaxIdByPermissionIds(orgIds map[string][]int) (maxId int64) {
|
|
|
return
|
|
|
}
|
|
|
if len(orgIds["HT"]) == 0 {
|
|
|
- err := db.Model(&Report{}).Select("MAX(id) id").Where(" source='ETA' and org_id in ?", orgIds["ETA"]).Scan(&maxId).Error
|
|
|
+ err := db.Model(&Report{}).Select("MAX(id) id").Where("status = ?", StatusPublish).Where(" source='ETA' and org_id in ?", orgIds["ETA"]).Scan(&maxId).Error
|
|
|
if err != nil {
|
|
|
logger.Error("获取报告最大ID失败:%v", err)
|
|
|
return 0
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
- err := db.Model(&Report{}).Select("MAX(id) id").Where(" source='ETA' and org_id in ?", orgIds["ETA"]).Or("source='HT' and org_id in ?", orgIds["HT"]).Scan(&maxId).Error
|
|
|
+ err := db.Model(&Report{}).Select("MAX(id) id").Where("status = ?", StatusPublish).Where(" source='ETA' and org_id in ?", orgIds["ETA"]).Or("source='HT' and org_id in ?", orgIds["HT"]).Scan(&maxId).Error
|
|
|
if err != nil {
|
|
|
logger.Error("获取报告最大ID失败:%v", err)
|
|
|
return 0
|
|
@@ -229,7 +228,7 @@ func GetMaxIdByPermissionIds(orgIds map[string][]int) (maxId int64) {
|
|
|
}
|
|
|
func GetTotalPageCount() (total int64) {
|
|
|
db := models.Main()
|
|
|
- err := db.Model(&Report{}).Count(&total).Error
|
|
|
+ err := db.Model(&Report{}).Where("status = ?", StatusPublish).Count(&total).Error
|
|
|
if err != nil {
|
|
|
logger.Error("统计报告数量失败:%v", err)
|
|
|
}
|
|
@@ -238,11 +237,11 @@ func GetTotalPageCount() (total int64) {
|
|
|
|
|
|
func GetTotalPageCountByAnalyst(analyst string) (total int64, latestId int64) {
|
|
|
db := models.Main()
|
|
|
- err := db.Model(&Report{}).Where("author =?", analyst).Count(&total).Error
|
|
|
+ err := db.Model(&Report{}).Where("status = ?", StatusPublish).Where("author like ?", "%"+analyst+"%").Count(&total).Error
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
|
- err = db.Model(&Report{}).Select("Max(id)").Where("author =?", analyst).Scan(&latestId).Error
|
|
|
+ err = db.Model(&Report{}).Select("Max(id)").Where("status = ?", StatusPublish).Where("author like ?", "%"+analyst+"%").Scan(&latestId).Error
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
@@ -259,7 +258,7 @@ func GetReportPage(latestId int64, limit int, offset int) (list []Report, err er
|
|
|
logger.Error("非法的limit参数:%d", limit)
|
|
|
}
|
|
|
db := models.Main()
|
|
|
- err = db.Select(CommonColumns).Where("id<= ?", latestId).Order("published_time desc").Limit(limit).Offset(offset).Find(&list).Error
|
|
|
+ err = db.Select(CommonColumns).Where("id<= ?", latestId).Where("status = ?", StatusPublish).Order("published_time desc").Limit(limit).Offset(offset).Find(&list).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -278,20 +277,20 @@ func GetReportPageByOrgIds(latestId int64, limit int, offset int, orgIds map[str
|
|
|
}
|
|
|
db := models.Main()
|
|
|
if len(orgIds["ETA"]) == 0 {
|
|
|
- err = db.Select(CommonColumns).Where("id<= ?", latestId).Where(" source='HT' and org_id in ?", orgIds["HT"]).Order("published_time desc").Limit(limit).Offset(offset).Find(&list).Error
|
|
|
+ err = db.Select(CommonColumns).Where("id<= ?", latestId).Where("status = ?", StatusPublish).Where(" source='HT' and org_id in ?", orgIds["HT"]).Order("published_time desc").Limit(limit).Offset(offset).Find(&list).Error
|
|
|
return
|
|
|
}
|
|
|
if len(orgIds["HT"]) == 0 {
|
|
|
- err = db.Select(CommonColumns).Where("id<= ?", latestId).Where("source='ETA' and org_id in ?", orgIds["ETA"]).Order("published_time desc").Limit(limit).Offset(offset).Find(&list).Error
|
|
|
+ err = db.Select(CommonColumns).Where("id<= ?", latestId).Where("status = ?", StatusPublish).Where("source='ETA' and org_id in ?", orgIds["ETA"]).Order("published_time desc").Limit(limit).Offset(offset).Find(&list).Error
|
|
|
return
|
|
|
}
|
|
|
- err = db.Select(CommonColumns).Where("id<= ?", latestId).Where("(source='ETA' and org_id in ? ) or (source='HT' and org_id in ?) ", orgIds["ETA"], orgIds["HT"]).Order("published_time desc").Limit(limit).Offset(offset).Find(&list).Error
|
|
|
+ err = db.Select(CommonColumns).Where("id<= ?", latestId).Where("status = ?", StatusPublish).Where("(source='ETA' and org_id in ? ) or (source='HT' and org_id in ?) ", orgIds["ETA"], orgIds["HT"]).Order("published_time desc").Limit(limit).Offset(offset).Find(&list).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
func GetNewReportByPublishTime(time time.Time) (list []Report) {
|
|
|
db := models.Main()
|
|
|
- err := db.Select(taskColumns).Where("published_time >= ?", time).Order("published_time desc").Find(&list).Error
|
|
|
+ err := db.Select(taskColumns).Where("status = ?", StatusPublish).Where("published_time >= ?", time).Order("published_time desc").Find(&list).Error
|
|
|
if err != nil {
|
|
|
logger.Error("查询新发布的报告列表失败:%v", err)
|
|
|
}
|
|
@@ -308,6 +307,6 @@ func GetReportPageByAnalyst(latestId int64, limit int, offset int, analyst strin
|
|
|
logger.Error("非法的limit参数:%d", limit)
|
|
|
}
|
|
|
db := models.Main()
|
|
|
- err = db.Select(CommonColumns).Where("id<= ? and author = ?", latestId, analyst).Order("published_time desc").Limit(limit).Offset(offset).Find(&list).Error
|
|
|
+ err = db.Select(CommonColumns).Where("status = ?", StatusPublish).Where("id<= ? and author = ?", latestId, analyst).Order("published_time desc").Limit(limit).Offset(offset).Find(&list).Error
|
|
|
return
|
|
|
}
|