employService.go 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925
  1. package service
  2. import (
  3. "app.yhyue.com/moapp/jybase/common"
  4. "app.yhyue.com/moapp/jybase/date"
  5. elastic "app.yhyue.com/moapp/jybase/es"
  6. "app.yhyue.com/moapp/jypkg/ent/util"
  7. MC "bp.jydev.jianyu360.cn/CRM/application/api/common"
  8. "bp.jydev.jianyu360.cn/CRM/application/api/internal/types"
  9. "bp.jydev.jianyu360.cn/CRM/application/entity"
  10. "database/sql"
  11. "fmt"
  12. "github.com/RoaringBitmap/roaring"
  13. "github.com/gogf/gf/v2/util/gconv"
  14. "log"
  15. "strings"
  16. "time"
  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.SourceId)
  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. if aobj != nil || *aobj != nil || len(*aobj) > 0 {
  260. obj = (*aobj)[0]
  261. }
  262. toptype := common.InterfaceToStr(obj["toptype"])
  263. subtype := common.InterfaceToStr(obj["subtype"])
  264. pushTime := ""
  265. if obj != nil && len(obj) > 0 {
  266. data["title"] = common.ObjToString(obj["title"])
  267. data["city"] = obj["city"]
  268. data["area"] = obj["area"]
  269. data["subtype"] = obj["subtype"]
  270. data["buyerclass"] = obj["buyerclass"]
  271. data["budget"] = obj["budget"]
  272. data["bidamount"] = obj["bidamount"]
  273. data["annex"] = 0
  274. data["buyer"] = obj["buyer"]
  275. data["winner"] = obj["s_winner"]
  276. data["jybx_url"] = "/article/content/" + v1 + ".html"
  277. //类型处理
  278. pushTime = time.Unix(common.Int64All(obj["publishtime"]), 0).Format(date.Date_Full_Layout)
  279. data["source"] = 1
  280. data["source_id"] = id
  281. if subtype == "拟建" {
  282. data["source"] = 2
  283. }
  284. if toptype == "采购意向" || toptype == "预告" || toptype == "招标" || toptype == "" {
  285. data["type"] = 2
  286. } else {
  287. if subtype == "废标" || subtype == "流标" || subtype == "其它" {
  288. data["type"] = 2
  289. } else if subtype == "成交" || subtype == "中标" || subtype == "合同" || subtype == "验收" || subtype == "违规" {
  290. data["type"] = 3
  291. } else {
  292. data["type"] = 1
  293. }
  294. }
  295. if obj["projectinfo"] != nil {
  296. projectinfo := common.ObjToMap(obj["projectinfo"])
  297. if (*projectinfo)["attachments"] != nil {
  298. data["annex"] = 1
  299. }
  300. }
  301. data["publishtime"] = pushTime
  302. data["show_time"] = pushTime
  303. data["projectname"] = obj["projectname"]
  304. procurementlist, _ := obj["procurementlist"].([]interface{})
  305. for _, vs := range procurementlist { //1.采购意向清单数据集打码处理
  306. vsMap, _ := vs.(map[string]interface{})
  307. if vsMap["expurasingtime"] != nil {
  308. data["expurasing_time"] = vsMap["expurasingtime"]
  309. break
  310. }
  311. }
  312. }
  313. data["status"] = 1
  314. data["employ_way"] = 1
  315. data["create_time"] = time.Now().Format(date.Date_Full_Layout)
  316. if subtype == "拟建" {
  317. data = niJianHandle(id, data, v1, pushTime)
  318. data["type"] = 1
  319. }
  320. return data
  321. }
  322. // GetBuyerIdByName 通过采购单位名称获取id
  323. func getBuyerIdByName(buyerName string) (buyerId string) {
  324. r := elastic.Get(BuyerIndex, BuyerType, fmt.Sprintf(`{"query":{"bool":{"must":[{"term":{"buyer_name":"%s"}}]}},"size":1,"_source":["city","id"]}`, buyerName))
  325. if r == nil || len(*r) == 0 {
  326. return
  327. }
  328. buyerId, _ = (*r)[0]["_id"].(string)
  329. return
  330. }
  331. // IdFormat id解密
  332. func idFormat(encryptionId string, employType int64) string {
  333. decryptId := ""
  334. switch employType {
  335. case 1, 2:
  336. decryptId = util.DecodeId(encryptionId)
  337. case 3:
  338. if len(encryptionId) > 0 && len([]rune(encryptionId)) == len(encryptionId) {
  339. //此数据是id
  340. //获取中文名字
  341. decryptId = util.DecodeId(encryptionId)
  342. } else {
  343. //次数据传的名字
  344. decryptId = getBuyerIdByName(encryptionId)
  345. }
  346. }
  347. return decryptId
  348. }
  349. type Employ struct {
  350. Source int64
  351. IsNiJian bool
  352. ProjectId string
  353. Id string
  354. SourceId string
  355. Subtype string
  356. }
  357. // employKeyFormat 根据收录类型 字段处理 table,findKey,employKey,source
  358. func employKeyFormat(employType int64, idArrStr string) (string, string, string, map[string]Employ) {
  359. table := ""
  360. employKey := "company_id"
  361. findKey := "employ_custom_id"
  362. infoIdMap := map[string]Employ{}
  363. idArr := []string{}
  364. source := int64(0)
  365. switch employType {
  366. case 1:
  367. table = entity.EMPLOY_INFO
  368. employKey = "source_id"
  369. findKey = "employ_info_id"
  370. source = 1
  371. case 2:
  372. table = entity.EMPLOY_CUSTOM
  373. source = 1
  374. case 3:
  375. table = entity.EMPLOY_CUSTOM
  376. source = 2
  377. case 4:
  378. table = entity.EMPLOY_INFO
  379. source = 2
  380. employKey = "source_id"
  381. findKey = "employ_info_id"
  382. }
  383. for _, v := range strings.Split(idArrStr, ",") {
  384. id := idFormat(v, employType)
  385. idArr = append(idArr, id)
  386. infoIdMap[id] = Employ{
  387. Source: source,
  388. IsNiJian: false,
  389. ProjectId: "",
  390. Id: v,
  391. SourceId: id,
  392. }
  393. }
  394. if employType == 1 {
  395. table = entity.EMPLOY_INFO
  396. employKey = "source_id"
  397. findKey = "employ_info_id"
  398. source = 1
  399. aobj := elastic.Get(INDEX, TYPE, fmt.Sprintf(`{"query":{"bool":{"must_not":[],"should":[ {
  400. "terms": {
  401. "id": [
  402. "%s"
  403. ]
  404. }
  405. }]}},"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, `","`)))
  406. if aobj != nil && len(*aobj) > 0 || *aobj != nil {
  407. for _, v := range *aobj {
  408. id := common.InterfaceToStr(v["_id"])
  409. subtype := common.InterfaceToStr(v["subtype"])
  410. data, ok := infoIdMap[id]
  411. data.Subtype = subtype
  412. if subtype == "拟建" && ok {
  413. project, _ := MC.MgoProject.FindOne("projectset_proposed", map[string]interface{}{
  414. "ids": id,
  415. })
  416. data.Source = 2
  417. if project != nil && len(*project) > 0 {
  418. projectId := common.InterfaceToStr((*project)["_id"])
  419. data.IsNiJian = true
  420. data.ProjectId = projectId
  421. }
  422. }
  423. infoIdMap[id] = data
  424. }
  425. }
  426. }
  427. return table, findKey, employKey, infoIdMap
  428. }
  429. // IgnoreOperate 忽略操作
  430. func (e *EmPloyService) IgnoreOperate(in *types.IgnoreOperateReq) (bool, string) {
  431. //
  432. table := ""
  433. switch in.EmployType {
  434. case 1, 4:
  435. table = entity.EMPLOY_INFO
  436. case 2, 3:
  437. table = entity.EMPLOY_CUSTOM
  438. }
  439. msg := ""
  440. fool := true
  441. for _, v := range strings.Split(in.IdArr, ",") {
  442. id := idFormat(v, in.EmployType)
  443. if id == "" {
  444. log.Println(v, id, in.EmployType, "忽略处理,id解析失败")
  445. continue
  446. }
  447. findMap := map[string]interface{}{
  448. "position_id": in.PositionId,
  449. }
  450. if in.EmployType == 3 || in.EmployType == 2 {
  451. findMap["company_id"] = id
  452. } else {
  453. findMap["source_id"] = id
  454. }
  455. if MC.CrmMysql.Count(table, findMap) == 0 {
  456. log.Println(v, id, in.EmployType, "忽略处理,id所对应数据不存在")
  457. fool = false
  458. if in.EmployType == 1 {
  459. if in.IsIgnore {
  460. msg = "该资讯已有员工收录,不可忽略。"
  461. } else {
  462. msg = "该资讯已有员工收录,不可取消忽略。"
  463. }
  464. } else {
  465. if in.IsIgnore {
  466. msg = "该企业已有员工收录,不可忽略。"
  467. } else {
  468. msg = "该企业已有员工收录,不可取消忽略。"
  469. }
  470. }
  471. continue
  472. }
  473. if in.IsIgnore {
  474. MC.CrmMysql.Update(table, findMap, map[string]interface{}{
  475. "is_ignore": 1,
  476. "is_handle": 1,
  477. })
  478. } else {
  479. MC.CrmMysql.Update(table, findMap, map[string]interface{}{
  480. "is_ignore": 0,
  481. "is_handle": 1,
  482. })
  483. }
  484. }
  485. return fool, msg
  486. }
  487. // DistributePerson 分发操作
  488. func (e *EmPloyService) DistributePerson(in *types.EmployDistributeReq) bool {
  489. return MC.CrmMysql.ExecTx("收录操作", func(tx *sql.Tx) bool {
  490. personMap := map[int64]PersonSmmary{}
  491. //人员信息处理
  492. for _, person := range in.Person {
  493. personMap[person.PositionId] = PersonSmmary{
  494. EntUserId: person.EntUserId,
  495. EntDeptId: person.EntDeptId,
  496. }
  497. }
  498. //分发数据处理
  499. infoMap := map[string]map[string]interface{}{}
  500. onlyMap := map[string]interface{}{}
  501. //标讯数据处理
  502. for _, v := range strings.Split(in.EmployIdArr, ",") {
  503. if onlyMap[v] == nil {
  504. //查询信息
  505. infoDataList := MC.CrmMysql.SelectBySqlByTx(tx, "SELECT * FROM employ_info WHERE id=?", v)
  506. if infoDataList != nil && len(*infoDataList) > 0 {
  507. source_id := common.InterfaceToStr((*infoDataList)[0]["source_id"])
  508. if onlyMap[source_id] == nil {
  509. (*infoDataList)[0]["dis_id"] = v
  510. (*infoDataList)[0]["is_handle"] = 0
  511. (*infoDataList)[0]["is_ignore"] = 0
  512. (*infoDataList)[0]["is_dis"] = 0
  513. (*infoDataList)[0]["is_create_clue"] = 0
  514. (*infoDataList)[0]["is_create_chance"] = 0
  515. (*infoDataList)[0]["is_create_custom"] = 0
  516. (*infoDataList)[0]["create_time"] = time.Now().Format(date.Date_Full_Layout)
  517. delete((*infoDataList)[0], "id")
  518. if common.IntAll((*infoDataList)[0]["is_dis"]) != 1 {
  519. MC.CrmMysql.UpdateByTx(tx, entity.EMPLOY_INFO, map[string]interface{}{
  520. "id": v,
  521. }, map[string]interface{}{
  522. "is_dis": 1,
  523. "is_handle": 1,
  524. })
  525. }
  526. infoMap[source_id] = (*infoDataList)[0]
  527. onlyMap[source_id] = v
  528. } else {
  529. log.Println(v, "查询不到改收录信息")
  530. continue
  531. }
  532. }
  533. }
  534. }
  535. //普通人员分发
  536. for positionId, personSmmary := range personMap {
  537. //查询时候收录过
  538. for _, v := range infoMap {
  539. //查询时候收录过
  540. findMap := map[string]interface{}{
  541. "position_id": positionId,
  542. "source_id": v["source_id"],
  543. }
  544. if MC.CrmMysql.Count(entity.EMPLOY_INFO, findMap) == 0 {
  545. //新增
  546. v["ent_user_id"] = personSmmary.EntUserId
  547. v["ent_dept_id"] = personSmmary.EntDeptId
  548. v["position_id"] = positionId
  549. MC.CrmMysql.InsertByTx(tx, entity.EMPLOY_INFO, v)
  550. }
  551. }
  552. }
  553. if in.EntNicheDis > 0 {
  554. //查询分配员有没有该数据
  555. for _, v := range infoMap {
  556. //查询时候收录过
  557. findMap := map[string]interface{}{
  558. "position_id": in.PositionId,
  559. "source_id": v["source_id"],
  560. }
  561. employPositionId := v["position_id"]
  562. if employPositionId != in.PositionId {
  563. //分发消息不属于自己
  564. if MC.CrmMysql.Count(entity.EMPLOY_INFO, findMap) == 0 {
  565. v["ent_user_id"] = in.EntUserId
  566. v["position_id"] = in.PositionId
  567. v["is_handle"] = 1
  568. v["ent_dept_id"] = in.EntDeptId
  569. MC.CrmMysql.InsertByTx(tx, entity.EMPLOY_INFO, v)
  570. } else {
  571. MC.CrmMysql.UpdateByTx(tx, entity.EMPLOY_INFO, findMap, map[string]interface{}{
  572. "is_handle": 1,
  573. })
  574. }
  575. }
  576. }
  577. }
  578. return true
  579. })
  580. }
  581. func niJianHandle(infoId string, data map[string]interface{}, v1, pushTime string) map[string]interface{} {
  582. project, _ := MC.MgoProject.FindOne("projectset_proposed", map[string]interface{}{
  583. "ids": infoId,
  584. })
  585. if project != nil && len(*project) > 0 {
  586. city := common.InterfaceToStr((*project)["city"])
  587. area := common.InterfaceToStr((*project)["area"])
  588. category_code := common.InterfaceToStr((*project)["category_code"])
  589. lasttime := common.Int64All((*project)["lasttime"])
  590. ownerclass_code := common.InterfaceToStr((*project)["ownerclass_code"])
  591. total_investment := common.InterfaceToStr((*project)["total_investment"])
  592. project_stage_code := common.InterfaceToStr((*project)["project_stage_code"])
  593. infoList := gconv.SliceMap((*project)["list"])
  594. title := ""
  595. projectname := ""
  596. if len(infoList) > 0 {
  597. title = common.InterfaceToStr(infoList[0]["title"])
  598. projectname = common.InterfaceToStr(infoList[0]["projectname"])
  599. }
  600. category := ""
  601. ownerclass := ""
  602. project_stage := ""
  603. if category_code != "" {
  604. categoryData := MC.NiJian.FindOne("d_nzj_category_code", map[string]interface{}{
  605. "code": category_code,
  606. }, "name", "")
  607. category = common.InterfaceToStr((*categoryData)["name"])
  608. }
  609. if ownerclass_code != "" {
  610. ownerclassData := MC.NiJian.FindOne("d_nzj_ownerclass_code", map[string]interface{}{
  611. "code": ownerclass_code,
  612. }, "name", "")
  613. ownerclass = common.InterfaceToStr((*ownerclassData)["name"])
  614. }
  615. if project_stage_code != "" {
  616. projectStageData := MC.NiJian.FindOne("d_nzj_project_stage_code", map[string]interface{}{
  617. "code": project_stage_code,
  618. }, "name", "")
  619. project_stage = common.InterfaceToStr((*projectStageData)["name"])
  620. }
  621. data["title"] = title
  622. data["city"] = city
  623. data["area"] = area
  624. data["projectname"] = projectname
  625. data["ownerclass"] = ownerclass
  626. data["project_stage"] = project_stage
  627. data["project_category"] = category
  628. data["project_investment"] = total_investment
  629. lastTimeStr := common.If(lasttime == 0, pushTime, time.Unix(lasttime, 0).Format(date.Date_Full_Layout))
  630. data["project_evolve"] = lastTimeStr
  631. data["show_time"] = lastTimeStr
  632. data["publishtime"] = lastTimeStr
  633. pid := common.InterfaceToStr((*project)["_id"])
  634. data["jybx_url"] = "/succbi/nzj/app/nzj.app/nzj_detail_0.spg?pid=" + pid
  635. data["source"] = 2
  636. data["source_id"] = pid
  637. } else {
  638. data["source"] = 1
  639. data["source_id"] = infoId
  640. data["jybx_url"] = "/article/content/" + v1 + ".html"
  641. }
  642. return data
  643. }
  644. // 个人收录情况查询
  645. func employInfoPerson(table, employKey, findKey string, in *types.InfoEmployinfoReq, version int, infoId1Arr, infoId2Arr, niJianIdArr, wuye1Arr, wuye2Arr []string) map[string]map[string]interface{} {
  646. //
  647. data := map[string]map[string]interface{}{}
  648. infoData1 := &[]map[string]interface{}{}
  649. infoData2 := &[]map[string]interface{}{}
  650. niJianData := &[]map[string]interface{}{}
  651. wuyeData1 := &[]map[string]interface{}{}
  652. wuyeData2 := &[]map[string]interface{}{}
  653. if len(infoId1Arr) > 0 {
  654. infoData1 = MC.CrmMysql.SelectBySql(fmt.Sprintf("select is_ignore,status,id,type from %s where position_id =? and %s in ('%s') GROUP BY %s ", table, employKey, strings.Join(infoId1Arr, "','"), employKey), in.PositionId, 1)
  655. }
  656. if len(infoId2Arr) > 0 {
  657. infoData2 = MC.CrmMysql.SelectBySql(fmt.Sprintf("select is_ignore,status,id,type from %s where position_id =? and %s in '%s') GROUP BY %s ", table, employKey, strings.Join(infoId2Arr, "','"), employKey), in.PositionId, 1)
  658. }
  659. if len(niJianIdArr) > 0 {
  660. niJianData = MC.CrmMysql.SelectBySql(fmt.Sprintf("select is_ignore,status,id,type from %s where position_id =? and %s in ('%s') GROUP BY %s ", table, employKey, strings.Join(niJianIdArr, "','"), employKey), in.PositionId, 1)
  661. }
  662. if len(wuye1Arr) > 0 {
  663. wuyeData1 = MC.CrmMysql.SelectBySql(fmt.Sprintf("select is_ignore,status,id,type from %s where position_id =? and %s in ('%s') GROUP BY %s ", table, employKey, strings.Join(wuye1Arr, "','"), employKey), in.PositionId, 1)
  664. }
  665. if len(wuye2Arr) > 0 {
  666. wuyeData2 = MC.CrmMysql.SelectBySql(fmt.Sprintf("select is_ignore,status,id,type from %s where position_id =? and %s in ('%s') GROUP BY %s ", table, employKey, strings.Join(wuye2Arr, "','"), employKey), in.PositionId, 1)
  667. }
  668. for _, v := range *infoData1 {
  669. valueMap := map[string]interface{}{
  670. "id": v,
  671. "isIgnore": false,
  672. "isEmploy": false,
  673. "customCount": 0,
  674. "clueCount": 0,
  675. "chanceCount": 0,
  676. "type": 1,
  677. }
  678. sourceId := gconv.String(v[employKey])
  679. data[sourceId] = EmployHandle(valueMap, v, 0, in.From, len(strings.Split(in.IdArr, ",")) == 1, findKey, in.PositionId, in.PositionType, in.EmployType)
  680. }
  681. for _, v := range *infoData2 {
  682. valueMap := map[string]interface{}{
  683. "id": v,
  684. "isIgnore": false,
  685. "isEmploy": false,
  686. "customCount": 0,
  687. "clueCount": 0,
  688. "chanceCount": 0,
  689. "type": 1,
  690. }
  691. sourceId := gconv.String(v[employKey])
  692. data[sourceId] = EmployHandle(valueMap, v, 0, in.From, len(strings.Split(in.IdArr, ",")) == 1, findKey, in.PositionId, in.PositionType, in.EmployType)
  693. }
  694. for _, v := range *niJianData {
  695. valueMap := map[string]interface{}{
  696. "id": v,
  697. "isIgnore": false,
  698. "isEmploy": false,
  699. "customCount": 0,
  700. "clueCount": 0,
  701. "chanceCount": 0,
  702. "type": 1,
  703. }
  704. sourceId := gconv.String(v[employKey])
  705. data[sourceId] = EmployHandle(valueMap, v, 0, in.From, len(strings.Split(in.IdArr, ",")) == 1, findKey, in.PositionId, in.PositionType, in.EmployType)
  706. }
  707. for _, v := range *wuyeData1 {
  708. valueMap := map[string]interface{}{
  709. "id": v,
  710. "isIgnore": false,
  711. "isEmploy": false,
  712. "customCount": 0,
  713. "clueCount": 0,
  714. "chanceCount": 0,
  715. "type": 1,
  716. }
  717. sourceId := gconv.String(v[employKey])
  718. data[sourceId] = EmployHandle(valueMap, v, 1, in.From, len(strings.Split(in.IdArr, ",")) == 1, findKey, in.PositionId, in.PositionType, in.EmployType)
  719. }
  720. for _, v := range *wuyeData2 {
  721. valueMap := map[string]interface{}{
  722. "id": v,
  723. "isIgnore": false,
  724. "isEmploy": false,
  725. "customCount": 0,
  726. "clueCount": 0,
  727. "chanceCount": 0,
  728. "type": 1,
  729. }
  730. sourceId := gconv.String(v[employKey])
  731. data[sourceId] = EmployHandle(valueMap, v, 1, in.From, len(strings.Split(in.IdArr, ",")) == 1, findKey, in.PositionId, in.PositionType, in.EmployType)
  732. }
  733. return data
  734. }
  735. // 企业收录情况查询
  736. func employInfoEnt(table, employKey, findKey, depIDArr string, in *types.InfoEmployinfoReq, version int, infoId1Arr, infoId2Arr, niJianIdArr, wuye1Arr, wuye2Arr []string) map[string]map[string]interface{} {
  737. data := map[string]map[string]interface{}{}
  738. infoData1 := &[]map[string]interface{}{}
  739. infoData2 := &[]map[string]interface{}{}
  740. niJianData := &[]map[string]interface{}{}
  741. wuyeData1 := &[]map[string]interface{}{}
  742. wuyeData2 := &[]map[string]interface{}{}
  743. if len(infoId1Arr) > 0 {
  744. infoData1 = MC.CrmMysql.SelectBySql(fmt.Sprintf("select %s,GROUP_CONCAT(id) as employIdArr,MAX(is_ignore) as is_ignore,MAX(status) as status from %s where %s in ('%s') and source=? and ent_dept_id in (%s) GROUP BY %s ", employKey, table, employKey, strings.Join(infoId1Arr, "','"), depIDArr, employKey), 1)
  745. }
  746. if len(infoId2Arr) > 0 {
  747. infoData2 = MC.CrmMysql.SelectBySql(fmt.Sprintf("select %s, GROUP_CONCAT(id) as employIdArr,MAX(is_ignore) as is_ignore,MAX(status) as status from %s where %s in ('%s') and source=? and ent_dept_id in (%s) GROUP BY %s ", employKey, table, employKey, strings.Join(infoId2Arr, "','"), depIDArr, employKey), 2)
  748. }
  749. if len(niJianIdArr) > 0 {
  750. niJianData = MC.CrmMysql.SelectBySql(fmt.Sprintf("select %s, GROUP_CONCAT(id) as employIdArr,MAX(is_ignore) as is_ignore,MAX(status) as status from %s where %s in ('%s') and source=? and ent_dept_id in (%s) GROUP BY %s ", employKey, table, employKey, strings.Join(niJianIdArr, "','"), depIDArr, employKey), 2)
  751. }
  752. if len(wuye1Arr) > 0 {
  753. wuyeData1 = MC.CrmMysql.SelectBySql(fmt.Sprintf("select %s, id,is_ignore,status ,type from %s where %s in ('%s') and status =1 and source=? and ent_dept_id in (%s) GROUP BY %s ", employKey, table, employKey, strings.Join(wuye1Arr, "','"), depIDArr, employKey), 1)
  754. }
  755. if len(wuye2Arr) > 0 {
  756. wuyeData2 = MC.CrmMysql.SelectBySql(fmt.Sprintf("select %s id,is_ignore,status ,type from %s where %s in ('%s') and status =1 and source=? and ent_dept_id in (%s) GROUP BY %s ", employKey, table, employKey, strings.Join(wuye2Arr, "','"), depIDArr, employKey), 2)
  757. }
  758. for _, v := range *infoData1 {
  759. valueMap := map[string]interface{}{
  760. "id": v,
  761. "isIgnore": false,
  762. "isEmploy": false,
  763. "customCount": 0,
  764. "clueCount": 0,
  765. "chanceCount": 0,
  766. "type": 1,
  767. }
  768. sourceId := gconv.String(v[employKey])
  769. data[sourceId] = EmployHandle(valueMap, v, 0, in.From, len(strings.Split(in.IdArr, ",")) == 1, findKey, in.PositionId, in.PositionType, in.EmployType)
  770. }
  771. for _, v := range *infoData2 {
  772. valueMap := map[string]interface{}{
  773. "id": v,
  774. "isIgnore": false,
  775. "isEmploy": false,
  776. "customCount": 0,
  777. "clueCount": 0,
  778. "chanceCount": 0,
  779. "type": 1,
  780. }
  781. sourceId := gconv.String(v[employKey])
  782. data[sourceId] = EmployHandle(valueMap, v, 0, in.From, len(strings.Split(in.IdArr, ",")) == 1, findKey, in.PositionId, in.PositionType, in.EmployType)
  783. }
  784. for _, v := range *niJianData {
  785. valueMap := map[string]interface{}{
  786. "id": v,
  787. "isIgnore": false,
  788. "isEmploy": false,
  789. "customCount": 0,
  790. "clueCount": 0,
  791. "chanceCount": 0,
  792. "type": 1,
  793. }
  794. sourceId := gconv.String(v[employKey])
  795. data[sourceId] = EmployHandle(valueMap, v, version, in.From, len(strings.Split(in.IdArr, ",")) == 1, findKey, in.PositionId, in.PositionType, in.EmployType)
  796. }
  797. for _, v := range *wuyeData1 {
  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. data[sourceId] = EmployHandle(valueMap, v, 1, in.From, len(strings.Split(in.IdArr, ",")) == 1, findKey, in.PositionId, in.PositionType, in.EmployType)
  809. }
  810. for _, v := range *wuyeData2 {
  811. valueMap := map[string]interface{}{
  812. "id": v,
  813. "isIgnore": false,
  814. "isEmploy": false,
  815. "customCount": 0,
  816. "clueCount": 0,
  817. "chanceCount": 0,
  818. "type": 1,
  819. }
  820. sourceId := gconv.String(v[employKey])
  821. data[sourceId] = EmployHandle(valueMap, v, 1, in.From, len(strings.Split(in.IdArr, ",")) == 1, findKey, in.PositionId, in.PositionType, in.EmployType)
  822. }
  823. return data
  824. }
  825. 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{} {
  826. employType := common.Int64All(employData["type"])
  827. employStatus := common.Int64All(employData["status"])
  828. employ2 := false
  829. employ3 := false
  830. employIgnore := false
  831. employId := int64(0)
  832. is_ignore := int64(0)
  833. employArrStr := ""
  834. if version == 1 {
  835. is_ignore = common.Int64All(employData["is_ignore"])
  836. switch employType {
  837. case 2:
  838. if valueMap["employ3"] != nil {
  839. employ3 = gconv.Bool(valueMap["employ3"])
  840. }
  841. if employStatus == 1 {
  842. employ2 = true
  843. }
  844. case 3:
  845. if valueMap["employ2"] != nil {
  846. employ3 = gconv.Bool(valueMap["employ2"])
  847. }
  848. if employStatus == 1 {
  849. employ3 = true
  850. }
  851. }
  852. if is_ignore > 0 {
  853. employIgnore = true
  854. }
  855. employType = common.Int64All(employData["type"])
  856. employId = common.Int64All(employData["id"])
  857. valueMap["isIgnore"] = employIgnore
  858. if originate == "jhfp" {
  859. valueMap["isEmploy"] = employ3
  860. } else {
  861. valueMap["isEmploy"] = common.If(employ2 && employ3, true, false)
  862. }
  863. valueMap["type"] = employType
  864. valueMap["employ2"] = employ2
  865. valueMap["employ3"] = employ3
  866. valueMap["employId"] = employId
  867. } else {
  868. valueMap["isIgnore"] = common.If(common.Int64All(employData["is_ignore"]) == 1, true, false)
  869. valueMap["isEmploy"] = common.If(common.Int64All(employData["status"]) == 1, true, false)
  870. valueMap["type"] = common.Int64All(employData["type"])
  871. employArrStr := common.InterfaceToStr(employData["employIdArr"])
  872. valueMap["employId"] = strings.Split(employArrStr, ",")[0]
  873. }
  874. if single && employArrStr != "" {
  875. //列表查询
  876. //是否忽略处理
  877. //客户数量
  878. customSql := ""
  879. clueSql := ""
  880. chanceSql := ""
  881. if positionType == 0 {
  882. customSql = fmt.Sprintf("select COUNT(1) from %s where %s in (%s) and position_id=?", entity.CUSTOM, findKey, employArrStr, positionId)
  883. clueSql = fmt.Sprintf("select COUNT(1) from %s where employ_info_id in (%s) and position_id=?", entity.SALE_CLUE, employArrStr, positionId)
  884. chanceSql = fmt.Sprintf("select COUNT(1) from %s where employ_info_id in (%s) and position_id=?", entity.SALE_CHANCE, employArrStr, positionId)
  885. } else {
  886. customSql = fmt.Sprintf("select COUNT(1) from %s where %s in (%s)", entity.CUSTOM, findKey, employArrStr)
  887. clueSql = fmt.Sprintf("select COUNT(1) from %s where employ_info_id in (%s)", entity.SALE_CLUE, employArrStr)
  888. chanceSql = fmt.Sprintf("select COUNT(1) from %s where employ_info_id in (%s)", entity.SALE_CHANCE, employArrStr)
  889. }
  890. customCount := MC.CrmMysql.CountBySql(customSql)
  891. valueMap["customCount"] = customCount
  892. if inEmployType == 1 || inEmployType == 4 {
  893. //销售线索数量
  894. clueCount := MC.CrmMysql.CountBySql(clueSql)
  895. valueMap["clueCount"] = clueCount
  896. //销售机会数量
  897. chanceCount := MC.CrmMysql.CountBySql(chanceSql)
  898. valueMap["chanceCount"] = chanceCount
  899. }
  900. } else {
  901. valueMap["chanceCount"] = 0
  902. valueMap["clueCount"] = 0
  903. valueMap["customCount"] = 0
  904. }
  905. return valueMap
  906. }