SELECT plan.TotalPlanNum,ySplan.UsePlanNum,A.*,B.CourseName,C.AssistName,IFNULL(C.AssistIcon,'') AS AssistIcon,D.TeacherName,IFNULL(D.TeacherHead,'') AS TeacherHead
,E.SName AS SchoolName,IFNULL(F.RoomName,'') AS RoomName
FROM rb_class AS A LEFT JOIN rb_course AS B ON A.CouseId=B.CourseId
LEFT JOIN rb_assist AS C ON A.Assist_Id=C.AId
LEFT JOIN rb_teacher AS D ON A.Teacher_Id=D.TId
LEFT JOIN rb_school AS E ON A.School_Id=E.SId
LEFT JOIN rb_class_room AS F ON A.ClassRoomId=F.RoomId
LEFT JOIN ((SELECT ClassId,COUNT(*) as TotalPlanNum from rb_class_plan where `Status`=0 GROUP BY ClassId)) as plan on plan.ClassId=a.ClassId
LEFT JOIN ((SELECT ClassId,COUNT(*) as UsePlanNum from rb_class_plan where `Status`=0 and DATE_FORMAT(ClassDate,'%Y-%m-%d') <=DATE_FORMAT(NOW(),'%Y-%m-%d') GROUP BY ClassId)) as ySplan on ySplan.ClassId=a.ClassId
WHERE 1=1 ");
if(query!=null)
{
if(query.Group_Id>0)
{
builder.AppendFormat(" AND A.{0}={1} ",nameof(RB_Class_ViewModel.Group_Id),query.Group_Id);
}
if(query.School_Id>0)
{
builder.AppendFormat(" AND A.{0}={1} ",nameof(RB_Class_ViewModel.School_Id),query.School_Id);
}
if(query.Status>=0)
{
builder.AppendFormat(" AND A.{0}={1} ",nameof(RB_Class_ViewModel.Status),(int)query.Status);
}
if(query.ClassStatus>0)
{
builder.AppendFormat(" AND A.{0}={1} ",nameof(RB_Class_ViewModel.ClassStatus),(int)query.ClassStatus);
}
if(!string.IsNullOrWhiteSpace(query.ClassName))
{
builder.AppendFormat(" AND A.{0} LIKE @ClassName ",nameof(RB_Class_ViewModel.ClassName));
,SUM(A.minNum) AS ClassMinutes,MIN(A.StartTime) AS StartTime,MAX(A.EndTime) AS EndTime,A.CompleteProgress
,SUM(A.minNum) AS ClassMinutes,MIN(A.StartTime) AS StartTime,MAX(A.EndTime) AS EndTime,A.CompleteProgress,a.TotalPlanNum,
(SELECT COUNT(*) from rb_class_plan where `Status`=0 and DATE_FORMAT(ClassDate,'%Y-%m-%d') <=DATE_FORMAT(a.ClassDate,'%Y-%m-%d') and ClassId=a.ClassId) as Ranks
FROM
(
SELECT A.ClassPlanId, A.ClassId,A.ClassDate,A.ClassRoomId,B.ClassName,C.CourseName,B.Teacher_Id,IFNULL(D.TeacherName,'') AS TeacherName,E.RoomName
,TIMESTAMPDIFF(MINUTE, CONCAT('2020-12-16',' ',F.StartTime), CONCAT('2020-12-16',' ',F.EndTime)) AS minNum,F.StartTime,F.EndTime,B.CompleteProgress
,TIMESTAMPDIFF(MINUTE, CONCAT('2020-12-16',' ',F.StartTime), CONCAT('2020-12-16',' ',F.EndTime)) AS minNum,F.StartTime,F.EndTime,B.CompleteProgress,plan.TotalPlanNum
FROM rb_class_plan AS A INNER JOIN rb_class AS B ON A.ClassId=B.ClassId
LEFT JOIN rb_course AS C ON B.CouseId=C.CourseId
LEFT JOIN rb_teacher AS D ON B.Teacher_Id=D.TId
LEFT JOIN rb_class_room AS E ON A.ClassRoomId=E.RoomId
LEFT JOIN rb_class_time F on A.ClassPlanId = F.ClassPlanId
LEFT JOIN ((SELECT ClassId,COUNT(*) as TotalPlanNum from rb_class_plan where `Status`=0 GROUP BY ClassId)) as plan on plan.ClassId=a.ClassId
WHERE 1=1 AND A.`Status`=0 {0}
) AS A
GROUP BY A.ClassPlanId,A.ClassId ,A.ClassDate,A.ClassRoomId,A.CompleteProgress