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

namespace Edu.Repository.OKR
{
    /// <summary>
    /// OKR规则仓储层
    /// </summary>
    public class RB_OKR_RuleRepository : BaseRepository<RB_OKR_Rule>
    {

        /// <summary>
        /// 获取分页列表
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="rowsCount"></param>
        /// <param name="demodel"></param>
        /// <returns></returns>
        public List<RB_OKR_Rule_ViewModel> GetPageList(int pageIndex, int pageSize, out long rowsCount, RB_OKR_Rule_ViewModel demodel)
        {
            string where = $@" 1=1 and Status =0";
            if (demodel.Group_Id > 0)
            {
                where += $@" and {nameof(RB_OKR_Rule_ViewModel.Group_Id)} ={demodel.Group_Id}";
            }
            if (!string.IsNullOrEmpty(demodel.RuleName))
            {
                where += $@" and {nameof(RB_OKR_Rule_ViewModel.RuleName)} like '%{demodel.RuleName}%'";
            }
            if (demodel.Way > 0)
            {
                where += $@" and {nameof(RB_OKR_Rule_ViewModel.Way)} ={demodel.Way}";
            }
            if (demodel.Enable > 0)
            {
                where += $@" and {nameof(RB_OKR_Rule_ViewModel.Enable)} ={demodel.Enable}";
            }
            
            string sql = $@" select * from RB_OKR_Rule where {where} order by Id desc";
            return GetPage<RB_OKR_Rule_ViewModel>(pageIndex, pageSize, out rowsCount, sql).ToList();
        }

        /// <summary>
        /// 获取列表
        /// </summary>
        /// <param name="demodel"></param>
        /// <returns></returns>
        public List<RB_OKR_Rule_ViewModel> GetList(RB_OKR_Rule_ViewModel demodel)
        {
            string where = $@" 1=1 and Status =0";
            if (demodel.Group_Id > 0)
            {
                where += $@" and {nameof(RB_OKR_Rule_ViewModel.Group_Id)} ={demodel.Group_Id}";
            }
            if (!string.IsNullOrEmpty(demodel.RuleName))
            {
                where += $@" and {nameof(RB_OKR_Rule_ViewModel.RuleName)} like '%{demodel.RuleName}%'";
            }
            if (demodel.Way > 0)
            {
                where += $@" and {nameof(RB_OKR_Rule_ViewModel.Way)} ={demodel.Way}";
            }
            if (demodel.Enable > 0)
            {
                where += $@" and {nameof(RB_OKR_Rule_ViewModel.Enable)} ={demodel.Enable}";
            }

            string sql = $@" select * from RB_OKR_Rule where {where} order by Id desc";
            return Get<RB_OKR_Rule_ViewModel>(sql).ToList();
        }
    }
}
