using Edu.Common.Enum;
using Edu.Model.Entity.Web;
using Edu.Model.ViewModel.Web;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using VT.FW.DB.Dapper;

namespace Edu.Repository.Web
{
    /// <summary>
    /// 招聘类型仓储层
    /// </summary>
    public class RB_Web_RecruitmentTypeRepository : BaseRepository<RB_Web_RecruitmentType>
    {
        /// <summary>
        /// 获取招聘类型分页列表
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="rowsCount"></param>
        /// <param name="query"></param>
        /// <returns></returns>
        public List<RB_Web_RecruitmentType_ViewModel> GetWebRecruitmentTypePageRepository(int pageIndex, int pageSize, out long rowsCount, RB_Web_RecruitmentType_ViewModel query)
        {
            rowsCount = 0;
            var parameters = new DynamicParameters();
            StringBuilder builder = new StringBuilder();
            builder.Append(@"
SELECT A.* 
FROM RB_Web_RecruitmentType AS A
WHERE 1=1
");
            builder.AppendFormat(@" AND A.{0}={1} ", nameof(RB_Web_RecruitmentType_ViewModel.Status), (int)DateStateEnum.Normal);
            if (query == null)
            {
                return new List<RB_Web_RecruitmentType_ViewModel>();
            }
            else
            {
                if (query.Group_Id > 0)
                {
                    builder.AppendFormat(@" AND A.{0}={1} ", nameof(RB_Web_RecruitmentType_ViewModel.Group_Id), query.Group_Id);
                }
                if (!string.IsNullOrEmpty(query.TypeName))
                {
                    builder.AppendFormat(" AND A.{0} LIKE @TypeName ", nameof(RB_Web_RecruitmentType_ViewModel.TypeName));
                    parameters.Add("TypeName", "%" + query.TypeName.Trim() + "%");
                }
            }
            builder.AppendFormat(" ORDER BY A.{0} DESC ", nameof(RB_Web_RecruitmentType_ViewModel.Id));
            return GetPage<RB_Web_RecruitmentType_ViewModel>(pageIndex, pageSize, out rowsCount, builder.ToString(), parameters).ToList();
        }

        /// <summary>
        /// 获取招聘类型列表
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public List<RB_Web_RecruitmentType_ViewModel> GetWebRecruitmentTypeListRepository(RB_Web_RecruitmentType_ViewModel query)
        {
            var parameters = new DynamicParameters();
            StringBuilder builder = new StringBuilder();
            builder.Append(@"
SELECT A.* 
FROM RB_Web_RecruitmentType AS A
WHERE 1=1
");
            builder.AppendFormat(@" AND A.{0}={1} ", nameof(RB_Web_RecruitmentType_ViewModel.Status), (int)DateStateEnum.Normal);
            if (query == null)
            {
                return new List<RB_Web_RecruitmentType_ViewModel>();
            }
            else
            {
                if (query.Group_Id > 0)
                {
                    builder.AppendFormat(@" AND A.{0}={1} ", nameof(RB_Web_RecruitmentType_ViewModel.Group_Id), query.Group_Id);
                }
                if (!string.IsNullOrEmpty(query.TypeName))
                {
                    builder.AppendFormat(" AND A.{0} LIKE @TypeName ", nameof(RB_Web_RecruitmentType_ViewModel.TypeName));
                    parameters.Add("TypeName", "%" + query.TypeName.Trim() + "%");
                }
            }
            builder.AppendFormat(" ORDER BY A.{0} DESC ", nameof(RB_Web_RecruitmentType_ViewModel.Id));
            return Get<RB_Web_RecruitmentType_ViewModel>(builder.ToString(), parameters).ToList();
        }
    }
}
