employService.go 26 KB

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