subscribe_servcie.go 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. package product
  2. import (
  3. logger "eta/eta_mini_ht_api/common/component/log"
  4. "eta/eta_mini_ht_api/common/utils/page"
  5. "eta/eta_mini_ht_api/domian/merchant"
  6. "sync"
  7. "time"
  8. )
  9. type SubscribeDTO struct {
  10. Title string `json:"title"`
  11. Abstract string `json:"abstract"`
  12. SourceId int `json:"sourceId"`
  13. SourceTitle string `json:"sourceTitle"`
  14. SourceAbstract string `json:"sourceAbstract"`
  15. SourceSrc string `json:"sourceSrc"`
  16. Type string `json:"type"`
  17. RiskLevel string `json:"riskLevel"`
  18. CoverUrl string `json:"coverUrl"`
  19. PermissionNames []string `json:"permissionNames"`
  20. CreatedDate string `json:"createdDate"`
  21. }
  22. func SubscribeList(templateUserId int, productType string, pageInfo page.PageInfo) (list []SubscribeDTO, err error) {
  23. var subscribeList []merchant.UserAccessDTO
  24. subscribeList, err = merchant.SubscribeList(templateUserId, productType, pageInfo)
  25. var wg sync.WaitGroup
  26. wg.Add(len(subscribeList))
  27. for _, Subscribe := range subscribeList {
  28. go func(Subscribe merchant.UserAccessDTO) {
  29. defer wg.Done()
  30. product, _ := merchant.GetMerchantProductById(Subscribe.ProductID)
  31. subscribe := convertToSubscribeDTO(product)
  32. if err != nil {
  33. logger.Error("获取风险等级失败[productId:%d]", product.Id)
  34. }
  35. switch product.Type {
  36. case "audio", "video":
  37. subscribe.RiskLevel, subscribe.SourceTitle, _, subscribe.CoverUrl, subscribe.SourceSrc, subscribe.PermissionNames, _, err = GetProductRiskLevel(product)
  38. case "report":
  39. subscribe.RiskLevel, subscribe.SourceTitle, subscribe.SourceAbstract, subscribe.CoverUrl, _, subscribe.PermissionNames, _, err = GetProductRiskLevel(product)
  40. case "package":
  41. subscribe.RiskLevel, _, _, subscribe.CoverUrl, _, subscribe.PermissionNames, _, err = GetProductRiskLevel(product)
  42. default:
  43. logger.Error("未知产品类型[productType:%s]", product.Type)
  44. return
  45. }
  46. list = append(list, subscribe)
  47. }(Subscribe)
  48. }
  49. wg.Wait()
  50. return
  51. }
  52. func convertToSubscribeDTO(product merchant.MerchantProductDTO) SubscribeDTO {
  53. return SubscribeDTO{
  54. SourceId: product.SourceId,
  55. Type: product.Type,
  56. Title: product.Title,
  57. Abstract: product.Description,
  58. CoverUrl: product.CoverUrl,
  59. CreatedDate: product.CreatedTime.Format(time.DateOnly),
  60. }
  61. }
  62. func GetTotalUserPageCountByProductType(productType string, templateUserId int) (int64, int64) {
  63. return merchant.GetTotalUserPageCountByProductType(productType, templateUserId)
  64. }