package front import ( "fmt" "jy/src/jfw/config" "jy/src/jfw/jyutil" "log" "math/rand" "strconv" "strings" "sync" "time" . "app.yhyue.com/moapp/jybase/api" "app.yhyue.com/moapp/jybase/encrypt" "app.yhyue.com/moapp/jypkg/common/src/qfw/util/jy" "app.yhyue.com/moapp/jypkg/jylabutil" "app.yhyue.com/moapp/jypkg/public" "app.yhyue.com/moapp/jypkg/common/src/qfw/util/bidsearch" util "app.yhyue.com/moapp/jybase/common" "app.yhyue.com/moapp/jybase/redis" elastic "app.yhyue.com/moapp/jybase/es" "app.yhyue.com/moapp/jybase/go-xweb/xweb" "github.com/SKatiyar/qr" ) type Pcsearch struct { *xweb.Action pcSearchIndex xweb.Mapper `xweb:"/jylab/(supsearch|medical|bi)/index.html"` //搜索首页 searchPower xweb.Mapper `xweb:"/jylab/(supsearch|medical|bi)/searchPower"` //搜索权限页面 getNewBids xweb.Mapper `xweb:"/jylab/supsearch/getNewBids"` //最新招标信息 getstatus xweb.Mapper `xweb:"/jylab/supsearch/getstatus"` //实验室开启状态 //proposedProject xweb.Mapper `xweb:"/jylab/supsearch/proposedProject.html"` //拟建项目-- 此功能已取消 影响es 检索功能 qr xweb.Mapper `xweb:"/jylab/supsearch/qr/(.*)"` //生成进入实验室的二维码 changePro xweb.Mapper `xweb:"/jylab/changePro"` //修改提示信息状态 } var industrylist map[string][]string var sortArray []string var PCS_index map[string]interface{} var PCS_time int var PCSLock = &sync.Mutex{} var FileSignBool = false const ( BidFieldMedical = "0101" ) var ( // DomainPageType 缓存标签 DomainPageType = map[string]string{ BidFieldMedical: "medical", // 医疗领域 } ) // MedicalFunctionCode 医疗行业权益代码 const ( MedicalFunctionCode = "lyh_yl_ylbxss" MobileTagSearchFunctionCode = "zbcgss_zgydbqjs" ) func init() { xweb.AddAction(&Pcsearch{}) industrylist, sortArray = jy.Getindustrys(util.ObjToString(config.Sysconfig["industry"]), mongodb) //清除搜索列表内存缓存 间隔时间 PCS_time = util.IntAll(config.Sysconfig["PCS_time"]) go func() { time.Sleep(time.Second * 5) PCS_task() }() PCSLock.Lock() PCS_index = map[string]interface{}{} PCSLock.Unlock() //搜索字段添加 附件标识 if FileSignBool, _ = config.Sysconfig["fileSignBool"].(bool); FileSignBool { bidSearch_field_1 = bidSearch_field_1 + bidSearch_field_file bidSearch_field = bidSearch_field + bidSearch_field_file //搜索优化 BidSearchFieldBase += BidSearchFieldFile BidSearchFieldOfVip += BidSearchFieldFile } } // 定时清理搜索列表页 从redis获取存入内存中的数据 func PCS_task() { //根据配置延迟 PCS_time 小时执行 sub := time.Hour * time.Duration(PCS_time) timer := time.NewTimer(sub) log.Println(PCS_time, "小时后执行清除缓存操作") defer timer.Stop() for { select { case <-timer.C: { PCSLock.Lock() PCS_index = map[string]interface{}{} PCSLock.Unlock() timer.Reset(time.Hour * time.Duration(PCS_time)) } } } } // 返回内存中列表也的数据,只获取首页,其他页面访问量暂时不多 func PCS_list(page_type string, pageSize int, userId string) []map[string]interface{} { /*var _page_type = page_type //如果page_type为空,则是获取非拟建数据。 if page_type == "" { _page_type = "page_index" } PCSLock.Lock() defer PCSLock.Unlock() if PCS_index[_page_type] == nil { PCS_index[_page_type] = Newbids(page_type)[0] }*/ if pageSize == 0 { pageSize = 50 } newbid := Newbids(page_type, userId) if len(newbid) > 0 { return newbid[0:pageSize] } else { return nil } } func (p *Pcsearch) ChangePro() { defer util.Catch() userid := p.GetSession("userId") if userid != nil { jylabutil.UpdateAuthory(userid.(string), "i_tablepro", 1) } } // 此功能已失效 func (p *Pcsearch) ProposedProject() error { defer util.Catch() var shareid = p.GetString("id") if len(shareid) == 0 { shareid = "10" } p.T["logid"] = config.Seoconfig["jynjxmy"].(string) b_word, _, s_word := jy.InterceptSearchKW(p.GetString("keywords"), util.IntAllDef(config.Sysconfig["keywordsLimit"], 35), true) area := p.GetString("area") //地区 publishtime := p.GetString("publishtime") //发布时间 subtype := p.GetString("subtype") //信息类型 pageSize, _ := p.GetInteger("pageSize") //信息类型 if subtype == "" { subtype = "拟建" } userId, _ := p.GetSession("userId").(string) var totalPage int64 var list *[]map[string]interface{} var status = 1 var count int64 if publishtime == "" { var ( now = time.Now() startTime = fmt.Sprint(time.Date(now.Year(), now.Month()-6, now.Day(), now.Hour(), now.Minute(), now.Second(), 0, time.Local).Unix()) //最近7天 endTime = fmt.Sprint(now.Unix()) ) publishtime = fmt.Sprintf("%s_%s", startTime, endTime) } if len(s_word) > 0 { status = 2 count, totalPage, list = bidsearch.GetPcBidSearchData(s_word, area, "", publishtime, subtype, "", "", "", "", "", "", "", "", 0, true, nil, bidSearch_field_1, "", false, false, "", pageSize, userId) listSize := 0 if list != nil { listSize = len(*list) } public.SaveUserSearchLog(p.Request, util.ObjToString(p.GetSession("userId")), count, "pc", "拟建", map[string]interface{}{ "search_word": s_word, "search_area": area, "search_publishtime": publishtime, "pagenum": 1, "pagesize": listSize, }) } else { p.DisableHttpCache() p.T["list"] = PCS_list("nijian", pageSize, userId) //Newbids("nijian")[0] totalPage = 10 count = 500 } if status == 2 { if list != nil { for _, v := range *list { v["_id"] = encrypt.EncodeArticleId2ByCheck(v["_id"].(string)) stp, _ := v["subtype"].(string) if stp == "" { stp, _ = v["toptype"].(string) } area, _ := v["area"].(string) v["stypeadd"], v["areaadd"], _ = classify(stp, area, "") //正文匹配检索关键词 highlight, _ := v["highlight"].(map[string][]string) detail := "" for _, val := range highlight["detail"] { detail += public.ClearHtml.ReplaceAllString(val, "") } v["detail"] = detail } } p.T["list"] = list } p.T["area"] = area p.T["subtype"] = subtype p.T["publishtime"] = publishtime p.T["timeslot"] = p.GetString("timeslot") p.T["totalPage"] = totalPage p.T["count"] = count p.T["keywords"] = b_word p.T["searchvalue"] = s_word p.T["login"] = p.Session().Get("user") p.SetSession("paramkey", b_word) if publishtime == "lately-7" { p.SetSession("parampublishtime", "最近7天") } else if publishtime == "lately-30" { p.SetSession("parampublishtime", "最近30天") } else if publishtime == "thisyear" { p.SetSession("parampublishtime", "去年") } else { p.SetSession("parampublishtime", publishtime) } p.SetSession("paramarea", area) p.T["shareid"] = se.EncodeString(shareid) return p.Render("/pc/proproject.html", &p.T) } func (p *Pcsearch) Getstatus() error { defer util.Catch() var supstatus, entstatus, tablepro, dataexportstatus, portraitpower, followent, smartstatus bool if userid := util.ObjToString(p.GetSession("userId")); userid != "" { user := jyutil.Compatible.Select(userid, `{"i_tablepro":1}`) if len(*user) > 0 { tablepro = util.Int64All((*user)["i_tablepro"]) == 1 } } p.ServeJson(map[string]interface{}{ "smartstatus": smartstatus, "supstatus": supstatus, "entstatus": entstatus, "tablepro": tablepro, "dataexportstatus": dataexportstatus, "portraitpower": portraitpower, "followent": followent, }) return nil } func (p *Pcsearch) GetNewBids() error { sessVal := p.Session().GetMultiple() pagenum, _ := p.GetInteger("pageNumber") pageSize, _ := p.GetInteger("pageSize") pageType := p.GetString("pageType") bidField := p.GetString("bid_field") //userId, _ := p.GetSession("userId").(string) userId := util.ObjToString(sessVal["base_user_id"]) //baseUserId := p.GetSession("base_user_id") baseUserId := util.Int64All(sessVal["base_user_id"]) searchGroup, _ := p.GetInteger("searchGroup") //搜索分组;默认0:全部;1:招标采购搜索;2:超前项目。 vipStatus := jy.GetVipState(p.Session(), *config.Middleground, userId) // 如果是领域化数据j if bidField != "" { if domainPageType, ok := DomainPageType[bidField]; ok { pageType = domainPageType //bidField = domainPageType } //领域化数据 如果没有权限直接返回空数据 if (vipStatus.BigMember <= 0 && vipStatus.VipState <= 0) || (!jy.HasBidFieldPower(config.Middleground, p.Session(), MedicalFunctionCode)) { p.ServeJson(map[string]interface{}{ "list": []map[string]interface{}{}, "count": 0, "totalPage": 0, "total": 0, }) return nil } } so := &SearchOptimize{ UserId: userId, PageNum: pagenum, PageSize: pageSize, BidField: bidField, NewUserId: baseUserId, SearchGroup: searchGroup, IsPay: vipStatus.IsPayedUser(), R: p.Request, } //搜索条件处理 so.SearchParamsHandle() var ( list []*map[string]interface{} count, total int64 ) list, count, total = so.GetBidSearchListByCache() // count, total, list = so.GetBidSearchList(false) if pageType == "" { //最新招标信息仅第一页条展示表格多字段 for k, v := range list { if pagenum == 1 && k < 20 { continue } delete((*v), "bidopentime") delete((*v), "buyer") delete((*v), "k") delete((*v), "projectcode") delete((*v), "projectname") delete((*v), "winner") delete((*v), "timetemp") delete((*v), "budget") delete((*v), "s_subscopeclass") delete((*v), "toptype") } } log.Println("userId:+++", userId) if userId == "" { for _, v := range list { *v = SearchFilter(*v) } } p.ServeJson(map[string]interface{}{ "list": list, "count": count, "total": total, "totalPage": (count + 1) / int64(pageSize), }) return nil } type ( SearchItems struct { Key string `json:"key" doc:"提交后端接口时需要的Key: keyword"` Label string `json:"label" doc:"页面展示的标签:关键词"` Type string `json:"type" doc:"操作类型:下拉、时间选择、多选等"` DefaultVal []string `json:"defaultVal"` Options []*SearchItemsValOptions `json:"options" doc:"选项"` } SearchItemsValOptions struct { Key string `json:"key" doc:"后端接受值"` Label string `json:"label" doc:"展示标签"` } ) var ( mobileTagItemsValOptions = []*SearchItemsValOptions{ {Key: "all", Label: "全部"}, {Key: "军队类", Label: "军队类"}, {Key: "武警类", Label: "武警类"}, {Key: "融通类", Label: "融通类"}, {Key: "退役类", Label: "退役类"}, {Key: "融办类", Label: "融办类"}, {Key: "某某类", Label: "“某某”类"}, } mobileTagItemsValOptionsAll = []string{"军队类", "武警类", "融通类", "退役类", "融办类", "某某类"} ) // SearchPower 搜索权益列表 func (p *Pcsearch) SearchPower(module string) { sessVal := p.Session().GetMultiple() userId := util.ObjToString(sessVal["userId"]) data, err := func() ([]*SearchItems, error) { var r []*SearchItems switch module { case "supsearch": //搜索页面检索内容 if userId != "" && jy.HasBidFieldPower(config.Middleground, p.Session(), MobileTagSearchFunctionCode) { r = append(r, &SearchItems{ Key: "mobileTag", Label: "融创", Type: "multiple", DefaultVal: append(mobileTagItemsValOptionsAll, "all"), //默认选择全部 Options: mobileTagItemsValOptions, }) } } return r, nil }() p.ServeJson(NewResult(data, err)) } // PcSearchIndex 路由搜索 func (p *Pcsearch) PcSearchIndex(module string) error { defer util.Catch() sessVal := p.Session().GetMultiple() p.T["logid"] = config.Seoconfig["jysslby"].(string) pageSize, _ := p.GetInteger("pageSize") if pageSize == 0 { pageSize = 50 } accountId := util.Int64All(sessVal["accountId"]) entAccountId := util.Int64All(sessVal["entAccountId"]) entId := util.Int64All(sessVal["entId"]) entUserId := util.Int64All(sessVal["entUserId"]) keywords := p.GetString("keywords") industry := strings.TrimSpace(p.GetString("industry")) //选中的行业 area := p.GetString("area") //地区 publishtime := p.GetString("publishtime") //发布时间 timeslot := p.GetString("timeslot") //显示选择时间 toptype := p.GetString("toptype") //信息类型 subtype := p.GetString("subtype") //信息类型 minprice := p.GetString("minprice") //最低价格 maxprice := p.GetString("maxprice") //最高价格 fileExists := p.GetString("fileExists") //是否有附件--所有用户都可用此功能 0:全部;1:有附件;-1:无附件 //搜索优化P260--start-- searchGroup, _ := p.GetInteger("searchGroup") //搜索分组;默认0:全部;1:招标采购搜索;2:超前项目。 searchMode, _ := p.GetInteger("searchMode") //搜索模式;默认0:精准模式(不进行系统分词);1:模糊模式(进行系统分词)。 wordsMode, _ := p.GetInteger("wordsMode") //搜索关键词模式;默认0:包含所有关键词;1:包含任意关键词。 additionalWords := p.GetString("additionalWords") //关键词:附加关键词(副:五组,每组最多15个字符 每组,号隔开) //--end-- //userId, _ := p.GetSession("userId").(string) //phone, _ := p.GetSession("phone").(string) userId := util.ObjToString(sessVal["userId"]) phone := util.ObjToString(sessVal["phone"]) selectType := p.GetString("selectType") //搜索范围 if selectType == "" { selectType = "title,content" } //p353包含采购意向与拟建 noLoginBl := false if userId == "" { //未登录用户访问全部信息类型 需要过滤掉 拟建 // p397 未登录用户收回查看拟建权限 if searchGroup < 2 { if strings.Contains(subtype, "采购意向") || strings.Contains(subtype, "拟建") { var ss []string for _, v := range strings.Split(subtype, ",") { if v != "采购意向" && !strings.Contains(v, "拟建") { ss = append(ss, v) } } subtype = strings.Join(ss, ",") } if subtype == "" { subtype = "招标预告,招标公告,招标结果,招标信用信息" noLoginBl = true } } //未登录用户搜索范围 标题和 正文 var selectTypeArr []string selectTypeSplit := strings.Split(selectType, ",") // 未登录用户只能搜标题和正文 for i := 0; i < len(selectTypeSplit); i++ { if selectTypeSplit[i] == "title" || selectTypeSplit[i] == "content" { selectTypeArr = append(selectTypeArr, selectTypeSplit[i]) } } if len(selectTypeArr) > 0 { selectType = strings.Join(selectTypeArr, ",") } if publishtime != "" { publishtime = "" } } //高级筛选 仅vip用户可查询 var ( hasBuyerTel, hasWinnerTel = "", "" //是否有采购单位电话、是否有中标单位电话 y:有 n:没有 buyerclass = "" //采购单位类别 notkey = "" //排除词 city = "" //城市 付费用户可用 district = "" regionMap = "" buyer = "" winner = "" agency = "" mobileTag []string //P513中国移动定制招标采购搜索 ) // 领域化标识 territorialization := p.GetString("bid_field") switch module { case "medical": // 领域类型 医疗-0101 if territorialization == "" { territorialization = "0101" } case "BIProperty": territorialization = territorialization default: territorialization = "" } if territorialization == "" { territorialization = p.GetString("property") } userInfo := jy.GetVipState(p.Session(), *config.Middleground, userId) queryItems := userInfo.GetQueryItems(selectType, util.Int64All(config.Sysconfig["bidSearchOldUserLimit"])) isPayedUser := userInfo.IsPayedUser() if isPayedUser { buyerclass = p.GetString("buyerclass") hasBuyerTel, hasWinnerTel = p.GetString("buyertel"), p.GetString("winnertel") notkey = p.GetString("notkey") city = p.GetString("city") //城市 付费用户可用 district = p.GetString("district") regionMap = p.GetString("regionMap") //P492招标采购搜索匹配采购单位等优化 buyer = p.GetString("buyer") //采购单位 winner = p.GetString("winner") //中标企业 agency = p.GetString("agency") //招标代理机构 } //历史导出数据回显 if strings.Contains(p.Url(), "?goback") { keywords = util.ObjToString(sessVal["Echo_keywords"]) publishtime = util.ObjToString(sessVal["Echo_publishtime"]) area = util.ObjToString(sessVal["Echo_area"]) subtype = util.ObjToString(sessVal["Echo_subtype"]) minprice = util.ObjToString(sessVal["Echo_minprice"]) maxprice = util.ObjToString(sessVal["Echo_maxprice"]) buyerclass = util.ObjToString(sessVal["Echo_buyerclass"]) selectType = util.ObjToString(sessVal["Echo_selectType"]) timeslot = util.ObjToString(sessVal["Echo_timeslot"]) hasBuyerTel = util.ObjToString(sessVal["Echo_hasBuyertel"]) hasWinnerTel = util.ObjToString(sessVal["Echo_hasWinnertel"]) industry = util.ObjToString(sessVal["Echo_industry"]) notkey = util.ObjToString(sessVal["Echo_notkey"]) fileExists = util.ObjToString(sessVal["Echo_fileExists"]) city = util.ObjToString(sessVal["Echo_city"]) district = util.ObjToString(sessVal["Echo_district"]) regionMap = util.ObjToString(sessVal["Echo_regionMap"]) bidField = util.ObjToString(sessVal["Echo_bid_field"]) // 领域化数据 0101-医疗行业 territorialization = util.ObjToString(sessVal["Echo_bid_field"]) // 领域化数据 0101-医疗行业 searchGroup = util.IntAll(sessVal["Echo_searchGroup"]) //搜索分组;默认0:全部;1:招标采购搜索;2:超前项目。 searchMode = util.IntAll(sessVal["Echo_searchMode"]) //搜索模式;默认0:精准模式(不进行系统分词);1:模糊模式(进行系统分词)。 wordsMode = util.IntAll(sessVal["Echo_wordsMode"]) //搜索关键词模式;默认0:包含所有关键词;1:包含任意关键词。 additionalWords = util.ObjToString(sessVal["Echo_additionalWords"]) //关键词:附加关键词(副:五组,每组最多15个字符 每组,号隔开) queryItems = userInfo.GetQueryItems(selectType, util.Int64All(config.Sysconfig["bidSearchOldUserLimit"])) //P492招标采购搜索匹配采购单位等优化 buyer = util.ObjToString(sessVal["Echo_buyer"]) winner = util.ObjToString(sessVal["Echo_winner"]) agency = util.ObjToString(sessVal["Echo_agency"]) } keywordsLimit := util.IntAllDef(config.Sysconfig["keywordsLimit"], 35) searchLimit := public.IsSearchLimit(queryItems) //-----------------------------未登录用户支持非单字符查询-------------------------- if userId == "" { keywordsLimit = util.IntAllDef(config.Sysconfig["keywordsLimitNologin"], 25) //未登录用户标题、正文都限制,已登录用户只限制正文 searchLimit = true if len([]rune(keywords)) == 1 { //未登录用户搜索不让搜索单字 keywords = "" } } var ( list []*map[string]interface{} count, total int64 secondFlag = "" isSearch = true b_word, a_word, s_word, heightKeys = "", "", "", "" ) onList, _ := jyutil.IsOnTheWhitelist(p.Session()) if keywords != "" { // p329 非白名单用户 处理通用词 if !onList && len(industry) == 0 { keywords = jyutil.FilterGeneric(keywords) // 关键词处理通用词 additionalWords = jyutil.AdditionalFilterGeneric(additionalWords) // 附加词处理通用词 } b_word, a_word, s_word = jy.InterceptSearchKW(keywords, keywordsLimit, len(industry) == 0) } if strings.Index(p.Refer(), "/page_workDesktop/work-bench") > -1 { //超级搜索页面 移动定制搜索标签(仅工作台内展示) mobileTag = p.GetSlice("mobileTag[]") //if len(mobileTag) > 0 { //当无该权限,把此字段置空 if !jy.HasBidFieldPower(config.Middleground, p.Session(), MobileTagSearchFunctionCode) { mobileTag = []string{} } else if (len(mobileTag) > 0 && mobileTag[0] == "all") || len(mobileTag) == 0 { mobileTag = mobileTagItemsValOptionsAll } //} } //医疗领域化信息 用户前提是大会员 超级订阅,才有领域化功能的权限 if territorialization != "" && territorialization != "BIProperty" { isSearch = false userInfo := jy.GetVipState(p.Session(), *config.Middleground, userId) if userInfo.BigMember > 0 || userInfo.VipState > 0 { if jy.HasBidFieldPower(config.Middleground, p.Session(), MedicalFunctionCode) { isSearch = true } } } isLimit := 1 if isSearch { searchTypeSwitch, _ := config.Sysconfig["searchTypeSwitch"].(bool) so := NewSearchOptimize(mobileTag, userId, phone, area, city, district, subtype, toptype, publishtime, strings.Join(queryItems, ","), fmt.Sprintf("%s-%s", minprice, maxprice), industry, buyerclass, hasBuyerTel, hasWinnerTel, fileExists, s_word, additionalWords, notkey, "PC", territorialization, "", "", "", 0, pageSize, searchGroup, searchMode, wordsMode, "", "", 0, 0, *userInfo, searchTypeSwitch, p.Request, accountId, entAccountId, entId, entUserId, buyer, winner, agency) heightKeys = so.HeightKeys //主关键词和附加词合并,多组空格隔开,作为前端渲染高亮关键词使用 //关键词 行业 附加词 //放开用户不输入关键词可搜索 --P297需求 // p329 反爬白名单用户放开 非反爬白名单用户不放开未输入关键词 if len(s_word) > 0 || (len(s_word) == 0 && onList) || len(industry) > 0 || strings.TrimSpace(so.AdditionalWords) != "" || len(so.MobileTag) > 0 { if searchLimit { isLimit = public.Lst.IsLimited(p.Request, p.ResponseWriter, p.Session(), isPayedUser) if isLimit == 1 { //没有被限制 defer public.Lst.Limit() } } if isLimit == 1 { count, total, list = so.GetBidSearchList(false) } } else { p.DisableHttpCache() list, count, total = so.GetBidSearchListByCache() } } if noLoginBl { subtype = "" } if userId == "" { for _, v := range list { *v = SearchFilter(*v) } } p.T["list"] = list p.T["secondFlag"] = secondFlag p.T["area"] = area p.T["publishtime"] = publishtime p.T["timeslot"] = timeslot p.T["toptype"] = toptype p.T["subtype"] = subtype p.T["searchvalue"] = keywords //搜索关键词 p.T["minprice"] = minprice p.T["maxprice"] = maxprice p.T["buyerclass"] = buyerclass p.T["buyertel"] = hasBuyerTel p.T["winnertel"] = hasWinnerTel p.T["notkey"] = notkey p.T["fileExists"] = fileExists p.T["city"] = city p.T["district"] = district p.T["regionMap"] = regionMap p.T["bid_field"] = territorialization p.SetSession("paramkey", b_word) switch publishtime { case "lately-7": p.SetSession("parampublishtime", "最近7天") case "lately-30": p.SetSession("parampublishtime", "最近30天") case "thisyear": p.SetSession("parampublishtime", "近一年") case "threeyear": p.SetSession("parampublishtime", "近三年") case "fiveyear": p.SetSession("parampublishtime", "近五年") default: p.SetSession("parampublishtime", publishtime) } p.SetSession("paramarea", area) if subtype != "" { p.SetSession("paraminfotype", subtype) } else { p.SetSession("paraminfotype", toptype) } //} p.T["selectType"] = selectType p.T["login"] = p.Session().Get("user") p.T["count"] = count p.T["totalPage"] = (count + 1) / int64(pageSize) p.T["keywords"] = keywords //搜索关键词 p.T["heightWords"] = heightKeys //主关键词和附加词合并后 p.T["industry"] = industry p.T["industrylist"] = industrylist p.T["sortArray"] = sortArray p.T["showVipScreen"] = isPayedUser p.T["bidField"] = territorialization p.T["module"] = module p.T["interceptKeyWords"] = b_word //超出限制关键词限制长度 截取后 p.T["interceptOtherWords"] = a_word //超出限制关键词限制长度 截取后 提示关键词 p.T["interceptLimit"] = keywordsLimit // p.T["searchGroup"] = searchGroup p.T["searchMode"] = searchMode p.T["wordsMode"] = wordsMode p.T["additionalWords"] = additionalWords p.T["total"] = total p.T["isVip"] = userInfo.VipState > 0 p.T["isMember"] = userInfo.BigMember > 0 p.T["isEntniche"] = userInfo.EntMember > 0 p.T["isEntnicheNew"] = userInfo.IsNewEnt p.T["isEntService"] = userInfo.EntService p.T["vipBefore202209"] = userInfo.VipState > 0 && userInfo.VipStartData < util.Int64All(config.Sysconfig["contextOldVipLimit"]) //超级订阅 超强项目 // cooperateCode := "" if userId != "" { //企业画像 权限 p.T["portraitpower"] = jylabutil.IsAuthorized(userId, "i_portraitpower") } else { if cc, err := p.GetCookie(jy.ChannelCookieName); err == nil { cooperateCode = cc.Value } } p.T["cooperateCode"] = cooperateCode p.T["isLimit"] = isLimit if module == "supsearch" { p.T["simpleTemplateData"] = map[string]interface{}{ "isEntniche": p.T["isEntniche"], "isVip": p.T["isVip"], "isMember": p.T["isMember"], "vipBefore202209": p.T["vipBefore202209"], "searchMode": searchMode, "searchvalue": keywords, "additionalWords": additionalWords, "listLength": util.If(list != nil, len(list), 0), } } return p.Render("/pc/supsearch.html", &p.T) } // Newbids 最新招标信息 --已失效 func Newbids(p, userId string) []map[string]interface{} { return nil ////fmt.Println("11111", redis.Get("newother", "index_list")) //nologin := "" //count := 500 //pagenum := 10 //limit := 50 //if userId == "" { // nologin = "_nologin" // count = bidsearch.SearchMaxPageCount_NOLOGIN // pagenum = 20 // limit = 250 //} //indexOk, _ := redis.Exists("newother", "index_list"+p+nologin) //pages := []map[string]interface{}{} //if indexOk { // pages = util.ObjArrToMapArr(redis.Get("newother", "index_list"+p+nologin).([]interface{})) //} //if len(pages) == 0 { // var list *[]map[string]interface{} // subtype := "" // bidField := "" // // 判断是不是医疗行业 // if p == "medical" { // bidField = "0101" // } else { // if len(p) > 0 { // subtype = "拟建" // } // //未登录用户访问全部信息类型 需要过滤掉 拟建和采购意向 // if subtype == "" { // subtype = "拟建,招标预告,招标公告,招标结果,招标信用信息" // } // } // //查询置顶信息 // var ss []map[string]interface{} // ls := top500(subtype, bidField, userId) // if ls != nil && len(*ls) > 0 { // ss = append(ss, *ls...) // } // //pages = append(pages, ls) // if ls == nil || len(*ls) < count { // intns := make([]int, 0) // for i := 0; i < pagenum; i++ { // if len(intns) == 0 { // intns = append(intns, rand.Intn(1000)) // } else { // for { // v := rand.Intn(intns[(i-1)] + 1000) // if v-intns[(i-1)] > limit { // intns = append(intns, v) // break // } // } // } // } // for i := 0; i < pagenum; i++ { // _, list = getLastNewsData("", "", "", "", subtype, "", "", "", "", "", "", "", "Y", intns[i], true, false, "", bidField, limit) // if list != nil && len(*list) > 0 { // ss = append(ss, *list...) // } // } // } // data := duplicateRemoval(ss) // if len(data) > 0 { // pages = data // redis.Put("newother", "index_list"+p+nologin, pages, 60*60*24) // pages = util.ObjArrToMapArr(redis.Get("newother", "index_list"+p+nologin).([]interface{})) // } //} //return pages } // Newbids 最新招标信息 func NewBidddingsForSEO(p string, pageNum, limit int) []map[string]interface{} { indexOk, _ := redis.Exists("newother", "index_list_"+p) pages := []map[string]interface{}{} if indexOk { pages = util.ObjArrToMapArr(redis.Get("newother", "index_list_"+p).([]interface{})) } else { var ss []map[string]interface{} intns := make([]int, 0) for i := 0; i < pageNum; i++ { if len(intns) == 0 { intns = append(intns, rand.Intn(30)) } else { for { v := rand.Intn(intns[(i-1)] + 50) if v-intns[(i-1)] > limit { intns = append(intns, v) break } } } } for i := 0; i < pageNum; i++ { list := elastic.GetPage(INDEX, TYPE, "", `{"publishtime":-1}`, bidField, intns[i], limit) if list != nil && len(*list) > 0 { ss = append(ss, *list...) } } if len(ss) > 0 { pages = ss redis.Put("newother", "index_list_"+p, ss, 60*60*24) } } return pages } func duplicateRemoval(ss []map[string]interface{}) []map[string]interface{} { d := make(map[string]interface{}) data := []map[string]interface{}{} for _, v := range ss { id := util.InterfaceToStr(v["_id"]) if _, ok := d[id]; ok || id == "" { continue } t := time.Unix(util.Int64All(v["publishtime"]), 0) v["timetemp"] = fmt.Sprint(util.Int64All(v["publishtime"])) v["_id"] = encrypt.EncodeArticleId2ByCheck(id) v["time"] = util.TimeDiff(t) var stp = "" if v["subtype"] != nil { stp, _ = v["subtype"].(string) } else { stp = "" } if stp == "" && v["toptype"] != nil { stp, _ = v["toptype"].(string) } area, _ := v["area"].(string) indtry := util.ObjToString(v["industry"]) v["stypeadd"], v["areaadd"], v["indadd"] = classify(stp, area, indtry) if v["filetext"] != nil { delete(v, "filetext") v["fileExists"] = true } if _, ok := d[id]; ok { continue } d[id] = true v["k"] = util.IntAll(v["k"]) + 1 data = append(data, v) } return data } var topTypeMap = map[string]string{ "招标预告": "预告", "招标公告": "招标", "招标结果": "结果", "招标信用信息": "其它", } // 未登录变成top5000了... func top500(subtype string, bidField string, userId string) (list *[]map[string]interface{}) { qstr := "" if bidField != "" { // 如果是领域化数据 q := `{"query": {"bool": {"should": [{"term": {"dataweight": 1}}], "must": [ {"term": {"bid_field": "%s"}}]}}}` qstr = fmt.Sprintf(q, bidField) } else { var query = `` qstr = `{"query": {"bool": {"must": [%s]}}}` if subtype != "" { var topTypes []string var subTypes []string for _, v := range strings.Split(subtype, ",") { if v1, ok := topTypeMap[v]; ok { topTypes = append(topTypes, fmt.Sprintf(`"%s"`, v1)) } else { subTypes = append(subTypes, fmt.Sprintf(`"%s"`, v)) } } log.Println("信息类型搜索:", topTypes, subTypes) if len(subTypes) > 0 && len(topTypes) > 0 { query = fmt.Sprintf(`{"bool": {"should": [{"terms": {"subtype": [%s]}},{"terms": {"toptype": [%s]}}]}}`, strings.Join(subTypes, ","), strings.Join(topTypes, ",")) } else if len(subTypes) > 0 { query += fmt.Sprintf(`{"terms":{"subtype":[%s]}}`, strings.Join(subTypes, ",")) } else if len(topTypes) > 0 { query += fmt.Sprintf(`{"terms":{"toptype":[%s]}}`, strings.Join(topTypes, ",")) } } if query != `` { query = query + `,` + `{"term": {"dataweight": 1}}` } else { query = `{"term": {"dataweight": 1}}` } qstr = fmt.Sprintf(qstr, query) } count := 500 if userId == "" { count = bidsearch.SearchMaxPageCount_NOLOGIN } repl := elastic.GetAllByNgram(INDEX, TYPE, qstr, `"title"`, `{"publishtime":-1}`, bidSearch_field, 0, count, 115, false) if repl != nil && *repl != nil && len(*repl) > 0 { public.BidListConvert("", repl) list = repl } return } // 二维码图片 func (p *Pcsearch) Qr(t string) error { openid := p.GetSession("openid") if openid == nil { return nil } w := p.ResponseWriter w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate") w.Header().Set("Pragma", "no-cache") w.Header().Set("Expires", "0") w.Header().Set("Content-Type", "image/png") data := config.Sysconfig["webdomain"].(string) + "/front/sess/" + sewx.EncodeString(openid.(string)+",uid,"+strconv.Itoa(int(time.Now().Unix()))+",qrToLab") + "__" + t r, _ := qr.Encode(data, qr.M) pngdat := r.PNG() _, err := w.Write(pngdat) return err }