|
@@ -3,6 +3,7 @@ package service
|
|
import (
|
|
import (
|
|
"ElectronicInvoice/util"
|
|
"ElectronicInvoice/util"
|
|
"context"
|
|
"context"
|
|
|
|
+ "fmt"
|
|
"github.com/gogf/gf/v2/errors/gerror"
|
|
"github.com/gogf/gf/v2/errors/gerror"
|
|
"github.com/gogf/gf/v2/frame/g"
|
|
"github.com/gogf/gf/v2/frame/g"
|
|
"github.com/gogf/gf/v2/os/gcron"
|
|
"github.com/gogf/gf/v2/os/gcron"
|
|
@@ -160,15 +161,40 @@ func (im *InvoiceManager) NoticeJob(ctx context.Context) {
|
|
var (
|
|
var (
|
|
unMakeRed = 0
|
|
unMakeRed = 0
|
|
unMakeBlue = 0
|
|
unMakeBlue = 0
|
|
|
|
+
|
|
|
|
+ limitHours = g.Cfg().MustGet(ctx, "invoiceJob.notice.unFinish.hours", 24).Int64()
|
|
)
|
|
)
|
|
|
|
|
|
- unMakeBlue, _ = g.DB().GetCount(ctx, "")
|
|
|
|
- unMakeRed, _ = g.DB().GetCount(ctx, "")
|
|
|
|
|
|
+ if im.StopRunning {
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ createTimeLimit := time.Now().Unix() - limitHours*60*60
|
|
|
|
+
|
|
|
|
+ // 蓝票未完成发票数量查询
|
|
|
|
+ unMakeBlue, _ = g.DB().GetCount(ctx, `SELECT count(*) FROM(
|
|
|
|
+ SELECT a.id as onlyId FROM invoice a WHERE a.invoice_variety like '%电子%' AND ((a.invoice_status=0 AND a.invoice_changed=0) or (a.invoice_status=2 AND a.invoice_changed=1 )) AND (a.invoice_order_code is NULL OR a.invoice_order_code not like '%,%') AND a.create_time > UNIX_TIMESTAMP('2024-04-23 00:00:00') AND a.create_time<?
|
|
|
|
+ UNION
|
|
|
|
+ SELECT a.only_Identifying as onlyId FROM invoice a WHERE a.invoice_variety like '%电子%' AND ((a.invoice_status=0 AND a.invoice_changed=0) or (a.invoice_status=2 AND a.invoice_changed=1)) AND a.invoice_order_code like '%,%' AND a.create_time > UNIX_TIMESTAMP('2024-04-23 00:00:00') AND a.create_time<? GROUP BY invoice_order_code
|
|
|
|
+ ) as data`, createTimeLimit, createTimeLimit)
|
|
|
|
+
|
|
|
|
+ // 红票未完成发票数量查询
|
|
|
|
+ unMakeRed, _ = g.DB().GetCount(ctx, `SELECT count(*) FROM(
|
|
|
|
+ SELECT a.invoice_number as onlyId FROM invoice a WHERE a.invoice_variety like '%电子%' AND a.invoice_status=0 AND a.invoice_changed=1 AND (a.invoice_order_code is NULL OR a.invoice_order_code not like '%,%') AND a.create_time > UNIX_TIMESTAMP('2024-04-23 00:00:00') AND a.create_time<?
|
|
|
|
+ UNION
|
|
|
|
+ SELECT a.invoice_number as onlyId FROM invoice a WHERE a.invoice_variety like '%电子%' AND a.invoice_status=0 AND a.invoice_changed=1 AND a.invoice_order_code like '%,%' AND a.create_time > UNIX_TIMESTAMP('2024-04-23 00:00:00') AND a.create_time<? GROUP BY invoice_order_code
|
|
|
|
+ ) as data`, createTimeLimit, createTimeLimit)
|
|
|
|
|
|
if unMakeRed > 0 || unMakeBlue > 0 {
|
|
if unMakeRed > 0 || unMakeBlue > 0 {
|
|
- context := ``
|
|
|
|
- err := util.SendSimpleMsg2ChatBot(context, g.Cfg().MustGet(ctx, "invoiceJob.notice.unFinish.notice").Strings()...)
|
|
|
|
- if err != nil {
|
|
|
|
|
|
+ noticeMsg := fmt.Sprintf("开票超%d小时提醒\n", limitHours)
|
|
|
|
+ if unMakeBlue > 0 {
|
|
|
|
+ noticeMsg += fmt.Sprintf("蓝票:%d例\n", unMakeBlue)
|
|
|
|
+ }
|
|
|
|
+ if unMakeRed > 0 {
|
|
|
|
+ noticeMsg += fmt.Sprintf("红票:%d例\n", unMakeRed)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if err := util.SendSimpleMsg2ChatBot(noticeMsg, g.Cfg().MustGet(ctx, "invoiceJob.notice.unFinish.notice").Strings()...); err != nil {
|
|
g.Log().Errorf(ctx, "发送未开票消息异常 %v", err)
|
|
g.Log().Errorf(ctx, "发送未开票消息异常 %v", err)
|
|
}
|
|
}
|
|
}
|
|
}
|