package service import ( "app.yhyue.com/moapp/jybase/common" ME "app.yhyue.com/moapp/jybase/encrypt" elastic "app.yhyue.com/moapp/jybase/es" "app.yhyue.com/moapp/jybase/mongodb" "app.yhyue.com/moapp/jybase/redis" IC "bp.jydev.jianyu360.cn/BaseService/jyMicroservices/jyBXCore/rpc/init" "fmt" "github.com/gogf/gf/v2/util/gconv" "log" "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("业务类型", "businesstype", entId, positionId) if len(industryArr) > 0 { data = append(data, map[string]interface{}{ "key": "businesstype", "type": "selectList", "label": "业务类型", "defaultVal": []string{""}, "props": map[string]interface{}{ "multiple": true, }, "options": industryArr, }) } case "行业": industryArr, _ := getConfiguration("行业", "industry", entId, positionId) 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, positionId) 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, positionId int64) ([]map[string]interface{}, map[string]interface{}) { dataMap := make(map[string]interface{}) filedType := "" data := &[]map[string]interface{}{} if conditionType == "industry" { filedType = "2" data = IC.BiMysql.SelectBySql(`SELECT DISTINCT b.name,b.code as code FROM customer_data_yys_permissions a INNER JOIN d_yys_analyze_dimensions b on a.position_id=? and a.ent_id = ? and a.is_delete = 0 AND a.element_name = ? and FIND_IN_SET( b.code,a.element_value) inner join d_yys_dimensions_order c on b.name=c.name and b.type= c.type and b.type=? order by c.id `, positionId, entId, conditionName, filedType) } else { if conditionType == "winner_tag" { filedType = "3" } else { filedType = "6" } data = IC.BiMysql.SelectBySql(`SELECT DISTINCT b.name,b.code as code FROM customer_data_yys_permissions a INNER JOIN d_yys_analyze_dimensions b on a.position_id=? and a.ent_id = ? and a.is_delete = 0 AND a.element_name = ? and FIND_IN_SET( b.code,a.element_value) inner join d_yys_dimensions_order c on b.name=c.name and b.type= c.type and b.type=? order by c.id `, positionId, entId, conditionName, filedType) } options := []map[string]interface{}{} if data == nil { return options, dataMap } if len(*data) == 0 { if conditionType == "industry" { data = IC.BiMysql.SelectBySql(`SELECT DISTINCT a.name,a.code FROM d_yys_analyze_dimensions a inner join d_yys_dimensions_order b on a.name=b.name and a.type=b.type and a.ent_id = ? and a.type=? order by b.id`, entId, filedType) } else { data = IC.BiMysql.SelectBySql(`SELECT DISTINCT a.name,a.code FROM d_yys_analyze_dimensions a where a.ent_id = ? and a.type=? order by a.code`, entId, filedType) } } 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, }) dataMap[gconv.String(code)] = name } } return options, dataMap } 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 t1.行业要素值="null" OR FIND_IN_SET(t0.INDUSTRY, t1.行业要素值)) AND (t1.地区要素值 IS NULL OR t1.地区要素值="null" OR FIND_IN_SET(t0.REGION, t1.地区要素值)) AND (t1.中标标签要素值 IS NULL OR t1.中标标签要素值="null" OR FIND_IN_SET(t0.WINNER_TAG, t1.中标标签要素值)) AND (t1.经营单位要素值 IS NULL OR t1.经营单位要素值="null" or FIND_IN_SET(t0.tagname2, t1.经营单位要素值)) AND (t0.STATUS = 1) GROUP BY area, city, district ORDER 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 { UserId string 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 Businesstype string } func SearchList(operator Operator) (int64, *[]map[string]interface{}, int64) { 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 != "" { go keyHandle(operator.KeyWords, operator.UserId) 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) == 1 { if len(topType) > 0 { filterArr = append(filterArr, fmt.Sprintf(`{"match":{"toptype":"%s"}}`, strings.Join(topType, `","`))) } //信息类型二级 if len(subtype) > 0 { filterArr = append(filterArr, fmt.Sprintf(`{"terms":{"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":{"tagname1":"*%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":{"tagname2":"%s"}}`, v)) } mustArr = append(mustArr, fmt.Sprintf(shouldStr, strings.Join(keyArr, ","))) } //价格处理 if operator.Price != "" { priceArr := strings.Split(operator.Price, "_") minPrice := gconv.Int64(priceArr[0]) * 10000 maxPrice := gconv.Int64(priceArr[1]) * 10000 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(maxPrice))) budgetArr = append(budgetArr, fmt.Sprintf(` { "range": { "budget": { "lte": "%s" } } } `, gconv.String(maxPrice))) } 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, 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 := "" query1 += `{"terms":{"district":[` for k, v := range district { if k > 0 { query1 += `,` } query1 += `"` + v + `"` } query1 += `]}}` filterArr = append(filterArr, query1) } } //业务类型处理 if operator.Businesstype != "" { filterArr = append(filterArr, fmt.Sprintf(`{"terms":{"businesstype":["%s"]}}`, strings.ReplaceAll(operator.Businesstype, ",", `","`))) } //行业处理 if operator.Industry != "" { filterArr = append(filterArr, fmt.Sprintf(`{"terms":{"industry":["%s"]}}`, strings.ReplaceAll(operator.Industry, ",", `","`))) } //中标人标签处理 if operator.WinnerTag != "" { filterArr = append(filterArr, fmt.Sprintf(`{"terms":{"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 != "" && tagname != "null" { filterArr = append(filterArr, fmt.Sprintf(`{"terms":{"tagname":["%s"]}}`, strings.Join(strings.Split(tagname, ","), `","`))) } if region != "" && tagname != "null" { filterArr = append(filterArr, fmt.Sprintf(`{"terms":{"region":["%s"]}}`, strings.Join(strings.Split(region, ","), `","`))) } if winner_tag != "" && tagname != "null" { filterArr = append(filterArr, fmt.Sprintf(`{"terms":{"winner_tag":["%s"]}}`, strings.Join(strings.Split(winner_tag, ","), `","`))) } if industry != "" && tagname != "null" { filterArr = append(filterArr, fmt.Sprintf(`{"terms":{"industry":["%s"]}}`, strings.Join(strings.Split(industry, ","), `","`))) } } //es sql拼接 queryStr := "" orderStr := "" mysqlOrderStr := "" if operator.Tag == 0 { if operator.Order == 0 { orderStr = `{"publishtime":{"order":"desc"}}` mysqlOrderStr = ` order by a.publishtime desc` } else { orderStr = `{"publishtime":{"order":"asc"}}` mysqlOrderStr = ` order by a.publishtime asc` } } else if operator.Tag == 1 { if operator.Order == 0 { orderStr = `{"publishtime":{"order":"desc"}}` mysqlOrderStr = ` order by a.publishtime desc` } else { orderStr = `{"expurasingtime":{"order":"asc"}}` mysqlOrderStr = ` order by a.expurasingtime asc` } } else if operator.Tag == 2 { if operator.Order == 0 { orderStr = `{"publishtime":{"order":"desc"}}` mysqlOrderStr = ` order by a.publishtime desc` } else { orderStr = `{"bidopentime":{"order":"asc"}}` mysqlOrderStr = ` order by a.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 := []interface{}{} wh := []string{} for _, v := range *data { id := gconv.String(v["id"]) idArr = append(idArr, id) wh = append(wh, "?") } sqlStr := fmt.Sprintf(` SELECT a.* FROM customer_data a where a.id in (%s) %s `, strings.Join(wh, ","), mysqlOrderStr) fmt.Println(sqlStr, idArr) data = IC.BiMysql.SelectBySql(sqlStr, idArr...) if data != nil && len(*data) > 0 { _, winnerMap := getConfiguration("运营商中标标签", "winner_tag", operator.EntId, operator.PositionId) _, industryMap := getConfiguration("行业", "industry", operator.EntId, operator.PositionId) fileArr := &[]map[string]interface{}{} if operator.Tag == 0 { fileArr = IC.BiMysql.SelectBySql("select * from field_order ") } else { fileArr = IC.BiMysql.SelectBySql("select * from field_order where FIND_IN_SET(?,config_class)", operator.Tag) } //中标单位处理 for i, v := range *data { newData := map[string]interface{}{} v["publishtime"] = TimeHandle(gconv.String(v["publishtime"])) v["bidopentime"] = TimeHandle(gconv.String(v["bidopentime"])) v["expurasingtime"] = TimeHandle(gconv.String(v["expurasingtime"])) v["industry"] = industryMap[gconv.String(v["industry"])] v["winner_tag"] = winnerMap[gconv.String(v["winner_tag"])] v["bidendtime"] = TimeHandle(gconv.String(v["bidendtime"])) for _, m := range *fileArr { key := gconv.String(m["file"]) newData[key] = v[key] } bid := gconv.String(v["bid"]) if mongodb.IsObjectIdHex(bid) { newData["bid"] = ME.EncodeArticleId2ByCheck(bid) } else { newData["bid"] = "" } infoid := gconv.String(v["infoid"]) newData["infoid"] = ME.EncodeArticleId2ByCheck(infoid) (*data)[i] = newData } } total := count count = gconv.Int64(common.If(count > 2000, 2000, count)) return count, data, total } else { return count, &[]map[string]interface{}{}, 0 } } func TimeHandle(timeStr string) int64 { if timeStr == "" { return 0 } // 定义一个布局,需要与时间字符串格式相匹配 layout := "2006-01-02 15:04:05" // 使用Parse将字符串转换为time.Time类型 t, err := time.Parse(layout, timeStr) if err != nil { fmt.Println(err) return 0 } // 将time.Time类型转换为时间戳(单位:秒) return t.Unix() } func keyHandle(keys, userId string) { //历史记录 history := redis.GetStr("other", "s_"+userId) keyArr := SearchHistory(history, keys) if len(keyArr) > 0 { if b := redis.Put("other", "s_"+userId, strings.Join(keyArr, ","), -1); !b { log.Println("保存搜索记录异常,用户id:", userId) } } } // SearchHistory 格式化 关键词搜索历史记录 func SearchHistory(history, searchValue string) (arrS []string) { //主关键词 var searchKeys = strings.Split(searchValue, IC.C.JYKeyMark) //附加词 //关键词 和 附加词 合并,作为新的关键词历史搜索记录 if len(searchKeys) > 0 { arrS = strings.Split(history, ",") //新增历史记录 if history == "" { arrS = make([]string, 0) } for _, sv := range searchKeys { for k, v := range arrS { if v == strings.TrimSpace(sv) { arrS = append(arrS[:k], arrS[k+1:]...) break } } } arrS = append(arrS, searchKeys...) if len(arrS) > 10 { arrS = arrS[len(arrS)-10:] } } return arrS }