|
@@ -1,13 +1,17 @@
|
|
|
package activity
|
|
|
|
|
|
import (
|
|
|
+ "errors"
|
|
|
"gorm.io/gorm"
|
|
|
"hongze/hongze_yb/global"
|
|
|
+ "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/services/company"
|
|
|
"hongze/hongze_yb/services/user"
|
|
@@ -189,8 +193,8 @@ func GetUserAuthActivityIds(userInfo user.UserInfo) (acrivityIds []int, err erro
|
|
|
}
|
|
|
|
|
|
// SyncTeleconferenceOldData 同步旧数据
|
|
|
-func SyncTeleconferenceOldData() (countSuccess int, err error) {
|
|
|
- // 查询所有三个月内的数据及相关音频
|
|
|
+func SyncTeleconferenceOldData() (countTotal, countSuccess int, err error) {
|
|
|
+ // 查询所有前三个月的电话会
|
|
|
condition := "enabled = 1"
|
|
|
pars := make([]interface{}, 0)
|
|
|
nowTime := time.Now()
|
|
@@ -201,9 +205,54 @@ func SyncTeleconferenceOldData() (countSuccess int, err error) {
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
|
+ countTotal = len(teleconferenceList)
|
|
|
+
|
|
|
+ // 取出电话会IDs和报告Ids
|
|
|
+ var teleconferenceIds, reportIds []int
|
|
|
+ for i := 0; i < len(teleconferenceList); i++ {
|
|
|
+ teleconferenceIds = append(teleconferenceIds, int(teleconferenceList[i].TeleconferenceID))
|
|
|
+ reportIds = append(reportIds, int(teleconferenceList[i].ReferResearchReportID))
|
|
|
+ }
|
|
|
|
|
|
- // 开启事务
|
|
|
+ // 报告名称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
|
|
|
+ }
|
|
|
|
|
|
+ // 音频列表
|
|
|
+ voicesList, err := teleconference_video.GetListByTeleconferenceIds(teleconferenceIds)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // 开启事务
|
|
|
+ tx := global.DEFAULT_MYSQL.Begin()
|
|
|
+ defer func() {
|
|
|
+ if err != nil {
|
|
|
+ tx.Rollback()
|
|
|
+ } else {
|
|
|
+ tx.Commit()
|
|
|
+ }
|
|
|
+ }()
|
|
|
|
|
|
// 遍历数据
|
|
|
for _, item := range teleconferenceList {
|
|
@@ -214,37 +263,48 @@ func SyncTeleconferenceOldData() (countSuccess int, err error) {
|
|
|
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]
|
|
|
+ }
|
|
|
|
|
|
- // 匹配主讲人信息
|
|
|
- /*if firstActivityTypeId == 1 {
|
|
|
+ // TODO:匹配主讲人头像-规则暂定
|
|
|
+ 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: 0,
|
|
|
- FirstActivityTypeName: "",
|
|
|
- ActivityTypeID: 0,
|
|
|
- ActivityTypeName: "",
|
|
|
+ FirstActivityTypeID: firstActivityTypeId,
|
|
|
+ FirstActivityTypeName: firstActivityTypeName,
|
|
|
+ ActivityTypeID: activityTypeId,
|
|
|
+ ActivityTypeName: activityTypeName,
|
|
|
ActivityName: item.TeleconferenceTitle,
|
|
|
StartTime: item.StartTime,
|
|
|
EndTime: item.EndTime,
|
|
|
- Speaker: "",
|
|
|
+ Speaker: item.Speaker,
|
|
|
SpeakerHeadPic: "",
|
|
|
- SpeakerBackgroundPic: "",
|
|
|
- SingaporeTel: "",
|
|
|
+ SpeakerBackgroundPic: backgroundPic,
|
|
|
+ SingaporeTel: item.SingaporeTelephone,
|
|
|
ParticipationCode: item.Password,
|
|
|
MainlandTel: item.Telephone,
|
|
|
HongKongTel: item.HkTelephone,
|
|
|
ReportID: reportId,
|
|
|
ReportLink: reportLink,
|
|
|
- ReportName: "",
|
|
|
+ ReportName: reportName,
|
|
|
Remarks: item.Remark,
|
|
|
PublishStatus: 1,
|
|
|
IsSendWxMsg: 1,
|
|
@@ -252,22 +312,31 @@ func SyncTeleconferenceOldData() (countSuccess int, err error) {
|
|
|
ModifyTime: nowTime,
|
|
|
CreateTime: nowTime,
|
|
|
}
|
|
|
- activityId, tempErr := activityInfo.Create()
|
|
|
- if tempErr != nil {
|
|
|
+
|
|
|
+ // 开启事务之后的操作要使用tx
|
|
|
+ activityCreate := tx.Debug().Create(activityInfo)
|
|
|
+ if activityCreate.Error != nil {
|
|
|
+ err = errors.New("新增活动失败")
|
|
|
return
|
|
|
}
|
|
|
+ activityId := activityInfo.ActivityID
|
|
|
|
|
|
// 5.新增活动音频-音频列表
|
|
|
- activityVoice := &yb_activity_voice.YbActivityVoice{
|
|
|
- ActivityVoiceID: activityId,
|
|
|
- VoiceURL: item.VideoURL,
|
|
|
- VoiceName: item.VideoName,
|
|
|
- VoicePlaySeconds: item.VideoPlaySeconds,
|
|
|
- CreateTime: nowTime,
|
|
|
- }
|
|
|
- tempErr = activityVoice.Create()
|
|
|
- if tempErr != nil {
|
|
|
- return
|
|
|
+ for _, voice := range voicesList {
|
|
|
+ if int(item.TeleconferenceID) == voice.TeleconferenceID {
|
|
|
+ activityVoice := &yb_activity_voice.YbActivityVoice{
|
|
|
+ ActivityVoiceID: 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.新增活动关联权限-源数据权限仅一个
|
|
@@ -277,10 +346,12 @@ func SyncTeleconferenceOldData() (countSuccess int, err error) {
|
|
|
PermissionName: "",
|
|
|
CreateTime: nowTime,
|
|
|
}
|
|
|
- tempErr = activityPermission.Create()
|
|
|
- if tempErr != nil {
|
|
|
+ activityPermissionCreate := tx.Debug().Create(activityPermission)
|
|
|
+ if activityPermissionCreate.Error != nil {
|
|
|
+ err = errors.New("新增活动权限失败")
|
|
|
return
|
|
|
}
|
|
|
+ countSuccess += 1
|
|
|
}
|
|
|
|
|
|
return
|