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