xuzhiheng 2 жил өмнө
parent
commit
ee73ac55f7
3 өөрчлөгдсөн 115 нэмэгдсэн , 161 устгасан
  1. 1 61
      clueSync/config.json
  2. 95 91
      clueSync/job.go
  3. 19 9
      clueSync/tag.go

+ 1 - 61
clueSync/config.json

@@ -1,61 +1 @@
-{
-	"cornexp1": "0 */30 * * * ?",
-	"cornexp2": "0 */10 * * * ?",
-	"cornexp3": "0 */5 * * * ?",
-	"cornexp4": "0 0 0 */1 * ? ",
-	"cornexp5": "0 */5 * * * ?",
-	"cornexp6": "0 */10 * * * ?",
-	"lastOrderId": 172463,
-	"lastUserId": "6440f0e37242fb7cbc685b7b",
-	"lastId": "6440faf7bd4ea1862af84c56",
-	"lastOrderTime": "2023-04-23 00:00:00",
-	"lastUserTime": "2023-04-23 00:00:00",
-	"lastSubscribeId": "64473e36c572141d78ec7a03",
-	"countLimit": 1000,
-	"tiDb": {
-		"host": "192.168.3.149",
-		"port": 4000,
-		"database": "jianyu_subjectdb_test",
-		"user": "root",
-		"password": "Tibi#20211222",
-		"poolsize": 20,
-		"maxidle": 40,
-		"maxleft": 40
-	},
-	"baseService": {
-		"host": "192.168.3.217",
-		"port": 4000,
-		"database": "base_service",
-		"user": "root",
-		"password": "=PDT49#80Z!RVv52_z",
-		"poolsize": 20,
-		"maxidle": 40,
-		"maxleft": 40
-	},
-	"mysql": {
-		"host": "192.168.3.149",
-		"port": 3306,
-		"database": "jianyu",
-		"user": "root",
-		"password": "Topnet123",
-		"poolsize": 20,
-		"maxidle": 40,
-		"maxleft": 40
-	},
-	"mgo": {
-		"address": "192.168.3.206:27080",
-		"dbName": "qfw",
-		"dbSize": 20
-	},
-	"mgoLog": {
-		"address": "192.168.3.206:27090",
-		"dbName": "qfw",
-		"dbSize": 20,
-		"user": "admin",
-		"password": "123456"
-	},
-	"es": {
-		"address": "http://192.168.3.206:9800",
-		"dbSize": 20
-	}
-}
+{"cornexp1":"0 */30 * * * ?","cornexp2":"0 */10 * * * ?","cornexp3":"0 */5 * * * ?","cornexp4":"0 0 0 */1 * ? ","cornexp5":"0 */5 * * * ?","cornexp6":"0 */10 * * * ?","lastOrderId":172508,"lastUserId":"644101e58b6d74a60a09aec7","lastId":"6440faf7bd4ea1862af84c56","lastOrderTime":"2023-04-25 00:00:00","lastUserTime":"2023-04-25 00:00:00","lastSubscribeId":"64473e36c572141d78ec7a03","countLimit":1000,"tiDb":{"host":"192.168.3.149","port":4000,"database":"jianyu_subjectdb_test","user":"root","password":"Tibi#20211222","poolsize":20,"maxidle":40,"maxleft":40},"baseService":{"host":"192.168.3.217","port":4000,"database":"base_service","user":"root","password":"=PDT49#80Z!RVv52_z","poolsize":20,"maxidle":40,"maxleft":40},"mysql":{"host":"192.168.3.149","port":3306,"database":"jianyu","user":"root","password":"Topnet123","poolsize":20,"maxidle":40,"maxleft":40},"mgo":{"address":"192.168.3.206:27080","dbName":"qfw","dbSize":20},"mgoLog":{"address":"192.168.3.206:27090","dbName":"qfw","dbSize":20,"user":"admin","password":"123456"},"es":{"address":"http://192.168.3.206:9800","dbSize":20}}

+ 95 - 91
clueSync/job.go

