Browse Source

fix:权限校验

Roc 9 months ago
parent
commit
b2f62a081d

+ 1 - 129
controllers/report.go

@@ -1718,72 +1718,6 @@ func (this *ReportController) GetChapterTrendTag() {
 	br.Data = list
 }
 
-// EditChapterTrendTag
-// @Title 编辑章节趋势标签
-// @Description 编辑章节趋势标签
-// @Param	request	body models.EditReportChapterReq true "type json string"
-// @Success 200 Ret=200 保存成功
-// @router /editChapterTrendTag [post]
-func (this *ReportController) EditChapterTrendTag() {
-	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 models.EditChapterTrendTagReq
-	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
-	if err != nil {
-		br.Msg = "参数解析异常!"
-		br.ErrMsg = "参数解析失败,Err:" + err.Error()
-		return
-	}
-	if req.ReportChapterId <= 0 {
-		br.Msg = "章节ID有误"
-		return
-	}
-	if req.Trend == "" {
-		br.Msg = "请输入标签"
-		return
-	}
-
-	chapterInfo, err := models.GetReportChapterInfoById(req.ReportChapterId)
-	if err != nil {
-		br.Msg = "获取章节信息失败"
-		br.ErrMsg = "获取章节信息失败, Err: " + err.Error()
-		return
-	}
-
-	// 更新章节标签
-	chapterInfo.Trend = req.Trend
-	updateCols := make([]string, 0)
-	updateCols = append(updateCols, "Trend")
-	if err = chapterInfo.UpdateChapter(updateCols); err != nil {
-		br.Msg = "更新标签失败"
-		br.ErrMsg = "更新标签失败, Err: " + err.Error()
-		return
-	}
-
-	// 添加关键词
-	if err = models.AddTrendTagKeyWord(req.Trend); err != nil {
-		br.Msg = "添加标签关键词失败"
-		br.ErrMsg = "添加标签关键词失败, Err: " + err.Error()
-		return
-	}
-
-	br.Ret = 200
-	br.Success = true
-	br.Msg = "保存成功"
-}
-
 // GetDayReportTickerList
 // @Title 获取晨报数据指标列表
 // @Description 获取晨报数据指标列表
@@ -2028,68 +1962,6 @@ func (this *ReportController) PublishDayWeekReport() {
 	br.Msg = "操作成功"
 }
 
-// GetSunCode 获取太阳码
-// @Title 公共模块
-// @Description 获取分享海报
-// @Param	request	body models.SunCodeReq true "type json string"
-// @Success 200 {object} string "获取成功"
-// @failure 400 {string} string "获取失败"
-// @router /getSunCode [post]
-func (this *ReportController) GetSunCode() {
-	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
-	}
-	if utils.BusinessCode != utils.BusinessCodeRelease && utils.BusinessCode != utils.BusinessCodeSandbox && utils.BusinessCode != utils.BusinessCodeDebug {
-		br.Ret = 200
-		br.Success = true
-		br.Msg = "操作成功"
-		return
-	}
-
-	var req models.SunCodeReq
-	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
-	if err != nil {
-		br.Msg = "参数解析异常!"
-		br.ErrMsg = "参数解析失败,Err:" + err.Error()
-		return
-	}
-
-	var sunCodeUrl string
-	//先查,查不到再去生成上传
-	item, err := models.GetYbPcSunCode(req.CodeScene, req.CodePage)
-	if err != nil && err.Error() != utils.ErrNoRow() {
-		br.Msg = "查询太阳码失败!"
-		br.ErrMsg = "查询太阳码失败,Err:" + err.Error()
-		return
-	}
-	if item != nil {
-		sunCodeUrl = item.SuncodeUrl
-	}
-
-	if sunCodeUrl == "" {
-		sunCodeUrl, err = services.PcCreateAndUploadSunCode(req.CodeScene, req.CodePage)
-		if err != nil {
-			br.Msg = "生成太阳码失败!"
-			br.ErrMsg = "生成太阳码失败,Err:" + err.Error()
-			return
-		}
-	}
-
-	br.Data = sunCodeUrl
-	br.Ret = 200
-	br.Success = true
-	br.Msg = "操作成功"
-}
-
 // GetStopDayWeekReportChapterTypeList
 // @Title 获取暂停更新的晨报周报章节类型列表
 // @Description 获取暂停更新的晨报周报章节类型列表
@@ -2197,7 +2069,7 @@ func (this *ReportController) MarkEditStatus() {
 		return
 	}
 	//更新标记key
