Ver Fonte

fix:章节

Roc há 9 meses atrás
pai
commit
3954907daf

+ 22 - 0
controllers/report.go

@@ -618,6 +618,8 @@ func (this *ReportController) Add() {
 			//utils.SendEmail(utils.APPNAME+"失败提醒", "解析 ContentSub 失败,Err:"+err.Error(), utils.EmailSendToUsers)
 		}
 	}
+
+	// 报告期数
 	maxStage, err := models.GetReportStage(req.ClassifyIdFirst, req.ClassifyIdSecond)
 	if err != nil {
 		br.Msg = "期数获取失败!"
@@ -633,6 +635,15 @@ 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
+	}
+
 	item := new(models.Report)
 	item.AddType = req.AddType
 	item.ClassifyIdFirst = req.ClassifyIdFirst
@@ -658,6 +669,12 @@ func (this *ReportController) Add() {
 	item.NeedSplice = 0
 	item.ClassifyIdThird = req.ClassifyIdThird
 	item.ClassifyNameThird = req.ClassifyNameThird
+
+	// 产品要求,如果是多人协作,那么就是章节类型的报告
+	if req.CollaborateType == 2 {
+		item.HasChapter = 1
+		item.ChapterType = ""
+	}
 	item.CollaborateType = req.CollaborateType
 	item.ReportLayout = req.ReportLayout
 	item.IsPublicPublish = req.IsPublicPublish
@@ -674,6 +691,11 @@ func (this *ReportController) Add() {
 		go models.ModifyReportCode(newReportId, reportCode)
 	}
 
+	// 如果有章节的话,那么就自动生成章节
+	if item.HasChapter == 1 {
+
+	}
+
 	//处理权限
 	//if utils.BusinessCode == utils.BusinessCodeRelease || utils.BusinessCode == utils.BusinessCodeSandbox {
 	go func() {

+ 43 - 61
controllers/report_chapter_type.go

@@ -16,7 +16,7 @@ type ReportChapterTypeController struct {
 // List
 // @Title 报告章节列表
 // @Description 报告章节列表
-// @Param   ReportType  query  string  true  "报告类型: day-晨报; week-周报"
+// @Param   ClassifyId  query  int  true  "所属分类id"
 // @Success 200 {object} models.ReportChapterTypePageListResp
 // @router /chapter_type/list [get]
 func (this *ReportChapterTypeController) List() {
@@ -33,22 +33,27 @@ func (this *ReportChapterTypeController) List() {
 		br.Ret = 408
 		return
 	}
-	reportType := this.GetString("ReportType")
-	typeArr := []string{utils.REPORT_TYPE_DAY, utils.REPORT_TYPE_WEEK}
-	if !utils.InArrayByStr(typeArr, reportType) {
-		br.Msg = "请选择报告类型"
+	classifyId, _ := this.GetInt("ClassifyId", 0)
+	if classifyId <= 0 {
+		br.Msg = "请选择分类"
 		return
 	}
-	cond := ` AND research_type = ?`
+
+	cond := ` AND report_classify_id = ?`
 	pars := make([]interface{}, 0)
-	pars = append(pars, reportType)
+	pars = append(pars, classifyId)
 	list, e := models.GetReportChapterTypePageList(cond, pars)
 	if e != nil {
 		br.Msg = "获取失败"
 		br.ErrMsg = "获取报告章节列表失败, Err: " + e.Error()
 		return
 	}
-	mappingList, e := models.GetChapterTypePermissionByResearchType(reportType)
+	chapterTypeIdList := make([]int, 0)
+	for _, v := range list {
+		chapterTypeIdList = append(chapterTypeIdList, v.ReportChapterTypeId)
+	}
+
+	mappingList, e := models.GetChapterTypePermissionByChapterTypeIdList(chapterTypeIdList)
 	if e != nil {
 		br.Msg = "获取失败"
 		br.ErrMsg = "获取章节类型权限列表失败, Err: " + e.Error()
@@ -116,15 +121,16 @@ func (this *ReportChapterTypeController) Add() {
 		br.Msg = "请输入章节名称"
 		return
 	}
-	typeArr := []string{utils.REPORT_TYPE_DAY, utils.REPORT_TYPE_WEEK}
-	if !utils.InArrayByStr(typeArr, req.ResearchType) {
-		br.Msg = "请选择报告类型"
+
+	if req.ClassifyId <= 0 {
+		br.Msg = "请选择分类"
 		return
 	}
+
 	// 重名校验
-	cond := ` AND report_chapter_type_name = ? AND research_type = ?`
+	cond := ` AND report_chapter_type_name = ? AND report_classify_id = ?`
 	pars := make([]interface{}, 0)
-	pars = append(pars, req.ReportChapterTypeName, req.ResearchType)
+	pars = append(pars, req.ReportChapterTypeName, req.ClassifyId)
 	exists, e := models.GetReportChapterTypeByCondition(cond, pars)
 	if e != nil && e.Error() != utils.ErrNoRow() {
 		br.Msg = "操作失败"
@@ -149,7 +155,8 @@ func (this *ReportChapterTypeController) Add() {
 	item.Enabled = 1
 	item.CreatedTime = nowTime
 	item.LastUpdatedTime = nowTime
-	item.ResearchType = req.ResearchType
+	//item.ResearchType = req.ResearchType
+	item.ReportClassifyId = req.ClassifyId
 	item.IsSet = 0
 	item.ReportChapterTypeKey = req.ReportChapterTypeName
 	item.TickerTitle = req.ReportChapterTypeName
@@ -174,29 +181,20 @@ func (this *ReportChapterTypeController) Add() {
 		permissionIdName[permissionList[i].ChartPermissionId] = permissionList[i].PermissionName
 	}
 
-	researchType := item.ResearchType
-	newPermissions := make([]*models.ReportChapterTypePermission, 0)       // 报告章节权限表(新)
-	newWeekPermissions := make([]*models.ChartPermissionChapterMapping, 0) // 报告章节权限表(老)
+	newPermissions := make([]*models.ReportChapterTypePermission, 0) // 报告章节权限表(新)
 	for i := range req.ChartPermissionIdList {
 		newPermissions = append(newPermissions, &models.ReportChapterTypePermission{
 			ReportChapterTypeId:   item.ReportChapterTypeId,
 			ReportChapterTypeName: item.ReportChapterTypeName,
 			ChartPermissionId:     req.ChartPermissionIdList[i],
 			PermissionName:        permissionIdName[req.ChartPermissionIdList[i]],
-			ResearchType:          researchType,
-			CreatedTime:           nowTime,
+			//ResearchType:          researchType,
+			CreatedTime: nowTime,
 		})
-		if researchType == utils.REPORT_TYPE_WEEK {
-			newWeekPermissions = append(newWeekPermissions, &models.ChartPermissionChapterMapping{
-				ChartPermissionId:   req.ChartPermissionIdList[i],
-				ReportChapterTypeId: item.ReportChapterTypeId,
-				ResearchType:        researchType,
-			})
-		}
 	}
 
 	// 设置权限
-	e = models.SetReportChapterTypePermission(item.ReportChapterTypeId, researchType, newPermissions, newWeekPermissions)
+	e = models.SetReportChapterTypePermission(item.ReportChapterTypeId, newPermissions)
 	if e != nil {
 		br.Msg = "操作失败"
 		br.ErrMsg = "设置章节类型权限失败, Err: " + e.Error()
@@ -211,7 +209,7 @@ func (this *ReportChapterTypeController) Add() {
 	//todo 同步更新crm章节权限和章节类型
 	go func() {
 		var syncReq services.ChapterTypeSyncReq
-		syncReq.ResearchType = researchType
+		//syncReq.ResearchType = researchType
 		syncReq.ReportChapterTypeId = item.ReportChapterTypeId
 		_, _ = services.ReportChapterTypeSync(&syncReq)
 	}()
@@ -254,15 +252,16 @@ func (this *ReportChapterTypeController) Edit() {
 		br.Msg = "请输入章节名称"
 		return
 	}
-	typeArr := []string{utils.REPORT_TYPE_DAY, utils.REPORT_TYPE_WEEK}
-	if !utils.InArrayByStr(typeArr, req.ResearchType) {
-		br.Msg = "请选择报告类型"
+
+	if req.ClassifyId <= 0 {
+		br.Msg = "请选择分类"
 		return
 	}
+
 	// 重名校验
-	cond := ` AND report_chapter_type_name = ? AND research_type = ?`
+	cond := ` AND report_chapter_type_name = ? AND report_classify_id = ?`
 	pars := make([]interface{}, 0)
-	pars = append(pars, req.ReportChapterTypeName, req.ResearchType)
+	pars = append(pars, req.ReportChapterTypeName, req.ClassifyId)
 	exists, e := models.GetReportChapterTypeByCondition(cond, pars)
 	if e != nil && e.Error() != utils.ErrNoRow() {
 		br.Msg = "操作失败"
@@ -297,29 +296,20 @@ func (this *ReportChapterTypeController) Edit() {
 		permissionIdName[permissionList[i].ChartPermissionId] = permissionList[i].PermissionName
 	}
 
-	researchType := item.ResearchType
-	newPermissions := make([]*models.ReportChapterTypePermission, 0)       // 报告章节权限表(新)
-	newWeekPermissions := make([]*models.ChartPermissionChapterMapping, 0) // 报告章节权限表(老)
+	newPermissions := make([]*models.ReportChapterTypePermission, 0) // 报告章节权限表(新)
 	for i := range req.ChartPermissionIdList {
 		newPermissions = append(newPermissions, &models.ReportChapterTypePermission{
 			ReportChapterTypeId:   item.ReportChapterTypeId,
 			ReportChapterTypeName: item.ReportChapterTypeName,
 			ChartPermissionId:     req.ChartPermissionIdList[i],
 			PermissionName:        permissionIdName[req.ChartPermissionIdList[i]],
-			ResearchType:          researchType,
-			CreatedTime:           nowTime,
+			//ResearchType:          researchType,
+			CreatedTime: nowTime,
 		})
-		if researchType == utils.REPORT_TYPE_WEEK {
-			newWeekPermissions = append(newWeekPermissions, &models.ChartPermissionChapterMapping{
-				ChartPermissionId:   req.ChartPermissionIdList[i],
-				ReportChapterTypeId: item.ReportChapterTypeId,
-				ResearchType:        researchType,
-			})
-		}
 	}
 
 	// 设置权限
-	e = models.SetReportChapterTypePermission(item.ReportChapterTypeId, researchType, newPermissions, newWeekPermissions)
+	e = models.SetReportChapterTypePermission(item.ReportChapterTypeId, newPermissions)
 	if e != nil {
 		br.Msg = "操作失败"
 		br.ErrMsg = "设置章节类型权限失败, Err: " + e.Error()
@@ -338,9 +328,10 @@ func (this *ReportChapterTypeController) Edit() {
 		_ = utils.Rc.Delete(key)
 	}
 
+	// todo 处理crm那边的报告权限逻辑
 	go func() {
 		var syncReq services.ChapterTypeSyncReq
-		syncReq.ResearchType = researchType
+		//syncReq.ResearchType = researchType
 		syncReq.ReportChapterTypeId = item.ReportChapterTypeId
 		_, _ = services.ReportChapterTypeSync(&syncReq)
 	}()
@@ -474,30 +465,21 @@ func (this *ReportChapterTypeController) AuthSetting() {
 		permissionIdName[permissionList[i].ChartPermissionId] = permissionList[i].PermissionName
 	}
 
-	researchType := item.ResearchType
 	nowTime := time.Now().Local()
-	newPermissions := make([]*models.ReportChapterTypePermission, 0)       // 报告章节权限表(新)
-	newWeekPermissions := make([]*models.ChartPermissionChapterMapping, 0) // 报告章节权限表(老)
+	newPermissions := make([]*models.ReportChapterTypePermission, 0) // 报告章节权限表(新)
 	for i := range req.ChartPermissionIdList {
 		newPermissions = append(newPermissions, &models.ReportChapterTypePermission{
 			ReportChapterTypeId:   item.ReportChapterTypeId,
 			ReportChapterTypeName: item.ReportChapterTypeName,
 			ChartPermissionId:     req.ChartPermissionIdList[i],
 			PermissionName:        permissionIdName[req.ChartPermissionIdList[i]],
-			ResearchType:          researchType,
-			CreatedTime:           nowTime,
+			//ResearchType:          researchType,
+			CreatedTime: nowTime,
 		})
-		if researchType == utils.REPORT_TYPE_WEEK {
-			newWeekPermissions = append(newWeekPermissions, &models.ChartPermissionChapterMapping{
-				ChartPermissionId:   req.ChartPermissionIdList[i],
-				ReportChapterTypeId: item.ReportChapterTypeId,
-				ResearchType:        researchType,
-			})
-		}
 	}
 
 	// 设置权限
-	e = models.SetReportChapterTypePermission(item.ReportChapterTypeId, researchType, newPermissions, newWeekPermissions)
+	e = models.SetReportChapterTypePermission(item.ReportChapterTypeId, newPermissions)
 	if e != nil {
 		br.Msg = "操作失败"
 		br.ErrMsg = "设置章节类型权限失败, Err: " + e.Error()
@@ -546,7 +528,7 @@ func (this *ReportChapterTypeController) PermissionList() {
 		br.Msg = "章节不存在或已被删除"
 		return
 	}
-	list, e := models.GetChapterTypePermissionByTypeIdAndResearchType(typeId, item.ResearchType)
+	list, e := models.GetChapterTypePermissionByReportChapterTypeId(typeId)
 	if e != nil {
 		br.Msg = "章节不存在或已被删除"
 		br.ErrMsg = "获取章节类型权限列表失败, Err: " + e.Error()

+ 17 - 2
models/report_chapter_type.go

@@ -30,6 +30,7 @@ type ReportChapterType struct {
 	IsSet                  int       `description:"是否设置:0为设置,1已设置"`
 	YbIconUrl              string    `description:"研报小程序icon"`
 	YbBottomIcon           string    `description:"研报小程序详情底部icon"`
+	ReportClassifyId       int       `description:"所属分类id"`
 }
 
 func (r *ReportChapterType) Create() (err error) {
@@ -341,7 +342,7 @@ type ReportChapterTypeListItem struct {
 // ReportChapterTypeAddReq 新增章节类型请求体
 type ReportChapterTypeAddReq struct {
 	ReportChapterTypeName string `description:"报告章节类型名称"`
-	ResearchType          string `description:"研报类型"`
+	ClassifyId            int    `description:"所属报告分类id"`
 	ChartPermissionIdList []int  `description:"权限id数组"`
 	/*SelectedImage         string `description:"选中时的icon"`
 	UnselectedImage       string `description:"未选中时的icon"`
@@ -354,7 +355,7 @@ type ReportChapterTypeAddReq struct {
 type ReportChapterTypeEditReq struct {
 	ReportChapterTypeId   int    `description:"报告章节类型id"`
 	ReportChapterTypeName string `description:"报告章节类型名称"`
-	ResearchType          string `description:"研报类型"`
+	ClassifyId            int    `description:"所属报告分类id"`
 	ChartPermissionIdList []int  `description:"权限id数组"`
 	/*SelectedImage         string `description:"选中时的icon"`
 	UnselectedImage       string `description:"未选中时的icon"`
@@ -447,3 +448,17 @@ func (r *ReportChapterType) SetEnabled(id, enabled int) (err error) {
 	_, err = o.Raw(sql, enabled, id).Exec()
 	return
 }
+
+// GetReportChapterTypeListByClassifyId
+// @Description: 通过报告类型获取章节类型列表
+// @author: Roc
+// @datetime 2024-06-03 16:00:12
+// @param classifyId int
+// @return list []*ReportChapterType
+// @return err error
+func GetReportChapterTypeListByClassifyId(classifyId int) (list []*ReportChapterType, err error) {
+	o := orm.NewOrmUsingDB("rddp")
+	sql := ` SELECT * FROM report_chapter_type WHERE report_classify_id = ? AND enabled = 1`
+	_, err = o.Raw(sql, classifyId).QueryRows(&list)
+	return
+}

+ 47 - 22
models/report_chapter_type_permission.go

@@ -16,16 +16,22 @@ type ReportChapterTypePermission struct {
 	CreatedTime           time.Time `description:"创建时间"`
 }
 
-// GetChapterTypePermissionByTypeIdAndResearchType 根据章节类型ID及研报类型获取章节类型权限列表
-func GetChapterTypePermissionByTypeIdAndResearchType(typeId int, researchType string) (list []*ReportChapterTypePermission, err error) {
+// GetChapterTypePermissionByReportChapterTypeId
+// @Description: 根据章节类型ID获取章节类型权限列表
+// @author: Roc
+// @datetime 2024-06-03 15:42:47
+// @param typeId int
+// @return list []*ReportChapterTypePermission
+// @return err error
+func GetChapterTypePermissionByReportChapterTypeId(typeId int) (list []*ReportChapterTypePermission, err error) {
 	o := orm.NewOrmUsingDB("rddp")
-	sql := ` SELECT * FROM report_chapter_type_permission WHERE report_chapter_type_id = ? AND research_type = ? ORDER BY chart_permission_id ASC `
-	_, err = o.Raw(sql, typeId, researchType).QueryRows(&list)
+	sql := ` SELECT * FROM report_chapter_type_permission WHERE report_chapter_type_id = ?  ORDER BY chart_permission_id ASC `
+	_, err = o.Raw(sql, typeId).QueryRows(&list)
 	return
 }
 
 // SetReportChapterTypePermission 设置报告章节类型权限
-func SetReportChapterTypePermission(chapterTypeId int, researchType string, newPermissions []*ReportChapterTypePermission, newWeekPermissions []*ChartPermissionChapterMapping) (err error) {
+func SetReportChapterTypePermission(chapterTypeId int, newPermissions []*ReportChapterTypePermission) (err error) {
 	o := orm.NewOrmUsingDB("rddp")
 	to, err := o.Begin()
 	if err != nil {
@@ -40,8 +46,8 @@ func SetReportChapterTypePermission(chapterTypeId int, researchType string, newP
 	}()
 
 	// 删除原章节类型权限
-	sql := `DELETE FROM report_chapter_type_permission WHERE report_chapter_type_id = ? AND research_type = ?`
-	_, err = to.Raw(sql, chapterTypeId, researchType).Exec()
+	sql := `DELETE FROM report_chapter_type_permission WHERE report_chapter_type_id = ?`
+	_, err = to.Raw(sql, chapterTypeId).Exec()
 	if err != nil {
 		return
 	}
@@ -55,22 +61,23 @@ func SetReportChapterTypePermission(chapterTypeId int, researchType string, newP
 	}
 
 	// 周报章节调整chart_permission_chapter_mapping表
-	if researchType == utils.REPORT_TYPE_WEEK {
-		// 删除原权限
-		sql = `DELETE FROM chart_permission_chapter_mapping WHERE report_chapter_type_id = ? AND research_type = ?`
-		_, err = to.Raw(sql, chapterTypeId, researchType).Exec()
-		if err != nil {
-			return
-		}
+	//if researchType == utils.REPORT_TYPE_WEEK {
+	//	// 删除原权限
+	//	sql = `DELETE FROM chart_permission_chapter_mapping WHERE report_chapter_type_id = ? AND research_type = ?`
+	//	_, err = to.Raw(sql, chapterTypeId, researchType).Exec()
+	//	if err != nil {
+	//		return
+	//	}
+	//
+	//	// 新增权限
+	//	if len(newWeekPermissions) > 0 {
+	//		_, err = to.InsertMulti(len(newWeekPermissions), newWeekPermissions)
+	//		if err != nil {
+	//			return
+	//		}
+	//	}
+	//}
 
-		// 新增权限
-		if len(newWeekPermissions) > 0 {
-			_, err = to.InsertMulti(len(newWeekPermissions), newWeekPermissions)
-			if err != nil {
-				return
-			}
-		}
-	}
 	return
 }
 
@@ -81,3 +88,21 @@ func GetChapterTypePermissionByResearchType(researchType string) (list []*Report
 	_, err = o.Raw(sql, researchType).QueryRows(&list)
 	return
 }
+
+// GetChapterTypePermissionByChapterTypeIdList
+// @Description: 根据章节类型ID列表获取章节类型权限列表
+// @author: Roc
+// @datetime 2024-06-03 14:10:17
+// @param chapterTypeIdList []int
+// @return list []*ReportChapterTypePermission
+// @return err error
+func GetChapterTypePermissionByChapterTypeIdList(chapterTypeIdList []int) (list []*ReportChapterTypePermission, err error) {
+	num := len(chapterTypeIdList)
+	if num <= 0 {
+		return
+	}
+	o := orm.NewOrmUsingDB("rddp")
+	sql := ` SELECT * FROM report_chapter_type_permission WHERE report_chapter_type_id in (` + utils.GetOrmInReplace(num) + `) ORDER BY chart_permission_id ASC `
+	_, err = o.Raw(sql, chapterTypeIdList).QueryRows(&list)
+	return
+}

+ 116 - 140
services/report.go

@@ -11,7 +11,6 @@ import (
 	"eta/eta_api/utils"
 	"fmt"
 	"github.com/PuerkitoBio/goquery"
-	"github.com/rdlucklib/rdluck_tools/http"
 	"html"
 	"os"
 	"regexp"
@@ -45,143 +44,6 @@ func GetReportContentSub(content string) (contentSub string, err error) {
 	return
 }
 
-type ZgParam struct {
-}
-
-// 找钢网
-func ZhaoGangSend(report *models.ReportDetail) (err error) {
-	defer func() {
-		if err != nil {
-			go alarm_msg.SendAlarmMsg("发送报告至找刚网失败,Err"+err.Error(), 3)
-			//go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "发送报告至找刚网失败 ErrMsg:"+err.Error(), utils.EmailSendToUsers)
-		}
-	}()
-	reportIdStr := strconv.Itoa(report.Id)
-	articleId := utils.MD5(reportIdStr)
-
-	var reportType int
-	if report.ClassifyNameSecond == "知白守黑日评" {
-		reportType = 1
-	} else {
-		reportType = 2
-	}
-	contentHtml := html.UnescapeString(report.Content)
-
-	doc, err := goquery.NewDocumentFromReader(strings.NewReader(contentHtml))
-	if err != nil {
-		fmt.Println("Create Doc Err:" + err.Error())
-		err = errors.New("Create Doc Err:" + err.Error())
-		return
-	}
-	doc.Find("p").Each(func(i int, p *goquery.Selection) {
-		phtml, err := p.Html()
-		if err != nil {
-			fmt.Println("Err:" + err.Error())
-			return
-		}
-		if phtml == "<br/>" {
-			if i == 0 {
-				p.Remove()
-			} else {
-				p.ReplaceWithHtml("<br/>")
-			}
-		} else {
-			p.SetAttr("style", "line-height:30px")
-		}
-	})
-	doc.Find("img").Each(func(i int, img *goquery.Selection) {
-		img.SetAttr("style", "width:100%;")
-	})
-	contentHtml, _ = doc.Find("body").Html()
-
-	createDate, _ := time.Parse(utils.FormatDateTime, report.CreateTime)
-	createDay := createDate.Format("0102")
-	title := "【第 " + strconv.Itoa(report.Stage) + "期|FICC" + "】 " + report.Title + "(" + createDay + ")"
-	contentSummary := report.Abstract
-
-	postUrl := `http://appserver.index.zhaogang.com/double.index.appserver.service/api/v1/wechat/article/hongze/push`
-	signStr := "zhaogang_data_vip" + "articleId" + articleId + "type" + strconv.Itoa(reportType) + "title" + title + "contentSummary" + contentSummary + "zhaogang_data_vip"
-	fmt.Println("signStr:", signStr)
-	sign := utils.MD5(signStr)
-	disclaimers := `<p>1、本报告仅供弘则弥道(上海)投资咨询有限公司正式签约的机构客户使用,不会仅因接收人/接受机构收到本报告而将其视为客户。</p >         <p>2、本报告根据国际和行业通行的准则,以合法渠道获得这些信息,尽可能保证可靠、准确和完整,但并不保证报告所述信息的准确性和完整性,也不保证本报告所包含的信息或建议在本报告发出后不会发生任何变更。本报告中所提供的信息仅供参考。</p >         <p>3、报告中的内容不对投资者做出的最终操作建议做任何的担保,也没有任何形式的分享投资收益或者分担投资损失的书面或口头承诺。不作为客户在投资、法律、会计或税务等方面的最终操作建议,也不作为道义的、责任的和法律的依据或者凭证,无论是否已经明示或者暗示。</p >         <p>4、在任何情况下,本公司不对客户/接受人/接受机构因使用报告中内容所引致的一切损失负责任,客户/接受人/接受机构需自行承担全部风险。</p >`
-	param := make(map[string]interface{})
-	dataMap := make(map[string]interface{})
-	contentMap := make(map[string]interface{})
-
-	dataMap["articleId"] = articleId
-	dataMap["type"] = reportType
-	dataMap["title"] = title
-	dataMap["contentSummary"] = contentSummary
-
-	contentMap["contentHtml"] = contentHtml
-	contentMap["articleAuthor"] = report.Author
-	//contentMap["publishedTime"] = report.PublishTime.Format(utils.FormatDateTime)
-	contentMap["publishedTime"] = report.PublishTime
-	contentMap["audioName"] = report.VideoName
-	contentMap["audioUrl"] = report.VideoUrl
-
-	videoPlaySeconds := report.VideoPlaySeconds
-	f, _ := strconv.ParseFloat(videoPlaySeconds, 64)
-	contentMap["audioLength"] = f * 1000
-	contentMap["disclaimers"] = disclaimers
-
-	param["cardData"] = dataMap
-	param["contentData"] = contentMap
-	param["sign"] = strings.ToUpper(sign)
-
-	paramJson, err := json.Marshal(param)
-	if err != nil {
-		fmt.Println("param json.Marshal Err:" + err.Error())
-		err = errors.New("param json.Marshal Err:" + err.Error())
-		return
-	}
-
-	utils.FileLog.Info("ZhaoGangSend parms:%s", string(paramJson))
-	result, err := http.Post(postUrl, string(paramJson), "application/json")
-	if err != nil {
-		fmt.Println("post err:" + err.Error())
-		err = errors.New("post Err:" + err.Error())
-		return
-	}
-	utils.FileLog.Info("ZhaoGangSend Result:%s", string(result))
-	//返回数据校验
-	mapResult := make(map[string]interface{})
-	err = json.Unmarshal(result, &mapResult)
-	if err != nil {
-		fmt.Println("找钢网返回数据转json失败: err:", err.Error(), ";返回数据:", string(result))
-		err = errors.New(fmt.Sprint("找钢网返回数据转json失败: err:", err.Error(), ";返回数据:", string(result)))
-		return
-	}
-	if resultCode, ok := mapResult["code"]; ok {
-		tmpResultCode := resultCode.(float64)
-		if tmpResultCode != 200 {
-			fmt.Println("找钢网返回数据异常,code返回参异常;返回数据:", string(result))
-			err = errors.New(fmt.Sprint("找钢网返回数据异常,code返回参异常;返回数据:", string(result)))
-			return
-		}
-	} else {
-		fmt.Println("找钢网返回数据异常,缺少code返回参;返回数据:", string(result))
-		err = errors.New(fmt.Sprint("找钢网返回数据异常,缺少code返回参;返回数据:", string(result)))
-		return
-	}
-
-	utils.FileLog.Info("%s", string(result))
-	return
-}
-
-/*func init() {
-	fmt.Println("start")
-	vint := 845
-	report, err := models.GetReportById(vint)
-	if err != nil {
-		fmt.Println("GetReportById Err", err.Error())
-		return
-	}
-	ZhaoGangSend(report)
-	fmt.Println("end")
-	return
-}*/
-
 // PublishDayWeekReport 发布晨周报
 func PublishDayWeekReport(reportId int) (tips string, err error) {
 	report, err := models.GetReportByReportId(reportId)
@@ -372,7 +234,7 @@ func UpdateReportEs(reportId int, publishState int) (err error) {
 		if len(chapterList) > 0 {
 			for i := 0; i < len(chapterList); i++ {
 				// 章节对应的品种
-				permissionList, tmpErr := models.GetChapterTypePermissionByTypeIdAndResearchType(chapterList[i].TypeId, chapterList[i].ReportType)
+				permissionList, tmpErr := models.GetChapterTypePermissionByReportChapterTypeId(chapterList[i].TypeId)
 				if tmpErr != nil {
 					return
 				}
@@ -491,7 +353,7 @@ func UpdateReportChapterEs(reportChapterId int) (err error) {
 		return
 	}
 	// 章节对应的品种
-	permissionList, tmpErr := models.GetChapterTypePermissionByTypeIdAndResearchType(chapterInfo.TypeId, chapterInfo.ReportType)
+	permissionList, tmpErr := models.GetChapterTypePermissionByReportChapterTypeId(chapterInfo.TypeId)
 	if tmpErr != nil {
 		return
 	}
@@ -1285,3 +1147,117 @@ func SaveReportLogs(item *models.Report, chapters []*models.ReportChapter, admin
 	}
 	return
 }
+
+func AddReportChapter(reportInfo *models.Report, inheritReportId int) (err error, errMsg string) {
+	// 获取最小分类id
+	minClassifyId := reportInfo.ClassifyIdThird
+	if minClassifyId <= 0 {
+		minClassifyId = reportInfo.ClassifyIdSecond
+	}
+	if minClassifyId <= 0 {
+		minClassifyId = reportInfo.ClassifyIdFirst
+	}
+	if minClassifyId <= 0 {
+		errMsg = "分类异常"
+		err = errors.New(errMsg)
+		return
+	}
+
+	errMsg = "生成报告章节失败"
+	// 章节类型列表
+	typeList, err := models.GetReportChapterTypeListByClassifyId(minClassifyId)
+	if err != nil {
+		err = errors.New(errMsg)
+		return
+	}
+
+	var chapterList []*models.ReportChapter
+	// 报告继承
+	skip := false
+	if inheritReportId > 0 {
+		inheritReport, tmpErr := models.GetReportByReportId(inheritReportId)
+		if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
+			errMsg = "获取待继承的报告失败"
+			err = tmpErr
+			return
+		}
+		if inheritReport != nil {
+			// 继承上一篇章节内容
+			inheritReportChapters, tmpErr := models.GetPublishedChapterListByReportId(inheritReport.Id)
+			if tmpErr != nil {
+				errMsg = "获取待继承的报告章节失败"
+				err = tmpErr
+				return
+			}
+			chapterMap := make(map[int]*models.ReportChapter)
+			for i := 0; i < len(inheritReportChapters); i++ {
+				chapterMap[inheritReportChapters[i].TypeId] = inheritReportChapters[i]
+			}
+			for _, typeItem := range typeList {
+				v := chapterMap[typeItem.ReportChapterTypeId]
+				chapterItem := new(models.ReportChapter)
+				if v != nil {
+					chapterItem.AddType = 2
+					chapterItem.Title = v.Title
+					chapterItem.ReportType = reportType
+					chapterItem.ClassifyIdFirst = classifyId
+					chapterItem.ClassifyNameFirst = classifyName
+					chapterItem.TypeId = typeItem.ReportChapterTypeId
+					chapterItem.TypeName = typeItem.ReportChapterTypeName
+					chapterItem.Content = v.Content
+					chapterItem.ContentSub = v.ContentSub
+					chapterItem.Stage = stage
+					chapterItem.PublishState = 1
+					chapterItem.Sort = typeItem.Sort
+					chapterItem.CreateTime = req.CreateTime
+					chapterItem.ModifyTime = time.Now()
+				} else {
+					chapterItem.AddType = 1
+					chapterItem.ReportType = reportType
+					chapterItem.ClassifyIdFirst = classifyId
+					chapterItem.ClassifyNameFirst = classifyName
+					chapterItem.TypeId = typeItem.ReportChapterTypeId
+					chapterItem.TypeName = typeItem.ReportChapterTypeName
+					chapterItem.Stage = stage
+					chapterItem.PublishState = 1
+					chapterItem.Sort = typeItem.Sort
+					chapterItem.CreateTime = req.CreateTime
+					chapterItem.ModifyTime = time.Now()
+				}
+				chapterList = append(chapterList, chapterItem)
+			}
+			skip = true
+		}
+	}
+	if !skip {
+		// 空白章节
+		for _, typeItem := range typeList {
+			chapterItem := new(models.ReportChapter)
+			chapterItem.AddType = 1
+			chapterItem.ReportType = reportType
+			chapterItem.ClassifyIdFirst = classifyId
+			chapterItem.ClassifyNameFirst = classifyName
+			chapterItem.TypeId = typeItem.ReportChapterTypeId
+			chapterItem.TypeName = typeItem.ReportChapterTypeName
+			chapterItem.Stage = stage
+			chapterItem.PublishState = 1
+			chapterItem.Sort = typeItem.Sort
+			chapterItem.CreateTime = req.CreateTime
+			chapterItem.ModifyTime = time.Now()
+			chapterList = append(chapterList, chapterItem)
+		}
+	}
+
+	// 新增报告及章节
+	var reportId int64
+	if reportId, err = models.AddReportAndChapter(item, chapterList); err != nil {
+		br.Msg = "保存失败"
+		br.ErrMsg = "新增报告及章节失败, Err: " + err.Error()
+		return
+	}
+	reportCode := utils.MD5(strconv.Itoa(int(reportId)))
+	// 修改唯一编码
+	{
+		go models.ModifyReportCode(reportId, reportCode)
+	}
+}