employService.go 21 KB

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