浏览代码

Merge remote-tracking branch 'origin/eta/1.8.4' into debug

Roc 11 月之前
父节点
当前提交
b8c1eb8014

+ 1 - 1
controllers/data_manage/bloomberg_data.go

@@ -357,7 +357,7 @@ func (this *BloombergDataController) NameCheck() {
 	}
 
 	// 重名校验
-	edbList, e := data_manage.GetEdbInfoByNameArr(indexNames)
+	edbList, e := data_manage.GetEdbInfoByNameArr(indexNames, utils.EDB_INFO_TYPE)
 	if e != nil {
 		br.Msg = "操作失败"
 		br.ErrMsg = "获取重名指标失败, Err: " + e.Error()

+ 509 - 0
controllers/data_manage/business_data.go

@@ -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"
+)
+
+// EdbBusinessController 外部数据(商家)
+type EdbBusinessController struct {
+	controllers.BaseAuthController
+}
+
+// SourceList
+// @Title 来源列表
+// @Description 来源列表接口
+// @Success 200 {object} []*data_manageEdbBusinessSource
+// @router /business_data/source/list [get]
+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
+}
+
+// List
+// @Title 获取指标列表
+// @Description 获取指标列表接口
+// @Param   PageSize   query   int  true       "每页数据条数"
+// @Param   CurrentIndex   query   int  true       "当前页页码,从1开始"
+// @Param   Frequency   query   string  true       "频度"
+// @Param   Source   query   int  true       "来源"
+// @Param   Keywords   query   string  true       "编码/名称关键词"
+// @Success 200 {object} models.DataListResp
+// @router /business_data/list [get]
+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
+}
+
+// AddCheck
+// @Title 新增校验
+// @Description 新增校验
+// @Param	request	body request.BusinessDataBatchAddCheckReq true "type json string"
+// @Success 200 string "操作成功"
+// @router /business_data/add_check [post]
+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)
+		}
+		// 查询max+1个指标
+		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
+}
+
+// NameCheck
+// @Title 重名校验
+// @Description 批量新增
+// @Param	request	body data_manage.AddEdbInfoReq true "type json string"
+// @Success 200 string "操作成功"
+// @router /business_data/name_check [post]
+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
+}
+
+// BatchAdd
+// @Title 批量新增
+// @Description 批量新增
+// @Param	request	body data_manage.AddEdbInfoReq true "type json string"
+// @Success 200 string "操作成功"
+// @router /business_data/batch_add [post]
+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
+		}
+	}
+
+	// 限定同一时间最多批量新增100个指标
+	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
+}

+ 177 - 0
models/data_manage/base_from_business_index.go

