Browse Source

解冻处理

WH01243 1 year ago
parent
commit
ea4e056815
1 changed files with 39 additions and 30 deletions
  1. 39 30
      clueSync/autoTask.go

+ 39 - 30
clueSync/autoTask.go

@@ -389,7 +389,6 @@ func Thaw() {
 		if k == 0 {
 			break
 		}
-
 		nowTime = nowTime.AddDate(0, 0, -1)
 
 		if !IsBreak(nowTime) {
@@ -407,22 +406,32 @@ func Thaw() {
 	}
 	//查询
 	fmt.Println()
+	layout := "2006-01-02 15:04:05"
+	//三天以后退公海处理
 	TiDb.SelectByBath(100, func(l *[]map[string]interface{}) bool {
 		for _, v := range *l {
 			clueId := gconv.Int64(v["id"])
 			positionId := gconv.Int64(v["position_id"])
-			if !FindUpperLimit(gconv.String(positionId), "positionId") {
-				//退公海处理
+			freezeInt64 := int64(0)
+			freezeStr := gconv.String(v["FREEZE_TIME"])
+			if freezeStr != "" {
+				t, _ := time.Parse(layout, freezeStr)
+				freezeInt64 = t.Unix()
+			}
+			if freezeInt64 < nowTime.Unix() {
+				//超三天处理
+				//分配状态改改
 				if TiDb.Update("dwd_f_crm_clue_info", map[string]interface{}{"id": clueId}, map[string]interface{}{
-					"is_assign": 1,
+					"is_assign":   0,
+					"position_id": 0,
 				}) {
 					TiDb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
 						"clue_id":      clueId,
-						"position_id":  positionId,
+						"position_id":  0,
 						"change_field": "position_id",
 						"change_type":  "所属人变更",
-						"old_value":    "/",
-						"new_value":    nameMap[positionId],
+						"old_value":    nameMap[positionId],
+						"new_value":    "/",
 						"createtime":   nowTime,
 						"BCPCID":       common.GetRandom(32),
 						"operator_id":  -1,
@@ -430,47 +439,47 @@ func Thaw() {
 				}
 				TiDb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
 					"clue_id":      clueId,
-					"position_id":  positionId,
+					"position_id":  0,
 					"change_field": "position_id",
 					"change_type":  "线索解冻",
-					"new_value":    "销售人员私海线索已释放",
+					"new_value":    "自动退回公海",
 					"createtime":   nowTime,
 					"BCPCID":       common.GetRandom(32),
 					"operator_id":  -1,
 				})
 			} else {
-				//分配状态改改
-				if TiDb.Update("dwd_f_crm_clue_info", map[string]interface{}{"id": clueId}, map[string]interface{}{
-					"is_assign":   0,
-					"position_id": 0,
-				}) {
+				fmt.Println(FindUpperLimit(gconv.String(positionId), "positionId"))
+				if !FindUpperLimit(gconv.String(positionId), "positionId") {
+					if TiDb.Update("dwd_f_crm_clue_info", map[string]interface{}{"id": clueId}, map[string]interface{}{
+						"is_assign": 1,
+					}) {
+						TiDb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
+							"clue_id":      clueId,
+							"position_id":  positionId,
+							"change_field": "position_id",
+							"change_type":  "所属人变更",
+							"old_value":    "/",
+							"new_value":    nameMap[positionId],
+							"createtime":   nowTime,
+							"BCPCID":       common.GetRandom(32),
+							"operator_id":  -1,
+						})
+					}
 					TiDb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
 						"clue_id":      clueId,
-						"position_id":  0,
+						"position_id":  positionId,
 						"change_field": "position_id",
-						"change_type":  "所属人变更",
-						"old_value":    nameMap[positionId],
-						"new_value":    "/",
+						"change_type":  "线索解冻",
+						"new_value":    "销售人员私海线索已释放",
 						"createtime":   nowTime,
 						"BCPCID":       common.GetRandom(32),
 						"operator_id":  -1,
 					})
 				}
-				TiDb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
-					"clue_id":      clueId,
-					"position_id":  0,
-					"change_field": "position_id",
-					"change_type":  "线索解冻",
-					"new_value":    "自动退回公海",
-					"createtime":   nowTime,
-					"BCPCID":       common.GetRandom(32),
-					"operator_id":  -1,
-				})
 			}
-
 		}
 		return true
-	}, `select id,position_id from dwd_f_crm_clue_info where is_assign = -3 and FREEZE_TIME<=? `, nowTime.Format(date.Date_Full_Layout))
+	}, `select id,position_id,FREEZE_TIME from dwd_f_crm_clue_info where is_assign = -3 `)
 }
 func IsBreak(currentTime time.Time) bool {
 	if currentTime.Weekday() == time.Sunday {