ziwen 1 年之前
父节点
当前提交
2c77cdac6b
共有 7 个文件被更改,包括 184 次插入0 次删除
  1. 90 0
      controller/help_doc.go
  2. 二进制
      hz_eta_docs_api
  3. 1 0
      init_serve/router.go
  4. 41 0
      models/crm/help_doc_classify.go
  5. 7 0
      models/request/help_doc.go
  6. 13 0
      routers/help_doc.go
  7. 32 0
      services/help_doc_classify.go

+ 90 - 0
controller/help_doc.go

@@ -0,0 +1,90 @@
+package controller
+
+import (
+	"fmt"
+	"github.com/gin-gonic/gin"
+	"github.com/go-playground/validator/v10"
+	"hongze/hz_eta_docs_api/controller/resp"
+	"hongze/hz_eta_docs_api/global"
+	"hongze/hz_eta_docs_api/models/crm"
+	"hongze/hz_eta_docs_api/models/request"
+	"hongze/hz_eta_docs_api/services"
+)
+
+// HelpDocController 帮助文档
+type HelpDocController struct{}
+
+// Menu
+// @Description 菜单
+// @Success 200 {string} string "获取成功"
+// @Router /help_doc/classify/list [get]
+func (a *HelpDocController) ClassifyList(c *gin.Context) {
+	var req request.HelpDocClassifyListReq
+	err := c.Bind(&req)
+	if err != nil {
+		errs, ok := err.(validator.ValidationErrors)
+		if !ok {
+			resp.FailData("参数解析失败", "Err:"+err.Error(), c)
+			return
+		}
+		resp.FailData("参数解析失败", errs.Translate(global.Trans), c)
+		return
+	}
+fmt.Println("code:",req.BusCode)
+	// 获取列表数据
+	logOb := new(crm.HelpDocClassify)
+	rootList, e := logOb.GetItemsByCondition("parent_id=0", make([]interface{}, 0), "sort asc,classify_id asc")
+	if e != nil {
+		resp.FailMsg("获取失败", "获取帮助文档列表失败, Err: "+e.Error(), c)
+		return
+	}
+
+	classifyAll, e := logOb.GetItemsByCondition("", make([]interface{}, 0), "sort asc,classify_id asc")
+	if e != nil {
+		resp.FailMsg("获取失败", "获取帮助文档列表失败, Err: "+e.Error(), c)
+		return
+	}
+
+	classifies := make([]*crm.HelpDocClassifyItems, 0)
+	for _, v := range classifyAll {
+		child := make([]*crm.HelpDocClassifyItems, 0)
+		item := crm.HelpDocClassifyItems{
+			ClassifyId:         v.ClassifyId,
+			ClassifyName:       v.ClassifyName,
+			ParentId:           v.ParentId,
+			Level:              v.Level,
+			Sort:               v.Sort,
+			SysUserId:          v.SysUserId,
+			SysUserRealName:    v.SysUserRealName,
+			VisibleBusinessIds: v.VisibleBusinessIds,
+			Children:           child,
+		}
+		classifies = append(classifies, &item)
+	}
+
+
+	roots := make([]*crm.HelpDocClassifyItems, 0)
+	for _, v := range rootList {
+		child := make([]*crm.HelpDocClassifyItems, 0)
+		item := crm.HelpDocClassifyItems{
+			ClassifyId:         v.ClassifyId,
+			ClassifyName:       v.ClassifyName,
+			ParentId:           v.ParentId,
+			Level:              v.Level,
+			Sort:               v.Sort,
+			SysUserId:          v.SysUserId,
+			SysUserRealName:    v.SysUserRealName,
+			VisibleBusinessIds: v.VisibleBusinessIds,
+			Children:           child,
+		}
+		roots = append(roots, &item)
+	}
+	nodeAll := make([]*crm.HelpDocClassifyItems, 0)
+	for k := range roots {
+		rootNode := roots[k]
+		services.HelpDocClassifyItemsMakeTree(classifies, rootNode)
+		nodeAll = append(nodeAll, rootNode)
+	}
+
+	resp.OkData("获取成功", nodeAll, c)
+}

二进制
hz_eta_docs_api


+ 1 - 0
init_serve/router.go

@@ -18,5 +18,6 @@ func InitRouter() (r *gin.Engine) {
 
 	rBase := r.Group("api/")
 	routers.InitVersionUpdateLog(rBase) // 版本更新日志
+	routers.InitHelpDoc(rBase)          // 帮助文档
 	return
 }

