employService.go 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628
  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. if in.EmployType == 1 || in.EmployType == 4 {
  90. data = infoFind(id, v1)
  91. } else if in.EmployType == 2 {
  92. data = customFind(id, in.EmployType)
  93. data["jybx_url"] = "/swordfish/page_big_pc/svip/ent_ser_portrait/" + v1
  94. } else if in.EmployType == 3 {
  95. data = customFind(id, in.EmployType)
  96. data["jybx_url"] = "/swordfish/page_big_pc/unit_portrayal/" + v1
  97. }
  98. data["source"] = source
  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. pushTime := time.Unix(common.Int64All(obj["publishtime"]), 0).Format(date.Date_Full_Layout)
  194. if subtype == "拟建" {
  195. data = niJianHandle(id, data, v1, pushTime)
  196. data["type"] = 1
  197. } else {
  198. if toptype == "采购意向" || toptype == "预告" || toptype == "招标" {
  199. data["type"] = 2
  200. } else {
  201. if subtype == "废标" || subtype == "流标" || subtype == "其它" {
  202. data["type"] = 2
  203. } else if subtype == "成交" || subtype == "中标" || subtype == "合同" || subtype == "验收" || subtype == "违规" {
  204. data["type"] = 3
  205. } else {
  206. data["type"] = 1
  207. }
  208. }
  209. }
  210. if obj["projectinfo"] != nil {
  211. projectinfo := common.ObjToMap(obj["projectinfo"])
  212. if (*projectinfo)["attachments"] != nil {
  213. data["annex"] = 1
  214. }
  215. }
  216. data["publishtime"] = pushTime
  217. data["show_time"] = pushTime
  218. data["projectname"] = obj["projectname"]
  219. procurementlist, _ := obj["procurementlist"].([]interface{})
  220. for _, vs := range procurementlist { //1.采购意向清单数据集打码处理
  221. vsMap, _ := vs.(map[string]interface{})
  222. if vsMap["expurasingtime"] != nil {
  223. data["expurasing_time"] = vsMap["expurasingtime"]
  224. break
  225. }
  226. }
  227. }
  228. data["status"] = 1
  229. data["employ_way"] = 1
  230. data["source_id"] = id
  231. data["create_time"] = time.Now().Format(date.Date_Full_Layout)
  232. return data
  233. }
  234. // GetBuyerIdByName 通过采购单位名称获取id
  235. func getBuyerIdByName(buyerName string) (buyerId string) {
  236. r := elastic.Get(BuyerIndex, BuyerType, fmt.Sprintf(`{"query":{"bool":{"must":[{"term":{"buyer_name":"%s"}}]}},"size":1,"_source":["city","id"]}`, buyerName))
  237. if r == nil || len(*r) == 0 {
  238. return
  239. }
  240. buyerId, _ = (*r)[0]["_id"].(string)
  241. return
  242. }
  243. // IdFormat id解密
  244. func idFormat(encryptionId string, employType int64) string {
  245. decryptId := ""
  246. switch employType {
  247. case 1, 2:
  248. decryptId = util.DecodeId(encryptionId)
  249. case 3:
  250. if len(encryptionId) > 0 && len([]rune(encryptionId)) == len(encryptionId) {
  251. //此数据是id
  252. //获取中文名字
  253. decryptId = util.DecodeId(encryptionId)
  254. } else {
  255. //次数据传的名字
  256. decryptId = getBuyerIdByName(encryptionId)
  257. }
  258. }
  259. return decryptId
  260. }
  261. // employKeyFormat 根据收录类型 字段处理 table,findKey,employKey,source
  262. func employKeyFormat(employType int64, id string) (string, string, string, int64) {
  263. table := ""
  264. employKey := "company_id"
  265. findKey := "employ_custom_id"
  266. source := int64(0)
  267. switch employType {
  268. case 1:
  269. table = entity.EMPLOY_INFO
  270. employKey = "source_id"
  271. findKey = "employ_info_id"
  272. source = 1
  273. obj := map[string]interface{}{}
  274. brobj, ok := MC.Mgo.Find("bidding_rec", bson.M{"s_id": id}, `{"l_recoverydate":-1}`, public.MgoBiddingFields, false, 0, 1)
  275. if ok && (*brobj) != nil && len(*brobj) == 1 && (*brobj)[0] != nil {
  276. obj = (*brobj)[0]
  277. } else {
  278. aobj, ok := MC.MgoBidding.FindById("bidding", id, public.MgoBiddingFields)
  279. if ok && (aobj == nil || *aobj == nil || len(*aobj) == 0) {
  280. aobj, ok = MC.MgoBidding.FindById("bidding_back", id, public.MgoBiddingFields)
  281. }
  282. obj = *aobj
  283. }
  284. if ok && obj != nil && len(obj) > 0 {
  285. subtype := common.InterfaceToStr(obj["subtype"])
  286. if subtype == "拟建" {
  287. source = 2
  288. }
  289. }
  290. case 2:
  291. table = entity.EMPLOY_CUSTOM
  292. source = 1
  293. case 3:
  294. table = entity.EMPLOY_CUSTOM
  295. source = 2
  296. case 4:
  297. table = entity.EMPLOY_INFO
  298. source = 2
  299. employKey = "source_id"
  300. findKey = "employ_info_id"
  301. }
  302. return table, findKey, employKey, source
  303. }
  304. // IgnoreOperate 忽略操作
  305. func (e *EmPloyService) IgnoreOperate(in *types.IgnoreOperateReq) (bool, string) {
  306. //
  307. table := ""
  308. switch in.EmployType {
  309. case 1, 4:
  310. table = entity.EMPLOY_INFO
  311. case 2, 3:
  312. table = entity.EMPLOY_CUSTOM
  313. }
  314. msg := ""
  315. fool := true
  316. for _, v := range strings.Split(in.IdArr, ",") {
  317. id := idFormat(v, in.EmployType)
  318. if id == "" {
  319. log.Println(v, id, in.EmployType, "忽略处理,id解析失败")
  320. break
  321. }
  322. findMap := map[string]interface{}{
  323. "position_id": in.PositionId,
  324. }
  325. if in.EmployType == 3 || in.EmployType == 2 {
  326. findMap["company_id"] = id
  327. } else {
  328. findMap["source_id"] = id
  329. }
  330. if MC.CrmMysql.Count(table, findMap) == 0 {
  331. log.Println(v, id, in.EmployType, "忽略处理,id所对应数据不存在")
  332. fool = false
  333. if in.EmployType == 1 {
  334. if in.IsIgnore {
  335. msg = "该资讯已有员工收录,不可忽略。"
  336. } else {
  337. msg = "该资讯已有员工收录,不可取消忽略。"
  338. }
  339. } else {
  340. if in.IsIgnore {
  341. msg = "该企业已有员工收录,不可忽略。"
  342. } else {
  343. msg = "该企业已有员工收录,不可取消忽略。"
  344. }
  345. }
  346. break
  347. }
  348. if in.IsIgnore {
  349. MC.CrmMysql.Update(table, findMap, map[string]interface{}{
  350. "is_ignore": 1,
  351. "is_handle": 1,
  352. })
  353. } else {
  354. MC.CrmMysql.Update(table, findMap, map[string]interface{}{
  355. "is_ignore": 0,
  356. "is_handle": 1,
  357. })
  358. }
  359. }
  360. return fool, msg
  361. }
  362. // DistributePerson 分发操作
  363. func (e *EmPloyService) DistributePerson(in *types.EmployDistributeReq) bool {
  364. return MC.CrmMysql.ExecTx("收录操作", func(tx *sql.Tx) bool {
  365. personMap := map[int64]PersonSmmary{}
  366. //人员信息处理
  367. for _, person := range in.Person {
  368. personMap[person.PositionId] = PersonSmmary{
  369. EntUserId: person.EntUserId,
  370. }
  371. }
  372. //分发数据处理
  373. infoMap := map[string]map[string]interface{}{}
  374. onlyMap := map[string]interface{}{}
  375. //标讯数据处理
  376. for _, v := range strings.Split(in.EmployIdArr, ",") {
  377. if onlyMap[v] == nil {
  378. //查询信息
  379. infoDataList := MC.CrmMysql.SelectBySqlByTx(tx, "SELECT * FROM employ_info WHERE id=?", v)
  380. if infoDataList != nil && len(*infoDataList) > 0 {
  381. source_id := common.InterfaceToStr((*infoDataList)[0]["source_id"])
  382. if onlyMap[source_id] == nil {
  383. (*infoDataList)[0]["dis_id"] = v
  384. (*infoDataList)[0]["is_handle"] = 0
  385. (*infoDataList)[0]["is_ignore"] = 0
  386. (*infoDataList)[0]["is_dis"] = 0
  387. (*infoDataList)[0]["is_create_clue"] = 0
  388. (*infoDataList)[0]["is_create_chance"] = 0
  389. (*infoDataList)[0]["is_create_custom"] = 0
  390. (*infoDataList)[0]["create_time"] = time.Now().Format(date.Date_Full_Layout)
  391. delete((*infoDataList)[0], "id")
  392. if common.IntAll((*infoDataList)[0]["is_dis"]) != 1 {
  393. MC.CrmMysql.UpdateByTx(tx, entity.EMPLOY_INFO, map[string]interface{}{
  394. "id": v,
  395. }, map[string]interface{}{
  396. "is_dis": 1,
  397. "is_handle": 1,
  398. })
  399. }
  400. infoMap[source_id] = (*infoDataList)[0]
  401. onlyMap[source_id] = v
  402. } else {
  403. log.Println(v, "查询不到改收录信息")
  404. continue
  405. }
  406. }
  407. }
  408. }
  409. //普通人员分发
  410. for positionId, personSmmary := range personMap {
  411. //查询时候收录过
  412. for _, v := range infoMap {
  413. //查询时候收录过
  414. findMap := map[string]interface{}{
  415. "position_id": positionId,
  416. "source_id": v["source_id"],
  417. "source": v["source"],
  418. }
  419. if MC.CrmMysql.Count(entity.EMPLOY_INFO, findMap) == 0 {
  420. //新增
  421. v["ent_user_id"] = personSmmary.EntUserId
  422. v["position_id"] = positionId
  423. MC.CrmMysql.InsertByTx(tx, entity.EMPLOY_INFO, v)
  424. }
  425. }
  426. }
  427. if in.EntNicheDis > 0 {
  428. //查询分配员有没有该数据
  429. for _, v := range infoMap {
  430. //查询时候收录过
  431. findMap := map[string]interface{}{
  432. "position_id": in.PositionId,
  433. "source_id": v["source_id"],
  434. "source": v["source"],
  435. }
  436. employPositionId := v["position_id"]
  437. if employPositionId != in.PositionId {
  438. //分发消息不属于自己
  439. if MC.CrmMysql.Count(entity.EMPLOY_INFO, findMap) == 0 {
  440. v["ent_user_id"] = in.EntUserId
  441. v["position_id"] = in.PositionId
  442. v["is_handle"] = 1
  443. MC.CrmMysql.InsertByTx(tx, entity.EMPLOY_INFO, v)
  444. } else {
  445. MC.CrmMysql.UpdateByTx(tx, entity.EMPLOY_INFO, findMap, map[string]interface{}{
  446. "is_handle": 1,
  447. })
  448. }
  449. }
  450. }
  451. }
  452. return true
  453. })
  454. }
  455. func niJianHandle(infoId string, data map[string]interface{}, v1, pushTime string) map[string]interface{} {
  456. project, _ := MC.MgoProject.FindOne("projectset_proposed", map[string]interface{}{
  457. "ids": infoId,
  458. })
  459. if project != nil && len(*project) > 0 {
  460. city := common.InterfaceToStr((*project)["city"])
  461. area := common.InterfaceToStr((*project)["area"])
  462. category_code := common.InterfaceToStr((*project)["category_code"])
  463. lasttime := common.Int64All((*project)["lasttime"])
  464. ownerclass_code := common.InterfaceToStr((*project)["ownerclass_code"])
  465. total_investment := common.InterfaceToStr((*project)["total_investment"])
  466. project_stage_code := common.InterfaceToStr((*project)["project_stage_code"])
  467. infoList := gconv.SliceMap((*project)["list"])
  468. title := ""
  469. projectname := ""
  470. if len(infoList) > 0 {
  471. title = common.InterfaceToStr(infoList[0]["title"])
  472. projectname = common.InterfaceToStr(infoList[0]["projectname"])
  473. }
  474. category := ""
  475. ownerclass := ""
  476. project_stage := ""
  477. if category_code != "" {
  478. categoryData := MC.NiJian.FindOne("d_nzj_category_code", map[string]interface{}{
  479. "code": category_code,
  480. }, "name", "")
  481. category = common.InterfaceToStr((*categoryData)["name"])
  482. }
  483. if ownerclass_code != "" {
  484. ownerclassData := MC.NiJian.FindOne("d_nzj_ownerclass_code", map[string]interface{}{
  485. "code": ownerclass_code,
  486. }, "name", "")
  487. ownerclass = common.InterfaceToStr((*ownerclassData)["name"])
  488. }
  489. if project_stage_code != "" {
  490. projectStageData := MC.NiJian.FindOne("d_nzj_project_stage_code", map[string]interface{}{
  491. "code": project_stage_code,
  492. }, "name", "")
  493. project_stage = common.InterfaceToStr((*projectStageData)["name"])
  494. }
  495. data["title"] = title
  496. data["city"] = city
  497. data["area"] = area
  498. data["projectname"] = projectname
  499. data["ownerclass"] = ownerclass
  500. data["project_stage"] = project_stage
  501. data["project_category"] = category
  502. data["project_investment"] = total_investment
  503. lastTimeStr := common.If(lasttime == 0, pushTime, time.Unix(lasttime, 0).Format(date.Date_Full_Layout))
  504. data["project_evolve"] = lastTimeStr
  505. data["show_time"] = lastTimeStr
  506. data["publishtime"] = lastTimeStr
  507. pid := common.InterfaceToStr((*project)["_id"])
  508. data["jybx_url"] = "/succbi/nzj/app/nzj.app/nzj_detail_0.spg?pid=" + pid
  509. } else {
  510. data["jybx_url"] = "/article/content/" + v1 + ".html"
  511. }
  512. data["source"] = 2
  513. return data
  514. }
  515. // 个人收录情况查询
  516. func employInfoPerson(v, table, id, employKey, findKey string, source int64, in *types.InfoEmployinfoReq) map[string]interface{} {
  517. valueMap := map[string]interface{}{
  518. "id": v,
  519. }
  520. employData := MC.CrmMysql.FindOne(table, map[string]interface{}{
  521. employKey: id,
  522. "position_id": in.PositionId,
  523. "source": source,
  524. }, "is_ignore,status,id", "")
  525. employId := int64(0)
  526. if employData != nil && len(*employData) > 0 {
  527. valueMap["isIgnore"] = common.If(common.Int64All((*employData)["is_ignore"]) == 1, true, false)
  528. valueMap["isEmploy"] = common.If(common.Int64All((*employData)["status"]) == 1, true, false)
  529. employId = common.Int64All((*employData)["id"])
  530. valueMap["employId"] = employId
  531. } else {
  532. valueMap["isIgnore"] = false
  533. valueMap["isEmploy"] = false
  534. }
  535. if len(strings.Split(in.IdArr, ",")) == 1 && employId > 0 {
  536. //列表查询
  537. //是否忽略处理
  538. //客户数量
  539. customCount := MC.CrmMysql.Count(entity.CUSTOM, map[string]interface{}{
  540. findKey: employId,
  541. "position_id": in.PositionId,
  542. })
  543. valueMap["customCount"] = customCount
  544. if in.EmployType == 1 || in.EmployType == 4 {
  545. //销售线索数量
  546. clueCount := MC.CrmMysql.Count(entity.SALE_CLUE, map[string]interface{}{
  547. "employ_info_id": employId,
  548. "position_id": in.PositionId,
  549. })
  550. valueMap["clueCount"] = clueCount
  551. //销售机会数量
  552. chanceCount := MC.CrmMysql.Count(entity.SALE_CHANCE, map[string]interface{}{
  553. "employ_info_id": id,
  554. "position_id": in.PositionId,
  555. })
  556. valueMap["chanceCount"] = chanceCount
  557. }
  558. } else {
  559. valueMap["chanceCount"] = 0
  560. valueMap["clueCount"] = 0
  561. valueMap["isIgnore"] = false
  562. valueMap["customCount"] = 0
  563. }
  564. return valueMap
  565. }
  566. // 企业收录情况查询
  567. func employInfoEnt(v, table, id, employKey, findKey, depIDArr string, source int64, in *types.InfoEmployinfoReq) map[string]interface{} {
  568. valueMap := map[string]interface{}{
  569. "id": v,
  570. "isIgnore": false,
  571. "isEmploy": false,
  572. "customCount": 0,
  573. "clueCount": 0,
  574. "chanceCount": 0,
  575. }
  576. 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)
  577. employArrStr := ""
  578. if employData != nil && len(*employData) > 0 {
  579. valueMap["isIgnore"] = common.If(common.Int64All((*employData)[0]["is_ignore"]) == 1, true, false)
  580. valueMap["isEmploy"] = common.If(common.Int64All((*employData)[0]["status"]) == 1, true, false)
  581. employArrStr = common.InterfaceToStr((*employData)[0]["employIdArr"])
  582. valueMap["employId"] = strings.Split(employArrStr, ",")[0]
  583. } else {
  584. valueMap["isIgnore"] = false
  585. valueMap["isIgnore"] = false
  586. }
  587. if len(strings.Split(in.IdArr, ",")) == 1 && employArrStr != "" {
  588. //列表查询
  589. //是否忽略处理
  590. //客户数量
  591. customSql := fmt.Sprintf("select COUNT(1) from %s where %s in (%s)", entity.CUSTOM, findKey, employArrStr)
  592. customCount := MC.CrmMysql.CountBySql(customSql)
  593. valueMap["customCount"] = customCount
  594. if in.EmployType == 1 || in.EmployType == 4 {
  595. //销售线索数量
  596. clueSql := fmt.Sprintf("select COUNT(1) from %s where employ_info_id in (%s)", entity.SALE_CLUE, employArrStr)
  597. clueCount := MC.CrmMysql.CountBySql(clueSql)
  598. valueMap["clueCount"] = clueCount
  599. //销售机会数量
  600. chanceSql := fmt.Sprintf("select COUNT(1) from %s where employ_info_id in (%s)", entity.SALE_CHANCE, employArrStr)
  601. chanceCount := MC.CrmMysql.CountBySql(chanceSql)
  602. valueMap["chanceCount"] = chanceCount
  603. }
  604. } else {
  605. valueMap["chanceCount"] = 0
  606. valueMap["clueCount"] = 0
  607. valueMap["customCount"] = 0
  608. }
  609. return valueMap
  610. }