employService.go 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015
  1. package service
  2. import (
  3. "database/sql"
  4. "fmt"
  5. "log"
  6. "strings"
  7. "time"
  8. "app.yhyue.com/moapp/jybase/common"
  9. "app.yhyue.com/moapp/jybase/date"
  10. elastic "app.yhyue.com/moapp/jybase/es"
  11. "app.yhyue.com/moapp/jypkg/ent/util"
  12. MC "bp.jydev.jianyu360.cn/CRM/application/api/common"
  13. "bp.jydev.jianyu360.cn/CRM/application/api/internal/types"
  14. "bp.jydev.jianyu360.cn/CRM/application/entity"
  15. "github.com/RoaringBitmap/roaring"
  16. "github.com/gogf/gf/v2/util/gconv"
  17. )
  18. const (
  19. BuyerIndex = "buyer" // 采购单位index
  20. BuyerType = "buyer"
  21. INDEX = "bidding"
  22. TYPE = "bidding"
  23. )
  24. type EmPloyService struct{}
  25. type PersonSmmary struct {
  26. EntUserId int64
  27. EntDeptId int64
  28. Summary map[int64]*roaring.Bitmap
  29. }
  30. // InfoEmployinfo 收录情况查询
  31. func (e *EmPloyService) InfoEmployinfo(in *types.InfoEmployinfoReq) ([]map[string]interface{}, int64) {
  32. var data []map[string]interface{}
  33. depIDArr := ""
  34. batchEmploy := int64(0)
  35. if in.EntNicheDis > 0 {
  36. //查询所有部门标识
  37. deptArr := MC.MainMysql.SelectBySql("select GROUP_CONCAT(DISTINCT b.id) as depIDArr from entniche_department_parent a"+
  38. " INNER JOIN entniche_department b "+
  39. "on (b.ent_id=? and (b.id=? or (a.pid=? and a.id=b.id)))", in.EntId, in.EntDeptId, in.EntDeptId)
  40. if len(*deptArr) == 0 {
  41. return data, batchEmploy
  42. }
  43. depIDArr = common.InterfaceToStr((*deptArr)[0]["depIDArr"])
  44. if depIDArr == "" {
  45. return data, batchEmploy
  46. }
  47. }
  48. //是否可以批量收录配置回显
  49. accountId := int64(0)
  50. if in.PositionType == 0 {
  51. accountId = in.AccountId
  52. } else {
  53. accountId = in.EntAccountId
  54. }
  55. configData := MC.CrmMysql.FindOne("config_tenant", map[string]interface{}{
  56. "account_id": accountId,
  57. }, "batch_employ", "")
  58. if configData != nil {
  59. batchEmploy = gconv.Int64((*configData)["batch_employ"])
  60. }
  61. //版本查询
  62. res := MC.Middleground.ResourceCenter.Haspowers(in.AccountId, in.EntAccountId, in.EntId, in.EntUserId)
  63. version := 0
  64. for _, pCode := range res.Powers {
  65. //0:通用版 1:物业专版
  66. if pCode == "bi_yx_wyzb" {
  67. version = 1
  68. }
  69. }
  70. infoId1Arr := []string{}
  71. niJianIdArr := []string{}
  72. infoId2Arr := []string{}
  73. wuye1Arr := []string{}
  74. wuye2Arr := []string{}
  75. infoMap := map[string]interface{}{}
  76. table, findKey, employKey, employData := employKeyFormat(in.EmployType, in.IdArr)
  77. for _, employ := range employData {
  78. source := employ.Source
  79. isNiJian := employ.IsNiJian
  80. if (employ.Subtype == "成交" || employ.Subtype == "中标" || employ.Subtype == "合同" || employ.Subtype == "验收" || employ.Subtype == "违规") && in.EmployType == 1 && version == 1 {
  81. infoMap[employ.Id] = employ.ProjectId
  82. if isNiJian {
  83. infoMap[employ.Id] = employ.ProjectId
  84. if source == 1 {
  85. wuye1Arr = append(wuye1Arr, employ.ProjectId)
  86. } else {
  87. wuye2Arr = append(wuye2Arr, employ.ProjectId)
  88. }
  89. } else {
  90. infoMap[employ.Id] = employ.SourceId
  91. if source == 1 {
  92. wuye1Arr = append(wuye1Arr, employ.SourceId)
  93. } else {
  94. wuye2Arr = append(wuye2Arr, employ.SourceId)
  95. }
  96. }
  97. } else if isNiJian {
  98. infoMap[employ.Id] = employ.ProjectId
  99. niJianIdArr = append(niJianIdArr, employ.ProjectId)
  100. } else if source == 2 {
  101. infoMap[employ.Id] = employ.SourceId
  102. infoId2Arr = append(infoId2Arr, employ.SourceId)
  103. } else if source == 1 {
  104. infoMap[employ.Id] = employ.SourceId
  105. infoId1Arr = append(infoId1Arr, employ.SourceId)
  106. }
  107. }
  108. //收录情况查询
  109. dataList := map[string]map[string]interface{}{}
  110. if in.EntNicheDis > 0 {
  111. dataList = employInfoEnt(table, employKey, findKey, depIDArr, in, version, infoId1Arr, infoId2Arr, niJianIdArr, wuye1Arr, wuye2Arr)
  112. } else {
  113. dataList = employInfoPerson(table, employKey, findKey, in, version, infoId1Arr, infoId2Arr, niJianIdArr, wuye1Arr, wuye2Arr)
  114. }
  115. for k, v := range infoMap {
  116. fool := true
  117. for sourceId, v1 := range dataList {
  118. if v == sourceId {
  119. v1["id"] = k
  120. data = append(data, v1)
  121. fool = false
  122. break
  123. }
  124. }
  125. if fool {
  126. data = append(data, map[string]interface{}{
  127. "id": k,
  128. "isIgnore": false,
  129. "isEmploy": false,
  130. "customCount": 0,
  131. "clueCount": 0,
  132. "chanceCount": 0,
  133. "type": 1,
  134. })
  135. }
  136. }
  137. return data, batchEmploy
  138. }
  139. // EmployOperate 收录操作
  140. func (e *EmPloyService) EmployOperate(in *types.EmployOperateReq) (bool, string) {
  141. log.Println("收录入参", in)
  142. //收录汇总表
  143. //summaryMap := SummaryFormat(in.PositionId)
  144. msg := ""
  145. return MC.CrmMysql.ExecTx("收录操作", func(tx *sql.Tx) bool {
  146. fool := false
  147. //id转中文
  148. table, _, employKey, data := employKeyFormat(in.EmployType, in.IdArr)
  149. for id, employ := range data {
  150. findMap := map[string]interface{}{}
  151. findMap["position_id"] = in.PositionId
  152. if employ.IsNiJian {
  153. findMap[employKey] = employ.ProjectId
  154. } else {
  155. findMap[employKey] = id
  156. }
  157. if employ.SourceId == "" {
  158. log.Println(employ.Id, in.EmployType, "该信息查询不到数据")
  159. continue
  160. }
  161. if in.IsEmploy {
  162. if MC.CrmMysql.Count(table, findMap) > 0 {
  163. MC.CrmMysql.UpdateByTx(tx, table, findMap, map[string]interface{}{
  164. "status": 1,
  165. })
  166. } else {
  167. //收录新增
  168. data := map[string]interface{}{}
  169. if in.EmployType == 1 || in.EmployType == 4 {
  170. data = infoFind(id, employ.Id)
  171. } else if in.EmployType == 2 {
  172. data = customFind(id, in.EmployType)
  173. data["jybx_url"] = "/swordfish/page_big_pc/ent_portrait/" + employ.Id
  174. data["source"] = employ.Source
  175. } else if in.EmployType == 3 {
  176. data = customFind(id, in.EmployType)
  177. data["jybx_url"] = "/publicapply/biTransfer?buyerName=" + employ.Id
  178. data["source"] = employ.Source
  179. }
  180. data["position_id"] = in.PositionId
  181. data["ent_id"] = in.EntId
  182. data["ent_dept_id"] = in.EntDeptId
  183. data["ent_user_id"] = in.EntUserId
  184. ok := MC.CrmMysql.InsertByTx(tx, table, data)
  185. if ok <= 0 {
  186. log.Println(employ.Id, id, in.EmployType, "收录失败")
  187. continue
  188. }
  189. }
  190. fool = true
  191. } else {
  192. //取消收录
  193. if in.From == "jhfp" {
  194. findMap["type"] = 3
  195. }
  196. if MC.CrmMysql.Count(table, findMap) > 0 {
  197. ok := MC.CrmMysql.UpdateByTx(tx, table, findMap, map[string]interface{}{
  198. "status": -1,
  199. })
  200. if !ok {
  201. log.Println(employ.Id, id, in.EmployType, "取消收录失败")
  202. continue
  203. }
  204. fool = true
  205. } else {
  206. if in.EmployType == 1 {
  207. msg = "该资讯已有员工收录,不可取消收录。"
  208. continue
  209. } else {
  210. msg = "该企业已有员工收录,不可取消收录。"
  211. continue
  212. }
  213. }
  214. }
  215. }
  216. if in.IsEmploy && !fool {
  217. msg = "收录失败"
  218. }
  219. return fool
  220. }), msg
  221. }
  222. // customFind 企业信息查询
  223. func customFind(id string, employType int64) map[string]interface{} {
  224. data := map[string]interface{}{}
  225. //company_id 企业id name户名称 address 地址 industry 行业
  226. if employType == 2 {
  227. //企业详情
  228. entinfo, _ := MC.MgoEnt.FindOneByField("qyxy_std", map[string]interface{}{"_id": id}, map[string]interface{}{
  229. "company_address": 1, //注册地
  230. "company_name": 1,
  231. })
  232. if entinfo != nil && len(*entinfo) > 0 {
  233. data["name"] = (*entinfo)["company_name"]
  234. data["address"] = (*entinfo)["company_address"]
  235. data["company_id"] = id
  236. }
  237. } else {
  238. //采购单位详情
  239. rs := elastic.Get(BuyerIndex, BuyerType, fmt.Sprintf(`{"query":{"bool":{"must":[{"terms":{"_id":["%s"]}}]}},"size":1,"_source":["buyer_name","city"]}`, id))
  240. if rs != nil && len(*rs) > 0 {
  241. data["name"] = (*rs)[0]["buyer_name"]
  242. data["address"] = (*rs)[0]["city"]
  243. data["company_id"] = id
  244. }
  245. }
  246. data["status"] = 1
  247. data["create_time"] = time.Now().Format(date.Date_Full_Layout)
  248. return data
  249. }
  250. // infoFind 标讯信息查询
  251. func infoFind(id string, v1 string) map[string]interface{} {
  252. data := map[string]interface{}{}
  253. //source_id 信息id、项目id- title 标题-area 省 -city 市 -subtype 信息类型二级分类
  254. //buyerclass 采购单位行业 -budget 预算 -bidamount 中标金额 buyer采购单位 annex有无附件 publishtime发布时间 projectname 项目时间
  255. //ownerclass 业主类型(拟在建搜索) expurasing_time 预计采购时间 jybx_url 标讯详情页
  256. //标讯信息
  257. obj := map[string]interface{}{}
  258. 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))
  259. log.Println(len(*aobj))
  260. if aobj != nil || *aobj != nil || len(*aobj) > 0 {
  261. obj = (*aobj)[0]
  262. }
  263. toptype := common.InterfaceToStr(obj["toptype"])
  264. subtype := common.InterfaceToStr(obj["subtype"])
  265. pushTime := ""
  266. if obj != nil && len(obj) > 0 {
  267. data["title"] = common.ObjToString(obj["title"])
  268. city := gconv.String(obj["city"])
  269. area := gconv.String(obj["area"])
  270. data["city"] = city
  271. data["area"] = area
  272. //省份代码处理
  273. areaCode := ""
  274. if MC.AreaCodeMap[city] != "" {
  275. areaCode = MC.AreaCodeMap[city]
  276. } else {
  277. areaCode = MC.AreaCodeMap[area]
  278. }
  279. data["area_code"] = areaCode
  280. data["subtype"] = obj["subtype"]
  281. data["buyerclass"] = obj["buyerclass"]
  282. data["budget"] = obj["budget"]
  283. data["bidamount"] = obj["bidamount"]
  284. data["annex"] = 0
  285. data["buyer"] = obj["buyer"]
  286. data["winner"] = obj["s_winner"]
  287. data["jybx_url"] = "/article/content/" + v1 + ".html"
  288. //类型处理
  289. pushTime = time.Unix(common.Int64All(obj["publishtime"]), 0).Format(date.Date_Full_Layout)
  290. data["source"] = 1
  291. data["source_id"] = id
  292. if subtype == "拟建" {
  293. data["source"] = 2
  294. }
  295. if toptype == "采购意向" || toptype == "预告" || toptype == "招标" || toptype == "" {
  296. data["type"] = 2
  297. } else {
  298. if subtype == "废标" || subtype == "流标" || subtype == "其它" {
  299. data["type"] = 2
  300. } else if subtype == "成交" || subtype == "中标" || subtype == "合同" || subtype == "验收" || subtype == "违规" {
  301. data["type"] = 3
  302. } else {
  303. data["type"] = 1
  304. }
  305. }
  306. if obj["projectinfo"] != nil {
  307. projectinfo := common.ObjToMap(obj["projectinfo"])
  308. if (*projectinfo)["attachments"] != nil {
  309. data["annex"] = 1
  310. }
  311. }
  312. data["publishtime"] = pushTime
  313. data["show_time"] = pushTime
  314. data["projectname"] = obj["projectname"]
  315. procurementlist, _ := obj["procurementlist"].([]interface{})
  316. for _, vs := range procurementlist { //1.采购意向清单数据集打码处理
  317. vsMap, _ := vs.(map[string]interface{})
  318. if vsMap["expurasingtime"] != nil {
  319. data["expurasing_time"] = vsMap["expurasingtime"]
  320. break
  321. }
  322. }
  323. }
  324. data["status"] = 1
  325. data["employ_way"] = 1
  326. data["create_time"] = time.Now().Format(date.Date_Full_Layout)
  327. if subtype == "拟建" {
  328. data = niJianHandle(id, data, v1, pushTime)
  329. data["type"] = 1
  330. }
  331. return data
  332. }
  333. // GetBuyerIdByName 通过采购单位名称获取id
  334. func getBuyerIdByName(buyerName string) (buyerId string) {
  335. r := elastic.Get(BuyerIndex, BuyerType, fmt.Sprintf(`{"query":{"bool":{"must":[{"term":{"buyer_name":"%s"}}]}},"size":1,"_source":["city","id"]}`, buyerName))
  336. if r == nil || len(*r) == 0 {
  337. return
  338. }
  339. buyerId, _ = (*r)[0]["_id"].(string)
  340. return
  341. }
  342. // IdFormat id解密
  343. func idFormat(encryptionId string, employType int64) string {
  344. decryptId := ""
  345. switch employType {
  346. case 1, 2:
  347. decryptId = util.DecodeId(encryptionId)
  348. case 3:
  349. if len(encryptionId) > 0 && len([]rune(encryptionId)) == len(encryptionId) {
  350. //此数据是id
  351. //获取中文名字
  352. decryptId = util.DecodeId(encryptionId)
  353. } else {
  354. //次数据传的名字
  355. decryptId = getBuyerIdByName(encryptionId)
  356. }
  357. }
  358. return decryptId
  359. }
  360. type Employ struct {
  361. Source int64
  362. IsNiJian bool
  363. ProjectId string
  364. Id string
  365. SourceId string
  366. Subtype string
  367. }
  368. // employKeyFormat 根据收录类型 字段处理 table,findKey,employKey,source
  369. func employKeyFormat(employType int64, idArrStr string) (string, string, string, map[string]Employ) {
  370. table := ""
  371. employKey := "company_id"
  372. findKey := "employ_custom_id"
  373. infoIdMap := map[string]Employ{}
  374. idArr := []string{}
  375. source := int64(0)
  376. switch employType {
  377. case 1:
  378. table = entity.EMPLOY_INFO
  379. employKey = "source_id"
  380. findKey = "employ_info_id"
  381. source = 1
  382. case 2:
  383. table = entity.EMPLOY_CUSTOM
  384. source = 1
  385. case 3:
  386. table = entity.EMPLOY_CUSTOM
  387. source = 2
  388. case 4:
  389. table = entity.EMPLOY_INFO
  390. source = 2
  391. employKey = "source_id"
  392. findKey = "employ_info_id"
  393. }
  394. for _, v := range strings.Split(idArrStr, ",") {
  395. id := idFormat(v, employType)
  396. idArr = append(idArr, id)
  397. infoIdMap[id] = Employ{
  398. Source: source,
  399. IsNiJian: false,
  400. ProjectId: "",
  401. Id: v,
  402. SourceId: id,
  403. }
  404. }
  405. if employType == 1 {
  406. table = entity.EMPLOY_INFO
  407. employKey = "source_id"
  408. findKey = "employ_info_id"
  409. source = 1
  410. aobj := elastic.Get(INDEX, TYPE, fmt.Sprintf(`{"query":{"bool":{"must_not":[],"should":[ {
  411. "terms": {
  412. "id": [
  413. "%s"
  414. ]
  415. }
  416. }]}},"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, `","`)))
  417. if aobj != nil && len(*aobj) > 0 || *aobj != nil {
  418. for _, v := range *aobj {
  419. id := common.InterfaceToStr(v["_id"])
  420. subtype := common.InterfaceToStr(v["subtype"])
  421. data, ok := infoIdMap[id]
  422. data.Subtype = subtype
  423. if subtype == "拟建" && ok {
  424. project, _ := MC.MgoProject.FindOne("projectset_proposed", map[string]interface{}{
  425. "ids": id,
  426. })
  427. data.Source = 2
  428. if project != nil && len(*project) > 0 {
  429. projectId := common.InterfaceToStr((*project)["_id"])
  430. data.IsNiJian = true
  431. data.ProjectId = projectId
  432. }
  433. }
  434. infoIdMap[id] = data
  435. }
  436. }
  437. }
  438. return table, findKey, employKey, infoIdMap
  439. }
  440. // IgnoreOperate 忽略操作
  441. func (e *EmPloyService) IgnoreOperate(in *types.IgnoreOperateReq) (bool, string) {
  442. //
  443. table := ""
  444. switch in.EmployType {
  445. case 1, 4:
  446. table = entity.EMPLOY_INFO
  447. case 2, 3:
  448. table = entity.EMPLOY_CUSTOM
  449. }
  450. msg := ""
  451. fool := true
  452. for _, v := range strings.Split(in.IdArr, ",") {
  453. id := idFormat(v, in.EmployType)
  454. if id == "" {
  455. log.Println(v, id, in.EmployType, "忽略处理,id解析失败")
  456. continue
  457. }
  458. findMap := map[string]interface{}{
  459. "position_id": in.PositionId,
  460. }
  461. if in.EmployType == 3 || in.EmployType == 2 {
  462. findMap["company_id"] = id
  463. } else {
  464. findMap["source_id"] = id
  465. }
  466. if MC.CrmMysql.Count(table, findMap) == 0 {
  467. log.Println(v, id, in.EmployType, "忽略处理,id所对应数据不存在")
  468. fool = false
  469. if in.EmployType == 1 {
  470. if in.IsIgnore {
  471. msg = "该资讯已有员工收录,不可忽略。"
  472. } else {
  473. msg = "该资讯已有员工收录,不可取消忽略。"
  474. }
  475. } else {
  476. if in.IsIgnore {
  477. msg = "该企业已有员工收录,不可忽略。"
  478. } else {
  479. msg = "该企业已有员工收录,不可取消忽略。"
  480. }
  481. }
  482. continue
  483. }
  484. if in.IsIgnore {
  485. MC.CrmMysql.Update(table, findMap, map[string]interface{}{
  486. "is_ignore": 1,
  487. "is_handle": 1,
  488. })
  489. } else {
  490. MC.CrmMysql.Update(table, findMap, map[string]interface{}{
  491. "is_ignore": 0,
  492. "is_handle": 1,
  493. })
  494. }
  495. }
  496. return fool, msg
  497. }
  498. // DistributePerson 分发操作
  499. func (e *EmPloyService) DistributePerson(in *types.EmployDistributeReq) bool {
  500. return MC.CrmMysql.ExecTx("收录操作", func(tx *sql.Tx) bool {
  501. personMap := map[int64]PersonSmmary{}
  502. //人员信息处理
  503. for _, person := range in.Person {
  504. personMap[person.PositionId] = PersonSmmary{
  505. EntUserId: person.EntUserId,
  506. EntDeptId: person.EntDeptId,
  507. }
  508. }
  509. //分发数据处理
  510. infoMap := map[string]map[string]interface{}{}
  511. onlyMap := map[string]interface{}{}
  512. //标讯数据处理
  513. for _, v := range strings.Split(in.EmployIdArr, ",") {
  514. if onlyMap[v] == nil {
  515. //查询信息
  516. infoDataList := MC.CrmMysql.SelectBySqlByTx(tx, "SELECT * FROM employ_info WHERE id=?", v)
  517. if infoDataList != nil && len(*infoDataList) > 0 {
  518. source_id := common.InterfaceToStr((*infoDataList)[0]["source_id"])
  519. if onlyMap[source_id] == nil {
  520. (*infoDataList)[0]["dis_id"] = v
  521. (*infoDataList)[0]["is_handle"] = 0
  522. (*infoDataList)[0]["is_ignore"] = 0
  523. (*infoDataList)[0]["is_dis"] = 0
  524. (*infoDataList)[0]["is_create_clue"] = 0
  525. (*infoDataList)[0]["is_create_chance"] = 0
  526. (*infoDataList)[0]["is_create_custom"] = 0
  527. (*infoDataList)[0]["create_time"] = time.Now().Format(date.Date_Full_Layout)
  528. delete((*infoDataList)[0], "id")
  529. if common.IntAll((*infoDataList)[0]["is_dis"]) != 1 {
  530. MC.CrmMysql.UpdateByTx(tx, entity.EMPLOY_INFO, map[string]interface{}{
  531. "id": v,
  532. }, map[string]interface{}{
  533. "is_dis": 1,
  534. "is_handle": 1,
  535. })
  536. }
  537. infoMap[source_id] = (*infoDataList)[0]
  538. onlyMap[source_id] = v
  539. } else {
  540. log.Println(v, "查询不到改收录信息")
  541. continue
  542. }
  543. }
  544. }
  545. }
  546. //普通人员分发
  547. for positionId, personSmmary := range personMap {
  548. //查询时候收录过
  549. for _, v := range infoMap {
  550. //查询时候收录过
  551. findMap := map[string]interface{}{
  552. "position_id": positionId,
  553. "source_id": v["source_id"],
  554. }
  555. if MC.CrmMysql.Count(entity.EMPLOY_INFO, findMap) == 0 {
  556. //新增
  557. v["ent_user_id"] = personSmmary.EntUserId
  558. v["ent_dept_id"] = personSmmary.EntDeptId
  559. v["position_id"] = positionId
  560. MC.CrmMysql.InsertByTx(tx, entity.EMPLOY_INFO, v)
  561. }
  562. }
  563. }
  564. if in.EntNicheDis > 0 {
  565. //查询分配员有没有该数据
  566. for _, v := range infoMap {
  567. //查询时候收录过
  568. findMap := map[string]interface{}{
  569. "position_id": in.PositionId,
  570. "source_id": v["source_id"],
  571. }
  572. employPositionId := v["position_id"]
  573. if employPositionId != in.PositionId {
  574. //分发消息不属于自己
  575. if MC.CrmMysql.Count(entity.EMPLOY_INFO, findMap) == 0 {
  576. v["ent_user_id"] = in.EntUserId
  577. v["position_id"] = in.PositionId
  578. v["is_handle"] = 1
  579. v["ent_dept_id"] = in.EntDeptId
  580. MC.CrmMysql.InsertByTx(tx, entity.EMPLOY_INFO, v)
  581. } else {
  582. MC.CrmMysql.UpdateByTx(tx, entity.EMPLOY_INFO, findMap, map[string]interface{}{
  583. "is_handle": 1,
  584. })
  585. }
  586. }
  587. }
  588. }
  589. return true
  590. })
  591. }
  592. func niJianHandle(infoId string, data map[string]interface{}, v1, pushTime string) map[string]interface{} {
  593. project, _ := MC.MgoProject.FindOne("projectset_proposed", map[string]interface{}{
  594. "ids": infoId,
  595. })
  596. if project != nil && len(*project) > 0 {
  597. city := common.InterfaceToStr((*project)["city"])
  598. area := common.InterfaceToStr((*project)["area"])
  599. category_code := common.InterfaceToStr((*project)["category_code"])
  600. lasttime := common.Int64All((*project)["lasttime"])
  601. ownerclass_code := common.InterfaceToStr((*project)["ownerclass_code"])
  602. total_investment := common.InterfaceToStr((*project)["total_investment"])
  603. project_stage_code := common.InterfaceToStr((*project)["project_stage_code"])
  604. infoList := gconv.SliceMap((*project)["list"])
  605. title := ""
  606. projectname := ""
  607. if len(infoList) > 0 {
  608. title = common.InterfaceToStr(infoList[0]["title"])
  609. projectname = common.InterfaceToStr(infoList[0]["projectname"])
  610. }
  611. category := ""
  612. ownerclass := ""
  613. project_stage := ""
  614. if category_code != "" {
  615. categoryData := MC.NiJian.FindOne("d_nzj_category_code", map[string]interface{}{
  616. "code": category_code,
  617. }, "name", "")
  618. category = common.InterfaceToStr((*categoryData)["name"])
  619. }
  620. if ownerclass_code != "" {
  621. ownerclassData := MC.NiJian.FindOne("d_nzj_ownerclass_code", map[string]interface{}{
  622. "code": ownerclass_code,
  623. }, "name", "")
  624. ownerclass = common.InterfaceToStr((*ownerclassData)["name"])
  625. }
  626. if project_stage_code != "" {
  627. projectStageData := MC.NiJian.FindOne("d_nzj_project_stage_code", map[string]interface{}{
  628. "code": project_stage_code,
  629. }, "name", "")
  630. project_stage = common.InterfaceToStr((*projectStageData)["name"])
  631. }
  632. data["title"] = title
  633. data["city"] = city
  634. data["area"] = area
  635. data["projectname"] = projectname
  636. data["ownerclass"] = ownerclass
  637. data["project_stage"] = project_stage
  638. data["project_category"] = category
  639. data["project_investment"] = total_investment
  640. lastTimeStr := common.If(lasttime == 0, pushTime, time.Unix(lasttime, 0).Format(date.Date_Full_Layout))
  641. data["project_evolve"] = lastTimeStr
  642. data["show_time"] = lastTimeStr
  643. data["publishtime"] = lastTimeStr
  644. pid := common.InterfaceToStr((*project)["_id"])
  645. data["jybx_url"] = "/succbi/nzj/app/nzj.app/nzj_detail_0.spg?pid=" + pid
  646. data["source"] = 2
  647. data["source_id"] = pid
  648. } else {
  649. data["source"] = 1
  650. data["source_id"] = infoId
  651. data["jybx_url"] = "/article/content/" + v1 + ".html"
  652. }
  653. return data
  654. }
  655. // 个人收录情况查询
  656. func employInfoPerson(table, employKey, findKey string, in *types.InfoEmployinfoReq, version int, infoId1Arr, infoId2Arr, niJianIdArr, wuye1Arr, wuye2Arr []string) map[string]map[string]interface{} {
  657. //
  658. data := map[string]map[string]interface{}{}
  659. infoData1 := &[]map[string]interface{}{}
  660. infoData2 := &[]map[string]interface{}{}
  661. niJianData := &[]map[string]interface{}{}
  662. wuyeData1 := &[]map[string]interface{}{}
  663. wuyeData2 := &[]map[string]interface{}{}
  664. orderKey := "type"
  665. if employKey == "company_id" {
  666. orderKey = "source"
  667. }
  668. if len(infoId1Arr) > 0 {
  669. 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)
  670. }
  671. if len(infoId2Arr) > 0 {
  672. 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)
  673. }
  674. if len(niJianIdArr) > 0 {
  675. 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)
  676. }
  677. if len(wuye1Arr) > 0 {
  678. 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)
  679. }
  680. if len(wuye2Arr) > 0 {
  681. 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)
  682. }
  683. for _, v := range *infoData1 {
  684. valueMap := map[string]interface{}{
  685. "id": v,
  686. "isIgnore": false,
  687. "isEmploy": false,
  688. "customCount": 0,
  689. "clueCount": 0,
  690. "chanceCount": 0,
  691. "type": 1,
  692. }
  693. sourceId := gconv.String(v[employKey])
  694. if _, ok := data[sourceId]; ok {
  695. data[sourceId] = EmployHandle(data[sourceId], v, 0, in.From, len(strings.Split(in.IdArr, ",")) == 1, findKey, in.PositionId, in.PositionType, in.EmployType)
  696. } else {
  697. data[sourceId] = EmployHandle(valueMap, v, 0, in.From, len(strings.Split(in.IdArr, ",")) == 1, findKey, in.PositionId, in.PositionType, in.EmployType)
  698. }
  699. }
  700. for _, v := range *infoData2 {
  701. valueMap := map[string]interface{}{
  702. "id": v,
  703. "isIgnore": false,
  704. "isEmploy": false,
  705. "customCount": 0,
  706. "clueCount": 0,
  707. "chanceCount": 0,
  708. "type": 1,
  709. }
  710. sourceId := gconv.String(v[employKey])
  711. if _, ok := data[sourceId]; ok {
  712. data[sourceId] = EmployHandle(data[sourceId], v, 0, in.From, len(strings.Split(in.IdArr, ",")) == 1, findKey, in.PositionId, in.PositionType, in.EmployType)
  713. } else {
  714. data[sourceId] = EmployHandle(valueMap, v, 0, in.From, len(strings.Split(in.IdArr, ",")) == 1, findKey, in.PositionId, in.PositionType, in.EmployType)
  715. }
  716. }
  717. for _, v := range *niJianData {
  718. valueMap := map[string]interface{}{
  719. "id": v,
  720. "isIgnore": false,
  721. "isEmploy": false,
  722. "customCount": 0,
  723. "clueCount": 0,
  724. "chanceCount": 0,
  725. "type": 1,
  726. }
  727. sourceId := gconv.String(v[employKey])
  728. if _, ok := data[sourceId]; ok {
  729. data[sourceId] = EmployHandle(data[sourceId], v, 0, in.From, len(strings.Split(in.IdArr, ",")) == 1, findKey, in.PositionId, in.PositionType, in.EmployType)
  730. } else {
  731. data[sourceId] = EmployHandle(valueMap, v, 0, in.From, len(strings.Split(in.IdArr, ",")) == 1, findKey, in.PositionId, in.PositionType, in.EmployType)
  732. }
  733. }
  734. for _, v := range *wuyeData1 {
  735. valueMap := map[string]interface{}{
  736. "id": v,
  737. "isIgnore": false,
  738. "isEmploy": false,
  739. "customCount": 0,
  740. "clueCount": 0,
  741. "chanceCount": 0,
  742. "type": 1,
  743. }
  744. sourceId := gconv.String(v[employKey])
  745. if _, ok := data[sourceId]; ok {
  746. data[sourceId] = EmployHandle(data[sourceId], v, 1, in.From, len(strings.Split(in.IdArr, ",")) == 1, findKey, in.PositionId, in.PositionType, in.EmployType)
  747. } else {
  748. data[sourceId] = EmployHandle(valueMap, v, 1, in.From, len(strings.Split(in.IdArr, ",")) == 1, findKey, in.PositionId, in.PositionType, in.EmployType)
  749. }
  750. }
  751. for _, v := range *wuyeData2 {
  752. valueMap := map[string]interface{}{
  753. "id": v,
  754. "isIgnore": false,
  755. "isEmploy": false,
  756. "customCount": 0,
  757. "clueCount": 0,
  758. "chanceCount": 0,
  759. "type": 1,
  760. }
  761. sourceId := gconv.String(v[employKey])
  762. if _, ok := data[sourceId]; ok {
  763. data[sourceId] = EmployHandle(data[sourceId], v, 1, in.From, len(strings.Split(in.IdArr, ",")) == 1, findKey, in.PositionId, in.PositionType, in.EmployType)
  764. } else {
  765. data[sourceId] = EmployHandle(valueMap, v, 1, in.From, len(strings.Split(in.IdArr, ",")) == 1, findKey, in.PositionId, in.PositionType, in.EmployType)
  766. }
  767. }
  768. return data
  769. }
  770. // 企业收录情况查询
  771. func employInfoEnt(table, employKey, findKey, depIDArr string, in *types.InfoEmployinfoReq, version int, infoId1Arr, infoId2Arr, niJianIdArr, wuye1Arr, wuye2Arr []string) map[string]map[string]interface{} {
  772. data := map[string]map[string]interface{}{}
  773. infoData1 := &[]map[string]interface{}{}
  774. infoData2 := &[]map[string]interface{}{}
  775. niJianData := &[]map[string]interface{}{}
  776. wuyeData1 := &[]map[string]interface{}{}
  777. wuyeData2 := &[]map[string]interface{}{}
  778. orderKey := "type"
  779. if employKey == "company_id" {
  780. orderKey = "source"
  781. }
  782. if len(infoId1Arr) > 0 {
  783. 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)
  784. }
  785. if len(infoId2Arr) > 0 {
  786. 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)
  787. }
  788. if len(niJianIdArr) > 0 {
  789. 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)
  790. }
  791. if len(wuye1Arr) > 0 {
  792. 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)
  793. }
  794. if len(wuye2Arr) > 0 {
  795. 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)
  796. }
  797. for _, v := range *infoData1 {
  798. valueMap := map[string]interface{}{
  799. "id": v,
  800. "isIgnore": false,
  801. "isEmploy": false,
  802. "customCount": 0,
  803. "clueCount": 0,
  804. "chanceCount": 0,
  805. "type": 1,
  806. }
  807. sourceId := gconv.String(v[employKey])
  808. if _, ok := data[sourceId]; ok {
  809. data[sourceId] = EmployHandle(data[sourceId], v, 0, in.From, len(strings.Split(in.IdArr, ",")) == 1, findKey, in.PositionId, in.PositionType, in.EmployType)
  810. } else {
  811. data[sourceId] = EmployHandle(valueMap, v, 0, in.From, len(strings.Split(in.IdArr, ",")) == 1, findKey, in.PositionId, in.PositionType, in.EmployType)
  812. }
  813. }
  814. for _, v := range *infoData2 {
  815. valueMap := map[string]interface{}{
  816. "id": v,
  817. "isIgnore": false,
  818. "isEmploy": false,
  819. "customCount": 0,
  820. "clueCount": 0,
  821. "chanceCount": 0,
  822. "type": 1,
  823. }
  824. sourceId := gconv.String(v[employKey])
  825. if _, ok := data[sourceId]; ok {
  826. data[sourceId] = EmployHandle(data[sourceId], v, 0, in.From, len(strings.Split(in.IdArr, ",")) == 1, findKey, in.PositionId, in.PositionType, in.EmployType)
  827. } else {
  828. data[sourceId] = EmployHandle(valueMap, v, 0, in.From, len(strings.Split(in.IdArr, ",")) == 1, findKey, in.PositionId, in.PositionType, in.EmployType)
  829. }
  830. }
  831. for _, v := range *niJianData {
  832. valueMap := map[string]interface{}{
  833. "id": v,
  834. "isIgnore": false,
  835. "isEmploy": false,
  836. "customCount": 0,
  837. "clueCount": 0,
  838. "chanceCount": 0,
  839. "type": 1,
  840. }
  841. sourceId := gconv.String(v[employKey])
  842. if _, ok := data[sourceId]; ok {
  843. data[sourceId] = EmployHandle(data[sourceId], v, version, in.From, len(strings.Split(in.IdArr, ",")) == 1, findKey, in.PositionId, in.PositionType, in.EmployType)
  844. } else {
  845. data[sourceId] = EmployHandle(valueMap, v, version, in.From, len(strings.Split(in.IdArr, ",")) == 1, findKey, in.PositionId, in.PositionType, in.EmployType)
  846. }
  847. }
  848. for _, v := range *wuyeData1 {
  849. valueMap := map[string]interface{}{
  850. "id": v,
  851. "isIgnore": false,
  852. "isEmploy": false,
  853. "customCount": 0,
  854. "clueCount": 0,
  855. "chanceCount": 0,
  856. "type": 1,
  857. }
  858. sourceId := gconv.String(v[employKey])
  859. if _, ok := data[sourceId]; ok {
  860. data[sourceId] = EmployHandle(data[sourceId], v, 1, in.From, len(strings.Split(in.IdArr, ",")) == 1, findKey, in.PositionId, in.PositionType, in.EmployType)
  861. } else {
  862. data[sourceId] = EmployHandle(valueMap, v, 1, in.From, len(strings.Split(in.IdArr, ",")) == 1, findKey, in.PositionId, in.PositionType, in.EmployType)
  863. }
  864. }
  865. for _, v := range *wuyeData2 {
  866. valueMap := map[string]interface{}{
  867. "id": v,
  868. "isIgnore": false,
  869. "isEmploy": false,
  870. "customCount": 0,
  871. "clueCount": 0,
  872. "chanceCount": 0,
  873. "type": 1,
  874. }
  875. sourceId := gconv.String(v[employKey])
  876. if _, ok := data[sourceId]; ok {
  877. data[sourceId] = EmployHandle(data[sourceId], v, 1, in.From, len(strings.Split(in.IdArr, ",")) == 1, findKey, in.PositionId, in.PositionType, in.EmployType)
  878. } else {
  879. data[sourceId] = EmployHandle(valueMap, v, 1, in.From, len(strings.Split(in.IdArr, ",")) == 1, findKey, in.PositionId, in.PositionType, in.EmployType)
  880. }
  881. }
  882. return data
  883. }
  884. 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{} {
  885. employType := common.Int64All(employData["type"])
  886. employStatus := common.Int64All(employData["status"])
  887. employ2 := false
  888. employ3 := false
  889. employIgnore := false
  890. employId := int64(0)
  891. is_ignore := int64(0)
  892. employArrStr := ""
  893. //收录标识处理
  894. if common.Int64All(employData["id"]) == 0 {
  895. if len(gconv.String(employData["employIdArr"])) > 0 {
  896. employArrStr = gconv.String(employData["employIdArr"])
  897. employId = gconv.Int64(strings.Split(employArrStr, ",")[0])
  898. }
  899. } else {
  900. employId = common.Int64All(employData["id"])
  901. }
  902. if version == 1 {
  903. is_ignore = common.Int64All(employData["is_ignore"])
  904. switch employType {
  905. case 2:
  906. if valueMap["employ3"] != nil {
  907. employ3 = gconv.Bool(valueMap["employ3"])
  908. }
  909. if employStatus == 1 {
  910. employ2 = true
  911. }
  912. case 3:
  913. if valueMap["employ2"] != nil {
  914. employ2 = gconv.Bool(valueMap["employ2"])
  915. }
  916. if employStatus == 1 {
  917. employ3 = true
  918. }
  919. }
  920. if is_ignore > 0 {
  921. employIgnore = true
  922. }
  923. employType = common.Int64All(employData["type"])
  924. valueMap["isIgnore"] = employIgnore
  925. if originate == "jhfp" {
  926. valueMap["isEmploy"] = employ3
  927. } else {
  928. valueMap["isEmploy"] = common.If(employ2 && employ3, true, false)
  929. }
  930. valueMap["type"] = employType
  931. valueMap["employ2"] = employ2
  932. valueMap["employ3"] = employ3
  933. valueMap["employId"] = employId
  934. } else {
  935. valueMap["isIgnore"] = common.If(common.Int64All(employData["is_ignore"]) == 1, true, false)
  936. valueMap["isEmploy"] = common.If(common.Int64All(employData["status"]) == 1, true, false)
  937. valueMap["type"] = common.Int64All(employData["type"])
  938. valueMap["employId"] = employId
  939. }
  940. if employType == 2 {
  941. valueMap["intelligenceId"] = employId
  942. }
  943. if single && employArrStr != "" {
  944. //列表查询
  945. //是否忽略处理
  946. //客户数量
  947. customSql := ""
  948. clueSql := ""
  949. chanceSql := ""
  950. if positionType == 0 {
  951. customSql = fmt.Sprintf("select COUNT(1) from %s where %s in (%s) and position_id=%d", entity.CUSTOM, findKey, employArrStr, positionId)
  952. clueSql = fmt.Sprintf("select COUNT(1) from %s where employ_info_id in (%s) and position_id=%d", entity.SALE_CLUE, employArrStr, positionId)
  953. chanceSql = fmt.Sprintf("select COUNT(1) from %s where employ_info_id in (%s) and position_id=%d", entity.SALE_CHANCE, employArrStr, positionId)
  954. } else {
  955. customSql = fmt.Sprintf("select COUNT(1) from %s where %s in (%s)", entity.CUSTOM, findKey, employArrStr)
  956. clueSql = fmt.Sprintf("select COUNT(1) from %s where employ_info_id in (%s)", entity.SALE_CLUE, employArrStr)
  957. chanceSql = fmt.Sprintf("select COUNT(1) from %s where employ_info_id in (%s)", entity.SALE_CHANCE, employArrStr)
  958. }
  959. customCount := MC.CrmMysql.CountBySql(customSql)
  960. valueMap["customCount"] = customCount
  961. if inEmployType == 1 || inEmployType == 4 {
  962. //销售线索数量
  963. clueCount := MC.CrmMysql.CountBySql(clueSql)
  964. valueMap["clueCount"] = clueCount
  965. //销售机会数量
  966. chanceCount := MC.CrmMysql.CountBySql(chanceSql)
  967. valueMap["chanceCount"] = chanceCount
  968. }
  969. } else {
  970. valueMap["chanceCount"] = 0
  971. valueMap["clueCount"] = 0
  972. valueMap["customCount"] = 0
  973. }
  974. return valueMap
  975. }