Kaynağa Gözat

wip:路由提交

wangkaiyue 1 yıl önce
ebeveyn
işleme
febbb19b75

+ 41 - 7
internal/controller/area.go

@@ -13,7 +13,7 @@ import (
 // AreaIndexHandler 地区站首页
 func AreaIndexHandler(areaNode *service.AreaNode, r *ghttp.Request) {
 	areaType := r.Get("type").String()
-	service.HtmlRender.Render(r, utility.GetCommonRenderPatch(r.Request.UserAgent(), "area_index.html"),
+	utility.HtmlRender.Render(r, utility.GetCommonRenderPatch(r.Request.UserAgent(), "area_index.html"),
 		g.Map{
 			"areaType": areaType,
 			"areaNode": areaNode,
@@ -21,23 +21,57 @@ func AreaIndexHandler(areaNode *service.AreaNode, r *ghttp.Request) {
 		})
 }
 
-// AreaListHandler 地区列表页面
-func AreaListHandler(areaNode *service.AreaNode, r *ghttp.Request) {
+// CityListHandler 城市子站列表页面
+func CityListHandler(areaNode *service.AreaNode, r *ghttp.Request) {
 	pageNum := r.Get("pageNum", 1).Int() //页码
+	code := r.Get("code").String()
+	cityNode := service.JyBxSeoAreaRoot.GetNodeByCode(code)
+	if cityNode == nil {
+		utility.HtmlRender.NotFound(r)
+		return
+	}
 	// 查询数据
-	query := service.NewBiddingQuery().EquipArea(areaNode)
+	query := service.NewBiddingQuery().EquipArea(cityNode)
 	rData, err := query.GetDataPageList(r.Context(), pageNum, consts.BiddingListMaxTotal, "AreaPageHandler", service.JyBxSeoAreaRoot.GetData)
 	if err != nil {
 		g.Log().Errorf(r.Context(), err.Error())
-		service.HtmlRender.RenderError(r, fmt.Errorf("获取列表数据异常"))
+		utility.HtmlRender.RenderError(r, fmt.Errorf("获取列表数据异常"))
 		return
 	}
-	service.HtmlRender.Render(r, utility.GetCommonRenderPatch(r.Request.UserAgent(), "area_list.html"),
+	utility.HtmlRender.Render(r, utility.GetCommonRenderPatch(r.Request.UserAgent(), "area_list.html"),
 		g.Map{
 			"areaNode": areaNode,
+			"cityNode": cityNode,
 			"list":     rData.List,
 			//"tdk":        service.JySeoTdk.GetAreaSTypeListTdk(r.Context(), sTypeNode.Code, areaNode.Name),
-			"pagination": service.GetLetterPaging(pageNum, gconv.Int(rData.Total), fmt.Sprintf("/%s_p%s", areaNode.Code, "%d")),
+			"pagination": utility.GetLetterPaging(pageNum, gconv.Int(rData.Total), fmt.Sprintf("/%s_%s", cityNode.Code, "%d")),
+		},
+	)
+}
+
+func AreaClassListHandler(areaNode *service.AreaNode, r *ghttp.Request) {
+	pageNum := r.Get("pageNum", 1).Int() //页码
+	code := r.Get("code").String()
+	classNode := service.JyBxSeoClassRoot.GetNodeByCode(code)
+	if classNode == nil {
+		utility.HtmlRender.NotFound(r)
+		return
+	}
+	// 查询数据
+	query := service.NewBiddingQuery().EquipArea(areaNode).EquipIndustry(classNode.Name, "")
+	rData, err := query.GetDataPageList(r.Context(), pageNum, consts.BiddingListMaxTotal, "AreaPageHandler", service.JyBxSeoAreaRoot.GetData)
+	if err != nil {
+		g.Log().Errorf(r.Context(), err.Error())
+		utility.HtmlRender.RenderError(r, fmt.Errorf("获取列表数据异常"))
+		return
+	}
+	utility.HtmlRender.Render(r, utility.GetCommonRenderPatch(r.Request.UserAgent(), "area_list.html"),
+		g.Map{
+			"areaNode":  areaNode,
+			"classNode": classNode,
+			"list":      rData.List,
+			//"tdk":        service.JySeoTdk.GetAreaSTypeListTdk(r.Context(), sTypeNode.Code, areaNode.Name),
+			"pagination": utility.GetLetterPaging(pageNum, gconv.Int(rData.Total), fmt.Sprintf("/%s_%s", classNode.Code, "%d")),
 		},
 	)
 }

+ 9 - 1
internal/controller/detail.go

@@ -8,8 +8,16 @@ import (
 )
 
 func BiddingDetail(r *ghttp.Request) {
-	service.HtmlRender.Render(r, utility.GetCommonRenderPatch(r.Request.UserAgent(), "detail.html"),
+	isLogin := utility.JySessionLoginEd(r)
+	seoId := r.Get("seoId").String()
+	if seoId == "" {
+		utility.HtmlRender.NotFound(r)
+		return
+	}
+	detail := service.JyBxSeoDetailRoot.GetDetail(seoId, isLogin)
+	utility.HtmlRender.Render(r, utility.GetCommonRenderPatch(r.Request.UserAgent(), "detail.html"),
 		g.Map{
+			"detail": detail,
 			//"tdk":      service.JySeoTdk.GetAreaIndexTdk(r.Context(), node.Name),
 		})
 }

+ 22 - 18
internal/controller/transfer.go

@@ -3,39 +3,43 @@ package controller
 import (
 	"github.com/gogf/gf/v2/net/ghttp"
 	"jybxseo/internal/service"
+	"jybxseo/utility"
 	"strings"
 )
 
 // IndexTransfer 首页中转
 func IndexTransfer(r *ghttp.Request) {
 	subDomain := getSubdomain(r.Request.Host)
-	if areaNode := service.JyBxSeoAreaRoot.GetNodeByCode(subDomain); areaNode != nil { //判断是否是地区
+	if areaNode := service.JyBxSeoAreaRoot.GetNodeByCode(subDomain); areaNode != nil {
+		//地区首页
 		AreaIndexHandler(areaNode, r)
 		return
-	} else if service.JyBxSeoAreaRoot.GetNodeByCode(subDomain) != nil { //判断是否是行业(后续开发)
-		service.HtmlRender.NotFound(r)
-		return
-	} else {
-		//判断是否是行业
-		service.HtmlRender.NotFound(r)
-		return
+		//} else if classNode := service.JyBxSeoClassRoot.GetNodeByCode(subDomain); classNode != nil {
+		//	//判断是否是行业(后续开发)
+		//	return
 	}
+	// 未知页面
+	utility.HtmlRender.NotFound(r)
 }
 
 // ListTransfer 列表页中转
 func ListTransfer(r *ghttp.Request) {
 	subDomain := getSubdomain(r.Request.Host)
-	if areaNode := service.JyBxSeoAreaRoot.GetNodeByCode(subDomain); areaNode != nil { //判断是否是地区
-		AreaListHandler(areaNode, r)
-		return
-	} else if service.JyBxSeoAreaRoot.GetNodeByCode(subDomain) != nil { //判断是否是行业(后续开发)
-		service.HtmlRender.NotFound(r)
-		return
-	} else {
-		//判断是否是行业
-		service.HtmlRender.NotFound(r)
-		return
+	if areaNode := service.JyBxSeoAreaRoot.GetNodeByCode(subDomain); areaNode != nil {
+		//判断是否是地区
+		code := r.Get("code").String()
+		if areaNode.GetChildNode(code) != nil {
+			CityListHandler(areaNode, r)
+			return
+		} else if service.JyBxSeoClassRoot.GetNodeByCode(code) != nil {
+			AreaClassListHandler(areaNode, r)
+			return
+		}
+		//} else if classNode := service.JyBxSeoClassRoot.GetNodeByCode(subDomain); classNode != nil { //待开发
+		// //判断是否是行业(后续开发)
+		// return
 	}
+	utility.HtmlRender.NotFound(r)
 }
 
 // getSubdomain 获取二级域名

+ 12 - 0
internal/service/areaStruct.go

@@ -109,6 +109,18 @@ func (aRoot *AreaRoot) GetData(ctx context.Context, maxTotal int, query *SeoBidd
 	return FillingBiddingBaseFields(ctx, queryRes.List())
 }
 
+func (an *AreaNode) GetChildNode(code string) *AreaNode {
+	if len(an.Child) == 0 {
+		return nil
+	}
+	for _, node := range an.Child {
+		if node.Code == code {
+			return node
+		}
+	}
+	return nil
+}
+
 // GetNodeByCode 根据code
 func (aRoot *AreaRoot) GetNodeByCode(code string) *AreaNode {
 	return aRoot.areaCodeMap[code]

+ 128 - 0
internal/service/classStruct.go

@@ -0,0 +1,128 @@
+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"
+	"jybxseo/internal/consts"
+)
+
+var (
+	JyBxSeoClassRoot *ClassRoot = &ClassRoot{}
+)
+
+type (
+	ClassRoot struct {
+		classTree    map[string]*ClassNode //层级关系
+		classCodeMap map[string]*ClassNode //所有节点平铺 key:code
+		classNameMap map[string]*ClassNode //所有节点平铺 key:name
+		rootList     []*ClassNode          //根节点
+	}
+	ClassNode struct {
+		Name  string       `json:"name" doc:"名称"`
+		Code  string       `json:"code" doc:"代码"`
+		PNode *ClassNode   `json:"pNode" doc:"父节点代码"`
+		Type  int          `json:"type" doc:"1一级分类 2二级分类"`
+		Child []*ClassNode `json:"child" doc:"子栏目"`
+	}
+)
+
+func init() {
+	JyBxSeoClassRoot.LoadClassFrom(gctx.New())
+}
+
+func (cRoot *ClassRoot) LoadClassFrom(ctx context.Context) {
+	classTree, classCodeMap, classNameMap := map[string]*ClassNode{}, map[string]*ClassNode{}, map[string]*ClassNode{}
+	var rootArr []*ClassNode
+	for _, m := range g.Cfg("global").MustGet(context.Background(), "allClassTree").Maps() {
+		root := &ClassNode{
+			Name: gconv.String(m["name"]),
+			Code: gconv.String(m["code"]),
+			Type: 1,
+		}
+		for _, n := range gconv.Maps(m["child"]) {
+			node := &ClassNode{
+				Name:  gconv.String(n["name"]),
+				Code:  gconv.String(n["code"]),
+				PNode: root,
+				Type:  2,
+			}
+			root.Child = append(root.Child, node)
+
+			//if classCodeMap[node.Code] != nil {
+			//	fmt.Println("node.Code重复", node.Code)
+			//}
+			//if classNameMap[node.Name] != nil {
+			//	fmt.Println("node.Name重复", node.Name)
+			//}
+
+			classCodeMap[node.Code] = node
+			classNameMap[node.Name] = node
+		}
+		classTree[root.Code] = root
+		classCodeMap[root.Code] = root
+		classCodeMap[root.Name] = root
+		rootArr = append(rootArr, root)
+	}
+	cRoot.classTree, cRoot.classCodeMap = classTree, classCodeMap
+	cRoot.classNameMap = classNameMap
+	cRoot.rootList = rootArr
+}
+
+// GetData 获取地区数据
+func (cRoot *ClassRoot) GetData(ctx context.Context, maxTotal int, query *SeoBiddingQuery) []map[string]interface{} {
+	var sql string
+	var values []interface{}
+	if query.district != "" {
+		sql += " AND b.district=? "
+		values = append(values, query.district)
+	} else if query.city != "" {
+		sql += " AND b.city=? "
+		values = append(values, query.city)
+	} else if query.area != "" {
+		sql += " AND b.area=? "
+		values = append(values, query.area)
+	}
+
+	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+50)
+	queryRes, err := g.DB().Query(ctx, fmt.Sprintf(`SELECT b.bid_id
+			FROM jyseo.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 (cRoot *ClassRoot) GetNodeByCode(code string) *ClassNode {
+	return cRoot.classCodeMap[code]
+}
+
+// GetNodeByName 根据省份名字获取node
+func (cRoot *ClassRoot) GetNodeByName(name string) *ClassNode {
+	return cRoot.classNameMap[name]
+}
+
+// GetAllRootNodes 获取全部根地区节点
+func (cRoot *ClassRoot) GetAllRootNodes() []*ClassNode {
+	return cRoot.rootList
+}

+ 17 - 0
internal/service/detailStruct.go

@@ -0,0 +1,17 @@
+package service
+
+var (
+	JyBxSeoDetailRoot *DetailRoot = &DetailRoot{}
+)
+
+type (
+	DetailRoot struct {
+	}
+)
+
+// GetDetail 根据seoId查询标讯详情
+// seoId 标讯seoId标识
+// isLogin 是否登录,未登录内容加密
+func (*DetailRoot) GetDetail(seoId string, isLogin bool) map[string]interface{} {
+	return nil
+}

+ 4 - 4
internal/service/queryStruct.go

@@ -126,11 +126,11 @@ func (query *SeoBiddingQuery) GetDataPageList(ctx context.Context, pageNum, maxT
 	vars, err = g.Redis().Get(ctx, query.getDataPageListCacheKey(pageNum, maxTotal, flag))
 	if err != nil || vars.IsNil() {
 		//并发限制
-		if ok := JySeoQueryListLimit.Limit(); !ok {
+		if ok := utility.JySeoQueryListLimit.Limit(); !ok {
 			err = fmt.Errorf("请求超时")
 			return
 		}
-		defer JySeoQueryListLimit.Reset()
+		defer utility.JySeoQueryListLimit.Reset()
 
 		data := getData(ctx, maxTotal, query)
 		formatData := query.dataFormat(data)
@@ -178,11 +178,11 @@ func (query *SeoBiddingQuery) GetOnceData(ctx context.Context, total int, flag s
 	vars, err = g.Redis().Get(ctx, cacheKey)
 	if err != nil || vars.IsNil() {
 		//并发限制
-		if ok := JySeoQueryTabLimit.Limit(); !ok {
+		if ok := utility.JySeoQueryTabLimit.Limit(); !ok {
 			err = fmt.Errorf("请求超时")
 			return
 		}
-		defer JySeoQueryTabLimit.Reset()
+		defer utility.JySeoQueryTabLimit.Reset()
 
 		data := getData(ctx, total, query)
 		if len(data) > total {

+ 10 - 10
manifest/config/global.yaml

@@ -1183,8 +1183,8 @@ allClassTree:
         code: GGXCYS
       - name: 物业
         code: WY
-      - name: 其他
-        code: QT
+      - name: 服务其他  #[其他]重复
+        code: FWQT #[QT]重复
       - name: 法律咨询
         code: FLZX
       - name: 会计
@@ -1250,26 +1250,26 @@ allClassTree:
         code: RJKF
       - name: 运维服务
         code: YWFW
-      - name: 其他
-        code: QT
+      - name: 信息其他 #[其他]重复
+        code: XXQT  #[QT]重复
   - name: 交通工程
     code: JTGC
     child:
-      - name: 道路
-        code: DL
+      - name: 交通道路 #[道路]重复
+        code: JTDL   #[DL]重复
       - name: 轨道
         code: GD
       - name: 桥梁
         code: QL
       - name: 隧道
         code: SD
-      - name: 其他
-        code: QT
+      - name: 交通其他  # [其他]重复
+        code: JTQT # [QT]重复
   - name: 市政设施
     code: SZSS
     child:
-      - name: 道路
-        code: DL
+      - name: 市政道路 # [道路]重复
+        code: SZDL    # [DL]重复
       - name: 绿化
         code: LH
       - name: 线路管网

+ 3 - 0
utility/db.go

@@ -3,8 +3,10 @@ package utility
 import (
 	m "app.yhyue.com/moapp/jybase/mongodb"
 	"context"
+	"fmt"
 	"github.com/gogf/gf/v2/frame/g"
 	"github.com/gogf/gf/v2/os/gctx"
+	"jybxseo/internal/consts"
 )
 
 type (
@@ -27,6 +29,7 @@ var (
 
 func init() {
 	initCtx := gctx.New()
+	fmt.Println(consts.CityType)
 	if err := g.Cfg().MustGet(initCtx, "mongodb").Struct(&mongdbConf); err != nil {
 		panic(err)
 	}

+ 1 - 1
internal/service/limit.go → utility/limit.go

@@ -1,4 +1,4 @@
-package service
+package utility
 
 import (
 	"github.com/gogf/gf/v2/frame/g"

+ 1 - 1
internal/service/paging.go → utility/paging.go

@@ -1,4 +1,4 @@
-package service
+package utility
 
 import (
 	"fmt"

+ 1 - 1
internal/service/response.go → utility/response.go

@@ -1,4 +1,4 @@
-package service
+package utility
 
 import (
 	"fmt"