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.
 
 
 
 
 
 

400 lines
14 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-05-24 15:40
  16. /// 描 述:学生请假记录
  17. /// </summary>
  18. public class StuAttendanceLeaveService : RepositoryFactory
  19. {
  20. #region 获取数据
  21. /// <summary>
  22. /// 获取页面显示列表数据
  23. /// <summary>
  24. /// <param name="queryJson">查询参数</param>
  25. /// <returns></returns>
  26. public IEnumerable<StuAttendanceLeaveEntity> GetPageList(Pagination pagination, string queryJson)
  27. {
  28. try
  29. {
  30. var strSql = new StringBuilder();
  31. strSql.Append("SELECT t.*,c.ClassDiredctorNo,c.ClassTutorNo ");
  32. strSql.Append(" FROM StuAttendanceLeave t left join ClassInfo c on t.ClassNo=c.ClassNo ");
  33. strSql.Append(" WHERE 1=1 ");
  34. var queryParam = queryJson.ToJObject();
  35. // 虚拟参数
  36. var dp = new DynamicParameters(new { });
  37. if (!queryParam["StartTime"].IsEmpty() && !queryParam["EndTime"].IsEmpty())
  38. {
  39. dp.Add("startTime", queryParam["StartTime"].ToDate(), DbType.DateTime);
  40. dp.Add("endTime", queryParam["EndTime"].ToDate(), DbType.DateTime);
  41. strSql.Append(" AND ( t.LessonDate >= @startTime AND t.LessonDate <= @endTime ) ");
  42. }
  43. if (!queryParam["LessonName"].IsEmpty())
  44. {
  45. dp.Add("LessonName", "%" + queryParam["LessonName"].ToString() + "%", DbType.String);
  46. strSql.Append(" AND t.LessonName Like @LessonName ");
  47. }
  48. if (!queryParam["Grade"].IsEmpty())
  49. {
  50. dp.Add("Grade", queryParam["Grade"].ToString(), DbType.String);
  51. strSql.Append(" AND t.Grade = @Grade ");
  52. }
  53. if (!queryParam["StuNo"].IsEmpty())
  54. {
  55. dp.Add("StuNo", queryParam["StuNo"].ToString(), DbType.String);
  56. strSql.Append(" AND t.StuNo = @StuNo ");
  57. }
  58. if (!queryParam["StuName"].IsEmpty())
  59. {
  60. dp.Add("StuName", "%" + queryParam["StuName"].ToString() + "%", DbType.String);
  61. strSql.Append(" AND t.StuName Like @StuName ");
  62. }
  63. if (!queryParam["EmpNo"].IsEmpty())
  64. {
  65. dp.Add("EmpNo", "%" + queryParam["EmpNo"].ToString() + "%", DbType.String);
  66. strSql.Append(" AND t.EmpNo Like @EmpNo ");
  67. }
  68. //班级班主任/辅导员
  69. if (!queryParam["ClassManagerNo"].IsEmpty())
  70. {
  71. dp.Add("ClassManagerNo", queryParam["ClassManagerNo"].ToString(), DbType.String);
  72. dp.Add("ClassManagerNo2", "%" + queryParam["ClassManagerNo"].ToString() + "%", DbType.String);
  73. strSql.Append(" AND (c.ClassDiredctorNo = @ClassManagerNo or c.ClassTutorNo like @ClassManagerNo2) ");
  74. }
  75. var result = this.BaseRepository("CollegeMIS").FindList<StuAttendanceLeaveEntity>(strSql.ToString(), dp, pagination);
  76. return result;
  77. }
  78. catch (Exception ex)
  79. {
  80. if (ex is ExceptionEx)
  81. {
  82. throw;
  83. }
  84. else
  85. {
  86. throw ExceptionEx.ThrowServiceException(ex);
  87. }
  88. }
  89. }
  90. /// <summary>
  91. /// 获取页面显示列表数据
  92. /// <summary>
  93. /// <param name="queryJson">查询参数</param>
  94. /// <returns></returns>
  95. public IEnumerable<StuAttendanceLeaveEntity> GetList(string queryJson)
  96. {
  97. try
  98. {
  99. var strSql = new StringBuilder();
  100. strSql.Append("SELECT ");
  101. strSql.Append(@"
  102. t.ID,
  103. t.AcademicYearNo,
  104. t.Semester,
  105. t.StuNo,
  106. t.StuName,
  107. t.Grade,
  108. t.DeptNo,
  109. t.DeptName,
  110. t.MajorNo,
  111. t.MajorName,
  112. t.ClassNo
  113. ");
  114. strSql.Append(" FROM StuAttendanceLeave t ");
  115. strSql.Append(" WHERE 1=1 ");
  116. var queryParam = queryJson.ToJObject();
  117. // 虚拟参数
  118. var dp = new DynamicParameters(new { });
  119. var result = this.BaseRepository("CollegeMIS").FindList<StuAttendanceLeaveEntity>(strSql.ToString(), dp);
  120. //获取登录帐号
  121. var userInfo = LoginUserInfo.Get();
  122. //获取当前帐号所管理的班级
  123. var classes = this.BaseRepository("CollegeMIS").FindList<ClassInfoEntity>(a => a.ClassDiredctorNo == userInfo.account).Select(a => a.ClassNo);
  124. var list = result.Where(a => classes.Contains(a.ClassNo)).ToList();
  125. return list;
  126. }
  127. catch (Exception ex)
  128. {
  129. if (ex is ExceptionEx)
  130. {
  131. throw;
  132. }
  133. else
  134. {
  135. throw ExceptionEx.ThrowServiceException(ex);
  136. }
  137. }
  138. }
  139. internal void Check(string keyValue, string checkValue)
  140. {
  141. try
  142. {
  143. var entity = this.BaseRepository("CollegeMIS").FindEntity<StuAttendanceLeaveEntity>(a => a.ID == keyValue);
  144. if (null != entity)
  145. {
  146. entity.IsCheck = checkValue;
  147. }
  148. entity.Modify(keyValue);
  149. }
  150. catch (Exception ex)
  151. {
  152. if (ex is ExceptionEx)
  153. {
  154. throw;
  155. }
  156. else
  157. {
  158. throw ExceptionEx.ThrowServiceException(ex);
  159. }
  160. }
  161. }
  162. public List<StuAttendanceLeaveEntity> GetList()
  163. {
  164. try
  165. {
  166. return this.BaseRepository("CollegeMIS").FindList<StuAttendanceLeaveEntity>().ToList();
  167. }
  168. catch (Exception ex)
  169. {
  170. if (ex is ExceptionEx)
  171. {
  172. throw;
  173. }
  174. else
  175. {
  176. throw ExceptionEx.ThrowServiceException(ex);
  177. }
  178. }
  179. }
  180. /// <summary>
  181. /// 获取StuAttendanceLeave表实体数据
  182. /// <param name="keyValue">主键</param>
  183. /// <summary>
  184. /// <returns></returns>
  185. public StuAttendanceLeaveEntity GetStuAttendanceLeaveEntity(string keyValue)
  186. {
  187. try
  188. {
  189. return this.BaseRepository("CollegeMIS").FindEntity<StuAttendanceLeaveEntity>(keyValue);
  190. }
  191. catch (Exception ex)
  192. {
  193. if (ex is ExceptionEx)
  194. {
  195. throw;
  196. }
  197. else
  198. {
  199. throw ExceptionEx.ThrowServiceException(ex);
  200. }
  201. }
  202. }
  203. /// <summary>
  204. /// 获取页面显示列表数据
  205. /// <summary>
  206. /// <param name="queryJson">查询参数</param>
  207. /// <returns></returns>
  208. public IEnumerable<StuAttendanceLeaveEntity> GetListByJson(string queryJson)
  209. {
  210. try
  211. {
  212. var strSql = new StringBuilder();
  213. strSql.Append("SELECT t.* ");
  214. strSql.Append(" FROM StuAttendanceLeave t");
  215. strSql.Append(" WHERE 1=1 ");
  216. var queryParam = queryJson.ToJObject();
  217. // 虚拟参数
  218. var dp = new DynamicParameters(new { });
  219. if (!queryParam["LessonName"].IsEmpty())
  220. {
  221. dp.Add("LessonName", "%" + queryParam["LessonName"].ToString() + "%", DbType.String);
  222. strSql.Append(" AND t.LessonName Like @LessonName ");
  223. }
  224. if (!queryParam["Grade"].IsEmpty())
  225. {
  226. dp.Add("Grade", queryParam["Grade"].ToString(), DbType.String);
  227. strSql.Append(" AND t.Grade = @Grade ");
  228. }
  229. if (!queryParam["StuNo"].IsEmpty())
  230. {
  231. dp.Add("StuNo", queryParam["StuNo"].ToString(), DbType.String);
  232. strSql.Append(" AND t.StuNo = @StuNo ");
  233. }
  234. if (!queryParam["StuName"].IsEmpty())
  235. {
  236. dp.Add("StuName", "%" + queryParam["StuName"].ToString() + "%", DbType.String);
  237. strSql.Append(" AND t.StuName Like @StuName ");
  238. }
  239. if (!queryParam["EmpNo"].IsEmpty())
  240. {
  241. dp.Add("EmpNo", "%" + queryParam["EmpNo"].ToString() + "%", DbType.String);
  242. strSql.Append(" AND t.EmpNo Like @EmpNo ");
  243. }
  244. if (!queryParam["AcademicYearNo"].IsEmpty())
  245. {
  246. dp.Add("AcademicYearNo", queryParam["AcademicYearNo"].ToString(), DbType.String);
  247. strSql.Append(" AND t.AcademicYearNo = @AcademicYearNo ");
  248. }
  249. if (!queryParam["Semester"].IsEmpty())
  250. {
  251. dp.Add("Semester", queryParam["Semester"].ToString(), DbType.String);
  252. strSql.Append(" AND t.Semester = @Semester ");
  253. }
  254. var result = this.BaseRepository("CollegeMIS").FindList<StuAttendanceLeaveEntity>(strSql.ToString(), dp);
  255. return result;
  256. }
  257. catch (Exception ex)
  258. {
  259. if (ex is ExceptionEx)
  260. {
  261. throw;
  262. }
  263. else
  264. {
  265. throw ExceptionEx.ThrowServiceException(ex);
  266. }
  267. }
  268. }
  269. #endregion
  270. #region 提交数据
  271. /// <summary>
  272. /// 删除实体数据
  273. /// <param name="keyValue">主键</param>
  274. /// <summary>
  275. /// <returns></returns>
  276. public void DeleteEntity(string keyValue)
  277. {
  278. try
  279. {
  280. this.BaseRepository("CollegeMIS").Delete<StuAttendanceLeaveEntity>(t => t.ID == keyValue);
  281. }
  282. catch (Exception ex)
  283. {
  284. if (ex is ExceptionEx)
  285. {
  286. throw;
  287. }
  288. else
  289. {
  290. throw ExceptionEx.ThrowServiceException(ex);
  291. }
  292. }
  293. }
  294. /// <summary>
  295. /// 保存实体数据(新增、修改)
  296. /// <param name="keyValue">主键</param>
  297. /// <summary>
  298. /// <returns></returns>
  299. public void SaveEntity(string keyValue, StuAttendanceLeaveEntity entity)
  300. {
  301. try
  302. {
  303. entity.UpdateDate = DateTime.Now;
  304. if (!string.IsNullOrEmpty(keyValue))
  305. {
  306. entity.Modify(keyValue);
  307. this.BaseRepository("CollegeMIS").Update(entity);
  308. }
  309. else
  310. {
  311. //去重:多条件查询是否有新增数据
  312. var isExistModel = this.BaseRepository("CollegeMIS").FindEntity<StuAttendanceLeaveEntity>(x =>
  313. x.AcademicYearNo == entity.AcademicYearNo && x.Semester == entity.Semester &&
  314. x.StuNo == entity.StuNo && x.LessonNo == entity.LessonNo && x.TeachClassNo == entity.TeachClassNo &&
  315. x.LessonSortNo == entity.LessonSortNo && x.LessonDate == entity.LessonDate && x.LessonTime == entity.LessonTime &&
  316. x.EmpNo == entity.EmpNo && x.ClassRoomNo == entity.ClassRoomNo
  317. );
  318. if (isExistModel != null)
  319. {
  320. entity.Modify(isExistModel.ID);
  321. this.BaseRepository("CollegeMIS").Update(entity);
  322. }
  323. else
  324. {
  325. entity.Create();
  326. this.BaseRepository("CollegeMIS").Insert(entity);
  327. }
  328. }
  329. }
  330. catch (Exception ex)
  331. {
  332. if (ex is ExceptionEx)
  333. {
  334. throw;
  335. }
  336. else
  337. {
  338. throw ExceptionEx.ThrowServiceException(ex);
  339. }
  340. }
  341. }
  342. /// <summary>
  343. /// 保存实体数据(新增、修改)
  344. /// <param name="keyValue">主键</param>
  345. /// <summary>
  346. /// <returns></returns>
  347. public void SaveEntity(UserInfo userInfo, string keyValue, StuAttendanceLeaveEntity entity)
  348. {
  349. try
  350. {
  351. entity.UpdateDate = DateTime.Now;
  352. if (!string.IsNullOrEmpty(keyValue))
  353. {
  354. entity.Modify(keyValue, userInfo);
  355. this.BaseRepository("CollegeMIS").Update(entity);
  356. }
  357. else
  358. {
  359. entity.Create(userInfo);
  360. this.BaseRepository("CollegeMIS").Insert(entity);
  361. }
  362. }
  363. catch (Exception ex)
  364. {
  365. if (ex is ExceptionEx)
  366. {
  367. throw;
  368. }
  369. else
  370. {
  371. throw ExceptionEx.ThrowServiceException(ex);
  372. }
  373. }
  374. }
  375. #endregion
  376. }
  377. }