edb_info_refresh.go 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915
  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. // 如果是钢联化工,那么需要过滤供应商暂停的指标
  645. if req.Source == utils.DATA_SOURCE_MYSTEEL_CHEMICAL {
  646. // 获取未被供应商暂停的指标
  647. tmpEdbCodeList := make([]string, 0)
  648. for _, v := range edbList {
  649. tmpEdbCodeList = append(tmpEdbCodeList, v.EdbCode)
  650. }
  651. notIsSupplierStopIndexList, e := data_manage.GetNotIsSupplierStopIndexByCodeList(tmpEdbCodeList, 0)
  652. if e != nil {
  653. br.Msg = "获取失败"
  654. br.ErrMsg = "获取数据失败,Err:" + e.Error()
  655. return
  656. }
  657. // 未被供应商暂停的指标编码
  658. notIsSupplierStopIndexCodeList := make([]string, 0)
  659. for _, v := range notIsSupplierStopIndexList {
  660. notIsSupplierStopIndexCodeList = append(notIsSupplierStopIndexCodeList, v.IndexCode)
  661. }
  662. //查询未被供应商暂停的指标信息
  663. edbList, err = data_manage.GetEdbInfoByEdbCodeList(utils.DATA_SOURCE_MYSTEEL_CHEMICAL, notIsSupplierStopIndexCodeList)
  664. if err != nil {
  665. br.Msg = "获取失败"
  666. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  667. return
  668. }
  669. if len(edbList) <= 0 {
  670. br.Ret = 200
  671. br.Success = true
  672. br.Msg = "保存成功"
  673. return
  674. }
  675. }
  676. fromEdbIdList := make([]int, 0)
  677. for _, v := range edbList {
  678. if req.Source == utils.DATA_SOURCE_MYSTEEL_CHEMICAL {
  679. edbCodeList = append(edbCodeList, v.EdbCode)
  680. }
  681. if v.EdbInfoType == 0 {
  682. fromEdbIdList = append(fromEdbIdList, v.EdbInfoId)
  683. }
  684. }
  685. isStop := 0
  686. if req.ModifyStatus == `暂停` {
  687. isStop = 1
  688. }
  689. // 查询计算指标ID
  690. // 查询相关的计算指标
  691. calculateEdbIdList := make([]int, 0)
  692. if isStop == 1 {
  693. hasFind := make(map[int]struct{})
  694. calculateEdbIdList, err = data.GetCalculateEdbByFromEdbInfo(fromEdbIdList, calculateEdbIdList, hasFind)
  695. if err != nil {
  696. br.Msg = "查询计算指标信息失败"
  697. br.ErrMsg = "查询计算指标信息失败,Err:" + err.Error()
  698. return
  699. }
  700. }
  701. switch req.Source {
  702. case utils.DATA_SOURCE_MYSTEEL_CHEMICAL: // 钢联化工
  703. err = data_manage.ModifyMysteelChemicalUpdateStatusByEdbInfoIds(edbIdList, isStop, edbCodeList, calculateEdbIdList)
  704. default:
  705. err = data_manage.EdbInfoUpdateStatusByEdbInfoId(edbIdList, isStop, calculateEdbIdList)
  706. }
  707. if err != nil {
  708. br.Msg = `保存失败`
  709. br.ErrMsg = "保存失败,Err:" + err.Error()
  710. return
  711. }
  712. br.Ret = 200
  713. br.Success = true
  714. br.Msg = "保存成功"
  715. }
  716. // GetEdbRefreshEdbConfig
  717. // @Title 获取单个指标的刷新配置列表接口
  718. // @Description 获取单个指标的刷新配置列表接口
  719. // @Param Source query int true "来源:1:同花顺,2:wind,3:彭博"
  720. // @Param SubSource query int true "来源:0:经济数据库,1:日期序列"
  721. // @Param EdbInfoId query int false "指标id"
  722. // @Success 200 {object} data_manage.RefreshBaseEdbInfoResp
  723. // @router /edb_info/refresh/edb_config [get]
  724. func (c *EdbInfoController) GetEdbRefreshEdbConfig() {
  725. br := new(models.BaseResponse).Init()
  726. defer func() {
  727. c.Data["json"] = br
  728. c.ServeJSON()
  729. }()
  730. source, _ := c.GetInt("Source")
  731. subSource, _ := c.GetInt("SubSource")
  732. edbInfoId, _ := c.GetInt("EdbInfoId")
  733. if source <= 0 {
  734. br.Msg = "来源不能为空"
  735. br.IsSendEmail = false
  736. return
  737. }
  738. if edbInfoId <= 0 {
  739. br.Msg = "指标不能为空"
  740. br.IsSendEmail = false
  741. return
  742. }
  743. // 获取指标的刷新配置列表
  744. list, err := edb_refresh.GetEdbRefreshConfigListBySourceAndeEdbInfoId(source, subSource, edbInfoId)
  745. if err != nil {
  746. br.Msg = "获取失败"
  747. br.ErrMsg = err.Error()
  748. return
  749. }
  750. if len(list) > 0 {
  751. br.Ret = 200
  752. br.Success = true
  753. br.Msg = "获取成功"
  754. br.Data = list
  755. return
  756. }
  757. // 如果没有找到该指标的配置,那么就查询默认配置
  758. var frequency string
  759. // 根据类型查找指标的频度信息
  760. switch source {
  761. case utils.DATA_SOURCE_MYSTEEL_CHEMICAL: // 钢联
  762. item, err := data_manage.GetBaseFromMysteelChemicalIndexByIndexId(edbInfoId)
  763. if err != nil {
  764. br.Msg = "获取指标信息失败"
  765. br.ErrMsg = err.Error()
  766. return
  767. }
  768. frequency = item.Frequency
  769. case utils.DATA_SOURCE_YS: // 有色
  770. item, err := data_manage.GetSmmIndexById(edbInfoId)
  771. if err != nil {
  772. br.Msg = "获取指标信息失败"
  773. br.ErrMsg = err.Error()
  774. return
  775. }
  776. frequency = item.Frequency
  777. default:
  778. item, err := data_manage.GetEdbInfoById(edbInfoId)
  779. if err != nil {
  780. br.Msg = "获取指标信息失败"
  781. br.ErrMsg = err.Error()
  782. return
  783. }
  784. frequency = item.Frequency
  785. }
  786. if frequency == `` {
  787. br.Msg = "获取的指标频度信息异常"
  788. br.IsSendEmail = false
  789. return
  790. }
  791. tmpList, err := edb_refresh.GetListBySourceAndFrequency(source, subSource, frequency)
  792. if err != nil {
  793. br.Msg = "获取失败"
  794. br.ErrMsg = err.Error()
  795. return
  796. }
  797. list = make([]*edb_refresh.EdbRefreshConfigItem, 0)
  798. for _, v := range tmpList {
  799. list = append(list, &edb_refresh.EdbRefreshConfigItem{
  800. RefreshFrequency: v.RefreshFrequency,
  801. RefreshFrequencyDay: v.RefreshFrequencyDay,
  802. RefreshTime: v.RefreshTime,
  803. RefreshAllData: v.RefreshAllData,
  804. RefreshDataNum: v.RefreshDataNum,
  805. })
  806. }
  807. br.Ret = 200
  808. br.Success = true
  809. br.Msg = "获取成功"
  810. br.Data = list
  811. }