using Edu.Model.Entity.User;
using Edu.Model.ViewModel.User;
using System.Collections.Generic;
using System.Linq;

namespace Edu.Repository.User
{
    /// <summary>
    /// 打卡记录扩展信息
    /// </summary>
    public partial class Rb_workdaysetingRepository : BaseRepository<RB_WorkdaySeting>
    {
        /// <summary>
        /// 获取工作日
        /// </summary>
        /// <param name="empId">员工id</param>
        /// <param name="workDay">工作日，周一</param>
        /// <returns></returns>
        public RB_WorkdaySeting_Extend GetWorkDay(int empId, string workDay)
        {
            return Get<RB_WorkdaySeting_Extend>($@"SELECT * from rb_workdayseting w where  w.Workday  = '{workDay}'
                and w.AttendanceId = (SELECT a.Id from rb_attendance a 
                INNER JOIN (SELECT e.RB_Branch_id,e.RB_Group_id from rb_employee e where e.EmployeeId = {empId}) as e
                on e.RB_Branch_id =a.RB_BranchId and e.RB_Group_id =a.RB_GroupId)").ToList().FirstOrDefault();
        }

        /// <summary>
        /// 获取公司当天是否需要打卡
        /// </summary>
        /// <param name="branchid"></param>
        /// <param name="workDay"></param>
        /// <returns></returns>
        public RB_WorkdaySeting_Extend GetWorkDayToBranch(int branchid, string workDay)
        {
            return Get<RB_WorkdaySeting_Extend>($@"SELECT * from rb_workdayseting w where  w.Workday  = '{workDay}'
                and w.AttendanceId = (SELECT a.Id from rb_attendance a where a.RB_BranchId={branchid})").ToList().FirstOrDefault();
        }

        /// <summary>
        /// 获取工作日列表
        /// </summary>
        /// <param name="empId">员工id</param>
        /// <returns></returns>
        public List<RB_WorkdaySeting_Extend> GetWorkDayList(int empId)
        {
            return Get<RB_WorkdaySeting_Extend>($@"SELECT * from rb_workdayseting w where w.AttendanceId = (SELECT a.Id from rb_attendance a 
                INNER JOIN (SELECT e.RB_Branch_id,e.RB_Group_id from rb_employee e where e.EmployeeId = {empId}) as e
                on e.RB_Branch_id =a.RB_BranchId and e.RB_Group_id =a.RB_GroupId)").ToList();
        }
    }
}
