operator.go 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853
  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.element_value as 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.element_value,a.element_value)
  293. and b.element_field=? order by code `, entId, conditionName, conditionType)
  294. options := []map[string]interface{}{}
  295. if data == nil {
  296. return options
  297. }
  298. if len(*data) == 0 {
  299. data = IC.BiMysql.SelectBySql(`SELECT
  300. DISTINCT name,element_value as code
  301. FROM
  302. customer_data_yys_permission_elements where
  303. ent_id = ?
  304. and element_field=? and pcode!="" order by code`, entId, conditionType)
  305. }
  306. if data != nil && len(*data) > 0 {
  307. options = append(options, map[string]interface{}{
  308. "label": "全部",
  309. "value": "",
  310. })
  311. for _, v := range *data {
  312. name := gconv.String(v["name"])
  313. code := gconv.Int64(v["code"])
  314. options = append(options, map[string]interface{}{
  315. "label": name,
  316. "value": code,
  317. })
  318. }
  319. }
  320. return options
  321. }
  322. func getLabel(entId int64) []map[string]interface{} {
  323. // 私有标签查询
  324. data := []map[string]interface{}{}
  325. labelArr := IC.BiMysql.SelectBySql(`SELECT * FROM private_label WHERE ent_id = ? AND level > 0 ORDER BY id`, entId)
  326. if labelArr != nil && len(*labelArr) != 0 {
  327. // 使用切片来存储一级标签及其对应的二级、三级标签
  328. labelIdArr := []int64{}
  329. labels := make(map[int64]map[string]interface{}) // 存储各级标签
  330. labelOptions := make(map[int64][]map[string]interface{}) // 存储各级标签的选项
  331. for _, m := range *labelArr {
  332. key := "tagname"
  333. switch len(labels) {
  334. case 1:
  335. key = "tagname1"
  336. case 2:
  337. key = "tagname2"
  338. }
  339. level := gconv.Int64(m["level"])
  340. name := gconv.String(m["name"])
  341. pid := gconv.Int64(m["pid"]) // 将 pid 转换为 int64
  342. id := gconv.Int64(m["id"]) // 将 id 转换为 int64
  343. if level == 1 {
  344. labelIdArr = append(labelIdArr, id)
  345. // 处理一级标签
  346. labels[id] = map[string]interface{}{
  347. "id": id,
  348. "key": key,
  349. "type": "selectList",
  350. "label": name,
  351. "defaultVal": []string{""},
  352. "props": map[string]interface{}{
  353. "multiple": true,
  354. },
  355. "options": []map[string]interface{}{}, // 初始化选项
  356. }
  357. } else {
  358. // 处理二级和三级标签
  359. if _, exists := labels[pid]; exists {
  360. if len(labelOptions[pid]) == 0 {
  361. labelOptions[pid] = append(labelOptions[pid], map[string]interface{}{
  362. "label": "全部",
  363. "value": "",
  364. })
  365. }
  366. labelOptions[pid] = append(labelOptions[pid], map[string]interface{}{
  367. "label": name,
  368. "value": name,
  369. })
  370. }
  371. }
  372. }
  373. // 将标签及其选项添加到最终数据中
  374. for _, m := range labelIdArr {
  375. for _, label := range labels {
  376. id := gconv.Int64(label["id"])
  377. if id == m {
  378. if options, exists := labelOptions[label["id"].(int64)]; exists && len(options) > 0 {
  379. label["options"] = options
  380. }
  381. data = append(data, label)
  382. }
  383. }
  384. }
  385. }
  386. return data
  387. }
  388. func getArea(entid, positionId int64, labelArr *[]map[string]interface{}) map[string]interface{} {
  389. data := make(map[string]map[string][]string)
  390. // 私有标签查询
  391. areaArr := IC.BiMysql.SelectBySql(`
  392. SELECT
  393. t0.area, t0.city, t0.district
  394. FROM
  395. bi_service.customer_data t0
  396. INNER JOIN (
  397. SELECT
  398. ent_id AS 企业_ID,
  399. MAX(CASE WHEN element_name = '行业' THEN element_value END) AS 行业要素值,
  400. MAX(CASE WHEN element_name = '运营商中标标签' THEN element_value END) AS 中标标签要素值,
  401. MAX(CASE WHEN element_name = '地区' THEN element_value END) AS 地区要素值,
  402. MAX(CASE WHEN element_name = '经营单位' THEN element_value END) AS 经营单位要素值
  403. FROM
  404. bi_service.customer_data_yys_permissions
  405. WHERE
  406. is_delete = 0 and position_id=? and ent_id=?
  407. ) t1 ON t0.eid = t1.企业_ID
  408. WHERE
  409. (t1.行业要素值 IS NULL OR FIND_IN_SET(t0.INDUSTRY, t1.行业要素值)) AND
  410. (t1.地区要素值 IS NULL OR FIND_IN_SET(t0.REGION, t1.地区要素值)) AND
  411. (t1.中标标签要素值 IS NULL OR FIND_IN_SET(t0.WINNER_TAG, t1.中标标签要素值)) AND
  412. (t1.经营单位要素值 IS NULL OR FIND_IN_SET(t0.tagname2, t1.经营单位要素值)) AND
  413. (t0.STATUS = 1)
  414. GROUP BY area, city, district`, positionId, entid)
  415. if areaArr == nil || len(*areaArr) == 0 {
  416. //查找全局变量
  417. areaArr = IC.BiMysql.SelectBySql(`
  418. SELECT
  419. area,
  420. city,
  421. district
  422. FROM
  423. customer_data
  424. WHERE
  425. eid = ?
  426. GROUP BY
  427. area,
  428. city,
  429. district
  430. ORDER BY
  431. area,
  432. city,
  433. district;`, entid)
  434. }
  435. if areaArr != nil && len(*areaArr) > 0 {
  436. for _, m := range *areaArr {
  437. area := gconv.String(m["area"])
  438. city := gconv.String(m["city"])
  439. district := gconv.String(m["district"])
  440. if area == "" || city == "" {
  441. continue // 跳过无效的区域或城市
  442. }
  443. if _, exists := data[area]; !exists {
  444. data[area] = make(map[string][]string)
  445. }
  446. if district != "" {
  447. data[area][city] = append(data[area][city], district)
  448. } else {
  449. data[area][city] = []string{} // 存储空数组以表示没有区
  450. }
  451. }
  452. }
  453. isCity, isDistrict := false, false
  454. for _, v := range *labelArr {
  455. configName := gconv.String(v["config_name"])
  456. if configName == "城市" {
  457. isCity = true
  458. } else if configName == "区县" {
  459. isDistrict = true
  460. }
  461. }
  462. if !isCity {
  463. //没有设置市区
  464. for k := range data {
  465. data[k] = map[string][]string{}
  466. }
  467. } else if !isDistrict {
  468. //没有设置区县
  469. for k, v := range data {
  470. for k1 := range v {
  471. v[k1] = []string{}
  472. }
  473. data[k] = v
  474. }
  475. }
  476. if len(data) > 0 {
  477. return map[string]interface{}{
  478. "key": "province",
  479. "type": "component-popup-area",
  480. "label": "城市",
  481. "defaultVal": "",
  482. "options": data,
  483. }
  484. }
  485. return map[string]interface{}{}
  486. }
  487. type Operator struct {
  488. EntId int64 //企业id 没有企业 企业id=0
  489. Tag int64
  490. PageNum int64 //当前页码
  491. PageSize int64 //每页数量
  492. Province string //省份
  493. TopType string //信息类型-二级
  494. PublishTime string //发布时间
  495. SelectType string //搜索范围:标题;正文等
  496. Price string //价格
  497. Tagname string
  498. Tagname1 string
  499. Tagname2 string
  500. WordsMode int64 //搜索关键词模式;默认0:包含所有,1:包含任意
  501. KeyWords string //关键词:多个空格隔开(主)
  502. PurchaseTime string //采购时间
  503. OpeningTime string //开标时间
  504. Industry string
  505. WinnerTag string
  506. PositionId int64
  507. Order int64
  508. }
  509. func SearchList(operator Operator) (int64, *[]map[string]interface{}, int64) {
  510. if operator.PageSize == 0 {
  511. operator.PageSize = 10
  512. }
  513. start := (operator.PageNum - 1) * operator.PageSize
  514. if start < 0 {
  515. start = 0
  516. }
  517. var query = `{"query":{"bool":{"must":[%s],"filter":[%s],"minimum_should_match":1,
  518. "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]
  519. }`
  520. shouldStr := `{"bool":{"should":[%s]}}`
  521. mustArr := []string{}
  522. filterArr := []string{
  523. fmt.Sprintf(`{"match":{"ent_id":"%s"}}`, gconv.String(operator.EntId)),
  524. }
  525. //must处理
  526. //filter处理
  527. if operator.Tag == 1 {
  528. filterArr = append(filterArr, `{"match":{"toptype":"采购意向"}}`)
  529. operator.TopType = ""
  530. } else if operator.Tag == 2 {
  531. mustArr = append(mustArr, `{"exists":{"field":"bidopentime"}}`)
  532. operator.TopType = ""
  533. }
  534. if operator.PublishTime != "" {
  535. pushTime := strings.Split(operator.PublishTime, "_")
  536. for k, v := range pushTime {
  537. if k == 0 {
  538. if v != "" {
  539. filterArr = append(filterArr, fmt.Sprintf(`{"range":{"publishtime":{"gte":"%s"}}}`, v))
  540. }
  541. }
  542. if k == 1 {
  543. if v != "" {
  544. filterArr = append(filterArr, fmt.Sprintf(`{"range":{"publishtime":{"lt":"%s"}}}`, v))
  545. }
  546. }
  547. }
  548. }
  549. //采购时间
  550. if operator.PurchaseTime != "" {
  551. purchaseTime := strings.Split(operator.PurchaseTime, "_")
  552. for k, v := range purchaseTime {
  553. if k == 0 {
  554. if v != "" {
  555. filterArr = append(filterArr, fmt.Sprintf(`{"range":{"expurasingtime":{"gte":"%s"}}}`, v))
  556. }
  557. }
  558. if k == 1 {
  559. if v != "" {
  560. filterArr = append(filterArr, fmt.Sprintf(`{"range":{"expurasingtime":{"lt":"%s"}}}`, v))
  561. }
  562. }
  563. }
  564. }
  565. //开标时间
  566. if operator.OpeningTime != "" {
  567. openingTime := strings.Split(operator.OpeningTime, "_")
  568. for k, v := range openingTime {
  569. if k == 0 {
  570. if v != "" {
  571. filterArr = append(filterArr, fmt.Sprintf(`{"range":{"bidopentime":{"gte":"%s"}}}`, v))
  572. }
  573. }
  574. if k == 1 {
  575. if v != "" {
  576. filterArr = append(filterArr, fmt.Sprintf(`{"range":{"bidopentime":{"lt":"%s"}}}`, v))
  577. }
  578. }
  579. }
  580. }
  581. //关键词
  582. if operator.KeyWords != "" {
  583. if operator.WordsMode == 1 {
  584. keyArr := []string{}
  585. for _, v := range strings.Split(operator.KeyWords, ",") {
  586. keyArr = append(keyArr, fmt.Sprintf(`{"match_phrase":{"%s":"%s"}}`, operator.SelectType, v))
  587. }
  588. mustArr = append(mustArr, fmt.Sprintf(shouldStr, strings.Join(keyArr, ",")))
  589. } else {
  590. for _, v := range strings.Split(operator.KeyWords, ",") {
  591. filterArr = append(filterArr, fmt.Sprintf(`{"match_phrase":{"%s":"%s"}}`, operator.SelectType, v))
  592. }
  593. }
  594. }
  595. //信息类型一级
  596. //{"match":{"toptype":"结果"}},{"terms":{"subtype":["结果变更","中标"]}}
  597. topType := []string{}
  598. subtype := []string{}
  599. if operator.TopType != "" {
  600. for k, v := range gconv.Map(operator.TopType) {
  601. topType = append(topType, k)
  602. for _, v1 := range gconv.Interfaces(v) {
  603. subtype = append(subtype, gconv.String(v1))
  604. }
  605. }
  606. if len(topType) > 0 {
  607. filterArr = append(filterArr, fmt.Sprintf(`{"match":{"toptype":"%s"}}`, strings.Join(topType, `","`)))
  608. }
  609. //信息类型二级
  610. if len(subtype) > 0 {
  611. filterArr = append(filterArr, fmt.Sprintf(`{"terms":{"subtype":["%s"]}}`, strings.Join(subtype, `","`)))
  612. }
  613. }
  614. //私有标签1
  615. if operator.Tagname != "" {
  616. keyArr := []string{}
  617. for _, v := range strings.Split(operator.Tagname, ",") {
  618. keyArr = append(keyArr, fmt.Sprintf(`{"wildcard":{"tagname":"*%s"}}`, v))
  619. }
  620. mustArr = append(mustArr, fmt.Sprintf(shouldStr, strings.Join(keyArr, ",")))
  621. }
  622. //私有标签2
  623. if operator.Tagname1 != "" {
  624. keyArr := []string{}
  625. for _, v := range strings.Split(operator.Tagname1, ",") {
  626. keyArr = append(keyArr, fmt.Sprintf(`{"wildcard":{"tagname":"*%s*"}}`, v))
  627. }
  628. mustArr = append(mustArr, fmt.Sprintf(shouldStr, strings.Join(keyArr, ",")))
  629. }
  630. //私有标签3
  631. if operator.Tagname2 != "" {
  632. keyArr := []string{}
  633. for _, v := range strings.Split(operator.Tagname2, ",") {
  634. keyArr = append(keyArr, fmt.Sprintf(`{"wildcard":{"tagname":"%s"}}`, v))
  635. }
  636. mustArr = append(mustArr, fmt.Sprintf(shouldStr, strings.Join(keyArr, ",")))
  637. }
  638. //价格处理
  639. if operator.Price != "" {
  640. priceArr := strings.Split(operator.Price, "_")
  641. minPrice := gconv.Int64(priceArr[0]) * 10000
  642. maxPrice := gconv.Int64(priceArr[1]) * 10000
  643. bidamountArr := []string{`
  644. {
  645. "exists": {
  646. "field": "bidamount"
  647. }
  648. }`, fmt.Sprintf(`
  649. {
  650. "range": {
  651. "bidamount": {
  652. "gte": "%s"
  653. }
  654. }
  655. }
  656. `, gconv.String(minPrice))}
  657. budgetArr := []string{`
  658. {
  659. "exists": {
  660. "field": "budget"
  661. }
  662. }`, fmt.Sprintf(`
  663. {
  664. "range": {
  665. "budget": {
  666. "gte": "%s"
  667. }
  668. }
  669. }
  670. `, gconv.String(minPrice))}
  671. if maxPrice > 0 {
  672. bidamountArr = append(bidamountArr, fmt.Sprintf(`
  673. {
  674. "range": {
  675. "bidamount": {
  676. "lte": "%s"
  677. }
  678. }
  679. }
  680. `, gconv.String(maxPrice)))
  681. budgetArr = append(budgetArr, fmt.Sprintf(`
  682. {
  683. "range": {
  684. "budget": {
  685. "lte": "%s"
  686. }
  687. }
  688. }
  689. `, gconv.String(maxPrice)))
  690. }
  691. mustArr = append(mustArr, fmt.Sprintf(`{"bool":{"should":[{"bool":{"filter":[%s]}},{"bool":{"filter":[%s],"must_not":[{"exists":{"field":"bidamount"}}]}}]}}`, strings.Join(bidamountArr, ","), strings.Join(budgetArr, ",")))
  692. }
  693. //地区搜索
  694. area := []string{}
  695. city := []string{}
  696. district := []string{}
  697. if operator.Province != "" {
  698. for k, v := range gconv.Map(operator.Province) {
  699. area = append(area, gconv.String(k))
  700. for k1, v1 := range gconv.Map(v) {
  701. city = append(city, k1)
  702. for _, v3 := range gconv.SliceStr(v1) {
  703. district = append(district, v3)
  704. }
  705. }
  706. }
  707. if len(area) > 0 {
  708. query1 := ""
  709. query1 += `{"terms":{"area":[`
  710. for k, v := range area {
  711. if k > 0 {
  712. query1 += `,`
  713. }
  714. query1 += `"` + v + `"`
  715. }
  716. query1 += `]}}`
  717. filterArr = append(filterArr, query1)
  718. }
  719. //市--未登录用户不能根据市和地区筛选
  720. if len(city) > 0 {
  721. query1 := ""
  722. query1 += `{"terms":{"city":[`
  723. for k, v := range city {
  724. if k > 0 {
  725. query1 += `,`
  726. }
  727. query1 += `"` + v + `"`
  728. }
  729. query1 += `]}}`
  730. filterArr = append(filterArr, query1)
  731. }
  732. if len(district) > 0 {
  733. query1 := ""
  734. query1 += `{"terms":{"district":[`
  735. for k, v := range district {
  736. if k > 0 {
  737. query1 += `,`
  738. }
  739. query1 += `"` + v + `"`
  740. }
  741. query1 += `]}}`
  742. filterArr = append(filterArr, query1)
  743. }
  744. }
  745. //行业处理
  746. if operator.Industry != "" {
  747. filterArr = append(filterArr, fmt.Sprintf(`{"terms":{"industry":["%s"]}}`, strings.ReplaceAll(operator.Industry, ",", `","`)))
  748. }
  749. //中标人标签处理
  750. if operator.WinnerTag != "" {
  751. filterArr = append(filterArr, fmt.Sprintf(`{"terms":{"winner_tag":["%s"]}}`, strings.ReplaceAll(operator.WinnerTag, ",", `","`)))
  752. }
  753. //查看自己是否定制
  754. /*configData := IC.BiMysql.SelectBySql(`SELECT
  755. MAX( CASE WHEN element_name = '行业' THEN element_value END ) AS industry,
  756. MAX( CASE WHEN element_name = '运营商中标标签' THEN element_value END ) AS winner_tag,
  757. MAX( CASE WHEN element_name = '地区' THEN element_value END ) AS region,
  758. MAX( CASE WHEN element_name = '经营单位' THEN element_value END ) AS tagname
  759. FROM
  760. bi_service.customer_data_yys_permissions
  761. WHERE
  762. is_delete = 0
  763. AND position_id = ?
  764. AND ent_id = ?`, operator.PositionId, operator.EntId)
  765. if configData != nil && len(*configData) > 0 {
  766. tagname := gconv.String((*configData)[0]["tagname"])
  767. region := gconv.String((*configData)[0]["region"])
  768. winner_tag := gconv.String((*configData)[0]["winner_tag"])
  769. industry := gconv.String((*configData)[0]["industry"])
  770. if tagname != "" {
  771. filterArr = append(filterArr, fmt.Sprintf(`{"terms":{"tagname":["%s"]}}`, strings.Join(strings.Split(tagname, ","), `","`)))
  772. }
  773. if region != "" {
  774. filterArr = append(filterArr, fmt.Sprintf(`{"terms":{"region":["%s"]}}`, strings.Join(strings.Split(region, ","), `","`)))
  775. }
  776. if winner_tag != "" {
  777. filterArr = append(filterArr, fmt.Sprintf(`{"terms":{"winner_tag":["%s"]}}`, strings.Join(strings.Split(winner_tag, ","), `","`)))
  778. }
  779. if industry != "" {
  780. filterArr = append(filterArr, fmt.Sprintf(`{"terms":{"industry":["%s"]}}`, strings.Join(strings.Split(industry, ","), `","`)))
  781. }
  782. }*/
  783. //es sql拼接
  784. queryStr := ""
  785. orderStr := ""
  786. mysqlOrderStr := ""
  787. if operator.Tag == 1 {
  788. if operator.Order == 0 {
  789. orderStr = `{"publishtime":{"order":"desc"}}`
  790. mysqlOrderStr = ` order by publishtime desc`
  791. } else {
  792. orderStr = `{"publishtime":{"order":"asc"}}`
  793. mysqlOrderStr = ` order by publishtime asc`
  794. }
  795. } else if operator.Tag == 2 {
  796. if operator.Order == 0 {
  797. orderStr = `{"publishtime":{"order":"desc"}}`
  798. mysqlOrderStr = ` order by publishtime desc`
  799. } else {
  800. orderStr = `{"expurasingtime":{"order":"asc"}}`
  801. mysqlOrderStr = ` order by expurasingtime asc`
  802. }
  803. } else {
  804. if operator.Order == 0 {
  805. orderStr = `{"publishtime":{"order":"desc"}}`
  806. mysqlOrderStr = ` order by publishtime desc`
  807. } else {
  808. orderStr = `{"bidopentime":{"order":"asc"}}`
  809. mysqlOrderStr = ` order by bidopentime asc`
  810. }
  811. }
  812. queryStr = fmt.Sprintf(query, strings.Join(mustArr, ","), strings.Join(filterArr, ","), start, operator.PageSize, orderStr)
  813. fmt.Println(queryStr)
  814. start1 := time.Now().Unix()
  815. fmt.Println(start1)
  816. var count int64
  817. var data *[]map[string]interface{}
  818. count, data = elastic.GetWithCount(yysIndex, yysType, "", queryStr)
  819. end1 := time.Now().Unix()
  820. fmt.Println(end1)
  821. fmt.Println("时差", end1-start1)
  822. if len(*data) > 0 {
  823. //查询tidb真实数据
  824. idArr := []interface{}{}
  825. wh := []string{}
  826. for _, v := range *data {
  827. id := gconv.String(v["id"])
  828. idArr = append(idArr, id)
  829. wh = append(wh, "?")
  830. }
  831. sqlStr := fmt.Sprintf(`select * from customer_data where id in (%s) %s `, strings.Join(wh, ","), mysqlOrderStr)
  832. fmt.Println(sqlStr, idArr)
  833. data = IC.BiMysql.SelectBySql(sqlStr,
  834. idArr...)
  835. total := count
  836. count = gconv.Int64(common.If(count > 2000, 2000, count))
  837. return count, data, total
  838. } else {
  839. return count, &[]map[string]interface{}{}, 0
  840. }
  841. }