chart_info.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598
  1. package services
  2. import (
  3. "context"
  4. "encoding/json"
  5. "eta/eta_forum_task/models"
  6. "eta/eta_forum_task/services/alarm_msg"
  7. "eta/eta_forum_task/services/eta_forum"
  8. "eta/eta_forum_task/utils"
  9. "fmt"
  10. "strconv"
  11. "time"
  12. )
  13. func EtaForumChartUpdate(cont context.Context) (err error) {
  14. err = ChartInfoSaveBatch()
  15. return
  16. }
  17. // UpdateChart 更新社区里的图表接口
  18. func UpdateChart(chartInfoId int) (err error, errMsg string) {
  19. // 设置缓存 防止重复更新
  20. cacheKey := "eta_forum_task:UpdateChart:" + strconv.Itoa(chartInfoId)
  21. if utils.Rc.Get(cacheKey) != nil {
  22. err = fmt.Errorf("系统处理中,请稍后重试!")
  23. return
  24. }
  25. utils.Rc.SetNX(cacheKey, 1, 10*time.Minute)
  26. defer func() {
  27. if err != nil {
  28. go alarm_msg.SendAlarmMsg(fmt.Sprintf("更新图表至社区失败:Err:%v,ErrMsg:%s", err, errMsg), 3)
  29. }
  30. utils.Rc.Delete(cacheKey)
  31. }()
  32. // 查询图表信息
  33. chartInfo, err := models.GetChartInfoById(chartInfoId)
  34. if err != nil {
  35. if err.Error() == utils.ErrNoRow() {
  36. errMsg = "图表不存在"
  37. err = fmt.Errorf(errMsg)
  38. return
  39. }
  40. errMsg = "获取图表信息失败"
  41. err = fmt.Errorf("获取图表信息失败,Err:" + err.Error())
  42. return
  43. }
  44. if chartInfo.ForumChartInfoId <= 0 {
  45. return
  46. }
  47. //查询图表指标
  48. //获取原图表关联的指标信息列表
  49. chartMappingList, err := models.GetChartMappingList(chartInfoId)
  50. if err != nil {
  51. errMsg = "获取图表关联的指标信息失败"
  52. err = fmt.Errorf("获取图表关联的指标信息失败,Err:" + err.Error())
  53. return
  54. }
  55. edbIds := make([]int, 0)
  56. edbInfoStr := ""
  57. for _, v := range chartMappingList {
  58. edbIds = append(edbIds, v.EdbInfoId)
  59. edbInfoStr += strconv.Itoa(v.EdbInfoId) + ","
  60. }
  61. chartSeriesList := make([]*models.ChartSeries, 0)
  62. chartSeriesEdbList := make([]*models.ChartSeriesEdbMapping, 0)
  63. if chartInfo.ChartType == utils.CHART_TYPE_SECTION_COMBINE {
  64. chartSeriesList, err = models.GetChartSeriesByChartInfoId(chartInfoId)
  65. if err != nil {
  66. errMsg = "获取图表关联的系列信息失败"
  67. err = fmt.Errorf("获取图表关联的系列信息失败,Err:" + err.Error())
  68. return
  69. }
  70. chartSeriesEdbList, err = models.GetChartSeriesEdbByChartInfoId(chartInfoId)
  71. if err != nil {
  72. errMsg = "获取图表关联的系列指标信息失败"
  73. err = fmt.Errorf("获取图表关联的系列指标信息失败,Err:" + err.Error())
  74. return
  75. }
  76. }
  77. var (
  78. edbInfoList []*models.EdbInfo
  79. edbMappingList []*models.EdbInfoCalculateMapping
  80. edbInfoDataList []*eta_forum.AddEdbDataReq
  81. )
  82. //查询指标详情
  83. isGetEdbData := false
  84. // 查询投研资源库里的图表和指标绑定关系
  85. oldEdbInfoStr, err := models.GetEdbInfoIdsByChartInfoId(chartInfoId)
  86. if err != nil {
  87. errMsg = "获取投研资源库里的图表和指标绑定关系失败"
  88. err = fmt.Errorf("获取投研资源库里的图表和指标绑定关系失败,Err:" + err.Error())
  89. return
  90. }
  91. if oldEdbInfoStr != edbInfoStr { // 图表更换过指标需要重新获取指标数据
  92. isGetEdbData = true
  93. }
  94. edbInfoList, edbMappingList, edbInfoDataList, err = GetEdbListByEdbInfoId(edbIds, isGetEdbData)
  95. if err != nil {
  96. errMsg = "获取指标详情失败"
  97. err = fmt.Errorf("获取指标详情失败,Err:" + err.Error())
  98. return
  99. }
  100. descriptionList, err, errMsg := getChartDescriptionWithAdminNameByChartInfoId(chartInfoId)
  101. if err != nil {
  102. errMsg = "获取图表简介失败"
  103. err = fmt.Errorf("获取图表简介失败,Err:" + err.Error())
  104. return
  105. }
  106. req := new(eta_forum.ChartSaveLibReq)
  107. req.ChartInfo = chartInfo
  108. req.ChartInfo.ChartInfoId = chartInfo.ForumChartInfoId
  109. req.ChartEdbMapping = chartMappingList
  110. req.EdbInfoList = edbInfoList
  111. req.EdbInfoDataList = edbInfoDataList
  112. req.EdbInfoCalculateMapping = edbMappingList
  113. req.ChartSeries = chartSeriesList
  114. req.ChartSeriesEdbMapping = chartSeriesEdbList
  115. req.Description = descriptionList
  116. // 查询创建者信息
  117. creatorInfo, _ := models.GetSysUserById(chartInfo.SysUserId)
  118. if creatorInfo != nil {
  119. req.CreatorInfo = creatorInfo
  120. }
  121. // 添加计算指标
  122. reqJson, err := json.Marshal(req)
  123. if err != nil {
  124. errMsg = "参数解析异常"
  125. err = fmt.Errorf("参数解析异常,Err:" + err.Error())
  126. return
  127. }
  128. respItem, err := eta_forum.ChartUpdateLib(string(reqJson))
  129. if err != nil {
  130. errMsg = "更新失败"
  131. err = fmt.Errorf("上传失败,Err:" + err.Error())
  132. return
  133. }
  134. if respItem.Ret != 200 {
  135. errMsg = "更新失败"
  136. err = fmt.Errorf(respItem.ErrMsg)
  137. return
  138. }
  139. // 更新投研资源库里的图表和指标绑定关系
  140. err = models.UpdateForumChartEdbMapping(chartInfoId, edbInfoStr)
  141. if err != nil {
  142. errMsg = "更新投研资源库里的图表和指标绑定关系失败"
  143. err = fmt.Errorf("更新投研资源库里的图表和指标绑定关系失败,Err:" + err.Error())
  144. return
  145. }
  146. return
  147. }
  148. func GetEdbListByEdbInfoId(edbInfoIds []int, isGetEdbData bool) (edbInfoList []*models.EdbInfo, edbMappingList []*models.EdbInfoCalculateMapping, edbInfoDataList []*eta_forum.AddEdbDataReq, err error) {
  149. //查询指标信息
  150. //查询指标映射
  151. //查询所有指标数据
  152. //查询这个指标相关的mapping信息放到数组里,
  153. //将得到的指标ID信息放到数组里
  154. chartEdbInfoIdMap := make(map[int]struct{}) //只查询图表上直接相关的指标数据
  155. hasFindMap := make(map[int]struct{})
  156. edbInfoIdMap := make(map[int]struct{})
  157. edbMappingList = make([]*models.EdbInfoCalculateMapping, 0)
  158. edbMappingMap := make(map[int]struct{})
  159. for _, edbInfoId := range edbInfoIds {
  160. chartEdbInfoIdMap[edbInfoId] = struct{}{}
  161. edbMappingList, err = traceEdbInfoByEdbInfoId(edbInfoId, hasFindMap, edbInfoIdMap, edbMappingList, edbMappingMap)
  162. if err != nil {
  163. return
  164. }
  165. }
  166. // 指标信息map
  167. edbInfoIdList := make([]int, 0)
  168. for k, _ := range edbInfoIdMap {
  169. edbInfoIdList = append(edbInfoIdList, k)
  170. }
  171. edbInfoList, err = models.GetEdbInfoByIdList(edbInfoIdList)
  172. if err != nil {
  173. err = fmt.Errorf("traceEdbInfoByEdbInfoId GetEdbInfoByIdList err: %s", err.Error())
  174. return
  175. }
  176. if isGetEdbData {
  177. for _, v := range edbInfoList {
  178. if _, ok := chartEdbInfoIdMap[v.EdbInfoId]; !ok {
  179. continue
  180. }
  181. var dataList []*models.EdbDataBase
  182. if v.Source == utils.DATA_SOURCE_BUSINESS && utils.UseMongo {
  183. dataList, err = models.GetEdbDataBaseMongoByEdbInfoId(v.EdbInfoId, v.Source, v.SubSource)
  184. } else if v.Source == utils.DATA_SOURCE_THS && v.SubSource == utils.DATA_SUB_SOURCE_HIGH_FREQUENCY && utils.UseMongo {
  185. dataList, err = models.GetThsHfEdbDataBaseMongoByEdbInfoId(v.EdbInfoId, v.Source, v.SubSource)
  186. } else {
  187. dataList, err = models.GetEdbDataBaseByEdbInfoId(v.EdbInfoId, v.Source, v.SubSource)
  188. }
  189. if err != nil {
  190. err = fmt.Errorf("查询指标数据失败 Err: %s", err.Error())
  191. return
  192. }
  193. tmp := new(eta_forum.AddEdbDataReq)
  194. tmp.EdbCode = v.EdbCode
  195. tmp.EdbType = v.EdbType
  196. tmp.DataList = dataList
  197. edbInfoDataList = append(edbInfoDataList, tmp)
  198. }
  199. }
  200. return
  201. }
  202. // traceEdbInfoByEdbInfoId 指标追溯
  203. func traceEdbInfoByEdbInfoId(edbInfoId int, hasFindMap map[int]struct{}, edbInfoIdMap map[int]struct{}, edbMappingList []*models.EdbInfoCalculateMapping, edbMappingMap map[int]struct{}) (newEdbMappingList []*models.EdbInfoCalculateMapping, err error) {
  204. newEdbMappingList = edbMappingList
  205. _, ok := hasFindMap[edbInfoId]
  206. if ok {
  207. return
  208. }
  209. if _, ok1 := edbInfoIdMap[edbInfoId]; !ok1 {
  210. edbInfoIdMap[edbInfoId] = struct{}{}
  211. }
  212. edbInfoMappingList, e := models.GetEdbInfoCalculateMappingListByEdbInfoId(edbInfoId)
  213. if e != nil {
  214. err = fmt.Errorf("GetEdbInfoCalculateMappingListByEdbInfoId err: %s", e.Error())
  215. return
  216. }
  217. if len(edbInfoMappingList) > 0 {
  218. fromEdbInfoIdList := make([]int, 0)
  219. for _, v := range edbInfoMappingList {
  220. fromEdbInfoIdList = append(fromEdbInfoIdList, v.FromEdbInfoId)
  221. if _, ok1 := edbInfoIdMap[v.FromEdbInfoId]; !ok1 {
  222. edbInfoIdMap[v.FromEdbInfoId] = struct{}{}
  223. }
  224. if _, ok2 := edbMappingMap[v.EdbInfoCalculateMappingId]; !ok2 {
  225. edbMappingMap[v.EdbInfoCalculateMappingId] = struct{}{}
  226. tmp := &models.EdbInfoCalculateMapping{
  227. EdbInfoCalculateMappingId: v.EdbInfoCalculateMappingId,
  228. EdbInfoId: v.EdbInfoId,
  229. Source: v.Source,
  230. SourceName: v.SourceName,
  231. EdbCode: v.EdbCode,
  232. FromEdbInfoId: v.FromEdbInfoId,
  233. FromEdbCode: v.FromEdbCode,
  234. FromEdbName: v.FromEdbName,
  235. FromSource: v.FromSource,
  236. FromSourceName: v.FromSourceName,
  237. FromTag: v.FromTag,
  238. Sort: v.Sort,
  239. CreateTime: v.CreateTime,
  240. ModifyTime: v.ModifyTime,
  241. }
  242. newEdbMappingList = append(newEdbMappingList, tmp)
  243. }
  244. if edbInfoId != v.FromEdbInfoId && (v.FromEdbType == 2 || v.FromEdbInfoType == 1) {
  245. // 查过了就不查了
  246. if _, ok2 := hasFindMap[v.FromEdbInfoId]; !ok2 {
  247. newEdbMappingList, e = traceEdbInfoByEdbInfoId(v.FromEdbInfoId, hasFindMap, edbInfoIdMap, newEdbMappingList, edbMappingMap)
  248. if e != nil {
  249. err = fmt.Errorf("traceEdbInfoByEdbInfoId err: %s", e.Error())
  250. return
  251. }
  252. }
  253. }
  254. hasFindMap[v.FromEdbInfoId] = struct{}{}
  255. }
  256. }
  257. hasFindMap[edbInfoId] = struct{}{}
  258. return
  259. }
  260. // 批量上传图表分类信息
  261. func ChartInfoSaveBatch() (err error) {
  262. var tmpErr []error
  263. cacheKey := "eta_forum_task:ChartInfoSaveBatchAdmin"
  264. if !utils.Rc.SetNX(cacheKey, 1, 30*time.Minute) {
  265. err = fmt.Errorf("系统处理中,请稍后重试!")
  266. return
  267. }
  268. defer func() {
  269. utils.Rc.Delete(cacheKey)
  270. stack := ""
  271. if err != nil {
  272. stack = fmt.Sprintln(stack + err.Error())
  273. }
  274. if len(tmpErr) > 0 {
  275. for _, v := range tmpErr {
  276. stack = fmt.Sprintln(stack + v.Error())
  277. }
  278. }
  279. if stack != "" {
  280. utils.FileLog.Error("批量上传资源库图表信息失败"+"<br/>"+stack)
  281. go alarm_msg.SendAlarmMsg("批量上传资源库图表信息失败"+"<br/>"+stack, 3)
  282. }
  283. }()
  284. // 已上架的图表都更新,批量更新图表信息
  285. condition := " and source=1 and forum_chart_info_id > 0 and resource_status =1"
  286. // 查询需要更新的图表信息总数
  287. total, err := models.GetChartInfoCountByCondition(condition, []interface{}{})
  288. if err != nil {
  289. return
  290. }
  291. if total > 0 {
  292. // 批量上传图表信息
  293. offset := 0
  294. pageSize := 100
  295. success := 0
  296. // 循环更新100个图表数据
  297. for i := 0; offset < total; i++ {
  298. // 查询需要更新的图表信息
  299. chartInfos, e := models.GetChartInfoListByCondition(condition, []interface{}{}, offset, pageSize)
  300. if e != nil {
  301. err = fmt.Errorf("查询需要更新的图表信息失败: %v", e)
  302. return
  303. }
  304. if len(chartInfos) == 0 {
  305. break
  306. }
  307. // 循环更新图表数据
  308. for _, chartInfo := range chartInfos {
  309. var er error
  310. var msg string
  311. // 更新图表数据
  312. er, msg = UpdateChart(chartInfo.ChartInfoId)
  313. if er != nil {
  314. er = fmt.Errorf("图表ID %d, 更新图表数据失败: %s, %v", chartInfo.ChartInfoId, msg, er)
  315. tmpErr = append(tmpErr, er)
  316. continue
  317. }
  318. success += 1
  319. }
  320. offset = (i + 1) * pageSize
  321. }
  322. utils.FileLog.Info("更新图表数据完成, 更新图表数据总数:", success)
  323. }
  324. sysUser, err := models.GetSysUserByAdminName("admin")
  325. if err != nil {
  326. err = fmt.Errorf("获取系统用户失败,Err:" + err.Error())
  327. return
  328. }
  329. // 获取精选资源分类已经上架的分类
  330. classifyCondition := " AND source=? and is_selected=1 and resource_status=1 "
  331. var classifyPars []interface{}
  332. classifyPars = append(classifyPars, utils.CHART_SOURCE_DEFAULT)
  333. classifyList, err := models.GetChartClassifyListByCondition(classifyCondition, classifyPars)
  334. if err != nil {
  335. return
  336. }
  337. chartClassifyIdList := make([]string, 0)
  338. for _, v := range classifyList {
  339. chartClassifyIdList = append(chartClassifyIdList, strconv.Itoa(v.ChartClassifyId))
  340. }
  341. if len(chartClassifyIdList) == 0 {
  342. return
  343. }
  344. // 批量上传图表信息
  345. condition = " and source=1 and forum_chart_info_id = 0 and chart_classify_id in ("+utils.GetOrmInReplace(len(chartClassifyIdList))+") and resource_status !=2"
  346. // 查询需要更新的图表信息总数
  347. total, err = models.GetChartInfoCountByCondition(condition, []interface{}{chartClassifyIdList})
  348. if err != nil {
  349. return
  350. }
  351. if total == 0 {
  352. return
  353. }
  354. // 批量上传图表信息
  355. offset := 0
  356. pageSize := 100
  357. success := 0
  358. // 循环更新100个图表数据
  359. for i := 0; offset < total; i++ {
  360. // 查询需要更新的图表信息
  361. chartInfos, e := models.GetChartInfoListByCondition(condition, []interface{}{chartClassifyIdList}, offset, pageSize)
  362. if e != nil {
  363. err = fmt.Errorf("查询需要更新的图表信息失败: %v", e)
  364. return
  365. }
  366. if len(chartInfos) == 0 {
  367. break
  368. }
  369. // 循环更新图表数据
  370. for _, chartInfo := range chartInfos {
  371. var er error
  372. var msg string
  373. // 上传图表数据
  374. er, msg = UploadChart(chartInfo.ChartInfoId, "", sysUser)
  375. if er != nil {
  376. er = fmt.Errorf("图表ID %d, 上传图表数据失败: %s, %v", chartInfo.ChartInfoId, msg, er)
  377. tmpErr = append(tmpErr, er)
  378. continue
  379. }
  380. success += 1
  381. }
  382. offset = (i + 1) * pageSize
  383. }
  384. utils.FileLog.Info("上传图表数据完成, 上传图表数据总数:", success)
  385. // 更新指标数据
  386. utils.Rc.LPush(utils.CACHE_KEY_EDB_DATA_UPDATE_LOG, []byte("1"))
  387. return
  388. }
  389. // UploadChart 上传图表接口
  390. func UploadChart(chartInfoId int, description string, uploaderInfo *models.Admin) (err error, errMsg string) {
  391. // 设置缓存 防止重复上传
  392. cacheKey := "eta_forum_task:UploadChart:" + strconv.Itoa(chartInfoId)
  393. if utils.Rc.Get(cacheKey) != nil {
  394. err = fmt.Errorf("系统处理中,请稍后重试!")
  395. return
  396. }
  397. utils.Rc.SetNX(cacheKey, 1, 10*time.Minute)
  398. defer func() {
  399. if err != nil {
  400. go alarm_msg.SendAlarmMsg(fmt.Sprintf("上传图表至社区失败:Err:%v,ErrMsg:%s", err, errMsg), 3)
  401. }
  402. utils.Rc.Delete(cacheKey)
  403. }()
  404. // 查询图表信息
  405. chartInfo, err := models.GetChartInfoById(chartInfoId)
  406. if err != nil {
  407. if err.Error() == utils.ErrNoRow() {
  408. errMsg = "图表不存在"
  409. err = fmt.Errorf(errMsg)
  410. return
  411. }
  412. errMsg = "获取图表信息失败"
  413. err = fmt.Errorf("获取图表信息失败,Err:" + err.Error())
  414. return
  415. }
  416. if chartInfo.ForumChartInfoId > 0 {
  417. errMsg = "该图表已上传至社区,无法再次上传"
  418. err = fmt.Errorf(errMsg)
  419. return
  420. }
  421. //查询图表主题
  422. //查询图表指标
  423. //获取原图表关联的指标信息列表
  424. chartMappingList, err := models.GetChartMappingList(chartInfoId)
  425. if err != nil {
  426. errMsg = "获取图表关联的指标信息失败"
  427. err = fmt.Errorf("获取图表关联的指标信息失败,Err:" + err.Error())
  428. return
  429. }
  430. edbIds := make([]int, 0)
  431. edbInfoStr := ""
  432. for _, v := range chartMappingList {
  433. edbIds = append(edbIds, v.EdbInfoId)
  434. edbInfoStr += strconv.Itoa(v.EdbInfoId) + ","
  435. }
  436. chartSeriesList := make([]*models.ChartSeries, 0)
  437. chartSeriesEdbList := make([]*models.ChartSeriesEdbMapping, 0)
  438. if chartInfo.ChartType == utils.CHART_TYPE_SECTION_COMBINE {
  439. chartSeriesList, err = models.GetChartSeriesByChartInfoId(chartInfoId)
  440. if err != nil {
  441. errMsg = "获取图表关联的系列信息失败"
  442. err = fmt.Errorf("获取图表关联的系列信息失败,Err:" + err.Error())
  443. return
  444. }
  445. chartSeriesEdbList, err = models.GetChartSeriesEdbByChartInfoId(chartInfoId)
  446. if err != nil {
  447. errMsg = "获取图表关联的系列指标信息失败"
  448. err = fmt.Errorf("获取图表关联的系列指标信息失败,Err:" + err.Error())
  449. return
  450. }
  451. }
  452. var (
  453. edbInfoList []*models.EdbInfo
  454. edbMappingList []*models.EdbInfoCalculateMapping
  455. edbInfoDataList []*eta_forum.AddEdbDataReq
  456. )
  457. //查询指标详情
  458. edbInfoList, edbMappingList, edbInfoDataList, err = GetEdbListByEdbInfoId(edbIds, true)
  459. if err != nil {
  460. errMsg = "获取指标详情失败"
  461. err = fmt.Errorf("获取指标详情失败,Err:" + err.Error())
  462. return
  463. }
  464. descriptionList, err, errMsg := getChartDescriptionWithAdminNameByChartInfoId(chartInfoId)
  465. if err != nil {
  466. errMsg = "获取图表简介失败"
  467. err = fmt.Errorf("获取图表简介失败,Err:" + err.Error())
  468. return
  469. }
  470. req := new(eta_forum.ChartSaveLibReq)
  471. req.ChartInfo = chartInfo
  472. req.ChartEdbMapping = chartMappingList
  473. req.EdbInfoList = edbInfoList
  474. req.EdbInfoDataList = edbInfoDataList
  475. req.EdbInfoCalculateMapping = edbMappingList
  476. req.Description = descriptionList
  477. req.ChartSeries = chartSeriesList
  478. req.ChartSeriesEdbMapping = chartSeriesEdbList
  479. // 查询创建者信息
  480. creatorInfo, _ := models.GetSysUserById(chartInfo.SysUserId)
  481. if creatorInfo != nil {
  482. req.CreatorInfo = creatorInfo
  483. }
  484. req.UploaderInfo = uploaderInfo
  485. // 添加计算指标
  486. reqJson, err := json.Marshal(req)
  487. if err != nil {
  488. errMsg = "参数解析异常"
  489. err = fmt.Errorf("参数解析异常,Err:" + err.Error())
  490. return
  491. }
  492. respItem, err := eta_forum.ChartSaveLib(string(reqJson))
  493. if err != nil {
  494. errMsg = "上传失败"
  495. err = fmt.Errorf("上传失败,Err:" + err.Error())
  496. return
  497. }
  498. if respItem.Ret != 200 {
  499. errMsg = "上传失败"
  500. err = fmt.Errorf(respItem.ErrMsg)
  501. return
  502. }
  503. if respItem.Data != nil && respItem.Data.ChartInfoId != 0 {
  504. // 更新社区返回的图表ID
  505. err = models.SetForumChartInfoId(chartInfoId, respItem.Data.ChartInfoId, utils.ChartClassifyResourceStatusUp)
  506. if err != nil {
  507. errMsg = "更新图表ID失败"
  508. err = fmt.Errorf("更新图表ID失败,Err:" + err.Error())
  509. return
  510. }
  511. // 新增投研资源库里的图表和指标绑定关系
  512. err = models.AddForumChartEdbMapping(chartInfoId, edbInfoStr)
  513. if err != nil {
  514. errMsg = "新增投研资源库里的图表和指标绑定关系失败"
  515. err = fmt.Errorf("新增投研资源库里的图表和指标绑定关系失败,Err:" + err.Error())
  516. return
  517. }
  518. }
  519. return
  520. }
  521. func getChartDescriptionWithAdminNameByChartInfoId(chartInfoId int) (list []*models.ChartDescriptionReq, err error, errMsg string) {
  522. descriptionList, err := models.GetChartDescriptionByChartInfoId(chartInfoId)
  523. if err != nil {
  524. errMsg = "获取图表简介失败"
  525. err = fmt.Errorf("获取图表简介失败,Err:" + err.Error())
  526. return
  527. }
  528. // 查询创建者信息
  529. adminIdList := make([]int, 0)
  530. for _, v := range descriptionList {
  531. adminIdList = append(adminIdList, v.SysUserId)
  532. }
  533. adminList, err := models.GetAdminListByIdList(adminIdList)
  534. if err != nil {
  535. errMsg = "获取创建者信息失败"
  536. err = fmt.Errorf("获取创建者信息失败,Err:" + err.Error())
  537. return
  538. }
  539. adminMap := make(map[int]string)
  540. for _, v := range adminList {
  541. adminMap[v.AdminId] = v.AdminName
  542. }
  543. for _, v := range descriptionList {
  544. adminName, ok := adminMap[v.SysUserId]
  545. if !ok {
  546. adminName = ""
  547. }
  548. list = append(list, &models.ChartDescriptionReq{
  549. Id: v.Id,
  550. ChartInfoId: v.ChartInfoId,
  551. Description: v.Description,
  552. AdminName: adminName,
  553. SysUserId: v.SysUserId,
  554. SysUserRealName: v.SysUserRealName,
  555. ModifyTime: v.ModifyTime,
  556. CreateTime: v.CreateTime,
  557. })
  558. }
  559. return
  560. }