@@ -0,0 +1,177 @@
+package data_manage
+
+import (
+	"eta/eta_api/utils"
+	"github.com/beego/beego/v2/client/orm"
+	"github.com/rdlucklib/rdluck_tools/paging"
+	"time"
+)
+
+// BaseFromBusinessIndex
+// @Description: 外部指标(商家系统)表
+type BaseFromBusinessIndex struct {
+	BaseFromBusinessIndexId int64     `orm:"column(base_from_business_index_id);pk"`
+	IndexCode               string    `description:"指标编码"`
+	IndexName               string    `description:"指标名称"`
+	Unit                    string    `description:"单位"`
+	Frequency               string    `description:"频度"`
+	Source                  int       `description:"数据来源"`
+	SourceName              string    `description:"数据来源名称"`
+	StartDate               time.Time `description:"开始日期"`
+	EndDate                 time.Time `description:"结束日期"`
+	Remark                  string    `description:"备注字段"`
+	BaseModifyTime          time.Time `description:"基础信息(名称,单位,频度)变更时间"`
+	DataUpdateTime          time.Time `description:"最近一次数据发生变化的时间"`
+	CreateTime              time.Time `description:"创建时间"`
+	ModifyTime              time.Time `description:"修改时间"`
+}
+
+var BaseFromBusinessIndexCols = struct {
+	BaseFromBusinessIndexId string
+	IndexCode               string
+	IndexName               string
+	Unit                    string
+	Frequency               string
+	Source                  string
+	SourceName              string
+	StartDate               string
+	EndDate                 string
+	Remark                  string
+	BaseModifyTime          string
+	DataUpdateTime          string
+	CreateTime              string
+	ModifyTime              string
+}{
+	BaseFromBusinessIndexId: "base_from_business_index_id",
+	IndexCode:               "index_code",
+	IndexName:               "index_name",
+	Unit:                    "unit",
+	Frequency:               "frequency",
+	Source:                  "source",
+	SourceName:              "source_name",
+	StartDate:               "start_date",
+	EndDate:                 "end_date",
+	Remark:                  "remark",
+	BaseModifyTime:          "base_modify_time",
+	DataUpdateTime:          "data_update_time",
+	CreateTime:              "create_time",
+	ModifyTime:              "modify_time",
+}
+
+// EdbBusinessSource
+// @Description: 外部数据(商家)指标来源
+type EdbBusinessSource struct {
+	EdbBusinessSourceId int64     `orm:"column(edb_business_source_id);pk"`
+	SourceName          string    `description:"来源名称"` // 来源名称
+	CreateTime          time.Time `description:"创建时间"` // 创建时间
+}
+
+// GetEdbBusinessSourceItem
+// @Description: 根据来源名称获取来源信息
+// @author: Roc
+// @receiver m
+// @datetime 2024-04-25 18:09:03
+// @param sourceName string
+// @return item *EdbBusinessSource
+// @return err error
+func (m *EdbBusinessSource) GetEdbBusinessSourceItem(sourceName string) (item *EdbBusinessSource, err error) {
+	o := orm.NewOrmUsingDB("data")
+	sql := `SELECT * FROM edb_business_source WHERE source_name = ? `
+	err = o.Raw(sql, sourceName).QueryRow(&item)
+	return
+}
+
+// GetAllList
+// @Description: 获取所有来源列表
+// @author: Roc
+// @receiver m
+// @datetime 2024-05-06 09:21:42
+// @return items []*EdbBusinessSource
+// @return err error
+func (m *EdbBusinessSource) GetAllList() (items []*EdbBusinessSource, err error) {
+	o := orm.NewOrmUsingDB("data")
+	sql := `SELECT * FROM edb_business_source order by  edb_business_source_id desc `
+	_, err = o.Raw(sql).QueryRows(&items)
+
+	return
+}
+
+func (m *BaseFromBusinessIndex) GetListCount(condition string, pars []interface{}) (count int, err error) {
+	sql := ` select count(1) as count FROM base_from_business_index as a WHERE 1=1 `
+	if condition != "" {
+		sql += condition
+	}
+	o := orm.NewOrmUsingDB("data")
+	err = o.Raw(sql, pars).QueryRow(&count)
+
+	return
+}
+func (m *BaseFromBusinessIndex) GetList(condition string, pars []interface{}, startSize, pageSize int) (items []*BaseFromBusinessIndex, err error) {
+	sql := `select * FROM base_from_business_index AS a  WHERE 1=1 `
+	if condition != "" {
+		sql += condition
+	}
+	sql += ` order by a.base_from_business_index_id desc limit ?,? `
+	o := orm.NewOrmUsingDB("data")
+	_, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
+
+	return
+}
+
+// BusinessIndexListResp
+// @Description: 外部(商家)指标列表返回
+type BusinessIndexListResp struct {
+	List   []*BaseFromBusinessIndexItem
+	Paging *paging.PagingItem `description:"分页数据"`
+}
+
+// BaseFromBusinessIndexItem
+// @Description: 外部指标(商家系统)结构
+type BaseFromBusinessIndexItem struct {
+	BaseFromBusinessIndexId int64  `orm:"column(base_from_business_index_id);pk"`
+	IndexCode               string `description:"指标编码"`
+	IndexName               string `description:"指标名称"`
+	Unit                    string `description:"单位"`
+	Frequency               string `description:"频度"`
+	Source                  int    `description:"数据来源"`
+	SourceName              string `description:"数据来源名称"`
+	StartDate               string `description:"开始日期"`
+	EndDate                 string `description:"结束日期"`
+	Remark                  string `description:"备注字段"`
+	BaseModifyTime          string `description:"基础信息(名称,单位,频度)变更时间"`
+	DataUpdateTime          string `description:"最近一次数据发生变化的时间"`
+	CreateTime              string `description:"创建时间"`
+	ModifyTime              string `description:"修改时间"`
+	EdbInfoId               int    `description:"eta指标库的id"`
+	EdbUniqueCode           string `description:"指标库唯一编码"`
+	EdbClassifyId           int    `description:"指标库分类ID"`
+	EdbExist                int    `description:"指标库是否已添加:0-否;1-是"`
+}
+
+func (m *BaseFromBusinessIndex) GetPageItemsByCondition(condition string, pars []interface{}, startSize, pageSize int) (items []*BaseFromBusinessIndexItem, err error) {
+	sql := `select a.*,b.edb_info_id,b.unique_code as edb_unique_code,b.classify_id as edb_classify_id FROM base_from_business_index AS a LEFT JOIN edb_info b on a.index_code=b.edb_code AND b.source=? WHERE 1=1 `
+	if condition != "" {
+		sql += condition
+	}
+	sql += ` order by a.base_from_business_index_id desc limit ?,? `
+	o := orm.NewOrmUsingDB("data")
+	_, err = o.Raw(sql, utils.DATA_SOURCE_BUSINESS, pars, startSize, pageSize).QueryRows(&items)
+
+	return
+}
+
+func (m *BaseFromBusinessIndex) GeItemsByCondition(condition string, pars []interface{}, limitSize int) (items []*BaseFromBusinessIndexItem, err error) {
+	sql := `select a.*,b.edb_info_id,b.unique_code as edb_unique_code,b.classify_id as edb_classify_id FROM base_from_business_index AS a LEFT JOIN edb_info b on a.index_code=b.edb_code AND b.source=? WHERE 1=1 `
+	if condition != "" {
+		sql += condition
+	}
+	sql += ` order by a.base_from_business_index_id desc `
+
+	if limitSize > 0 {
+		sql += " limit ? "
+	}
+	o := orm.NewOrmUsingDB("data")
+	_, err = o.Raw(sql, utils.DATA_SOURCE_BUSINESS, pars, limitSize).QueryRows(&items)
+
+	return
+}

