Browse Source

Merge branch 'ETA_1.4.4'

zwxi 1 year ago
parent
commit
71e7c4c40f

+ 247 - 126
controllers/data_manage/edb_info.go

@@ -161,46 +161,79 @@ func (this *EdbInfoController) EdbInfoSearch() {
 
 		searchItem := new(data_manage.EdbInfoSearch)
 		if source == utils.DATA_SOURCE_THS {
-			dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, utils.DATA_SOURCE_THS, subSource, utils.EDB_DATA_LIMIT)
-			if err != nil && err.Error() != utils.ErrNoRow() {
-				br.Msg = "获取失败"
-				br.ErrMsg = "获取Ths已存在信息失败,Err:" + err.Error()
-				return
-			}
-
-			fmt.Println("ths len:", len(dataItems))
-			if len(dataItems) > 0 {
-				fmt.Println("ths data exist")
-				searchItem.EdbCode = edbCode
-				minDate, maxDate, err := data_manage.GetEdbDataThsMaxOrMinDate(edbCode)
-				if err != nil {
+			fmt.Println("subSource:", subSource)
+			if subSource == utils.DATA_SUB_SOURCE_EDB {
+				dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, utils.DATA_SOURCE_THS, subSource, utils.EDB_DATA_LIMIT)
+				if err != nil && err.Error() != utils.ErrNoRow() {
 					br.Msg = "获取失败"
-					br.ErrMsg = "获取Ths日期信息失败,Err:" + err.Error()
+					br.ErrMsg = "获取Ths已存在信息失败,Err:" + err.Error()
 					return
 				}
-				searchItem.DataList = dataItems
-				searchItem.StartDate = minDate
-				searchItem.EndDate = maxDate
-			} else {
-				//endDate := dateNow.AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDate)
-				//searchItem, err = data.GetEdbDataByThs(edbCode, startDate, endDate)
-				//if err != nil {
-				//	br.Msg = "获取失败"
-				//	br.ErrMsg = "获取失败,Err:" + err.Error()
-				//	return
-				//}
-				respItem, err := data.AddEdbData(source, edbCode)
+
+				fmt.Println("ths len:", len(dataItems))
+				if len(dataItems) > 0 {
+					fmt.Println("ths data exist")
+					searchItem.EdbCode = edbCode
+					minDate, maxDate, err := data_manage.GetEdbDataThsMaxOrMinDate(edbCode)
+					if err != nil {
+						br.Msg = "获取失败"
+						br.ErrMsg = "获取Ths日期信息失败,Err:" + err.Error()
+						return
+					}
+					searchItem.DataList = dataItems
+					searchItem.StartDate = minDate
+					searchItem.EndDate = maxDate
+				} else {
+					//endDate := dateNow.AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDate)
+					//searchItem, err = data.GetEdbDataByThs(edbCode, startDate, endDate)
+					//if err != nil {
+					//	br.Msg = "获取失败"
+					//	br.ErrMsg = "获取失败,Err:" + err.Error()
+					//	return
+					//}
+					respItem, err := data.AddEdbData(source, edbCode)
+					if err != nil {
+						br.Msg = "获取失败"
+						br.ErrMsg = "获取失败,Err:" + err.Error()
+						return
+					}
+					if respItem.Ret != 200 {
+						br.Msg = "未搜索到该指标"
+						br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
+						return
+					}
+					isAdd = true
+				}
+			} else if subSource == utils.DATA_SUB_SOURCE_DATE {
+				if stockCode == "" {
+					br.Msg = "请输入证券代码"
+					return
+				}
+				if edbCode == "" {
+					br.Msg = "请输入指标代码"
+					return
+				}
+				respItem, err := data.AddEdbDataThsDs(source, stockCode, edbCode)
 				if err != nil {
 					br.Msg = "获取失败"
 					br.ErrMsg = "获取失败,Err:" + err.Error()
 					return
 				}
 				if respItem.Ret != 200 {
-					br.Msg = "未搜索到该指标"
+					if respItem.Ret == 421 {
+						br.Msg = "该渠道已超过添加上限"
+					} else if respItem.Ret == 4052 {
+						br.Msg = "该指标已下架"
+					} else {
+						br.Msg = "未搜索到该指标"
+					}
 					br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
 					return
 				}
 				isAdd = true
+			} else {
+				br.Msg = "无效的渠道来源"
+				return
 			}
 		} else if source == utils.DATA_SOURCE_WIND {
 			fmt.Println("subSource:", subSource)
@@ -1664,87 +1697,113 @@ func (this *EdbInfoController) EdbInfoSearch() {
 		}
 		if isAdd {
 			if subSource == utils.DATA_SUB_SOURCE_DATE {
-				//wsdData := windWsdRespItem.Data
-				//var buf bytes.Buffer
-				//// 创建一个encoder并指定目标为buf
-				//enc := gob.NewEncoder(&buf)
-				//
-				//// 将data编码到buf中
-				//err = enc.Encode(wsdData)
-				//if err != nil {
-				//	br.Msg = "获取失败"
-				//	br.ErrMsg = "获取数据失败,wind wsd encoding GOB Err:" + err.Error()
-				//	return
-				//}
-				//
-				//wsdDataMap := make(map[string]map[string]interface{})
-				//err = json.Unmarshal(buf.Bytes(), &wsdDataMap)
-				//if err != nil {
-				//	br.Msg = "获取失败"
-				//	br.ErrMsg = "获取数据失败,wind wsd json.Unmarshal Err:" + err.Error()
-				//	return
-				//}
-				//
-				//stockList := make([]*data_manage.StockInfo, 0)
-				//
-				//dataList := make([]*data_manage.EdbInfoSearchData, 0)
-				//for wk, wv := range wsdDataMap {
-				//	for vk, vv := range wv {
-				//		wkInt, err := strconv.ParseInt(wk, 10, 64)
-				//		if err != nil {
-				//			br.Msg = "获取失败"
-				//			br.ErrMsg = "获取数据失败,转换日期类型失败 Err:" + err.Error()
-				//			return
-				//		}
-				//
-				//		vk = strings.ToLower(vk)
-				//		wkInt = wkInt / 1000
-				//		t := time.Unix(wkInt, 0)
-				//		dateTime := t.Format(utils.FormatDate)
-				//		//saveVal := utils.SubFloatToString(val, 20)
-				//		if vv == nil {
-				//			continue
-				//		}
-				//		var saveVal string
-				//		switch vt := vv.(type) {
-				//		case int:
-				//			saveVal = strconv.Itoa(vt)
-				//		case float64:
-				//			saveVal = utils.SubFloatToFloatStr(vt, 20)
-				//		case string:
-				//			saveVal = vt
-				//		}
-				//
-				//		dataItem := new(data_manage.EdbInfoSearchData)
-				//		dataItem.Value = saveVal
-				//		dataItem.DataTime = dateTime
-				//		dataList = append(dataList, dataItem)
-				//		if len(dataList) >= 10 {
-				//			break
-				//		}
-				//	}
-				//}
-				//searchItem.StockList = stockList
-
-				stockList := make([]*data_manage.StockInfo, 0)
-				edbCodeArr := strings.Split(edbCode, ",")
-				for _, v := range edbCodeArr {
-					indexCode := utils.WindDbWsd + stockCode + v
+				if source == utils.DATA_SOURCE_WIND {
+					//wsdData := windWsdRespItem.Data
+					//var buf bytes.Buffer
+					//// 创建一个encoder并指定目标为buf
+					//enc := gob.NewEncoder(&buf)
+					//
+					//// 将data编码到buf中
+					//err = enc.Encode(wsdData)
+					//if err != nil {
+					//	br.Msg = "获取失败"
+					//	br.ErrMsg = "获取数据失败,wind wsd encoding GOB Err:" + err.Error()
+					//	return
+					//}
+					//
+					//wsdDataMap := make(map[string]map[string]interface{})
+					//err = json.Unmarshal(buf.Bytes(), &wsdDataMap)
+					//if err != nil {
+					//	br.Msg = "获取失败"
+					//	br.ErrMsg = "获取数据失败,wind wsd json.Unmarshal Err:" + err.Error()
+					//	return
+					//}
+					//
+					//stockList := make([]*data_manage.StockInfo, 0)
+					//
+					//dataList := make([]*data_manage.EdbInfoSearchData, 0)
+					//for wk, wv := range wsdDataMap {
+					//	for vk, vv := range wv {
+					//		wkInt, err := strconv.ParseInt(wk, 10, 64)
+					//		if err != nil {
+					//			br.Msg = "获取失败"
+					//			br.ErrMsg = "获取数据失败,转换日期类型失败 Err:" + err.Error()
+					//			return
+					//		}
+					//
+					//		vk = strings.ToLower(vk)
+					//		wkInt = wkInt / 1000
+					//		t := time.Unix(wkInt, 0)
+					//		dateTime := t.Format(utils.FormatDate)
+					//		//saveVal := utils.SubFloatToString(val, 20)
+					//		if vv == nil {
+					//			continue
+					//		}
+					//		var saveVal string
+					//		switch vt := vv.(type) {
+					//		case int:
+					//			saveVal = strconv.Itoa(vt)
+					//		case float64:
+					//			saveVal = utils.SubFloatToFloatStr(vt, 20)
+					//		case string:
+					//			saveVal = vt
+					//		}
+					//
+					//		dataItem := new(data_manage.EdbInfoSearchData)
+					//		dataItem.Value = saveVal
+					//		dataItem.DataTime = dateTime
+					//		dataList = append(dataList, dataItem)
+					//		if len(dataList) >= 10 {
+					//			break
+					//		}
+					//	}
+					//}
+					//searchItem.StockList = stockList
+
+					stockList := make([]*data_manage.StockInfo, 0)
+					edbCodeArr := strings.Split(edbCode, ",")
+					for _, v := range edbCodeArr {
+						indexCode := utils.WindDbWsd + stockCode + v
+
+						dataList, err := data_manage.GetEdbDataAllByEdbCodeAndSubSource(indexCode, source, utils.DATA_SUB_SOURCE_DATE, utils.EDB_DATA_LIMIT)
+						if err != nil && err.Error() != utils.ErrNoRow() {
+							br.Msg = "获取失败"
+							br.ErrMsg = "获取数据失败,GetEdbDataAllByEdbCode Err:" + err.Error()
+							return
+						}
 
-					dataList, err := data_manage.GetEdbDataAllByEdbCodeAndSubSource(indexCode, source, utils.DATA_SUB_SOURCE_DATE, utils.EDB_DATA_LIMIT)
-					if err != nil && err.Error() != utils.ErrNoRow() {
-						br.Msg = "获取失败"
-						br.ErrMsg = "获取数据失败,GetEdbDataAllByEdbCode Err:" + err.Error()
-						return
+						stockInfo := new(data_manage.StockInfo)
+						stockInfo.StockCode = stockCode
+						stockInfo.EdbCode = v
+						stockInfo.DataList = dataList
+						stockList = append(stockList, stockInfo)
 					}
+					searchItem.StockList = stockList
+				} else if source == utils.DATA_SOURCE_THS {
+					stockList := make([]*data_manage.StockInfo, 0)
+					edbCodeArr := strings.Split(edbCode, ",")
+					for _, v := range edbCodeArr {
+						indexCode := utils.ThsDs + stockCode + v
+
+						dataList, err := data_manage.GetEdbDataAllByEdbCodeAndSubSource(indexCode, source, utils.DATA_SUB_SOURCE_DATE, utils.EDB_DATA_LIMIT)
+						if err != nil && err.Error() != utils.ErrNoRow() {
+							br.Msg = "获取失败"
+							br.ErrMsg = "获取数据失败,GetEdbDataAllByEdbCode Err:" + err.Error()
+							return
+						}
 
-					stockInfo := new(data_manage.StockInfo)
-					stockInfo.StockCode = stockCode
-					stockInfo.EdbCode = v
-					stockInfo.DataList = dataList
-					stockList = append(stockList, stockInfo)
+						stockInfo := new(data_manage.StockInfo)
+						stockInfo.StockCode = stockCode
+						stockInfo.EdbCode = v
+						stockInfo.DataList = dataList
+						stockList = append(stockList, stockInfo)
+					}
+					searchItem.StockList = stockList
+				} else {
+					br.Msg = "来源错误"
+					br.ErrMsg = "来源错误"
+					return
 				}
-				searchItem.StockList = stockList
 			} else {
 				dataList, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, subSource, utils.EDB_DATA_LIMIT)
 				if err != nil && err.Error() != utils.ErrNoRow() {
@@ -1901,20 +1960,41 @@ func (this *EdbInfoController) EdbInfoList() {
 	dataPars = append(dataPars, edbInfoItem.EdbInfoId)
 
 	if edbInfoItem.SubSource == utils.DATA_SUB_SOURCE_DATE {
-		dataCount, err := data_manage.GetEdbWsdDataCountByCondition(dataCondition, dataPars, edbInfoItem.Source)
-		if err != nil && err.Error() != utils.ErrNoRow() {
-			br.Msg = "获取指标信息失败"
-			br.ErrMsg = "获取指标数据总数失败,Err:" + err.Error()
-			return
-		}
-		page = paging.GetPaging(currentIndex, pageSize, dataCount)
-		dataList, err := data_manage.GetEdbWsdDataListByCondition(dataCondition, dataPars, edbInfoItem.Source, pageSize, startSize)
-		if err != nil {
-			br.Msg = "获取指标信息失败"
-			br.ErrMsg = "获取指标数据失败,Err:" + err.Error()
+		if edbInfoItem.Source == utils.DATA_SOURCE_WIND {
+			dataCount, err := data_manage.GetEdbWsdDataCountByCondition(dataCondition, dataPars, edbInfoItem.Source)
+			if err != nil && err.Error() != utils.ErrNoRow() {
+				br.Msg = "获取指标信息失败"
+				br.ErrMsg = "获取指标数据总数失败,Err:" + err.Error()
+				return
+			}
+			page = paging.GetPaging(currentIndex, pageSize, dataCount)
+			dataList, err := data_manage.GetEdbWsdDataListByCondition(dataCondition, dataPars, edbInfoItem.Source, pageSize, startSize)
+			if err != nil {
+				br.Msg = "获取指标信息失败"
+				br.ErrMsg = "获取指标数据失败,Err:" + err.Error()
+				return
+			}
+			edbInfoItem.DataList = dataList
+		} else if edbInfoItem.Source == utils.DATA_SOURCE_THS {
+			dataCount, err := data_manage.GetTHsDsDataCountByCondition(dataCondition, dataPars, edbInfoItem.Source)
+			if err != nil && err.Error() != utils.ErrNoRow() {
+				br.Msg = "获取指标信息失败"
+				br.ErrMsg = "获取指标数据总数失败,Err:" + err.Error()
+				return
+			}
+			page = paging.GetPaging(currentIndex, pageSize, dataCount)
+			dataList, err := data_manage.GetThsDsDataListByCondition(dataCondition, dataPars, edbInfoItem.Source, pageSize, startSize)
+			if err != nil {
+				br.Msg = "获取指标信息失败"
+				br.ErrMsg = "获取指标数据失败,Err:" + err.Error()
+				return
+			}
+			edbInfoItem.DataList = dataList
+		} else {
+			br.Msg = "指标数据源id错误"
+			br.ErrMsg = "指标数据源id错误"
 			return
 		}
-		edbInfoItem.DataList = dataList
 	} else {
 		dataCount, err := data_manage.GetEdbDataCountByCondition(dataCondition, dataPars, edbInfoItem.Source, edbInfoItem.SubSource)
 		if err != nil && err.Error() != utils.ErrNoRow() {
@@ -5027,7 +5107,7 @@ func (this *EdbInfoController) EdbInfoExistCheck() {
 		return
 	}
 
-	if source != utils.DATA_SOURCE_WIND {
+	if source != utils.DATA_SOURCE_WIND && source != utils.DATA_SOURCE_THS {
 		br.Msg = "无效的数据来源"
 		return
 	}
@@ -5040,9 +5120,19 @@ func (this *EdbInfoController) EdbInfoExistCheck() {
 	edbCodeArr := strings.Split(edbCode, ",")
 	stockCodeArr := strings.Split(stockCode, ",")
 
+	var prefix string
+	if source == utils.DATA_SOURCE_WIND {
+		prefix = utils.WindDbWsd
+	} else if source == utils.DATA_SOURCE_THS {
+		prefix = utils.ThsDs
+	} else {
+		br.Msg = "来源错误"
+		br.ErrMsg = "来源错误"
+		return
+	}
 	for _, sv := range stockCodeArr {
 		for _, ev := range edbCodeArr {
-			indexCode := utils.WindDbWsd + sv + ev
+			indexCode := prefix + sv + ev
 			indexCodeArr = append(indexCodeArr, indexCode)
 		}
 	}
@@ -5054,6 +5144,9 @@ func (this *EdbInfoController) EdbInfoExistCheck() {
 	}
 	var existStockCodeArr []string
 	var existEdbCodeArr []string
+	var existClassifyId []int
+	var existIndexId []int
+
 	for _, indexItem := range indexList {
 		for _, sv := range stockCodeArr {
 			for _, ev := range edbCodeArr {
@@ -5062,6 +5155,8 @@ func (this *EdbInfoController) EdbInfoExistCheck() {
 				}
 				if strings.Contains(indexItem.EdbCode, ev) {
 					existEdbCodeArr = append(existEdbCodeArr, ev)
+					existClassifyId = append(existClassifyId, indexItem.ClassifyId)
+					existIndexId = append(existIndexId, indexItem.EdbInfoId)
 				}
 			}
 		}
@@ -5073,6 +5168,9 @@ func (this *EdbInfoController) EdbInfoExistCheck() {
 	}
 	resp.ExistEdbCodeArr = existEdbCodeArr
 	resp.ExistStockCodeArr = existStockCodeArr
+	resp.ExistClassifyId = existClassifyId
+	resp.ExistIndexId = existIndexId
+	resp.ExistEdbInfo = indexList
 	br.Ret = 200
 	br.Success = true
 	br.Msg = "获取成功"
@@ -5120,19 +5218,39 @@ func (this *EdbInfoController) EdbInfoBatchAdd() {
 		return
 	}
 
-	source := utils.DATA_SOURCE_WIND
-	if source <= 0 {
-		br.Msg = "无效的数据来源"
+	resp := new(data_manage.AddEdbInfoResp)
+
+	var edbNames string
+	for _, v := range req.BatchList {
+		edbNames += "'" + v.EdbName + "',"
+	}
+	edbNames = strings.Trim(edbNames, ",")
+	infoList, err := data_manage.GetEdbInfoByNames(edbNames)
+	if err != nil {
+		br.Msg = "查询指标名称重复错误!"
+		br.ErrMsg = "GetEdbInfoByNames,Err:" + err.Error()
+		return
+	}
+	if len(infoList) > 0 {
+		for _, v := range infoList {
+			resp.ExistEdbName = append(resp.ExistEdbName, v.EdbName)
+		}
+		br.Data = resp
+		br.Msg = "指标名称重复!"
+		br.ErrMsg = "指标名称重复"
 		return
 	}
-
-	resp := new(data_manage.AddEdbInfoResp)
 
 	for k, v := range req.BatchList {
 		v.EdbName = strings.Trim(v.EdbName, " ")
 		v.EdbCode = strings.Trim(v.EdbCode, " ")
 		v.StockCode = strings.Trim(v.StockCode, " ")
 
+		if v.Source <= 0 {
+			br.Msg = "无效的数据来源"
+			return
+		}
+
 		if v.EdbCode == "" {
 			br.Msg = "指标ID不能为空"
 			return
@@ -5159,14 +5277,17 @@ func (this *EdbInfoController) EdbInfoBatchAdd() {
 		}
 
 		edbInfoItem := new(data_manage.EdbInfo)
-		edbInfoItem.Source = source
-		switch source {
+		edbInfoItem.Source = v.Source
+		switch v.Source {
 		case utils.DATA_SOURCE_WIND:
 			edbInfoItem.SourceName = "wind"
+			edbInfoItem.EdbCode = utils.WindDbWsd + v.StockCode + v.EdbCode
+		case utils.DATA_SOURCE_THS:
+			edbInfoItem.SourceName = "ths"
+			edbInfoItem.EdbCode = utils.ThsDs + v.StockCode + v.EdbCode
 		}
 		edbInfoItem.SubSource = 1
 		edbInfoItem.SubSourceName = "日期序列"
-		edbInfoItem.EdbCode = utils.WindDbWsd + v.StockCode + v.EdbCode
 		edbInfoItem.EdbName = v.EdbName
 		edbInfoItem.Frequency = v.Frequency
 		edbInfoItem.Unit = v.Unit

+ 11 - 0
models/data_manage/edb_data_base.go

@@ -12,6 +12,11 @@ func GetEdbDataTableName(source, subSource int) (tableName string) {
 	switch source {
 	case utils.DATA_SOURCE_THS:
 		tableName = "edb_data_ths"
+		if subSource == utils.DATA_SUB_SOURCE_DATE {
+			tableName = "edb_data_ths_ds"
+		} else {
+			tableName = "edb_data_ths"
+		}
 	case utils.DATA_SOURCE_WIND:
 		if subSource == utils.DATA_SUB_SOURCE_DATE {
 			tableName = "edb_data_wind_wsd"
@@ -256,6 +261,12 @@ func GetEdbDataTableNameAndSubSource(source, subSource int) (tableName string) {
 		} else {
 			tableName = "edb_data_wind_wsd"
 		}
+	case utils.DATA_SOURCE_THS:
+		if subSource == utils.DATA_SUB_SOURCE_EDB {
+			tableName = "edb_data_ths_ds"
+		} else {
+			tableName = "edb_data_ths"
+		}
 	default:
 		edbSource := EdbSourceIdMap[source]
 		if edbSource != nil {

+ 63 - 0
models/data_manage/edb_data_ths_ds.go

@@ -0,0 +1,63 @@
+package data_manage
+
+import (
+	"fmt"
+	"github.com/beego/beego/v2/client/orm"
+)
+
+func ModifyEdbInfoThsDsDataStatus(edbInfoId int64, edbCode string) (err error) {
+	o := orm.NewOrmUsingDB("data")
+	tableName := `edb_data_ths_ds`
+	sql := ` UPDATE %s SET edb_info_id=?,modify_time=NOW() WHERE edb_code=? `
+	sql = fmt.Sprintf(sql, tableName)
+	_, err = o.Raw(sql, edbInfoId, edbCode).Exec()
+	return
+}
+
+// GetEdbDataList 获取指标的数据(日期正序返回)
+func GetEdbDataThsDsList(endInfoId int, startDate, endDate string) (list []*EdbDataList, err error) {
+	tableName := `edb_data_ths_ds`
+	var pars []interface{}
+	sql := `SELECT edb_data_id,edb_info_id,data_time,value,data_timestamp FROM %s WHERE edb_info_id=? `
+	if startDate != "" {
+		sql += ` AND data_time>=? `
+		pars = append(pars, startDate)
+	}
+	if endDate != "" {
+		sql += ` AND data_time<=? `
+		pars = append(pars, endDate)
+	}
+
+	sql += ` ORDER BY data_time ASC `
+	sql = fmt.Sprintf(sql, tableName)
+	o := orm.NewOrmUsingDB("data")
+	_, err = o.Raw(sql, endInfoId, pars).QueryRows(&list)
+	return
+}
+
+func GetTHsDsDataCountByCondition(condition string, pars []interface{}, source int) (count int, err error) {
+	o := orm.NewOrmUsingDB("data")
+	tableName := `edb_data_ths_ds`
+	sql := ` SELECT COUNT(1) AS count FROM %s WHERE 1=1 `
+	sql = fmt.Sprintf(sql, tableName)
+	if condition != "" {
+		sql += condition
+	}
+	err = o.Raw(sql, pars).QueryRow(&count)
+	return
+}
+
+func GetThsDsDataListByCondition(condition string, pars []interface{}, source, pageSize, startSize int) (item []*EdbData, err error) {
+	o := orm.NewOrmUsingDB("data")
+	tableName := `edb_data_ths_ds`
+	sql := ` SELECT * FROM %s WHERE 1=1 `
+	sql = fmt.Sprintf(sql, tableName)
+
+	if condition != "" {
+		sql += condition
+	}
+	sql += ` ORDER BY data_time DESC `
+	sql += ` LIMIT ?,? `
+	_, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&item)
+	return
+}

+ 2 - 2
models/data_manage/edb_data_wind_wsd.go

@@ -5,9 +5,9 @@ import (
 	"github.com/beego/beego/v2/client/orm"
 )
 
-func ModifyEdbInfoWindWsdDataStatus(edbInfoId int64, edbCode string) (err error) {
+func ModifyEdbInfoWindWsdDataStatus(source, subSource int, edbInfoId int64, edbCode string) (err error) {
 	o := orm.NewOrmUsingDB("data")
-	tableName := `edb_data_wind_wsd`
+	tableName := GetEdbDataTableNameAndSubSource(source, subSource)
 	sql := ` UPDATE %s SET edb_info_id=?,modify_time=NOW() WHERE edb_code=? `
 	sql = fmt.Sprintf(sql, tableName)
 	_, err = o.Raw(sql, edbInfoId, edbCode).Exec()

+ 20 - 6
models/data_manage/edb_info.go

@@ -193,6 +193,8 @@ func DeleteEdbInfoAndData(edbInfoId, source, subSource int) (err error) {
 	} else {
 		if source == utils.DATA_SOURCE_WIND {
 			tableName = "edb_data_wind_wsd"
+		} else if source == utils.DATA_SOURCE_THS {
+			tableName = "edb_data_ths_ds"
 		}
 	}
 
@@ -588,9 +590,10 @@ func ModifyCalculateEdbInfo(item *EditEdbInfoReq) (err error) {
 }
 
 type AddEdbInfoResp struct {
-	EdbInfoId  int    `description:"指标ID"`
-	UniqueCode string `description:"指标唯一编码"`
-	ClassifyId int    `description:"分类id"`
+	EdbInfoId    int      `description:"指标ID"`
+	UniqueCode   string   `description:"指标唯一编码"`
+	ClassifyId   int      `description:"分类id"`
+	ExistEdbName []string `description:"重复指标名称"`
 }
 
 // 根据基础指标获取所有关联指标
@@ -1649,9 +1652,12 @@ func GetEdbInfoAdminList(edbType int) (list []int, err error) {
 }
 
 type EdbInfoExistCheckResp struct {
-	IndexExist        bool     `description:"指标是否存在:true,存在,false:不存在"`
-	ExistStockCodeArr []string `description:"存在的证券代码"`
-	ExistEdbCodeArr   []string `description:"存在的指标代码"`
+	IndexExist        bool       `description:"指标是否存在:true,存在,false:不存在"`
+	ExistStockCodeArr []string   `description:"存在的证券代码"`
+	ExistEdbCodeArr   []string   `description:"存在的指标代码"`
+	ExistClassifyId   []int      `description:"存在的分类id"`
+	ExistIndexId      []int      `description:"存在的指标id"`
+	ExistEdbInfo      []*EdbInfo `description:"存在的指标"`
 }
 
 type BatchAddEdbInfoReq struct {
@@ -1686,3 +1692,11 @@ func GetEdbInfoWsdMaxAndMinInfo(source, subSource int, edbCode string) (item *Ed
 	item.LatestValue = latest_value
 	return
 }
+
+// GetEdbInfoByNames 根据名称获取普通的指标
+func GetEdbInfoByNames(edbNames string) (items []*EdbInfoList, err error) {
+	o := orm.NewOrmUsingDB("data")
+	sql := ` SELECT * FROM edb_info WHERE edb_name IN (` + edbNames + `) AND edb_info_type = 0 `
+	_, err = o.Raw(sql).QueryRows(&items)
+	return
+}

+ 20 - 0
services/data/base_edb_lib.go

@@ -95,6 +95,21 @@ func AddEdbDataWindWsd(source int, stockCode, edbCode string) (resp *models.Base
 	return
 }
 
+// AddEdbDataThsDs 新增指标数据
+func AddEdbDataThsDs(source int, stockCode, edbCode string) (resp *models.BaseResponse, err error) {
+	param := make(map[string]interface{})
+	param["EdbCode"] = edbCode
+	param["StockCode"] = stockCode
+	param["Source"] = source
+	urlStr := `ths/ds/add`
+	if urlStr == "" {
+		err = fmt.Errorf("未实现该指标的刷新接口,请联系管理员")
+		return
+	}
+	resp, err = postRefreshEdbData(param, urlStr)
+	return
+}
+
 type AddPredictEdbDataResponse struct {
 	Ret         int
 	Msg         string
@@ -150,6 +165,11 @@ func RefreshEdbData(edbInfoId, source, subSource int, edbCode, startDate string)
 	switch source {
 	case utils.DATA_SOURCE_THS:
 		urlStr = "ths/refresh"
+		if subSource == 0 {
+			urlStr = "ths/refresh"
+		} else {
+			urlStr = "ths/ds/refresh"
+		}
 	case utils.DATA_SOURCE_WIND:
 		if subSource == 0 {
 			urlStr = "wind/refresh"

+ 1 - 1
services/data/edb_info.go

@@ -3028,7 +3028,7 @@ func EdbInfoWsdAdd(item *data_manage.EdbInfo) (edbInfo *data_manage.EdbInfo, err
 	}
 	edbInfo.EdbInfoId = int(edbInfoId)
 	//保存数据
-	err = data_manage.ModifyEdbInfoWindWsdDataStatus(edbInfoId, item.EdbCode)
+	err = data_manage.ModifyEdbInfoWindWsdDataStatus(source, item.SubSource, edbInfoId, item.EdbCode)
 	if err != nil {
 		errMsg = "保存失败"
 		err = errors.New("修改数据对应指标ID失败,Err:" + err.Error())

+ 1 - 0
utils/constants.go

@@ -361,6 +361,7 @@ const (
 
 const (
 	WindDbWsd = "wsd"
+	ThsDs = "thsds"
 )
 
 const (