using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MMoneyCoderSharp.Data.Request.봉차트
{
    internal class CandleStockDIS : ACandleData
    {
        public CandleStockDIS(DBDefine.봉차트세부종목 recvDataType, DBDefine.데이터기간 recvDataLength, string recvStockCode) : base(recvDataType, recvDataLength)
        {

            this.mStockCode = recvStockCode;

        }

        protected override void setQuery()
        {

            #region 지수

            this.queryIndexNow = @"SELECT DISTINCT 
			b.f_stock_code stock_code, 
			b.F_STOCK_WANNAME stock_name, 
			a.f_curr_price curr_price, 
			ABS(a.f_net_chg) net_chg, 
			decode(a.f_chg_type, '1', '상한', '2', '상승', '3', '보합', '4', '하한', '5', '하락') chg_type, 
			round((a.f_net_chg / decode(a.f_chg_type, '1', (a.f_curr_price - a.f_net_chg), 
				'2', (a.f_curr_price - a.f_net_chg), 
				'3', (a.f_curr_price), 
				'4', -1 * (a.f_curr_price + a.f_net_chg), 
				'5', -1 * (a.f_curr_price + a.f_net_chg))) * 100, 2) rate 
			FROM t_stop_online1 a, t_stock b 
			WHERE b.f_mkt_halt = 'Y' 
			
			AND a.f_curr_price < > 0 

			AND a.f_stock_code = b.f_stock_code 
				AND b.f_stock_wanname = '{0}'";



            this.queryIndexLast = @"select O.OPEN_DAY,   X.F_STOCK_CODE,  X.f_stock_wanname, 
					X.F_CHG_TYPE, X.F_NET_CHG, 
					X.F_HIGH_PRICE, X.F_LOW_PRICE, X.F_INIT_PRICE, 
					X.F_CURR_PRICE, X.F_MA5_PRICE, X.F_MA20_PRICE 
					from(select  a.F_DATA_DATE, a.F_STOCK_CODE, b.f_stock_wanname, 
						a.F_CHG_TYPE, a.F_NET_CHG, 
						a.F_HIGH_PRICE, a.F_LOW_PRICE, a.F_INIT_PRICE, 
						a.F_CURR_PRICE, a.F_MA5_PRICE, a.F_MA20_PRICE 
						from t_candle_history a, t_stock b 
			where a.f_stock_code = b.f_stock_code 
			and b.f_stock_wanname = '{1}'  
				and b.f_mkt_halt = 'Y' 
				order by a.F_DATA_DATE desc) X, 
					(select open_day from(select open_day from v_open_day 
						order by open_day desc) 
			where rownum <= {0} ) O 

			where X.f_data_date(+) = o.open_day 
			order by O.OPEN_DAY";

            #endregion
            }
        }
    }
