using Edu.Common.Enum; using Edu.Model.Entity.Scroll; using Edu.Model.ViewModel.Scroll; using System; using System.Collections.Generic; using System.Linq; using System.Text; using VT.FW.DB.Dapper; namespace Edu.Repository.Scroll { /// /// 滚动开班预约仓储层 /// public class RB_Scroll_AppointmentRepository : BaseRepository { /// /// 获取列表 /// /// /// public List GetList(RB_Scroll_Appointment_ViewModel demodel) { DynamicParameters parameters = new DynamicParameters(); string where = $@" 1=1 and r.{nameof(RB_Scroll_Appointment_ViewModel.Status)} =0 and r.{nameof(RB_Scroll_Appointment_ViewModel.State)} <>5"; if (demodel.Group_Id > 0) { where += $@" and r.{nameof(RB_Scroll_Appointment_ViewModel.Group_Id)} ={demodel.Group_Id}"; } if (demodel.State > 0) { where += $@" and r.{nameof(RB_Scroll_Appointment_ViewModel.State)} ={(int)demodel.State}"; } if (!string.IsNullOrEmpty(demodel.StartTime)) { where += $@" and r.{nameof(RB_Scroll_Appointment_ViewModel.Date)} >='{demodel.StartTime}'"; } if (!string.IsNullOrEmpty(demodel.EntTime)) { where += $@" and r.{nameof(RB_Scroll_Appointment_ViewModel.Date)} <='{demodel.EntTime} 23:59:59'"; } if (!string.IsNullOrEmpty(demodel.CourseEndTimeStr)) { where += $@" and r.{nameof(RB_Scroll_Appointment_ViewModel.CourseEndTime)} <='{demodel.CourseEndTimeStr}'"; } if (demodel.TeacherId > 0) { where += $@" and c.AccountId ={demodel.TeacherId}"; } if (demodel.StuId > 0) { where += $@" and r.{nameof(RB_Scroll_Appointment_ViewModel.StuId)} ={demodel.StuId}"; } if (demodel.GuestId > 0) { where += $@" and r.{nameof(RB_Scroll_Appointment_ViewModel.GuestId)} ={demodel.GuestId}"; } if (!string.IsNullOrEmpty(demodel.StuIds)) { where += $@" and r.{nameof(RB_Scroll_Appointment_ViewModel.StuId)} in({demodel.StuIds})"; } if (demodel.AppointType > 0) { where += $@" and r.{nameof(RB_Scroll_Appointment_ViewModel.AppointType)} ={demodel.AppointType}"; } string sql = $@" SELECT r.*,c.AccountId as TeacherId,s.StuName,cou.CourseName,cou.ScrollMinNum,cou.ScrollMaxNum From RB_Scroll_Appointment r inner join rb_account c on r.AccountId = c.Id inner join rb_student s on r.StuId = s.StuId inner join rb_course cou on r.CourseId = cou.CourseId WHERE {where} ORDER BY r.Id asc "; return Get(sql, parameters).ToList(); } /// /// 获取我预约的次数 /// /// /// /// public RB_Scroll_Appointment_ViewModel GetMyAppointmentNum(int stuId, int guestId, int group_Id) { string sql = $@"SELECT MAX(Date) AS Date, COUNT(0) as ScrollMinNum FROM rb_scroll_appointment WHERE `Status` =0 and State <>5 and CourseEndTime >='{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}' and Group_Id ={group_Id} and StuId ={stuId} and GuestId ={guestId} HAVING COUNT(0) >0"; return Get(sql).FirstOrDefault(); } /// /// 获取分页列表 /// /// /// /// /// /// public List GetAppointPageList(int pageIndex, int pageSize, out long count, RB_Scroll_Appointment_ViewModel demodel) { DynamicParameters parameters = new DynamicParameters(); string where = $@" 1=1 and r.{nameof(RB_Scroll_Appointment_ViewModel.Status)} =0 "; if (demodel.Group_Id > 0) { where += $@" and r.{nameof(RB_Scroll_Appointment_ViewModel.Group_Id)} ={demodel.Group_Id}"; } if (demodel.State > 0) { where += $@" and r.{nameof(RB_Scroll_Appointment_ViewModel.State)} ={(int)demodel.State}"; } if (demodel.AccountId > 0) { where += $@" and r.{nameof(RB_Scroll_Appointment_ViewModel.AccountId)} ={demodel.AccountId}"; } if (demodel.TeacherId > 0) { where += $@" and c.AccountId ={demodel.TeacherId}"; } if (demodel.StuId > 0) { where += $@" and r.{nameof(RB_Scroll_Appointment_ViewModel.StuId)} ={demodel.StuId}"; } if (demodel.CourseId > 0) { where += $@" and r.{nameof(RB_Scroll_Appointment_ViewModel.LearnCourseId)} ={demodel.CourseId}"; } if (!string.IsNullOrEmpty(demodel.StartTime)) { where += $@" and r.{nameof(RB_Scroll_Appointment_ViewModel.Date)} >='{demodel.StartTime}'"; } if (!string.IsNullOrEmpty(demodel.EntTime)) { where += $@" and r.{nameof(RB_Scroll_Appointment_ViewModel.Date)} <='{demodel.EntTime} 23:59:59'"; } if (demodel.Q_SelectNormal == 1) { where += $@" and r.{nameof(RB_Scroll_Appointment_ViewModel.State)} <>5"; } string sql = $@" SELECT r.*,c.AccountId as TeacherId,t.TeacherName,t.TeacherHead,s.StuName,cou.CourseName,cou.ScrollMinNum,cou.ScrollMaxNum,cou.CourseTimeId,cr.RoomName,sc.SName as RoomSchoolName From RB_Scroll_Appointment r inner join rb_account c on r.AccountId = c.Id inner join rb_teacher t on c.AccountId = t.TId inner join rb_student s on r.StuId = s.StuId inner join rb_course cou on r.LearnCourseId = cou.CourseId inner join rb_class_room cr on r.RoomId = cr.RoomId left join rb_school sc on sc.SId = cr.School_Id WHERE {where} ORDER BY r.Id desc "; return GetPage(pageIndex, pageSize, out count, sql, parameters).ToList(); } /// /// 获取列表 /// /// /// public List GetAppointList(RB_Scroll_Appointment_ViewModel demodel) { DynamicParameters parameters = new DynamicParameters(); string where = $@" 1=1 and r.{nameof(RB_Scroll_Appointment_ViewModel.Status)} =0 and r.{nameof(RB_Scroll_Appointment_ViewModel.State)} <>5"; if (demodel.Group_Id > 0) { where += $@" and r.{nameof(RB_Scroll_Appointment_ViewModel.Group_Id)} ={demodel.Group_Id}"; } if (demodel.State > 0) { where += $@" and r.{nameof(RB_Scroll_Appointment_ViewModel.State)} ={(int)demodel.State}"; } if (demodel.AccountId > 0) { where += $@" and r.{nameof(RB_Scroll_Appointment_ViewModel.AccountId)} ={demodel.AccountId}"; } if (demodel.TeacherId > 0) { where += $@" and c.AccountId ={demodel.TeacherId}"; } if (demodel.StuId > 0) { where += $@" and r.{nameof(RB_Scroll_Appointment_ViewModel.StuId)} ={demodel.StuId}"; } if (demodel.GuestId > 0) { where += $@" and r.{nameof(RB_Scroll_Appointment_ViewModel.GuestId)} ={demodel.GuestId}"; } if (!string.IsNullOrEmpty(demodel.StuIds)) { where += $@" and r.{nameof(RB_Scroll_Appointment_ViewModel.StuId)} in({demodel.StuIds})"; } if (!string.IsNullOrEmpty(demodel.GuestIds)) { where += $@" and r.{nameof(RB_Scroll_Appointment_ViewModel.GuestId)} in({demodel.GuestIds})"; } if (demodel.CourseId > 0) { where += $@" and r.{nameof(RB_Scroll_Appointment_ViewModel.CourseId)} ={demodel.CourseId}"; } if (demodel.RoomId > 0) { where += $@" and r.{nameof(RB_Scroll_Appointment_ViewModel.RoomId)} ={demodel.RoomId}"; } if (demodel.ChapterNo > 0) { where += $@" and r.{nameof(RB_Scroll_Appointment_ViewModel.ChapterNo)} ={demodel.ChapterNo}"; } if (demodel.CourseGradeId > 0) { where += $@" and r.{nameof(RB_Scroll_Appointment_ViewModel.CourseGradeId)} ={(int)demodel.CourseGradeId}"; } if (demodel.CourseGradeNo > 0) { where += $@" and r.{nameof(RB_Scroll_Appointment_ViewModel.CourseGradeNo)} ={demodel.CourseGradeNo}"; } if (!string.IsNullOrEmpty(demodel.StartTime)) { where += $@" and r.{nameof(RB_Scroll_Appointment_ViewModel.Date)} >='{demodel.StartTime}'"; } if (!string.IsNullOrEmpty(demodel.EntTime)) { where += $@" and r.{nameof(RB_Scroll_Appointment_ViewModel.Date)} <='{demodel.EntTime} 23:59:59'"; } if (!string.IsNullOrEmpty(demodel.AppointIds)) { where += $@" and r.{nameof(RB_Scroll_Appointment_ViewModel.Id)} in({demodel.AppointIds})"; } if (!string.IsNullOrEmpty(demodel.ShiftSort)) { where += $@" and r.{nameof(RB_Scroll_Appointment_ViewModel.ShiftSort)} ='{demodel.ShiftSort}'"; } if (demodel.AppointType > 0) { where += $@" and r.{nameof(RB_Scroll_Appointment_ViewModel.AppointType)} ={demodel.AppointType}"; } if (demodel.Q_AppointState > 0) { if (demodel.Q_AppointState == 1) { where += $@" and r.{nameof(RB_Scroll_Appointment_ViewModel.State)} =1"; } else if (demodel.Q_AppointState == 2) { where += $@" and r.{nameof(RB_Scroll_Appointment_ViewModel.State)} in(2,3,4)"; } } string sql = $@" SELECT r.*,c.AccountId as TeacherId,c.WorkUserId,t.TeacherName,t.TeacherHead,s.StuName,sch.OpenId as StuOpenId,cou.CourseName,cou.ScrollMinNum,cou.ScrollMaxNum,cou.CourseTimeId,cr.RoomName,cr.School_Id as RoomSchoolId,sc.SName as RoomSchoolName ,og.TotalChapterNo From RB_Scroll_Appointment r inner join rb_order_guest og on r.GuestId = og.Id inner join rb_account c on r.AccountId = c.Id inner join rb_teacher t on c.AccountId = t.TId inner join rb_student s on r.StuId = s.StuId inner join rb_account sch on sch.AccountId = s.StuId and sch.AccountType =4 inner join rb_course cou on r.CourseId = cou.CourseId inner join rb_class_room cr on r.RoomId = cr.RoomId left join rb_school sc on sc.SId = cr.School_Id WHERE {where} ORDER BY r.Id desc "; return Get(sql, parameters).ToList(); } /// /// 更新预约章节 /// /// /// /// /// public void UpdateAppointSkipCourse(int stuId, int guestId, int ChapterNum,int SChapterNo, int groupId) { //string sql = $@"UPDATE rb_scroll_appointment SET ChapterNo = ChapterNo +{ChapterNum} WHERE Group_Id ={groupId} and StuId ={stuId} and GuestId ={guestId} "; string sql = $@"UPDATE rb_scroll_appointment a SET a.ChapterNo = a.ChapterNo +{ChapterNum},a.CourseGradeId = (SELECT CourseRate FROM rb_course_chapter c WHERE c.Group_Id ={groupId} and c.CourseId =a.LearnCourseId and c.ChapterNo =a.ChapterNo) ,a.CourseGradeNo = (SELECT ChapterGradeNo FROM rb_course_chapter c WHERE c.Group_Id ={groupId} and c.CourseId =a.LearnCourseId and c.ChapterNo =a.ChapterNo) WHERE a.Group_Id ={groupId} and a.StuId ={stuId} and a.GuestId ={guestId}"; if (SChapterNo > 0) { sql += $@" and a.ChapterNo >={SChapterNo}"; } Execute(sql); } /// /// 获取可重复上课的学员 /// /// /// /// /// /// public List GetCanAppointmentAgainList(string stuName, int courseGradeNo, int courseGradeId, int group_Id) { string sql = $@"SELECT a.Id,a.StuId,a.GuestId,a.OrderId,a.CourseId,s.StuName FROM rb_scroll_appointment a LEFT JOIN rb_student s on a.StuId = s.StuId WHERE a.Group_Id ={group_Id} and a.State =3 and a.AppointType =1 and a.CourseGradeNo ={courseGradeNo} and a.CourseGradeId ={courseGradeId} and s.StuName LIKE '%{stuName}%' ORDER BY a.OrderId DESC"; return Get(sql).ToList(); } } }