Browse Source

完善程序,分割日志

xuzhiheng 2 years ago
parent
commit
8b564f9af3
7 changed files with 189 additions and 46 deletions
  1. 1 0
      clueSync/config.go
  2. 1 0
      clueSync/config.json
  3. 4 0
      clueSync/go.mod
  4. 11 0
      clueSync/go.sum
  5. 96 46
      clueSync/job.go
  6. 73 0
      clueSync/log.go
  7. 3 0
      clueSync/main.go

+ 1 - 0
clueSync/config.go

@@ -23,6 +23,7 @@ type (
 		LastSubscribeId string `json:"lastSubscribeId"`
 		XlsxNum         string `json:"xlsxNum"`
 		CountLimit      int64  `json:"countLimit"`
+		RedisServer     string `json:"redisServer"`
 		TiDb            struct {
 			Host        string `json:"host"`
 			Port        int    `json:"port"`

+ 1 - 0
clueSync/config.json

@@ -14,6 +14,7 @@
 	"lastSubscribeId": "64473e36c572141d78ec7a03",
 	"countLimit": 1000,
 	"xlsxNum": "1",
+	"redisServer":"192.168.3.206:1712",
 	"tiDb": {
 		"host": "192.168.3.217",
 		"port": 4000,

+ 4 - 0
clueSync/go.mod

@@ -5,6 +5,10 @@ go 1.14
 require (
 	app.yhyue.com/moapp/jybase v0.0.0-20230405040249-a36a23595798
 	app.yhyue.com/zhp/util v0.0.0-20211207072713-d9f1393203de
+	github.com/go-xweb/httpsession v0.0.0-20141220075701-356d3b4d38d6 // indirect
+	github.com/go-xweb/log v0.0.0-20140701090824-270d183ad77e // indirect
+	github.com/go-xweb/uuid v0.0.0-20140604020037-d7dce341f851 // indirect
+	github.com/go-xweb/xweb v0.2.1
 	github.com/nsqio/go-nsq v1.1.0
 	github.com/robfig/cron v1.2.0
 	github.com/tealeg/xlsx v1.0.5

+ 11 - 0
clueSync/go.sum

@@ -121,6 +121,7 @@ github.com/fortytw2/leaktest v1.3.0/go.mod h1:jDsjWgpAGjm2CA7WthBh/CdZYEPF31XHqu
 github.com/frankban/quicktest v1.11.3/go.mod h1:wRf/ReqHper53s+kmmSZizM8NamnL3IM0I9ntUbOk+k=
 github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
 github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
+github.com/garyburd/redigo v1.6.2 h1:yE/pwKCrbLpLpQICzYTeZ7JsTA/C53wFTJHaEtRqniM=
 github.com/garyburd/redigo v1.6.2/go.mod h1:NR3MbYisc3/PwhQ00EMzDiPmrwpPxAn5GI05/YaO1SY=
 github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
 github.com/globalsign/mgo v0.0.0-20181015135952-eeefdecb41b8/go.mod h1:xkRDCp4j0OGD1HRkm4kmhM+pmpv3AKq5SU7GMg4oO/Q=
@@ -152,6 +153,14 @@ github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LB
 github.com/go-stack/stack v1.8.0 h1:5SgMzNM5HxrEjV0ww2lTmX6E2Izsfxas4+YHWRs3Lsk=
 github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
 github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE=
+github.com/go-xweb/httpsession v0.0.0-20141220075701-356d3b4d38d6 h1:DUiWdm3rS8cC96Y0XeVkDeizzEK6X+qiNgXytLVtbkM=
+github.com/go-xweb/httpsession v0.0.0-20141220075701-356d3b4d38d6/go.mod h1:lwPk13GS+i/NK4FkMm68IcJrAwiu+HtjYa1Y4kW59aY=
+github.com/go-xweb/log v0.0.0-20140701090824-270d183ad77e h1:xmffs7hgrWpAOcquZrdlWpAEaAdlI9myaYcUUmhIP7k=
+github.com/go-xweb/log v0.0.0-20140701090824-270d183ad77e/go.mod h1:ASmYUSBf32lWkkNVX/pnOU4MLuUQpFH4qYHvWHt/l0w=
+github.com/go-xweb/uuid v0.0.0-20140604020037-d7dce341f851 h1:D46USD6oGNWzoJ/h5CWaFq3ELLoLoJzllJ03Xh78VYg=
+github.com/go-xweb/uuid v0.0.0-20140604020037-d7dce341f851/go.mod h1:OmDEC58ZYO1Esk+Uy32SB6LWof9lyROl7q76dBFOCWw=
+github.com/go-xweb/xweb v0.2.1 h1:u5t/ttuSfxiIMDTXj/Pouw9C2ASNABWT16JWHyrtdvY=
+github.com/go-xweb/xweb v0.2.1/go.mod h1:vPjYJgfidYAgBKIwiAyKFC1hfczlqsw9rRT8LtwrGew=
 github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
 github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
 github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
@@ -189,6 +198,7 @@ github.com/golang/snappy v0.0.1 h1:Qgr9rKW7uDUkrbSmQeiDsGa8SjGyCOGtuasMWwvp2P4=
 github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
 github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM=
 github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
+github.com/gomodule/redigo v1.8.9 h1:Sl3u+2BI/kk+VEatbj0scLdrFhjPmbxOc1myhDP41ws=
 github.com/gomodule/redigo v1.8.9/go.mod h1:7ArFNvsTjH8GMMzB4uy1snslv2BwmginuMs06a1uzZE=
 github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
 github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
@@ -240,6 +250,7 @@ github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542/go.mod h1:Ow0tF8D4Kplb
 github.com/hashicorp/go-uuid v1.0.2/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
 github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
 github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
+github.com/howeyc/fsnotify v0.9.0 h1:0gtV5JmOKH4A8SsFxG2BczSeXWWPvcMT0euZt5gDAxY=
 github.com/howeyc/fsnotify v0.9.0/go.mod h1:41HzSPxBGeFRQKEEwgh49TRw/nKBsYZ2cF1OzPjSJsA=
 github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
 github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=

+ 96 - 46
clueSync/job.go

@@ -7,6 +7,8 @@ import (
 	"strings"
 	"time"
 
+	"app.yhyue.com/moapp/jybase/redis"
+
 	"app.yhyue.com/moapp/jybase/common"
 	"app.yhyue.com/moapp/jybase/mongodb"
 )
@@ -21,14 +23,19 @@ func orders() {
 	sql := fmt.Sprintf(`select * from dataexport_order where order_status = 0 and product_type in ("大会员","VIP订阅","数据流量包","历史数据") and create_time <= "%s" and create_time >= "%s" and id > %s`, selectTimeEnd, selectTimeStart, fmt.Sprint(lastOrderId))
 	data := Mysql.SelectBySql(sql)
 	if data != nil && *data != nil && len(*data) > 0 {
-		for k, v := range *data {
-			FormatData(v, "orders")
-			if k == len(*data)-1 {
-				lastOrderId = common.IntAll(v["id"])
+		for _, v := range *data {
+			// FormatData(v, "orders")
+			// if k == len(*data)-1 {
+			// 	lastOrderId = common.IntAll(v["id"])
+			// }
+			ok1, _ := FormatData(v, "orders")
+			if !ok1 {
+				common.WriteSysConfig(&cfg)
+				break
 			}
+			cfg.LastOrderId = common.IntAll(v["id"])
 		}
 	}
-	cfg.LastOrderId = lastOrderId
 	common.WriteSysConfig(&cfg)
 	log.Println("未支付订单定时任务结束")
 }
@@ -90,8 +97,13 @@ func saleLeads() {
 		if !iter.Next(&thisData) {
 			break
 		}
+		ok1, _ := FormatData(thisData, "saleLeads")
+		if !ok1 {
+			common.WriteSysConfig(&cfg)
+			break
+		}
 		cfg.LastId = mongodb.BsonIdToSId(thisData["_id"])
-		FormatData(thisData, "saleLeads")
+		// FormatData(thisData, "saleLeads")
 	}
 	common.WriteSysConfig(&cfg)
 	log.Println("用户留资定时任务结束")
@@ -162,9 +174,22 @@ func FormatData(data map[string]interface{}, item string) (bool, bool) {
 	}
 	//域外用户和内部用户和没有手机号,不存线索
 	if source == 5 || source == 6 || phone == "" {
+		log.Println("线索分配失败,线索过滤!!", item, source, phone, userId)
 		return true, false
 	}
 	if uId == "" {
+		if isExists, _ := redis.Exists("bidx", "bidx_userId_"+userId); isExists {
+			redisInt := redis.GetInt("bidx", "bidx_userId_"+userId)
+			if redisInt > 2 {
+				log.Println("线索分配失败,线索缺少信息,任务已执行超过3次", item, userId, phone)
+				return true, true
+			} else {
+				redis.Incr("bidx", "bidx_userId_"+userId)
+			}
+		} else {
+			redis.Put("bidx", "bidx_userId_"+userId, 1, 3600)
+		}
+		log.Println("线索分配失败,线索缺少信息", item, phone, userId)
 		return false, false
 	}
 	//不是留资的要查一遍留资
@@ -189,34 +214,44 @@ func FormatData(data map[string]interface{}, item string) (bool, bool) {
 	//follow_project_area --> follow_project_monitor
 	follow_project_area = getAreaCode(userId)
 	//seatNumber position_id
-	//自动分配规则暂不确定
 	log.Println("data +++", top_cluetype, sub_cluetype, level, follow_project_area)
 	if top_cluetype == "" || sub_cluetype == "" || level == "" {
+		log.Println("线索分配失败,线索过滤top_cluetype!!", item, uId, phone, userId)
 		return true, true
 	}
 	position_id, seatNumber, saleName, saleData := autoDraw(level)
 	log.Println("data -------", position_id, seatNumber, saleName)
-	if position_id > 0 && seatNumber != "" && top_cluetype != "" && sub_cluetype != "" {
+	if position_id > 0 && seatNumber != "" {
 		if TiDb.Count("dwd_f_crm_private_sea", map[string]interface{}{"position_id": position_id}) >= cfg.CountLimit {
-			return true, false
+			log.Println("线索分配失败,私海线索数据超过限制", item, position_id, seatNumber, uId, userId, phone)
+			TiDb.UpdateOrDeleteBySql(`update dwd_f_crm_clue_autodraw_record set count = count + 1 where seatNumber = ? and clue_level = ?`, seatNumber, level)
+			return false, false
+			// position_id, seatNumber, saleName, saleData = autoDraw(level)
 		}
-		uCount := TiDb.FindOne("dwd_f_crm_clue_info", map[string]interface{}{"uid": uId}, "", "")
+		uCount, oks := TiDb.FindOne("dwd_f_crm_clue_info", map[string]interface{}{"uid": uId}, "", ""), true
 		if uCount != nil && len(*uCount) > 0 {
-			UpdateClue(*uCount, saleData, item, userId, uId, top_cluetype, sub_cluetype, topname, subname, cluename, name, saleName, phone, position, department, industry, follow_project_area, role, seatNumber, position_id)
+			oks = UpdateClue(*uCount, saleData, item, userId, uId, top_cluetype, sub_cluetype, topname, subname, cluename, name, saleName, phone, position, department, industry, follow_project_area, role, seatNumber, position_id)
+		} else {
+			oks = SaveClue(item, userId, uId, top_cluetype, sub_cluetype, topname, subname, cluename, name, saleName, phone, position, department, industry, follow_project_area, role, seatNumber, position_id)
+		}
+		if oks {
+			TiDb.UpdateOrDeleteBySql(`update dwd_f_crm_clue_autodraw_record set count = count + 1 where seatNumber = ? and clue_level = ?`, seatNumber, level)
 		} else {
-			SaveClue(item, userId, uId, top_cluetype, sub_cluetype, topname, subname, cluename, name, saleName, phone, position, department, industry, follow_project_area, role, seatNumber, position_id)
+			log.Println("线索分配失败!!", item, position_id, seatNumber, uId, userId, phone)
+			return false, false
 		}
 	}
 	return true, true
 }
 
-func SaveClue(item, userId, uId, top_cluetype, sub_cluetype, topname, subname, cluename, name, saleName, phone, position, department, industry, follow_project_area, role, seatNumber string, positionId int64) {
+func SaveClue(item, userId, uId, top_cluetype, sub_cluetype, topname, subname, cluename, name, saleName, phone, position, department, industry, follow_project_area, role, seatNumber string, positionId int64) bool {
 	nowTime := time.Now().Format("2006-01-02 15:04:05")
 	nowTimes := time.Unix(time.Now().Unix()+3600*12, 0).Format("2006-01-02 15:04:05")
+	clueId, seaId, uodateId1, uodateId2, uodateId3, uodateId4 := int64(0), int64(0), int64(0), int64(0), int64(0), int64(0)
 	// BCPCID := common.GetRandom(32)
-	TiDb.ExecTx("保存线索", func(tx *sql.Tx) bool {
+	if TiDb.ExecTx("保存线索", func(tx *sql.Tx) bool {
 		//线索
-		clueId := TiDb.InsertByTx(tx, "dwd_f_crm_clue_info", map[string]interface{}{
+		clueId = TiDb.InsertByTx(tx, "dwd_f_crm_clue_info", map[string]interface{}{
 			"userid":              userId,
 			"uid":                 uId,
 			"seatNumber":          seatNumber,
@@ -238,7 +273,7 @@ func SaveClue(item, userId, uId, top_cluetype, sub_cluetype, topname, subname, c
 			"role":                role,
 		})
 		//私海 --> 任务车
-		seaId := TiDb.InsertByTx(tx, "dwd_f_crm_private_sea", map[string]interface{}{
+		seaId = TiDb.InsertByTx(tx, "dwd_f_crm_private_sea", map[string]interface{}{
 			"clue_id":      clueId,
 			"seatNumber":   seatNumber,
 			"position_id":  positionId,
@@ -251,7 +286,7 @@ func SaveClue(item, userId, uId, top_cluetype, sub_cluetype, topname, subname, c
 			"tasksource":   "线索自动分配" + "-" + topname + "-" + subname,
 		})
 		//变更记录
-		uodateId1 := TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
+		uodateId1 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
 			"clue_id":     clueId,
 			"position_id": positionId,
 			"change_type": "创建线索",
@@ -260,7 +295,7 @@ func SaveClue(item, userId, uId, top_cluetype, sub_cluetype, topname, subname, c
 			"BCPCID":      common.GetRandom(32),
 			"operator_id": -1,
 		})
-		uodateId2 := TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
+		uodateId2 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
 			"clue_id":      clueId,
 			"position_id":  positionId,
 			"change_field": "position_id",
@@ -271,7 +306,7 @@ func SaveClue(item, userId, uId, top_cluetype, sub_cluetype, topname, subname, c
 			"BCPCID":       common.GetRandom(32),
 			"operator_id":  -1,
 		})
-		uodateId3 := TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
+		uodateId3 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
 			"clue_id":      clueId,
 			"position_id":  positionId,
 			"change_field": "trailstatus",
@@ -282,7 +317,7 @@ func SaveClue(item, userId, uId, top_cluetype, sub_cluetype, topname, subname, c
 			"BCPCID":       common.GetRandom(32),
 			"operator_id":  -1,
 		})
-		uodateId4 := TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
+		uodateId4 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
 			"clue_id":     clueId,
 			"position_id": positionId,
 			"change_type": "加入任务车",
@@ -291,11 +326,17 @@ func SaveClue(item, userId, uId, top_cluetype, sub_cluetype, topname, subname, c
 			"BCPCID":      common.GetRandom(32),
 			"operator_id": -1,
 		})
-		return clueId > 0 && seaId > 0 && uodateId1 > 0 && uodateId2 > 0 && uodateId3 > 0 && uodateId4 > 0
-	})
+		return clueId > -1 && seaId > -1 && uodateId1 > -1 && uodateId2 > -1 && uodateId3 > -1 && uodateId4 > -1
+	}) {
+		log.Println("线索分配成功")
+		return true
+	} else {
+		log.Println("线索分配失败!!!", clueId, seaId, uodateId1, uodateId2, uodateId3, uodateId4, " 用户信息 ", item, position, seatNumber, uId, userId, phone)
+		return false
+	}
 }
 
-func UpdateClue(data map[string]interface{}, saleData []map[string]interface{}, item, userId, uId, top_cluetype, sub_cluetype, topname, subname, cluename, name, saleName, phone, position, department, industry, follow_project_area, role, seatNumber string, positionId int64) {
+func UpdateClue(data map[string]interface{}, saleData []map[string]interface{}, item, userId, uId, top_cluetype, sub_cluetype, topname, subname, cluename, name, saleName, phone, position, department, industry, follow_project_area, role, seatNumber string, positionId int64) bool {
 	nowTime := time.Now().Format("2006-01-02 15:04:05")
 	nowTimes := time.Unix(time.Now().Unix()+3600*12, 0).Format("2006-01-02 15:04:05")
 	//trailstatus = 无意向 为变更线索状态
@@ -377,18 +418,19 @@ func UpdateClue(data map[string]interface{}, saleData []map[string]interface{},
 		insertSeaData["seatNumber"] = common.ObjToString(data["seatNumber"])
 		insertSeaData["position_id"] = common.Int64All(data["position_id"])
 	}
+	ok, ok1, ok2, seaId := true, true, true, int64(0)
+	updateId1, updateId2, updateId3, updateId4, updateId5 := int64(0), int64(0), int64(0), int64(0), int64(0)
+	updateId6, updateId7, updateId8, updateId9, updateId10 := int64(0), int64(0), int64(0), int64(0), int64(0)
+	updateId11, updateId12, updateId13 := int64(0), int64(0), int64(0)
 	if TiDb.ExecTx("更新线索", func(tx *sql.Tx) bool {
 		//线索
-		ok := TiDb.UpdateByTx(tx, "dwd_f_crm_clue_info", map[string]interface{}{"uid": uId}, clueUpdateData)
-		ok1, seaId := false, int64(0)
+		ok = TiDb.UpdateByTx(tx, "dwd_f_crm_clue_info", map[string]interface{}{"uid": uId}, clueUpdateData)
 		if is_assign == 1 {
 			ok1 = TiDb.UpdateByTx(tx, "dwd_f_crm_private_sea", map[string]interface{}{"clue_id": clueId}, seaUpdateData)
 		} else {
+			ok2 = TiDb.Delete("dwd_f_crm_open_sea", map[string]interface{}{"clue_id": clueId})
 			seaId = TiDb.InsertByTx(tx, "dwd_f_crm_private_sea", insertSeaData)
 		}
-		updateId1, updateId2, updateId3, updateId4, updateId5 := int64(0), int64(0), int64(0), int64(0), int64(0)
-		updateId6, updateId7, updateId8, updateId9, updateId10 := int64(0), int64(0), int64(0), int64(0), int64(0)
-		updateId11, updateId12, updateId13 := int64(0), int64(0), int64(0)
 		//变更记录
 		if trailstatus == "00" || trailstatus == "01" {
 			updateId1 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
@@ -396,8 +438,8 @@ func UpdateClue(data map[string]interface{}, saleData []map[string]interface{},
 				"position_id":  positionId,
 				"change_field": "position_id",
 				"change_type":  "所属人变更",
-				"old_value":    oldsaleName,
-				"new_value":    saleName,
+				"old_value":    common.If(oldsaleName != "", oldsaleName, "/"),
+				"new_value":    common.If(saleName != "", saleName, "/"),
 				"createtime":   nowTime,
 				"BCPCID":       common.GetRandom(32),
 				"operator_id":  -1,
@@ -437,17 +479,19 @@ func UpdateClue(data map[string]interface{}, saleData []map[string]interface{},
 					"operator_id":  -1,
 				})
 			} else {
-				updateId2 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
-					"clue_id":      clueId,
-					"position_id":  common.Int64All(data["position_id"]),
-					"change_field": "trailstatus",
-					"change_type":  "基本信息变更",
-					"old_value":    "商机线索",
-					"new_value":    "流失",
-					"createtime":   nowTime,
-					"BCPCID":       common.GetRandom(32),
-					"operator_id":  -1,
-				})
+				if common.Int64All(data["position_id"]) > 0 {
+					updateId2 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
+						"clue_id":      clueId,
+						"position_id":  common.Int64All(data["position_id"]),
+						"change_field": "trailstatus",
+						"change_type":  "基本信息变更",
+						"old_value":    "商机线索",
+						"new_value":    "流失",
+						"createtime":   nowTime,
+						"BCPCID":       common.GetRandom(32),
+						"operator_id":  -1,
+					})
+				}
 				updateId3 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
 					"clue_id":      clueId,
 					"position_id":  positionId,
@@ -621,6 +665,10 @@ func UpdateClue(data map[string]interface{}, saleData []map[string]interface{},
 				"baseinfo_id": uId,
 			})
 		}
+		return true
+	} else {
+		log.Println("线索更新失败!!!", ok, ok1, ok2, seaId, updateId1, updateId2, updateId3, updateId4, updateId5, updateId6, updateId7, updateId8, updateId9, updateId10, updateId11, updateId12, updateId13, " 用户信息 ", item, position, seatNumber, uId, userId, phone)
+		return false
 	}
 }
 
@@ -708,9 +756,11 @@ func getClueType(item string, data map[string]interface{}) (pcode, code, level,
 
 // 获取自动分配的人
 func autoDraw(mode string) (positionId int64, seatNumber, saleName string, saleData []map[string]interface{}) {
-	query := `select * from jy_salesperson_info where status = 0 and position != 0`
+	query := `select * from jy_salesperson_info where`
 	if mode == "A" || mode == "B" {
-		query += ` and is_complete = 1`
+		query += ` is_complete = 1`
+	} else {
+		query += ` is_complete = 1 or is_complete = 0`
 	}
 	data := TiDb.SelectBySql(query)
 	if data != nil && len(*data) > 0 {
@@ -795,9 +845,9 @@ func autoDraw(mode string) (positionId int64, seatNumber, saleName string, saleD
 				saleName = common.ObjToString(v["name"])
 			}
 		}
-		if positionId > 0 {
-			TiDb.UpdateOrDeleteBySql(`update dwd_f_crm_clue_autodraw_record set count = count + 1 where seatNumber = ? and clue_level = ?`, seatNumber, mode)
-		}
+		// if positionId > 0 {
+		// 	TiDb.UpdateOrDeleteBySql(`update dwd_f_crm_clue_autodraw_record set count = count + 1 where seatNumber = ? and clue_level = ?`, seatNumber, mode)
+		// }
 	}
 	return
 }

+ 73 - 0
clueSync/log.go

@@ -0,0 +1,73 @@
+package main
+
+/**
+日志文件自动切换,默认保留15天内日志
+**/
+
+import (
+	"log"
+	"os"
+	"path/filepath"
+	"regexp"
+	"time"
+
+	"github.com/go-xweb/xweb"
+	"github.com/robfig/cron"
+)
+
+// 日志格式
+var fileReg = regexp.MustCompile("^(\\d{4}_[0-9_]{14})\\.log$")
+
+// 当前日志文件句柄
+var LogFile *os.File
+
+// 时间格式
+var FMT = "2006_01_02_15_04_05"
+
+// 日志目录
+var LogPath = "./jylog"
+
+func init() {
+	os.Mkdir(LogPath, os.ModePerm)
+	//默认保留15天内的日志,-1为永久保留
+	initLog(15)
+}
+
+func initLog(saveDay int) {
+	go logfile()
+	task := cron.New()
+	task.Start()
+	task.AddFunc("0 0 0 * * ?", func() {
+		go logfile()
+		time.Sleep(50 * time.Second)
+		if saveDay > 0 {
+			filepath.Walk(LogPath, func(path string, info os.FileInfo, err error) error {
+				str := fileReg.FindStringSubmatch(info.Name())
+				if len(str) == 2 {
+					t, er := time.ParseInLocation(FMT, str[1], time.Local)
+					if er == nil {
+						if (time.Now().Unix()-t.Unix())/86400 > int64(saveDay) {
+							log.Println("delete log file:", path, os.Remove(path))
+						}
+					}
+				}
+				return nil
+			})
+		}
+	})
+}
+
+// 创建并切换输出文件
+func logfile() {
+	now := time.Now().Format(FMT)
+	file, _ := os.Create(LogPath + "/" + now + ".log")
+	log.SetOutput(file)
+	xweb.RootApp().Logger.SetOutput(file)
+	go func(file *os.File) {
+		time.Sleep(5 * time.Second)
+		if LogFile != nil {
+			LogFile.Close()
+		}
+		LogFile = file
+	}(file)
+}

+ 3 - 0
clueSync/main.go

@@ -5,6 +5,8 @@ import (
 	"fmt"
 	"log"
 
+	"app.yhyue.com/moapp/jybase/redis"
+
 	"app.yhyue.com/moapp/jybase/common"
 	elastic "app.yhyue.com/moapp/jybase/esv1"
 	"app.yhyue.com/moapp/jybase/mongodb"
@@ -61,6 +63,7 @@ func main() {
 		I_size:  cfg.Es.DbSize,
 	}
 	Es.InitElasticSize()
+	redis.InitRedis(cfg.RedisServer)
 	Mgo = mongodb.NewMgo(cfg.Mgo.Address, cfg.Mgo.DbName, cfg.Mgo.DbSize)
 	MgoLog = mongodb.NewMgoWithUser(cfg.MgoLog.Address, cfg.MgoLog.DbName, cfg.MgoLog.User, cfg.MgoLog.Password, cfg.MgoLog.DbSize)
 	InitArea()