employService.go 26 KB

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