123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- package service
- import (
- "context"
- "fmt"
- "github.com/gogf/gf/v2/frame/g"
- "github.com/gogf/gf/v2/os/gctx"
- "github.com/gogf/gf/v2/util/gconv"
- )
- var (
- JySeoKeyWordPinyinRoot *keywordPinyinRoot = &keywordPinyinRoot{}
- )
- type (
- keywordPinyinRoot struct {
- allKeywordsMap map[string]*KeyWordHotNode
- industryMap map[string][]*KeyWordHotNode
- }
- KeyWordHotNode struct {
- Code string `json:"code" doc:"代码"`
- Name string `json:"name" doc:"名称"`
- Industry string `json:"industry" doc:"行业"`
- Url string `json:"url" doc:"地址"`
- }
- )
- func init() {
- JySeoKeyWordPinyinRoot.LoadKeyWordFull(gctx.New())
- }
- func (sRoot *keywordPinyinRoot) LoadKeyWordFull(ctx context.Context) {
- hotSubjectKeywords := g.Config("global").MustGet(ctx, "pinyinKeywords").Maps()
- hotKeywordsMap, industryMap := map[string]*KeyWordHotNode{}, map[string][]*KeyWordHotNode{}
- for _, keyword := range hotSubjectKeywords {
- code := gconv.String(keyword["code"])
- name := gconv.String(keyword["name"])
- industry := gconv.String(keyword["industry"])
- node := &KeyWordHotNode{
- Code: code,
- Name: name,
- Industry: industry,
- Url: fmt.Sprintf("/list/keywords/%s.html", code),
- }
- hotKeywordsMap[code] = node
- industryMap[industry] = append(industryMap[industry], node)
- }
- sRoot.allKeywordsMap = hotKeywordsMap
- sRoot.industryMap = industryMap
- }
- // GetData 查询数据
- func (sRoot *keywordPinyinRoot) GetData(ctx context.Context, maxTotal int, query *SeoBiddingQuery) []map[string]interface{} {
- var sql string
- var values []interface{}
- if query.keys != "" {
- sql += " AND b.keyword=? "
- values = append(values, query.keys)
- }
- if query.topClass != "" {
- sql += " AND b.industry=? "
- values = append(values, query.topClass)
- }
- values = append(values, maxTotal+50)
- queryRes, err := g.DB().Query(ctx, fmt.Sprintf(`SELECT bid_id
- FROM new_pinyinKeywords b WHERE 1=1 %s
- ORDER BY b.publish_time DESC
- LIMIT 0,?`, sql), values...)
- if err != nil || queryRes.IsEmpty() {
- return nil
- }
- return FillingBiddingBaseFields(ctx, queryRes.List(), true)
- //res, err := g.DB().Query(ctx, "SELECT * FROM new_bidList WHERE bid_id IN ( SELECT bid_id FROM new_pinyinKeywords b WHERE 1=1 "+sql+" order by publish_time desc limit 0,? ) ORDER BY publish_time desc LIMIT 0, ?", values...)
- //if err != nil {
- // return nil
- //}
- //return res.List()
- }
- // GetPinyinNode 获取随机标的物
- func (sRoot *keywordPinyinRoot) GetPinyinNode(key string) *KeyWordHotNode {
- return sRoot.allKeywordsMap[key]
- }
- // GetPinyinNodeByIndustry 根据行业获取词
- func (sRoot *keywordPinyinRoot) GetPinyinNodeByIndustry() map[string][]*KeyWordHotNode {
- return sRoot.industryMap
- }
- func (sRoot *keywordPinyinRoot) GetPinyinIndustryShowSort() []string {
- return g.Config("global").MustGet(context.Background(), "pinyinKeywordsSort").Strings()
- }
- // GetRandomHotKeywords 获取随机拼音关键词
- func (sRoot *keywordPinyinRoot) GetRandomHotKeywords(num int) []*KeyWordHotNode {
- rData := make([]*KeyWordHotNode, 0, num)
- for _, node := range sRoot.allKeywordsMap {
- if len(rData) == num {
- return rData
- }
- rData = append(rData, node)
- }
- return rData
- }
|