//sql=sqlSelect+sqlFrom+sqlWhere+sqlOrder
string sql = string.Empty;
string sqlSelect = "SELECT cc.ClassId,cc.ClassName,cp.CourseName,pp.Title,pp.ReleaseTime,pp.IsPublic,pp.id as preparationId,cu.id as UnitId,cp.id as PackId,pp.ExamId,pp.IsPractice,pp.ExamId ";//查询列
//数据来源
string sqlFrom = @"from yk_preparation pp -- 课程备课
join yk_courseunit cu on pp.CoureUnitId=cu.id -- 课程单元
join yk_coursepack cp on cu.CoursePackId=cp.id -- 课程包
left join yk_courseclass cc on cc.CoursePackId=cp.Id ";
StringBuilder sqlWhere = new StringBuilder();//查询条件
string sqlOrder = string.Empty;//排序
string sqlCount = string.Empty;//查询总记录数
sqlWhere.Append("where pp.`Status` = 0 and cu.`Status` = 0 ");
sqlWhere.Append("and cp.TeacherId = @0 ");//当前老师
sqlWhere.Append("and cp.Term = @8 ");//当前学期
//课程名称
if(coursePackId>0)
sqlWhere.Append("and cp.id [email protected] ");
//课程单元
if (unitId>0)
sqlWhere.Append("and cu.id [email protected] ");
//是否分享 (-1:全部,0:不共享,1:共享)
//if(isPublic >=0)
// sqlWhere.Append("and pp.IsPublic = @3 ");
//发布日期
sqlWhere.Append("and pp.ReleaseTime between @4 and @5 ");
sqlOrder="ORDER BY pp.ReleaseTime DESC ";
sql = sqlSelect + sqlFrom + sqlWhere.ToString() + sqlOrder + "limit @6,@7 ";
sqlCount = @"select count(pp.id) "+sqlFrom+sqlWhere.ToString();
int pageStart = (pageIndex - 1) * pageSize;
List<PreparationModel> list = _content.FindPage<PreparationModel>(sql, sqlCount, pageIndex, pageSize, out totalCount, teacherId, coursePackId, unitId, isPublic, publishDateStart, publishDateEnd, pageStart, pageSize,termId);
return list;