浏览代码

fix:company_report_record

Roc 2 年之前
父节点
当前提交
b67f6943a8
共有 2 个文件被更改,包括 58 次插入11 次删除
  1. 9 7
      models/company_report_record.go
  2. 49 4
      services/company/company_report_record.go

+ 9 - 7
models/company_report_record.go

@@ -8,6 +8,7 @@ import (
 type CompanyReportRecord struct {
 	CompanyReportRecordId int `orm:"column(company_report_record_id);pk"`
 	CompanyId             int
+	ProductId             int
 	CompanyProductId      int
 	CompanyName           string
 	Status                string
@@ -27,19 +28,20 @@ func AddCompanyReportRecord(item *CompanyReportRecord) (lastId int64, err error)
 	return
 }
 
-func GetExistCompanyReportRecord(endDate string) (list []*CompanyReportRecord, err error) {
-	sql := ` SELECT * FROM  company_report_record WHERE create_date>=? `
+func GetExistCompanyReportRecord(endDate string, productId int) (list []*CompanyReportRecord, err error) {
+	sql := ` SELECT * FROM  company_report_record WHERE create_date>=? AND product_id = ? `
 	o := orm.NewOrm()
-	_, err = o.Raw(sql, endDate).QueryRows(&list)
+	_, err = o.Raw(sql, endDate, productId).QueryRows(&list)
 	return
 }
 
-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
+func GetCompanyList(productId int) (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,b.product_id 
 			FROM  company AS a
-			INNER JOIN company_product AS b ON a.company_id=b.company_id `
+			INNER JOIN company_product AS b ON a.company_id=b.company_id 
+WHERE b.product_id = ? `
 	o := orm.NewOrm()
-	_, err = o.Raw(sql).QueryRows(&list)
+	_, err = o.Raw(sql, productId).QueryRows(&list)
 	return
 }
 

+ 49 - 4
services/company/company_report_record.go

@@ -21,8 +21,10 @@ func AddCompanyReportRecord(cont context.Context) (err error) {
 	}()
 
 	endDate := time.Now().Format(utils.FormatDate)
+	productId := 1
 
-	existList, err := models.GetExistCompanyReportRecord(endDate)
+	// 查找已经记录的ficc的记录
+	existList, err := models.GetExistCompanyReportRecord(endDate, productId)
 	if err != nil {
 		return
 	}
@@ -30,15 +32,23 @@ func AddCompanyReportRecord(cont context.Context) (err error) {
 	for _, v := range existList {
 		existMap[v.CompanyId] = v
 	}
-	list, err := models.GetCompanyList(endDate)
+	// 查找当前ficc的客户列表
+	list, err := models.GetCompanyList(productId)
 	if err != nil {
 		return
 	}
 	for _, v := range list {
-		if _, ok := existMap[v.CompanyId]; ok { //修改
+		if info, ok := existMap[v.CompanyId]; ok { //修改
+			//校验字段是否变更,如果有变更,那么就更新
+			if !checkUpdate(info, v) {
+				continue
+			}
 			utils.FileLog.Info("update company:" + strconv.Itoa(v.CompanyId))
 			recordWhereParams := make(map[string]interface{})
-			recordWhereParams["company_id"] = v.CompanyId
+			//recordWhereParams["company_id"] = v.CompanyId
+			//recordWhereParams["product_id"] = productId
+			//recordWhereParams["create_date"] = endDate
+			recordWhereParams["company_report_record_id"] = info.CompanyReportRecordId
 
 			recordUpdateParams := make(map[string]interface{})
 			recordUpdateParams["company_name"] = v.CompanyName
@@ -54,6 +64,7 @@ func AddCompanyReportRecord(cont context.Context) (err error) {
 			utils.FileLog.Info("add company:" + strconv.Itoa(v.CompanyId))
 			item := new(models.CompanyReportRecord)
 			item.CompanyId = v.CompanyId
+			item.ProductId = v.ProductId
 			item.CompanyProductId = v.CompanyProductId
 			item.CompanyName = v.CompanyName
 			item.Status = v.Status
@@ -74,3 +85,37 @@ func AddCompanyReportRecord(cont context.Context) (err error) {
 	companyLock.Unlock()
 	return err
 }
+
+// checkUpdate 判断是否要更新
+func checkUpdate(companyReportRecordInfo, companyInfo *models.CompanyReportRecord) bool {
+	// 潜在用户过滤
+	if companyInfo.CompanyId == 1 {
+		return false
+	}
+	//状态
+	if companyReportRecordInfo.Status != companyInfo.Status {
+		return true
+	}
+	//客户名称
+	if companyReportRecordInfo.CompanyName != companyInfo.CompanyName {
+		return true
+	}
+	//有效开始时间
+	if companyReportRecordInfo.StartDate != companyInfo.StartDate {
+		return true
+	}
+	//有效结束时间
+	if companyReportRecordInfo.EndDate != companyInfo.EndDate {
+		return true
+	}
+	//所属销售
+	if companyReportRecordInfo.SellerId != companyInfo.SellerId {
+		return true
+	}
+	//社会信用码
+	if companyReportRecordInfo.CreditCode != companyInfo.CreditCode {
+		return true
+	}
+
+	return false
+}