operator.go 30 KB

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