edb_info_refresh.go 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748
  1. package data_manage
  2. import (
  3. "encoding/json"
  4. "eta_gn/eta_api/models"
  5. "eta_gn/eta_api/models/data_manage"
  6. "eta_gn/eta_api/models/data_manage/edb_refresh"
  7. "eta_gn/eta_api/models/data_manage/edb_refresh/request"
  8. "eta_gn/eta_api/services/data"
  9. "eta_gn/eta_api/utils"
  10. "fmt"
  11. "github.com/rdlucklib/rdluck_tools/paging"
  12. )
  13. // RefreshSourceList
  14. // @Title 获取指标刷新配置的来源接口
  15. // @Description 获取指标刷新配置的来源接口
  16. // @Success Ret=200 获取成功
  17. // @router /edb_info/refresh/source_list [get]
  18. func (c *EdbInfoController) RefreshSourceList() {
  19. br := new(models.BaseResponse).Init()
  20. defer func() {
  21. c.Data["json"] = br
  22. c.ServeJSON()
  23. }()
  24. item := edb_refresh.EdbRefreshSource{}
  25. tmpList, err := item.GetAllList()
  26. if err != nil {
  27. br.Msg = "获取失败"
  28. br.ErrMsg = "获取刷新数据源失败, Err: " + err.Error()
  29. return
  30. }
  31. list := make([]edb_refresh.EdbRefreshSourceList, 0)
  32. tmpMap := make(map[int]edb_refresh.EdbRefreshSourceList, 0)
  33. for _, v := range tmpList {
  34. tmp, ok := tmpMap[v.Source]
  35. if ok {
  36. continue
  37. }
  38. tmp = edb_refresh.EdbRefreshSourceList{
  39. Source: v.Source,
  40. SourceName: v.SourceName,
  41. SourceNameEn: v.SourceNameEn,
  42. //SubSource: v.SubSource,
  43. //SubSourceName: v.SubSourceName,
  44. Child: make([]edb_refresh.EdbRefreshSourceList, 0),
  45. HasChild: v.HasChild,
  46. }
  47. if v.HasChild == 1 {
  48. for _, v2 := range tmpList {
  49. if v2.Source == v.Source {
  50. tmp.Child = append(tmp.Child, edb_refresh.EdbRefreshSourceList{
  51. Source: v2.Source,
  52. SourceName: v2.SourceName,
  53. SubSource: v2.SubSource,
  54. SubSourceName: v2.SubSourceName,
  55. SourceNameEn: v2.SourceNameEn,
  56. SubSourceNameEn: v2.SubSourceNameEn,
  57. HasChild: 0,
  58. })
  59. }
  60. }
  61. }
  62. tmpMap[v.Source] = tmp
  63. list = append(list, tmp)
  64. }
  65. br.Ret = 200
  66. br.Success = true
  67. br.Msg = "获取成功"
  68. br.Data = list
  69. }
  70. // RefreshClassifyList
  71. // @Title 获取指标分类列表接口
  72. // @Description 获取指标分类列表接口
  73. // @Param Source query int true "来源:1:同花顺,2:wind,3:彭博"
  74. // @Success Ret=200 获取成功
  75. // @router /edb_info/refresh/classify_list [get]
  76. func (c *EdbInfoController) RefreshClassifyList() {
  77. br := new(models.BaseResponse).Init()
  78. defer func() {
  79. c.Data["json"] = br
  80. c.ServeJSON()
  81. }()
  82. source, _ := c.GetInt("Source", utils.DATA_SOURCE_MYSTEEL_CHEMICAL)
  83. list := make([]*edb_refresh.BaseClassifyItems, 0)
  84. switch source {
  85. default:
  86. tmpList, err := data_manage.GetAllEdbClassify()
  87. if err != nil && !utils.IsErrNoRow(err) {
  88. br.Msg = "获取失败"
  89. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  90. return
  91. }
  92. for _, v := range tmpList {
  93. list = append(list, &edb_refresh.BaseClassifyItems{
  94. ClassifyId: v.ClassifyId,
  95. ClassifyName: v.ClassifyName,
  96. ParentId: v.ParentId,
  97. UniqueCode: fmt.Sprint(v.ClassifyId),
  98. Children: nil,
  99. })
  100. }
  101. list = buildTree(list, 0)
  102. //fmt.Println(result)
  103. }
  104. br.Ret = 200
  105. br.Success = true
  106. br.Msg = "获取成功"
  107. br.Data = list
  108. }
  109. // 生成多层级列表的递归函数
  110. func buildTree(items []*edb_refresh.BaseClassifyItems, parentId int) []*edb_refresh.BaseClassifyItems {
  111. var result []*edb_refresh.BaseClassifyItems
  112. // 遍历所有分类项
  113. for i := range items {
  114. // 找到当前节点的子节点
  115. if items[i].ParentId == parentId {
  116. // 递归构建子节点的子节点
  117. items[i].Children = buildTree(items, items[i].ClassifyId)
  118. // 将当前节点添加到结果中
  119. result = append(result, items[i])
  120. }
  121. }
  122. return result
  123. }
  124. // RefreshEdbList
  125. // @Title 获取待配置的指标列表接口
  126. // @Description 获取待配置的指标列表接口
  127. // @Param Source query int true "来源:1:同花顺,2:wind,3:彭博"
  128. // @Param SubSource query int true "来源:0:经济数据库,1:日期序列"
  129. // @Param ClassifyId query string false "分类ID,支持多选,用英文,隔开"
  130. // @Param TerminalCode query string false "终端编码"
  131. // @Param SysUserId query string false "创建人,支持多选,用英文,隔开"
  132. // @Param Frequency query string false "频度,支持多选,用英文,隔开"
  133. // @Param Keyword query string false "关键词"
  134. // @Param SortParam query string false "排序字段参数,用来排序的字段, 枚举值:'data_time':日期"
  135. // @Param SortType query string true "如何排序,是正序还是倒序,枚举值:`asc 正序`,`desc 倒叙`"
  136. // @Success 200 {object} data_manage.RefreshBaseEdbInfoResp
  137. // @router /edb_info/refresh/edb_list [get]
  138. func (c *EdbInfoController) RefreshEdbList() {
  139. br := new(models.BaseResponse).Init()
  140. defer func() {
  141. c.Data["json"] = br
  142. c.ServeJSON()
  143. }()
  144. source, _ := c.GetInt("Source")
  145. subSource, _ := c.GetInt("SubSource")
  146. classifyId := c.GetString("ClassifyId")
  147. terminalCode := c.GetString("TerminalCode")
  148. sysUserId := c.GetString("SysUserId")
  149. frequency := c.GetString("Frequency")
  150. keyword := c.GetString("Keyword")
  151. status := c.GetString("Status")
  152. sortParam := c.GetString("SortParam")
  153. sortType := c.GetString("SortType")
  154. switch sortParam {
  155. case "end_date":
  156. default:
  157. sortParam = " end_date "
  158. }
  159. switch sortType {
  160. case "desc", "asc":
  161. default:
  162. sortType = "desc"
  163. }
  164. pageSize, _ := c.GetInt("PageSize")
  165. currentIndex, _ := c.GetInt("CurrentIndex")
  166. var startSize int
  167. if pageSize <= 0 {
  168. pageSize = utils.PageSize20
  169. }
  170. if currentIndex <= 0 {
  171. currentIndex = 1
  172. }
  173. startSize = utils.StartIndex(currentIndex, pageSize)
  174. total, list, err := data.GetList(source, subSource, classifyId, terminalCode, sysUserId, frequency, keyword, status, startSize, pageSize, sortParam, sortType)
  175. if err != nil && !utils.IsErrNoRow(err) {
  176. br.Msg = "获取失败"
  177. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  178. return
  179. }
  180. page := paging.GetPaging(currentIndex, pageSize, total)
  181. resp := data_manage.RefreshBaseEdbInfoResp{
  182. Paging: page,
  183. List: list,
  184. }
  185. // 刷新时间格式化
  186. list, err, errMsg, isSendEmail := data.HandleRefreshTime(source, subSource, list)
  187. if err != nil {
  188. br.Msg = errMsg
  189. br.ErrMsg = "保存失败,Err:" + err.Error()
  190. br.IsSendEmail = isSendEmail
  191. return
  192. }
  193. br.Ret = 200
  194. br.Success = true
  195. br.Msg = "获取成功"
  196. br.Data = resp
  197. }
  198. // GetEdbRefreshDefaultConfig
  199. // @Title 获取待配置的指标列表接口
  200. // @Description 获取待配置的指标列表接口
  201. // @Param Source query int true "来源:1:同花顺,2:wind,3:彭博"
  202. // @Param SubSource query int true "来源:0:经济数据库,1:日期序列"
  203. // @Param Frequency query string false "频度"
  204. // @Success 200 {object} data_manage.RefreshBaseEdbInfoResp
  205. // @router /edb_info/refresh/default_config [get]
  206. func (c *EdbInfoController) GetEdbRefreshDefaultConfig() {
  207. br := new(models.BaseResponse).Init()
  208. defer func() {
  209. c.Data["json"] = br
  210. c.ServeJSON()
  211. }()
  212. source, _ := c.GetInt("Source")
  213. subSource, _ := c.GetInt("SubSource")
  214. frequency := c.GetString("Frequency")
  215. if source <= 0 {
  216. br.Msg = "来源不能为空"
  217. br.IsSendEmail = false
  218. return
  219. }
  220. // 非有色的来源,频度不能为空
  221. if source != utils.DATA_SOURCE_YS && frequency == `` {
  222. br.Msg = "频度不能为空"
  223. br.IsSendEmail = false
  224. return
  225. }
  226. list, err := edb_refresh.GetListBySourceAndFrequency(source, subSource, frequency)
  227. if err != nil {
  228. br.Msg = "获取失败"
  229. br.ErrMsg = err.Error()
  230. return
  231. }
  232. br.Ret = 200
  233. br.Success = true
  234. br.Msg = "获取成功"
  235. br.Data = list
  236. }
  237. // SaveEdbRefreshDefaultConfig
  238. // @Title 设置默认的指标刷新配置接口
  239. // @Description 设置默认的指标刷新配置接口
  240. // @Param request body data_manage.SaveEdbRefreshDefaultConfigReq true "type json string"
  241. // @Success Ret=200 保存成功
  242. // @router /edb_info/refresh/default_config/save [post]
  243. func (c *EdbInfoController) SaveEdbRefreshDefaultConfig() {
  244. br := new(models.BaseResponse).Init()
  245. defer func() {
  246. c.Data["json"] = br
  247. c.ServeJSON()
  248. }()
  249. var req request.SaveEdbRefreshDefaultConfigReq
  250. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  251. if err != nil {
  252. br.Msg = "参数解析异常!"
  253. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  254. return
  255. }
  256. // 保存
  257. err, errMsg, isSendEmail := data.SaveEdbRefreshDefaultConfig(req.Source, req.SubSource, req.Frequency, req.List)
  258. if err != nil {
  259. br.Msg = errMsg
  260. br.ErrMsg = "保存失败,Err:" + err.Error()
  261. br.IsSendEmail = isSendEmail
  262. return
  263. }
  264. br.Ret = 200
  265. br.Success = true
  266. br.Msg = "保存成功"
  267. }
  268. // SaveEdbRefreshConfig
  269. // @Title 设置指标刷新配置接口
  270. // @Description 设置指标刷新配置接口
  271. // @Param request body data_manage.SaveEdbRefreshConfigReq true "type json string"
  272. // @Success 200 {object} data_manage.RefreshBaseEdbInfoResp
  273. // @router /edb_info/refresh/config/save [post]
  274. func (c *EdbInfoController) SaveEdbRefreshConfig() {
  275. br := new(models.BaseResponse).Init()
  276. defer func() {
  277. c.Data["json"] = br
  278. c.ServeJSON()
  279. }()
  280. var req request.SaveEdbRefreshConfigReq
  281. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  282. if err != nil {
  283. br.Msg = "参数解析异常!"
  284. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  285. return
  286. }
  287. // 保存
  288. err, errMsg, isSendEmail := data.SaveEdbRefreshConfig(req.Source, req.SubSource, req.ClassifyId, req.TerminalCode, req.Frequency, req.Keyword, req.Status, req.SysUserId, req.IsSelectAll, req.List, req.EdbSelectIdList, c.SysUser.AdminId, c.SysUser.RealName)
  289. if err != nil {
  290. br.Msg = errMsg
  291. br.ErrMsg = "保存失败,Err:" + err.Error()
  292. br.IsSendEmail = isSendEmail
  293. return
  294. }
  295. br.Ret = 200
  296. br.Success = true
  297. br.Msg = "保存成功"
  298. }
  299. // SaveEdbRefreshStatus
  300. // @Title 设置指标刷新状态接口
  301. // @Description 设置指标刷新状态接口
  302. // @Param request body data_manage.SaveEdbRefreshStatusReq true "type json string"
  303. // @Success 200 {object} data_manage.RefreshBaseEdbInfoResp
  304. // @router /edb_info/refresh/status/save [post]
  305. func (c *EdbInfoController) SaveEdbRefreshStatus() {
  306. br := new(models.BaseResponse).Init()
  307. defer func() {
  308. c.Data["json"] = br
  309. c.ServeJSON()
  310. }()
  311. var req request.SaveEdbRefreshStatusReq
  312. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  313. if err != nil {
  314. br.Msg = "参数解析异常!"
  315. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  316. return
  317. }
  318. if req.Source <= 0 {
  319. br.Msg = "来源不能为空"
  320. br.IsSendEmail = false
  321. return
  322. }
  323. // todo 批量设置刷新状态修改
  324. edbIdList := make([]int, 0)
  325. edbCodeList := make([]string, 0)
  326. // 指标id列表
  327. if req.IsSelectAll {
  328. // 如果是列表全选
  329. _, edbList, err := data.GetList(req.Source, req.SubSource, req.ClassifyId, req.TerminalCode, req.SysUserId, req.Frequency, req.Keyword, req.Status, 0, 100000, "", "")
  330. if err != nil && !utils.IsErrNoRow(err) {
  331. br.Msg = "获取失败"
  332. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  333. return
  334. }
  335. // 不配置的指标id
  336. notIdMap := make(map[int]int, 0)
  337. for _, v := range req.EdbSelectIdList {
  338. notIdMap[v] = v
  339. }
  340. for _, v := range edbList {
  341. _, ok := notIdMap[v.EdbInfoId]
  342. // 在不配置的指标id列表内的话,那就过滤
  343. if ok {
  344. continue
  345. }
  346. // 加入到待配置的指标列表id
  347. edbIdList = append(edbIdList, v.EdbInfoId)
  348. edbCodeList = append(edbCodeList, v.IndexCode)
  349. }
  350. } else {
  351. edbIdList = req.EdbSelectIdList
  352. }
  353. if len(edbIdList) <= 0 {
  354. br.Msg = "指标不能为空"
  355. br.IsSendEmail = false
  356. return
  357. }
  358. isStop := 0
  359. if req.ModifyStatus == `暂停` {
  360. isStop = 1
  361. }
  362. if len(edbIdList) <= 0 {
  363. br.Msg = "指标不能为空"
  364. br.IsSendEmail = false
  365. return
  366. }
  367. //查询计算指标信息
  368. calculateEdbIdList := make([]int, 0)
  369. if isStop == 1 {
  370. fromEdbIdList := make([]int, 0)
  371. edbList, e := data_manage.GetEdbInfoByIdList(edbIdList)
  372. if e != nil && !utils.IsErrNoRow(e) {
  373. br.Msg = "获取失败"
  374. br.ErrMsg = "获取数据失败,Err:" + e.Error()
  375. return
  376. }
  377. for _, v := range edbList {
  378. if v.EdbInfoType == 0 {
  379. fromEdbIdList = append(fromEdbIdList, v.EdbInfoId)
  380. }
  381. }
  382. hasFind := make(map[int]struct{})
  383. calculateEdbIdList, err = data.GetCalculateEdbByFromEdbInfo(fromEdbIdList, calculateEdbIdList, hasFind)
  384. if err != nil {
  385. br.Msg = "查询计算指标信息失败"
  386. br.ErrMsg = "查询计算指标信息失败,Err:" + err.Error()
  387. return
  388. }
  389. }
  390. switch req.Source {
  391. default:
  392. err = data_manage.ModifyEdbInfoUpdateStatus(edbIdList, isStop, calculateEdbIdList)
  393. }
  394. if err != nil {
  395. br.Msg = `保存失败`
  396. br.ErrMsg = "保存失败,Err:" + err.Error()
  397. return
  398. }
  399. br.Ret = 200
  400. br.Success = true
  401. br.Msg = "保存成功"
  402. }
  403. // SaveEdbRefreshStatusSingle
  404. // @Title 设置单个指标刷新状态接口
  405. // @Description 设置单个指标刷新状态接口
  406. // @Param request body data_manage.SaveEdbRefreshStatusReq true "type json string"
  407. // @Success 200 {object} data_manage.RefreshBaseEdbInfoResp
  408. // @router /edb_info/single_refresh/status/save [post]
  409. func (c *EdbInfoController) SaveEdbRefreshStatusSingle() {
  410. br := new(models.BaseResponse).Init()
  411. defer func() {
  412. c.Data["json"] = br
  413. c.ServeJSON()
  414. }()
  415. var req request.SaveEdbRefreshStatusSingleReq
  416. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  417. if err != nil {
  418. br.Msg = "参数解析异常!"
  419. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  420. return
  421. }
  422. if req.EdbInfoId <= 0 {
  423. br.Msg = "请选择指标"
  424. br.IsSendEmail = false
  425. return
  426. }
  427. // 查询指标
  428. edbInfo, err := data_manage.GetEdbInfoById(req.EdbInfoId)
  429. if err != nil {
  430. if utils.IsErrNoRow(err) {
  431. br.Msg = "指标不存在"
  432. return
  433. }
  434. br.Msg = "查询指标失败"
  435. br.ErrMsg = "查询指标失败,Err:" + err.Error()
  436. return
  437. }
  438. // 查询指标的指标代码
  439. calculateEdbIdList := make([]int, 0)
  440. isStop := 0
  441. if req.ModifyStatus == `暂停` {
  442. isStop = 1
  443. }
  444. if isStop == 1 && edbInfo.EdbInfoType == 0 { //基础指标, 只有在停用的情况下才需要查询计算指标
  445. hasFind := make(map[int]struct{})
  446. calculateEdbIdList, err = data.GetCalculateEdbByFromEdbInfo([]int{edbInfo.EdbInfoId}, calculateEdbIdList, hasFind)
  447. if err != nil {
  448. br.Msg = "查询计算指标信息失败"
  449. br.ErrMsg = "查询计算指标信息失败,Err:" + err.Error()
  450. return
  451. }
  452. }
  453. switch edbInfo.Source {
  454. default: // wind
  455. err = data_manage.EdbInfoUpdateStatusByEdbInfoId([]int{edbInfo.EdbInfoId}, isStop, calculateEdbIdList)
  456. }
  457. if err != nil {
  458. br.Msg = `保存失败`
  459. br.ErrMsg = "保存失败,Err:" + err.Error()
  460. return
  461. }
  462. br.Ret = 200
  463. br.Success = true
  464. br.Msg = "保存成功"
  465. }
  466. // SaveRelationEdbRefreshStatus
  467. // @Title 批量设置被引用的指标刷新状态接口
  468. // @Description 批量设置被引用的指标刷新状态接口
  469. // @Param request body data_manage.SaveEdbRefreshStatusReq true "type json string"
  470. // @Success 200 {object} data_manage.RefreshBaseEdbInfoResp
  471. // @router /edb_info/relation/refresh/save [post]
  472. func (c *EdbInfoController) SaveRelationEdbRefreshStatus() {
  473. br := new(models.BaseResponse).Init()
  474. defer func() {
  475. c.Data["json"] = br
  476. c.ServeJSON()
  477. }()
  478. var req request.SaveRelationEdbRefreshStatusReq
  479. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  480. if err != nil {
  481. br.Msg = "参数解析异常!"
  482. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  483. return
  484. }
  485. if req.Source <= 0 {
  486. br.Msg = "来源不能为空"
  487. br.IsSendEmail = false
  488. return
  489. }
  490. edbType := 1 //基础指标
  491. switch req.Source {
  492. case utils.DATA_SOURCE_MYSTEEL_CHEMICAL, utils.DATA_SOURCE_WIND: // wind
  493. case -1:
  494. req.Source = 0
  495. edbType = 2
  496. default:
  497. br.Msg = "暂不支持设置其他来源的指标"
  498. return
  499. }
  500. // todo 批量设置刷新状态修改
  501. edbIdList := make([]int, 0)
  502. edbCodeList := make([]string, 0)
  503. // 指标id列表
  504. if req.IsSelectAll {
  505. // 如果是列表全选
  506. _, edbList, err := data.GetEdbRelationList(req.Source, edbType, req.ClassifyId, req.SysUserId, req.Frequency, req.Keyword, req.Status, 0, 100000, "", "")
  507. if err != nil && !utils.IsErrNoRow(err) {
  508. br.Msg = "获取失败"
  509. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  510. return
  511. }
  512. // 不配置的指标id
  513. notIdMap := make(map[int]int, 0)
  514. for _, v := range req.EdbSelectIdList {
  515. notIdMap[v] = v
  516. }
  517. for _, v := range edbList {
  518. _, ok := notIdMap[v.EdbInfoId]
  519. // 在不配置的指标id列表内的话,那就过滤
  520. if ok {
  521. continue
  522. }
  523. // 加入到待配置的指标列表id
  524. edbIdList = append(edbIdList, v.EdbInfoId)
  525. }
  526. } else {
  527. edbIdList = req.EdbSelectIdList
  528. }
  529. if len(edbIdList) <= 0 {
  530. br.Msg = "指标不能为空"
  531. br.IsSendEmail = false
  532. return
  533. }
  534. //查询指标信息
  535. edbList, e := data_manage.GetEdbInfoByIdList(edbIdList)
  536. if e != nil && !utils.IsErrNoRow(e) {
  537. br.Msg = "获取失败"
  538. br.ErrMsg = "获取数据失败,Err:" + e.Error()
  539. return
  540. }
  541. fromEdbIdList := make([]int, 0)
  542. for _, v := range edbList {
  543. if req.Source == utils.DATA_SOURCE_MYSTEEL_CHEMICAL {
  544. edbCodeList = append(edbCodeList, v.EdbCode)
  545. }
  546. if v.EdbInfoType == 0 {
  547. fromEdbIdList = append(fromEdbIdList, v.EdbInfoId)
  548. }
  549. }
  550. isStop := 0
  551. if req.ModifyStatus == `暂停` {
  552. isStop = 1
  553. }
  554. // 查询计算指标ID
  555. // 查询相关的计算指标
  556. calculateEdbIdList := make([]int, 0)
  557. if isStop == 1 {
  558. hasFind := make(map[int]struct{})
  559. calculateEdbIdList, err = data.GetCalculateEdbByFromEdbInfo(fromEdbIdList, calculateEdbIdList, hasFind)
  560. if err != nil {
  561. br.Msg = "查询计算指标信息失败"
  562. br.ErrMsg = "查询计算指标信息失败,Err:" + err.Error()
  563. return
  564. }
  565. }
  566. switch req.Source {
  567. default:
  568. err = data_manage.EdbInfoUpdateStatusByEdbInfoId(edbIdList, isStop, calculateEdbIdList)
  569. }
  570. if err != nil {
  571. br.Msg = `保存失败`
  572. br.ErrMsg = "保存失败,Err:" + err.Error()
  573. return
  574. }
  575. br.Ret = 200
  576. br.Success = true
  577. br.Msg = "保存成功"
  578. }
  579. // GetEdbRefreshEdbConfig
  580. // @Title 获取单个指标的刷新配置列表接口
  581. // @Description 获取单个指标的刷新配置列表接口
  582. // @Param Source query int true "来源:1:同花顺,2:wind,3:彭博"
  583. // @Param SubSource query int true "来源:0:经济数据库,1:日期序列"
  584. // @Param EdbInfoId query int false "指标id"
  585. // @Success 200 {object} data_manage.RefreshBaseEdbInfoResp
  586. // @router /edb_info/refresh/edb_config [get]
  587. func (c *EdbInfoController) GetEdbRefreshEdbConfig() {
  588. br := new(models.BaseResponse).Init()
  589. defer func() {
  590. c.Data["json"] = br
  591. c.ServeJSON()
  592. }()
  593. source, _ := c.GetInt("Source")
  594. subSource, _ := c.GetInt("SubSource")
  595. edbInfoId, _ := c.GetInt("EdbInfoId")
  596. if source <= 0 {
  597. br.Msg = "来源不能为空"
  598. br.IsSendEmail = false
  599. return
  600. }
  601. if edbInfoId <= 0 {
  602. br.Msg = "指标不能为空"
  603. br.IsSendEmail = false
  604. return
  605. }
  606. // 获取指标的刷新配置列表
  607. list, err := edb_refresh.GetEdbRefreshConfigListBySourceAndeEdbInfoId(source, subSource, edbInfoId)
  608. if err != nil {
  609. br.Msg = "获取失败"
  610. br.ErrMsg = err.Error()
  611. return
  612. }
  613. if len(list) > 0 {
  614. br.Ret = 200
  615. br.Success = true
  616. br.Msg = "获取成功"
  617. br.Data = list
  618. return
  619. }
  620. // 如果没有找到该指标的配置,那么就查询默认配置
  621. var frequency string
  622. // 根据类型查找指标的频度信息
  623. switch source {
  624. default:
  625. item, err := data_manage.GetEdbInfoById(edbInfoId)
  626. if err != nil {
  627. br.Msg = "获取指标信息失败"
  628. br.ErrMsg = err.Error()
  629. return
  630. }
  631. frequency = item.Frequency
  632. }
  633. if frequency == `` {
  634. br.Msg = "获取的指标频度信息异常"
  635. br.IsSendEmail = false
  636. return
  637. }
  638. tmpList, err := edb_refresh.GetListBySourceAndFrequency(source, subSource, frequency)
  639. if err != nil {
  640. br.Msg = "获取失败"
  641. br.ErrMsg = err.Error()
  642. return
  643. }
  644. list = make([]*edb_refresh.EdbRefreshConfigItem, 0)
  645. for _, v := range tmpList {
  646. list = append(list, &edb_refresh.EdbRefreshConfigItem{
  647. RefreshFrequency: v.RefreshFrequency,
  648. RefreshFrequencyDay: v.RefreshFrequencyDay,
  649. RefreshTime: v.RefreshTime,
  650. RefreshAllData: v.RefreshAllData,
  651. RefreshDataNum: v.RefreshDataNum,
  652. })
  653. }
  654. br.Ret = 200
  655. br.Success = true
  656. br.Msg = "获取成功"
  657. br.Data = list
  658. }