employService.go 20 KB

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