Jelajahi Sumber

防撞单处理

WH01243 5 bulan lalu
induk
melakukan
32f62eb809

+ 0 - 2
api/biservice.go

@@ -38,9 +38,7 @@ func main() {
 	ctx := svc.NewServiceContext(c)
 	server := rest.MustNewServer(c.RestConf)
 	defer server.Stop()
-
 	handler.RegisterHandlers(server, ctx)
-
 	fmt.Printf("Starting server at %s:%d...\n", c.Host, c.Port)
 	server.Start()
 

+ 4 - 1
api/internal/logic/getcompanytypelogic.go

@@ -29,13 +29,16 @@ func (l *GetCompanyTypeLogic) GetCompanyType(req *types.GetCompanyTypeReq) (resp
 		CompanyName: req.CompanyName,
 	})
 	status := int64(0)
+	companyStatus := ""
 	if res != nil {
 		status = res.Status
+		companyStatus = res.CompanStatus
 	}
 
 	resp = &types.BiResp{
 		Data: map[string]interface{}{
-			"status": status,
+			"status":        status,
+			"companyStatus": companyStatus,
 		},
 	}
 	return resp, err

+ 1 - 0
entity/entity.go

@@ -56,6 +56,7 @@ var (
 	}
 	CodeLock = map[int64]interface{}{
 		1: "无需锁定",
+		0: "/",
 	}
 	PublicKey        = ""
 	GmailAuth        []*mail.GmailAuth

+ 131 - 64
service/clue.go

