|
@@ -5,6 +5,7 @@ import (
|
|
|
"eta/eta_api/models/data_manage"
|
|
|
"eta/eta_api/utils"
|
|
|
"fmt"
|
|
|
+ "strings"
|
|
|
"time"
|
|
|
)
|
|
|
|
|
@@ -94,3 +95,81 @@ func createTerminalCode(source int, sourceName string) (terminalCode string) {
|
|
|
terminalCode = utils.MD5(fmt.Sprintf("%d_%s_%s_%d", source, sourceName, time.Now(), randInt))
|
|
|
return
|
|
|
}
|
|
|
+
|
|
|
+// GetEdbTerminalDirInfo 获取指标的终端信息
|
|
|
+func GetEdbTerminalDirInfo(indexId, source int) (info *data_manage.EdbTerminalDirInfo, err error) {
|
|
|
+ // 查询指标信息
|
|
|
+ var terminalCode, filePath, name, dirPath string
|
|
|
+ switch source {
|
|
|
+ case utils.DATA_SOURCE_MYSTEEL_CHEMICAL:
|
|
|
+ // 查询钢联指标信息
|
|
|
+ indexInfo, e := data_manage.GetBaseFromMysteelChemicalIndexByIndexId(indexId)
|
|
|
+ if e != nil {
|
|
|
+ err = errors.New("获取指标信息失败, Err:" + e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ terminalCode = indexInfo.TerminalCode
|
|
|
+ filePath = indexInfo.MergeFilePath
|
|
|
+ if filePath == "" && indexInfo.FilePath != "" {
|
|
|
+ filePath = indexInfo.FilePath
|
|
|
+ }
|
|
|
+ break
|
|
|
+ case utils.DATA_SOURCE_YS:
|
|
|
+ // 查询有色指标信息
|
|
|
+ indexInfo, e := data_manage.GetBaseFromSmmIndexByIndexId(indexId)
|
|
|
+ if e != nil {
|
|
|
+ err = errors.New("获取指标信息失败, Err:" + e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ terminalCode = indexInfo.TerminalCode
|
|
|
+ filePath = indexInfo.RenameFileName
|
|
|
+ break
|
|
|
+ case utils.DATA_SOURCE_SCI:
|
|
|
+ // 查询SCI指标信息
|
|
|
+ indexInfo, e := data_manage.GetBaseFromSciIndexByIndexId(indexId)
|
|
|
+ if e != nil {
|
|
|
+ err = errors.New("获取指标信息失败, Err:" + e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ terminalCode = indexInfo.TerminalCode
|
|
|
+ filePath = indexInfo.FilePath
|
|
|
+ break
|
|
|
+ default:
|
|
|
+ err = errors.New("不支持其他来源")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ // 查询终端信息
|
|
|
+ if terminalCode == "" {
|
|
|
+ err = errors.New("获取终端信息失败, Err:终端编码为空")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ terminalInfo, err := data_manage.GetEdbTerminalByCode(terminalCode)
|
|
|
+ if err != nil {
|
|
|
+ err = errors.New("获取终端信息失败, Err:" + err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if terminalInfo.Source != source {
|
|
|
+ err = errors.New("获取终端信息失败, Err:指标来源与终端来源不一致")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ name = terminalInfo.Name
|
|
|
+ // 截取最后的文件名称
|
|
|
+ if filePath != "" {
|
|
|
+ // 使用 strings.LastIndex 和切片操作获取文件路径(不包括文件名)
|
|
|
+ lastIndex := strings.LastIndex(filePath, `\`)
|
|
|
+ if lastIndex != -1 {
|
|
|
+ dirPath = filePath[:lastIndex]
|
|
|
+ //fmt.Println("文件路径:", dirPath)
|
|
|
+ fileName := filePath[lastIndex+1:]
|
|
|
+ //fmt.Println("文件名:", fileName)
|
|
|
+ filePath = fileName
|
|
|
+ }
|
|
|
+ }
|
|
|
+ info = &data_manage.EdbTerminalDirInfo{
|
|
|
+ TerminalCode: terminalCode,
|
|
|
+ FilePath: filePath,
|
|
|
+ Name: name,
|
|
|
+ DirPath: dirPath,
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|