edb_info_refresh.go 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924
  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. if br.ErrMsg == "" {
  239. br.IsSendEmail = false
  240. }
  241. c.Data["json"] = br
  242. c.ServeJSON()
  243. }()
  244. sysUser := c.SysUser
  245. if sysUser == nil {
  246. br.Msg = "请登录"
  247. br.ErrMsg = "请登录,SysUser Is Empty"
  248. br.Ret = 408
  249. return
  250. }
  251. source, _ := c.GetInt("Source")
  252. subSource, _ := c.GetInt("SubSource")
  253. classifyId := c.GetString("ClassifyId")
  254. terminalCode := c.GetString("TerminalCode")
  255. sysUserId := c.GetString("SysUserId")
  256. frequency := c.GetString("Frequency")
  257. keyword := c.GetString("Keyword")
  258. status := c.GetString("Status")
  259. sortParam := c.GetString("SortParam")
  260. sortType := c.GetString("SortType")
  261. switch sortParam {
  262. case "end_date":
  263. default:
  264. sortParam = " end_date "
  265. }
  266. switch sortType {
  267. case "desc", "asc":
  268. default:
  269. sortType = "desc"
  270. }
  271. pageSize, _ := c.GetInt("PageSize")
  272. currentIndex, _ := c.GetInt("CurrentIndex")
  273. var startSize int
  274. if pageSize <= 0 {
  275. pageSize = utils.PageSize20
  276. }
  277. if currentIndex <= 0 {
  278. currentIndex = 1
  279. }
  280. startSize = utils.StartIndex(currentIndex, pageSize)
  281. total, list, err := data.GetList(source, subSource, classifyId, terminalCode, sysUserId, frequency, keyword, status, startSize, pageSize, sortParam, sortType)
  282. if err != nil && err.Error() != utils.ErrNoRow() {
  283. br.Msg = "获取失败"
  284. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  285. return
  286. }
  287. page := paging.GetPaging(currentIndex, pageSize, total)
  288. resp := data_manage.RefreshBaseEdbInfoResp{
  289. Paging: page,
  290. List: list,
  291. }
  292. // 刷新时间格式化
  293. list, err, errMsg, isSendEmail := data.HandleRefreshTime(source, subSource, list)
  294. if err != nil {
  295. br.Msg = errMsg
  296. br.ErrMsg = "保存失败,Err:" + err.Error()
  297. br.IsSendEmail = isSendEmail
  298. return
  299. }
  300. br.Ret = 200
  301. br.Success = true
  302. br.Msg = "获取成功"
  303. br.Data = resp
  304. }
  305. // GetEdbRefreshDefaultConfig
  306. // @Title 获取待配置的指标列表接口
  307. // @Description 获取待配置的指标列表接口
  308. // @Param Source query int true "来源:1:同花顺,2:wind,3:彭博"
  309. // @Param SubSource query int true "来源:0:经济数据库,1:日期序列"
  310. // @Param Frequency query string false "频度"
  311. // @Success 200 {object} data_manage.RefreshBaseEdbInfoResp
  312. // @router /edb_info/refresh/default_config [get]
  313. func (c *EdbInfoController) GetEdbRefreshDefaultConfig() {
  314. br := new(models.BaseResponse).Init()
  315. defer func() {
  316. c.Data["json"] = br
  317. c.ServeJSON()
  318. }()
  319. source, _ := c.GetInt("Source")
  320. subSource, _ := c.GetInt("SubSource")
  321. frequency := c.GetString("Frequency")
  322. if source <= 0 {
  323. br.Msg = "来源不能为空"
  324. br.IsSendEmail = false
  325. return
  326. }
  327. // 非有色的来源,频度不能为空
  328. if source != utils.DATA_SOURCE_YS && frequency == `` {
  329. br.Msg = "频度不能为空"
  330. br.IsSendEmail = false
  331. return
  332. }
  333. list, err := edb_refresh.GetListBySourceAndFrequency(source, subSource, frequency)
  334. if err != nil {
  335. br.Msg = "获取失败"
  336. br.ErrMsg = err.Error()
  337. return
  338. }
  339. br.Ret = 200
  340. br.Success = true
  341. br.Msg = "获取成功"
  342. br.Data = list
  343. }
  344. // SaveEdbRefreshDefaultConfig
  345. // @Title 设置默认的指标刷新配置接口
  346. // @Description 设置默认的指标刷新配置接口
  347. // @Param request body data_manage.SaveEdbRefreshDefaultConfigReq true "type json string"
  348. // @Success Ret=200 保存成功
  349. // @router /edb_info/refresh/default_config/save [post]
  350. func (c *EdbInfoController) SaveEdbRefreshDefaultConfig() {
  351. br := new(models.BaseResponse).Init()
  352. defer func() {
  353. c.Data["json"] = br
  354. c.ServeJSON()
  355. }()
  356. var req request.SaveEdbRefreshDefaultConfigReq
  357. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  358. if err != nil {
  359. br.Msg = "参数解析异常!"
  360. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  361. return
  362. }
  363. // 保存
  364. err, errMsg, isSendEmail := data.SaveEdbRefreshDefaultConfig(req.Source, req.SubSource, req.Frequency, req.List)
  365. if err != nil {
  366. br.Msg = errMsg
  367. br.ErrMsg = "保存失败,Err:" + err.Error()
  368. br.IsSendEmail = isSendEmail
  369. return
  370. }
  371. br.Ret = 200
  372. br.Success = true
  373. br.Msg = "保存成功"
  374. }
  375. // SaveEdbRefreshConfig
  376. // @Title 设置指标刷新配置接口
  377. // @Description 设置指标刷新配置接口
  378. // @Param request body data_manage.SaveEdbRefreshConfigReq true "type json string"
  379. // @Success 200 {object} data_manage.RefreshBaseEdbInfoResp
  380. // @router /edb_info/refresh/config/save [post]
  381. func (c *EdbInfoController) SaveEdbRefreshConfig() {
  382. br := new(models.BaseResponse).Init()
  383. defer func() {
  384. c.Data["json"] = br
  385. c.ServeJSON()
  386. }()
  387. var req request.SaveEdbRefreshConfigReq
  388. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  389. if err != nil {
  390. br.Msg = "参数解析异常!"
  391. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  392. return
  393. }
  394. // 保存
  395. 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)
  396. if err != nil {
  397. br.Msg = errMsg
  398. br.ErrMsg = "保存失败,Err:" + err.Error()
  399. br.IsSendEmail = isSendEmail
  400. return
  401. }
  402. br.Ret = 200
  403. br.Success = true
  404. br.Msg = "保存成功"
  405. }
  406. // SaveEdbRefreshStatus
  407. // @Title 设置指标刷新状态接口
  408. // @Description 设置指标刷新状态接口
  409. // @Param request body data_manage.SaveEdbRefreshStatusReq true "type json string"
  410. // @Success 200 {object} data_manage.RefreshBaseEdbInfoResp
  411. // @router /edb_info/refresh/status/save [post]
  412. func (c *EdbInfoController) SaveEdbRefreshStatus() {
  413. br := new(models.BaseResponse).Init()
  414. defer func() {
  415. c.Data["json"] = br
  416. c.ServeJSON()
  417. }()
  418. var req request.SaveEdbRefreshStatusReq
  419. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  420. if err != nil {
  421. br.Msg = "参数解析异常!"
  422. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  423. return
  424. }
  425. if req.Source <= 0 {
  426. br.Msg = "来源不能为空"
  427. br.IsSendEmail = false
  428. return
  429. }
  430. // todo 批量设置刷新状态修改
  431. edbIdList := make([]int, 0)
  432. edbCodeList := make([]string, 0)
  433. // 指标id列表
  434. if req.IsSelectAll {
  435. // 如果是列表全选
  436. _, edbList, err := data.GetList(req.Source, req.SubSource, req.ClassifyId, req.TerminalCode, req.SysUserId, req.Frequency, req.Keyword, req.Status, 0, 100000, "", "")
  437. if err != nil && err.Error() != utils.ErrNoRow() {
  438. br.Msg = "获取失败"
  439. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  440. return
  441. }
  442. // 不配置的指标id
  443. notIdMap := make(map[int]int, 0)
  444. for _, v := range req.EdbSelectIdList {
  445. notIdMap[v] = v
  446. }
  447. for _, v := range edbList {
  448. _, ok := notIdMap[v.EdbInfoId]
  449. // 在不配置的指标id列表内的话,那就过滤
  450. if ok {
  451. continue
  452. }
  453. // 加入到待配置的指标列表id
  454. edbIdList = append(edbIdList, v.EdbInfoId)
  455. edbCodeList = append(edbCodeList, v.IndexCode)
  456. }
  457. } else {
  458. edbIdList = req.EdbSelectIdList
  459. }
  460. if len(edbIdList) <= 0 {
  461. br.Msg = "指标不能为空"
  462. br.IsSendEmail = false
  463. return
  464. }
  465. isStop := 0
  466. if req.ModifyStatus == `暂停` {
  467. isStop = 1
  468. }
  469. if len(edbIdList) <= 0 {
  470. br.Msg = "指标不能为空"
  471. br.IsSendEmail = false
  472. return
  473. }
  474. //查询计算指标信息
  475. calculateEdbIdList := make([]int, 0)
  476. if isStop == 1 {
  477. fromEdbIdList := make([]int, 0)
  478. edbList, e := data_manage.GetEdbInfoByIdList(edbIdList)
  479. if e != nil && e.Error() != utils.ErrNoRow() {
  480. br.Msg = "获取失败"
  481. br.ErrMsg = "获取数据失败,Err:" + e.Error()
  482. return
  483. }
  484. for _, v := range edbList {
  485. if v.EdbInfoType == 0 {
  486. fromEdbIdList = append(fromEdbIdList, v.EdbInfoId)
  487. }
  488. }
  489. hasFind := make(map[int]struct{})
  490. calculateEdbIdList, err = data.GetCalculateEdbByFromEdbInfo(fromEdbIdList, calculateEdbIdList, hasFind)
  491. if err != nil {
  492. br.Msg = "查询计算指标信息失败"
  493. br.ErrMsg = "查询计算指标信息失败,Err:" + err.Error()
  494. return
  495. }
  496. }
  497. switch req.Source {
  498. case utils.DATA_SOURCE_MYSTEEL_CHEMICAL: // 钢联
  499. err = data_manage.ModifyMysteelChemicalUpdateStatus(edbIdList, edbCodeList, isStop)
  500. case utils.DATA_SOURCE_YS: // 有色
  501. err = data_manage.ModifySmmUpdateStatus(edbIdList, edbCodeList, isStop)
  502. default:
  503. err = data_manage.ModifyEdbInfoUpdateStatus(edbIdList, isStop, calculateEdbIdList)
  504. }
  505. if err != nil {
  506. br.Msg = `保存失败`
  507. br.ErrMsg = "保存失败,Err:" + err.Error()
  508. return
  509. }
  510. br.Ret = 200
  511. br.Success = true
  512. br.Msg = "保存成功"
  513. }
  514. // SaveEdbRefreshStatusSingle
  515. // @Title 设置单个指标刷新状态接口
  516. // @Description 设置单个指标刷新状态接口
  517. // @Param request body data_manage.SaveEdbRefreshStatusReq true "type json string"
  518. // @Success 200 {object} data_manage.RefreshBaseEdbInfoResp
  519. // @router /edb_info/single_refresh/status/save [post]
  520. func (c *EdbInfoController) SaveEdbRefreshStatusSingle() {
  521. br := new(models.BaseResponse).Init()
  522. defer func() {
  523. c.Data["json"] = br
  524. c.ServeJSON()
  525. }()
  526. var req request.SaveEdbRefreshStatusSingleReq
  527. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  528. if err != nil {
  529. br.Msg = "参数解析异常!"
  530. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  531. return
  532. }
  533. if req.EdbInfoId <= 0 {
  534. br.Msg = "请选择指标"
  535. br.IsSendEmail = false
  536. return
  537. }
  538. // 查询指标
  539. edbInfo, err := data_manage.GetEdbInfoById(req.EdbInfoId)
  540. if err != nil {
  541. if err.Error() == utils.ErrNoRow() {
  542. br.Msg = "指标不存在"
  543. return
  544. }
  545. br.Msg = "查询指标失败"
  546. br.ErrMsg = "查询指标失败,Err:" + err.Error()
  547. return
  548. }
  549. // 查询指标的指标代码
  550. calculateEdbIdList := make([]int, 0)
  551. isStop := 0
  552. if req.ModifyStatus == `暂停` {
  553. isStop = 1
  554. }
  555. if isStop == 1 && edbInfo.EdbInfoType == 0 { //基础指标, 只有在停用的情况下才需要查询计算指标
  556. hasFind := make(map[int]struct{})
  557. calculateEdbIdList, err = data.GetCalculateEdbByFromEdbInfo([]int{edbInfo.EdbInfoId}, calculateEdbIdList, hasFind)
  558. if err != nil {
  559. br.Msg = "查询计算指标信息失败"
  560. br.ErrMsg = "查询计算指标信息失败,Err:" + err.Error()
  561. return
  562. }
  563. }
  564. switch edbInfo.Source {
  565. case utils.DATA_SOURCE_MYSTEEL_CHEMICAL: // 钢联
  566. err = data_manage.ModifyMysteelChemicalUpdateStatusByEdbInfoId(edbInfo.EdbInfoId, isStop, edbInfo.EdbCode, calculateEdbIdList)
  567. default: // wind
  568. err = data_manage.EdbInfoUpdateStatusByEdbInfoId([]int{edbInfo.EdbInfoId}, 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. // SaveRelationEdbRefreshStatus
  580. // @Title 批量设置被引用的指标刷新状态接口
  581. // @Description 批量设置被引用的指标刷新状态接口
  582. // @Param request body data_manage.SaveEdbRefreshStatusReq true "type json string"
  583. // @Success 200 {object} data_manage.RefreshBaseEdbInfoResp
  584. // @router /edb_info/relation/refresh/save [post]
  585. func (c *EdbInfoController) SaveRelationEdbRefreshStatus() {
  586. br := new(models.BaseResponse).Init()
  587. defer func() {
  588. c.Data["json"] = br
  589. c.ServeJSON()
  590. }()
  591. var req request.SaveRelationEdbRefreshStatusReq
  592. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  593. if err != nil {
  594. br.Msg = "参数解析异常!"
  595. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  596. return
  597. }
  598. if req.Source <= 0 {
  599. br.Msg = "来源不能为空"
  600. br.IsSendEmail = false
  601. return
  602. }
  603. edbType := 1 //基础指标
  604. switch req.Source {
  605. case utils.DATA_SOURCE_MYSTEEL_CHEMICAL, utils.DATA_SOURCE_WIND: // wind
  606. case -1:
  607. req.Source = 0
  608. edbType = 2
  609. default:
  610. br.Msg = "暂不支持设置其他来源的指标"
  611. return
  612. }
  613. // todo 批量设置刷新状态修改
  614. edbIdList := make([]int, 0)
  615. edbCodeList := make([]string, 0)
  616. // 指标id列表
  617. if req.IsSelectAll {
  618. // 如果是列表全选
  619. _, edbList, err := data.GetEdbRelationList(req.Source, edbType, req.ClassifyId, req.SysUserId, req.Frequency, req.Keyword, req.Status, 0, 100000, "", "")
  620. if err != nil && err.Error() != utils.ErrNoRow() {
  621. br.Msg = "获取失败"
  622. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  623. return
  624. }
  625. // 不配置的指标id
  626. notIdMap := make(map[int]int, 0)
  627. for _, v := range req.EdbSelectIdList {
  628. notIdMap[v] = v
  629. }
  630. for _, v := range edbList {
  631. _, ok := notIdMap[v.EdbInfoId]
  632. // 在不配置的指标id列表内的话,那就过滤
  633. if ok {
  634. continue
  635. }
  636. // 加入到待配置的指标列表id
  637. edbIdList = append(edbIdList, v.EdbInfoId)
  638. }
  639. } else {
  640. edbIdList = req.EdbSelectIdList
  641. }
  642. if len(edbIdList) <= 0 {
  643. br.Msg = "指标不能为空"
  644. br.IsSendEmail = false
  645. return
  646. }
  647. //查询指标信息
  648. edbList, e := data_manage.GetEdbInfoByIdList(edbIdList)
  649. if e != nil && e.Error() != utils.ErrNoRow() {
  650. br.Msg = "获取失败"
  651. br.ErrMsg = "获取数据失败,Err:" + e.Error()
  652. return
  653. }
  654. // 如果是钢联化工,那么需要过滤供应商暂停的指标
  655. if req.Source == utils.DATA_SOURCE_MYSTEEL_CHEMICAL {
  656. // 获取未被供应商暂停的指标
  657. tmpEdbCodeList := make([]string, 0)
  658. for _, v := range edbList {
  659. tmpEdbCodeList = append(tmpEdbCodeList, v.EdbCode)
  660. }
  661. notIsSupplierStopIndexList, e := data_manage.GetNotIsSupplierStopIndexByCodeList(tmpEdbCodeList, 0)
  662. if e != nil {
  663. br.Msg = "获取失败"
  664. br.ErrMsg = "获取数据失败,Err:" + e.Error()
  665. return
  666. }
  667. // 未被供应商暂停的指标编码
  668. notIsSupplierStopIndexCodeList := make([]string, 0)
  669. for _, v := range notIsSupplierStopIndexList {
  670. notIsSupplierStopIndexCodeList = append(notIsSupplierStopIndexCodeList, v.IndexCode)
  671. }
  672. //查询未被供应商暂停的指标信息
  673. edbList, err = data_manage.GetEdbInfoByEdbCodeList(utils.DATA_SOURCE_MYSTEEL_CHEMICAL, notIsSupplierStopIndexCodeList)
  674. if err != nil {
  675. br.Msg = "获取失败"
  676. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  677. return
  678. }
  679. if len(edbList) <= 0 {
  680. br.Ret = 200
  681. br.Success = true
  682. br.Msg = "保存成功"
  683. return
  684. }
  685. }
  686. fromEdbIdList := make([]int, 0)
  687. for _, v := range edbList {
  688. if req.Source == utils.DATA_SOURCE_MYSTEEL_CHEMICAL {
  689. edbCodeList = append(edbCodeList, v.EdbCode)
  690. }
  691. if v.EdbInfoType == 0 {
  692. fromEdbIdList = append(fromEdbIdList, v.EdbInfoId)
  693. }
  694. }
  695. isStop := 0
  696. if req.ModifyStatus == `暂停` {
  697. isStop = 1
  698. }
  699. // 查询计算指标ID
  700. // 查询相关的计算指标
  701. calculateEdbIdList := make([]int, 0)
  702. if isStop == 1 {
  703. hasFind := make(map[int]struct{})
  704. calculateEdbIdList, err = data.GetCalculateEdbByFromEdbInfo(fromEdbIdList, calculateEdbIdList, hasFind)
  705. if err != nil {
  706. br.Msg = "查询计算指标信息失败"
  707. br.ErrMsg = "查询计算指标信息失败,Err:" + err.Error()
  708. return
  709. }
  710. }
  711. switch req.Source {
  712. case utils.DATA_SOURCE_MYSTEEL_CHEMICAL: // 上海钢联
  713. err = data_manage.ModifyMysteelChemicalUpdateStatusByEdbInfoIds(edbIdList, isStop, edbCodeList, calculateEdbIdList)
  714. default:
  715. err = data_manage.EdbInfoUpdateStatusByEdbInfoId(edbIdList, isStop, calculateEdbIdList)
  716. }
  717. if err != nil {
  718. br.Msg = `保存失败`
  719. br.ErrMsg = "保存失败,Err:" + err.Error()
  720. return
  721. }
  722. br.Ret = 200
  723. br.Success = true
  724. br.Msg = "保存成功"
  725. }
  726. // GetEdbRefreshEdbConfig
  727. // @Title 获取单个指标的刷新配置列表接口
  728. // @Description 获取单个指标的刷新配置列表接口
  729. // @Param Source query int true "来源:1:同花顺,2:wind,3:彭博"
  730. // @Param SubSource query int true "来源:0:经济数据库,1:日期序列"
  731. // @Param EdbInfoId query int false "指标id"
  732. // @Success 200 {object} data_manage.RefreshBaseEdbInfoResp
  733. // @router /edb_info/refresh/edb_config [get]
  734. func (c *EdbInfoController) GetEdbRefreshEdbConfig() {
  735. br := new(models.BaseResponse).Init()
  736. defer func() {
  737. c.Data["json"] = br
  738. c.ServeJSON()
  739. }()
  740. source, _ := c.GetInt("Source")
  741. subSource, _ := c.GetInt("SubSource")
  742. edbInfoId, _ := c.GetInt("EdbInfoId")
  743. if source <= 0 {
  744. br.Msg = "来源不能为空"
  745. br.IsSendEmail = false
  746. return
  747. }
  748. if edbInfoId <= 0 {
  749. br.Msg = "指标不能为空"
  750. br.IsSendEmail = false
  751. return
  752. }
  753. // 获取指标的刷新配置列表
  754. list, err := edb_refresh.GetEdbRefreshConfigListBySourceAndeEdbInfoId(source, subSource, edbInfoId)
  755. if err != nil {
  756. br.Msg = "获取失败"
  757. br.ErrMsg = err.Error()
  758. return
  759. }
  760. if len(list) > 0 {
  761. br.Ret = 200
  762. br.Success = true
  763. br.Msg = "获取成功"
  764. br.Data = list
  765. return
  766. }
  767. // 如果没有找到该指标的配置,那么就查询默认配置
  768. var frequency string
  769. // 根据类型查找指标的频度信息
  770. switch source {
  771. case utils.DATA_SOURCE_MYSTEEL_CHEMICAL: // 钢联
  772. item, err := data_manage.GetBaseFromMysteelChemicalIndexByIndexId(edbInfoId)
  773. if err != nil {
  774. br.Msg = "获取指标信息失败"
  775. br.ErrMsg = err.Error()
  776. return
  777. }
  778. frequency = item.Frequency
  779. case utils.DATA_SOURCE_YS: // 有色
  780. item, err := data_manage.GetSmmIndexById(edbInfoId)
  781. if err != nil {
  782. br.Msg = "获取指标信息失败"
  783. br.ErrMsg = err.Error()
  784. return
  785. }
  786. frequency = item.Frequency
  787. default:
  788. item, err := data_manage.GetEdbInfoById(edbInfoId)
  789. if err != nil {
  790. br.Msg = "获取指标信息失败"
  791. br.ErrMsg = err.Error()
  792. return
  793. }
  794. frequency = item.Frequency
  795. }
  796. if frequency == `` {
  797. br.Msg = "获取的指标频度信息异常"
  798. br.IsSendEmail = false
  799. return
  800. }
  801. tmpList, err := edb_refresh.GetListBySourceAndFrequency(source, subSource, frequency)
  802. if err != nil {
  803. br.Msg = "获取失败"
  804. br.ErrMsg = err.Error()
  805. return
  806. }
  807. list = make([]*edb_refresh.EdbRefreshConfigItem, 0)
  808. for _, v := range tmpList {
  809. list = append(list, &edb_refresh.EdbRefreshConfigItem{
  810. RefreshFrequency: v.RefreshFrequency,
  811. RefreshFrequencyDay: v.RefreshFrequencyDay,
  812. RefreshTime: v.RefreshTime,
  813. RefreshAllData: v.RefreshAllData,
  814. RefreshDataNum: v.RefreshDataNum,
  815. })
  816. }
  817. br.Ret = 200
  818. br.Success = true
  819. br.Msg = "获取成功"
  820. br.Data = list
  821. }