@@ -500,8 +500,8 @@ func DrawClue(this *biservice.DrawClueReq) *biservice.AddProjectResp {
 func DrawClueSync(this *biservice.DrawClueReq) (int, int) {
 	if DataLock.TryLock() {
 		defer DataLock.Unlock()
-		count1 := JyBiTidb.CountBySql(`select count(1) as count from dwd_f_crm_clue_info where level_open=1 and is_assign=0 and  (lock_position_id is  null and   lock_position_id=? ) and is_transfer != 1 `, this.PositionId)
-		count2 := JyBiTidb.CountBySql(`select count(1) as count from dwd_f_crm_clue_info where level_open=2 and is_assign=0 and  (lock_position_id is  null and   lock_position_id=? ) and is_transfer != 1`, this.PositionId)
+		count1 := JyBiTidb.CountBySql(`select count(1) as count from dwd_f_crm_clue_info where level_open=1 and is_assign=0 and  (lock_position_id is  null or   lock_position_id=? ) and is_transfer != 1 `, this.PositionId)
+		count2 := JyBiTidb.CountBySql(`select count(1) as count from dwd_f_crm_clue_info where level_open=2 and is_assign=0 and  (lock_position_id is  null or   lock_position_id=? ) and is_transfer != 1`, this.PositionId)
 		counts1, counts2, counts3 := int64(0), int64(0), int64(0)
 		counts1 = int64(math.Ceil(float64(this.Count) / float64(10) * 5))
 		if this.Count-counts1 == 0 {
@@ -542,7 +542,7 @@ func DrawClues(positionId, count1, count2, count3 int64) int {
 		for {
 			logx.Info("等级1线索领取", count1, counts1, counts)
 			data := JyBiTidb.SelectBySql(`SELECT a.label,a.labelChangeTime,a.last_ring_time as ctime,a.id,a.trailstatus,a.cluename FROM dwd_f_crm_clue_info a 
-					WHERE a.level_open = 1 AND a.is_assign = 0 AND a.uid !="" AND a.is_transfer != 1 GROUP BY a.id ORDER BY ctime asc limit ?,1`, counts1)
+					WHERE a.level_open = 1 AND a.is_assign = 0 AND a.uid !="" AND a.is_transfer != 1 and  (lock_position_id is  null or   lock_position_id=? ) GROUP BY a.id ORDER BY ctime asc limit ?,1`, counts1, positionId)
 			counts1++
 			if data != nil && len(*data) > 0 {
 				count := batchDraw(*data, nowTime, seatNumber, name, positionId, "2")
@@ -566,7 +566,7 @@ func DrawClues(positionId, count1, count2, count3 int64) int {
 		for {
 			logx.Info("等级2线索领取", count2, counts1, counts)
 			data := JyBiTidb.SelectBySql(`SELECT  a.label,a.labelChangeTime,a.last_ring_time as ctime,a.id,a.trailstatus,a.cluename FROM dwd_f_crm_clue_info a 
-					WHERE a.level_open = 2 AND a.is_assign = 0 AND a.uid !="" AND a.is_transfer != 1 GROUP BY a.id ORDER BY ctime asc limit ?,1`, counts1)
+					WHERE a.level_open = 2 AND a.is_assign = 0 AND a.uid !="" AND a.is_transfer != 1  and  (lock_position_id is  null or   lock_position_id=? ) GROUP BY a.id ORDER BY ctime asc limit ?,1`, counts1, positionId)
 			counts1++
 			if data != nil && len(*data) > 0 {
 				count := batchDraw(*data, nowTime, seatNumber, name, positionId, "2")
@@ -590,7 +590,7 @@ func DrawClues(positionId, count1, count2, count3 int64) int {
 		for {
 			logx.Info("等级3线索领取", count3, counts1, counts)
 			data := JyBiTidb.SelectBySql(`SELECT a.label,a.labelChangeTime, a.last_ring_time as ctime,a.id,a.trailstatus,a.cluename FROM dwd_f_crm_clue_info a 
-					WHERE a.level_open = 3 AND a.is_assign = 0 AND a.uid !="" AND a.is_transfer != 1 GROUP BY a.id ORDER BY ctime asc limit ?,1`, counts1)
+					WHERE a.level_open = 3 AND a.is_assign = 0 AND a.uid !="" AND a.is_transfer != 1 and  (lock_position_id is  null or   lock_position_id=? ) GROUP BY a.id ORDER BY ctime asc limit ?,1`, counts1, positionId)
 			counts1++
 			if data != nil && len(*data) > 0 {
 				count := batchDraw(*data, nowTime, seatNumber, name, positionId, "2")
@@ -603,7 +603,7 @@ func DrawClues(positionId, count1, count2, count3 int64) int {
 				break
 			}
 			if counts1 > 5*int(count3) {
-				drawCount += int(counts)
+				drawCount += counts
 				break
 			}
 		}
@@ -635,49 +635,31 @@ func batchDraw(data []map[string]interface{}, nowTime, seatNumber, name string,
 			updateClue["trailstatus"] = "01"
 			//判断一下是否需要变更锁定信息
 			recordId3, recordId4, recordId5, recordId6 := int64(0), int64(0), int64(0), int64(0)
-			lock_position_id := gconv.Int64(v["lock_position_id"])
-			lock_status := gconv.Int64(v["lock_status"])
+			lockPositionId := gconv.Int64(v["lock_position_id"])
+			oldLockStatus := gconv.Int64(v["lock_status"])
 			group := gconv.Int64(v["COMPANY_NATURE"])
 			business := gconv.Int64(v["COMPANY_VERIFICATION"])
-			new_lock_status := int64(2)
+			newLockStatus := int64(2)
 			clueName := gconv.String(v["cluename"])
 			if group == 1 && business != 3 {
 				//无需锁定处理
-				if lock_status != 3 {
-					new_lock_status = 3
+				if oldLockStatus != 3 {
+					newLockStatus = 3
 				}
 			} else if group == 0 && business == 1 {
 				//已锁定处理
-				new_lock_status = 1
+				newLockStatus = 1
 			}
-			updateClue["lock_status"] = new_lock_status
+			updateClue["lock_status"] = newLockStatus
 			updateClue["lock_time"] = nowTime
-			if new_lock_status != lock_status {
+			if newLockStatus != oldLockStatus {
 				//锁定状态变更
-				recordId5 = JyBiTidb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
-					"clue_id":      clueId,
-					"position_id":  positionId,
-					"change_field": "lock_status",
-					"change_type":  "基本信息变更",
-					"old_value":    common.If(lock_status == 0, "/", CodeLock[lock_status]),
-					"new_value":    CodeLock[lock_status],
-					"createtime":   nowTime,
-					"BCPCID":       common.GetRandom(32),
-					"operator_id":  positionId,
-				})
-				recordId6 = JyBiTidb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
-					"clue_id":      clueId,
-					"position_id":  positionId,
-					"change_field": "lock_position_id",
-					"change_type":  "绑定人变更",
-					"old_value":    "/",
-					"new_value":    name,
-					"createtime":   nowTime,
-					"BCPCID":       common.GetRandom(32),
-					"operator_id":  positionId,
-				})
+				recordId5 = AddLockeStatusChange(tx, clueId, positionId, 0, oldLockStatus, nowTime, clueName)
 			}
-			if positionId != lock_position_id && new_lock_status != lock_status && new_lock_status == 1 {
+			if newLockStatus > 0 {
+				recordId6 = AddLockePersonChange(tx, clueId, positionId, "/", name, nowTime, clueName)
+			}
+			if positionId != lockPositionId && newLockStatus != oldLockStatus && newLockStatus == 1 {
 				updateClue["lock_position_id"] = positionId
 				//锁定人员变更
 				clueArr := JyBiMysql.SelectBySql(`SELECT
@@ -688,35 +670,16 @@ func batchDraw(data []map[string]interface{}, nowTime, seatNumber, name string,
 	  			on   a.company=?  and   a.association_company=b.cluename  and   b.COMPANY_VERIFICATION=1 and  b.COMPANY_NATURE=0`, clueName)
 				if clueArr != nil && len(*clueArr) > 0 {
 					for _, v1 := range *clueArr {
-						lock_position_id1 := gconv.Int64(v1["lock_position_id"])
-						lock_status1 := gconv.Int64(v1["lock_status"])
-						clueId1 := gconv.Int64(v1["id"])
-						if ((lock_position_id1 != positionId && lock_position_id1 != 0) || lock_position_id1 == 0) && lock_status1 != lock_status {
+						oldLockPositionId := gconv.Int64(v1["lock_position_id"])
+						oldLockStatus := gconv.Int64(v1["lock_status"])
+						//锁定状态变更
+						if oldLockStatus != oldLockStatus {
 							//锁定状态变更
-							JyBiTidb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
-								"clue_id":      clueId1,
-								"position_id":  positionId,
-								"change_field": "lock_status",
-								"change_type":  "基本信息变更",
-								"old_value":    common.If(lock_status1 == 0, "/", CodeLock[lock_status1]),
-								"new_value":    CodeLock[lock_status],
-								"createtime":   nowTime,
-								"BCPCID":       common.GetRandom(32),
-								"operator_id":  positionId,
-							})
-							JyBiTidb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
-								"clue_id":      clueId,
-								"position_id":  positionId,
-								"change_field": "lock_position_id",
-								"change_type":  "绑定人变更",
-								"old_value":    "/",
-								"new_value":    name,
-								"createtime":   nowTime,
-								"BCPCID":       common.GetRandom(32),
-								"operator_id":  positionId,
-							})
+							recordId5 = AddLockeStatusChange(tx, clueId, positionId, 0, oldLockStatus, nowTime, clueName)
+						}
+						if oldLockStatus > 0 && oldLockPositionId != positionId {
+							recordId6 = AddLockePersonChange(tx, clueId, positionId, "/", name, nowTime, clueName)
 						}
-
 					}
 				}
 			}
@@ -1334,3 +1297,107 @@ func LabelHandel(tx *sql.Tx, oldlabelType, labelType, clueId int64, level, oldTr
 		log.Println("线索标签修改:", ok)
 	}
 }
+
+// 锁定状态变更
+func AddLockeStatusChange(tx *sql.Tx, clueId, positionId, oldLockStatus, lock_status int64, nowTime, clueName string) int64 {
+	//需要批量查处理   后期处理
+	if clueName != "" {
+		_, clueList := FindRelatedData(clueName)
+		for _, v := range clueList {
+			JyBiTidb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
+				"clue_id":      v,
+				"position_id":  positionId,
+				"change_field": "lock_status",
+				"change_type":  "基本信息变更",
+				"old_value":    common.If(lock_status == 0, CodeLock[lock_status], CodeLock[lock_status]),
+				"new_value":    CodeLock[lock_status],
+				"createtime":   nowTime,
+				"BCPCID":       common.GetRandom(32),
+				"operator_id":  positionId,
+			})
+		}
+	}
+	return 1
+}
+
+// 锁定人认变更
+func AddLockePersonChange(tx *sql.Tx, clueId, positionId int64, oldpersonName, personName, nowTime, clueName string) int64 {
+	//需要批量查处理   后期处理
+	if clueName != "" {
+		lockPositionId, clueList := FindRelatedData(clueName)
+		if lockPositionId != positionId {
+			log.Println(clueName, positionId, lockPositionId, "锁定人变更失败")
+		}
+		for _, v := range clueList {
+			JyBiTidb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
+				"clue_id":      v,
+				"position_id":  positionId,
+				"change_field": "lock_position_id",
+				"change_type":  "锁定人变更",
+				"old_value":    oldpersonName,
+				"new_value":    personName,
+				"createtime":   nowTime,
+				"BCPCID":       common.GetRandom(32),
+				"operator_id":  positionId,
+			})
+		}
+	}
+	return 1
+}
+
+// 关联公司查询
+func FindRelatedData(companyName string) (int64, []int64) {
+	sqlStr := fmt.Sprintf(`SELECT
+			position_id,id
+		FROM
+			dwd_f_crm_clue_info 
+		WHERE
+			(cluename IN ( SELECT companyName FROM ( SELECT b_name AS companyName FROM ent_relation WHERE a_name ="%s" UNION SELECT a_name AS companyName FROM ent_relation WHERE b_name = "%s") ) 
+			or  cluename="%s" )
+			     AND position_id > 0 
+			LIMIT 1`, companyName, companyName, companyName)
+	companyList := JyTidb.SelectBySql(sqlStr)
+	if companyList == nil || len(*companyList) == 0 {
+		return 0, []int64{}
+	}
+	positionId := int64(0)
+	clueList := []int64{}
+	for _, v := range *companyList {
+		if gconv.Int64(v["position_id"]) > 0 {
+			positionId = gconv.Int64(v["position_id"])
+		}
+		clueList = append(clueList, gconv.Int64(v["id"]))
+	}
+	return positionId, clueList
+}
+
+// 动态记录新增
+func AddChangeRecord(tx *sql.Tx, clueId, positionId int64, changeField, changeType, newValue, oldValue, nowTime, BCPCID string, operatorId int64) int64 {
+	if BCPCID == "" {
+		BCPCID = common.GetRandom(32)
+	}
+	if tx == nil {
+		return JyTidb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
+			"clue_id":      clueId,
+			"position_id":  positionId,
+			"change_field": changeField,
+			"change_type":  changeType,
+			"old_value":    oldValue,
+			"new_value":    newValue,
+			"createtime":   nowTime,
+			"BCPCID":       BCPCID,
+			"operator_id":  operatorId,
+		})
+	}
+	return JyTidb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
+		"clue_id":      clueId,
+		"position_id":  positionId,
+		"change_field": changeField,
+		"change_type":  changeType,
+		"old_value":    oldValue,
+		"new_value":    newValue,
+		"createtime":   nowTime,
+		"BCPCID":       BCPCID,
+		"operator_id":  operatorId,
+	})
+}

+ 4 - 4
vipTask/entity/timetask.go

@@ -20,6 +20,7 @@ func (t *TimeTask) Run() {
 	})
 }
 func (t *TimeTask) DataHandle(allocation []*config.ExpireConfig) {
+	logx.Info("刷库开始", allocation)
 	for _, expireConfig := range allocation {
 		sourceMap := config.Subjectdb.FindOne("clue_info_source", map[string]interface{}{
 			"judge": expireConfig.EndDays,
@@ -40,6 +41,7 @@ func (t *TimeTask) DataHandle(allocation []*config.ExpireConfig) {
 // 分批处理数据
 func PersonExpireHandle(allocation *config.ExpireConfig, sourceId int64) {
 	//按时间查询数据
+	logx.Info("个人数据查询", allocation)
 	endTime := GetFutureDateTime(allocation.EndDays)
 	startTime := GetFutureDateTime(allocation.StartDays)
 	sess := config.UserMgo.GetMgoConn()
@@ -106,16 +108,14 @@ func PersonExpireHandle(allocation *config.ExpireConfig, sourceId int64) {
 }
 func EntExpireHandle(allocation *config.ExpireConfig, sourceId int64) {
 	//按时间查询数据
+	logx.Info("企业数据查询", allocation)
 	endTime := GetFutureDateTimeStr(allocation.EndDays)
 	startTime := GetFutureDateTimeStr(allocation.StartDays)
 	config.JianYu.SelectByBath(1, func(l *[]map[string]interface{}) bool {
 		go func(m map[string]interface{}) {
-			//logx.Info("企业数据处理", allocation, m)
+			logx.Info("企业数据处理", allocation, m)
 			//企业开始结束时间查询
 			endId := gconv.Int64(m["ent_id"])
-			if endId == 86268 {
-				logx.Info(1111)
-			}
 			orderList := config.JianYu.SelectBySql("select start_time,end_time  from  entniche_wait_empower where  ent_id=? ORDER BY  end_time desc", endId)
 			if (*orderList) == nil || len(*orderList) == 0 {
 				return