Quellcode durchsuchen

fix:报告改版

Roc vor 8 Monaten
Ursprung
Commit
e194efbac6

+ 1 - 1
controllers/classify.go

@@ -57,7 +57,7 @@ func (this *ClassifyController) ListClassify() {
 		tmpList, tmpErr := services.GetParentClassifyListByParentIdList(currParentClassifyIdList)
 		if tmpErr != nil {
 			br.Msg = "获取失败"
-			br.ErrMsg = "获取上级分类信息失败,Err:" + err.Error()
+			br.ErrMsg = "获取上级分类信息失败,Err:" + tmpErr.Error()
 			return
 		}
 		for _, v := range tmpList {

+ 14 - 5
controllers/report.go

@@ -1850,7 +1850,7 @@ func (this *ReportController) MarkEditStatus() {
 // @Title 模板消息/客群消息推送接口
 // @Description 模板消息/客群消息推送接口
 // @Param	request	body models.SendTemplateMsgReq true "type json string"
-// @Success 200 Ret=200 推送成功
+// @Success 200 {object} models.SendTemplateMsgResp
 // @router /sendMsg [post]
 func (this *ReportController) SendMsg() {
 	br := new(models.BaseResponse).Init()
@@ -1884,13 +1884,13 @@ func (this *ReportController) SendMsg() {
 		}()
 	}
 
-	report, e := models.GetReportById(req.ReportId)
+	reportInfo, e := models.GetReportByReportId(req.ReportId)
 	if e != nil {
 		br.Msg = "报告不存在或已被删除, 请刷新页面"
 		br.ErrMsg = "获取报告失败, Err: " + e.Error()
 		return
 	}
-	if report.MsgIsSend == 1 && report.ThsMsgIsSend == 1 {
+	if reportInfo.MsgIsSend == 1 && reportInfo.ThsMsgIsSend == 1 {
 		br.Msg = "消息已推送,请勿重复操作"
 		br.ErrMsg = "消息已推送,请勿重复操作"
 		return
@@ -1911,7 +1911,7 @@ func (this *ReportController) SendMsg() {
 
 	// 可能存在历史数据两个只推了一个所以此处加个判断
 	// 推送模板消息
-	if report.MsgIsSend == 0 {
+	if reportInfo.MsgIsSend == 0 {
 		go func() {
 			fmt.Println("推送模板消息:", req.ReportId)
 			_ = services.SendMiniProgramReportWxMsg(req.ReportId)
@@ -1919,7 +1919,12 @@ func (this *ReportController) SendMsg() {
 	}
 
 	// 更新推送消息状态
-	if err = models.ModifyReportMsgIsSendV2(req.ReportId); err != nil {
+	reportInfo.MsgIsSend = 1
+	reportInfo.ThsMsgIsSend = 1
+	reportInfo.MsgSendTime = time.Now()
+	reportInfo.ModifyTime = time.Now()
+	err = reportInfo.UpdateReport([]string{"MsgIsSend", "ThsMsgIsSend", "MsgSendTime", "ModifyTime"})
+	if err != nil {
 		br.Msg = "推送失败"
 		br.ErrMsg = "更新报告消息状态失败, Err:" + err.Error()
 		return
@@ -1929,6 +1934,10 @@ func (this *ReportController) SendMsg() {
 	br.Success = true
 	br.Msg = "推送成功"
 	br.IsAddLog = true
+	br.Data = models.SendTemplateMsgResp{
+		ReportId:    reportInfo.Id,
+		MsgSendTime: reportInfo.MsgSendTime.Format(utils.FormatDateTime),
+	}
 }
 
 // CheckDayWeekReportChapterVideo

+ 140 - 1
controllers/report_chapter.go

@@ -346,7 +346,9 @@ func (this *ReportController) EditDayWeekChapter() {
 		}
 	}
 
-	reportChapterInfo.Title = req.Title
+	if req.Title != `` {
+		reportChapterInfo.Title = req.Title
+	}
 	//reportChapterInfo.AddType = req.AddType
 	reportChapterInfo.Author = req.Author
 	reportChapterInfo.Content = html.EscapeString(req.Content)
@@ -1396,3 +1398,140 @@ func (this *ReportController) GetUnPublishReportChapterList() {
 	br.Msg = "获取成功"
 	br.Data = unPublishedList
 }
+
+// EditChapterTitle
+// @Title 编辑章节标题
+// @Description 编辑章节标题
+// @Param	request	body models.EditReportChapterReq true "type json string"
+// @Success 200 Ret=200 保存成功
+// @router /chapter/title/edit [post]
+func (this *ReportController) EditChapterTitle() {
+	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.Title == "" {
+		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
+	}
+	// 报告的最后编辑人
+	reportInfo.LastModifyAdminId = sysUser.AdminId
+	reportInfo.LastModifyAdminName = sysUser.RealName
+	reportInfo.ModifyTime = time.Now()
+
+	reportChapterInfo.Title = req.Title
+	reportChapterInfo.LastModifyAdminId = sysUser.AdminId
+	reportChapterInfo.LastModifyAdminName = sysUser.RealName
+	reportChapterInfo.ModifyTime = time.Now()
+
+	updateCols := make([]string, 0)
+	updateCols = append(updateCols, "Title", "LastModifyAdminId", "LastModifyAdminName", "ModifyTime")
+
+	// 更新报告的最近编辑人信息
+	if err = reportInfo.UpdateReport([]string{"LastModifyAdminId", "LastModifyAdminName", "ModifyTime"}); err != nil {
+		br.Msg = "保存失败"
+		br.ErrMsg = "报告章节内容保存失败, Err: " + err.Error()
+		return
+	}
+	// 更新章节
+	if err = reportChapterInfo.UpdateChapter(updateCols); 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
+		}
+	}
+
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "保存成功"
+}

+ 5 - 0
controllers/report_v2.go

@@ -1494,6 +1494,11 @@ func (this *ReportController) SubmitApprove() {
 		return
 	}
 
+	// 报告权限处理
+	{
+		go services.HandleReportPermission(reportItem)
+	}
+
 	br.Ret = 200
 	br.Success = true
 	br.Msg = "操作成功"

+ 8 - 1
models/report.go

@@ -426,7 +426,7 @@ func GetReportStage(classifyIdFirst, classifyIdSecond, classifyIdThird int) (cou
 	} else if classifyIdSecond > 0 {
 		sql += " AND classify_id_second = ? "
 	} else {
-		sql = " AND classify_id_first = ? "
+		sql += " AND classify_id_first = ? "
 	}
 	o.Raw(sql, yearStart, classifyId).QueryRow(&count)
 
@@ -622,6 +622,13 @@ type SendTemplateMsgReq struct {
 	ReportId int `description:"报告id"`
 }
 
+// SendTemplateMsgResp
+// @Description: 报告推送返回结构体
+type SendTemplateMsgResp struct {
+	ReportId    int    `description:"报告id"`
+	MsgSendTime string `description:"报告推送时间"`
+}
+
 func ModifyReportMsgIsSend(reportId int) (err error) {
 	o := orm.NewOrmUsingDB("rddp")
 	report, err := GetReportById(reportId)

+ 1 - 0
models/report_approve/report_approve_flow.go

@@ -364,6 +364,7 @@ func FormatFlowAndNodesItem2Detail(flowItem *ReportApproveFlow, nodeItems []*Rep
 	detail.ReportType = flowItem.ReportType
 	detail.ClassifyFirstId = flowItem.ClassifyFirstId
 	detail.ClassifySecondId = flowItem.ClassifySecondId
+	detail.ClassifyThirdId = flowItem.ClassifyThirdId
 	detail.CreateTime = utils.TimeTransferString(utils.FormatDateTime, flowItem.CreateTime)
 	detail.ModifyTime = utils.TimeTransferString(utils.FormatDateTime, flowItem.ModifyTime)
 	detail.Nodes = make([]*ReportApproveNodeItem, 0)

+ 1 - 1
models/report_v2.go

@@ -369,7 +369,7 @@ func GetReportListCountByAuthorized(condition string, pars []interface{}) (count
 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,author,report_layout,collaborate_type,is_public_publish FROM report as a WHERE 1=1  `
+	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,author,report_layout,collaborate_type,is_public_publish,abstract FROM report as a WHERE 1=1  `
 	if condition != "" {
 		sql += condition
 	}

+ 13 - 0
services/report_v2.go

@@ -1325,3 +1325,16 @@ func handleReportPermission(reportId int64, minClassifyId int) {
 
 	return
 }
+
+// HandleReportPermission
+// @Description: 报告权限处理
+// @author: Roc
+// @datetime 2024-07-12 11:17:49
+// @param reportInfo *models.Report
+func HandleReportPermission(reportInfo *models.Report) {
+	minClassifyId, _, tmpErr := getMinClassify(reportInfo)
+	if tmpErr != nil {
+		return
+	}
+	handleReportPermission(int64(reportInfo.Id), minClassifyId)
+}