|
@@ -1719,29 +1719,39 @@ func getRefreshEdbInfoListByIds(edbInfoIdList []int) (newBaseEdbInfoArr, newBase
|
|
|
}
|
|
|
|
|
|
// EdbInfoAdd 添加指标到指标库
|
|
|
-func EdbInfoAdd(source, subSource, classifyId int, edbCode, edbName, frequency, unit, startDate, endDate string, sysUserId int, sysUserRealName string) (edbInfo *data_manage.EdbInfo, err error, errMsg string, isSendEmail bool) {
|
|
|
+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) {
|
|
|
isSendEmail = true
|
|
|
+
|
|
|
//判断指标名称是否存在
|
|
|
- var condition string
|
|
|
- var pars []interface{}
|
|
|
- //condition += " AND source=? "
|
|
|
- //pars = append(pars, source)
|
|
|
+ {
|
|
|
+ var count int
|
|
|
+ var condition string
|
|
|
+ var pars []interface{}
|
|
|
|
|
|
- condition += " AND edb_name=? "
|
|
|
- pars = append(pars, edbName)
|
|
|
+ //condition += " AND source=? "
|
|
|
+ //pars = append(pars, source)
|
|
|
|
|
|
- count, err := data_manage.GetEdbInfoCountByCondition(condition, pars)
|
|
|
- if err != nil {
|
|
|
- errMsg = "判断指标名称是否存在失败"
|
|
|
- err = errors.New("判断指标名称是否存在失败,Err:" + err.Error())
|
|
|
- return
|
|
|
- }
|
|
|
+ switch lang {
|
|
|
+ case utils.EnLangVersion:
|
|
|
+ condition += " AND edb_name_en = ? "
|
|
|
+ default:
|
|
|
+ condition += " AND edb_name=? "
|
|
|
+ }
|
|
|
+ pars = append(pars, edbName)
|
|
|
|
|
|
- if count > 0 {
|
|
|
- errMsg = "指标名称已存在,请重新填写"
|
|
|
- err = errors.New(errMsg)
|
|
|
- isSendEmail = false
|
|
|
- return
|
|
|
+ count, err = data_manage.GetEdbInfoCountByCondition(condition, pars)
|
|
|
+ if err != nil {
|
|
|
+ errMsg = "判断指标名称是否存在失败"
|
|
|
+ err = errors.New("判断指标名称是否存在失败,Err:" + err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ if count > 0 {
|
|
|
+ errMsg = "指标名称已存在,请重新填写"
|
|
|
+ err = errors.New(errMsg)
|
|
|
+ isSendEmail = false
|
|
|
+ return
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
edbInfo = new(data_manage.EdbInfo)
|
|
@@ -1793,29 +1803,12 @@ func EdbInfoAdd(source, subSource, classifyId int, edbCode, edbName, frequency,
|
|
|
if source == utils.DATA_SOURCE_STOCK_PLANT {
|
|
|
edbType = 2 //计算指标
|
|
|
}
|
|
|
- // todo 如果缓存中的终端信息丢了是否需要调整 从缓存中获取
|
|
|
- serverUrl := ``
|
|
|
- if edbInfo.Source == utils.DATA_SOURCE_WIND {
|
|
|
- windCacheKey := utils.CACHE_WIND_URL + ":" + edbCode
|
|
|
- serverUrl, _ = utils.Rc.RedisString(windCacheKey)
|
|
|
- if serverUrl == `` {
|
|
|
- if len(utils.Hz_Data_WIND_Url_List) >= 1 {
|
|
|
- serverUrl = utils.Hz_Data_WIND_Url_List[len(utils.Hz_Data_WIND_Url_List)-1] //默认是最后一个服务器地址
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- // 获取终端信息
|
|
|
- terminalCodeCacheKey := utils.CACHE_EDB_TERMINAL_CODE_URL + edbCode
|
|
|
- terminalCode, tE := utils.Rc.RedisString(terminalCodeCacheKey)
|
|
|
- if tE != nil {
|
|
|
- utils.FileLog.Info(fmt.Sprintf("从缓存中获取数据源终端信息失败, Err: %s", tE))
|
|
|
- }
|
|
|
- var sourceIndexName string
|
|
|
- if terminalCode == "" {
|
|
|
- terminalCode, sourceIndexName, tE = GetTerminalFromBaseIndex(source, edbCode)
|
|
|
- if tE != nil {
|
|
|
- utils.FileLog.Info(fmt.Sprintf("获取数据源终端信息失败, Err: %s", tE))
|
|
|
- }
|
|
|
+ // 从缓存中获取
|
|
|
+ terminalCode, serverUrl, sourceIndexName, e := GetEdbTerminalCodeBySource(edbInfo.Source, edbInfo.EdbCode, edbInfo.StockCode)
|
|
|
+ if e != nil {
|
|
|
+ errMsg = "获取可以使用的终端地址失败"
|
|
|
+ err = errors.New("获取可以使用的终端地址失败,Err:" + e.Error())
|
|
|
+ return
|
|
|
}
|
|
|
//获取该层级下最大的排序数
|
|
|
maxSort, err := GetEdbClassifyMaxSort(classifyId, 0)
|
|
@@ -1827,9 +1820,11 @@ func EdbInfoAdd(source, subSource, classifyId int, edbCode, edbName, frequency,
|
|
|
|
|
|
edbInfo.EdbCode = edbCode
|
|
|
edbInfo.EdbName = edbName
|
|
|
+ edbInfo.EdbNameEn = edbName
|
|
|
edbInfo.EdbNameSource = edbName
|
|
|
edbInfo.Frequency = frequency
|
|
|
edbInfo.Unit = unit
|
|
|
+ edbInfo.UnitEn = frequency
|
|
|
edbInfo.StartDate = startDate
|
|
|
edbInfo.EndDate = endDate
|
|
|
edbInfo.ClassifyId = classifyId
|
|
@@ -1885,6 +1880,7 @@ func TraceEdbInfoByEdbInfoId(edbInfoId, sysUserId int) (traceEdbInfo data_manage
|
|
|
EdbInfoId: edbInfoId,
|
|
|
EdbInfoType: edbInfo.EdbInfoType,
|
|
|
EdbName: edbInfo.EdbName,
|
|
|
+ EdbNameEn: edbInfo.EdbNameEn,
|
|
|
EdbType: edbInfo.EdbType,
|
|
|
//Source: edbInfo.Source,
|
|
|
UniqueCode: edbInfo.UniqueCode,
|
|
@@ -1969,6 +1965,7 @@ func TraceEdbInfoByEdbInfoIdList(edbInfoIdList []int) (traceEdbInfoList []data_m
|
|
|
EdbInfoId: edbInfo.EdbInfoId,
|
|
|
EdbInfoType: edbInfo.EdbInfoType,
|
|
|
EdbName: edbInfo.EdbName,
|
|
|
+ EdbNameEn: edbInfo.EdbNameEn,
|
|
|
EdbType: edbInfo.EdbType,
|
|
|
//Source: edbInfo.Source,
|
|
|
UniqueCode: edbInfo.UniqueCode,
|
|
@@ -2078,7 +2075,7 @@ func handleTraceEdbInfo(traceEdbInfoResp data_manage.TraceEdbInfoResp, parentEdb
|
|
|
}
|
|
|
|
|
|
//traceEdbInfoResp.EdbName = edbInfo.EdbName
|
|
|
- traceEdbInfoResp.EdbName, traceEdbInfoResp.RuleTitle = getEdbRuleTitle(edbInfo, parentEdbInfo, traceEdbInfoResp.Child, edbInfoMap, edbMappingMap)
|
|
|
+ traceEdbInfoResp.EdbName, traceEdbInfoResp.EdbNameEn, traceEdbInfoResp.RuleTitle, traceEdbInfoResp.RuleTitleEn = getEdbRuleTitle(edbInfo, parentEdbInfo, traceEdbInfoResp.Child, edbInfoMap, edbMappingMap)
|
|
|
|
|
|
if traceEdbInfoResp.Child != nil && len(traceEdbInfoResp.Child) > 0 {
|
|
|
for k, v := range traceEdbInfoResp.Child {
|
|
@@ -2097,9 +2094,11 @@ func handleTraceEdbInfo(traceEdbInfoResp data_manage.TraceEdbInfoResp, parentEdb
|
|
|
}
|
|
|
|
|
|
// getEdbRule 获取规则名称
|
|
|
-func getEdbRuleTitle(edbInfo, parentEdbInfo *data_manage.EdbInfo, childList []data_manage.TraceEdbInfoResp, edbInfoMap map[int]*data_manage.EdbInfo, edbMappingMap map[int][]*data_manage.EdbInfoCalculateMappingInfo) (edbName, ruleTitle string) {
|
|
|
+func getEdbRuleTitle(edbInfo, parentEdbInfo *data_manage.EdbInfo, childList []data_manage.TraceEdbInfoResp, edbInfoMap map[int]*data_manage.EdbInfo, edbMappingMap map[int][]*data_manage.EdbInfoCalculateMappingInfo) (edbName, edbNameEn, ruleTitle, ruleTitleEn string) {
|
|
|
edbName = edbInfo.EdbName
|
|
|
+ edbNameEn = edbInfo.EdbNameEn
|
|
|
ruleTitle = `来源于` + edbInfo.SourceName
|
|
|
+ ruleTitleEn = `Source From: ` + edbInfo.SourceName
|
|
|
|
|
|
if parentEdbInfo != nil {
|
|
|
edbMappingList, ok := edbMappingMap[parentEdbInfo.EdbInfoId]
|
|
@@ -2112,6 +2111,7 @@ func getEdbRuleTitle(edbInfo, parentEdbInfo *data_manage.EdbInfo, childList []da
|
|
|
for _, v := range edbMappingList {
|
|
|
if v.FromEdbInfoId == edbInfo.EdbInfoId {
|
|
|
edbName = fmt.Sprintf("%s(%s)", edbInfo.EdbName, v.FromTag)
|
|
|
+ edbName = fmt.Sprintf("%s(%s)", edbInfo.EdbNameEn, v.FromTag)
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -2119,12 +2119,16 @@ func getEdbRuleTitle(edbInfo, parentEdbInfo *data_manage.EdbInfo, childList []da
|
|
|
for _, v := range edbMappingList {
|
|
|
if v.FromEdbInfoId == edbInfo.EdbInfoId {
|
|
|
tmpName := ``
|
|
|
+ tmpNameEn := ``
|
|
|
if v.FromTag == `A` {
|
|
|
tmpName = `拼接日期前`
|
|
|
+ tmpNameEn = `Before Concatenation Date:`
|
|
|
} else if v.FromTag == `B` {
|
|
|
tmpName = `拼接日期后`
|
|
|
+ tmpNameEn = `After Concatenation Date:`
|
|
|
}
|
|
|
edbName = fmt.Sprintf("%s(%s)", edbInfo.EdbName, tmpName)
|
|
|
+ edbNameEn = fmt.Sprintf("%s(%s)", edbInfo.EdbNameEn, tmpNameEn)
|
|
|
}
|
|
|
}
|
|
|
case utils.DATA_SOURCE_CALCULATE_NHCC, utils.DATA_SOURCE_PREDICT_CALCULATE_NHCC: //计算指标(拟合残差)
|
|
@@ -2132,12 +2136,16 @@ func getEdbRuleTitle(edbInfo, parentEdbInfo *data_manage.EdbInfo, childList []da
|
|
|
//(需对上游指标+自变量,领先10天/因变量)
|
|
|
if v.FromEdbInfoId == edbInfo.EdbInfoId {
|
|
|
tmpName := ``
|
|
|
+ tmpNameEn := ``
|
|
|
if v.FromTag == `A` {
|
|
|
tmpName = fmt.Sprintf(`自变量,领先%d天`, v.MoveValue)
|
|
|
+ tmpNameEn = fmt.Sprintf(`Independent Variable, Lead %d Days:`, v.MoveValue)
|
|
|
} else if v.FromTag == `B` {
|
|
|
tmpName = `因变量`
|
|
|
+ tmpNameEn = `Dependent Variable`
|
|
|
}
|
|
|
edbName = fmt.Sprintf("%s(%s)", edbInfo.EdbName, tmpName)
|
|
|
+ edbNameEn = fmt.Sprintf("%s(%s)", edbInfo.EdbNameEn, tmpNameEn)
|
|
|
}
|
|
|
}
|
|
|
case utils.DATA_SOURCE_CALCULATE_CORRELATION: // 滚动相关性
|
|
@@ -2164,22 +2172,31 @@ func getEdbRuleTitle(edbInfo, parentEdbInfo *data_manage.EdbInfo, childList []da
|
|
|
ruleTitle = "=" + edbInfo.CalculateFormula
|
|
|
case utils.DATA_SOURCE_CALCULATE_LJZZY, utils.DATA_SOURCE_PREDICT_CALCULATE_LJZZY:
|
|
|
ruleTitle = `累计转月值计算`
|
|
|
+ ruleTitleEn = `Cumulative to Monthly Calculation`
|
|
|
case utils.DATA_SOURCE_CALCULATE_TBZ, utils.DATA_SOURCE_PREDICT_CALCULATE_TBZ:
|
|
|
ruleTitle = `同比值计算`
|
|
|
+ ruleTitleEn = `Year-on-Year Value Calculation`
|
|
|
case utils.DATA_SOURCE_CALCULATE_TCZ, utils.DATA_SOURCE_PREDICT_CALCULATE_TCZ:
|
|
|
ruleTitle = `同差值计算`
|
|
|
+ ruleTitleEn = `Yearly Difference Calculation`
|
|
|
case utils.DATA_SOURCE_CALCULATE_NSZYDPJJS, utils.DATA_SOURCE_PREDICT_CALCULATE_NSZYDPJJS:
|
|
|
ruleTitle = fmt.Sprintf("N数值移动均值计算(N=%s)", edbInfo.CalculateFormula)
|
|
|
+ ruleTitleEn = fmt.Sprintf("N-Value Moving Average Calculation(N=%s)", edbInfo.CalculateFormula)
|
|
|
case utils.DATA_SOURCE_CALCULATE_HBZ, utils.DATA_SOURCE_PREDICT_CALCULATE_HBZ:
|
|
|
ruleTitle = fmt.Sprintf("N数值环比值计算(N=%s)", edbInfo.CalculateFormula)
|
|
|
+ ruleTitleEn = fmt.Sprintf("N-Value Sequential Comparison Calculation(N=%s)", edbInfo.CalculateFormula)
|
|
|
case utils.DATA_SOURCE_CALCULATE_HCZ, utils.DATA_SOURCE_PREDICT_CALCULATE_HCZ:
|
|
|
ruleTitle = fmt.Sprintf("N数值环差值计算(N=%s)", edbInfo.CalculateFormula)
|
|
|
+ ruleTitleEn = fmt.Sprintf("N-Value Sequential Difference Calculation(N=%s)", edbInfo.CalculateFormula)
|
|
|
case utils.DATA_SOURCE_CALCULATE_TIME_SHIFT, utils.DATA_SOURCE_PREDICT_CALCULATE_TIME_SHIFT:
|
|
|
moveType := `领先`
|
|
|
+ moveTypeEn := `Lead`
|
|
|
if edbInfo.MoveType == 2 {
|
|
|
moveType = "滞后"
|
|
|
+ moveTypeEn = `Lag`
|
|
|
}
|
|
|
ruleTitle = fmt.Sprintf("时间移位计算(%s%s%s)", moveType, edbInfo.CalculateFormula, edbInfo.MoveFrequency)
|
|
|
+ ruleTitleEn = fmt.Sprintf("Time Shift Calculation(%s%s%s)", moveTypeEn, edbInfo.CalculateFormula, edbInfo.MoveFrequency)
|
|
|
case utils.DATA_SOURCE_CALCULATE_BP, utils.DATA_SOURCE_PREDICT_CALCULATE_BP: // 变频
|
|
|
childFrequency := ``
|
|
|
if len(childList) > 0 {
|
|
@@ -2189,14 +2206,19 @@ func getEdbRuleTitle(edbInfo, parentEdbInfo *data_manage.EdbInfo, childList []da
|
|
|
|
|
|
}
|
|
|
ruleTitle = fmt.Sprintf("升频计算(%s转%s)", childFrequency, edbInfo.Frequency)
|
|
|
+ ruleTitleEn = fmt.Sprintf("Upsampling Calculation(%s转%s)", childFrequency, edbInfo.Frequency)
|
|
|
case utils.DATA_SOURCE_CALCULATE_ZJPJ, utils.DATA_SOURCE_PREDICT_CALCULATE_ZJPJ: // 直接拼接
|
|
|
ruleTitle = fmt.Sprintf("直接拼接计算(%s)", edbInfo.CalculateFormula)
|
|
|
+ ruleTitleEn = fmt.Sprintf("Direct Concatenation Calculation(%s)", edbInfo.CalculateFormula)
|
|
|
case utils.DATA_SOURCE_CALCULATE_LJZTBPJ, utils.DATA_SOURCE_PREDICT_CALCULATE_LJZTBPJ: // 累计值同比拼
|
|
|
ruleTitle = fmt.Sprintf("累计值同比值拼接计算(%s)", edbInfo.CalculateFormula)
|
|
|
+ ruleTitleEn = fmt.Sprintf("Cumulative Year-on-Year Concatenation Calculation(%s)", edbInfo.CalculateFormula)
|
|
|
case utils.DATA_SOURCE_PYTHON:
|
|
|
ruleTitle = `代码运算`
|
|
|
+ ruleTitleEn = `Code Computation`
|
|
|
case utils.DATA_SOURCE_CALCULATE_CJJX, utils.DATA_SOURCE_PREDICT_CALCULATE_CJJX:
|
|
|
ruleTitle = fmt.Sprintf("超季节性计算(N=%s,%s)", edbInfo.CalculateFormula, edbInfo.Calendar)
|
|
|
+ ruleTitleEn = fmt.Sprintf("Super Seasonality Calculation(N=%s,%s)", edbInfo.CalculateFormula, edbInfo.Calendar)
|
|
|
case utils.DATA_SOURCE_CALCULATE_NHCC, utils.DATA_SOURCE_PREDICT_CALCULATE_NHCC: //计算指标(拟合残差)
|
|
|
var startDate, endDate string
|
|
|
dateList := strings.Split(edbInfo.CalculateFormula, ",")
|
|
@@ -2205,10 +2227,13 @@ func getEdbRuleTitle(edbInfo, parentEdbInfo *data_manage.EdbInfo, childList []da
|
|
|
endDate = dateList[1]
|
|
|
}
|
|
|
ruleTitle = fmt.Sprintf("拟合残差计算(%s至%s)", startDate, endDate)
|
|
|
+ ruleTitleEn = fmt.Sprintf("Fit Residual Calculation(%s至%s)", startDate, endDate)
|
|
|
case utils.DATA_SOURCE_CALCULATE_ADJUST:
|
|
|
ruleTitle = `数据调整`
|
|
|
+ ruleTitleEn = `Data Adjustment`
|
|
|
case utils.DATA_SOURCE_CALCULATE_NH, utils.DATA_SOURCE_PREDICT_CALCULATE_NH:
|
|
|
ruleTitle = `年化计算`
|
|
|
+ ruleTitleEn = `Annualization Calculation`
|
|
|
case utils.DATA_SOURCE_CALCULATE_KSZS, utils.DATA_SOURCE_PREDICT_CALCULATE_KSZS: // 扩散指数->53
|
|
|
type KszsConfig struct {
|
|
|
DateType int `description:"扩散指标日期;1:全部指标日期并集;2:部分指标日期并集"`
|
|
@@ -2264,8 +2289,10 @@ func getEdbRuleTitle(edbInfo, parentEdbInfo *data_manage.EdbInfo, childList []da
|
|
|
}
|
|
|
}
|
|
|
ruleTitle = fmt.Sprintf("扩散指数计算(%s至%s)", startDate.Format(utils.FormatDate), endDate.Format(utils.FormatDate))
|
|
|
+ ruleTitleEn = fmt.Sprintf("Diffusion Index Calculation(%s to %s)", startDate.Format(utils.FormatDate), endDate.Format(utils.FormatDate))
|
|
|
case utils.DATA_SOURCE_STOCK_PLANT:
|
|
|
ruleTitle = `来源于装置分析`
|
|
|
+ ruleTitleEn = `Derived from Plant Analysis`
|
|
|
case utils.DATA_SOURCE_CALCULATE_CORRELATION:
|
|
|
type EdbCalculateFormula struct {
|
|
|
BaseCalculateValue int `description:"基础计算窗口"`
|
|
@@ -2281,6 +2308,7 @@ func getEdbRuleTitle(edbInfo, parentEdbInfo *data_manage.EdbInfo, childList []da
|
|
|
return
|
|
|
}
|
|
|
ruleTitle = fmt.Sprintf("滚动相关性(计算窗口%d%s,B领先A%d%s)", correlationConf.CalculateValue, correlationConf.CalculateUnit, correlationConf.LeadValue, correlationConf.LeadUnit)
|
|
|
+ ruleTitleEn = fmt.Sprintf("Rolling Correlation (Calculation Window %d%s, B Leads A %d%s)", correlationConf.CalculateValue, correlationConf.CalculateUnit, correlationConf.LeadValue, correlationConf.LeadUnit)
|
|
|
case utils.DATA_SOURCE_CALCULATE_JP, utils.DATA_SOURCE_PREDICT_CALCULATE_JP:
|
|
|
childFrequency := ``
|
|
|
if len(childList) > 0 {
|
|
@@ -2290,8 +2318,10 @@ func getEdbRuleTitle(edbInfo, parentEdbInfo *data_manage.EdbInfo, childList []da
|
|
|
|
|
|
}
|
|
|
ruleTitle = fmt.Sprintf("降频计算(%s转%s,%s)", childFrequency, edbInfo.Frequency, edbInfo.CalculateFormula)
|
|
|
+ ruleTitleEn = fmt.Sprintf("Downsampling Calculation(%s to %s,%s)", childFrequency, edbInfo.Frequency, edbInfo.CalculateFormula)
|
|
|
case utils.DATA_SOURCE_CALCULATE_STANDARD_DEVIATION:
|
|
|
ruleTitle = fmt.Sprintf("标准差(滚动%s期)", edbInfo.CalculateFormula)
|
|
|
+ ruleTitleEn = fmt.Sprintf("Standard Deviation (Rolling %s Periods)", edbInfo.CalculateFormula)
|
|
|
case utils.DATA_SOURCE_CALCULATE_PERCENTILE, utils.DATA_SOURCE_PREDICT_CALCULATE_PERCENTILE:
|
|
|
type TempCalculate struct {
|
|
|
CalculateValue int `description:"计算窗口"`
|
|
@@ -2302,8 +2332,10 @@ func getEdbRuleTitle(edbInfo, parentEdbInfo *data_manage.EdbInfo, childList []da
|
|
|
return
|
|
|
}
|
|
|
ruleTitle = fmt.Sprintf("百分位(时间长度%d%s)", cf.CalculateValue, cf.CalculateUnit)
|
|
|
+ ruleTitle = fmt.Sprintf("Percentile (Time Length %d%s)", cf.CalculateValue, cf.CalculateUnit)
|
|
|
case utils.DATA_SOURCE_CALCULATE_ZSXY, utils.DATA_SOURCE_PREDICT_CALCULATE_ZSXY:
|
|
|
ruleTitle = `指数修匀计算`
|
|
|
+ ruleTitle = `Index Smoothing Calculation`
|
|
|
}
|
|
|
|
|
|
return
|
|
@@ -2725,3 +2757,113 @@ func EdbInfoSmmApiAdd(item *data_manage.EdbInfo) (edbInfo *data_manage.EdbInfo,
|
|
|
AddOrEditEdbInfoToEs(int(edbInfoId))
|
|
|
return
|
|
|
}
|
|
|
+
|
|
|
+// GetEdbTerminal 获取终端信息
|
|
|
+func GetEdbTerminal(source int, oldTerminalCode string) (edbTerminal *data_manage.EdbTerminal, err error) {
|
|
|
+ if source == utils.DATA_SOURCE_WIND && oldTerminalCode == "" {
|
|
|
+ tmpConfig := new(data_manage.EdbConfig)
|
|
|
+ tmpConfig, err = data_manage.GetConfigDetailByCode("wind_terminal_code")
|
|
|
+ if err != nil && err.Error() != utils.ErrNoRow() {
|
|
|
+ err = errors.New("获取配置的wind地址失败,err:" + err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ err = nil
|
|
|
+ if tmpConfig != nil {
|
|
|
+ oldTerminalCode = tmpConfig.ConfigValue
|
|
|
+ //return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if oldTerminalCode != "" {
|
|
|
+ edbTerminal, err = data_manage.GetEdbTerminalByCode(oldTerminalCode)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // 配置中没有的话,那么就从分组获取,
|
|
|
+ list, err := data_manage.GetEdbCountGroupByTerminal(source)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ //windUrlNum := 0
|
|
|
+
|
|
|
+ //获取对应的配置url
|
|
|
+ terminalNumMap := make(map[string]int)
|
|
|
+ for _, v := range list {
|
|
|
+ terminalNumMap[v.TerminalCode] = v.Total
|
|
|
+ }
|
|
|
+
|
|
|
+ terminalList, err := data_manage.GetEdbTerminalListBySource(source)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if len(terminalList) == 0 {
|
|
|
+ err = errors.New("终端地址未配置")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ num := 0
|
|
|
+ for _, v := range terminalList {
|
|
|
+ tmpNum := terminalNumMap[v.TerminalCode]
|
|
|
+ if edbTerminal == nil {
|
|
|
+ edbTerminal = v
|
|
|
+ num = tmpNum
|
|
|
+ } else if tmpNum < num {
|
|
|
+ edbTerminal = v
|
|
|
+ num = tmpNum
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if edbTerminal == nil {
|
|
|
+ err = errors.New("获取配置的终端地址失败")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ /*if edbTerminal != nil {
|
|
|
+ windUrl = edbTerminal.ServerUrl
|
|
|
+ terminalCode = edbTerminal.TerminalCode
|
|
|
+ }*/
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+func GetEdbTerminalCodeBySource(source int, edbCode, stockCode string) (terminalCode, serverUrl, sourceIndexName string, err error) {
|
|
|
+ var e error
|
|
|
+ if stockCode != "" {
|
|
|
+ terminalCodeCacheKey := utils.CACHE_EDB_TERMINAL_CODE_URL + stockCode
|
|
|
+ terminalCode, e = utils.Rc.RedisString(terminalCodeCacheKey)
|
|
|
+ if e != nil {
|
|
|
+ utils.FileLog.Info(fmt.Sprintf("从缓存中获取数据源终端信息失败, Err: %s", e))
|
|
|
+ }
|
|
|
+
|
|
|
+ terminalInfo, e := GetEdbTerminal(source, terminalCode)
|
|
|
+ if e != nil {
|
|
|
+ err = errors.New("获取可以使用的终端失败,Err:" + e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ serverUrl = terminalInfo.ServerUrl
|
|
|
+ terminalCode = terminalInfo.TerminalCode
|
|
|
+ return
|
|
|
+ }
|
|
|
+ // 获取终端信息
|
|
|
+ terminalCodeCacheKey := utils.CACHE_EDB_TERMINAL_CODE_URL + edbCode
|
|
|
+ terminalCode, tE := utils.Rc.RedisString(terminalCodeCacheKey)
|
|
|
+ if tE != nil {
|
|
|
+ utils.FileLog.Info(fmt.Sprintf("从缓存中获取数据源终端信息失败, Err: %s", tE))
|
|
|
+ }
|
|
|
+ var terminalCodeOrigin string
|
|
|
+ terminalCodeOrigin, sourceIndexName, tE = GetTerminalFromBaseIndex(source, edbCode)
|
|
|
+ if tE != nil {
|
|
|
+ utils.FileLog.Info(fmt.Sprintf("获取数据源终端信息失败, Err: %s", tE))
|
|
|
+ }
|
|
|
+ if terminalCodeOrigin != "" {
|
|
|
+ terminalCode = terminalCodeOrigin
|
|
|
+ }
|
|
|
+ if source == utils.DATA_SOURCE_WIND || source == utils.DATA_SOURCE_THS {
|
|
|
+ terminalInfo, e := GetEdbTerminal(source, terminalCode)
|
|
|
+ if e != nil {
|
|
|
+ err = errors.New("获取可以使用的终端失败,Err:" + e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ serverUrl = terminalInfo.ServerUrl
|
|
|
+ terminalCode = terminalInfo.TerminalCode
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|