|
@@ -0,0 +1,47 @@
|
|
|
+package service
|
|
|
+
|
|
|
+import (
|
|
|
+ "ElectronicInvoice/internal/consts"
|
|
|
+ "context"
|
|
|
+ "github.com/gogf/gf/v2/errors/gerror"
|
|
|
+ "github.com/gogf/gf/v2/frame/g"
|
|
|
+ "time"
|
|
|
+)
|
|
|
+
|
|
|
+type redBatch struct {
|
|
|
+ Date string `json:"date"`
|
|
|
+ Code string `json:"code"`
|
|
|
+}
|
|
|
+
|
|
|
+func (im *InvoiceManager) RunRedBatchOnce(ctx context.Context) {
|
|
|
+ var (
|
|
|
+ arr []*redBatch
|
|
|
+ okNum int
|
|
|
+ )
|
|
|
+ err := g.Cfg("redBatchTmp").MustGet(ctx, "list").Struct(&arr)
|
|
|
+ if err != nil {
|
|
|
+ g.Log().Errorf(ctx, "RunJob-RunRedBatchOnce 读取红冲列表异常")
|
|
|
+ }
|
|
|
+ for _, data := range arr {
|
|
|
+ select {
|
|
|
+ case im.RunPool <- true:
|
|
|
+ case <-time.After(time.Minute * 5):
|
|
|
+ err = gerror.Wrap(consts.WaitTimeOut, "simpleMakeInvoice-开票等待超时")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ err := im.Auth.MakeSingleRedInvoice(MakeRedInvoiceData{
|
|
|
+ Num: data.Code,
|
|
|
+ Date: data.Date,
|
|
|
+ })
|
|
|
+ if err != nil {
|
|
|
+ <-im.RunPool
|
|
|
+ if gerror.Is(err, consts.LoginOutErr) {
|
|
|
+ g.Log().Errorf(ctx, "RunJob-RunRedBatchOnce-身份过期,需要重新登录")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ okNum++
|
|
|
+ }
|
|
|
+ }
|
|
|
+ g.Log().Infof(ctx, "RunJob-RunRedBatchOnce 共%d个 完成%d个", len(arr), okNum)
|
|
|
+}
|