employService.go 26 KB

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