operator.go 25 KB

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