+ 3 - 3
models/data_manage/edb_info.go

@@ -1924,13 +1924,13 @@ func GetEdbInfoCount(source int, edbCode string) (count int, err error) {
 }
 
 // GetEdbInfoByNameArr 根据名称获取指标
-func GetEdbInfoByNameArr(names []string) (items []*EdbInfo, err error) {
+func GetEdbInfoByNameArr(names []string, edbInfoType int) (items []*EdbInfo, err error) {
 	if len(names) == 0 {
 		return
 	}
 	o := orm.NewOrmUsingDB("data")
-	sql := fmt.Sprintf(`SELECT edb_info_id, edb_code, edb_name FROM edb_info WHERE edb_name IN (%s)`, utils.GetOrmInReplace(len(names)))
-	_, err = o.Raw(sql, names).QueryRows(&items)
+	sql := fmt.Sprintf(`SELECT edb_info_id, edb_code, edb_name FROM edb_info WHERE edb_name IN (%s) AND edb_info_type = ? `, utils.GetOrmInReplace(len(names)))
+	_, err = o.Raw(sql, names, edbInfoType).QueryRows(&items)
 	return
 }
 

+ 17 - 0
models/data_manage/request/business_data.go

@@ -0,0 +1,17 @@
+package request
+
+// BusinessDataListReq 指标列表筛选
+type BusinessDataListReq struct {
+	PageSize     int    `form:"PageSize"`
+	CurrentIndex int    `form:"CurrentIndex"`
+	Frequency    string `form:"Frequency" description:"频度"`
+	Source       int    `form:"Source" description:"来源id"`
+	Keywords     string `form:"Keywords" description:"指标ID/指标名称"`
+	ListAll      bool   `form:"ListAll" description:"列表全选"`
+}
+
+// BusinessDataBatchAddCheckReq 外部(商家)指标批量添加校验
+type BusinessDataBatchAddCheckReq struct {
+	BusinessDataListReq
+	IndexCodes []string `form:"IndexCodes" description:"全选为false时, 该数组为选中; 全选为true时, 该数组为不选的指标"`
+}

+ 45 - 0
routers/commentsRouter.go

@@ -2689,6 +2689,51 @@ func init() {
             Filters: nil,
             Params: nil})
 
