123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005 |
- package service
- import (
- "database/sql"
- "fmt"
- "log"
- "strings"
- "time"
- "app.yhyue.com/moapp/jybase/common"
- "app.yhyue.com/moapp/jybase/date"
- elastic "app.yhyue.com/moapp/jybase/es"
- "app.yhyue.com/moapp/jypkg/ent/util"
- MC "bp.jydev.jianyu360.cn/CRM/application/api/common"
- "bp.jydev.jianyu360.cn/CRM/application/api/internal/types"
- "bp.jydev.jianyu360.cn/CRM/application/entity"
- "github.com/RoaringBitmap/roaring"
- "github.com/gogf/gf/v2/util/gconv"
- )
- const (
- BuyerIndex = "buyer" // 采购单位index
- BuyerType = "buyer"
- INDEX = "bidding"
- TYPE = "bidding"
- )
- type EmPloyService struct{}
- type PersonSmmary struct {
- EntUserId int64
- EntDeptId int64
- Summary map[int64]*roaring.Bitmap
- }
- // InfoEmployinfo 收录情况查询
- func (e *EmPloyService) InfoEmployinfo(in *types.InfoEmployinfoReq) ([]map[string]interface{}, int64) {
- var data []map[string]interface{}
- depIDArr := ""
- batchEmploy := int64(0)
- if in.EntNicheDis > 0 {
- //查询所有部门标识
- deptArr := MC.MainMysql.SelectBySql("select GROUP_CONCAT(DISTINCT b.id) as depIDArr from entniche_department_parent a"+
- " INNER JOIN entniche_department b "+
- "on (b.ent_id=? and (b.id=? or (a.pid=? and a.id=b.id)))", in.EntId, in.EntDeptId, in.EntDeptId)
- if len(*deptArr) == 0 {
- return data, batchEmploy
- }
- depIDArr = common.InterfaceToStr((*deptArr)[0]["depIDArr"])
- if depIDArr == "" {
- return data, batchEmploy
- }
- }
- //是否可以批量收录配置回显
- accountId := int64(0)
- if in.PositionType == 0 {
- accountId = in.AccountId
- } else {
- accountId = in.EntAccountId
- }
- configData := MC.CrmMysql.FindOne("config_tenant", map[string]interface{}{
- "account_id": accountId,
- }, "batch_employ", "")
- if configData != nil {
- batchEmploy = gconv.Int64((*configData)["batch_employ"])
- }
- //版本查询
- res := MC.Middleground.ResourceCenter.Haspowers(in.AccountId, in.EntAccountId, in.EntId, in.EntUserId)
- version := 0
- for _, pCode := range res.Powers {
- //0:通用版 1:物业专版
- if pCode == "bi_yx_wyzb" {
- version = 1
- }
- }
- infoId1Arr := []string{}
- niJianIdArr := []string{}
- infoId2Arr := []string{}
- wuye1Arr := []string{}
- wuye2Arr := []string{}
- infoMap := map[string]interface{}{}
- table, findKey, employKey, employData := employKeyFormat(in.EmployType, in.IdArr)
- for _, employ := range employData {
- source := employ.Source
- isNiJian := employ.IsNiJian
- if (employ.Subtype == "成交" || employ.Subtype == "中标" || employ.Subtype == "合同" || employ.Subtype == "验收" || employ.Subtype == "违规") && in.EmployType == 1 && version == 1 {
- infoMap[employ.Id] = employ.ProjectId
- if isNiJian {
- infoMap[employ.Id] = employ.ProjectId
- if source == 1 {
- wuye1Arr = append(wuye1Arr, employ.ProjectId)
- } else {
- wuye2Arr = append(wuye2Arr, employ.ProjectId)
- }
- } else {
- infoMap[employ.Id] = employ.SourceId
- if source == 1 {
- wuye1Arr = append(wuye1Arr, employ.SourceId)
- } else {
- wuye2Arr = append(wuye2Arr, employ.SourceId)
- }
- }
- } else if isNiJian {
- infoMap[employ.Id] = employ.ProjectId
- niJianIdArr = append(niJianIdArr, employ.ProjectId)
- } else if source == 2 {
- infoMap[employ.Id] = employ.SourceId
- infoId2Arr = append(infoId2Arr, employ.SourceId)
- } else if source == 1 {
- infoMap[employ.Id] = employ.SourceId
- infoId1Arr = append(infoId1Arr, employ.SourceId)
- }
- }
- //收录情况查询
- dataList := map[string]map[string]interface{}{}
- if in.EntNicheDis > 0 {
- dataList = employInfoEnt(table, employKey, findKey, depIDArr, in, version, infoId1Arr, infoId2Arr, niJianIdArr, wuye1Arr, wuye2Arr)
- } else {
- dataList = employInfoPerson(table, employKey, findKey, in, version, infoId1Arr, infoId2Arr, niJianIdArr, wuye1Arr, wuye2Arr)
- }
- for k, v := range infoMap {
- fool := true
- for sourceId, v1 := range dataList {
- if v == sourceId {
- v1["id"] = k
- data = append(data, v1)
- fool = false
- break
- }
- }
- if fool {
- data = append(data, map[string]interface{}{
- "id": k,
- "isIgnore": false,
- "isEmploy": false,
- "customCount": 0,
- "clueCount": 0,
- "chanceCount": 0,
- "type": 1,
- })
- }
- }
- return data, batchEmploy
- }
- // EmployOperate 收录操作
- func (e *EmPloyService) EmployOperate(in *types.EmployOperateReq) (bool, string) {
- log.Println("收录入参", in)
- //收录汇总表
- //summaryMap := SummaryFormat(in.PositionId)
- msg := ""
- return MC.CrmMysql.ExecTx("收录操作", func(tx *sql.Tx) bool {
- fool := false
- //id转中文
- table, _, employKey, data := employKeyFormat(in.EmployType, in.IdArr)
- for id, employ := range data {
- findMap := map[string]interface{}{}
- findMap["position_id"] = in.PositionId
- if employ.IsNiJian {
- findMap[employKey] = employ.ProjectId
- } else {
- findMap[employKey] = id
- }
- if employ.SourceId == "" {
- log.Println(employ.Id, in.EmployType, "该信息查询不到数据")
- continue
- }
- if in.IsEmploy {
- if MC.CrmMysql.Count(table, findMap) > 0 {
- MC.CrmMysql.UpdateByTx(tx, table, findMap, map[string]interface{}{
- "status": 1,
- })
- } else {
- //收录新增
- data := map[string]interface{}{}
- if in.EmployType == 1 || in.EmployType == 4 {
- data = infoFind(id, employ.Id)
- } else if in.EmployType == 2 {
- data = customFind(id, in.EmployType)
- data["jybx_url"] = "/swordfish/page_big_pc/ent_portrait/" + employ.Id
- data["source"] = employ.Source
- } else if in.EmployType == 3 {
- data = customFind(id, in.EmployType)
- data["jybx_url"] = "/publicapply/biTransfer?buyerName=" + employ.Id
- data["source"] = employ.Source
- }
- data["position_id"] = in.PositionId
- data["ent_id"] = in.EntId
- data["ent_dept_id"] = in.EntDeptId
- data["ent_user_id"] = in.EntUserId
- ok := MC.CrmMysql.InsertByTx(tx, table, data)
- if ok <= 0 {
- log.Println(employ.Id, id, in.EmployType, "收录失败")
- continue
- }
- }
- fool = true
- } else {
- //取消收录
- if in.From == "jhfp" {
- findMap["type"] = 3
- }
- if MC.CrmMysql.Count(table, findMap) > 0 {
- ok := MC.CrmMysql.UpdateByTx(tx, table, findMap, map[string]interface{}{
- "status": -1,
- })
- if !ok {
- log.Println(employ.Id, id, in.EmployType, "取消收录失败")
- continue
- }
- fool = true
- } else {
- if in.EmployType == 1 {
- msg = "该资讯已有员工收录,不可取消收录。"
- continue
- } else {
- msg = "该企业已有员工收录,不可取消收录。"
- continue
- }
- }
- }
- }
- if in.IsEmploy && !fool {
- msg = "收录失败"
- }
- return fool
- }), msg
- }
- // customFind 企业信息查询
- func customFind(id string, employType int64) map[string]interface{} {
- data := map[string]interface{}{}
- //company_id 企业id name户名称 address 地址 industry 行业
- if employType == 2 {
- //企业详情
- entinfo, _ := MC.MgoEnt.FindOneByField("qyxy_std", map[string]interface{}{"_id": id}, map[string]interface{}{
- "company_address": 1, //注册地
- "company_name": 1,
- })
- if entinfo != nil && len(*entinfo) > 0 {
- data["name"] = (*entinfo)["company_name"]
- data["address"] = (*entinfo)["company_address"]
- data["company_id"] = id
- }
- } else {
- //采购单位详情
- 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"] = id
- }
- }
- data["status"] = 1
- data["create_time"] = time.Now().Format(date.Date_Full_Layout)
- return data
- }
- // infoFind 标讯信息查询
- func infoFind(id string, v1 string) map[string]interface{} {
- data := map[string]interface{}{}
- //source_id 信息id、项目id- title 标题-area 省 -city 市 -subtype 信息类型二级分类
- //buyerclass 采购单位行业 -budget 预算 -bidamount 中标金额 buyer采购单位 annex有无附件 publishtime发布时间 projectname 项目时间
- //ownerclass 业主类型(拟在建搜索) expurasing_time 预计采购时间 jybx_url 标讯详情页
- //标讯信息
- obj := map[string]interface{}{}
- aobj := elastic.Get(INDEX, TYPE, fmt.Sprintf(`{"query":{"bool":{"must":[{"match":{"id":"%s"}}],"must_not":[],"should":[]}},"from":0,"size":10,"_source":["_id","purchasinglist","projectname","projectcode","title","s_winner","buyertel","bidstatus","site","bidamount","toptype","winneraddr","winner","agency","buyer","detail","city","subtype","buyerclass","href","comeintime","winnertel","area","publishtime","buyeraddr","agencytel","budget","entidlist","buyerperson","winnerperson","agencyaddr","recommended_service","competehref","owner","total_investment","projectaddr","projectperiod","approvedept","approvecontent","approvecode","approvenumber","approvetime","approvestatus","project_scale"],"sort":[],"aggs":{}}`, id))
- log.Println(len(*aobj))
- if aobj != nil || *aobj != nil || len(*aobj) > 0 {
- obj = (*aobj)[0]
- }
- toptype := common.InterfaceToStr(obj["toptype"])
- subtype := common.InterfaceToStr(obj["subtype"])
- pushTime := ""
- if obj != nil && len(obj) > 0 {
- data["title"] = common.ObjToString(obj["title"])
- data["city"] = obj["city"]
- data["area"] = obj["area"]
- data["subtype"] = obj["subtype"]
- data["buyerclass"] = obj["buyerclass"]
- data["budget"] = obj["budget"]
- data["bidamount"] = obj["bidamount"]
- data["annex"] = 0
- data["buyer"] = obj["buyer"]
- data["winner"] = obj["s_winner"]
- data["jybx_url"] = "/article/content/" + v1 + ".html"
- //类型处理
- pushTime = time.Unix(common.Int64All(obj["publishtime"]), 0).Format(date.Date_Full_Layout)
- data["source"] = 1
- data["source_id"] = id
- if subtype == "拟建" {
- data["source"] = 2
- }
- if toptype == "采购意向" || toptype == "预告" || toptype == "招标" || toptype == "" {
- data["type"] = 2
- } else {
- if subtype == "废标" || subtype == "流标" || subtype == "其它" {
- data["type"] = 2
- } else if subtype == "成交" || subtype == "中标" || subtype == "合同" || subtype == "验收" || subtype == "违规" {
- data["type"] = 3
- } else {
- data["type"] = 1
- }
- }
- if obj["projectinfo"] != nil {
- projectinfo := common.ObjToMap(obj["projectinfo"])
- if (*projectinfo)["attachments"] != nil {
- data["annex"] = 1
- }
- }
- data["publishtime"] = pushTime
- data["show_time"] = pushTime
- data["projectname"] = obj["projectname"]
- procurementlist, _ := obj["procurementlist"].([]interface{})
- for _, vs := range procurementlist { //1.采购意向清单数据集打码处理
- vsMap, _ := vs.(map[string]interface{})
- if vsMap["expurasingtime"] != nil {
- data["expurasing_time"] = vsMap["expurasingtime"]
- break
- }
- }
- }
- data["status"] = 1
- data["employ_way"] = 1
- data["create_time"] = time.Now().Format(date.Date_Full_Layout)
- if subtype == "拟建" {
- data = niJianHandle(id, data, v1, pushTime)
- data["type"] = 1
- }
- return data
- }
- // GetBuyerIdByName 通过采购单位名称获取id
- func getBuyerIdByName(buyerName string) (buyerId string) {
- r := elastic.Get(BuyerIndex, BuyerType, fmt.Sprintf(`{"query":{"bool":{"must":[{"term":{"buyer_name":"%s"}}]}},"size":1,"_source":["city","id"]}`, buyerName))
- if r == nil || len(*r) == 0 {
- return
- }
- buyerId, _ = (*r)[0]["_id"].(string)
- return
- }
- // IdFormat id解密
- 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
- }
- type Employ struct {
- Source int64
- IsNiJian bool
- ProjectId string
- Id string
- SourceId string
- Subtype string
- }
- // employKeyFormat 根据收录类型 字段处理 table,findKey,employKey,source
- func employKeyFormat(employType int64, idArrStr string) (string, string, string, map[string]Employ) {
- table := ""
- employKey := "company_id"
- findKey := "employ_custom_id"
- infoIdMap := map[string]Employ{}
- idArr := []string{}
- 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"
- }
- for _, v := range strings.Split(idArrStr, ",") {
- id := idFormat(v, employType)
- idArr = append(idArr, id)
- infoIdMap[id] = Employ{
- Source: source,
- IsNiJian: false,
- ProjectId: "",
- Id: v,
- SourceId: id,
- }
- }
- if employType == 1 {
- table = entity.EMPLOY_INFO
- employKey = "source_id"
- findKey = "employ_info_id"
- source = 1
- aobj := elastic.Get(INDEX, TYPE, fmt.Sprintf(`{"query":{"bool":{"must_not":[],"should":[ {
- "terms": {
- "id": [
- "%s"
- ]
- }
- }]}},"from":0,"size":100,"_source":["_id","purchasinglist","projectname","projectcode","title","s_winner","buyertel","bidstatus","site","bidamount","toptype","winneraddr","winner","agency","buyer","detail","city","subtype","buyerclass","href","comeintime","winnertel","area","publishtime","buyeraddr","agencytel","budget","entidlist","buyerperson","winnerperson","agencyaddr","recommended_service","competehref","owner","total_investment","projectaddr","projectperiod","approvedept","approvecontent","approvecode","approvenumber","approvetime","approvestatus","project_scale"],"sort":[],"aggs":{}}`, strings.Join(idArr, `","`)))
- if aobj != nil && len(*aobj) > 0 || *aobj != nil {
- for _, v := range *aobj {
- id := common.InterfaceToStr(v["_id"])
- subtype := common.InterfaceToStr(v["subtype"])
- data, ok := infoIdMap[id]
- data.Subtype = subtype
- if subtype == "拟建" && ok {
- project, _ := MC.MgoProject.FindOne("projectset_proposed", map[string]interface{}{
- "ids": id,
- })
- data.Source = 2
- if project != nil && len(*project) > 0 {
- projectId := common.InterfaceToStr((*project)["_id"])
- data.IsNiJian = true
- data.ProjectId = projectId
- }
- }
- infoIdMap[id] = data
- }
- }
- }
- return table, findKey, employKey, infoIdMap
- }
- // IgnoreOperate 忽略操作
- func (e *EmPloyService) IgnoreOperate(in *types.IgnoreOperateReq) (bool, string) {
- //
- table := ""
- switch in.EmployType {
- case 1, 4:
- table = entity.EMPLOY_INFO
- case 2, 3:
- table = entity.EMPLOY_CUSTOM
- }
- msg := ""
- fool := true
- for _, v := range strings.Split(in.IdArr, ",") {
- id := idFormat(v, in.EmployType)
- if id == "" {
- log.Println(v, id, in.EmployType, "忽略处理,id解析失败")
- continue
- }
- 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所对应数据不存在")
- fool = false
- if in.EmployType == 1 {
- if in.IsIgnore {
- msg = "该资讯已有员工收录,不可忽略。"
- } else {
- msg = "该资讯已有员工收录,不可取消忽略。"
- }
- } else {
- if in.IsIgnore {
- msg = "该企业已有员工收录,不可忽略。"
- } else {
- msg = "该企业已有员工收录,不可取消忽略。"
- }
- }
- continue
- }
- if in.IsIgnore {
- MC.CrmMysql.Update(table, findMap, map[string]interface{}{
- "is_ignore": 1,
- "is_handle": 1,
- })
- } else {
- MC.CrmMysql.Update(table, findMap, map[string]interface{}{
- "is_ignore": 0,
- "is_handle": 1,
- })
- }
- }
- return fool, msg
- }
- // DistributePerson 分发操作
- 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,
- EntDeptId: person.EntDeptId,
- }
- }
- //分发数据处理
- infoMap := map[string]map[string]interface{}{}
- onlyMap := map[string]interface{}{}
- //标讯数据处理
- for _, v := range strings.Split(in.EmployIdArr, ",") {
- if onlyMap[v] == nil {
- //查询信息
- infoDataList := MC.CrmMysql.SelectBySqlByTx(tx, "SELECT * FROM employ_info WHERE id=?", v)
- if infoDataList != nil && len(*infoDataList) > 0 {
- source_id := common.InterfaceToStr((*infoDataList)[0]["source_id"])
- if onlyMap[source_id] == nil {
- (*infoDataList)[0]["dis_id"] = v
- (*infoDataList)[0]["is_handle"] = 0
- (*infoDataList)[0]["is_ignore"] = 0
- (*infoDataList)[0]["is_dis"] = 0
- (*infoDataList)[0]["is_create_clue"] = 0
- (*infoDataList)[0]["is_create_chance"] = 0
- (*infoDataList)[0]["is_create_custom"] = 0
- (*infoDataList)[0]["create_time"] = time.Now().Format(date.Date_Full_Layout)
- delete((*infoDataList)[0], "id")
- if common.IntAll((*infoDataList)[0]["is_dis"]) != 1 {
- MC.CrmMysql.UpdateByTx(tx, entity.EMPLOY_INFO, map[string]interface{}{
- "id": v,
- }, map[string]interface{}{
- "is_dis": 1,
- "is_handle": 1,
- })
- }
- infoMap[source_id] = (*infoDataList)[0]
- onlyMap[source_id] = v
- } else {
- log.Println(v, "查询不到改收录信息")
- continue
- }
- }
- }
- }
- //普通人员分发
- for positionId, personSmmary := range personMap {
- //查询时候收录过
- for _, v := range infoMap {
- //查询时候收录过
- findMap := map[string]interface{}{
- "position_id": positionId,
- "source_id": v["source_id"],
- }
- if MC.CrmMysql.Count(entity.EMPLOY_INFO, findMap) == 0 {
- //新增
- v["ent_user_id"] = personSmmary.EntUserId
- v["ent_dept_id"] = personSmmary.EntDeptId
- v["position_id"] = positionId
- MC.CrmMysql.InsertByTx(tx, entity.EMPLOY_INFO, v)
- }
- }
- }
- if in.EntNicheDis > 0 {
- //查询分配员有没有该数据
- for _, v := range infoMap {
- //查询时候收录过
- findMap := map[string]interface{}{
- "position_id": in.PositionId,
- "source_id": v["source_id"],
- }
- employPositionId := v["position_id"]
- if employPositionId != in.PositionId {
- //分发消息不属于自己
- if MC.CrmMysql.Count(entity.EMPLOY_INFO, findMap) == 0 {
- v["ent_user_id"] = in.EntUserId
- v["position_id"] = in.PositionId
- v["is_handle"] = 1
- v["ent_dept_id"] = in.EntDeptId
- MC.CrmMysql.InsertByTx(tx, entity.EMPLOY_INFO, v)
- } else {
- MC.CrmMysql.UpdateByTx(tx, entity.EMPLOY_INFO, findMap, map[string]interface{}{
- "is_handle": 1,
- })
- }
- }
- }
- }
- return true
- })
- }
- func niJianHandle(infoId string, data map[string]interface{}, v1, pushTime string) map[string]interface{} {
- project, _ := MC.MgoProject.FindOne("projectset_proposed", map[string]interface{}{
- "ids": infoId,
- })
- if project != nil && len(*project) > 0 {
- city := common.InterfaceToStr((*project)["city"])
- area := common.InterfaceToStr((*project)["area"])
- category_code := common.InterfaceToStr((*project)["category_code"])
- lasttime := common.Int64All((*project)["lasttime"])
- ownerclass_code := common.InterfaceToStr((*project)["ownerclass_code"])
- total_investment := common.InterfaceToStr((*project)["total_investment"])
- project_stage_code := common.InterfaceToStr((*project)["project_stage_code"])
- infoList := gconv.SliceMap((*project)["list"])
- title := ""
- projectname := ""
- if len(infoList) > 0 {
- title = common.InterfaceToStr(infoList[0]["title"])
- projectname = common.InterfaceToStr(infoList[0]["projectname"])
- }
- category := ""
- ownerclass := ""
- project_stage := ""
- if category_code != "" {
- categoryData := MC.NiJian.FindOne("d_nzj_category_code", map[string]interface{}{
- "code": category_code,
- }, "name", "")
- category = common.InterfaceToStr((*categoryData)["name"])
- }
- if ownerclass_code != "" {
- ownerclassData := MC.NiJian.FindOne("d_nzj_ownerclass_code", map[string]interface{}{
- "code": ownerclass_code,
- }, "name", "")
- ownerclass = common.InterfaceToStr((*ownerclassData)["name"])
- }
- if project_stage_code != "" {
- projectStageData := MC.NiJian.FindOne("d_nzj_project_stage_code", map[string]interface{}{
- "code": project_stage_code,
- }, "name", "")
- project_stage = common.InterfaceToStr((*projectStageData)["name"])
- }
- data["title"] = title
- data["city"] = city
- data["area"] = area
- data["projectname"] = projectname
- data["ownerclass"] = ownerclass
- data["project_stage"] = project_stage
- data["project_category"] = category
- data["project_investment"] = total_investment
- lastTimeStr := common.If(lasttime == 0, pushTime, time.Unix(lasttime, 0).Format(date.Date_Full_Layout))
- data["project_evolve"] = lastTimeStr
- data["show_time"] = lastTimeStr
- data["publishtime"] = lastTimeStr
- pid := common.InterfaceToStr((*project)["_id"])
- data["jybx_url"] = "/succbi/nzj/app/nzj.app/nzj_detail_0.spg?pid=" + pid
- data["source"] = 2
- data["source_id"] = pid
- } else {
- data["source"] = 1
- data["source_id"] = infoId
- data["jybx_url"] = "/article/content/" + v1 + ".html"
- }
- return data
- }
- // 个人收录情况查询
- func employInfoPerson(table, employKey, findKey string, in *types.InfoEmployinfoReq, version int, infoId1Arr, infoId2Arr, niJianIdArr, wuye1Arr, wuye2Arr []string) map[string]map[string]interface{} {
- //
- data := map[string]map[string]interface{}{}
- infoData1 := &[]map[string]interface{}{}
- infoData2 := &[]map[string]interface{}{}
- niJianData := &[]map[string]interface{}{}
- wuyeData1 := &[]map[string]interface{}{}
- wuyeData2 := &[]map[string]interface{}{}
- orderKey := "type"
- if employKey == "company_id" {
- orderKey = "source"
- }
- if len(infoId1Arr) > 0 {
- infoData1 = MC.CrmMysql.SelectBySql(fmt.Sprintf("select %s, is_ignore,status,id,%s from %s where position_id =? and %s in ('%s') GROUP BY %s ,%s order by %s ", employKey, orderKey, table, employKey, strings.Join(infoId1Arr, "','"), employKey, orderKey, orderKey), in.PositionId)
- }
- if len(infoId2Arr) > 0 {
- infoData2 = MC.CrmMysql.SelectBySql(fmt.Sprintf("select %s, is_ignore,status,id,%s from %s where position_id =? and %s in ('%s') GROUP BY %s ,%s order by %s ", employKey, orderKey, table, employKey, strings.Join(infoId2Arr, "','"), employKey, orderKey, orderKey), in.PositionId)
- }
- if len(niJianIdArr) > 0 {
- niJianData = MC.CrmMysql.SelectBySql(fmt.Sprintf("select %s, is_ignore,status,id,%s from %s where position_id =? and %s in ('%s') GROUP BY %s ,%s order by %s ", employKey, orderKey, table, employKey, strings.Join(niJianIdArr, "','"), employKey, orderKey, orderKey), in.PositionId)
- }
- if len(wuye1Arr) > 0 {
- wuyeData1 = MC.CrmMysql.SelectBySql(fmt.Sprintf("select %s, is_ignore,status,id,%s from %s where position_id =? and %s in ('%s') GROUP BY %s ,%s order by %s ", employKey, orderKey, table, employKey, strings.Join(wuye1Arr, "','"), employKey, orderKey, orderKey), in.PositionId)
- }
- if len(wuye2Arr) > 0 {
- wuyeData2 = MC.CrmMysql.SelectBySql(fmt.Sprintf("select %s, is_ignore,status,id,%s from %s where position_id =? and %s in ('%s') GROUP BY %s ,%s order by %s ", employKey, orderKey, table, employKey, strings.Join(wuye2Arr, "','"), employKey, orderKey, orderKey), in.PositionId)
- }
- for _, v := range *infoData1 {
- valueMap := map[string]interface{}{
- "id": v,
- "isIgnore": false,
- "isEmploy": false,
- "customCount": 0,
- "clueCount": 0,
- "chanceCount": 0,
- "type": 1,
- }
- sourceId := gconv.String(v[employKey])
- if _, ok := data[sourceId]; ok {
- data[sourceId] = EmployHandle(data[sourceId], v, 0, in.From, len(strings.Split(in.IdArr, ",")) == 1, findKey, in.PositionId, in.PositionType, in.EmployType)
- } else {
- data[sourceId] = EmployHandle(valueMap, v, 0, in.From, len(strings.Split(in.IdArr, ",")) == 1, findKey, in.PositionId, in.PositionType, in.EmployType)
- }
- }
- for _, v := range *infoData2 {
- valueMap := map[string]interface{}{
- "id": v,
- "isIgnore": false,
- "isEmploy": false,
- "customCount": 0,
- "clueCount": 0,
- "chanceCount": 0,
- "type": 1,
- }
- sourceId := gconv.String(v[employKey])
- if _, ok := data[sourceId]; ok {
- data[sourceId] = EmployHandle(data[sourceId], v, 0, in.From, len(strings.Split(in.IdArr, ",")) == 1, findKey, in.PositionId, in.PositionType, in.EmployType)
- } else {
- data[sourceId] = EmployHandle(valueMap, v, 0, in.From, len(strings.Split(in.IdArr, ",")) == 1, findKey, in.PositionId, in.PositionType, in.EmployType)
- }
- }
- for _, v := range *niJianData {
- valueMap := map[string]interface{}{
- "id": v,
- "isIgnore": false,
- "isEmploy": false,
- "customCount": 0,
- "clueCount": 0,
- "chanceCount": 0,
- "type": 1,
- }
- sourceId := gconv.String(v[employKey])
- if _, ok := data[sourceId]; ok {
- data[sourceId] = EmployHandle(data[sourceId], v, 0, in.From, len(strings.Split(in.IdArr, ",")) == 1, findKey, in.PositionId, in.PositionType, in.EmployType)
- } else {
- data[sourceId] = EmployHandle(valueMap, v, 0, in.From, len(strings.Split(in.IdArr, ",")) == 1, findKey, in.PositionId, in.PositionType, in.EmployType)
- }
- }
- for _, v := range *wuyeData1 {
- valueMap := map[string]interface{}{
- "id": v,
- "isIgnore": false,
- "isEmploy": false,
- "customCount": 0,
- "clueCount": 0,
- "chanceCount": 0,
- "type": 1,
- }
- sourceId := gconv.String(v[employKey])
- if _, ok := data[sourceId]; ok {
- data[sourceId] = EmployHandle(data[sourceId], v, 1, in.From, len(strings.Split(in.IdArr, ",")) == 1, findKey, in.PositionId, in.PositionType, in.EmployType)
- } else {
- data[sourceId] = EmployHandle(valueMap, v, 1, in.From, len(strings.Split(in.IdArr, ",")) == 1, findKey, in.PositionId, in.PositionType, in.EmployType)
- }
- }
- for _, v := range *wuyeData2 {
- valueMap := map[string]interface{}{
- "id": v,
- "isIgnore": false,
- "isEmploy": false,
- "customCount": 0,
- "clueCount": 0,
- "chanceCount": 0,
- "type": 1,
- }
- sourceId := gconv.String(v[employKey])
- if _, ok := data[sourceId]; ok {
- data[sourceId] = EmployHandle(data[sourceId], v, 1, in.From, len(strings.Split(in.IdArr, ",")) == 1, findKey, in.PositionId, in.PositionType, in.EmployType)
- } else {
- data[sourceId] = EmployHandle(valueMap, v, 1, in.From, len(strings.Split(in.IdArr, ",")) == 1, findKey, in.PositionId, in.PositionType, in.EmployType)
- }
- }
- return data
- }
- // 企业收录情况查询
- func employInfoEnt(table, employKey, findKey, depIDArr string, in *types.InfoEmployinfoReq, version int, infoId1Arr, infoId2Arr, niJianIdArr, wuye1Arr, wuye2Arr []string) map[string]map[string]interface{} {
- data := map[string]map[string]interface{}{}
- infoData1 := &[]map[string]interface{}{}
- infoData2 := &[]map[string]interface{}{}
- niJianData := &[]map[string]interface{}{}
- wuyeData1 := &[]map[string]interface{}{}
- wuyeData2 := &[]map[string]interface{}{}
- orderKey := "type"
- if employKey == "company_id" {
- orderKey = "source"
- }
- if len(infoId1Arr) > 0 {
- infoData1 = MC.CrmMysql.SelectBySql(fmt.Sprintf("select %s,GROUP_CONCAT(id) as employIdArr,MAX(is_ignore) as is_ignore,MAX(status) as status,%s from %s where %s in ('%s') and source=? and ent_dept_id in (%s) GROUP BY %s ,%s order by %s", employKey, orderKey, table, employKey, strings.Join(infoId1Arr, "','"), depIDArr, employKey, orderKey, orderKey), 1)
- }
- if len(infoId2Arr) > 0 {
- infoData2 = MC.CrmMysql.SelectBySql(fmt.Sprintf("select %s, GROUP_CONCAT(id) as employIdArr,MAX(is_ignore) as is_ignore,MAX(status) as status,%s from %s where %s in ('%s') and source=? and ent_dept_id in (%s) GROUP BY %s ,%s order by %s", employKey, orderKey, table, employKey, strings.Join(infoId2Arr, "','"), depIDArr, employKey, orderKey, orderKey), 2)
- }
- if len(niJianIdArr) > 0 {
- niJianData = MC.CrmMysql.SelectBySql(fmt.Sprintf("select %s, GROUP_CONCAT(id) as employIdArr,MAX(is_ignore) as is_ignore,MAX(status) as status,%s from %s where %s in ('%s') and source=? and ent_dept_id in (%s) GROUP BY %s ,%s order by %s", employKey, orderKey, table, employKey, strings.Join(niJianIdArr, "','"), depIDArr, employKey, orderKey, orderKey), 2)
- }
- if len(wuye1Arr) > 0 {
- wuyeData1 = MC.CrmMysql.SelectBySql(fmt.Sprintf("select %s, id,is_ignore,status,%s from %s where %s in ('%s') and status =1 and source=? and ent_dept_id in (%s) GROUP BY %s ,%s order by %s", employKey, orderKey, table, employKey, strings.Join(wuye1Arr, "','"), depIDArr, employKey, orderKey, orderKey), 1)
- }
- if len(wuye2Arr) > 0 {
- wuyeData2 = MC.CrmMysql.SelectBySql(fmt.Sprintf("select %s, id,is_ignore,status,%s from %s where %s in ('%s') and status =1 and source=? and ent_dept_id in (%s) GROUP BY %s ,%s order by %s", employKey, orderKey, table, employKey, strings.Join(wuye2Arr, "','"), depIDArr, employKey, orderKey, orderKey), 2)
- }
- for _, v := range *infoData1 {
- valueMap := map[string]interface{}{
- "id": v,
- "isIgnore": false,
- "isEmploy": false,
- "customCount": 0,
- "clueCount": 0,
- "chanceCount": 0,
- "type": 1,
- }
- sourceId := gconv.String(v[employKey])
- if _, ok := data[sourceId]; ok {
- data[sourceId] = EmployHandle(data[sourceId], v, 0, in.From, len(strings.Split(in.IdArr, ",")) == 1, findKey, in.PositionId, in.PositionType, in.EmployType)
- } else {
- data[sourceId] = EmployHandle(valueMap, v, 0, in.From, len(strings.Split(in.IdArr, ",")) == 1, findKey, in.PositionId, in.PositionType, in.EmployType)
- }
- }
- for _, v := range *infoData2 {
- valueMap := map[string]interface{}{
- "id": v,
- "isIgnore": false,
- "isEmploy": false,
- "customCount": 0,
- "clueCount": 0,
- "chanceCount": 0,
- "type": 1,
- }
- sourceId := gconv.String(v[employKey])
- if _, ok := data[sourceId]; ok {
- data[sourceId] = EmployHandle(data[sourceId], v, 0, in.From, len(strings.Split(in.IdArr, ",")) == 1, findKey, in.PositionId, in.PositionType, in.EmployType)
- } else {
- data[sourceId] = EmployHandle(valueMap, v, 0, in.From, len(strings.Split(in.IdArr, ",")) == 1, findKey, in.PositionId, in.PositionType, in.EmployType)
- }
- }
- for _, v := range *niJianData {
- valueMap := map[string]interface{}{
- "id": v,
- "isIgnore": false,
- "isEmploy": false,
- "customCount": 0,
- "clueCount": 0,
- "chanceCount": 0,
- "type": 1,
- }
- sourceId := gconv.String(v[employKey])
- if _, ok := data[sourceId]; ok {
- data[sourceId] = EmployHandle(data[sourceId], v, version, in.From, len(strings.Split(in.IdArr, ",")) == 1, findKey, in.PositionId, in.PositionType, in.EmployType)
- } else {
- data[sourceId] = EmployHandle(valueMap, v, version, in.From, len(strings.Split(in.IdArr, ",")) == 1, findKey, in.PositionId, in.PositionType, in.EmployType)
- }
- }
- for _, v := range *wuyeData1 {
- valueMap := map[string]interface{}{
- "id": v,
- "isIgnore": false,
- "isEmploy": false,
- "customCount": 0,
- "clueCount": 0,
- "chanceCount": 0,
- "type": 1,
- }
- sourceId := gconv.String(v[employKey])
- if _, ok := data[sourceId]; ok {
- data[sourceId] = EmployHandle(data[sourceId], v, 1, in.From, len(strings.Split(in.IdArr, ",")) == 1, findKey, in.PositionId, in.PositionType, in.EmployType)
- } else {
- data[sourceId] = EmployHandle(valueMap, v, 1, in.From, len(strings.Split(in.IdArr, ",")) == 1, findKey, in.PositionId, in.PositionType, in.EmployType)
- }
- }
- for _, v := range *wuyeData2 {
- valueMap := map[string]interface{}{
- "id": v,
- "isIgnore": false,
- "isEmploy": false,
- "customCount": 0,
- "clueCount": 0,
- "chanceCount": 0,
- "type": 1,
- }
- sourceId := gconv.String(v[employKey])
- if _, ok := data[sourceId]; ok {
- data[sourceId] = EmployHandle(data[sourceId], v, 1, in.From, len(strings.Split(in.IdArr, ",")) == 1, findKey, in.PositionId, in.PositionType, in.EmployType)
- } else {
- data[sourceId] = EmployHandle(valueMap, v, 1, in.From, len(strings.Split(in.IdArr, ",")) == 1, findKey, in.PositionId, in.PositionType, in.EmployType)
- }
- }
- return data
- }
- func EmployHandle(valueMap map[string]interface{}, employData map[string]interface{}, version int, originate string, single bool, findKey string, positionId, positionType, inEmployType int64) map[string]interface{} {
- employType := common.Int64All(employData["type"])
- employStatus := common.Int64All(employData["status"])
- employ2 := false
- employ3 := false
- employIgnore := false
- employId := int64(0)
- is_ignore := int64(0)
- employArrStr := ""
- //收录标识处理
- if common.Int64All(employData["id"]) == 0 {
- if len(gconv.String(employData["employIdArr"])) > 0 {
- employArrStr = gconv.String(employData["employIdArr"])
- employId = gconv.Int64(strings.Split(employArrStr, ",")[0])
- }
- } else {
- employId = common.Int64All(employData["id"])
- }
- if version == 1 {
- is_ignore = common.Int64All(employData["is_ignore"])
- switch employType {
- case 2:
- if valueMap["employ3"] != nil {
- employ3 = gconv.Bool(valueMap["employ3"])
- }
- if employStatus == 1 {
- employ2 = true
- }
- case 3:
- if valueMap["employ2"] != nil {
- employ2 = gconv.Bool(valueMap["employ2"])
- }
- if employStatus == 1 {
- employ3 = true
- }
- }
- if is_ignore > 0 {
- employIgnore = true
- }
- employType = common.Int64All(employData["type"])
- valueMap["isIgnore"] = employIgnore
- if originate == "jhfp" {
- valueMap["isEmploy"] = employ3
- } else {
- valueMap["isEmploy"] = common.If(employ2 && employ3, true, false)
- }
- valueMap["type"] = employType
- valueMap["employ2"] = employ2
- valueMap["employ3"] = employ3
- valueMap["employId"] = employId
- } else {
- valueMap["isIgnore"] = common.If(common.Int64All(employData["is_ignore"]) == 1, true, false)
- valueMap["isEmploy"] = common.If(common.Int64All(employData["status"]) == 1, true, false)
- valueMap["type"] = common.Int64All(employData["type"])
- valueMap["employId"] = employId
- }
- if employType == 2 {
- valueMap["intelligenceId"] = employId
- }
- if single && employArrStr != "" {
- //列表查询
- //是否忽略处理
- //客户数量
- customSql := ""
- clueSql := ""
- chanceSql := ""
- if positionType == 0 {
- customSql = fmt.Sprintf("select COUNT(1) from %s where %s in (%s) and position_id=%d", entity.CUSTOM, findKey, employArrStr, positionId)
- clueSql = fmt.Sprintf("select COUNT(1) from %s where employ_info_id in (%s) and position_id=%d", entity.SALE_CLUE, employArrStr, positionId)
- chanceSql = fmt.Sprintf("select COUNT(1) from %s where employ_info_id in (%s) and position_id=%d", entity.SALE_CHANCE, employArrStr, positionId)
- } else {
- customSql = fmt.Sprintf("select COUNT(1) from %s where %s in (%s)", entity.CUSTOM, findKey, employArrStr)
- clueSql = fmt.Sprintf("select COUNT(1) from %s where employ_info_id in (%s)", entity.SALE_CLUE, employArrStr)
- chanceSql = fmt.Sprintf("select COUNT(1) from %s where employ_info_id in (%s)", entity.SALE_CHANCE, employArrStr)
- }
- customCount := MC.CrmMysql.CountBySql(customSql)
- valueMap["customCount"] = customCount
- if inEmployType == 1 || inEmployType == 4 {
- //销售线索数量
- clueCount := MC.CrmMysql.CountBySql(clueSql)
- valueMap["clueCount"] = clueCount
- //销售机会数量
- chanceCount := MC.CrmMysql.CountBySql(chanceSql)
- valueMap["chanceCount"] = chanceCount
- }
- } else {
- valueMap["chanceCount"] = 0
- valueMap["clueCount"] = 0
- valueMap["customCount"] = 0
- }
- return valueMap
- }
|