package front import ( qu "app.yhyue.com/moapp/jybase/common" "app.yhyue.com/moapp/jybase/encrypt" elastic "app.yhyue.com/moapp/jybase/es" "app.yhyue.com/moapp/jybase/redis" "app.yhyue.com/moapp/jypkg/common/src/qfw/util/bidsearch" "app.yhyue.com/moapp/jypkg/public" "encoding/json" "fmt" "jy/src/jfw/config" "jy/src/jfw/jyutil" "jy/src/jfw/paging" "log" "math" "math/rand" "strconv" "sync" "time" "net/http" "app.yhyue.com/moapp/jybase/date" "app.yhyue.com/moapp/jybase/go-xweb/httpsession" ) type KeyType struct { Name string `json:"name"` Url string `json:"url"` SeedData []KeyType `json:"seedData"` } // RegionAndInformationAndTender 1地域 2信息类型 3热门招标 func RegionAndInformationAndTender() map[string]interface{} { if bytes, err := redis.GetBytes(RedisNameNew, "regionAndInformationAndTender"); err == nil && bytes != nil { rData := map[string]interface{}{} if err := json.Unmarshal(*bytes, &rData); err != nil { log.Printf("[MANAGER-ERR]RegionAndInformationAndTender GetData Error %v \n", err) return nil } return rData } data := make(map[string]interface{}) for _, v := range []int{1, 2, 3} { data[fmt.Sprintf("labUrl_%d", v)] = GetLabUrl(v) //1地域 2信息类型 3热门招标 } if bytes, err := json.Marshal(data); err == nil && bytes != nil { _ = redis.PutBytes(RedisNameNew, "regionAndInformationAndTender", &bytes, 2*60*60) } return data } // HotSubjectMatter 热门标的物 func HotSubjectMatter() []map[string]interface{} { checkedLetter := LetterArr[getRandomWithAll(0, len(LetterArr))] industryHref := fmt.Sprintf("/tags/industry/%s_%s_all_%s.html", "%v", "all", "%v") letterLabel, _, _ := GetLetterPaging(1, checkedLetter) //热门标的物 随机字母标签 tradeLabel := GetIndustry(industryHref) //热门标的物 行业分类标签 letterLabel = append(letterLabel, tradeLabel...) var subjectMatter []map[string]interface{} if len(letterLabel) > 0 { for _, v := range jyutil.GenerateRandomNumber(0, len(letterLabel)-1, 200) { subjectMatter = append(subjectMatter, letterLabel[v]) } } return subjectMatter } // 随机展示200中标企业 func GetWinnerInfo() (data []BuyerList) { randGen := rand.New(rand.NewSource(time.Now().UnixNano())) from := randGen.Intn(100) //关联中标企业 r := elastic.Get("winner", "winner", fmt.Sprintf(`{"query": {"bool": {"must": []}},"_source": ["_id","name"],"from": %d,"size": 200}`, from)) if r != nil { for _, v := range *r { var vs BuyerList id := encrypt.EncodeArticleId2ByCheck(qu.InterfaceToStr(v["_id"])) vs.Name = qu.InterfaceToStr(v["name"]) vs.Url = fmt.Sprintf("/swordfish/page_big_pc/ent_portrait/%s", id) data = append(data, vs) } } return } // ContentRecommendation 实用内容推荐 func ContentRecommendation() []KeyType { if bytes, err := redis.GetBytes(RedisNameNew, "contentRecommendation"); err == nil && bytes != nil { var rData []KeyType log.Println() if err := json.Unmarshal(*bytes, &rData); err != nil { log.Printf("[MANAGER-ERR]contentRecommendation GetData Error %v \n", err) return nil } return rData } columnCode, _ := config.Sysconfig["columnCode"].(map[string]interface{}) jySchoolCode := qu.InterfaceToStr(columnCode["招投标攻略"]) industryInfoCode := qu.InterfaceToStr(columnCode["行业资讯"]) industryInfoUrl, _ := config.Sysconfig["industryInfoUrl"].(map[string]interface{}) jySchoolUrl, _ := config.Sysconfig["jySchoolUrl"].(map[string]interface{}) column, ok := mongodb.Find("column", map[string]interface{}{"$or": []map[string]interface{}{ {"pid": "ztbgl"}, {"pid": "hyzx"}, {"pid": "bzzx"}, }}, `{"i_order":1}`, "", false, -1, -1) dataMap := make(map[string][]KeyType) if ok && column != nil && len(*column) > 0 { for _, v := range *column { pid := qu.InterfaceToStr(v["pid"]) code := qu.InterfaceToStr(v["s_columncode"]) var v1 KeyType v1.Name = qu.InterfaceToStr(v["s_columnname"]) if pid == jySchoolCode { v1.Url = fmt.Sprintf(qu.InterfaceToStr(jySchoolUrl["towUrl"]), code) } else if pid == industryInfoCode { v1.Url = fmt.Sprintf(qu.InterfaceToStr(industryInfoUrl["towUrl"]), code) } else if pid == "bzzx" { v1.Url = fmt.Sprintf("/helpCenter/catalog/%s", code) } dataMap[pid] = append(dataMap[pid], v1) } } var data []KeyType for _, v := range []string{jySchoolCode, industryInfoCode, "bzzx"} { if v1, ok1 := dataMap[v]; ok1 && v1 != nil { var d KeyType switch v { case jySchoolCode: d.Name = "招投标攻略" d.Url = qu.InterfaceToStr(jySchoolUrl["homeUrl"]) d.SeedData = v1 case industryInfoCode: d.Name = "行业资讯" d.Url = qu.InterfaceToStr(industryInfoUrl["homeUrl"]) d.SeedData = v1 case "bzzx": d.Name = "帮助中心" d.Url = "/helpCenter/index" d.SeedData = v1 } data = append(data, d) } } if bytes, err := json.Marshal(data); err == nil && bytes != nil { _ = redis.PutBytes(RedisNameNew, "contentRecommendation", &bytes, 12*60*60) } return data } type Signal struct { Name string `json:"name"` Url string `json:"url"` Data []map[string]interface{} `json:"data"` } // 推荐标讯 func RecommendationBeacon() []Signal { if bytes, err := redis.GetBytes(RedisNameNew, "recommendationBeacon"); err == nil && bytes != nil { var rData []Signal if err := json.Unmarshal(*bytes, &rData); err != nil { log.Printf("[MANAGER-ERR]recommendationBeacon GetData Error %v \n", err) return nil } return rData } sy := sync.RWMutex{} wg := sync.WaitGroup{} var data, dataArr []Signal for _, v := range []string{"招标预告", "招标公告", "招标结果", "招标信用信息"} { wg.Add(1) go func(vst string) { defer wg.Done() var list []map[string]interface{} _, _, lists := bidsearch.GetPcBidSearchData("", "", "", "", vst, "", "", "", "", "", "", "", "", 1, false, nil, bidSearch_field_1, "", false, false, "", 8, "") if lists != nil { for _, v1 := range *lists { v1["_id"] = encrypt.CommonEncodeArticle("content", v1["_id"].(string)) delete(v1, "toptype") delete(v1, "s_subscopeclass") tmpdate := v1["publishtime"] v1["publishtime"] = qu.Int64All(tmpdate.(float64)) if v1["budget"] != nil { v1["budget"] = ConversionMoeny(v1["budget"]) } else if v1["bidamount"] != nil { v1["budget"] = ConversionMoeny(v1["bidamount"]) } } list = *lists } var d Signal d.Name = vst d.Url = fmt.Sprintf("/jylab/supsearch/index.html?subtype=%s", vst) d.Data = list sy.Lock() dataArr = append(dataArr, d) sy.Unlock() }(v) } wg.Wait() for _, v := range []string{"招标预告", "招标公告", "招标结果", "招标信用信息"} { for _, v1 := range dataArr { if v == v1.Name { data = append(data, v1) } } } if bytes, err := json.Marshal(data); err == nil && bytes != nil { _ = redis.PutBytes(RedisNameNew, "recommendationBeacon", &bytes, 5*60) } return data } // 不包含上限 [min, max) func getRandomWithAll(min, max int) int { rand.Seed(time.Now().UnixNano()) return rand.Intn(max-min) + min } // this.T["letterList"],this.T["letterListCount"],this.T["pagingMap"]=this.GetLetterPaging(pageNum,checkedLetter) func GetLetterPaging(pageNum int, checkedLetter string) (letterList []map[string]interface{}, letterListCount int64, pagingMap map[string]interface{}) { seoLetterPageSize := qu.Int64All(config.Seoconfig["seoLetterPageSize"]) if pageNum == 0 { pageNum = 1 } letterList, letterListCount = GetLetterMap(seoLetterPageSize, int64(pageNum), checkedLetter) pagecount := int(math.Ceil(qu.Float64All(letterListCount) / float64(seoLetterPageSize))) paging := paging.PaggingHtml(pageNum, pagecount, fmt.Sprintf("/tags/letter/%s", checkedLetter)+"_%v.html") pagingMap = map[string]interface{}{ "paging": paging, "pageNum": pageNum, "pageCount": pagecount, "pageSize": seoLetterPageSize, } return } func GetLetterMap(pageSize, pageNum int64, letter string) ([]map[string]interface{}, int64) { m := []map[string]interface{}{} sql := `select id,name,letter from seo_words.seo_resource where letter = ? order by id desc` cql := `select count(1) from seo_words.seo_resource where letter = ?` offset := (pageNum - 1) * pageSize sql += fmt.Sprintf(" limit %v,%v", offset, pageSize) data := public.BaseMysql.SelectBySql(sql, letter) count := public.BaseMysql.CountBySql(cql, letter) if data != nil { for _, v := range *data { letter := qu.ObjToString(v["letter"]) id := qu.Int64All(v["id"]) name := qu.ObjToString(v["name"]) name += qu.ObjToString(config.Seoconfig["seoKeywordSuffix"]) m = append(m, map[string]interface{}{ "name": name, "url": fmt.Sprintf("/tags/letter/all_all_all_%v_%v.html", letter, id), }) } } return m, count } func GetIndustry(industryHref string) []map[string]interface{} { data := public.BaseMysql.SelectBySql(`select a.id,a.name,b.id class_id,b.name class_1 from seo_words.seo_industry a left join seo_words.seo_industry_class b on a.class_1=b.name order by a.class_1`) industryArr := []string{} industryMap := map[string][]map[string]interface{}{} if len(*data) > 0 && data != nil { for _, v := range *data { class := qu.ObjToString(v["class_1"]) name := qu.ObjToString(v["name"]) id := qu.Int64All(v["id"]) industryId := qu.Int64All(v["class_id"]) if !IsInArr(industryArr, class) { industryArr = append(industryArr, class) } industryMap[class] = append(industryMap[class], map[string]interface{}{ "name": name + qu.ObjToString(config.Seoconfig["seoKeywordSuffix"]), // "url": fmt.Sprintf("/tags/industry/%v_all_all_%v.html", industryId, id), "url": fmt.Sprintf(industryHref, industryId, id), }) } } m := []map[string]interface{}{} // for _, v := range industryArr { m = append(m, industryMap[v]...) } return m } type BuyerList struct { Name string `json:"name"` Url string `json:"url"` } // 热门采购单位 func HotBuyerList(entIsNew bool) []*BuyerList { // 使用当前时间作为随机数生成器的种子 randGen := rand.New(rand.NewSource(time.Now().UnixNano())) // 获取一个范围在 [0, 100) 的随机整数 start := randGen.Intn(100) buyerQuery := fmt.Sprintf(`{"query": {"bool": {"must": [{"exists": {"field": "name"}}]}},"from": %d,"size": %d}`, start, 200) log.Println("buyerQuery:", buyerQuery) data := elastic.Get("buyer", "buyer", buyerQuery) if len(*data) > 0 { var buyerList []*BuyerList for _, b := range *data { name := qu.ObjToString(b["name"]) buyerList = append(buyerList, &BuyerList{ Name: name, Url: qu.If(entIsNew, fmt.Sprintf("/entpc/unit_portrayal/%s", name), fmt.Sprintf("/swordfish/page_big_pc/unit_portrayal/%s", name)).(string), }) } return buyerList } return nil } func GetIncludedInfo() map[string]interface{} { if bytes, err := redis.GetBytes(RedisNameNew, "jyIncludedInfo"); err == nil && bytes != nil { rData := map[string]interface{}{} if err := json.Unmarshal(*bytes, &rData); err != nil { log.Printf("[MANAGER-ERR]jyIncludedInfo GetData Error %v \n", err) return nil } return rData } data := public.BaseMysql.SelectBySql(`select bid,project,ent,buyer,bid_day_update,bid_field,field_accuracy,create_time from included_info order by create_time desc limit 1`) if data == nil || len(*data) <= 0 { return nil } info := (*data)[0] //招标信息的数值 bid := qu.Int64All(info["bid"]) Bid, BidUnit := formdataNum(bid) //招标采购项目的数值 project := qu.Int64All(info["project"]) Project, ProjectUnit := formdataNum(project) //企业数据库的数值 ent := qu.Int64All(info["ent"]) Ent, EntUnit := formdataNum(ent) //采购单位库的数值 buyer := qu.Int64All(info["buyer"]) Buyer, BuyerUnit := formdataNum(buyer) //每日更新招标信息的数值 bid_day_update := qu.Int64All(info["bid_day_update"]) BidDayUpdate, BidDayUpdateUnit := formdataNum(bid_day_update) mdata, ok := public.MQFW.Find("swordfish_index", map[string]interface{}{ "i_push": map[string]interface{}{ "$exists": true, }, }, `{"_id":-1}`, `{"i_push":1}`, false, 0, 1) i_push := 0 if mdata != nil && ok && len(*mdata) > 0 { swordData := (*mdata)[0] i_push = qu.IntAll(swordData["i_push"]) } Push, PushUnit := formdataNum(int64(i_push)) m := map[string]interface{}{ "bid": Bid, "bidUnit": BidUnit, "project": Project, "projectUnit": ProjectUnit, "ent": Ent, "entUnit": EntUnit, "buyer": Buyer, "buyerUnit": BuyerUnit, "bidDayUpdate": BidDayUpdate, "bidDayUpdateUnit": BidDayUpdateUnit, "push": Push, "pushUnit": PushUnit, } if bytes, err := json.Marshal(m); err == nil && bytes != nil { _ = redis.PutBytes(RedisNameNew, "jyIncludedInfo", &bytes, 2*60*60) } return m } func HotKey() []string { if bytes, err := redis.GetBytes(RedisNameNew, "jyhotkey_7"); err == nil && bytes != nil { rData := []string{} if err := json.Unmarshal(*bytes, &rData); err != nil { log.Printf("[MANAGER-ERR]jyhotkey_7 GetData Error %v \n", err) return nil } return rData } num := 7 count := public.BaseMysql.CountBySql(`select count(1) from seo_words.seo_resource;`) rand.Seed(time.Now().UnixNano()) randNum := rand.Intn(int(count) - num) data := public.BaseMysql.SelectBySql(`select name from seo_words.seo_resource limit ?,?`, randNum, num) arr := []string{} for _, v := range *data { arr = append(arr, qu.ObjToString(v["name"])) } if bytes, err := json.Marshal(arr); err == nil && bytes != nil { _ = redis.PutBytes(RedisNameNew, "jyhotkey_7", &bytes, 10*60) } return arr } func NewIndexbids(session *httpsession.Session, r *http.Request) []map[string]interface{} { if bytes, err := redis.GetBytes(RedisNameNew, "jyNewIndexbids"); err == nil && bytes != nil { rData := []map[string]interface{}{} if err := json.Unmarshal(*bytes, &rData); err != nil { log.Printf("[MANAGER-ERR]jyNewIndexbids GetData Error %v \n", err) return rData } return rData } /* userInfo := jy.GetVipState(session, *config.Middleground, "") so := NewSearchOptimize("", "", "", "", "招标预告,招标公告,招标结果,招标信用信息", "", "", "title", "", "", "", "", "", "", "", "", "", "PC", "", 0, 50, 0, 0, 0, *userInfo, true, r) so.DefaultSearchParamsAuto() //缓存数据 _, total, _ := so.GetBidSearchList(true) data.Count = total */ _, _, lists := bidsearch.GetPcBidSearchData("", "", "", "", "", "", "", "", "", "", "", "", "", 1, false, nil, bidSearch_field_1, "", false, false, "", 10, "") if lists != nil { for _, v1 := range *lists { v1["_id"] = encrypt.CommonEncodeArticle("content", v1["_id"].(string)) delete(v1, "toptype") delete(v1, "s_subscopeclass") tmpdate := v1["publishtime"] v1["publishtime"] = time.Unix(qu.Int64All(tmpdate.(float64)), 0).Format(date.Date_Short_Layout) if v1["budget"] != nil { v1["budget"] = ConversionMoeny(v1["budget"]) } else if v1["bidamount"] != nil { v1["budget"] = ConversionMoeny(v1["bidamount"]) } } } if bytes, err := json.Marshal(*lists); err == nil && bytes != nil { _ = redis.PutBytes(RedisNameNew, "jyNewIndexbids", &bytes, 5*60) } return *lists } // 格式输出数据 // 亿亿、万亿、亿、万 只有一位的时候保留1位小数点 两位及以上不保留 1.1亿 11亿 func formdataNum(num int64) (floatNum float64, unit string) { s_num := strconv.Itoa(int(num)) len_m := len(s_num) m := "" indexArr := []int{17, 13, 9, 5} unitArr := []string{"亿亿", "万亿", "亿", "万"} for k, v := range indexArr { if len_m > v { if qu.IntAll(s_num[len_m-(v-1):len_m-(v-2)]) >= 5 { if qu.IntAll(s_num[0:len_m-(v-1)])+1 == 10 { //满10 进 1 m1, _ := strconv.Atoi(s_num[0 : len_m-(v-1)]) m = strconv.Itoa(m1 + 1) } else { //满 万 进1 单位 if qu.IntAll(s_num[0:len_m-(v-1)])+1 == 10000 { m = "1" unit = unitArr[k-1] } else { m = strconv.Itoa(qu.IntAll(s_num[0:len_m-(v-1)]) + 1) } } // log.Println("m1:", m) } else { m = s_num[0 : len_m-(v-1)] // log.Println("m2:", m) } } else if len_m == v { // if qu.IntAll(s_num[len_m-(v-2):len_m-(v-3)]) >= 5 { m = s_num[0 : len_m-(v-1)] //满10 进 1 if qu.IntAll(s_num[len_m-(v-1):len_m-(v-2)])+1 == 10 { m1, _ := strconv.Atoi(s_num[0 : len_m-(v-1)]) m = strconv.Itoa(m1 + 1) } else { m += "." + strconv.Itoa(qu.IntAll(s_num[len_m-(v-1):len_m-(v-2)])+1) } // log.Println("m3:", m) } else { m = s_num[0 : len_m-(v-1)] m += "." + s_num[len_m-(v-1):len_m-(v-2)] // log.Println("m4:", m) } } if m != "" { if unit == "" { unit = unitArr[k] } break } } if m == "" { m = s_num } //string 转float floatNum, _ = strconv.ParseFloat(m, 64) return floatNum, unit }