base_from_rzd.go 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708
  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. var dataList []models.EdbDataRzd
  253. for _, data := range req {
  254. edbInfo, err := models.GetEdbInfoByEdbCode(utils.DATA_SOURCE_RZD, data.IndexCode)
  255. if err != nil {
  256. br.Msg = "指标不存在!"
  257. br.ErrMsg = "指标不存在"
  258. return
  259. }
  260. if edbInfo.EdbInfoId == 0 {
  261. continue
  262. }
  263. dataRzd := models.EdbDataRzd{
  264. EdbInfoId: data.BaseFromRzdIndexId,
  265. DataTime: data.DataTime,
  266. Value: data.Value,
  267. EdbCode: data.IndexCode,
  268. CreateTime: utils.GetCurrentTime(),
  269. ModifyTime: utils.GetCurrentTime(),
  270. DataTimestamp: uint64(time.Now().UnixNano() / int64(time.Millisecond)),
  271. }
  272. dataList = append(dataList, dataRzd)
  273. }
  274. _ = models.AddRzdEdbDataList(dataList)
  275. br.Ret = 200
  276. br.Success = true
  277. br.Msg = "处理成功"
  278. }
  279. // AddRzdIndex
  280. // @Title 新增指标
  281. // @Description 新增指标
  282. // @Success 200 string "处理成功"
  283. // @router /add/rzd/index [post]
  284. func (this *BaseFromRzdController) AddRzdIndex() {
  285. br := new(models.BaseResponse).Init()
  286. var cacheKey string
  287. defer func() {
  288. if br.ErrMsg == "" {
  289. br.IsSendEmail = false
  290. }
  291. _ = utils.Rc.Delete(cacheKey)
  292. this.Data["json"] = br
  293. this.ServeJSON()
  294. }()
  295. var req models.BaseFromRzdIndex
  296. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  297. if err != nil {
  298. br.Msg = "参数解析异常!"
  299. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  300. return
  301. }
  302. indexId, err := models.AddRzdIndex(&req)
  303. if err != nil {
  304. return
  305. }
  306. br.Ret = 200
  307. br.Success = true
  308. br.Data = indexId
  309. br.Msg = "处理成功"
  310. }
  311. // GetRzdIndexDataByIndexIdAndDataTime
  312. // @Title 根据指标code和时间获取指标数据
  313. // @Description 根据指标code和时间获取指标数据
  314. // @Success 200 {object} models.BaseFromLyData
  315. // @router /get/rzd/index/data/by/code/and/time [post]
  316. func (this *BaseFromRzdController) GetRzdIndexDataByIndexIdAndDataTime() {
  317. br := new(models.BaseResponse).Init()
  318. var cacheKey string
  319. defer func() {
  320. if br.ErrMsg == "" {
  321. br.IsSendEmail = false
  322. }
  323. _ = utils.Rc.Delete(cacheKey)
  324. this.Data["json"] = br
  325. this.ServeJSON()
  326. }()
  327. var reqData struct {
  328. IndexCode string `json:"IndexCode"`
  329. DataTime string `json:"DataTime"`
  330. }
  331. err := json.Unmarshal(this.Ctx.Input.RequestBody, &reqData)
  332. if err != nil {
  333. br.ErrMsg = "无法解析请求体"
  334. return
  335. }
  336. indexCode := reqData.IndexCode
  337. if indexCode == "" {
  338. br.Msg = "请输入指标code!"
  339. br.ErrMsg = "请输入指标code"
  340. return
  341. }
  342. dataTime := reqData.DataTime
  343. if dataTime == "" {
  344. br.Msg = "请输入时间!"
  345. br.ErrMsg = "请输入时间"
  346. return
  347. }
  348. rzdData, err := models.GetRzdDataByIndexCodeAndDataTime(indexCode, dataTime)
  349. if err != nil {
  350. return
  351. }
  352. br.Ret = 200
  353. br.Success = true
  354. br.Data = rzdData
  355. br.Msg = "获取成功"
  356. }
  357. // UpdateRzdDataById
  358. // @Title 更新数据源指标数据
  359. // @Description 更新数据源指标数据
  360. // @Success 200 string "处理成功"
  361. // @router /update/rzd/data/by/id [post]
  362. func (this *BaseFromRzdController) UpdateRzdDataById() {
  363. br := new(models.BaseResponse).Init()
  364. var cacheKey string
  365. defer func() {
  366. if br.ErrMsg == "" {
  367. br.IsSendEmail = false
  368. }
  369. _ = utils.Rc.Delete(cacheKey)
  370. this.Data["json"] = br
  371. this.ServeJSON()
  372. }()
  373. var reqData struct {
  374. Id int `json:"Id"`
  375. Value float64 `json:"Value"`
  376. }
  377. err := json.Unmarshal(this.Ctx.Input.RequestBody, &reqData)
  378. if err != nil {
  379. br.ErrMsg = "无法解析请求体"
  380. return
  381. }
  382. id := reqData.Id
  383. if id == 0 {
  384. br.Msg = "请输入id!"
  385. br.ErrMsg = "请输入id"
  386. return
  387. }
  388. value := reqData.Value
  389. if value == 0 {
  390. br.Msg = "请输入值!"
  391. br.ErrMsg = "请输入值"
  392. return
  393. }
  394. err = models.UpdateRzdDataById(id, value)
  395. if err != nil {
  396. return
  397. }
  398. br.Ret = 200
  399. br.Success = true
  400. br.Msg = "处理成功"
  401. }
  402. // GetRzdEdbDataByIndexCodeAndDataTime
  403. // @Title 根据指标编码和精确日期获取指标库数据
  404. // @Description 根据指标编码和精确日期获取指标库数据
  405. // @Success 200 {object} []models.EdbDataRzd
  406. // @router /get/edb/rzd/data/by/code/and/time [post]
  407. func (this *BaseFromRzdController) GetRzdEdbDataByIndexCodeAndDataTime() {
  408. br := new(models.BaseResponse).Init()
  409. var cacheKey string
  410. defer func() {
  411. if br.ErrMsg == "" {
  412. br.IsSendEmail = false
  413. }
  414. _ = utils.Rc.Delete(cacheKey)
  415. this.Data["json"] = br
  416. this.ServeJSON()
  417. }()
  418. var reqData struct {
  419. IndexCode string `json:"IndexCode"`
  420. DataTime string `json:"DataTime"`
  421. }
  422. err := json.Unmarshal(this.Ctx.Input.RequestBody, &reqData)
  423. if err != nil {
  424. br.ErrMsg = "无法解析请求体"
  425. return
  426. }
  427. indexCode := reqData.IndexCode
  428. if indexCode == "" {
  429. br.Msg = "请输入指标id!"
  430. br.ErrMsg = "请输入指标id"
  431. return
  432. }
  433. dataTime := reqData.DataTime
  434. if dataTime == "" {
  435. br.Msg = "请输入时间!"
  436. br.ErrMsg = "请输入时间"
  437. return
  438. }
  439. lyEdbData, err := models.GetLyEdbDataByIndexCodeAndExactDataTime(indexCode, dataTime)
  440. if err != nil {
  441. return
  442. }
  443. br.Ret = 200
  444. br.Success = true
  445. br.Data = lyEdbData
  446. br.Msg = "获取成功"
  447. }
  448. // GetRzdEdbInfoByIndexCode
  449. // @Title 根据指标编码获取指标库指标
  450. // @Description 根据指标编码获取指标库指标
  451. // @Success 200 {object} []models.EdbDataRzd
  452. // @router /get/rzd/edb/info/by/code [post]
  453. func (this *BaseFromRzdController) GetRzdEdbInfoByIndexCode() {
  454. br := new(models.BaseResponse).Init()
  455. var cacheKey string
  456. defer func() {
  457. if br.ErrMsg == "" {
  458. br.IsSendEmail = false
  459. }
  460. _ = utils.Rc.Delete(cacheKey)
  461. this.Data["json"] = br
  462. this.ServeJSON()
  463. }()
  464. var reqData struct {
  465. IndexCode string `json:"IndexCode"`
  466. Source int `json:"Source"`
  467. }
  468. err := json.Unmarshal(this.Ctx.Input.RequestBody, &reqData)
  469. if err != nil {
  470. br.ErrMsg = "无法解析请求体"
  471. return
  472. }
  473. indexCode := reqData.IndexCode
  474. if indexCode == "" {
  475. br.Msg = "请输入指标id!"
  476. br.ErrMsg = "请输入指标id"
  477. return
  478. }
  479. source := reqData.Source
  480. if source == 0 {
  481. br.Msg = "请输入来源!"
  482. br.ErrMsg = "请输入来源"
  483. return
  484. }
  485. lyEdbData, err := models.GetEdbInfoByEdbCode(source, indexCode)
  486. if err != nil {
  487. return
  488. }
  489. br.Ret = 200
  490. br.Success = true
  491. br.Data = lyEdbData
  492. br.Msg = "获取成功"
  493. }
  494. // UpdateRzdEdbDataById
  495. // @Title 更新指标库数据 须根据指标编码和日期更新 仅适合月度数据
  496. // @Description 更新指标库数据 须根据指标编码和日期更新 仅适合月度数据
  497. // @Success 200 string "处理成功"
  498. // @router /update/rzd/edb/data/by/id [post]
  499. func (this *BaseFromRzdController) UpdateRzdEdbDataById() {
  500. br := new(models.BaseResponse).Init()
  501. var cacheKey string
  502. defer func() {
  503. if br.ErrMsg == "" {
  504. br.IsSendEmail = false
  505. }
  506. _ = utils.Rc.Delete(cacheKey)
  507. this.Data["json"] = br
  508. this.ServeJSON()
  509. }()
  510. var reqData struct {
  511. Id int `json:"Id"`
  512. Value float64 `json:"Value"`
  513. }
  514. err := json.Unmarshal(this.Ctx.Input.RequestBody, &reqData)
  515. if err != nil {
  516. br.ErrMsg = "无法解析请求体"
  517. return
  518. }
  519. id := reqData.Id
  520. if id == 0 {
  521. br.Msg = "请输入id!"
  522. br.ErrMsg = "请输入id"
  523. return
  524. }
  525. value := reqData.Value
  526. if value == 0 {
  527. br.Msg = "请输入值!"
  528. br.ErrMsg = "请输入值"
  529. return
  530. }
  531. err = models.UpdateRzdEdbDataById(id, value)
  532. if err != nil {
  533. return
  534. }
  535. br.Ret = 200
  536. br.Success = true
  537. br.Msg = "处理成功"
  538. }
  539. // GetRzdIndexByCode
  540. // @Title 查询指标编码是否存在
  541. // @Description 查询指标编码是否存在
  542. // @Success 200 {object} models.BaseFromLyIndex
  543. // @router /get/rzd/index/by/code [post]
  544. func (this *BaseFromRzdController) GetRzdIndexByCode() {
  545. br := new(models.BaseResponse).Init()
  546. var cacheKey string
  547. defer func() {
  548. if br.ErrMsg == "" {
  549. br.IsSendEmail = false
  550. }
  551. _ = utils.Rc.Delete(cacheKey)
  552. this.Data["json"] = br
  553. this.ServeJSON()
  554. }()
  555. var reqData struct {
  556. IndexCode string `json:"IndexCode"`
  557. }
  558. err := json.Unmarshal(this.Ctx.Input.RequestBody, &reqData)
  559. if err != nil {
  560. br.ErrMsg = "无法解析请求体"
  561. return
  562. }
  563. indexCode := reqData.IndexCode
  564. if indexCode == "" {
  565. br.Msg = "请输入指标id!"
  566. br.ErrMsg = "请输入指标id"
  567. return
  568. }
  569. rzdIndex, err := models.GetRzdIndexByCode(indexCode)
  570. if err != nil {
  571. return
  572. }
  573. br.Ret = 200
  574. br.Success = true
  575. br.Data = rzdIndex
  576. br.Msg = "获取成功"
  577. }
  578. // AddBatchRzdEdbData
  579. // @Title 批量增加睿咨得指标库数据
  580. // @Description 批量增加睿咨得指标库数据
  581. // @Success 200 string "处理成功"
  582. // @router /add/batch/rzd/edb/data [post]
  583. func (this *BaseFromRzdController) AddBatchRzdEdbData() {
  584. br := new(models.BaseResponse).Init()
  585. var cacheKey string
  586. defer func() {
  587. if br.ErrMsg == "" {
  588. br.IsSendEmail = false
  589. }
  590. _ = utils.Rc.Delete(cacheKey)
  591. this.Data["json"] = br
  592. this.ServeJSON()
  593. }()
  594. var req []models.EdbDataRzd
  595. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  596. if err != nil {
  597. br.Msg = "参数解析异常!"
  598. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  599. return
  600. }
  601. err = models.AddRzdEdbDataList(req)
  602. if err != nil {
  603. return
  604. }
  605. br.Ret = 200
  606. br.Success = true
  607. br.Msg = "处理成功"
  608. }
  609. // UpdateRzdEdbData
  610. // @Title 修改指标数据
  611. // @Description 修改指标数据
  612. // @Success 200 string "处理成功"
  613. // @router /update/rzd/edb/data [post]
  614. func (this *BaseFromRzdController) UpdateRzdEdbData() {
  615. br := new(models.BaseResponse).Init()
  616. var cacheKey string
  617. defer func() {
  618. if br.ErrMsg == "" {
  619. br.IsSendEmail = false
  620. }
  621. _ = utils.Rc.Delete(cacheKey)
  622. this.Data["json"] = br
  623. this.ServeJSON()
  624. }()
  625. var req models.BaseFromRzdData
  626. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  627. if err != nil {
  628. br.Msg = "参数解析异常!"
  629. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  630. return
  631. }
  632. err = models.UpdateRzdData(&req)
  633. if err != nil {
  634. return
  635. }
  636. // 同步更新指标库数据
  637. edbInfo, err := models.GetEdbInfoByEdbCode(utils.DATA_SOURCE_RZD, req.IndexCode)
  638. if err != nil {
  639. br.Msg = "指标不存在!"
  640. br.ErrMsg = "指标不存在"
  641. return
  642. }
  643. if edbInfo.EdbInfoId > 0 {
  644. err = models.UpdateRzdEdbDataByIndexCodeAndDataTime(req.BaseFromRzdIndexId, req.DataTime, req.Value)
  645. if err != nil {
  646. return
  647. }
  648. }
  649. br.Ret = 200
  650. br.Success = true
  651. br.Msg = "处理成功"
  652. }