employService.go 22 KB

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