-	data, err := services.UpdateReportEditMark(req.ReportId, sysUser.AdminId, req.Status, sysUser.RealName, this.Lang)
+	data, err := services.UpdateReportEditMark(req.ReportId, req.ReportChapterId, sysUser.AdminId, req.Status, sysUser.RealName, this.Lang)
 	if err != nil {
 		br.Msg = err.Error()
 		return

+ 852 - 0
controllers/report_chapter.go

@@ -0,0 +1,852 @@
+package controllers
+
+import (
+	"encoding/json"
+	"eta/eta_api/models"
+	"eta/eta_api/models/report"
+	"eta/eta_api/services"
+	"eta/eta_api/utils"
+	"html"
+	"strconv"
+	"time"
+)
+
+// EditDayWeekChapter
+// @Title 编辑晨周报章节内容
+// @Description 编辑晨周报章节内容
+// @Param	request	body models.EditReportChapterReq true "type json string"
+// @Success 200 Ret=200 保存成功
+// @router /addChapter [post]
+func (this *ReportController) AddDayWeekChapter() {
+	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 models.AddReportChapterReq
+	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 = "报告ID有误"
+		return
+	}
+
+	// 获取报告详情
+	reportInfo, err := models.GetReportById(req.ReportId)
+	if err != nil {
+		br.Msg = "报告信息有误"
+		br.ErrMsg = "报告信息有误, Err: " + err.Error()
+		return
+	}
+	if reportInfo.State == 2 {
+		br.Msg = "该报告已发布,不允许编辑"
+		br.ErrMsg = "该报告已发布,不允许编辑"
+		return
+	}
+
+	newContent := req.Content
+	// 更新章节及指标
+	contentSub := ""
+	if req.Content != "" {
+		e := utils.ContentXssCheck(req.Content)
+		if e != nil {
+			br.Msg = "存在非法标签"
+			br.ErrMsg = "存在非法标签, Err: " + e.Error()
+			return
+		}
+		contentClean, e := services.FilterReportContentBr(req.Content)
+		if e != nil {
+			br.Msg = "内容去除前后空格失败"
+			br.ErrMsg = "内容去除前后空格失败, Err: " + e.Error()
+			return
+		}
+		req.Content = contentClean
+
+		contentSub, err = services.GetReportContentSub(req.Content)
+		if err != nil {
+			br.Msg = "内容分段解析失败"
+			br.ErrMsg = "编辑报告章节-解析 ContentSub 失败, Err: " + err.Error()
+			return
+		}
+	}
+	if req.Content == "" {
+		req.Content = newContent
+	}
+
+	reportChapterInfo := new(models.ReportChapter)
+	reportChapterInfo.ReportId = reportInfo.Id
+	reportChapterInfo.ClassifyIdFirst = reportInfo.ClassifyIdFirst
+	reportChapterInfo.ClassifyNameFirst = reportInfo.ClassifyNameFirst
+
+	reportChapterInfo.Title = req.Title
+	reportChapterInfo.AddType = 1
+	reportChapterInfo.Author = req.Author
+	reportChapterInfo.Content = html.EscapeString(req.Content)
+	reportChapterInfo.ContentSub = html.EscapeString(contentSub)
+	reportChapterInfo.IsEdit = 1
+	reportChapterInfo.CreateTime = req.CreateTime
+	reportChapterInfo.VideoKind = 1
+
+	reportChapterInfo.ClassifyIdSecond = reportInfo.ClassifyIdSecond
+	reportChapterInfo.ClassifyNameSecond = reportInfo.ClassifyNameSecond
+	reportChapterInfo.ClassifyIdThird = reportInfo.ClassifyIdThird
+	reportChapterInfo.ClassifyNameThird = reportInfo.ClassifyNameThird
+	reportChapterInfo.LastModifyAdminId = sysUser.AdminId
+	reportChapterInfo.LastModifyAdminName = sysUser.RealName
+	reportChapterInfo.ContentModifyTime = time.Now()
+	reportChapterInfo.ContentStruct = html.EscapeString(req.ContentStruct)
+	reportChapterInfo.CanvasColor = req.CanvasColor
+	reportChapterInfo.HeadResourceId = req.HeadResourceId
+	reportChapterInfo.EndResourceId = req.EndResourceId
+
+	err = reportChapterInfo.Add()
+	if err != nil {
+		br.Msg = "新增失败"
+		br.ErrMsg = "报告章节内容保存失败, Err: " + err.Error()
+		return
+	}
+
+	// 备份关键数据
+	chapters := make([]*models.ReportChapter, 0)
+	chapters = append(chapters, reportChapterInfo)
+	go services.SaveReportLogs(nil, chapters, sysUser.AdminId, sysUser.RealName)
+
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "保存成功"
+}
+
+// EditDayWeekChapter
+// @Title 编辑晨周报章节内容
+// @Description 编辑晨周报章节内容
+// @Param	request	body models.EditReportChapterReq true "type json string"
+// @Success 200 Ret=200 保存成功
+// @router /editDayWeekChapter [post]
+func (this *ReportController) EditDayWeekChapter() {
+	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 models.EditReportChapterReq
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
+	if err != nil {
+		br.Msg = "参数解析异常!"
+		br.ErrMsg = "参数解析失败,Err:" + err.Error()
+		return
+	}
+	reportChapterId := req.ReportChapterId
+	if reportChapterId <= 0 {
+		br.Msg = "报告章节ID有误"
+		return
+	}
+	if req.Content == "" {
+		br.Msg = "请输入内容"
+		return
+	}
+
+	// 获取章节详情
+	reportChapterInfo, err := models.GetReportChapterInfoById(reportChapterId)
+	if err != nil {
+		br.Msg = "报告章节信息有误"
+		br.ErrMsg = "报告章节信息有误, Err: " + err.Error()
+		return
+	}
+
+	// 获取报告详情
+	reportInfo, err := models.GetReportByReportId(reportChapterInfo.ReportId)
+	if err != nil {
+		br.Msg = "报告信息有误"
+		br.ErrMsg = "报告信息有误, Err: " + err.Error()
+		return
+	}
+
+	// 操作权限校验
+	{
+		// 如果不是创建人,那么就要去查看是否授权
+		if reportInfo.AdminId != sysUser.AdminId {
+			// 授权用户权限校验
+			chapterGrantObj := report.ReportChapterGrant{}
+			_, tmpErr := chapterGrantObj.GetGrantByIdAndAdmin(reportChapterInfo.ReportChapterId, sysUser.AdminId)
+			if tmpErr != nil {
+				if tmpErr.Error() == utils.ErrNoRow() {
+					br.Msg = "没有权限"
+					br.ErrMsg = "没有权限"
+					br.IsSendEmail = false
+					return
+				}
+				br.Msg = "获取章节id授权用户失败"
+				br.ErrMsg = "获取章节id授权用户失败, Err: " + tmpErr.Error()
+				return
+			}
+		}
+
+		// 标记更新中
+		{
+			markStatus, err := services.UpdateReportEditMark(reportChapterInfo.ReportId, reportChapterInfo.ReportChapterId, sysUser.AdminId, 1, sysUser.RealName, this.Lang)
+			if err != nil {
+				br.Msg = err.Error()
+				return
+			}
+			if markStatus.Status == 1 {
+				br.Msg = markStatus.Msg
+				br.IsSendEmail = false
+				return
+			}
+		}
+	}
+
+	if reportInfo.State == 2 {
+		br.Msg = "该报告已发布,不允许编辑"
+		br.ErrMsg = "该报告已发布,不允许编辑"
+		return
+	}
+
+	reqTickerList := req.TickerList
+	// 更新章节及指标
+	contentSub := ""
+	if req.Content != "" {
+		e := utils.ContentXssCheck(req.Content)
+		if e != nil {
+			br.Msg = "存在非法标签"
+			br.ErrMsg = "存在非法标签, Err: " + e.Error()
+			return
+		}
+		contentClean, e := services.FilterReportContentBr(req.Content)
+		if e != nil {
+			br.Msg = "内容去除前后空格失败"
+			br.ErrMsg = "内容去除前后空格失败, Err: " + e.Error()
+			return
+		}
+		req.Content = contentClean
+
+		contentSub, err = services.GetReportContentSub(req.Content)
+		if err != nil {
+			br.Msg = "内容分段解析失败"
+			br.ErrMsg = "编辑报告章节-解析 ContentSub 失败, Err: " + err.Error()
+			return
+		}
+	}
+
+	reportChapterInfo.Title = req.Title
+	//reportChapterInfo.AddType = req.AddType
+	reportChapterInfo.Author = req.Author
+	reportChapterInfo.Content = html.EscapeString(req.Content)
+	reportChapterInfo.ContentSub = html.EscapeString(contentSub)
+	reportChapterInfo.IsEdit = 1
+	reportChapterInfo.CreateTime = req.CreateTime
+	reportChapterInfo.VideoUrl = req.VideoUrl
+	reportChapterInfo.VideoName = req.VideoName
+	reportChapterInfo.VideoPlaySeconds = req.VideoPlaySeconds
+	reportChapterInfo.VideoSize = req.VideoSize
+	reportChapterInfo.VideoKind = 1
+
+	reportChapterInfo.LastModifyAdminId = sysUser.AdminId
+	reportChapterInfo.LastModifyAdminName = sysUser.RealName
+	reportChapterInfo.ContentModifyTime = time.Now()
+	reportChapterInfo.ContentStruct = html.EscapeString(req.ContentStruct)
+	reportChapterInfo.CanvasColor = req.CanvasColor
+	reportChapterInfo.HeadResourceId = req.HeadResourceId
+	reportChapterInfo.EndResourceId = req.EndResourceId
+
+	updateCols := make([]string, 0)
+	updateCols = append(updateCols, "Title", "AddType", "Author", "Content", "ContentSub", "IsEdit", "CreateTime")
+	if req.VideoUrl != "" {
+		updateCols = append(updateCols, "VideoUrl", "VideoName", "VideoSize", "VideoPlaySeconds", "VideoKind")
+	}
+
+	updateCols = append(updateCols, "LastModifyAdminId", "LastModifyAdminName", "ContentModifyTime", "ContentStruct", "CanvasColor", "HeadResourceId", "EndResourceId")
+
+	// 章节报告更新指标
+	tickerList := make([]*models.ReportChapterTicker, 0)
+	if len(reqTickerList) > 0 {
+		nowTime := time.Now()
+		for i := 0; i < len(reqTickerList); i++ {
+			tickerList = append(tickerList, &models.ReportChapterTicker{
+				ReportChapterId: reportChapterInfo.ReportChapterId,
+				Sort:            reqTickerList[i].Sort,
+				Ticker:          reqTickerList[i].Ticker,
+				CreateTime:      nowTime,
+				UpdateTime:      nowTime,
+			})
+		}
+	}
+	err = models.UpdateChapterAndTicker(reportChapterInfo, updateCols, tickerList)
+	if err != nil {
+		br.Msg = "保存失败"
+		br.ErrMsg = "报告章节内容保存失败, Err: " + err.Error()
+		return
+	}
+
+	// 标记更新中
+	{
+		markStatus, err := services.UpdateReportEditMark(reportChapterInfo.ReportId, reportChapterInfo.ReportChapterId, sysUser.AdminId, 1, sysUser.RealName, this.Lang)
+		if err != nil {
+			br.Msg = err.Error()
+			return
+		}
+		if markStatus.Status == 1 {
+			br.Msg = markStatus.Msg
+			return
+		}
+	}
+
+	// 备份关键数据
+	chapters := make([]*models.ReportChapter, 0)
+	chapters = append(chapters, reportChapterInfo)
+	go services.SaveReportLogs(nil, chapters, sysUser.AdminId, sysUser.RealName)
+
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "保存成功"
+}
+
+// EditChapterBaseInfoAndPermission
+// @Title 修改报告章节的基础信息、授权用户权限、品种权限
+// @Description 修改报告章节的基础信息、授权用户权限、品种权限
+// @Param	request	body models.EditReportChapterReq true "type json string"
+// @Success 200 Ret=200 保存成功
+// @router /chapter/base_info/edit [post]
+func (this *ReportController) EditChapterBaseInfoAndPermission() {
+	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 models.EditReportChapterBaseInfoAndPermissionReq
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
+	if err != nil {
+		br.Msg = "参数解析异常!"
+		br.ErrMsg = "参数解析失败,Err:" + err.Error()
+		return
+	}
+	reportChapterId := req.ReportChapterId
+	if reportChapterId <= 0 {
+		br.Msg = "报告章节ID有误"
+		return
+	}
+	// 获取章节详情
+	reportChapterInfo, err := models.GetReportChapterInfoById(reportChapterId)
+	if err != nil {
+		br.Msg = "报告章节信息有误"
+		br.ErrMsg = "报告章节信息有误, Err: " + err.Error()
+		return
+	}
+	// 获取报告详情
+	reportInfo, err := models.GetReportByReportId(reportChapterInfo.ReportId)
+	if err != nil {
+		br.Msg = "报告信息有误"
+		br.ErrMsg = "报告信息有误, Err: " + err.Error()
+		return
+	}
+	if reportInfo.State == 2 {
+		br.Msg = "该报告已发布,不允许编辑"
+		br.ErrMsg = "该报告已发布,不允许编辑"
+		return
+	}
+
+	err, errMsg := services.EditChapterBaseInfoAndPermission(reportInfo, reportChapterInfo, req.Title, req.PermissionIdList, req.AdminIdList)
+	if err != nil {
+		br.Msg = "保存失败"
+		if errMsg != "" {
+			br.Msg = errMsg
+		}
+		br.ErrMsg = "保存失败,Err:" + err.Error()
+		return
+	}
+
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "保存成功"
+}
+
+// GetReportChapterList
+// @Title 获取报告章节列表
+// @Description 获取报告章节列表
+// @Param   ReportId	query	string	true	"报告ID"
+// @Success 200 {object} company.CompanyListResp
+// @router /getReportChapterList [get]
+func (this *ReportController) GetReportChapterList() {
+	// TODO 授权用户校验
+	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
+	}
+
+	reqReportId := this.GetString("ReportId")
+	reportId, _ := strconv.Atoi(reqReportId)
+	if reportId <= 0 {
+		br.Msg = "报告ID有误"
+		return
+	}
+
+	// 获取章节列表
+	chapterList, err := models.GetChapterListByReportId(reportId)
+	if err != nil {
+		br.Msg = "获取章节列表失败"
+		br.ErrMsg = "获取章节列表失败, Err: " + err.Error()
+		return
+	}
+	typeList, err := models.GetReportChapterTypeList()
+	if err != nil {
+		br.Msg = "获取章节类型列表失败"
+		br.ErrMsg = "获取章节类型列表失败, Err: " + err.Error()
+		return
+	}
+	typeIdImg := make(map[int]string)
+	for i := 0; i < len(typeList); i++ {
+		typeIdImg[typeList[i].ReportChapterTypeId] = typeList[i].EditImgUrl
+	}
+
+	resp := make([]models.ReportChapterResp, 0)
+	if len(chapterList) > 0 {
+		chapterIdList := make([]int, 0)
+		// 章节id授权用户列表map
+		chapterIdGrandListMap := make(map[int][]int)
+		// 章节id关联品种id列表map
+		chapterIdPermissionListMap := make(map[int][]int)
+
+		for _, v := range chapterList {
+			chapterIdList = append(chapterIdList, v.ReportChapterId)
+		}
+
+		// 处理章节id授权用户列表
+		{
+			chapterGrantObj := report.ReportChapterGrant{}
+			chapterGrantList, tmpErr := chapterGrantObj.GetGrantListByIdList(chapterIdList)
+			if tmpErr != nil {
+				br.Msg = "获取章节id授权用户列表失败"
+				br.ErrMsg = "获取章节id授权用户列表失败, Err: " + tmpErr.Error()
+				return
+			}
+
+			for _, v := range chapterGrantList {
+				tmpChapterIdGrandList, ok := chapterIdGrandListMap[v.ReportChapterId]
+				if !ok {
+					tmpChapterIdGrandList = make([]int, 0)
+				}
+				chapterIdGrandListMap[v.ReportChapterId] = append(tmpChapterIdGrandList, v.AdminId)
+			}
+		}
+
+		// 处理章节id关联品种id列表
+		{
+			obj := report.ReportChapterPermissionMapping{}
+			chapterPermissionList, tmpErr := obj.GetPermissionListByIdList(chapterIdList)
+			if tmpErr != nil {
+				br.Msg = "获取章节id关联品种列表失败"
+				br.ErrMsg = "获取章节id关联品种列表失败, Err: " + tmpErr.Error()
+				return
+			}
+
+			for _, v := range chapterPermissionList {
+				tmpChapterIdPermissionList, ok := chapterIdPermissionListMap[v.ReportChapterId]
+				if !ok {
+					tmpChapterIdPermissionList = make([]int, 0)
+				}
+				chapterIdPermissionListMap[v.ReportChapterId] = append(tmpChapterIdPermissionList, v.ChartPermissionId)
+			}
+		}
+
+		// TODO 获取更新规则
+		researchType := chapterList[0].ReportType
+		chapterTypeList, tmpErr := models.GetAllReportChapterTypeListByResearchType(researchType)
+		if tmpErr != nil {
+			br.Msg = "获取更新规则失败"
+			br.ErrMsg = "获取更新规则失败, Err: " + tmpErr.Error()
+			return
+		}
+		// 调整章节更新
+		nowTime := time.Now().Local()
+		for _, item := range chapterList {
+			stop := false
+			for _, rule := range chapterTypeList {
+				if rule.ReportChapterTypeId == item.TypeId {
+					//fmt.Println("rule.Enabled :", rule.Enabled, ";name=", rule.ReportChapterTypeName, "item.IsEdit:", item.IsEdit, "rule.IsSet:", rule.IsSet)
+					// 如果被永久暂停更新了
+					if rule.Enabled == 0 && item.IsEdit == 0 { //该章节已被永久禁用,同时未被操作过
+						stop = true
+					} else if rule.PauseStartTime != "" && rule.PauseEndTime != "" && rule.PauseStartTime != utils.EmptyDateStr && rule.PauseEndTime != utils.EmptyDateStr {
+						startTime, timeErr := time.ParseInLocation(utils.FormatDate, rule.PauseStartTime, time.Local)
+						if timeErr != nil {
+							br.Msg = "获取更新规则失败"
+							br.ErrMsg = "更新规则时间转换失败4001, Err: " + timeErr.Error()
+							return
+						}
+						endTime, timeErr := time.ParseInLocation(utils.FormatDate, rule.PauseEndTime, time.Local)
+						if timeErr != nil {
+							br.Msg = "获取更新规则失败"
+							br.ErrMsg = "更新规则时间转换失败4002, Err: " + timeErr.Error()
+							return
+						}
+						// 暂停更新
+						if nowTime.After(startTime) && nowTime.Before(endTime.AddDate(0, 0, 1)) {
+							stop = true
+						}
+						break
+					}
+				}
+			}
+			if !stop {
+				// 授权的用户列表
+				tmpChapterIdGrandList, ok := chapterIdGrandListMap[item.ReportChapterId]
+				if !ok {
+					tmpChapterIdGrandList = make([]int, 0)
+				}
+				// 关联的品种列表
+				tmpChapterIdPermissionList, ok := chapterIdPermissionListMap[item.ReportChapterId]
+				if !ok {
+					tmpChapterIdPermissionList = make([]int, 0)
+				}
+
+				tmpChapterItem := models.ReportChapterResp{
+					ReportChapterId:  item.ReportChapterId,
+					ReportId:         item.ReportId,
+					ReportType:       item.ReportType,
+					TypeId:           item.TypeId,
+					TypeName:         item.TypeName,
+					TypeEditImg:      typeIdImg[item.TypeId],
+					Title:            item.Title,
+					IsEdit:           item.IsEdit,
+					Trend:            item.Trend,
+					Sort:             item.Sort,
+					PublishState:     item.PublishState,
+					VideoUrl:         item.VideoUrl,
+					VideoName:        item.VideoName,
+					VideoPlaySeconds: item.VideoPlaySeconds,
+					VideoSize:        item.VideoSize,
+					VideoKind:        item.VideoKind,
+					ModifyTime:       item.ModifyTime.Format(utils.FormatDate),
+					GrandAdminIdList: tmpChapterIdGrandList,
+					PermissionIdList: tmpChapterIdPermissionList,
+				}
+				markStatus, err := services.UpdateReportEditMark(item.ReportId, item.ReportChapterId, this.SysUser.AdminId, 2, this.SysUser.RealName, this.Lang)
+				if err != nil {
+					br.Msg = "查询标记状态失败"
+					br.ErrMsg = "查询标记状态失败,Err:" + err.Error()
+					return
+				}
+
+				if markStatus.Status == 0 {
+					tmpChapterItem.CanEdit = true
+				} else {
+					tmpChapterItem.Editor = markStatus.Editor
+				}
+
+				resp = append(resp, tmpChapterItem)
+			}
+		}
+	}
+
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "获取成功"
+	br.Data = resp
+}
+
+// GetDayWeekChapter
+// @Title 获取晨周报章节信息
+// @Description 获取晨周报章节信息
+// @Param	ReportChapterId  query  int  true  "报告章节ID"
+// @Success 200 Ret=200 保存成功
+// @router /getDayWeekChapter [get]
+func (this *ReportController) GetDayWeekChapter() {
+	// TODO 授权用户校验
+	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
+	}
+
+	reportChapterId, _ := this.GetInt("ReportChapterId")
+	if reportChapterId <= 0 {
+		br.Msg = "参数有误"
+		return
+	}
+	chapterInfo, err := models.GetReportChapterInfoById(reportChapterId)
+	if err != nil {
+		br.Msg = "获取章节信息失败"
+		br.ErrMsg = "获取章节信息失败, Err: " + err.Error()
+		return
+	}
+	if chapterInfo != nil {
+		chapterInfo.Content = html.UnescapeString(chapterInfo.Content)
+		chapterInfo.ContentSub = html.UnescapeString(chapterInfo.ContentSub)
+		chapterInfo.ContentStruct = html.UnescapeString(chapterInfo.ContentStruct)
+	}
+
+	// 授权用户列表map
+	chapterGrantIdList := make([]int, 0)
+	// 关联品种id列表map
+	chapterPermissionIdList := make([]int, 0)
+	// 处理章节id授权用户列表
+	{
+		chapterGrantObj := report.ReportChapterGrant{}
+		chapterGrantList, tmpErr := chapterGrantObj.GetGrantListById(chapterInfo.ReportChapterId)
+		if tmpErr != nil {
+			br.Msg = "获取章节id授权用户列表失败"
+			br.ErrMsg = "获取章节id授权用户列表失败, Err: " + tmpErr.Error()
+			return
+		}
+
+		for _, v := range chapterGrantList {
+			chapterGrantIdList = append(chapterGrantIdList, v.AdminId)
+		}
+	}
+
+	// 处理章节id关联品种id列表
+	{
+		obj := report.ReportChapterPermissionMapping{}
+		chapterPermissionList, tmpErr := obj.GetPermissionListById(chapterInfo.ReportChapterId)
+		if tmpErr != nil {
+			br.Msg = "获取章节id关联品种列表失败"
+			br.ErrMsg = "获取章节id关联品种列表失败, Err: " + tmpErr.Error()
+			return
+		}
+
+		for _, v := range chapterPermissionList {
+			chapterPermissionIdList = append(chapterPermissionIdList, v.ChartPermissionId)
+		}
+	}
+
+	resp := models.ReportChapterItem{
+		ReportChapter:    *chapterInfo,
+		GrandAdminIdList: chapterGrantIdList,
+		PermissionIdList: chapterPermissionIdList,
+	}
+
+	// 获取当前编辑状态
+	{
+		markStatus, err := services.UpdateReportEditMark(chapterInfo.ReportId, chapterInfo.ReportChapterId, this.SysUser.AdminId, 2, this.SysUser.RealName, this.Lang)
+		if err != nil {
+			br.Msg = "查询标记状态失败"
+			br.ErrMsg = "查询标记状态失败,Err:" + err.Error()
+			return
+		}
+		if markStatus.Status == 0 {
+			resp.CanEdit = true
+		} else {
+			resp.Editor = markStatus.Editor
+		}
+	}
+
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "获取成功"
+	br.Data = resp
+}
+
+// ChapterMove
+// @Title 移动章节类型
+// @Description 移动章节类型
+// @Param	request	body models.PermissionMoveReq true "type json string"
+// @Success 200 Ret=200 操作成功
+// @router /chapter/move [post]
+func (this *ReportController) ChapterMove() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		if br.ErrMsg == "" {
+			br.IsSendEmail = false
+		}
+		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 models.ReportChapterMoveReq
+	if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
+		br.Msg = "参数解析异常!"
+		br.ErrMsg = "参数解析失败,Err:" + e.Error()
+		return
+	}
+
+	if req.ReportChapterId == 0 {
+		br.Msg = "请选择要移动的章节"
+		return
+	}
+	e, msg := services.MoveReportChapter(&req)
+	if e != nil {
+		br.Msg = msg
+		br.ErrMsg = "移动品种失败, Err: " + e.Error()
+		return
+	}
+
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "操作成功"
+}
+
+// EditChapterTrendTag
+// @Title 编辑章节趋势标签
+// @Description 编辑章节趋势标签
+// @Param	request	body models.EditReportChapterReq true "type json string"
+// @Success 200 Ret=200 保存成功
+// @router /editChapterTrendTag [post]
+func (this *ReportController) EditChapterTrendTag() {
+	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 models.EditChapterTrendTagReq
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
+	if err != nil {
+		br.Msg = "参数解析异常!"
+		br.ErrMsg = "参数解析失败,Err:" + err.Error()
+		return
+	}
+	if req.ReportChapterId <= 0 {
+		br.Msg = "章节ID有误"
+		return
+	}
+	if req.Trend == "" {
+		br.Msg = "请输入标签"
+		return
+	}
+
+	chapterInfo, err := models.GetReportChapterInfoById(req.ReportChapterId)
+	if err != nil {
+		br.Msg = "获取章节信息失败"
+		br.ErrMsg = "获取章节信息失败, Err: " + err.Error()
+		return
+	}
+
+	// 更新章节标签
+	chapterInfo.Trend = req.Trend
+	updateCols := make([]string, 0)
+	updateCols = append(updateCols, "Trend")
+	if err = chapterInfo.UpdateChapter(updateCols); err != nil {
+		br.Msg = "更新标签失败"
+		br.ErrMsg = "更新标签失败, Err: " + err.Error()
+		return
+	}
+
+	// 添加关键词
+	if err = models.AddTrendTagKeyWord(req.Trend); err != nil {
+		br.Msg = "添加标签关键词失败"
+		br.ErrMsg = "添加标签关键词失败, Err: " + err.Error()
+		return
+	}
+
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "保存成功"
+}
+
+// GetSunCode 获取太阳码
+// @Title 公共模块
+// @Description 获取分享海报
+// @Param	request	body models.SunCodeReq true "type json string"
+// @Success 200 {object} string "获取成功"
+// @failure 400 {string} string "获取失败"
+// @router /getSunCode [post]
+func (this *ReportController) GetSunCode() {
+	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 models.SunCodeReq
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
+	if err != nil {
+		br.Msg = "参数解析异常!"
+		br.ErrMsg = "参数解析失败,Err:" + err.Error()
+		return
+	}
+
+	var sunCodeUrl string
+	//先查,查不到再去生成上传
+	item, err := models.GetYbPcSunCode(req.CodeScene, req.CodePage)
+	if err != nil && err.Error() != utils.ErrNoRow() {
+		br.Msg = "查询太阳码失败!"
+		br.ErrMsg = "查询太阳码失败,Err:" + err.Error()
+		return
+	}
+	if item != nil {
+		sunCodeUrl = item.SuncodeUrl
+	}
+
+	if sunCodeUrl == "" {
+		sunCodeUrl, err = services.PcCreateAndUploadSunCode(req.CodeScene, req.CodePage)
+		if err != nil {
+			br.Msg = "生成太阳码失败!"
+			br.ErrMsg = "生成太阳码失败,Err:" + err.Error()
+			return
+		}
+	}
+
+	br.Data = sunCodeUrl
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "操作成功"
+}

