user_following_service.go 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. package user
  2. import (
  3. "errors"
  4. userDao "eta/eta_mini_ht_api/models/user"
  5. "time"
  6. )
  7. type FollowDTO struct {
  8. UserId int `json:"userId"`
  9. AnalystId int `json:"analystId"`
  10. AnalystName string `json:"analystName"`
  11. FollowType string `json:"followType"`
  12. FollowedTime time.Time `json:"followedTime"`
  13. }
  14. func convertToCrmFollowingAnalyst(dto FollowDTO) userDao.UserAnalystFollowList {
  15. return userDao.UserAnalystFollowList{
  16. FinancialAnalystID: dto.AnalystId,
  17. FinancialAnalystName: dto.AnalystName,
  18. FollowedTime: time.Now(),
  19. Followed: followType(dto.FollowType),
  20. UserID: dto.UserId,
  21. }
  22. }
  23. func GetPostUser(authorName string, PublishTime string) (ids []int) {
  24. return userDao.GetPostUser(authorName, PublishTime)
  25. }
  26. func convertToFollowDTO(follow userDao.UserAnalystFollowList) (dto FollowDTO) {
  27. return FollowDTO{
  28. UserId: follow.UserID,
  29. AnalystId: follow.FinancialAnalystID,
  30. AnalystName: follow.FinancialAnalystName,
  31. FollowType: string(follow.Followed),
  32. FollowedTime: follow.FollowedTime,
  33. }
  34. }
  35. func convertFollowStatusToFollowDTO(follow userDao.FollowStatus) (dto FollowDTO) {
  36. return FollowDTO{
  37. AnalystName: follow.FinancialAnalystName,
  38. FollowType: string(follow.Followed),
  39. }
  40. }
  41. func followType(followType string) userDao.FollowingType {
  42. switch followType {
  43. case "following":
  44. return userDao.Following
  45. case "unfollowed":
  46. return userDao.Unfollowed
  47. default:
  48. return ""
  49. }
  50. }
  51. func FollowAnalystsByName(userId int, analysts []FollowDTO, follow string) error {
  52. flType := followType(follow)
  53. var userFollows []userDao.UserAnalystFollowList
  54. if flType == "" {
  55. return errors.New("关注状态非法")
  56. }
  57. for _, analyst := range analysts {
  58. userFollow := convertToCrmFollowingAnalyst(analyst)
  59. userFollow.Followed = flType
  60. userFollows = append(userFollows, userFollow)
  61. }
  62. return userDao.FollowAnalystsByName(userId, userFollows, flType)
  63. }
  64. func CheckFollowStatusByNames(userId int, names []string) (follows []FollowDTO, err error) {
  65. list, err := userDao.CheckFollowStatusByNames(userId, names)
  66. if err != nil {
  67. return
  68. }
  69. for _, follow := range list {
  70. follows = append(follows, convertFollowStatusToFollowDTO(follow))
  71. }
  72. return
  73. }
  74. func GetFollowingAnalystList(userId int) (dtoList []FollowDTO, err error) {
  75. list, err := userDao.GetFollowingAnalystList(userId)
  76. if err != nil {
  77. return
  78. }
  79. for _, follow := range list {
  80. dtoList = append(dtoList, convertToFollowDTO(follow))
  81. }
  82. return
  83. }
  84. func GetFollowed(userId int, analystId int) string {
  85. return userDao.GetFollowed(userId, analystId)
  86. }
  87. func FollowAnalyst(dto FollowDTO) (err error) {
  88. follow := convertToCrmFollowingAnalyst(dto)
  89. return userDao.FollowAnalyst(follow)
  90. }
  91. func GetFollowing(userId int, analystId int) string {
  92. return userDao.GetFollowing(userId, analystId)
  93. }