operator.go 23 KB

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