فهرست منبع

新增客户存量数据统计

longyu 3 سال پیش
والد
کامیت
df42f77a0d
3فایلهای تغییر یافته به همراه14 افزوده شده و 4 حذف شده
  1. 2 3
      models/company_report_record.go
  2. 6 1
      services/company/company_report_record.go
  3. 6 0
      services/task.go

+ 2 - 3
models/company_report_record.go

@@ -38,10 +38,9 @@ func GetCompanyList(endDate string) (list []*CompanyReportRecord, err error) {
 	sql := ` SELECT a.company_id,a.company_name,a.credit_code,b.status,b.start_date,b.end_date,b.seller_id,b.seller_name,b.company_product_id
 			FROM  company AS a
 			INNER JOIN company_product AS b ON a.company_id=b.company_id
-			WHERE b.product_id=1
-			AND b.create_time>=? `
+			WHERE b.product_id=1`
 	o := orm.NewOrm()
-	_, err = o.Raw(sql, endDate).QueryRows(&list)
+	_, err = o.Raw(sql).QueryRows(&list)
 	return
 }
 

+ 6 - 1
services/company/company_report_record.go

@@ -6,17 +6,21 @@ import (
 	"hongze/hongze_task/models"
 	"hongze/hongze_task/utils"
 	"strconv"
+	"sync"
 	"time"
 )
 
+var companyLock sync.Mutex
+
 func AddCompanyReportRecord(cont context.Context) (err error) {
+	companyLock.Lock()
 	defer func() {
 		if err != nil {
 			fmt.Println("AddReportRecord Err:" + err.Error())
 		}
 	}()
 
-	endDate := time.Now().AddDate(-1, 0, 0).Format(utils.FormatDate)
+	endDate := time.Now().Format(utils.FormatDate)
 
 	existList, err := models.GetExistCompanyReportRecord(endDate)
 	if err != nil {
@@ -67,5 +71,6 @@ func AddCompanyReportRecord(cont context.Context) (err error) {
 			}
 		}
 	}
+	companyLock.Unlock()
 	return err
 }

+ 6 - 0
services/task.go

@@ -6,6 +6,7 @@ import (
 	"fmt"
 	"github.com/beego/beego/v2/task"
 	"hongze/hongze_task/models"
+	"hongze/hongze_task/services/company"
 	"hongze/hongze_task/services/company_contract"
 	"hongze/hongze_task/services/data"
 	"hongze/hongze_task/services/roadshow"
@@ -87,6 +88,11 @@ func Task() {
 
 	addReportRecord := task.NewTask("addReportRecord", "0 0 */1 * * *", roadshow.AddReportRecord)
 	task.AddTask("addReportRecord", addReportRecord)
+
+	//存量客户数据统计
+	addCompanyReportRecord := task.NewTask("addCompanyReportRecord", "0 0 */1 * * *", company.AddCompanyReportRecord)
+	task.AddTask("addCompanyReportRecord", addCompanyReportRecord)
+
 	task.StartTask()
 
 	fmt.Println("task end")