+ 292 - 796
controllers/report_v2.go

@@ -3,6 +3,7 @@ package controllers
 import (
 	"encoding/json"
 	"eta/eta_api/models"
+	"eta/eta_api/models/report"
 	"eta/eta_api/models/report_approve"
 	"eta/eta_api/services"
 	"eta/eta_api/services/alarm_msg"
@@ -15,6 +16,8 @@ import (
 	"time"
 )
 
+// TODO 报告的权限校验(跳过列表页,直接进入详情页,不管是普通报告还是章节报告)
+
 // ListReport
 // @Title 获取报告列表接口
 // @Description 获取报告列表
@@ -260,20 +263,20 @@ func (this *ReportController) ListReport() {
 			}
 			item.Editor = adminInfo.RealName
 		}*/
-		if item.ClassifyNameFirst == "周报" || item.ClassifyNameFirst == "晨报" {
+		if item.HasChapter == 1 {
+			item.CanEdit = true
+			continue
+		}
+		markStatus, err := services.UpdateReportEditMark(item.Id, 0, this.SysUser.AdminId, 2, this.SysUser.RealName, this.Lang)
+		if err != nil {
+			br.Msg = "查询标记状态失败"
+			br.ErrMsg = "查询标记状态失败,Err:" + err.Error()
+			return
+		}
+		if markStatus.Status == 0 {
 			item.CanEdit = true
 		} else {
-			markStatus, err := services.UpdateReportEditMark(item.Id, this.SysUser.AdminId, 2, this.SysUser.RealName, this.Lang)
-			if err != nil {
-				br.Msg = "查询标记状态失败"
-				br.ErrMsg = "查询标记状态失败,Err:" + err.Error()
-				return
-			}
-			if markStatus.Status == 0 {
-				item.CanEdit = true
-			} else {
-				item.Editor = markStatus.Editor
-			}
+			item.Editor = markStatus.Editor
 		}
 	}
 
@@ -472,7 +475,7 @@ func (this *ReportController) Edit() {
 	}
 
 	//更新标记key
