Browse Source

fix:ppt转报告

Roc 9 months ago
parent
commit
c97f11adb1
8 changed files with 153 additions and 188 deletions
  1. 1 1
      controllers/ppt_v2.go
  2. 2 14
      controllers/report_v2.go
  3. 3 3
      models/ppt_v2.go
  4. 0 73
      models/report.go
  5. 72 0
      models/report_v2.go
  6. 52 10
      services/ppt.go
  7. 23 28
      services/report.go
  8. 0 59
      services/report_push.go

+ 1 - 1
controllers/ppt_v2.go

@@ -850,7 +850,7 @@ func (this *PptV2Controller) ToReport() {
 		br.Msg = "参数有误"
 		return
 	}
-	reportId, reportCode, msg, e := services.SavePPTReport(req.PptId, req.ClassifyIdSecond, req.Title, sysUser)
+	reportId, reportCode, msg, e := services.SavePPTReport(req.PptId, req.ClassifyId, req.Title, sysUser)
 	if e != nil {
 		br.Msg = msg
 		br.ErrMsg = "PPT转报告失败, Err: " + e.Error()

+ 2 - 14
controllers/report_v2.go

@@ -128,7 +128,8 @@ func (this *ReportController) ListReport() {
 	switch filterReportType {
 	// 筛选报告类型,1:公共研报,2:共享研报,3:我的研报
 	case 1:
-		condition += ` AND a.is_public_publish = ? AND a.state in (2,6)`
+		condition += ` AND a.is_public_publish = ? `
+		//condition += `  AND a.state in (2,6) `
 		pars = append(pars, 1)
 	case 3:
 		condition += ` AND a.admin_id = ? `
@@ -370,19 +371,6 @@ func (this *ReportController) Add() {
 		return
 	}
 
-	// 协作方式,1:个人,2:多人协作。默认:1
-	if req.CollaborateType == 0 {
-		req.CollaborateType = 1
-	}
-	// 报告布局,1:常规布局,2:智能布局。默认:1
-	if req.ReportLayout == 0 {
-		req.ReportLayout = 1
-	}
-	// 是否公开发布,1:是,2:否
-	if req.IsPublicPublish == 0 {
-		req.IsPublicPublish = 1
-	}
-
 	item := new(models.Report)
 	item.AddType = req.AddType
 	item.ReportVersion = 2

+ 3 - 3
models/ppt_v2.go

@@ -222,9 +222,9 @@ type PptV2ConfigResp struct {
 }
 
 type PPT2ReportReq struct {
-	PptId            int    `description:"PPT主键"`
-	ClassifyIdSecond int    `description:"报告二级分类ID"`
-	Title            string `description:"标题"`
+	PptId      int    `description:"PPT主键"`
+	ClassifyId int    `description:"报告二级分类ID"`
+	Title      string `description:"标题"`
 }
 
 // AddPptV2Multi 批量新增ppt

+ 0 - 73
models/report.go

@@ -2,7 +2,6 @@ package models
 
 import (
 	"errors"
-	"eta/eta_api/models/report"
 	"eta/eta_api/utils"
 	"fmt"
 	"github.com/beego/beego/v2/client/orm"
@@ -759,78 +758,6 @@ func GetDayWeekReportStage(classifyIdFirst int, yearStart time.Time) (count int,
 	return
 }
 
-// AddReportAndChapter
-// @Description: 新增报告及章节
-// @author: Roc
-// @datetime 2024-06-06 17:08:34
-// @param reportItem *Report
-// @param allGrantUserList []*report.ReportGrant
-// @param addReportChapterList []AddReportChapter
-// @return reportId int64
-// @return err error
-func AddReportAndChapter(reportItem *Report, allGrantUserList []*report.ReportGrant, addReportChapterList []AddReportChapter) (reportId int64, err error) {
-	o := orm.NewOrmUsingDB("rddp")
-	to, err := o.Begin()
-	if err != nil {
-		return
-	}
-	defer func() {
-		if err != nil {
-			_ = to.Rollback()
-		} else {
-			_ = to.Commit()
-		}
-	}()
-
-	// 新增报告
-	reportId, err = to.Insert(reportItem)
-	if err != nil {
-		return
-	}
-	reportItem.Id = int(reportId)
-
-	// 新增报告授权
-	if len(allGrantUserList) > 0 {
-		for _, v := range allGrantUserList {
-			v.ReportId = reportItem.Id
-		}
-		_, err = to.InsertMulti(500, allGrantUserList)
-		if err != nil {
-			return
-		}
-	}
-
-	// 新增报告章节
-	if len(addReportChapterList) > 0 {
-		for _, addReportChapter := range addReportChapterList {
-			// 新增章节
-			chapterItem := addReportChapter.ReportChapter
-			chapterItem.ReportId = int(reportId)
-			cpId, tmpErr := to.Insert(chapterItem)
-			if tmpErr != nil {
-				err = tmpErr
-				return
-			}
-			chapterItem.ReportChapterId = int(cpId)
-
-			// 新增章节授权
-			if len(addReportChapter.GrantList) > 0 {
-				grantList := addReportChapter.GrantList
-				for _, v := range grantList {
-					v.ReportChapterId = chapterItem.ReportChapterId
-				}
-				_, err = to.InsertMulti(500, grantList)
-				if err != nil {
-					return
-				}
-			}
-
-		}
-	}
-
-	return
-}
-
 // GetReportByReportId 主键获取报告
 func GetReportByReportId(reportId int) (item *Report, err error) {
 	o := orm.NewOrmUsingDB("rddp")

+ 72 - 0
models/report_v2.go

@@ -6,6 +6,78 @@ import (
 	"github.com/beego/beego/v2/client/orm"
 )
 
+// AddReportAndChapter
+// @Description: 新增报告及章节
+// @author: Roc
+// @datetime 2024-06-06 17:08:34
+// @param reportItem *Report
+// @param allGrantUserList []*report.ReportGrant
+// @param addReportChapterList []AddReportChapter
+// @return reportId int64
+// @return err error
+func AddReportAndChapter(reportItem *Report, allGrantUserList []*report.ReportGrant, addReportChapterList []AddReportChapter) (reportId int64, err error) {
+	o := orm.NewOrmUsingDB("rddp")
+	to, err := o.Begin()
+	if err != nil {
+		return
+	}
+	defer func() {
+		if err != nil {
+			_ = to.Rollback()
+		} else {
+			_ = to.Commit()
+		}
+	}()
+
+	// 新增报告
+	reportId, err = to.Insert(reportItem)
+	if err != nil {
+		return
+	}
+	reportItem.Id = int(reportId)
+
+	// 新增报告授权
+	if len(allGrantUserList) > 0 {
+		for _, v := range allGrantUserList {
+			v.ReportId = reportItem.Id
+		}
+		_, err = to.InsertMulti(500, allGrantUserList)
+		if err != nil {
+			return
+		}
+	}
+
+	// 新增报告章节
+	if len(addReportChapterList) > 0 {
+		for _, addReportChapter := range addReportChapterList {
+			// 新增章节
+			chapterItem := addReportChapter.ReportChapter
+			chapterItem.ReportId = int(reportId)
+			cpId, tmpErr := to.Insert(chapterItem)
+			if tmpErr != nil {
+				err = tmpErr
+				return
+			}
+			chapterItem.ReportChapterId = int(cpId)
+
+			// 新增章节授权
+			if len(addReportChapter.GrantList) > 0 {
+				grantList := addReportChapter.GrantList
+				for _, v := range grantList {
+					v.ReportChapterId = chapterItem.ReportChapterId
+				}
+				_, err = to.InsertMulti(500, grantList)
+				if err != nil {
+					return
+				}
+			}
+
+		}
+	}
+
+	return
+}
+
 // EditReportAndPermission
 // @Description: 修改报告的基础信息、授权用户权限
 // @author: Roc

+ 52 - 10
services/ppt.go

@@ -41,7 +41,7 @@ type PPTContentElements struct {
 }
 
 // SavePPTReport 保存PPT报告
-func SavePPTReport(pptId, classifyIdSecond int, title string, adminInfo *system.Admin) (reportId int, reportCode, errMsg string, err error) {
+func SavePPTReport(pptId, classifyId int, title string, adminInfo *system.Admin) (reportId int, reportCode, errMsg string, err error) {
 	defer func() {
 		if err != nil {
 			utils.FileLog.Info("%s", err.Error())
@@ -68,7 +68,7 @@ func SavePPTReport(pptId, classifyIdSecond int, title string, adminInfo *system.
 	}
 
 	// 2023-02-21 PPT可多次转为报告, 不做关联
-	if classifyIdSecond == 0 {
+	if classifyId == 0 {
 		errMsg = "请选择报告类型"
 		err = errors.New("请选择报告类型")
 		return
@@ -90,17 +90,48 @@ func SavePPTReport(pptId, classifyIdSecond int, title string, adminInfo *system.
 		classifyMap[v.Id] = v
 	}
 	classifyIdFirst := 0
+	classifyIdSecond := 0
+	classifyIdThird := 0
 	classifyNameFirst := ""
 	classifyNameSecond := ""
-	secondClassify := classifyMap[classifyIdSecond]
-	if secondClassify != nil {
-		classifyNameSecond = secondClassify.ClassifyName
-		firstClassify := classifyMap[secondClassify.ParentId]
-		if firstClassify != nil {
-			classifyIdFirst = firstClassify.Id
-			classifyNameFirst = firstClassify.ClassifyName
-		}
+	classifyNameThird := ""
+
+	// 最小单元分类,第二级别的分类 ,最大的分类
+	var baseClassify, twoClassify, threeClassify *models.Classify
+
+	var hasTwo, hasThird bool
+	baseClassify, ok := classifyMap[classifyId]
+	if !ok {
+		errMsg = "分类异常"
+		err = errors.New("获取分类失败 ")
+		return
+	}
+	twoClassify, hasTwo = classifyMap[baseClassify.ParentId]
+	if ok {
+		threeClassify, hasThird = classifyMap[twoClassify.ParentId]
+	}
+
+	if hasThird { // 如果确实是有三级分类
+		classifyIdFirst = threeClassify.Id
+		classifyNameFirst = threeClassify.ClassifyName
+
+		classifyIdSecond = twoClassify.Id
+		classifyNameSecond = twoClassify.ClassifyName
+
+		classifyIdThird = baseClassify.Id
+		classifyNameThird = baseClassify.ClassifyName
+	} else if hasTwo {
+		classifyIdFirst = twoClassify.Id
+		classifyNameFirst = twoClassify.ClassifyName
+
+		classifyIdSecond = baseClassify.Id
+		classifyNameSecond = baseClassify.ClassifyName
+
+	} else {
+		classifyIdFirst = baseClassify.Id
+		classifyNameFirst = baseClassify.ClassifyName
 	}
+
 	// 新增报告
 	nowTime := time.Now().Local()
 	reportReq := &models.AddReq{
@@ -109,6 +140,8 @@ func SavePPTReport(pptId, classifyIdSecond int, title string, adminInfo *system.
 		ClassifyNameFirst:  classifyNameFirst,
 		ClassifyIdSecond:   classifyIdSecond,
 		ClassifyNameSecond: classifyNameSecond,
+		ClassifyIdThird:    classifyIdThird,
+		ClassifyNameThird:  classifyNameThird,
 		Title:              title,
 		Abstract:           "",
 		Author:             "FICC团队",
@@ -117,7 +150,16 @@ func SavePPTReport(pptId, classifyIdSecond int, title string, adminInfo *system.
 		Content:            htm,
 		CreateTime:         nowTime.Format(utils.FormatDateTime),
 		ReportVersion:      2,
+		CollaborateType:    1, // 协作方式,1:个人,2:多人协作。默认:1
+		ReportLayout:       1, // 报告布局,1:常规布局,2:智能布局。默认:1
+		IsPublicPublish:    2, // 是否公开发布,1:是,2:否
+	}
+
+	// 如果PPT是公开的,则报告也公开发布
+	if item.IsShare == 1 {
+		reportReq.IsPublicPublish = 1
 	}
+
 	newReportId, newCode, _, e := CreateNewReport(*reportReq, adminInfo)
 	if e != nil {
 		errMsg = "转换失败"

+ 23 - 28
services/report.go

@@ -823,36 +823,31 @@ func CreateNewReport(req models.AddReq, adminInfo *system.Admin) (newReportId in
 	item.ReportVersion = req.ReportVersion
 	item.AdminId = adminInfo.AdminId
 	item.AdminRealName = adminInfo.RealName
-	newReportId, e = models.AddReport(item)
-	if e != nil {
-		errMsg = "保存失败"
-		err = errors.New("保存失败,Err:" + e.Error())
-		return
-	}
 
-	// 处理权限
-	//if utils.BusinessCode == utils.BusinessCodeRelease || utils.BusinessCode == utils.BusinessCodeSandbox {
-	go func() {
-		permissionItems, e := models.GetPermission(req.ClassifyIdSecond)
-		if e != nil {
-			alarm_msg.SendAlarmMsg("获取权限失败,Err:"+err.Error(), 3)
-		}
-		for _, v := range permissionItems {
-			e = models.AddChartPermissionChapterMapping(v.ChartPermissionId, newReportId)
-			if e != nil {
-				alarm_msg.SendAlarmMsg("新增权限失败,Err:"+err.Error(), 3)
-			}
-		}
-		// 同步crm权限
-		_ = EditReportPermissionSync(newReportId, req.ClassifyIdSecond)
-	}()
-	//}
+	item.ClassifyIdThird = req.ClassifyIdThird
+	item.ClassifyNameThird = req.ClassifyNameThird
+	// 产品要求,如果是多人协作,那么就是章节类型的报告
+	if req.CollaborateType == 2 {
+		item.HasChapter = 1
+		item.ChapterType = ""
+	}
+	item.LastModifyAdminId = adminInfo.AdminId
+	item.LastModifyAdminName = adminInfo.RealName
+	item.ContentModifyTime = time.Now()
+	item.NeedSplice = 0
+	item.ContentStruct = html.EscapeString(req.ContentStruct)
+	item.HeadImg = req.HeadImg
+	item.EndImg = req.EndImg
+	item.CanvasColor = req.CanvasColor
+	item.HeadResourceId = req.HeadResourceId
+	item.EndResourceId = req.EndResourceId
+	item.CollaborateType = req.CollaborateType
+	item.ReportLayout = req.ReportLayout
+	item.IsPublicPublish = req.IsPublicPublish
+	item.ReportCreateTime = time.Now()
+
+	err, errMsg = AddReportAndChapter(item, 0, req.GrantAdminIdList)
 
-	reportCode = utils.MD5(strconv.Itoa(int(newReportId)))
-	//修改唯一编码
-	{
-		go models.ModifyReportCode(newReportId, reportCode)
-	}
 	return
 }
 

+ 0 - 59
services/report_push.go

@@ -1,12 +1,9 @@
 package services
 
 import (
-	"fmt"
 	"eta/eta_api/models"
 	"eta/eta_api/services/alarm_msg"
-	"eta/eta_api/utils"
 	"strconv"
-	"time"
 )
 
 //func init() {
@@ -14,61 +11,6 @@ import (
 //	SendReportToThs(report)
 //}
 
-// SendReportToEmail 发送报告邮件
-func SendReportToEmail(report *models.ReportDetail) (err error) {
-	if utils.BusinessCode != utils.BusinessCodeRelease && utils.BusinessCode != utils.BusinessCodeSandbox && utils.BusinessCode != utils.BusinessCodeDebug {
-		// 客户不做报告邮件推送
-		return
-	}
-	fmt.Println("SendReportToEmail")
-	defer func() {
-		if err != nil {
-			//fmt.Println(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "发送消息至同花顺失败 ErrMsg:"+err.Error(), utils.EmailSendToUsers)
-			go alarm_msg.SendAlarmMsg("发送报告至邮件失败,SendReportToEmail ErrMsg:"+err.Error(), 3)
-			//go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "SendReportToEmail ErrMsg:"+err.Error(), utils.EmailSendToUsers)
-		}
-	}()
-	toUser := ``
-	jumpUrl := ``
-	if utils.RunMode == "debug" {
-		//toUser = `glji@hzinsights.com`
-		toUser = `317699326@qq.com`
-		jumpUrl = "http://rddpweb.brilliantstart.cn/reportdtl?id=1578" + strconv.Itoa(report.Id)
-	} else {
-		toUser = "lijun011112@gtjas.com"
-		jumpUrl = "https://ficc.hzinsights.com/reportdtl?id=" + strconv.Itoa(report.Id)
-	}
-
-	createDate, err := time.Parse(utils.FormatDateTime, report.CreateTime)
-	createDateFrom := createDate.Format("060102")
-	emailBody :=
-		`<!DOCTYPE html>
-<html lang="en">
-<head>
-    <meta charset="UTF-8">
-    <meta http-equiv="X-UA-Compatible" content="IE=edge">
-    <meta name="viewport" content="width=device-width, initial-scale=1.0">
-    <title>Email</title>
-</head>
-<body>
-    <div>
-        <h2 style="font-size: 16px;">弘则研报:<span>` + report.Title + "_" + createDateFrom + `</span><span></span></h2>
-        <div style="font-size: 14px;margin-left: 40px;">
-            <p>你好,</p>
-            <p>今日报告已推送。</p>
-            <p><span>报告类型:</span><span>` + report.ClassifyNameFirst + `</span></p>
-            <p><span>报告标题:</span><span>` + report.Title + `</span></p>
-            <p><span>报告链接:</span><a href="` + jumpUrl + `">弘则研究</a></p>
-        </div>
-    </div>
-</body>
-</html>`
-	fmt.Println("start SendReportToEmail")
-	result, err := utils.SendEmailByHz("弘则研报报告", emailBody, toUser)
-	fmt.Println("send result:", result, err)
-	return
-}
-
 // SendReportMiniToThs 发送报告-研报小程序到同花顺
 func SendReportMiniToThs(report *models.ReportDetail) (err error) {
 	defer func() {
@@ -78,7 +20,6 @@ func SendReportMiniToThs(report *models.ReportDetail) (err error) {
 		}
 	}()
 	if report.HasChapter == 0 {
-		go SendReportToEmail(report)
 	}
 	return
 }