edb_info_refresh.go 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878
  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. if len(edbIdList) <= 0 {
  460. br.Msg = "指标不能为空"
  461. br.IsSendEmail = false
  462. return
  463. }
  464. //查询计算指标信息
  465. calculateEdbIdList := make([]int, 0)
  466. if isStop == 1 {
  467. fromEdbIdList := make([]int, 0)
  468. edbList, e := data_manage.GetEdbInfoByIdList(edbIdList)
  469. if e != nil && e.Error() != utils.ErrNoRow() {
  470. br.Msg = "获取失败"
  471. br.ErrMsg = "获取数据失败,Err:" + e.Error()
  472. return
  473. }
  474. for _, v := range edbList {
  475. if v.EdbInfoType == 0 {
  476. fromEdbIdList = append(fromEdbIdList, v.EdbInfoId)
  477. }
  478. }
  479. hasFind := make(map[int]struct{})
  480. calculateEdbIdList, err = data.GetCalculateEdbByFromEdbInfo(fromEdbIdList, calculateEdbIdList, hasFind)
  481. if err != nil {
  482. br.Msg = "查询计算指标信息失败"
  483. br.ErrMsg = "查询计算指标信息失败,Err:" + err.Error()
  484. return
  485. }
  486. }
  487. switch req.Source {
  488. case utils.DATA_SOURCE_MYSTEEL_CHEMICAL: // 钢联
  489. err = data_manage.ModifyMysteelChemicalUpdateStatus(edbIdList, edbCodeList, isStop)
  490. case utils.DATA_SOURCE_YS: // 有色
  491. err = data_manage.ModifySmmUpdateStatus(edbIdList, edbCodeList, isStop)
  492. default:
  493. err = data_manage.ModifyEdbInfoUpdateStatus(edbIdList, isStop, calculateEdbIdList)
  494. }
  495. if err != nil {
  496. br.Msg = `保存失败`
  497. br.ErrMsg = "保存失败,Err:" + err.Error()
  498. return
  499. }
  500. br.Ret = 200
  501. br.Success = true
  502. br.Msg = "保存成功"
  503. }
  504. // SaveEdbRefreshStatusSingle
  505. // @Title 设置单个指标刷新状态接口
  506. // @Description 设置单个指标刷新状态接口
  507. // @Param request body data_manage.SaveEdbRefreshStatusReq true "type json string"
  508. // @Success 200 {object} data_manage.RefreshBaseEdbInfoResp
  509. // @router /edb_info/single_refresh/status/save [post]
  510. func (c *EdbInfoController) SaveEdbRefreshStatusSingle() {
  511. br := new(models.BaseResponse).Init()
  512. defer func() {
  513. c.Data["json"] = br
  514. c.ServeJSON()
  515. }()
  516. var req request.SaveEdbRefreshStatusSingleReq
  517. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  518. if err != nil {
  519. br.Msg = "参数解析异常!"
  520. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  521. return
  522. }
  523. if req.EdbInfoId <= 0 {
  524. br.Msg = "请选择指标"
  525. br.IsSendEmail = false
  526. return
  527. }
  528. // 查询指标
  529. edbInfo, err := data_manage.GetEdbInfoById(req.EdbInfoId)
  530. if err != nil {
  531. if err.Error() == utils.ErrNoRow() {
  532. br.Msg = "指标不存在"
  533. return
  534. }
  535. br.Msg = "查询指标失败"
  536. br.ErrMsg = "查询指标失败,Err:" + err.Error()
  537. return
  538. }
  539. // 查询指标的指标代码
  540. calculateEdbIdList := make([]int, 0)
  541. isStop := 0
  542. if req.ModifyStatus == `暂停` {
  543. isStop = 1
  544. }
  545. if isStop == 1 && edbInfo.EdbInfoType == 0 { //基础指标, 只有在停用的情况下才需要查询计算指标
  546. hasFind := make(map[int]struct{})
  547. calculateEdbIdList, err = data.GetCalculateEdbByFromEdbInfo([]int{edbInfo.EdbInfoId}, calculateEdbIdList, hasFind)
  548. if err != nil {
  549. br.Msg = "查询计算指标信息失败"
  550. br.ErrMsg = "查询计算指标信息失败,Err:" + err.Error()
  551. return
  552. }
  553. }
  554. switch edbInfo.Source {
  555. case utils.DATA_SOURCE_MYSTEEL_CHEMICAL: // 钢联
  556. err = data_manage.ModifyMysteelChemicalUpdateStatusByEdbInfoId(edbInfo.EdbInfoId, isStop, edbInfo.EdbCode, calculateEdbIdList)
  557. default: // wind
  558. err = data_manage.EdbInfoUpdateStatusByEdbInfoId([]int{edbInfo.EdbInfoId}, isStop, calculateEdbIdList)
  559. }
  560. if err != nil {
  561. br.Msg = `保存失败`
  562. br.ErrMsg = "保存失败,Err:" + err.Error()
  563. return
  564. }
  565. br.Ret = 200
  566. br.Success = true
  567. br.Msg = "保存成功"
  568. }
  569. // SaveRelationEdbRefreshStatus
  570. // @Title 批量设置被引用的指标刷新状态接口
  571. // @Description 批量设置被引用的指标刷新状态接口
  572. // @Param request body data_manage.SaveEdbRefreshStatusReq true "type json string"
  573. // @Success 200 {object} data_manage.RefreshBaseEdbInfoResp
  574. // @router /edb_info/relation/refresh/save [post]
  575. func (c *EdbInfoController) SaveRelationEdbRefreshStatus() {
  576. br := new(models.BaseResponse).Init()
  577. defer func() {
  578. c.Data["json"] = br
  579. c.ServeJSON()
  580. }()
  581. var req request.SaveRelationEdbRefreshStatusReq
  582. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  583. if err != nil {
  584. br.Msg = "参数解析异常!"
  585. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  586. return
  587. }
  588. if req.Source <= 0 {
  589. br.Msg = "来源不能为空"
  590. br.IsSendEmail = false
  591. return
  592. }
  593. edbType := 1 //基础指标
  594. switch req.Source {
  595. case utils.DATA_SOURCE_MYSTEEL_CHEMICAL, utils.DATA_SOURCE_WIND: // wind
  596. case -1:
  597. req.Source = 0
  598. edbType = 2
  599. default:
  600. br.Msg = "暂不支持设置其他来源的指标"
  601. return
  602. }
  603. // todo 批量设置刷新状态修改
  604. edbIdList := make([]int, 0)
  605. edbCodeList := make([]string, 0)
  606. // 指标id列表
  607. if req.IsSelectAll {
  608. // 如果是列表全选
  609. _, edbList, err := data.GetEdbRelationList(req.Source, edbType, req.ClassifyId, req.SysUserId, req.Frequency, req.Keyword, req.Status, 0, 100000, "", "")
  610. if err != nil && err.Error() != utils.ErrNoRow() {
  611. br.Msg = "获取失败"
  612. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  613. return
  614. }
  615. // 不配置的指标id
  616. notIdMap := make(map[int]int, 0)
  617. for _, v := range req.EdbSelectIdList {
  618. notIdMap[v] = v
  619. }
  620. for _, v := range edbList {
  621. _, ok := notIdMap[v.EdbInfoId]
  622. // 在不配置的指标id列表内的话,那就过滤
  623. if ok {
  624. continue
  625. }
  626. // 加入到待配置的指标列表id
  627. edbIdList = append(edbIdList, v.EdbInfoId)
  628. }
  629. } else {
  630. edbIdList = req.EdbSelectIdList
  631. }
  632. if len(edbIdList) <= 0 {
  633. br.Msg = "指标不能为空"
  634. br.IsSendEmail = false
  635. return
  636. }
  637. //查询指标信息
  638. edbList, e := data_manage.GetEdbInfoByIdList(edbIdList)
  639. if e != nil && e.Error() != utils.ErrNoRow() {
  640. br.Msg = "获取失败"
  641. br.ErrMsg = "获取数据失败,Err:" + e.Error()
  642. return
  643. }
  644. fromEdbIdList := make([]int, 0)
  645. for _, v := range edbList {
  646. if req.Source == utils.DATA_SOURCE_MYSTEEL_CHEMICAL {
  647. edbCodeList = append(edbCodeList, v.EdbCode)
  648. }
  649. if v.EdbInfoType == 0 {
  650. fromEdbIdList = append(fromEdbIdList, v.EdbInfoId)
  651. }
  652. }
  653. isStop := 0
  654. if req.ModifyStatus == `暂停` {
  655. isStop = 1
  656. }
  657. // 查询计算指标ID
  658. // 查询相关的计算指标
  659. calculateEdbIdList := make([]int, 0)
  660. if isStop == 1 {
  661. hasFind := make(map[int]struct{})
  662. calculateEdbIdList, err = data.GetCalculateEdbByFromEdbInfo(fromEdbIdList, calculateEdbIdList, hasFind)
  663. if err != nil {
  664. br.Msg = "查询计算指标信息失败"
  665. br.ErrMsg = "查询计算指标信息失败,Err:" + err.Error()
  666. return
  667. }
  668. }
  669. switch req.Source {
  670. case utils.DATA_SOURCE_MYSTEEL_CHEMICAL: // 钢联化工
  671. err = data_manage.ModifyMysteelChemicalUpdateStatusByEdbInfoIds(edbIdList, isStop, edbCodeList, calculateEdbIdList)
  672. default:
  673. err = data_manage.EdbInfoUpdateStatusByEdbInfoId(edbIdList, isStop, calculateEdbIdList)
  674. }
  675. if err != nil {
  676. br.Msg = `保存失败`
  677. br.ErrMsg = "保存失败,Err:" + err.Error()
  678. return
  679. }
  680. br.Ret = 200
  681. br.Success = true
  682. br.Msg = "保存成功"
  683. }
  684. // GetEdbRefreshEdbConfig
  685. // @Title 获取单个指标的刷新配置列表接口
  686. // @Description 获取单个指标的刷新配置列表接口
  687. // @Param Source query int true "来源:1:同花顺,2:wind,3:彭博"
  688. // @Param SubSource query int true "来源:0:经济数据库,1:日期序列"
  689. // @Param EdbInfoId query int false "指标id"
  690. // @Success 200 {object} data_manage.RefreshBaseEdbInfoResp
  691. // @router /edb_info/refresh/edb_config [get]
  692. func (c *EdbInfoController) GetEdbRefreshEdbConfig() {
  693. br := new(models.BaseResponse).Init()
  694. defer func() {
  695. c.Data["json"] = br
  696. c.ServeJSON()
  697. }()
  698. source, _ := c.GetInt("Source")
  699. subSource, _ := c.GetInt("SubSource")
  700. edbInfoId, _ := c.GetInt("EdbInfoId")
  701. if source <= 0 {
  702. br.Msg = "来源不能为空"
  703. br.IsSendEmail = false
  704. return
  705. }
  706. if edbInfoId <= 0 {
  707. br.Msg = "指标不能为空"
  708. br.IsSendEmail = false
  709. return
  710. }
  711. // 获取指标的刷新配置列表
  712. list, err := edb_refresh.GetEdbRefreshConfigListBySourceAndeEdbInfoId(source, subSource, edbInfoId)
  713. if err != nil {
  714. br.Msg = "获取失败"
  715. br.ErrMsg = err.Error()
  716. return
  717. }
  718. if len(list) > 0 {
  719. br.Ret = 200
  720. br.Success = true
  721. br.Msg = "获取成功"
  722. br.Data = list
  723. return
  724. }
  725. // 如果没有找到该指标的配置,那么就查询默认配置
  726. var frequency string
  727. // 根据类型查找指标的频度信息
  728. switch source {
  729. case utils.DATA_SOURCE_MYSTEEL_CHEMICAL: // 钢联
  730. item, err := data_manage.GetBaseFromMysteelChemicalIndexByIndexId(edbInfoId)
  731. if err != nil {
  732. br.Msg = "获取指标信息失败"
  733. br.ErrMsg = err.Error()
  734. return
  735. }
  736. frequency = item.Frequency
  737. case utils.DATA_SOURCE_YS: // 有色
  738. item, err := data_manage.GetSmmIndexById(edbInfoId)
  739. if err != nil {
  740. br.Msg = "获取指标信息失败"
  741. br.ErrMsg = err.Error()
  742. return
  743. }
  744. frequency = item.Frequency
  745. default:
  746. item, err := data_manage.GetEdbInfoById(edbInfoId)
  747. if err != nil {
  748. br.Msg = "获取指标信息失败"
  749. br.ErrMsg = err.Error()
  750. return
  751. }
  752. frequency = item.Frequency
  753. }
  754. if frequency == `` {
  755. br.Msg = "获取的指标频度信息异常"
  756. br.IsSendEmail = false
  757. return
  758. }
  759. tmpList, err := edb_refresh.GetListBySourceAndFrequency(source, subSource, frequency)
  760. if err != nil {
  761. br.Msg = "获取失败"
  762. br.ErrMsg = err.Error()
  763. return
  764. }
  765. list = make([]*edb_refresh.EdbRefreshConfigItem, 0)
  766. for _, v := range tmpList {
  767. list = append(list, &edb_refresh.EdbRefreshConfigItem{
  768. RefreshFrequency: v.RefreshFrequency,
  769. RefreshFrequencyDay: v.RefreshFrequencyDay,
  770. RefreshTime: v.RefreshTime,
  771. RefreshAllData: v.RefreshAllData,
  772. RefreshDataNum: v.RefreshDataNum,
  773. })
  774. }
  775. br.Ret = 200
  776. br.Success = true
  777. br.Msg = "获取成功"
  778. br.Data = list
  779. }