/// <summary> /// 财务指标信息转成指标股票信息 /// </summary> /// <param name="obj"></param> /// <returns></returns> public static List <FinanceIndexInfo> Transfer2ListFinanceIndexInfo(object obj, ulong securityID) { List <FinanceIndexInfo> lstInfo = new List <FinanceIndexInfo>(); List <DateTime> listDate = GetFinanceDate(); PropertyInfo[] properties = obj.GetType().GetProperties(); foreach (PropertyInfo pro in properties) { if (pro.Name.EndsWith("Specified")) { continue; } if (pro.PropertyType.IsGenericType) { if (pro.PropertyType.GetGenericArguments()[0] == typeof(DataColumn)) { List <DataColumn> lstCol = pro.GetValue(obj, null) as List <DataColumn>; if (lstCol.Count == 0) { continue; } Dictionary <string, string[]> dicStr = GetStringValue(lstCol); DataColumn colSymbol = null; //股票编码列 DataColumn colEndDate = null; //截止日期列 foreach (DataColumn col in lstCol) { if (col.name == "Symbol") { colSymbol = col; } else if (col.name == "EndDate") { colEndDate = col; } } uint count = lstCol[0].count; for (int i = 0; i < count; i++) { //股票编号 string symbol = Convert.ToString(GetValueObj(i, colSymbol.type, colSymbol.data, dicStr[colSymbol.name])); //截止日期 DateTime endDate = Convert.ToDateTime(GetValueObj(i, colEndDate.type, colEndDate.data, null)); if (listDate.Contains(endDate) == false) { continue; } foreach (DataColumn col in lstCol) { if (col == colSymbol || col == colEndDate) { //股票安全码列、股票列、截止日期列跳过,只处理指标列 continue; } object objValue = GetValueObj(i, col.type, col.data, null); if (IsInvalidDecValue(col.type, objValue) == false) //判断是否非法数值 { FinanceIndexInfo info = new FinanceIndexInfo(); lstInfo.Add(info); info.SecurityID = securityID; info.Symbol = symbol; info.EndDate = endDate; info.EndDateName = GetTermDisplay_Quarter(endDate); info.IndexCode = col.name; info.IndexValue = Convert.ToDouble(objValue); } } } } } } return(lstInfo); }
/// <summary> /// 同步财务指标信息 /// </summary> public static void SyncFinaceIndex() { // 记日志 LogHelper.Info("总运行", "开始:同步财务指标数据"); DspRequest dspRequest = new DspRequest(); dspRequest.DealData = SaveFinaceIndex; LstRetryReqFinance = new List <ReqFinance>(); try { //取得所有a股安全码 List <ulong> lstSecurityID = MongoDBHelper.AsQueryable <SymbolInfo>().Select(m => m.SecurityID).ToList(); //取得所有财务指标编码 List <string> lstIndexCode = GetAllFinaceIndexCode(); ////删除已过期的数据 //DeleteOverdueFinaceIndex(lstSecurityID[0]); // 根据代码同步所有财务指标数据 foreach (var securityID in lstSecurityID) { try { FinanceIndexInfo info = MongoDBHelper.AsQueryable <FinanceIndexInfo>() .Where(m => m.SecurityID == securityID) .OrderByDescending(m => m.EndDate) .FirstOrDefault(); DateTime lastDate = new DateTime(1990, 1, 1); if (info != null) { lastDate = info.EndDate; } ReqFinance req = DSPHelper.GetReqFinance(securityID, lstIndexCode, lastDate); if (req != null) { dspRequest.AsyncSendData(req, DSPHelper.WaitTime, req); } } catch (Exception ex) { string errMsg = "同步财务指标异常.SecurityID:" + securityID; LogHelper.Error("异常", errMsg, ex); } } //等待DSP任务完成 dspRequest.WaitFinished(); if (LstRetryReqFinance.Count > 0) { //重试 RetrySyncFinaceIndex(dspRequest, 1); //等待DSP任务完成 dspRequest.WaitFinished(); } ////给10秒钟mongodb。 //Thread.Sleep(10000); } catch (Exception ex) { LogHelper.Error("异常", "同步财务指标发生异常.", ex); } finally { dspRequest.Dispose(); LogHelper.Info("总运行", "结束:同步财务指标数据"); } }