瀏覽代碼

报告发布调整

hsun 5 月之前
父節點
當前提交
76225a9aff
共有 5 個文件被更改,包括 217 次插入58 次删除
  1. 31 26
      controllers/ppt_v2.go
  2. 6 4
      controllers/report_v2.go
  3. 28 23
      models/report.go
  4. 149 4
      services/report_v2.go
  5. 3 1
      services/smart_report.go

+ 31 - 26
controllers/ppt_v2.go

@@ -772,35 +772,40 @@ func (this *PptV2Controller) SaveLog() {
 	pptItem.TitleSetting = req.TitleSetting
 	pptItem.PptPage = len(pptContent)
 	err = pptItem.Update([]string{"TemplateType", "BackgroundImg", "Title", "ReportType", "PptDate", "Content", "ModifyTime", "TitleSetting", "ppt_page"})
-
-	// 将更新后的PPT, 置顶
-	pptMap, err := models.GetPptMappingByPptId(int64(req.PptId))
-	if err != nil {
-		br.Msg = `该PPT信息不存在, 保存失败`
-		br.ErrMsg = `该PPT信息不存在, 保存失败, Err` + err.Error()
-		br.IsSendEmail = false
-		return
-	}
-	pptMapList, err := models.GetPptMappingListByGroupId(pptMap.GroupId)
 	if err != nil {
-		br.ErrMsg = "PPT目录信息异常"
+		br.Msg = "自动保存失败"
+		br.ErrMsg = fmt.Sprintf("自动保存PPT失败, ID: %d, Err: %v", pptItem.PptId, err)
 		return
 	}
-	count, err := models.GetPptMappingByGroupPptCountId(pptMap.GroupPptId, this.SysUser.AdminId)
-	if err != nil {
-		br.Msg = "查询映射关系失败"
-		br.ErrMsg = "查询映射关系失败, 保存失败, Err:" + err.Error()
-		return
-	}
-	if !pptMap.IsMoved && len(pptMapList) > 1 && count > 0 {
-		// 如果没有人为移动位置, 且当前用户有权限, 默认将当前ppt置顶
-		err = ppt.MoveGroupPpt(pptMap.GroupId, pptMap.GroupPptId, pptMapList[0].GroupPptId, 0, this.SysUser.AdminId)
-		if err != nil {
-			br.Msg = err.Error()
-			br.ErrMsg = "移动失败,Err:" + err.Error()
-			return
-		}
-	}
+
+	// 将更新后的PPT, 置顶
+	//pptMap, err := models.GetPptMappingByPptId(int64(req.PptId))
+	//if err != nil {
+	//	br.Msg = `该PPT信息不存在, 保存失败`
+	//	br.ErrMsg = `该PPT信息不存在, 保存失败, Err` + err.Error()
+	//	br.IsSendEmail = false
+	//	return
+	//}
+	//pptMapList, err := models.GetPptMappingListByGroupId(pptMap.GroupId)
+	//if err != nil {
+	//	br.ErrMsg = "PPT目录信息异常"
+	//	return
+	//}
+	//count, err := models.GetPptMappingByGroupPptCountId(pptMap.GroupPptId, this.SysUser.AdminId)
+	//if err != nil {
+	//	br.Msg = "查询映射关系失败"
+	//	br.ErrMsg = "查询映射关系失败, 保存失败, Err:" + err.Error()
+	//	return
+	//}
+	//if !pptMap.IsMoved && len(pptMapList) > 1 && count > 0 {
+	//	// 如果没有人为移动位置, 且当前用户有权限, 默认将当前ppt置顶
+	//	err = ppt.MoveGroupPpt(pptMap.GroupId, pptMap.GroupPptId, pptMapList[0].GroupPptId, 0, this.SysUser.AdminId)
+	//	if err != nil {
+	//		br.Msg = err.Error()
+	//		br.ErrMsg = "移动失败,Err:" + err.Error()
+	//		return
+	//	}
+	//}
 
 	//日志记录
 	logInfo := &models.PptV2SaveLog{

+ 6 - 4
controllers/report_v2.go

@@ -427,9 +427,10 @@ func (this *ReportController) Add() {
 		req.ReportLayout = 1
 	}
 	// 是否公开发布,1:是,2:否
-	if req.IsPublicPublish == 0 {
-		req.IsPublicPublish = 1
-	}
+	req.IsPublicPublish = 2 // 本地报告固定不公开
+	//if req.IsPublicPublish == 0 {
+	//	req.IsPublicPublish = 1
+	//}
 
 	classifyItemList, err := models.GetClassifyListByIdList([]int{req.ClassifyIdFirst, req.ClassifyIdSecond, req.ClassifyIdThird})
 	classifyMap := make(map[int]string)
@@ -492,6 +493,7 @@ func (this *ReportController) Add() {
 	item.ReportLayout = req.ReportLayout
 	item.IsPublicPublish = req.IsPublicPublish
 	item.ReportCreateTime = time.Now()
+	item.ReportSource = utils.ReportSourceLocal
 
 	err, errMsg := services.AddReportAndChapter(item, req.InheritReportId, req.GrantAdminIdList)
 	if err != nil {
@@ -1233,7 +1235,7 @@ func (this *ReportController) PublishReport() {
 		}
 
 		// 报告发布
-		tmpTips, err, errMsg := services.PublishReport(vint, req.ReportUrl, this.SysUser)
+		tmpTips, err, errMsg := services.PublishReportV2(vint, this.SysUser)
 		if err != nil {
 			br.Msg = errMsg
 			br.ErrMsg = "报告发布失败,Err:" + err.Error()

+ 28 - 23
models/report.go

@@ -69,26 +69,30 @@ type Report struct {
 	DetailImgUrl       string    `gorm:"column:detail_img_url" description:"报告详情长图地址"`
 	DetailPdfUrl       string    `gorm:"column:detail_pdf_url" description:"报告详情PDF地址"`
 
-	ContentStruct       string    `gorm:"column:content_struct" description:"内容组件"`
-	LastModifyAdminId   int       `gorm:"column:last_modify_admin_id" description:"最后更新人ID"`
-	LastModifyAdminName string    `gorm:"column:last_modify_admin_name" description:"最后更新人姓名"`
-	ContentModifyTime   time.Time `gorm:"column:content_modify_time" description:"内容更新时间"`
-	Pv                  int       `gorm:"column:pv" description:"pv"`
-	Uv                  int       `gorm:"column:uv" description:"uv"`
-	HeadImg             string    `gorm:"column:head_img" description:"报告头图地址"`
-	EndImg              string    `gorm:"column:end_img" description:"报告尾图地址"`
-	CanvasColor         string    `gorm:"column:canvas_color" description:"画布颜色"`
-	NeedSplice          int       `gorm:"column:need_splice" description:"是否拼接版头版位的标记,主要是为了兼容历史报告。0-不需要 1-需要"`
-	HeadResourceId      int       `gorm:"column:head_resource_id" description:"版头资源ID"`
-	EndResourceId       int       `gorm:"column:end_resource_id" description:"版尾资源ID"`
-	ClassifyIdThird     int       `gorm:"column:classify_id_third" description:"三级分类id"`
-	ClassifyNameThird   string    `gorm:"column:classify_name_third" description:"三级分类名称"`
-	CollaborateType     int8      `gorm:"column:collaborate_type" description:"协作方式,1:个人,2:多人协作。默认:1"`
-	ReportLayout        int8      `gorm:"column:report_layout" description:"报告布局,1:常规布局,2:智能布局。默认:1"`
-	IsPublicPublish     int8      `gorm:"column:is_public_publish" description:"是否公开发布,1:是,2:否"`
-	ReportCreateTime    time.Time `gorm:"column:report_create_time" description:"报告时间创建时间"`
-	InheritReportId     int       `gorm:"column:inherit_report_id" description:"待继承的报告ID"`
-	VoiceGenerateType   int       `gorm:"column:voice_generate_type" description:"音频生成方式,0:系统生成,1:人工上传"`
+	ContentStruct       string     `gorm:"column:content_struct" description:"内容组件"`
+	LastModifyAdminId   int        `gorm:"column:last_modify_admin_id" description:"最后更新人ID"`
+	LastModifyAdminName string     `gorm:"column:last_modify_admin_name" description:"最后更新人姓名"`
+	ContentModifyTime   time.Time  `gorm:"column:content_modify_time" description:"内容更新时间"`
+	Pv                  int        `gorm:"column:pv" description:"pv"`
+	Uv                  int        `gorm:"column:uv" description:"uv"`
+	HeadImg             string     `gorm:"column:head_img" description:"报告头图地址"`
+	EndImg              string     `gorm:"column:end_img" description:"报告尾图地址"`
+	CanvasColor         string     `gorm:"column:canvas_color" description:"画布颜色"`
+	NeedSplice          int        `gorm:"column:need_splice" description:"是否拼接版头版位的标记,主要是为了兼容历史报告。0-不需要 1-需要"`
+	HeadResourceId      int        `gorm:"column:head_resource_id" description:"版头资源ID"`
+	EndResourceId       int        `gorm:"column:end_resource_id" description:"版尾资源ID"`
+	ClassifyIdThird     int        `gorm:"column:classify_id_third" description:"三级分类id"`
+	ClassifyNameThird   string     `gorm:"column:classify_name_third" description:"三级分类名称"`
+	CollaborateType     int8       `gorm:"column:collaborate_type" description:"协作方式,1:个人,2:多人协作。默认:1"`
+	ReportLayout        int8       `gorm:"column:report_layout" description:"报告布局,1:常规布局,2:智能布局。默认:1"`
+	IsPublicPublish     int8       `gorm:"column:is_public_publish" description:"是否公开发布,1:是,2:否"`
+	ReportCreateTime    time.Time  `gorm:"column:report_create_time" description:"报告时间创建时间"`
+	InheritReportId     int        `gorm:"column:inherit_report_id" description:"待继承的报告ID"`
+	VoiceGenerateType   int        `gorm:"column:voice_generate_type" description:"音频生成方式,0:系统生成,1:人工上传"`
+	ReportSource        int        `gorm:"column:report_source" description:"报告来源:1-系统内;2-智力共享"`
+	OutReportId         string     `gorm:"column:out_report_id" description:"外部报告ID(或编码)"`
+	PrePublishTime      *time.Time `gorm:"column:pre_publish_time" description:"预发布时间"`
+	PreMsgSend          int        `gorm:"column:pre_msg_send" description:"定时发布成功后是否立即推送模版消息,0:未发送,1:已发送"`
 }
 
 type ReportList struct {
@@ -151,6 +155,7 @@ type ReportList struct {
 	ClassifyIdThird     int               `gorm:"column:classify_id_third" description:"三级分类id"`
 	ClassifyNameThird   string            `gorm:"column:classify_name_third" description:"三级分类名称"`
 	InheritReportId     int               `gorm:"column:inherit_report_id" description:"待继承的报告ID"`
+	ReportSource        int               `gorm:"column:report_source" description:"报告来源:1-系统内;2-智力共享"`
 }
 
 type ReportListResp struct {
@@ -247,12 +252,12 @@ func GetReportListCountByGrant(condition string, pars []interface{}) (count int,
 // @return items []*ReportList
 // @return err error
 func GetReportListByGrant(condition string, pars []interface{}, startSize, pageSize int) (items []*ReportList, err error) {
-	sql := `SELECT a.id,a.add_type,a.classify_id_first,a.classify_name_first,a.classify_id_second,a.classify_name_second,a.title,a.abstract,a.author,a.frequency,a.create_time,a.modify_time,a.state,a.publish_time,a.pre_publish_time,a.stage,a.msg_is_send,a.pre_msg_send,a.video_url,a.video_name,a.video_play_seconds,a.report_code,a.video_size,a.report_version,a.ths_msg_is_send,a.has_chapter,a.chapter_type,a.old_report_id,a.msg_send_time,a.admin_id,a.admin_real_name,a.approve_time,a.approve_id,a.detail_img_url,a.detail_pdf_url,a.last_modify_admin_id,a.last_modify_admin_name,a.content_modify_time,a.pv,a.uv,a.canvas_color,a.need_splice,a.head_resource_id,a.end_resource_id,a.classify_id_third,a.classify_name_third,a.collaborate_type,a.report_layout,a.is_public_publish,a.report_create_time,a.inherit_report_id,a.voice_generate_type FROM report as a JOIN report_grant b on a.id = b.report_id  WHERE 1=1  `
+	sql := `SELECT a.id,a.add_type,a.classify_id_first,a.classify_name_first,a.classify_id_second,a.classify_name_second,a.title,a.abstract,a.author,a.frequency,a.create_time,a.modify_time,a.state,a.publish_time,a.pre_publish_time,a.stage,a.msg_is_send,a.pre_msg_send,a.video_url,a.video_name,a.video_play_seconds,a.report_code,a.video_size,a.report_version,a.ths_msg_is_send,a.has_chapter,a.chapter_type,a.old_report_id,a.msg_send_time,a.admin_id,a.admin_real_name,a.approve_time,a.approve_id,a.detail_img_url,a.detail_pdf_url,a.last_modify_admin_id,a.last_modify_admin_name,a.content_modify_time,a.pv,a.uv,a.canvas_color,a.need_splice,a.head_resource_id,a.end_resource_id,a.classify_id_third,a.classify_name_third,a.collaborate_type,a.report_layout,a.is_public_publish,a.report_create_time,a.inherit_report_id,a.voice_generate_type,a.report_source FROM report as a JOIN report_grant b on a.id = b.report_id  WHERE 1=1  `
 	if condition != "" {
 		sql += condition
 	}
 	// 排序:1:未发布;2:已发布;3-待提交;4-待审批;5-已驳回;6-已通过
-	sql += ` GROUP BY a.id,a.add_type,a.classify_id_first,a.classify_name_first,a.classify_id_second,a.classify_name_second,a.title,a.abstract,a.author,a.frequency,a.create_time,a.modify_time,a.state,a.publish_time,a.pre_publish_time,a.stage,a.msg_is_send,a.pre_msg_send,a.video_url,a.video_name,a.video_play_seconds,a.report_code,a.video_size,a.report_version,a.ths_msg_is_send,a.has_chapter,a.chapter_type,a.old_report_id,a.msg_send_time,a.admin_id,a.admin_real_name,a.approve_time,a.approve_id,a.detail_img_url,a.detail_pdf_url,a.last_modify_admin_id,a.last_modify_admin_name,a.content_modify_time,a.pv,a.uv,a.canvas_color,a.need_splice,a.head_resource_id,a.end_resource_id,a.classify_id_third,a.classify_name_third,a.collaborate_type,a.report_layout,a.is_public_publish,a.report_create_time,a.inherit_report_id,a.voice_generate_type
+	sql += ` GROUP BY a.id,a.add_type,a.classify_id_first,a.classify_name_first,a.classify_id_second,a.classify_name_second,a.title,a.abstract,a.author,a.frequency,a.create_time,a.modify_time,a.state,a.publish_time,a.pre_publish_time,a.stage,a.msg_is_send,a.pre_msg_send,a.video_url,a.video_name,a.video_play_seconds,a.report_code,a.video_size,a.report_version,a.ths_msg_is_send,a.has_chapter,a.chapter_type,a.old_report_id,a.msg_send_time,a.admin_id,a.admin_real_name,a.approve_time,a.approve_id,a.detail_img_url,a.detail_pdf_url,a.last_modify_admin_id,a.last_modify_admin_name,a.content_modify_time,a.pv,a.uv,a.canvas_color,a.need_splice,a.head_resource_id,a.end_resource_id,a.classify_id_third,a.classify_name_third,a.collaborate_type,a.report_layout,a.is_public_publish,a.report_create_time,a.inherit_report_id,a.voice_generate_type,a.report_source
 
 		ORDER BY CASE a."state"   
         WHEN 3 THEN 1  
@@ -443,7 +448,7 @@ func GetReportStage(classifyIdFirst, classifyIdSecond, classifyIdThird int) (cou
 
 type PublishReq struct {
 	ReportIds string `description:"报告id,多个用英文逗号隔开"`
-	ReportUrl string `description:"报告Url"`
+	//ReportUrl string `description:"报告Url"`
 }
 
 type PublishCancelReq struct {

+ 149 - 4
services/report_v2.go

@@ -172,9 +172,10 @@ func EditReport(reportInfo *models.Report, req models.EditReq, sysUser *system.A
 	}
 	//reportInfo.CollaborateType = req.CollaborateType
 	//reportInfo.ReportLayout = req.ReportLayout
-	if req.IsPublicPublish <= 0 {
-		req.IsPublicPublish = 1
-	}
+	//if req.IsPublicPublish <= 0 {
+	//	req.IsPublicPublish = 1
+	//}
+	req.IsPublicPublish = 2 // 本地报告固定不公开
 	reportInfo.IsPublicPublish = req.IsPublicPublish
 	reportInfo.LastModifyAdminId = sysUser.AdminId
 	reportInfo.LastModifyAdminName = sysUser.RealName
@@ -1346,7 +1347,7 @@ func handleReportPermission(reportId int64, minClassifyId int) {
 	}
 
 	// 同步crm权限
-	_ = EditReportPermissionSync(reportId, minClassifyId)
+	//_ = EditReportPermissionSync(reportId, minClassifyId)
 
 	return
 }
@@ -1457,3 +1458,147 @@ func GetReportWaterMarkPdf(reportInfo *models.Report, sysUser *system.Admin) {
 	waterMarkStr := fmt.Sprintf("%s - %s", sysUser.RealName, sysUser.Mobile)
 	GeneralWaterMarkPdf(filePath, waterMarkStr)
 }
+
+// PublishReportV2
+// @Description: 报告发布
+// @author: Roc
+// @datetime 2024-06-20 09:44:13
+// @param reportId int
+// @param reportUrl string
+// @param sysUser *system.Admin
+// @return tips string
+// @return err error
+// @return errMsg string
+func PublishReportV2(reportId int, sysUser *system.Admin) (tips string, err error, errMsg string) {
+	errMsg = `操作失败`
+
+	// 获取报告
+	reportInfo, err := models.GetReportByReportId(reportId)
+	if err != nil {
+		if utils.IsErrNoRow(err) {
+			errMsg = "报告不存在, 请刷新页面"
+			return
+		}
+		return
+	}
+	if reportInfo == nil {
+		err = fmt.Errorf("报告信息有误, ReportId: %d", reportId)
+		return
+	}
+	if reportInfo.ReportSource == utils.ReportSourceLocal && reportInfo.State != models.ReportStateUnpublished {
+		errMsg = "报告状态异常"
+		err = fmt.Errorf("报告状态异常, ReportId: %d, State: %d", reportId, reportInfo.State)
+		return
+	}
+	if reportInfo.ReportSource == utils.ReportSourceOuter && reportInfo.State != models.ReportStateWaitSubmit && reportInfo.State != models.ReportStateRefused {
+		errMsg = "报告状态异常"
+		err = fmt.Errorf("外部报告状态异常, ReportId: %d, State: %d", reportId, reportInfo.State)
+		return
+	}
+
+	// 如果有章节,那么校验章节的状态
+	chapters := make([]*models.ReportChapter, 0)
+	if reportInfo.HasChapter == 1 {
+		cps, e := models.GetChapterListByReportId(reportId)
+		if e != nil {
+			err = fmt.Errorf("获取报告章节失败, ReportId: %d, Err: %v", reportId, e)
+			return
+		}
+		chapters = cps
+		if len(chapters) <= 0 {
+			tips = "报告章节为空,不可发布"
+			errMsg = tips
+			err = errors.New(tips)
+			return
+		}
+		for _, chapter := range chapters {
+			if chapter.PublishState == 1 {
+				tips = "还存在未发布的章节"
+				errMsg = tips
+				err = errors.New(tips)
+				return
+			}
+		}
+	}
+
+	// 非章节报告
+	if reportInfo.HasChapter == 0 && reportInfo.Content == "" {
+		errMsg = `报告内容为空,不可发布`
+		err = errors.New("报告内容为空,不需要生成,report_id:" + strconv.Itoa(reportId))
+		return
+	}
+
+	// 报告变更后的状态
+	stateMap := map[int]int{
+		models.ReportStateUnpublished: models.ReportStatePublished,   // 未发布->已发布
+		models.ReportStateWaitSubmit:  models.ReportStateWaitApprove, // 待提交->待审批
+		models.ReportStateRefused:     models.ReportStateWaitApprove, // 已驳回->待审批
+	}
+	state := stateMap[reportInfo.State]
+	if state == 0 {
+		err = fmt.Errorf("报告当前状态异常, ReportId: %d, State: %d")
+		return
+	}
+	// 如果报告曾经发布过,并且已经发送过模版消息,则章节的发布时间为报告的发布时间
+	var publishTime time.Time
+	if reportInfo.MsgIsSend == 1 && reportInfo.PublishTime.IsZero() {
+		publishTime = reportInfo.PublishTime
+	} else {
+		publishTime = time.Now()
+	}
+	reportInfo.State = state
+	reportInfo.PublishTime = publishTime
+	reportInfo.PrePublishTime = nil // 重置预发布时间
+	reportInfo.PreMsgSend = 0       // 重置预发送消息状态
+	reportInfo.ModifyTime = time.Now()
+	reportInfo.LastModifyAdminId = sysUser.AdminId
+	reportInfo.LastModifyAdminName = sysUser.RealName
+	updateCols := []string{"State", "PublishTime", "PrePublishTime", "PreMsgSend", "ModifyTime", "LastModifyAdminId", "LastModifyAdminName"}
+
+	// 发布报告和章节
+	if e := models.PublishReportAndChapter(reportInfo, true, updateCols); e != nil {
+		err = errors.New("发布报告及章节失败")
+		return
+	}
+
+	// 后置处理
+	go func() {
+		// 发布时备份内容
+		SaveReportLogs(reportInfo, chapters, reportInfo.AdminId, reportInfo.AdminRealName)
+
+		// 更新ES
+		_ = UpdateReportEs(reportId, 2)
+
+		// 记录日志
+		recordItem := &models.ReportStateRecord{
+			ReportId:   reportId,
+			ReportType: 1,
+			State:      state,
+			AdminId:    sysUser.AdminId,
+			AdminName:  sysUser.AdminName,
+			CreateTime: time.Now(),
+		}
+		_, _ = models.AddReportStateRecord(recordItem)
+
+		// 报告权限
+		minClassifyId, _, e := getMinClassify(reportInfo)
+		if e != nil {
+			utils.FileLog.Info(fmt.Sprintf("报告权限处理失败, ReportId: %d, Err: %v", reportId, e))
+			return
+		}
+		handleReportPermission(int64(reportInfo.Id), minClassifyId)
+	}()
+
+	// 生成报告pdf和长图, 外部报告回调发起审批
+	go func() {
+		reportPdfUrl := GetGeneralPdfUrl(reportInfo.ReportCode, reportInfo.ClassifyNameFirst, reportInfo.ReportLayout)
+		_, _ = Report2pdfAndJpeg(reportPdfUrl, reportId, 1)
+		if reportInfo.ReportSource != utils.ReportSourceOuter {
+			return
+		}
+
+		// TODO:回调智力共享
+
+	}()
+	return
+}

+ 3 - 1
services/smart_report.go

@@ -165,7 +165,7 @@ finally:
 // @param reportUrl string
 // @param reportId int
 // @param reportType int
-func Report2pdfAndJpeg(reportUrl string, reportId, reportType int) {
+func Report2pdfAndJpeg(reportUrl string, reportId, reportType int) (imgUrl, pdfUrl string) {
 	var err error
 
 	defer func() {
@@ -230,6 +230,7 @@ func Report2pdfAndJpeg(reportUrl string, reportId, reportType int) {
 	defer func() {
 		_ = os.Remove(pdfPath)
 	}()
+	pdfUrl = resourceUrl
 
 	// 更新pdf url
 	err = models.ModifyReportPdfUrl(reportId, resourceUrl)
@@ -271,6 +272,7 @@ func Report2pdfAndJpeg(reportUrl string, reportId, reportType int) {
 	defer func() {
 		_ = os.Remove(jpegPath)
 	}()
+	imgUrl = resourceUrl
 
 	err = models.ModifyReportImgUrl(reportId, resourceUrl)
 	if err != nil {