employService.go 27 KB

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