operator.go 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787
  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. "log"
  8. "strings"
  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": "subtype",
  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": "subtype",
  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. }
  496. func SearchList(operator Operator) (int64, *[]map[string]interface{}) {
  497. if operator.PageSize == 0 {
  498. operator.PageSize = 10
  499. }
  500. start := (operator.PageNum - 1) * operator.PageSize
  501. if start < 0 {
  502. start = 0
  503. }
  504. var query = `{"query":{"bool":{"must":[%s],"filter":[%s],"minimum_should_match":1,
  505. "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":[{"publishtime":{"order":"desc"}}]
  506. }`
  507. shouldStr := `{"bool":{"should":[%s]}}`
  508. mustArr := []string{}
  509. filterArr := []string{
  510. fmt.Sprintf(`{"match":{"ent_id":"%s"}}`, gconv.String(operator.EntId)),
  511. }
  512. //must处理
  513. //filter处理
  514. if operator.Tag == 1 {
  515. filterArr = append(filterArr, `{"match":{"toptype":"采购意向"}}`)
  516. operator.TopType = ""
  517. } else if operator.Tag == 2 {
  518. mustArr = append(mustArr, `{"exists":{"field":"bidopentime"}}`)
  519. operator.TopType = ""
  520. }
  521. if operator.PublishTime != "" {
  522. pushTime := strings.Split(operator.PublishTime, "_")
  523. for k, v := range pushTime {
  524. if k == 0 {
  525. if v != "" {
  526. filterArr = append(filterArr, fmt.Sprint(`{"range":{"publishtime":{"gte":"%d"}}}`, v))
  527. }
  528. }
  529. if k == 1 {
  530. if v != "" {
  531. filterArr = append(filterArr, fmt.Sprint(`{"range":{"publishtime":{"lt":"%d"}}}`, v))
  532. }
  533. }
  534. }
  535. }
  536. //采购时间
  537. if operator.PurchaseTime != "" {
  538. purchaseTime := strings.Split(operator.PurchaseTime, "_")
  539. for k, v := range purchaseTime {
  540. if k == 0 {
  541. if v != "" {
  542. filterArr = append(filterArr, fmt.Sprint(`{"range":{"expurasingtime":{"gte":"%d"}}}`, v))
  543. }
  544. }
  545. if k == 1 {
  546. if v != "" {
  547. filterArr = append(filterArr, fmt.Sprint(`{"range":{"publishtime":{"lt":"%d"}}}`, v))
  548. }
  549. }
  550. }
  551. }
  552. //开标时间
  553. if operator.OpeningTime != "" {
  554. openingTime := strings.Split(operator.OpeningTime, "_")
  555. for k, v := range openingTime {
  556. if k == 0 {
  557. if v != "" {
  558. filterArr = append(filterArr, fmt.Sprint(`{"range":{"bidopentime":{"gte":"%d"}}}`, v))
  559. }
  560. }
  561. if k == 1 {
  562. if v != "" {
  563. filterArr = append(filterArr, fmt.Sprint(`{"range":{"bidopentime":{"lt":"%d"}}}`, v))
  564. }
  565. }
  566. }
  567. }
  568. //关键词
  569. if operator.KeyWords != "" {
  570. if operator.WordsMode == 1 {
  571. keyArr := []string{}
  572. for _, v := range strings.Split(operator.KeyWords, ",") {
  573. keyArr = append(keyArr, fmt.Sprintf(`{"match_phrase":{"%s":"%s"}`, operator.SelectType, v))
  574. }
  575. mustArr = append(mustArr, fmt.Sprintf(shouldStr, strings.Join(keyArr, ",")))
  576. } else {
  577. for _, v := range strings.Split(operator.KeyWords, ",") {
  578. filterArr = append(filterArr, fmt.Sprintf(`{"match_phrase":{"%s":"%s"}}`, operator.SelectType, v))
  579. }
  580. }
  581. }
  582. //信息类型一级
  583. //{"match":{"toptype":"结果"}},{"terms":{"subtype":["结果变更","中标"]}}
  584. topType := []string{}
  585. subtype := []string{}
  586. if operator.TopType != "" {
  587. for k, v := range gconv.Map(operator.TopType) {
  588. topType = append(topType, k)
  589. for _, v1 := range gconv.Interfaces(v) {
  590. subtype = append(subtype, gconv.String(v1))
  591. }
  592. }
  593. if len(topType) > 0 {
  594. filterArr = append(filterArr, fmt.Sprintf(`{"match":{"toptype":"%s"}}`), strings.Join(topType, `","`))
  595. }
  596. //信息类型二级
  597. if len(subtype) > 0 {
  598. filterArr = append(filterArr, fmt.Sprintf(`{"match":{"subtype":["%s"]}}`, strings.Join(subtype, `","`)))
  599. }
  600. }
  601. //私有标签1
  602. if operator.Tagname != "" {
  603. keyArr := []string{}
  604. for _, v := range strings.Split(operator.Tagname, ",") {
  605. keyArr = append(keyArr, fmt.Sprintf(`{"wildcard":{"tagname":"*%s"}}`, v))
  606. }
  607. mustArr = append(mustArr, fmt.Sprintf(shouldStr, strings.Join(keyArr, ",")))
  608. }
  609. //私有标签2
  610. if operator.Tagname1 != "" {
  611. keyArr := []string{}
  612. for _, v := range strings.Split(operator.Tagname1, ",") {
  613. keyArr = append(keyArr, fmt.Sprintf(`{"wildcard":{"tagname":"*%s*"}}`, v))
  614. }
  615. mustArr = append(mustArr, fmt.Sprintf(shouldStr, strings.Join(keyArr, ",")))
  616. }
  617. //私有标签3
  618. if operator.Tagname2 != "" {
  619. keyArr := []string{}
  620. for _, v := range strings.Split(operator.Tagname2, ",") {
  621. keyArr = append(keyArr, fmt.Sprintf(`{"wildcard":{"tagname":"%s"}}`, v))
  622. }
  623. mustArr = append(mustArr, fmt.Sprintf(shouldStr, strings.Join(keyArr, ",")))
  624. }
  625. //价格处理
  626. if operator.Price != "" {
  627. priceArr := strings.Split(operator.Price, "-")
  628. minPrice := gconv.Int64(priceArr[0])
  629. maxPrice := gconv.Int64(priceArr[1])
  630. bidamountArr := []string{`
  631. {
  632. "exists": {
  633. "field": "bidamount"
  634. }
  635. }`, fmt.Sprintf(`
  636. {
  637. "range": {
  638. "bidamount": {
  639. "gte": %s
  640. }
  641. }
  642. }
  643. `, gconv.String(minPrice))}
  644. budgetArr := []string{`
  645. {
  646. "exists": {
  647. "field": "budget"
  648. }
  649. }`, fmt.Sprintf(`
  650. {
  651. "range": {
  652. "budget": {
  653. "gte": %s
  654. }
  655. }
  656. }
  657. `, gconv.String(minPrice))}
  658. if maxPrice > 0 {
  659. bidamountArr = append(bidamountArr, fmt.Sprintf(`
  660. {
  661. "range": {
  662. "bidamount": {
  663. "lte": "%s"
  664. }
  665. }
  666. }
  667. `, gconv.String(minPrice)))
  668. budgetArr = append(budgetArr, fmt.Sprintf(`
  669. {
  670. "range": {
  671. "budget": {
  672. "lte": "%s"
  673. }
  674. }
  675. }
  676. `, gconv.String(minPrice)))
  677. }
  678. mustArr = append(mustArr, fmt.Sprintf(`{"bool":{"should":[{"bool":{"filter":[%s]}},{"bool":{"filter":[%s],"must_not":[{"exists":{"field":"bidamount"}}]}}]}}`, strings.Join(bidamountArr, ","), strings.Join(budgetArr, ",")))
  679. }
  680. //地区搜索
  681. area := []string{}
  682. city := []string{}
  683. district := []string{}
  684. if operator.Province != "" {
  685. for k, v := range gconv.Map(operator.Province) {
  686. area = append(area, gconv.String(k))
  687. for k1, v1 := range gconv.Map(v) {
  688. city = append(city, k1)
  689. for _, v3 := range gconv.SliceStr(v1) {
  690. district = append(district, fmt.Sprintf("%s_%s"), k1, v3)
  691. }
  692. }
  693. }
  694. if len(area) > 0 {
  695. query1 := ""
  696. query1 += `{"terms":{"area":[`
  697. for k, v := range strings.Split(operator.Province, ",") {
  698. if k > 0 {
  699. query1 += `,`
  700. }
  701. query1 += `"` + v + `"`
  702. }
  703. query1 += `]}}`
  704. filterArr = append(filterArr, query1)
  705. }
  706. //市--未登录用户不能根据市和地区筛选
  707. if len(city) > 0 {
  708. query1 := ""
  709. query1 += `{"terms":{"city":[`
  710. for k, v := range city {
  711. if k > 0 {
  712. query1 += `,`
  713. }
  714. query1 += `"` + v + `"`
  715. }
  716. query1 += `]}}`
  717. filterArr = append(filterArr, query1)
  718. }
  719. if len(district) > 0 {
  720. query1 := ""
  721. for k, v := range district {
  722. if k > 0 {
  723. query1 += `,`
  724. }
  725. cityName := strings.Split(v, "_")[0]
  726. districtName := strings.Split(v, "_")[1]
  727. queryBoolMustAndDistrict := `{"bool":{"must":[{"terms":{"city":["%s"]}},{"terms":{"district":["%s"]}}]}}`
  728. query1 += fmt.Sprintf(queryBoolMustAndDistrict, cityName, districtName)
  729. }
  730. filterArr = append(filterArr, query1)
  731. }
  732. }
  733. //行业处理
  734. if operator.Industry != "" {
  735. filterArr = append(filterArr, fmt.Sprintf(`{"match":{"industry":["%s"]}}`, strings.ReplaceAll(operator.Industry, ",", `","`)))
  736. }
  737. //中标人标签处理
  738. if operator.WinnerTag != "" {
  739. filterArr = append(filterArr, fmt.Sprintf(`{"match":{"winner_tag":["%s"]}}`, strings.ReplaceAll(operator.WinnerTag, ",", `","`)))
  740. }
  741. //查看自己是否定制
  742. /*configData := IC.BiMysql.SelectBySql(`SELECT
  743. MAX( CASE WHEN element_name = '行业' THEN element_value END ) AS industry,
  744. MAX( CASE WHEN element_name = '运营商中标标签' THEN element_value END ) AS winner_tag,
  745. MAX( CASE WHEN element_name = '地区' THEN element_value END ) AS region,
  746. MAX( CASE WHEN element_name = '经营单位' THEN element_value END ) AS tagname
  747. FROM
  748. bi_service.customer_data_yys_permissions
  749. WHERE
  750. is_delete = 0
  751. AND position_id = ?
  752. AND ent_id = ?`, operator.PositionId, operator.EntId)
  753. if configData != nil && len(*configData) > 0 {
  754. tagname := gconv.String((*configData)[0]["tagname"])
  755. region := gconv.String((*configData)[0]["region"])
  756. winner_tag := gconv.String((*configData)[0]["winner_tag"])
  757. industry := gconv.String((*configData)[0]["industry"])
  758. if tagname != "" {
  759. filterArr = append(filterArr, fmt.Sprintf(`{"terms":{"tagname":["%s"]}}`, strings.Join(strings.Split(tagname, ","), `","`)))
  760. }
  761. if region != "" {
  762. filterArr = append(filterArr, fmt.Sprintf(`{"terms":{"region":["%s"]}}`, strings.Join(strings.Split(region, ","), `","`)))
  763. }
  764. if winner_tag != "" {
  765. filterArr = append(filterArr, fmt.Sprintf(`{"terms":{"winner_tag":["%s"]}}`, strings.Join(strings.Split(winner_tag, ","), `","`)))
  766. }
  767. if industry != "" {
  768. filterArr = append(filterArr, fmt.Sprintf(`{"terms":{"industry":["%s"]}}`, strings.Join(strings.Split(industry, ","), `","`)))
  769. }
  770. }*/
  771. //es sql拼接
  772. queryStr := fmt.Sprintf(query, strings.Join(mustArr, ","), strings.Join(filterArr, ","), start, operator.PageSize)
  773. fmt.Println(queryStr)
  774. count, data := elastic.GetWithCount(yysIndex, yysType, "", queryStr)
  775. log.Println()
  776. return count, data
  777. }