edb_info_refresh.go 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865
  1. package data_manage
  2. import (
  3. "encoding/json"
  4. "eta/eta_api/models"
  5. "eta/eta_api/models/data_manage"
  6. "eta/eta_api/models/data_manage/edb_refresh"
  7. "eta/eta_api/models/data_manage/edb_refresh/request"
  8. "eta/eta_api/services/data"
  9. "eta/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. case utils.DATA_SOURCE_MYSTEEL_CHEMICAL: // 钢联
  86. rootList, err := data_manage.GetBaseFromMysteelChemicalClassifyByParentId(0)
  87. if err != nil && err.Error() != utils.ErrNoRow() {
  88. br.Msg = "获取失败"
  89. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  90. return
  91. }
  92. classifyAll, err := data_manage.GetAllBaseFromMysteelChemicalClassify()
  93. if err != nil && err.Error() != utils.ErrNoRow() {
  94. br.Msg = "获取失败"
  95. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  96. return
  97. }
  98. rootChildMap := make(map[int][]*edb_refresh.BaseClassifyItems)
  99. for _, v := range classifyAll {
  100. //tmpList, ok := rootChildMap[v.ParentId]
  101. //if !ok {
  102. // tmpList = make([]data_manage.BaseClassifyItems, 0)
  103. //}
  104. //tmpList = append(tmpList, data_manage.BaseClassifyItems{
  105. // ClassifyId: v.BaseFromMysteelChemicalClassifyId,
  106. // ClassifyName: v.ClassifyName,
  107. // ParentId: v.ParentId,
  108. // UniqueCode: fmt.Sprint(v.BaseFromMysteelChemicalClassifyId),
  109. // Children: nil,
  110. //})
  111. //rootChildMap[v.ParentId] = tmpList
  112. rootChildMap[v.ParentId] = append(rootChildMap[v.ParentId], &edb_refresh.BaseClassifyItems{
  113. ClassifyId: v.BaseFromMysteelChemicalClassifyId,
  114. ClassifyName: v.ClassifyName,
  115. ParentId: v.ParentId,
  116. UniqueCode: fmt.Sprint(v.BaseFromMysteelChemicalClassifyId),
  117. Children: nil,
  118. })
  119. }
  120. for _, v := range rootList {
  121. tmp := &edb_refresh.BaseClassifyItems{
  122. ClassifyId: v.BaseFromMysteelChemicalClassifyId,
  123. ClassifyName: v.ClassifyName,
  124. ParentId: v.ParentId,
  125. UniqueCode: fmt.Sprint(v.BaseFromMysteelChemicalClassifyId),
  126. Children: nil,
  127. }
  128. if existItems, ok := rootChildMap[v.BaseFromMysteelChemicalClassifyId]; ok {
  129. tmp.Children = existItems
  130. } else {
  131. items := make([]*edb_refresh.BaseClassifyItems, 0)
  132. tmp.Children = items
  133. }
  134. list = append(list, tmp)
  135. }
  136. case utils.DATA_SOURCE_YS: // 有色
  137. list = append(list, &edb_refresh.BaseClassifyItems{
  138. ClassifyId: 0,
  139. ClassifyName: "未分类",
  140. ParentId: 0,
  141. UniqueCode: fmt.Sprint(0),
  142. Children: nil,
  143. })
  144. rootList, err := data_manage.GetBaseFromSmmClassifyByParentId(0)
  145. if err != nil && err.Error() != utils.ErrNoRow() {
  146. br.Msg = "获取失败"
  147. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  148. return
  149. }
  150. classifyAll, err := data_manage.GetAllBaseFromSmmClassify()
  151. if err != nil && err.Error() != utils.ErrNoRow() {
  152. br.Msg = "获取失败"
  153. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  154. return
  155. }
  156. rootChildMap := make(map[int][]*edb_refresh.BaseClassifyItems)
  157. for _, v := range classifyAll {
  158. rootChildMap[v.ParentId] = append(rootChildMap[v.ParentId], &edb_refresh.BaseClassifyItems{
  159. ClassifyId: v.ClassifyId,
  160. ClassifyName: v.ClassifyName,
  161. ParentId: v.ParentId,
  162. UniqueCode: fmt.Sprint(v.ClassifyId),
  163. Children: nil,
  164. })
  165. }
  166. for _, v := range rootList {
  167. tmp := &edb_refresh.BaseClassifyItems{
  168. ClassifyId: v.ClassifyId,
  169. ClassifyName: v.ClassifyName,
  170. ParentId: v.ParentId,
  171. UniqueCode: fmt.Sprint(v.ClassifyId),
  172. Children: nil,
  173. }
  174. if existItems, ok := rootChildMap[v.ClassifyId]; ok {
  175. tmp.Children = existItems
  176. } else {
  177. items := make([]*edb_refresh.BaseClassifyItems, 0)
  178. tmp.Children = items
  179. }
  180. list = append(list, tmp)
  181. }
  182. default:
  183. tmpList, err := data_manage.GetAllEdbClassify()
  184. if err != nil && err.Error() != utils.ErrNoRow() {
  185. br.Msg = "获取失败"
  186. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  187. return
  188. }
  189. for _, v := range tmpList {
  190. list = append(list, &edb_refresh.BaseClassifyItems{
  191. ClassifyId: v.ClassifyId,
  192. ClassifyName: v.ClassifyName,
  193. ParentId: v.ParentId,
  194. UniqueCode: fmt.Sprint(v.ClassifyId),
  195. Children: nil,
  196. })
  197. }
  198. list = buildTree(list, 0)
  199. //fmt.Println(result)
  200. }
  201. br.Ret = 200
  202. br.Success = true
  203. br.Msg = "获取成功"
  204. br.Data = list
  205. }
  206. // 生成多层级列表的递归函数
  207. func buildTree(items []*edb_refresh.BaseClassifyItems, parentId int) []*edb_refresh.BaseClassifyItems {
  208. var result []*edb_refresh.BaseClassifyItems
  209. // 遍历所有分类项
  210. for i := range items {
  211. // 找到当前节点的子节点
  212. if items[i].ParentId == parentId {
  213. // 递归构建子节点的子节点
  214. items[i].Children = buildTree(items, items[i].ClassifyId)
  215. // 将当前节点添加到结果中
  216. result = append(result, items[i])
  217. }
  218. }
  219. return result
  220. }
  221. // RefreshEdbList
  222. // @Title 获取待配置的指标列表接口
  223. // @Description 获取待配置的指标列表接口
  224. // @Param Source query int true "来源:1:同花顺,2:wind,3:彭博"
  225. // @Param SubSource query int true "来源:0:经济数据库,1:日期序列"
  226. // @Param ClassifyId query string false "分类ID,支持多选,用英文,隔开"
  227. // @Param TerminalCode query string false "终端编码"
  228. // @Param SysUserId query string false "创建人,支持多选,用英文,隔开"
  229. // @Param Frequency query string false "频度,支持多选,用英文,隔开"
  230. // @Param Keyword query string false "关键词"
  231. // @Param SortParam query string false "排序字段参数,用来排序的字段, 枚举值:'data_time':日期"
  232. // @Param SortType query string true "如何排序,是正序还是倒序,枚举值:`asc 正序`,`desc 倒叙`"
  233. // @Success 200 {object} data_manage.RefreshBaseEdbInfoResp
  234. // @router /edb_info/refresh/edb_list [get]
  235. func (c *EdbInfoController) RefreshEdbList() {
  236. br := new(models.BaseResponse).Init()
  237. defer func() {
  238. c.Data["json"] = br
  239. c.ServeJSON()
  240. }()
  241. source, _ := c.GetInt("Source")
  242. subSource, _ := c.GetInt("SubSource")
  243. classifyId := c.GetString("ClassifyId")
  244. terminalCode := c.GetString("TerminalCode")
  245. sysUserId := c.GetString("SysUserId")
  246. frequency := c.GetString("Frequency")
  247. keyword := c.GetString("Keyword")
  248. status := c.GetString("Status")
  249. sortParam := c.GetString("SortParam")
  250. sortType := c.GetString("SortType")
  251. switch sortParam {
  252. case "end_date":
  253. default:
  254. sortParam = " end_date "
  255. }
  256. switch sortType {
  257. case "desc", "asc":
  258. default:
  259. sortType = "desc"
  260. }
  261. pageSize, _ := c.GetInt("PageSize")
  262. currentIndex, _ := c.GetInt("CurrentIndex")
  263. var startSize int
  264. if pageSize <= 0 {
  265. pageSize = utils.PageSize20
  266. }
  267. if currentIndex <= 0 {
  268. currentIndex = 1
  269. }
  270. startSize = utils.StartIndex(currentIndex, pageSize)
  271. total, list, err := data.GetList(source, subSource, classifyId, terminalCode, sysUserId, frequency, keyword, status, startSize, pageSize, sortParam, sortType)
  272. if err != nil && err.Error() != utils.ErrNoRow() {
  273. br.Msg = "获取失败"
  274. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  275. return
  276. }
  277. page := paging.GetPaging(currentIndex, pageSize, total)
  278. resp := data_manage.RefreshBaseEdbInfoResp{
  279. Paging: page,
  280. List: list,
  281. }
  282. // 刷新时间格式化
  283. list, err, errMsg, isSendEmail := data.HandleRefreshTime(source, subSource, list)
  284. if err != nil {
  285. br.Msg = errMsg
  286. br.ErrMsg = "保存失败,Err:" + err.Error()
  287. br.IsSendEmail = isSendEmail
  288. return
  289. }
  290. br.Ret = 200
  291. br.Success = true
  292. br.Msg = "获取成功"
  293. br.Data = resp
  294. }
  295. // GetEdbRefreshDefaultConfig
  296. // @Title 获取待配置的指标列表接口
  297. // @Description 获取待配置的指标列表接口
  298. // @Param Source query int true "来源:1:同花顺,2:wind,3:彭博"
  299. // @Param SubSource query int true "来源:0:经济数据库,1:日期序列"
  300. // @Param Frequency query string false "频度"
  301. // @Success 200 {object} data_manage.RefreshBaseEdbInfoResp
  302. // @router /edb_info/refresh/default_config [get]
  303. func (c *EdbInfoController) GetEdbRefreshDefaultConfig() {
  304. br := new(models.BaseResponse).Init()
  305. defer func() {
  306. c.Data["json"] = br
  307. c.ServeJSON()
  308. }()
  309. source, _ := c.GetInt("Source")
  310. subSource, _ := c.GetInt("SubSource")
  311. frequency := c.GetString("Frequency")
  312. if source <= 0 {
  313. br.Msg = "来源不能为空"
  314. br.IsSendEmail = false
  315. return
  316. }
  317. // 非有色的来源,频度不能为空
  318. if source != utils.DATA_SOURCE_YS && frequency == `` {
  319. br.Msg = "频度不能为空"
  320. br.IsSendEmail = false
  321. return
  322. }
  323. list, err := edb_refresh.GetListBySourceAndFrequency(source, subSource, frequency)
  324. if err != nil {
  325. br.Msg = "获取失败"
  326. br.ErrMsg = err.Error()
  327. return
  328. }
  329. br.Ret = 200
  330. br.Success = true
  331. br.Msg = "获取成功"
  332. br.Data = list
  333. }
  334. // SaveEdbRefreshDefaultConfig
  335. // @Title 设置默认的指标刷新配置接口
  336. // @Description 设置默认的指标刷新配置接口
  337. // @Param request body data_manage.SaveEdbRefreshDefaultConfigReq true "type json string"
  338. // @Success Ret=200 保存成功
  339. // @router /edb_info/refresh/default_config/save [post]
  340. func (c *EdbInfoController) SaveEdbRefreshDefaultConfig() {
  341. br := new(models.BaseResponse).Init()
  342. defer func() {
  343. c.Data["json"] = br
  344. c.ServeJSON()
  345. }()
  346. var req request.SaveEdbRefreshDefaultConfigReq
  347. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  348. if err != nil {
  349. br.Msg = "参数解析异常!"
  350. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  351. return
  352. }
  353. // 保存
  354. err, errMsg, isSendEmail := data.SaveEdbRefreshDefaultConfig(req.Source, req.SubSource, req.Frequency, req.List)
  355. if err != nil {
  356. br.Msg = errMsg
  357. br.ErrMsg = "保存失败,Err:" + err.Error()
  358. br.IsSendEmail = isSendEmail
  359. return
  360. }
  361. br.Ret = 200
  362. br.Success = true
  363. br.Msg = "保存成功"
  364. }
  365. // SaveEdbRefreshConfig
  366. // @Title 设置指标刷新配置接口
  367. // @Description 设置指标刷新配置接口
  368. // @Param request body data_manage.SaveEdbRefreshConfigReq true "type json string"
  369. // @Success 200 {object} data_manage.RefreshBaseEdbInfoResp
  370. // @router /edb_info/refresh/config/save [post]
  371. func (c *EdbInfoController) SaveEdbRefreshConfig() {
  372. br := new(models.BaseResponse).Init()
  373. defer func() {
  374. c.Data["json"] = br
  375. c.ServeJSON()
  376. }()
  377. var req request.SaveEdbRefreshConfigReq
  378. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  379. if err != nil {
  380. br.Msg = "参数解析异常!"
  381. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  382. return
  383. }
  384. // 保存
  385. 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)
  386. if err != nil {
  387. br.Msg = errMsg
  388. br.ErrMsg = "保存失败,Err:" + err.Error()
  389. br.IsSendEmail = isSendEmail
  390. return
  391. }
  392. br.Ret = 200
  393. br.Success = true
  394. br.Msg = "保存成功"
  395. }
  396. // SaveEdbRefreshStatus
  397. // @Title 设置指标刷新状态接口
  398. // @Description 设置指标刷新状态接口
  399. // @Param request body data_manage.SaveEdbRefreshStatusReq true "type json string"
  400. // @Success 200 {object} data_manage.RefreshBaseEdbInfoResp
  401. // @router /edb_info/refresh/status/save [post]
  402. func (c *EdbInfoController) SaveEdbRefreshStatus() {
  403. br := new(models.BaseResponse).Init()
  404. defer func() {
  405. c.Data["json"] = br
  406. c.ServeJSON()
  407. }()
  408. var req request.SaveEdbRefreshStatusReq
  409. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  410. if err != nil {
  411. br.Msg = "参数解析异常!"
  412. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  413. return
  414. }
  415. if req.Source <= 0 {
  416. br.Msg = "来源不能为空"
  417. br.IsSendEmail = false
  418. return
  419. }
  420. // todo 批量设置刷新状态修改
  421. edbIdList := make([]int, 0)
  422. edbCodeList := make([]string, 0)
  423. // 指标id列表
  424. if req.IsSelectAll {
  425. // 如果是列表全选
  426. _, edbList, err := data.GetList(req.Source, req.SubSource, req.ClassifyId, req.TerminalCode, req.SysUserId, req.Frequency, req.Keyword, req.Status, 0, 100000, "", "")
  427. if err != nil && err.Error() != utils.ErrNoRow() {
  428. br.Msg = "获取失败"
  429. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  430. return
  431. }
  432. // 不配置的指标id
  433. notIdMap := make(map[int]int, 0)
  434. for _, v := range req.EdbSelectIdList {
  435. notIdMap[v] = v
  436. }
  437. for _, v := range edbList {
  438. _, ok := notIdMap[v.EdbInfoId]
  439. // 在不配置的指标id列表内的话,那就过滤
  440. if ok {
  441. continue
  442. }
  443. // 加入到待配置的指标列表id
  444. edbIdList = append(edbIdList, v.EdbInfoId)
  445. edbCodeList = append(edbCodeList, v.IndexCode)
  446. }
  447. } else {
  448. edbIdList = req.EdbSelectIdList
  449. }
  450. if len(edbIdList) <= 0 {
  451. br.Msg = "指标不能为空"
  452. br.IsSendEmail = false
  453. return
  454. }
  455. isStop := 0
  456. if req.ModifyStatus == `暂停` {
  457. isStop = 1
  458. }
  459. switch req.Source {
  460. case utils.DATA_SOURCE_MYSTEEL_CHEMICAL: // 钢联
  461. err = data_manage.ModifyMysteelChemicalUpdateStatus(edbIdList, edbCodeList, isStop)
  462. case utils.DATA_SOURCE_YS: // 有色
  463. err = data_manage.ModifySmmUpdateStatus(edbIdList, edbCodeList, isStop)
  464. default:
  465. err = data_manage.ModifyEdbInfoUpdateStatus(edbIdList, isStop)
  466. }
  467. if err != nil {
  468. br.Msg = `保存失败`
  469. br.ErrMsg = "保存失败,Err:" + err.Error()
  470. return
  471. }
  472. br.Ret = 200
  473. br.Success = true
  474. br.Msg = "保存成功"
  475. }
  476. // SaveEdbRefreshStatusSingle
  477. // @Title 设置单个指标刷新状态接口
  478. // @Description 设置单个指标刷新状态接口
  479. // @Param request body data_manage.SaveEdbRefreshStatusReq true "type json string"
  480. // @Success 200 {object} data_manage.RefreshBaseEdbInfoResp
  481. // @router /edb_info/single_refresh/status/save [post]
  482. func (c *EdbInfoController) SaveEdbRefreshStatusSingle() {
  483. br := new(models.BaseResponse).Init()
  484. defer func() {
  485. c.Data["json"] = br
  486. c.ServeJSON()
  487. }()
  488. var req request.SaveEdbRefreshStatusSingleReq
  489. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  490. if err != nil {
  491. br.Msg = "参数解析异常!"
  492. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  493. return
  494. }
  495. if req.EdbInfoId <= 0 {
  496. br.Msg = "请选择指标"
  497. br.IsSendEmail = false
  498. return
  499. }
  500. // 查询指标
  501. edbInfo, err := data_manage.GetEdbInfoById(req.EdbInfoId)
  502. if err != nil {
  503. if err.Error() == utils.ErrNoRow() {
  504. br.Msg = "指标不存在"
  505. return
  506. }
  507. br.Msg = "查询指标失败"
  508. br.ErrMsg = "查询指标失败,Err:" + err.Error()
  509. return
  510. }
  511. // 查询指标的指标代码
  512. calculateEdbIdList := make([]int, 0)
  513. isStop := 0
  514. if req.ModifyStatus == `暂停` {
  515. isStop = 1
  516. }
  517. calculateEdb := make([]*data_manage.EdbInfoCalculateMapping, 0)
  518. if edbInfo.EdbInfoType == 0 && edbInfo.EdbType == 1 { //基础指标
  519. // 查询相关的计算指标
  520. calculateEdb, err = data_manage.GetAllCalculateByEdbInfoId(edbInfo.EdbInfoId)
  521. if err != nil {
  522. if err.Error() == utils.ErrNoRow() {
  523. br.Msg = "指标不存在"
  524. return
  525. }
  526. br.Msg = "查询计算指标失败"
  527. br.ErrMsg = "查询计算指标失败,Err:" + err.Error()
  528. return
  529. }
  530. }
  531. // 遍历指标列表,把计算指标id整理成数组
  532. if len(calculateEdb) > 0 {
  533. for _, calculateEdbInfo := range calculateEdb {
  534. calculateEdbIdList = append(calculateEdbIdList, calculateEdbInfo.EdbInfoId)
  535. }
  536. }
  537. switch edbInfo.Source {
  538. case utils.DATA_SOURCE_MYSTEEL_CHEMICAL: // 钢联
  539. err = data_manage.ModifyMysteelChemicalUpdateStatusByEdbInfoId(edbInfo.EdbInfoId, isStop, edbInfo.EdbCode, calculateEdbIdList)
  540. case utils.DATA_SOURCE_WIND: // wind
  541. err = data_manage.WindEdbInfoUpdateStatusByEdbInfoId([]int{edbInfo.EdbInfoId}, isStop, calculateEdbIdList)
  542. default:
  543. // todo 支持其他的指标设置
  544. err = data_manage.EdbInfoUpdateStatusByEdbInfoId([]int{edbInfo.EdbInfoId}, isStop)
  545. return
  546. }
  547. if err != nil {
  548. br.Msg = `保存失败`
  549. br.ErrMsg = "保存失败,Err:" + err.Error()
  550. return
  551. }
  552. br.Ret = 200
  553. br.Success = true
  554. br.Msg = "保存成功"
  555. }
  556. // SaveRelationEdbRefreshStatus
  557. // @Title 批量设置被引用的指标刷新状态接口
  558. // @Description 批量设置被引用的指标刷新状态接口
  559. // @Param request body data_manage.SaveEdbRefreshStatusReq true "type json string"
  560. // @Success 200 {object} data_manage.RefreshBaseEdbInfoResp
  561. // @router /edb_info/relation/refresh/save [post]
  562. func (c *EdbInfoController) SaveRelationEdbRefreshStatus() {
  563. br := new(models.BaseResponse).Init()
  564. defer func() {
  565. c.Data["json"] = br
  566. c.ServeJSON()
  567. }()
  568. var req request.SaveRelationEdbRefreshStatusReq
  569. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  570. if err != nil {
  571. br.Msg = "参数解析异常!"
  572. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  573. return
  574. }
  575. if req.Source <= 0 {
  576. br.Msg = "来源不能为空"
  577. br.IsSendEmail = false
  578. return
  579. }
  580. switch req.Source {
  581. case utils.DATA_SOURCE_MYSTEEL_CHEMICAL, utils.DATA_SOURCE_WIND: // wind
  582. default:
  583. br.Msg = "暂不支持设置其他来源的指标"
  584. return
  585. }
  586. // todo 批量设置刷新状态修改
  587. edbIdList := make([]int, 0)
  588. edbCodeList := make([]string, 0)
  589. // 指标id列表
  590. if req.IsSelectAll {
  591. // 如果是列表全选
  592. _, edbList, err := data.GetEdbRelationList(req.Source, req.EdbInfoType, req.ClassifyId, req.SysUserId, req.Frequency, req.Keyword, req.Status, 0, 100000, "", "")
  593. if err != nil && err.Error() != utils.ErrNoRow() {
  594. br.Msg = "获取失败"
  595. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  596. return
  597. }
  598. // 不配置的指标id
  599. notIdMap := make(map[int]int, 0)
  600. for _, v := range req.EdbSelectIdList {
  601. notIdMap[v] = v
  602. }
  603. for _, v := range edbList {
  604. _, ok := notIdMap[v.EdbInfoId]
  605. // 在不配置的指标id列表内的话,那就过滤
  606. if ok {
  607. continue
  608. }
  609. // 加入到待配置的指标列表id
  610. edbIdList = append(edbIdList, v.EdbInfoId)
  611. edbCodeList = append(edbCodeList, v.EdbCode)
  612. }
  613. } else {
  614. edbIdList = req.EdbSelectIdList
  615. if req.Source == utils.DATA_SOURCE_MYSTEEL_CHEMICAL {
  616. //查询指标信息
  617. edbList, e := data_manage.GetEdbInfoByIdList(edbIdList)
  618. if e != nil && e.Error() != utils.ErrNoRow() {
  619. br.Msg = "获取失败"
  620. br.ErrMsg = "获取数据失败,Err:" + e.Error()
  621. return
  622. }
  623. for _, v := range edbList {
  624. edbCodeList = append(edbCodeList, v.EdbCode)
  625. }
  626. }
  627. }
  628. if len(edbIdList) <= 0 {
  629. br.Msg = "指标不能为空"
  630. br.IsSendEmail = false
  631. return
  632. }
  633. isStop := 0
  634. if req.ModifyStatus == `暂停` {
  635. isStop = 1
  636. }
  637. // 查询计算指标ID
  638. // 查询相关的计算指标
  639. calculateEdbIdList := make([]int, 0)
  640. calculateEdb, err := data_manage.GetAllCalculateByEdbInfoIds(edbIdList)
  641. if err != nil {
  642. if err.Error() == utils.ErrNoRow() {
  643. br.Msg = "指标不存在"
  644. return
  645. }
  646. br.Msg = "查询计算指标失败"
  647. br.ErrMsg = "查询计算指标失败,Err:" + err.Error()
  648. }
  649. // 遍历指标列表,把计算指标id整理成数组
  650. if len(calculateEdb) > 0 {
  651. for _, calculateEdbInfo := range calculateEdb {
  652. calculateEdbIdList = append(calculateEdbIdList, calculateEdbInfo.EdbInfoId)
  653. }
  654. }
  655. switch req.Source {
  656. case utils.DATA_SOURCE_MYSTEEL_CHEMICAL: // 钢联化工
  657. err = data_manage.ModifyMysteelChemicalUpdateStatusByEdbInfoIds(edbIdList, isStop, edbCodeList, calculateEdbIdList)
  658. case utils.DATA_SOURCE_WIND: // wind
  659. err = data_manage.WindEdbInfoUpdateStatusByEdbInfoId(edbIdList, isStop, calculateEdbIdList)
  660. default:
  661. err = data_manage.EdbInfoUpdateStatusByEdbInfoId(edbIdList, isStop)
  662. return
  663. }
  664. if err != nil {
  665. br.Msg = `保存失败`
  666. br.ErrMsg = "保存失败,Err:" + err.Error()
  667. return
  668. }
  669. br.Ret = 200
  670. br.Success = true
  671. br.Msg = "保存成功"
  672. }
  673. // GetEdbRefreshEdbConfig
  674. // @Title 获取单个指标的刷新配置列表接口
  675. // @Description 获取单个指标的刷新配置列表接口
  676. // @Param Source query int true "来源:1:同花顺,2:wind,3:彭博"
  677. // @Param SubSource query int true "来源:0:经济数据库,1:日期序列"
  678. // @Param EdbInfoId query int false "指标id"
  679. // @Success 200 {object} data_manage.RefreshBaseEdbInfoResp
  680. // @router /edb_info/refresh/edb_config [get]
  681. func (c *EdbInfoController) GetEdbRefreshEdbConfig() {
  682. br := new(models.BaseResponse).Init()
  683. defer func() {
  684. c.Data["json"] = br
  685. c.ServeJSON()
  686. }()
  687. source, _ := c.GetInt("Source")
  688. subSource, _ := c.GetInt("SubSource")
  689. edbInfoId, _ := c.GetInt("EdbInfoId")
  690. if source <= 0 {
  691. br.Msg = "来源不能为空"
  692. br.IsSendEmail = false
  693. return
  694. }
  695. if edbInfoId <= 0 {
  696. br.Msg = "指标不能为空"
  697. br.IsSendEmail = false
  698. return
  699. }
  700. // 获取指标的刷新配置列表
  701. list, err := edb_refresh.GetEdbRefreshConfigListBySourceAndeEdbInfoId(source, subSource, edbInfoId)
  702. if err != nil {
  703. br.Msg = "获取失败"
  704. br.ErrMsg = err.Error()
  705. return
  706. }
  707. if len(list) > 0 {
  708. br.Ret = 200
  709. br.Success = true
  710. br.Msg = "获取成功"
  711. br.Data = list
  712. return
  713. }
  714. // 如果没有找到该指标的配置,那么就查询默认配置
  715. var frequency string
  716. // 根据类型查找指标的频度信息
  717. switch source {
  718. case utils.DATA_SOURCE_MYSTEEL_CHEMICAL: // 钢联
  719. item, err := data_manage.GetBaseFromMysteelChemicalIndexByIndexId(edbInfoId)
  720. if err != nil {
  721. br.Msg = "获取指标信息失败"
  722. br.ErrMsg = err.Error()
  723. return
  724. }
  725. frequency = item.Frequency
  726. case utils.DATA_SOURCE_YS: // 有色
  727. item, err := data_manage.GetSmmIndexById(edbInfoId)
  728. if err != nil {
  729. br.Msg = "获取指标信息失败"
  730. br.ErrMsg = err.Error()
  731. return
  732. }
  733. frequency = item.Frequency
  734. default:
  735. item, err := data_manage.GetEdbInfoById(edbInfoId)
  736. if err != nil {
  737. br.Msg = "获取指标信息失败"
  738. br.ErrMsg = err.Error()
  739. return
  740. }
  741. frequency = item.Frequency
  742. }
  743. if frequency == `` {
  744. br.Msg = "获取的指标频度信息异常"
  745. br.IsSendEmail = false
  746. return
  747. }
  748. tmpList, err := edb_refresh.GetListBySourceAndFrequency(source, subSource, frequency)
  749. if err != nil {
  750. br.Msg = "获取失败"
  751. br.ErrMsg = err.Error()
  752. return
  753. }
  754. list = make([]*edb_refresh.EdbRefreshConfigItem, 0)
  755. for _, v := range tmpList {
  756. list = append(list, &edb_refresh.EdbRefreshConfigItem{
  757. RefreshFrequency: v.RefreshFrequency,
  758. RefreshFrequencyDay: v.RefreshFrequencyDay,
  759. RefreshTime: v.RefreshTime,
  760. RefreshAllData: v.RefreshAllData,
  761. RefreshDataNum: v.RefreshDataNum,
  762. })
  763. }
  764. br.Ret = 200
  765. br.Success = true
  766. br.Msg = "获取成功"
  767. br.Data = list
  768. }