base_from_rzd_index_controller.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708
  1. // Package data_manage
  2. // @Author gmy 2024/8/12 14:31:00
  3. package data_manage
  4. import (
  5. "encoding/json"
  6. "eta/eta_api/controllers"
  7. "eta/eta_api/models"
  8. "eta/eta_api/models/data_manage"
  9. "eta/eta_api/models/system"
  10. "eta/eta_api/services/data"
  11. etaTrialService "eta/eta_api/services/eta_trial"
  12. "eta/eta_api/utils"
  13. "fmt"
  14. "github.com/tealeg/xlsx"
  15. "os"
  16. "path/filepath"
  17. "strconv"
  18. "strings"
  19. "time"
  20. )
  21. // BaseFromRzdIndexController 睿姿得数据控制器
  22. type BaseFromRzdIndexController struct {
  23. controllers.BaseAuthController
  24. }
  25. // RzdClassify
  26. // @Title 睿姿得数据分类
  27. // @Description 汾渭数据分类接口
  28. // @Success 200 {object} data_manage.BaseFromRzdClassifyResponse
  29. // @router /rzd/classify [get]
  30. func (this *BaseFromRzdIndexController) RzdClassify() {
  31. br := new(models.BaseResponse).Init()
  32. defer func() {
  33. if br.ErrMsg == "" {
  34. br.IsSendEmail = false
  35. }
  36. this.Data["json"] = br
  37. this.ServeJSON()
  38. }()
  39. sysUser := this.SysUser
  40. if sysUser == nil {
  41. br.Msg = "请登录"
  42. br.ErrMsg = "请登录,SysUser Is Empty"
  43. br.Ret = 408
  44. return
  45. }
  46. classifies, e := data.RzdClassifyList()
  47. if e != nil {
  48. br.Msg = "获取失败"
  49. br.ErrMsg = "获取睿姿得数据分类失败, Err: " + e.Error()
  50. return
  51. }
  52. br.Data = classifies
  53. br.Ret = 200
  54. br.Success = true
  55. br.Msg = "获取成功"
  56. }
  57. // RzdIndexData
  58. // @Title 获取睿姿得数据
  59. // @Description 获取睿姿得数据
  60. // @Param PageSize query int true "每页数据条数"
  61. // @Param CurrentIndex query int true "当前页页码,从1开始"
  62. // @Param ClassifyId query string true "分类id"
  63. // @Param Frequency query string true "频率"
  64. // @Success 200
  65. // @router /rzd/index/data [get]
  66. func (this *BaseFromRzdIndexController) RzdIndexData() {
  67. br := new(models.BaseResponse).Init()
  68. defer func() {
  69. if br.ErrMsg == "" {
  70. br.IsSendEmail = false
  71. }
  72. this.Data["json"] = br
  73. this.ServeJSON()
  74. }()
  75. sysUser := this.SysUser
  76. if sysUser == nil {
  77. br.Msg = "请登录"
  78. br.ErrMsg = "请登录,SysUser Is Empty"
  79. br.Ret = 408
  80. return
  81. }
  82. pageSize, _ := this.GetInt("PageSize")
  83. currentIndex, _ := this.GetInt("CurrentIndex")
  84. var startSize int
  85. if pageSize <= 0 {
  86. pageSize = utils.PageSize20
  87. }
  88. if currentIndex <= 0 {
  89. currentIndex = 1
  90. }
  91. startSize = utils.StartIndex(currentIndex, pageSize)
  92. classifyId, _ := this.GetInt("ClassifyId")
  93. if classifyId < 0 {
  94. br.Msg = "请选择分类"
  95. br.ErrMsg = "请选择分类"
  96. return
  97. }
  98. frequency := this.GetString("Frequency")
  99. resultList, err := data.RzdIndexData(classifyId, frequency, currentIndex, startSize, pageSize)
  100. if err != nil {
  101. return
  102. }
  103. br.Ret = 200
  104. br.Success = true
  105. br.Msg = "获取成功"
  106. br.Data = resultList
  107. }
  108. // RzdIndexDetail
  109. // @Title 获取睿姿得数据指标详情
  110. // @Description 获取睿姿得数据指标详情
  111. // @Param IndexCode query string true "查询参数 指标id"
  112. // @Success 200
  113. // @router /rzd/index/detail [get]
  114. func (this *BaseFromRzdIndexController) RzdIndexDetail() {
  115. br := new(models.BaseResponse).Init()
  116. defer func() {
  117. if br.ErrMsg == "" {
  118. br.IsSendEmail = false
  119. }
  120. this.Data["json"] = br
  121. this.ServeJSON()
  122. }()
  123. sysUser := this.SysUser
  124. if sysUser == nil {
  125. br.Msg = "请登录"
  126. br.ErrMsg = "请登录,SysUser Is Empty"
  127. br.Ret = 408
  128. return
  129. }
  130. indexCode := this.GetString("IndexCode")
  131. pageSize, _ := this.GetInt("PageSize")
  132. currentIndex, _ := this.GetInt("CurrentIndex")
  133. var startSize int
  134. if pageSize <= 0 {
  135. pageSize = utils.PageSize20
  136. }
  137. if currentIndex <= 0 {
  138. currentIndex = 1
  139. }
  140. startSize = utils.StartIndex(currentIndex, pageSize)
  141. indexDetail, err := data.GetRzdIndexDetail(indexCode, currentIndex, startSize, pageSize)
  142. if err != nil {
  143. return
  144. }
  145. br.Ret = 200
  146. br.Success = true
  147. br.Msg = "获取成功"
  148. br.Data = indexDetail
  149. }
  150. // RzdIndexList
  151. // @Title 获取睿姿得数据指标列表
  152. // @Description 获取睿姿得数据指标详情
  153. // @Param searchParams query string true "查询参数 指标id/指标名称"
  154. // @Success 200
  155. // @router /rzd/index/list [get]
  156. func (this *BaseFromRzdIndexController) RzdIndexList() {
  157. br := new(models.BaseResponse).Init()
  158. defer func() {
  159. if br.ErrMsg == "" {
  160. br.IsSendEmail = false
  161. }
  162. this.Data["json"] = br
  163. this.ServeJSON()
  164. }()
  165. sysUser := this.SysUser
  166. if sysUser == nil {
  167. br.Msg = "请登录"
  168. br.ErrMsg = "请登录,SysUser Is Empty"
  169. br.Ret = 408
  170. return
  171. }
  172. searchParams := this.GetString("SearchParams")
  173. indexList, err := data.GetRzdIndexList(searchParams)
  174. if err != nil {
  175. return
  176. }
  177. br.Ret = 200
  178. br.Success = true
  179. br.Msg = "获取成功"
  180. br.Data = indexList
  181. }
  182. // GetRzdFrequencyList
  183. // @Title 查询频率列表
  184. // @Description 查询频率列表
  185. // @Param classifyId query int false "指标唯一编码"
  186. // @Success 200 {object} []string
  187. // @router /rzd/frequency/list [get]
  188. func (this *BaseFromRzdIndexController) GetRzdFrequencyList() {
  189. br := new(models.BaseResponse).Init()
  190. defer func() {
  191. if br.ErrMsg == "" {
  192. br.IsSendEmail = false
  193. }
  194. this.Data["json"] = br
  195. this.ServeJSON()
  196. }()
  197. sysUser := this.SysUser
  198. if sysUser == nil {
  199. br.Msg = "请登录"
  200. br.ErrMsg = "请登录,SysUser Is Empty"
  201. br.Ret = 408
  202. return
  203. }
  204. classifyId, _ := this.GetInt("ClassifyId")
  205. if classifyId < 0 {
  206. br.Msg = "请选择分类"
  207. br.ErrMsg = "请选择分类"
  208. return
  209. }
  210. frequencyList, err := data.GetRzdIndexFrequency(classifyId)
  211. if err != nil {
  212. return
  213. }
  214. br.Ret = 200
  215. br.Success = true
  216. br.Msg = "获取成功"
  217. br.Data = frequencyList
  218. }
  219. // RzdIndexAddValidate
  220. // @Title 新增加入到指标库校验
  221. // @Description 新增加入到指标库校验
  222. // @Param req body data_manage.BaseFromFenWeiIndexBatchAddCheckReq true "请求参数"
  223. // @Success 200 {object} []data_manage.IndexCheckData
  224. // @router /rzd/index/add/validate [post]
  225. func (this *BaseFromRzdIndexController) RzdIndexAddValidate() {
  226. br := new(models.BaseResponse).Init()
  227. defer func() {
  228. if br.ErrMsg == "" {
  229. br.IsSendEmail = false
  230. }
  231. this.Data["json"] = br
  232. this.ServeJSON()
  233. }()
  234. sysUser := this.SysUser
  235. if sysUser == nil {
  236. br.Msg = "请登录"
  237. br.ErrMsg = "请登录,SysUser Is Empty"
  238. br.Ret = 408
  239. return
  240. }
  241. var req *data_manage.BaseFromRzdIndexBatchAddCheckReq
  242. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
  243. br.Msg = "参数解析异常!"
  244. br.ErrMsg = "参数解析失败,Err:" + e.Error()
  245. return
  246. }
  247. // 校验指标编码是否存在
  248. addValidate, err := data.RzdIndexAddValidate(req)
  249. if err != nil {
  250. br.Ret = 403
  251. br.Success = false
  252. br.Msg = err.Error()
  253. return
  254. }
  255. br.Data = addValidate
  256. br.Ret = 200
  257. br.Success = true
  258. br.Msg = "操作成功"
  259. }
  260. // RzdIndexAdd
  261. // @Title 指标添加到指标库
  262. // @Description 指标添加到指标库
  263. // @Param req body []data_manage.AddEdbInfoReq true "请求参数"
  264. // @Success 200 string "操作成功"
  265. // @router /rzd/index/add [post]
  266. func (this *BaseFromRzdIndexController) RzdIndexAdd() {
  267. br := new(models.BaseResponse).Init()
  268. defer func() {
  269. if br.ErrMsg == "" {
  270. br.IsSendEmail = false
  271. }
  272. this.Data["json"] = br
  273. this.ServeJSON()
  274. }()
  275. sysUser := this.SysUser
  276. if sysUser == nil {
  277. br.Msg = "请登录"
  278. br.ErrMsg = "请登录,SysUser Is Empty"
  279. br.Ret = 408
  280. return
  281. }
  282. deleteCache := true
  283. cacheKey := "CACHE_EDB_INFO_BATCH_ADD_RZD_" + strconv.Itoa(sysUser.AdminId)
  284. defer func() {
  285. if deleteCache {
  286. _ = utils.Rc.Delete(cacheKey)
  287. }
  288. }()
  289. if !utils.Rc.SetNX(cacheKey, 1, 30*time.Second) {
  290. deleteCache = false
  291. br.Msg = "系统处理中,请稍后重试!"
  292. br.ErrMsg = "系统处理中,请稍后重试!" + sysUser.RealName + ";data:" + string(this.Ctx.Input.RequestBody)
  293. return
  294. }
  295. var req []*data_manage.AddEdbInfoReq
  296. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
  297. br.Msg = "参数解析异常!"
  298. br.ErrMsg = "参数解析失败,Err:" + e.Error()
  299. return
  300. }
  301. if len(req) == 0 {
  302. br.Msg = "请选择指标"
  303. return
  304. }
  305. if len(req) > 30 {
  306. br.Msg = "批量添加指标数量不得超过" + strconv.Itoa(30) + "个"
  307. return
  308. }
  309. indexNames := make([]string, 0)
  310. resp := make([]*data_manage.RzdNameCheckResult, 0)
  311. for _, index := range req {
  312. index.EdbCode = strings.TrimSpace(index.EdbCode)
  313. if index.EdbCode == "" {
  314. br.Msg = "指标ID不可为空"
  315. return
  316. }
  317. index.EdbName = strings.TrimSpace(index.EdbName)
  318. if index.EdbName == "" {
  319. br.Msg = "请输入指标名称"
  320. return
  321. }
  322. index.Frequency = strings.TrimSpace(index.Frequency)
  323. if index.Frequency == "" {
  324. br.Msg = "请选择频度"
  325. return
  326. }
  327. index.Unit = strings.TrimSpace(index.Unit)
  328. if index.Unit == "" {
  329. br.Msg = "请输入单位"
  330. return
  331. }
  332. if index.ClassifyId <= 0 {
  333. br.Msg = "请选择分类"
  334. return
  335. }
  336. indexNames = append(indexNames, index.EdbName)
  337. resp = append(resp, &data_manage.RzdNameCheckResult{
  338. IndexCode: index.EdbCode,
  339. IndexName: index.EdbName,
  340. Exist: false,
  341. })
  342. }
  343. // 指标名称重复校验
  344. nameCheck, err := data.RzdIndexNameCheck(indexNames, resp)
  345. if err != nil {
  346. br.Msg = err.Error()
  347. br.ErrMsg = err.Error()
  348. return
  349. }
  350. for _, v := range nameCheck {
  351. if v.Exist {
  352. br.Msg = "指标名称重复"
  353. br.Data = nameCheck
  354. br.Ret = 200
  355. br.Success = true
  356. return
  357. }
  358. }
  359. for _, v := range req {
  360. var rzdIndexAddReq data_manage.RzdIndexAddReq
  361. rzdIndexAddReq.EdbCode = v.EdbCode
  362. rzdIndexAddReq.EdbName = v.EdbName
  363. rzdIndexAddReq.Frequency = v.Frequency
  364. rzdIndexAddReq.Unit = v.Unit
  365. rzdIndexAddReq.ClassifyId = v.ClassifyId
  366. rzdIndexAddReq.AdminId = sysUser.AdminId
  367. rzdIndexAddReq.AdminRealName = sysUser.RealName
  368. // 新增指标到指标库
  369. edbInfo, e, errMsg, skip := data.RzdIndexAdd(rzdIndexAddReq, this.Lang)
  370. if e != nil {
  371. br.Msg = "操作失败"
  372. if errMsg != "" {
  373. br.Msg = errMsg
  374. }
  375. br.ErrMsg = e.Error()
  376. return
  377. }
  378. if skip {
  379. continue
  380. }
  381. // todo 下面两段代码能否抽离出来???
  382. // 试用平台更新用户累计新增指标数
  383. if utils.BusinessCode == utils.BusinessCodeSandbox {
  384. go func() {
  385. adminItem, e := system.GetSysAdminById(sysUser.AdminId)
  386. if e != nil {
  387. tips := fmt.Sprintf("试用平台更新用户累计新增指标数-获取用户失败, Err: " + e.Error())
  388. utils.FileLog.Info(tips)
  389. return
  390. }
  391. if adminItem.DepartmentName != "ETA试用客户" {
  392. return
  393. }
  394. var ur etaTrialService.EtaTrialUserReq
  395. ur.Mobile = adminItem.Mobile
  396. _, _ = etaTrialService.UpdateUserIndexNum(ur)
  397. }()
  398. }
  399. // 新增操作日志
  400. {
  401. edbLog := new(data_manage.EdbInfoLog)
  402. edbLog.EdbInfoId = edbInfo.EdbInfoId
  403. edbLog.SourceName = edbInfo.SourceName
  404. edbLog.Source = edbInfo.Source
  405. edbLog.EdbCode = edbInfo.EdbCode
  406. edbLog.EdbName = edbInfo.EdbName
  407. edbLog.ClassifyId = edbInfo.ClassifyId
  408. edbLog.SysUserId = sysUser.AdminId
  409. edbLog.SysUserRealName = sysUser.RealName
  410. edbLog.CreateTime = time.Now()
  411. edbLog.Content = string(this.Ctx.Input.RequestBody)
  412. edbLog.Status = "新增指标"
  413. edbLog.Method = this.Ctx.Input.URI()
  414. go data_manage.AddEdbInfoLog(edbLog)
  415. }
  416. }
  417. br.Msg = "操作成功"
  418. br.Ret = 200
  419. br.Success = true
  420. br.IsAddLog = true
  421. }
  422. // RzdIndexDataExport
  423. // @Title 导出指标数据
  424. // @Description 导出指标数据
  425. // @Param IndexCode query string false "指标编码"
  426. // @Param ClassifyId query int false "分类ID"
  427. // @Success 200 string "操作成功"
  428. // @router /rzd/index/data/export [get]
  429. func (this *BaseFromRzdIndexController) RzdIndexDataExport() {
  430. br := new(models.BaseResponse).Init()
  431. defer func() {
  432. this.Data["json"] = br
  433. this.ServeJSON()
  434. }()
  435. sysUser := this.SysUser
  436. if sysUser == nil {
  437. br.Msg = "请重新登录"
  438. return
  439. }
  440. classifyId, _ := this.GetInt("ClassifyId") //分类
  441. indexCode := this.GetString("IndexCode") //指标唯一编码
  442. if classifyId <= 0 {
  443. br.Msg = "请选择分类"
  444. return
  445. }
  446. dir, _ := os.Executable()
  447. exPath := filepath.Dir(dir)
  448. downLoadFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  449. xlsxFile := xlsx.NewFile()
  450. classifyIdList, err := data.RzdClassifyRecursiveQuery(classifyId)
  451. if err != nil {
  452. br.Msg = "查询分类失败"
  453. br.ErrMsg = "查询分类失败"
  454. return
  455. }
  456. classifyIdList = append(classifyIdList, classifyId)
  457. frequencies, err := data_manage.GetRzdIndexFrequency(classifyIdList)
  458. if err != nil {
  459. br.Msg = "查询频度失败"
  460. br.ErrMsg = "查询频度失败"
  461. return
  462. }
  463. fileName := `睿姿得数据`
  464. if classifyId > 0 && indexCode == "" {
  465. fenWeiClassify, err := data_manage.GetRzdClassifyItemByClassifyId(classifyId)
  466. if err != nil {
  467. return
  468. }
  469. fileName = fenWeiClassify.ClassifyName
  470. }
  471. if frequencies == nil {
  472. sheet, err := xlsxFile.AddSheet("无数据")
  473. if err != nil {
  474. br.Msg = "新增Sheet失败"
  475. br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
  476. return
  477. }
  478. rowSecName := sheet.AddRow()
  479. celSecName := rowSecName.AddCell()
  480. celSecName.SetValue("")
  481. }
  482. for _, frequency := range frequencies {
  483. fenWeiIndices, err := data_manage.GetRzdIndexByCodeAndClassify(indexCode, classifyIdList, frequency)
  484. if err != nil {
  485. return
  486. }
  487. var sheet *xlsx.Sheet
  488. if len(fenWeiIndices) > 0 {
  489. sheetName := *frequency
  490. if sheetName == "" {
  491. sheetName = "无频度"
  492. }
  493. sheet, err = xlsxFile.AddSheet(sheetName)
  494. if err != nil {
  495. br.Msg = "新增Sheet失败"
  496. br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
  497. return
  498. }
  499. } else {
  500. continue
  501. }
  502. if indexCode != "" {
  503. fileName = fenWeiIndices[0].IndexName
  504. }
  505. //获取指标数据
  506. rowSecName := sheet.AddRow()
  507. celSecName := rowSecName.AddCell()
  508. celSecName.SetValue("指标名称/Metric Nome")
  509. rowFrequency := sheet.AddRow()
  510. celFrequency := rowFrequency.AddCell()
  511. celFrequency.SetValue("频率/Frequency")
  512. rowUnit := sheet.AddRow()
  513. celUnit := rowUnit.AddCell()
  514. celUnit.SetValue("单位/Unit")
  515. rowModifyDate := sheet.AddRow()
  516. rowModifyCell := rowModifyDate.AddCell()
  517. rowModifyCell.SetValue("更新时间/Update Time")
  518. dataMap := make(map[string]map[string]*data_manage.BaseFromRzdData)
  519. var tradeCodeList []string
  520. for _, v := range fenWeiIndices {
  521. cellSenName := rowSecName.AddCell()
  522. cellSenName.SetValue(v.IndexName)
  523. celFrequency := rowFrequency.AddCell()
  524. celFrequency.SetValue(v.Frequency)
  525. celUnit := rowUnit.AddCell()
  526. celUnit.SetValue(v.Unit)
  527. rowModifyCell := rowModifyDate.AddCell()
  528. updateTimeStr := utils.FormatDateString(v.ModifyTime)
  529. rowModifyCell.SetValue(updateTimeStr)
  530. tradeCodeList = append(tradeCodeList, v.IndexCode)
  531. var dataList []*data_manage.BaseFromRzdData
  532. dataList, err = data_manage.GetBaseFormRzdDataByIndexCode(v.IndexCode)
  533. if err != nil && err.Error() != utils.ErrNoRow() {
  534. br.ErrMsg = "GetBaseFormRzdDataByIndexCode,Err:" + err.Error()
  535. br.Msg = "获取数据失败"
  536. return
  537. }
  538. for _, item := range dataList {
  539. if dataMap[item.IndexCode] == nil {
  540. dataMap[item.IndexCode] = make(map[string]*data_manage.BaseFromRzdData)
  541. }
  542. dataMap[item.IndexCode][item.DataTime] = item
  543. }
  544. }
  545. tradeCodeStr := strings.Join(tradeCodeList, "','")
  546. tradeCodeStr = "'" + tradeCodeStr + "'"
  547. dataTimeList, err := data_manage.GetRzdDataListByIndexCodes(tradeCodeStr)
  548. if err != nil {
  549. br.Msg = "获取数据失败"
  550. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  551. return
  552. }
  553. for _, dataTime := range dataTimeList {
  554. rowData := sheet.AddRow()
  555. celDate := rowData.AddCell()
  556. celDate.SetValue(dataTime)
  557. for _, m := range fenWeiIndices {
  558. celData := rowData.AddCell()
  559. if dataMap[m.IndexCode][dataTime] != nil {
  560. celData.SetValue(dataMap[m.IndexCode][dataTime].Value)
  561. }
  562. }
  563. }
  564. }
  565. err = xlsxFile.Save(downLoadFilePath)
  566. if err != nil {
  567. //有指标无数据时先导出一遍空表
  568. sheet, err := xlsxFile.AddSheet("无数据")
  569. if err != nil {
  570. br.Msg = "新增Sheet失败"
  571. br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
  572. return
  573. }
  574. rowSecName := sheet.AddRow()
  575. celSecName := rowSecName.AddCell()
  576. celSecName.SetValue("")
  577. err = xlsxFile.Save(downLoadFilePath)
  578. if err != nil {
  579. br.Msg = "保存文件失败"
  580. br.ErrMsg = "保存文件失败"
  581. return
  582. }
  583. }
  584. fileName += time.Now().Format("06.01.02") + `.xlsx` //文件名称
  585. this.Ctx.Output.Download(downLoadFilePath, fileName)
  586. defer func() {
  587. os.Remove(downLoadFilePath)
  588. }()
  589. br.Ret = 200
  590. br.Success = true
  591. br.Msg = "success"
  592. }
  593. // GetRzdIndexInfo
  594. // @Title 添加指标-根据条件获取指标信息
  595. // @Description 添加指标-根据条件获取指标信息
  596. // @Param KeyWord query string false "关键字"
  597. // @Param ClassifyIds query string false "分类id"
  598. // @Param Frequencies query string false "频率"
  599. // @Param PageSize query int false "每页数据条数"
  600. // @Param CurrentIndex query int false "当前页页码,从1开始"
  601. // @Success 200 {object} data_manage.BaseFromRzdIndexPage
  602. // @router /rzd/get/index/info [get]
  603. func (this *BaseFromRzdIndexController) GetRzdIndexInfo() {
  604. br := new(models.BaseResponse).Init()
  605. defer func() {
  606. if br.ErrMsg == "" {
  607. br.IsSendEmail = false
  608. }
  609. this.Data["json"] = br
  610. this.ServeJSON()
  611. }()
  612. sysUser := this.SysUser
  613. if sysUser == nil {
  614. br.Msg = "请登录"
  615. br.ErrMsg = "请登录,SysUser Is Empty"
  616. br.Ret = 408
  617. return
  618. }
  619. keyWord := this.GetString("KeyWord")
  620. classifyIds := this.GetString("ClassifyIds")
  621. frequencies := this.GetString("Frequencies")
  622. pageSize, _ := this.GetInt("PageSize")
  623. currentIndex, _ := this.GetInt("CurrentIndex")
  624. var startSize int
  625. if pageSize <= 0 {
  626. pageSize = utils.PageSize20
  627. }
  628. if currentIndex <= 0 {
  629. currentIndex = 1
  630. }
  631. startSize = utils.StartIndex(currentIndex, pageSize)
  632. var classifyIdList []string
  633. var frequencyList []string
  634. if classifyIds != "" {
  635. classifyIdList = strings.Split(classifyIds, ",")
  636. }
  637. if frequencies != "" {
  638. frequencyList = strings.Split(frequencies, ",")
  639. }
  640. indexInfoPage, err := data.GetRzdIndexInfo(keyWord, classifyIdList, frequencyList, currentIndex, startSize, pageSize)
  641. if err != nil {
  642. return
  643. }
  644. br.Ret = 200
  645. br.Success = true
  646. br.Msg = "获取成功"
  647. br.Data = indexInfoPage
  648. }