operator.go 23 KB

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