|
@@ -16,12 +16,14 @@ var (
|
|
|
)
|
|
|
|
|
|
type InvoiceManager struct {
|
|
|
- Auth *TripartiteAuth
|
|
|
- Login bool //登录状态
|
|
|
- OCRPass bool //活体检测状态是否通过
|
|
|
- runPool chan bool //任务(每次只能进行一个开票任务)
|
|
|
- phoneCode chan string //短信验证码池
|
|
|
- ScanLogin chan bool //扫码登录
|
|
|
+ Auth *TripartiteAuth
|
|
|
+ jobRunning bool //开票是否运行中
|
|
|
+ StopRunning bool //财务占用账号,需要暂停任务
|
|
|
+ Login bool //登录状态
|
|
|
+ OCRPass bool //活体检测状态是否通过
|
|
|
+ runPool chan bool //任务(每次只能进行一个开票任务)
|
|
|
+ phoneCode chan string //短信验证码池
|
|
|
+ ScanLogin chan bool //扫码登录
|
|
|
}
|
|
|
|
|
|
func init() {
|
|
@@ -30,7 +32,7 @@ func init() {
|
|
|
//if err != nil {
|
|
|
// panic(err)
|
|
|
//}
|
|
|
- //go JyInvoiceManager.RunOneJob(context.Background())
|
|
|
+ //go JyInvoiceManager.RunOneJob(context.Background())//流程
|
|
|
//go JyInvoiceManager.Demo(context.Background()) //开票
|
|
|
//go JyInvoiceManager.RedDemo(context.Background())//红冲
|
|
|
}
|
|
@@ -73,6 +75,16 @@ func (im *InvoiceManager) MobileVerificationClear() error {
|
|
|
|
|
|
// RunJob 开票定时任务
|
|
|
func (im *InvoiceManager) RunJob(ctx context.Context) {
|
|
|
+ if im.jobRunning || im.StopRunning {
|
|
|
+ g.Log().Infof(ctx, "RunJob-程序本次任务中断 jobRunning:%v StopRunning:%v", im.jobRunning, im.StopRunning)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ im.jobRunning = true
|
|
|
+ defer func() {
|
|
|
+ im.jobRunning = false
|
|
|
+ g.Log().Infof(ctx, "RunJob-开票任务完成")
|
|
|
+ }()
|
|
|
+
|
|
|
if g.Cfg().MustGet(ctx, "invoiceJob.stop", false).Bool() {
|
|
|
g.Log().Infof(ctx, "RunJob-开票程序任务已暂停,开启请删除 config.json > invoiceJob.stop")
|
|
|
return
|
|
@@ -87,14 +99,20 @@ func (im *InvoiceManager) RunJob(ctx context.Context) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ //TODO 普通蓝票任务
|
|
|
total, okNum, err := im.simpleMakeInvoice(ctx)
|
|
|
if err != nil {
|
|
|
- g.Log().Errorf(ctx, "开蓝票任务异常 %v", err)
|
|
|
+ if gerror.Is(err, consts.LoginOutErr) {
|
|
|
+ g.Log().Infof(ctx, "RunJob-任务中止-身份过期,需要重新登录")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ g.Log().Errorf(ctx, "RunJob-开蓝票任务异常 %v", err)
|
|
|
} else {
|
|
|
- g.Log().Infof(ctx, "开蓝票任务完成 共%d个 完成%d个", total, okNum)
|
|
|
+ g.Log().Infof(ctx, "RunJob-开蓝票任务完成 共%d个 完成%d个", total, okNum)
|
|
|
}
|
|
|
|
|
|
- g.Log().Infof(ctx, "RunJob-开票任务完成")
|
|
|
+ //TODO 红票任务
|
|
|
+
|
|
|
}
|
|
|
|
|
|
// simpleMakeInvoice 简单开票
|
|
@@ -104,7 +122,7 @@ func (im *InvoiceManager) simpleMakeInvoice(ctx context.Context) (total, okNum i
|
|
|
)
|
|
|
|
|
|
//查询需要开票的数据
|
|
|
- res, err = g.DB().Query(ctx, "SELECT * FROM invoice WHERE invoice_status=0 AND invoice_variety='普通发票(电子发票)' AND invoice_order_code is NULL ")
|
|
|
+ res, err = g.DB().Query(ctx, "SELECT * FROM invoice WHERE invoice_status=0 AND invoice_changed=0 AND invoice_variety='普通发票(电子发票)' AND invoice_order_code is NULL ")
|
|
|
if err != nil {
|
|
|
g.Log().Errorf(ctx, "RunJob-simpleMakeInvoice-查询待开票异常 %s", err)
|
|
|
return -1, -1, gerror.Wrap(err, "simpleMakeInvoice-查询待开票异常")
|
|
@@ -115,7 +133,7 @@ func (im *InvoiceManager) simpleMakeInvoice(ctx context.Context) (total, okNum i
|
|
|
select {
|
|
|
case im.runPool <- true:
|
|
|
case <-time.After(time.Minute * 5):
|
|
|
- g.Log().Errorf(ctx, "RunJob-simpleMakeInvoice-开票等待异常,结束此次任务")
|
|
|
+ g.Log().Errorf(ctx, "RunJob-simpleMakeInvoice-开票等待超时,结束此次任务")
|
|
|
return
|
|
|
}
|
|
|
var (
|