|
@@ -34,6 +34,7 @@ type Report struct {
|
|
|
Source ReportSource `gorm:"column:source;comment:'研报来源1:eta 2:海通'" json:"source"`
|
|
|
Title string `gorm:"column:title;comment:'标题'" json:"title"`
|
|
|
Abstract string `gorm:"column:abstract;comment:'摘要'" json:"abstract"`
|
|
|
+ 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"`
|
|
@@ -43,6 +44,11 @@ type Report struct {
|
|
|
UpdatedTime time.Time `gorm:"column:updated_time;comment:'修改时间'" json:"updated_time"`
|
|
|
}
|
|
|
|
|
|
+func GetIdsByPlateNames(plateName []string) (ids []int, err error) {
|
|
|
+ db := models.Main()
|
|
|
+ err = db.Model(&Report{}).Select("distinct org_id").Where(" source ='HT' and plate_name in ? ", plateName).Scan(&ids).Error
|
|
|
+ return
|
|
|
+}
|
|
|
func BatchInsertReport(list *[]Report) (err error) {
|
|
|
db := models.Main()
|
|
|
//手动事务
|
|
@@ -128,9 +134,33 @@ func GetListByCondition[T any](column string, values []T) (reports []Report, err
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
-func GetMaxIdByPermissionIds(orgIds []int) (maxId int64) {
|
|
|
+func GetMaxIdByPermissionIds(orgIds map[string][]int) (maxId int64) {
|
|
|
db := models.Main()
|
|
|
- err := db.Model(&Report{}).Select("MAX(id) id").Where("org_id in ?", orgIds).Scan(&maxId).Error
|
|
|
+ if len(orgIds["ETA"]) == 0 && len(orgIds["HT"]) == 0 {
|
|
|
+ err := db.Model(&Report{}).Select("MAX(id) id").Scan(&maxId).Error
|
|
|
+ if err != nil {
|
|
|
+ logger.Error("获取报告最大ID失败:%v", err)
|
|
|
+ return 0
|
|
|
+ }
|
|
|
+ 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
|
|
|
+ if err != nil {
|
|
|
+ logger.Error("获取报告最大ID失败:%v", err)
|
|
|
+ return 0
|
|
|
+ }
|
|
|
+ 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
|
|
|
+ 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
|
|
|
if err != nil {
|
|
|
logger.Error("获取报告最大ID失败:%v", err)
|
|
|
return 0
|
|
@@ -173,8 +203,8 @@ func GetReportPage(latestId int64, limit int, offset int) (list []Report, err er
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-func GetReportPageByOrgIds(latestId int64, limit int, offset int, orgIds []int) (list []Report, err error) {
|
|
|
- if len(orgIds) == 0 {
|
|
|
+func GetReportPageByOrgIds(latestId int64, limit int, offset int, orgIds map[string][]int) (list []Report, err error) {
|
|
|
+ if len(orgIds["ETA"]) == 0 && len(orgIds["HT"]) == 0 {
|
|
|
return GetReportPage(latestId, limit, offset)
|
|
|
}
|
|
|
if latestId < 0 {
|
|
@@ -187,7 +217,15 @@ func GetReportPageByOrgIds(latestId int64, limit int, offset int, orgIds []int)
|
|
|
logger.Error("非法的limit参数:%d", limit)
|
|
|
}
|
|
|
db := models.Main()
|
|
|
- err = db.Select(CommonColumns).Where("id<= ? and org_id in ?", latestId, orgIds).Order("published_time desc").Limit(limit).Offset(offset).Find(&list).Error
|
|
|
+ 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
|
|
|
+ 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
|
|
|
+ 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
|
|
|
return
|
|
|
}
|
|
|
|