employService.go 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661
  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. "app.yhyue.com/moapp/jypkg/public"
  8. MC "bp.jydev.jianyu360.cn/CRM/application/api/common"
  9. "bp.jydev.jianyu360.cn/CRM/application/api/internal/types"
  10. "bp.jydev.jianyu360.cn/CRM/application/entity"
  11. "database/sql"
  12. "fmt"
  13. "github.com/RoaringBitmap/roaring"
  14. "github.com/gogf/gf/v2/util/gconv"
  15. "go.mongodb.org/mongo-driver/bson"
  16. "log"
  17. "strings"
  18. "time"
  19. )
  20. const (
  21. BuyerIndex = "buyer" // 采购单位index
  22. BuyerType = "buyer"
  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{} {
  32. var data []map[string]interface{}
  33. depIDArr := ""
  34. if in.EntNicheDis > 0 {
  35. //查询所有部门标识
  36. deptArr := MC.MainMysql.SelectBySql("select GROUP_CONCAT(DISTINCT b.id) as depIDArr from entniche_department_parent a"+
  37. " INNER JOIN entniche_department b "+
  38. "on (b.ent_id=? and (b.id=? or (a.pid=? and a.id=b.id)))", in.EntId, in.EntDeptId, in.EntDeptId)
  39. if len(*deptArr) == 0 {
  40. return data
  41. }
  42. depIDArr = common.InterfaceToStr((*deptArr)[0]["depIDArr"])
  43. if depIDArr == "" {
  44. return data
  45. }
  46. }
  47. for _, v := range strings.Split(in.IdArr, ",") {
  48. id := ""
  49. id = idFormat(v, in.EmployType)
  50. table, findKey, employKey, source, projectId, isNiJian := employKeyFormat(in.EmployType, id)
  51. if id == "" {
  52. log.Println(v, in.EmployType, "该信息查询不到数据")
  53. break
  54. }
  55. if in.EntNicheDis > 0 {
  56. data = append(data, employInfoEnt(v, table, id, employKey, findKey, depIDArr, source, in, projectId, isNiJian))
  57. } else {
  58. data = append(data, employInfoPerson(v, table, id, employKey, findKey, source, in, projectId, isNiJian))
  59. }
  60. }
  61. return data
  62. }
  63. // EmployOperate 收录操作
  64. func (e *EmPloyService) EmployOperate(in *types.EmployOperateReq) (bool, string) {
  65. log.Println("收录入参", in)
  66. //收录汇总表
  67. //summaryMap := SummaryFormat(in.PositionId)
  68. msg := ""
  69. return MC.CrmMysql.ExecTx("收录操作", func(tx *sql.Tx) bool {
  70. fool := true
  71. for _, v1 := range strings.Split(in.IdArr, ",") {
  72. //id转中文
  73. id := ""
  74. findMap := map[string]interface{}{}
  75. findMap["position_id"] = in.PositionId
  76. id = idFormat(v1, in.EmployType)
  77. table, _, employKey, source, projectId, isNijian := employKeyFormat(in.EmployType, id)
  78. findMap["source"] = source
  79. if isNijian {
  80. findMap[employKey] = id
  81. } else {
  82. findMap[employKey] = projectId
  83. }
  84. if id == "" {
  85. log.Println(v1, in.EmployType, "该信息查询不到数据")
  86. break
  87. }
  88. if in.IsEmploy {
  89. if MC.CrmMysql.Count(table, findMap) > 0 {
  90. MC.CrmMysql.UpdateByTx(tx, table, findMap, map[string]interface{}{
  91. "status": 1,
  92. })
  93. } else {
  94. //收录新增
  95. data := map[string]interface{}{}
  96. if in.EmployType == 1 || in.EmployType == 4 {
  97. data = infoFind(id, v1)
  98. } else if in.EmployType == 2 {
  99. data = customFind(id, in.EmployType)
  100. data["jybx_url"] = "/swordfish/page_big_pc/svip/ent_ser_portrait/" + v1
  101. data["source"] = source
  102. } else if in.EmployType == 3 {
  103. data = customFind(id, in.EmployType)
  104. data["jybx_url"] = "/swordfish/page_big_pc/unit_portrayal/" + v1
  105. data["source"] = source
  106. }
  107. data["position_id"] = in.PositionId
  108. data["ent_id"] = in.EntId
  109. data["ent_dept_id"] = in.EntDeptId
  110. data["ent_user_id"] = in.EntUserId
  111. ok := MC.CrmMysql.InsertByTx(tx, table, data)
  112. if ok <= 0 {
  113. log.Println(v1, id, in.EmployType, "收录失败")
  114. break
  115. }
  116. }
  117. fool = true
  118. } else {
  119. //取消收录
  120. if MC.CrmMysql.Count(table, findMap) > 0 {
  121. ok := MC.CrmMysql.UpdateByTx(tx, table, findMap, map[string]interface{}{
  122. "status": -1,
  123. })
  124. if !ok {
  125. log.Println(v1, id, in.EmployType, "取消收录失败")
  126. }
  127. } else {
  128. fool = false
  129. if in.EmployType == 1 {
  130. msg = "该资讯已有员工收录,不可取消收录。"
  131. } else {
  132. msg = "该企业已有员工收录,不可取消收录。"
  133. }
  134. }
  135. }
  136. return fool
  137. }
  138. return fool
  139. }), msg
  140. }
  141. // customFind 企业信息查询
  142. func customFind(id string, employType int64) map[string]interface{} {
  143. data := map[string]interface{}{}
  144. //company_id 企业id name户名称 address 地址 industry 行业
  145. if employType == 2 {
  146. //企业详情
  147. entinfo, _ := MC.MgoEnt.FindOneByField("qyxy_std", map[string]interface{}{"_id": id}, map[string]interface{}{
  148. "company_address": 1, //注册地
  149. "company_name": 1,
  150. })
  151. if entinfo != nil && len(*entinfo) > 0 {
  152. data["name"] = (*entinfo)["company_name"]
  153. data["address"] = (*entinfo)["company_address"]
  154. data["company_id"] = id
  155. }
  156. } else {
  157. //采购单位详情
  158. rs := elastic.Get(BuyerIndex, BuyerType, fmt.Sprintf(`{"query":{"bool":{"must":[{"terms":{"_id":["%s"]}}]}},"size":1,"_source":["buyer_name","city"]}`, id))
  159. if rs != nil && len(*rs) > 0 {
  160. data["name"] = (*rs)[0]["buyer_name"]
  161. data["address"] = (*rs)[0]["city"]
  162. data["company_id"] = id
  163. }
  164. }
  165. data["status"] = 1
  166. data["create_time"] = time.Now().Format(date.Date_Full_Layout)
  167. return data
  168. }
  169. // infoFind 标讯信息查询
  170. func infoFind(id string, v1 string) map[string]interface{} {
  171. data := map[string]interface{}{}
  172. //source_id 信息id、项目id- title 标题-area 省 -city 市 -subtype 信息类型二级分类
  173. //buyerclass 采购单位行业 -budget 预算 -bidamount 中标金额 buyer采购单位 annex有无附件 publishtime发布时间 projectname 项目时间
  174. //ownerclass 业主类型(拟在建搜索) expurasing_time 预计采购时间 jybx_url 标讯详情页
  175. //标讯信息
  176. obj := map[string]interface{}{}
  177. aobj, ok := MC.MgoBidding.FindById("bidding", id, public.MgoBiddingFields)
  178. if ok && (aobj == nil || *aobj == nil || len(*aobj) == 0) {
  179. aobj, ok = MC.MgoBidding.FindById("bidding_back", id, public.MgoBiddingFields)
  180. }
  181. toptype := common.InterfaceToStr(obj["toptype"])
  182. subtype := common.InterfaceToStr(obj["subtype"])
  183. pushTime := ""
  184. if ok && obj != nil && len(obj) > 0 {
  185. data["title"] = common.ObjToString(obj["title"])
  186. data["city"] = obj["city"]
  187. data["area"] = obj["area"]
  188. data["subtype"] = obj["subtype"]
  189. data["buyerclass"] = obj["buyerclass"]
  190. data["budget"] = obj["budget"]
  191. data["bidamount"] = obj["bidamount"]
  192. data["annex"] = 0
  193. data["buyer"] = obj["buyer"]
  194. data["winner"] = obj["s_winner"]
  195. data["jybx_url"] = "/article/content/" + v1 + ".html"
  196. //类型处理
  197. pushTime = time.Unix(common.Int64All(obj["publishtime"]), 0).Format(date.Date_Full_Layout)
  198. data["source"] = 1
  199. data["source_id"] = id
  200. if toptype == "采购意向" || toptype == "预告" || toptype == "招标" {
  201. data["type"] = 2
  202. } else {
  203. if subtype == "废标" || subtype == "流标" || subtype == "其它" {
  204. data["type"] = 2
  205. } else if subtype == "成交" || subtype == "中标" || subtype == "合同" || subtype == "验收" || subtype == "违规" {
  206. data["type"] = 3
  207. } else {
  208. data["type"] = 1
  209. }
  210. }
  211. if obj["projectinfo"] != nil {
  212. projectinfo := common.ObjToMap(obj["projectinfo"])
  213. if (*projectinfo)["attachments"] != nil {
  214. data["annex"] = 1
  215. }
  216. }
  217. data["publishtime"] = pushTime
  218. data["show_time"] = pushTime
  219. data["projectname"] = obj["projectname"]
  220. procurementlist, _ := obj["procurementlist"].([]interface{})
  221. for _, vs := range procurementlist { //1.采购意向清单数据集打码处理
  222. vsMap, _ := vs.(map[string]interface{})
  223. if vsMap["expurasingtime"] != nil {
  224. data["expurasing_time"] = vsMap["expurasingtime"]
  225. break
  226. }
  227. }
  228. }
  229. data["status"] = 1
  230. data["employ_way"] = 1
  231. data["create_time"] = time.Now().Format(date.Date_Full_Layout)
  232. if subtype == "拟建" {
  233. data = niJianHandle(id, data, v1, pushTime)
  234. data["type"] = 1
  235. }
  236. return data
  237. }
  238. // GetBuyerIdByName 通过采购单位名称获取id
  239. func getBuyerIdByName(buyerName string) (buyerId string) {
  240. r := elastic.Get(BuyerIndex, BuyerType, fmt.Sprintf(`{"query":{"bool":{"must":[{"term":{"buyer_name":"%s"}}]}},"size":1,"_source":["city","id"]}`, buyerName))
  241. if r == nil || len(*r) == 0 {
  242. return
  243. }
  244. buyerId, _ = (*r)[0]["_id"].(string)
  245. return
  246. }
  247. // IdFormat id解密
  248. func idFormat(encryptionId string, employType int64) string {
  249. decryptId := ""
  250. switch employType {
  251. case 1, 2:
  252. decryptId = util.DecodeId(encryptionId)
  253. case 3:
  254. if len(encryptionId) > 0 && len([]rune(encryptionId)) == len(encryptionId) {
  255. //此数据是id
  256. //获取中文名字
  257. decryptId = util.DecodeId(encryptionId)
  258. } else {
  259. //次数据传的名字
  260. decryptId = getBuyerIdByName(encryptionId)
  261. }
  262. }
  263. return decryptId
  264. }
  265. // employKeyFormat 根据收录类型 字段处理 table,findKey,employKey,source
  266. func employKeyFormat(employType int64, id string) (string, string, string, int64, string, bool) {
  267. table := ""
  268. employKey := "company_id"
  269. findKey := "employ_custom_id"
  270. projectId := ""
  271. source := int64(0)
  272. IsNiJian := false
  273. switch employType {
  274. case 1:
  275. table = entity.EMPLOY_INFO
  276. employKey = "source_id"
  277. findKey = "employ_info_id"
  278. source = 1
  279. obj := map[string]interface{}{}
  280. brobj, ok := MC.Mgo.Find("bidding_rec", bson.M{"s_id": id}, `{"l_recoverydate":-1}`, public.MgoBiddingFields, false, 0, 1)
  281. if ok && (*brobj) != nil && len(*brobj) == 1 && (*brobj)[0] != nil {
  282. obj = (*brobj)[0]
  283. } else {
  284. aobj, ok := MC.MgoBidding.FindById("bidding", id, public.MgoBiddingFields)
  285. if ok && (aobj == nil || *aobj == nil || len(*aobj) == 0) {
  286. aobj, ok = MC.MgoBidding.FindById("bidding_back", id, public.MgoBiddingFields)
  287. }
  288. obj = *aobj
  289. }
  290. if ok && obj != nil && len(obj) > 0 {
  291. subtype := common.InterfaceToStr(obj["subtype"])
  292. if subtype == "拟建" {
  293. project, _ := MC.MgoProject.FindOne("projectset_proposed", map[string]interface{}{
  294. "ids": id,
  295. })
  296. source = 2
  297. if project != nil && len(*project) > 0 {
  298. projectId = common.InterfaceToStr((*project)["_id"])
  299. IsNiJian = true
  300. }
  301. }
  302. }
  303. case 2:
  304. table = entity.EMPLOY_CUSTOM
  305. source = 1
  306. case 3:
  307. table = entity.EMPLOY_CUSTOM
  308. source = 2
  309. case 4:
  310. table = entity.EMPLOY_INFO
  311. source = 2
  312. employKey = "source_id"
  313. findKey = "employ_info_id"
  314. }
  315. return table, findKey, employKey, source, projectId, IsNiJian
  316. }
  317. // IgnoreOperate 忽略操作
  318. func (e *EmPloyService) IgnoreOperate(in *types.IgnoreOperateReq) (bool, string) {
  319. //
  320. table := ""
  321. switch in.EmployType {
  322. case 1, 4:
  323. table = entity.EMPLOY_INFO
  324. case 2, 3:
  325. table = entity.EMPLOY_CUSTOM
  326. }
  327. msg := ""
  328. fool := true
  329. for _, v := range strings.Split(in.IdArr, ",") {
  330. id := idFormat(v, in.EmployType)
  331. if id == "" {
  332. log.Println(v, id, in.EmployType, "忽略处理,id解析失败")
  333. break
  334. }
  335. findMap := map[string]interface{}{
  336. "position_id": in.PositionId,
  337. }
  338. if in.EmployType == 3 || in.EmployType == 2 {
  339. findMap["company_id"] = id
  340. } else {
  341. findMap["source_id"] = id
  342. }
  343. if MC.CrmMysql.Count(table, findMap) == 0 {
  344. log.Println(v, id, in.EmployType, "忽略处理,id所对应数据不存在")
  345. fool = false
  346. if in.EmployType == 1 {
  347. if in.IsIgnore {
  348. msg = "该资讯已有员工收录,不可忽略。"
  349. } else {
  350. msg = "该资讯已有员工收录,不可取消忽略。"
  351. }
  352. } else {
  353. if in.IsIgnore {
  354. msg = "该企业已有员工收录,不可忽略。"
  355. } else {
  356. msg = "该企业已有员工收录,不可取消忽略。"
  357. }
  358. }
  359. break
  360. }
  361. if in.IsIgnore {
  362. MC.CrmMysql.Update(table, findMap, map[string]interface{}{
  363. "is_ignore": 1,
  364. "is_handle": 1,
  365. })
  366. } else {
  367. MC.CrmMysql.Update(table, findMap, map[string]interface{}{
  368. "is_ignore": 0,
  369. "is_handle": 1,
  370. })
  371. }
  372. }
  373. return fool, msg
  374. }
  375. // DistributePerson 分发操作
  376. func (e *EmPloyService) DistributePerson(in *types.EmployDistributeReq) bool {
  377. return MC.CrmMysql.ExecTx("收录操作", func(tx *sql.Tx) bool {
  378. personMap := map[int64]PersonSmmary{}
  379. //人员信息处理
  380. for _, person := range in.Person {
  381. personMap[person.PositionId] = PersonSmmary{
  382. EntUserId: person.EntUserId,
  383. EntDeptId: person.EntDeptId,
  384. }
  385. }
  386. //分发数据处理
  387. infoMap := map[string]map[string]interface{}{}
  388. onlyMap := map[string]interface{}{}
  389. //标讯数据处理
  390. for _, v := range strings.Split(in.EmployIdArr, ",") {
  391. if onlyMap[v] == nil {
  392. //查询信息
  393. infoDataList := MC.CrmMysql.SelectBySqlByTx(tx, "SELECT * FROM employ_info WHERE id=?", v)
  394. if infoDataList != nil && len(*infoDataList) > 0 {
  395. source_id := common.InterfaceToStr((*infoDataList)[0]["source_id"])
  396. if onlyMap[source_id] == nil {
  397. (*infoDataList)[0]["dis_id"] = v
  398. (*infoDataList)[0]["is_handle"] = 0
  399. (*infoDataList)[0]["is_ignore"] = 0
  400. (*infoDataList)[0]["is_dis"] = 0
  401. (*infoDataList)[0]["is_create_clue"] = 0
  402. (*infoDataList)[0]["is_create_chance"] = 0
  403. (*infoDataList)[0]["is_create_custom"] = 0
  404. (*infoDataList)[0]["create_time"] = time.Now().Format(date.Date_Full_Layout)
  405. delete((*infoDataList)[0], "id")
  406. if common.IntAll((*infoDataList)[0]["is_dis"]) != 1 {
  407. MC.CrmMysql.UpdateByTx(tx, entity.EMPLOY_INFO, map[string]interface{}{
  408. "id": v,
  409. }, map[string]interface{}{
  410. "is_dis": 1,
  411. "is_handle": 1,
  412. })
  413. }
  414. infoMap[source_id] = (*infoDataList)[0]
  415. onlyMap[source_id] = v
  416. } else {
  417. log.Println(v, "查询不到改收录信息")
  418. continue
  419. }
  420. }
  421. }
  422. }
  423. //普通人员分发
  424. for positionId, personSmmary := range personMap {
  425. //查询时候收录过
  426. for _, v := range infoMap {
  427. //查询时候收录过
  428. findMap := map[string]interface{}{
  429. "position_id": positionId,
  430. "source_id": v["source_id"],
  431. "source": v["source"],
  432. }
  433. if MC.CrmMysql.Count(entity.EMPLOY_INFO, findMap) == 0 {
  434. //新增
  435. v["ent_user_id"] = personSmmary.EntUserId
  436. v["ent_dept_id"] = personSmmary.EntDeptId
  437. v["position_id"] = positionId
  438. MC.CrmMysql.InsertByTx(tx, entity.EMPLOY_INFO, v)
  439. }
  440. }
  441. }
  442. if in.EntNicheDis > 0 {
  443. //查询分配员有没有该数据
  444. for _, v := range infoMap {
  445. //查询时候收录过
  446. findMap := map[string]interface{}{
  447. "position_id": in.PositionId,
  448. "source_id": v["source_id"],
  449. "source": v["source"],
  450. }
  451. employPositionId := v["position_id"]
  452. if employPositionId != in.PositionId {
  453. //分发消息不属于自己
  454. if MC.CrmMysql.Count(entity.EMPLOY_INFO, findMap) == 0 {
  455. v["ent_user_id"] = in.EntUserId
  456. v["position_id"] = in.PositionId
  457. v["is_handle"] = 1
  458. v["ent_dept_id"] = in.EntDeptId
  459. MC.CrmMysql.InsertByTx(tx, entity.EMPLOY_INFO, v)
  460. } else {
  461. MC.CrmMysql.UpdateByTx(tx, entity.EMPLOY_INFO, findMap, map[string]interface{}{
  462. "is_handle": 1,
  463. })
  464. }
  465. }
  466. }
  467. }
  468. return true
  469. })
  470. }
  471. func niJianHandle(infoId string, data map[string]interface{}, v1, pushTime string) map[string]interface{} {
  472. project, _ := MC.MgoProject.FindOne("projectset_proposed", map[string]interface{}{
  473. "ids": infoId,
  474. })
  475. if project != nil && len(*project) > 0 {
  476. city := common.InterfaceToStr((*project)["city"])
  477. area := common.InterfaceToStr((*project)["area"])
  478. category_code := common.InterfaceToStr((*project)["category_code"])
  479. lasttime := common.Int64All((*project)["lasttime"])
  480. ownerclass_code := common.InterfaceToStr((*project)["ownerclass_code"])
  481. total_investment := common.InterfaceToStr((*project)["total_investment"])
  482. project_stage_code := common.InterfaceToStr((*project)["project_stage_code"])
  483. infoList := gconv.SliceMap((*project)["list"])
  484. title := ""
  485. projectname := ""
  486. if len(infoList) > 0 {
  487. title = common.InterfaceToStr(infoList[0]["title"])
  488. projectname = common.InterfaceToStr(infoList[0]["projectname"])
  489. }
  490. category := ""
  491. ownerclass := ""
  492. project_stage := ""
  493. if category_code != "" {
  494. categoryData := MC.NiJian.FindOne("d_nzj_category_code", map[string]interface{}{
  495. "code": category_code,
  496. }, "name", "")
  497. category = common.InterfaceToStr((*categoryData)["name"])
  498. }
  499. if ownerclass_code != "" {
  500. ownerclassData := MC.NiJian.FindOne("d_nzj_ownerclass_code", map[string]interface{}{
  501. "code": ownerclass_code,
  502. }, "name", "")
  503. ownerclass = common.InterfaceToStr((*ownerclassData)["name"])
  504. }
  505. if project_stage_code != "" {
  506. projectStageData := MC.NiJian.FindOne("d_nzj_project_stage_code", map[string]interface{}{
  507. "code": project_stage_code,
  508. }, "name", "")
  509. project_stage = common.InterfaceToStr((*projectStageData)["name"])
  510. }
  511. data["title"] = title
  512. data["city"] = city
  513. data["area"] = area
  514. data["projectname"] = projectname
  515. data["ownerclass"] = ownerclass
  516. data["project_stage"] = project_stage
  517. data["project_category"] = category
  518. data["project_investment"] = total_investment
  519. lastTimeStr := common.If(lasttime == 0, pushTime, time.Unix(lasttime, 0).Format(date.Date_Full_Layout))
  520. data["project_evolve"] = lastTimeStr
  521. data["show_time"] = lastTimeStr
  522. data["publishtime"] = lastTimeStr
  523. pid := common.InterfaceToStr((*project)["_id"])
  524. data["jybx_url"] = "/succbi/nzj/app/nzj.app/nzj_detail_0.spg?pid=" + pid
  525. data["source"] = 2
  526. data["source_id"] = pid
  527. } else {
  528. data["source"] = 1
  529. data["source_id"] = infoId
  530. data["jybx_url"] = "/article/content/" + v1 + ".html"
  531. }
  532. return data
  533. }
  534. // 个人收录情况查询
  535. func employInfoPerson(v, table, id, employKey, findKey string, source int64, in *types.InfoEmployinfoReq, projectId string, isNiJian bool) map[string]interface{} {
  536. valueMap := map[string]interface{}{
  537. "id": v,
  538. }
  539. sourceId := ""
  540. if isNiJian {
  541. sourceId = id
  542. } else {
  543. sourceId = projectId
  544. }
  545. employData := MC.CrmMysql.FindOne(table, map[string]interface{}{
  546. employKey: sourceId,
  547. "position_id": in.PositionId,
  548. "source": source,
  549. }, "is_ignore,status,id", "")
  550. employId := int64(0)
  551. if employData != nil && len(*employData) > 0 {
  552. valueMap["isIgnore"] = common.If(common.Int64All((*employData)["is_ignore"]) == 1, true, false)
  553. valueMap["isEmploy"] = common.If(common.Int64All((*employData)["status"]) == 1, true, false)
  554. employId = common.Int64All((*employData)["id"])
  555. valueMap["employId"] = employId
  556. } else {
  557. valueMap["isIgnore"] = false
  558. valueMap["isEmploy"] = false
  559. }
  560. if len(strings.Split(in.IdArr, ",")) == 1 && employId > 0 {
  561. //列表查询
  562. //是否忽略处理
  563. //客户数量
  564. customCount := MC.CrmMysql.Count(entity.CUSTOM, map[string]interface{}{
  565. findKey: employId,
  566. "position_id": in.PositionId,
  567. })
  568. valueMap["customCount"] = customCount
  569. if in.EmployType == 1 || in.EmployType == 4 {
  570. //销售线索数量
  571. clueCount := MC.CrmMysql.Count(entity.SALE_CLUE, map[string]interface{}{
  572. "employ_info_id": employId,
  573. "position_id": in.PositionId,
  574. })
  575. valueMap["clueCount"] = clueCount
  576. //销售机会数量
  577. chanceCount := MC.CrmMysql.Count(entity.SALE_CHANCE, map[string]interface{}{
  578. "employ_info_id": id,
  579. "position_id": in.PositionId,
  580. })
  581. valueMap["chanceCount"] = chanceCount
  582. }
  583. } else {
  584. valueMap["chanceCount"] = 0
  585. valueMap["clueCount"] = 0
  586. valueMap["isIgnore"] = false
  587. valueMap["customCount"] = 0
  588. }
  589. return valueMap
  590. }
  591. // 企业收录情况查询
  592. func employInfoEnt(v, table, id, employKey, findKey, depIDArr string, source int64, in *types.InfoEmployinfoReq, projectId string, isNiJian bool) map[string]interface{} {
  593. valueMap := map[string]interface{}{
  594. "id": v,
  595. "isIgnore": false,
  596. "isEmploy": false,
  597. "customCount": 0,
  598. "clueCount": 0,
  599. "chanceCount": 0,
  600. }
  601. sourceId := ""
  602. if isNiJian {
  603. sourceId = projectId
  604. } else {
  605. sourceId = id
  606. }
  607. employData := MC.CrmMysql.SelectBySql(fmt.Sprintf("select GROUP_CONCAT(id) as employIdArr,MAX(is_ignore) as is_ignore,MAX(status) as status from %s where %s=? and source=? and ent_dept_id in (%s) and status=1", table, employKey, depIDArr), sourceId, source)
  608. employArrStr := ""
  609. if employData != nil && len(*employData) > 0 {
  610. valueMap["isIgnore"] = common.If(common.Int64All((*employData)[0]["is_ignore"]) == 1, true, false)
  611. valueMap["isEmploy"] = common.If(common.Int64All((*employData)[0]["status"]) == 1, true, false)
  612. employArrStr = common.InterfaceToStr((*employData)[0]["employIdArr"])
  613. valueMap["employId"] = strings.Split(employArrStr, ",")[0]
  614. } else {
  615. valueMap["isIgnore"] = false
  616. valueMap["isIgnore"] = false
  617. }
  618. if len(strings.Split(in.IdArr, ",")) == 1 && employArrStr != "" {
  619. //列表查询
  620. //是否忽略处理
  621. //客户数量
  622. customSql := fmt.Sprintf("select COUNT(1) from %s where %s in (%s)", entity.CUSTOM, findKey, employArrStr)
  623. customCount := MC.CrmMysql.CountBySql(customSql)
  624. valueMap["customCount"] = customCount
  625. if in.EmployType == 1 || in.EmployType == 4 {
  626. //销售线索数量
  627. clueSql := fmt.Sprintf("select COUNT(1) from %s where employ_info_id in (%s)", entity.SALE_CLUE, employArrStr)
  628. clueCount := MC.CrmMysql.CountBySql(clueSql)
  629. valueMap["clueCount"] = clueCount
  630. //销售机会数量
  631. chanceSql := fmt.Sprintf("select COUNT(1) from %s where employ_info_id in (%s)", entity.SALE_CHANCE, employArrStr)
  632. chanceCount := MC.CrmMysql.CountBySql(chanceSql)
  633. valueMap["chanceCount"] = chanceCount
  634. }
  635. } else {
  636. valueMap["chanceCount"] = 0
  637. valueMap["clueCount"] = 0
  638. valueMap["customCount"] = 0
  639. }
  640. return valueMap
  641. }