-	markStatus, err := services.UpdateReportEditMark(int(req.ReportId), sysUser.AdminId, 1, sysUser.RealName, this.Lang)
+	markStatus, err := services.UpdateReportEditMark(int(req.ReportId), 0, sysUser.AdminId, 1, sysUser.RealName, this.Lang)
 	if err != nil {
 		br.Msg = err.Error()
 		return
@@ -484,7 +487,7 @@ func (this *ReportController) Edit() {
 	}
 
 	var stage int
-	report, e := models.GetReportByReportId(int(req.ReportId))
+	reportInfo, e := models.GetReportByReportId(int(req.ReportId))
 	if e != nil {
 		if e.Error() == utils.ErrNoRow() {
 			br.Msg = "报告已被删除, 请刷新页面"
@@ -494,20 +497,20 @@ func (this *ReportController) Edit() {
 		br.ErrMsg = "获取报告失败, Err: " + e.Error()
 		return
 	}
-	if report.State == models.ReportStatePublished || report.State == models.ReportStatePass {
+	if reportInfo.State == models.ReportStatePublished || reportInfo.State == models.ReportStatePass {
 		br.Msg = "该报告已发布,不允许编辑"
 		br.ErrMsg = "该报告已发布,不允许编辑"
 		return
 	}
-	if report.ClassifyNameFirst != req.ClassifyNameFirst || report.ClassifyNameSecond != req.ClassifyNameSecond {
+	if reportInfo.ClassifyNameFirst != req.ClassifyNameFirst || reportInfo.ClassifyNameSecond != req.ClassifyNameSecond {
 		// 报告期数
 		maxStage, _ := models.GetReportStageEdit(req.ClassifyIdFirst, req.ClassifyIdSecond, req.ClassifyIdThird, int(req.ReportId))
 		maxStage = maxStage + 1
 		stage = maxStage
 	} else {
-		stage = report.Stage
+		stage = reportInfo.Stage
 	}
-	//if req.State != report.State {
+	//if req.State != reportInfo.State {
 	//	recordItem := &models.ReportStateRecord{
 	//		ReportId:   int(req.ReportId),
 	//		ReportType: 1,
@@ -522,28 +525,28 @@ func (this *ReportController) Edit() {
 	//}
 
 	//item := new(models.Report)
-	report.ClassifyIdFirst = req.ClassifyIdFirst
-	report.ClassifyNameFirst = req.ClassifyNameFirst
-	report.ClassifyIdSecond = req.ClassifyIdSecond
-	report.ClassifyNameSecond = req.ClassifyNameSecond
-	report.ClassifyIdThird = req.ClassifyIdThird
-	report.ClassifyNameThird = req.ClassifyNameThird
-	report.Title = req.Title
-	report.Abstract = req.Abstract
-	report.Author = req.Author
-	report.Frequency = req.Frequency
-	//report.State = report.State // 编辑不变更状态
-	report.Stage = stage // 编辑不变更期数
-	//report.Content = html.EscapeString(req.Content)	// 编辑不变更具体内容
-	//report.ContentSub = html.EscapeString(contentSub)	// 编辑不变更具体内容
-	report.CreateTime = req.CreateTime
-	//report.CollaborateType = req.CollaborateType
-	//report.ReportLayout = req.ReportLayout
+	reportInfo.ClassifyIdFirst = req.ClassifyIdFirst
+	reportInfo.ClassifyNameFirst = req.ClassifyNameFirst
+	reportInfo.ClassifyIdSecond = req.ClassifyIdSecond
+	reportInfo.ClassifyNameSecond = req.ClassifyNameSecond
+	reportInfo.ClassifyIdThird = req.ClassifyIdThird
+	reportInfo.ClassifyNameThird = req.ClassifyNameThird
+	reportInfo.Title = req.Title
+	reportInfo.Abstract = req.Abstract
+	reportInfo.Author = req.Author
+	reportInfo.Frequency = req.Frequency
+	//reportInfo.State = reportInfo.State // 编辑不变更状态
+	reportInfo.Stage = stage // 编辑不变更期数
+	//reportInfo.Content = html.EscapeString(req.Content)	// 编辑不变更具体内容
+	//reportInfo.ContentSub = html.EscapeString(contentSub)	// 编辑不变更具体内容
+	reportInfo.CreateTime = req.CreateTime
+	//reportInfo.CollaborateType = req.CollaborateType
+	//reportInfo.ReportLayout = req.ReportLayout
 	if req.IsPublicPublish <= 0 {
 		req.IsPublicPublish = 1
 	}
-	report.IsPublicPublish = req.IsPublicPublish
-	err = report.Update([]string{"ClassifyIdFirst", "ClassifyNameFirst", "ClassifyIdSecond", "ClassifyNameSecond", "ClassifyIdThird", "ClassifyNameThird", "Title", "Abstract", "Author", "Frequency", "Stage", "CreateTime", "IsPublicPublish"})
+	reportInfo.IsPublicPublish = req.IsPublicPublish
+	err = reportInfo.Update([]string{"ClassifyIdFirst", "ClassifyNameFirst", "ClassifyIdSecond", "ClassifyNameSecond", "ClassifyIdThird", "ClassifyNameThird", "Title", "Abstract", "Author", "Frequency", "Stage", "CreateTime", "IsPublicPublish"})
 	if err != nil {
 		br.Msg = "保存失败"
 		br.ErrMsg = "保存失败,Err:" + err.Error()
@@ -751,7 +754,7 @@ func (this *ReportController) SaveReportContent() {
 
 	// 标记更新中
 	{
-		markStatus, err := services.UpdateReportEditMark(int(req.ReportId), sysUser.AdminId, 1, sysUser.RealName, this.Lang)
+		markStatus, err := services.UpdateReportEditMark(int(req.ReportId), 0, sysUser.AdminId, 1, sysUser.RealName, this.Lang)
 		if err != nil {
 			br.Msg = err.Error()
 			return
@@ -817,19 +820,18 @@ func (this *ReportController) SaveReportContent() {
 	br.Data = resp
 }
 
-// GetReportChapterList
-// @Title 获取报告章节列表
-// @Description 获取报告章节列表
-// @Param   ReportId	query	string	true	"报告ID"
-// @Success 200 {object} company.CompanyListResp
-// @router /getReportChapterList [get]
-func (this *ReportController) GetReportChapterList() {
+// PublishDayWeekReportChapter
+// @Title 发布晨周报章节
+// @Description 发布晨周报章节
+// @Param	request	body models.PublishReportChapterReq true "type json string"
+// @Success 200 Ret=200 操作成功
+// @router /publishDayWeekReportChapter [post]
+func (this *ReportController) PublishDayWeekReportChapter() {
 	br := new(models.BaseResponse).Init()
 	defer func() {
 		this.Data["json"] = br
 		this.ServeJSON()
 	}()
-
 	sysUser := this.SysUser
 	if sysUser == nil {
 		br.Msg = "请登录"
@@ -838,141 +840,43 @@ func (this *ReportController) GetReportChapterList() {
 		return
 	}
 
-	reqReportId := this.GetString("ReportId")
-	reportId, _ := strconv.Atoi(reqReportId)
-	if reportId <= 0 {
-		br.Msg = "报告ID有误"
-		return
-	}
-
-	// 获取章节列表
-	chapterList, err := models.GetChapterListByReportId(reportId)
+	var req models.PublishReportChapterReq
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
 	if err != nil {
-		br.Msg = "获取章节列表失败"
-		br.ErrMsg = "获取章节列表失败, Err: " + err.Error()
+		br.Msg = "参数解析异常!"
+		br.ErrMsg = "参数解析失败,Err:" + err.Error()
 		return
 	}
-	typeList, err := models.GetReportChapterTypeList()
-	if err != nil {
-		br.Msg = "获取章节类型列表失败"
-		br.ErrMsg = "获取章节类型列表失败, Err: " + err.Error()
+	if req.ReportChapterId <= 0 {
+		br.Msg = "参数有误"
 		return
 	}
-	typeIdImg := make(map[int]string)
-	for i := 0; i < len(typeList); i++ {
-		typeIdImg[typeList[i].ReportChapterTypeId] = typeList[i].EditImgUrl
-	}
-
-	resp := make([]*models.ReportChapterResp, 0)
-	if len(chapterList) > 0 {
-		// 获取更新规则
-		researchType := chapterList[0].ReportType
-		chapterTypeList, tmpErr := models.GetAllReportChapterTypeListByResearchType(researchType)
-		if tmpErr != nil {
-			br.Msg = "获取更新规则失败"
-			br.ErrMsg = "获取更新规则失败, Err: " + tmpErr.Error()
-			return
-		}
-		// 调整章节更新
-		nowTime := time.Now().Local()
-		for _, item := range chapterList {
-			stop := false
-			for _, rule := range chapterTypeList {
-				if rule.ReportChapterTypeId == item.TypeId {
-					//fmt.Println("rule.Enabled :", rule.Enabled, ";name=", rule.ReportChapterTypeName, "item.IsEdit:", item.IsEdit, "rule.IsSet:", rule.IsSet)
-					// 如果被永久暂停更新了
-					if rule.Enabled == 0 && item.IsEdit == 0 { //该章节已被永久禁用,同时未被操作过
-						stop = true
-					} else if rule.PauseStartTime != "" && rule.PauseEndTime != "" && rule.PauseStartTime != utils.EmptyDateStr && rule.PauseEndTime != utils.EmptyDateStr {
-						startTime, timeErr := time.ParseInLocation(utils.FormatDate, rule.PauseStartTime, time.Local)
-						if timeErr != nil {
-							br.Msg = "获取更新规则失败"
-							br.ErrMsg = "更新规则时间转换失败4001, Err: " + timeErr.Error()
-							return
-						}
-						endTime, timeErr := time.ParseInLocation(utils.FormatDate, rule.PauseEndTime, time.Local)
-						if timeErr != nil {
-							br.Msg = "获取更新规则失败"
-							br.ErrMsg = "更新规则时间转换失败4002, Err: " + timeErr.Error()
-							return
-						}
-						// 暂停更新
-						if nowTime.After(startTime) && nowTime.Before(endTime.AddDate(0, 0, 1)) {
-							stop = true
-						}
-						break
-					}
-				}
-			}
-			if !stop {
-				resp = append(resp, &models.ReportChapterResp{
-					ReportChapterId:  item.ReportChapterId,
-					ReportId:         item.ReportId,
-					ReportType:       item.ReportType,
-					TypeId:           item.TypeId,
-					TypeName:         item.TypeName,
-					TypeEditImg:      typeIdImg[item.TypeId],
-					Title:            item.Title,
-					IsEdit:           item.IsEdit,
-					Trend:            item.Trend,
-					Sort:             item.Sort,
-					PublishState:     item.PublishState,
-					VideoUrl:         item.VideoUrl,
-					VideoName:        item.VideoName,
-					VideoPlaySeconds: item.VideoPlaySeconds,
-					VideoSize:        item.VideoSize,
-					VideoKind:        item.VideoKind,
-					ModifyTime:       item.ModifyTime.Format(utils.FormatDate),
-				})
-			}
-		}
+	if req.Title == "" {
+		br.Msg = "请输入标题"
+		return
 	}
-
-	br.Ret = 200
-	br.Success = true
-	br.Msg = "获取成功"
-	br.Data = resp
-}
-
-// EditDayWeekChapter
-// @Title 编辑晨周报章节内容
-// @Description 编辑晨周报章节内容
-// @Param	request	body models.EditReportChapterReq true "type json string"
-// @Success 200 Ret=200 保存成功
-// @router /addChapter [post]
-func (this *ReportController) AddDayWeekChapter() {
-	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
+	if req.Content == "" {
+		br.Msg = "请输入内容"
 		return
 	}
-
-	var req models.AddReportChapterReq
-	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
-	if err != nil {
-		br.Msg = "参数解析异常!"
-		br.ErrMsg = "参数解析失败,Err:" + err.Error()
+	if req.AddType == 0 {
+		br.Msg = "请选择新增方式"
 		return
 	}
 
-	if req.ReportId <= 0 {
-		br.Msg = "报告ID有误"
+	reqTickerList := req.TickerList
+
+	chapterInfo, err := models.GetReportChapterInfoById(req.ReportChapterId)
+	if err != nil {
+		br.Msg = "章节信息有误"
+		br.ErrMsg = "获取章节信息失败, Err: " + err.Error()
 		return
 	}
 
-	// 获取报告详情
-	reportInfo, err := models.GetReportById(req.ReportId)
+	reportInfo, err := models.GetReportById(chapterInfo.ReportId)
 	if err != nil {
-		br.Msg = "报告信息有误"
-		br.ErrMsg = "报告信息有误, Err: " + err.Error()
+		br.Msg = "查询报告有误"
+		br.ErrMsg = "查询报告信息失败, Err: " + err.Error()
 		return
 	}
 	if reportInfo.State == 2 {
@@ -981,141 +885,70 @@ func (this *ReportController) AddDayWeekChapter() {
 		return
 	}
 
-	newContent := req.Content
-	// 更新章节及指标
-	contentSub := ""
-	if req.Content != "" {
-		e := utils.ContentXssCheck(req.Content)
-		if e != nil {
-			br.Msg = "存在非法标签"
-			br.ErrMsg = "存在非法标签, Err: " + e.Error()
-			return
-		}
-		contentClean, e := services.FilterReportContentBr(req.Content)
-		if e != nil {
-			br.Msg = "内容去除前后空格失败"
-			br.ErrMsg = "内容去除前后空格失败, Err: " + e.Error()
-			return
-		}
-		req.Content = contentClean
-
-		contentSub, err = services.GetReportContentSub(req.Content)
-		if err != nil {
-			br.Msg = "内容分段解析失败"
-			br.ErrMsg = "编辑报告章节-解析 ContentSub 失败, Err: " + err.Error()
-			return
-		}
-	}
-	if req.Content == "" {
-		req.Content = newContent
-	}
-
-	reportChapterInfo := new(models.ReportChapter)
-	reportChapterInfo.ReportId = reportInfo.Id
-	reportChapterInfo.ClassifyIdFirst = reportInfo.ClassifyIdFirst
-	reportChapterInfo.ClassifyNameFirst = reportInfo.ClassifyNameFirst
-
-	reportChapterInfo.Title = req.Title
-	reportChapterInfo.AddType = 1
-	reportChapterInfo.Author = req.Author
-	reportChapterInfo.Content = html.EscapeString(req.Content)
-	reportChapterInfo.ContentSub = html.EscapeString(contentSub)
-	reportChapterInfo.IsEdit = 1
-	reportChapterInfo.CreateTime = req.CreateTime
-	reportChapterInfo.VideoKind = 1
-
-	reportChapterInfo.ClassifyIdSecond = reportInfo.ClassifyIdSecond
-	reportChapterInfo.ClassifyNameSecond = reportInfo.ClassifyNameSecond
-	reportChapterInfo.ClassifyIdThird = reportInfo.ClassifyIdThird
-	reportChapterInfo.ClassifyNameThird = reportInfo.ClassifyNameThird
-	reportChapterInfo.LastModifyAdminId = sysUser.AdminId
-	reportChapterInfo.LastModifyAdminName = sysUser.RealName
-	reportChapterInfo.ContentModifyTime = time.Now()
-	reportChapterInfo.ContentStruct = html.EscapeString(req.ContentStruct)
-	reportChapterInfo.CanvasColor = req.CanvasColor
-	reportChapterInfo.HeadResourceId = req.HeadResourceId
-	reportChapterInfo.EndResourceId = req.EndResourceId
-
-	err = reportChapterInfo.Add()
-	if err != nil {
-		br.Msg = "新增失败"
-		br.ErrMsg = "报告章节内容保存失败, Err: " + err.Error()
-		return
-	}
-
-	// 备份关键数据
-	chapters := make([]*models.ReportChapter, 0)
-	chapters = append(chapters, reportChapterInfo)
-	go services.SaveReportLogs(nil, chapters, sysUser.AdminId, sysUser.RealName)
-
-	br.Ret = 200
-	br.Success = true
-	br.Msg = "保存成功"
-}
-
-// EditDayWeekChapter
-// @Title 编辑晨周报章节内容
-// @Description 编辑晨周报章节内容
-// @Param	request	body models.EditReportChapterReq true "type json string"
-// @Success 200 Ret=200 保存成功
-// @router /editDayWeekChapter [post]
-func (this *ReportController) EditDayWeekChapter() {
-	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
+	// 图表刷新状态
+	refreshResult := data.CheckBatchChartRefreshResult("report", chapterInfo.ReportId, chapterInfo.ReportChapterId)
+	if !refreshResult {
+		br.Msg = "图表刷新未完成,请稍后操作"
+		br.ErrMsg = "图表刷新未完成,请稍后操作"
+		br.IsSendEmail = false
 		return
 	}
 
-	var req models.EditReportChapterReq
-	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
+	// 获取规则配置
+	reportChapterTypeRule, err := models.GetReportChapterTypeById(chapterInfo.TypeId)
 	if err != nil {
-		br.Msg = "参数解析异常!"
-		br.ErrMsg = "参数解析失败,Err:" + err.Error()
-		return
-	}
-	reportChapterId := req.ReportChapterId
-	if reportChapterId <= 0 {
-		br.Msg = "报告章节ID有误"
-		return
-	}
-	if req.Content == "" {
-		br.Msg = "请输入内容"
+		br.Msg = "获取配置信息异常"
+		br.ErrMsg = "获取配置信息异常, Err: " + err.Error()
 		return
 	}
-	//if req.AddType == 0 {
-	//	br.Msg = "请选择新增方式"
-	//	return
-	//}
-	// 获取章节详情
-	reportChapterInfo, err := models.GetReportChapterInfoById(reportChapterId)
-	if err != nil {
-		br.Msg = "报告章节信息有误"
-		br.ErrMsg = "报告章节信息有误, Err: " + err.Error()
+	if reportChapterTypeRule.Enabled == 0 {
+		br.Msg = "该章节已永久停更"
+		br.ErrMsg = "该章节已永久停更 "
+		br.IsSendEmail = false
 		return
 	}
-	// 获取报告详情
-	reportInfo, err := models.GetReportById(reportChapterInfo.ReportId)
-	if err != nil {
-		br.Msg = "报告信息有误"
-		br.ErrMsg = "报告信息有误, Err: " + err.Error()
-		return
+
+	updateCols := make([]string, 0)
+	updateCols = append(updateCols, "Title", "AddType", "Author", "Content", "ContentSub", "IsEdit", "CreateTime", "PublishState", "PublishTime")
+
+	var needHandleVideo bool // 是否需要处理音频文件
+	nowTime := time.Now()
+	var publishTime time.Time
+	if reportInfo.MsgIsSend == 1 && reportInfo.PublishTime != "" { //如果报告曾经发布过,并且已经发送过模版消息,则章节的发布时间为报告的发布时间
+		publishTime, _ = time.ParseInLocation(utils.FormatDateTime, reportInfo.PublishTime, time.Local)
+	} else {
+		publishTime = time.Now()
 	}
-	if reportInfo.State == 2 {
-		br.Msg = "该报告已发布,不允许编辑"
-		br.ErrMsg = "该报告已发布,不允许编辑"
-		return
+	if req.VideoUrl != "" {
+		chapterInfo.VideoUrl = req.VideoUrl
+		chapterInfo.VideoName = req.VideoName
+		chapterInfo.VideoSize = req.VideoSize
+		chapterInfo.VideoPlaySeconds = req.VideoPlaySeconds
+		chapterInfo.VideoKind = 1
+
+		updateCols = append(updateCols, "VideoUrl", "VideoName", "VideoSize", "VideoPlaySeconds", "VideoKind")
+
+		// 手动上传的音频需要处理音频文件
+		needHandleVideo = true
+	} else {
+		if chapterInfo.VideoUrl == "" {
+			// 生成video
+			videoUrl, videoName, videoSize, videoPlaySeconds, err := services.CreateReportVideo(req.Title, req.Content, publishTime.Format(utils.FormatDateTime))
+			if err != nil {
+				br.Msg = "生成video失败"
+				br.ErrMsg = "生成video失败, Err: " + err.Error()
+				return
+			}
+			chapterInfo.VideoUrl = videoUrl
+			chapterInfo.VideoName = videoName
+			chapterInfo.VideoSize = videoSize
+			chapterInfo.VideoPlaySeconds = fmt.Sprintf("%.2f", videoPlaySeconds)
+			chapterInfo.VideoKind = 2
+			updateCols = append(updateCols, "VideoUrl", "VideoName", "VideoSize", "VideoPlaySeconds", "VideoKind")
+		}
 	}
 
-	reqTickerList := req.TickerList
-	// 更新章节及指标
+	// 更新章节信息
 	contentSub := ""
 	if req.Content != "" {
 		e := utils.ContentXssCheck(req.Content)
@@ -1139,43 +972,22 @@ func (this *ReportController) EditDayWeekChapter() {
 			return
 		}
 	}
+	chapterInfo.Title = req.Title
+	chapterInfo.AddType = req.AddType
+	chapterInfo.Author = req.Author
+	chapterInfo.Content = html.EscapeString(req.Content)
+	chapterInfo.ContentSub = html.EscapeString(contentSub)
+	chapterInfo.IsEdit = 1
+	chapterInfo.CreateTime = req.CreateTime
+	chapterInfo.PublishState = 2
+	chapterInfo.PublishTime = publishTime
 
-	reportChapterInfo.Title = req.Title
-	//reportChapterInfo.AddType = req.AddType
-	reportChapterInfo.Author = req.Author
-	reportChapterInfo.Content = html.EscapeString(req.Content)
-	reportChapterInfo.ContentSub = html.EscapeString(contentSub)
-	reportChapterInfo.IsEdit = 1
-	reportChapterInfo.CreateTime = req.CreateTime
-	reportChapterInfo.VideoUrl = req.VideoUrl
-	reportChapterInfo.VideoName = req.VideoName
-	reportChapterInfo.VideoPlaySeconds = req.VideoPlaySeconds
-	reportChapterInfo.VideoSize = req.VideoSize
-	reportChapterInfo.VideoKind = 1
-
-	reportChapterInfo.LastModifyAdminId = sysUser.AdminId
-	reportChapterInfo.LastModifyAdminName = sysUser.RealName
-	reportChapterInfo.ContentModifyTime = time.Now()
-	reportChapterInfo.ContentStruct = html.EscapeString(req.ContentStruct)
-	reportChapterInfo.CanvasColor = req.CanvasColor
-	reportChapterInfo.HeadResourceId = req.HeadResourceId
-	reportChapterInfo.EndResourceId = req.EndResourceId
-
-	updateCols := make([]string, 0)
-	updateCols = append(updateCols, "Title", "AddType", "Author", "Content", "ContentSub", "IsEdit", "CreateTime")
-	if req.VideoUrl != "" {
-		updateCols = append(updateCols, "VideoUrl", "VideoName", "VideoSize", "VideoPlaySeconds", "VideoKind")
-	}
-
-	updateCols = append(updateCols, "LastModifyAdminId", "LastModifyAdminName", "ContentModifyTime", "ContentStruct", "CanvasColor", "HeadResourceId", "EndResourceId")
-
-	// 章节报告更新指标
+	// 晨报更新指标
 	tickerList := make([]*models.ReportChapterTicker, 0)
-	if len(reqTickerList) > 0 {
-		nowTime := time.Now()
+	if chapterInfo.ReportType == "day" && len(reqTickerList) > 0 {
 		for i := 0; i < len(reqTickerList); i++ {
 			tickerList = append(tickerList, &models.ReportChapterTicker{
-				ReportChapterId: reportChapterInfo.ReportChapterId,
+				ReportChapterId: chapterInfo.ReportChapterId,
 				Sort:            reqTickerList[i].Sort,
 				Ticker:          reqTickerList[i].Ticker,
 				CreateTime:      nowTime,
@@ -1183,543 +995,227 @@ func (this *ReportController) EditDayWeekChapter() {
 			})
 		}
 	}
-	err = models.UpdateChapterAndTicker(reportChapterInfo, updateCols, tickerList)
-	if err != nil {
-		br.Msg = "保存失败"
+	if err = models.UpdateChapterAndTicker(chapterInfo, updateCols, tickerList); err != nil {
+		br.Msg = "发布失败"
 		br.ErrMsg = "报告章节内容保存失败, Err: " + err.Error()
 		return
 	}
+	// 更新章节ES
+	{
+		go services.UpdateReportChapterEs(chapterInfo.ReportChapterId)
+	}
+
+	// 同时发布报告
+	if req.PublishReport == 1 {
+		if _, e := services.PublishDayWeekReport(chapterInfo.ReportId); e != nil {
+			br.Msg = "章节发布成功,报告发布失败,请手动发布报告"
+			br.ErrMsg = "发布晨/周报失败, Err: " + e.Error()
+			return
+		}
+	}
 
-	// 备份关键数据
-	chapters := make([]*models.ReportChapter, 0)
-	chapters = append(chapters, reportChapterInfo)
-	go services.SaveReportLogs(nil, chapters, sysUser.AdminId, sysUser.RealName)
+	// 处理报告中的音频文件分贝
+	if needHandleVideo {
+		go services.HandleVideoDecibel(chapterInfo)
+	}
 
 	br.Ret = 200
 	br.Success = true
-	br.Msg = "保存成功"
+	br.Msg = "操作成功"
 }
 
-// EditChapterBaseInfoAndPermission
-// @Title 修改报告章节的基础信息、授权用户权限、品种权限
-// @Description 修改报告章节的基础信息、授权用户权限、品种权限
-// @Param	request	body models.EditReportChapterReq true "type json string"
-// @Success 200 Ret=200 保存成功
-// @router /chapter/base_info/edit [post]
-func (this *ReportController) EditChapterBaseInfoAndPermission() {
+// AuthorizedListReport
+// @Title 获取有权限的报告列表接口
+// @Description 获取有权限的报告列表接口
+// @Param   PageSize   query   int  true       "每页数据条数"
+// @Param   CurrentIndex   query   int  true       "当前页页码,从1开始"
+// @Param   KeyWord   query   string  true       "搜索关键词"
+// @Param   ClassifyIdFirst   query   int  true       "一级分类id"
+// @Param   ClassifyIdSecond   query   int  true       "二级分类id"
+// @Param   ClassifyIdThird   query   int  true       "三级分类id"
+// @Success 200 {object} models.ReportListResp
+// @router /list/authorized [get]
+func (this *ReportController) AuthorizedListReport() {
 	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
+	pageSize, _ := this.GetInt("PageSize")
+	currentIndex, _ := this.GetInt("CurrentIndex")
+	keyword := this.GetString("KeyWord")
+	classifyIdFirst, _ := this.GetInt("ClassifyIdFirst", 0)
+	classifyIdSecond, _ := this.GetInt("ClassifyIdSecond", 0)
+	classifyIdThird, _ := this.GetInt("ClassifyIdThird", 0)
+
+	var startSize int
+	if pageSize <= 0 {
+		pageSize = utils.PageSize20
+	}
+	if currentIndex <= 0 {
+		currentIndex = 1
 	}
+	startSize = utils.StartIndex(currentIndex, pageSize)
+	var list []*models.ReportList
 
-	var req models.EditReportChapterBaseInfoAndPermissionReq
-	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
-	if err != nil {
-		br.Msg = "参数解析异常!"
-		br.ErrMsg = "参数解析失败,Err:" + err.Error()
+	// 没有输入信息,那就不展示
+	if keyword == `` {
+		page := paging.GetPaging(currentIndex, pageSize, 0)
+		resp := new(models.ReportListResp)
+		resp.Paging = page
+		resp.List = list
+		br.Ret = 200
+		br.Success = true
+		br.Msg = "获取成功"
+		br.Data = resp
 		return
 	}
-	reportChapterId := req.ReportChapterId
-	if reportChapterId <= 0 {
-		br.Msg = "报告章节ID有误"
-		return
+
+	// 当前用户有权限的报告id列表
+	grantReportIdList := make([]int, 0)
+	{
+		obj := report.ReportGrant{}
+		grantList, err := obj.GetGrantListByAdminId(this.SysUser.AdminId)
+		if err != nil {
+			br.Msg = "获取失败"
+			br.ErrMsg = "获取授权报告id失败,Err:" + err.Error()
+			return
+		}
+		for _, v := range grantList {
+			grantReportIdList = append(grantReportIdList, v.ReportId)
+		}
 	}
-	// 获取章节详情
-	reportChapterInfo, err := models.GetReportChapterInfoById(reportChapterId)
-	if err != nil {
-		br.Msg = "报告章节信息有误"
-		br.ErrMsg = "报告章节信息有误, Err: " + err.Error()
-		return
+
+	var condition string
+	var pars []interface{}
+
+	condition += ` AND a.title LIKE ? `
+	pars = utils.GetLikeKeywordPars(pars, keyword, 1)
+
+	if classifyIdFirst > 0 {
+		condition += ` AND a.classify_id_first = ? `
+		pars = append(pars, classifyIdFirst)
 	}
-	// 获取报告详情
-	reportInfo, err := models.GetReportByReportId(reportChapterInfo.ReportId)
-	if err != nil {
-		br.Msg = "报告信息有误"
-		br.ErrMsg = "报告信息有误, Err: " + err.Error()
-		return
+	if classifyIdSecond > 0 {
+		condition += ` AND a.classify_id_second = ? `
+		pars = append(pars, classifyIdSecond)
 	}
-	if reportInfo.State == 2 {
-		br.Msg = "该报告已发布,不允许编辑"
-		br.ErrMsg = "该报告已发布,不允许编辑"
-		return
+	if classifyIdThird > 0 {
+		condition += ` AND a.classify_id_third = ? `
+		pars = append(pars, classifyIdSecond)
 	}
 
-	err, errMsg := services.EditChapterBaseInfoAndPermission(reportInfo, reportChapterInfo, req.Title, req.PermissionIdList, req.AdminIdList)
-	if err != nil {
-		br.Msg = "保存失败"
-		if errMsg != "" {
-			br.Msg = errMsg
-		}
-		br.ErrMsg = "保存失败,Err:" + err.Error()
-		return
-	}
+	var err error
+	var total int
 
-	br.Ret = 200
-	br.Success = true
-	br.Msg = "保存成功"
-}
+	orCondition := `AND ( (a.is_public_publish = ? AND a.state in (2,6)) or a.admin_id = ? `
+	pars = append(pars, 1, this.SysUser.AdminId)
 
-// GetDayWeekChapter
-// @Title 获取晨周报章节信息
-// @Description 获取晨周报章节信息
-// @Param	ReportChapterId  query  int  true  "报告章节ID"
-// @Success 200 Ret=200 保存成功
-// @router /getDayWeekChapter [get]
-func (this *ReportController) GetDayWeekChapter() {
-	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
+	// 当前用户有权限的报告id列表
+	num := len(grantReportIdList)
+	if num > 0 {
+		orCondition += ` OR a.id in (` + utils.GetOrmInReplace(num) + `)`
+		pars = append(pars, grantReportIdList)
 	}
+	orCondition += ` ) `
 
-	reportChapterId, _ := this.GetInt("ReportChapterId")
-	if reportChapterId <= 0 {
-		br.Msg = "参数有误"
+	condition += orCondition
+
+	total, err = models.GetReportListCountByAuthorized(condition, pars)
+	if err != nil {
+		br.Msg = "获取失败"
+		br.ErrMsg = "获取失败,Err:" + err.Error()
 		return
 	}
-	chapterInfo, err := models.GetReportChapterInfoById(reportChapterId)
+	list, err = models.GetReportListByAuthorized(condition, pars, startSize, pageSize)
 	if err != nil {
-		br.Msg = "获取章节信息失败"
-		br.ErrMsg = "获取章节信息失败, Err: " + err.Error()
+		br.Msg = "获取失败"
+		br.ErrMsg = "获取失败,Err:" + err.Error()
 		return
 	}
-	if chapterInfo != nil {
-		chapterInfo.Content = html.UnescapeString(chapterInfo.Content)
-		chapterInfo.ContentSub = html.UnescapeString(chapterInfo.ContentSub)
-		chapterInfo.ContentStruct = html.UnescapeString(chapterInfo.ContentStruct)
-	}
 
+	//for _, item := range list {
+	//	if item.HasChapter == 1 {
+	//		item.CanEdit = true
+	//	} else {
+	//		markStatus, err := services.UpdateReportEditMark(item.Id, this.SysUser.AdminId, 2, this.SysUser.RealName, this.Lang)
+	//		if err != nil {
+	//			br.Msg = "查询标记状态失败"
+	//			br.ErrMsg = "查询标记状态失败,Err:" + err.Error()
+	//			return
+	//		}
+	//		if markStatus.Status == 0 {
+	//			item.CanEdit = true
+	//		} else {
+	//			item.Editor = markStatus.Editor
+	//		}
+	//	}
+	//}
+
+	page := paging.GetPaging(currentIndex, pageSize, total)
+	resp := new(models.ReportListResp)
+	resp.Paging = page
+	resp.List = list
 	br.Ret = 200
 	br.Success = true
 	br.Msg = "获取成功"
-	br.Data = chapterInfo
+	br.Data = resp
 }
 
-// PublishDayWeekReportChapter
-// @Title 发布晨周报章节
-// @Description 发布晨周报章节
-// @Param	request	body models.PublishReportChapterReq true "type json string"
-// @Success 200 Ret=200 操作成功
-// @router /publishDayWeekReportChapter [post]
-func (this *ReportController) PublishDayWeekReportChapter() {
+// BaseDetail
+// @Title 获取报告基础信息详情接口
+// @Description 获取报告基础信息详情接口
+// @Param	request	body models.ReportDetailReq true "type json string"
+// @Success 200 {object} models.Report
+// @router /detail/base [get]
+func (this *ReportController) BaseDetail() {
 	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 models.PublishReportChapterReq
+	/*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.ReportChapterId <= 0 {
-		br.Msg = "参数有误"
-		return
-	}
-	if req.Title == "" {
-		br.Msg = "请输入标题"
-		return
-	}
-	if req.Content == "" {
-		br.Msg = "请输入内容"
-		return
-	}
-	if req.AddType == 0 {
-		br.Msg = "请选择新增方式"
-		return
-	}
-
-	reqTickerList := req.TickerList
-
-	chapterInfo, err := models.GetReportChapterInfoById(req.ReportChapterId)
-	if err != nil {
-		br.Msg = "章节信息有误"
-		br.ErrMsg = "获取章节信息失败, Err: " + err.Error()
+	if req.ReportId <= 0 {
+		br.Msg = "参数错误"
 		return
-	}
-
-	reportInfo, err := models.GetReportById(chapterInfo.ReportId)
+	}*/
+	reportId, err := this.GetInt("ReportId")
 	if err != nil {
-		br.Msg = "查询报告有误"
-		br.ErrMsg = "查询报告信息失败, Err: " + err.Error()
-		return
-	}
-	if reportInfo.State == 2 {
-		br.Msg = "该报告已发布,不允许编辑"
-		br.ErrMsg = "该报告已发布,不允许编辑"
+		br.Msg = "获取参数失败!"
+		br.ErrMsg = "获取参数失败,Err:" + err.Error()
 		return
 	}
-
-	// 图表刷新状态
-	refreshResult := data.CheckBatchChartRefreshResult("report", chapterInfo.ReportId, chapterInfo.ReportChapterId)
-	if !refreshResult {
-		br.Msg = "图表刷新未完成,请稍后操作"
-		br.ErrMsg = "图表刷新未完成,请稍后操作"
-		br.IsSendEmail = false
+	if reportId <= 0 {
+		br.Msg = "参数错误"
 		return
 	}
-
-	// 获取规则配置
-	reportChapterTypeRule, err := models.GetReportChapterTypeById(chapterInfo.TypeId)
+	item, err := models.GetReportById(reportId)
 	if err != nil {
-		br.Msg = "获取配置信息异常"
-		br.ErrMsg = "获取配置信息异常, Err: " + err.Error()
-		return
-	}
-	if reportChapterTypeRule.Enabled == 0 {
-		br.Msg = "该章节已永久停更"
-		br.ErrMsg = "该章节已永久停更 "
-		br.IsSendEmail = false
-		return
-	}
-
-	updateCols := make([]string, 0)
-	updateCols = append(updateCols, "Title", "AddType", "Author", "Content", "ContentSub", "IsEdit", "CreateTime", "PublishState", "PublishTime")
-
-	var needHandleVideo bool // 是否需要处理音频文件
-	nowTime := time.Now()
-	var publishTime time.Time
-	if reportInfo.MsgIsSend == 1 && reportInfo.PublishTime != "" { //如果报告曾经发布过,并且已经发送过模版消息,则章节的发布时间为报告的发布时间
-		publishTime, _ = time.ParseInLocation(utils.FormatDateTime, reportInfo.PublishTime, time.Local)
-	} else {
-		publishTime = time.Now()
-	}
-	if req.VideoUrl != "" {
-		chapterInfo.VideoUrl = req.VideoUrl
-		chapterInfo.VideoName = req.VideoName
-		chapterInfo.VideoSize = req.VideoSize
-		chapterInfo.VideoPlaySeconds = req.VideoPlaySeconds
-		chapterInfo.VideoKind = 1
-
-		updateCols = append(updateCols, "VideoUrl", "VideoName", "VideoSize", "VideoPlaySeconds", "VideoKind")
-
-		// 手动上传的音频需要处理音频文件
-		needHandleVideo = true
-	} else {
-		if chapterInfo.VideoUrl == "" {
-			// 生成video
-			videoUrl, videoName, videoSize, videoPlaySeconds, err := services.CreateReportVideo(req.Title, req.Content, publishTime.Format(utils.FormatDateTime))
-			if err != nil {
-				br.Msg = "生成video失败"
-				br.ErrMsg = "生成video失败, Err: " + err.Error()
-				return
-			}
-			chapterInfo.VideoUrl = videoUrl
-			chapterInfo.VideoName = videoName
-			chapterInfo.VideoSize = videoSize
-			chapterInfo.VideoPlaySeconds = fmt.Sprintf("%.2f", videoPlaySeconds)
-			chapterInfo.VideoKind = 2
-			updateCols = append(updateCols, "VideoUrl", "VideoName", "VideoSize", "VideoPlaySeconds", "VideoKind")
-		}
-	}
-
-	// 更新章节信息
-	contentSub := ""
-	if req.Content != "" {
-		e := utils.ContentXssCheck(req.Content)
-		if e != nil {
-			br.Msg = "存在非法标签"
-			br.ErrMsg = "存在非法标签, Err: " + e.Error()
-			return
-		}
-		contentClean, e := services.FilterReportContentBr(req.Content)
-		if e != nil {
-			br.Msg = "内容去除前后空格失败"
-			br.ErrMsg = "内容去除前后空格失败, Err: " + e.Error()
-			return
-		}
-		req.Content = contentClean
-
-		contentSub, err = services.GetReportContentSub(req.Content)
-		if err != nil {
-			br.Msg = "内容分段解析失败"
-			br.ErrMsg = "编辑报告章节-解析 ContentSub 失败, Err: " + err.Error()
+		if err.Error() == utils.ErrNoRow() {
+			br.Msg = "报告已被删除"
 			return
 		}
-	}
-	chapterInfo.Title = req.Title
-	chapterInfo.AddType = req.AddType
-	chapterInfo.Author = req.Author
-	chapterInfo.Content = html.EscapeString(req.Content)
-	chapterInfo.ContentSub = html.EscapeString(contentSub)
-	chapterInfo.IsEdit = 1
-	chapterInfo.CreateTime = req.CreateTime
-	chapterInfo.PublishState = 2
-	chapterInfo.PublishTime = publishTime
-
-	// 晨报更新指标
-	tickerList := make([]*models.ReportChapterTicker, 0)
-	if chapterInfo.ReportType == "day" && len(reqTickerList) > 0 {
-		for i := 0; i < len(reqTickerList); i++ {
-			tickerList = append(tickerList, &models.ReportChapterTicker{
-				ReportChapterId: chapterInfo.ReportChapterId,
-				Sort:            reqTickerList[i].Sort,
-				Ticker:          reqTickerList[i].Ticker,
-				CreateTime:      nowTime,
-				UpdateTime:      nowTime,
-			})
-		}
-	}
-	if err = models.UpdateChapterAndTicker(chapterInfo, updateCols, tickerList); err != nil {
-		br.Msg = "发布失败"
-		br.ErrMsg = "报告章节内容保存失败, Err: " + err.Error()
+		br.Msg = "获取失败"
+		br.ErrMsg = "获取失败,Err:" + err.Error()
 		return
 	}
-	// 更新章节ES
-	{
-		go services.UpdateReportChapterEs(chapterInfo.ReportChapterId)
-	}
-
-	// 同时发布报告
-	if req.PublishReport == 1 {
-		if _, e := services.PublishDayWeekReport(chapterInfo.ReportId); e != nil {
-			br.Msg = "章节发布成功,报告发布失败,请手动发布报告"
-			br.ErrMsg = "发布晨/周报失败, Err: " + e.Error()
-			return
-		}
-	}
-
-	// 处理报告中的音频文件分贝
-	if needHandleVideo {
-		go services.HandleVideoDecibel(chapterInfo)
-	}
-
-	br.Ret = 200
-	br.Success = true
-	br.Msg = "操作成功"
-}
-
-// AuthorizedListReport
-// @Title 获取有权限的报告列表接口
-// @Description 获取有权限的报告列表接口
-// @Param   PageSize   query   int  true       "每页数据条数"
-// @Param   CurrentIndex   query   int  true       "当前页页码,从1开始"
-// @Param   KeyWord   query   string  true       "搜索关键词"
-// @Success 200 {object} models.ReportListResp
-// @router /list/authorized [get]
-func (this *ReportController) AuthorizedListReport() {
-	br := new(models.BaseResponse).Init()
-	defer func() {
-		this.Data["json"] = br
-		this.ServeJSON()
-	}()
-	pageSize, _ := this.GetInt("PageSize")
-	currentIndex, _ := this.GetInt("CurrentIndex")
-
-	timeType := this.GetString("TimeType")
-	keyWord := this.GetString("KeyWord")
-	filterReportType, _ := this.GetInt("FilterReportType", 1)
-
-	var startSize int
-	if pageSize <= 0 {
-		pageSize = utils.PageSize20
-	}
-	if currentIndex <= 0 {
-		currentIndex = 1
-	}
-	startSize = utils.StartIndex(currentIndex, pageSize)
-
-	if timeType == "" {
-		timeType = "publish_time"
-	}
-	var condition string
-	var pars []interface{}
-
-	if keyWord != "" {
-		condition += ` AND (a.title LIKE ? OR a.admin_real_name LIKE ? ) `
-		pars = utils.GetLikeKeywordPars(pars, keyWord, 2)
-	}
-
-	var err error
-	var total int
-	var list []*models.ReportList
-
-	switch filterReportType {
-	// 筛选报告类型,1:公共研报,2:共享研报,3:我的研报
-	case 1:
-		condition += ` AND a.is_public_publish = ? AND a.state in (2,6)`
-		pars = append(pars, 1)
-	case 3:
-		condition += ` AND a.admin_id = ? `
-		pars = append(pars, this.SysUser.AdminId)
-	case 2:
-		condition += ` AND (a.admin_id = ? or b.admin_id = ?) `
-		pars = append(pars, this.SysUser.AdminId, this.SysUser.AdminId)
-	}
-
-	// 共享报告需要连表查询,所以需要单独写
-	if filterReportType == 2 {
-		total, err = models.GetReportListCountByGrant(condition, pars)
-		if err != nil {
-			br.Msg = "获取失败"
-			br.ErrMsg = "获取失败,Err:" + err.Error()
-			return
-		}
-		list, err = models.GetReportListByGrant(condition, pars, startSize, pageSize)
-		if err != nil {
-			br.Msg = "获取失败"
-			br.ErrMsg = "获取失败,Err:" + err.Error()
-			return
-		}
-	} else {
-		total, err = models.GetReportListCountV1(condition, pars)
-		if err != nil {
-			br.Msg = "获取失败"
-			br.ErrMsg = "获取失败,Err:" + err.Error()
-			return
-		}
-		list, err = models.GetReportListV1(condition, pars, startSize, pageSize)
-		if err != nil {
-			br.Msg = "获取失败"
-			br.ErrMsg = "获取失败,Err:" + err.Error()
-			return
-		}
-	}
-
-	listLen := len(list)
-	if listLen > 0 {
-		pvMap := make(map[int]int)
-		uvMap := make(map[int]int)
-		reportIdArr := make([]string, 0)
-		syncReportIdArr := make([]string, 0)      // 同步过来的报告IDs
-		oldAndNewReportIdMap := make(map[int]int) // 旧报告和新报告的id对应关系
-		for i := 0; i < listLen; i++ {
-			reportIdArr = append(reportIdArr, strconv.Itoa(list[i].Id))
-			if list[i].OldReportId > 0 {
-				syncReportIdArr = append(syncReportIdArr, strconv.Itoa(list[i].OldReportId))
-				oldAndNewReportIdMap[list[i].OldReportId] = list[i].Id
-			}
-			pvMap[list[i].Id] = list[i].Pv
-			uvMap[list[i].Id] = list[i].Uv
-		}
 
-		// 当下报告的pv,uv
-		if len(reportIdArr) > 0 {
-			pvList, e := models.GetReportPvUvByReportIdList(reportIdArr)
-			if e != nil {
-				br.Msg = "获取失败"
-				br.ErrMsg = "获取同步报告对应的PV、UV失败, Err: " + e.Error()
-				return
-			}
-			for _, v := range pvList {
-				pv := pvMap[v.ReportId]
-				uv := uvMap[v.ReportId]
-				pvMap[v.ReportId] = v.PvTotal + pv
-				uvMap[v.ReportId] = v.UvTotal + uv
-			}
-		}
-
-		//reportIds := strings.Join(reportIdArr, ",")
-		//syncReportIds := strings.Join(syncReportIdArr, ",")
+	// 基础信息就不获取章节信息了
+	chapterList := make([]*models.ReportChapter, 0)
 
-		// 查询同步过来的报告对应的老报告PV+UV
-		if len(syncReportIdArr) > 0 {
-			puvList, e := models.GetPUVByResearchReportIds(syncReportIdArr)
-			if e != nil {
-				br.Msg = "获取失败"
-				br.ErrMsg = "获取同步报告对应的PV、UV失败, Err: " + e.Error()
-				return
-			}
-			puvLen := len(puvList)
-			for i := 0; i < puvLen; i++ {
-				newReportId, ok := oldAndNewReportIdMap[puvList[i].ResearchReportId]
-				if ok {
-					pv := pvMap[newReportId]
-					uv := uvMap[newReportId]
-					pvMap[newReportId] = puvList[i].Pv + pv
-					uvMap[newReportId] = puvList[i].Uv + uv
-				}
-			}
-		}
-		// 晨周报音频列表
-		videoList, err := models.GetReportChapterVideoListByReportIds(reportIdArr)
-		if err != nil {
-			br.Msg = "获取失败"
-			br.ErrMsg = "获取报告音频文件失败,Err:" + err.Error()
-			return
-		}
-		for i := 0; i < listLen; i++ {
-			list[i].Content = html.UnescapeString(list[i].Content)
-			list[i].ContentSub = html.UnescapeString(list[i].ContentSub)
-			// 除周报外其余报告均可推送客群
-			list[i].NeedThsMsg = 1
-			//if list[i].HasChapter == 1 && list[i].ChapterType == utils.REPORT_TYPE_WEEK {
-			//	list[i].NeedThsMsg = 0
-			//}
-			chapterList := make([]*models.ReportChapterVideoList, 0)
-			for ii := 0; ii < len(videoList); ii++ {
-				if list[i].Id == videoList[ii].ReportId {
-					chapterList = append(chapterList, videoList[ii])
-				}
-			}
-			list[i].ChapterVideoList = chapterList
-			list[i].Pv += pvMap[list[i].Id]
-			list[i].Uv += uvMap[list[i].Id]
-		}
-	}
+	item.Content = html.UnescapeString(item.Content)
+	item.ContentSub = html.UnescapeString(item.ContentSub)
 
-	for _, item := range list {
-		/*key := fmt.Sprint(`crm:report:edit:`, item.Id)
-		opUserId, _ := utils.Rc.RedisInt(key)
-		//如果当前没有人操作,获取当前操作人是本人,那么编辑按钮可用
-		if opUserId <= 0 || (opUserId == this.SysUser.AdminId) || item.ClassifyNameFirst == "周报" || item.ClassifyNameFirst == "晨报" {
-			item.CanEdit = true
-		} else {
-			adminInfo, errAdmin := system.GetSysUserById(opUserId)
-			if errAdmin != nil {
-				br.Msg = "获取失败"
-				br.ErrMsg = "获取失败,Err:" + errAdmin.Error()
-				return
-			}
-			item.Editor = adminInfo.RealName
-		}*/
-		if item.ClassifyNameFirst == "周报" || item.ClassifyNameFirst == "晨报" {
-			item.CanEdit = true
-		} else {
-			markStatus, err := services.UpdateReportEditMark(item.Id, this.SysUser.AdminId, 2, this.SysUser.RealName, this.Lang)
-			if err != nil {
-				br.Msg = "查询标记状态失败"
-				br.ErrMsg = "查询标记状态失败,Err:" + err.Error()
-				return
-			}
-			if markStatus.Status == 0 {
-				item.CanEdit = true
-			} else {
-				item.Editor = markStatus.Editor
-			}
-		}
+	resp := &models.ReportDetailView{
+		ReportDetail: item,
+		ChapterList:  chapterList,
 	}
-
-	page := paging.GetPaging(currentIndex, pageSize, total)
-	resp := new(models.ReportListResp)
-	resp.Paging = page
-	resp.List = list
 	br.Ret = 200
 	br.Success = true
 	br.Msg = "获取成功"

+ 48 - 3
models/report.go

@@ -858,7 +858,8 @@ func (reportInfo *Report) UpdateReport(cols []string) (err error) {
 	return
 }
 
-// 晨周报详情
+// ReportDetailView
+// @Description: 晨周报详情
 type ReportDetailView struct {
 	*ReportDetail
 	ChapterList []*ReportChapter
@@ -1290,8 +1291,9 @@ func UpdateReportChapterPublishTime(reportId int, videoNameDate string) (err err
 
 // MarkEditReport 标记编辑英文研报的请求数据
 type MarkEditReport struct {
-	ReportId int `description:"研报id"`
-	Status   int `description:"标记状态,1:编辑中,2:编辑完成"`
+	ReportId        int `description:"研报id"`
+	ReportChapterId int `description:"研报章节id"`
+	Status          int `description:"标记状态,1:编辑中,2:编辑完成"`
 }
 
 type MarkReportResp struct {
@@ -1515,3 +1517,46 @@ func EditChapterBaseInfoAndPermission(reportChapterInfo *ReportChapter, updateCo
 
 	return
 }
+
+// GetReportListCountByAuthorized
+// @Description: 获取有权限的报告列表的报告数量
+// @author: Roc
+// @datetime 2024-05-30 15:14:01
+// @param condition string
+// @param pars []interface{}
+// @return count int
+// @return err error
+func GetReportListCountByAuthorized(condition string, pars []interface{}) (count int, err error) {
+	o := orm.NewOrmUsingDB("rddp")
+	sql := `SELECT COUNT(1) AS count  FROM report as a 
+ WHERE 1=1  `
+	if condition != "" {
+		sql += condition
+	}
+
+	err = o.Raw(sql, pars).QueryRow(&count)
+	return
+}
+
+// GetReportListByAuthorized
+// @Description: 获取有权限的报告列表的数据
+// @author: Roc
+// @datetime 2024-05-30 15:15:07
+// @param condition string
+// @param pars []interface{}
+// @param startSize int
+// @param pageSize int
+// @return items []*ReportList
+// @return err error
+func GetReportListByAuthorized(condition string, pars []interface{}, startSize, pageSize int) (items []*ReportList, err error) {
+	o := orm.NewOrmUsingDB("rddp")
+
+	sql := `SELECT id,classify_id_first,classify_name_first,classify_id_second,classify_name_second,classify_id_third,classify_name_third,title,stage,create_time FROM report as a WHERE 1=1  `
+	if condition != "" {
+		sql += condition
+	}
+	// 排序:1:未发布;2:已发布;3-待提交;4-待审批;5-已驳回;6-已通过
+	sql += ` GROUP BY a.id ORDER BY FIELD(state,3,1,4,5,6,2), modify_time DESC LIMIT ?,?`
+	_, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
+	return
+}

+ 16 - 0
models/report/report_grant.go

@@ -108,3 +108,19 @@ func (m ReportGrant) GetGrantByIdAndAdmin(reportId, sysUserId int) (item *Report
 
 	return
 }
+
+// GetGrantListByAdminId
+// @Description: 根据id获取授权列表
+// @author: Roc
+// @receiver m
+// @datetime 2024-06-04 15:33:58
+// @param adminId int
+// @return list []*ReportGrant
+// @return err error
+func (m ReportGrant) GetGrantListByAdminId(adminId int) (list []*ReportGrant, err error) {
+	o := orm.NewOrmUsingDB("rddp")
+	sql := `SELECT * FROM report_grant WHERE admin_id=? `
+	_, err = o.Raw(sql, adminId).QueryRows(&list)
+
+	return
+}

+ 114 - 5
models/report_chapter.go

@@ -52,6 +52,16 @@ type ReportChapter struct {
 	ReportCreateTime    time.Time `description:"报告时间创建时间"`
 }
 
+// ReportChapterItem
+// @Description: 章节详情(带有一些额外的数据)
+type ReportChapterItem struct {
+	ReportChapter
+	GrandAdminIdList []int  `description:"授权的用户id列表"`
+	PermissionIdList []int  `description:"关联的品种id列表"`
+	CanEdit          bool   `description:"是否可编辑"`
+	Editor           string `description:"编辑人"`
+}
+
 type ReportChapterResp struct {
 	ReportChapterId  int    `description:"报告章节ID"`
 	ReportId         int    `description:"报告ID"`
@@ -77,6 +87,10 @@ type ReportChapterResp struct {
 	PublishTime      string `description:"发布时间"`
 	CreateTime       string `description:"创建时间"`
 	ModifyTime       string `description:"修改时间"`
+	GrandAdminIdList []int  `description:"授权的用户id列表"`
+	PermissionIdList []int  `description:"关联的品种id列表"`
+	CanEdit          bool   `description:"是否可编辑"`
+	Editor           string `description:"编辑人"`
 }
 
 // GetChapterListByReportId 根据ReportId获取章节列表
@@ -170,21 +184,21 @@ func GetLastPublishedReportChapter(typeId int, reportType string) (item *ReportC
 // @receiver chapterInfo
 // @datetime 2024-06-04 15:14:41
 // @return err error
-func (chapterInfo *ReportChapter) Add() (err error) {
+func (chapterChapterInfo *ReportChapter) Add() (err error) {
 	o := orm.NewOrmUsingDB("rddp")
-	lastId, err := o.Insert(chapterInfo)
+	lastId, err := o.Insert(chapterChapterInfo)
 	if err != nil {
 		return
 	}
-	chapterInfo.ReportChapterId = int(lastId)
+	chapterChapterInfo.ReportChapterId = int(lastId)
 
 	return
 }
 
 // UpdateChapter 更新报表章节
-func (chapterInfo *ReportChapter) UpdateChapter(cols []string) (err error) {
+func (chapterChapterInfo *ReportChapter) UpdateChapter(cols []string) (err error) {
 	o := orm.NewOrmUsingDB("rddp")
-	_, err = o.Update(chapterInfo, cols...)
+	_, err = o.Update(chapterChapterInfo, cols...)
 
 	return
 }
@@ -398,3 +412,98 @@ func GetReportChapterIdList(reportId int) (list []int, err error) {
 
 	return
 }
+
+// ReportChapterMoveReq
+// @Description:  报告章节移动请求
+type ReportChapterMoveReq struct {
+	ReportChapterId int `description:"报告章节id"`
+	//	ParentChartPermissionId int `description:"父级品种id"`
+	PrevReportChapterId int `description:"上一个兄弟节点报告章节id"`
+	NextReportChapterId int `description:"下一个兄弟节点报告章节id"`
+}
+
+// GetReportChapterById
+// @Description: 获取具体章节
+// @author: Roc
+// @receiver r
+// @datetime 2024-06-06 09:32:40
+// @param reportChapterId int
+// @return item *ReportChapter
+// @return err error
+func (chapterChapterInfo *ReportChapter) GetReportChapterById(reportChapterId int) (item *ReportChapter, err error) {
+	o := orm.NewOrmUsingDB("rddp")
+	sql := ` SELECT * FROM report_chapter WHERE report_chapter_id = ?`
+	err = o.Raw(sql, reportChapterId).QueryRow(&item)
+	return
+}
+
+// UpdateReportChapterSortByReportId
+// @Description: 根据父类id更新排序
+// @author: Roc
+// @receiver chapterChapterInfo
+// @datetime 2024-06-06 09:39:28
+// @param reportId int
+// @param reportChapterId int
+// @param nowSort int
+// @param updateSort string
+// @return err error
+func (chapterChapterInfo *ReportChapter) UpdateReportChapterSortByReportId(reportId, reportChapterId, nowSort int, updateSort string) (err error) {
+	o := orm.NewOrmUsingDB("rddp")
+	pars := make([]interface{}, 0)
+	sql := ` update report_chapter set sort = ` + updateSort + ` WHERE report_id = ? AND sort > ?`
+	pars = append(pars, reportId, nowSort)
+
+	if reportChapterId > 0 {
+		sql += ` or ( report_chapter_id > ?  and sort = ? )`
+		pars = append(pars, reportChapterId, nowSort)
+	}
+
+	_, err = o.Raw(sql, pars).Exec()
+
+	return
+}
+
+// GetFirstReportChapterByReportId
+// @Description: 获取当前报告下,且排序数相同 的排序第一条的数据
+// @author: Roc
+// @receiver chapterChapterInfo
+// @datetime 2024-06-06 09:45:32
+// @param reportId int
+// @return item *ReportChapter
+// @return err error
+func (chapterChapterInfo *ReportChapter) GetFirstReportChapterByReportId(reportId int) (item *ReportChapter, err error) {
+	o := orm.NewOrmUsingDB("rddp")
+	sql := ` SELECT * FROM report_chapter WHERE 1 = 1 AND report_id = ? ORDER BY sort ASC, report_chapter_id ASC LIMIT 1`
+	err = o.Raw(sql, reportId).QueryRow(&item)
+	return
+}
+
+// GetMaxSortByReportId
+// @Description: 获取最大的排序值
+// @author: Roc
+// @receiver chapterChapterInfo
+// @datetime 2024-06-06 09:44:13
+// @param reportId int
+// @return maxSort int
+// @return err error
+func (chapterChapterInfo *ReportChapter) GetMaxSortByReportId(reportId int) (maxSort int, err error) {
+	o := orm.NewOrmUsingDB("rddp")
+	sql := `SELECT max(sort) AS sort FROM report_chapter WHERE report_id = ?`
+	err = o.Raw(sql, reportId).QueryRow(&maxSort)
+
+	return
+}
+
+// Update
+// @Description: 数据变更
+// @author: Roc
+// @receiver chapterChapterInfo
+// @datetime 2024-06-06 09:47:46
+// @param cols []string
+// @return err error
+func (chapterChapterInfo *ReportChapter) Update(cols []string) (err error) {
+	o := orm.NewOrmUsingDB("rddp")
+	_, err = o.Update(chapterChapterInfo, cols...)
+
+	return
+}

+ 18 - 0
routers/commentsRouter.go

@@ -7828,6 +7828,15 @@ func init() {
             Filters: nil,
             Params: nil})
 
+    beego.GlobalControllerRouter["eta/eta_api/controllers:ReportController"] = append(beego.GlobalControllerRouter["eta/eta_api/controllers:ReportController"],
+        beego.ControllerComments{
+            Method: "ChapterMove",
+            Router: `/chapter/move`,
+            AllowHTTPMethods: []string{"post"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
     beego.GlobalControllerRouter["eta/eta_api/controllers:ReportController"] = append(beego.GlobalControllerRouter["eta/eta_api/controllers:ReportController"],
         beego.ControllerComments{
             Method: "ClassifyIdDetail",
@@ -7855,6 +7864,15 @@ func init() {
             Filters: nil,
             Params: nil})
 
+    beego.GlobalControllerRouter["eta/eta_api/controllers:ReportController"] = append(beego.GlobalControllerRouter["eta/eta_api/controllers:ReportController"],
+        beego.ControllerComments{
+            Method: "BaseDetail",
+            Router: `/detail/base`,
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
     beego.GlobalControllerRouter["eta/eta_api/controllers:ReportController"] = append(beego.GlobalControllerRouter["eta/eta_api/controllers:ReportController"],
         beego.ControllerComments{
             Method: "Edit",

+ 12 - 4
services/report.go

@@ -1038,9 +1038,13 @@ func GetReportContentSubWithoutIframe(content string) (contentSub string, err er
 
 // UpdateReportEditMark 更新研报当前更新状态
 // status 枚举值 1:编辑中,0:完成编辑, 2:只做查询
-func UpdateReportEditMark(reportId, nowUserId, status int, nowUserName, lang string) (ret models.MarkReportResp, err error) {
+func UpdateReportEditMark(reportId, reportChapterId, nowUserId, status int, nowUserName, lang string) (ret models.MarkReportResp, err error) {
 	//更新标记key
 	key := fmt.Sprint(`crm:report:edit:`, reportId)
+	//  章节id不为0则加上章节id
+	if reportChapterId > 0 {
+		key = fmt.Sprint(key, ":", reportChapterId)
+	}
 	ret.Status = 0
 	ret.Msg = "无人编辑"
 
@@ -1069,9 +1073,6 @@ func UpdateReportEditMark(reportId, nowUserId, status int, nowUserName, lang str
 		classifyNameFirst = reportInfo.ClassifyNameFirst
 	}
 
-	if classifyNameFirst == "晨报" || classifyNameFirst == "周报" {
-		return
-	}
 	if opUserId > 0 && opUserId != nowUserId {
 		editor := opUser.Editor
 		if editor == "" {
@@ -1183,6 +1184,13 @@ func AddReportAndChapter(reportInfo *models.Report, inheritReportId int) (err er
 			return
 		}
 		if inheritReport != nil {
+			// 判断当前的报告分类与继承的报告分类是否一致
+			if inheritReport.ClassifyIdFirst != reportInfo.ClassifyIdFirst || inheritReport.ClassifyIdSecond != reportInfo.ClassifyIdSecond || inheritReport.ClassifyIdThird != reportInfo.ClassifyIdThird {
+				errMsg = "分类异常,与继承的报告分类不一致"
+				err = tmpErr
+				return
+			}
+
 			reportInfo.ChapterType = inheritReport.ChapterType
 			reportInfo.Content = inheritReport.Content
 			reportInfo.ContentSub = inheritReport.ContentSub

+ 169 - 0
services/report_chapter.go

@@ -0,0 +1,169 @@
+package services
+
+import (
+	"eta/eta_api/models"
+	"eta/eta_api/utils"
+	"fmt"
+	"time"
+)
+
+// MoveReportChapter
+// @Description: 移动报告章节
+// @author: Roc
+// @datetime 2024-06-06 09:48:52
+// @param req *models.ReportChapterMoveReq
+// @return err error
+// @return errMsg string
+func MoveReportChapter(req *models.ReportChapterMoveReq) (err error, errMsg string) {
+	ob := new(models.ReportChapter)
+	reportChapterId := req.ReportChapterId
+	prevReportChapterId := req.PrevReportChapterId
+	nextReportChapterId := req.NextReportChapterId
+
+	//如果有传入 上一个兄弟节点分类id
+	var (
+		reportChapter     *models.ReportChapter
+		prevReportChapter *models.ReportChapter
+		nextReportChapter *models.ReportChapter
+
+		prevSort int
+		nextSort int
+	)
+
+	// 移动对象为分类, 判断权限
+	reportChapter, err = ob.GetReportChapterById(reportChapterId)
+	if err != nil {
+		if err.Error() == utils.ErrNoRow() {
+			errMsg = "当前报告章节不存在"
+			err = fmt.Errorf("获取报告章节信息失败,Err:" + err.Error())
+			return
+		}
+		errMsg = "移动失败"
+		err = fmt.Errorf("获取章节信息失败,Err:" + err.Error())
+		return
+	} else if reportChapter.ReportChapterId == 0 {
+		errMsg = "当前报告章节不存在"
+		err = fmt.Errorf("获取报告章节信息失败,Err:" + err.Error())
+		return
+	}
+
+	if prevReportChapterId > 0 {
+		prevReportChapter, err = ob.GetReportChapterById(prevReportChapterId)
+		if err != nil {
+			errMsg = "移动失败"
+			err = fmt.Errorf("获取上一个兄弟节点分类信息失败,Err:" + err.Error())
+			return
+		}
+		prevSort = prevReportChapter.Sort
+	}
+
+	if nextReportChapterId > 0 {
+		//下一个兄弟节点
+		nextReportChapter, err = ob.GetReportChapterById(nextReportChapterId)
+		if err != nil {
+			errMsg = "移动失败"
+			err = fmt.Errorf("获取下一个兄弟节点分类信息失败,Err:" + err.Error())
+			return
+		}
+		nextSort = nextReportChapter.Sort
+	}
+
+	err, errMsg = moveReportChapter(reportChapter, prevReportChapter, nextReportChapter, reportChapter.ReportId, prevSort, nextSort)
+	return
+}
+
+// moveReportChapter
+// @Description: 移动章节分类
+// @author: Roc
+// @datetime 2024-06-06 09:48:46
+// @param reportChapter *models.ReportChapter
+// @param prevReportChapter *models.ReportChapter
+// @param nextReportChapter *models.ReportChapter
+// @param reportId int
+// @param prevSort int
+// @param nextSort int
+// @return err error
+// @return errMsg string
+func moveReportChapter(reportChapter, prevReportChapter, nextReportChapter *models.ReportChapter, reportId int, prevSort, nextSort int) (err error, errMsg string) {
+	ob := new(models.ReportChapter)
+	updateCol := make([]string, 0)
+
+	if prevSort > 0 {
+		//如果是移动在两个兄弟节点之间
+		if nextSort > 0 {
+			//下一个兄弟节点
+			//如果上一个兄弟与下一个兄弟的排序权重是一致的,那么需要将下一个兄弟(以及下个兄弟的同样排序权重)的排序权重+2,自己变成上一个兄弟的排序权重+1
+			if prevSort == nextSort || prevSort == reportChapter.Sort {
+				//变更兄弟节点的排序
+				updateSortStr := `sort + 2`
+
+				//变更分类
+				if prevReportChapter != nil {
+					_ = ob.UpdateReportChapterSortByReportId(reportId, prevReportChapter.ReportChapterId, prevReportChapter.Sort, updateSortStr)
+				} else {
+					_ = ob.UpdateReportChapterSortByReportId(reportId, 0, prevSort, updateSortStr)
+				}
+
+			} else {
+				//如果下一个兄弟的排序权重正好是上个兄弟节点的下一层,那么需要再加一层了
+				if nextSort-prevSort == 1 {
+					//变更兄弟节点的排序
+					updateSortStr := `sort + 1`
+
+					//变更分类
+					if prevReportChapter != nil {
+						_ = ob.UpdateReportChapterSortByReportId(reportId, prevReportChapter.ReportChapterId, prevSort, updateSortStr)
+					} else {
+						_ = ob.UpdateReportChapterSortByReportId(reportId, 0, prevSort, updateSortStr)
+					}
+
+				}
+			}
+		}
+
+		reportChapter.Sort = prevSort + 1
+		reportChapter.ModifyTime = time.Now()
+		updateCol = append(updateCol, "Sort", "ModifyTime")
+	} else if prevReportChapter == nil && nextReportChapter == nil {
+		//处理只拖动到目录里,默认放到目录底部的情况
+		var maxSort int
+		maxSort, err = ob.GetMaxSortByReportId(reportId)
+		if err != nil {
+			errMsg = "移动失败"
+			err = fmt.Errorf("查询组内排序信息失败,Err:" + err.Error())
+			return
+		}
+		reportChapter.Sort = maxSort + 1 //那就是排在组内最后一位
+		reportChapter.ModifyTime = time.Now()
+		updateCol = append(updateCol, "Sort", "ModifyTime")
+	} else {
+		// 拖动到父级分类的第一位
+		firstReportChapter, tmpErr := ob.GetFirstReportChapterByReportId(reportId)
+		if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
+			errMsg = "移动失败"
+			err = fmt.Errorf("获取当前报告下,且排序数相同 的排序第一条的数据失败,Err:" + tmpErr.Error())
+			return
+		}
+
+		//如果该分类下存在其他分类,且第一个其他分类的排序等于0,那么需要调整排序
+		if firstReportChapter != nil && firstReportChapter.ReportChapterId != 0 && firstReportChapter.Sort == 0 {
+			updateSortStr := ` sort + 1 `
+			_ = ob.UpdateReportChapterSortByReportId(reportId, firstReportChapter.ReportChapterId-1, 0, updateSortStr)
+		}
+
+		reportChapter.Sort = 0 //那就是排在第一位
+		reportChapter.ModifyTime = time.Now()
+		updateCol = append(updateCol, "Sort", "ModifyTime")
+	}
+
+	//更新
+	if len(updateCol) > 0 {
+		err = reportChapter.Update(updateCol)
+		if err != nil {
+			errMsg = "移动失败"
+			err = fmt.Errorf("修改失败,Err:" + err.Error())
+			return
+		}
+	}
+	return
+}