Эх сурвалжийг харах

Merge branch 'CRM_14.0' into debug

ziwen 1 жил өмнө
parent
commit
9375a8ee47

+ 141 - 108
controllers/help_doc/doc.go

@@ -1,7 +1,12 @@
 package help_doc
 
 import (
+	"encoding/json"
 	"hongze/hz_crm_api/controllers"
+	"hongze/hz_crm_api/models"
+	"hongze/hz_crm_api/models/help_doc"
+	"html"
+	"time"
 )
 
 // HelpDocController 帮助文档
@@ -9,63 +14,76 @@ type HelpDocController struct {
 	controllers.BaseAuthController
 }
 
-//// @Title 新增报告接口
-//// @Description 新增报告
-//// @Param	request	body help_doc.AddHelpDocReq true "type json string"
-//// @Success 200 {object} models.AddEnglishReportResp
-//// @router /add [post]
-//func (this *HelpDocController) Add() {
-//	br := new(models.BaseResponse).Init()
-//	defer func() {
-//		this.Data["json"] = br
-//		this.ServeJSON()
-//	}()
-//	sysUser := this.SysUser
-//	if sysUser == nil {
-//		br.Msg = "请登录"
-//		br.ErrMsg = "请登录,SysUser Is Empty"
-//		br.Ret = 408
-//		return
-//	}
-//	var req help_doc.AddHelpDocReq
-//	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
-//	if err != nil {
-//		br.Msg = "参数解析异常!"
-//		br.ErrMsg = "参数解析失败,Err:" + err.Error()
-//		return
-//	}
-//	if req.Content == "" {
-//		br.Msg = "请输入内容"
-//		return
-//	}
-//
-//	item := new(help_doc.HelpDoc)
-//	item.ClassifyId = req.ClassifyId
-//	item.ClassifyName = req.ClassifyName
-//	item.Title = req.Title
-//	item.Author = req.Author
-//	item.Status = req.Status
-//	item.Content = html.EscapeString(req.Content)
-//	item.CreateTime = time.Now()
-//	item.ModifyTime = time.Now()
-//	item.AdminId = sysUser.AdminId
-//	item.AdminRealName = sysUser.RealName
-//	_, err = help_doc.AddHelpDoc(item)
-//	if err != nil {
-//		br.Msg = "保存失败"
-//		br.ErrMsg = "保存失败,Err:" + err.Error()
-//		return
-//	}
-//
-//	//resp := new(models.AddEnglishReportResp)
-//	//resp.ReportId = newReportId
-//	//resp.ReportCode = reportCode
-//	br.Ret = 200
-//	br.Success = true
-//	br.Msg = "保存成功"
-//	//br.Data = resp
-//}
-//
+// @Title 新增报告接口
+// @Description 新增报告
+// @Param	request	body help_doc.AddHelpDocReq true "type json string"
+// @Success 200 {object} models.AddEnglishReportResp
+// @router /add [post]
+func (this *HelpDocController) Add() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	sysUser := this.SysUser
+	if sysUser == nil {
+		br.Msg = "请登录"
+		br.ErrMsg = "请登录,SysUser Is Empty"
+		br.Ret = 408
+		return
+	}
+	var req help_doc.AddHelpDocReq
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
+	if err != nil {
+		br.Msg = "参数解析异常!"
+		br.ErrMsg = "参数解析失败,Err:" + err.Error()
+		return
+	}
+	if req.Content == "" {
+		br.Msg = "请输入内容"
+		return
+	}
+	var anchor []byte
+	if req.AnchorData != nil{
+		anchor,err = json.Marshal(req.AnchorData)
+		if err != nil {
+			br.Msg = "参数解析异常!"
+			br.ErrMsg = "参数解析失败,Err:" + err.Error()
+			return
+		}
+	}
+
+	item := new(help_doc.HelpDoc)
+	item.ClassifyId = req.ClassifyId
+	item.Title = req.Title
+	item.Author = req.Author
+	item.Status = req.Status
+	item.Content = html.EscapeString(req.Content)
+	item.CreateTime = time.Now()
+	item.ModifyTime = time.Now()
+	item.AdminId = sysUser.AdminId
+	item.AdminRealName = sysUser.RealName
+	item.Anchor = string(anchor)
+	if req.Status == 2 {
+		item.PublishTime = time.Now()
+	}
+	_, err = help_doc.AddHelpDoc(item)
+	if err != nil {
+		br.Msg = "保存失败"
+		br.ErrMsg = "保存失败,Err:" + err.Error()
+		return
+	}
+
+	if req.Status == 1 {
+		br.Msg = "新增成功"
+	} else {
+		br.Msg = "发布成功"
+	}
+	br.Ret = 200
+	br.Success = true
+
+}
+
 //// @Title 编辑报告接口
 //// @Description 编辑报告
 //// @Param	request	body models.EditEnglishReportReq true "type json string"
