operator.go 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837
  1. package service
  2. import (
  3. elastic "app.yhyue.com/moapp/jybase/es"
  4. IC "bp.jydev.jianyu360.cn/BaseService/jyMicroservices/jyBXCore/rpc/init"
  5. "fmt"
  6. "github.com/gogf/gf/v2/util/gconv"
  7. "strings"
  8. "time"
  9. )
  10. var (
  11. yysIndex = "bidding_customer"
  12. yysType = "bidding_customer"
  13. )
  14. func GetCriteria(entId, positionId int64) map[int]interface{} {
  15. result := map[int]interface{}{}
  16. //for i := 0; i < 1; i++ {
  17. for i := 0; i < 3; i++ {
  18. result[i] = getGetCriteriaType(entId, positionId, int64(i))
  19. }
  20. return result
  21. }
  22. func getGetCriteriaType(entId, positionId, tag int64) []map[string]interface{} {
  23. data := []map[string]interface{}{}
  24. if tag == 1 {
  25. data = append(data, map[string]interface{}{
  26. "key": "purchaseTime",
  27. "type": "dateTimeList",
  28. "label": "预计采购时间",
  29. "defaultVal": "",
  30. "props": map[string]interface{}{
  31. "multiple": false,
  32. "endTimeFeature": true,
  33. },
  34. "options": []map[string]interface{}{
  35. {
  36. "label": "全部", "value": "",
  37. },
  38. {
  39. "label": "本月", "value": "thisMonth",
  40. },
  41. {
  42. "label": "下月", "value": "nextMonth",
  43. },
  44. {
  45. "label": "自定义", "value": "exact",
  46. },
  47. },
  48. })
  49. } else if tag == 2 {
  50. data = append(data, map[string]interface{}{
  51. "key": "openingTime",
  52. "type": "dateTimeList",
  53. "label": "开标日期",
  54. "defaultVal": "",
  55. "props": map[string]interface{}{
  56. "multiple": false,
  57. "endTimeFeature": true,
  58. },
  59. "options": []map[string]interface{}{
  60. {
  61. "label": "全部", "value": "",
  62. },
  63. {
  64. "label": "本周", "value": "thisWeek",
  65. },
  66. {
  67. "label": "下周", "value": "nextWeek",
  68. },
  69. {
  70. "label": "本月", "value": "thisMonth",
  71. },
  72. {
  73. "label": "自定义", "value": "exact",
  74. },
  75. },
  76. })
  77. }
  78. //发布时间
  79. data = append(data, map[string]interface{}{
  80. "key": "publishTime",
  81. "type": "dateTimeList",
  82. "label": "发布时间",
  83. "defaultVal": "",
  84. "props": map[string]interface{}{
  85. "multiple": false,
  86. "endTimeFeature": true,
  87. },
  88. "options": []map[string]interface{}{
  89. {
  90. "label": "全部", "value": "",
  91. },
  92. {
  93. "label": "昨天", "value": "yesterday",
  94. },
  95. {
  96. "label": "上周", "value": "lastWeek",
  97. },
  98. {
  99. "label": "上一个月", "value": "lastMonth",
  100. },
  101. {
  102. "label": "自定义", "value": "exact",
  103. },
  104. },
  105. })
  106. //私有标签处理
  107. getlalArr := getLabel(entId)
  108. if len(getlalArr) > 0 {
  109. data = append(data, getlalArr...)
  110. }
  111. //查询都显示什么数据
  112. labelArr := IC.BiMysql.SelectBySql(`SELECT * FROM customer_data_yys_config WHERE ent_id = ? and config_type="筛选条件" and config_class=? ORDER BY id`, entId, tag)
  113. if labelArr != nil && len(*labelArr) > 0 {
  114. for _, v := range *labelArr {
  115. configName := gconv.String(v["config_name"])
  116. switch configName {
  117. case "行业":
  118. industryArr := getConfiguration("行业", "industry", entId)
  119. if len(industryArr) > 0 {
  120. data = append(data, map[string]interface{}{
  121. "key": "industry",
  122. "type": "selectList",
  123. "label": "行业",
  124. "defaultVal": []string{""},
  125. "props": map[string]interface{}{
  126. "multiple": true,
  127. },
  128. "options": industryArr,
  129. })
  130. }
  131. case "中标人标签":
  132. winnerArr := getConfiguration("运营商中标标签", "winner_tag", entId)
  133. if len(winnerArr) > 0 {
  134. data = append(data, map[string]interface{}{
  135. "key": "winnerTag",
  136. "type": "selectList",
  137. "label": "中标人标签",
  138. "defaultVal": []string{""},
  139. "props": map[string]interface{}{
  140. "multiple": true,
  141. },
  142. "options": winnerArr,
  143. })
  144. }
  145. case "信息类型":
  146. //查看是否有二级信息
  147. isExist := false
  148. for _, v := range *labelArr {
  149. configName1 := gconv.String(v["config_name"])
  150. if configName1 == "信息类型二级" {
  151. isExist = true
  152. }
  153. }
  154. if isExist {
  155. data = append(data, map[string]interface{}{
  156. "key": "topType",
  157. "type": "component-popup-infotype",
  158. "label": "信息类型",
  159. "cascader": true,
  160. "collectionMark": 1,
  161. "defaultVal": "",
  162. "childLabel": "信息类型二级",
  163. "props": map[string]interface{}{
  164. "multiple": false,
  165. },
  166. "options": []map[string]interface{}{
  167. {
  168. "label": "全部",
  169. "value": "",
  170. "children": []map[string]interface{}{},
  171. },
  172. {
  173. "label": "预告",
  174. "value": "预告",
  175. "children": []map[string]interface{}{
  176. {"label": "预告", "value": "预告"},
  177. {"label": "预审", "value": "预审"},
  178. {"label": "预审结果", "value": "预审结果"},
  179. {"label": "论证意见", "value": "论证意见"},
  180. {"label": "需求公示", "value": "需求公示"},
  181. {"label": "其它", "value": "其它"},
  182. },
  183. }, {
  184. "label": "招标",
  185. "value": "招标",
  186. "children": []map[string]interface{}{
  187. {"label": "变更", "value": "变更"},
  188. {"label": "邀标", "value": "邀标"},
  189. {"label": "询价", "value": "询价"},
  190. {"label": "竞谈", "value": "竞谈"},
  191. {"label": "单一", "value": "单一"},
  192. {"label": "竞价", "value": "竞价"},
  193. {"label": "招标", "value": "招标"},
  194. {"label": "其它", "value": "其它"},
  195. },
  196. }, {
  197. "label": "结果",
  198. "value": "结果",
  199. "children": []map[string]interface{}{
  200. {"label": "废标", "value": "废标"},
  201. {"label": "流标", "value": "流标"},
  202. {"label": "结果变更", "value": "结果变更"},
  203. {"label": "中标", "value": "中标"},
  204. {"label": "成交", "value": "成交"},
  205. {"label": "其它", "value": "其它"},
  206. },
  207. }, {
  208. "label": "采购意向",
  209. "value": "采购意向",
  210. "children": []map[string]interface{}{
  211. {"label": "采购意向", "value": "采购意向"},
  212. },
  213. }, {
  214. "label": "拟建",
  215. "value": "拟建",
  216. "children": []map[string]interface{}{
  217. {"label": "拟建", "value": "拟建"},
  218. },
  219. }, {
  220. "label": "其它",
  221. "value": "其它",
  222. "children": []map[string]interface{}{
  223. {"label": "合同", "value": "合同"},
  224. {"label": "验收", "value": "验收"},
  225. {"label": "违规", "value": "违规"},
  226. {"label": "其它", "value": "其它"},
  227. },
  228. }}})
  229. } else {
  230. data = append(data, map[string]interface{}{
  231. "key": "topType",
  232. "type": "selectList",
  233. "label": "信息类型",
  234. "cascader": true,
  235. "collectionMark": 1,
  236. "defaultVal": "",
  237. "props": map[string]interface{}{
  238. "multiple": false,
  239. },
  240. "options": []map[string]interface{}{
  241. {
  242. "label": "全部",
  243. "value": "",
  244. "children": []map[string]interface{}{},
  245. },
  246. {
  247. "label": "预告",
  248. "value": "预告",
  249. "children": []map[string]interface{}{},
  250. }, {
  251. "label": "招标",
  252. "value": "招标",
  253. "children": []map[string]interface{}{},
  254. }, {
  255. "label": "结果",
  256. "value": "结果",
  257. "children": []map[string]interface{}{},
  258. }, {
  259. "label": "采购意向",
  260. "value": "采购意向",
  261. "children": []map[string]interface{}{},
  262. }, {
  263. "label": "拟建",
  264. "value": "拟建",
  265. "children": []map[string]interface{}{},
  266. }, {
  267. "label": "其它",
  268. "value": "其它",
  269. "children": []map[string]interface{}{},
  270. }}})
  271. }
  272. case "省份":
  273. areaMap := getArea(entId, positionId, labelArr)
  274. if areaMap != nil && len(areaMap) != 0 {
  275. data = append(data, areaMap)
  276. }
  277. }
  278. }
  279. }
  280. return data
  281. }
  282. func getConfiguration(conditionName, conditionType string, entId int64) []map[string]interface{} {
  283. data := IC.BiMysql.SelectBySql(`SELECT
  284. DISTINCT b.name,b.code
  285. FROM
  286. customer_data_yys_permissions a INNER JOIN customer_data_yys_permission_elements b
  287. on
  288. a.ent_id = ?
  289. and a.is_delete = 0
  290. AND a.element_name = ?
  291. and FIND_IN_SET( b.code,a.element_value)
  292. and b.element_field=?`, entId, conditionName, conditionType)
  293. options := []map[string]interface{}{}
  294. if data != nil && len(*data) > 0 {
  295. options = append(options, map[string]interface{}{
  296. "label": "全部",
  297. "value": "",
  298. })
  299. for _, v := range *data {
  300. name := gconv.String(v["name"])
  301. code := gconv.Int64(v["code"])
  302. options = append(options, map[string]interface{}{
  303. "label": name,
  304. "value": code,
  305. })
  306. }
  307. }
  308. return options
  309. }
  310. func getLabel(entId int64) []map[string]interface{} {
  311. // 私有标签查询
  312. data := []map[string]interface{}{}
  313. labelArr := IC.BiMysql.SelectBySql(`SELECT * FROM private_label WHERE ent_id = ? AND level > 0 ORDER BY id`, entId)
  314. if labelArr != nil && len(*labelArr) != 0 {
  315. // 使用切片来存储一级标签及其对应的二级、三级标签
  316. labelIdArr := []int64{}
  317. labels := make(map[int64]map[string]interface{}) // 存储各级标签
  318. labelOptions := make(map[int64][]map[string]interface{}) // 存储各级标签的选项
  319. for _, m := range *labelArr {
  320. key := "tagname"
  321. switch len(labels) {
  322. case 1:
  323. key = "tagname1"
  324. case 2:
  325. key = "tagname2"
  326. }
  327. level := gconv.Int64(m["level"])
  328. name := gconv.String(m["name"])
  329. pid := gconv.Int64(m["pid"]) // 将 pid 转换为 int64
  330. id := gconv.Int64(m["id"]) // 将 id 转换为 int64
  331. if level == 1 {
  332. labelIdArr = append(labelIdArr, id)
  333. // 处理一级标签
  334. labels[id] = map[string]interface{}{
  335. "id": id,
  336. "key": key,
  337. "type": "selectList",
  338. "label": name,
  339. "defaultVal": []string{""},
  340. "props": map[string]interface{}{
  341. "multiple": true,
  342. },
  343. "options": []map[string]interface{}{}, // 初始化选项
  344. }
  345. } else {
  346. // 处理二级和三级标签
  347. if _, exists := labels[pid]; exists {
  348. if len(labelOptions[pid]) == 0 {
  349. labelOptions[pid] = append(labelOptions[pid], map[string]interface{}{
  350. "label": "全部",
  351. "value": "",
  352. })
  353. }
  354. labelOptions[pid] = append(labelOptions[pid], map[string]interface{}{
  355. "label": name,
  356. "value": name,
  357. })
  358. }
  359. }
  360. }
  361. // 将标签及其选项添加到最终数据中
  362. for _, m := range labelIdArr {
  363. for _, label := range labels {
  364. id := gconv.Int64(label["id"])
  365. if id == m {
  366. if options, exists := labelOptions[label["id"].(int64)]; exists && len(options) > 0 {
  367. label["options"] = options
  368. }
  369. data = append(data, label)
  370. }
  371. }
  372. }
  373. }
  374. return data
  375. }
  376. func getArea(entid, positionId int64, labelArr *[]map[string]interface{}) map[string]interface{} {
  377. data := make(map[string]map[string][]string)
  378. // 私有标签查询
  379. areaArr := IC.BiMysql.SelectBySql(`
  380. SELECT
  381. t0.area, t0.city, t0.district
  382. FROM
  383. bi_service.customer_data t0
  384. INNER JOIN (
  385. SELECT
  386. ent_id AS 企业_ID,
  387. MAX(CASE WHEN element_name = '行业' THEN element_value END) AS 行业要素值,
  388. MAX(CASE WHEN element_name = '运营商中标标签' THEN element_value END) AS 中标标签要素值,
  389. MAX(CASE WHEN element_name = '地区' THEN element_value END) AS 地区要素值,
  390. MAX(CASE WHEN element_name = '经营单位' THEN element_value END) AS 经营单位要素值
  391. FROM
  392. bi_service.customer_data_yys_permissions
  393. WHERE
  394. is_delete = 0 and position_id=? and ent_id=?
  395. ) t1 ON t0.eid = t1.企业_ID
  396. WHERE
  397. (t1.行业要素值 IS NULL OR FIND_IN_SET(t0.INDUSTRY, t1.行业要素值)) AND
  398. (t1.地区要素值 IS NULL OR FIND_IN_SET(t0.REGION, t1.地区要素值)) AND
  399. (t1.中标标签要素值 IS NULL OR FIND_IN_SET(t0.WINNER_TAG, t1.中标标签要素值)) AND
  400. (t1.经营单位要素值 IS NULL OR FIND_IN_SET(t0.tagname2, t1.经营单位要素值)) AND
  401. (t0.STATUS = 1)
  402. GROUP BY area, city, district`, positionId, entid)
  403. if areaArr == nil || len(*areaArr) == 0 {
  404. //查找全局变量
  405. areaArr = IC.BiMysql.SelectBySql(`
  406. SELECT
  407. area,
  408. city,
  409. district
  410. FROM
  411. customer_data
  412. WHERE
  413. eid = ?
  414. GROUP BY
  415. area,
  416. city,
  417. district
  418. ORDER BY
  419. area,
  420. city,
  421. district;`, entid)
  422. }
  423. if areaArr != nil && len(*areaArr) > 0 {
  424. for _, m := range *areaArr {
  425. area := gconv.String(m["area"])
  426. city := gconv.String(m["city"])
  427. district := gconv.String(m["district"])
  428. if area == "" || city == "" {
  429. continue // 跳过无效的区域或城市
  430. }
  431. if _, exists := data[area]; !exists {
  432. data[area] = make(map[string][]string)
  433. }
  434. if district != "" {
  435. data[area][city] = append(data[area][city], district)
  436. } else {
  437. data[area][city] = []string{} // 存储空数组以表示没有区
  438. }
  439. }
  440. }
  441. isCity, isDistrict := false, false
  442. for _, v := range *labelArr {
  443. configName := gconv.String(v["config_name"])
  444. if configName == "城市" {
  445. isCity = true
  446. } else if configName == "区县" {
  447. isDistrict = true
  448. }
  449. }
  450. if !isCity {
  451. //没有设置市区
  452. for k := range data {
  453. data[k] = map[string][]string{}
  454. }
  455. } else if !isDistrict {
  456. //没有设置区县
  457. for k, v := range data {
  458. for k1 := range v {
  459. v[k1] = []string{}
  460. }
  461. data[k] = v
  462. }
  463. }
  464. if len(data) > 0 {
  465. return map[string]interface{}{
  466. "key": "province",
  467. "type": "component-popup-area",
  468. "label": "城市",
  469. "defaultVal": "",
  470. "options": data,
  471. }
  472. }
  473. return map[string]interface{}{}
  474. }
  475. type Operator struct {
  476. EntId int64 //企业id 没有企业 企业id=0
  477. Tag int64
  478. PageNum int64 //当前页码
  479. PageSize int64 //每页数量
  480. Province string //省份
  481. TopType string //信息类型-二级
  482. PublishTime string //发布时间
  483. SelectType string //搜索范围:标题;正文等
  484. Price string //价格
  485. Tagname string
  486. Tagname1 string
  487. Tagname2 string
  488. WordsMode int64 //搜索关键词模式;默认0:包含所有,1:包含任意
  489. KeyWords string //关键词:多个空格隔开(主)
  490. PurchaseTime string //采购时间
  491. OpeningTime string //开标时间
  492. Industry string
  493. WinnerTag string
  494. PositionId int64
  495. Order int64
  496. }
  497. func SearchList(operator Operator) (int64, *[]map[string]interface{}) {
  498. if operator.PageSize == 0 {
  499. operator.PageSize = 10
  500. }
  501. start := (operator.PageNum - 1) * operator.PageSize
  502. if start < 0 {
  503. start = 0
  504. }
  505. var query = `{"query":{"bool":{"must":[%s],"filter":[%s],"minimum_should_match":1,
  506. "should":[{"exists":{"field":"bidamount"}},{"bool":{"should":[{"exists":{"field":"budget"}},{"bool":{"must_not":[{"exists":{"field":"budget"}}]}}],"must_not":[{"exists":{"field":"bidamount"}}]}}]}},"from":"%d","size":"%d","sort":[%s]
  507. }`
  508. shouldStr := `{"bool":{"should":[%s]}}`
  509. mustArr := []string{}
  510. filterArr := []string{
  511. fmt.Sprintf(`{"match":{"ent_id":"%s"}}`, gconv.String(operator.EntId)),
  512. }
  513. //must处理
  514. //filter处理
  515. if operator.Tag == 1 {
  516. filterArr = append(filterArr, `{"match":{"toptype":"采购意向"}}`)
  517. operator.TopType = ""
  518. } else if operator.Tag == 2 {
  519. mustArr = append(mustArr, `{"exists":{"field":"bidopentime"}}`)
  520. operator.TopType = ""
  521. }
  522. if operator.PublishTime != "" {
  523. pushTime := strings.Split(operator.PublishTime, "_")
  524. for k, v := range pushTime {
  525. if k == 0 {
  526. if v != "" {
  527. filterArr = append(filterArr, fmt.Sprintf(`{"range":{"publishtime":{"gte":"%s"}}}`, v))
  528. }
  529. }
  530. if k == 1 {
  531. if v != "" {
  532. filterArr = append(filterArr, fmt.Sprintf(`{"range":{"publishtime":{"lt":"%s"}}}`, v))
  533. }
  534. }
  535. }
  536. }
  537. //采购时间
  538. if operator.PurchaseTime != "" {
  539. purchaseTime := strings.Split(operator.PurchaseTime, "_")
  540. for k, v := range purchaseTime {
  541. if k == 0 {
  542. if v != "" {
  543. filterArr = append(filterArr, fmt.Sprintf(`{"range":{"expurasingtime":{"gte":"%s"}}}`, v))
  544. }
  545. }
  546. if k == 1 {
  547. if v != "" {
  548. filterArr = append(filterArr, fmt.Sprintf(`{"range":{"expurasingtime":{"lt":"%s"}}}`, v))
  549. }
  550. }
  551. }
  552. }
  553. //开标时间
  554. if operator.OpeningTime != "" {
  555. openingTime := strings.Split(operator.OpeningTime, "_")
  556. for k, v := range openingTime {
  557. if k == 0 {
  558. if v != "" {
  559. filterArr = append(filterArr, fmt.Sprintf(`{"range":{"bidopentime":{"gte":"%s"}}}`, v))
  560. }
  561. }
  562. if k == 1 {
  563. if v != "" {
  564. filterArr = append(filterArr, fmt.Sprintf(`{"range":{"bidopentime":{"lt":"%s"}}}`, v))
  565. }
  566. }
  567. }
  568. }
  569. //关键词
  570. if operator.KeyWords != "" {
  571. if operator.WordsMode == 1 {
  572. keyArr := []string{}
  573. for _, v := range strings.Split(operator.KeyWords, ",") {
  574. keyArr = append(keyArr, fmt.Sprintf(`{"match_phrase":{"%s":"%s"}`, operator.SelectType, v))
  575. }
  576. mustArr = append(mustArr, fmt.Sprintf(shouldStr, strings.Join(keyArr, ",")))
  577. } else {
  578. for _, v := range strings.Split(operator.KeyWords, ",") {
  579. filterArr = append(filterArr, fmt.Sprintf(`{"match_phrase":{"%s":"%s"}}`, operator.SelectType, v))
  580. }
  581. }
  582. }
  583. //信息类型一级
  584. //{"match":{"toptype":"结果"}},{"terms":{"subtype":["结果变更","中标"]}}
  585. topType := []string{}
  586. subtype := []string{}
  587. if operator.TopType != "" {
  588. for k, v := range gconv.Map(operator.TopType) {
  589. topType = append(topType, k)
  590. for _, v1 := range gconv.Interfaces(v) {
  591. subtype = append(subtype, gconv.String(v1))
  592. }
  593. }
  594. if len(topType) > 0 {
  595. filterArr = append(filterArr, fmt.Sprintf(`{"match":{"toptype":"%s"}}`), strings.Join(topType, `","`))
  596. }
  597. //信息类型二级
  598. if len(subtype) > 0 {
  599. filterArr = append(filterArr, fmt.Sprintf(`{"match":{"subtype":["%s"]}}`, strings.Join(subtype, `","`)))
  600. }
  601. }
  602. //私有标签1
  603. if operator.Tagname != "" {
  604. keyArr := []string{}
  605. for _, v := range strings.Split(operator.Tagname, ",") {
  606. keyArr = append(keyArr, fmt.Sprintf(`{"wildcard":{"tagname":"*%s"}}`, v))
  607. }
  608. mustArr = append(mustArr, fmt.Sprintf(shouldStr, strings.Join(keyArr, ",")))
  609. }
  610. //私有标签2
  611. if operator.Tagname1 != "" {
  612. keyArr := []string{}
  613. for _, v := range strings.Split(operator.Tagname1, ",") {
  614. keyArr = append(keyArr, fmt.Sprintf(`{"wildcard":{"tagname":"*%s*"}}`, v))
  615. }
  616. mustArr = append(mustArr, fmt.Sprintf(shouldStr, strings.Join(keyArr, ",")))
  617. }
  618. //私有标签3
  619. if operator.Tagname2 != "" {
  620. keyArr := []string{}
  621. for _, v := range strings.Split(operator.Tagname2, ",") {
  622. keyArr = append(keyArr, fmt.Sprintf(`{"wildcard":{"tagname":"%s"}}`, v))
  623. }
  624. mustArr = append(mustArr, fmt.Sprintf(shouldStr, strings.Join(keyArr, ",")))
  625. }
  626. //价格处理
  627. if operator.Price != "" {
  628. priceArr := strings.Split(operator.Price, "-")
  629. minPrice := gconv.Int64(priceArr[0])
  630. maxPrice := gconv.Int64(priceArr[1])
  631. bidamountArr := []string{`
  632. {
  633. "exists": {
  634. "field": "bidamount"
  635. }
  636. }`, fmt.Sprintf(`
  637. {
  638. "range": {
  639. "bidamount": {
  640. "gte": %s
  641. }
  642. }
  643. }
  644. `, gconv.String(minPrice))}
  645. budgetArr := []string{`
  646. {
  647. "exists": {
  648. "field": "budget"
  649. }
  650. }`, fmt.Sprintf(`
  651. {
  652. "range": {
  653. "budget": {
  654. "gte": %s
  655. }
  656. }
  657. }
  658. `, gconv.String(minPrice))}
  659. if maxPrice > 0 {
  660. bidamountArr = append(bidamountArr, fmt.Sprintf(`
  661. {
  662. "range": {
  663. "bidamount": {
  664. "lte": "%s"
  665. }
  666. }
  667. }
  668. `, gconv.String(minPrice)))
  669. budgetArr = append(budgetArr, fmt.Sprintf(`
  670. {
  671. "range": {
  672. "budget": {
  673. "lte": "%s"
  674. }
  675. }
  676. }
  677. `, gconv.String(minPrice)))
  678. }
  679. mustArr = append(mustArr, fmt.Sprintf(`{"bool":{"should":[{"bool":{"filter":[%s]}},{"bool":{"filter":[%s],"must_not":[{"exists":{"field":"bidamount"}}]}}]}}`, strings.Join(bidamountArr, ","), strings.Join(budgetArr, ",")))
  680. }
  681. //地区搜索
  682. area := []string{}
  683. city := []string{}
  684. district := []string{}
  685. if operator.Province != "" {
  686. for k, v := range gconv.Map(operator.Province) {
  687. area = append(area, gconv.String(k))
  688. for k1, v1 := range gconv.Map(v) {
  689. city = append(city, k1)
  690. for _, v3 := range gconv.SliceStr(v1) {
  691. district = append(district, fmt.Sprintf("%s_%s"), k1, v3)
  692. }
  693. }
  694. }
  695. if len(area) > 0 {
  696. query1 := ""
  697. query1 += `{"terms":{"area":[`
  698. for k, v := range area {
  699. if k > 0 {
  700. query1 += `,`
  701. }
  702. query1 += `"` + v + `"`
  703. }
  704. query1 += `]}}`
  705. filterArr = append(filterArr, query1)
  706. }
  707. //市--未登录用户不能根据市和地区筛选
  708. if len(city) > 0 {
  709. query1 := ""
  710. query1 += `{"terms":{"city":[`
  711. for k, v := range city {
  712. if k > 0 {
  713. query1 += `,`
  714. }
  715. query1 += `"` + v + `"`
  716. }
  717. query1 += `]}}`
  718. filterArr = append(filterArr, query1)
  719. }
  720. if len(district) > 0 {
  721. query1 := ""
  722. for k, v := range district {
  723. if k > 0 {
  724. query1 += `,`
  725. }
  726. cityName := strings.Split(v, "_")[0]
  727. districtName := strings.Split(v, "_")[1]
  728. queryBoolMustAndDistrict := `{"bool":{"must":[{"terms":{"city":["%s"]}},{"terms":{"district":["%s"]}}]}}`
  729. query1 += fmt.Sprintf(queryBoolMustAndDistrict, cityName, districtName)
  730. }
  731. filterArr = append(filterArr, query1)
  732. }
  733. }
  734. //行业处理
  735. if operator.Industry != "" {
  736. filterArr = append(filterArr, fmt.Sprintf(`{"match":{"industry":["%s"]}}`, strings.ReplaceAll(operator.Industry, ",", `","`)))
  737. }
  738. //中标人标签处理
  739. if operator.WinnerTag != "" {
  740. filterArr = append(filterArr, fmt.Sprintf(`{"match":{"winner_tag":["%s"]}}`, strings.ReplaceAll(operator.WinnerTag, ",", `","`)))
  741. }
  742. //查看自己是否定制
  743. /*configData := IC.BiMysql.SelectBySql(`SELECT
  744. MAX( CASE WHEN element_name = '行业' THEN element_value END ) AS industry,
  745. MAX( CASE WHEN element_name = '运营商中标标签' THEN element_value END ) AS winner_tag,
  746. MAX( CASE WHEN element_name = '地区' THEN element_value END ) AS region,
  747. MAX( CASE WHEN element_name = '经营单位' THEN element_value END ) AS tagname
  748. FROM
  749. bi_service.customer_data_yys_permissions
  750. WHERE
  751. is_delete = 0
  752. AND position_id = ?
  753. AND ent_id = ?`, operator.PositionId, operator.EntId)
  754. if configData != nil && len(*configData) > 0 {
  755. tagname := gconv.String((*configData)[0]["tagname"])
  756. region := gconv.String((*configData)[0]["region"])
  757. winner_tag := gconv.String((*configData)[0]["winner_tag"])
  758. industry := gconv.String((*configData)[0]["industry"])
  759. if tagname != "" {
  760. filterArr = append(filterArr, fmt.Sprintf(`{"terms":{"tagname":["%s"]}}`, strings.Join(strings.Split(tagname, ","), `","`)))
  761. }
  762. if region != "" {
  763. filterArr = append(filterArr, fmt.Sprintf(`{"terms":{"region":["%s"]}}`, strings.Join(strings.Split(region, ","), `","`)))
  764. }
  765. if winner_tag != "" {
  766. filterArr = append(filterArr, fmt.Sprintf(`{"terms":{"winner_tag":["%s"]}}`, strings.Join(strings.Split(winner_tag, ","), `","`)))
  767. }
  768. if industry != "" {
  769. filterArr = append(filterArr, fmt.Sprintf(`{"terms":{"industry":["%s"]}}`, strings.Join(strings.Split(industry, ","), `","`)))
  770. }
  771. }*/
  772. //es sql拼接
  773. queryStr := ""
  774. orderStr := ""
  775. mysqlOrderStr := ""
  776. if operator.Tag == 1 {
  777. if operator.Order == 0 {
  778. orderStr = `{"publishtime":{"order":"desc"}}`
  779. mysqlOrderStr = ` order by publishtime desc`
  780. } else {
  781. orderStr = `{"publishtime":{"order":"asc"}}`
  782. mysqlOrderStr = ` order by publishtime asc`
  783. }
  784. } else if operator.Tag == 2 {
  785. if operator.Order == 0 {
  786. orderStr = `{"publishtime":{"order":"desc"}}`
  787. mysqlOrderStr = ` order by publishtime desc`
  788. } else {
  789. orderStr = `{"expurasingtime":{"order":"asc"}}`
  790. mysqlOrderStr = ` order by expurasingtime asc`
  791. }
  792. } else {
  793. if operator.Order == 0 {
  794. orderStr = `{"publishtime":{"order":"desc"}}`
  795. mysqlOrderStr = ` order by publishtime desc`
  796. } else {
  797. orderStr = `{"bidopentime":{"order":"asc"}}`
  798. mysqlOrderStr = ` order by bidopentime asc`
  799. }
  800. }
  801. queryStr = fmt.Sprintf(query, strings.Join(mustArr, ","), strings.Join(filterArr, ","), start, operator.PageSize, orderStr)
  802. fmt.Println(queryStr)
  803. start1 := time.Now().Unix()
  804. fmt.Println(start1)
  805. var count int64
  806. var data *[]map[string]interface{}
  807. count, data = elastic.GetWithCount(yysIndex, yysType, "", queryStr)
  808. end1 := time.Now().Unix()
  809. fmt.Println(end1)
  810. fmt.Println("时差", end1-start1)
  811. if len(*data) > 0 {
  812. //查询tidb真实数据
  813. idArr := []string{}
  814. for _, v := range *data {
  815. id := gconv.String(v["id"])
  816. idArr = append(idArr, id)
  817. }
  818. sqlStr := fmt.Sprintf(`select * from customer_data where FIND_IN_SET (id,?) %s `, mysqlOrderStr)
  819. fmt.Println(sqlStr)
  820. data = IC.BiMysql.SelectBySql(sqlStr,
  821. strings.Join(idArr, ","))
  822. return count, data
  823. } else {
  824. return count, &[]map[string]interface{}{}
  825. }
  826. }