|
@@ -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,
|
|
|
+ })
|
|
|
+}
|