Browse Source

Merge branch 'dev_v1.0.34_wh' of BaseService/biService into feature/v1.0.34

王浩 7 months ago
parent
commit
2e96909223
5 changed files with 191 additions and 120 deletions
  1. 1 0
      rpc/biService.proto
  2. 3 3
      rpc/internal/logic/getcompanytypelogic.go
  3. 94 83
      service/clue.go
  4. 1 1
      service/clueByPhone.go
  5. 92 33
      service/company.go

+ 1 - 0
rpc/biService.proto

@@ -155,6 +155,7 @@ message CompanyReq {
 
 message CompanyResp {
 	int64 status = 1;
+	string companStatus=2;
 }
 
 message DistributeClueShowReq {

+ 3 - 3
rpc/internal/logic/getcompanytypelogic.go

@@ -26,10 +26,10 @@ func NewGetCompanyTypeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Ge
 
 func (l *GetCompanyTypeLogic) GetCompanyType(in *pb.CompanyReq) (*pb.CompanyResp, error) {
 	// todo: add your logic here and delete this line
-
-	status := service.GetCompanyType(in)
+	status, companStatus := service.GetCompanyType(in)
 	data := gconv.Int64(status)
 	return &pb.CompanyResp{
-		Status: data,
+		Status:       data,
+		CompanStatus: companStatus,
 	}, nil
 }

+ 94 - 83
service/clue.go

@@ -185,7 +185,7 @@ func ClueAdd(this *biservice.ClueAddReq, col string) *biservice.AddProjectResp {
 	if this.Company == "" {
 		this.Company = this.Phone
 	}
-	isGroup, isCommerce := CompanyType(this.Company)
+	isGroup, isCommerce, _ := CompanyType(this.Company)
 	saveMap := map[string]interface{}{
 		"unique_id":        this.Phone,
 		"phone":            this.Phone,
@@ -499,8 +499,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 is_transfer != 1`)
-		count2 := JyBiTidb.CountBySql(`select count(1) as count from dwd_f_crm_clue_info where level_open=2 and is_assign=0 and is_transfer != 1`)
+		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)
 		counts1, counts2, counts3 := int64(0), int64(0), int64(0)
 		counts1 = int64(math.Ceil(float64(this.Count) / float64(10) * 5))
 		if this.Count-counts1 == 0 {
@@ -534,56 +534,6 @@ func DrawClues(positionId, count1, count2, count3 int64) int {
 	nowTime := time.Now().Format("2006-01-02 15:04:05")
 	seatNumber, name := getSeatNumber(positionId)
 	drawCount := 0
-	//data1, data2, data3, drawCount := &[]map[string]interface{}{}, &[]map[string]interface{}{}, &[]map[string]interface{}{}, 0
-	/*if count1 > 0 {
-		data1 = JyBiTidb.SelectBySql(`SELECT * from dwd_f_crm_clue_info where is_assign = 0 and level_open = ? and cluename in (SELECT cluename from dwd_f_crm_clue_info where position_id = ? GROUP BY cluename)`, 1, positionId)
-		if data1 != nil && len(*data1) > 0 {
-			if int64(len(*data1)) >= count1 {
-				data11 := (*data1)[0:count1]
-				data1 = &data11
-				count1 = 0
-			} else {
-				count1 = count1 - int64(len(*data1))
-			}
-		}
-	}
-	if count2 > 0 {
-		data2 = JyBiTidb.SelectBySql(`SELECT * from dwd_f_crm_clue_info where is_assign = 0 and level_open = ? and cluename in (SELECT cluename from dwd_f_crm_clue_info where position_id = ? GROUP BY cluename)`, 2, positionId)
-		if data2 != nil && len(*data2) > 0 {
-			if int64(len(*data2)) >= count2 {
-				data11 := (*data2)[0:count2]
-				data2 = &data11
-				count2 = 0
-			} else {
-				count2 = count2 - int64(len(*data2))
-			}
-		}
-	}
-	if count3 > 0 {
-		data3 = JyBiTidb.SelectBySql(`SELECT * from dwd_f_crm_clue_info where is_assign = 0 and level_open = ? and cluename in (SELECT cluename from dwd_f_crm_clue_info where position_id = ? GROUP BY cluename)`, 3, positionId)
-		if data3 != nil && len(*data3) > 0 {
-			if int64(len(*data3)) >= count3 {
-				data11 := (*data3)[0:count3]
-				data3 = &data11
-				count3 = 0
-			} else {
-				count3 = count3 - int64(len(*data3))
-			}
-		}
-	}*/
-	//
-	/*if data1 != nil && len(*data1) > 0 {
-		count := batchDraw(*data1, nowTime, seatNumber, name, positionId, "1")
-		drawCount += count
-	}
-	if data2 != nil && len(*data2) > 0 {
-		count := batchDraw(*data2, nowTime, seatNumber, name, positionId, "1")
-		drawCount += count
-	}
-	if data3 != nil && len(*data3) > 0 {
-		count := batchDraw(*data3, nowTime, seatNumber, name, positionId, "1")
-		drawCount += count
-	}*/
 	//
 	logx.Info("count1,count2,count3 ", count1, count2, count3, drawCount)
 	if count1 > 0 {
@@ -591,7 +541,7 @@ func DrawClues(positionId, count1, count2, count3 int64) int {
 		for {
 			logx.Info("等级1线索领取", count1, counts1, counts)
 			data := JyBiTidb.SelectBySql(`SELECT 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.lock_position_id is  null or   a.lock_position_id=? ) AND a.uid !="" AND a.is_transfer != 1  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")
@@ -615,7 +565,7 @@ func DrawClues(positionId, count1, count2, count3 int64) int {
 		for {
 			logx.Info("等级2线索领取", count2, counts1, counts)
 			data := JyBiTidb.SelectBySql(`SELECT 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.lock_position_id is  null or   a.lock_position_id=? ) AND a.uid !="" AND a.is_transfer != 1 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")
@@ -664,32 +614,6 @@ func batchDraw(data []map[string]interface{}, nowTime, seatNumber, name string,
 	count := 0
 	for _, v := range data {
 		clueId := common.Int64All(v["id"])
-		//cluename := common.ObjToString(v["cluename"])
-		/*	if dataType == "2" {
-			cdata := JyBiMysql.FindOne("dwd_f_crm_clue_info", map[string]interface{}{"cluename": cluename, "is_assign": 1, "company_nature": 0, "company_verification": 1}, "", "")
-			if cdata != nil && len(*cdata) > 0 {
-				salePositionId := common.Int64All((*cdata)["position_id"])
-				if pcount := JyBiMysql.Count("dwd_f_crm_personnel_management", map[string]interface{}{"resign": 0, "position_id": salePositionId}); pcount > 0 {
-					logx.Info("当前线索有在职销售 ", clueId, cluename)
-					return count
-				} else {
-					saledata := JyBiMysql.SelectBySql(`SELECT position_id from dwd_d_crm_department_level_succbi WHERE bi_pcode in (SELECT bi_pcode from dwd_d_crm_department_level_succbi WHERE position_id = ?) AND resign = 0`, salePositionId)
-					if saledata != nil && len(*saledata) > 0 {
-						isOk := false
-						for _, s := range *saledata {
-							sid := common.Int64All(s["position_id"])
-							if sid == positionId {
-								isOk = true
-							}
-						}
-						if !isOk {
-							logx.Info("当前线索销售离职,只能同部门领取 ", clueId, cluename)
-							return count
-						}
-					}
-				}
-			}
-		}*/
 		trailstatus := common.ObjToString(v["trailstatus"])
 		if JyBiMysql.ExecTx("领取线索等", func(tx *sql.Tx) bool {
 			updateClue := map[string]interface{}{
@@ -708,6 +632,93 @@ func batchDraw(data []map[string]interface{}, nowTime, seatNumber, name string,
 				"clue_level":           nil,
 			}
 			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"])
+			group := gconv.Int64(v["COMPANY_NATURE"])
+			business := gconv.Int64(v["COMPANY_VERIFICATION"])
+			new_lock_status := int64(2)
+			clueName := gconv.String(v["cluename"])
+			if group == 1 && business != 3 {
+				//无需锁定处理
+				if lock_status != 3 {
+					new_lock_status = 3
+				}
+			} else if group == 0 && business == 1 {
+				//已锁定处理
+				new_lock_status = 1
+			}
+			updateClue["lock_status"] = new_lock_status
+			updateClue["lock_time"] = nowTime
+			if new_lock_status != lock_status {
+				//锁定状态变更
+				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,
+				})
+			}
+			if positionId != lock_position_id && new_lock_status != lock_status && new_lock_status == 1 {
+				updateClue["lock_position_id"] = positionId
+				//锁定人员变更
+				clueArr := JyBiMysql.SelectBySql(`SELECT
+					 b.id,b.lock_status,b.lock_position_id
+				FROM
+					relatedRelationships a
+					INNER JOIN dwd_f_crm_clue_info b
+	  			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 collection {
+						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 {
+							//锁定状态变更
+							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,
+							})
+						}
+
+					}
+				}
+			}
 			ok1 := JyBiTidb.UpdateByTx(tx, "dwd_f_crm_clue_info", map[string]interface{}{"id": clueId}, updateClue)
 			recordId := JyBiTidb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
 				"clue_id":      clueId,
@@ -737,7 +748,7 @@ func batchDraw(data []map[string]interface{}, nowTime, seatNumber, name string,
 				"BCPCID":      common.GetRandom(32),
 				"operator_id": positionId,
 			})
-			recordId3, recordId4 := int64(0), int64(0)
+
 			recordId3 = JyBiTidb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
 				"clue_id":      clueId,
 				"position_id":  positionId,
@@ -914,7 +925,7 @@ func ClueImportSync(this *biservice.ClueImportReq) (string, int) {
 					cluename := common.ObjToString(v["cluename"])
 					name := common.ObjToString(v["name"])
 					position := common.ObjToString(v["position"])
-					isGroup, isCommerce := CompanyType(cluename)
+					isGroup, isCommerce, _ := CompanyType(cluename)
 					clueData := JyBiTidb.FindOne("dwd_f_crm_clue_info", map[string]interface{}{"phone": phone}, "", "")
 					if clueData == nil || len(*clueData) == 0 {
 						countAdd++

+ 1 - 1
service/clueByPhone.go

@@ -39,7 +39,7 @@ func CreateClue(in *pb.CreateCuleReq) (result *pb.BiReply, err error) {
 		userId = common.ObjToString((*userInfo)["userid"])
 		userName = common.ObjToString((*userInfo)["name"])
 	}
-	isGroup, isCommerce := CompanyType(in.Phone) //判断是否集团公司、工商库
+	isGroup, isCommerce, _ := CompanyType(in.Phone) //判断是否集团公司、工商库
 	clueId := int64(0)
 	if entity.JyBiTidb.ExecTx("保存线索", func(tx *sql.Tx) bool {
 		nowTime := time.Now().Format("2006-01-02 15:04:05")

+ 92 - 33
service/company.go

@@ -15,12 +15,16 @@ import (
 )
 
 // 判断是不是集团公司 判断在不在工商库 return 1集团公司 2工商库  3都是  -1都不是
-func GetCompanyType(this *biservice.CompanyReq) int {
+func GetCompanyType(this *biservice.CompanyReq) (int, string) {
 	status := -1
+	companStatus := ""
 	if this.CompanyName == "" {
-		return status
+		return status, companStatus
+	}
+	isGroup, isCommerce, companStatus := CompanyType(this.CompanyName)
+	if companStatus == "注销" || && companStatus == "吊销" || companStatus == "撤销" {
+		return status, companStatus
 	}
-	isGroup, isCommerce := CompanyType(this.CompanyName)
 	//判断
 	if isGroup && isCommerce {
 		status = 3
@@ -29,20 +33,28 @@ func GetCompanyType(this *biservice.CompanyReq) int {
 	} else if isCommerce {
 		status = 2
 	}
-	return status
+	return status, companStatus
 }
 
-func CompanyType(companyName string) (bool, bool) {
+func CompanyType(companyName string) (bool, bool, string) {
 	isGroup, isCommerce := false, false
 	//是否是集团
 	if c := JyBiTidb.CountBySql(`select count(1) from group_company_name where company_name=?`, companyName); c > 0 {
 		isGroup = true
 	}
 	//是否在工商库
-	if c := MgoQyxy.Count("qyxy_std", map[string]interface{}{"company_name": companyName, "company_type": map[string]interface{}{"$ne": "个体工商户"}}); c > 0 {
+	companyStatus := ""
+	data, _ := MgoQyxy.FindOneByField("qyxy_std",
+		map[string]interface{}{"company_name": companyName, "company_type": map[string]interface{}{"$ne": "个体工商户"}},
+		map[string]interface{}{
+			"company_status": 1, //变更记录
+		})
+	if data != nil || len(*data) == 0 {
 		isCommerce = true
+	} else {
+		companyStatus = gconv.String((*data)["company_status"])
 	}
-	return isGroup, isCommerce
+	return isGroup, isCommerce, companyStatus
 }
 
 // 查询是否达上限
@@ -57,6 +69,35 @@ func FindUpperLimit(positionId int64) bool {
 // CompanyCounts 目前数量
 // ClueCount 线索的数量
 func DistributeClueShow(this *biservice.DistributeClueShowReq, allocationCap int64) *biservice.DistributeClueShowResp {
+	//部门人员初始化
+	//判断一下是否需要做锁定人员变更
+	deptArr := JyBiTidb.SelectBySql(`SELECT
+					a.name,
+					b.dept_name,
+					a.position_id 
+				FROM
+					dwd_f_crm_personnel_management a
+					INNER JOIN dwd_d_crm_department_level_succbi b ON a.seat_number != "" 
+					AND a.seat_number IS NOT NULL 
+					AND a.resign = 0 
+					AND a.position_id = b.position_id 
+					AND b.resign =0 and     b.dept_name like  "%销售%"`)
+	deptMap := map[int64]map[string]interface{}{}
+	if deptArr == nil || len(*deptArr) == 0 {
+		return &biservice.DistributeClueShowResp{
+			ErrorCode: 1,
+			ErrorMsg:  "部门用户查询失败",
+		}
+	}
+	for _, m := range *deptArr {
+		userPositionId := gconv.Int64(m["position_id"])
+		deptName := gconv.String(m["dept_name"])
+		userName := gconv.String(m["name"])
+		deptMap[userPositionId] = map[string]interface{}{
+			"name":     userName,
+			"deptName": deptName,
+		}
+	}
 	rdata := []*biservice.DistributeClueShowss{}
 	pArr := []string{}
 	for _, c := range this.Datas { //初始化返回数据
@@ -97,6 +138,31 @@ func DistributeClueShow(this *biservice.DistributeClueShowReq, allocationCap int
 	}
 	clueArrs1 := []string{}
 	clueArrs1 = strings.Split(this.ClueIdList, ",")
+	if len(clueArrs1) == 1 && len(this.Datas) == 1 {
+		//判断一下是否是关联公司
+		clueData := JyBiTidb.FindOne("dwd_f_crm_clue_info", map[string]interface{}{
+			"id": clueArrs1[0],
+		}, "", "")
+		if clueData != nil && len(*clueData) > 0 {
+			lock_position_id := gconv.Int64("lock_position_id")
+			if lock_position_id != 0 {
+				if lock_position_id != this.Datas[0].PositionId {
+					personName:=gconv.String(deptMap[lock_position_id]["name"])
+					if IsSameDepartment(gconv.String(deptMap[lock_position_id]["deptName"]), gconv.String(deptMap[this.Datas[0].PositionId])) != 1 {
+						return &biservice.DistributeClueShowResp{
+							ErrorCode: 1,
+							ErrorMsg:  personName,
+						}
+					}else {
+						return &biservice.DistributeClueShowResp{
+							ErrorCode: 2,
+							ErrorMsg:  personName,
+						}
+					}
+				}
+			}
+		}
+	}
 	logx.Info("clueArrs1 ", clueArrs1)
 	for _, v := range strings.Split(this.ClueIdList, ",") {
 		count := 1
@@ -104,20 +170,6 @@ func DistributeClueShow(this *biservice.DistributeClueShowReq, allocationCap int
 		minCount, minIndex := int64(0), -1
 		isindexok := false
 		k1 := 0
-		for _, r := range rdata {
-			if !r.FullStatus {
-				if this.DataType == 1 {
-					if k1 == 0 {
-						minCount = r.CompanyCounts
-						break
-					}
-				} else {
-					if r.CompanyCounts < r.CompanyCount {
-						minCount = r.CompanyCounts
-					}
-				}
-			}
-		}
 		for _, r := range rdata {
 			if !r.FullStatus {
 				if this.DataType == 1 {
@@ -177,18 +229,6 @@ func DistributeClueShow(this *biservice.DistributeClueShowReq, allocationCap int
 			log.Println("3333", id, rdata[minIndex].PositionId)
 		}
 	}
-	/*if this.DataType == 2 {
-		for _, v := range rdata {
-			if this.UpdatePositionID == v.PositionId {
-				if v.CompanyCounts < v.CompanyCount {
-					return &biservice.DistributeClueShowResp{
-						ErrorCode: 1,
-						ErrorMsg:  "超出私海线索上限",
-					}
-				}
-			}
-		}
-	}*/
 	return &biservice.DistributeClueShowResp{
 		ErrorCode: 0,
 		Data:      rdata,
@@ -363,3 +403,22 @@ func dclue(v, positionId, isTask, thispositionId int64) {
 		}
 	}
 }
+func IsSameDepartment(dept1 string, dept2 string) int64 {
+	deptArr1 := strings.Split(dept1, "/")
+	deptArr2 := strings.Split(dept2, "/")
+
+	// 如果两个部门的长度不同,则不属于同一部门
+	if len(deptArr1) != len(deptArr2) {
+		return 2
+	}
+
+	// 比较每一层的部门
+	for i := 0; i < len(deptArr1); i++ {
+		if deptArr1[i] != deptArr2[i] {
+			return 2
+		}
+	}
+
+	// 如果到这里,说明它们属于同一部门
+	return 1
+}