analyst_service.go 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. Position string `json:"position"`
  17. InvestmentCertificate string `json:"investmentCertificate"`
  18. ProfessionalCertificate string `json:"professionalCertificate"`
  19. }
  20. func GetAnalystCount() (total int64, latestId int64) {
  21. return analystService.GetCount()
  22. }
  23. func GetAnalystList(pageInfo page.PageInfo, userId int) (analysts []Analyst, err error) {
  24. List, err := analystService.GetAnalystList(pageInfo)
  25. if err != nil {
  26. logger.Error("查询研究员列表失败:%v", err)
  27. err = exception.New(exception.GetAnalystListFailed)
  28. }
  29. for _, item := range List {
  30. analysts = append(analysts, convertToAnalyst(item))
  31. }
  32. var wg sync.WaitGroup
  33. for i := 0; i < len(List); i++ {
  34. wg.Add(1)
  35. go func(analyst *Analyst) {
  36. defer wg.Done()
  37. analyst.Following = userService.GetFollowing(userId, analyst.Id)
  38. }(&analysts[i])
  39. }
  40. wg.Wait()
  41. return
  42. }
  43. func convertToAnalyst(analyst analystService.FinancialAnalystDTO) Analyst {
  44. return Analyst{
  45. Id: analyst.Id,
  46. Name: analyst.Name,
  47. HeadImgUrl: analyst.HeadImgUrl,
  48. Introduction: analyst.Introduction,
  49. Following: "",
  50. Position: analyst.Position,
  51. ProfessionalCertificate: analyst.ProfessionalCertificate,
  52. InvestmentCertificate: analyst.InvestmentCertificate,
  53. }
  54. }