|
@@ -0,0 +1,509 @@
|
|
|
+package data_manage
|
|
|
+
|
|
|
+import (
|
|
|
+ "encoding/json"
|
|
|
+ "eta/eta_api/controllers"
|
|
|
+ "eta/eta_api/models"
|
|
|
+ "eta/eta_api/models/data_manage"
|
|
|
+ "eta/eta_api/models/data_manage/request"
|
|
|
+ "eta/eta_api/models/system"
|
|
|
+ "eta/eta_api/services/data"
|
|
|
+ etaTrialService "eta/eta_api/services/eta_trial"
|
|
|
+ "eta/eta_api/utils"
|
|
|
+ "fmt"
|
|
|
+ "github.com/rdlucklib/rdluck_tools/paging"
|
|
|
+ "strconv"
|
|
|
+ "strings"
|
|
|
+ "time"
|
|
|
+)
|
|
|
+
|
|
|
+
|
|
|
+type EdbBusinessController struct {
|
|
|
+ controllers.BaseAuthController
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+func (c *EdbBusinessController) SourceList() {
|
|
|
+ br := new(models.BaseResponse).Init()
|
|
|
+ defer func() {
|
|
|
+ c.Data["json"] = br
|
|
|
+ c.ServeJSON()
|
|
|
+ }()
|
|
|
+
|
|
|
+ obj := data_manage.EdbBusinessSource{}
|
|
|
+ list, err := obj.GetAllList()
|
|
|
+ if err != nil && err.Error() != utils.ErrNoRow() {
|
|
|
+ br.Msg = "获取失败"
|
|
|
+ br.ErrMsg = "获取数据失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ br.Ret = 200
|
|
|
+ br.Success = true
|
|
|
+ br.Msg = "获取成功"
|
|
|
+ br.Data = list
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+func (c *EdbBusinessController) List() {
|
|
|
+ br := new(models.BaseResponse).Init()
|
|
|
+ defer func() {
|
|
|
+ c.Data["json"] = br
|
|
|
+ c.ServeJSON()
|
|
|
+ }()
|
|
|
+ pageSize, _ := c.GetInt("PageSize")
|
|
|
+ currentIndex, _ := c.GetInt("CurrentIndex")
|
|
|
+ keywords := c.GetString("Keywords")
|
|
|
+ frequency := c.GetString("Frequency")
|
|
|
+ source, _ := c.GetInt("Source")
|
|
|
+
|
|
|
+ var startSize int
|
|
|
+ if pageSize <= 0 {
|
|
|
+ pageSize = utils.PageSize20
|
|
|
+ }
|
|
|
+ if currentIndex <= 0 {
|
|
|
+ currentIndex = 1
|
|
|
+ }
|
|
|
+ startSize = utils.StartIndex(currentIndex, pageSize)
|
|
|
+
|
|
|
+ var condition string
|
|
|
+ var pars []interface{}
|
|
|
+
|
|
|
+ if keywords != "" {
|
|
|
+ keywordSlice := strings.Split(keywords, " ")
|
|
|
+ if len(keywordSlice) > 0 {
|
|
|
+ tmpConditionSlice := make([]string, 0)
|
|
|
+ tmpConditionSlice = append(tmpConditionSlice, ` a.index_name like ? or a.index_code like ? `)
|
|
|
+ pars = utils.GetLikeKeywordPars(pars, keywords, 2)
|
|
|
+
|
|
|
+ for _, v := range keywordSlice {
|
|
|
+ if v == ` ` || v == `` {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ tmpConditionSlice = append(tmpConditionSlice, ` a.index_name like ? or a.index_code like ? `)
|
|
|
+ pars = utils.GetLikeKeywordPars(pars, v, 2)
|
|
|
+ }
|
|
|
+ condition += ` AND (` + strings.Join(tmpConditionSlice, " or ") + `)`
|
|
|
+
|
|
|
+ } else {
|
|
|
+ condition += ` a.index_name like ? or a.index_code like ? `
|
|
|
+ pars = utils.GetLikeKeywordPars(pars, keywords, 2)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if frequency != "" {
|
|
|
+ condition += ` AND a.frequency = ? `
|
|
|
+ pars = append(pars, frequency)
|
|
|
+ }
|
|
|
+
|
|
|
+ if source > 0 {
|
|
|
+ condition += ` AND a.source = ? `
|
|
|
+ pars = append(pars, source)
|
|
|
+ }
|
|
|
+
|
|
|
+ obj := data_manage.BaseFromBusinessIndex{}
|
|
|
+
|
|
|
+ total, err := obj.GetListCount(condition, pars)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "获取失败"
|
|
|
+ br.ErrMsg = "获取失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ list, err := obj.GetPageItemsByCondition(condition, pars, startSize, pageSize)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "获取失败"
|
|
|
+ br.ErrMsg = "获取失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if len(list) <= 0 {
|
|
|
+ list = make([]*data_manage.BaseFromBusinessIndexItem, 0)
|
|
|
+ }
|
|
|
+
|
|
|
+ page := paging.GetPaging(currentIndex, pageSize, total)
|
|
|
+ resp := data_manage.BusinessIndexListResp{
|
|
|
+ List: list,
|
|
|
+ Paging: page,
|
|
|
+ }
|
|
|
+
|
|
|
+ br.Ret = 200
|
|
|
+ br.Success = true
|
|
|
+ br.Msg = "获取成功"
|
|
|
+ br.Data = resp
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+func (c *EdbBusinessController) AddCheck() {
|
|
|
+ br := new(models.BaseResponse).Init()
|
|
|
+ defer func() {
|
|
|
+ if br.ErrMsg == "" {
|
|
|
+ br.IsSendEmail = false
|
|
|
+ }
|
|
|
+ c.Data["json"] = br
|
|
|
+ c.ServeJSON()
|
|
|
+ }()
|
|
|
+ sysUser := c.SysUser
|
|
|
+ if sysUser == nil {
|
|
|
+ br.Msg = "请登录"
|
|
|
+ br.ErrMsg = "请登录,SysUser Is Empty"
|
|
|
+ br.Ret = 408
|
|
|
+ return
|
|
|
+ }
|
|
|
+ var req *request.BusinessDataBatchAddCheckReq
|
|
|
+ if e := json.Unmarshal(c.Ctx.Input.RequestBody, &req); e != nil {
|
|
|
+ br.Msg = "参数解析异常!"
|
|
|
+ br.ErrMsg = "参数解析失败,Err:" + e.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ codeMax := 100
|
|
|
+ codeLen := len(req.IndexCodes)
|
|
|
+
|
|
|
+
|
|
|
+ existsEdb, e := data_manage.GetEdbCodesBySource(utils.DATA_SOURCE_BUSINESS)
|
|
|
+ if e != nil {
|
|
|
+ br.Msg = "获取失败"
|
|
|
+ br.ErrMsg = "获取Bloomberg已添加的指标失败, Err: " + e.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ existMap := make(map[string]*data_manage.EdbInfo)
|
|
|
+ for _, v := range existsEdb {
|
|
|
+ existMap[v.EdbCode] = v
|
|
|
+ }
|
|
|
+
|
|
|
+ list := make([]*data_manage.BaseFromBusinessIndexItem, 0)
|
|
|
+ obj := data_manage.BaseFromBusinessIndex{}
|
|
|
+ if !req.ListAll {
|
|
|
+
|
|
|
+ if codeLen == 0 {
|
|
|
+ br.Msg = "请选择指标"
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if codeLen > codeMax {
|
|
|
+ br.Msg = fmt.Sprintf("最多只能选择%d个指标", codeMax)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ cond := fmt.Sprintf(` AND %s IN (%s)`, data_manage.BaseFromBusinessIndexCols.IndexCode, utils.GetOrmInReplace(codeLen))
|
|
|
+ pars := make([]interface{}, 0)
|
|
|
+ pars = append(pars, req.IndexCodes)
|
|
|
+ list, e = obj.GeItemsByCondition(cond, pars, 0)
|
|
|
+ if e != nil {
|
|
|
+ br.Msg = "获取失败"
|
|
|
+ br.ErrMsg = "获取Bloomberg原始指标列表失败, Err: " + e.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+
|
|
|
+ condition := ``
|
|
|
+ pars := make([]interface{}, 0)
|
|
|
+
|
|
|
+
|
|
|
+ req.Keywords = strings.TrimSpace(req.Keywords)
|
|
|
+ if req.Keywords != "" {
|
|
|
+ keywordSlice := strings.Split(req.Keywords, " ")
|
|
|
+ if len(keywordSlice) > 0 {
|
|
|
+ tmpConditionSlice := make([]string, 0)
|
|
|
+ tmpConditionSlice = append(tmpConditionSlice, ` a.index_name like ? or a.index_code like ? `)
|
|
|
+ pars = utils.GetLikeKeywordPars(pars, req.Keywords, 2)
|
|
|
+
|
|
|
+ for _, v := range keywordSlice {
|
|
|
+ if v == ` ` || v == `` {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ tmpConditionSlice = append(tmpConditionSlice, ` a.index_name like ? or a.index_code like ? `)
|
|
|
+ pars = utils.GetLikeKeywordPars(pars, v, 2)
|
|
|
+ }
|
|
|
+ condition += ` AND (` + strings.Join(tmpConditionSlice, " or ") + `)`
|
|
|
+
|
|
|
+ } else {
|
|
|
+ condition += ` a.index_name like ? or a.index_code like ? `
|
|
|
+ pars = utils.GetLikeKeywordPars(pars, req.Keywords, 2)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if req.Frequency != "" {
|
|
|
+ condition += ` AND a.frequency = ? `
|
|
|
+ pars = append(pars, req.Frequency)
|
|
|
+ }
|
|
|
+
|
|
|
+ if req.Source > 0 {
|
|
|
+ condition += ` AND a.source = ? `
|
|
|
+ pars = append(pars, req.Source)
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if codeLen > 0 {
|
|
|
+ condition += fmt.Sprintf(` AND a.%s NOT IN (%s)`, data_manage.BaseFromBloombergIndexCols.IndexCode, utils.GetOrmInReplace(codeLen))
|
|
|
+ pars = append(pars, req.IndexCodes)
|
|
|
+ }
|
|
|
+
|
|
|
+ list, e = obj.GeItemsByCondition(condition, pars, codeMax+1)
|
|
|
+ if e != nil {
|
|
|
+ br.Msg = "获取失败"
|
|
|
+ br.ErrMsg = "获取外部原始指标列表失败, Err: " + e.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if len(list) > codeMax {
|
|
|
+ br.Msg = fmt.Sprintf("最多只能选择%d个指标", codeMax)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ resp := make([]*data_manage.BaseFromBusinessIndexItem, 0)
|
|
|
+ for _, v := range list {
|
|
|
+ if v.EdbInfoId > 0 {
|
|
|
+ v.EdbExist = 1
|
|
|
+ }
|
|
|
+ resp = append(resp, v)
|
|
|
+ }
|
|
|
+
|
|
|
+ br.Data = resp
|
|
|
+ br.Msg = "校验成功"
|
|
|
+ br.Ret = 200
|
|
|
+ br.Success = true
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+func (c *EdbBusinessController) NameCheck() {
|
|
|
+ br := new(models.BaseResponse).Init()
|
|
|
+ defer func() {
|
|
|
+ if br.ErrMsg == "" {
|
|
|
+ br.IsSendEmail = false
|
|
|
+ }
|
|
|
+ c.Data["json"] = br
|
|
|
+ c.ServeJSON()
|
|
|
+ }()
|
|
|
+ sysUser := c.SysUser
|
|
|
+ if sysUser == nil {
|
|
|
+ br.Msg = "请登录"
|
|
|
+ br.ErrMsg = "请登录,SysUser Is Empty"
|
|
|
+ br.Ret = 408
|
|
|
+ return
|
|
|
+ }
|
|
|
+ var req []*data_manage.AddEdbInfoReq
|
|
|
+ if e := json.Unmarshal(c.Ctx.Input.RequestBody, &req); e != nil {
|
|
|
+ br.Msg = "参数解析异常!"
|
|
|
+ br.ErrMsg = "参数解析失败,Err:" + e.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if len(req) == 0 {
|
|
|
+ br.Msg = "请选择指标"
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ type NameCheckResult struct {
|
|
|
+ EdbCode string
|
|
|
+ EdbName string
|
|
|
+ Exist bool
|
|
|
+ }
|
|
|
+ indexNames := make([]string, 0)
|
|
|
+ resp := make([]*NameCheckResult, 0)
|
|
|
+ for _, v := range req {
|
|
|
+ v.EdbCode = strings.TrimSpace(v.EdbCode)
|
|
|
+ if v.EdbCode == "" {
|
|
|
+ br.Msg = "指标ID不可为空"
|
|
|
+ return
|
|
|
+ }
|
|
|
+ v.EdbName = strings.TrimSpace(v.EdbName)
|
|
|
+ if v.EdbName == "" {
|
|
|
+ br.Msg = "请输入指标名称"
|
|
|
+ return
|
|
|
+ }
|
|
|
+ indexNames = append(indexNames, v.EdbName)
|
|
|
+ resp = append(resp, &NameCheckResult{
|
|
|
+ EdbCode: v.EdbCode,
|
|
|
+ EdbName: v.EdbName,
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ edbList, e := data_manage.GetEdbInfoByNameArr(indexNames, utils.EDB_INFO_TYPE)
|
|
|
+ if e != nil {
|
|
|
+ br.Msg = "操作失败"
|
|
|
+ br.ErrMsg = "获取重名指标失败, Err: " + e.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ nameExists := make(map[string]bool)
|
|
|
+ for _, v := range edbList {
|
|
|
+ nameExists[v.EdbName] = true
|
|
|
+ }
|
|
|
+ if len(nameExists) > 0 {
|
|
|
+ for _, v := range resp {
|
|
|
+ v.Exist = nameExists[v.EdbName]
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ br.Data = resp
|
|
|
+ br.Msg = "校验成功"
|
|
|
+ br.Ret = 200
|
|
|
+ br.Success = true
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+func (c *EdbBusinessController) BatchAdd() {
|
|
|
+ br := new(models.BaseResponse).Init()
|
|
|
+ defer func() {
|
|
|
+ if br.ErrMsg == "" {
|
|
|
+ br.IsSendEmail = false
|
|
|
+ }
|
|
|
+ c.Data["json"] = br
|
|
|
+ c.ServeJSON()
|
|
|
+ }()
|
|
|
+ sysUser := c.SysUser
|
|
|
+ if sysUser == nil {
|
|
|
+ br.Msg = "请登录"
|
|
|
+ br.ErrMsg = "请登录,SysUser Is Empty"
|
|
|
+ br.Ret = 408
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ deleteCache := true
|
|
|
+ cacheKey := "CACHE_EDB_INFO_BATCH_ADD_BUSINESS_" + strconv.Itoa(sysUser.AdminId)
|
|
|
+ defer func() {
|
|
|
+ if deleteCache {
|
|
|
+ _ = utils.Rc.Delete(cacheKey)
|
|
|
+ }
|
|
|
+ }()
|
|
|
+ if !utils.Rc.SetNX(cacheKey, 1, 30*time.Second) {
|
|
|
+ deleteCache = false
|
|
|
+ br.Msg = "系统处理中,请稍后重试!"
|
|
|
+ br.ErrMsg = "系统处理中,请稍后重试!" + sysUser.RealName + ";data:" + string(c.Ctx.Input.RequestBody)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ var req []*data_manage.AddEdbInfoReq
|
|
|
+ if e := json.Unmarshal(c.Ctx.Input.RequestBody, &req); e != nil {
|
|
|
+ br.Msg = "参数解析异常!"
|
|
|
+ br.ErrMsg = "参数解析失败,Err:" + e.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if len(req) == 0 {
|
|
|
+ br.Msg = "请选择指标"
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if len(req) > 30 {
|
|
|
+ br.Msg = "批量添加指标数量不得超过30个"
|
|
|
+ return
|
|
|
+ }
|
|
|
+ indexNames := make([]string, 0)
|
|
|
+ for _, v := range req {
|
|
|
+ v.EdbCode = strings.TrimSpace(v.EdbCode)
|
|
|
+ if v.EdbCode == "" {
|
|
|
+ br.Msg = "指标ID不可为空"
|
|
|
+ return
|
|
|
+ }
|
|
|
+ v.EdbName = strings.TrimSpace(v.EdbName)
|
|
|
+ if v.EdbName == "" {
|
|
|
+ br.Msg = "请输入指标名称"
|
|
|
+ return
|
|
|
+ }
|
|
|
+ indexNames = append(indexNames, v.EdbName)
|
|
|
+ v.Frequency = strings.TrimSpace(v.Frequency)
|
|
|
+ if v.Frequency == "" {
|
|
|
+ br.Msg = "请选择频度"
|
|
|
+ return
|
|
|
+ }
|
|
|
+ v.Unit = strings.TrimSpace(v.Unit)
|
|
|
+ if v.Unit == "" {
|
|
|
+ br.Msg = "请输入单位"
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if v.ClassifyId <= 0 {
|
|
|
+ br.Msg = "请选择分类"
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ for _, v := range req {
|
|
|
+ var r data.BusinessIndexSource2EdbReq
|
|
|
+ r.EdbCode = v.EdbCode
|
|
|
+ r.EdbName = v.EdbName
|
|
|
+ r.Frequency = v.Frequency
|
|
|
+ r.Unit = v.Unit
|
|
|
+ r.ClassifyId = v.ClassifyId
|
|
|
+ r.AdminId = sysUser.AdminId
|
|
|
+ r.AdminRealName = sysUser.RealName
|
|
|
+
|
|
|
+ edbInfo, e, errMsg, skip := data.BusinessIndexSource2Edb(r, c.Lang)
|
|
|
+ if e != nil {
|
|
|
+ br.Msg = "操作失败"
|
|
|
+ if errMsg != "" {
|
|
|
+ br.Msg = errMsg
|
|
|
+ }
|
|
|
+ br.ErrMsg = e.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if skip {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if utils.BusinessCode == utils.BusinessCodeSandbox {
|
|
|
+ go func() {
|
|
|
+ adminItem, e := system.GetSysAdminById(sysUser.AdminId)
|
|
|
+ if e != nil {
|
|
|
+ tips := fmt.Sprintf("试用平台更新用户累计新增指标数-获取用户失败, Err: " + e.Error())
|
|
|
+ utils.FileLog.Info(tips)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if adminItem.DepartmentName != "ETA试用客户" {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ var ur etaTrialService.EtaTrialUserReq
|
|
|
+ ur.Mobile = adminItem.Mobile
|
|
|
+ _, _ = etaTrialService.UpdateUserIndexNum(ur)
|
|
|
+ }()
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ {
|
|
|
+ edbLog := new(data_manage.EdbInfoLog)
|
|
|
+ edbLog.EdbInfoId = edbInfo.EdbInfoId
|
|
|
+ edbLog.SourceName = edbInfo.SourceName
|
|
|
+ edbLog.Source = edbInfo.Source
|
|
|
+ edbLog.EdbCode = edbInfo.EdbCode
|
|
|
+ edbLog.EdbName = edbInfo.EdbName
|
|
|
+ edbLog.ClassifyId = edbInfo.ClassifyId
|
|
|
+ edbLog.SysUserId = sysUser.AdminId
|
|
|
+ edbLog.SysUserRealName = sysUser.RealName
|
|
|
+ edbLog.CreateTime = time.Now()
|
|
|
+ edbLog.Content = string(c.Ctx.Input.RequestBody)
|
|
|
+ edbLog.Status = "新增指标"
|
|
|
+ edbLog.Method = c.Ctx.Input.URI()
|
|
|
+ go data_manage.AddEdbInfoLog(edbLog)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ br.Msg = "操作成功"
|
|
|
+ br.Ret = 200
|
|
|
+ br.Success = true
|
|
|
+ br.IsAddLog = true
|
|
|
+}
|