Эх сурвалжийг харах

Merge branch 'crm_15.9' of http://8.136.199.33:3000/hongze/hongze_cygx into debug

xingzai 8 сар өмнө
parent
commit
c9ae3ac5c5

+ 29 - 8
models/rai_serve/rai_serve_company.go

@@ -2,6 +2,7 @@ package rai_serve
 
 import (
 	"github.com/beego/beego/v2/client/orm"
+	"hongze/hongze_cygx/utils"
 	"time"
 )
 
@@ -25,7 +26,7 @@ type CygxRaiServeCompany struct {
 	IsUserMaker       int       `comment:"近四周之内是否包含决策人 ,1是、0否"`
 }
 
-func AddCygxRaiServeCompanyMulti(items []*CygxRaiServeCompany) (err error) {
+func AddCygxRaiServeCompanyMulti(items, itemsUpdate []*CygxRaiServeCompany, delCompanyIds []int) (err error) {
 	o, err := orm.NewOrm().Begin()
 	if err != nil {
 		return
@@ -38,19 +39,39 @@ func AddCygxRaiServeCompanyMulti(items []*CygxRaiServeCompany) (err error) {
 		}
 	}()
 
-	//if len(deleteCompanyIds) > 0 {
-	//删除不属于权益共享的公司
-	sql := ` DELETE FROM cygx_rai_serve_company  `
-	_, err = o.Raw(sql).Exec()
-	if err != nil {
-		return
+	if len(delCompanyIds) > 0 {
+		//删除不属于权益共享的公司
+		sql := ` DELETE FROM cygx_rai_serve_company WHERE company_id IN (` + utils.GetOrmInReplace(len(delCompanyIds)) + `)  `
+		_, err = o.Raw(sql, delCompanyIds).Exec()
+		if err != nil {
+			return
+		}
 	}
-	//}
 
 	//批量插入新的关联数据
 	if len(items) > 0 {
 		//批量添加流水信息
 		_, err = o.InsertMulti(len(items), items)
+		if err != nil {
+			return
+		}
+	}
+
+	if len(itemsUpdate) > 0 {
+		p, errUpdate := o.Raw("UPDATE cygx_rai_serve_company SET company_name = ? ,seller_id =? ,seller_name = ?  ,start_date = ? ,end_date = ? ,share_seller = ? ,share_seller_id = ? ,share_group_id = ?  WHERE company_id = ?").Prepare()
+		if errUpdate != nil {
+			err = errUpdate
+			return
+		}
+		defer func() {
+			_ = p.Close() // 别忘记关闭 statement
+		}()
+		for _, v := range items {
+			_, err = p.Exec(v.CompanyName, v.SellerId, v.SellerName, v.StartDate, v.EndDate, v.ShareSeller, v.ShareSellerId, v.ShareGroupId, v.CompanyId)
+			if err != nil {
+				return
+			}
+		}
 	}
 
 	return

+ 41 - 6
services/rai_serve_count.go

@@ -56,14 +56,22 @@ func UpdateRaiServeBillDate(cont context.Context) (err error) {
 			go utils.SendAlarmMsg(fmt.Sprint("定时任务处理权益服务公司 失败 UpdateRaiServeBillDate  ,err:", err.Error()), 2)
 		}
 	}()
+
+	err = UpdateRaiServeCompany() // 处理共享机构信息
+	if err != nil {
+		return
+	}
+
 	err = UpdateCygxRaiServeBillByCompanyIds() // 处理个人流水记录
 	if err != nil {
 		return
 	}
+
 	err = UpdateCygxRaiServeBillWeekTask() // 更新周度服务明细
 	if err != nil {
 		return
 	}
+
 	err = UpdateWeekAvg() //更新最近四周平均覆盖率,是否标红,权限,时间,金额
 	if err != nil {
 		return
@@ -90,12 +98,29 @@ func UpdateRaiServeCompany() (err error) {
 		return
 	}
 
+	raiServeCompanyList, e := rai_serve.GetCygxRaiServeCompanyAllList()
+	if e != nil {
+		err = errors.New("GetCygxRaiServeCompanyAllList, Err: " + e.Error())
+		return
+	}
+
+	mapOLdCompany := make(map[int]bool)
+	mapOLdCompanyDate := make(map[int]string)
+	for _, v := range raiServeCompanyList {
+		mapOLdCompany[v.CompanyId] = true
+		mapOLdCompanyDate[v.CompanyId] = fmt.Sprint(v.CompanyId, v.CompanyName, v.SellerId, v.StartDate, v.EndDate, v.ShareSeller, v.ShareSellerId, v.Status, v.GroupId, v.ShareGroupId)
+	}
+
+	var delCompanyIds []int // 需要删除的公司ID
+	for _, v := range listCompanyProduct {
+		if !mapOLdCompany[v.CompanyId] {
+			delCompanyIds = append(delCompanyIds, v.CompanyId)
+		}
+	}
+
 	var items []*rai_serve.CygxRaiServeCompany
+	var itemsUpadte []*rai_serve.CygxRaiServeCompany
 	for _, v := range listCompanyProduct {
-		//mapNewCompanyId[v.CompanyId] = true
-		//if mapOldCompanyId[v.CompanyId] {
-		//	continue
-		//}
 		item := new(rai_serve.CygxRaiServeCompany)
 		item.CompanyId = v.CompanyId
 		item.CompanyName = v.CompanyName
@@ -109,11 +134,21 @@ func UpdateRaiServeCompany() (err error) {
 		item.Status = v.Status
 		item.GroupId = v.GroupId
 		item.ShareGroupId = v.ShareGroupId
-		items = append(items, item)
+		if !mapOLdCompany[v.CompanyId] {
+			items = append(items, item) // 如果原有数据不存在就新增
+		} else {
+			if mapOLdCompanyDate[v.CompanyId] != fmt.Sprint(v.CompanyId, v.CompanyName, v.SellerId, v.StartDate, v.EndDate, v.ShareSeller, v.ShareSellerId, v.Status, v.GroupId, v.ShareGroupId) {
+				itemsUpadte = append(itemsUpadte, item) // 新老数据不一致就进行修改
+			}
+		}
 	}
 
+	fmt.Println("items", len(items))
+	fmt.Println("itemsUpadte", len(itemsUpadte))
+	fmt.Println("delCompanyIds", len(delCompanyIds))
+
 	//先删除老的再添加新的
-	e = rai_serve.AddCygxRaiServeCompanyMulti(items)
+	e = rai_serve.AddCygxRaiServeCompanyMulti(items, itemsUpadte, delCompanyIds)
 	if e != nil {
 		err = errors.New("AddCygxRaiServeCompanyMulti, Err: " + e.Error())
 		return

+ 2 - 2
services/task.go

@@ -156,8 +156,8 @@ func Task() {
 		getYanxuanSpecialLikeCountDifferent := task.NewTask("getYanxuanSpecialLikeCountDifferent", "0 0 */1 * * *", GetYanxuanSpecialLikeCountDifferent)
 		task.AddTask("定时任务处理退款回调", getYanxuanSpecialLikeCountDifferent) //定时任务处理退款回调
 
-		updateRaiServeCompanyDate := task.NewTask("updateRaiServeCompanyDate", "0 0 1 * * *", UpdateRaiServeCompanyDate)
-		task.AddTask("定时任务处理权益服务公司", updateRaiServeCompanyDate) //定时任务处理权益服务公司
+		//updateRaiServeCompanyDate := task.NewTask("updateRaiServeCompanyDate", "0 0 1 * * *", UpdateRaiServeCompanyDate)
+		//task.AddTask("定时任务处理权益服务公司", updateRaiServeCompanyDate) //定时任务处理权益服务公司
 
 		updateRaiServeBillDate := task.NewTask("updateRaiServeBillDate", "0 */10 * * * *", UpdateRaiServeBillDate)
 		task.AddTask("定时任务处理权益服务记录明细", updateRaiServeBillDate) //定时任务处理权益服务记录明细