using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Edu.Model.Entity.EduTask;
using Edu.Model.ViewModel.Course;
using Edu.Model.ViewModel.EduTask;
using Edu.Model.ViewModel.Grade;
using Edu.Model.ViewModel.Sell;
using Edu.Repository.Grade;
using Edu.Repository.Sell;
using VT.FW.DB;
namespace Edu.Repository.EduTask
{
///
/// 临时上课邀请申请仓储
///
public class RB_Student_TempInvitationRepository : BaseRepository
{
///
/// 教务单据仓储层对象
///
private readonly RB_Education_ReceiptRepository education_ReceiptRepository = new RB_Education_ReceiptRepository();
///
/// 临时上课邀请记录
///
private readonly RB_Temporary_InvitationRepository temporaryInvitationRepository = new RB_Temporary_InvitationRepository();
///
/// 订单学员仓储层对象
///
private readonly RB_Order_GuestRepository order_GuestRepository = new RB_Order_GuestRepository();
///
/// 班级上课计划仓储层对象
///
private readonly RB_Class_PlanRepository class_PlanRepository = new RB_Class_PlanRepository();
///
/// 班级上课计划上课时间仓储层对象
///
private readonly RB_Class_TimeRepository class_TimeRepository = new RB_Class_TimeRepository();
///
/// 获取临时上课邀请申请列表
///
///
///
public List GetStundetTempInvitationListRepository(RB_Student_TempInvitation_ViewModel query)
{
StringBuilder builder = new StringBuilder();
builder.AppendFormat(@"
SELECT A.*,IFNULL(B.ClassName,'') AS ClassName
FROM RB_Student_TempInvitation AS A LEFT JOIN rb_class AS B ON A.ClassId=B.ClassId
WHERE 1=1
");
if (query != null)
{
if (!string.IsNullOrEmpty(query.Q_TempInvitation_Ids))
{
builder.AppendFormat(@" AND A.{0} IN ({1}) ", nameof(RB_Student_TempInvitation_ViewModel.Id), query.Q_TempInvitation_Ids);
}
}
return Get(builder.ToString()).ToList();
}
///
/// 审核通过后更新临时上课记录表
///
///
///
public bool UpdateStundetTempInvitation(object Id)
{
//查询当前调课信息
bool flag = false;
var receiptModel = education_ReceiptRepository.GetEntity(Id);
if (receiptModel == null || receiptModel.Id == 0)
{
return false;
}
if (receiptModel.ReceiptType != Common.Enum.Finance.ReceiptTypeEnum.InvitationClass)
{
return false;
}
var model = GetEntity(receiptModel.RelationId);
if (model == null || model.Id == 0)
{
return false;
}
else //更新学生的信息
{
//学生信息
List orderGuestList = new List();
//班级上课计划列表
List planList = new List();
//班级上课时间列表
List timeList = new List();
string orderGuestIds = model.OrderGuestIds;
if (!string.IsNullOrWhiteSpace(orderGuestIds))
{
orderGuestList = order_GuestRepository.GetStopingStudentPage(new RB_Order_Guest_ViewModel
{
OrderGuestIds = orderGuestIds
});
}
string classTimeIds = model.ClassTimeIds;
if (!string.IsNullOrWhiteSpace(classTimeIds))
{
timeList = class_TimeRepository.GetClassTimeListRepository(new RB_Class_Time_ViewModel { QClassTimeIds = classTimeIds });
if (timeList != null && timeList.Any())
{
string classPlanIds = string.Join(",", timeList.Select(x => x.ClassPlanId));
if (!string.IsNullOrWhiteSpace(classPlanIds))
{
planList = class_PlanRepository.GetClassPlanListRepository(new RB_Class_Plan_ViewModel { QClassPlanIds = classPlanIds });
}
}
}
List tempInvitationList = new List();
foreach (var item in timeList)
{
foreach (var itemGuest in orderGuestList)
{
RB_Temporary_Invitation invitationModel = new RB_Temporary_Invitation()
{
Id = 0,
ClassId = model.ClassId,
Group_Id = model.Group_Id,
School_Id = model.School_Id,
CourseId = model.CourseId,
ClassPlanId = item.ClassPlanId,
ClassTimeId = item.ClassTimeId,
OrderGuestId = itemGuest.Id,
CreateBy = model.CreateBy,
CreateTime = DateTime.Now
};
tempInvitationList.Add(invitationModel);
}
}
if (tempInvitationList!=null&& tempInvitationList.Any())
{
flag = temporaryInvitationRepository.InsertBatch(tempInvitationList);
}
}
return flag;
}
}
}