base_from_ly.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765
  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 BaseFromLyController struct {
  14. BaseAuthController
  15. }
  16. // Add
  17. // @Title 新增粮油商务网指标
  18. // @Description 新增粮油商务网指标
  19. // @router /add [post]
  20. func (this *BaseFromLyController) 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_LY
  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.AddEdbDataFromLy(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 *BaseFromLyController) 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_LY
  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. // GetLyClassifyByName
  135. // @Title 获取分类
  136. // @Description 获取分类
  137. // @Success 200 {object} models.BaseFromLyClassify
  138. // @router /get/ly/classify/by/name [post]
  139. func (this *BaseFromLyController) GetLyClassifyByName() {
  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. CategoryName string `json:"CategoryName"`
  152. }
  153. err := json.Unmarshal(this.Ctx.Input.RequestBody, &reqData)
  154. if err != nil {
  155. br.ErrMsg = "无法解析请求体"
  156. return
  157. }
  158. categoryName := reqData.CategoryName
  159. if categoryName == "" {
  160. br.Msg = "请输入分类!"
  161. br.ErrMsg = "请输入分类"
  162. return
  163. }
  164. lyClassify, err := models.GetLyClassifyByName(categoryName)
  165. if err != nil {
  166. return
  167. }
  168. br.Ret = 200
  169. br.Success = true
  170. br.Data = lyClassify
  171. br.Msg = "获取成功"
  172. }
  173. // GetLyIndexRecordByUrl
  174. // @Title 根据url获取指标已读取记录
  175. // @Description 根据url获取指标已读取记录
  176. // @Success 200 {object} models.BaseFromLyIndexRecord
  177. // @router /get/ly/index/record/by/url [post]
  178. func (this *BaseFromLyController) GetLyIndexRecordByUrl() {
  179. br := new(models.BaseResponse).Init()
  180. var cacheKey string
  181. defer func() {
  182. if br.ErrMsg == "" {
  183. br.IsSendEmail = false
  184. }
  185. _ = utils.Rc.Delete(cacheKey)
  186. this.Data["json"] = br
  187. this.ServeJSON()
  188. }()
  189. var reqData struct {
  190. Url string `json:"Url"`
  191. }
  192. err := json.Unmarshal(this.Ctx.Input.RequestBody, &reqData)
  193. if err != nil {
  194. br.ErrMsg = "无法解析请求体"
  195. return
  196. }
  197. url := reqData.Url
  198. if url == "" {
  199. br.Msg = "请输入地址链接!"
  200. br.ErrMsg = "请输入地址链接"
  201. return
  202. }
  203. lyIndexRecord, err := models.GetLyIndexRecordByUrl(url)
  204. if err != nil {
  205. return
  206. }
  207. br.Ret = 200
  208. br.Success = true
  209. br.Data = lyIndexRecord
  210. br.Msg = "获取成功"
  211. }
  212. // AddLyIndexRecord
  213. // @Title 维护指标数据读取进度到数据库
  214. // @Description 维护指标数据读取进度到数据库
  215. // @Success 200 string "处理成功"
  216. // @router /add/ly/index/record [post]
  217. func (this *BaseFromLyController) AddLyIndexRecord() {
  218. br := new(models.BaseResponse).Init()
  219. var cacheKey string
  220. defer func() {
  221. if br.ErrMsg == "" {
  222. br.IsSendEmail = false
  223. }
  224. _ = utils.Rc.Delete(cacheKey)
  225. this.Data["json"] = br
  226. this.ServeJSON()
  227. }()
  228. var req models.BaseFromLyIndexRecord
  229. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  230. if err != nil {
  231. br.Msg = "参数解析异常!"
  232. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  233. return
  234. }
  235. id, err := models.AddLyIndexRecord(&req)
  236. if err != nil {
  237. return
  238. }
  239. br.Ret = 200
  240. br.Success = true
  241. br.Data = id
  242. br.Msg = "处理成功"
  243. }
  244. // AddLyDataList
  245. // @Title 新增指标数据
  246. // @Description 新增指标数据列表
  247. // @Success 200 string "处理成功"
  248. // @router /add/ly/data/list [post]
  249. func (this *BaseFromLyController) AddLyDataList() {
  250. br := new(models.BaseResponse).Init()
  251. var cacheKey string
  252. defer func() {
  253. if br.ErrMsg == "" {
  254. br.IsSendEmail = false
  255. }
  256. _ = utils.Rc.Delete(cacheKey)
  257. this.Data["json"] = br
  258. this.ServeJSON()
  259. }()
  260. var req []models.BaseFromLyData
  261. fmt.Println(string(this.Ctx.Input.RequestBody))
  262. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  263. if err != nil {
  264. br.Msg = "参数解析异常!"
  265. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  266. return
  267. }
  268. err = models.AddLyDataList(req)
  269. if err != nil {
  270. br.Msg = "新增指标数据失败!"
  271. br.ErrMsg = "新增指标数据失败,Err:" + err.Error()
  272. return
  273. }
  274. br.Ret = 200
  275. br.Success = true
  276. br.Msg = "处理成功"
  277. }
  278. // AddLyIndex
  279. // @Title 新增指标
  280. // @Description 新增指标
  281. // @Success 200 string "处理成功"
  282. // @router /add/ly/index [post]
  283. func (this *BaseFromLyController) AddLyIndex() {
  284. br := new(models.BaseResponse).Init()
  285. var cacheKey string
  286. defer func() {
  287. if br.ErrMsg == "" {
  288. br.IsSendEmail = false
  289. }
  290. _ = utils.Rc.Delete(cacheKey)
  291. this.Data["json"] = br
  292. this.ServeJSON()
  293. }()
  294. var req models.BaseFromLyIndex
  295. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  296. if err != nil {
  297. br.Msg = "参数解析异常!"
  298. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  299. return
  300. }
  301. indexId, err := models.AddLyIndex(&req)
  302. if err != nil {
  303. return
  304. }
  305. br.Ret = 200
  306. br.Success = true
  307. br.Data = indexId
  308. br.Msg = "处理成功"
  309. }
  310. // GetLyDataByIndexIdAndDataTime
  311. // @Title 根据指标id和时间获取指标数据
  312. // @Description 根据指标id和时间获取指标数据
  313. // @Success 200 {object} models.BaseFromLyData
  314. // @router /get/ly/data/by/index/id/and/data/time [post]
  315. func (this *BaseFromLyController) GetLyDataByIndexIdAndDataTime() {
  316. br := new(models.BaseResponse).Init()
  317. var cacheKey string
  318. defer func() {
  319. if br.ErrMsg == "" {
  320. br.IsSendEmail = false
  321. }
  322. _ = utils.Rc.Delete(cacheKey)
  323. this.Data["json"] = br
  324. this.ServeJSON()
  325. }()
  326. var reqData struct {
  327. IndexId int `json:"IndexId"`
  328. DataTime string `json:"DataTime"`
  329. }
  330. err := json.Unmarshal(this.Ctx.Input.RequestBody, &reqData)
  331. if err != nil {
  332. br.ErrMsg = "无法解析请求体"
  333. return
  334. }
  335. indexId := reqData.IndexId
  336. if indexId == 0 {
  337. br.Msg = "请输入指标id!"
  338. br.ErrMsg = "请输入指标id"
  339. return
  340. }
  341. dataTime := reqData.DataTime
  342. if dataTime == "" {
  343. br.Msg = "请输入时间!"
  344. br.ErrMsg = "请输入时间"
  345. return
  346. }
  347. lyData, err := models.GetLyDataByIndexIdAndDataTime(indexId, dataTime)
  348. if err != nil {
  349. return
  350. }
  351. br.Ret = 200
  352. br.Success = true
  353. br.Data = lyData
  354. br.Msg = "获取成功"
  355. }
  356. // GetLyDataByIndexIdAndDataTimeYM
  357. // @Title 根据指标id和年月时间获取指标数据
  358. // @Description 根据指标id和年月时间获取指标数据
  359. // @Success 200 {object} models.BaseFromLyData
  360. // @router /get/ly/data/by/index/id/and/data/time/ym [post]
  361. func (this *BaseFromLyController) GetLyDataByIndexIdAndDataTimeYM() {
  362. br := new(models.BaseResponse).Init()
  363. var cacheKey string
  364. defer func() {
  365. if br.ErrMsg == "" {
  366. br.IsSendEmail = false
  367. }
  368. _ = utils.Rc.Delete(cacheKey)
  369. this.Data["json"] = br
  370. this.ServeJSON()
  371. }()
  372. var reqData struct {
  373. IndexId int `json:"IndexId"`
  374. YearMonth string `json:"YearMonth"`
  375. }
  376. err := json.Unmarshal(this.Ctx.Input.RequestBody, &reqData)
  377. if err != nil {
  378. br.ErrMsg = "无法解析请求体"
  379. return
  380. }
  381. indexId := reqData.IndexId
  382. if indexId == 0 {
  383. br.Msg = "请输入指标id!"
  384. br.ErrMsg = "请输入指标id"
  385. return
  386. }
  387. yearMonth := reqData.YearMonth
  388. if yearMonth == "" {
  389. br.Msg = "请输入时间!"
  390. br.ErrMsg = "请输入时间"
  391. return
  392. }
  393. lyData, err := models.GetLyDataByIndexIdAndDataTimeYM(indexId, yearMonth)
  394. if err != nil {
  395. return
  396. }
  397. br.Ret = 200
  398. br.Success = true
  399. br.Data = lyData
  400. br.Msg = "获取成功"
  401. }
  402. // UpdateLyDataById
  403. // @Title 更新数据源指标数据
  404. // @Description 更新数据源指标数据
  405. // @Success 200 string "处理成功"
  406. // @router /update/ly/data/by/id [post]
  407. func (this *BaseFromLyController) UpdateLyDataById() {
  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. Id int `json:"Id"`
  420. Value float64 `json:"Value"`
  421. }
  422. err := json.Unmarshal(this.Ctx.Input.RequestBody, &reqData)
  423. if err != nil {
  424. br.ErrMsg = "无法解析请求体"
  425. return
  426. }
  427. id := reqData.Id
  428. if id == 0 {
  429. br.Msg = "请输入id!"
  430. br.ErrMsg = "请输入id"
  431. return
  432. }
  433. value := reqData.Value
  434. if value == 0 {
  435. br.Msg = "请输入值!"
  436. br.ErrMsg = "请输入值"
  437. return
  438. }
  439. err = models.UpdateLyDataById(id, value)
  440. if err != nil {
  441. return
  442. }
  443. br.Ret = 200
  444. br.Success = true
  445. br.Msg = "处理成功"
  446. }
  447. // GetLyEdbDataByIndexCodeAndDataTime
  448. // @Title 根据指标编码和模糊日期获取指标库数据
  449. // @Description 根据指标编码和模糊日期获取指标库数据
  450. // @Success 200 {object} []models.EdbDataLy
  451. // @router /get/ly/edb/data/by/index/code/and/data/time [post]
  452. func (this *BaseFromLyController) GetLyEdbDataByIndexCodeAndDataTime() {
  453. br := new(models.BaseResponse).Init()
  454. var cacheKey string
  455. defer func() {
  456. if br.ErrMsg == "" {
  457. br.IsSendEmail = false
  458. }
  459. _ = utils.Rc.Delete(cacheKey)
  460. this.Data["json"] = br
  461. this.ServeJSON()
  462. }()
  463. var reqData struct {
  464. IndexCode string `json:"IndexCode"`
  465. DataTime string `json:"DataTime"`
  466. }
  467. err := json.Unmarshal(this.Ctx.Input.RequestBody, &reqData)
  468. if err != nil {
  469. br.ErrMsg = "无法解析请求体"
  470. return
  471. }
  472. indexCode := reqData.IndexCode
  473. if indexCode == "" {
  474. br.Msg = "请输入指标id!"
  475. br.ErrMsg = "请输入指标id"
  476. return
  477. }
  478. dataTime := reqData.DataTime
  479. if dataTime == "" {
  480. br.Msg = "请输入时间!"
  481. br.ErrMsg = "请输入时间"
  482. return
  483. }
  484. lyEdbData, err := models.GetLyEdbDataByIndexCodeAndDataTime(indexCode, dataTime)
  485. if err != nil {
  486. return
  487. }
  488. br.Ret = 200
  489. br.Success = true
  490. br.Data = lyEdbData
  491. br.Msg = "获取成功"
  492. }
  493. // GetLyEdbDataByIndexCodeAndExactDataTime
  494. // @Title 根据指标编码和精确日期获取指标库数据
  495. // @Description 根据指标编码和精确日期获取指标库数据
  496. // @Success 200 {object} []models.EdbDataLy
  497. // @router /get/ly/edb/data/by/index/code/and/exact/data/time [post]
  498. func (this *BaseFromLyController) GetLyEdbDataByIndexCodeAndExactDataTime() {
  499. br := new(models.BaseResponse).Init()
  500. var cacheKey string
  501. defer func() {
  502. if br.ErrMsg == "" {
  503. br.IsSendEmail = false
  504. }
  505. _ = utils.Rc.Delete(cacheKey)
  506. this.Data["json"] = br
  507. this.ServeJSON()
  508. }()
  509. var reqData struct {
  510. IndexCode string `json:"IndexCode"`
  511. DataTime string `json:"DataTime"`
  512. }
  513. err := json.Unmarshal(this.Ctx.Input.RequestBody, &reqData)
  514. if err != nil {
  515. br.ErrMsg = "无法解析请求体"
  516. return
  517. }
  518. indexCode := reqData.IndexCode
  519. if indexCode == "" {
  520. br.Msg = "请输入指标id!"
  521. br.ErrMsg = "请输入指标id"
  522. return
  523. }
  524. dataTime := reqData.DataTime
  525. if dataTime == "" {
  526. br.Msg = "请输入时间!"
  527. br.ErrMsg = "请输入时间"
  528. return
  529. }
  530. lyEdbData, err := models.GetLyEdbDataByIndexCodeAndExactDataTime(indexCode, dataTime)
  531. if err != nil {
  532. return
  533. }
  534. br.Ret = 200
  535. br.Success = true
  536. br.Data = lyEdbData
  537. br.Msg = "获取成功"
  538. }
  539. // UpdateLyEdbDataById
  540. // @Title 更新指标库数据 须根据指标编码和日期更新 仅适合月度数据
  541. // @Description 更新指标库数据 须根据指标编码和日期更新 仅适合月度数据
  542. // @Success 200 string "处理成功"
  543. // @router /update/ly/edb/data/by/id [post]
  544. func (this *BaseFromLyController) UpdateLyEdbDataById() {
  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. Id int `json:"Id"`
  557. Value float64 `json:"Value"`
  558. }
  559. err := json.Unmarshal(this.Ctx.Input.RequestBody, &reqData)
  560. if err != nil {
  561. br.ErrMsg = "无法解析请求体"
  562. return
  563. }
  564. id := reqData.Id
  565. if id == 0 {
  566. br.Msg = "请输入id!"
  567. br.ErrMsg = "请输入id"
  568. return
  569. }
  570. value := reqData.Value
  571. if value == 0 {
  572. br.Msg = "请输入值!"
  573. br.ErrMsg = "请输入值"
  574. return
  575. }
  576. err = models.UpdateLyEdbDataById(id, value)
  577. if err != nil {
  578. return
  579. }
  580. br.Ret = 200
  581. br.Success = true
  582. br.Msg = "处理成功"
  583. }
  584. // GetLyIndexByCode
  585. // @Title 查询指标编码是否存在
  586. // @Description 查询指标编码是否存在
  587. // @Success 200 {object} models.BaseFromLyIndex
  588. // @router /get/ly/index/by/code [post]
  589. func (this *BaseFromLyController) GetLyIndexByCode() {
  590. br := new(models.BaseResponse).Init()
  591. var cacheKey string
  592. defer func() {
  593. if br.ErrMsg == "" {
  594. br.IsSendEmail = false
  595. }
  596. _ = utils.Rc.Delete(cacheKey)
  597. this.Data["json"] = br
  598. this.ServeJSON()
  599. }()
  600. var reqData struct {
  601. IndexCode string `json:"IndexCode"`
  602. }
  603. err := json.Unmarshal(this.Ctx.Input.RequestBody, &reqData)
  604. if err != nil {
  605. br.ErrMsg = "无法解析请求体"
  606. return
  607. }
  608. indexCode := reqData.IndexCode
  609. if indexCode == "" {
  610. br.Msg = "请输入指标id!"
  611. br.ErrMsg = "请输入指标id"
  612. return
  613. }
  614. lyIndex, err := models.GetLyIndexByCode(indexCode)
  615. if err != nil {
  616. return
  617. }
  618. br.Ret = 200
  619. br.Success = true
  620. br.Data = lyIndex
  621. br.Msg = "获取成功"
  622. }
  623. // GetEdbInfoByIndexCode
  624. // @Title 根据指标code获取指标信息
  625. // @Description 根据指标code获取指标信息
  626. // @Success 200 {object} models.EdbInfo
  627. // @router /get/edb/info/by/index/code [post]
  628. func (this *BaseFromLyController) GetEdbInfoByIndexCode() {
  629. br := new(models.BaseResponse).Init()
  630. var cacheKey string
  631. defer func() {
  632. if br.ErrMsg == "" {
  633. br.IsSendEmail = false
  634. }
  635. _ = utils.Rc.Delete(cacheKey)
  636. this.Data["json"] = br
  637. this.ServeJSON()
  638. }()
  639. var reqData struct {
  640. IndexCode string `json:"IndexCode"`
  641. Source int `json:"Source"`
  642. }
  643. err := json.Unmarshal(this.Ctx.Input.RequestBody, &reqData)
  644. if err != nil {
  645. br.ErrMsg = "无法解析请求体"
  646. return
  647. }
  648. indexCode := reqData.IndexCode
  649. if indexCode == "" {
  650. br.Msg = "请输入指标id!"
  651. br.ErrMsg = "请输入指标id"
  652. return
  653. }
  654. source := reqData.Source
  655. if source == 0 {
  656. br.Msg = "请输入来源!"
  657. br.ErrMsg = "请输入来源"
  658. return
  659. }
  660. lyEdbData, err := models.GetEdbInfoByEdbCode(source, indexCode)
  661. if err != nil {
  662. return
  663. }
  664. br.Ret = 200
  665. br.Success = true
  666. br.Data = lyEdbData
  667. br.Msg = "获取成功"
  668. }
  669. // AddBatchLyEdbData
  670. // @Title 批量增加粮油指标库数据
  671. // @Description 批量增加粮油指标库数据
  672. // @Success 200 string "处理成功"
  673. // @router /add/batch/ly/edb/data [post]
  674. func (this *BaseFromLyController) AddBatchLyEdbData() {
  675. br := new(models.BaseResponse).Init()
  676. var cacheKey string
  677. defer func() {
  678. if br.ErrMsg == "" {
  679. br.IsSendEmail = false
  680. }
  681. _ = utils.Rc.Delete(cacheKey)
  682. this.Data["json"] = br
  683. this.ServeJSON()
  684. }()
  685. var req []models.EdbDataLy
  686. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  687. if err != nil {
  688. br.Msg = "参数解析异常!"
  689. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  690. return
  691. }
  692. err = models.AddLyEdbDataList(req)
  693. if err != nil {
  694. return
  695. }
  696. br.Ret = 200
  697. br.Success = true
  698. br.Msg = "处理成功"
  699. }