Browse Source

Merge remote-tracking branch 'origin/yb/1.1'

Roc 3 years ago
parent
commit
51a294fa82

+ 0 - 16
controller/activity/activity.go

@@ -252,20 +252,4 @@ func calcuDrawXandY(drawText string, fontSize, canvasLength, canvasWidth int) (x
 	}
 
 	return
-}
-
-// SyncOldActivityData 同步三个月前电话会数据
-func SyncOldActivityData(c *gin.Context) {
-	authCode := c.DefaultQuery("auth_code", "0")
-	if authCode != "10086" {
-		response.Fail("无权操作", c)
-		return
-	}
-	countTotal, countSuccess, err := activity.SyncTeleconferenceOldData()
-	if err != nil {
-		response.Fail("同步失败" + err.Error(), c)
-		return
-	}
-	tips := "同步总数:" + strconv.Itoa(countTotal) + ", 同步成功数:" + strconv.Itoa(countSuccess)
-	response.OkData("同步成功", tips, c)
 }

+ 38 - 0
controller/report/research_report.go

@@ -45,3 +45,41 @@ func GetResearchReportInfo(c *gin.Context) {
 	}
 	response.OkData("获取成功", reportInfo, c)
 }
+
+// GetResearchReportChapter
+// @Tags 报告接口
+// @Summary  获取报告章节详情
+// @Description 获取报告章节详情
+// @Security ApiKeyAuth
+// @Param Authorization	header string true "Bearer 31a165baebe6dec616b1f8f3207b4273"
+// @Accept  json
+// @Product json
+// @Param research_report_type_id query int true "章节ID"
+// @Success 200 {object} yb_activity.ActivityDetail
+// @failure 400 {string} string "获取失败"
+// @Router /report/research_report_chapter [get]
+func GetResearchReportChapter(c *gin.Context) {
+	userInfo := user.GetInfoByClaims(c)
+
+	researchReportTypeIdStr := c.DefaultQuery("research_report_type_id", "")
+	if researchReportTypeIdStr == "" {
+		response.Fail("请传入报告章节id", c)
+		return
+	}
+	researchReportId, tmpErr := strconv.Atoi(researchReportTypeIdStr)
+	if tmpErr != nil {
+		response.Fail("报告章节id异常", c)
+		return
+	}
+
+	reportInfo, hasPermission, err := report.GetResearchReportTypeContentInfo(uint64(researchReportId), userInfo.UserID)
+	if err != nil {
+		response.Fail("获取报告章节失败", c)
+		return
+	}
+	if !hasPermission {
+		response.Fail("无权限", c)
+		return
+	}
+	response.OkData("获取成功", reportInfo, c)
+}

+ 79 - 6
logic/report/research_report.go

@@ -3,9 +3,18 @@ package report
 import (
 	"hongze/hongze_yb/models/tables/company_report_permission"
 	"hongze/hongze_yb/models/tables/research_report"
+	"hongze/hongze_yb/models/tables/research_report_type"
 	"hongze/hongze_yb/utils"
 )
 
