operator.go 26 KB

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