123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- 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"
- "jyseo/internal/consts"
- )
- var (
- JySeoSTypeRoot *STypeRoot = &STypeRoot{}
- )
- type (
- STypeRoot struct {
- sTypeTree map[string]*STypeNode //字母code层级关系
- sTypeAllNode map[string]*STypeNode //字母code所有节点平铺
- sTypeIdMap map[string]*STypeNode //数字id对应的信息类型
- nameMap map[string]*STypeNode
- parentNodes []*STypeNode //父级节点
- }
- STypeNode struct {
- Name string `json:"name" doc:"名称"`
- Code string `json:"code" doc:"代码"`
- PNode *STypeNode `json:"pNode" doc:"父节点"`
- Id string `json:"id" doc:"id"`
- Alias string `json:"alias" doc:"别称"`
- SIGN int `json:"sign" doc:"标签"`
- Child []*STypeNode `json:"child" doc:"子栏目"`
- }
- )
- func init() {
- JySeoSTypeRoot.LoadSTypeFrom(gctx.New())
- }
- func (sRoot *STypeRoot) LoadSTypeFrom(ctx context.Context) {
- sTypeTree, nameMap, sTypeAllNode, sTypeIdMap := map[string]*STypeNode{}, map[string]*STypeNode{}, map[string]*STypeNode{}, map[string]*STypeNode{}
- var parentNodes []*STypeNode
- for _, m := range g.Cfg("global").MustGet(context.Background(), "allSTypeTree").Maps() {
- root := &STypeNode{
- Name: gconv.String(m["name"]),
- Code: gconv.String(m["code"]),
- Id: gconv.String(m["id"]),
- Alias: gconv.String(m["name"]),
- SIGN: gconv.Int(m["signId"]),
- }
- if alias := gconv.String(m["alias"]); alias != "" {
- root.Alias = alias
- }
- for _, n := range gconv.Maps(m["child"]) {
- node := &STypeNode{
- Name: gconv.String(n["name"]),
- Code: gconv.String(n["code"]),
- Alias: gconv.String(n["name"]),
- PNode: root,
- }
- root.Child = append(root.Child, node)
- sTypeAllNode[node.Code] = node
- nameMap[node.Name] = node
- }
- nameMap[root.Name] = root
- sTypeTree[root.Code] = root
- sTypeAllNode[root.Code] = root
- sTypeIdMap[root.Id] = root
- parentNodes = append(parentNodes, root)
- }
- sRoot.sTypeTree, sRoot.sTypeAllNode, sRoot.sTypeIdMap = sTypeTree, sTypeAllNode, sTypeIdMap
- sRoot.parentNodes = parentNodes
- sRoot.nameMap = nameMap
- }
- func (sRoot *STypeRoot) GetData(ctx context.Context, maxTotal int, query *SeoBiddingQuery) []map[string]interface{} {
- var sql string
- var values []interface{}
- if query.topType != "" {
- if val, _ := consts.TopTypeMap[query.topType]; val != "" {
- sql += " AND b.toptype=? "
- values = append(values, val)
- } else {
- sql += " AND b.toptype=? "
- values = append(values, query.topType)
- }
- } else if query.subType != "" && query.keys == "" {
- sql += " AND b.subtype=? "
- values = append(values, query.subType)
- } else if query.topType == "" && query.subType == "" {
- sql += " AND (b.toptype !='拟建' AND b.toptype !='采购意向') "
- }
- values = append(values, maxTotal)
- queryRes, err := g.DB().Query(ctx, fmt.Sprintf(`SELECT b.bid_id
- FROM new_areaClass 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())
- }
- // GetNodeByCode 根据字母code获取信息类型节点
- func (sRoot *STypeRoot) GetNodeByCode(code string) *STypeNode {
- return sRoot.sTypeAllNode[code]
- }
- // GetNodeById 根据id获取信息类型节点
- func (sRoot *STypeRoot) GetNodeById(code string) *STypeNode {
- return sRoot.sTypeIdMap[code]
- }
- // GetParentNodes 获取节点树
- func (sRoot *STypeRoot) GetParentNodes() []*STypeNode {
- return sRoot.parentNodes
- }
- func (sRoot *STypeRoot) GetNodeByName(name string) *STypeNode {
- return sRoot.nameMap[name]
- }
|