employService.go 31 KB

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