using Edu.Common.Plugin;
using Edu.Model.ViewModel.Scroll;
using Edu.Model.ViewModel.User;
using Edu.Repository.Scroll;
using Edu.Repository.User;
using Senparc.Weixin.Annotations;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using VT.FW.DB;
namespace Edu.Module.Course
{
///
/// 学员预约处理类
///
public class PlanAppoimentModule
{
///
/// 学员预约仓储层
///
private readonly RB_Plan_AppointmentRepository plan_AppointmentRepository = new RB_Plan_AppointmentRepository();
///
/// 学员预约详情仓储层
///
private readonly RB_Plan_Appointment_DetailsRepository plan_Appointment_DetailsRepository = new RB_Plan_Appointment_DetailsRepository();
///
/// 字典仓储层对象
///
private readonly Rb_dictvalueRepository dictvalueRepository = new Rb_dictvalueRepository();
///
/// 上课时段
///
private readonly RB_Scroll_CourseTimeRepository scroll_CourseTimeRepository = new RB_Scroll_CourseTimeRepository();
///
/// 获取上课时段列表
///
///
///
public List GetScrollCourseTimeList(int group_Id)
{
List timeList = new List();
var list = scroll_CourseTimeRepository.GetList(new RB_Scroll_CourseTime_ViewModel() { Group_Id = group_Id });
foreach (var item in list.Where(qitem=>qitem.Id==1))
{
item.TimeList = new List();
if (!string.IsNullOrEmpty(item.Content))
{
timeList = JsonHelper.DeserializeObject>(item.Content);
}
}
if (timeList == null || (timeList != null && timeList.Count <= 0))
{
timeList.Add(new CourseTimeModel()
{
StartTime = "09:30",
EndTime = "11:00",
Sort = 1
});
timeList.Add(new CourseTimeModel()
{
StartTime = "11:10",
EndTime = "12:40",
Sort = 2
});
timeList.Add(new CourseTimeModel()
{
StartTime = "13:30",
EndTime = "15:00",
Sort = 3
});
timeList.Add(new CourseTimeModel()
{
StartTime = "15:10",
EndTime = "16:40",
Sort = 4
});
timeList.Add(new CourseTimeModel()
{
StartTime = "16:50",
EndTime = "18:20",
Sort = 5
});
timeList.Add(new CourseTimeModel()
{
StartTime = "19:00",
EndTime = "20:30",
Sort = 6
});
}
return timeList;
}
///
/// 获取学员预约列表
///
///
///
public List GetPlanAppointmentListModule(RB_Plan_Appointment_ViewModel query)
{
return plan_AppointmentRepository.GetPlanAppointmentListRepository(query);
}
///
/// 获取学员预约详情列表
///
///
///
public List GetPlanAppointmentDetailsListModule(RB_Plan_Appointment_Details_ViewModel query)
{
return plan_Appointment_DetailsRepository.GetPlanAppointmentDetailsListRepository(query);
}
///
/// 获取学员预约截止日期配置
///
///
///
public RB_Dictvalue_Extend GetPlanAppointmentConfigModule(RB_Dictvalue_Extend query)
{
var model = dictvalueRepository.GetList(query)?.FirstOrDefault();
return model;
}
///
/// 新增修改学员预约配置
///
///
///
public bool SetPlanAppointmentConfigModule(RB_Dictvalue_Extend model)
{
bool flag = false;
if (model.ID > 0)
{
Dictionary fileds = new Dictionary()
{
{nameof(RB_Dictvalue_Extend.Code),model.Code }
};
flag = dictvalueRepository.Update(fileds, new WhereHelper(nameof(RB_Dictvalue_Extend.ID), model.ID));
}
else
{
var newId = dictvalueRepository.Insert(model);
model.ID = newId;
flag = newId > 0;
}
return flag;
}
///
/// 新增修改学员预约
///
///
///
public bool SetPlanAppointmentModule(RB_Plan_Appointment_ViewModel model)
{
bool flag = false;
var oldModel = GetPlanAppointmentListModule(new RB_Plan_Appointment_ViewModel()
{
QDate = Common.ConvertHelper.FormatDate(model.Date),
})?.Where(qitem => qitem.StartTime == model.StartTime && qitem.EndTime == model.EndTime)?.FirstOrDefault();
model.Id = oldModel?.Id ?? 0;
if (model.Id > 0)
{
Dictionary fileds = new Dictionary()
{
{nameof(RB_Plan_Appointment_ViewModel.Group_Id),model.Group_Id },
};
flag = plan_AppointmentRepository.Update(fileds, new WhereHelper(nameof(RB_Plan_Appointment_ViewModel.Id), model.Id));
}
else
{
var newId = plan_AppointmentRepository.Insert(model);
model.Id = newId;
flag = newId > 0;
}
var oldList = GetPlanAppointmentDetailsListModule(new RB_Plan_Appointment_Details_ViewModel()
{
PlanAppointmentId = model.Id
});
if (model.DetailsList != null && model.DetailsList.Count > 0)
{
foreach (var item in model.DetailsList)
{
var oldDetailModel = oldList?.Where(qitem => qitem.Status == 0 && qitem.StuId == item.StuId)?.FirstOrDefault();
item.DetailsId = oldDetailModel?.DetailsId ?? 0;
item.PlanAppointmentId = model.Id;
if (item.DetailsId > 0)
{
plan_Appointment_DetailsRepository.Update(item);
}
else
{
plan_Appointment_DetailsRepository.Insert(item);
}
}
}
return flag;
}
///
/// 学员根据编号删除预约信息
///
///
///
public bool RemovePlanAppointmentModule(int DetailsId)
{
Dictionary fileds = new Dictionary()
{
{nameof(RB_Plan_Appointment_Details_ViewModel.Status),1 }
};
bool flag = plan_Appointment_DetailsRepository.Update(fileds, new WhereHelper(nameof(RB_Plan_Appointment_Details_ViewModel.DetailsId), DetailsId));
return flag;
}
///
/// 获取学员预约列表
///
///
///
public List GetPlanAppointmentStatic(RB_Plan_Appointment_Details_ViewModel query)
{
return plan_Appointment_DetailsRepository.GetPlanAppointmentStaticRepository(query);
}
///
/// 小程序学员预约记录统计
///
///
///
public List