package data import ( "encoding/json" "eta/eta_api/models" "eta/eta_api/models/data_manage" "eta/eta_api/utils" "fmt" ) // CheckExistThsHfEdb 校验已存在的同花顺高频指标 func CheckExistThsHfEdb(stockCodes, edbCodes []string) (checkResp data_manage.ThsHfExistCheckResp, existMap map[string]bool, err error) { // 待校验的指标编码 var indexCode []string prefix := utils.ThsHf for _, sv := range stockCodes { for _, ev := range edbCodes { t := fmt.Sprintf("%s%s%s", prefix, sv, ev) indexCode = append(indexCode, t) } } baseIndexes := make([]*data_manage.BaseFromThsHfIndex, 0) { ob := new(data_manage.BaseFromThsHfIndex) fields := []string{ob.Cols().PrimaryId, ob.Cols().IndexCode, ob.Cols().IndexName, ob.Cols().StockCode, ob.Cols().Indicator} list, e := ob.GetItemsByCondition(``, make([]interface{}, 0), fields, "") if e != nil { err = fmt.Errorf("获取高频指标列表失败, %v", e) return } baseIndexes = list } var existNum int existMap = make(map[string]bool) for _, bv := range baseIndexes { code := fmt.Sprintf("%s%s%s", prefix, bv.StockCode, bv.Indicator) for _, iv := range indexCode { if code != iv { continue } existMap[fmt.Sprintf("%s-%s", bv.StockCode, bv.Indicator)] = true existNum += 1 checkResp.ExistIndex = append(checkResp.ExistIndex, data_manage.ThsHfExistCheckIndex{ IndexId: bv.BaseFromThsHfIndexId, IndexCode: bv.IndexCode, IndexName: bv.IndexName, }) break } } if existNum > 0 && existNum == len(indexCode) { checkResp.ExistAll = true } return } // GetEdbDataThsHf 获取同花顺高频数据指标 func GetEdbDataThsHf(req data_manage.ThsHfSearchEdbReq) (indexes []*data_manage.ThsHfIndexWithData, err error) { param := make(map[string]interface{}) param["StockCode"] = req.StockCode param["EdbCode"] = req.EdbCode param["StartTime"] = req.StartTime param["EndTime"] = req.EndTime param["Interval"] = req.Interval param["Fill"] = req.Fill param["CPS"] = req.CPS param["BaseDate"] = req.BaseDate uri := `ths/hf/edb_data` resp, e := postThsHfEdbData(param, uri) if e != nil { err = fmt.Errorf("postThsHfEdbData, %v", e) return } if resp.Ret == 200 { indexes = resp.Data } return } // postThsHfEdbData 刷新指标数据 func postThsHfEdbData(param map[string]interface{}, urlStr string) (resp *data_manage.ThsHfIndexDataLibResp, err error) { postUrl := utils.EDB_LIB_URL + urlStr postData, err := json.Marshal(param) if err != nil { return } result, err := HttpPost(postUrl, string(postData), utils.ZhLangVersion, "application/json") if err != nil { return } utils.FileLog.Info("postRefreshEdbData:" + postUrl + ";" + string(postData) + ";result:" + string(result)) err = json.Unmarshal(result, &resp) if err != nil { return } return resp, nil } // BaseAddThsHf 新增数据源 func BaseAddThsHf(req data_manage.ThsHfBaseAddReq) (resp *models.BaseResponse, err error) { param := make(map[string]interface{}) param["StartTime"] = req.StartTime param["EndTime"] = req.EndTime param["Interval"] = req.Interval param["Fill"] = req.Fill param["CPS"] = req.CPS param["BaseDate"] = req.BaseDate param["SysAdminId"] = req.SysAdminId param["SysAdminName"] = req.SysAdminName param["ClassifyId"] = req.ClassifyId param["Unit"] = req.Unit param["IndexName"] = req.IndexName param["Frequency"] = req.Frequency param["StockCode"] = req.StockCode param["EdbCode"] = req.EdbCode uri := `ths/hf/base/add` res, e := postRefreshEdbData(param, uri) if e != nil { err = fmt.Errorf("postRefreshEdbData, %v", e) return } resp = res return }