using Mall.Model.Entity.TradePavilion;
using Mall.Model.Query;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Mall.Repository.TradePavilion
{
    /// <summary>
    /// 首页推荐数据统计
    /// </summary>
    public class TradeIndexRepository : BaseRepository<RB_Brand>
    {
        /// <summary>
        /// 获取首页推荐数据
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="rowsCount"></param>
        /// <param name="query"></param>
        /// <returns></returns>
        public List<TradeIndexResult> GetTradeIndexPageRepository(int pageIndex, int pageSize, out long rowsCount, TradeIndexQuery query)
        {
            StringBuilder builder = new StringBuilder();
            builder.AppendFormat(@"
SELECT A.*
FROM
(
     SELECT ID AS DataId,CarrierName AS DataName,1 AS DataType,Logo AS CoverImg,RecommendDate,'' AS FullBrandName,ProjectType,Address 
		 FROM rb_carrier WHERE Status=0 AND IsRecommend=1 AND MallBaseId={0}
     UNION ALL 
     SELECT BuildId AS DataId,Name AS DataName,2 AS DataType,Banner AS CoverImg,RecommendDate,'' AS FullBrandName, 0 AS ProjectType,'' AS Address  
		 FROM rb_building WHERE Status=0 AND IsRecommend=1 AND MallBaseId={0}
     UNION ALL
     SELECT ID AS DataId,BrandName AS DataName,3 AS DataType,Logo AS CoverImg,RecommendDate,FullBrandName,0 AS ProjectType,'' AS Address   
		 FROM rb_brand WHERE Status=0 AND IsRecommend=1 AND MallBaseId={0}
     UNION ALL
     SELECT ServiceId AS DataId,Name AS DataName,4 AS DataType,Banner AS CoverImg,RecommendDate,'' AS FullBrandName,0 AS ProjectType,'' AS Address  
		 FROM rb_enterpriseservices WHERE Status=0 AND IsRecommend=1 AND MallBaseId={0}
) AS A WHERE 1=1 
", query.MallBaseId);
            builder.AppendFormat(" ORDER BY A.RecommendDate DESC  ");
            return base.GetPage<TradeIndexResult>(pageIndex, pageSize, out rowsCount, builder.ToString()).ToList();
        }
    }
}
