12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- package service
- import (
- "ElectronicInvoice/internal/consts"
- "context"
- "github.com/gogf/gf/v2/errors/gerror"
- "github.com/gogf/gf/v2/frame/g"
- "time"
- )
- func (im *InvoiceManager) Demo(ctx context.Context) {
- c := MakeInvoiceData{
- Type: "2",
- Gmfmc: "测试个人",
- Gmfnsrsbh: "",
- Id: "0888886",
- InvoiceArr: []MakeInvoiceItems{{
- Xmmc: "0fccdac71c36a8552ba662e7a2f42726",
- WhStatus: 1,
- Je: "2",
- Sl: "1",
- }},
- }
- err := im.Auth.MakeSingleInvoice(c)
- if err != nil {
- g.Log().Errorf(ctx, "开票失败 %v", err)
- }
- }
- func (im *InvoiceManager) RedDemo(ctx context.Context) {
- err := im.Auth.MakeSingleRedInvoice(MakeRedInvoiceData{
- Num: "24112000000026895182",
- Date: "2024-04-22",
- })
- if err != nil {
- g.Log().Errorf(ctx, "红冲失败 %v", err)
- }
- }
- func (im *InvoiceManager) RunOneJob(ctx context.Context) {
- t := 0
- start:
- if im.Login != true {
- for i := 0; i < 10; i++ {
- if err := im.Auth.Login(); err != nil {
- g.Log().Errorf(ctx, "模拟登录异常 %v", err)
- } else {
- g.Log().Infof(ctx, "登录成功")
- break
- }
- time.Sleep(time.Minute)
- }
- }
- if !im.Login {
- g.Log().Infof(ctx, "登录失败退出")
- return
- }
- //for i := 0; i < 3; i++ {
- select {
- case im.RunPool <- true:
- case <-time.After(time.Minute):
- g.Log().Errorf(ctx, "RunJob-开票等待异常,结束此次任务")
- return
- }
- c := MakeInvoiceData{
- Type: "2",
- Gmfmc: "测试个人",
- Gmfnsrsbh: "",
- Id: "0888886",
- InvoiceArr: []MakeInvoiceItems{{
- Xmmc: "0fccdac71c36a8552ba662e7a2f42726",
- WhStatus: 1,
- Je: "2",
- Sl: "1",
- }},
- }
- err := im.Auth.MakeSingleInvoice(c)
- if err != nil {
- <-im.RunPool
- }
- if gerror.Is(err, consts.LoginOutErr) {
- g.Log().Infof(ctx, "RunJob-身份过期,需要重新登录")
- if t == 0 {
- t = t + 1
- time.Sleep(time.Second * 5)
- goto start
- }
- }
- if err != nil {
- g.Log().Errorf(ctx, "RunJob-开票接口调用异常 %v", err)
- }
- //}
- }
|