@@ -121,8 +139,6 @@ type HelpDocController struct {
 //	//	}
 //	//}
 //
-//	var stage int
-//	report, _ := models.GetEnglishReportById(int(req.ReportId))
 //
 //	item := new(help_doc.HelpDoc)
 //	item.ClassifyId = req.ClassifyIdFirst
@@ -147,55 +163,72 @@ type HelpDocController struct {
 //	br.Msg = "保存成功"
 //	br.Data = resp
 //}
-//
-//// @Title 获取报告详情接口
-//// @Description 获取报告详情
-//// @Param	request	body models.ReportDetailReq true "type json string"
-//// @Success 200 {object} models.EnglishReportDetailView
-//// @router /detail [get]
-//func (this *HelpDocController) Detail() {
-//	br := new(models.BaseResponse).Init()
-//	defer func() {
-//		this.Data["json"] = br
-//		this.ServeJSON()
-//	}()
-//	/*var req models.ReportDetailReq
-//	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
-//	if err != nil {
-//		br.Msg = "参数解析异常!"
-//		br.ErrMsg = "参数解析失败,Err:" + err.Error()
-//		return
-//	}
-//	if req.ReportId <= 0 {
-//		br.Msg = "参数错误"
-//		return
-//	}*/
-//	reportId, err := this.GetInt("ReportId")
-//	if err != nil {
-//		br.Msg = "获取参数失败!"
-//		br.ErrMsg = "获取参数失败,Err:" + err.Error()
-//		return
-//	}
-//	if reportId <= 0 {
-//		br.Msg = "参数错误"
-//		return
-//	}
-//	item, err := models.GetEnglishReportById(reportId)
-//	if err != nil {
-//		br.Msg = "获取失败"
-//		br.ErrMsg = "获取失败,Err:" + err.Error()
-//		return
-//	}
-//
-//	item.Content = html.UnescapeString(item.Content)
-//	item.ContentSub = html.UnescapeString(item.ContentSub)
-//
-//	br.Ret = 200
-//	br.Success = true
-//	br.Msg = "获取成功"
-//	br.Data = item
-//}
-//
+
+
+
+// @Title 获取报告详情接口
+// @Description 获取报告详情
+// @Param	request	body models.ReportDetailReq true "type json string"
+// @Success 200 {object} models.EnglishReportDetailView
+// @router /detail [get]
+func (this *HelpDocController) Detail() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+
+	docId, err := this.GetInt("DocId")
+	if err != nil {
+		br.Msg = "获取参数失败!"
+		br.ErrMsg = "获取参数失败,Err:" + err.Error()
+		return
+	}
+	if docId <= 0 {
+		br.Msg = "参数错误"
+		return
+	}
+	item, err := help_doc.GetHelpDocById(docId)
+	if err != nil {
+		br.Msg = "获取失败"
+		br.ErrMsg = "获取失败,Err:" + err.Error()
+		return
+	}
+
+	item.Content = html.UnescapeString(item.Content)
+
+	var anchor []help_doc.AnchorList
+	if item.Anchor != "" {
+		err = json.Unmarshal([]byte(item.Anchor),&anchor)
+		if err != nil {
+			br.Msg = "解析失败"
+			br.ErrMsg = "解析失败,Err:" + err.Error()
+			return
+		}
+	}
+
+	resp := help_doc.HelpDocResp{
+		Id:            item.Id,
+		ClassifyId:    item.ClassifyId,
+		ClassifyName:  item.ClassifyName,
+		Title:         item.Title,
+		Author:        item.Author,
+		CreateTime:    item.CreateTime,
+		ModifyTime:    item.ModifyTime,
+		Status:        item.Status,
+		PublishTime:   item.PublishTime,
+		Content:       item.Content,
+		AdminId:       item.AdminId,
+		AdminRealName: item.AdminRealName,
+		Anchor:        anchor,
+	}
+
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "获取成功"
+	br.Data = resp
+}
+
 //// @Title 获取报告列表接口
 //// @Description 获取报告列表
 //// @Param   PageSize   query   int  true       "每页数据条数"

+ 2 - 1
models/db.go

@@ -664,6 +664,7 @@ func initEtaVersionUpdateLog() {
 func initHelpDoc() {
 	//注册对象
 	orm.RegisterModel(
-		new(help_doc.HelpDocClassify), //主题
+		new(help_doc.HelpDocClassify), //分类
+		new(help_doc.HelpDoc),         //文章
 	)
 }

+ 64 - 18
models/help_doc/help_doc.go

@@ -16,8 +16,25 @@ type HelpDoc struct {
 	Status        int       // 1:未发布,2:已发布
 	PublishTime   time.Time // 发布时间
 	Content       string    // 内容
-	AdminId       int     // 创建人
+	AdminId       int       // 创建人
 	AdminRealName string    // 创建人姓名
+	Anchor        string    // 锚点
+}
+
+type HelpDocItem struct {
+	Id            int    `orm:"column(id);pk"`
+	ClassifyId    int    // 分类id
+	ClassifyName  string // 分类名称
+	Title         string // 标题
+	Author        string // 作者
+	CreateTime    string // 创建时间
+	ModifyTime    string // 修改时间
+	Status        int    // 1:未发布,2:已发布
+	PublishTime   string // 发布时间
+	Content       string // 内容
+	AdminId       int    // 创建人
+	AdminRealName string // 创建人姓名
+	Anchor        string // 创建人姓名
 }
 
 func EditHelpDocClassifyId(classifyId int, classifyName string) (err error) {
@@ -28,12 +45,18 @@ func EditHelpDocClassifyId(classifyId int, classifyName string) (err error) {
 }
 
 type AddHelpDocReq struct {
-	ClassifyId   int    `description:"一级分类id"`
-	ClassifyName string `description:"一级分类名称"`
-	Title        string `description:"标题"`
-	Author       string `description:"作者"`
-	Status       int    `description:"状态:1:未发布,2:已发布"`
-	Content      string `description:"内容"`
+	ClassifyId int    `description:"分类id"`
+	Title      string `description:"标题"`
+	Author     string `description:"作者"`
+	Status     int    `description:"状态:1:未发布,2:已发布"`
+	Content    string `description:"内容"`
+	AnchorData []AnchorList
+}
+
+type AnchorList struct {
+	AnchorId string
+	Anchor   string
+	Child    []AnchorList
 }
 
 func AddHelpDoc(item *HelpDoc) (lastId int64, err error) {
@@ -44,16 +67,16 @@ func AddHelpDoc(item *HelpDoc) (lastId int64, err error) {
 
 type EditHelpDocReq struct {
 	Id           int64  `description:"文章id"`
-	ClassifyId    int    `description:"分类id"`
-	ClassifyName  string `description:"分类名称"`
-	Title              string `description:"标题"`
-	Abstract           string `description:"摘要"`
-	Author             string `description:"作者"`
-	Frequency          string `description:"频度"`
-	State              int    `description:"状态:1:未发布,2:已发布"`
-	Content            string `description:"内容"`
-	CreateTime         string `description:"创建时间"`
-	Overview           string `description:"英文概述部分"`
+	ClassifyId   int    `description:"分类id"`
+	ClassifyName string `description:"分类名称"`
+	Title        string `description:"标题"`
+	Abstract     string `description:"摘要"`
+	Author       string `description:"作者"`
+	Frequency    string `description:"频度"`
+	State        int    `description:"状态:1:未发布,2:已发布"`
+	Content      string `description:"内容"`
+	CreateTime   string `description:"创建时间"`
+	Overview     string `description:"英文概述部分"`
 }
 
 //func EditHelpDoc(item *HelpDoc, reportId int64) (err error) {
@@ -79,4 +102,27 @@ type EditHelpDocReq struct {
 //	_, err = o.Raw(sql, item.ClassifyIdFirst, item.ClassifyNameFirst, item.ClassifyIdSecond, item.ClassifyNameSecond, item.Title,
 //		item.Abstract, item.Author, item.Frequency, item.State, item.Content, item.ContentSub, item.Stage, item.CreateTime, time.Now(), item.Overview, reportId).Exec()
 //	return
-//}
+//}
+
+func GetHelpDocById(docId int) (item *HelpDocItem, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT * FROM help_doc WHERE id=?`
+	err = o.Raw(sql, docId).QueryRow(&item)
+	return
+}
+
+type HelpDocResp struct {
+	Id            int          `orm:"column(id);pk"`
+	ClassifyId    int          // 分类id
+	ClassifyName  string       // 分类名称
+	Title         string       // 标题
+	Author        string       // 作者
+	CreateTime    string       // 创建时间
+	ModifyTime    string       // 修改时间
+	Status        int          // 1:未发布,2:已发布
+	PublishTime   string       // 发布时间
+	Content       string       // 内容
+	AdminId       int          // 创建人
+	AdminRealName string       // 创建人姓名
+	Anchor        []AnchorList // 锚点
+}

+ 27 - 0
routers/commentsRouter.go

@@ -6595,6 +6595,33 @@ func init() {
             Filters: nil,
             Params: nil})
 
+    beego.GlobalControllerRouter["hongze/hz_crm_api/controllers/help_doc:HelpDocController"] = append(beego.GlobalControllerRouter["hongze/hz_crm_api/controllers/help_doc:HelpDocController"],
+        beego.ControllerComments{
+            Method: "Add",
+            Router: `/add`,
+            AllowHTTPMethods: []string{"post"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
+    beego.GlobalControllerRouter["hongze/hz_crm_api/controllers/help_doc:HelpDocController"] = append(beego.GlobalControllerRouter["hongze/hz_crm_api/controllers/help_doc:HelpDocController"],
+        beego.ControllerComments{
+            Method: "Detail",
+            Router: `/detail`,
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
+    beego.GlobalControllerRouter["hongze/hz_crm_api/controllers/help_doc:HelpDocController"] = append(beego.GlobalControllerRouter["hongze/hz_crm_api/controllers/help_doc:HelpDocController"],
+        beego.ControllerComments{
+            Method: "Detail",
+            Router: `/edit`,
+            AllowHTTPMethods: []string{"post"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
     beego.GlobalControllerRouter["hongze/hz_crm_api/controllers/roadshow:CalendarController"] = append(beego.GlobalControllerRouter["hongze/hz_crm_api/controllers/roadshow:CalendarController"],
         beego.ControllerComments{
             Method: "Accept",

+ 2 - 4
services/data/help_doc_classify.go

@@ -23,13 +23,11 @@ func HelpDocClassifyItemsMakeTree(allNode []*help_doc.HelpDocClassifyItems, node
 			if has {
 				HelpDocClassifyItemsMakeTree(allNode, v) //递归添加节点
 			} else {
-				childrenArr := make([]*help_doc.HelpDocClassifyItems, 0)
-				v.Children = childrenArr
+				v.Children = nil
 			}
 		}
 	} else {
-		childrenArr := make([]*help_doc.HelpDocClassifyItems, 0)
-		node.Children = childrenArr
+		node.Children = nil
 	}
 }