base.go 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. package TaxSb
  2. import (
  3. "git.listensoft.net/tool/jspkit/common"
  4. "git.listensoft.net/tool/jspkit/common/models"
  5. "git.listensoft.net/tool/jspkit/common/watermark"
  6. "git.listensoft.net/tool/jspkit/logger"
  7. "git.listensoft.net/tool/jspkit/taxerr"
  8. "github.com/go-rod/rod"
  9. "github.com/go-rod/rod/lib/input"
  10. "os"
  11. "time"
  12. )
  13. func SaveErrImg(p *rod.Page, info models.CompanyInfo) string {
  14. var check_path string
  15. check_path = "./data/sbImg/" + info.TaxNo + "/"
  16. if !common.PathExists(check_path) {
  17. os.MkdirAll(check_path, os.ModePerm)
  18. }
  19. check_path = check_path + info.Period + "-" + time.Now().Format("2006-01-02-15-04-05") + ".png"
  20. p.Timeout(common.ClickTimeOut).MustScreenshot(check_path)
  21. watermark.Add(check_path)
  22. check_path2 := common.PostSbjt(info.TaxNo, info.Period, check_path)
  23. os.Remove(check_path)
  24. return check_path2
  25. }
  26. func MustElementX(page *rod.Page, xpath string) *rod.Element {
  27. return page.Timeout(common.ClickTimeOut).MustSearch(xpath)
  28. }
  29. func WaitElementXZcFz(page *rod.Page, xpath string, interval float64) *rod.Element {
  30. for i := 0; i < 60; i++ {
  31. for i := 0; i < 60; i++ {
  32. // page.Timeout(common.ClickTimeOut).MustElement("#frmFrame").MustFrame().MustElement(`#frmMain`).MustFrame().MustElement(`#frmSheet`).MustFrame()
  33. if page.MustHas("#frmFrame") && page.MustElement("#frmFrame").MustFrame().MustHas(`#frmMain`) && page.MustElement("#frmFrame").MustFrame().MustElement(`#frmMain`).MustFrame().MustHas(`#frmSheet`) {
  34. if has, el, _ := page.MustElement("#frmFrame").MustFrame().MustElement(`#frmMain`).MustFrame().MustElement(`#frmSheet`).MustFrame().HasX(xpath); has {
  35. return el
  36. }
  37. }
  38. time.Sleep(time.Duration(float64(time.Second) * interval))
  39. }
  40. time.Sleep(time.Duration(float64(time.Second) * interval))
  41. }
  42. logger.Info("页面加载失败元素未找到,请稍后再试", xpath)
  43. panic(taxerr.NewWebStuckTitle(common.InfoCscsts))
  44. }
  45. func inputStr(el *rod.Element, inputVal string) {
  46. _ = rod.Try(func() {
  47. if inputVal == "" {
  48. inputVal = "0"
  49. }
  50. _ = rod.Try(func() {
  51. el.Page().Keyboard.MustType(input.Backspace)
  52. })
  53. _ = rod.Try(func() {
  54. for _, v := range inputVal {
  55. _ = el.Page().Keyboard.Type(input.Key(v))
  56. time.Sleep(time.Millisecond * 10)
  57. }
  58. })
  59. })
  60. }