base_from_mysteel_chemical.go 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805
  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. dataUpdateTime := time.Now().Format(utils.FormatDateTime)
  106. utils.Rc.SetNX(cacheKey, 1, 1*time.Minute)
  107. err = models.RefreshEdbDataFromMysteelChemical(req.EdbInfoId, req.EdbCode, req.StartDate)
  108. if err != nil && err.Error() != utils.ErrNoRow() {
  109. br.Msg = "刷新指标信息失败!"
  110. br.ErrMsg = "刷新指标信息失败 RefreshEdbDataFromMysteel,Err:" + err.Error()
  111. return
  112. }
  113. // 更新指标最大最小值
  114. erDataUpdateDate, err, errMsg := models.UnifiedModifyEdbInfoMaxAndMinInfoDataUpdate(edbInfo, dataUpdateTime)
  115. if err != nil {
  116. br.Msg = errMsg
  117. br.ErrMsg = err.Error()
  118. return
  119. }
  120. // 添加指标刷新成功日志
  121. if erDataUpdateDate != "" {
  122. _ = services.AddEdbInfoUpdateLog(edbInfo.EdbInfoId, 1, "", 1, "", 0, 0)
  123. } else {
  124. _ = services.AddEdbInfoUpdateLog(edbInfo.EdbInfoId, 1, "", 2, "未刷新到数据", 0, 0)
  125. }
  126. // 更新ES
  127. go logic.UpdateEs(edbInfo.EdbInfoId)
  128. br.Ret = 200
  129. br.Success = true
  130. br.Msg = "获取成功"
  131. }
  132. // @Title 查询刷新钢联指标的接口
  133. // @Description 查询刷新钢联指标的接口
  134. // @Success 200 {object} models.CheckDeleteClassifyResp
  135. // @router /query/refresh [post]
  136. func (this *MySteelChemicalController) QueryRefresh() {
  137. br := new(models.BaseResponse).Init()
  138. defer func() {
  139. this.Data["json"] = br
  140. this.ServeJSON()
  141. }()
  142. mysteelIndex := new(models.BaseFromMysteelChemicalIndex)
  143. list, err := mysteelIndex.GetIndexRefreshAllByMergeFile()
  144. if err != nil && err.Error() != utils.ErrNoRow() {
  145. br.Msg = "获取失败!"
  146. br.ErrMsg = "获取失败,Err:" + err.Error()
  147. return
  148. }
  149. if list == nil {
  150. list = make([]*models.BaseFromMysteelChemicalIndex, 0)
  151. }
  152. br.Ret = 200
  153. br.Data = list
  154. br.Success = true
  155. br.Msg = "获取成功"
  156. }
  157. // @Title 处理钢联指标的接口
  158. // @Description 处理钢联指标的接口
  159. // @Success 200 {object} models.HandleMysteelIndexResp
  160. // @router /handle/mysteel/index [post]
  161. func (this *MySteelChemicalController) HandleMysteelIndex() {
  162. br := new(models.BaseResponse).Init()
  163. defer func() {
  164. this.Data["json"] = br
  165. this.ServeJSON()
  166. }()
  167. body := this.Ctx.Input.RequestBody
  168. var req models.HandleMysteelIndexResp
  169. err := json.Unmarshal(body, &req)
  170. if err != nil {
  171. br.Msg = "参数解析异常!"
  172. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  173. return
  174. }
  175. err = services.HandleMysteelIndex(&req)
  176. if err != nil {
  177. fmt.Println("HandleMysteelIndex Err:" + err.Error())
  178. br.Msg = "处理失败"
  179. br.ErrMsg = "处理失败,Err:" + err.Error()
  180. return
  181. }
  182. br.Ret = 200
  183. br.Success = true
  184. br.Msg = "处理成功"
  185. }
  186. // GetMaxFileIndex
  187. // @Title 获取最大的文件编号下标
  188. // @Description 获取最大的文件编号下标
  189. // @Success 200 {object} models.HandleMysteelIndexResp
  190. // @router /getMaxFileIndex [post]
  191. func (this *MySteelChemicalController) GetMaxFileIndex() {
  192. br := new(models.BaseResponse).Init()
  193. defer func() {
  194. this.Data["json"] = br
  195. this.ServeJSON()
  196. }()
  197. var req models.GetMaxFileIndexReq
  198. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  199. if err != nil {
  200. br.Msg = "参数解析异常!"
  201. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  202. return
  203. }
  204. indexObj := new(models.BaseFromMysteelChemicalIndex)
  205. // 获取最大的文件编号下标
  206. item, err := indexObj.GetMaxFileIndex(req.Frequency)
  207. if err != nil {
  208. return
  209. }
  210. br.Data = item
  211. br.Ret = 200
  212. br.Success = true
  213. br.Msg = "处理成功"
  214. }
  215. // GetNoMergeIndexByFrequencyCount
  216. // @Title 获取未合并的指标总数量
  217. // @Description 获取未合并的指标总数量
  218. // @Success 200 {object} models.HandleMysteelIndexResp
  219. // @router /getNoMergeIndexByFrequencyCount [post]
  220. func (this *MySteelChemicalController) GetNoMergeIndexByFrequencyCount() {
  221. br := new(models.BaseResponse).Init()
  222. defer func() {
  223. this.Data["json"] = br
  224. this.ServeJSON()
  225. }()
  226. var req models.GetMaxFileIndexReq
  227. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  228. if err != nil {
  229. br.Msg = "参数解析异常!"
  230. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  231. return
  232. }
  233. indexObj := new(models.BaseFromMysteelChemicalIndex)
  234. // 获取未合并的指标总数量
  235. indexTotal, err := indexObj.GetNoMergeIndexByFrequencyCount(req.Frequency)
  236. if err != nil {
  237. return
  238. }
  239. br.Data = indexTotal
  240. br.Ret = 200
  241. br.Success = true
  242. br.Msg = "处理成功"
  243. }
  244. // GetNoMergeIndexByFrequencyPage
  245. // @Title 获取未合并的指标列表
  246. // @Description 获取未合并的指标列表
  247. // @Success 200 {object} models.HandleMysteelIndexResp
  248. // @router /getNoMergeIndexByFrequencyPage [post]
  249. func (this *MySteelChemicalController) GetNoMergeIndexByFrequencyPage() {
  250. br := new(models.BaseResponse).Init()
  251. defer func() {
  252. this.Data["json"] = br
  253. this.ServeJSON()
  254. }()
  255. var req models.GetNoMergeIndexByFrequencyPageReq
  256. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  257. if err != nil {
  258. br.Msg = "参数解析异常!"
  259. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  260. return
  261. }
  262. indexObj := new(models.BaseFromMysteelChemicalIndex)
  263. // 获取未合并的指标总数量
  264. indexTotal, err := indexObj.GetNoMergeIndexByFrequencyPage(req.Frequency, req.Limit)
  265. if err != nil {
  266. return
  267. }
  268. br.Data = indexTotal
  269. br.Ret = 200
  270. br.Success = true
  271. br.Msg = "处理成功"
  272. }
  273. // GetIndexCountByMergeFilePath
  274. // @Title 获取该文件下标已经存在多少的指标
  275. // @Description 获取该文件下标已经存在多少的指标
  276. // @Success 200 {object} models.HandleMysteelIndexResp
  277. // @router /getIndexCountByMergeFilePath [post]
  278. func (this *MySteelChemicalController) GetIndexCountByMergeFilePath() {
  279. br := new(models.BaseResponse).Init()
  280. defer func() {
  281. this.Data["json"] = br
  282. this.ServeJSON()
  283. }()
  284. var req models.GetIndexCountByMergeFilePathReq
  285. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  286. if err != nil {
  287. br.Msg = "参数解析异常!"
  288. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  289. return
  290. }
  291. if req.MergeFilePath == "" {
  292. br.Msg = "参数有误"
  293. br.ErrMsg = "参数有误, 文件路径有误"
  294. return
  295. }
  296. indexObj := new(models.BaseFromMysteelChemicalIndex)
  297. indexTotal, err := indexObj.GetIndexCountByMergeFilePath(req.MergeFilePath)
  298. if err != nil {
  299. return
  300. }
  301. br.Data = indexTotal
  302. br.Ret = 200
  303. br.Success = true
  304. br.Msg = "获取成功"
  305. }
  306. // GetIndexCreate
  307. // @Title 获取两分钟前新增的指标
  308. // @Description 获取两分钟前新增的指标
  309. // @Success 200 {object} models.BaseFromMysteelChemicalIndex
  310. // @router /getIndexCreate [post]
  311. func (this *MySteelChemicalController) GetIndexCreate() {
  312. br := new(models.BaseResponse).Init()
  313. defer func() {
  314. this.Data["json"] = br
  315. this.ServeJSON()
  316. }()
  317. // 终端编码
  318. terminalCode := this.GetString("TerminalCode")
  319. indexObj := new(models.BaseFromMysteelChemicalIndex)
  320. items, err := indexObj.GetIndexCreate(terminalCode)
  321. if err != nil {
  322. br.Msg = "获取失败"
  323. br.ErrMsg = "获取指标失败, Err: " + err.Error()
  324. return
  325. }
  326. if items == nil {
  327. items = make([]*models.BaseFromMysteelChemicalIndex, 0)
  328. }
  329. br.Data = items
  330. br.Ret = 200
  331. br.Success = true
  332. br.Msg = "获取成功"
  333. }
  334. // GetIndexRefreshMethanolByMergeFile
  335. // @Title 获取需要刷新的甲醇文件
  336. // @Description 获取需要刷新的甲醇文件
  337. // @Success 200 {object} models.BaseFromMysteelChemicalIndex
  338. // @router /getIndexRefreshMethanolByMergeFile [post]
  339. func (this *MySteelChemicalController) GetIndexRefreshMethanolByMergeFile() {
  340. br := new(models.BaseResponse).Init()
  341. defer func() {
  342. this.Data["json"] = br
  343. this.ServeJSON()
  344. }()
  345. indexObj := new(models.BaseFromMysteelChemicalIndex)
  346. items, err := indexObj.GetIndexRefreshMethanolByMergeFile()
  347. if err != nil {
  348. br.Msg = "获取失败"
  349. br.ErrMsg = "获取指标失败, Err: " + err.Error()
  350. return
  351. }
  352. if items == nil {
  353. items = make([]*models.BaseFromMysteelChemicalIndex, 0)
  354. }
  355. br.Data = items
  356. br.Ret = 200
  357. br.Success = true
  358. br.Msg = "获取成功"
  359. }
  360. // GetIndexRefreshMethanolByTimely
  361. // @Title 获取需要及时刷新的文件
  362. // @Description 获取需要及时刷新的文件
  363. // @Success 200 {object} models.BaseFromMysteelChemicalIndex
  364. // @router /getIndexRefreshMethanolByTimely [post]
  365. func (this *MySteelChemicalController) GetIndexRefreshMethanolByTimely() {
  366. br := new(models.BaseResponse).Init()
  367. defer func() {
  368. this.Data["json"] = br
  369. this.ServeJSON()
  370. }()
  371. indexObj := new(models.BaseFromMysteelChemicalIndex)
  372. items, err := indexObj.GetIndexRefreshMethanolByTimely()
  373. if err != nil {
  374. br.Msg = "获取失败"
  375. br.ErrMsg = "获取指标失败, Err: " + err.Error()
  376. return
  377. }
  378. if items == nil {
  379. items = make([]*models.BaseFromMysteelChemicalIndex, 0)
  380. }
  381. br.Data = items
  382. br.Ret = 200
  383. br.Success = true
  384. br.Msg = "获取成功"
  385. }
  386. // GetIndexByFrequency
  387. // @Title 根据频率获取指标
  388. // @Description 根据频率获取指标
  389. // @Success 200 {object} models.BaseFromMysteelChemicalIndex
  390. // @router /getIndexByFrequency [post]
  391. func (this *MySteelChemicalController) GetIndexByFrequency() {
  392. br := new(models.BaseResponse).Init()
  393. defer func() {
  394. this.Data["json"] = br
  395. this.ServeJSON()
  396. }()
  397. var req models.GetIndexByFrequencyReq
  398. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  399. if err != nil {
  400. br.Msg = "参数解析异常!"
  401. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  402. return
  403. }
  404. if req.Frequency == "" {
  405. br.Msg = "参数有误"
  406. br.ErrMsg = "参数有误"
  407. return
  408. }
  409. indexObj := new(models.BaseFromMysteelChemicalIndex)
  410. items, err := indexObj.GetIndexByFrequency(req.Frequency)
  411. if err != nil {
  412. br.Msg = "获取失败"
  413. br.ErrMsg = "获取指标失败, Err: " + err.Error()
  414. return
  415. }
  416. if items == nil {
  417. items = make([]*models.BaseFromMysteelChemicalIndex, 0)
  418. }
  419. br.Data = items
  420. br.Ret = 200
  421. br.Success = true
  422. br.Msg = "获取成功"
  423. }
  424. // GetIndexRefreshWeek
  425. // @Title 根据周获取指标
  426. // @Description 根据周获取指标
  427. // @Success 200 {object} models.BaseFromMysteelChemicalIndex
  428. // @router /getIndexRefreshWeek [post]
  429. func (this *MySteelChemicalController) GetIndexRefreshWeek() {
  430. br := new(models.BaseResponse).Init()
  431. defer func() {
  432. this.Data["json"] = br
  433. this.ServeJSON()
  434. }()
  435. var req models.GetIndexRefreshWeekReq
  436. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  437. if err != nil {
  438. br.Msg = "参数解析异常!"
  439. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  440. return
  441. }
  442. if req.NowWeekZn == "" || req.StartTime == "" || req.EndTime == "" {
  443. br.Msg = "参数有误"
  444. br.ErrMsg = "参数有误"
  445. return
  446. }
  447. indexObj := new(models.BaseFromMysteelChemicalIndex)
  448. items, err := indexObj.GetIndexRefreshWeek(req.NowWeekZn, req.StartTime, req.EndTime)
  449. if err != nil {
  450. br.Msg = "获取失败"
  451. br.ErrMsg = "获取指标失败, Err: " + err.Error()
  452. return
  453. }
  454. if items == nil {
  455. items = make([]*models.BaseFromMysteelChemicalIndex, 0)
  456. }
  457. br.Data = items
  458. br.Ret = 200
  459. br.Success = true
  460. br.Msg = "获取成功"
  461. }
  462. // UpdateIndex
  463. // @Title 更新指标
  464. // @Description 更新指标
  465. // @Success 200 string "操作成功"
  466. // @router /updateIndex [post]
  467. //func (this *MySteelChemicalController) UpdateIndex() {
  468. // br := new(models.BaseResponse).Init()
  469. // defer func() {
  470. // this.Data["json"] = br
  471. // this.ServeJSON()
  472. // }()
  473. // var req models.UpdateIndexReq
  474. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  475. // if err != nil {
  476. // br.Msg = "参数解析异常!"
  477. // br.ErrMsg = "参数解析失败,Err:" + err.Error()
  478. // return
  479. // }
  480. // if req.Item == nil {
  481. // br.Msg = "参数有误"
  482. // br.ErrMsg = "参数有误, 指标信息有误"
  483. // return
  484. // }
  485. // if len(req.UpdateCols) == 0 {
  486. // br.Msg = "参数有误"
  487. // br.ErrMsg = "参数有误, 无更新字段"
  488. // return
  489. // }
  490. //
  491. // // 更新指标
  492. // indexObj := new(models.BaseFromMysteelChemicalIndex)
  493. // err = indexObj.UpdateIndex(req.Item, req.UpdateCols)
  494. // if err != nil {
  495. // br.Msg = "操作失败"
  496. // br.ErrMsg = "批量更新指标失败, MultiUpdateIndexByIndexCode err: " + err.Error()
  497. // return
  498. // }
  499. //
  500. // br.Ret = 200
  501. // br.Success = true
  502. // br.Msg = "操作成功"
  503. //}
  504. // MultiUpdateIndex
  505. // @Title 批量更新指标
  506. // @Description 批量更新指标
  507. // @Success 200 string "操作成功"
  508. // @router /multiUpdateIndex [post]
  509. func (this *MySteelChemicalController) MultiUpdateIndex() {
  510. br := new(models.BaseResponse).Init()
  511. defer func() {
  512. this.Data["json"] = br
  513. this.ServeJSON()
  514. }()
  515. var req []models.UpdateIndexReq
  516. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  517. if err != nil {
  518. br.Msg = "参数解析异常!"
  519. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  520. return
  521. }
  522. if len(req) == 0 {
  523. br.Msg = "参数有误"
  524. br.ErrMsg = "参数有误, 无指标需要更新"
  525. return
  526. }
  527. // 批量更新指标
  528. indexObj := new(models.BaseFromMysteelChemicalIndex)
  529. err = indexObj.MultiUpdateIndex(req)
  530. if err != nil {
  531. br.Msg = "操作失败"
  532. br.ErrMsg = "批量更新指标失败, MultiUpdateIndex err: " + err.Error()
  533. return
  534. }
  535. br.Ret = 200
  536. br.Success = true
  537. br.Msg = "操作成功"
  538. }
  539. // AddMysteelIndex
  540. // @Title 处理钢联指标的接口
  541. // @Description 处理钢联指标的接口
  542. // @Success 200 {object} models.AddMysteelIndexResp
  543. // @router /add/mysteel/index [post]
  544. func (this *MySteelChemicalController) AddMysteelIndex() {
  545. br := new(models.BaseResponse).Init()
  546. defer func() {
  547. this.Data["json"] = br
  548. this.ServeJSON()
  549. }()
  550. var req models.AddMysteelIndexResp
  551. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  552. if err != nil {
  553. br.Msg = "参数解析异常!"
  554. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  555. return
  556. }
  557. mysteelIndexObj := new(models.BaseFromMysteelChemicalIndex)
  558. indexItem, err := mysteelIndexObj.GetIndexItem(req.EdbCode)
  559. var isAdd bool
  560. if err != nil {
  561. if err.Error() == utils.ErrNoRow() {
  562. isAdd = true
  563. } else {
  564. br.Msg = "判断指标是否存在失败"
  565. br.ErrMsg = "判断指标是否存在失败,Err:" + err.Error()
  566. return
  567. }
  568. }
  569. if indexItem == nil {
  570. isAdd = true
  571. }
  572. if isAdd {
  573. mysteelIndexObj.IndexCode = req.EdbCode
  574. mysteelIndexObj.TerminalCode = req.TerminalCode
  575. mysteelIndexObj.BaseFromMysteelChemicalClassifyId = req.BaseFromMysteelChemicalClassifyId
  576. mysteelIndexObj.SysUserId = req.SysUserId
  577. mysteelIndexObj.SysUserRealName = req.SysUserRealName
  578. mysteelIndexObj.CreateTime = time.Now()
  579. mysteelIndexObj.ModifyTime = time.Now()
  580. err = mysteelIndexObj.Add()
  581. if err != nil {
  582. br.Msg = "新增指标失败"
  583. br.ErrMsg = "新增指标失败,Err:" + err.Error()
  584. return
  585. }
  586. }
  587. br.Ret = 200
  588. br.Success = true
  589. br.Msg = "新增成功"
  590. }
  591. // GetIndexDetailByCode
  592. // @Title 获取指标详情
  593. // @Description 获取指标详情
  594. // @Success 200 {object} models.GetIndexDetailReq
  595. // @router /index_detail [post]
  596. func (this *MySteelChemicalController) GetIndexDetailByCode() {
  597. br := new(models.BaseResponse).Init()
  598. defer func() {
  599. this.Data["json"] = br
  600. this.ServeJSON()
  601. }()
  602. var req models.GetIndexDetailReq
  603. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  604. if err != nil {
  605. br.Msg = "参数解析异常!"
  606. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  607. return
  608. }
  609. if req.IndexCode == "" {
  610. br.Msg = "参数有误"
  611. br.ErrMsg = "参数有误"
  612. return
  613. }
  614. indexObj := new(models.BaseFromMysteelChemicalIndex)
  615. item, err := indexObj.GetIndexItem(req.IndexCode)
  616. if err != nil {
  617. br.Msg = "获取失败"
  618. br.ErrMsg = "获取指标失败, Err: " + err.Error()
  619. return
  620. }
  621. br.Data = item
  622. br.Ret = 200
  623. br.Success = true
  624. br.Msg = "获取成功"
  625. }
  626. // GetIndexCountByFrequency
  627. // @Title 根据频度获取指标总数量
  628. // @Description 根据频度获取指标总数量
  629. // @Success 200 {object} models.HandleMysteelIndexResp
  630. // @router /getIndexCountByFrequency [post]
  631. func (this *MySteelChemicalController) GetIndexCountByFrequency() {
  632. br := new(models.BaseResponse).Init()
  633. defer func() {
  634. this.Data["json"] = br
  635. this.ServeJSON()
  636. }()
  637. var req models.GetMaxFileIndexReq
  638. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  639. if err != nil {
  640. br.Msg = "参数解析异常!"
  641. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  642. return
  643. }
  644. var condition string
  645. var pars []interface{}
  646. if req.Frequency != "" {
  647. condition += ` AND frequency = ? `
  648. pars = append(pars, req.Frequency)
  649. }
  650. if req.EndDate != "" {
  651. condition += ` AND end_date < ? `
  652. pars = append(pars, req.EndDate)
  653. }
  654. // 终端编码
  655. condition += ` AND terminal_code = ? `
  656. pars = append(pars, req.TerminalCode)
  657. condition += ` AND is_stop = 0 `
  658. indexObj := new(models.BaseFromMysteelChemicalIndex)
  659. // 获取未合并的指标总数量
  660. indexTotal, err := indexObj.GetIndexCountByFrequency(condition, pars)
  661. if err != nil {
  662. return
  663. }
  664. br.Data = indexTotal
  665. br.Ret = 200
  666. br.Success = true
  667. br.Msg = "处理成功"
  668. }
  669. // GetIndexLimitByFrequency
  670. // @Title 获取未合并的指标列表
  671. // @Description 获取未合并的指标列表
  672. // @Success 200 {object} models.HandleMysteelIndexResp
  673. // @router /getIndexLimitByFrequency [post]
  674. func (this *MySteelChemicalController) GetIndexLimitByFrequency() {
  675. br := new(models.BaseResponse).Init()
  676. defer func() {
  677. this.Data["json"] = br
  678. this.ServeJSON()
  679. }()
  680. var req models.GetNoMergeIndexByFrequencyPageReq
  681. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  682. if err != nil {
  683. br.Msg = "参数解析异常!"
  684. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  685. return
  686. }
  687. indexObj := new(models.BaseFromMysteelChemicalIndex)
  688. // 获取未合并的指标总数量
  689. indexTotal, err := indexObj.GetIndexLimitByFrequency(req.Frequency, req.Limit)
  690. if err != nil {
  691. return
  692. }
  693. br.Data = indexTotal
  694. br.Ret = 200
  695. br.Success = true
  696. br.Msg = "处理成功"
  697. }
  698. // GetIndexPageByFrequency
  699. // @Title 获取钢联指标分页数据
  700. // @Description 获取钢联指标分页数据
  701. // @Success 200 {object} models.HandleMysteelIndexResp
  702. // @router /getIndexPageByFrequency [post]
  703. func (this *MySteelChemicalController) GetIndexPageByFrequency() {
  704. br := new(models.BaseResponse).Init()
  705. defer func() {
  706. this.Data["json"] = br
  707. this.ServeJSON()
  708. }()
  709. var req models.GetIndexPageByFrequencyPageReq
  710. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  711. if err != nil {
  712. br.Msg = "参数解析异常!"
  713. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  714. return
  715. }
  716. var condition string
  717. var pars []interface{}
  718. if req.Frequency != "" {
  719. condition += ` AND frequency = ? `
  720. pars = append(pars, req.Frequency)
  721. }
  722. if req.EndDate != "" {
  723. condition += ` AND end_date < ? `
  724. pars = append(pars, req.EndDate)
  725. }
  726. // 终端编码
  727. condition += ` AND terminal_code = ? `
  728. pars = append(pars, req.TerminalCode)
  729. condition += ` AND is_stop = 0 `
  730. indexObj := new(models.BaseFromMysteelChemicalIndex)
  731. // 获取未合并的指标总数量
  732. indexTotal, err := indexObj.GetIndexPageByFrequency(condition, pars, req.StartSize, req.PageSize)
  733. if err != nil {
  734. return
  735. }
  736. br.Data = indexTotal
  737. br.Ret = 200
  738. br.Success = true
  739. br.Msg = "处理成功"
  740. }