report.go 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. package services
  2. import (
  3. "errors"
  4. "fmt"
  5. "github.com/PuerkitoBio/goquery"
  6. "hongze/hz_crm_api/models"
  7. "hongze/hz_crm_api/utils"
  8. "html"
  9. "strings"
  10. )
  11. func GetReportContentSub(content string) (contentSub string, err error) {
  12. content = html.UnescapeString(content)
  13. doc, err := goquery.NewDocumentFromReader(strings.NewReader(content))
  14. if err != nil {
  15. fmt.Println("create doc err:", err.Error())
  16. return
  17. }
  18. n := 0
  19. doc.Find("p").Each(func(i int, s *goquery.Selection) {
  20. if n >= 5 {
  21. return
  22. }
  23. n++
  24. phtml, err := s.Html()
  25. if err != nil {
  26. fmt.Println("get html err", err.Error())
  27. return
  28. }
  29. if s.Text() != "" || strings.Contains(phtml, "src") {
  30. contentSub = contentSub + "<p>" + phtml + "</p>"
  31. }
  32. })
  33. return
  34. }
  35. // GetMinClassify
  36. // @Description: 获取最小分类ID
  37. // @author: Roc
  38. // @datetime 2024-06-20 09:23:19
  39. // @param reportInfo *models.Report
  40. // @return minClassifyId int
  41. // @return minClassifyName string
  42. // @return err error
  43. func GetMinClassify(reportInfo *models.Report) (minClassifyId int, minClassifyName string, err error) {
  44. defer func() {
  45. if err != nil {
  46. utils.FileLog.Error("获取最小分类ID失败,报告ID:%d,Err:%s", reportInfo.Id, err.Error())
  47. }
  48. }()
  49. minClassifyId = reportInfo.ClassifyIdThird
  50. minClassifyName = reportInfo.ClassifyNameThird
  51. if minClassifyId <= 0 {
  52. minClassifyId = reportInfo.ClassifyIdSecond
  53. minClassifyName = reportInfo.ClassifyNameSecond
  54. }
  55. if minClassifyId <= 0 {
  56. minClassifyId = reportInfo.ClassifyIdFirst
  57. minClassifyName = reportInfo.ClassifyNameFirst
  58. }
  59. if minClassifyId <= 0 {
  60. err = errors.New("分类异常")
  61. }
  62. return
  63. }