report_service.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649
  1. package report
  2. import (
  3. "encoding/json"
  4. "eta/eta_mini_ht_api/common/component/config"
  5. "eta/eta_mini_ht_api/common/component/es"
  6. logger "eta/eta_mini_ht_api/common/component/log"
  7. "eta/eta_mini_ht_api/common/contants"
  8. "eta/eta_mini_ht_api/common/utils/page"
  9. stringUtils "eta/eta_mini_ht_api/common/utils/string"
  10. analystService "eta/eta_mini_ht_api/domian/financial_analyst"
  11. userService "eta/eta_mini_ht_api/domian/user"
  12. "eta/eta_mini_ht_api/models"
  13. "eta/eta_mini_ht_api/models/eta"
  14. etaDao "eta/eta_mini_ht_api/models/eta"
  15. "eta/eta_mini_ht_api/models/ht"
  16. mediaDao "eta/eta_mini_ht_api/models/media"
  17. reportDao "eta/eta_mini_ht_api/models/report"
  18. "github.com/google/uuid"
  19. "math/rand"
  20. "strconv"
  21. "strings"
  22. "time"
  23. )
  24. const (
  25. SourceETA = "ETA"
  26. SourceHT = "HT"
  27. DESC models.Order = "desc"
  28. ASC models.Order = "asc"
  29. ESColumn = "title"
  30. ESRangeColumn = "reportId"
  31. )
  32. var (
  33. sortField = []string{"_score:desc"}
  34. htConfig = config.GetConfig(contants.HT).(*config.HTBizConfig)
  35. )
  36. func elastic() *es.ESClient {
  37. return es.GetInstance()
  38. }
  39. // ESReport Report ES研报mapping
  40. type ESReport struct {
  41. ReportID int `json:"reportId"`
  42. OrgId int `json:"orgId"`
  43. Title string `json:"title"`
  44. Author string `json:"author"`
  45. Source reportDao.ReportSource `json:"source"`
  46. Abstract string `json:"abstract"`
  47. CoverSrc int `json:"coverSrc"`
  48. Status reportDao.ReportStatus `json:"status"`
  49. PublishedTime string `json:"publishedTime"`
  50. }
  51. type ReportDTO struct {
  52. ReportID int `json:"reportId"`
  53. OrgId int `json:"orgId"`
  54. Title string `json:"title"`
  55. Author string `json:"author"`
  56. Source string `json:"source"`
  57. Abstract string `json:"abstract"`
  58. PublishedTime string `json:"publishedTime"`
  59. SecondPermission map[int]string `json:"-"`
  60. Permissions map[int]string `json:"-"`
  61. PermissionNames interface{} `json:"permissionNames,omitempty"`
  62. Highlight []string `json:"highlight,omitempty"`
  63. Detail json.RawMessage `json:"detail,omitempty"`
  64. CoverSrc int `json:"coverSrc"`
  65. }
  66. type Detail struct {
  67. }
  68. type PermissionDTO struct {
  69. ID int
  70. Name string
  71. ParentID int
  72. }
  73. func GetGetReportById(reportId int) (ReportDTO ReportDTO, err error) {
  74. report, err := reportDao.GetReportById(reportId)
  75. if err != nil {
  76. return
  77. }
  78. orgId := report.OrgID
  79. names, _ := reportDao.GetAuthorByOrgId(orgId, string(report.Source))
  80. if names != nil && len(names) > 1 {
  81. names = stringUtils.UniqueItems(names)
  82. report.Author = strings.Join(names, ",")
  83. }
  84. report.PublishedTime = report.PublishedTime[:10]
  85. ReportDTO = convertReportDTO(report)
  86. return
  87. }
  88. func GetTotalPageCount() (total int64) {
  89. return reportDao.GetTotalPageCount()
  90. }
  91. func GetTotalPageCountByAnalyst(analyst string) (total int64, latestId int64) {
  92. return reportDao.GetTotalPageCountByAnalyst(analyst)
  93. }
  94. func SearchMaxReportId(key string) (total int64, reportId int64) {
  95. sort := []string{"reportId:desc"}
  96. request := matchAll(sort, key)
  97. //同步es
  98. re, err := elastic().Count(request)
  99. if err != nil {
  100. logger.Error("es搜索异常:%v", err)
  101. }
  102. count := re.Count
  103. total = int64(count)
  104. if total > 0 {
  105. request = match(key, 0, count, sort)
  106. re, err = elastic().Search(request)
  107. if err != nil {
  108. logger.Error("es搜索异常:%v", err)
  109. }
  110. hits := elastic().GetSource(re.Hits)
  111. data := hits[0].Source
  112. report := ReportDTO{}
  113. err = json.Unmarshal(data, &report)
  114. if err != nil {
  115. logger.Error("获取当前最大研报id失败:%v", err)
  116. return
  117. }
  118. reportId = int64(report.ReportID)
  119. }
  120. return
  121. }
  122. func SearchReportList(key string, from int, size int, max int64) (reports []ReportDTO, err error) {
  123. //同步es
  124. sorts := append(sortField, "publishedTime:desc")
  125. request := matchRange(key, from, size, max, sorts)
  126. re, err := elastic().Search(request)
  127. if err != nil {
  128. logger.Error("es搜索异常:%v", err)
  129. }
  130. hits := elastic().GetSource(re.Hits)
  131. if len(hits) == 0 {
  132. reports = []ReportDTO{}
  133. return
  134. }
  135. for _, hit := range hits {
  136. var content map[string][]string
  137. err = json.Unmarshal(hit.Highlight, &content)
  138. report := ReportDTO{}
  139. err = json.Unmarshal(hit.Source, &report)
  140. if err != nil {
  141. logger.Error("解析研报数据失败:%v", err)
  142. continue
  143. }
  144. report.Highlight = content[ESColumn]
  145. report.Title = report.Highlight[0]
  146. report.PublishedTime = report.PublishedTime[:10]
  147. reports = append(reports, report)
  148. }
  149. return
  150. }
  151. func GetReportPageByAnalyst(pageInfo page.PageInfo, analyst string) (list []ReportDTO, err error) {
  152. offset := page.StartIndex(pageInfo.Current, pageInfo.PageSize)
  153. reports, err := reportDao.GetReportPageByAnalyst(pageInfo.LatestId, pageInfo.PageSize, offset, analyst)
  154. if err != nil {
  155. logger.Error("分页查询报告列表失败:%v", err)
  156. return
  157. }
  158. list = make([]ReportDTO, 0)
  159. if reports != nil {
  160. for _, report := range reports {
  161. dto := convertReportDTO(report)
  162. list = append(list, dto)
  163. }
  164. }
  165. return
  166. }
  167. func GetReportPageByOrgIds(pageInfo page.PageInfo, orgIds []int) (list []ReportDTO, err error) {
  168. offset := page.StartIndex(pageInfo.Current, pageInfo.PageSize)
  169. reports, err := reportDao.GetReportPageByOrgIds(pageInfo.LatestId, pageInfo.PageSize, offset, orgIds)
  170. if err != nil {
  171. logger.Error("分页查询报告列表失败:%v", err)
  172. return
  173. }
  174. list = make([]ReportDTO, 0)
  175. if reports != nil {
  176. for _, report := range reports {
  177. dto := convertReportDTO(report)
  178. list = append(list, dto)
  179. }
  180. }
  181. return
  182. }
  183. func GetNewReportByPublishTime(time time.Time) (reports []ReportDTO) {
  184. list := reportDao.GetNewReportByPublishTime(time)
  185. if list != nil {
  186. for _, report := range list {
  187. dto := convertReportDTO(report)
  188. reports = append(reports, dto)
  189. }
  190. }
  191. return
  192. }
  193. func GetReportPage(pageInfo page.PageInfo) (list []ReportDTO, err error) {
  194. offset := page.StartIndex(pageInfo.Current, pageInfo.PageSize)
  195. reports, err := reportDao.GetReportPage(pageInfo.LatestId, pageInfo.PageSize, offset)
  196. if err != nil {
  197. logger.Error("分页查询报告列表失败:%v", err)
  198. return
  199. }
  200. list = make([]ReportDTO, 0)
  201. if reports != nil {
  202. for _, report := range reports {
  203. dto := convertReportDTO(report)
  204. list = append(list, dto)
  205. }
  206. }
  207. return
  208. }
  209. func getETAReportFirstPermissions(id int) (permissionDTOs []PermissionDTO) {
  210. classifyId, err := etaDao.GetReportClassifyById(id)
  211. if err != nil || classifyId == 0 {
  212. logger.Error("获取研报分类信息失败:%v", err)
  213. return
  214. }
  215. permissions, err := etaDao.GetFirstPermissionsByClassifyID(classifyId)
  216. if err != nil {
  217. logger.Error("获取研报一级品种信息失败:%v", err)
  218. return
  219. }
  220. for _, permission := range permissions {
  221. permissionDTOs = append(permissionDTOs, convertPermissionDTO(permission))
  222. }
  223. return
  224. }
  225. func getETAReportSecondPermissions(id int) (permissionDTOs []PermissionDTO) {
  226. classifyId, err := etaDao.GetReportClassifyById(id)
  227. if err != nil || classifyId == 0 {
  228. logger.Error("获取研报分类信息失败:%v", err)
  229. return
  230. }
  231. permissions, err := etaDao.GetSecondPermissionsByClassifyID(classifyId)
  232. if err != nil {
  233. logger.Error("获取研报二级品种信息失败:%v", err)
  234. return
  235. }
  236. for _, permission := range permissions {
  237. permissionDTOs = append(permissionDTOs, convertPermissionDTO(permission))
  238. }
  239. return
  240. }
  241. func (es ESReport) GetId() string {
  242. return strconv.Itoa(es.ReportID)
  243. }
  244. func GetETALatestReportId() (id int, err error) {
  245. return reportDao.GetLatestReportIdBySource(reportDao.SourceETA)
  246. }
  247. func GetHTLatestReportId() (id int, err error) {
  248. return reportDao.GetLatestReportIdBySource(reportDao.SourceHT)
  249. }
  250. func InitETAReportList(list []eta.ETAReport) (err error) {
  251. logger.Info("同步研报数量%d", len(list))
  252. var reports []reportDao.Report
  253. for _, etaRp := range list {
  254. authorNames := strings.Split(etaRp.Author, ",")
  255. authorNamesWithOutEmpty := stringUtils.RemoveEmptyStrings(authorNames)
  256. for _, authorName := range authorNamesWithOutEmpty {
  257. var coverSrc int
  258. var permissions []etaDao.ChartPermission
  259. permissions, err = etaDao.GetSecondPermissionsByClassifyID(etaRp.ClassifyID)
  260. if err != nil || len(permissions) == 0 {
  261. logger.Error("获取研报二级品种信息失败:%v", err)
  262. coverSrc = 0
  263. } else {
  264. permissionsId := permissions[0].ChartPermissionID
  265. var ids []int
  266. ids, err = mediaDao.GetIdsByPermissionId(permissionsId)
  267. if err != nil {
  268. logger.Error("获取图片资源失败:%v", err)
  269. }
  270. if ids == nil || len(ids) == 0 {
  271. coverSrc = 0
  272. } else {
  273. src := rand.NewSource(time.Now().UnixNano())
  274. r := rand.New(src)
  275. // 从切片中随机选择一个元素
  276. randomIndex := r.Intn(len(ids))
  277. coverSrc = ids[randomIndex]
  278. }
  279. }
  280. destRp := convertEtaReport(etaRp)
  281. destRp.Author = authorName
  282. destRp.CoverSrc = coverSrc
  283. reports = append(reports, destRp)
  284. }
  285. }
  286. err = reportDao.BatchInsertReport(&reports)
  287. if err != nil {
  288. logger.Error("同步ETA研报失败:%v", err)
  289. return
  290. }
  291. return syncES(reports)
  292. }
  293. func SyncETAReportList(list []eta.ETAReport) (err error) {
  294. logger.Info("同步研报数量%d", len(list))
  295. var reports []reportDao.Report
  296. for _, etaRp := range list {
  297. authorNames := strings.Split(etaRp.Author, ",")
  298. authorNamesWithOutEmpty := stringUtils.RemoveEmptyStrings(authorNames)
  299. for _, authorName := range authorNamesWithOutEmpty {
  300. destRp := convertEtaReport(etaRp)
  301. destRp.Author = authorName
  302. reports = append(reports, destRp)
  303. }
  304. }
  305. err = reportDao.BatchInsertReport(&reports)
  306. if err != nil {
  307. logger.Error("同步ETA研报失败:%v", err)
  308. return
  309. }
  310. //for _, etaRp := range reports {
  311. // esRp := convertEsReport(etaRp)
  312. // esReports = append(esReports, esRp)
  313. //}
  314. return syncESAndSendMessage(reports)
  315. ////同步es
  316. //err = elastic().BulkInsert(htConfig.GetReportIndex(), esReports)
  317. //if err != nil {
  318. // logger.Error("同步ETA研报到es失败:%v", err)
  319. // return
  320. //}
  321. ////生产meta信息
  322. //logger.Info("生成推送META信息")
  323. //for _, report := range reports {
  324. // userIds := userService.GetPostUser(report.Author, report.PublishedTime)
  325. // var author analystService.FinancialAnalystDTO
  326. // author, err = analystService.GetAnalystByName(report.Author)
  327. // if err != nil {
  328. // logger.Error("获取研报作者失败:%v", err)
  329. // continue
  330. // }
  331. // if len(userIds) > 0 {
  332. // usersStr := stringUtils.IntToStringSlice(userIds)
  333. // Meta := userService.MetaData{
  334. // AuthorName: report.Author,
  335. // AuthorId: author.Id,
  336. // SourceId: report.ID,
  337. // PublishedTime: report.PublishedTime,
  338. // }
  339. // metaStr, _ := json.Marshal(Meta)
  340. // toStr := strings.Join(usersStr, ",")
  341. // UUID := uuid.New()
  342. // uuidStr := UUID.String()
  343. // metaContent := userService.MetaInfoDTO{
  344. // From: "ETA",
  345. // Uid: "report:" + uuidStr,
  346. // Meta: string(metaStr),
  347. // MetaType: "USER_NOTICE",
  348. // SourceType: "REPORT",
  349. // To: toStr,
  350. // }
  351. // err = userService.CreateMetaInfo(metaContent)
  352. // if err != nil {
  353. // logger.Error("创建Meta信息失败:%v", err)
  354. // return err
  355. // }
  356. // }
  357. //}
  358. }
  359. func syncESAndSendMessage(reports []reportDao.Report) (err error) {
  360. var esReports []es.ESBase
  361. for _, etaRp := range reports {
  362. esRp := convertEsReport(etaRp)
  363. esReports = append(esReports, esRp)
  364. }
  365. //同步es
  366. err = elastic().BulkInsert(htConfig.GetReportIndex(), esReports)
  367. if err != nil {
  368. logger.Error("同步ETA研报到es失败:%v", err)
  369. return
  370. }
  371. //生产meta信息
  372. logger.Info("生成推送META信息")
  373. for _, report := range reports {
  374. userIds := userService.GetPostUser(report.Author, report.PublishedTime)
  375. var author analystService.FinancialAnalystDTO
  376. author, err = analystService.GetAnalystByName(report.Author)
  377. if err != nil {
  378. logger.Error("获取研报作者失败:%v", err)
  379. continue
  380. }
  381. if len(userIds) > 0 {
  382. usersStr := stringUtils.IntToStringSlice(userIds)
  383. Meta := userService.MetaData{
  384. AuthorName: report.Author,
  385. AuthorId: author.Id,
  386. SourceId: report.ID,
  387. PublishedTime: report.PublishedTime,
  388. }
  389. metaStr, _ := json.Marshal(Meta)
  390. toStr := strings.Join(usersStr, ",")
  391. UUID := uuid.New()
  392. uuidStr := UUID.String()
  393. metaContent := userService.MetaInfoDTO{
  394. From: "HT",
  395. Uid: "report:" + uuidStr,
  396. Meta: string(metaStr),
  397. MetaType: "USER_NOTICE",
  398. SourceType: "REPORT",
  399. To: toStr,
  400. }
  401. err = userService.CreateMetaInfo(metaContent)
  402. if err != nil {
  403. logger.Error("创建Meta信息失败:%v", err)
  404. return err
  405. }
  406. }
  407. }
  408. return
  409. }
  410. func syncES(reports []reportDao.Report) (err error) {
  411. var esReports []es.ESBase
  412. for _, etaRp := range reports {
  413. esRp := convertEsReport(etaRp)
  414. esReports = append(esReports, esRp)
  415. }
  416. //同步es
  417. err = elastic().BulkInsert(htConfig.GetReportIndex(), esReports)
  418. if err != nil {
  419. logger.Error("同步ETA研报到es失败:%v", err)
  420. return
  421. }
  422. ////生产meta信息
  423. //logger.Info("生成推送META信息")
  424. //for _, report := range reports {
  425. // userIds := userService.GetPostUser(report.Author, report.PublishedTime)
  426. // var author analystService.FinancialAnalystDTO
  427. // author, err = analystService.GetAnalystByName(report.Author)
  428. // if err != nil {
  429. // logger.Error("获取研报作者失败:%v", err)
  430. // continue
  431. // }
  432. // if len(userIds) > 0 {
  433. // usersStr := stringUtils.IntToStringSlice(userIds)
  434. // Meta := userService.MetaData{
  435. // AuthorName: report.Author,
  436. // AuthorId: author.Id,
  437. // SourceId: report.ID,
  438. // PublishedTime: report.PublishedTime,
  439. // }
  440. // metaStr, _ := json.Marshal(Meta)
  441. // toStr := strings.Join(usersStr, ",")
  442. // UUID := uuid.New()
  443. // uuidStr := UUID.String()
  444. // metaContent := userService.MetaInfoDTO{
  445. // From: "HT",
  446. // Uid: "report:" + uuidStr,
  447. // Meta: string(metaStr),
  448. // MetaType: "USER_NOTICE",
  449. // SourceType: "REPORT",
  450. // To: toStr,
  451. // }
  452. // err = userService.CreateMetaInfo(metaContent)
  453. // if err != nil {
  454. // logger.Error("创建Meta信息失败:%v", err)
  455. // return err
  456. // }
  457. // }
  458. //}
  459. return
  460. }
  461. func InitHTReportList(list []ht.HTReport) (err error) {
  462. logger.Info("同步研报数量%d", len(list))
  463. var reports []reportDao.Report
  464. for _, htRp := range list {
  465. var authorStr string
  466. authorStr, err = reportDao.GetGLAuthorNames(htRp.Plate, htRp.Permission)
  467. if err != nil {
  468. logger.Error("获取钢联研报作者失败:%v", err)
  469. }
  470. if authorStr != "" {
  471. htRp.Author = authorStr
  472. }
  473. authorNames := strings.Split(htRp.Author, ",")
  474. authorNamesWithOutEmpty := stringUtils.RemoveEmptyStrings(authorNames)
  475. for _, authorName := range authorNamesWithOutEmpty {
  476. destRp := convertHTReport(htRp)
  477. destRp.Author = authorName
  478. reports = append(reports, destRp)
  479. }
  480. }
  481. err = reportDao.BatchInsertReport(&reports)
  482. if err != nil {
  483. logger.Error("同步HT研报失败:%v", err)
  484. return
  485. }
  486. return syncES(reports)
  487. }
  488. func SyncHTReportList(list []ht.HTReport) (err error) {
  489. logger.Info("同步研报数量%d", len(list))
  490. var reports []reportDao.Report
  491. for _, htRp := range list {
  492. var authorStr string
  493. authorStr, err = reportDao.GetGLAuthorNames(htRp.Plate, htRp.Permission)
  494. if err != nil {
  495. logger.Error("获取钢联研报作者失败:%v", err)
  496. }
  497. if authorStr != "" {
  498. htRp.Author = authorStr
  499. }
  500. authorNames := strings.Split(htRp.Author, ",")
  501. authorNamesWithOutEmpty := stringUtils.RemoveEmptyStrings(authorNames)
  502. for _, authorName := range authorNamesWithOutEmpty {
  503. destRp := convertHTReport(htRp)
  504. destRp.Author = authorName
  505. reports = append(reports, destRp)
  506. }
  507. }
  508. err = reportDao.BatchInsertReport(&reports)
  509. if err != nil {
  510. logger.Error("同步HT研报失败:%v", err)
  511. return
  512. }
  513. return syncESAndSendMessage(reports)
  514. }
  515. func GetListOrderByConditionWeekly(week bool, column string, limit int, order models.Order) (dtoList []ReportDTO, err error) {
  516. reports, err := reportDao.GetListOrderByCondition(week, column, limit, order)
  517. if err != nil {
  518. logger.Error("获取研报失败:%v", err)
  519. return
  520. }
  521. for _, report := range reports {
  522. dto := convertReportDTO(report)
  523. dtoList = append(dtoList, dto)
  524. }
  525. return
  526. }
  527. func GetListByCondition[T any](column string, ids []T) (dtoList []ReportDTO, err error) {
  528. var values []interface{}
  529. for _, id := range ids {
  530. values = append(values, id)
  531. }
  532. reports, err := reportDao.GetListByCondition(column, ids)
  533. if err != nil {
  534. logger.Error("获取研报失败:%v", err)
  535. return
  536. }
  537. for _, report := range reports {
  538. dto := convertReportDTO(report)
  539. dtoList = append(dtoList, dto)
  540. }
  541. return
  542. }
  543. func GetTotalPageCountByPermissionIds(permissionIds []int) (total int64, latestId int64, ids []int) {
  544. //TODO 一期品种筛选reportIds
  545. htIds, err := GetHTReportIdsByPermissionIds(permissionIds)
  546. if err != nil {
  547. logger.Error("品种筛选ht报告id失败:%v", err)
  548. htIds = []int{}
  549. }
  550. etaIds, err := GetETAReportIdsByPermissionIds(permissionIds)
  551. if err != nil {
  552. logger.Error("品种筛选eta报告id失败:%v", err)
  553. etaIds = []int{}
  554. }
  555. total = int64(len(etaIds) + len(htIds))
  556. ids = append(etaIds, htIds...)
  557. latestId = reportDao.GetMaxIdByPermissionIds(ids)
  558. return
  559. }
  560. func convertEtaReport(etaRp eta.ETAReport) reportDao.Report {
  561. return reportDao.Report{
  562. OrgID: etaRp.ID,
  563. Title: etaRp.Title,
  564. Abstract: etaRp.Abstract,
  565. Author: etaRp.Author,
  566. CoverSrc: 0,
  567. PublishedTime: etaRp.PublishTime,
  568. Source: reportDao.SourceETA,
  569. SendStatus: reportDao.UNSEND,
  570. Status: reportDao.StatusInit,
  571. }
  572. }
  573. func convertHTReport(etaRp ht.HTReport) reportDao.Report {
  574. return reportDao.Report{
  575. OrgID: etaRp.ID,
  576. Title: etaRp.Title,
  577. Abstract: etaRp.Abstract,
  578. Author: etaRp.Author,
  579. PublishedTime: etaRp.PublishTime,
  580. Source: reportDao.SourceHT,
  581. SendStatus: reportDao.UNSEND,
  582. Status: reportDao.StatusInit,
  583. }
  584. }
  585. func convertEsReport(report reportDao.Report) ESReport {
  586. return ESReport{
  587. ReportID: report.ID,
  588. Title: report.Title,
  589. OrgId: report.OrgID,
  590. Author: report.Author,
  591. Source: report.Source,
  592. Abstract: report.Abstract,
  593. Status: report.Status,
  594. CoverSrc: report.CoverSrc,
  595. PublishedTime: report.PublishedTime,
  596. }
  597. }
  598. func convertReportDTO(report reportDao.Report) (reportDTO ReportDTO) {
  599. reportDTO = ReportDTO{
  600. ReportID: report.ID,
  601. Title: report.Title,
  602. OrgId: report.OrgID,
  603. Author: report.Author,
  604. Source: string(report.Source),
  605. Abstract: report.Abstract,
  606. PublishedTime: report.PublishedTime,
  607. }
  608. publishDate, err := time.Parse(time.DateTime, reportDTO.PublishedTime)
  609. if err == nil {
  610. reportDTO.PublishedTime = publishDate.Format(time.DateOnly)
  611. }
  612. return
  613. }
  614. func matchAll(sorts []string, key string) (request *es.ESQueryRequest) {
  615. req := new(es.ESQueryRequest)
  616. return req.CreateESQueryRequest(htConfig.GetReportIndex(), ESColumn, key, 0, 1, sorts, es.MatchAll)
  617. }
  618. func match(key string, from int, to int, sorts []string) (request *es.ESQueryRequest) {
  619. req := new(es.ESQueryRequest)
  620. return req.CreateESQueryRequest(htConfig.GetReportIndex(), ESColumn, key, from, to, sorts, es.Match)
  621. }
  622. func matchRange(key string, from int, to int, max int64, sorts []string) (request *es.ESQueryRequest) {
  623. req := new(es.ESQueryRequest)
  624. return req.CreateESQueryRequest(htConfig.GetReportIndex(), ESColumn, key, from, to, sorts, es.Range).Range(0, max, ESRangeColumn)
  625. }