base_from_rzd.go 17 KB

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