You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

229 lines
8.5 KiB

  1. using Dapper;
  2. using Learun.DataBase.Repository;
  3. using Learun.Util;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Data;
  7. using System.Linq;
  8. using System.Text;
  9. namespace Learun.Application.TwoDevelopment.EducationalAdministration
  10. {
  11. /// <summary>
  12. /// 版 本 Learun-ADMS-Ultimate V7.0.0 数字化智慧校园
  13. /// Copyright (c) 2013-2018 北京泉江科技有限公司
  14. /// 创 建:超级管理员
  15. /// 日 期:2019-08-26 16:58
  16. /// 描 述:选修合班设置
  17. /// </summary>
  18. public class ElectiveMergeService : RepositoryFactory
  19. {
  20. #region 获取数据
  21. /// <summary>
  22. /// 获取页面显示列表数据
  23. /// <summary>
  24. /// <param name="queryJson">查询参数</param>
  25. /// <returns></returns>
  26. public IEnumerable<ElectiveMergeEntity> GetPageList(Pagination pagination, string queryJson)
  27. {
  28. try
  29. {
  30. var strSql = new StringBuilder();
  31. strSql.Append(@"select distinct a.*,d.StudyScore from ElectiveMerge a left join
  32. ElectiveMergeItem b
  33. on a.EMId = b.EmId left join lessoninfo d on a.LessonId=d.LessonId
  34. ");
  35. strSql.Append(" WHERE 1=1 ");
  36. var queryParam = queryJson.ToJObject();
  37. // 虚拟参数
  38. var dp = new DynamicParameters(new { });
  39. if (!queryParam["AcademicYearNo"].IsEmpty())
  40. {
  41. dp.Add("AcademicYearNo", "" + queryParam["AcademicYearNo"].ToString() + "", DbType.String);
  42. strSql.Append(" AND a.AcademicYearNo =@AcademicYearNo ");
  43. }
  44. if (!queryParam["Semester"].IsEmpty())
  45. {
  46. dp.Add("Semester", "" + queryParam["Semester"].ToString() + "", DbType.String);
  47. strSql.Append(" AND a.Semester = @Semester ");
  48. }
  49. if (!queryParam["LessonName"].IsEmpty())
  50. {
  51. dp.Add("LessonName", "%" + queryParam["LessonName"].ToString() + "%", DbType.String);
  52. strSql.Append(" AND a.LessonName Like @LessonName ");
  53. }
  54. return this.BaseRepository("CollegeMIS").FindList<ElectiveMergeEntity>(strSql.ToString(), dp);
  55. }
  56. catch (Exception ex)
  57. {
  58. if (ex is ExceptionEx)
  59. {
  60. throw;
  61. }
  62. else
  63. {
  64. throw ExceptionEx.ThrowServiceException(ex);
  65. }
  66. }
  67. }
  68. /// <summary>
  69. /// 获取ElectiveMerge表实体数据
  70. /// <param name="keyValue">主键</param>
  71. /// <summary>
  72. /// <returns></returns>
  73. public ElectiveMergeEntity GetElectiveMergeEntity(string keyValue)
  74. {
  75. try
  76. {
  77. var ementity = this.BaseRepository("CollegeMIS").FindEntity<ElectiveMergeEntity>(keyValue);
  78. var stumax = this.BaseRepository("CollegeMIS").FindObject(@"select distinct isnull(c.StuNumMax,0) from ElectiveMerge a left join
  79. ElectiveMergeItem b
  80. on a.EMId = b.EmId left join OpenLessonPlanOfElective c
  81. on b.OLPOEId = c.Id where a.EMId = '"+keyValue+"'");
  82. ementity.StuNumMax = Convert.ToInt32(stumax);
  83. return ementity;
  84. }
  85. catch (Exception ex)
  86. {
  87. if (ex is ExceptionEx)
  88. {
  89. throw;
  90. }
  91. else
  92. {
  93. throw ExceptionEx.ThrowServiceException(ex);
  94. }
  95. }
  96. }
  97. #endregion
  98. #region 提交数据
  99. /// <summary>
  100. /// 删除实体数据
  101. /// <param name="keyValue">主键</param>
  102. /// <summary>
  103. /// <returns></returns>
  104. public void DeleteEntity(string keyValue)
  105. {
  106. var db = this.BaseRepository("CollegeMIS");
  107. try
  108. {
  109. db.BeginTrans();
  110. var deldatalist = db.FindList<ElectiveMergeItemEntity>(m => m.EmId == keyValue).OrderBy(m=>Convert.ToInt32(m.LessonSection));
  111. var deldatafirst = deldatalist.First();
  112. var deldatalast= deldatalist.Last();
  113. var opfirst = db.FindEntity<OpenLessonPlanOfElectiveEntity>(m => m.Id == deldatafirst.OLPOEId);
  114. opfirst.LessonSection = deldatafirst.LessonSection;
  115. opfirst.LessonTime = deldatafirst.LessonTime;
  116. db.Update(opfirst);
  117. db.ExecuteBySql("insert into OpenLessonPlanOfElective select * from OpenLessonPlanOfElectiveDel where id='" + deldatalast.OLPOEId + "'");
  118. db.ExecuteBySql("delete from OpenLessonPlanOfElectiveDel where id='" + deldatalast.OLPOEId + "'");
  119. db.Delete<ElectiveMergeItemEntity>(m => m.EmId == keyValue);
  120. db.Delete<ElectiveMergeEntity>(t => t.EMId == keyValue);
  121. db.Commit();
  122. }
  123. catch (Exception ex)
  124. {
  125. db.Rollback();
  126. if (ex is ExceptionEx)
  127. {
  128. throw;
  129. }
  130. else
  131. {
  132. throw ExceptionEx.ThrowServiceException(ex);
  133. }
  134. }
  135. }
  136. /// <summary>
  137. /// 保存实体数据(新增、修改)
  138. /// <param name="keyValue">主键</param>
  139. /// <summary>
  140. /// <returns></returns>
  141. public void SaveEntity(string keyValue, ElectiveMergeEntity entity, List<ElectiveMergeItemEntity> electiveMergeItemEntity)
  142. {
  143. var db = this.BaseRepository("CollegeMIS");
  144. try
  145. {
  146. if (!string.IsNullOrEmpty(keyValue))
  147. {
  148. entity.Modify(keyValue);
  149. this.BaseRepository("CollegeMIS").Update(entity);
  150. }
  151. else
  152. {
  153. db.BeginTrans();
  154. db.Insert(entity);
  155. db.Insert(electiveMergeItemEntity);
  156. var ids =string.Join(",",electiveMergeItemEntity.Select(n => n.OLPOEId));
  157. var olplist = db.FindList<OpenLessonPlanOfElectiveEntity>(m =>
  158. ids.Contains(m.Id)).OrderBy(c=>Convert.ToInt32(c.LessonSection));
  159. var opfirst = olplist.First();
  160. var oplast = olplist.Last();
  161. opfirst.LessonSection +=","+ oplast.LessonSection;
  162. opfirst.LessonTime += "," + oplast.LessonTime;
  163. db.Update(opfirst);
  164. db.ExecuteBySql("insert into OpenLessonPlanOfElectiveDel select * from OpenLessonPlanOfElective where id='"+ oplast.Id+ "'");
  165. db.Delete(oplast);
  166. db.Commit();
  167. }
  168. }
  169. catch (Exception ex)
  170. {
  171. db.Rollback();
  172. if (ex is ExceptionEx)
  173. {
  174. throw;
  175. }
  176. else
  177. {
  178. throw ExceptionEx.ThrowServiceException(ex);
  179. }
  180. }
  181. }
  182. #endregion
  183. public void SetStuNumMax(string keyValue, int entityStuNumMax)
  184. {
  185. var db = this.BaseRepository("CollegeMIS");
  186. try
  187. {
  188. db.BeginTrans();
  189. var datetimenow = DateTime.Now;
  190. var loginuserinfo = LoginUserInfo.Get();
  191. var olpl = db.FindList<OpenLessonPlanOfElectiveEntity>(@"select c.id from ElectiveMerge a left join
  192. ElectiveMergeItem b
  193. on a.EMId = b.EmId left join OpenLessonPlanOfElective c
  194. on b.OLPOEId = c.Id where a.EMId = '"+ keyValue + "'");
  195. foreach (var opitem in olpl)
  196. {
  197. opitem.StuNumMax = entityStuNumMax;
  198. opitem.ModifyTime = datetimenow;
  199. opitem.ModifyUserId = loginuserinfo.userId;
  200. opitem.ModifyUserName = loginuserinfo.realName;
  201. db.Update(opitem);
  202. }
  203. db.Commit();
  204. }
  205. catch (Exception ex)
  206. {
  207. db.Rollback();
  208. if (ex is ExceptionEx)
  209. {
  210. throw;
  211. }
  212. else
  213. {
  214. throw ExceptionEx.ThrowServiceException(ex);
  215. }
  216. }
  217. }
  218. }
  219. }