+ 41 - 0
models/crm/help_doc_classify.go

@@ -0,0 +1,41 @@
+package crm
+
+import "hongze/hz_eta_docs_api/global"
+
+type HelpDocClassify struct {
+	ClassifyId         int    `gorm:"column:classify_id;primary_key;AUTO_INCREMENT" json:"classify_id"`
+	ClassifyName       string `gorm:"column:classify_name;NOT NULL" json:"classify_name"`   // 分类名称
+	ParentId           int    `gorm:"column:parent_id;default:0;NOT NULL" json:"parent_id"` // 父级id
+	CreateTime         string `gorm:"column:create_time" json:"create_time"`                // 创建时间
+	ModifyTime         string `gorm:"column:modify_time" json:"modify_time"`                // 修改时间
+	SysUserId          int    `gorm:"column:sys_user_id" json:"sys_user_id"`                // 创建人id
+	SysUserRealName    string `gorm:"column:sys_user_real_name" json:"sys_user_real_name"`  // 创建人姓名
+	Level              int    `gorm:"column:level;default:0" json:"level"`                  // 层级
+	Sort               int    `gorm:"column:sort;default:10" json:"sort"`                   // 排序字段,越小越靠前,默认值:10
+	VisibleBusinessIds string `gorm:"column:visible_business_ids;NOT NULL" json:"-"`        // 可见商家ids
+}
+
+func (m *HelpDocClassify) TableName() string {
+	return "`help_doc_classify`"
+}
+
+// GetItemsByCondition 获取列表
+func (m *HelpDocClassify) GetItemsByCondition(condition string, pars []interface{}, orderRule string) (items []*HelpDocClassify, err error) {
+	if orderRule == "" {
+		orderRule = "create_time DESC"
+	}
+	err = global.MYSQL["hz_crm"].Where(condition, pars...).Order(orderRule).Find(&items).Error
+	return
+}
+
+type HelpDocClassifyItems struct {
+	ClassifyId         int `description:"分类id"`
+	ClassifyName       string
+	ParentId           int
+	Level              int    `description:"层级"`
+	Sort               int    `description:"排序字段,越小越靠前,默认值:10"`
+	SysUserId          int    `description:"创建人id"`
+	SysUserRealName    string `description:"创建人姓名"`
+	VisibleBusinessIds string `json:"-"`
+	Children           []*HelpDocClassifyItems
+}

+ 7 - 0
models/request/help_doc.go

@@ -0,0 +1,7 @@
+package request
+
+// VersionUpdateLogListReq 更新日志列表请求体
+type HelpDocClassifyListReq struct {
+	BusCode string `json:"bus_code" form:"bus_code"`
+}
+

+ 13 - 0
routers/help_doc.go

@@ -0,0 +1,13 @@
+package routers
+
+import (
+	"github.com/gin-gonic/gin"
+	"hongze/hz_eta_docs_api/controller"
+)
+
+func InitHelpDoc(r *gin.RouterGroup) {
+	c := new(controller.HelpDocController)
+	authGroup := r.Group("help_doc/")
+	authGroup.GET("classify/list", c.ClassifyList)
+}
+

+ 32 - 0
services/help_doc_classify.go

@@ -0,0 +1,32 @@
+package services
+
+import "hongze/hz_eta_docs_api/models/crm"
+
+func helpDocClassifyHaveChild(allNode []*crm.HelpDocClassifyItems, node *crm.HelpDocClassifyItems) (childs []*crm.HelpDocClassifyItems, yes bool) {
+	for _, v := range allNode {
+		if v.ParentId == node.ClassifyId {
+			childs = append(childs, v)
+		}
+	}
+	if len(childs) > 0 {
+		yes = true
+	}
+	return
+}
+
+func HelpDocClassifyItemsMakeTree(allNode []*crm.HelpDocClassifyItems, node *crm.HelpDocClassifyItems) {
+	childs, _ := helpDocClassifyHaveChild(allNode, node) //判断节点是否有子节点并返回
+	if len(childs) > 0 {
+		node.Children = append(node.Children, childs[0:]...) //添加子节点
+		for _, v := range childs {                           //查询子节点的子节点,并添加到子节点
+			_, has := helpDocClassifyHaveChild(allNode, v)
+			if has {
+				HelpDocClassifyItemsMakeTree(allNode, v) //递归添加节点
+			} else {
+				v.Children = nil
+			}
+		}
+	} else {
+		node.Children = nil
+	}
+}