operator.go 23 KB

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