|
@@ -25,7 +25,7 @@ func UpdateChart(chartInfoId int) (err error, errMsg string) {
|
|
|
err = fmt.Errorf("系统处理中,请稍后重试!")
|
|
|
return
|
|
|
}
|
|
|
- utils.Rc.SetNX(cacheKey, 1, 30*time.Second)
|
|
|
+ utils.Rc.SetNX(cacheKey, 1, 10*time.Minute)
|
|
|
defer func() {
|
|
|
if err != nil {
|
|
|
go alarm_msg.SendAlarmMsg(fmt.Sprintf("更新图表至社区失败:Err:%v,ErrMsg:%s", err, errMsg), 3)
|
|
@@ -57,8 +57,10 @@ func UpdateChart(chartInfoId int) (err error, errMsg string) {
|
|
|
return
|
|
|
}
|
|
|
edbIds := make([]int, 0)
|
|
|
+ edbInfoStr := ""
|
|
|
for _, v := range chartMappingList {
|
|
|
edbIds = append(edbIds, v.EdbInfoId)
|
|
|
+ edbInfoStr += strconv.Itoa(v.EdbInfoId) + ","
|
|
|
}
|
|
|
chartSeriesList := make([]*models.ChartSeries, 0)
|
|
|
chartSeriesEdbList := make([]*models.ChartSeriesEdbMapping, 0)
|
|
@@ -83,7 +85,18 @@ func UpdateChart(chartInfoId int) (err error, errMsg string) {
|
|
|
edbInfoDataList []*eta_forum.AddEdbDataReq
|
|
|
)
|
|
|
//查询指标详情
|
|
|
- edbInfoList, edbMappingList, edbInfoDataList, err = GetEdbListByEdbInfoId(edbIds)
|
|
|
+ isGetEdbData := false
|
|
|
+ // 查询投研资源库里的图表和指标绑定关系
|
|
|
+ oldEdbInfoStr, err := models.GetEdbInfoIdsByChartInfoId(chartInfoId)
|
|
|
+ if err != nil {
|
|
|
+ errMsg = "获取投研资源库里的图表和指标绑定关系失败"
|
|
|
+ err = fmt.Errorf("获取投研资源库里的图表和指标绑定关系失败,Err:" + err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if oldEdbInfoStr != edbInfoStr { // 图表更换过指标需要重新获取指标数据
|
|
|
+ isGetEdbData = true
|
|
|
+ }
|
|
|
+ edbInfoList, edbMappingList, edbInfoDataList, err = GetEdbListByEdbInfoId(edbIds, isGetEdbData)
|
|
|
if err != nil {
|
|
|
errMsg = "获取指标详情失败"
|
|
|
err = fmt.Errorf("获取指标详情失败,Err:" + err.Error())
|
|
@@ -129,11 +142,17 @@ func UpdateChart(chartInfoId int) (err error, errMsg string) {
|
|
|
err = fmt.Errorf(respItem.ErrMsg)
|
|
|
return
|
|
|
}
|
|
|
-
|
|
|
+ // 更新投研资源库里的图表和指标绑定关系
|
|
|
+ err = models.UpdateForumChartEdbMapping(chartInfoId, edbInfoStr)
|
|
|
+ if err != nil {
|
|
|
+ errMsg = "更新投研资源库里的图表和指标绑定关系失败"
|
|
|
+ err = fmt.Errorf("更新投研资源库里的图表和指标绑定关系失败,Err:" + err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-func GetEdbListByEdbInfoId(edbInfoIds []int) (edbInfoList []*models.EdbInfo, edbMappingList []*models.EdbInfoCalculateMapping, edbInfoDataList []*eta_forum.AddEdbDataReq, err error) {
|
|
|
+func GetEdbListByEdbInfoId(edbInfoIds []int, isGetEdbData bool) (edbInfoList []*models.EdbInfo, edbMappingList []*models.EdbInfoCalculateMapping, edbInfoDataList []*eta_forum.AddEdbDataReq, err error) {
|
|
|
//查询指标信息
|
|
|
//查询指标映射
|
|
|
//查询所有指标数据
|
|
@@ -162,29 +181,30 @@ func GetEdbListByEdbInfoId(edbInfoIds []int) (edbInfoList []*models.EdbInfo, edb
|
|
|
err = fmt.Errorf("traceEdbInfoByEdbInfoId GetEdbInfoByIdList err: %s", err.Error())
|
|
|
return
|
|
|
}
|
|
|
+ if isGetEdbData {
|
|
|
+ for _, v := range edbInfoList {
|
|
|
+ if _, ok := chartEdbInfoIdMap[v.EdbInfoId]; !ok {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ var dataList []*models.EdbDataBase
|
|
|
+ if v.Source == utils.DATA_SOURCE_BUSINESS && utils.UseMongo {
|
|
|
+ dataList, err = models.GetEdbDataBaseMongoByEdbInfoId(v.EdbInfoId, v.Source, v.SubSource)
|
|
|
+ } else if v.Source == utils.DATA_SOURCE_THS && v.SubSource == utils.DATA_SUB_SOURCE_HIGH_FREQUENCY && utils.UseMongo {
|
|
|
+ dataList, err = models.GetThsHfEdbDataBaseMongoByEdbInfoId(v.EdbInfoId, v.Source, v.SubSource)
|
|
|
+ } else {
|
|
|
+ dataList, err = models.GetEdbDataBaseByEdbInfoId(v.EdbInfoId, v.Source, v.SubSource)
|
|
|
+ }
|
|
|
+ if err != nil {
|
|
|
+ err = fmt.Errorf("查询指标数据失败 Err: %s", err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
|
|
|
- for _, v := range edbInfoList {
|
|
|
- if _, ok := chartEdbInfoIdMap[v.EdbInfoId]; !ok {
|
|
|
- continue
|
|
|
- }
|
|
|
- var dataList []*models.EdbDataBase
|
|
|
- if v.Source == utils.DATA_SOURCE_BUSINESS && utils.UseMongo {
|
|
|
- dataList, err = models.GetEdbDataBaseMongoByEdbInfoId(v.EdbInfoId, v.Source, v.SubSource)
|
|
|
- } else if v.Source == utils.DATA_SOURCE_THS && v.SubSource == utils.DATA_SUB_SOURCE_HIGH_FREQUENCY && utils.UseMongo {
|
|
|
- dataList, err = models.GetThsHfEdbDataBaseMongoByEdbInfoId(v.EdbInfoId, v.Source, v.SubSource)
|
|
|
- } else {
|
|
|
- dataList, err = models.GetEdbDataBaseByEdbInfoId(v.EdbInfoId, v.Source, v.SubSource)
|
|
|
- }
|
|
|
- if err != nil {
|
|
|
- err = fmt.Errorf("查询指标数据失败 Err: %s", err.Error())
|
|
|
- return
|
|
|
+ tmp := new(eta_forum.AddEdbDataReq)
|
|
|
+ tmp.EdbCode = v.EdbCode
|
|
|
+ tmp.EdbType = v.EdbType
|
|
|
+ tmp.DataList = dataList
|
|
|
+ edbInfoDataList = append(edbInfoDataList, tmp)
|
|
|
}
|
|
|
-
|
|
|
- tmp := new(eta_forum.AddEdbDataReq)
|
|
|
- tmp.EdbCode = v.EdbCode
|
|
|
- tmp.EdbType = v.EdbType
|
|
|
- tmp.DataList = dataList
|
|
|
- edbInfoDataList = append(edbInfoDataList, tmp)
|
|
|
}
|
|
|
return
|
|
|
}
|
|
@@ -257,12 +277,13 @@ func traceEdbInfoByEdbInfoId(edbInfoId int, hasFindMap map[int]struct{}, edbInfo
|
|
|
// 批量上传图表分类信息
|
|
|
func ChartInfoSaveBatch() (err error) {
|
|
|
var tmpErr []error
|
|
|
- deleteCache := true
|
|
|
cacheKey := "eta_forum_task:ChartInfoSaveBatchAdmin"
|
|
|
+ if !utils.Rc.SetNX(cacheKey, 1, 30*time.Minute) {
|
|
|
+ err = fmt.Errorf("系统处理中,请稍后重试!")
|
|
|
+ return
|
|
|
+ }
|
|
|
defer func() {
|
|
|
- if deleteCache {
|
|
|
- _ = utils.Rc.Delete(cacheKey)
|
|
|
- }
|
|
|
+ utils.Rc.Delete(cacheKey)
|
|
|
stack := ""
|
|
|
if err != nil {
|
|
|
stack = fmt.Sprintln(stack + err.Error())
|
|
@@ -277,12 +298,6 @@ func ChartInfoSaveBatch() (err error) {
|
|
|
go alarm_msg.SendAlarmMsg("批量上传资源库图表信息失败"+"<br/>"+stack, 3)
|
|
|
}
|
|
|
}()
|
|
|
- if !utils.Rc.SetNX(cacheKey, 1, 30*time.Second) {
|
|
|
- deleteCache = false
|
|
|
- err = fmt.Errorf("系统处理中,请稍后重试!")
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
// 已上架的图表都更新,批量更新图表信息
|
|
|
condition := " and source=1 and forum_chart_info_id > 0 and resource_status =1"
|
|
|
// 查询需要更新的图表信息总数
|
|
@@ -304,6 +319,9 @@ func ChartInfoSaveBatch() (err error) {
|
|
|
err = fmt.Errorf("查询需要更新的图表信息失败: %v", e)
|
|
|
return
|
|
|
}
|
|
|
+ if len(chartInfos) == 0 {
|
|
|
+ break
|
|
|
+ }
|
|
|
// 循环更新图表数据
|
|
|
for _, chartInfo := range chartInfos {
|
|
|
var er error
|
|
@@ -368,6 +386,9 @@ func ChartInfoSaveBatch() (err error) {
|
|
|
err = fmt.Errorf("查询需要更新的图表信息失败: %v", e)
|
|
|
return
|
|
|
}
|
|
|
+ if len(chartInfos) == 0 {
|
|
|
+ break
|
|
|
+ }
|
|
|
// 循环更新图表数据
|
|
|
for _, chartInfo := range chartInfos {
|
|
|
var er error
|
|
@@ -387,6 +408,8 @@ func ChartInfoSaveBatch() (err error) {
|
|
|
}
|
|
|
utils.FileLog.Info("上传图表数据完成, 上传图表数据总数:", success)
|
|
|
|
|
|
+ // 更新指标数据
|
|
|
+ utils.Rc.LPush(utils.CACHE_KEY_EDB_DATA_UPDATE_LOG, []byte("1"))
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -398,7 +421,7 @@ func UploadChart(chartInfoId int, description string, uploaderInfo *models.Admin
|
|
|
err = fmt.Errorf("系统处理中,请稍后重试!")
|
|
|
return
|
|
|
}
|
|
|
- utils.Rc.SetNX(cacheKey, 1, 30*time.Second)
|
|
|
+ utils.Rc.SetNX(cacheKey, 1, 10*time.Minute)
|
|
|
defer func() {
|
|
|
if err != nil {
|
|
|
go alarm_msg.SendAlarmMsg(fmt.Sprintf("上传图表至社区失败:Err:%v,ErrMsg:%s", err, errMsg), 3)
|
|
@@ -434,8 +457,10 @@ func UploadChart(chartInfoId int, description string, uploaderInfo *models.Admin
|
|
|
return
|
|
|
}
|
|
|
edbIds := make([]int, 0)
|
|
|
+ edbInfoStr := ""
|
|
|
for _, v := range chartMappingList {
|
|
|
edbIds = append(edbIds, v.EdbInfoId)
|
|
|
+ edbInfoStr += strconv.Itoa(v.EdbInfoId) + ","
|
|
|
}
|
|
|
chartSeriesList := make([]*models.ChartSeries, 0)
|
|
|
chartSeriesEdbList := make([]*models.ChartSeriesEdbMapping, 0)
|
|
@@ -461,7 +486,7 @@ func UploadChart(chartInfoId int, description string, uploaderInfo *models.Admin
|
|
|
edbInfoDataList []*eta_forum.AddEdbDataReq
|
|
|
)
|
|
|
//查询指标详情
|
|
|
- edbInfoList, edbMappingList, edbInfoDataList, err = GetEdbListByEdbInfoId(edbIds)
|
|
|
+ edbInfoList, edbMappingList, edbInfoDataList, err = GetEdbListByEdbInfoId(edbIds, true)
|
|
|
if err != nil {
|
|
|
errMsg = "获取指标详情失败"
|
|
|
err = fmt.Errorf("获取指标详情失败,Err:" + err.Error())
|
|
@@ -518,6 +543,14 @@ func UploadChart(chartInfoId int, description string, uploaderInfo *models.Admin
|
|
|
err = fmt.Errorf("更新图表ID失败,Err:" + err.Error())
|
|
|
return
|
|
|
}
|
|
|
+
|
|
|
+ // 新增投研资源库里的图表和指标绑定关系
|
|
|
+ err = models.AddForumChartEdbMapping(chartInfoId, edbInfoStr)
|
|
|
+ if err != nil {
|
|
|
+ errMsg = "新增投研资源库里的图表和指标绑定关系失败"
|
|
|
+ err = fmt.Errorf("新增投研资源库里的图表和指标绑定关系失败,Err:" + err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
return
|