@@ -308,24 +308,17 @@ func UpdateClue(data map[string]interface{}, saleData []map[string]interface{},
 	if oldTaskTime != "" {
 		t1, err := time.Parse("2006-01-02 15:04:05", oldTaskTime)
 		if err == nil && time.Now().Before(t1) {
-			taskTime = oldTaskTime
-		} else {
 			taskTime = nowTime
+		} else {
+			taskTime = oldTaskTime
 		}
 	}
 	clueUpdateData := map[string]interface{}{
-		"is_assign":           1,
-		"updatetime":          nowTime,
-		"cluename":            cluename,
-		"top_cluetype":        top_cluetype,
-		"sub_cluetype":        sub_cluetype,
-		"name":                name,
-		"position":            position,
-		"department":          department,
-		"industry":            industry,
-		"follow_project_area": follow_project_area,
-		"role":                role,
-		"userid":              userId,
+		"is_assign":    1,
+		"updatetime":   nowTime,
+		"top_cluetype": top_cluetype,
+		"sub_cluetype": sub_cluetype,
+		"userid":       userId,
 	}
 	seaUpdateData := map[string]interface{}{
 		"comeinsource": 2,
@@ -345,6 +338,15 @@ func UpdateClue(data map[string]interface{}, saleData []map[string]interface{},
 		"taskstatus":   0,
 		"tasksource":   "线索来源自动更新" + "-" + topname + "-" + subname,
 	}
+	if item != "orders" {
+		clueUpdateData["name"] = name
+		clueUpdateData["position"] = position
+		clueUpdateData["department"] = department
+		clueUpdateData["industry"] = industry
+		clueUpdateData["follow_project_area"] = follow_project_area
+		clueUpdateData["role"] = role
+		clueUpdateData["cluename"] = cluename
+	}
 	if trailstatus == "00" || trailstatus == "01" {
 		clueUpdateData["seatNumber"] = seatNumber
 		clueUpdateData["position_id"] = positionId
@@ -477,83 +479,85 @@ func UpdateClue(data map[string]interface{}, saleData []map[string]interface{},
 				old_subname = common.ObjToString((*pcodeData)["name"])
 			}
 		}
-		if old_name != name {
-			updateId6 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
-				"clue_id":      clueId,
-				"position_id":  common.If(trailstatus == "00" || trailstatus == "01", positionId, common.Int64All(data["position_id"])),
-				"change_field": "name",
-				"change_type":  "基本信息变更",
-				"old_value":    common.If(old_name != "", old_name, "/"),
-				"new_value":    common.If(name != "", name, "/"),
-				"createtime":   nowTime,
-				"BCPCID":       BCPCID,
-				"operator_id":  -1,
-			})
-		}
-		if old_position != position {
-			updateId7 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
-				"clue_id":      clueId,
-				"position_id":  common.If(trailstatus == "00" || trailstatus == "01", positionId, common.Int64All(data["position_id"])),
-				"change_field": "position",
-				"change_type":  "基本信息变更",
-				"old_value":    common.If(old_position != "", old_position, "/"),
-				"new_value":    common.If(position != "", position, "/"),
-				"createtime":   nowTime,
-				"BCPCID":       BCPCID,
-				"operator_id":  -1,
-			})
-		}
-		if old_department != department {
-			updateId8 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
-				"clue_id":      clueId,
-				"position_id":  common.If(trailstatus == "00" || trailstatus == "01", positionId, common.Int64All(data["position_id"])),
-				"change_field": "department",
-				"change_type":  "基本信息变更",
-				"old_value":    common.If(old_department != "", old_department, "/"),
-				"new_value":    common.If(department != "", department, "/"),
-				"createtime":   nowTime,
-				"BCPCID":       BCPCID,
-				"operator_id":  -1,
-			})
-		}
-		if old_role != role {
-			updateId9 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
-				"clue_id":      clueId,
-				"position_id":  common.If(trailstatus == "00" || trailstatus == "01", positionId, common.Int64All(data["position_id"])),
-				"change_field": "role",
-				"change_type":  "基本信息变更",
-				"old_value":    common.If(old_role != "", old_role, "/"),
-				"new_value":    common.If(role != "", role, "/"),
-				"createtime":   nowTime,
-				"BCPCID":       BCPCID,
-				"operator_id":  -1,
-			})
-		}
-		if old_follow_project_area != follow_project_area {
-			updateId10 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
-				"clue_id":      clueId,
-				"position_id":  common.If(trailstatus == "00" || trailstatus == "01", positionId, common.Int64All(data["position_id"])),
-				"change_field": "follow_project_area",
-				"change_type":  "基本信息变更",
-				"old_value":    common.If(old_follow_project_area != "", old_follow_project_area, "/"),
-				"new_value":    common.If(follow_project_area != "", follow_project_area, "/"),
-				"createtime":   nowTime,
-				"BCPCID":       BCPCID,
-				"operator_id":  -1,
-			})
-		}
-		if old_cluename != cluename {
-			updateId11 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
-				"clue_id":      clueId,
-				"position_id":  common.If(trailstatus == "00" || trailstatus == "01", positionId, common.Int64All(data["position_id"])),
-				"change_field": "cluename",
-				"change_type":  "基本信息变更",
-				"old_value":    common.If(old_cluename != "", old_cluename, "/"),
-				"new_value":    common.If(cluename != "", cluename, "/"),
-				"createtime":   nowTime,
-				"BCPCID":       BCPCID,
-				"operator_id":  -1,
-			})
+		if item != "orders" {
+			if old_name != name {
+				updateId6 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
+					"clue_id":      clueId,
+					"position_id":  common.If(trailstatus == "00" || trailstatus == "01", positionId, common.Int64All(data["position_id"])),
+					"change_field": "name",
+					"change_type":  "基本信息变更",
+					"old_value":    common.If(old_name != "", old_name, "/"),
+					"new_value":    common.If(name != "", name, "/"),
+					"createtime":   nowTime,
+					"BCPCID":       BCPCID,
+					"operator_id":  -1,
+				})
+			}
+			if old_position != position {
+				updateId7 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
+					"clue_id":      clueId,
+					"position_id":  common.If(trailstatus == "00" || trailstatus == "01", positionId, common.Int64All(data["position_id"])),
+					"change_field": "position",
+					"change_type":  "基本信息变更",
+					"old_value":    common.If(old_position != "", old_position, "/"),
+					"new_value":    common.If(position != "", position, "/"),
+					"createtime":   nowTime,
+					"BCPCID":       BCPCID,
+					"operator_id":  -1,
+				})
+			}
+			if old_department != department {
+				updateId8 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
+					"clue_id":      clueId,
+					"position_id":  common.If(trailstatus == "00" || trailstatus == "01", positionId, common.Int64All(data["position_id"])),
+					"change_field": "department",
+					"change_type":  "基本信息变更",
+					"old_value":    common.If(old_department != "", old_department, "/"),
+					"new_value":    common.If(department != "", department, "/"),
+					"createtime":   nowTime,
+					"BCPCID":       BCPCID,
+					"operator_id":  -1,
+				})
+			}
+			if old_role != role {
+				updateId9 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
+					"clue_id":      clueId,
+					"position_id":  common.If(trailstatus == "00" || trailstatus == "01", positionId, common.Int64All(data["position_id"])),
+					"change_field": "role",
+					"change_type":  "基本信息变更",
+					"old_value":    common.If(old_role != "", old_role, "/"),
+					"new_value":    common.If(role != "", role, "/"),
+					"createtime":   nowTime,
+					"BCPCID":       BCPCID,
+					"operator_id":  -1,
+				})
+			}
+			if old_follow_project_area != follow_project_area {
+				updateId10 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
+					"clue_id":      clueId,
+					"position_id":  common.If(trailstatus == "00" || trailstatus == "01", positionId, common.Int64All(data["position_id"])),
+					"change_field": "follow_project_area",
+					"change_type":  "基本信息变更",
+					"old_value":    common.If(old_follow_project_area != "", old_follow_project_area, "/"),
+					"new_value":    common.If(follow_project_area != "", follow_project_area, "/"),
+					"createtime":   nowTime,
+					"BCPCID":       BCPCID,
+					"operator_id":  -1,
+				})
+			}
+			if old_cluename != cluename {
+				updateId11 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
+					"clue_id":      clueId,
+					"position_id":  common.If(trailstatus == "00" || trailstatus == "01", positionId, common.Int64All(data["position_id"])),
+					"change_field": "cluename",
+					"change_type":  "基本信息变更",
+					"old_value":    common.If(old_cluename != "", old_cluename, "/"),
+					"new_value":    common.If(cluename != "", cluename, "/"),
+					"createtime":   nowTime,
+					"BCPCID":       BCPCID,
+					"operator_id":  -1,
+				})
+			}
 		}
 		if old_top_cluetype != top_cluetype {
 			updateId12 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{

+ 19 - 9
clueSync/tag.go

@@ -167,11 +167,13 @@ func tagAddSync() {
 			userId := common.ObjToString(v["userid"])
 			uId := common.ObjToString(v["uid"])
 			if registedate == "" || uId == "" || userId == "" {
-				log.Println("缺少信息")
-				return
+				log.Println("缺少信息", uId, userId)
+				continue
+			} else {
+				log.Println("新注册", uId, userId)
 			}
 			if k == len(*userData)-1 {
-				cfg.LastOrderTime = updatetime
+				cfg.LastUserTime = updatetime
 			}
 			if TiDb.Count("dwd_f_crm_attribute_label", map[string]interface{}{"uid": uId}) > 0 {
 				TiDb.Update("dwd_f_crm_attribute_label", map[string]interface{}{"uid": uId}, map[string]interface{}{
@@ -187,25 +189,32 @@ func tagAddSync() {
 			}
 		}
 	}
-	orderData := TiDb.SelectBySql(`select product_type,autoUpdate,uid from dwd_f_userbase_order_info where order_status = 1 and autoUpdate >= "` + cfg.LastOrderTime + `"`)
+	log.Println("注册日期定时任务结束")
+	orderData := TiDb.SelectBySql(`select product_type,autoUpdate,uid from dwd_f_userbase_order_info where order_status = 1 and autoUpdate >= "` + cfg.LastOrderTime + `" order by autoUpdate desc`)
 	if orderData != nil && len(*orderData) > 0 {
-		for k, vv := range *orderData {
+		for k, order := range *orderData {
 			nowTime := time.Now().Format("2006-01-02 15:04:05")
-			autoUpdate := common.ObjToString(vv["autoUpdate"])
-			uId := common.ObjToString(vv["uid"])
+			autoUpdate := common.ObjToString(order["autoUpdate"])
+			uId := common.ObjToString(order["uid"])
+			if uId == "" {
+				log.Println("缺少信息")
+				continue
+			}
 			product_types := ""
-			if k == len(*userData)-1 {
+			if k == 0 {
 				cfg.LastOrderTime = autoUpdate
 			}
 			orderDatas := TiDb.Find("dwd_f_userbase_order_info", map[string]interface{}{"uid": uId, "order_status": 1, "delete_status": 0}, "", "", -1, -1)
 			if orderDatas != nil && len(*orderDatas) > 0 {
 				product_type_arr, product_type_arrs := []string{}, []string{}
-				for _, v := range *orderData {
+				for _, v := range *orderDatas {
 					product_type := common.ObjToString(v["product_type"])
+					log.Println("product_type ", product_type)
 					if product_type != "" {
 						product_type_arr = append(product_type_arr, product_type)
 					}
 				}
+				log.Println("product_type_arr ", product_type_arr)
 				for _, v := range product_type_arr {
 					isOk := false
 					for _, vv := range product_type_arrs {
@@ -219,6 +228,7 @@ func tagAddSync() {
 				}
 				product_types = strings.Join(product_type_arrs, ",")
 			}
+			log.Println("product_types ", uId, product_types)
 			if TiDb.Count("dwd_f_crm_attribute_label", map[string]interface{}{"uid": uId}) > 0 {
 				TiDb.Update("dwd_f_crm_attribute_label", map[string]interface{}{"uid": uId}, map[string]interface{}{
 					"product_type": product_types,