financial_analyst_service.go 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. HeadImgUrl string
  12. Introduction string
  13. Status bool
  14. Deleted bool
  15. }
  16. func GetAnalystList(pageInfo page.PageInfo) (analystsDTO []FinancialAnalystDTO, err error) {
  17. offset := page.StartIndex(pageInfo.Current, pageInfo.PageSize)
  18. analystList, err := financialAnalystDao.GetAnalystList(pageInfo.LatestId, offset, pageInfo.PageSize)
  19. for _, analyst := range analystList {
  20. analystsDTO = append(analystsDTO, convertToBaseDTO(analyst))
  21. }
  22. return
  23. }
  24. func GetAnalystById(id int) (financialAnalyst FinancialAnalystDTO, err error) {
  25. analyst, err := financialAnalystDao.GetAnalystById(id)
  26. if err != nil {
  27. logger.Error("获取研究员失败: %v", err)
  28. return
  29. }
  30. financialAnalyst = convertToBaseDTO(analyst)
  31. return
  32. }
  33. func GetCount() (total int64, latestId int64) {
  34. return financialAnalystDao.GetCount()
  35. }
  36. func GetAnalystByName(name string) (financialAnalyst FinancialAnalystDTO, err error) {
  37. analyst, err := financialAnalystDao.GetAnalystByName(name)
  38. if err != nil {
  39. logger.Error("获取研究员失败: %v", err)
  40. return
  41. }
  42. financialAnalyst = convertToBaseDTO(analyst)
  43. return
  44. }
  45. func SyncAnalyst(list []FinancialAnalystDTO) (err error) {
  46. var financialAnalystList []financialAnalystDao.CrmFinancialAnalyst
  47. for _, dto := range list {
  48. financialAnalyst := convert(dto)
  49. financialAnalystList = append(financialAnalystList, financialAnalyst)
  50. }
  51. return financialAnalystDao.BatchInsertOrUpdate(financialAnalystList)
  52. }
  53. func convert(dto FinancialAnalystDTO) (financialAnalyst financialAnalystDao.CrmFinancialAnalyst) {
  54. var status financialAnalystDao.AnalystStatus
  55. if dto.Status {
  56. status = financialAnalystDao.AnalystStatusEnabled
  57. } else {
  58. status = financialAnalystDao.AnalystStatusDisabled
  59. }
  60. return financialAnalystDao.CrmFinancialAnalyst{
  61. ETAId: dto.ETAId,
  62. Name: dto.Name,
  63. Status: status,
  64. Deleted: dto.Deleted,
  65. }
  66. }
  67. func convertToBaseDTO(financialAnalyst financialAnalystDao.CrmFinancialAnalyst) (dto FinancialAnalystDTO) {
  68. return FinancialAnalystDTO{
  69. Id: financialAnalyst.Id,
  70. ETAId: financialAnalyst.ETAId,
  71. HeadImgUrl: financialAnalyst.HeadImgURL,
  72. Name: financialAnalyst.Name,
  73. Introduction: financialAnalyst.Introduction,
  74. }
  75. }