bloomberg_data.go 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717
  1. package data_manage
  2. import (
  3. "encoding/json"
  4. "eta/eta_api/controllers"
  5. "eta/eta_api/models"
  6. "eta/eta_api/models/data_manage"
  7. "eta/eta_api/models/system"
  8. "eta/eta_api/services/data"
  9. "eta/eta_api/services/elastic"
  10. etaTrialService "eta/eta_api/services/eta_trial"
  11. "eta/eta_api/utils"
  12. "fmt"
  13. "strconv"
  14. "strings"
  15. "time"
  16. "github.com/rdlucklib/rdluck_tools/paging"
  17. )
  18. // BloombergDataController 彭博数据源
  19. type BloombergDataController struct {
  20. controllers.BaseAuthController
  21. }
  22. // List
  23. // @Title 指标列表
  24. // @Description 指标列表
  25. // @Param PageSize query int false "每页数据量"
  26. // @Param CurrentIndex query int false "页码"
  27. // @Param Frequency query string false "频度"
  28. // @Param Keywords query string false "指标ID/指标名称"
  29. // @Param ListAll query bool false "列表全选"
  30. // @Param SortField query int false "排序字段: 0-默认; 1-开始时间; 2-最新时间; 3-更新时间"
  31. // @Param SortRule query int false "排序方式: 0-默认; 1-正序; 2-倒序"
  32. // @Success 200 {object} data_manage.BloombergSourceListResp
  33. // @router /bloomberg_source/list [get]
  34. func (this *BloombergDataController) List() {
  35. br := new(models.BaseResponse).Init()
  36. defer func() {
  37. if br.ErrMsg == "" {
  38. br.IsSendEmail = false
  39. }
  40. this.Data["json"] = br
  41. this.ServeJSON()
  42. }()
  43. sysUser := this.SysUser
  44. if sysUser == nil {
  45. br.Msg = "请登录"
  46. br.ErrMsg = "请登录,SysUser Is Empty"
  47. br.Ret = 408
  48. return
  49. }
  50. params := new(data_manage.BloombergSourceListReq)
  51. if e := this.ParseForm(params); e != nil {
  52. br.Msg = "获取失败"
  53. br.ErrMsg = "参数解析失败, Err: " + e.Error()
  54. return
  55. }
  56. var startSize int
  57. if params.PageSize <= 0 {
  58. params.PageSize = utils.PageSize20
  59. }
  60. if params.CurrentIndex <= 0 {
  61. params.CurrentIndex = 1
  62. }
  63. startSize = utils.StartIndex(params.CurrentIndex, params.PageSize)
  64. dataResp := new(data_manage.BloombergSourceListResp)
  65. cond := ``
  66. pars := make([]interface{}, 0)
  67. // 筛选项
  68. {
  69. params.Keywords = strings.TrimSpace(params.Keywords)
  70. if params.Keywords != "" {
  71. // 空格分词搜
  72. //indexCodeCol := data_manage.BaseFromBloombergIndexCols.IndexCode
  73. //indexNameCol := data_manage.BaseFromBloombergIndexCols.IndexName
  74. //keywordArr := strings.Split(params.Keywords, " ")
  75. //if len(keywordArr) > 1 {
  76. // sliceArr := make([]string, 0)
  77. // sliceArr = append(sliceArr, fmt.Sprintf(` %s LIKE ? OR %s LIKE ? `, indexCodeCol, indexNameCol))
  78. // pars = utils.GetLikeKeywordPars(pars, params.Keywords, 2)
  79. //
  80. // for _, v := range keywordArr {
  81. // if v == ` ` || v == `` {
  82. // continue
  83. // }
  84. // sliceArr = append(sliceArr, fmt.Sprintf(` %s LIKE ? OR %s LIKE ? `, indexCodeCol, indexNameCol))
  85. // pars = utils.GetLikeKeywordPars(pars, v, 2)
  86. // }
  87. // cond += ` AND (` + strings.Join(sliceArr, " OR ") + `)`
  88. //} else {
  89. // cond += fmt.Sprintf(` AND (%s LIKE ? OR %s LIKE ?)`, indexCodeCol, indexNameCol)
  90. // pars = utils.GetLikeKeywordPars(pars, params.Keywords, 2)
  91. //}
  92. // ES搜
  93. _, list, e := elastic.SearchDataSourceIndex(utils.EsDataSourceIndexName, params.Keywords, utils.DATA_SOURCE_BLOOMBERG, 0, []int{}, []int{}, []string{}, startSize, params.PageSize)
  94. if e != nil {
  95. br.Msg = "获取失败"
  96. br.ErrMsg = fmt.Sprintf("ES-搜索Bloomberg指标失败, %v", e)
  97. return
  98. }
  99. if len(list) == 0 {
  100. dataResp.Paging = paging.GetPaging(params.CurrentIndex, params.PageSize, 0)
  101. dataResp.List = make([]*data_manage.BaseFromBloombergIndexItem, 0)
  102. br.Data = dataResp
  103. br.Ret = 200
  104. br.Success = true
  105. br.Msg = "获取成功"
  106. return
  107. }
  108. var indexIds []int
  109. for _, v := range list {
  110. indexIds = append(indexIds, v.PrimaryId)
  111. }
  112. cond += fmt.Sprintf(" AND %s IN (%s)", data_manage.BaseFromBloombergIndexCols.BaseFromBloombergIndexId, utils.GetOrmInReplace(len(indexIds)))
  113. pars = append(pars, indexIds)
  114. }
  115. if params.Frequency != "" {
  116. cond += fmt.Sprintf(` AND %s = ?`, data_manage.BaseFromBloombergIndexCols.Frequency)
  117. pars = append(pars, params.Frequency)
  118. }
  119. }
  120. // 分页列表
  121. bloombergOb := new(data_manage.BaseFromBloombergIndex)
  122. total, e := bloombergOb.GetCountByCondition(cond, pars)
  123. if e != nil {
  124. br.Msg = "获取失败"
  125. br.ErrMsg = "获取Bloomberg原始指标列表总数失败, Err: " + e.Error()
  126. return
  127. }
  128. // 排序, 默认创建时间倒序
  129. orderFields := map[int]string{
  130. 0: data_manage.BaseFromBloombergIndexCols.CreateTime, 1: data_manage.BaseFromBloombergIndexCols.StartDate,
  131. 2: data_manage.BaseFromBloombergIndexCols.EndDate, 3: data_manage.BaseFromBloombergIndexCols.ModifyTime,
  132. }
  133. orderType := map[int]string{0: "DESC", 1: "ASC", 2: "DESC"}
  134. orderRule := fmt.Sprintf("%s %s", orderFields[params.SortField], orderType[params.SortRule])
  135. // 列表
  136. edbList := make([]*data_manage.BaseFromBloombergIndex, 0)
  137. if params.ListAll {
  138. list, e := bloombergOb.GetItemsByCondition(cond, pars, []string{}, orderRule, 0)
  139. if e != nil {
  140. br.Msg = "获取失败"
  141. br.ErrMsg = "获取Bloomberg原始指标列表失败, Err: " + e.Error()
  142. return
  143. }
  144. edbList = list
  145. } else {
  146. list, e := bloombergOb.GetPageItemsByCondition(cond, pars, []string{}, orderRule, startSize, params.PageSize)
  147. if e != nil {
  148. br.Msg = "获取失败"
  149. br.ErrMsg = "获取Bloomberg原始指标分页列表失败, Err: " + e.Error()
  150. return
  151. }
  152. edbList = list
  153. }
  154. // 获取指标库已有指标
  155. existsEdb, e := data_manage.GetEdbCodesBySource(utils.DATA_SOURCE_BLOOMBERG)
  156. if e != nil {
  157. br.Msg = "获取失败"
  158. br.ErrMsg = "获取Bloomberg已添加的指标失败, Err: " + e.Error()
  159. return
  160. }
  161. existMap := make(map[string]*data_manage.EdbInfo)
  162. for _, v := range existsEdb {
  163. existMap[v.EdbCode] = v
  164. }
  165. respList := make([]*data_manage.BaseFromBloombergIndexItem, 0)
  166. for _, v := range edbList {
  167. t := data_manage.FormatBaseFromBloombergIndex2Item(v)
  168. ed := existMap[v.IndexCode]
  169. if ed != nil {
  170. t.EdbExist = 1
  171. t.EdbInfoId = ed.EdbInfoId
  172. t.EdbUniqueCode = ed.UniqueCode
  173. t.EdbClassifyId = ed.ClassifyId
  174. }
  175. respList = append(respList, t)
  176. }
  177. page := paging.GetPaging(params.CurrentIndex, params.PageSize, total)
  178. dataResp.Paging = page
  179. dataResp.List = respList
  180. br.Data = dataResp
  181. br.Ret = 200
  182. br.Success = true
  183. br.Msg = "获取成功"
  184. }
  185. // BatchAdd
  186. // @Title 批量新增
  187. // @Description 批量新增
  188. // @Param request body data_manage.AddEdbInfoReq true "type json string"
  189. // @Success 200 string "操作成功"
  190. // @router /bloomberg_source/batch_add [post]
  191. func (this *BloombergDataController) BatchAdd() {
  192. br := new(models.BaseResponse).Init()
  193. defer func() {
  194. if br.ErrMsg == "" {
  195. br.IsSendEmail = false
  196. }
  197. this.Data["json"] = br
  198. this.ServeJSON()
  199. }()
  200. sysUser := this.SysUser
  201. if sysUser == nil {
  202. br.Msg = "请登录"
  203. br.ErrMsg = "请登录,SysUser Is Empty"
  204. br.Ret = 408
  205. return
  206. }
  207. deleteCache := true
  208. cacheKey := "CACHE_EDB_INFO_BATCH_ADD_BLOOMBERG_" + strconv.Itoa(sysUser.AdminId)
  209. defer func() {
  210. if deleteCache {
  211. _ = utils.Rc.Delete(cacheKey)
  212. }
  213. }()
  214. if !utils.Rc.SetNX(cacheKey, 1, 30*time.Second) {
  215. deleteCache = false
  216. br.Msg = "系统处理中,请稍后重试!"
  217. br.ErrMsg = "系统处理中,请稍后重试!" + sysUser.RealName + ";data:" + string(this.Ctx.Input.RequestBody)
  218. return
  219. }
  220. var req []*data_manage.AddEdbInfoReq
  221. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
  222. br.Msg = "参数解析异常!"
  223. br.ErrMsg = "参数解析失败,Err:" + e.Error()
  224. return
  225. }
  226. if len(req) == 0 {
  227. br.Msg = "请选择指标"
  228. return
  229. }
  230. if len(req) > 30 {
  231. br.Msg = "批量添加指标数量不得超过30个"
  232. return
  233. }
  234. indexNames := make([]string, 0)
  235. for _, v := range req {
  236. v.EdbCode = strings.TrimSpace(v.EdbCode)
  237. if v.EdbCode == "" {
  238. br.Msg = "指标ID不可为空"
  239. return
  240. }
  241. v.EdbName = strings.TrimSpace(v.EdbName)
  242. if v.EdbName == "" {
  243. br.Msg = "请输入指标名称"
  244. return
  245. }
  246. indexNames = append(indexNames, v.EdbName)
  247. v.Frequency = strings.TrimSpace(v.Frequency)
  248. if v.Frequency == "" {
  249. br.Msg = "请选择频度"
  250. return
  251. }
  252. v.Unit = strings.TrimSpace(v.Unit)
  253. if v.Unit == "" {
  254. br.Msg = "请输入单位"
  255. return
  256. }
  257. if v.ClassifyId <= 0 {
  258. br.Msg = "请选择分类"
  259. return
  260. }
  261. }
  262. // 限定同一时间最多批量新增30个指标
  263. for _, v := range req {
  264. var r data.BloombergIndexSource2EdbReq
  265. r.EdbCode = v.EdbCode
  266. r.EdbName = v.EdbName
  267. r.Frequency = v.Frequency
  268. r.Unit = v.Unit
  269. r.ClassifyId = v.ClassifyId
  270. r.AdminId = sysUser.AdminId
  271. r.AdminRealName = sysUser.RealName
  272. edbInfo, e, errMsg, skip := data.BloombergIndexSource2Edb(r, this.Lang)
  273. if e != nil {
  274. br.Msg = "操作失败"
  275. if errMsg != "" {
  276. br.Msg = errMsg
  277. }
  278. br.ErrMsg = e.Error()
  279. return
  280. }
  281. if skip {
  282. continue
  283. }
  284. // 试用平台更新用户累计新增指标数
  285. if utils.BusinessCode == utils.BusinessCodeSandbox {
  286. go func() {
  287. adminItem, e := system.GetSysAdminById(sysUser.AdminId)
  288. if e != nil {
  289. tips := fmt.Sprintf("试用平台更新用户累计新增指标数-获取用户失败, Err: " + e.Error())
  290. utils.FileLog.Info(tips)
  291. return
  292. }
  293. if adminItem.DepartmentName != "ETA试用客户" {
  294. return
  295. }
  296. var ur etaTrialService.EtaTrialUserReq
  297. ur.Mobile = adminItem.Mobile
  298. _, _ = etaTrialService.UpdateUserIndexNum(ur)
  299. }()
  300. }
  301. // 新增操作日志
  302. {
  303. edbLog := new(data_manage.EdbInfoLog)
  304. edbLog.EdbInfoId = edbInfo.EdbInfoId
  305. edbLog.SourceName = edbInfo.SourceName
  306. edbLog.Source = edbInfo.Source
  307. edbLog.EdbCode = edbInfo.EdbCode
  308. edbLog.EdbName = edbInfo.EdbName
  309. edbLog.ClassifyId = edbInfo.ClassifyId
  310. edbLog.SysUserId = sysUser.AdminId
  311. edbLog.SysUserRealName = sysUser.RealName
  312. edbLog.CreateTime = time.Now()
  313. edbLog.Content = string(this.Ctx.Input.RequestBody)
  314. edbLog.Status = "新增指标"
  315. edbLog.Method = this.Ctx.Input.URI()
  316. go data_manage.AddEdbInfoLog(edbLog)
  317. }
  318. }
  319. br.Msg = "操作成功"
  320. br.Ret = 200
  321. br.Success = true
  322. br.IsAddLog = true
  323. }
  324. // NameCheck
  325. // @Title 重名校验
  326. // @Description 批量新增
  327. // @Param request body data_manage.AddEdbInfoReq true "type json string"
  328. // @Success 200 string "操作成功"
  329. // @router /bloomberg_source/name_check [post]
  330. func (this *BloombergDataController) NameCheck() {
  331. br := new(models.BaseResponse).Init()
  332. defer func() {
  333. if br.ErrMsg == "" {
  334. br.IsSendEmail = false
  335. }
  336. this.Data["json"] = br
  337. this.ServeJSON()
  338. }()
  339. sysUser := this.SysUser
  340. if sysUser == nil {
  341. br.Msg = "请登录"
  342. br.ErrMsg = "请登录,SysUser Is Empty"
  343. br.Ret = 408
  344. return
  345. }
  346. var req []*data_manage.AddEdbInfoReq
  347. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
  348. br.Msg = "参数解析异常!"
  349. br.ErrMsg = "参数解析失败,Err:" + e.Error()
  350. return
  351. }
  352. if len(req) == 0 {
  353. br.Msg = "请选择指标"
  354. return
  355. }
  356. type NameCheckResult struct {
  357. EdbCode string
  358. EdbName string
  359. Exist bool
  360. }
  361. indexNames := make([]string, 0)
  362. resp := make([]*NameCheckResult, 0)
  363. for _, v := range req {
  364. v.EdbCode = strings.TrimSpace(v.EdbCode)
  365. if v.EdbCode == "" {
  366. br.Msg = "指标ID不可为空"
  367. return
  368. }
  369. v.EdbName = strings.TrimSpace(v.EdbName)
  370. if v.EdbName == "" {
  371. br.Msg = "请输入指标名称"
  372. return
  373. }
  374. indexNames = append(indexNames, v.EdbName)
  375. resp = append(resp, &NameCheckResult{
  376. EdbCode: v.EdbCode,
  377. EdbName: v.EdbName,
  378. })
  379. }
  380. // 重名校验
  381. edbList, e := data_manage.GetEdbInfoByNameArr(indexNames, utils.EDB_INFO_TYPE)
  382. if e != nil {
  383. br.Msg = "操作失败"
  384. br.ErrMsg = "获取重名指标失败, Err: " + e.Error()
  385. return
  386. }
  387. nameExists := make(map[string]bool)
  388. for _, v := range edbList {
  389. nameExists[v.EdbName] = true
  390. }
  391. if len(nameExists) > 0 {
  392. for _, v := range resp {
  393. v.Exist = nameExists[v.EdbName]
  394. }
  395. }
  396. br.Data = resp
  397. br.Msg = "操作成功"
  398. br.Ret = 200
  399. br.Success = true
  400. }
  401. // AddCheck
  402. // @Title 新增校验
  403. // @Description 新增校验
  404. // @Param request body data_manage.BloombergSourceBatchAddCheckReq true "type json string"
  405. // @Success 200 string "操作成功"
  406. // @router /bloomberg_source/add_check [post]
  407. func (this *BloombergDataController) AddCheck() {
  408. br := new(models.BaseResponse).Init()
  409. defer func() {
  410. if br.ErrMsg == "" {
  411. br.IsSendEmail = false
  412. }
  413. this.Data["json"] = br
  414. this.ServeJSON()
  415. }()
  416. sysUser := this.SysUser
  417. if sysUser == nil {
  418. br.Msg = "请登录"
  419. br.ErrMsg = "请登录,SysUser Is Empty"
  420. br.Ret = 408
  421. return
  422. }
  423. var req *data_manage.BloombergSourceBatchAddCheckReq
  424. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
  425. br.Msg = "参数解析异常!"
  426. br.ErrMsg = "参数解析失败,Err:" + e.Error()
  427. return
  428. }
  429. codeMax := 30
  430. codeLen := len(req.IndexCodes)
  431. // 排序, 默认创建时间倒序
  432. orderFields := map[int]string{
  433. 0: data_manage.BaseFromBloombergIndexCols.CreateTime, 1: data_manage.BaseFromBloombergIndexCols.StartDate,
  434. 2: data_manage.BaseFromBloombergIndexCols.EndDate, 3: data_manage.BaseFromBloombergIndexCols.ModifyTime,
  435. }
  436. orderType := map[int]string{0: "DESC", 1: "ASC", 2: "DESC"}
  437. orderRule := fmt.Sprintf("%s %s", orderFields[req.SortField], orderType[req.SortRule])
  438. // 获取指标库已有指标
  439. existsEdb, e := data_manage.GetEdbCodesBySource(utils.DATA_SOURCE_BLOOMBERG)
  440. if e != nil {
  441. br.Msg = "获取失败"
  442. br.ErrMsg = "获取Bloomberg已添加的指标失败, Err: " + e.Error()
  443. return
  444. }
  445. existMap := make(map[string]*data_manage.EdbInfo)
  446. for _, v := range existsEdb {
  447. existMap[v.EdbCode] = v
  448. }
  449. // 非全选-不需要频率等筛选条件
  450. bloombergOb := new(data_manage.BaseFromBloombergIndex)
  451. if !req.ListAll {
  452. if codeLen == 0 {
  453. br.Msg = "请选择指标"
  454. return
  455. }
  456. if codeLen > codeMax {
  457. br.Msg = fmt.Sprintf("最多只能选择%d个指标", codeMax)
  458. return
  459. }
  460. // 查询选中的指标
  461. cond := fmt.Sprintf(` AND %s IN (%s)`, data_manage.BaseFromBloombergIndexCols.IndexCode, utils.GetOrmInReplace(codeLen))
  462. pars := make([]interface{}, 0)
  463. pars = append(pars, req.IndexCodes)
  464. list, e := bloombergOb.GetItemsByCondition(cond, pars, []string{}, orderRule, 0)
  465. if e != nil {
  466. br.Msg = "获取失败"
  467. br.ErrMsg = "获取Bloomberg原始指标列表失败, Err: " + e.Error()
  468. return
  469. }
  470. resp := make([]*data_manage.BaseFromBloombergIndexItem, 0)
  471. for _, v := range list {
  472. t := data_manage.FormatBaseFromBloombergIndex2Item(v)
  473. ed := existMap[v.IndexCode]
  474. if ed != nil {
  475. t.EdbExist = 1
  476. t.EdbInfoId = ed.EdbInfoId
  477. t.EdbUniqueCode = ed.UniqueCode
  478. t.EdbClassifyId = ed.ClassifyId
  479. }
  480. resp = append(resp, t)
  481. }
  482. br.Data = resp
  483. br.Msg = "校验成功"
  484. br.Ret = 200
  485. br.Success = true
  486. return
  487. }
  488. // 全选-需要频率等筛选条件
  489. cond := ``
  490. pars := make([]interface{}, 0)
  491. // 筛选项
  492. req.Keywords = strings.TrimSpace(req.Keywords)
  493. if req.Keywords != "" {
  494. // 空格分词搜
  495. indexCodeCol := data_manage.BaseFromBloombergIndexCols.IndexCode
  496. indexNameCol := data_manage.BaseFromBloombergIndexCols.IndexName
  497. keywordArr := strings.Split(req.Keywords, " ")
  498. if len(keywordArr) > 1 {
  499. sliceArr := make([]string, 0)
  500. sliceArr = append(sliceArr, fmt.Sprintf(` %s LIKE ? OR %s LIKE ? `, indexCodeCol, indexNameCol))
  501. pars = utils.GetLikeKeywordPars(pars, req.Keywords, 2)
  502. for _, v := range keywordArr {
  503. if v == ` ` || v == `` {
  504. continue
  505. }
  506. sliceArr = append(sliceArr, fmt.Sprintf(` %s LIKE ? OR %s LIKE ? `, indexCodeCol, indexNameCol))
  507. pars = utils.GetLikeKeywordPars(pars, v, 2)
  508. }
  509. cond += ` AND (` + strings.Join(sliceArr, " OR ") + `)`
  510. } else {
  511. cond += fmt.Sprintf(` AND (%s LIKE ? OR %s LIKE ?)`, indexCodeCol, indexNameCol)
  512. pars = utils.GetLikeKeywordPars(pars, req.Keywords, 2)
  513. }
  514. }
  515. if req.Frequency != "" {
  516. cond += fmt.Sprintf(` AND %s = ?`, data_manage.BaseFromBloombergIndexCols.Frequency)
  517. pars = append(pars, req.Frequency)
  518. }
  519. // 排除对应指标
  520. if codeLen > 0 {
  521. cond += fmt.Sprintf(` AND %s NOT IN (%s)`, data_manage.BaseFromBloombergIndexCols.IndexCode, utils.GetOrmInReplace(codeLen))
  522. pars = append(pars, req.IndexCodes)
  523. }
  524. // 查询max+1个指标
  525. list, e := bloombergOb.GetItemsByCondition(cond, pars, []string{}, orderRule, codeMax+1)
  526. if e != nil {
  527. br.Msg = "获取失败"
  528. br.ErrMsg = "获取Bloomberg原始指标列表失败, Err: " + e.Error()
  529. return
  530. }
  531. if len(list) > codeMax {
  532. br.Msg = fmt.Sprintf("最多只能选择%d个指标", codeMax)
  533. return
  534. }
  535. resp := make([]*data_manage.BaseFromBloombergIndexItem, 0)
  536. for _, v := range list {
  537. t := data_manage.FormatBaseFromBloombergIndex2Item(v)
  538. ed := existMap[v.IndexCode]
  539. if ed != nil {
  540. t.EdbExist = 1
  541. t.EdbInfoId = ed.EdbInfoId
  542. t.EdbUniqueCode = ed.UniqueCode
  543. t.EdbClassifyId = ed.ClassifyId
  544. }
  545. resp = append(resp, t)
  546. }
  547. br.Data = resp
  548. br.Msg = "校验成功"
  549. br.Ret = 200
  550. br.Success = true
  551. }
  552. // EdbInfoAdd
  553. // @Title 加入到指标库
  554. // @Description 加入到指标库
  555. // @Param request body data_manage.AddEdbInfoReq true "type json string"
  556. // @Success 200 string "操作成功"
  557. // @router /bloomberg_source/edb_add [post]
  558. func (this *BloombergDataController) EdbInfoAdd() {
  559. br := new(models.BaseResponse).Init()
  560. defer func() {
  561. this.Data["json"] = br
  562. this.ServeJSON()
  563. }()
  564. sysUser := this.SysUser
  565. if sysUser == nil {
  566. br.Msg = "请登录"
  567. br.ErrMsg = "请登录,SysUser Is Empty"
  568. br.Ret = 408
  569. return
  570. }
  571. deleteCache := true
  572. cacheKey := "CACHE_EDB_INFO_SINGLE_ADD_BLOOMBERG_" + strconv.Itoa(sysUser.AdminId)
  573. defer func() {
  574. if deleteCache {
  575. _ = utils.Rc.Delete(cacheKey)
  576. }
  577. }()
  578. if !utils.Rc.SetNX(cacheKey, 1, 30*time.Second) {
  579. deleteCache = false
  580. br.Msg = "系统处理中,请稍后重试!"
  581. br.ErrMsg = "系统处理中,请稍后重试!" + sysUser.RealName + ";data:" + string(this.Ctx.Input.RequestBody)
  582. return
  583. }
  584. req := new(data_manage.AddEdbInfoReq)
  585. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
  586. br.Msg = "参数解析异常!"
  587. br.ErrMsg = "参数解析失败,Err:" + e.Error()
  588. return
  589. }
  590. if req.EdbCode == "" {
  591. br.Msg = "指标ID不可为空"
  592. return
  593. }
  594. req.EdbName = strings.TrimSpace(req.EdbName)
  595. if req.EdbName == "" {
  596. br.Msg = "请输入指标名称"
  597. return
  598. }
  599. req.Frequency = strings.TrimSpace(req.Frequency)
  600. if req.Frequency == "" {
  601. br.Msg = "请选择频度"
  602. return
  603. }
  604. req.Unit = strings.TrimSpace(req.Unit)
  605. if req.Unit == "" {
  606. br.Msg = "请输入单位"
  607. return
  608. }
  609. if req.ClassifyId <= 0 {
  610. br.Msg = "请选择分类"
  611. return
  612. }
  613. // 新增指标
  614. var r data.BloombergIndexSource2EdbReq
  615. r.EdbCode = req.EdbCode
  616. r.EdbName = req.EdbName
  617. r.Frequency = req.Frequency
  618. r.Unit = req.Unit
  619. r.ClassifyId = req.ClassifyId
  620. r.AdminId = this.SysUser.AdminId
  621. r.AdminRealName = this.SysUser.RealName
  622. edbInfo, e, errMsg, skip := data.BloombergIndexSource2Edb(r, this.Lang)
  623. if e != nil {
  624. br.Msg = "操作失败"
  625. if errMsg != "" {
  626. br.Msg = errMsg
  627. }
  628. br.ErrMsg = e.Error()
  629. return
  630. }
  631. if skip {
  632. br.Msg = "指标已存在"
  633. return
  634. }
  635. // 试用平台更新用户累计新增指标数
  636. if utils.BusinessCode == utils.BusinessCodeSandbox {
  637. go func() {
  638. adminItem, e := system.GetSysAdminById(sysUser.AdminId)
  639. if e != nil {
  640. tips := fmt.Sprintf("试用平台更新用户累计新增指标数-获取用户失败, Err: " + e.Error())
  641. utils.FileLog.Info(tips)
  642. return
  643. }
  644. if adminItem.DepartmentName != "ETA试用客户" {
  645. return
  646. }
  647. var ur etaTrialService.EtaTrialUserReq
  648. ur.Mobile = adminItem.Mobile
  649. _, _ = etaTrialService.UpdateUserIndexNum(ur)
  650. }()
  651. }
  652. // 新增操作日志
  653. {
  654. edbLog := new(data_manage.EdbInfoLog)
  655. edbLog.EdbInfoId = edbInfo.EdbInfoId
  656. edbLog.SourceName = edbInfo.SourceName
  657. edbLog.Source = edbInfo.Source
  658. edbLog.EdbCode = edbInfo.EdbCode
  659. edbLog.EdbName = edbInfo.EdbName
  660. edbLog.ClassifyId = edbInfo.ClassifyId
  661. edbLog.SysUserId = sysUser.AdminId
  662. edbLog.SysUserRealName = sysUser.RealName
  663. edbLog.CreateTime = time.Now()
  664. edbLog.Content = string(this.Ctx.Input.RequestBody)
  665. edbLog.Status = "新增指标"
  666. edbLog.Method = this.Ctx.Input.URI()
  667. go data_manage.AddEdbInfoLog(edbLog)
  668. }
  669. br.Msg = "操作成功"
  670. br.Ret = 200
  671. br.Success = true
  672. br.IsAddLog = true
  673. }