123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837 |
- package service
- import (
- elastic "app.yhyue.com/moapp/jybase/es"
- IC "bp.jydev.jianyu360.cn/BaseService/jyMicroservices/jyBXCore/rpc/init"
- "fmt"
- "github.com/gogf/gf/v2/util/gconv"
- "strings"
- "time"
- )
- var (
- yysIndex = "bidding_customer"
- yysType = "bidding_customer"
- )
- func GetCriteria(entId, positionId int64) map[int]interface{} {
- result := map[int]interface{}{}
- //for i := 0; i < 1; i++ {
- for i := 0; i < 3; i++ {
- result[i] = getGetCriteriaType(entId, positionId, int64(i))
- }
- return result
- }
- func getGetCriteriaType(entId, positionId, tag int64) []map[string]interface{} {
- data := []map[string]interface{}{}
- if tag == 1 {
- data = append(data, map[string]interface{}{
- "key": "purchaseTime",
- "type": "dateTimeList",
- "label": "预计采购时间",
- "defaultVal": "",
- "props": map[string]interface{}{
- "multiple": false,
- "endTimeFeature": true,
- },
- "options": []map[string]interface{}{
- {
- "label": "全部", "value": "",
- },
- {
- "label": "本月", "value": "thisMonth",
- },
- {
- "label": "下月", "value": "nextMonth",
- },
- {
- "label": "自定义", "value": "exact",
- },
- },
- })
- } else if tag == 2 {
- data = append(data, map[string]interface{}{
- "key": "openingTime",
- "type": "dateTimeList",
- "label": "开标日期",
- "defaultVal": "",
- "props": map[string]interface{}{
- "multiple": false,
- "endTimeFeature": true,
- },
- "options": []map[string]interface{}{
- {
- "label": "全部", "value": "",
- },
- {
- "label": "本周", "value": "thisWeek",
- },
- {
- "label": "下周", "value": "nextWeek",
- },
- {
- "label": "本月", "value": "thisMonth",
- },
- {
- "label": "自定义", "value": "exact",
- },
- },
- })
- }
- //发布时间
- data = append(data, map[string]interface{}{
- "key": "publishTime",
- "type": "dateTimeList",
- "label": "发布时间",
- "defaultVal": "",
- "props": map[string]interface{}{
- "multiple": false,
- "endTimeFeature": true,
- },
- "options": []map[string]interface{}{
- {
- "label": "全部", "value": "",
- },
- {
- "label": "昨天", "value": "yesterday",
- },
- {
- "label": "上周", "value": "lastWeek",
- },
- {
- "label": "上一个月", "value": "lastMonth",
- },
- {
- "label": "自定义", "value": "exact",
- },
- },
- })
- //私有标签处理
- getlalArr := getLabel(entId)
- if len(getlalArr) > 0 {
- data = append(data, getlalArr...)
- }
- //查询都显示什么数据
- labelArr := IC.BiMysql.SelectBySql(`SELECT * FROM customer_data_yys_config WHERE ent_id = ? and config_type="筛选条件" and config_class=? ORDER BY id`, entId, tag)
- if labelArr != nil && len(*labelArr) > 0 {
- for _, v := range *labelArr {
- configName := gconv.String(v["config_name"])
- switch configName {
- case "行业":
- industryArr := getConfiguration("行业", "industry", entId)
- if len(industryArr) > 0 {
- data = append(data, map[string]interface{}{
- "key": "industry",
- "type": "selectList",
- "label": "行业",
- "defaultVal": []string{""},
- "props": map[string]interface{}{
- "multiple": true,
- },
- "options": industryArr,
- })
- }
- case "中标人标签":
- winnerArr := getConfiguration("运营商中标标签", "winner_tag", entId)
- if len(winnerArr) > 0 {
- data = append(data, map[string]interface{}{
- "key": "winnerTag",
- "type": "selectList",
- "label": "中标人标签",
- "defaultVal": []string{""},
- "props": map[string]interface{}{
- "multiple": true,
- },
- "options": winnerArr,
- })
- }
- case "信息类型":
- //查看是否有二级信息
- isExist := false
- for _, v := range *labelArr {
- configName1 := gconv.String(v["config_name"])
- if configName1 == "信息类型二级" {
- isExist = true
- }
- }
- if isExist {
- data = append(data, map[string]interface{}{
- "key": "topType",
- "type": "component-popup-infotype",
- "label": "信息类型",
- "cascader": true,
- "collectionMark": 1,
- "defaultVal": "",
- "childLabel": "信息类型二级",
- "props": map[string]interface{}{
- "multiple": false,
- },
- "options": []map[string]interface{}{
- {
- "label": "全部",
- "value": "",
- "children": []map[string]interface{}{},
- },
- {
- "label": "预告",
- "value": "预告",
- "children": []map[string]interface{}{
- {"label": "预告", "value": "预告"},
- {"label": "预审", "value": "预审"},
- {"label": "预审结果", "value": "预审结果"},
- {"label": "论证意见", "value": "论证意见"},
- {"label": "需求公示", "value": "需求公示"},
- {"label": "其它", "value": "其它"},
- },
- }, {
- "label": "招标",
- "value": "招标",
- "children": []map[string]interface{}{
- {"label": "变更", "value": "变更"},
- {"label": "邀标", "value": "邀标"},
- {"label": "询价", "value": "询价"},
- {"label": "竞谈", "value": "竞谈"},
- {"label": "单一", "value": "单一"},
- {"label": "竞价", "value": "竞价"},
- {"label": "招标", "value": "招标"},
- {"label": "其它", "value": "其它"},
- },
- }, {
- "label": "结果",
- "value": "结果",
- "children": []map[string]interface{}{
- {"label": "废标", "value": "废标"},
- {"label": "流标", "value": "流标"},
- {"label": "结果变更", "value": "结果变更"},
- {"label": "中标", "value": "中标"},
- {"label": "成交", "value": "成交"},
- {"label": "其它", "value": "其它"},
- },
- }, {
- "label": "采购意向",
- "value": "采购意向",
- "children": []map[string]interface{}{
- {"label": "采购意向", "value": "采购意向"},
- },
- }, {
- "label": "拟建",
- "value": "拟建",
- "children": []map[string]interface{}{
- {"label": "拟建", "value": "拟建"},
- },
- }, {
- "label": "其它",
- "value": "其它",
- "children": []map[string]interface{}{
- {"label": "合同", "value": "合同"},
- {"label": "验收", "value": "验收"},
- {"label": "违规", "value": "违规"},
- {"label": "其它", "value": "其它"},
- },
- }}})
- } else {
- data = append(data, map[string]interface{}{
- "key": "topType",
- "type": "selectList",
- "label": "信息类型",
- "cascader": true,
- "collectionMark": 1,
- "defaultVal": "",
- "props": map[string]interface{}{
- "multiple": false,
- },
- "options": []map[string]interface{}{
- {
- "label": "全部",
- "value": "",
- "children": []map[string]interface{}{},
- },
- {
- "label": "预告",
- "value": "预告",
- "children": []map[string]interface{}{},
- }, {
- "label": "招标",
- "value": "招标",
- "children": []map[string]interface{}{},
- }, {
- "label": "结果",
- "value": "结果",
- "children": []map[string]interface{}{},
- }, {
- "label": "采购意向",
- "value": "采购意向",
- "children": []map[string]interface{}{},
- }, {
- "label": "拟建",
- "value": "拟建",
- "children": []map[string]interface{}{},
- }, {
- "label": "其它",
- "value": "其它",
- "children": []map[string]interface{}{},
- }}})
- }
- case "省份":
- areaMap := getArea(entId, positionId, labelArr)
- if areaMap != nil && len(areaMap) != 0 {
- data = append(data, areaMap)
- }
- }
- }
- }
- return data
- }
- func getConfiguration(conditionName, conditionType string, entId int64) []map[string]interface{} {
- data := IC.BiMysql.SelectBySql(`SELECT
- DISTINCT b.name,b.code
- FROM
- customer_data_yys_permissions a INNER JOIN customer_data_yys_permission_elements b
- on
- a.ent_id = ?
- and a.is_delete = 0
- AND a.element_name = ?
- and FIND_IN_SET( b.code,a.element_value)
- and b.element_field=?`, entId, conditionName, conditionType)
- options := []map[string]interface{}{}
- if data != nil && len(*data) > 0 {
- options = append(options, map[string]interface{}{
- "label": "全部",
- "value": "",
- })
- for _, v := range *data {
- name := gconv.String(v["name"])
- code := gconv.Int64(v["code"])
- options = append(options, map[string]interface{}{
- "label": name,
- "value": code,
- })
- }
- }
- return options
- }
- func getLabel(entId int64) []map[string]interface{} {
- // 私有标签查询
- data := []map[string]interface{}{}
- labelArr := IC.BiMysql.SelectBySql(`SELECT * FROM private_label WHERE ent_id = ? AND level > 0 ORDER BY id`, entId)
- if labelArr != nil && len(*labelArr) != 0 {
- // 使用切片来存储一级标签及其对应的二级、三级标签
- labelIdArr := []int64{}
- labels := make(map[int64]map[string]interface{}) // 存储各级标签
- labelOptions := make(map[int64][]map[string]interface{}) // 存储各级标签的选项
- for _, m := range *labelArr {
- key := "tagname"
- switch len(labels) {
- case 1:
- key = "tagname1"
- case 2:
- key = "tagname2"
- }
- level := gconv.Int64(m["level"])
- name := gconv.String(m["name"])
- pid := gconv.Int64(m["pid"]) // 将 pid 转换为 int64
- id := gconv.Int64(m["id"]) // 将 id 转换为 int64
- if level == 1 {
- labelIdArr = append(labelIdArr, id)
- // 处理一级标签
- labels[id] = map[string]interface{}{
- "id": id,
- "key": key,
- "type": "selectList",
- "label": name,
- "defaultVal": []string{""},
- "props": map[string]interface{}{
- "multiple": true,
- },
- "options": []map[string]interface{}{}, // 初始化选项
- }
- } else {
- // 处理二级和三级标签
- if _, exists := labels[pid]; exists {
- if len(labelOptions[pid]) == 0 {
- labelOptions[pid] = append(labelOptions[pid], map[string]interface{}{
- "label": "全部",
- "value": "",
- })
- }
- labelOptions[pid] = append(labelOptions[pid], map[string]interface{}{
- "label": name,
- "value": name,
- })
- }
- }
- }
- // 将标签及其选项添加到最终数据中
- for _, m := range labelIdArr {
- for _, label := range labels {
- id := gconv.Int64(label["id"])
- if id == m {
- if options, exists := labelOptions[label["id"].(int64)]; exists && len(options) > 0 {
- label["options"] = options
- }
- data = append(data, label)
- }
- }
- }
- }
- return data
- }
- func getArea(entid, positionId int64, labelArr *[]map[string]interface{}) map[string]interface{} {
- data := make(map[string]map[string][]string)
- // 私有标签查询
- areaArr := IC.BiMysql.SelectBySql(`
- SELECT
- t0.area, t0.city, t0.district
- FROM
- bi_service.customer_data t0
- INNER JOIN (
- SELECT
- ent_id AS 企业_ID,
- MAX(CASE WHEN element_name = '行业' THEN element_value END) AS 行业要素值,
- MAX(CASE WHEN element_name = '运营商中标标签' THEN element_value END) AS 中标标签要素值,
- MAX(CASE WHEN element_name = '地区' THEN element_value END) AS 地区要素值,
- MAX(CASE WHEN element_name = '经营单位' THEN element_value END) AS 经营单位要素值
- FROM
- bi_service.customer_data_yys_permissions
- WHERE
- is_delete = 0 and position_id=? and ent_id=?
- ) t1 ON t0.eid = t1.企业_ID
- WHERE
- (t1.行业要素值 IS NULL OR FIND_IN_SET(t0.INDUSTRY, t1.行业要素值)) AND
- (t1.地区要素值 IS NULL OR FIND_IN_SET(t0.REGION, t1.地区要素值)) AND
- (t1.中标标签要素值 IS NULL OR FIND_IN_SET(t0.WINNER_TAG, t1.中标标签要素值)) AND
- (t1.经营单位要素值 IS NULL OR FIND_IN_SET(t0.tagname2, t1.经营单位要素值)) AND
- (t0.STATUS = 1)
- GROUP BY area, city, district`, positionId, entid)
- if areaArr == nil || len(*areaArr) == 0 {
- //查找全局变量
- areaArr = IC.BiMysql.SelectBySql(`
- SELECT
- area,
- city,
- district
- FROM
- customer_data
- WHERE
- eid = ?
- GROUP BY
- area,
- city,
- district
- ORDER BY
- area,
- city,
- district;`, entid)
- }
- if areaArr != nil && len(*areaArr) > 0 {
- for _, m := range *areaArr {
- area := gconv.String(m["area"])
- city := gconv.String(m["city"])
- district := gconv.String(m["district"])
- if area == "" || city == "" {
- continue // 跳过无效的区域或城市
- }
- if _, exists := data[area]; !exists {
- data[area] = make(map[string][]string)
- }
- if district != "" {
- data[area][city] = append(data[area][city], district)
- } else {
- data[area][city] = []string{} // 存储空数组以表示没有区
- }
- }
- }
- isCity, isDistrict := false, false
- for _, v := range *labelArr {
- configName := gconv.String(v["config_name"])
- if configName == "城市" {
- isCity = true
- } else if configName == "区县" {
- isDistrict = true
- }
- }
- if !isCity {
- //没有设置市区
- for k := range data {
- data[k] = map[string][]string{}
- }
- } else if !isDistrict {
- //没有设置区县
- for k, v := range data {
- for k1 := range v {
- v[k1] = []string{}
- }
- data[k] = v
- }
- }
- if len(data) > 0 {
- return map[string]interface{}{
- "key": "province",
- "type": "component-popup-area",
- "label": "城市",
- "defaultVal": "",
- "options": data,
- }
- }
- return map[string]interface{}{}
- }
- type Operator struct {
- EntId int64 //企业id 没有企业 企业id=0
- Tag int64
- PageNum int64 //当前页码
- PageSize int64 //每页数量
- Province string //省份
- TopType string //信息类型-二级
- PublishTime string //发布时间
- SelectType string //搜索范围:标题;正文等
- Price string //价格
- Tagname string
- Tagname1 string
- Tagname2 string
- WordsMode int64 //搜索关键词模式;默认0:包含所有,1:包含任意
- KeyWords string //关键词:多个空格隔开(主)
- PurchaseTime string //采购时间
- OpeningTime string //开标时间
- Industry string
- WinnerTag string
- PositionId int64
- Order int64
- }
- func SearchList(operator Operator) (int64, *[]map[string]interface{}) {
- if operator.PageSize == 0 {
- operator.PageSize = 10
- }
- start := (operator.PageNum - 1) * operator.PageSize
- if start < 0 {
- start = 0
- }
- var query = `{"query":{"bool":{"must":[%s],"filter":[%s],"minimum_should_match":1,
- "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]
- }`
- shouldStr := `{"bool":{"should":[%s]}}`
- mustArr := []string{}
- filterArr := []string{
- fmt.Sprintf(`{"match":{"ent_id":"%s"}}`, gconv.String(operator.EntId)),
- }
- //must处理
- //filter处理
- if operator.Tag == 1 {
- filterArr = append(filterArr, `{"match":{"toptype":"采购意向"}}`)
- operator.TopType = ""
- } else if operator.Tag == 2 {
- mustArr = append(mustArr, `{"exists":{"field":"bidopentime"}}`)
- operator.TopType = ""
- }
- if operator.PublishTime != "" {
- pushTime := strings.Split(operator.PublishTime, "_")
- for k, v := range pushTime {
- if k == 0 {
- if v != "" {
- filterArr = append(filterArr, fmt.Sprintf(`{"range":{"publishtime":{"gte":"%s"}}}`, v))
- }
- }
- if k == 1 {
- if v != "" {
- filterArr = append(filterArr, fmt.Sprintf(`{"range":{"publishtime":{"lt":"%s"}}}`, v))
- }
- }
- }
- }
- //采购时间
- if operator.PurchaseTime != "" {
- purchaseTime := strings.Split(operator.PurchaseTime, "_")
- for k, v := range purchaseTime {
- if k == 0 {
- if v != "" {
- filterArr = append(filterArr, fmt.Sprintf(`{"range":{"expurasingtime":{"gte":"%s"}}}`, v))
- }
- }
- if k == 1 {
- if v != "" {
- filterArr = append(filterArr, fmt.Sprintf(`{"range":{"expurasingtime":{"lt":"%s"}}}`, v))
- }
- }
- }
- }
- //开标时间
- if operator.OpeningTime != "" {
- openingTime := strings.Split(operator.OpeningTime, "_")
- for k, v := range openingTime {
- if k == 0 {
- if v != "" {
- filterArr = append(filterArr, fmt.Sprintf(`{"range":{"bidopentime":{"gte":"%s"}}}`, v))
- }
- }
- if k == 1 {
- if v != "" {
- filterArr = append(filterArr, fmt.Sprintf(`{"range":{"bidopentime":{"lt":"%s"}}}`, v))
- }
- }
- }
- }
- //关键词
- if operator.KeyWords != "" {
- if operator.WordsMode == 1 {
- keyArr := []string{}
- for _, v := range strings.Split(operator.KeyWords, ",") {
- keyArr = append(keyArr, fmt.Sprintf(`{"match_phrase":{"%s":"%s"}`, operator.SelectType, v))
- }
- mustArr = append(mustArr, fmt.Sprintf(shouldStr, strings.Join(keyArr, ",")))
- } else {
- for _, v := range strings.Split(operator.KeyWords, ",") {
- filterArr = append(filterArr, fmt.Sprintf(`{"match_phrase":{"%s":"%s"}}`, operator.SelectType, v))
- }
- }
- }
- //信息类型一级
- //{"match":{"toptype":"结果"}},{"terms":{"subtype":["结果变更","中标"]}}
- topType := []string{}
- subtype := []string{}
- if operator.TopType != "" {
- for k, v := range gconv.Map(operator.TopType) {
- topType = append(topType, k)
- for _, v1 := range gconv.Interfaces(v) {
- subtype = append(subtype, gconv.String(v1))
- }
- }
- if len(topType) > 0 {
- filterArr = append(filterArr, fmt.Sprintf(`{"match":{"toptype":"%s"}}`), strings.Join(topType, `","`))
- }
- //信息类型二级
- if len(subtype) > 0 {
- filterArr = append(filterArr, fmt.Sprintf(`{"match":{"subtype":["%s"]}}`, strings.Join(subtype, `","`)))
- }
- }
- //私有标签1
- if operator.Tagname != "" {
- keyArr := []string{}
- for _, v := range strings.Split(operator.Tagname, ",") {
- keyArr = append(keyArr, fmt.Sprintf(`{"wildcard":{"tagname":"*%s"}}`, v))
- }
- mustArr = append(mustArr, fmt.Sprintf(shouldStr, strings.Join(keyArr, ",")))
- }
- //私有标签2
- if operator.Tagname1 != "" {
- keyArr := []string{}
- for _, v := range strings.Split(operator.Tagname1, ",") {
- keyArr = append(keyArr, fmt.Sprintf(`{"wildcard":{"tagname":"*%s*"}}`, v))
- }
- mustArr = append(mustArr, fmt.Sprintf(shouldStr, strings.Join(keyArr, ",")))
- }
- //私有标签3
- if operator.Tagname2 != "" {
- keyArr := []string{}
- for _, v := range strings.Split(operator.Tagname2, ",") {
- keyArr = append(keyArr, fmt.Sprintf(`{"wildcard":{"tagname":"%s"}}`, v))
- }
- mustArr = append(mustArr, fmt.Sprintf(shouldStr, strings.Join(keyArr, ",")))
- }
- //价格处理
- if operator.Price != "" {
- priceArr := strings.Split(operator.Price, "-")
- minPrice := gconv.Int64(priceArr[0])
- maxPrice := gconv.Int64(priceArr[1])
- bidamountArr := []string{`
- {
- "exists": {
- "field": "bidamount"
- }
- }`, fmt.Sprintf(`
- {
- "range": {
- "bidamount": {
- "gte": %s
- }
- }
- }
- `, gconv.String(minPrice))}
- budgetArr := []string{`
- {
- "exists": {
- "field": "budget"
- }
- }`, fmt.Sprintf(`
- {
- "range": {
- "budget": {
- "gte": %s
- }
- }
- }
- `, gconv.String(minPrice))}
- if maxPrice > 0 {
- bidamountArr = append(bidamountArr, fmt.Sprintf(`
- {
- "range": {
- "bidamount": {
- "lte": "%s"
- }
- }
- }
- `, gconv.String(minPrice)))
- budgetArr = append(budgetArr, fmt.Sprintf(`
- {
- "range": {
- "budget": {
- "lte": "%s"
- }
- }
- }
- `, gconv.String(minPrice)))
- }
- mustArr = append(mustArr, fmt.Sprintf(`{"bool":{"should":[{"bool":{"filter":[%s]}},{"bool":{"filter":[%s],"must_not":[{"exists":{"field":"bidamount"}}]}}]}}`, strings.Join(bidamountArr, ","), strings.Join(budgetArr, ",")))
- }
- //地区搜索
- area := []string{}
- city := []string{}
- district := []string{}
- if operator.Province != "" {
- for k, v := range gconv.Map(operator.Province) {
- area = append(area, gconv.String(k))
- for k1, v1 := range gconv.Map(v) {
- city = append(city, k1)
- for _, v3 := range gconv.SliceStr(v1) {
- district = append(district, fmt.Sprintf("%s_%s"), k1, v3)
- }
- }
- }
- if len(area) > 0 {
- query1 := ""
- query1 += `{"terms":{"area":[`
- for k, v := range area {
- if k > 0 {
- query1 += `,`
- }
- query1 += `"` + v + `"`
- }
- query1 += `]}}`
- filterArr = append(filterArr, query1)
- }
- //市--未登录用户不能根据市和地区筛选
- if len(city) > 0 {
- query1 := ""
- query1 += `{"terms":{"city":[`
- for k, v := range city {
- if k > 0 {
- query1 += `,`
- }
- query1 += `"` + v + `"`
- }
- query1 += `]}}`
- filterArr = append(filterArr, query1)
- }
- if len(district) > 0 {
- query1 := ""
- for k, v := range district {
- if k > 0 {
- query1 += `,`
- }
- cityName := strings.Split(v, "_")[0]
- districtName := strings.Split(v, "_")[1]
- queryBoolMustAndDistrict := `{"bool":{"must":[{"terms":{"city":["%s"]}},{"terms":{"district":["%s"]}}]}}`
- query1 += fmt.Sprintf(queryBoolMustAndDistrict, cityName, districtName)
- }
- filterArr = append(filterArr, query1)
- }
- }
- //行业处理
- if operator.Industry != "" {
- filterArr = append(filterArr, fmt.Sprintf(`{"match":{"industry":["%s"]}}`, strings.ReplaceAll(operator.Industry, ",", `","`)))
- }
- //中标人标签处理
- if operator.WinnerTag != "" {
- filterArr = append(filterArr, fmt.Sprintf(`{"match":{"winner_tag":["%s"]}}`, strings.ReplaceAll(operator.WinnerTag, ",", `","`)))
- }
- //查看自己是否定制
- /*configData := IC.BiMysql.SelectBySql(`SELECT
- MAX( CASE WHEN element_name = '行业' THEN element_value END ) AS industry,
- MAX( CASE WHEN element_name = '运营商中标标签' THEN element_value END ) AS winner_tag,
- MAX( CASE WHEN element_name = '地区' THEN element_value END ) AS region,
- MAX( CASE WHEN element_name = '经营单位' THEN element_value END ) AS tagname
- FROM
- bi_service.customer_data_yys_permissions
- WHERE
- is_delete = 0
- AND position_id = ?
- AND ent_id = ?`, operator.PositionId, operator.EntId)
- if configData != nil && len(*configData) > 0 {
- tagname := gconv.String((*configData)[0]["tagname"])
- region := gconv.String((*configData)[0]["region"])
- winner_tag := gconv.String((*configData)[0]["winner_tag"])
- industry := gconv.String((*configData)[0]["industry"])
- if tagname != "" {
- filterArr = append(filterArr, fmt.Sprintf(`{"terms":{"tagname":["%s"]}}`, strings.Join(strings.Split(tagname, ","), `","`)))
- }
- if region != "" {
- filterArr = append(filterArr, fmt.Sprintf(`{"terms":{"region":["%s"]}}`, strings.Join(strings.Split(region, ","), `","`)))
- }
- if winner_tag != "" {
- filterArr = append(filterArr, fmt.Sprintf(`{"terms":{"winner_tag":["%s"]}}`, strings.Join(strings.Split(winner_tag, ","), `","`)))
- }
- if industry != "" {
- filterArr = append(filterArr, fmt.Sprintf(`{"terms":{"industry":["%s"]}}`, strings.Join(strings.Split(industry, ","), `","`)))
- }
- }*/
- //es sql拼接
- queryStr := ""
- orderStr := ""
- mysqlOrderStr := ""
- if operator.Tag == 1 {
- if operator.Order == 0 {
- orderStr = `{"publishtime":{"order":"desc"}}`
- mysqlOrderStr = ` order by publishtime desc`
- } else {
- orderStr = `{"publishtime":{"order":"asc"}}`
- mysqlOrderStr = ` order by publishtime asc`
- }
- } else if operator.Tag == 2 {
- if operator.Order == 0 {
- orderStr = `{"publishtime":{"order":"desc"}}`
- mysqlOrderStr = ` order by publishtime desc`
- } else {
- orderStr = `{"expurasingtime":{"order":"asc"}}`
- mysqlOrderStr = ` order by expurasingtime asc`
- }
- } else {
- if operator.Order == 0 {
- orderStr = `{"publishtime":{"order":"desc"}}`
- mysqlOrderStr = ` order by publishtime desc`
- } else {
- orderStr = `{"bidopentime":{"order":"asc"}}`
- mysqlOrderStr = ` order by bidopentime asc`
- }
- }
- queryStr = fmt.Sprintf(query, strings.Join(mustArr, ","), strings.Join(filterArr, ","), start, operator.PageSize, orderStr)
- fmt.Println(queryStr)
- start1 := time.Now().Unix()
- fmt.Println(start1)
- var count int64
- var data *[]map[string]interface{}
- count, data = elastic.GetWithCount(yysIndex, yysType, "", queryStr)
- end1 := time.Now().Unix()
- fmt.Println(end1)
- fmt.Println("时差", end1-start1)
- if len(*data) > 0 {
- //查询tidb真实数据
- idArr := []string{}
- for _, v := range *data {
- id := gconv.String(v["id"])
- idArr = append(idArr, id)
- }
- sqlStr := fmt.Sprintf(`select * from customer_data where FIND_IN_SET (id,?) %s `, mysqlOrderStr)
- fmt.Println(sqlStr)
- data = IC.BiMysql.SelectBySql(sqlStr,
- strings.Join(idArr, ","))
- return count, data
- } else {
- return count, &[]map[string]interface{}{}
- }
- }
|