123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181 |
- package controller
- import (
- "encoding/json"
- "eta/eta_docs/controller/resp"
- "eta/eta_docs/global"
- "eta/eta_docs/models/crm"
- "eta/eta_docs/models/request"
- "eta/eta_docs/services"
- "eta/eta_docs/utils"
- "github.com/gin-gonic/gin"
- "github.com/go-playground/validator/v10"
- "html"
- )
- // HelpDocController 帮助文档
- type HelpDocController struct{}
- // ClassifyList
- // @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
- }
- etaOb := new(crm.EtaBusiness)
- var pars []interface{}
- pars = append(pars, req.BusCode)
- etaBusiness, e := etaOb.GetItemByCondition("code_encrypt=?", pars, "")
- if e != nil {
- resp.FailMsg("获取失败", "获取帮助文档列表失败, Err: "+e.Error(), c)
- return
- }
- nodeAll := make([]*crm.HelpDocClassifyItems, 0)
- if etaBusiness != nil {
- // 获取列表数据
- docOb := new(crm.HelpDocClassify)
- var pars []interface{}
- pars = append(pars, etaBusiness.EtaBusinessId)
- rootList, e := docOb.GetItemsByCondition("parent_id=0 AND FIND_IN_SET(?,visible_business_ids) > 0 ", pars, "sort asc,classify_id asc")
- if e != nil {
- resp.FailMsg("获取失败", "获取帮助文档列表失败, Err: "+e.Error(), c)
- return
- }
- classifyAll, e := docOb.GetItemsByCondition("FIND_IN_SET(?,visible_business_ids) > 0", pars, "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)
- }
- for k := range roots {
- rootNode := roots[k]
- services.HelpDocClassifyItemsMakeTree(classifies, rootNode)
- nodeAll = append(nodeAll, rootNode)
- }
- }
- resp.OkData("获取成功", nodeAll, c)
- }
- // Detail
- // @Description 文章详情
- // @Success 200 {string} string "获取成功"
- // @Router /help_doc/detail [get]
- func (a *HelpDocController) Detail(c *gin.Context) {
- var req request.HelpDocClassifyDetailReq
- 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
- }
- // 获取列表数据
- docOb := new(crm.HelpDoc)
- var pars []interface{}
- pars = append(pars, req.ClassifyId)
- item, e := docOb.GetItemByCondition("classify_id=?", pars, "")
- if e != nil {
- if e == utils.ErrNoRow {
- resp.SpecificFail("获取失败", "文章不存在, Err: "+e.Error(), c)
- return
- }
- resp.FailMsg("获取失败", "获取帮助文档列表失败, Err: "+e.Error(), c)
- return
- }
- if item.Status != 2 {
- resp.SpecificFail("获取失败", "文章未发布 ", c)
- return
- }
- item.Content = html.UnescapeString(item.Content)
- var anchor []crm.AnchorList
- if item.Anchor != "" {
- err = json.Unmarshal([]byte(item.Anchor), &anchor)
- if err != nil {
- resp.FailMsg("解析失败", "解析锚点失败, Err: "+e.Error(), c)
- return
- }
- }
- var recommend []crm.RecommendList
- if item.Recommend != "" {
- err = json.Unmarshal([]byte(item.Recommend), &recommend)
- if err != nil {
- resp.FailMsg("解析失败", "解析推荐链接失败, Err: "+e.Error(), c)
- return
- }
- }
- respItem := crm.HelpDocResp{
- Id: item.Id,
- ClassifyId: item.ClassifyId,
- Title: item.Title,
- Author: item.Author,
- CreateTime: item.CreateTime.Format(utils.FormatDateTime),
- ModifyTime: item.ModifyTime.Format(utils.FormatDateTime),
- Status: item.Status,
- PublishTime: item.PublishTime.Format(utils.FormatDateTime),
- Content: item.Content,
- AdminId: item.AdminId,
- AdminRealName: item.AdminRealName,
- Anchor: anchor,
- Recommend: recommend,
- }
- if item.PublishTime.IsZero() {
- respItem.PublishTime = ""
- }
- resp.OkData("获取成功", respItem, c)
- }
|