subscribe_servcie.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. )
  8. type SubscribeDTO struct {
  9. Title string
  10. Abstract string
  11. RiskLevel string
  12. CoverSrc string
  13. }
  14. func SubscribeList(templateUserId int, productType string, pageInfo page.PageInfo) (list []SubscribeDTO, err error) {
  15. var subscribeList []merchant.UserAccessDTO
  16. subscribeList, err = merchant.SubscribeList(templateUserId, productType, pageInfo)
  17. var wg sync.WaitGroup
  18. wg.Add(len(subscribeList))
  19. for _, Subscribe := range subscribeList {
  20. go func(Subscribe merchant.UserAccessDTO) {
  21. defer wg.Done()
  22. product, _ := merchant.GetMerchantProductById(Subscribe.ProductID)
  23. subscribe := convertToSubscribeDTO(product)
  24. subscribe.RiskLevel, err = GetProductRiskLevel(product)
  25. if err != nil {
  26. logger.Error("获取风险等级失败[productId:%d]", product.Id)
  27. }
  28. list = append(list, subscribe)
  29. }(Subscribe)
  30. }
  31. wg.Wait()
  32. return
  33. }
  34. func convertToSubscribeDTO(product merchant.MerchantProductDTO) SubscribeDTO {
  35. return SubscribeDTO{
  36. Title: product.Title,
  37. Abstract: product.Description,
  38. CoverSrc: product.CoverSrc,
  39. }
  40. }
  41. func GetTotalPageCountByProductType(productType string, templateUserId int) (int64, int64) {
  42. return merchant.GetTotalPageCountByProductType(productType, templateUserId)
  43. }