employService.go 23 KB

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