analyst_service.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package analyst
  2. import (
  3. logger "eta/eta_mini_ht_api/common/component/log"
  4. "eta/eta_mini_ht_api/common/exception"
  5. "eta/eta_mini_ht_api/common/utils/page"
  6. analystService "eta/eta_mini_ht_api/domian/financial_analyst"
  7. userService "eta/eta_mini_ht_api/domian/user"
  8. "sync"
  9. )
  10. type Analyst struct {
  11. Id int `json:"id"`
  12. Name string `json:"name"`
  13. HeadImgUrl string `json:"headImgUrl"`
  14. Introduction string `json:"introduction"`
  15. Following string `json:"following"`
  16. }
  17. func GetAnalystCount() (total int64, latestId int64) {
  18. return analystService.GetCount()
  19. }
  20. func GetAnalystList(pageInfo page.PageInfo, userId int) (analysts []Analyst, err error) {
  21. List, err := analystService.GetAnalystList(pageInfo)
  22. if err != nil {
  23. logger.Error("查询研究员列表失败:%v", err)
  24. err = exception.New(exception.GetAnalystListFailed)
  25. }
  26. for _, item := range List {
  27. analysts = append(analysts, convertToAnalyst(item))
  28. }
  29. var wg sync.WaitGroup
  30. for i := 0; i < len(List); i++ {
  31. wg.Add(1)
  32. go func(analyst *Analyst) {
  33. defer wg.Done()
  34. analyst.Following = userService.GetFollowing(userId, analyst.Id)
  35. }(&analysts[i])
  36. }
  37. wg.Wait()
  38. return
  39. }
  40. func convertToAnalyst(analyst analystService.FinancialAnalystDTO) Analyst {
  41. return Analyst{
  42. Id: analyst.Id,
  43. Name: analyst.Name,
  44. HeadImgUrl: analyst.HeadImgUrl,
  45. Introduction: analyst.Introduction,
  46. Following: "",
  47. }
  48. }