浏览代码

报告视频权限

hsun 1 年之前
父节点
当前提交
08672efebc

+ 30 - 18
controller/english_report/english_report.go

@@ -18,7 +18,7 @@ import (
 	"strconv"
 )
 
-type EnglishReportController struct {}
+type EnglishReportController struct{}
 
 func (er *EnglishReportController) List(c *gin.Context) {
 	req := new(english_report.ReportListReq)
@@ -43,11 +43,11 @@ func (er *EnglishReportController) List(c *gin.Context) {
 	var tmpList []*english_report.Report
 	list := make([]*english_report.ReportListItem, 0)
 
-	if req.ClassifyIdFirst >0 {
+	if req.ClassifyIdFirst > 0 {
 		condition += " and classify_id_first = ?"
 		pars = append(pars, req.ClassifyIdFirst)
 	}
-	if req.ClassifyIdSecond >0 {
+	if req.ClassifyIdSecond > 0 {
 		condition += " and classify_id_second = ?"
 		pars = append(pars, req.ClassifyIdSecond)
 	}
@@ -146,7 +146,7 @@ func (er *EnglishReportController) Classify(c *gin.Context) {
 		}
 		if child, ok := parentMap[v.Id]; ok {
 			tmp.Child = child
-		}else{
+		} else {
 			continue
 		}
 		list = append(list, tmp)
@@ -180,7 +180,7 @@ func (er *EnglishReportController) FilterByEs(c *gin.Context) {
 	reportList := make([]*english_report.SearchEnglishReportItem, 0)
 	searchResp, total, err := elasticService.SearchESEnglishReport(req.KeyWord, from, req.PageSize)
 	if err != nil {
-		resp.FailMsg("报告搜索失败", "报告搜索失败,Err:" + err.Error(), c)
+		resp.FailMsg("报告搜索失败", "报告搜索失败,Err:"+err.Error(), c)
 		return
 	}
 	var tempList []*english_report.ElasticEnglishReportDetail
@@ -194,7 +194,7 @@ func (er *EnglishReportController) FilterByEs(c *gin.Context) {
 			reportItem := new(english_report.ElasticEnglishReportDetail)
 			tmpErr = json.Unmarshal(itemJson, &reportItem)
 			if tmpErr != nil {
-				resp.FailMsg("报告搜索失败 解析出错", "报告搜索失败,Err:" + tmpErr.Error(), c)
+				resp.FailMsg("报告搜索失败 解析出错", "报告搜索失败,Err:"+tmpErr.Error(), c)
 				return
 			}
 			if len(v.Highlight["Title"]) > 0 {
@@ -213,7 +213,7 @@ func (er *EnglishReportController) FilterByEs(c *gin.Context) {
 	videoIds := make([]uint, 0)
 	videoMap := make(map[uint]*english_video.EnglishVideo)
 	videoItem := new(english_video.EnglishVideo)
-	if len(tempList)> 0 {
+	if len(tempList) > 0 {
 		for _, reportItem := range tempList {
 			if reportItem.VideoId > 0 {
 				videoIds = append(videoIds, reportItem.VideoId)
@@ -223,14 +223,14 @@ func (er *EnglishReportController) FilterByEs(c *gin.Context) {
 	if len(videoIds) > 0 {
 		videoList, e := videoItem.GetVideosByIds(videoIds)
 		if e != nil {
-			resp.FailMsg("查询线上路演列表出错", "查询线上路演列表出错,Err:" + e.Error(), c)
+			resp.FailMsg("查询线上路演列表出错", "查询线上路演列表出错,Err:"+e.Error(), c)
 			return
 		}
 		for _, v := range videoList {
 			videoMap[v.Id] = v
 		}
 	}
-	if len(tempList)> 0 {
+	if len(tempList) > 0 {
 		for _, reportItem := range tempList {
 			temp := new(english_report.SearchEnglishReportItem)
 			temp.Title = reportItem.Title
@@ -246,7 +246,7 @@ func (er *EnglishReportController) FilterByEs(c *gin.Context) {
 				temp.ClassifyIdSecond = reportItem.ClassifyIdSecond
 				temp.ClassifyNameSecond = reportItem.ClassifyNameSecond
 				temp.Stage, _ = strconv.Atoi(reportItem.StageStr)
-			}else if reportItem.VideoId > 0 {
+			} else if reportItem.VideoId > 0 {
 				if videoTemp, ok := videoMap[reportItem.VideoId]; ok {
 					temp.ReportType = 1
 					temp.Id = videoTemp.Id
@@ -285,20 +285,31 @@ func (er *EnglishReportController) Detail(c *gin.Context) {
 	reportItem := new(english_report.Report)
 	reportItem, err = reportItem.GetEnglishReportByCode(req.ReportCode)
 	if err != nil {
-		resp.FailMsg("该报告已删除", "报告查询失败,Err:" + err.Error(), c)
+		resp.FailMsg("该报告已删除", "报告查询失败,Err:"+err.Error(), c)
 		return
 	}
+
+	// 报告权限校验
+	authOk, e := english_report_service.CheckUserReportAuthByCompanyAndClassify(int(userinfo.CompanyId), reportItem.ClassifyIdSecond)
+	if e != nil {
+		resp.FailMsg("获取失败", "报告权限校验失败, Err: "+e.Error(), c)
+		return
+	}
+	content, subContent := ``, ``
+	if authOk {
+		subContent = html.UnescapeString(reportItem.ContentSub)
+		content = html.UnescapeString(reportItem.Content)
+	}
+
+	// 记录PV
 	err = reportItem.UpdatePvByReportCode(req.ReportCode)
 	if err != nil {
-		resp.FailMsg("更新失败", "更新失败,Err:" + err.Error(), c)
+		resp.FailMsg("更新失败", "更新失败,Err:"+err.Error(), c)
 		return
 	}
-	reportItem.ContentSub = html.UnescapeString(reportItem.ContentSub)
-	reportItem.Content = html.UnescapeString(reportItem.Content)
-
-	shareEmailId := userinfo.Id
 
 	// 记录邮箱
+	shareEmailId := userinfo.Id
 	if shareEmailId > 0 {
 		go english_report_service.DealEmail(reportItem, req.ReportCode, int(shareEmailId))
 	}
@@ -313,8 +324,8 @@ func (er *EnglishReportController) Detail(c *gin.Context) {
 		Abstract:           reportItem.Abstract,
 		Author:             reportItem.Author,
 		Overview:           reportItem.Overview,
-		Content:            reportItem.Content,
-		ContentSub:         reportItem.ContentSub,
+		Content:            content,
+		ContentSub:         subContent,
 		Frequency:          reportItem.Frequency,
 		PublishTime:        utils.TimeTransferString(utils.FormatDateTime, reportItem.PublishTime),
 		Stage:              reportItem.Stage,
@@ -329,5 +340,6 @@ func (er *EnglishReportController) Detail(c *gin.Context) {
 	}
 	baseData := new(english_report.ReportDetailResp)
 	baseData.Report = reportDetail
+	baseData.AuthOk = authOk
 	resp.OkData("查询成功", baseData, c)
 }

+ 25 - 10
controller/english_report/english_video.go

@@ -8,12 +8,13 @@ import (
 	"hongze/hongze_yb_en_api/models/base"
 	"hongze/hongze_yb_en_api/models/english_report"
 	"hongze/hongze_yb_en_api/models/english_video"
+	"hongze/hongze_yb_en_api/services"
 	english_report_service "hongze/hongze_yb_en_api/services/english_report"
 	"hongze/hongze_yb_en_api/utils"
 	"strconv"
 )
 
-type EnglishVideoController struct {}
+type EnglishVideoController struct{}
 
 func (er *EnglishVideoController) List(c *gin.Context) {
 	req := new(english_report.ReportListReq)
@@ -38,11 +39,11 @@ func (er *EnglishVideoController) List(c *gin.Context) {
 	var tmpList []*english_video.EnglishVideo
 	list := make([]*english_video.VideoListItem, 0)
 
-	if req.ClassifyIdFirst >0 {
+	if req.ClassifyIdFirst > 0 {
 		condition += " and classify_id_first = ?"
 		pars = append(pars, req.ClassifyIdFirst)
 	}
-	if req.ClassifyIdSecond >0 {
+	if req.ClassifyIdSecond > 0 {
 		condition += " and classify_id_second = ?"
 		pars = append(pars, req.ClassifyIdSecond)
 	}
@@ -95,16 +96,29 @@ func (er *EnglishVideoController) Detail(c *gin.Context) {
 		resp.FailData("参数解析失败", errs.Translate(global.Trans), c)
 		return
 	}
+	userinfo := services.GetInfoByClaims(c)
 
 	videoItem := new(english_video.EnglishVideo)
 	videoItem, err = videoItem.GetEnglishVideoByCode(req.VideoCode)
 	if err != nil {
-		resp.FailMsg("该报告已删除", "报告查询失败,Err:" + err.Error(), c)
+		resp.FailMsg("该报告已删除", "报告查询失败,Err:"+err.Error(), c)
 		return
 	}
+
+	// 权限校验
+	authOk, e := english_report_service.CheckUserReportAuthByCompanyAndClassify(int(userinfo.CompanyId), videoItem.ClassifyIdSecond)
+	if e != nil {
+		resp.FailMsg("获取失败", "报告权限校验失败, Err: "+e.Error(), c)
+		return
+	}
+	videoUrl := ``
+	if authOk {
+		videoUrl = videoItem.VideoUrl
+	}
+
 	err = videoItem.UpdatePvByVideoCode(req.VideoCode)
 	if err != nil {
-		resp.FailMsg("更新失败", "更新失败,Err:" + err.Error(), c)
+		resp.FailMsg("更新失败", "更新失败,Err:"+err.Error(), c)
 		return
 	}
 
@@ -128,7 +142,7 @@ func (er *EnglishVideoController) Detail(c *gin.Context) {
 		Author:             videoItem.Author,
 		Overview:           videoItem.Overview,
 		PublishTime:        utils.TimeTransferString(utils.FormatDateTime, videoItem.PublishTime),
-		VideoUrl:           videoItem.VideoUrl,
+		VideoUrl:           videoUrl,
 		VideoCoverUrl:      videoItem.VideoCoverUrl,
 		VideoSeconds:       videoItem.VideoSeconds,
 		VideoCode:          videoItem.VideoCode,
@@ -137,6 +151,7 @@ func (er *EnglishVideoController) Detail(c *gin.Context) {
 	}
 	baseData := new(english_video.VideoDetailResp)
 	baseData.Video = videoDetail
+	baseData.AuthOk = authOk
 	resp.OkData("查询成功", baseData, c)
 }
 
@@ -164,7 +179,7 @@ func (er *EnglishVideoController) VideoPlayLog(c *gin.Context) {
 	shareEmailId, _ := strconv.Atoi(shareEmailIdStr)
 
 	item := new(english_video.PlayLog)
-	if req.Id > 0 { 
+	if req.Id > 0 {
 		//查找当前播放日志,并更新停止播放时长
 		item.Id = req.Id
 		item, err = item.GetById()
@@ -173,13 +188,13 @@ func (er *EnglishVideoController) VideoPlayLog(c *gin.Context) {
 				resp.Fail("播放日志不存在", c)
 				return
 			}
-			resp.FailMsg("查询播放日志失败", "新增播放日志失败,Err:" + err.Error(), c)
+			resp.FailMsg("查询播放日志失败", "新增播放日志失败,Err:"+err.Error(), c)
 			return
 		}
 		item.StopSeconds = req.StopSeconds
 		err = item.Update([]string{"stop_seconds"})
 		if err != nil {
-			resp.FailMsg("更新播放日志失败", "更新播放日志失败,Err:" + err.Error(), c)
+			resp.FailMsg("更新播放日志失败", "更新播放日志失败,Err:"+err.Error(), c)
 			return
 		}
 	} else {
@@ -194,7 +209,7 @@ func (er *EnglishVideoController) VideoPlayLog(c *gin.Context) {
 		}
 		err = item.Add()
 		if err != nil {
-			resp.FailMsg("新增播放日志失败", "新增播放日志失败,Err:" + err.Error(), c)
+			resp.FailMsg("新增播放日志失败", "新增播放日志失败,Err:"+err.Error(), c)
 			return
 		}
 	}

+ 22 - 0
models/en_classify_permission/en_classify_permission.go

@@ -0,0 +1,22 @@
+package en_classify_permission
+
+import (
+	"hongze/hongze_yb_en_api/global"
+	"time"
+)
+
+type EnClassifyPermission struct {
+	EnClassifyPermissionNameId int       `gorm:"primaryKey;column:en_classify_permission_id" json:"en_classify_permission_id"`
+	EnClassifyId               int       `gorm:"column:en_classify_id" json:"en_classify_id"`
+	EnPermissionId             int       `gorm:"column:en_permission_id" json:"en_permission_id"`
+	CreateTime                 time.Time `gorm:"autoCreateTime;column:create_time" json:"create_time"` //创建时间
+}
+
+func (c *EnClassifyPermission) TableName() string {
+	return "en_classify_permission"
+}
+
+func (c *EnClassifyPermission) GetList(condition string, pars []interface{}) (list []*EnClassifyPermission, err error) {
+	err = global.DEFAULT_MYSQL.Model(c).Where(condition, pars).Order("create_time DESC").Scan(&list).Error
+	return
+}

+ 22 - 0
models/en_company_permission/en_company_permission.go

@@ -0,0 +1,22 @@
+package en_company_permission
+
+import (
+	"hongze/hongze_yb_en_api/global"
+	"time"
+)
+
+type EnCompanyPermission struct {
+	EnCompanyPermissionNameId int       `gorm:"primaryKey;column:en_company_permission_id" json:"en_company_permission_id"`
+	EnCompanyId               int       `gorm:"column:en_company_id" json:"en_company_id"`
+	EnPermissionId            int       `gorm:"column:en_permission_id" json:"en_permission_id"`
+	CreateTime                time.Time `gorm:"autoCreateTime;column:create_time" json:"create_time"` //创建时间
+}
+
+func (c *EnCompanyPermission) TableName() string {
+	return "en_company_permission"
+}
+
+func (c *EnCompanyPermission) GetList(condition string, pars []interface{}) (list []*EnCompanyPermission, err error) {
+	err = global.DEFAULT_MYSQL.Model(c).Where(condition, pars).Order("create_time DESC").Scan(&list).Error
+	return
+}

+ 6 - 7
models/english_report/report.go

@@ -42,8 +42,6 @@ func (r *Report) TableName() string {
 	return "english_report"
 }
 
-
-
 type ReportListReq struct {
 	ClassifyIdFirst  int `json:"classify_id_first" form:"classify_id_first"`
 	ClassifyIdSecond int `json:"classify_id_second" form:"classify_id_second"`
@@ -51,7 +49,7 @@ type ReportListReq struct {
 }
 
 type ReportListItem struct {
-	Id                 uint    `json:"id"`
+	Id                 uint   `json:"id"`
 	AddType            int8   `json:"add_type"`             //新增方式:1:新增报告,2:继承报告
 	ClassifyIdFirst    int    `json:"classify_id_first"`    //一级分类id
 	ClassifyNameFirst  string `json:"classify_name_first"`  //一级分类名称
@@ -73,13 +71,13 @@ type ReportListItem struct {
 }
 
 type ReportSearchReq struct {
-	KeyWord  string `json:"key_word" form:"key_word"`
+	KeyWord string `json:"key_word" form:"key_word"`
 	base.PageReq
 }
 
 type ReportDetailReq struct {
 	ReportCode string `json:"report_code" form:"report_code" binding:"required"` //报告唯一编码
-	ShareEmail int `json:"share_email" form:"share_email"` //推送的邮箱ID
+	ShareEmail int    `json:"share_email" form:"share_email"`                    //推送的邮箱ID
 }
 
 type ReportDetail struct {
@@ -110,6 +108,7 @@ type ReportDetail struct {
 
 type ReportDetailResp struct {
 	Report *ReportDetail `json:"report"`
+	AuthOk bool          `json:"auth_ok"`
 }
 
 type SearchEnglishReportItem struct {
@@ -150,7 +149,7 @@ type ElasticEnglishReportDetail struct {
 	CreateTime         string
 	PublishTime        string
 	ReportCode         string
-	Overview           string 
+	Overview           string
 }
 
 func (r *Report) SelectPage(page base.IPage, condition string, pars []interface{}) (count int64, results []*Report, err error) {
@@ -187,4 +186,4 @@ func (r *Report) UpdatePvByReportCode(reportCode string) (err error) {
 	sql := `UPDATE english_report SET pv = pv+1 WHERE report_code = ?  `
 	err = global.DEFAULT_MYSQL.Exec(sql, reportCode).Error
 	return
-}
+}

+ 6 - 6
models/english_video/english_video.go

@@ -29,7 +29,6 @@ type EnglishVideo struct {
 	base.TimeBase
 }
 
-
 // TableName get sql table name.获取数据库表名
 func (r *EnglishVideo) TableName() string {
 	return "english_video"
@@ -61,7 +60,7 @@ type VideoListItem struct {
 }
 
 type VideoSearchReq struct {
-	KeyWord  string `json:"key_word" form:"key_word"`
+	KeyWord string `json:"key_word" form:"key_word"`
 	base.PageReq
 }
 
@@ -90,11 +89,12 @@ type VideoDetail struct {
 }
 
 type VideoDetailResp struct {
-	Video *VideoDetail `json:"Video"`
+	Video  *VideoDetail `json:"Video"`
+	AuthOk bool         `json:"auth_ok"`
 }
 
 type SearchEnglishVideoItem struct {
-	Id                 uint    `json:"id"`
+	Id                 uint   `json:"id"`
 	ClassifyIdFirst    int    `json:"classify_id_first"`    //一级分类id
 	ClassifyNameFirst  string `json:"classify_name_first"`  //一级分类名称
 	ClassifyIdSecond   int    `json:"classify_id_second"`   //二级分类id
@@ -102,7 +102,7 @@ type SearchEnglishVideoItem struct {
 	Title              string `json:"title"`                //标题
 	Author             string `json:"author"`               //作者
 	PublishTime        string `json:"publish_time"`         //发布时间
-	VideoCode         string `json:"video_code"`          //唯一编码
+	VideoCode          string `json:"video_code"`           //唯一编码
 	CreateTime         string `json:"create_time"`          //创建时间
 	ContentSub         string `json:"content_sub"`          //内容前两个章节"`
 }
@@ -147,4 +147,4 @@ func (r *EnglishVideo) UpdatePvByVideoCode(videoCode string) (err error) {
 func (r *EnglishVideo) GetVideosByIds(ids []uint) (list []*EnglishVideo, err error) {
 	err = global.DEFAULT_MYSQL.Model(r).Where("id IN (?)", ids).Scan(&list).Error
 	return
-}
+}

+ 51 - 1
services/english_report/report.go

@@ -1,6 +1,9 @@
 package english_report
 
 import (
+	"fmt"
+	"hongze/hongze_yb_en_api/models/en_classify_permission"
+	"hongze/hongze_yb_en_api/models/en_company_permission"
 	"hongze/hongze_yb_en_api/models/english_company"
 	"hongze/hongze_yb_en_api/models/english_report"
 	"hongze/hongze_yb_en_api/models/english_report_email"
@@ -9,7 +12,7 @@ import (
 	"time"
 )
 
-func DealEmail(reportItem *english_report.Report, reportCode string, shareEmailId int) (err error, errMsg string)  {
+func DealEmail(reportItem *english_report.Report, reportCode string, shareEmailId int) (err error, errMsg string) {
 	defer func() {
 		if err != nil {
 			alarm_msg.SendAlarmMsg(utils.APPNAME+"更新英文报告邮箱PV失败, ErrMsg: "+errMsg, 2)
@@ -53,3 +56,50 @@ func DealEmail(reportItem *english_report.Report, reportCode string, shareEmailI
 	}
 	return
 }
+
+// CheckUserReportAuthByCompanyAndClassify 校验用户报告权限
+func CheckUserReportAuthByCompanyAndClassify(companyId, classifyId int) (authOk bool, err error) {
+	if companyId <= 0 || classifyId <= 0 {
+		return
+	}
+
+	// 客户权限
+	hasPermissions := make([]*en_company_permission.EnCompanyPermission, 0)
+	{
+		cond := ` AND en_company_id = ?`
+		pars := make([]interface{}, 0)
+		pars = append(pars, companyId)
+		ob := new(en_company_permission.EnCompanyPermission)
+		list, e := ob.GetList(cond, pars)
+		if e != nil {
+			err = fmt.Errorf("company permission GetList err: %s", e.Error())
+			return
+		}
+		hasPermissions = list
+	}
+
+	// 报告权限
+	reportPermissions := make([]*en_classify_permission.EnClassifyPermission, 0)
+	{
+		cond := ` AND en_classify_id = ?`
+		pars := make([]interface{}, 0)
+		pars = append(pars, companyId)
+		ob := new(en_classify_permission.EnClassifyPermission)
+		list, e := ob.GetList(cond, pars)
+		if e != nil {
+			err = fmt.Errorf("classify permission GetList err: %s", e.Error())
+			return
+		}
+		reportPermissions = list
+	}
+
+	for _, r := range reportPermissions {
+		for _, p := range hasPermissions {
+			if r.EnPermissionId == p.EnPermissionId {
+				authOk = true
+				return
+			}
+		}
+	}
+	return
+}