示例#1
0
 public List <YieldRateIncreaseMaxDaysReportModel> GetYieldRateIncreaseMaxDays([FromQuery] YieldRateIncreaseMaxDaysQueryModel queryModel)
 {
     if (!ModelState.IsValid)
     {
         throw new MyTwseException(MyTwseExceptionEnum.InvalidRequestParameterByModelState, ModelState);
     }
     return(_StockInfoService.GetYieldRateIncreaseMaxDays(queryModel));
 }
        public List <YieldRateIncreaseMaxDaysReportModel> GetYieldRateIncreaseMaxDays(YieldRateIncreaseMaxDaysQueryModel queryModel)
        {
            string sql = @"

WITH 
SI AS
(
	SELECT*,ROW_NUMBER() OVER (ORDER BY [DATE]) AS DateRowNum
	FROM StockInfo
	WHERE CODE = @Code
), 
T3 AS
(
	SELECT 
		MIN([Date])MinDate
	    ,MAX([Date])MaxDate
	    ,COUNT(1) Days
	FROM
	(
		SELECT 
			[DATE]	
			,DateRowNum - ROW_NUMBER() OVER (ORDER BY DateRowNum) AS RowNum
		FROM
		(
			SELECT 
			    S1.[Date]
			    ,CASE 
			        WHEN (S2.YieldRate-S1.YieldRate) > 0 OR S2.YieldRate IS NULL THEN 1 ELSE 0 END IsIncrease
			    ,S1.DateRowNum
			FROM SI S1
			LEFT JOIN SI S2 ON S1.DateRowNum = S2.DateRowNum - 1
			WHERE S1.CODE = @Code AND S1.[Date] >= @StartDate AND S1.[Date] <= @EndDate
		) AS T1
		WHERE T1.IsIncrease = 1
	)AS T2
	GROUP BY RowNum
)
SELECT * 
FROM T3 
WHERE Days = (SELECT MAX(Days)FROM T3)
";

            return(ExecSQL <YieldRateIncreaseMaxDaysReportModel>(sql, queryModel));
        }
示例#3
0
 /// <summary>
 /// 取得股票殖利率提升連續最大天數
 /// </summary>
 /// <param name="queryModel"></param>
 /// <returns></returns>
 public List <YieldRateIncreaseMaxDaysReportModel> GetYieldRateIncreaseMaxDays(YieldRateIncreaseMaxDaysQueryModel queryModel)
 {
     if (queryModel.StartDate > queryModel.EndDate)
     {
         throw new MyTwseException(MyTwseExceptionEnum.BadRequest, "開始時間不得大於結束時間");
     }
     CreateStockInfoData(queryModel.StartDate.Value, queryModel.EndDate.Value);
     return(_StockInfoRepository.GetYieldRateIncreaseMaxDays(queryModel));
 }