|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448 |
- using Dapper;
- using Learun.DataBase.Repository;
- using Learun.Util;
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Linq;
- using System.Text;
-
- namespace Learun.Application.TwoDevelopment.EducationalAdministration
- {
- /// <summary>
- /// 版 本 Learun-ADMS V7.0.6 力软敏捷开发框架
- /// Copyright (c) 2013-2020 力软信息技术(苏州)有限公司
- /// 创 建:超级管理员
- /// 日 期:2023-05-29 14:28
- /// 描 述:线上课程
- /// </summary>
- public class LessonInfoOfElectiveOnlineService : RepositoryFactory
- {
- #region 获取数据
-
- /// <summary>
- /// 获取页面显示列表数据
- /// </summary>
- /// <param name="pagination">查询参数</param>
- /// <param name="queryJson">查询参数</param>
- /// <returns></returns>
- public IEnumerable<LessonInfoOfElectiveOnlineEntity> GetPageList(Pagination pagination, string queryJson)
- {
- try
- {
- var strSql = new StringBuilder();
- strSql.Append("SELECT t.* ");
- strSql.Append(" FROM LessonInfoOfElectiveOnline t ");
- strSql.Append(" WHERE 1=1 ");
- var queryParam = queryJson.ToJObject();
- // 虚拟参数
- var dp = new DynamicParameters(new { });
- if (!queryParam["LessonNo"].IsEmpty())
- {
- dp.Add("LessonNo", "%" + queryParam["LessonNo"].ToString() + "%", DbType.String);
- strSql.Append(" AND t.LessonNo Like @LessonNo ");
- }
- if (!queryParam["LessonName"].IsEmpty())
- {
- dp.Add("LessonName", "%" + queryParam["LessonName"].ToString() + "%", DbType.String);
- strSql.Append(" AND t.LessonName Like @LessonName ");
- }
- if (!queryParam["AcademicYearNo"].IsEmpty())
- {
- dp.Add("AcademicYearNo", queryParam["AcademicYearNo"].ToString(), DbType.String);
- strSql.Append(" AND t.AcademicYearNo = @AcademicYearNo ");
- }
- if (!queryParam["Semester"].IsEmpty())
- {
- dp.Add("Semester", queryParam["Semester"].ToString(), DbType.String);
- strSql.Append(" AND t.Semester = @Semester ");
- }
- if (!queryParam["EmpNo"].IsEmpty())
- {
- dp.Add("EmpNo", queryParam["EmpNo"].ToString(), DbType.String);
- strSql.Append(" AND t.EmpNo = @EmpNo ");
- }
- if (!queryParam["CheckMark"].IsEmpty())
- {
- dp.Add("CheckMark", queryParam["CheckMark"].ToString(), DbType.String);
- strSql.Append(" AND t.CheckMark = @CheckMark ");
- }
- var list = new List<LessonInfoOfElectiveOnlineEntity>();
- list = this.BaseRepository("CollegeMIS").FindList<LessonInfoOfElectiveOnlineEntity>(strSql.ToString(), dp, pagination).ToList();
-
- //选课专业
- var majorSql = @"SELECT t.MajorName,t.MajorNo,a.* FROM ElectiveMajorOnline a left join CdMajor t on a.majorid=t.id";
- var electiveMajorOnlineList = this.BaseRepository("CollegeMIS").FindList<ElectiveMajorOnlineEntity>(majorSql);
- foreach (var item in list)
- {
- //模式二:正式选课
- var aa = this.BaseRepository("CollegeMIS").FindList<StuSelectLessonListOfElectiveOnlineEntity>(x => x.LIOEOId == item.Id);
- //已报名人数
- item.StuNumOfApply = aa.Where(x => (x.Status == 1 || x.Status == 2)).Count();
- //审核通过人数
- item.StuNum = aa.Where(x => x.Status == 2).Count();
- //选课专业
- item.ElectiveMajorOnlineList = electiveMajorOnlineList.Where(x => x.LIOEOId == item.Id).ToList();
- }
- return list;
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowServiceException(ex);
- }
- }
- }
-
- /// <summary>
- /// 获取LessonInfoOfElectiveOnline表实体数据
- /// </summary>
- /// <param name="keyValue">主键</param>
- /// <returns></returns>
- public LessonInfoOfElectiveOnlineEntity GetLessonInfoOfElectiveOnlineEntity(string keyValue)
- {
- try
- {
- var opeentity = BaseRepository("CollegeMIS").FindEntity<LessonInfoOfElectiveOnlineEntity>(keyValue);
- if (opeentity != null)
- {
- //模式二:正式选课
- var aa = this.BaseRepository("CollegeMIS").FindList<StuSelectLessonListOfElectiveOnlineEntity>(x => x.LIOEOId == opeentity.Id);
- //已报名人数
- opeentity.StuNumOfApply = aa.Where(x => (x.Status == 1 || x.Status == 2)).Count();
- }
- return opeentity;
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowServiceException(ex);
- }
- }
- }
-
- /// <summary>
- /// 获取LessonInfoOfElectiveOnline表实体数据
- /// </summary>
- /// <param name="keyValue">主键</param>
- /// <returns></returns>
- public LessonInfoOfElectiveOnlineEntity GetLessonInfoOfElectiveOnlineEntityByLessonNo(string lessonNo)
- {
- try
- {
- return BaseRepository("CollegeMIS").FindEntity<LessonInfoOfElectiveOnlineEntity>(x => x.LessonNo == lessonNo);
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowServiceException(ex);
- }
- }
- }
-
- /// <summary>
- /// 获取页面显示列表数据【学子在线-线上课程选课】
- /// <summary>
- /// <param name="queryJson">查询参数</param>
- /// <returns></returns>
- public IEnumerable<LessonInfoOfElectiveOnlineEntity> GetPageListOfStudent(Pagination pagination, string queryJson)
- {
- try
- {
- var queryParam = queryJson.ToJObject();
- // 虚拟参数
- var dp = new DynamicParameters(new { });
- //学号
- if (!queryParam["StuNo"].IsEmpty())
- {
- dp.Add("StuNo", queryParam["StuNo"].ToString(), DbType.String);
- }
- //教学工作安排中“线上选课”工作设置的学年学期
- var now = DateTime.Now;
- var EADateArrangeEntityAboutElective = this.BaseRepository("CollegeMIS").FindEntity<EADateArrangeEntity>(x => x.WorkName == "线上选课" && x.MakeDate <= now && x.EndDate >= now && x.CheckMark == "1");
- if (EADateArrangeEntityAboutElective == null)
- {
- return new List<LessonInfoOfElectiveOnlineEntity>();
- }
-
- var strSql = new StringBuilder();
- strSql.Append(@"select b.*,c.StuNo,c.StuName,c.Status,a.Id as ElectiveMajorOnlineId,a.MajorId,a.Grade from LessonInfoOfElectiveOnline b
- left join StuSelectLessonListOfElectiveOnline c on b.Id=c.LIOEOId and c.StuNo=@StuNo
- left join ElectiveMajorOnline a on a.LIOEOId=b.Id
- where not exists ( ");
- //不显示与已选课程 相同课程名称相同教师的课程
- strSql.Append(" select * from StuSelectLessonListOfElectiveOnline s where s.AcademicYearNo='" + EADateArrangeEntityAboutElective?.AcademicYearNo + "' and s.Semester='" + EADateArrangeEntityAboutElective.Semester + "' and s.StuNo=@StuNo and s.Status <>3 and s.LessonName=b.LessonName and s.EmpNo=b.EmpNo and s.LIOEOId!=b.Id ");
- strSql.Append(" ) ");
- strSql.Append(" AND b.CheckMark='1' ");
- strSql.Append(" AND b.AcademicYearNo='" + EADateArrangeEntityAboutElective?.AcademicYearNo + "' and b.Semester='" + EADateArrangeEntityAboutElective?.Semester + "' ");
- //学生选课显示‘是否可选’为‘是’的课程信息
- strSql.Append(" and b.IsAllowSelect=1 ");
- //管理选课专业可以为空
- if (!queryParam["StuMajorNo"].IsEmpty())
- {
- dp.Add("StuMajorNo", queryParam["StuMajorNo"].ToString(), DbType.String);
- strSql.Append(" and (a.MajorId is null or a.MajorId = @StuMajorNo ) ");
- }
- else
- {
- strSql.Append(" and a.MajorId is null ");
- }
- if (!queryParam["StuGrade"].IsEmpty())
- {
- dp.Add("StuGrade", queryParam["StuGrade"].ToString(), DbType.String);
- strSql.Append(" and (a.Grade is null or a.Grade = @StuGrade) ");
- }
- else
- {
- strSql.Append(" and a.Grade is null ");
- }
-
- if (!queryParam["LessonNo"].IsEmpty())
- {
- dp.Add("LessonNo", "%" + queryParam["LessonNo"].ToString() + "%", DbType.String);
- strSql.Append(" AND b.LessonNo like @LessonNo ");
- }
- if (!queryParam["LessonName"].IsEmpty())
- {
- dp.Add("LessonName", "%" + queryParam["LessonName"].ToString() + "%", DbType.String);
- strSql.Append(" AND b.LessonName Like @LessonName ");
- }
- var list = this.BaseRepository("CollegeMIS").FindList<LessonInfoOfElectiveOnlineEntity>(strSql.ToString(), dp, pagination);
- foreach (var item in list)
- {
- //模式二:正式选课
- var aa = this.BaseRepository("CollegeMIS").FindList<StuSelectLessonListOfElectiveOnlineEntity>(x => x.LIOEOId == item.Id);
- //已报名人数
- item.StuNumOfApply = aa.Where(x => (x.Status == 1 || x.Status == 2)).Count();
-
- }
- return list;
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowServiceException(ex);
- }
- }
- }
-
- #endregion
-
- #region 提交数据
-
- /// <summary>
- /// 删除实体数据
- /// </summary>
- /// <param name="keyValue">主键</param>
- public void DeleteEntity(string keyValue)
- {
- var db = this.BaseRepository("CollegeMIS").BeginTrans();
- try
- {
- //单个删除
- //this.BaseRepository("CollegeMIS").Delete<LessonInfoOfElectiveOnlineEntity>(t => t.Id == keyValue);
-
- //批量删除
- foreach (var item in keyValue.Split(','))
- {
- //删除选课专业
- db.ExecuteBySql($"delete from ElectiveMajorOnline where LIOEOId='{item}'");
- //删除选修课课程表
- db.ExecuteBySql($"delete from LessonInfoOfElectiveOnline where Id='{item}'");
- }
-
- db.Commit();
- }
- catch (Exception ex)
- {
- db.Rollback();
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowServiceException(ex);
- }
- }
- }
-
- /// <summary>
- /// 保存实体数据(新增、修改)
- /// </summary>
- /// <param name="keyValue">主键</param>
- /// <param name="entity">实体</param>
- public void SaveEntity(string keyValue, LessonInfoOfElectiveOnlineEntity entity)
- {
- try
- {
- if (!string.IsNullOrEmpty(keyValue))
- {
- entity.Modify(keyValue);
- this.BaseRepository("CollegeMIS").Update(entity);
- }
- else
- {
- entity.Create();
- this.BaseRepository("CollegeMIS").Insert(entity);
- }
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowServiceException(ex);
- }
- }
- }
-
- #endregion
-
- #region 扩展数据
-
- /// <summary>
- /// 启用/停用实体数据
- /// </summary>
- /// <param name="keyValue">主键</param>
- public void DoLock(string keyValue, string status)
- {
- try
- {
- //单个启用
- //this.BaseRepository("CollegeMIS").ExecuteBySql($"update LessonInfoOfElectiveOnline set CheckMark='{status}' where Id='{keyValue}' ");
-
- if (keyValue.Contains(","))
- {
- keyValue = string.Join("','", keyValue.Split(','));
- }
-
- string sql = $"update LessonInfoOfElectiveOnline set CheckMark='{status}' where Id in ('{keyValue}')";
- this.BaseRepository("CollegeMIS").ExecuteBySql(sql);
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowServiceException(ex);
- }
- }
- }
-
- /// <summary>
- /// 设置可选/取消可选
- /// </summary>
- /// <param name="keyValue"></param>
- /// <param name="IsAllowSelect"></param>
- public void SetUpIsAllowSelect(string keyValue, int IsAllowSelect)
- {
- try
- {
- if (keyValue.Contains(","))
- {
- keyValue = string.Join("','", keyValue.Split(','));
- }
-
- string sql = $"update LessonInfoOfElectiveOnline set IsAllowSelect='{IsAllowSelect}' where Id in ('{keyValue}')";
- this.BaseRepository("CollegeMIS").ExecuteBySql(sql);
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowServiceException(ex);
- }
- }
- }
-
- /// <summary>
- /// 批量设置人数
- /// </summary>
- /// <param name="keyValue"></param>
- /// <param name="StuNumMax"></param>
- public void SaveStuNumMax(string keyValue, int StuNumMax)
- {
- try
- {
- if (keyValue.Contains(","))
- {
- keyValue = string.Join("','", keyValue.Split(','));
- }
- this.BaseRepository("CollegeMIS").ExecuteBySql($"update LessonInfoOfElectiveOnline set StuNumMax='{StuNumMax}' where Id in ('{keyValue}')");
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowServiceException(ex);
- }
- }
- }
-
- /// <summary>
- /// 获取选课时间管理
- /// </summary>
- /// <returns></returns>
- public EADateArrangeEntity GetEADateArrangeEntityAboutElective()
- {
- try
- {
- var semesterAndYear = Common.GetSemesterAndYear();
- var strAcademicYear = semesterAndYear.AcademicYearShort;
- var strSemester = semesterAndYear.Semester;
- var now = DateTime.Now;
- //不判断学年学期
- return this.BaseRepository("CollegeMIS").FindEntity<EADateArrangeEntity>(x => x.WorkName == "线上选课" && x.MakeDate <= now && x.EndDate >= now && x.CheckMark == "1");
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowServiceException(ex);
- }
- }
- }
-
- #endregion
-
- }
- }
|