base_from_rzd.go 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709
  1. // @Author gmy 2024/8/13 16:01:00
  2. package controllers
  3. import (
  4. "encoding/json"
  5. "eta/eta_index_lib/logic"
  6. "eta/eta_index_lib/models"
  7. "eta/eta_index_lib/services"
  8. "eta/eta_index_lib/utils"
  9. "fmt"
  10. "strconv"
  11. "time"
  12. )
  13. type BaseFromRzdController struct {
  14. BaseAuthController
  15. }
  16. // Add
  17. // @Title 新增睿姿得指标
  18. // @Description 新增粮油商务网指标
  19. // @router /add [post]
  20. func (this *BaseFromRzdController) Add() {
  21. br := new(models.BaseResponse).Init()
  22. var cacheKey string
  23. defer func() {
  24. utils.Rc.Delete(cacheKey)
  25. this.Data["json"] = br
  26. this.ServeJSON()
  27. }()
  28. source := utils.DATA_SOURCE_RZD
  29. var req models.AddEdbInfoReq
  30. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  31. if err != nil {
  32. br.Msg = "参数解析异常!"
  33. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  34. return
  35. }
  36. if req.EdbCode == "" {
  37. br.Msg = "请输入指标编码!"
  38. br.ErrMsg = "请输入指标编码,指标编码为空"
  39. return
  40. }
  41. cacheKey = utils.CACHE_EDB_DATA_ADD + strconv.Itoa(source) + "_" + req.EdbCode
  42. if !utils.Rc.IsExist(cacheKey) {
  43. utils.Rc.SetNX(cacheKey, 1, 1*time.Minute)
  44. err = models.AddEdbDataFromRzd(req.EdbCode)
  45. if err != nil {
  46. br.Msg = "获取指标信息失败!"
  47. br.ErrMsg = "获取指标信息失败 AddEdbDataFromSci99,Err:" + err.Error()
  48. return
  49. }
  50. br.Ret = 200
  51. br.Success = true
  52. br.Msg = "获取成功"
  53. } else {
  54. br.Ret = 501
  55. br.Success = true
  56. br.Msg = "系统处理中,请稍后重试"
  57. }
  58. }
  59. // Refresh
  60. // @Title 刷新粮油商务网指标接口
  61. // @Description 刷新粮油商务网指标接口
  62. // @Success 200 {object} models.RefreshEdbInfoReq
  63. // @router /refresh [post]
  64. func (this *BaseFromRzdController) Refresh() {
  65. br := new(models.BaseResponse).Init()
  66. var cacheKey string
  67. defer func() {
  68. if br.ErrMsg == "" {
  69. br.IsSendEmail = false
  70. }
  71. _ = utils.Rc.Delete(cacheKey)
  72. this.Data["json"] = br
  73. this.ServeJSON()
  74. }()
  75. source := utils.DATA_SOURCE_RZD
  76. var req models.RefreshEdbInfoReq
  77. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  78. if err != nil {
  79. br.Msg = "参数解析异常!"
  80. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  81. return
  82. }
  83. if req.EdbCode == "" {
  84. br.Msg = "请输入指标编码!"
  85. br.ErrMsg = "请输入指标编码,指标编码为空"
  86. return
  87. }
  88. if req.EdbInfoId <= 0 {
  89. br.Msg = "请输入指标ID!"
  90. br.ErrMsg = "请输入指标ID"
  91. return
  92. }
  93. // 获取指标详情
  94. edbInfo, err := models.GetEdbInfoByEdbCode(source, req.EdbCode)
  95. if err != nil {
  96. br.Msg = "指标不存在!"
  97. br.ErrMsg = "指标不存在"
  98. return
  99. }
  100. cacheKey = utils.CACHE_EDB_DATA_REFRESH + strconv.Itoa(source) + "_" + req.EdbCode
  101. if utils.Rc.IsExist(cacheKey) {
  102. br.Ret = 501
  103. br.Success = true
  104. br.Msg = "系统处理中,请稍后重试"
  105. return
  106. }
  107. dataUpdateTime := time.Now().Format(utils.FormatDateTime)
  108. utils.Rc.SetNX(cacheKey, 1, 1*time.Minute)
  109. err = models.RefreshEdbDataFromBloomberg(req.EdbInfoId, req.EdbCode, req.StartDate)
  110. if err != nil && err.Error() != utils.ErrNoRow() {
  111. br.Msg = "刷新指标信息失败!"
  112. br.ErrMsg = "刷新指标信息失败 RefreshEdbDataFromBloomberg,Err:" + err.Error()
  113. return
  114. }
  115. // 更新指标最大最小值
  116. erDataUpdateDate, err, errMsg := models.UnifiedModifyEdbInfoMaxAndMinInfoDataUpdate(edbInfo, dataUpdateTime)
  117. if err != nil {
  118. br.Msg = errMsg
  119. br.ErrMsg = err.Error()
  120. return
  121. }
  122. // 添加指标刷新成功日志
  123. if erDataUpdateDate != "" {
  124. _ = services.AddEdbInfoUpdateLog(edbInfo.EdbInfoId, 1, "", 1, "", 0, 0)
  125. } else {
  126. _ = services.AddEdbInfoUpdateLog(edbInfo.EdbInfoId, 1, "", 2, "未刷新到数据", 0, 0)
  127. }
  128. // 更新ES
  129. go logic.UpdateEs(edbInfo.EdbInfoId)
  130. br.Ret = 200
  131. br.Success = true
  132. br.Msg = "获取成功"
  133. }
  134. // AddRzdClassify
  135. // @Title 新增分类
  136. // @Description 获取分类
  137. // @Success 200 {object} models.BaseFromRzdClassify
  138. // @router /add/rzd/classify [post]
  139. func (this *BaseFromRzdController) AddRzdClassify() {
  140. br := new(models.BaseResponse).Init()
  141. var cacheKey string
  142. defer func() {
  143. if br.ErrMsg == "" {
  144. br.IsSendEmail = false
  145. }
  146. _ = utils.Rc.Delete(cacheKey)
  147. this.Data["json"] = br
  148. this.ServeJSON()
  149. }()
  150. var reqData struct {
  151. ClassifyName string `json:"ClassifyName"`
  152. ParentId int `json:"parentId"`
  153. }
  154. err := json.Unmarshal(this.Ctx.Input.RequestBody, &reqData)
  155. if err != nil {
  156. br.ErrMsg = "无法解析请求体"
  157. return
  158. }
  159. categoryName := reqData.ClassifyName
  160. if categoryName == "" {
  161. br.Msg = "请输入分类!"
  162. br.ErrMsg = "请输入分类"
  163. return
  164. }
  165. rzdClassify := models.BaseFromRzdClassify{
  166. ClassifyName: categoryName,
  167. ParentId: reqData.ParentId,
  168. CreateTime: utils.GetCurrentTime(),
  169. ModifyTime: utils.GetCurrentTime(),
  170. }
  171. lyClassify, err := models.AddRzdClassify(&rzdClassify)
  172. if err != nil {
  173. return
  174. }
  175. br.Ret = 200
  176. br.Success = true
  177. br.Data = lyClassify
  178. br.Msg = "获取成功"
  179. }
  180. // GetRzdClassifyByName
  181. // @Title 获取分类
  182. // @Description 获取分类
  183. // @Success 200 {object} models.BaseFromRzdClassify
  184. // @router /get/rzd/classify/by/name [post]
  185. func (this *BaseFromRzdController) GetRzdClassifyByName() {
  186. br := new(models.BaseResponse).Init()
  187. var cacheKey string
  188. defer func() {
  189. if br.ErrMsg == "" {
  190. br.IsSendEmail = false
  191. }
  192. _ = utils.Rc.Delete(cacheKey)
  193. this.Data["json"] = br
  194. this.ServeJSON()
  195. }()
  196. var reqData struct {
  197. ClassifyName string `json:"ClassifyName"`
  198. }
  199. err := json.Unmarshal(this.Ctx.Input.RequestBody, &reqData)
  200. if err != nil {
  201. br.ErrMsg = "无法解析请求体"
  202. return
  203. }
  204. categoryName := reqData.ClassifyName
  205. if categoryName == "" {
  206. br.Msg = "请输入分类!"
  207. br.ErrMsg = "请输入分类"
  208. return
  209. }
  210. lyClassify, err := models.GetRzdClassifyByName(categoryName)
  211. if err != nil {
  212. return
  213. }
  214. br.Ret = 200
  215. br.Success = true
  216. br.Data = lyClassify
  217. br.Msg = "获取成功"
  218. }
  219. // AddBatchRzdData
  220. // @Title 新增数据源指标数据
  221. // @Description 新增数据源指标数据
  222. // @Success 200 string "处理成功"
  223. // @router /add/batch/rzd/data [post]
  224. func (this *BaseFromRzdController) AddBatchRzdData() {
  225. br := new(models.BaseResponse).Init()
  226. var cacheKey string
  227. defer func() {
  228. if br.ErrMsg == "" {
  229. br.IsSendEmail = false
  230. }
  231. _ = utils.Rc.Delete(cacheKey)
  232. this.Data["json"] = br
  233. this.ServeJSON()
  234. }()
  235. var req []models.BaseFromRzdData
  236. fmt.Println(string(this.Ctx.Input.RequestBody))
  237. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  238. if err != nil {
  239. br.Msg = "参数解析异常!"
  240. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  241. return
  242. }
  243. err = models.AddRzdDataList(req)
  244. if err != nil {
  245. br.Msg = "新增指标数据失败!"
  246. br.ErrMsg = "新增指标数据失败,Err:" + err.Error()
  247. return
  248. }
  249. // 同步新增指标库数据
  250. // 判断是否存在于指标库
  251. // 获取指标详情
  252. /* 调用方对 指标库数据做了维护处理
  253. var dataList []models.EdbDataRzd
  254. for _, data := range req {
  255. edbInfo, err := models.GetEdbInfoByEdbCode(utils.DATA_SOURCE_RZD, data.IndexCode)
  256. if err != nil {
  257. br.Msg = "指标不存在!"
  258. br.ErrMsg = "指标不存在"
  259. return
  260. }
  261. if edbInfo.EdbInfoId == 0 {
  262. continue
  263. }
  264. dataRzd := models.EdbDataRzd{
  265. EdbInfoId: data.BaseFromRzdIndexId,
  266. DataTime: data.DataTime,
  267. Value: data.Value,
  268. EdbCode: data.IndexCode,
  269. CreateTime: utils.GetCurrentTime(),
  270. ModifyTime: utils.GetCurrentTime(),
  271. DataTimestamp: uint64(time.Now().UnixNano() / int64(time.Millisecond)),
  272. }
  273. dataList = append(dataList, dataRzd)
  274. }
  275. _ = models.AddRzdEdbDataList(dataList)*/
  276. br.Ret = 200
  277. br.Success = true
  278. br.Msg = "处理成功"
  279. }
  280. // AddRzdIndex
  281. // @Title 新增指标
  282. // @Description 新增指标
  283. // @Success 200 string "处理成功"
  284. // @router /add/rzd/index [post]
  285. func (this *BaseFromRzdController) AddRzdIndex() {
  286. br := new(models.BaseResponse).Init()
  287. var cacheKey string
  288. defer func() {
  289. if br.ErrMsg == "" {
  290. br.IsSendEmail = false
  291. }
  292. _ = utils.Rc.Delete(cacheKey)
  293. this.Data["json"] = br
  294. this.ServeJSON()
  295. }()
  296. var req models.BaseFromRzdIndex
  297. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  298. if err != nil {
  299. br.Msg = "参数解析异常!"
  300. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  301. return
  302. }
  303. indexId, err := models.AddRzdIndex(&req)
  304. if err != nil {
  305. return
  306. }
  307. br.Ret = 200
  308. br.Success = true
  309. br.Data = indexId
  310. br.Msg = "处理成功"
  311. }
  312. // GetRzdIndexDataByIndexIdAndDataTime
  313. // @Title 根据指标code和时间获取指标数据
  314. // @Description 根据指标code和时间获取指标数据
  315. // @Success 200 {object} models.BaseFromLyData
  316. // @router /get/rzd/index/data/by/code/and/time [post]
  317. func (this *BaseFromRzdController) GetRzdIndexDataByIndexIdAndDataTime() {
  318. br := new(models.BaseResponse).Init()
  319. var cacheKey string
  320. defer func() {
  321. if br.ErrMsg == "" {
  322. br.IsSendEmail = false
  323. }
  324. _ = utils.Rc.Delete(cacheKey)
  325. this.Data["json"] = br
  326. this.ServeJSON()
  327. }()
  328. var reqData struct {
  329. IndexCode string `json:"IndexCode"`
  330. DataTime string `json:"DataTime"`
  331. }
  332. err := json.Unmarshal(this.Ctx.Input.RequestBody, &reqData)
  333. if err != nil {
  334. br.ErrMsg = "无法解析请求体"
  335. return
  336. }
  337. indexCode := reqData.IndexCode
  338. if indexCode == "" {
  339. br.Msg = "请输入指标code!"
  340. br.ErrMsg = "请输入指标code"
  341. return
  342. }
  343. dataTime := reqData.DataTime
  344. if dataTime == "" {
  345. br.Msg = "请输入时间!"
  346. br.ErrMsg = "请输入时间"
  347. return
  348. }
  349. rzdData, err := models.GetRzdDataByIndexCodeAndDataTime(indexCode, dataTime)
  350. if err != nil {
  351. return
  352. }
  353. br.Ret = 200
  354. br.Success = true
  355. br.Data = rzdData
  356. br.Msg = "获取成功"
  357. }
  358. // UpdateRzdDataById
  359. // @Title 更新数据源指标数据
  360. // @Description 更新数据源指标数据
  361. // @Success 200 string "处理成功"
  362. // @router /update/rzd/data/by/id [post]
  363. func (this *BaseFromRzdController) UpdateRzdDataById() {
  364. br := new(models.BaseResponse).Init()
  365. var cacheKey string
  366. defer func() {
  367. if br.ErrMsg == "" {
  368. br.IsSendEmail = false
  369. }
  370. _ = utils.Rc.Delete(cacheKey)
  371. this.Data["json"] = br
  372. this.ServeJSON()
  373. }()
  374. var reqData struct {
  375. Id int `json:"Id"`
  376. Value float64 `json:"Value"`
  377. }
  378. err := json.Unmarshal(this.Ctx.Input.RequestBody, &reqData)
  379. if err != nil {
  380. br.ErrMsg = "无法解析请求体"
  381. return
  382. }
  383. id := reqData.Id
  384. if id == 0 {
  385. br.Msg = "请输入id!"
  386. br.ErrMsg = "请输入id"
  387. return
  388. }
  389. value := reqData.Value
  390. if value == 0 {
  391. br.Msg = "请输入值!"
  392. br.ErrMsg = "请输入值"
  393. return
  394. }
  395. err = models.UpdateRzdDataById(id, value)
  396. if err != nil {
  397. return
  398. }
  399. br.Ret = 200
  400. br.Success = true
  401. br.Msg = "处理成功"
  402. }
  403. // GetRzdEdbDataByIndexCodeAndDataTime
  404. // @Title 根据指标编码和精确日期获取指标库数据
  405. // @Description 根据指标编码和精确日期获取指标库数据
  406. // @Success 200 {object} []models.EdbDataRzd
  407. // @router /get/edb/rzd/data/by/code/and/time [post]
  408. func (this *BaseFromRzdController) GetRzdEdbDataByIndexCodeAndDataTime() {
  409. br := new(models.BaseResponse).Init()
  410. var cacheKey string
  411. defer func() {
  412. if br.ErrMsg == "" {
  413. br.IsSendEmail = false
  414. }
  415. _ = utils.Rc.Delete(cacheKey)
  416. this.Data["json"] = br
  417. this.ServeJSON()
  418. }()
  419. var reqData struct {
  420. IndexCode string `json:"IndexCode"`
  421. DataTime string `json:"DataTime"`
  422. }
  423. err := json.Unmarshal(this.Ctx.Input.RequestBody, &reqData)
  424. if err != nil {
  425. br.ErrMsg = "无法解析请求体"
  426. return
  427. }
  428. indexCode := reqData.IndexCode
  429. if indexCode == "" {
  430. br.Msg = "请输入指标id!"
  431. br.ErrMsg = "请输入指标id"
  432. return
  433. }
  434. dataTime := reqData.DataTime
  435. if dataTime == "" {
  436. br.Msg = "请输入时间!"
  437. br.ErrMsg = "请输入时间"
  438. return
  439. }
  440. lyEdbData, err := models.GetLyEdbDataByIndexCodeAndExactDataTime(indexCode, dataTime)
  441. if err != nil {
  442. return
  443. }
  444. br.Ret = 200
  445. br.Success = true
  446. br.Data = lyEdbData
  447. br.Msg = "获取成功"
  448. }
  449. // GetRzdEdbInfoByIndexCode
  450. // @Title 根据指标编码获取指标库指标
  451. // @Description 根据指标编码获取指标库指标
  452. // @Success 200 {object} []models.EdbDataRzd
  453. // @router /get/rzd/edb/info/by/code [post]
  454. func (this *BaseFromRzdController) GetRzdEdbInfoByIndexCode() {
  455. br := new(models.BaseResponse).Init()
  456. var cacheKey string
  457. defer func() {
  458. if br.ErrMsg == "" {
  459. br.IsSendEmail = false
  460. }
  461. _ = utils.Rc.Delete(cacheKey)
  462. this.Data["json"] = br
  463. this.ServeJSON()
  464. }()
  465. var reqData struct {
  466. IndexCode string `json:"IndexCode"`
  467. Source int `json:"Source"`
  468. }
  469. err := json.Unmarshal(this.Ctx.Input.RequestBody, &reqData)
  470. if err != nil {
  471. br.ErrMsg = "无法解析请求体"
  472. return
  473. }
  474. indexCode := reqData.IndexCode
  475. if indexCode == "" {
  476. br.Msg = "请输入指标id!"
  477. br.ErrMsg = "请输入指标id"
  478. return
  479. }
  480. source := reqData.Source
  481. if source == 0 {
  482. br.Msg = "请输入来源!"
  483. br.ErrMsg = "请输入来源"
  484. return
  485. }
  486. lyEdbData, err := models.GetEdbInfoByEdbCode(source, indexCode)
  487. if err != nil {
  488. return
  489. }
  490. br.Ret = 200
  491. br.Success = true
  492. br.Data = lyEdbData
  493. br.Msg = "获取成功"
  494. }
  495. // UpdateRzdEdbDataById
  496. // @Title 更新指标库数据 须根据指标编码和日期更新 仅适合月度数据
  497. // @Description 更新指标库数据 须根据指标编码和日期更新 仅适合月度数据
  498. // @Success 200 string "处理成功"
  499. // @router /update/rzd/edb/data/by/id [post]
  500. func (this *BaseFromRzdController) UpdateRzdEdbDataById() {
  501. br := new(models.BaseResponse).Init()
  502. var cacheKey string
  503. defer func() {
  504. if br.ErrMsg == "" {
  505. br.IsSendEmail = false
  506. }
  507. _ = utils.Rc.Delete(cacheKey)
  508. this.Data["json"] = br
  509. this.ServeJSON()
  510. }()
  511. var reqData struct {
  512. Id int `json:"Id"`
  513. Value float64 `json:"Value"`
  514. }
  515. err := json.Unmarshal(this.Ctx.Input.RequestBody, &reqData)
  516. if err != nil {
  517. br.ErrMsg = "无法解析请求体"
  518. return
  519. }
  520. id := reqData.Id
  521. if id == 0 {
  522. br.Msg = "请输入id!"
  523. br.ErrMsg = "请输入id"
  524. return
  525. }
  526. value := reqData.Value
  527. if value == 0 {
  528. br.Msg = "请输入值!"
  529. br.ErrMsg = "请输入值"
  530. return
  531. }
  532. err = models.UpdateRzdEdbDataById(id, value)
  533. if err != nil {
  534. return
  535. }
  536. br.Ret = 200
  537. br.Success = true
  538. br.Msg = "处理成功"
  539. }
  540. // GetRzdIndexByCode
  541. // @Title 查询指标编码是否存在
  542. // @Description 查询指标编码是否存在
  543. // @Success 200 {object} models.BaseFromLyIndex
  544. // @router /get/rzd/index/by/code [post]
  545. func (this *BaseFromRzdController) GetRzdIndexByCode() {
  546. br := new(models.BaseResponse).Init()
  547. var cacheKey string
  548. defer func() {
  549. if br.ErrMsg == "" {
  550. br.IsSendEmail = false
  551. }
  552. _ = utils.Rc.Delete(cacheKey)
  553. this.Data["json"] = br
  554. this.ServeJSON()
  555. }()
  556. var reqData struct {
  557. IndexCode string `json:"IndexCode"`
  558. }
  559. err := json.Unmarshal(this.Ctx.Input.RequestBody, &reqData)
  560. if err != nil {
  561. br.ErrMsg = "无法解析请求体"
  562. return
  563. }
  564. indexCode := reqData.IndexCode
  565. if indexCode == "" {
  566. br.Msg = "请输入指标id!"
  567. br.ErrMsg = "请输入指标id"
  568. return
  569. }
  570. rzdIndex, err := models.GetRzdIndexByCode(indexCode)
  571. if err != nil {
  572. return
  573. }
  574. br.Ret = 200
  575. br.Success = true
  576. br.Data = rzdIndex
  577. br.Msg = "获取成功"
  578. }
  579. // AddBatchRzdEdbData
  580. // @Title 批量增加睿咨得指标库数据
  581. // @Description 批量增加睿咨得指标库数据
  582. // @Success 200 string "处理成功"
  583. // @router /add/batch/rzd/edb/data [post]
  584. func (this *BaseFromRzdController) AddBatchRzdEdbData() {
  585. br := new(models.BaseResponse).Init()
  586. var cacheKey string
  587. defer func() {
  588. if br.ErrMsg == "" {
  589. br.IsSendEmail = false
  590. }
  591. _ = utils.Rc.Delete(cacheKey)
  592. this.Data["json"] = br
  593. this.ServeJSON()
  594. }()
  595. var req []models.EdbDataRzd
  596. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  597. if err != nil {
  598. br.Msg = "参数解析异常!"
  599. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  600. return
  601. }
  602. err = models.AddRzdEdbDataList(req)
  603. if err != nil {
  604. return
  605. }
  606. br.Ret = 200
  607. br.Success = true
  608. br.Msg = "处理成功"
  609. }
  610. // UpdateRzdEdbData
  611. // @Title 修改指标数据
  612. // @Description 修改指标数据
  613. // @Success 200 string "处理成功"
  614. // @router /update/rzd/edb/data [post]
  615. func (this *BaseFromRzdController) UpdateRzdEdbData() {
  616. br := new(models.BaseResponse).Init()
  617. var cacheKey string
  618. defer func() {
  619. if br.ErrMsg == "" {
  620. br.IsSendEmail = false
  621. }
  622. _ = utils.Rc.Delete(cacheKey)
  623. this.Data["json"] = br
  624. this.ServeJSON()
  625. }()
  626. var req models.BaseFromRzdData
  627. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  628. if err != nil {
  629. br.Msg = "参数解析异常!"
  630. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  631. return
  632. }
  633. err = models.UpdateRzdData(&req)
  634. if err != nil {
  635. return
  636. }
  637. // 同步更新指标库数据
  638. edbInfo, err := models.GetEdbInfoByEdbCode(utils.DATA_SOURCE_RZD, req.IndexCode)
  639. if err != nil {
  640. br.Msg = "指标不存在!"
  641. br.ErrMsg = "指标不存在"
  642. return
  643. }
  644. if edbInfo.EdbInfoId > 0 {
  645. err = models.UpdateRzdEdbDataByIndexCodeAndDataTime(req.BaseFromRzdIndexId, req.DataTime, req.Value)
  646. if err != nil {
  647. return
  648. }
  649. }
  650. br.Ret = 200
  651. br.Success = true
  652. br.Msg = "处理成功"
  653. }