base_from_mysteel_chemical.go 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "eta/eta_index_lib/logic"
  5. "eta/eta_index_lib/models"
  6. "eta/eta_index_lib/services"
  7. "eta/eta_index_lib/utils"
  8. "fmt"
  9. "strconv"
  10. "time"
  11. )
  12. // MySteelChemicalController 钢联化工
  13. type MySteelChemicalController struct {
  14. BaseAuthController
  15. }
  16. // Add
  17. // @Title 新增钢联化工指标接口
  18. // @Description 新增钢联化工指标接口
  19. // @Success 200 {object} models.AddEdbInfoReq
  20. // @router /add [post]
  21. func (this *MySteelChemicalController) Add() {
  22. br := new(models.BaseResponse).Init()
  23. var cacheKey string
  24. defer func() {
  25. utils.Rc.Delete(cacheKey)
  26. this.Data["json"] = br
  27. this.ServeJSON()
  28. }()
  29. source := utils.DATA_SOURCE_MYSTEEL_CHEMICAL
  30. var req models.AddEdbInfoReq
  31. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  32. if err != nil {
  33. br.Msg = "参数解析异常!"
  34. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  35. return
  36. }
  37. if req.EdbCode == "" {
  38. br.Msg = "请输入指标编码!"
  39. br.ErrMsg = "请输入指标编码,指标编码为空"
  40. return
  41. }
  42. cacheKey = utils.CACHE_EDB_DATA_ADD + strconv.Itoa(source) + "_" + req.EdbCode
  43. if !utils.Rc.IsExist(cacheKey) {
  44. utils.Rc.SetNX(cacheKey, 1, 1*time.Minute)
  45. err = models.AddEdbDataFromMysteelChemical(req.EdbCode)
  46. if err != nil {
  47. br.Msg = "获取指标信息失败!"
  48. br.ErrMsg = "获取指标信息失败 AddEdbDataFromMysteelChemical,Err:" + err.Error()
  49. return
  50. }
  51. br.Ret = 200
  52. br.Success = true
  53. br.Msg = "获取成功"
  54. } else {
  55. br.Ret = 501
  56. br.Success = true
  57. br.Msg = "系统处理中,请稍后重试"
  58. }
  59. }
  60. // Refresh
  61. // @Title 刷新钢联化工指标接口
  62. // @Description 刷新钢联化工指标接口
  63. // @Success 200 {object} models.RefreshEdbInfoReq
  64. // @router /refresh [post]
  65. func (this *MySteelChemicalController) Refresh() {
  66. br := new(models.BaseResponse).Init()
  67. var cacheKey string
  68. defer func() {
  69. utils.Rc.Delete(cacheKey)
  70. this.Data["json"] = br
  71. this.ServeJSON()
  72. }()
  73. source := utils.DATA_SOURCE_MYSTEEL_CHEMICAL
  74. var req models.RefreshEdbInfoReq
  75. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  76. if err != nil {
  77. br.Msg = "参数解析异常!"
  78. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  79. return
  80. }
  81. if req.EdbCode == "" {
  82. br.Msg = "请输入指标编码!"
  83. br.ErrMsg = "请输入指标编码,指标编码为空"
  84. return
  85. }
  86. if req.EdbInfoId <= 0 {
  87. br.Msg = "请输入指标ID!"
  88. br.ErrMsg = "请输入指标ID"
  89. return
  90. }
  91. // 获取指标详情
  92. edbInfo, err := models.GetEdbInfoByEdbCode(source, req.EdbCode)
  93. if err != nil {
  94. br.Msg = "指标不存在!"
  95. br.ErrMsg = "指标不存在"
  96. return
  97. }
  98. cacheKey = utils.CACHE_EDB_DATA_REFRESH + strconv.Itoa(source) + "_" + req.EdbCode
  99. if utils.Rc.IsExist(cacheKey) {
  100. br.Ret = 501
  101. br.Success = true
  102. br.Msg = "系统处理中,请稍后重试"
  103. return
  104. }
  105. utils.Rc.SetNX(cacheKey, 1, 1*time.Minute)
  106. err = models.RefreshEdbDataFromMysteelChemical(req.EdbInfoId, req.EdbCode, req.StartDate)
  107. if err != nil && err.Error() != utils.ErrNoRow() {
  108. br.Msg = "刷新指标信息失败!"
  109. br.ErrMsg = "刷新指标信息失败 RefreshEdbDataFromMysteel,Err:" + err.Error()
  110. return
  111. }
  112. // 更新指标最大最小值
  113. err, errMsg := models.UnifiedModifyEdbInfoMaxAndMinInfo(edbInfo)
  114. if err != nil {
  115. br.Msg = errMsg
  116. br.ErrMsg = err.Error()
  117. return
  118. }
  119. // 更新ES
  120. go logic.UpdateEs(edbInfo.EdbInfoId)
  121. br.Ret = 200
  122. br.Success = true
  123. br.Msg = "获取成功"
  124. }
  125. // @Title 查询刷新钢联指标的接口
  126. // @Description 查询刷新钢联指标的接口
  127. // @Success 200 {object} models.CheckDeleteClassifyResp
  128. // @router /query/refresh [post]
  129. func (this *MySteelChemicalController) QueryRefresh() {
  130. br := new(models.BaseResponse).Init()
  131. defer func() {
  132. this.Data["json"] = br
  133. this.ServeJSON()
  134. }()
  135. mysteelIndex := new(models.BaseFromMysteelChemicalIndex)
  136. list, err := mysteelIndex.GetIndexRefreshAllByMergeFile()
  137. if err != nil && err.Error() != utils.ErrNoRow() {
  138. br.Msg = "获取失败!"
  139. br.ErrMsg = "获取失败,Err:" + err.Error()
  140. return
  141. }
  142. if list == nil {
  143. list = make([]*models.BaseFromMysteelChemicalIndex, 0)
  144. }
  145. br.Ret = 200
  146. br.Data = list
  147. br.Success = true
  148. br.Msg = "获取成功"
  149. }
  150. // @Title 处理钢联指标的接口
  151. // @Description 处理钢联指标的接口
  152. // @Success 200 {object} models.HandleMysteelIndexResp
  153. // @router /handle/mysteel/index [post]
  154. func (this *MySteelChemicalController) HandleMysteelIndex() {
  155. br := new(models.BaseResponse).Init()
  156. defer func() {
  157. this.Data["json"] = br
  158. this.ServeJSON()
  159. }()
  160. var req models.HandleMysteelIndexResp
  161. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  162. if err != nil {
  163. br.Msg = "参数解析异常!"
  164. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  165. return
  166. }
  167. err = services.HandleMysteelIndex(&req)
  168. if err != nil {
  169. fmt.Println("HandleMysteelIndex Err:" + err.Error())
  170. br.Msg = "处理失败"
  171. br.ErrMsg = "处理失败,Err:" + err.Error()
  172. return
  173. }
  174. br.Ret = 200
  175. br.Success = true
  176. br.Msg = "处理成功"
  177. }
  178. // GetMaxFileIndex
  179. // @Title 获取最大的文件编号下标
  180. // @Description 获取最大的文件编号下标
  181. // @Success 200 {object} models.HandleMysteelIndexResp
  182. // @router /getMaxFileIndex [post]
  183. func (this *MySteelChemicalController) GetMaxFileIndex() {
  184. br := new(models.BaseResponse).Init()
  185. defer func() {
  186. this.Data["json"] = br
  187. this.ServeJSON()
  188. }()
  189. var req models.GetMaxFileIndexReq
  190. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  191. if err != nil {
  192. br.Msg = "参数解析异常!"
  193. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  194. return
  195. }
  196. indexObj := new(models.BaseFromMysteelChemicalIndex)
  197. // 获取最大的文件编号下标
  198. item, err := indexObj.GetMaxFileIndex(req.Frequency)
  199. if err != nil {
  200. return
  201. }
  202. br.Data = item
  203. br.Ret = 200
  204. br.Success = true
  205. br.Msg = "处理成功"
  206. }
  207. // GetNoMergeIndexByFrequencyCount
  208. // @Title 获取未合并的指标总数量
  209. // @Description 获取未合并的指标总数量
  210. // @Success 200 {object} models.HandleMysteelIndexResp
  211. // @router /getNoMergeIndexByFrequencyCount [post]
  212. func (this *MySteelChemicalController) GetNoMergeIndexByFrequencyCount() {
  213. br := new(models.BaseResponse).Init()
  214. defer func() {
  215. this.Data["json"] = br
  216. this.ServeJSON()
  217. }()
  218. var req models.GetMaxFileIndexReq
  219. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  220. if err != nil {
  221. br.Msg = "参数解析异常!"
  222. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  223. return
  224. }
  225. indexObj := new(models.BaseFromMysteelChemicalIndex)
  226. // 获取未合并的指标总数量
  227. indexTotal, err := indexObj.GetNoMergeIndexByFrequencyCount(req.Frequency)
  228. if err != nil {
  229. return
  230. }
  231. br.Data = indexTotal
  232. br.Ret = 200
  233. br.Success = true
  234. br.Msg = "处理成功"
  235. }
  236. // GetNoMergeIndexByFrequencyPage
  237. // @Title 获取未合并的指标列表
  238. // @Description 获取未合并的指标列表
  239. // @Success 200 {object} models.HandleMysteelIndexResp
  240. // @router /getNoMergeIndexByFrequencyPage [post]
  241. func (this *MySteelChemicalController) GetNoMergeIndexByFrequencyPage() {
  242. br := new(models.BaseResponse).Init()
  243. defer func() {
  244. this.Data["json"] = br
  245. this.ServeJSON()
  246. }()
  247. var req models.GetNoMergeIndexByFrequencyPageReq
  248. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  249. if err != nil {
  250. br.Msg = "参数解析异常!"
  251. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  252. return
  253. }
  254. indexObj := new(models.BaseFromMysteelChemicalIndex)
  255. // 获取未合并的指标总数量
  256. indexTotal, err := indexObj.GetNoMergeIndexByFrequencyPage(req.Frequency, req.Limit)
  257. if err != nil {
  258. return
  259. }
  260. br.Data = indexTotal
  261. br.Ret = 200
  262. br.Success = true
  263. br.Msg = "处理成功"
  264. }
  265. // GetIndexCountByMergeFilePath
  266. // @Title 获取该文件下标已经存在多少的指标
  267. // @Description 获取该文件下标已经存在多少的指标
  268. // @Success 200 {object} models.HandleMysteelIndexResp
  269. // @router /getIndexCountByMergeFilePath [post]
  270. func (this *MySteelChemicalController) GetIndexCountByMergeFilePath() {
  271. br := new(models.BaseResponse).Init()
  272. defer func() {
  273. this.Data["json"] = br
  274. this.ServeJSON()
  275. }()
  276. var req models.GetIndexCountByMergeFilePathReq
  277. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  278. if err != nil {
  279. br.Msg = "参数解析异常!"
  280. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  281. return
  282. }
  283. if req.MergeFilePath == "" {
  284. br.Msg = "参数有误"
  285. br.ErrMsg = "参数有误, 文件路径有误"
  286. return
  287. }
  288. indexObj := new(models.BaseFromMysteelChemicalIndex)
  289. indexTotal, err := indexObj.GetIndexCountByMergeFilePath(req.MergeFilePath)
  290. if err != nil {
  291. return
  292. }
  293. br.Data = indexTotal
  294. br.Ret = 200
  295. br.Success = true
  296. br.Msg = "获取成功"
  297. }
  298. // GetIndexCreate
  299. // @Title 获取两分钟前新增的指标
  300. // @Description 获取两分钟前新增的指标
  301. // @Success 200 {object} models.BaseFromMysteelChemicalIndex
  302. // @router /getIndexCreate [post]
  303. func (this *MySteelChemicalController) GetIndexCreate() {
  304. br := new(models.BaseResponse).Init()
  305. defer func() {
  306. this.Data["json"] = br
  307. this.ServeJSON()
  308. }()
  309. indexObj := new(models.BaseFromMysteelChemicalIndex)
  310. items, err := indexObj.GetIndexCreate()
  311. if err != nil {
  312. br.Msg = "获取失败"
  313. br.ErrMsg = "获取指标失败, Err: " + err.Error()
  314. return
  315. }
  316. if items == nil {
  317. items = make([]*models.BaseFromMysteelChemicalIndex, 0)
  318. }
  319. br.Data = items
  320. br.Ret = 200
  321. br.Success = true
  322. br.Msg = "获取成功"
  323. }
  324. // GetIndexRefreshMethanolByMergeFile
  325. // @Title 获取需要刷新的甲醇文件
  326. // @Description 获取需要刷新的甲醇文件
  327. // @Success 200 {object} models.BaseFromMysteelChemicalIndex
  328. // @router /getIndexRefreshMethanolByMergeFile [post]
  329. func (this *MySteelChemicalController) GetIndexRefreshMethanolByMergeFile() {
  330. br := new(models.BaseResponse).Init()
  331. defer func() {
  332. this.Data["json"] = br
  333. this.ServeJSON()
  334. }()
  335. indexObj := new(models.BaseFromMysteelChemicalIndex)
  336. items, err := indexObj.GetIndexRefreshMethanolByMergeFile()
  337. if err != nil {
  338. br.Msg = "获取失败"
  339. br.ErrMsg = "获取指标失败, Err: " + err.Error()
  340. return
  341. }
  342. if items == nil {
  343. items = make([]*models.BaseFromMysteelChemicalIndex, 0)
  344. }
  345. br.Data = items
  346. br.Ret = 200
  347. br.Success = true
  348. br.Msg = "获取成功"
  349. }
  350. // GetIndexRefreshMethanolByTimely
  351. // @Title 获取需要及时刷新的文件
  352. // @Description 获取需要及时刷新的文件
  353. // @Success 200 {object} models.BaseFromMysteelChemicalIndex
  354. // @router /getIndexRefreshMethanolByTimely [post]
  355. func (this *MySteelChemicalController) GetIndexRefreshMethanolByTimely() {
  356. br := new(models.BaseResponse).Init()
  357. defer func() {
  358. this.Data["json"] = br
  359. this.ServeJSON()
  360. }()
  361. indexObj := new(models.BaseFromMysteelChemicalIndex)
  362. items, err := indexObj.GetIndexRefreshMethanolByTimely()
  363. if err != nil {
  364. br.Msg = "获取失败"
  365. br.ErrMsg = "获取指标失败, Err: " + err.Error()
  366. return
  367. }
  368. if items == nil {
  369. items = make([]*models.BaseFromMysteelChemicalIndex, 0)
  370. }
  371. br.Data = items
  372. br.Ret = 200
  373. br.Success = true
  374. br.Msg = "获取成功"
  375. }
  376. // GetIndexByFrequency
  377. // @Title 根据频率获取指标
  378. // @Description 根据频率获取指标
  379. // @Success 200 {object} models.BaseFromMysteelChemicalIndex
  380. // @router /getIndexByFrequency [post]
  381. func (this *MySteelChemicalController) GetIndexByFrequency() {
  382. br := new(models.BaseResponse).Init()
  383. defer func() {
  384. this.Data["json"] = br
  385. this.ServeJSON()
  386. }()
  387. var req models.GetIndexByFrequencyReq
  388. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  389. if err != nil {
  390. br.Msg = "参数解析异常!"
  391. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  392. return
  393. }
  394. if req.Frequency == "" {
  395. br.Msg = "参数有误"
  396. br.ErrMsg = "参数有误"
  397. return
  398. }
  399. indexObj := new(models.BaseFromMysteelChemicalIndex)
  400. items, err := indexObj.GetIndexByFrequency(req.Frequency)
  401. if err != nil {
  402. br.Msg = "获取失败"
  403. br.ErrMsg = "获取指标失败, Err: " + err.Error()
  404. return
  405. }
  406. if items == nil {
  407. items = make([]*models.BaseFromMysteelChemicalIndex, 0)
  408. }
  409. br.Data = items
  410. br.Ret = 200
  411. br.Success = true
  412. br.Msg = "获取成功"
  413. }
  414. // GetIndexRefreshWeek
  415. // @Title 根据周获取指标
  416. // @Description 根据周获取指标
  417. // @Success 200 {object} models.BaseFromMysteelChemicalIndex
  418. // @router /getIndexRefreshWeek [post]
  419. func (this *MySteelChemicalController) GetIndexRefreshWeek() {
  420. br := new(models.BaseResponse).Init()
  421. defer func() {
  422. this.Data["json"] = br
  423. this.ServeJSON()
  424. }()
  425. var req models.GetIndexRefreshWeekReq
  426. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  427. if err != nil {
  428. br.Msg = "参数解析异常!"
  429. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  430. return
  431. }
  432. if req.NowWeekZn == "" || req.StartTime == "" || req.EndTime == "" {
  433. br.Msg = "参数有误"
  434. br.ErrMsg = "参数有误"
  435. return
  436. }
  437. indexObj := new(models.BaseFromMysteelChemicalIndex)
  438. items, err := indexObj.GetIndexRefreshWeek(req.NowWeekZn, req.StartTime, req.EndTime)
  439. if err != nil {
  440. br.Msg = "获取失败"
  441. br.ErrMsg = "获取指标失败, Err: " + err.Error()
  442. return
  443. }
  444. if items == nil {
  445. items = make([]*models.BaseFromMysteelChemicalIndex, 0)
  446. }
  447. br.Data = items
  448. br.Ret = 200
  449. br.Success = true
  450. br.Msg = "获取成功"
  451. }
  452. // UpdateIndex
  453. // @Title 更新指标
  454. // @Description 更新指标
  455. // @Success 200 string "操作成功"
  456. // @router /updateIndex [post]
  457. //func (this *MySteelChemicalController) UpdateIndex() {
  458. // br := new(models.BaseResponse).Init()
  459. // defer func() {
  460. // this.Data["json"] = br
  461. // this.ServeJSON()
  462. // }()
  463. // var req models.UpdateIndexReq
  464. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  465. // if err != nil {
  466. // br.Msg = "参数解析异常!"
  467. // br.ErrMsg = "参数解析失败,Err:" + err.Error()
  468. // return
  469. // }
  470. // if req.Item == nil {
  471. // br.Msg = "参数有误"
  472. // br.ErrMsg = "参数有误, 指标信息有误"
  473. // return
  474. // }
  475. // if len(req.UpdateCols) == 0 {
  476. // br.Msg = "参数有误"
  477. // br.ErrMsg = "参数有误, 无更新字段"
  478. // return
  479. // }
  480. //
  481. // // 更新指标
  482. // indexObj := new(models.BaseFromMysteelChemicalIndex)
  483. // err = indexObj.UpdateIndex(req.Item, req.UpdateCols)
  484. // if err != nil {
  485. // br.Msg = "操作失败"
  486. // br.ErrMsg = "批量更新指标失败, MultiUpdateIndexByIndexCode err: " + err.Error()
  487. // return
  488. // }
  489. //
  490. // br.Ret = 200
  491. // br.Success = true
  492. // br.Msg = "操作成功"
  493. //}
  494. // MultiUpdateIndex
  495. // @Title 批量更新指标
  496. // @Description 批量更新指标
  497. // @Success 200 string "操作成功"
  498. // @router /multiUpdateIndex [post]
  499. func (this *MySteelChemicalController) MultiUpdateIndex() {
  500. br := new(models.BaseResponse).Init()
  501. defer func() {
  502. this.Data["json"] = br
  503. this.ServeJSON()
  504. }()
  505. var req []models.UpdateIndexReq
  506. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  507. if err != nil {
  508. br.Msg = "参数解析异常!"
  509. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  510. return
  511. }
  512. if len(req) == 0 {
  513. br.Msg = "参数有误"
  514. br.ErrMsg = "参数有误, 无指标需要更新"
  515. return
  516. }
  517. // 批量更新指标
  518. indexObj := new(models.BaseFromMysteelChemicalIndex)
  519. err = indexObj.MultiUpdateIndex(req)
  520. if err != nil {
  521. br.Msg = "操作失败"
  522. br.ErrMsg = "批量更新指标失败, MultiUpdateIndex err: " + err.Error()
  523. return
  524. }
  525. br.Ret = 200
  526. br.Success = true
  527. br.Msg = "操作成功"
  528. }
  529. // @Title 处理钢联指标的接口
  530. // @Description 处理钢联指标的接口
  531. // @Success 200 {object} models.AddMysteelIndexResp
  532. // @router /add/mysteel/index [post]
  533. func (this *MySteelChemicalController) AddMysteelIndex() {
  534. br := new(models.BaseResponse).Init()
  535. defer func() {
  536. this.Data["json"] = br
  537. this.ServeJSON()
  538. }()
  539. var req models.AddMysteelIndexResp
  540. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  541. if err != nil {
  542. br.Msg = "参数解析异常!"
  543. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  544. return
  545. }
  546. mysteelIndexObj := new(models.BaseFromMysteelChemicalIndex)
  547. indexItem, err := mysteelIndexObj.GetIndexItem(req.EdbCode)
  548. var isAdd bool
  549. if err != nil {
  550. if err.Error() == utils.ErrNoRow() {
  551. isAdd = true
  552. } else {
  553. br.Msg = "判断指标是否存在失败"
  554. br.ErrMsg = "判断指标是否存在失败,Err:" + err.Error()
  555. return
  556. }
  557. }
  558. if indexItem == nil {
  559. isAdd = true
  560. }
  561. if isAdd {
  562. mysteelIndexObj.IndexCode = req.EdbCode
  563. mysteelIndexObj.BaseFromMysteelChemicalClassifyId = req.BaseFromMysteelChemicalClassifyId
  564. err = mysteelIndexObj.Add()
  565. if err != nil {
  566. br.Msg = "新增指标失败"
  567. br.ErrMsg = "新增指标失败,Err:" + err.Error()
  568. return
  569. }
  570. }
  571. br.Ret = 200
  572. br.Success = true
  573. br.Msg = "新增成功"
  574. }
  575. // GetIndexDetailByCode
  576. // @Title 获取指标详情
  577. // @Description 获取指标详情
  578. // @Success 200 {object} models.GetIndexDetailReq
  579. // @router /index_detail [post]
  580. func (this *MySteelChemicalController) GetIndexDetailByCode() {
  581. br := new(models.BaseResponse).Init()
  582. defer func() {
  583. this.Data["json"] = br
  584. this.ServeJSON()
  585. }()
  586. var req models.GetIndexDetailReq
  587. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  588. if err != nil {
  589. br.Msg = "参数解析异常!"
  590. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  591. return
  592. }
  593. if req.IndexCode == "" {
  594. br.Msg = "参数有误"
  595. br.ErrMsg = "参数有误"
  596. return
  597. }
  598. indexObj := new(models.BaseFromMysteelChemicalIndex)
  599. item, err := indexObj.GetIndexItem(req.IndexCode)
  600. if err != nil {
  601. br.Msg = "获取失败"
  602. br.ErrMsg = "获取指标失败, Err: " + err.Error()
  603. return
  604. }
  605. br.Data = item
  606. br.Ret = 200
  607. br.Success = true
  608. br.Msg = "获取成功"
  609. }