employService.go 35 KB

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