employService.go 20 KB

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