فهرست منبع

fix: 同步三个月活动-完善主讲人同步规则

hsun 3 سال پیش
والد
کامیت
9d5bce84b7

+ 2 - 1
controller/activity/activity.go

@@ -260,5 +260,6 @@ func SyncOldActivityData(c *gin.Context) {
 		response.Fail("同步失败" + err.Error(), c)
 		return
 	}
-	response.OkData("同步成功", "同步总数:" + strconv.Itoa(countTotal) + ", 同步成功数:" + strconv.Itoa(countSuccess), c)
+	tips := "同步总数:" + strconv.Itoa(countTotal) + ", 同步成功数:" + strconv.Itoa(countSuccess)
+	response.OkData("同步成功", tips, c)
 }

+ 6 - 0
models/tables/chart_permission/query.go

@@ -28,3 +28,9 @@ func GetByWhereMap(where map[string]interface{}) (list []*ChartPermission, err e
 	err = global.DEFAULT_MYSQL.Where(cond, whereVal...).Find(&list).Error
 	return
 }
+
+// GetListByIds 通过IDs获取图表权限集合
+func GetListByIds(permissionIds []int) (list []*ChartPermission, err error) {
+	err = global.DEFAULT_MYSQL.Model(ChartPermission{}).Where("chart_permission_id IN (?)", permissionIds).Scan(&list).Error
+	return
+}

+ 8 - 0
models/tables/yb_speaker/query.go

@@ -1 +1,9 @@
 package yb_speaker
+
+import "hongze/hongze_yb/global"
+
+// GetSpeakerList 获取主讲人列表
+func GetSpeakerList() (list []*YbSpeaker, err error) {
+	err = global.DEFAULT_MYSQL.Model(YbSpeaker{}).Scan(&list).Error
+	return
+}

+ 45 - 5
services/activity/activity.go

@@ -4,6 +4,7 @@ import (
 	"errors"
 	"gorm.io/gorm"
 	"hongze/hongze_yb/global"
+	"hongze/hongze_yb/models/tables/chart_permission"
 	"hongze/hongze_yb/models/tables/research_report"
 	"hongze/hongze_yb/models/tables/teleconference"
 	"hongze/hongze_yb/models/tables/teleconference_video"
@@ -13,11 +14,13 @@ import (
 	"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"
 )
 
@@ -208,10 +211,11 @@ func SyncTeleconferenceOldData() (countTotal, countSuccess int, err error) {
 	countTotal = len(teleconferenceList)
 	
 	// 取出电话会IDs和报告Ids
-	var teleconferenceIds, reportIds []int
+	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
@@ -238,12 +242,32 @@ func SyncTeleconferenceOldData() (countTotal, countSuccess int, err error) {
 		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() {
@@ -256,6 +280,7 @@ func SyncTeleconferenceOldData() (countTotal, countSuccess int, err error) {
 
 	// 遍历数据
 	for _, item := range teleconferenceList {
+
 		// 匹配报告名称和link
 		reportId := int(item.ReferResearchReportID)
 		linkUrl := `https://details.hzinsights.com/ficcReportDetail?research_report_id=`
@@ -276,7 +301,22 @@ func SyncTeleconferenceOldData() (countTotal, countSuccess int, err error) {
 			firstActivityTypeName = typeIdNameMap[firstActivityTypeId]
 		}
 
-		// TODO:匹配主讲人头像-规则暂定
+		// 匹配主讲人头像
+		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 {
 			// 电话会议
@@ -295,8 +335,8 @@ func SyncTeleconferenceOldData() (countTotal, countSuccess int, err error) {
 			ActivityName: item.TeleconferenceTitle,
 			StartTime: item.StartTime,
 			EndTime: item.EndTime,
-			Speaker: item.Speaker,
-			SpeakerHeadPic: "",
+			Speaker: speakerName,
+			SpeakerHeadPic: speakerPic,
 			SpeakerBackgroundPic: backgroundPic,
 			SingaporeTel: item.SingaporeTelephone,
 			ParticipationCode: item.Password,
@@ -343,7 +383,7 @@ func SyncTeleconferenceOldData() (countTotal, countSuccess int, err error) {
 		activityPermission := &yb_activity_permission.YbActivityPermission{
 			ActivityID: uint32(activityId),
 			PermissionID: uint32(item.ReportPermissionID),
-			PermissionName: "",
+			PermissionName: chartPermissionIdNameMap[item.ReportPermissionID],
 			CreateTime: nowTime,
 		}
 		activityPermissionCreate := tx.Debug().Create(activityPermission)