employService.go 20 KB

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