+    beego.GlobalControllerRouter["eta/eta_api/controllers/data_manage:EdbBusinessController"] = append(beego.GlobalControllerRouter["eta/eta_api/controllers/data_manage:EdbBusinessController"],
+        beego.ControllerComments{
+            Method: "AddCheck",
+            Router: `/business_data/add_check`,
+            AllowHTTPMethods: []string{"post"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
+    beego.GlobalControllerRouter["eta/eta_api/controllers/data_manage:EdbBusinessController"] = append(beego.GlobalControllerRouter["eta/eta_api/controllers/data_manage:EdbBusinessController"],
+        beego.ControllerComments{
+            Method: "BatchAdd",
+            Router: `/business_data/batch_add`,
+            AllowHTTPMethods: []string{"post"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
+    beego.GlobalControllerRouter["eta/eta_api/controllers/data_manage:EdbBusinessController"] = append(beego.GlobalControllerRouter["eta/eta_api/controllers/data_manage:EdbBusinessController"],
+        beego.ControllerComments{
+            Method: "List",
+            Router: `/business_data/list`,
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
+    beego.GlobalControllerRouter["eta/eta_api/controllers/data_manage:EdbBusinessController"] = append(beego.GlobalControllerRouter["eta/eta_api/controllers/data_manage:EdbBusinessController"],
+        beego.ControllerComments{
+            Method: "NameCheck",
+            Router: `/business_data/name_check`,
+            AllowHTTPMethods: []string{"post"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
+    beego.GlobalControllerRouter["eta/eta_api/controllers/data_manage:EdbBusinessController"] = append(beego.GlobalControllerRouter["eta/eta_api/controllers/data_manage:EdbBusinessController"],
+        beego.ControllerComments{
+            Method: "SourceList",
+            Router: `/business_data/source/list`,
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
     beego.GlobalControllerRouter["eta/eta_api/controllers/data_manage:EdbClassifyController"] = append(beego.GlobalControllerRouter["eta/eta_api/controllers/data_manage:EdbClassifyController"],
         beego.ControllerComments{
             Method: "AddEdbClassify",

+ 1 - 0
routers/router.go

@@ -169,6 +169,7 @@ func init() {
 				&data_manage.ChartThemeController{},
 				&data_manage_permission.DataMangePermissionController{},
 				&data_manage.BloombergDataController{},
+				&data_manage.EdbBusinessController{},
 			),
 		),
 		web.NSNamespace("/my_chart",

+ 25 - 0
services/data/base_edb_lib.go

@@ -472,6 +472,31 @@ func BaseCalculate(param, lang string) (resp *BaseCalculateResp, err error) {
 	return
 }
 
+// AddBaseEdbInfo 新增基础指标
+func AddBaseEdbInfo(addBaseEdbInfoReqStr string, source, subSource int, lang string) (resp *AddPredictEdbDataResponse, err error) {
+	urlStr := ``
+	switch source {
+	case utils.DATA_SOURCE_BUSINESS:
+		urlStr = "business_index/add"
+	default:
+		edbSource := data_manage.EdbSourceIdMap[source]
+		if edbSource != nil {
+			urlStr = edbSource.EdbRefreshMethod
+		}
+	}
+	if urlStr == "" {
+		err = fmt.Errorf(fmt.Sprint("source:", source, ";未实现该指标的刷新接口,请联系管理员"))
+		return
+	}
+	_, resultByte, err := postAddEdbData(addBaseEdbInfoReqStr, urlStr, lang)
+	if err != nil {
+		return
+	}
+	err = json.Unmarshal(resultByte, &resp)
+
+	return
+}
+
 // postRefreshEdbData 刷新指标数据
 func postRefreshEdbData(param map[string]interface{}, urlStr string) (resp *models.BaseResponse, err error) {
 	postUrl := utils.EDB_LIB_URL + urlStr

+ 59 - 0
services/data/base_from_business.go

@@ -0,0 +1,59 @@
+package data
+
+import (
+	"eta/eta_api/models/data_manage"
+	"eta/eta_api/utils"
+	"fmt"
+)
+
+type BusinessIndexSource2EdbReq struct {
+	EdbCode       string
+	EdbName       string
+	Frequency     string
+	Unit          string
+	ClassifyId    int
+	AdminId       int
+	AdminRealName string
+}
+
+// BusinessIndexSource2Edb 新增彭博数据源到指标库
+func BusinessIndexSource2Edb(req BusinessIndexSource2EdbReq, lang string) (edb *data_manage.EdbInfo, err error, errMsg string, skip bool) {
+	if req.EdbCode == "" {
+		err = fmt.Errorf("指标ID为空")
+		return
+	}
+	defer func() {
+		if err != nil {
+			tips := fmt.Sprintf("BusinessIndexSource2Edb新增失败, Err: %s", err.Error())
+			fmt.Println(tips)
+			utils.FileLog.Info(tips)
+		}
+	}()
+	source := utils.DATA_SOURCE_BUSINESS
+
+	// 是否新增过指标
+	exist, e := data_manage.GetEdbInfoByEdbCode(source, req.EdbCode)
+	if e != nil && e.Error() != utils.ErrNoRow() {
+		err = fmt.Errorf("获取指标是否存在失败, err: %s", e.Error())
+		return
+	}
+	if exist != nil {
+		skip = true
+		return
+	}
+
+	// 开始结束时间
+	var startDate, endDate string
+
+	// 新增指标库
+	edbInfo, e, msg, _ := EdbInfoAdd(source, utils.DATA_SUB_SOURCE_EDB, req.ClassifyId, req.EdbCode, req.EdbName, req.Frequency, req.Unit, startDate, endDate, req.AdminId, req.AdminRealName, lang)
+	if e != nil {
+		errMsg = msg
+		err = fmt.Errorf("EdbInfo: 新增指标失败, err: %s", e.Error())
+		return
+	}
+
+	edb = edbInfo
+
+	return
+}

+ 40 - 0
services/data/edb_info.go

@@ -1718,8 +1718,48 @@ func getRefreshEdbInfoListByIds(edbInfoIdList []int) (newBaseEdbInfoArr, newBase
 	return
 }
 
+type AddEdbBaseInfoReq struct {
+	EdbCode         string `description:"指标编码"`
+	EdbName         string `description:"指标名称"`
+	Unit            string `description:"单位"`
+	ClassifyId      int    `description:"所属分类"`
+	SysUserId       int    `description:"用户id"`
+	SysUserRealName string `description:"用户真实名称"`
+}
+
 // EdbInfoAdd 添加指标到指标库
 func EdbInfoAdd(source, subSource, classifyId int, edbCode, edbName, frequency, unit, startDate, endDate string, sysUserId int, sysUserRealName, lang string) (edbInfo *data_manage.EdbInfo, err error, errMsg string, isSendEmail bool) {
+	// 有些指标的添加是走的指标公共服务
+	if source == utils.DATA_SOURCE_BUSINESS {
+		req2 := AddEdbBaseInfoReq{
+			EdbCode:         edbCode,
+			EdbName:         edbName,
+			Unit:            unit,
+			ClassifyId:      classifyId,
+			SysUserId:       sysUserId,
+			SysUserRealName: sysUserRealName,
+		}
+		reqJson, tmpErr := json.Marshal(req2)
+		if tmpErr != nil {
+			err = tmpErr
+			return
+		}
+		respItem, tmpErr := AddBaseEdbInfo(string(reqJson), source, subSource, lang)
+		if tmpErr != nil {
+			errMsg = "添加失败"
+			err = tmpErr
+			return
+		}
+		isSendEmail = respItem.IsSendEmail
+		if respItem.Ret != 200 {
+			errMsg = respItem.Msg
+			err = errors.New(respItem.ErrMsg)
+		} else {
+			edbInfo, err = data_manage.GetEdbInfoById(respItem.Data.EdbInfoId)
+		}
+		return
+	}
+
 	isSendEmail = true
 
 	//判断指标名称是否存在

+ 1 - 0
utils/constants.go

@@ -171,6 +171,7 @@ const (
 	DATA_SOURCE_GFEX                                 = 78       // 广州期货交易所->78
 	DATA_SOURCE_ICPI                                 = 79       // ICPI消费价格指数->79
 	DATA_SOURCE_BLOOMBERG                            = 83       // bloomberg彭博数据
+	DATA_SOURCE_BUSINESS                             = 84       // 来源于外部数据
 )
 
 // 数据刷新频率