employService.go 26 KB

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