Parcourir la source

忽略操作处理

WH01243 il y a 1 an
Parent
commit
8f60d5d1d4

+ 41 - 25
api/application.api

@@ -45,15 +45,14 @@ type (
 	}
 
 	EmployOperateReq {
-		AppId      string   `header:"appId,default=10000"`
-		BaseUserId int64    `header:"newUserId"`
-		PositionId int64    `header:"positionId,optional"`
-		EntUserId  int64    `header:"entUserId,optional"`
-		EntId      int64    `header:"entId,optional"`
-		IdArr      []string `json:"idArr"`      //信息id多条信息
-		IsEmploy   bool     `json:"isEmploy"`   //是否收录true收录 false取消收录
-		SourceType int64    `json:"sourceType"` //收录方式类型;1:线索处理 2:机会挖掘 3:任务复盘
-		EmployType int64    `json:"employType"` //来源方式来源;1标采购搜索、2企业搜索、3采购单位搜索、4拟在建项目
+		AppId      string `header:"appId,default=10000"`
+		BaseUserId int64  `header:"newUserId"`
+		PositionId int64  `header:"positionId,optional"`
+		EntUserId  int64  `header:"entUserId,optional"`
+		EntId      int64  `header:"entId,optional"`
+		IdArr      string `json:"idArr"`      //信息id多条信息
+		IsEmploy   bool   `json:"isEmploy"`   //是否收录true收录 false取消收录
+		EmployType int64  `json:"employType"` //来源方式来源;1招标采购、2企业、3采购单位、4拟在建项目
 	}
 
 	TransferReq {
@@ -67,23 +66,24 @@ type (
 	}
 
 	IgnoreOperateReq {
-		AppId       string   `header:"appId,default=10000"`
-		BaseUserId  int64    `header:"newUserId"`
-		PositionId  int64    `header:"positionId,optional"`
-		EntUserId   int64    `header:"entUserId,optional"`
-		EntId       int64    `header:"entId,optional"`
-		EmployIdArr []string `json:"employIdArr"` //收录记录集合
-		IsEmploy    bool     `json:"isEmploy"`    //是否忽略 true 忽略 false取消忽略
+		AppId      string `header:"appId,default=10000"`
+		BaseUserId int64  `header:"newUserId"`
+		PositionId int64  `header:"positionId,optional"`
+		EntUserId  int64  `header:"entUserId,optional"`
+		EntId      int64  `header:"entId,optional"`
+		IdArr      string `json:"idArr"`      //收录记录集合
+		IsIgnore   bool   `json:"isIgnore"`   //是否忽略 true 忽略 false取消忽略
+		EmployType int64  `json:"employType"` //来源方式来源;1招标采购、2企业、3采购单位、4拟在建项目
 	}
 
 	InfoEmployinfoReq {
-		AppId      string   `header:"appId,default=10000"`
-		BaseUserId int64    `header:"newUserId"`
-		PositionId int64    `header:"positionId,optional"`
-		EntUserId  int64    `header:"entUserId,optional"`
-		EntId      int64    `header:"entId,optional"`
-		EmployType int64    `json:"employType"` //1标采购搜索、2企业搜索、3采购单位搜索、4拟在建项目
-		Id         []string `json:"id"`         //id
+		AppId      string `header:"appId,default=10000"`
+		BaseUserId int64  `header:"newUserId"`
+		PositionId int64  `header:"positionId,optional"`
+		EntUserId  int64  `header:"entUserId,optional"`
+		EntId      int64  `header:"entId,optional"`
+		EmployType int64  `json:"employType"` //1标采购、2企业、3采购单位、4拟在建项目
+		IdArr      string `json:"idArr"`      //id
 	}
 
 	CustomAddReq {
@@ -115,6 +115,19 @@ type (
 
 	FileUploadReq {
 	}
+	EmployDistributeReq {
+		AppId       string             `header:"appId,default=10000"`
+		BaseUserId  int64              `header:"newUserId"`
+		PositionId  int64              `header:"positionId,optional"`
+		EntUserId   int64              `header:"entUserId,optional"`
+		EntId       int64              `header:"entId,optional"`
+		EmployIdArr string             `json:"employIdArr"`
+		Person      []DistributePerson `json:"person"`
+	}
+	DistributePerson {
+		PositionId int64 `json:"positionId"`
+		EntUserId  int64 `json:"entUserId"`
+	}
 )
 
 service crmApplication {
@@ -125,7 +138,7 @@ service crmApplication {
 	@handler saleChanceAdd
 	post /crmApplication/saleChance/add (SaleChanceReq) returns (Reply)
 	@doc "收录操作"
-	@handler infoOperate
+	@handler employOperate
 	post /crmApplication/employ/operate (EmployOperateReq) returns (Reply)
 	@doc "商业资讯的转办"
 	@handler transfer
@@ -134,7 +147,7 @@ service crmApplication {
 	@handler ignoreOperate
 	post /crmApplication/ignore/operate (IgnoreOperateReq) returns (Reply)
 	@doc "收录情况"
-	@handler infoEmployinfo
+	@handler employInfo
 	post /crmApplication/employ/info (InfoEmployinfoReq) returns (Reply)
 	@doc "创建客户"
 	@handler customAdd
@@ -142,4 +155,7 @@ service crmApplication {
 	@doc "文件上传"
 	@handler fileUpload
 	post /crmApplication/file/upload(FileUploadReq) returns (Reply)
+	@doc "分发"
+	@handler  employDistribute
+	post /crmApplication/employ/distribute(EmployDistributeReq) returns (Reply)
 }

+ 1 - 1
api/etc/crmapplication.yaml

@@ -14,7 +14,7 @@ UserCenterRpc:
 FileCenterRpc:
   Etcd:
     Hosts:
-    - 127.0.0.1:2379
+    - 192.168.3.149:2379
     Key: filecenter.rpc
 ossBucketName: jytest2022
 ossUrl: https://jytest2022.oss-cn-beijing.aliyuncs.com

+ 28 - 0
api/internal/handler/employdistributehandler.go

@@ -0,0 +1,28 @@
+package handler
+
+import (
+	"net/http"
+
+	"bp.jydev.jianyu360.cn/CRM/application/api/internal/logic"
+	"bp.jydev.jianyu360.cn/CRM/application/api/internal/svc"
+	"bp.jydev.jianyu360.cn/CRM/application/api/internal/types"
+	"github.com/zeromicro/go-zero/rest/httpx"
+)
+
+func employDistributeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
+	return func(w http.ResponseWriter, r *http.Request) {
+		var req types.EmployDistributeReq
+		if err := httpx.Parse(r, &req); err != nil {
+			httpx.ErrorCtx(r.Context(), w, err)
+			return
+		}
+
+		l := logic.NewEmployDistributeLogic(r.Context(), svcCtx)
+		resp, err := l.EmployDistribute(&req)
+		if err != nil {
+			httpx.ErrorCtx(r.Context(), w, err)
+		} else {
+			httpx.OkJsonCtx(r.Context(), w, resp)
+		}
+	}
+}

+ 3 - 3
api/internal/handler/infoemployinfohandler.go → api/internal/handler/employinfohandler.go

@@ -9,7 +9,7 @@ import (
 	"github.com/zeromicro/go-zero/rest/httpx"
 )
 
-func infoEmployinfoHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
+func employInfoHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
 	return func(w http.ResponseWriter, r *http.Request) {
 		var req types.InfoEmployinfoReq
 		if err := httpx.Parse(r, &req); err != nil {
@@ -17,8 +17,8 @@ func infoEmployinfoHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
 			return
 		}
 
-		l := logic.NewInfoEmployinfoLogic(r.Context(), svcCtx)
-		resp, err := l.InfoEmployinfo(&req)
+		l := logic.NewEmployInfoLogic(r.Context(), svcCtx)
+		resp, err := l.EmployInfo(&req)
 		if err != nil {
 			httpx.ErrorCtx(r.Context(), w, err)
 		} else {

+ 3 - 3
api/internal/handler/infooperatehandler.go → api/internal/handler/employoperatehandler.go

@@ -9,7 +9,7 @@ import (
 	"github.com/zeromicro/go-zero/rest/httpx"
 )
 
-func infoOperateHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
+func employOperateHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
 	return func(w http.ResponseWriter, r *http.Request) {
 		var req types.EmployOperateReq
 		if err := httpx.Parse(r, &req); err != nil {
@@ -17,8 +17,8 @@ func infoOperateHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
 			return
 		}
 
-		l := logic.NewInfoOperateLogic(r.Context(), svcCtx)
-		resp, err := l.InfoOperate(&req)
+		l := logic.NewEmployOperateLogic(r.Context(), svcCtx)
+		resp, err := l.EmployOperate(&req)
 		if err != nil {
 			httpx.ErrorCtx(r.Context(), w, err)
 		} else {

+ 7 - 2
api/internal/handler/routes.go

@@ -25,7 +25,7 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
 			{
 				Method:  http.MethodPost,
 				Path:    "/crmApplication/employ/operate",
-				Handler: infoOperateHandler(serverCtx),
+				Handler: employOperateHandler(serverCtx),
 			},
 			{
 				Method:  http.MethodPost,
@@ -40,7 +40,7 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
 			{
 				Method:  http.MethodPost,
 				Path:    "/crmApplication/employ/info",
-				Handler: infoEmployinfoHandler(serverCtx),
+				Handler: employInfoHandler(serverCtx),
 			},
 			{
 				Method:  http.MethodPost,
@@ -52,6 +52,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
 				Path:    "/crmApplication/file/upload",
 				Handler: fileUploadHandler(serverCtx),
 			},
+			{
+				Method:  http.MethodPost,
+				Path:    "/crmApplication/employ/distribute",
+				Handler: employDistributeHandler(serverCtx),
+			},
 		},
 	)
 }

+ 35 - 0
api/internal/logic/employdistributelogic.go

@@ -0,0 +1,35 @@
+package logic
+
+import (
+	"bp.jydev.jianyu360.cn/CRM/application/api/service"
+	"context"
+
+	"bp.jydev.jianyu360.cn/CRM/application/api/internal/svc"
+	"bp.jydev.jianyu360.cn/CRM/application/api/internal/types"
+
+	"github.com/zeromicro/go-zero/core/logx"
+)
+
+type EmployDistributeLogic struct {
+	logx.Logger
+	ctx    context.Context
+	svcCtx *svc.ServiceContext
+}
+
+func NewEmployDistributeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *EmployDistributeLogic {
+	return &EmployDistributeLogic{
+		Logger: logx.WithContext(ctx),
+		ctx:    ctx,
+		svcCtx: svcCtx,
+	}
+}
+
+func (l *EmployDistributeLogic) EmployDistribute(req *types.EmployDistributeReq) (resp *types.Reply, err error) {
+	// todo: add your logic here and delete this line
+	resp = &types.Reply{}
+	employService := &service.EmPloyService{}
+	resp.Data = map[string]interface{}{
+		"status": employService.DistributePerson(req),
+	}
+	return
+}

+ 4 - 6
api/internal/logic/infoemployinfologic.go → api/internal/logic/employinfologic.go

@@ -3,7 +3,6 @@ package logic
 import (
 	"bp.jydev.jianyu360.cn/CRM/application/api/service"
 	"context"
-	"log"
 
 	"bp.jydev.jianyu360.cn/CRM/application/api/internal/svc"
 	"bp.jydev.jianyu360.cn/CRM/application/api/internal/types"
@@ -11,25 +10,24 @@ import (
 	"github.com/zeromicro/go-zero/core/logx"
 )
 
-type InfoEmployinfoLogic struct {
+type EmployInfoLogic struct {
 	logx.Logger
 	ctx    context.Context
 	svcCtx *svc.ServiceContext
 }
 
-func NewInfoEmployinfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *InfoEmployinfoLogic {
-	return &InfoEmployinfoLogic{
+func NewEmployInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *EmployInfoLogic {
+	return &EmployInfoLogic{
 		Logger: logx.WithContext(ctx),
 		ctx:    ctx,
 		svcCtx: svcCtx,
 	}
 }
 
-func (l *InfoEmployinfoLogic) InfoEmployinfo(req *types.InfoEmployinfoReq) (resp *types.Reply, err error) {
+func (l *EmployInfoLogic) EmployInfo(req *types.InfoEmployinfoReq) (resp *types.Reply, err error) {
 	// todo: add your logic here and delete this line
 	resp = &types.Reply{}
 	employService := &service.EmPloyService{}
-	log.Println(employService.InfoEmployinfo(req))
 	resp.Data = employService.InfoEmployinfo(req)
 	return
 }

+ 7 - 6
api/internal/logic/infooperatelogic.go → api/internal/logic/employoperatelogic.go

@@ -1,29 +1,30 @@
 package logic
 
 import (
-	"bp.jydev.jianyu360.cn/CRM/application/api/internal/svc"
-	"bp.jydev.jianyu360.cn/CRM/application/api/internal/types"
 	"bp.jydev.jianyu360.cn/CRM/application/api/service"
 	"context"
 
+	"bp.jydev.jianyu360.cn/CRM/application/api/internal/svc"
+	"bp.jydev.jianyu360.cn/CRM/application/api/internal/types"
+
 	"github.com/zeromicro/go-zero/core/logx"
 )
 
-type InfoOperateLogic struct {
+type EmployOperateLogic struct {
 	logx.Logger
 	ctx    context.Context
 	svcCtx *svc.ServiceContext
 }
 
-func NewInfoOperateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *InfoOperateLogic {
-	return &InfoOperateLogic{
+func NewEmployOperateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *EmployOperateLogic {
+	return &EmployOperateLogic{
 		Logger: logx.WithContext(ctx),
 		ctx:    ctx,
 		svcCtx: svcCtx,
 	}
 }
 
-func (l *InfoOperateLogic) InfoOperate(req *types.EmployOperateReq) (resp *types.Reply, err error) {
+func (l *EmployOperateLogic) EmployOperate(req *types.EmployOperateReq) (resp *types.Reply, err error) {
 	// todo: add your logic here and delete this line
 	resp = &types.Reply{}
 	employService := &service.EmPloyService{}

+ 7 - 1
api/internal/logic/ignoreoperatelogic.go

@@ -1,6 +1,7 @@
 package logic
 
 import (
+	"bp.jydev.jianyu360.cn/CRM/application/api/service"
 	"context"
 
 	"bp.jydev.jianyu360.cn/CRM/application/api/internal/svc"
@@ -25,6 +26,11 @@ func NewIgnoreOperateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Ign
 
 func (l *IgnoreOperateLogic) IgnoreOperate(req *types.IgnoreOperateReq) (resp *types.Reply, err error) {
 	// todo: add your logic here and delete this line
-
+	resp = &types.Reply{}
+	employService := &service.EmPloyService{}
+	employService.IgnoreOperate(req)
+	resp.Data = map[string]interface{}{
+		"status": true,
+	}
 	return
 }

+ 300 - 227
api/service/EmployService.go

@@ -3,7 +3,6 @@ package service
 import (
 	"app.yhyue.com/moapp/jybase/common"
 	"app.yhyue.com/moapp/jybase/date"
-	"app.yhyue.com/moapp/jybase/encrypt"
 	elastic "app.yhyue.com/moapp/jybase/es"
 	"app.yhyue.com/moapp/jybase/mongodb"
 	"app.yhyue.com/moapp/jypkg/ent/util"
@@ -15,13 +14,14 @@ import (
 	"fmt"
 	"github.com/RoaringBitmap/roaring"
 	"go.mongodb.org/mongo-driver/bson"
+	"log"
+	"strings"
 	"time"
 )
 
 const (
 	BuyerIndex = "buyer" // 采购单位index
 	BuyerType  = "buyer"
-	query      = `{%s "query":{"bool":{"must":[%s],"must_not": [{"term": {"buyer_name": ""}}]}}}`
 )
 
 type EmPloyService struct{}
@@ -29,83 +29,23 @@ type EmPloyService struct{}
 // 收录情况查询
 func (e *EmPloyService) InfoEmployinfo(in *types.InfoEmployinfoReq) []map[string]interface{} {
 	data := []map[string]interface{}{}
-	for _, v := range in.Id {
+	for _, v := range strings.Split(in.IdArr, ",") {
 		vint := int64(0)
-		table := entity.EMPLOY_CUSTOM
+		table, findKey, employKey, source := EmployKeyFormat(in.EmployType)
 		id := ""
-		source := 0
-		if in.EmployType == 3 {
-			//判断传过来的是名字还是ID
-			//id转中文
-			if len(v) > 0 && len([]rune(v)) == len(v) {
-				//此数据是id
-				//获取中文名字
-				id = util.DecodeId(v)
-			} else {
-				//次数据传的名字
-				id = getBuyerIdByName(v)
-			}
-		} else {
-			id = util.DecodeId(v)
+		id = IdFormat(v, in.EmployType)
+		if id == "" {
+			log.Println(v, in.EmployType, "该信息查询不到数据")
+			break
 		}
 		valueMap := map[string]interface{}{
 			"id": v,
 		}
-		employKey := "company_id"
-		findKey := "employ_custom_id"
 		//有收录情况
-		rb := roaring.NewBitmap()
-		bytes := []byte{}
-		byte1 := []byte{}
-		byte2 := []byte{}
-		byte3 := []byte{}
-		byte4 := []byte{}
-		MC.CrmMysql.DB.QueryRow("select   search_tencent, search_buyer, search_ent, search_nzj from employ_summary where  position_id=?", in.PositionId).Scan(&byte1, &byte2, &byte3, &byte4)
-		if byte1 != nil {
-			search_tencent := roaring.NewBitmap()
-			search_buyer := roaring.NewBitmap()
-			search_ent := roaring.NewBitmap()
-			search_nzj := roaring.NewBitmap()
-			if byte1 != nil && len(byte1) > 0 {
-				search_tencent.UnmarshalBinary(byte1)
-			}
-			if byte2 != nil && len(byte2) > 0 {
-				search_buyer.UnmarshalBinary(byte2)
-			}
-			if byte3 != nil && len(byte3) > 0 {
-				search_ent.UnmarshalBinary(byte3)
-			}
-			if byte4 != nil && len(byte4) > 0 {
-				search_nzj.UnmarshalBinary(byte4)
-			}
-			switch in.EmployType {
-			case 1:
-				bytes = byte1
-				table = entity.EMPLOY_INFO
-				employKey = "source_id"
-				findKey = "employ_info_id"
-				source = 1
-			case 2:
-				bytes = byte2
-				source = 1
-			case 3:
-				bytes = byte3
-				source = 2
-			case 4:
-				bytes = byte4
-				source = 2
-				table = entity.EMPLOY_INFO
-				employKey = "source_id"
-				findKey = "employ_info_id"
-			}
-			err := rb.UnmarshalBinary(bytes)
-			if err != nil {
-				break
-			}
-			vint = mongodb.StringTOBsonId(v).Timestamp().Unix()
-			valueMap["isEmploy"] = rb.Contains(uint32(vint))
-		}
-		if len(in.Id) == 1 {
+		summaryMap := SummaryFormat(in.PositionId)
+		vint = mongodb.StringTOBsonId(id).Timestamp().Unix()
+		valueMap["isEmploy"] = summaryMap[in.EmployType].Contains(uint32(vint))
+		if len(strings.Split(in.IdArr, ",")) == 1 {
 			//列表查询
 			//是否忽略处理
 			employData := MC.CrmMysql.FindOne(table, map[string]interface{}{
@@ -114,29 +54,32 @@ func (e *EmPloyService) InfoEmployinfo(in *types.InfoEmployinfoReq) []map[string
 				"source":      source,
 			}, "", "")
 			if employData != nil && len(*employData) > 0 {
-				valueMap["isIgnore"] = common.Int64All((*employData)["is_ignore"])
-			} else {
-				valueMap["isIgnore"] = 0
-			}
-			//客户数量
-			customCount := MC.CrmMysql.Count(entity.CUSTOM, map[string]interface{}{
-				findKey:       id,
-				"position_id": in.PositionId,
-			})
-			valueMap["customCount"] = customCount
-			if in.EmployType == 1 || in.EmployType == 4 {
-				//销售线索数量
-				clueCount := MC.CrmMysql.Count(entity.SALE_CLUE, map[string]interface{}{
-					"employ_info_id": id,
-					"position_id":    in.PositionId,
-				})
-				valueMap["clueCount"] = clueCount
-				//销售机会数量
-				chanceCount := MC.CrmMysql.Count(entity.SALE_CHANCE, map[string]interface{}{
-					"employ_info_id": id,
-					"position_id":    in.PositionId,
+				valueMap["isIgnore"] = common.If(common.Int64All((*employData)["is_ignore"]) == 1, true, false)
+				//客户数量
+				customCount := MC.CrmMysql.Count(entity.CUSTOM, map[string]interface{}{
+					findKey:       id,
+					"position_id": in.PositionId,
 				})
-				valueMap["chanceCount"] = chanceCount
+				valueMap["customCount"] = customCount
+				if in.EmployType == 1 || in.EmployType == 4 {
+					//销售线索数量
+					clueCount := MC.CrmMysql.Count(entity.SALE_CLUE, map[string]interface{}{
+						"employ_info_id": id,
+						"position_id":    in.PositionId,
+					})
+					valueMap["clueCount"] = clueCount
+					//销售机会数量
+					chanceCount := MC.CrmMysql.Count(entity.SALE_CHANCE, map[string]interface{}{
+						"employ_info_id": id,
+						"position_id":    in.PositionId,
+					})
+					valueMap["chanceCount"] = chanceCount
+				}
+			} else {
+				valueMap["chanceCount"] = 0
+				valueMap["clueCount"] = 0
+				valueMap["isIgnore"] = false
+				valueMap["customCount"] = 0
 			}
 		}
 		data = append(data, valueMap)
@@ -147,64 +90,20 @@ func (e *EmPloyService) InfoEmployinfo(in *types.InfoEmployinfoReq) []map[string
 // 收录操作
 func (e *EmPloyService) EmployOperate(in *types.EmployOperateReq) bool {
 	//收录汇总表
-	employSummaryData := MC.CrmMysql.FindOne(entity.EMPLOY_SUMMARY, map[string]interface{}{
-		"position_id": in.PositionId,
-	}, "", "")
-	byte1 := []byte{}
-	byte2 := []byte{}
-	byte3 := []byte{}
-	byte4 := []byte{}
-	MC.CrmMysql.DB.QueryRow("select   search_tencent, search_buyer, search_ent, search_nzj from employ_summary where  position_id=?", in.PositionId).Scan(&byte1, &byte2, &byte3, &byte4)
-	search_tencent := roaring.NewBitmap()
-	search_buyer := roaring.NewBitmap()
-	search_ent := roaring.NewBitmap()
-	search_nzj := roaring.NewBitmap()
-	if byte1 != nil && len(byte1) > 0 {
-		search_tencent.UnmarshalBinary(byte1)
-	}
-	if byte2 != nil && len(byte2) > 0 {
-		search_buyer.UnmarshalBinary(byte2)
-	}
-	if byte3 != nil && len(byte3) > 0 {
-		search_ent.UnmarshalBinary(byte3)
-	}
-	if byte4 != nil && len(byte4) > 0 {
-		search_nzj.UnmarshalBinary(byte4)
-	}
-	table := ""
-	switch in.EmployType {
-	case 1, 4:
-		table = entity.EMPLOY_INFO
-	case 2, 3:
-		table = entity.EMPLOY_CUSTOM
-	}
+	table, _, employKey, source := EmployKeyFormat(in.EmployType)
+	summaryMap := SummaryFormat(in.PositionId)
 	return MC.CrmMysql.ExecTx("收录操作", func(tx *sql.Tx) bool {
-		for _, v1 := range in.IdArr {
+		fool := false
+		for _, v1 := range strings.Split(in.IdArr, ",") {
 			//id转中文
 			id := ""
-			name := ""
 			findMap := map[string]interface{}{}
 			findMap["position_id"] = in.PositionId
-			if in.EmployType == 3 {
-				//判断传过来的是名字还是ID
-				//id转中文
-				if len(v1) > 0 && len([]rune(v1)) == len(v1) {
-					//此数据是id
-					//获取中文名字
-					id = util.DecodeId(v1)
-					name = getBuyerIdByName(id)
-				} else {
-					//次数据传的名字
-					name = v1
-					id = getBuyerIdByName(v1)
-				}
-				findMap["company_id"] = id
-			} else if in.EmployType == 2 {
-				id = encrypt.DecodeArticleId2ByCheck(v1)[0]
-				findMap["company_id"] = id
-			} else {
-				id = encrypt.CommonDecodeArticle("content", v1)[0]
-				findMap["source_id"] = id
+			id = IdFormat(v1, in.EmployType)
+			findMap[employKey] = id
+			if id == "" {
+				log.Println(v1, in.EmployType, "该信息查询不到数据")
+				break
 			}
 			if in.IsEmploy {
 				if MC.CrmMysql.Count(table, findMap) > 0 {
@@ -214,96 +113,54 @@ func (e *EmPloyService) EmployOperate(in *types.EmployOperateReq) bool {
 				} else {
 					//收录新增
 					data := map[string]interface{}{}
-					if in.EmployType == 2 {
-						data = CustomFind(id, "", in.EmployType)
-					} else if in.EmployType == 3 {
-						//id转中文
-						data = CustomFind("", name, in.EmployType)
-					} else {
+					if in.EmployType == 1 || in.EmployType == 4 {
 						data = InfoFind(id, in.EmployType)
-						data["type"] = in.SourceType
-						data["source"] = in.EmployType
 						data["employ_way"] = 1
 						data["jybx_url"] = "/article/content/" + v1 + ".html"
+					} else {
+						data = CustomFind(id, in.EmployType)
 					}
 					data["position_id"] = in.PositionId
 					data["ent_id"] = in.EntId
-					MC.CrmMysql.InsertByTx(tx, table, data)
+					data["source"] = source
+					ok := MC.CrmMysql.InsertByTx(tx, table, data)
+					if ok <= 0 {
+						log.Println(v1, id, in.EmployType, "收录失败")
+						break
+					}
 				}
 			} else {
 				//取消收录
-				MC.CrmMysql.UpdateByTx(tx, table, findMap, map[string]interface{}{
+				ok := MC.CrmMysql.UpdateByTx(tx, table, findMap, map[string]interface{}{
 					"status": -1,
 				})
+				if !ok {
+					log.Println(v1, id, in.EmployType, "取消收录失败")
+				}
 			}
 			//收录汇总表处理
-			KeyHandle(mongodb.StringTOBsonId(id).Timestamp().Unix(), in.EmployType, in.IsEmploy, search_tencent, search_buyer, search_ent, search_nzj)
-		}
-		search_tencent_byte, _ := search_tencent.ToBytes()
-		search_buyer_byte, _ := search_buyer.ToBytes()
-		search_ent_byte, _ := search_ent.ToBytes()
-		search_nzj_byte, _ := search_nzj.ToBytes()
-		if employSummaryData != nil && len(*employSummaryData) > 0 {
-			//修改
-			MC.CrmMysql.UpdateByTx(tx, entity.EMPLOY_SUMMARY, map[string]interface{}{
-				"position_id": in.PositionId,
-			}, map[string]interface{}{
-				"search_tencent": search_tencent_byte,
-				"search_buyer":   search_buyer_byte,
-				"search_ent":     search_ent_byte,
-				"search_nzj":     search_nzj_byte,
-			})
-		} else {
-			//新增
-			MC.CrmMysql.InsertByTx(tx, entity.EMPLOY_SUMMARY, map[string]interface{}{
-				"position_id ":   in.PositionId,
-				"search_tencent": search_tencent_byte,
-				"search_buyer":   search_buyer_byte,
-				"search_ent":     search_ent_byte,
-				"search_nzj":     search_nzj_byte,
-			})
-		}
-		return true
-	})
-}
+			if in.IsEmploy {
+				summaryMap[in.EmployType].Add(uint32(mongodb.StringTOBsonId(id).Timestamp().Unix()))
+			} else {
+				summaryMap[in.EmployType].Remove(uint32(mongodb.StringTOBsonId(id).Timestamp().Unix()))
+			}
+			fool = true
 
-// 收录数据处理
-func KeyHandle(id int64, employType int64, isEmploy bool, search_tencent, search_buyer, search_ent, search_nzj *roaring.Bitmap) {
-	switch employType {
-	case 1:
-		if isEmploy {
-			search_tencent.Add(uint32(id))
-		} else {
-			search_tencent.Remove(uint32(id))
-		}
-	case 2:
-		if isEmploy {
-			search_buyer.Add(uint32(id))
-		} else {
-			search_buyer.Remove(uint32(id))
-		}
-	case 3:
-		if isEmploy {
-			search_ent.Add(uint32(id))
-		} else {
-			search_ent.Remove(uint32(id))
 		}
-	case 4:
-		if isEmploy {
-			search_nzj.Add(uint32(id))
+		if fool {
+			return SummarySave(tx, in.PositionId, summaryMap)
 		} else {
-			search_nzj.Remove(uint32(id))
+			return false
 		}
 
-	}
-	return
+	})
 }
 
 // 企业信息查询
-func CustomFind(id string, name string, employType int64) map[string]interface{} {
+func CustomFind(id string, employType int64) map[string]interface{} {
 	data := map[string]interface{}{}
 	//company_id 企业id name户名称 address 地址
-	if employType == 2 {
+	if employType == 3 {
 		//企业详情
 		entinfo, _ := MC.MgoEnt.FindOneByField("qyxy_std", map[string]interface{}{"_id": id}, map[string]interface{}{
 			"company_address": 1, //注册地
@@ -312,16 +169,15 @@ func CustomFind(id string, name string, employType int64) map[string]interface{}
 		if entinfo != nil && len(*entinfo) > 0 {
 			data["name"] = (*entinfo)["company_name"]
 			data["address"] = (*entinfo)["company_address"]
-			data["company_id"] = (*entinfo)["id"]
+			data["company_id"] = id
 		}
 	} else {
 		//采购单位详情
-		entNameQuery := fmt.Sprintf(`{"query":{"bool":{"must":[{"term":{"buyer_name":"%s"}}]}},"size":1,"_source":["city","buyer_name","id"]}`, name)
-		rs := elastic.Get(BuyerIndex, BuyerType, entNameQuery)
+		rs := elastic.Get(BuyerIndex, BuyerType, fmt.Sprintf(`{"query":{"bool":{"must":[{"terms":{"_id":["%s"]}}]}},"size":1,"_source":["buyer_name","city"]}`, id))
 		if rs != nil && len(*rs) > 0 {
 			data["name"] = (*rs)[0]["buyer_name"]
 			data["address"] = (*rs)[0]["city"]
-			data["company_id"] = (*rs)[0]["id"]
+			data["company_id"] = id
 		}
 	}
 	data["status"] = 1
@@ -362,6 +218,8 @@ func InfoFind(id string, employType int64) map[string]interface{} {
 			data["budget"] = obj["budget"]
 			data["bidamount"] = obj["bidamount"]
 			data["annex"] = 0
+			//类型处理
+			//data["type"] = in.SourceType
 			if obj["projectinfo"] != nil {
 				projectinfo := common.ObjToMap(obj["projectinfo"])
 				if (*projectinfo)["attachments"] != nil {
@@ -387,19 +245,234 @@ func InfoFind(id string, employType int64) map[string]interface{} {
 	data["create_time"] = time.Now().Format(date.Date_Full_Layout)
 	return data
 }
-func getBuyerNameById(buyerId string) (buyerName string) {
-	r := elastic.Get(BuyerIndex, BuyerType, fmt.Sprintf(`{"query":{"bool":{"must":[{"terms":{"_id":["%s"]}}]}},"size":1,"_source":["name"]}`, buyerId))
-	if r == nil || len(*r) == 0 {
-		return
-	}
-	buyerName, _ = (*r)[0]["name"].(string)
-	return
-}
 func getBuyerIdByName(buyeName string) (buyerId string) {
-	r := elastic.Get("buyer", "buyer", fmt.Sprintf(`{"query":{"bool":{"must":[{"term":{"buyer_name":"%s"}}]}},"size":1,"_source":["city","id"]}`, buyeName))
+	r := elastic.Get(BuyerIndex, BuyerType, fmt.Sprintf(`{"query":{"bool":{"must":[{"term":{"buyer_name":"%s"}}]}},"size":1,"_source":["city","id"]}`, buyeName))
 	if r == nil || len(*r) == 0 {
 		return
 	}
 	buyerId, _ = (*r)[0]["_id"].(string)
 	return
 }
+func IdFormat(encryptionId string, employType int64) string {
+	decryptId := ""
+	switch employType {
+	case 1, 2:
+		decryptId = util.DecodeId(encryptionId)
+	case 3:
+		if len(encryptionId) > 0 && len([]rune(encryptionId)) == len(encryptionId) {
+			//此数据是id
+			//获取中文名字
+			decryptId = util.DecodeId(encryptionId)
+		} else {
+			//次数据传的名字
+			decryptId = getBuyerIdByName(encryptionId)
+		}
+	}
+	return decryptId
+}
+func SummaryFormat(positionId int64) map[int64]*roaring.Bitmap {
+	byte1 := []byte{}
+	byte2 := []byte{}
+	byte3 := []byte{}
+	byte4 := []byte{}
+	MC.CrmMysql.DB.QueryRow("select   search_tencent, search_buyer, search_ent, search_nzj from employ_summary where  position_id=?", positionId).Scan(&byte1, &byte3, &byte2, &byte4)
+	rb1 := roaring.NewBitmap()
+	rb2 := roaring.NewBitmap()
+	rb3 := roaring.NewBitmap()
+	rb4 := roaring.NewBitmap()
+	data := map[int64]*roaring.Bitmap{}
+	if byte1 != nil && len(byte1) > 0 {
+		rb1.UnmarshalBinary(byte1)
+	}
+	if byte2 != nil && len(byte2) > 0 {
+		rb2.UnmarshalBinary(byte2)
+	}
+	if byte3 != nil && len(byte3) > 0 {
+		rb3.UnmarshalBinary(byte3)
+	}
+	if byte4 != nil && len(byte4) > 0 {
+		rb4.UnmarshalBinary(byte4)
+	}
+	data[1] = rb1
+	data[2] = rb2
+	data[3] = rb3
+	data[4] = rb4
+	return data
+}
+func SummarySave(tx *sql.Tx, positionId int64, data map[int64]*roaring.Bitmap) bool {
+	employSummaryData := MC.CrmMysql.FindOne(entity.EMPLOY_SUMMARY, map[string]interface{}{
+		"position_id": positionId,
+	}, "", "")
+	if employSummaryData != nil && len(*employSummaryData) > 0 {
+		//修改
+		updateData := map[string]interface{}{}
+		updateData["search_tencent"], _ = data[1].ToBytes()
+		updateData["search_buyer"], _ = data[3].ToBytes()
+		updateData["search_ent"], _ = data[2].ToBytes()
+		updateData["search_nzj"], _ = data[4].ToBytes()
+		ok := MC.CrmMysql.UpdateByTx(tx, entity.EMPLOY_SUMMARY, map[string]interface{}{
+			"position_id": positionId,
+		}, updateData)
+		return ok
+	} else {
+		//新增
+		insertData := map[string]interface{}{}
+		insertData["position_id"] = positionId
+		insertData["search_tencent"], _ = data[1].ToBytes()
+		insertData["search_buyer"], _ = data[3].ToBytes()
+		insertData["search_ent"], _ = data[2].ToBytes()
+		insertData["search_nzj"], _ = data[4].ToBytes()
+		ok := MC.CrmMysql.InsertByTx(tx, entity.EMPLOY_SUMMARY, insertData)
+		return ok > 0
+	}
+}
+
+// 根据收录类型 字段处理 table,findKey,employKey,source
+func EmployKeyFormat(employType int64) (string, string, string, int64) {
+	table := ""
+	employKey := "company_id"
+	findKey := "employ_custom_id"
+	source := int64(0)
+	switch employType {
+	case 1:
+		table = entity.EMPLOY_INFO
+		employKey = "source_id"
+		findKey = "employ_info_id"
+		source = 1
+	case 2:
+		table = entity.EMPLOY_CUSTOM
+		source = 1
+	case 3:
+		table = entity.EMPLOY_CUSTOM
+		source = 2
+	case 4:
+		table = entity.EMPLOY_INFO
+		source = 2
+		employKey = "source_id"
+		findKey = "employ_info_id"
+	}
+	return table, findKey, employKey, source
+
+}
+
+// 忽略操作
+func (e *EmPloyService) IgnoreOperate(in *types.IgnoreOperateReq) {
+	//
+	table := ""
+	switch in.EmployType {
+	case 1, 4:
+		table = entity.EMPLOY_INFO
+	case 2, 3:
+		table = entity.EMPLOY_CUSTOM
+	}
+	for _, v := range strings.Split(in.IdArr, ",") {
+		id := IdFormat(v, in.EmployType)
+		if id == "" {
+			log.Println(v, id, in.EmployType, "忽略处理,id解析失败")
+			break
+		}
+		findMap := map[string]interface{}{
+			"position_id": in.PositionId,
+		}
+		if in.EmployType == 3 || in.EmployType == 2 {
+			findMap["company_id"] = id
+		} else {
+			findMap["source_id"] = id
+		}
+		if MC.CrmMysql.Count(table, findMap) == 0 {
+			log.Println(v, id, in.EmployType, "忽略处理,id所对应数据不存在")
+			break
+		}
+		if in.IsIgnore {
+			MC.CrmMysql.Update(table, findMap, map[string]interface{}{
+				"is_ignore": 1,
+			})
+		} else {
+			MC.CrmMysql.Update(table, findMap, map[string]interface{}{
+				"is_ignore": 0,
+			})
+		}
+	}
+}
+
+type PersonSmmary struct {
+	EntUserId int64
+	Summary   map[int64]*roaring.Bitmap
+}
+
+// 分发操作
+func (e *EmPloyService) DistributePerson(in *types.EmployDistributeReq) bool {
+	return MC.CrmMysql.ExecTx("收录操作", func(tx *sql.Tx) bool {
+		personMap := map[int64]PersonSmmary{}
+		//汇总表查询
+		for _, person := range in.Person {
+			personMap[person.PositionId] = PersonSmmary{
+				EntUserId: person.EntUserId,
+				Summary:   SummaryFormat(person.PositionId),
+			}
+		}
+		//分发数据处理
+		infoMap := map[string]map[string]interface{}{}
+		for positionId, personSmmary := range personMap {
+			fool := false
+			for _, v := range strings.Split(in.EmployIdArr, ",") {
+				VMap := map[string]interface{}{}
+				if infoMap[v] == nil {
+					//新增记录
+					infoData := MC.CrmMysql.FindOne(entity.EMPLOY_INFO, map[string]interface{}{
+						"id": v,
+					}, "", "")
+					if infoData != nil && len(*infoData) > 0 {
+						(*infoData)["dis_id"] = v
+						(*infoData)["is_handle"] = 0
+						(*infoData)["is_ignore"] = 0
+						(*infoData)["is_dis"] = 0
+						(*infoData)["is_create_clue"] = 0
+						(*infoData)["is_create_chance"] = 0
+						(*infoData)["is_create_custom"] = 0
+						(*infoData)["create_time"] = time.Now().Format(date.Date_Full_Layout)
+						delete((*infoData), "id")
+					} else {
+						log.Println(v, "查询不到改收录信息")
+						break
+					}
+					//更改已分发状态
+					if common.IntAll((*infoData)["is_dis"]) != 1 {
+						MC.CrmMysql.UpdateByTx(tx, entity.EMPLOY_INFO, map[string]interface{}{
+							"id": v,
+						}, map[string]interface{}{
+							"is_dis": 1,
+						})
+					}
+					infoMap[v] = *infoData
+					VMap = (*infoData)
+				} else {
+					VMap = infoMap[v]
+				}
+				//查询时候收录过
+				findMap := map[string]interface{}{
+					"position_id": positionId,
+					"source_id":   VMap["source_id"],
+				}
+				if MC.CrmMysql.Count(entity.EMPLOY_INFO, findMap) == 0 {
+					//新增
+					//
+					VMap["ent_user_id"] = personSmmary.EntUserId
+					VMap["position_id"] = positionId
+					ok := MC.CrmMysql.InsertByTx(tx, entity.EMPLOY_INFO, VMap)
+					if ok > 0 {
+						employType := common.If(common.Int64All(VMap["source"]) == 1, 1, 4)
+						personSmmary.Summary[common.Int64All(employType)].Add(uint32(mongodb.StringTOBsonId(common.InterfaceToStr(VMap["source_id"])).Timestamp().Unix()))
+						fool = true
+					}
+				}
+				if fool {
+					if !SummarySave(tx, positionId, personSmmary.Summary) {
+						return false
+					}
+				}
+			}
+		}
+		return true
+	})
+}