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_PermissionRepository : BaseRepository<RB_OKR_Permission>
    {

        /// <summary>
        /// 获取分页列表
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="rowsCount"></param>
        /// <param name="demodel"></param>
        /// <returns></returns>
        public List<RB_OKR_Permission_ViewModel> GetPageList(int pageIndex, int pageSize, out long rowsCount, RB_OKR_Permission_ViewModel demodel)
        {
            string where = $@" 1=1";
            if (demodel.Group_Id > 0)
            {
                where += $@" and {nameof(RB_OKR_Permission_ViewModel.Group_Id)} ={demodel.Group_Id}";
            }
            if (demodel.PermissionType > 0)
            {
                where += $@" and {nameof(RB_OKR_Permission_ViewModel.PermissionType)} ={demodel.PermissionType}";
            }
            if (demodel.TargetId > 0)
            {
                where += $@" and {nameof(RB_OKR_Permission_ViewModel.TargetId)} ={demodel.TargetId}";
            }
            if (demodel.Type > 0)
            {
                where += $@" and {nameof(RB_OKR_Permission_ViewModel.Type)} ={demodel.Type}";
            }
            if (demodel.SourceId > 0)
            {
                where += $@" and {nameof(RB_OKR_Permission_ViewModel.SourceId)} ={demodel.SourceId}";
            }
            if (demodel.State > 0)
            {
                where += $@" and {nameof(RB_OKR_Permission_ViewModel.State)} ={demodel.State}";
            }

            string sql = $@" select * from RB_OKR_Permission where {where} order by Id desc";
            return GetPage<RB_OKR_Permission_ViewModel>(pageIndex, pageSize, out rowsCount, sql).ToList();
        }

        /// <summary>
        /// 获取列表
        /// </summary>
        /// <param name="demodel"></param>
        /// <returns></returns>
        public List<RB_OKR_Permission_ViewModel> GetList(RB_OKR_Permission_ViewModel demodel)
        {
            string where = $@" 1=1";
            if (demodel.Group_Id > 0)
            {
                where += $@" and {nameof(RB_OKR_Permission_ViewModel.Group_Id)} ={demodel.Group_Id}";
            }
            if (demodel.PermissionType > 0)
            {
                where += $@" and {nameof(RB_OKR_Permission_ViewModel.PermissionType)} ={demodel.PermissionType}";
            }
            if (demodel.TargetId > 0)
            {
                where += $@" and {nameof(RB_OKR_Permission_ViewModel.TargetId)} ={demodel.TargetId}";
            }
            if (!string.IsNullOrEmpty(demodel.ObjectiveIds))
            {
                where += $@" and {nameof(RB_OKR_Permission_ViewModel.TargetId)} in({demodel.ObjectiveIds})";
            }
            if (demodel.Type > 0)
            {
                where += $@" and {nameof(RB_OKR_Permission_ViewModel.Type)} ={demodel.Type}";
            }
            if (demodel.SourceId > 0)
            {
                where += $@" and {nameof(RB_OKR_Permission_ViewModel.SourceId)} ={demodel.SourceId}";
            }
            if (demodel.State > 0)
            {
                where += $@" and {nameof(RB_OKR_Permission_ViewModel.State)} ={demodel.State}";
            }
            if (demodel.CreateBy > 0)
            {
                where += $@" and {nameof(RB_OKR_Permission_ViewModel.CreateBy)} ={demodel.CreateBy}";
            }
            if (!string.IsNullOrEmpty(demodel.CreateByIds))
            {
                where += $@" and {nameof(RB_OKR_Permission_ViewModel.CreateBy)} in({demodel.CreateByIds})";
            }

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