employService.go 22 KB

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