소스 검색

自动分配处理

WH01243 1 년 전
부모
커밋
5eb599b1cb
4개의 변경된 파일60개의 추가작업 그리고 335개의 파일을 삭제
  1. 12 10
      clueSync/config.go
  2. 0 151
      clueSync/config.json
  3. 1 0
      clueSync/job.go
  4. 47 174
      clueSync/jobutil.go

+ 12 - 10
clueSync/config.go

@@ -138,16 +138,18 @@ type (
 			UserName string `json:"user	Name"`
 			Password string `json:"password"`
 		} `json:"es"`
-		AllocationCap  int64             `json:"allocationCap"`
-		WarningValue   int64             `json:"warningValue"`
-		NameToMail     map[string]string `json:"nameToMail"`
-		ThawDay        int64             `json:"thawDay"`
-		ProductArr     []string          `json:"productArr"`
-		LoopType       int64             `json:"loopType"`
-		BigSaleTime    int64             `json:"bigSaleTime"`
-		BigOrderTime   string            `json:"bigOrderTime"`
-		MarketSaleTime int64             `json:"marketSaleTime"`
-		MarketSaleMail string            `json:"marketSaleMail"`
+		AllocationCap   int64             `json:"allocationCap"`
+		WarningValue    int64             `json:"warningValue"`
+		NameToMail      map[string]string `json:"nameToMail"`
+		ThawDay         int64             `json:"thawDay"`
+		ProductArr      []string          `json:"productArr"`
+		LoopType        int64             `json:"loopType"`
+		BigSaleTime     int64             `json:"bigSaleTime"`
+		BigOrderTime    string            `json:"bigOrderTime"`
+		MarketSaleTime  int64             `json:"marketSaleTime"`
+		MarketSaleMail  string            `json:"marketSaleMail"`
+		AllocationTime  string            `json:"allocationTime"`
+		AllocationRatio float64           `json:"allocationRatio"`
 	}
 )
 

파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
+ 0 - 151
clueSync/config.json


+ 1 - 0
clueSync/job.go

