invoiceDemo.go 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. package service
  2. import (
  3. "ElectronicInvoice/internal/consts"
  4. "context"
  5. "github.com/gogf/gf/v2/errors/gerror"
  6. "github.com/gogf/gf/v2/frame/g"
  7. "time"
  8. )
  9. func (im *InvoiceManager) Demo(ctx context.Context) {
  10. c := MakeInvoiceData{
  11. Type: "2",
  12. Gmfmc: "测试个人",
  13. Gmfnsrsbh: "",
  14. Id: "0888886",
  15. InvoiceArr: []MakeInvoiceItems{{
  16. Xmmc: "0fccdac71c36a8552ba662e7a2f42726",
  17. WhStatus: 1,
  18. Je: "2",
  19. Sl: "1",
  20. }},
  21. }
  22. err := im.Auth.MakeSingleInvoice(c)
  23. if err != nil {
  24. g.Log().Errorf(ctx, "开票失败 %v", err)
  25. }
  26. }
  27. func (im *InvoiceManager) RedDemo(ctx context.Context) {
  28. err := im.Auth.MakeSingleRedInvoice(MakeRedInvoiceData{
  29. Num: "24112000000026895182",
  30. Date: "2024-04-22",
  31. })
  32. if err != nil {
  33. g.Log().Errorf(ctx, "红冲失败 %v", err)
  34. }
  35. }
  36. func (im *InvoiceManager) RunOneJob(ctx context.Context) {
  37. t := 0
  38. start:
  39. if im.Login != true {
  40. for i := 0; i < 10; i++ {
  41. if err := im.Auth.Login(); err != nil {
  42. g.Log().Errorf(ctx, "模拟登录异常 %v", err)
  43. } else {
  44. g.Log().Infof(ctx, "登录成功")
  45. break
  46. }
  47. time.Sleep(time.Minute)
  48. }
  49. }
  50. if !im.Login {
  51. g.Log().Infof(ctx, "登录失败退出")
  52. return
  53. }
  54. //for i := 0; i < 3; i++ {
  55. select {
  56. case im.RunPool <- true:
  57. case <-time.After(time.Minute):
  58. g.Log().Errorf(ctx, "RunJob-开票等待异常,结束此次任务")
  59. return
  60. }
  61. c := MakeInvoiceData{
  62. Type: "2",
  63. Gmfmc: "测试个人",
  64. Gmfnsrsbh: "",
  65. Id: "0888886",
  66. InvoiceArr: []MakeInvoiceItems{{
  67. Xmmc: "0fccdac71c36a8552ba662e7a2f42726",
  68. WhStatus: 1,
  69. Je: "2",
  70. Sl: "1",
  71. }},
  72. }
  73. err := im.Auth.MakeSingleInvoice(c)
  74. if err != nil {
  75. <-im.RunPool
  76. }
  77. if gerror.Is(err, consts.LoginOutErr) {
  78. g.Log().Infof(ctx, "RunJob-身份过期,需要重新登录")
  79. if t == 0 {
  80. t = t + 1
  81. time.Sleep(time.Second * 5)
  82. goto start
  83. }
  84. }
  85. if err != nil {
  86. g.Log().Errorf(ctx, "RunJob-开票接口调用异常 %v", err)
  87. }
  88. //}
  89. }