employService.go 26 KB

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