builder.AppendFormat(" AND {0}={1} ",nameof(RB_Class_LessonComment_ViewModel.ClassId),query.ClassId);
}
if(query.ClassPlanId>0)
if(query.ClassPlanId>0&&query.ClassDate.HasValue)
{
builder.AppendFormat(" AND ({0}={1} or DATE_FORMAT({2},'%y/%m/%d')= DATE_FORMAT('{3}','%y/%m/%d'))",nameof(RB_Class_LessonComment_ViewModel.ClassPlanId),query.ClassPlanId,nameof(RB_Class_LessonComment_ViewModel.ClassDate),query.ClassDate.Value);
}
elseif(query.ClassPlanId>0)
{
builder.AppendFormat(" AND {0}={1} ",nameof(RB_Class_LessonComment_ViewModel.ClassPlanId),query.ClassPlanId);
builder.AppendFormat(" AND {0}={1} ",nameof(RB_Class_LessonPlan.ClassId),query.ClassId);
}
if(query.ClassPlanId>0)
if(query.ClassPlanId>0&&query.ClassDate.HasValue)
{
builder.AppendFormat(" AND ({0}={1} or DATE_FORMAT({2},'%y/%m/%d')= DATE_FORMAT('{3}','%y/%m/%d'))",nameof(RB_Class_LessonPlan.ClassPlanId),query.ClassPlanId,nameof(RB_Class_LessonPlan.ClassDate),query.ClassDate.Value);
}
elseif(query.ClassPlanId>0)
{
builder.AppendFormat(" AND {0}={1} ",nameof(RB_Class_LessonPlan.ClassPlanId),query.ClassPlanId);
}
if(query.IsTemplate>-1)
{
builder.AppendFormat(" AND {0}={1} ",nameof(RB_Class_LessonPlan.IsTemplate),query.IsTemplate);
FROM RB_Order_Guest AS A LEFT JOIN rb_order AS B ON A.OrderId=B.OrderId
LEFT JOIN rb_course AS C ON (B.CourseId=C.CourseId AND B.CourseId>0 AND B.OrderType=1)
LEFT JOIN (SELECT OrderGuestId,MAX(TakeEffectTime) as StopClassEffectTime from rb_student_stopclass where IsAuditThrough=1 GROUP BY OrderGuestId) as sc on sc.OrderGuestId=a.Id
WHERE {where}";
LEFT JOIN rb_course AS C ON (B.CourseId=C.CourseId AND B.CourseId>0 AND B.OrderType=1) WHERE {where}";
SELECT A.*,IFNULL(B.IsChaBan,0) AS IsChaBan,IFNULL(B.StartClassHours,0) AS StartClassHours,school.SName as SchoolName,teacher.TeacherName,IFNULL(C.CourseName,'') AS CourseName,class.ClassNo,class.ClassName,b.EnterID
FROM RB_Order_Guest AS A LEFT JOIN rb_order AS B ON A.OrderId=B.OrderId
LEFT JOIN rb_class as class on class.ClassId=a.ClassId
LEFT JOIN rb_course AS C ON (B.CourseId=C.CourseId AND B.CourseId>0 AND B.OrderType=1)
LEFT JOIN (SELECT ClassId,COUNT(*) TotalPlanNum from rb_class_plan where `Status`=0 GROUP BY ClassId) as plan on plan.ClassId=class.ClassId
LEFT JOIN (SELECT ClassId,COUNT(*) Ranks from rb_class_plan where `Status`=0 and DATE_FORMAT(ClassDate,'%Y-%m-%d') <=DATE_FORMAT(NOW(),'%Y-%m-%d') GROUP BY ClassId) as planr on planr.ClassId=class.ClassId
LEFT JOIN rb_teacher as teacher on teacher.TId=class.Teacher_Id
LEFT JOIN rb_school as school on school.SId=class.School_Id
WHERE 1=1 and A.Status=0 and class.Status=0 and b.OrderState<>3 and a.GuestState in(1,6) ");
if(demodel.Group_Id>0)
{
builder.AppendFormat($@" AND A.{nameof(RB_Order_Guest_ViewModel.Group_Id)} ={demodel.Group_Id}");
}
if(demodel.School_Id>0)
{
builder.AppendFormat($@" AND A.{nameof(RB_Order_Guest_ViewModel.School_Id)} ={demodel.School_Id}");
}
if(demodel.OrderId>0)
{
builder.AppendFormat($@" AND A.{nameof(RB_Order_Guest_ViewModel.OrderId)} ={demodel.OrderId}");
}
if(demodel.Teacher_Id>0)
{
builder.AppendFormat($@" and class.Teacher_Id ={demodel.Teacher_Id}");
}
if(!string.IsNullOrEmpty(demodel.GuestName))
{
builder.AppendFormat($@" AND A.{nameof(RB_Order_Guest_ViewModel.GuestName)} like '%{demodel.GuestName}%'");
}
if(demodel.ClassId>0)
{
builder.AppendFormat($@" AND A.{nameof(RB_Order_Guest_ViewModel.ClassId)} !={demodel.ClassId}");
}
if(demodel.CourseId>0)
{
builder.AppendFormat($@" AND B.{nameof(RB_Order_Guest_ViewModel.CourseId)} ={demodel.CourseId}");
}
if(demodel.EnterID>0)
{
builder.AppendFormat($@" AND B.{nameof(RB_Order_Guest_ViewModel.EnterID)} ={demodel.EnterID}");
}
if(demodel.SourceId>0)
{
builder.AppendFormat($@" AND A.{nameof(RB_Order_Guest_ViewModel.SourceId)} ={demodel.SourceId}");
FROM RB_Order_Guest AS A LEFT JOIN rb_order AS B ON A.OrderId=B.OrderId
LEFT JOIN rb_course AS C ON (B.CourseId=C.CourseId AND B.CourseId>0 AND B.OrderType=1)
LEFT JOIN (SELECT OrderGuestId,MAX(TakeEffectTime) as StopClassEffectTime from rb_student_stopclass where IsAuditThrough=1 GROUP BY OrderGuestId) as sc on sc.OrderGuestId=a.Id