employService.go 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002
  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.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. orderKey := "type"
  654. if employKey == "company_id" {
  655. orderKey = "source"
  656. }
  657. if len(infoId1Arr) > 0 {
  658. 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)
  659. }
  660. if len(infoId2Arr) > 0 {
  661. 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)
  662. }
  663. if len(niJianIdArr) > 0 {
  664. 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)
  665. }
  666. if len(wuye1Arr) > 0 {
  667. 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)
  668. }
  669. if len(wuye2Arr) > 0 {
  670. 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)
  671. }
  672. for _, v := range *infoData1 {
  673. valueMap := map[string]interface{}{
  674. "id": v,
  675. "isIgnore": false,
  676. "isEmploy": false,
  677. "customCount": 0,
  678. "clueCount": 0,
  679. "chanceCount": 0,
  680. "type": 1,
  681. }
  682. sourceId := gconv.String(v[employKey])
  683. if _, ok := data[sourceId]; ok {
  684. data[sourceId] = EmployHandle(data[sourceId], v, 0, in.From, len(strings.Split(in.IdArr, ",")) == 1, findKey, in.PositionId, in.PositionType, in.EmployType)
  685. } else {
  686. data[sourceId] = EmployHandle(valueMap, v, 0, in.From, len(strings.Split(in.IdArr, ",")) == 1, findKey, in.PositionId, in.PositionType, in.EmployType)
  687. }
  688. }
  689. for _, v := range *infoData2 {
  690. valueMap := map[string]interface{}{
  691. "id": v,
  692. "isIgnore": false,
  693. "isEmploy": false,
  694. "customCount": 0,
  695. "clueCount": 0,
  696. "chanceCount": 0,
  697. "type": 1,
  698. }
  699. sourceId := gconv.String(v[employKey])
  700. if _, ok := data[sourceId]; ok {
  701. data[sourceId] = EmployHandle(data[sourceId], v, 0, in.From, len(strings.Split(in.IdArr, ",")) == 1, findKey, in.PositionId, in.PositionType, in.EmployType)
  702. } else {
  703. data[sourceId] = EmployHandle(valueMap, v, 0, in.From, len(strings.Split(in.IdArr, ",")) == 1, findKey, in.PositionId, in.PositionType, in.EmployType)
  704. }
  705. }
  706. for _, v := range *niJianData {
  707. valueMap := map[string]interface{}{
  708. "id": v,
  709. "isIgnore": false,
  710. "isEmploy": false,
  711. "customCount": 0,
  712. "clueCount": 0,
  713. "chanceCount": 0,
  714. "type": 1,
  715. }
  716. sourceId := gconv.String(v[employKey])
  717. if _, ok := data[sourceId]; ok {
  718. data[sourceId] = EmployHandle(data[sourceId], v, 0, in.From, len(strings.Split(in.IdArr, ",")) == 1, findKey, in.PositionId, in.PositionType, in.EmployType)
  719. } else {
  720. data[sourceId] = EmployHandle(valueMap, v, 0, in.From, len(strings.Split(in.IdArr, ",")) == 1, findKey, in.PositionId, in.PositionType, in.EmployType)
  721. }
  722. }
  723. for _, v := range *wuyeData1 {
  724. valueMap := map[string]interface{}{
  725. "id": v,
  726. "isIgnore": false,
  727. "isEmploy": false,
  728. "customCount": 0,
  729. "clueCount": 0,
  730. "chanceCount": 0,
  731. "type": 1,
  732. }
  733. sourceId := gconv.String(v[employKey])
  734. if _, ok := data[sourceId]; ok {
  735. data[sourceId] = EmployHandle(data[sourceId], v, 1, in.From, len(strings.Split(in.IdArr, ",")) == 1, findKey, in.PositionId, in.PositionType, in.EmployType)
  736. } else {
  737. data[sourceId] = EmployHandle(valueMap, v, 1, in.From, len(strings.Split(in.IdArr, ",")) == 1, findKey, in.PositionId, in.PositionType, in.EmployType)
  738. }
  739. }
  740. for _, v := range *wuyeData2 {
  741. valueMap := map[string]interface{}{
  742. "id": v,
  743. "isIgnore": false,
  744. "isEmploy": false,
  745. "customCount": 0,
  746. "clueCount": 0,
  747. "chanceCount": 0,
  748. "type": 1,
  749. }
  750. sourceId := gconv.String(v[employKey])
  751. if _, ok := data[sourceId]; ok {
  752. data[sourceId] = EmployHandle(data[sourceId], v, 1, in.From, len(strings.Split(in.IdArr, ",")) == 1, findKey, in.PositionId, in.PositionType, in.EmployType)
  753. } else {
  754. data[sourceId] = EmployHandle(valueMap, v, 1, in.From, len(strings.Split(in.IdArr, ",")) == 1, findKey, in.PositionId, in.PositionType, in.EmployType)
  755. }
  756. }
  757. return data
  758. }
  759. // 企业收录情况查询
  760. func employInfoEnt(table, employKey, findKey, depIDArr string, in *types.InfoEmployinfoReq, version int, infoId1Arr, infoId2Arr, niJianIdArr, wuye1Arr, wuye2Arr []string) map[string]map[string]interface{} {
  761. data := map[string]map[string]interface{}{}
  762. infoData1 := &[]map[string]interface{}{}
  763. infoData2 := &[]map[string]interface{}{}
  764. niJianData := &[]map[string]interface{}{}
  765. wuyeData1 := &[]map[string]interface{}{}
  766. wuyeData2 := &[]map[string]interface{}{}
  767. orderKey := "type"
  768. if employKey == "company_id" {
  769. orderKey = "source"
  770. }
  771. if len(infoId1Arr) > 0 {
  772. 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 ,%s order by %s", employKey, table, employKey, strings.Join(infoId1Arr, "','"), depIDArr, employKey, orderKey, orderKey), 1)
  773. }
  774. if len(infoId2Arr) > 0 {
  775. 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 ,%s order by %s", employKey, table, employKey, strings.Join(infoId2Arr, "','"), depIDArr, employKey, orderKey, orderKey), 2)
  776. }
  777. if len(niJianIdArr) > 0 {
  778. 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 ,%s order by %s", employKey, table, employKey, strings.Join(niJianIdArr, "','"), depIDArr, employKey, orderKey, orderKey), 2)
  779. }
  780. if len(wuye1Arr) > 0 {
  781. 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)
  782. }
  783. if len(wuye2Arr) > 0 {
  784. 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)
  785. }
  786. for _, v := range *infoData1 {
  787. valueMap := map[string]interface{}{
  788. "id": v,
  789. "isIgnore": false,
  790. "isEmploy": false,
  791. "customCount": 0,
  792. "clueCount": 0,
  793. "chanceCount": 0,
  794. "type": 1,
  795. }
  796. sourceId := gconv.String(v[employKey])
  797. if _, ok := data[sourceId]; ok {
  798. data[sourceId] = EmployHandle(data[sourceId], v, 0, in.From, len(strings.Split(in.IdArr, ",")) == 1, findKey, in.PositionId, in.PositionType, in.EmployType)
  799. } else {
  800. data[sourceId] = EmployHandle(valueMap, v, 0, in.From, len(strings.Split(in.IdArr, ",")) == 1, findKey, in.PositionId, in.PositionType, in.EmployType)
  801. }
  802. }
  803. for _, v := range *infoData2 {
  804. valueMap := map[string]interface{}{
  805. "id": v,
  806. "isIgnore": false,
  807. "isEmploy": false,
  808. "customCount": 0,
  809. "clueCount": 0,
  810. "chanceCount": 0,
  811. "type": 1,
  812. }
  813. sourceId := gconv.String(v[employKey])
  814. if _, ok := data[sourceId]; ok {
  815. data[sourceId] = EmployHandle(data[sourceId], v, 0, in.From, len(strings.Split(in.IdArr, ",")) == 1, findKey, in.PositionId, in.PositionType, in.EmployType)
  816. } else {
  817. data[sourceId] = EmployHandle(valueMap, v, 0, in.From, len(strings.Split(in.IdArr, ",")) == 1, findKey, in.PositionId, in.PositionType, in.EmployType)
  818. }
  819. }
  820. for _, v := range *niJianData {
  821. valueMap := map[string]interface{}{
  822. "id": v,
  823. "isIgnore": false,
  824. "isEmploy": false,
  825. "customCount": 0,
  826. "clueCount": 0,
  827. "chanceCount": 0,
  828. "type": 1,
  829. }
  830. sourceId := gconv.String(v[employKey])
  831. if _, ok := data[sourceId]; ok {
  832. data[sourceId] = EmployHandle(data[sourceId], v, version, in.From, len(strings.Split(in.IdArr, ",")) == 1, findKey, in.PositionId, in.PositionType, in.EmployType)
  833. } else {
  834. data[sourceId] = EmployHandle(valueMap, v, version, in.From, len(strings.Split(in.IdArr, ",")) == 1, findKey, in.PositionId, in.PositionType, in.EmployType)
  835. }
  836. }
  837. for _, v := range *wuyeData1 {
  838. valueMap := map[string]interface{}{
  839. "id": v,
  840. "isIgnore": false,
  841. "isEmploy": false,
  842. "customCount": 0,
  843. "clueCount": 0,
  844. "chanceCount": 0,
  845. "type": 1,
  846. }
  847. sourceId := gconv.String(v[employKey])
  848. if _, ok := data[sourceId]; ok {
  849. data[sourceId] = EmployHandle(data[sourceId], v, 1, in.From, len(strings.Split(in.IdArr, ",")) == 1, findKey, in.PositionId, in.PositionType, in.EmployType)
  850. } else {
  851. data[sourceId] = EmployHandle(valueMap, v, 1, in.From, len(strings.Split(in.IdArr, ",")) == 1, findKey, in.PositionId, in.PositionType, in.EmployType)
  852. }
  853. }
  854. for _, v := range *wuyeData2 {
  855. valueMap := map[string]interface{}{
  856. "id": v,
  857. "isIgnore": false,
  858. "isEmploy": false,
  859. "customCount": 0,
  860. "clueCount": 0,
  861. "chanceCount": 0,
  862. "type": 1,
  863. }
  864. sourceId := gconv.String(v[employKey])
  865. if _, ok := data[sourceId]; ok {
  866. data[sourceId] = EmployHandle(data[sourceId], v, 1, in.From, len(strings.Split(in.IdArr, ",")) == 1, findKey, in.PositionId, in.PositionType, in.EmployType)
  867. } else {
  868. data[sourceId] = EmployHandle(valueMap, v, 1, in.From, len(strings.Split(in.IdArr, ",")) == 1, findKey, in.PositionId, in.PositionType, in.EmployType)
  869. }
  870. }
  871. return data
  872. }
  873. 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{} {
  874. employType := common.Int64All(employData["type"])
  875. employStatus := common.Int64All(employData["status"])
  876. employ2 := false
  877. employ3 := false
  878. employIgnore := false
  879. employId := int64(0)
  880. is_ignore := int64(0)
  881. employArrStr := ""
  882. //收录标识处理
  883. if common.Int64All(employData["id"]) == 0 {
  884. if len(gconv.String(employData["employIdArr"])) > 0 {
  885. employArrStr = gconv.String(employData["employIdArr"])
  886. employId = gconv.Int64(strings.Split(employArrStr, ",")[0])
  887. }
  888. } else {
  889. employId = common.Int64All(employData["id"])
  890. }
  891. if version == 1 {
  892. is_ignore = common.Int64All(employData["is_ignore"])
  893. switch employType {
  894. case 2:
  895. if valueMap["employ3"] != nil {
  896. employ3 = gconv.Bool(valueMap["employ3"])
  897. }
  898. if employStatus == 1 {
  899. employ2 = true
  900. }
  901. valueMap["intelligenceId"] = employId
  902. case 3:
  903. if valueMap["employ2"] != nil {
  904. employ2 = gconv.Bool(valueMap["employ2"])
  905. }
  906. if employStatus == 1 {
  907. employ3 = true
  908. }
  909. }
  910. if is_ignore > 0 {
  911. employIgnore = true
  912. }
  913. employType = common.Int64All(employData["type"])
  914. valueMap["isIgnore"] = employIgnore
  915. if originate == "jhfp" {
  916. valueMap["isEmploy"] = employ3
  917. } else {
  918. valueMap["isEmploy"] = common.If(employ2 && employ3, true, false)
  919. }
  920. valueMap["type"] = employType
  921. valueMap["employ2"] = employ2
  922. valueMap["employ3"] = employ3
  923. valueMap["employId"] = employId
  924. } else {
  925. valueMap["isIgnore"] = common.If(common.Int64All(employData["is_ignore"]) == 1, true, false)
  926. valueMap["isEmploy"] = common.If(common.Int64All(employData["status"]) == 1, true, false)
  927. valueMap["type"] = common.Int64All(employData["type"])
  928. valueMap["employId"] = employId
  929. }
  930. if single && employArrStr != "" {
  931. //列表查询
  932. //是否忽略处理
  933. //客户数量
  934. customSql := ""
  935. clueSql := ""
  936. chanceSql := ""
  937. if positionType == 0 {
  938. customSql = fmt.Sprintf("select COUNT(1) from %s where %s in (%s) and position_id=%d", entity.CUSTOM, findKey, employArrStr, positionId)
  939. clueSql = fmt.Sprintf("select COUNT(1) from %s where employ_info_id in (%s) and position_id=%d", entity.SALE_CLUE, employArrStr, positionId)
  940. chanceSql = fmt.Sprintf("select COUNT(1) from %s where employ_info_id in (%s) and position_id=%d", entity.SALE_CHANCE, employArrStr, positionId)
  941. } else {
  942. customSql = fmt.Sprintf("select COUNT(1) from %s where %s in (%s)", entity.CUSTOM, findKey, employArrStr)
  943. clueSql = fmt.Sprintf("select COUNT(1) from %s where employ_info_id in (%s)", entity.SALE_CLUE, employArrStr)
  944. chanceSql = fmt.Sprintf("select COUNT(1) from %s where employ_info_id in (%s)", entity.SALE_CHANCE, employArrStr)
  945. }
  946. customCount := MC.CrmMysql.CountBySql(customSql)
  947. valueMap["customCount"] = customCount
  948. if inEmployType == 1 || inEmployType == 4 {
  949. //销售线索数量
  950. clueCount := MC.CrmMysql.CountBySql(clueSql)
  951. valueMap["clueCount"] = clueCount
  952. //销售机会数量
  953. chanceCount := MC.CrmMysql.CountBySql(chanceSql)
  954. valueMap["chanceCount"] = chanceCount
  955. }
  956. } else {
  957. valueMap["chanceCount"] = 0
  958. valueMap["clueCount"] = 0
  959. valueMap["customCount"] = 0
  960. }
  961. return valueMap
  962. }