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

namespace Edu.Repository.Sell
{
    /// <summary>
    /// 绩效备注仓储层
    /// </summary>
    public class RB_Teaching_PerfRemarkRepository : BaseRepository<RB_Teaching_PerfRemark>
    {
        /// <summary>
        /// 获取列表
        /// </summary>
        /// <param name="demodel"></param>
        /// <returns></returns>
        public List<RB_Teaching_PerfRemark_ViewModel> GetList(RB_Teaching_PerfRemark_ViewModel demodel)
        {
            string where = $@" 1=1";
            
            if (demodel.PerfId > 0)
            {
                where += $@" and {nameof(RB_Teaching_PerfRemark.PerfId)} ={demodel.PerfId}";
            }
            if (!string.IsNullOrEmpty(demodel.PerfIds))
            {
                where += $@" and {nameof(RB_Teaching_PerfRemark.PerfId)} in({demodel.PerfIds})";
            }

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

        /// <summary>
        /// 获取最后一条记录
        /// </summary>
        /// <param name="perfId"></param>
        /// <returns></returns>
        public RB_Teaching_PerfRemark_ViewModel GetLastRemark(int perfId)
        {
            string where = $@" 1=1";
            where += $@" and {nameof(RB_Teaching_PerfRemark.PerfId)} ={perfId}";

            string sql = $@" select * from RB_Teaching_PerfRemark where {where} order by Id desc limit 1";
            return Get<RB_Teaching_PerfRemark_ViewModel>(sql).FirstOrDefault();
        }
    }
}
