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.
 
 
 
 
 
 

359 lines
11 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 ClassInfoService : RepositoryFactory
  19. {
  20. #region 获取数据
  21. /// <summary>
  22. /// 获取页面显示列表数据
  23. /// <summary>
  24. /// <param name="queryJson">查询参数</param>
  25. /// <returns></returns>
  26. public IEnumerable<ClassInfoEntity> GetPageList(Pagination pagination, string queryJson)
  27. {
  28. try
  29. {
  30. var strSql = new StringBuilder();
  31. strSql.Append(" select t.*,fb1.Mobile as MobileOne,fb2.Mobile as MobileTwo from classinfo t ");
  32. strSql.Append(" left join empinfo fb1 on t.classdiredctorno = fb1.EmpNo");
  33. strSql.Append(" left join empinfo fb2 on t.ClassTutorNo = fb2.EmpNo");
  34. strSql.Append(" WHERE 1=1 ");
  35. var queryParam = queryJson.ToJObject();
  36. // 虚拟参数
  37. var dp = new DynamicParameters(new { });
  38. if (!queryParam["ClassName"].IsEmpty())
  39. {
  40. dp.Add("ClassName", "%" + queryParam["ClassName"].ToString() + "%", DbType.String);
  41. strSql.Append(" AND t.ClassName Like @ClassName ");
  42. }
  43. if (!queryParam["ClassNo"].IsEmpty())
  44. {
  45. dp.Add("ClassNo", "%" + queryParam["ClassNo"].ToString() + "%", DbType.String);
  46. strSql.Append(" AND t.ClassNo Like @ClassNo ");
  47. }
  48. if (!queryParam["DeptNo"].IsEmpty())
  49. {
  50. dp.Add("DeptNo", queryParam["DeptNo"].ToString(), DbType.String);
  51. strSql.Append(" AND t.DeptNo = @DeptNo ");
  52. }
  53. if (!queryParam["MajorNo"].IsEmpty())
  54. {
  55. dp.Add("MajorNo", queryParam["MajorNo"].ToString(), DbType.String);
  56. strSql.Append(" AND t.MajorNo = @MajorNo ");
  57. }
  58. return this.BaseRepository("CollegeMIS").FindList<ClassInfoEntity>(strSql.ToString(), dp, pagination);
  59. }
  60. catch (Exception ex)
  61. {
  62. if (ex is ExceptionEx)
  63. {
  64. throw;
  65. }
  66. else
  67. {
  68. throw ExceptionEx.ThrowServiceException(ex);
  69. }
  70. }
  71. }
  72. internal bool GetAny()
  73. {
  74. try
  75. {
  76. return this.BaseRepository("CollegeMIS").FindList<ClassInfoEntity>().ToList().Count > 0 ? true : false;
  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. /// 获取ClassInfo表实体数据
  92. /// <param name="keyValue">主键</param>
  93. /// <summary>
  94. /// <returns></returns>
  95. public ClassInfoEntity GetClassInfoEntity(string keyValue)
  96. {
  97. try
  98. {
  99. return this.BaseRepository("CollegeMIS").FindEntity<ClassInfoEntity>(keyValue);
  100. }
  101. catch (Exception ex)
  102. {
  103. if (ex is ExceptionEx)
  104. {
  105. throw;
  106. }
  107. else
  108. {
  109. throw ExceptionEx.ThrowServiceException(ex);
  110. }
  111. }
  112. }
  113. /// <summary>
  114. /// 获取ClassInfo表实体数据
  115. /// <param name="classNo">班级编号</param>
  116. /// <summary>
  117. /// <returns></returns>
  118. public ClassInfoEntity GetClassInfoEntityByClassNo(string classNo)
  119. {
  120. try
  121. {
  122. return this.BaseRepository("CollegeMIS").FindEntity<ClassInfoEntity>(x => x.ClassNo == classNo);
  123. }
  124. catch (Exception ex)
  125. {
  126. if (ex is ExceptionEx)
  127. {
  128. throw;
  129. }
  130. else
  131. {
  132. throw ExceptionEx.ThrowServiceException(ex);
  133. }
  134. }
  135. }
  136. /// <summary>
  137. /// 获取ClassInfo表实体数据
  138. /// <param name="className">班级名称</param>
  139. /// <summary>
  140. /// <returns></returns>
  141. public ClassInfoEntity GetClassInfoEntityByClassName(string className)
  142. {
  143. try
  144. {
  145. return this.BaseRepository("CollegeMIS").FindEntity<ClassInfoEntity>(x => x.ClassName == className);
  146. }
  147. catch (Exception ex)
  148. {
  149. if (ex is ExceptionEx)
  150. {
  151. throw;
  152. }
  153. else
  154. {
  155. throw ExceptionEx.ThrowServiceException(ex);
  156. }
  157. }
  158. }
  159. /// <summary>
  160. /// 根据班主任或辅导员账号查询班级
  161. /// <param name="account">班主任或辅导员账号</param>
  162. /// <summary>
  163. /// <returns></returns>
  164. public IEnumerable<ClassInfoEntity> GetListByAccount(string account)
  165. {
  166. try
  167. {
  168. return this.BaseRepository("CollegeMIS").FindList<ClassInfoEntity>(x => (x.ClassDiredctorNo == account || x.ClassTutorNo == account) && x.CheckMark == true);
  169. }
  170. catch (Exception ex)
  171. {
  172. if (ex is ExceptionEx)
  173. {
  174. throw;
  175. }
  176. else
  177. {
  178. throw ExceptionEx.ThrowServiceException(ex);
  179. }
  180. }
  181. }
  182. #endregion
  183. #region 提交数据
  184. public void Lock(string keyValue)
  185. {
  186. var db = this.BaseRepository("CollegeMIS").BeginTrans();
  187. try
  188. {
  189. //单个启用
  190. //this.BaseRepository("CollegeMIS").ExecuteBySql("update ClassInfo set CheckMark=1 where ClassId='" + keyValue + "'");
  191. //多个启用
  192. var keyValueArr = keyValue.Split(',');
  193. foreach (var item in keyValueArr)
  194. {
  195. db.ExecuteBySql("update ClassInfo set CheckMark=1 where ClassId='" + item + "'");
  196. }
  197. db.Commit();
  198. }
  199. catch (Exception ex)
  200. {
  201. db.Rollback();
  202. if (ex is ExceptionEx)
  203. {
  204. throw;
  205. }
  206. else
  207. {
  208. throw ExceptionEx.ThrowServiceException(ex);
  209. }
  210. }
  211. }
  212. public void UnLock(string keyValue)
  213. {
  214. var db = this.BaseRepository("CollegeMIS").BeginTrans();
  215. try
  216. {
  217. //单个停用
  218. //this.BaseRepository("CollegeMIS").ExecuteBySql("update ClassInfo set CheckMark=0 where ClassId='" + keyValue + "'");
  219. //多个停用
  220. var keyValueArr = keyValue.Split(',');
  221. foreach (var item in keyValueArr)
  222. {
  223. db.ExecuteBySql("update ClassInfo set CheckMark=0 where ClassId='" + item + "'");
  224. }
  225. db.Commit();
  226. }
  227. catch (Exception ex)
  228. {
  229. db.Rollback();
  230. if (ex is ExceptionEx)
  231. {
  232. throw;
  233. }
  234. else
  235. {
  236. throw ExceptionEx.ThrowServiceException(ex);
  237. }
  238. }
  239. }
  240. /// <summary>
  241. /// 删除实体数据
  242. /// <param name="keyValue">主键</param>
  243. /// <summary>
  244. /// <returns></returns>
  245. public void DeleteEntity(string keyValue)
  246. {
  247. var db = this.BaseRepository("CollegeMIS").BeginTrans();
  248. try
  249. {
  250. //单个删除
  251. //this.BaseRepository("CollegeMIS").Delete<ClassInfoEntity>(t => t.ClassId == keyValue);
  252. //多个删除
  253. var keyValueArr = keyValue.Split(',');
  254. foreach (var item in keyValueArr)
  255. {
  256. db.Delete<ClassInfoEntity>(t => t.ClassId == item);
  257. }
  258. db.Commit();
  259. }
  260. catch (Exception ex)
  261. {
  262. db.Rollback();
  263. if (ex is ExceptionEx)
  264. {
  265. throw;
  266. }
  267. else
  268. {
  269. throw ExceptionEx.ThrowServiceException(ex);
  270. }
  271. }
  272. }
  273. /// <summary>
  274. /// 保存实体数据(新增、修改)
  275. /// <param name="keyValue">主键</param>
  276. /// <summary>
  277. /// <returns></returns>
  278. public void SaveEntity(string keyValue, ClassInfoEntity entity)
  279. {
  280. try
  281. {
  282. if (!string.IsNullOrEmpty(keyValue))
  283. {
  284. entity.Modify(keyValue);
  285. this.BaseRepository("CollegeMIS").Update(entity);
  286. }
  287. else
  288. {
  289. entity.Create();
  290. this.BaseRepository("CollegeMIS").Insert(entity);
  291. }
  292. }
  293. catch (Exception ex)
  294. {
  295. if (ex is ExceptionEx)
  296. {
  297. throw;
  298. }
  299. else
  300. {
  301. throw ExceptionEx.ThrowServiceException(ex);
  302. }
  303. }
  304. }
  305. #endregion
  306. public IEnumerable<ClassInfoEntity> GetAllClass()
  307. {
  308. try
  309. {
  310. return this.BaseRepository("CollegeMIS").FindList<ClassInfoEntity>(m => m.CheckMark == true);
  311. }
  312. catch (Exception ex)
  313. {
  314. if (ex is ExceptionEx)
  315. {
  316. throw;
  317. }
  318. else
  319. {
  320. throw ExceptionEx.ThrowServiceException(ex);
  321. }
  322. }
  323. }
  324. public IEnumerable<ClassInfoEntity> GetClassByMajorNo(string MajorNo)
  325. {
  326. try
  327. {
  328. return this.BaseRepository("CollegeMIS").FindList<ClassInfoEntity>(m => m.CheckMark == true && m.MajorNo == MajorNo);
  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. }
  343. }