financial_analyst_service.go 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. package financial_analyst
  2. import (
  3. logger "eta/eta_mini_ht_api/common/component/log"
  4. "eta/eta_mini_ht_api/common/utils/page"
  5. financialAnalystDao "eta/eta_mini_ht_api/models/financial_analyst"
  6. )
  7. type FinancialAnalystDTO struct {
  8. Id int
  9. ETAId int
  10. Name string
  11. Position string
  12. InvestmentCertificate string
  13. ProfessionalCertificate string
  14. HeadImgUrl string
  15. HeadOriginImgUrl string
  16. Introduction string
  17. Status bool
  18. Deleted bool
  19. }
  20. func GetAnalystList(pageInfo page.PageInfo) (analystsDTO []FinancialAnalystDTO, err error) {
  21. offset := page.StartIndex(pageInfo.Current, pageInfo.PageSize)
  22. analystList, err := financialAnalystDao.GetAnalystList(pageInfo.LatestId, offset, pageInfo.PageSize)
  23. for _, analyst := range analystList {
  24. analystsDTO = append(analystsDTO, convertToBaseDTO(analyst))
  25. }
  26. return
  27. }
  28. func GetAnalystById(id int) (financialAnalyst FinancialAnalystDTO, err error) {
  29. analyst, err := financialAnalystDao.GetAnalystById(id)
  30. if err != nil {
  31. logger.Error("获取研究员失败: %v", err)
  32. return
  33. }
  34. financialAnalyst = convertToBaseDTO(analyst)
  35. return
  36. }
  37. func GetCount() (total int64, latestId int64) {
  38. return financialAnalystDao.GetCount()
  39. }
  40. func GetAnalystByName(name string) (financialAnalyst FinancialAnalystDTO, err error) {
  41. analyst, err := financialAnalystDao.GetAnalystByName(name)
  42. if err != nil {
  43. logger.Error("获取研究员失败: %v", err)
  44. return
  45. }
  46. financialAnalyst = convertToBaseDTO(analyst)
  47. return
  48. }
  49. func SyncAnalyst(list []FinancialAnalystDTO) (err error) {
  50. var financialAnalystList []financialAnalystDao.CrmFinancialAnalyst
  51. for _, dto := range list {
  52. financialAnalyst := convert(dto)
  53. financialAnalystList = append(financialAnalystList, financialAnalyst)
  54. }
  55. return financialAnalystDao.BatchInsertOrUpdate(financialAnalystList)
  56. }
  57. func convert(dto FinancialAnalystDTO) (financialAnalyst financialAnalystDao.CrmFinancialAnalyst) {
  58. var status financialAnalystDao.AnalystStatus
  59. if dto.Status {
  60. status = financialAnalystDao.AnalystStatusEnabled
  61. } else {
  62. status = financialAnalystDao.AnalystStatusDisabled
  63. }
  64. return financialAnalystDao.CrmFinancialAnalyst{
  65. ETAId: dto.ETAId,
  66. Name: dto.Name,
  67. Status: status,
  68. Deleted: dto.Deleted,
  69. }
  70. }
  71. func convertToBaseDTO(financialAnalyst financialAnalystDao.CrmFinancialAnalyst) (dto FinancialAnalystDTO) {
  72. return FinancialAnalystDTO{
  73. Id: financialAnalyst.Id,
  74. ETAId: financialAnalyst.ETAId,
  75. HeadImgUrl: financialAnalyst.HeadImgURL,
  76. HeadOriginImgUrl: financialAnalyst.HeadOriginImgUrl,
  77. Name: financialAnalyst.Name,
  78. Introduction: financialAnalyst.Introduction,
  79. ProfessionalCertificate: financialAnalyst.ProfessionalCertificate,
  80. InvestmentCertificate: financialAnalyst.InvestmentCertificate,
  81. Position: financialAnalyst.Position,
  82. }
  83. }