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.
 
 
 
 
 
 

261 lines
8.7 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 V7.0.6 力软敏捷开发框架
  13. /// Copyright (c) 2013-2020 力软信息技术(苏州)有限公司
  14. /// 创 建:超级管理员
  15. /// 日 期:2021-10-14 10:09
  16. /// 描 述:教学计划
  17. /// </summary>
  18. public class TeachingPlanService : RepositoryFactory
  19. {
  20. #region 获取数据
  21. /// <summary>
  22. /// 获取页面显示列表数据
  23. /// </summary>
  24. /// <param name="pagination">查询参数</param>
  25. /// <param name="queryJson">查询参数</param>
  26. /// <returns></returns>
  27. public IEnumerable<TeachingPlanEntity> GetPageList(Pagination pagination, string queryJson)
  28. {
  29. try
  30. {
  31. var strSql = new StringBuilder();
  32. strSql.Append("SELECT t.* ");
  33. strSql.Append(" FROM TeachingPlan t ");
  34. strSql.Append(" WHERE 1=1 ");
  35. var queryParam = queryJson.ToJObject();
  36. // 虚拟参数
  37. var dp = new DynamicParameters(new { });
  38. if (!queryParam["Name"].IsEmpty())
  39. {
  40. dp.Add("Name", "%" + queryParam["Name"].ToString() + "%", DbType.String);
  41. strSql.Append(" AND t.Name Like @Name ");
  42. }
  43. return this.BaseRepository("CollegeMIS").FindList<TeachingPlanEntity>(strSql.ToString(), dp, pagination);
  44. }
  45. catch (Exception ex)
  46. {
  47. if (ex is ExceptionEx)
  48. {
  49. throw;
  50. }
  51. else
  52. {
  53. throw ExceptionEx.ThrowServiceException(ex);
  54. }
  55. }
  56. }
  57. public IEnumerable<TeachingPlanEntity> GetPageListForManage(Pagination pagination, string queryJson)
  58. {
  59. try
  60. {
  61. string sql = "select * from TeachingPlan ";
  62. var dp = new DynamicParameters(new { });
  63. var list = this.BaseRepository("CollegeMIS").FindList<TeachingPlanEntity>(sql, dp, pagination);
  64. string tsql = @"select t.*,c.LessonTypeName from
  65. (select t.Major,b.LessonTypeId,count(1) as num from TeachingPlan t
  66. join TeachingPlanItem a on t.Id=a.TeachingPlanId
  67. join LessonInfo b on a.LessonNo=b.LessonNo
  68. group by b.LessonTypeId,t.Major) t
  69. join CdLessonType c on t.LessonTypeId=c.ltid ";
  70. var lessonList = this.BaseRepository("CollegeMIS").FindList<LessonData>(tsql);
  71. foreach (var item in list)
  72. {
  73. var lessonData = lessonList.Where(x => x.Major == item.Major);
  74. foreach (var lesson in lessonData)
  75. {
  76. if (lesson.LessonTypeName.Contains("专业课"))
  77. {
  78. item.Zyknum = lesson.num;
  79. }
  80. else if (lesson.LessonTypeName.Contains("公开课"))
  81. {
  82. item.Ggknum = lesson.num;
  83. }
  84. }
  85. }
  86. return list;
  87. }
  88. catch (Exception ex)
  89. {
  90. if (ex is ExceptionEx)
  91. {
  92. throw;
  93. }
  94. else
  95. {
  96. throw ExceptionEx.ThrowServiceException(ex);
  97. }
  98. }
  99. }
  100. /// <summary>
  101. /// 获取TeachingPlan表实体数据
  102. /// </summary>
  103. /// <param name="keyValue">主键</param>
  104. /// <returns></returns>
  105. public TeachingPlanEntity GetTeachingPlanEntity(string keyValue)
  106. {
  107. try
  108. {
  109. return this.BaseRepository("CollegeMIS").FindEntity<TeachingPlanEntity>(keyValue);
  110. }
  111. catch (Exception ex)
  112. {
  113. if (ex is ExceptionEx)
  114. {
  115. throw;
  116. }
  117. else
  118. {
  119. throw ExceptionEx.ThrowServiceException(ex);
  120. }
  121. }
  122. }
  123. /// <summary>
  124. /// 根据学年获取教学计划
  125. /// </summary>
  126. /// <param name="AcademicYearNo"></param>
  127. /// <param name="Semester"></param>
  128. /// <returns></returns>
  129. public List<TeachingPlanRes> GetTeachingPlan(string AcademicYearNo, string Semester)
  130. {
  131. try
  132. {
  133. var res = new List<TeachingPlanRes>();
  134. var list = new List<TeachingPlanEntity>();
  135. if (!string.IsNullOrEmpty(AcademicYearNo))
  136. {
  137. list = this.BaseRepository("CollegeMIS")
  138. .FindList<TeachingPlanEntity>(x => x.Grade == AcademicYearNo).ToList();
  139. }
  140. else
  141. {
  142. list = this.BaseRepository("CollegeMIS")
  143. .FindList<TeachingPlanEntity>().ToList();
  144. }
  145. foreach (var entity in list)
  146. {
  147. var data = new TeachingPlanRes();
  148. data.TeachingPlan = entity;
  149. data.TeachingPlanItem = this.BaseRepository("CollegeMIS")
  150. .FindList<TeachingPlanItemEntity>(x => x.TeachingPlanId == entity.Id);
  151. res.Add(data);
  152. }
  153. return res;
  154. }
  155. catch (Exception ex)
  156. {
  157. if (ex is ExceptionEx)
  158. {
  159. throw;
  160. }
  161. else
  162. {
  163. throw ExceptionEx.ThrowServiceException(ex);
  164. }
  165. }
  166. }
  167. #endregion
  168. #region 提交数据
  169. /// <summary>
  170. /// 删除实体数据
  171. /// </summary>
  172. /// <param name="keyValue">主键</param>
  173. public void DeleteEntity(string keyValue)
  174. {
  175. try
  176. {
  177. this.BaseRepository("CollegeMIS").Delete<TeachingPlanEntity>(t => t.Id == keyValue);
  178. }
  179. catch (Exception ex)
  180. {
  181. if (ex is ExceptionEx)
  182. {
  183. throw;
  184. }
  185. else
  186. {
  187. throw ExceptionEx.ThrowServiceException(ex);
  188. }
  189. }
  190. }
  191. /// <summary>
  192. /// 保存实体数据(新增、修改)
  193. /// </summary>
  194. /// <param name="keyValue">主键</param>
  195. /// <param name="entity">实体</param>
  196. public void SaveEntity(string keyValue, TeachingPlanEntity entity, List<TeachingPlanItemEntity> teachingPlanItemList)
  197. {
  198. var db = this.BaseRepository("CollegeMIS").BeginTrans();
  199. try
  200. {
  201. if (!string.IsNullOrEmpty(keyValue))
  202. {
  203. entity.Modify(keyValue);
  204. db.Update(entity);
  205. //删除课程子表
  206. db.Delete<TeachingPlanItemEntity>(x => x.TeachingPlanId == entity.Id);
  207. foreach (var itemEntity in teachingPlanItemList)
  208. {
  209. itemEntity.TeachingPlanId = entity.Id;
  210. db.Insert(itemEntity);
  211. }
  212. }
  213. else
  214. {
  215. entity.Create();
  216. db.Insert(entity);
  217. //新增
  218. var lessonInfoList = db.FindList<LessonInfoEntity>(x => x.TeachMajorNo == entity.Major);
  219. foreach (var lessonInfo in lessonInfoList)
  220. {
  221. TeachingPlanItemEntity itemEntity = new TeachingPlanItemEntity();
  222. itemEntity.Create();
  223. itemEntity.TeachingPlanId = entity.Id;
  224. itemEntity.LessonNo = lessonInfo.LessonNo;
  225. itemEntity.LessonTime = lessonInfo.TotalStudyHour;
  226. db.Insert(itemEntity);
  227. }
  228. }
  229. db.Commit();
  230. }
  231. catch (Exception ex)
  232. {
  233. db.Rollback();
  234. if (ex is ExceptionEx)
  235. {
  236. throw;
  237. }
  238. else
  239. {
  240. throw ExceptionEx.ThrowServiceException(ex);
  241. }
  242. }
  243. }
  244. #endregion
  245. }
  246. }