base_from_mysteel_chemical.go 24 KB

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