oilchem_data.go 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465
  1. package controllers
  2. import (
  3. "eta/eta_api/models"
  4. "eta/eta_api/models/data_manage"
  5. "eta/eta_api/utils"
  6. "github.com/rdlucklib/rdluck_tools/paging"
  7. )
  8. // OilchemClassify
  9. // @title 获取隆众资讯分类列表
  10. // @Description 获取隆众资讯分类列表
  11. // @Success 200 {object} models.
  12. // @router /data/oilchem/classify [get]
  13. func (this *TradeCommonController) OilchemClassify() {
  14. br := new(models.BaseResponse).Init()
  15. defer func() {
  16. this.Data["json"] = br
  17. this.ServeJSON()
  18. }()
  19. classifies, e := data_manage.GetOilchemClassifyList()
  20. if e != nil {
  21. br.Msg = "获取失败"
  22. br.ErrMsg = "获取隆众资讯分类数据分类失败, Err: " + e.Error()
  23. return
  24. }
  25. br.Data = classifies
  26. br.Ret = 200
  27. br.Success = true
  28. br.Msg = "获取成功"
  29. }
  30. // OilchemIndexList
  31. // @title 获取隆众资讯指标列表
  32. // @Description 获取隆众资讯指标列表
  33. // @Success 200 {object} models.
  34. // @router /data/oilchem/indexList [get]
  35. func (this *TradeCommonController) OilchemIndexList() {
  36. br := new(models.BaseResponse).Init()
  37. defer func() {
  38. this.Data["json"] = br
  39. this.ServeJSON()
  40. }()
  41. pageSize, _ := this.GetInt("PageSize")
  42. currentIndex, _ := this.GetInt("CurrentIndex")
  43. var startSize int
  44. if pageSize <= 0 {
  45. pageSize = utils.PageSize20
  46. }
  47. if currentIndex <= 0 {
  48. currentIndex = 1
  49. }
  50. startSize = utils.StartIndex(currentIndex, pageSize)
  51. classifyId, _ := this.GetInt("ClassifyId")
  52. var condition string
  53. var pars []interface{}
  54. if classifyId > 0{
  55. condition += ` AND classify_id=? `
  56. pars = append(pars, classifyId)
  57. }
  58. keyword := this.GetString("KeyWord")
  59. if keyword != "" {
  60. condition += ` AND (index_code =? OR index_name LIKE ?) `
  61. pars = append(pars, keyword)
  62. pars = append(pars, "%"+keyword+"%")
  63. }
  64. indexList, e := data_manage.GetOilchemIndexList(condition, pars, startSize, pageSize)
  65. if e != nil {
  66. br.Msg = "获取失败"
  67. br.ErrMsg = "获取隆众资讯分类数据分类失败, Err: " + e.Error()
  68. return
  69. }
  70. total, err := data_manage.GetOilchemIndexListCount(condition, pars)
  71. if err != nil {
  72. br.Msg = "获取失败"
  73. br.ErrMsg = "获取隆众资讯分类数据分类失败, Err: " + err.Error()
  74. return
  75. }
  76. page := paging.GetPaging(currentIndex, pageSize, total)
  77. resp := data_manage.BaseFromOilchemIndexListResp{}
  78. resp.List = indexList
  79. resp.Paging = page
  80. br.Data = indexList
  81. br.Ret = 200
  82. br.Success = true
  83. br.Msg = "获取成功"
  84. }
  85. // OilchemMineData
  86. // @title 获取隆众资讯详细数据列表
  87. // @Description 获取隆众资讯详细数据接口
  88. // @Param ClassifyId query int true "数据id"
  89. // @Param GroupName query string true "分组名"
  90. // @Param Frequency query string true "频度"
  91. // @Param PageSize query int true "每页数据条数"
  92. // @Param CurrentIndex query int true "当前页页码,从1开始"
  93. // @Success 200 {object} []data_manage.CoalmineDataResp
  94. // @router /data/oilchem/data [get]
  95. func (this *TradeCommonController) OilchemData() {
  96. br := new(models.BaseResponse).Init()
  97. defer func() {
  98. this.Data["json"] = br
  99. this.ServeJSON()
  100. }()
  101. pageSize, _ := this.GetInt("PageSize")
  102. currentIndex, _ := this.GetInt("CurrentIndex")
  103. var startSize int
  104. if pageSize <= 0 {
  105. pageSize = utils.PageSize20
  106. }
  107. if currentIndex <= 0 {
  108. currentIndex = 1
  109. }
  110. startSize = utils.StartIndex(currentIndex, pageSize)
  111. indexCode := this.GetString("IndexCode")
  112. if indexCode == "" {
  113. br.Msg = "请选择指标"
  114. br.ErrMsg = "请选择指标"
  115. return
  116. }
  117. //获取指标
  118. var condition string
  119. var pars []interface{}
  120. condition += ` AND index_code =? `
  121. pars = append(pars, indexCode)
  122. index, err := data_manage.GetOilchemIndexByCode(indexCode)
  123. if err != nil {
  124. br.Msg = "获取数据失败"
  125. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  126. return
  127. }
  128. dataList, err := data_manage.GetOilchemIndexData(condition, pars, startSize, pageSize)
  129. if err != nil {
  130. br.Msg = "获取数据失败"
  131. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  132. return
  133. }
  134. resp := data_manage.BaseFromOilchemIndexList{}
  135. resp.BaseFromOilchemIndexId = index.BaseFromOilchemIndexId
  136. resp.ClassifyId = index.ClassifyId
  137. resp.IndexCode = index.IndexCode
  138. resp.IndexName = index.IndexName
  139. resp.Frequency = index.Frequency
  140. resp.Unit = index.Unit
  141. total, err := data_manage.GetOilchemDataListCount(condition, pars)
  142. page := paging.GetPaging(currentIndex, pageSize, total)
  143. if len(dataList) > 0 {
  144. resp.ModifyTime = dataList[0].ModifyTime
  145. }
  146. resp.Paging = page
  147. resp.DataList = dataList
  148. br.Ret = 200
  149. br.Success = true
  150. br.Msg = "获取成功"
  151. br.Data = resp
  152. }
  153. // CoalSearchList
  154. // @Title 隆众资讯模糊搜索
  155. // @Description 隆众资讯模糊搜索
  156. // @Param Keyword query string ture "关键字搜索"
  157. // @Success 200 {object} models.BaseResponse
  158. // @router /data/oilchem/search [get]
  159. func (this *TradeCommonController) OilchemSearchList() {
  160. br := new(models.BaseResponse).Init()
  161. defer func() {
  162. this.Data["json"] = br
  163. this.ServeJSON()
  164. }()
  165. //关键字
  166. keyword := this.GetString("Keyword")
  167. list, err := data_manage.GetOilchemItemList(keyword)
  168. if err != nil {
  169. br.ErrMsg = "获取失败,Err:" + err.Error()
  170. br.Msg = "获取失败"
  171. return
  172. }
  173. br.Ret = 200
  174. br.Success = true
  175. br.Msg = "获取成功"
  176. br.Data = list
  177. }
  178. // ExportCoalList
  179. // @Title 导出隆众资讯数据
  180. // @Description 导出隆众资讯数据
  181. // @Param ClassifyId query int true "数据id"
  182. // @Param IndexName query string true "名称关键词"
  183. // @Param IndexCode query string true "指标唯一编码"
  184. // @Param TypeName query string true "分类"
  185. // @Param Frequency query string false "频度"
  186. // @Param UnitName query string false "单位"
  187. // @Success 200 导出成功
  188. // @router /export/mtjh [get]
  189. //func (this *TradeCommonController) ExportMtjhList() {
  190. // br := new(models.BaseResponse).Init()
  191. // defer func() {
  192. // this.Data["json"] = br
  193. // this.ServeJSON()
  194. // }()
  195. // area := this.GetString("Area")
  196. // indexCode := this.GetString("IndexCode") //指标唯一编码
  197. //
  198. // secNameList := make([]*models.EdbdataExportList, 0)
  199. //
  200. // dir, _ := os.Executable()
  201. // exPath := filepath.Dir(dir)
  202. //
  203. // downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  204. // xlsxFile := xlsx.NewFile()
  205. //
  206. // //不为空就是导出分类表
  207. // if indexCode == "" {
  208. // //获取指标
  209. // var secNameList []*string
  210. // var err error
  211. //
  212. // secNameList, err = data_manage.GetClassifyMtjhByArea(area)
  213. // if err != nil {
  214. // fmt.Println("获取数据失败,Err:" + err.Error())
  215. // return
  216. // }
  217. //
  218. // if len(secNameList) <= 0 {
  219. // fmt.Println("secNameList长度为0")
  220. // return
  221. // }
  222. // sheetNew, err := xlsxFile.AddSheet(area)
  223. //
  224. // if err != nil {
  225. // fmt.Println("新增Sheet失败", err.Error())
  226. // return
  227. // }
  228. // //sheetNew.SetColWidth()
  229. // //获取指标数据
  230. // windRow := sheetNew.AddRow()
  231. // secNameRow := sheetNew.AddRow()
  232. // indexCodeRow := sheetNew.AddRow()
  233. // frequencyRow := sheetNew.AddRow()
  234. // unitRow := sheetNew.AddRow()
  235. // lastModifyDateRow := sheetNew.AddRow()
  236. // //获取分类下指标最大数据量
  237. // var dataMax int
  238. //
  239. // dataMax, err = data_manage.GetCoalMtjhMaxCount(area)
  240. // if err != nil {
  241. // fmt.Println("获取指标最大数据量失败", err.Error())
  242. // return
  243. // }
  244. //
  245. // setRowIndex := 6
  246. // for k, sv := range secNameList {
  247. // //获取数据
  248. // dataList, err := data_manage.GetBaseFromMtjhIndexByCode(*sv)
  249. // if err != nil {
  250. // br.Msg = "获取数据失败"
  251. // br.ErrMsg = "获取数据失败,Err:" + err.Error()
  252. // return
  253. // }
  254. // windRow.AddCell().SetValue(area)
  255. // secNameRow.AddCell().SetValue("指标名称")
  256. // indexCodeRow.AddCell().SetValue("指标ID")
  257. // frequencyRow.AddCell().SetValue("频率")
  258. // unitRow.AddCell().SetValue("单位")
  259. // lastModifyDateRow.AddCell().SetValue("更新时间")
  260. //
  261. // secNameRow.AddCell().SetValue(dataList[0].IndexName)
  262. // indexCodeRow.AddCell().SetValue(dataList[0].IndexCode)
  263. // frequencyRow.AddCell().SetValue(dataList[0].Frequency)
  264. // unitRow.AddCell().SetValue(dataList[0].Unit)
  265. // lastModifyDateRow.AddCell().SetValue(dataList[0].ModifyTime)
  266. //
  267. // windRow.AddCell()
  268. // windRow.AddCell()
  269. // secNameRow.AddCell()
  270. // indexCodeRow.AddCell()
  271. // frequencyRow.AddCell()
  272. // unitRow.AddCell()
  273. // lastModifyDateRow.AddCell()
  274. // min := k * 3
  275. // sheetNew.SetColWidth(min, min, 15)
  276. //
  277. // if len(dataList) <= 0 {
  278. // for n := 0; n < dataMax; n++ {
  279. // rowIndex := setRowIndex + n
  280. // row := sheetNew.Row(rowIndex)
  281. // row.AddCell()
  282. // row.AddCell()
  283. // row.AddCell()
  284. // }
  285. // } else {
  286. // endRowIndex := 0
  287. // for rk, dv := range dataList {
  288. // rowIndex := setRowIndex + rk
  289. // row := sheetNew.Row(rowIndex)
  290. //
  291. // displayDate, _ := time.Parse(utils.FormatDate, dv.DataTime)
  292. // displayDateCell := row.AddCell()
  293. // style := new(xlsx.Style)
  294. // style.ApplyAlignment = true
  295. // style.Alignment.WrapText = true
  296. // displayDateCell.SetStyle(style)
  297. // displayDateCell.SetDate(displayDate)
  298. //
  299. // row.AddCell().SetValue(dv.DealValue)
  300. // row.AddCell()
  301. // endRowIndex = rowIndex
  302. // }
  303. // if len(dataList) < dataMax {
  304. // dataLen := dataMax - len(dataList)
  305. // for n := 0; n < dataLen; n++ {
  306. // rowIndex := (endRowIndex + 1) + n
  307. // row := sheetNew.Row(rowIndex)
  308. // row.AddCell()
  309. // row.AddCell()
  310. // row.AddCell()
  311. // }
  312. // }
  313. // }
  314. // }
  315. // } else {
  316. // sheet, err := xlsxFile.AddSheet("指标")
  317. // if err != nil {
  318. // br.Msg = "新增Sheet失败"
  319. // br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
  320. // return
  321. // }
  322. // //获取数据
  323. // dataList, err := data_manage.GetBaseFromMtjhIndexByCode(indexCode)
  324. // if err != nil {
  325. // br.Msg = "获取数据失败"
  326. // br.ErrMsg = "获取数据失败,Err:" + err.Error()
  327. // return
  328. // }
  329. //
  330. // mapping, err := data_manage.GetMtjhMappingItemByCode(indexCode)
  331. // if err != nil {
  332. // br.Msg = "获取煤炭数据失败"
  333. // br.ErrMsg = "获取煤炭度数据失败,Err:" + err.Error()
  334. // return
  335. // }
  336. // //获取指标数据
  337. // windRow := sheet.AddRow()
  338. // windRow.AddCell().SetValue("隆众资讯")
  339. // rowSecName := sheet.AddRow()
  340. // celSecName := rowSecName.AddCell()
  341. // celSecName.SetValue("指标名称")
  342. // cellSenName := rowSecName.AddCell()
  343. // cellSenName.SetValue(mapping.IndexName)
  344. // indexCodeRow := sheet.AddRow()
  345. // indexCodeRow.AddCell().SetValue("指标ID")
  346. // indexCodeRow.AddCell().SetValue(indexCode)
  347. //
  348. // rowFrequency := sheet.AddRow()
  349. // celFrequency := rowFrequency.AddCell()
  350. // celFrequency.SetValue("频率")
  351. // rowFrequency.AddCell().SetValue(mapping.Frequency)
  352. //
  353. // rowUnit := sheet.AddRow()
  354. // celUnit := rowUnit.AddCell()
  355. // celUnit.SetValue("单位")
  356. // cellUnit := rowUnit.AddCell()
  357. // cellUnit.SetValue(mapping.Unit)
  358. //
  359. // rowModifyDate := sheet.AddRow()
  360. // rowModifyCell := rowModifyDate.AddCell()
  361. // rowModifyCell.SetValue("更新时间")
  362. // rowModifyCell = rowModifyDate.AddCell()
  363. // rowModifyCell.SetValue(dataList[len(dataList)-1].ModifyTime)
  364. //
  365. // fmt.Println("len(dataList):", len(dataList))
  366. // dataMax, err := data_manage.GetMtjhCount(indexCode)
  367. // if err != nil {
  368. // fmt.Println("获取指标最大数据量失败", err.Error())
  369. // return
  370. // }
  371. // fmt.Println("dataMax:", dataMax)
  372. // if len(dataList) <= 0 {
  373. // for n := 0; n < dataMax; n++ {
  374. // rowIndex := 6 + n
  375. // row := sheet.Row(rowIndex)
  376. // row.AddCell()
  377. // row.AddCell()
  378. // row.AddCell()
  379. // }
  380. // } else {
  381. // endRowIndex := 0
  382. // for rk, dv := range dataList {
  383. // rowIndex := 6 + rk
  384. // row := sheet.Row(rowIndex)
  385. // displayDate, _ := time.Parse(utils.FormatDate, dv.DataTime)
  386. // displayDateCell := row.AddCell()
  387. // style := new(xlsx.Style)
  388. // style.ApplyAlignment = true
  389. // style.Alignment.WrapText = true
  390. // displayDateCell.SetStyle(style)
  391. // displayDateCell.SetDate(displayDate)
  392. //
  393. // row.AddCell().SetValue(dv.DealValue)
  394. // row.AddCell()
  395. // endRowIndex = rowIndex
  396. // }
  397. // if len(dataList) < dataMax {
  398. // dataLen := dataMax - len(dataList)
  399. // for n := 0; n < dataLen; n++ {
  400. // rowIndex := (endRowIndex + 1) + n
  401. // row := sheet.Row(rowIndex)
  402. // row.AddCell()
  403. // row.AddCell()
  404. // row.AddCell()
  405. // }
  406. // }
  407. // }
  408. // }
  409. //
  410. // err := xlsxFile.Save(downLoadnFilePath)
  411. // if err != nil {
  412. // br.Msg = "保存文件失败"
  413. // br.ErrMsg = "保存文件失败"
  414. // return
  415. // }
  416. // fileName := `隆众资讯数据`
  417. // if len(secNameList) > 0 {
  418. // fileName = secNameList[0].ClassifyName
  419. // }
  420. // fileName += time.Now().Format(utils.FormatDateUnSpace) + `.xlsx` //文件名称
  421. // this.Ctx.Output.Download(downLoadnFilePath, fileName)
  422. // defer func() {
  423. // os.Remove(downLoadnFilePath)
  424. // }()
  425. // br.Ret = 200
  426. // br.Success = true
  427. // br.Msg = "success"
  428. //
  429. //}