+type ResearchReportInfo struct {
+	ResearchReportInfo            *research_report.ResearchReport                     `json:"research_report_info"`
+	ResearchReportTypeList        []*company_report_permission.ResearchReportTypeList `json:"research_report_type_list"`
+	HasMenu                       int                                                 `json:"has_menu"`
+	ResearchReportTypeContentList []*research_report.ResearchReportTypeContent        `description:"报告详情"`
+}
+
+// GetResearchReportInfo 获取报告详情
 func GetResearchReportInfo(researchReportId, userId uint64) (result ResearchReportInfo, hasPermission bool, err error) {
 	//获取报告详情
 	reportInfo, err := research_report.GetByResearchReportId(researchReportId)
@@ -61,7 +70,7 @@ func GetResearchReportInfo(researchReportId, userId uint64) (result ResearchRepo
 	} else if len(researchReportTypeList) == 1 {
 		//只有一个章节,即没有目录的时候,需要直接返回章节详情
 		result.HasMenu = 0
-		researchReportTypeContent, tmpErr := research_report.GetResearchReportTypeContent(researchReportTypeList[0].ResearchReportTypeId)
+		researchReportTypeContent, tmpErr := research_report.GetResearchReportTypeContentList(researchReportTypeList[0].ResearchReportTypeId)
 		if tmpErr != nil {
 			return
 		}
@@ -70,9 +79,73 @@ func GetResearchReportInfo(researchReportId, userId uint64) (result ResearchRepo
 	return
 }
 
-type ResearchReportInfo struct {
-	ResearchReportInfo            *research_report.ResearchReport                     `json:"research_report_info"`
-	ResearchReportTypeList        []*company_report_permission.ResearchReportTypeList `json:"research_report_type_list"`
-	HasMenu                       int                                                 `json:"has_menu"`
-	ResearchReportTypeContentList []*research_report.ResearchReportTypeContent        `description:"报告详情"`
+type ResearchReportTypeContentInfo struct {
+	ResearchReportTypeInfo        *research_report_type.ResearchReportTypeInfo `json:"research_report_type_info"`
+	Add                           int                                          `json:"add"`
+	ResearchReportTypeContentList []*research_report.ResearchReportTypeContent `description:"报告详情" json:"research_report_type_content_list"`
+}
+
+// GetResearchReportTypeContentInfo 获取报告章节详情
+func GetResearchReportTypeContentInfo(researchReportTypeId, userId uint64) (result ResearchReportTypeContentInfo, hasPermission bool, err error) {
+	//获取章节详情
+	researchReportTypeContentList, err := research_report.GetResearchReportTypeContentList(researchReportTypeId)
+	if err != nil {
+		return
+	}
+	researchReportTypeInfo, err := research_report_type.GetResearchReportTypeInfo(researchReportTypeId)
+	//获取报告详情
+	reportInfo, err := research_report.GetByResearchReportId(researchReportTypeInfo.ResearchReportID)
+	if err != nil {
+		return
+	}
+	reportType := reportInfo.Type
+
+	//这些个报告需要做权限校验
+	if utils.InArray(reportInfo.Type, []string{"week", "month", "two_week", "other"}) {
+		list, tmpErr := company_report_permission.GetReportVarietyList(userId, reportType)
+		if tmpErr != nil {
+			err = tmpErr
+			return
+		}
+
+		if reportInfo.Type == "week" {
+			//周报校验章节是否在权限内
+			for _, v := range list {
+				if researchReportTypeInfo.ReportChapterTypeId == v.ReportChapterTypeId {
+					hasPermission = true
+					break
+				}
+			}
+		} else {
+			//双周报和月报校验 类型是否在权限内
+			for _, v := range list {
+				if reportInfo.ResearchReportID == v.ReportChapterTypeId {
+					hasPermission = true
+					break
+				}
+			}
+		}
+
+		if !hasPermission {
+			//permissionName, tmpErr := company_report_permission.GetPermissionNameByReportId(reportInfo.ResearchReportID, reportType)
+			//if tmpErr != nil {
+			//	err = tmpErr
+			//	return
+			//}
+			return
+		}
+	} else {
+		hasPermission = true
+	}
+	add := 1
+	if len(researchReportTypeContentList) > 0 {
+		add = 0
+	}
+
+	result = ResearchReportTypeContentInfo{
+		ResearchReportTypeContentList: researchReportTypeContentList,
+		ResearchReportTypeInfo:        researchReportTypeInfo,
+		Add:                           add,
+	}
+	return
 }

+ 2 - 2
models/tables/research_report/custom_query.go

@@ -17,8 +17,8 @@ type ResearchReportTypeContent struct {
 	LastUpdatedTime             time.Time `json:"last_updated_time" description:"最近一次更新时间"`
 }
 
-// GetResearchReportTypeContent 获取研究报告章节详情
-func GetResearchReportTypeContent(researchReportTypeId uint64) (items []*ResearchReportTypeContent, err error) {
+// GetResearchReportTypeContentList 获取研究报告章节详情
+func GetResearchReportTypeContentList(researchReportTypeId uint64) (items []*ResearchReportTypeContent, err error) {
 	sql := `select rrt.research_report_type_title,rrtc.*,rrt.research_report_type_id
 from research_report_type rrt
 inner join research_report_type_content rrtc on rrtc.research_report_type_id = rrt.research_report_type_id

+ 26 - 0
models/tables/research_report_type/custom_query.go

@@ -0,0 +1,26 @@
+package research_report_type
+
+import (
+	"hongze/hongze_yb/global"
+)
+
+type ResearchReportTypeInfo struct {
+	ResearchReportTypeTitle string `json:"research_report_type_title" description:"研究报告标题"`
+	BannerUrl               string `json:"banner_url" description:"banner url"`
+	ReportChapterTypeName   string `json:"report_chapter_type_name" description:"章节名称"`
+	ResearchReportID        uint64 `json:"research_report_id" description:"报告id"`
+	ResearchReportTypeID    uint64 `json:"research_report_type_id" description:"研究报告id"`
+	TypeID                  int    `json:"type_id" description:"分类id"`
+	ReportChapterTypeId     uint64 `json:"report_chapter_type_id" description:"章节名称"`
+}
+
+// GetResearchReportTypeInfo 获取研究报告类型详情
+func GetResearchReportTypeInfo(researchReportTypeId uint64) (item *ResearchReportTypeInfo, err error) {
+	sql := ` select rrt.research_report_type_title,rct.banner_url,rct.report_chapter_type_name,rrt.research_report_id,rrt.research_report_type_id,rrt.type_id,rct.report_chapter_type_name,rct.report_chapter_type_id
+            from research_report_type rrt
+            left join report_chapter_type rct on rct.report_chapter_type_id = rrt.type_id
+            where rrt.research_report_type_id =? limit 1`
+
+	err = global.DEFAULT_MYSQL.Raw(sql, researchReportTypeId).Scan(&item).Error
+	return
+}

+ 1 - 0
routers/research_report.go

@@ -11,5 +11,6 @@ func InitResearchReport(r *gin.Engine) {
 	rGroup := r.Group("report").Use(middleware.Token())
 	{
 		rGroup.GET("/research_report", report.GetResearchReportInfo)
+		rGroup.GET("/research_report_chapter", report.GetResearchReportChapter)
 	}
 }

+ 0 - 211
services/activity/activity.go

@@ -1,26 +1,17 @@
 package activity
 
 import (
-	"errors"
 	"gorm.io/gorm"
-	"hongze/hongze_yb/global"
-	"hongze/hongze_yb/models/tables/chart_permission"
 	"hongze/hongze_yb/models/tables/company_product"
-	"hongze/hongze_yb/models/tables/research_report"
-	"hongze/hongze_yb/models/tables/teleconference"
-	"hongze/hongze_yb/models/tables/teleconference_video"
 	"hongze/hongze_yb/models/tables/yb_activity"
 	"hongze/hongze_yb/models/tables/yb_activity_permission"
 	"hongze/hongze_yb/models/tables/yb_activity_register"
 	"hongze/hongze_yb/models/tables/yb_activity_remind"
-	"hongze/hongze_yb/models/tables/yb_activity_type"
 	"hongze/hongze_yb/models/tables/yb_activity_voice"
-	"hongze/hongze_yb/models/tables/yb_speaker"
 	"hongze/hongze_yb/services/company"
 	"hongze/hongze_yb/services/user"
 	"hongze/hongze_yb/utils"
 	"log"
-	"strconv"
 	"strings"
 	"time"
 )
@@ -203,207 +194,5 @@ func GetUserAuthActivityIds(userInfo user.UserInfo) (acrivityIds []int, err erro
 		acrivityIds = append(acrivityIds, int(v.ActivityID))
 	}
 
-	return
-}
-
-// SyncTeleconferenceOldData 同步旧数据
-func SyncTeleconferenceOldData() (countTotal, countSuccess int, err error) {
-	// 查询所有前三个月的电话会
-	condition := "enabled = 1"
-	pars := make([]interface{}, 0)
-	nowTime := time.Now()
-	threeMonth := nowTime.AddDate(0, -3, 0).Format(utils.FormatDateTime)
-	condition += " AND created_time >= ? AND created_time <= ?"
-	pars = append(pars, threeMonth, nowTime)
-	teleconferenceList, err := teleconference.GetTeleconferenceList(condition, pars)
-	if err != nil {
-		return
-	}
-	countTotal = len(teleconferenceList)
-	
-	// 取出电话会IDs和报告Ids
-	var teleconferenceIds, reportIds, chartPermissionIds []int
-	for i := 0; i < len(teleconferenceList); i++ {
-		teleconferenceIds = append(teleconferenceIds, int(teleconferenceList[i].TeleconferenceID))
-		reportIds = append(reportIds, int(teleconferenceList[i].ReferResearchReportID))
-		chartPermissionIds = append(chartPermissionIds, teleconferenceList[i].ReportPermissionID)
-	}
-
-	// 报告名称map
-	var reportIdNameMap = make(map[int]string, 0)
-	reportList, err := research_report.GetListByResearchReportIds(reportIds)
-	if err != nil {
-		return
-	}
-	for i := 0; i < len(reportList); i++ {
-		reportIdNameMap[int(reportList[i].ResearchReportID)] = reportList[i].ResearchReportName
-	}
-
-	// 活动类型map
-	var typeNameIdMap = make(map[string]int, 0)
-	var typeFirstMap = make(map[int]int, 0)
-	var typeIdNameMap = make(map[int]string, 0)
-	activityTypeList, err := yb_activity_type.GetTypeList()
-	if err != nil {
-		return
-	}
-	for _, activityType := range activityTypeList {
-		typeNameIdMap[activityType.ActivityTypeName] = activityType.ActivityTypeID
-		typeFirstMap[activityType.ActivityTypeID] = activityType.Pid
-		typeIdNameMap[activityType.ActivityTypeID] = activityType.ActivityTypeName
-	}
-
-	// 主讲人map
-	speakerList, err := yb_speaker.GetSpeakerList()
-	if err != nil {
-		return
-	}
-	var speakerNamePicMap = make(map[string]string, 0)
-	for i := 0; i < len(speakerList); i++ {
-		speakerNamePicMap[speakerList[i].SpeakerName] = speakerList[i].SpeakerHeadPic
-	}
-
-	// 音频列表
-	voicesList, err := teleconference_video.GetListByTeleconferenceIds(teleconferenceIds)
-	if err != nil {
-		return
-	}
-
-	// 图片权限map
-	chartPermissionList, err := chart_permission.GetListByIds(chartPermissionIds)
-	if err != nil {
-		return
-	}
-	var chartPermissionIdNameMap = make(map[int]string, 0)
-	for i := 0; i < len(chartPermissionList); i++ {
-		chartPermissionIdNameMap[int(chartPermissionList[i].ChartPermissionID)] = chartPermissionList[i].PermissionName
-	}
-
-	// 开启事务
-	tx := global.DEFAULT_MYSQL.Begin()
-	defer func() {
-		if err != nil {
-			tx.Rollback()
-		} else {
-			tx.Commit()
-		}
-	}()
-
-	// 遍历数据
-	for _, item := range teleconferenceList {
-
-		// 匹配报告名称和link
-		reportId := int(item.ReferResearchReportID)
-		linkUrl := `https://details.hzinsights.com/ficcReportDetail?research_report_id=`
-		if global.CONFIG.Serve.RunMode == `debug` {
-			linkUrl = `http://advisoryadmin.brilliantstart.cn/xcx_h5/ficcReportDetail?research_report_id=`
-		}
-		reportLink := linkUrl + strconv.Itoa(reportId)
-		reportName := reportIdNameMap[reportId]
-
-		// 匹配活动类型-中文匹配ID
-		var firstActivityTypeId, activityTypeId int
-		var firstActivityTypeName, activityTypeName string
-		activityTypeId = typeNameIdMap[item.Type]
-		if activityTypeId > 0 {
-			// 类型匹配到了
-			activityTypeName = typeIdNameMap[activityTypeId]
-			firstActivityTypeId = typeFirstMap[activityTypeId]
-			firstActivityTypeName = typeIdNameMap[firstActivityTypeId]
-		}
-
-		// 匹配主讲人头像
-		speakerName := item.Speaker
-		if speakerName == "" {
-			continue
-		} else if speakerName == "全体FICC研究员" || speakerName == "弘则FICC研究员" {
-			speakerName = "FICC研究员"
-		}
-		speakerPic := "https://hzstatic.hzinsights.com/static/images/202112/20211210/wn6c3oYKTfT4NbTZgRGflRuIBZaa.png"
-		for i := 0; i < len(speakerList); i++ {
-			if strings.Contains(speakerName, speakerList[i].SpeakerName) {
-				speakerName = speakerList[i].SpeakerName	// 存在多个人的情况,则以新表数据为准
-				speakerPic = speakerNamePicMap[speakerList[i].SpeakerName]
-				break
-			}
-		}
-
-		backgroundPic := ""
-		if firstActivityTypeId == 1 {
-			// 电话会议
-			backgroundPic = `https://hongze.oss-accelerate.aliyuncs.com/static/images/202112/20211214/nNSTxmH6lxlT0PAp7xcfJJTGX9Gu.png`
-		} else {
-			// 线下沙龙
-			backgroundPic = `https://hongze.oss-accelerate.aliyuncs.com/static/images/202112/20211214/k77gDxvFvuAnYUhF6PU1FOVDHI8O.png`
-		}
-
-		// 新增活动数据
-		activityInfo := &yb_activity.YbActivity{
-			FirstActivityTypeID: firstActivityTypeId,
-			FirstActivityTypeName: firstActivityTypeName,
-			ActivityTypeID: activityTypeId,
-			ActivityTypeName: activityTypeName,
-			ActivityName: item.TeleconferenceTitle,
-			StartTime: item.StartTime,
-			EndTime: item.EndTime,
-			Speaker: speakerName,
-			SpeakerHeadPic: speakerPic,
-			SpeakerBackgroundPic: backgroundPic,
-			SingaporeTel: item.SingaporeTelephone,
-			ParticipationCode: item.Password,
-			MainlandTel: item.Telephone,
-			HongKongTel: item.HkTelephone,
-			ReportID: reportId,
-			ReportLink: reportLink,
-			ReportName: reportName,
-			Remarks: item.Remark,
-			PublishStatus: 1,
-			IsSendWxMsg: 1,
-			IsSendSalonWxMsg: 1,
-			ModifyTime: nowTime,
-			CreateTime: nowTime,
-		}
-
-		// 开启事务之后的操作要使用tx
-		activityCreate := tx.Debug().Create(activityInfo)
-		if activityCreate.Error != nil {
-			err = errors.New("新增活动失败")
-			return
-		}
-		activityId := activityInfo.ActivityID
-
-		// 5.新增活动音频-音频列表
-		for _, voice := range voicesList {
-			if int(item.TeleconferenceID) == voice.TeleconferenceID {
-				activityVoice := &yb_activity_voice.YbActivityVoice{
-					ActivityID: uint32(activityId),
-					VoiceURL: voice.VideoURL,
-					VoiceName: voice.VideoName,
-					VoicePlaySeconds: voice.VideoPlaySeconds,
-					CreateTime: nowTime,
-				}
-				activityVoiceCreate := tx.Debug().Create(activityVoice)
-				if activityVoiceCreate.Error != nil {
-					err = errors.New("新增活动音频失败")
-					return
-				}
-			}
-		}
-
-		// 6.新增活动关联权限-源数据权限仅一个
-		activityPermission := &yb_activity_permission.YbActivityPermission{
-			ActivityID: uint32(activityId),
-			PermissionID: uint32(item.ReportPermissionID),
-			PermissionName: chartPermissionIdNameMap[item.ReportPermissionID],
-			CreateTime: nowTime,
-		}
-		activityPermissionCreate := tx.Debug().Create(activityPermission)
-		if activityPermissionCreate.Error != nil {
-			err = errors.New("新增活动权限失败")
-			return
-		}
-		countSuccess += 1
-	}
-
 	return
 }