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.
 
 
 
 
 
 

376 lines
13 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-01-29 11:08
  16. /// 描 述:班级信息管理
  17. /// </summary>
  18. public class TeachClassService : RepositoryFactory
  19. {
  20. #region 获取数据
  21. /// <summary>
  22. /// 获取页面显示列表数据
  23. /// <summary>
  24. /// <param name="queryJson">查询参数</param>
  25. /// <returns></returns>
  26. public IEnumerable<TeachClassEntity> GetPageList(Pagination pagination, string queryJson)
  27. {
  28. try
  29. {
  30. var strSql = new StringBuilder();
  31. strSql.Append("SELECT ");
  32. strSql.Append(@" t.*,op.ExamType,op.LessonName ");
  33. strSql.Append(" FROM TeachClass t ");
  34. strSql.Append(" left join openlessonplan op on op.academicyearno=t.academicyearno and op.semester=t.semester and op.DeptNo=t.DeptNo and op.majorno =t.majorno ");
  35. strSql.Append(" and op.grade =t.grade and op.lessonno =t.lessonno and op.F_SchoolId =t.F_SchoolId ");
  36. strSql.Append(" WHERE 1=1 ");
  37. var queryParam = queryJson.ToJObject();
  38. // 虚拟参数
  39. var dp = new DynamicParameters(new { });
  40. if (!queryParam["F_SchoolId"].IsEmpty())
  41. {
  42. dp.Add("F_SchoolId", queryParam["F_SchoolId"].ToString(), DbType.String);
  43. strSql.Append(" AND t.F_SchoolId = @F_SchoolId ");
  44. }
  45. if (!queryParam["AcademicYearNo"].IsEmpty())
  46. {
  47. dp.Add("AcademicYearNo", queryParam["AcademicYearNo"].ToString(), DbType.String);
  48. strSql.Append(" AND t.AcademicYearNo = @AcademicYearNo ");
  49. }
  50. if (!queryParam["Semester"].IsEmpty())
  51. {
  52. dp.Add("Semester", queryParam["Semester"].ToString(), DbType.String);
  53. strSql.Append(" AND t.Semester = @Semester ");
  54. }
  55. if (!queryParam["DeptNo"].IsEmpty())
  56. {
  57. dp.Add("DeptNo", queryParam["DeptNo"].ToString(), DbType.String);
  58. strSql.Append(" AND t.DeptNo = @DeptNo ");
  59. }
  60. if (!queryParam["MajorNo"].IsEmpty())
  61. {
  62. dp.Add("MajorNo", queryParam["MajorNo"].ToString(), DbType.String);
  63. strSql.Append(" AND t.MajorNo = @MajorNo ");
  64. }
  65. if (!queryParam["Grade"].IsEmpty())
  66. {
  67. dp.Add("Grade", "%" + queryParam["Grade"].ToString() + "%", DbType.String);
  68. strSql.Append(" AND t.Grade Like @Grade ");
  69. }
  70. if (!queryParam["LessonNo"].IsEmpty())
  71. {
  72. dp.Add("LessonNo", queryParam["LessonNo"].ToString(), DbType.String);
  73. strSql.Append(" AND t.LessonNo = @LessonNo ");
  74. }
  75. if (!queryParam["EmpNo"].IsEmpty())
  76. {
  77. dp.Add("EmpNo", queryParam["EmpNo"].ToString(), DbType.String);
  78. strSql.Append(" AND t.EmpNo = @EmpNo ");
  79. }
  80. if (!queryParam["ClassNo"].IsEmpty())
  81. {
  82. dp.Add("ClassNo", queryParam["ClassNo"].ToString(), DbType.String);
  83. strSql.Append(" AND t.TeachClassNo = @ClassNo ");
  84. }
  85. return this.BaseRepository("CollegeMIS").FindList<TeachClassEntity>(strSql.ToString(), dp, pagination);
  86. }
  87. catch (Exception ex)
  88. {
  89. if (ex is ExceptionEx)
  90. {
  91. throw;
  92. }
  93. else
  94. {
  95. throw ExceptionEx.ThrowServiceException(ex);
  96. }
  97. }
  98. }
  99. internal bool GetAny()
  100. {
  101. try
  102. {
  103. return this.BaseRepository("CollegeMIS").FindList<TeachClassEntity>().ToList().Count > 0 ? true : false;
  104. }
  105. catch (Exception ex)
  106. {
  107. if (ex is ExceptionEx)
  108. {
  109. throw;
  110. }
  111. else
  112. {
  113. throw ExceptionEx.ThrowServiceException(ex);
  114. }
  115. }
  116. }
  117. /// <summary>
  118. /// 获取ClassInfo表实体数据
  119. /// <param name="keyValue">主键</param>
  120. /// <summary>
  121. /// <returns></returns>
  122. public TeachClassEntity GetTeachClassEntity(string keyValue)
  123. {
  124. try
  125. {
  126. int ID = Convert.ToInt32(keyValue);
  127. return this.BaseRepository("CollegeMIS").FindEntity<TeachClassEntity>(ID);
  128. }
  129. catch (Exception ex)
  130. {
  131. if (ex is ExceptionEx)
  132. {
  133. throw;
  134. }
  135. else
  136. {
  137. throw ExceptionEx.ThrowServiceException(ex);
  138. }
  139. }
  140. }
  141. #endregion
  142. #region 提交数据
  143. /// <summary>
  144. /// 删除实体数据
  145. /// <param name="keyValue">主键</param>
  146. /// <summary>
  147. /// <returns></returns>
  148. public void DeleteEntity(string keyValue)
  149. {
  150. var db = this.BaseRepository("CollegeMIS").BeginTrans();
  151. try
  152. {
  153. //修改
  154. var keyValueArr = keyValue.Split(',');
  155. foreach (var item in keyValueArr)
  156. {
  157. var entity = this.BaseRepository("CollegeMIS").FindEntity<TeachClassEntity>(x => x.ID == Convert.ToInt32(item));
  158. if (entity != null)
  159. {
  160. entity.EmpNo = "";
  161. db.Update(entity);
  162. }
  163. }
  164. db.Commit();
  165. }
  166. catch (Exception ex)
  167. {
  168. db.Rollback();
  169. if (ex is ExceptionEx)
  170. {
  171. throw;
  172. }
  173. else
  174. {
  175. throw ExceptionEx.ThrowServiceException(ex);
  176. }
  177. }
  178. }
  179. /// <summary>
  180. /// 保存实体数据(新增、修改)
  181. /// <param name="keyValue">主键</param>
  182. /// <summary>
  183. /// <returns></returns>
  184. public void SaveEntity(string keyValue, TeachClassEntity entity)
  185. {
  186. try
  187. {
  188. var keyvalue = Convert.ToInt32(keyValue);
  189. if (!string.IsNullOrEmpty(keyValue))
  190. {
  191. entity.Modify(keyvalue);
  192. this.BaseRepository("CollegeMIS").Update(entity);
  193. }
  194. else
  195. {
  196. entity.Create();
  197. this.BaseRepository("CollegeMIS").Insert(entity);
  198. }
  199. }
  200. catch (Exception ex)
  201. {
  202. if (ex is ExceptionEx)
  203. {
  204. throw;
  205. }
  206. else
  207. {
  208. throw ExceptionEx.ThrowServiceException(ex);
  209. }
  210. }
  211. }
  212. /// <summary>
  213. /// 保存实体数据(新增、修改)
  214. /// <param name="keyValue">主键</param>
  215. /// <summary>
  216. /// <returns></returns>
  217. public void UpEmpNos(string xn, string xq, string classNo, string LessonNo, string EmpNo, string hisempno, string Grade)
  218. {
  219. try
  220. {
  221. StringBuilder sb = new StringBuilder();
  222. sb.Append(" update StuSelectLessonList set EmpNo ='" + EmpNo + "' where classno = '" + classNo + "' and Semester ='" + xq + "' and AcademicYearNo ='" + xn + "' and LessonNo ='" + LessonNo + "' and empno = '" + hisempno + "' and Grade = '" + Grade + "'");
  223. this.BaseRepository("CollegeMIS").ExecuteBySql(sb.ToString());
  224. }
  225. catch (Exception ex)
  226. {
  227. if (ex is ExceptionEx)
  228. {
  229. throw;
  230. }
  231. else
  232. {
  233. throw ExceptionEx.ThrowServiceException(ex);
  234. }
  235. }
  236. }
  237. #endregion
  238. #region 扩展数据
  239. public IEnumerable<TeachClassEntity> GetAllClass()
  240. {
  241. try
  242. {
  243. return this.BaseRepository("CollegeMIS").FindList<TeachClassEntity>();
  244. }
  245. catch (Exception ex)
  246. {
  247. if (ex is ExceptionEx)
  248. {
  249. throw;
  250. }
  251. else
  252. {
  253. throw ExceptionEx.ThrowServiceException(ex);
  254. }
  255. }
  256. }
  257. /// <summary>
  258. /// 获取ClassInfo表实体数据
  259. /// <param name="keyValue">主键</param>
  260. /// <summary>
  261. /// <returns></returns>
  262. public List<TeachClassEntity> GetTeachListById(string keyValue)
  263. {
  264. try
  265. {
  266. var id = keyValue.Split(',');
  267. return this.BaseRepository("CollegeMIS")
  268. .FindList<TeachClassEntity>(x => id.Contains(x.ID.ToString())).ToList();
  269. }
  270. catch (Exception ex)
  271. {
  272. if (ex is ExceptionEx)
  273. {
  274. throw;
  275. }
  276. else
  277. {
  278. throw ExceptionEx.ThrowServiceException(ex);
  279. }
  280. }
  281. }
  282. /// <summary>
  283. /// 保存数据
  284. /// </summary>
  285. /// <param name="keyValue">主键</param>
  286. /// <param name="entity"></param>
  287. public void SaveEntityList(List<TeachClassEntity> List)
  288. {
  289. var db = this.BaseRepository("CollegeMIS").BeginTrans();
  290. try
  291. {
  292. foreach (var item in List)
  293. {
  294. TeachClassEntity Teach = new TeachClassEntity();
  295. Teach.TeachClassNo = item.TeachClassNo;
  296. Teach.AcademicYearNo = item.AcademicYearNo;
  297. Teach.DeptNo = item.DeptNo;
  298. Teach.MajorNo = item.MajorNo;
  299. Teach.Grade = item.Grade;
  300. Teach.EmpNo = item.EmpNo;
  301. Teach.Semester = item.Semester;
  302. Teach.LessonNo = item.LessonNo;
  303. Teach.StuNum = item.StuNum;
  304. Teach.LessonSortNo = item.LessonSortNo;
  305. Teach.F_SchoolId = item.F_SchoolId;
  306. if (db.FindEntity<TeachClassEntity>(x => x.AcademicYearNo == Teach.AcademicYearNo && x.Semester == Teach.Semester
  307. && x.DeptNo == Teach.DeptNo && x.TeachClassNo == Teach.TeachClassNo
  308. && x.MajorNo == Teach.MajorNo && x.Grade == Teach.Grade
  309. && x.LessonNo == Teach.LessonNo && x.F_SchoolId == Teach.F_SchoolId) == null)
  310. {
  311. db.Insert(Teach);
  312. }
  313. }
  314. db.Commit();
  315. }
  316. catch (Exception ex)
  317. {
  318. db.Rollback();
  319. if (ex is ExceptionEx)
  320. {
  321. throw;
  322. }
  323. else
  324. {
  325. throw ExceptionEx.ThrowServiceException(ex);
  326. }
  327. }
  328. }
  329. /// <summary>
  330. /// 保存或修改教师
  331. /// </summary>
  332. /// <param name="keyValue"></param>
  333. /// <param name="EmpNo"></param>
  334. public void UpEmpNo(string keyValue, string EmpNo)
  335. {
  336. var db = this.BaseRepository("CollegeMIS").BeginTrans();
  337. try
  338. {
  339. var keyarray = keyValue.Split(',');
  340. foreach (var item in keyarray)
  341. {
  342. var entityList = this.GetTeachClassEntity(item);
  343. entityList.EmpNo = EmpNo;
  344. db.Update(entityList);
  345. }
  346. db.Commit();
  347. }
  348. catch (Exception ex)
  349. {
  350. db.Rollback();
  351. if (ex is ExceptionEx)
  352. {
  353. throw;
  354. }
  355. else
  356. {
  357. throw ExceptionEx.ThrowServiceException(ex);
  358. }
  359. }
  360. }
  361. #endregion
  362. }
  363. }