فهرست منبع

fix:研报改版

Roc 9 ماه پیش
والد
کامیت
be8a653b46
6فایلهای تغییر یافته به همراه381 افزوده شده و 127 حذف شده
  1. 138 53
      controllers/report.go
  2. 1 1
      controllers/report_author.go
  3. 175 50
      models/report.go
  4. 66 0
      models/report_grant.go
  5. 0 22
      services/report.go
  6. 1 1
      services/report_approve.go

+ 138 - 53
controllers/report.go

@@ -47,12 +47,13 @@ type ReportUploadCommonController struct {
 // @Param   StartDate   query   string  true       "开始时间"
 // @Param   EndDate   query   string  true       "结束时间"
 // @Param   Frequency   query   string  true       "频度"
-// @Param   ClassifyNameFirst   query   string  true       "一级分类名称"
-// @Param   ClassifyNameSecond   query   string  true       "二级分类名称"
+// @Param   ClassifyIdFirst   query   int  true       "一级分类id"
+// @Param   ClassifyIdSecond   query   int  true       "二级分类id"
+// @Param   ClassifyIdThird   query   int  true       "三级分类id"
 // @Param   State   query   int  true       "状态"
 // @Param   KeyWord   query   string  true       "搜索关键词"
 // @Param   PublishSort   query   string  true       "desc:降序,asc 升序(预留)"
-// @Param   CompanyType   query   string  false       "产品类型,枚举值:'ficc','权益';不传默认返回全部"
+// @Param   FilterReportType   query   string  true       "筛选报告类型,1:公共研报,2:共享研报,3:我的研报"
 // @Success 200 {object} models.ReportListResp
 // @router /list [get]
 func (this *ReportController) ListReport() {
@@ -68,12 +69,13 @@ func (this *ReportController) ListReport() {
 	startDate := this.GetString("StartDate")
 	endDate := this.GetString("EndDate")
 	frequency := this.GetString("Frequency")
-	classifyNameFirst := this.GetString("ClassifyNameFirst")
-	classifyNameSecond := this.GetString("ClassifyNameSecond")
+	classifyIdFirst, _ := this.GetInt("ClassifyIdFirst", 0)
+	classifyIdSecond, _ := this.GetInt("ClassifyIdSecond", 0)
+	classifyIdThird, _ := this.GetInt("ClassifyIdThird", 0)
 	state, _ := this.GetInt("State")
 	keyWord := this.GetString("KeyWord")
-	companyType := this.GetString("CompanyType")
 	msgIsSend, _ := this.GetInt("MsgIsSend")
+	filterReportType, _ := this.GetInt("FilterReportType", 1)
 
 	var startSize int
 	if pageSize <= 0 {
@@ -97,70 +99,130 @@ func (this *ReportController) ListReport() {
 	var pars []interface{}
 
 	if keyWord != "" {
-		condition += ` AND (title LIKE ? OR admin_real_name LIKE ? ) `
+		condition += ` AND (a.title LIKE ? OR a.admin_real_name LIKE ? ) `
 		pars = utils.GetLikeKeywordPars(pars, keyWord, 2)
 	}
 	if startDate != "" {
-		condition += ` AND ` + timeType + ` >= ? `
+		condition += ` AND a.` + timeType + ` >= ? `
 		pars = append(pars, startDate)
 	}
 	if endDate != "" {
-		condition += ` AND ` + timeType + ` <= ? `
+		condition += ` AND a.` + timeType + ` <= ? `
 		pars = append(pars, endDate)
 	}
 	if frequency != "" {
-		condition += ` AND frequency = ? `
+		condition += ` AND a.frequency = ? `
 		pars = append(pars, frequency)
 	}
-	if classifyNameFirst != "" {
-		condition += ` AND classify_name_first = ? `
-		pars = append(pars, classifyNameFirst)
-	}
 
-	if classifyNameSecond != "" {
-		condition += ` AND classify_name_second = ? `
-		pars = append(pars, classifyNameSecond)
+	if classifyIdFirst > 0 {
+		condition += ` AND a.classify_id_first = ? `
+		pars = append(pars, classifyIdFirst)
+	}
+	if classifyIdSecond > 0 {
+		condition += ` AND a.classify_id_second = ? `
+		pars = append(pars, classifyIdSecond)
 	}
+	if classifyIdThird > 0 {
+		condition += ` AND a.classify_id_third = ? `
+		pars = append(pars, classifyIdSecond)
+	}
+
 	if state > 0 {
-		condition += ` AND state = ? `
+		condition += ` AND a.state = ? `
 		pars = append(pars, state)
 	}
 	// 消息是否已推送 1-未推送; 2-已推送
 	if msgIsSend == 1 {
-		condition += ` AND (msg_is_send = 0 OR ths_msg_is_send = 0) `
+		condition += ` AND (a.msg_is_send = 0 OR a.ths_msg_is_send = 0) `
 	}
 	if msgIsSend == 2 {
-		condition += ` AND msg_is_send = 1 AND ths_msg_is_send = 1 `
+		condition += ` AND a.msg_is_send = 1 AND a.ths_msg_is_send = 1 `
 	}
-	total, err := models.GetReportListCount(condition, pars, companyType)
-	if err != nil {
-		br.Msg = "获取失败"
-		br.ErrMsg = "获取失败,Err:" + err.Error()
-		return
+
+	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.grant_admin_id = ?) `
+		pars = append(pars, this.SysUser.AdminId, this.SysUser.AdminId)
 	}
-	list, err := models.GetReportList(condition, pars, companyType, startSize, pageSize)
-	if err != nil {
-		br.Msg = "获取失败"
-		br.ErrMsg = "获取失败,Err:" + err.Error()
-		return
+
+	// 共享报告需要连表查询,所以需要单独写
+	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
+		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, ",")
 
 		// 查询同步过来的报告对应的老报告PV+UV
-		pvMap := make(map[int]int, 0)
-		uvMap := make(map[int]int, 0)
 		if len(syncReportIdArr) > 0 {
 			puvList, e := models.GetPUVByResearchReportIds(syncReportIdArr)
 			if e != nil {
@@ -170,8 +232,13 @@ func (this *ReportController) ListReport() {
 			}
 			puvLen := len(puvList)
 			for i := 0; i < puvLen; i++ {
-				pvMap[puvList[i].ResearchReportId] = puvList[i].Pv
-				uvMap[puvList[i].ResearchReportId] = puvList[i].Uv
+				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
+				}
 			}
 		}
 		// 晨周报音频列表
@@ -196,8 +263,8 @@ func (this *ReportController) ListReport() {
 				}
 			}
 			list[i].ChapterVideoList = chapterList
-			list[i].Pv += pvMap[list[i].OldReportId]
-			list[i].Uv += uvMap[list[i].OldReportId]
+			list[i].Pv += pvMap[list[i].Id]
+			list[i].Uv += uvMap[list[i].Id]
 		}
 	}
 
@@ -585,6 +652,16 @@ func (this *ReportController) Add() {
 	item.ReportVersion = req.ReportVersion
 	item.AdminId = sysUser.AdminId
 	item.AdminRealName = sysUser.RealName
+	item.LastModifyAdminId = sysUser.AdminId
+	item.LastModifyAdminName = sysUser.RealName
+	item.ContentModifyTime = time.Now()
+	item.NeedSplice = 0
+	item.ClassifyIdThird = req.ClassifyIdThird
+	item.ClassifyNameThird = req.ClassifyNameThird
+	item.CollaborateType = req.CollaborateType
+	item.ReportLayout = req.ReportLayout
+	item.IsPublicPublish = req.IsPublicPublish
+	item.ReportCreateTime = time.Now()
 	newReportId, err := models.AddReport(item)
 	if err != nil {
 		br.Msg = "保存失败"
@@ -705,7 +782,7 @@ func (this *ReportController) Edit() {
 	}
 
 	var stage int
-	report, e := models.GetReportById(int(req.ReportId))
+	report, e := models.GetReportByReportId(int(req.ReportId))
 	if e != nil {
 		if e.Error() == utils.ErrNoRow() {
 			br.Msg = "报告已被删除, 请刷新页面"
@@ -741,21 +818,29 @@ func (this *ReportController) Edit() {
 	//	}()
 	//}
 
-	item := new(models.Report)
-	item.ClassifyIdFirst = req.ClassifyIdFirst
-	item.ClassifyNameFirst = req.ClassifyNameFirst
-	item.ClassifyIdSecond = req.ClassifyIdSecond
-	item.ClassifyNameSecond = req.ClassifyNameSecond
-	item.Title = req.Title
-	item.Abstract = req.Abstract
-	item.Author = req.Author
-	item.Frequency = req.Frequency
-	item.State = report.State // 编辑不变更状态
-	item.Stage = stage
-	item.Content = html.EscapeString(req.Content)
-	item.ContentSub = html.EscapeString(contentSub)
-	item.CreateTime = req.CreateTime
-	err = models.EditReport(item, req.ReportId)
+	//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
+	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", "Content", "ContentSub", "CreateTime", "IsPublicPublish"})
 	if err != nil {
 		br.Msg = "保存失败"
 		br.ErrMsg = "保存失败,Err:" + err.Error()

+ 1 - 1
controllers/report_author.go

@@ -366,7 +366,7 @@ func (this *ReportAuthorController) DeleteAuthor() {
 		condition = " AND author = ? "
 		pars = append(pars, item.ReportAuthor)
 		if item.AuthorType == 1 {
-			count, err = models.GetReportListCount(condition, pars, "")
+			count, err = models.GetReportListCount(condition, pars)
 		} else {
 			count, err = models.GetEnglishReportListCount(condition, pars, "")
 		}

+ 175 - 50
models/report.go

@@ -30,39 +30,59 @@ const (
 )
 
 type Report struct {
-	Id                 int       `orm:"column(id)" description:"报告Id"`
-	AddType            int       `description:"新增方式:1:新增报告,2:继承报告"`
-	ClassifyIdFirst    int       `description:"一级分类id"`
-	ClassifyNameFirst  string    `description:"一级分类名称"`
-	ClassifyIdSecond   int       `description:"二级分类id"`
-	ClassifyNameSecond string    `description:"二级分类名称"`
-	Title              string    `description:"标题"`
-	Abstract           string    `description:"摘要"`
-	Author             string    `description:"作者"`
-	Frequency          string    `description:"频度"`
-	CreateTime         string    `description:"创建时间"`
-	ModifyTime         time.Time `description:"修改时间"`
-	State              int       `description:"1:未发布;2:已发布;3-待提交;4-待审批;5-已驳回;6-已通过"`
-	PublishTime        time.Time `description:"发布时间"`
-	Stage              int       `description:"期数"`
-	MsgIsSend          int       `description:"消息是否已发送,0:否,1:是"`
-	ThsMsgIsSend       int       `description:"客户群消息是否已发送,0:否,1:是"`
-	Content            string    `description:"内容"`
-	VideoUrl           string    `description:"音频文件URL"`
-	VideoName          string    `description:"音频文件名称"`
-	VideoPlaySeconds   string    `description:"音频播放时长"`
-	VideoSize          string    `description:"音频文件大小,单位M"`
-	ContentSub         string    `description:"内容前两个章节"`
-	ReportCode         string    `description:"报告唯一编码"`
-	ReportVersion      int       `description:"1:旧版,2:新版"`
-	HasChapter         int       `description:"是否有章节 0-否 1-是"`
-	ChapterType        string    `description:"章节类型 day-晨报 week-周报"`
-	OldReportId        int       `description:"research_report表ID, 大于0则表示该报告为老后台同步过来的"`
-	MsgSendTime        time.Time `description:"模版消息发送时间"`
-	AdminId            int       `description:"创建者账号"`
-	AdminRealName      string    `description:"创建者姓名"`
-	ApproveTime        time.Time `description:"审批时间"`
-	ApproveId          int       `description:"审批ID"`
+	Id                  int       `orm:"column(id)" description:"报告Id"`
+	AddType             int       `description:"新增方式:1:新增报告,2:继承报告"`
+	ClassifyIdFirst     int       `description:"一级分类id"`
+	ClassifyNameFirst   string    `description:"一级分类名称"`
+	ClassifyIdSecond    int       `description:"二级分类id"`
+	ClassifyNameSecond  string    `description:"二级分类名称"`
+	Title               string    `description:"标题"`
+	Abstract            string    `description:"摘要"`
+	Author              string    `description:"作者"`
+	Frequency           string    `description:"频度"`
+	CreateTime          string    `description:"创建时间"`
+	ModifyTime          time.Time `description:"修改时间"`
+	State               int       `description:"1:未发布;2:已发布;3-待提交;4-待审批;5-已驳回;6-已通过"`
+	PublishTime         time.Time `description:"发布时间"`
+	Stage               int       `description:"期数"`
+	MsgIsSend           int       `description:"消息是否已发送,0:否,1:是"`
+	ThsMsgIsSend        int       `description:"客户群消息是否已发送,0:否,1:是"`
+	Content             string    `description:"内容"`
+	VideoUrl            string    `description:"音频文件URL"`
+	VideoName           string    `description:"音频文件名称"`
+	VideoPlaySeconds    string    `description:"音频播放时长"`
+	VideoSize           string    `description:"音频文件大小,单位M"`
+	ContentSub          string    `description:"内容前两个章节"`
+	ReportCode          string    `description:"报告唯一编码"`
+	ReportVersion       int       `description:"1:旧版,2:新版"`
+	HasChapter          int       `description:"是否有章节 0-否 1-是"`
+	ChapterType         string    `description:"章节类型 day-晨报 week-周报"`
+	OldReportId         int       `description:"research_report表ID, 大于0则表示该报告为老后台同步过来的"`
+	MsgSendTime         time.Time `description:"模版消息发送时间"`
+	AdminId             int       `description:"创建者账号"`
+	AdminRealName       string    `description:"创建者姓名"`
+	ApproveTime         time.Time `description:"审批时间"`
+	ApproveId           int       `description:"审批ID"`
+	DetailImgUrl        string    `description:"报告详情长图地址"`
+	DetailPdfUrl        string    `description:"报告详情PDF地址"`
+	ContentStruct       string    `description:"内容组件"`
+	LastModifyAdminId   int       `description:"最后更新人ID"`
+	LastModifyAdminName string    `description:"最后更新人姓名"`
+	ContentModifyTime   time.Time `description:"内容更新时间"`
+	Pv                  int       `description:"pv"`
+	Uv                  int       `description:"uv"`
+	HeadImg             string    `description:"报告头图地址"`
+	EndImg              string    `description:"报告尾图地址"`
+	CanvasColor         string    `description:"画布颜色"`
+	NeedSplice          int       `description:"是否拼接版头版位的标记,主要是为了兼容历史报告。0-不需要 1-需要"`
+	HeadResourceId      int       `description:"版头资源ID"`
+	EndResourceId       int       `description:"版尾资源ID"`
+	ClassifyIdThird     int       `description:"三级分类id"`
+	ClassifyNameThird   string    `description:"三级分类名称"`
+	CollaborateType     int8      `description:"协作方式,1:个人,2:多人协作。默认:1"`
+	ReportLayout        int8      `description:"报告布局,1:常规布局,2:智能布局。默认:1"`
+	IsPublicPublish     int8      `description:"是否公开发布,1:是,2:否"`
+	ReportCreateTime    time.Time `description:"报告时间创建时间"`
 }
 
 type ReportList struct {
@@ -106,6 +126,8 @@ type ReportList struct {
 	ApproveTime        string                    `description:"审批时间"`
 	DetailImgUrl       string                    `description:"报告详情长图地址"`
 	DetailPdfUrl       string                    `description:"报告详情PDF地址"`
+	ReportLayout       int8                      `description:"报告布局,1:常规布局,2:智能布局。默认:1"`
+	ReportCreateTime   time.Time                 `description:"报告时间创建时间"`
 }
 
 type ReportListResp struct {
@@ -113,17 +135,111 @@ type ReportListResp struct {
 	Paging *paging.PagingItem `description:"分页数据"`
 }
 
-func GetReportListCount(condition string, pars []interface{}, companyType string) (count int, err error) {
-	//产品权限
-	companyTypeSqlStr := ``
-	if companyType == "ficc" {
-		companyTypeSqlStr = " AND classify_id_first != 40 "
-	} else if companyType == "权益" {
-		companyTypeSqlStr = " AND classify_id_first = 40 "
+// GetReportListCountV1
+// @Description: 获取普通报告列表的报告数量
+// @author: Roc
+// @datetime 2024-05-30 15:14:43
+// @param condition string
+// @param pars []interface{}
+// @return count int
+// @return err error
+func GetReportListCountV1(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
+}
+
+// GetReportListV1
+// @Description: 获取普通报告列表的数据
+// @author: Roc
+// @datetime 2024-05-30 15:14:25
+// @param condition string
+// @param pars []interface{}
+// @param startSize int
+// @param pageSize int
+// @return items []*ReportList
+// @return err error
+func GetReportListV1(condition string, pars []interface{}, startSize, pageSize int) (items []*ReportList, err error) {
+	o := orm.NewOrmUsingDB("rddp")
+
+	sql := `SELECT * FROM report as a WHERE 1=1  `
+	if condition != "" {
+		sql += condition
+	}
+	// 排序:1:未发布;2:已发布;3-待提交;4-待审批;5-已驳回;6-已通过
+	sql += `ORDER BY FIELD(state,3,1,4,5,6,2), modify_time DESC LIMIT ?,?`
+	_, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
+	return
+}
+
+type ReportPvUv struct {
+	ReportId int
+	PvTotal  int
+	UvTotal  int
+}
+
+func GetReportPvUvByReportIdList(reportIdList []string) (items []ReportPvUv, err error) {
+	num := len(reportIdList)
+	if num <= 0 {
+		return
+	}
+	o := orm.NewOrmUsingDB("rddp")
+
+	sql := `SELECT report_id, COUNT(1) as pv_total,COUNT(DISTINCT user_id) as uv_total  FROM report_view_record  WHERE report_id in (` + utils.GetOrmInReplace(num) + `) GROUP BY report_id`
+	_, err = o.Raw(sql, reportIdList).QueryRows(&items)
+	return
+}
+
+// GetReportListCountByGrant
+// @Description: 获取共享报告列表的报告数量
+// @author: Roc
+// @datetime 2024-05-30 15:14:01
+// @param condition string
+// @param pars []interface{}
+// @return count int
+// @return err error
+func GetReportListCountByGrant(condition string, pars []interface{}) (count int, err error) {
+	o := orm.NewOrmUsingDB("rddp")
+	sql := `SELECT COUNT(1) AS count  FROM report as a 
+    JOIN report_grant b on a.id=b.report_id 
+ WHERE 1=1  `
+	if condition != "" {
+		sql += condition
+	}
+	err = o.Raw(sql, pars).QueryRow(&count)
+	return
+}
+
+// GetReportListByGrant
+// @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 GetReportListByGrant(condition string, pars []interface{}, startSize, pageSize int) (items []*ReportList, err error) {
+	o := orm.NewOrmUsingDB("rddp")
+
+	sql := `SELECT * 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 += `ORDER BY FIELD(state,3,1,4,5,6,2), modify_time DESC LIMIT ?,?`
+	_, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
+	return
+}
 
+func GetReportListCount(condition string, pars []interface{}) (count int, err error) {
 	oRddp := orm.NewOrmUsingDB("rddp")
-	sql := `SELECT COUNT(1) AS count  FROM report WHERE 1=1 ` + companyTypeSqlStr
+	sql := `SELECT COUNT(1) AS count  FROM report WHERE 1=1 `
 	if condition != "" {
 		sql += condition
 	}
@@ -131,20 +247,13 @@ func GetReportListCount(condition string, pars []interface{}, companyType string
 	return
 }
 
-func GetReportList(condition string, pars []interface{}, companyType string, startSize, pageSize int) (items []*ReportList, err error) {
+func GetReportList(condition string, pars []interface{}, startSize, pageSize int) (items []*ReportList, err error) {
 	o := orm.NewOrmUsingDB("rddp")
-	//产品权限
-	companyTypeSqlStr := ``
-	if companyType == "ficc" {
-		companyTypeSqlStr = " AND classify_id_first != 40 "
-	} else if companyType == "权益" {
-		companyTypeSqlStr = " AND classify_id_first = 40 "
-	}
 
 	sql := `SELECT *,
         (SELECT COUNT(1) FROM report_view_record AS rvr WHERE rvr.report_id=report.id) AS pv,
         (SELECT COUNT(DISTINCT user_id) FROM report_view_record AS rvr WHERE rvr.report_id=report.id) AS uv
-        FROM report WHERE 1=1  ` + companyTypeSqlStr
+        FROM report WHERE 1=1  `
 	if condition != "" {
 		sql += condition
 	}
@@ -285,6 +394,8 @@ type AddReq struct {
 	ClassifyNameFirst  string `description:"一级分类名称"`
 	ClassifyIdSecond   int    `description:"二级分类id"`
 	ClassifyNameSecond string `description:"二级分类名称"`
+	ClassifyIdThird    int    `description:"三级分类id"`
+	ClassifyNameThird  string `description:"三级分类名称"`
 	Title              string `description:"标题"`
 	Abstract           string `description:"摘要"`
 	Author             string `description:"作者"`
@@ -293,6 +404,9 @@ type AddReq struct {
 	Content            string `description:"内容"`
 	CreateTime         string `description:"创建时间"`
 	ReportVersion      int    `description:"1:旧版,2:新版"`
+	CollaborateType    int8   `description:"协作方式,1:个人,2:多人协作。默认:1"`
+	ReportLayout       int8   `description:"报告布局,1:常规布局,2:智能布局。默认:1"`
+	IsPublicPublish    int8   `description:"是否公开发布,1:是,2:否"`
 }
 
 type PrePublishReq struct {
@@ -319,6 +433,8 @@ type EditReq struct {
 	ClassifyNameFirst  string `description:"一级分类名称"`
 	ClassifyIdSecond   int    `description:"二级分类id"`
 	ClassifyNameSecond string `description:"二级分类名称"`
+	ClassifyIdThird    int    `description:"三级分类id"`
+	ClassifyNameThird  string `description:"三级分类名称"`
 	Title              string `description:"标题"`
 	Abstract           string `description:"摘要"`
 	Author             string `description:"作者"`
@@ -326,6 +442,9 @@ type EditReq struct {
 	State              int    `description:"状态:1:未发布,2:已发布"`
 	Content            string `description:"内容"`
 	CreateTime         string `description:"创建时间"`
+	CollaborateType    int8   `description:"协作方式,1:个人,2:多人协作。默认:1"`
+	ReportLayout       int8   `description:"报告布局,1:常规布局,2:智能布局。默认:1"`
+	IsPublicPublish    int8   `description:"是否公开发布,1:是,2:否"`
 }
 
 type EditResp struct {
@@ -357,6 +476,12 @@ func EditReport(item *Report, reportId int64) (err error) {
 	return
 }
 
+func (m *Report) Update(cols []string) (err error) {
+	o := orm.NewOrm()
+	_, err = o.Update(m, cols...)
+	return
+}
+
 type ReportDetailReq struct {
 	ReportId int `description:"报告id"`
 }

+ 66 - 0
models/report_grant.go

@@ -0,0 +1,66 @@
+package models
+
+import (
+	"time"
+
+	"github.com/beego/beego/v2/client/orm"
+)
+
+// ReportGrant Ppt授权表
+type ReportGrant struct {
+	GrantId      int64     `orm:"column(grant_id);pk;auto" description:"自增序号"`
+	ReportId     int64     `description:"report ID"`
+	DepartmentId int64     `description:"授权部门id"`
+	GrantAdminId int64     `description:"授权部门id"`
+	CreateTime   time.Time `orm:"auto_now_add;type(datetime)" description:"创建时间"`
+}
+
+// GetReportGrantInfo 获取已经有权限的report列表
+func GetReportGrantInfo(reportId int) (list []*ReportGrant, err error) {
+	o := orm.NewOrmUsingDB("rddp")
+	sql := `SELECT * FROM report_grant WHERE report_id=? `
+	_, err = o.Raw(sql, reportId).QueryRows(&list)
+	return
+}
+
+// MultiAddReportGrant 批量添加授权记录
+func MultiAddReportGrant(reportId int, list []*ReportGrant) (err error) {
+	o := orm.NewOrmUsingDB("rddp")
+	to, err := o.Begin()
+	if err != nil {
+		return
+	}
+	defer func() {
+		if err != nil {
+			_ = to.Rollback()
+		} else {
+			_ = to.Commit()
+		}
+	}()
+
+	sql := "DELETE from report_grant where report_id=?"
+	_, err = to.Raw(sql, reportId).Exec()
+	if err != nil {
+		return
+	}
+
+	// 新增授权记录
+	if len(list) > 0 {
+		_, tmpErr := to.InsertMulti(len(list), list)
+		if tmpErr != nil {
+			err = tmpErr
+			return
+		}
+	}
+
+	return
+}
+
+// DeleteReportGrant 移除授权记录
+func DeleteReportGrant(reportId int) (err error) {
+	o := orm.NewOrmUsingDB("rddp")
+	sql := "DELETE from report_grant where report_id=?"
+	_, err = o.Raw(sql, reportId).Exec()
+
+	return
+}

+ 0 - 22
services/report.go

@@ -559,28 +559,6 @@ func DeleteReportAndChapter(reportId int) (err error) {
 	return
 }
 
-// UpdatePublishedReportToEs 更新已发布的报告ES
-func UpdatePublishedReportToEs() (err error) {
-	// 获取所有已发布的报告
-	var condition string
-	var pars []interface{}
-	condition = ` AND state IN (2, 6) `
-	reportList, err := models.GetReportList(condition, pars, "ficc", 1, 5000)
-	count := 0
-	failCount := 0
-	for i := 0; i < len(reportList); i++ {
-		if err = UpdateReportEs(reportList[i].Id, 2); err != nil {
-			fmt.Printf("更新失败, report_id: %d, Err: %s\n", reportList[i].Id, err.Error())
-			failCount += 1
-		} else {
-			count += 1
-		}
-	}
-	fmt.Printf("报告总数:%d, 更新成功数: %d, 更新失败数: %d", len(reportList), count, failCount)
-
-	return
-}
-
 // 替换报告内容中的base64图片
 func replaceReportBase64ToImg(content string) (newContent string, err error) {
 	if content == "" {

+ 1 - 1
services/report_approve.go

@@ -35,7 +35,7 @@ func CheckReportApproveFlowChange(reportType, classifyFirstId, classifySecondId
 	pars = append(pars, classifyFirstId, classifySecondId, models.ReportStateWaitApprove)
 	switch reportType {
 	case report_approve.FlowReportTypeChinese:
-		ct, e := models.GetReportListCount(cond, pars, "")
+		ct, e := models.GetReportListCount(cond, pars)
 		if e != nil {
 			err = fmt.Errorf("GetReportListCount err: %s", e.Error())
 			return