@@ -849,6 +849,7 @@ func UpdateClue(data map[string]interface{}, saleData []map[string]interface{},
 		//变更记录
 		if (trailstatus == "00" || old_position_id == 0 || (pIsOk && old_cluename != cluename && cluename != "")) && is_assign == 1 {
 			if trailstatus == "00" && trailstatusTime != "" && time.Now().Unix()-trailstatusTimes.Unix() < 86400 {
+
 			} else if old_position_id == 0 {
 				updateId1 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
 					"clue_id":      clueId,

+ 47 - 174
clueSync/jobutil.go

@@ -4,6 +4,7 @@ import (
 	"app.yhyue.com/moapp/jybase/redis"
 	"fmt"
 	"log"
+	"math"
 	"strings"
 	"time"
 
@@ -111,14 +112,14 @@ func WorkDataHandle(company, phone, demand, name, product string, acceptanceData
 		} else {
 			if positionId == 0 {
 				//线索变更
-				ok, data, saleData = FindPosition(0, "")
+				ok, data, saleData = FindPosition(0, "", gconv.String(acceptanceData["creator_time"]))
 				if !ok {
 					log.Println(positionId, "用户查询失败")
 					return false
 				}
 				UpdateClue(*uCount, saleData, "", "", uId, "5", "169", "新增线索", "主动咨询客服留资客户", company, name, gconv.String(data["name"]), phone, "", "", "", "", "", "", gconv.String(data["seat_number"]), "", gconv.Int64(data["position_id"]), "", "", "", []string{}, "", isGroup, isCommerce, true, demand)
 			} else {
-				ok, data, saleData = FindPosition(positionId, trailstatus)
+				ok, data, saleData = FindPosition(positionId, trailstatus, gconv.String(acceptanceData["creator_time"]))
 				if !ok {
 					log.Println(positionId, "用户查询失败")
 					return false
@@ -133,7 +134,7 @@ func WorkDataHandle(company, phone, demand, name, product string, acceptanceData
 		}
 	} else {
 		//新增线索
-		ok, data, _ = FindPosition(0, "")
+		ok, data, _ = FindPosition(0, "", gconv.String(acceptanceData["creator_time"]))
 		if !ok {
 			return false
 		}
@@ -212,6 +213,9 @@ func AddOrderWork(acceptanceData map[string]interface{}, userData map[string]int
 			"is_delete":           1,
 			"creator_time":        nowTime,
 			"handle_time":         common.If(gconv.Int64(userData["orderStatus"]) == 0, nowTime, nil),
+			"update_name":         common.If(gconv.Int64(userData["orderStatus"]) == 0, userData["name"], nil),
+			"update_position_id":  common.If(gconv.Int64(userData["orderStatus"]) == 0, userData["position_id"], nil),
+			"update_time":         common.If(gconv.Int64(userData["orderStatus"]) == 0, nowTime, nil),
 		}
 		WorkOrder.Insert("approval_record", approvalRecordMap)
 		WorkMail(personMap,
@@ -308,154 +312,38 @@ func FindNumber(moudle string) string {
 }
 
 // 人员查询
-func FindPosition(positionId int64, trailstatus string) (bool, map[string]interface{}, []map[string]interface{}) {
-	allData := []map[string]interface{}{}
-	//查询两个部门高级管理员
-	//查询两个部门所有人员标识
-	//电销三部
-	userData1 := TiDb.SelectBySql(`SELECT
-	a.position_id,
-	a.name,
-	b.seat_number
-FROM
-	dwd_d_crm_department_level_succbi a
-	INNER JOIN dwd_f_crm_personnel_management b ON a.resign = 0 and b.resign = 0
-	AND a.ent_id = 25917
-	AND a.dept_name LIKE "%电销部%"
-	AND a.position_id = b.position_id`)
-	userData3 := TiDb.SelectBySql(`SELECT
-	a.position_id,
-	a.name,
-	b.seat_number
-FROM
-	dwd_d_crm_department_level_succbi a
-	INNER JOIN dwd_f_crm_personnel_management b ON a.resign = 0 and b.resign = 0
-	AND a.ent_id = 25917
-	AND a.resign = 0
-	AND a.dept_name LIKE "%销售三部"
-	AND a.position_id = b.position_id`)
-	if userData3 == nil || len(*userData3) == 0 || userData1 == nil || len(*userData1) == 0 {
-		return false, map[string]interface{}{}, allData
-	}
-	//一部管理员信息
-	administrators1 := map[string]interface{}{}
-	//三部管理员信息
-	administrators3 := map[string]interface{}{}
-	//返回当前人信息
-	administrators := map[string]interface{}{}
-	//电销一部
-	positionIdArr1 := []string{}
-	positionIdArr3 := []string{}
-	proportion1 := float64(0)
-	proportion3 := float64(0)
-	for _, v := range *userData3 {
-		v["type"] = 3
-		personName := gconv.String(v["name"])
-		id := gconv.Int64(v["position_id"])
-		if id == positionId {
-			if personName == "孙鹏" {
-				v["orderStatus"] = 2
-			}
-			administrators = v
-		}
-		if personName == "孙鹏" {
-			v["orderStatus"] = 2
-			administrators3 = v
-			proportion3 += 0.5
-		} else {
-			proportion3 += 1
-		}
-		positionIdArr3 = append(positionIdArr3, gconv.String(id))
-		allData = append(allData, v)
-	}
-	for _, v := range *userData1 {
-		v["type"] = 1
-		personName := gconv.String(v["name"])
-		id := gconv.Int64(v["position_id"])
-		if id == positionId {
-			if personName == "沈炳毅" {
-				v["orderStatus"] = 2
-			}
-			administrators = v
-		}
-		if personName == "沈炳毅" {
-			v["orderStatus"] = 2
-			administrators1 = v
-			proportion1 += 0.5
-		} else {
-			proportion1 += 1
-		}
-		positionIdArr1 = append(positionIdArr1, gconv.String(id))
-		allData = append(allData, v)
-	}
-	if positionId != 0 {
-		if administrators == nil || len(administrators) == 0 {
-			return false, map[string]interface{}{}, allData
-		}
-		positiontype := gconv.Int64(administrators["type"])
-		if trailstatus == "01" || trailstatus == "03" || trailstatus == "04" {
-			switch positiontype {
-			case 1:
-				//找他上级
-				administrators = administrators1
-			case 3:
-				//找他上级
-				administrators = administrators3
-			}
-			return true, administrators, allData
-		} else {
-			return true, administrators, allData
-		}
-	}
-	//按照比例分配选择一部还是三部
-	//一部查询
-	deptCount1 := CalculateProportion1(strings.Join(positionIdArr1, ","))
-	//三部查询
-	deptCount3 := CalculateProportion1(strings.Join(positionIdArr3, ","))
+func GetAllocation(proportion1, proportion3 float64, deptCount1, deptCount3 int64, administrators1, administrators3 map[string]interface{}, creatorTime string) map[string]interface{} {
+	log.Println("分配比例查询", proportion1, proportion3, deptCount1, deptCount3)
 	if deptCount1 == 0 {
-		return true, administrators1, allData
+		return administrators1
 	}
 	if deptCount3 == 0 {
-		return true, administrators3, allData
+		return administrators3
 	}
-	if deptCount1/deptCount3 > proportion1/proportion3 {
-		return true, administrators3, allData
+	nowAllocationRatio := math.Round(gconv.Float64(deptCount1 / deptCount3))
+	if cfg.AllocationRatio == 0 {
+		//重新计算
+		cfg.AllocationRatio = math.Round(proportion1 / proportion3)
+		cfg.AllocationTime = creatorTime
+		common.WriteSysConfig(&cfg)
+		log.Println("新增计算比例", cfg.AllocationRatio)
 	} else {
-		return true, administrators1, allData
-	}
-	log.Println("电销信息获取失败", positionId)
-	return false, map[string]interface{}{}, allData
-}
-func CalculateProportion1(positionIsStr string) float64 {
-	createtime := time.Time{}
-	now := time.Now()
-	weekday := int(now.Weekday())
-	if weekday == 0 { // 如果是周日,则将其视为本周的最后一天
-		weekday = 7
-	}
-	switch cfg.LoopType {
-	case 1: //周
-		createtime = now.AddDate(0, 0, -weekday+1)
-	case 2: //月
-		createtime = time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, time.Local)
+		if nowAllocationRatio == cfg.AllocationRatio {
+			//重新计算
+			cfg.AllocationRatio = math.Round(proportion1 / proportion3)
+			cfg.AllocationTime = creatorTime
+			common.WriteSysConfig(&cfg)
+		}
 	}
-	count := float64(0)
-	sql := `SELECT
-			sum(1) as  count
-		FROM
-			order_work 
-		WHERE
-			  FIND_IN_SET(current_position_id ,?) 
-			AND is_delete=1
-			and   creator_time>?`
-	data := WorkOrder.SelectBySql(sql, positionIsStr, createtime.Format("2006-01-02"))
-	if data != nil && len(*data) > 0 {
-		count = gconv.Float64((*data)[0]["count"])
+	if nowAllocationRatio > cfg.AllocationRatio {
+		return administrators3
+	} else {
+		return administrators1
 	}
-	return count
-}
+	//达到比例也重新计算
 
-func FindPosition1(positionId int64, trailstatus string) (bool, map[string]interface{}, []map[string]interface{}) {
+}
+func FindPosition(positionId int64, trailstatus, creatorTime string) (bool, map[string]interface{}, []map[string]interface{}) {
 	allData := []map[string]interface{}{}
 	//查询两个部门高级管理员
 	//查询两个部门所有人员标识
@@ -504,9 +392,6 @@ FROM
 		id := gconv.Int64(v["position_id"])
 		roleId := gconv.Int64(v["role_id"])
 		if id == positionId {
-			if roleId == 8 {
-				v["orderStatus"] = 2
-			}
 			administrators = v
 		}
 		if roleId == 8 {
@@ -525,9 +410,6 @@ FROM
 		id := gconv.Int64(v["position_id"])
 		roleId := gconv.Int64(v["role_id"])
 		if id == positionId {
-			if roleId == 8 {
-				v["orderStatus"] = 2
-			}
 			administrators = v
 		}
 		if roleId == 8 {
@@ -565,45 +447,36 @@ FROM
 	deptCount1 := CalculateProportion(deptNameMap1)
 	//三部查询
 	deptCount3 := CalculateProportion(deptNameMap3)
-	if deptCount1 == 0 {
-		return true, administrators1, allData
-	}
-	if deptCount3 == 0 {
-		return true, administrators3, allData
-	}
-	if deptCount1/deptCount3 > proportion1/proportion3 {
-		return true, administrators3, allData
-	} else {
-		return true, administrators1, allData
-	}
+	return true, GetAllocation(proportion1, proportion3, deptCount1, deptCount3, administrators1, administrators3, creatorTime), allData
 	log.Println("电销信息获取失败", positionId)
 	return false, map[string]interface{}{}, allData
 }
 
-func CalculateProportion(deptNameMap map[string]interface{}) float64 {
+func CalculateProportion(deptNameMap map[string]interface{}) int64 {
 	deptNameStr := ""
 	for k := range deptNameMap {
 		if deptNameStr == "" {
 			deptNameStr = k
 		} else {
-			deptNameStr = fmt.Sprintf("%s%s", deptNameStr, k)
+			deptNameStr = fmt.Sprintf("%s,%s", deptNameStr, k)
 		}
 	}
 	if deptNameStr == "" {
-		return float64(0)
+		return int64(0)
 	}
-	count := float64(0)
-	sql := `SELECT
-			sum(1) as  count
-		FROM
-			order_work 
-		WHERE
-			  FIND_IN_SET(current_position_id ,?) 
-			AND is_delete=1
-			and   creator_time>?`
-	data := WorkOrder.SelectBySql(sql, "")
+	count := int64(0)
+	sql := fmt.Sprintf(`SELECT
+	sum(1) as  count
+FROM
+	order_work a
+	INNER JOIN approval_record b ON a.creator_time > "%s" 
+	AND FIND_IN_SET( a.department_no ,  "%s") 
+	AND a.work_order_no = b.work_order_no
+	and  (b.new_status!= 1 or  b.new_status   is null )
+	`, cfg.AllocationTime, deptNameStr)
+	data := WorkOrder.SelectBySql(sql)
 	if data != nil && len(*data) > 0 {
-		count = gconv.Float64((*data)[0]["count"])
+		count = gconv.Int64((*data)[0]["count"])
 	}
 	return count
 }

이 변경점에서 너무 많은 파일들이 변경되어 몇몇 파일들은 표시되지 않았습니다.