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.
 
 
 
 
 
 

335 lines
10 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. #endregion
  160. #region 提交数据
  161. public void Lock(string keyValue)
  162. {
  163. var db = this.BaseRepository("CollegeMIS").BeginTrans();
  164. try
  165. {
  166. //单个启用
  167. //this.BaseRepository("CollegeMIS").ExecuteBySql("update ClassInfo set CheckMark=1 where ClassId='" + keyValue + "'");
  168. //多个启用
  169. var keyValueArr = keyValue.Split(',');
  170. foreach (var item in keyValueArr)
  171. {
  172. db.ExecuteBySql("update ClassInfo set CheckMark=1 where ClassId='" + item + "'");
  173. }
  174. db.Commit();
  175. }
  176. catch (Exception ex)
  177. {
  178. db.Rollback();
  179. if (ex is ExceptionEx)
  180. {
  181. throw;
  182. }
  183. else
  184. {
  185. throw ExceptionEx.ThrowServiceException(ex);
  186. }
  187. }
  188. }
  189. public void UnLock(string keyValue)
  190. {
  191. var db = this.BaseRepository("CollegeMIS").BeginTrans();
  192. try
  193. {
  194. //单个停用
  195. //this.BaseRepository("CollegeMIS").ExecuteBySql("update ClassInfo set CheckMark=0 where ClassId='" + keyValue + "'");
  196. //多个停用
  197. var keyValueArr = keyValue.Split(',');
  198. foreach (var item in keyValueArr)
  199. {
  200. db.ExecuteBySql("update ClassInfo set CheckMark=0 where ClassId='" + item + "'");
  201. }
  202. db.Commit();
  203. }
  204. catch (Exception ex)
  205. {
  206. db.Rollback();
  207. if (ex is ExceptionEx)
  208. {
  209. throw;
  210. }
  211. else
  212. {
  213. throw ExceptionEx.ThrowServiceException(ex);
  214. }
  215. }
  216. }
  217. /// <summary>
  218. /// 删除实体数据
  219. /// <param name="keyValue">主键</param>
  220. /// <summary>
  221. /// <returns></returns>
  222. public void DeleteEntity(string keyValue)
  223. {
  224. var db = this.BaseRepository("CollegeMIS").BeginTrans();
  225. try
  226. {
  227. //单个删除
  228. //this.BaseRepository("CollegeMIS").Delete<ClassInfoEntity>(t => t.ClassId == keyValue);
  229. //多个删除
  230. var keyValueArr = keyValue.Split(',');
  231. foreach (var item in keyValueArr)
  232. {
  233. db.Delete<ClassInfoEntity>(t => t.ClassId == item);
  234. }
  235. db.Commit();
  236. }
  237. catch (Exception ex)
  238. {
  239. db.Rollback();
  240. if (ex is ExceptionEx)
  241. {
  242. throw;
  243. }
  244. else
  245. {
  246. throw ExceptionEx.ThrowServiceException(ex);
  247. }
  248. }
  249. }
  250. /// <summary>
  251. /// 保存实体数据(新增、修改)
  252. /// <param name="keyValue">主键</param>
  253. /// <summary>
  254. /// <returns></returns>
  255. public void SaveEntity(string keyValue, ClassInfoEntity entity)
  256. {
  257. try
  258. {
  259. if (!string.IsNullOrEmpty(keyValue))
  260. {
  261. entity.Modify(keyValue);
  262. this.BaseRepository("CollegeMIS").Update(entity);
  263. }
  264. else
  265. {
  266. entity.Create();
  267. this.BaseRepository("CollegeMIS").Insert(entity);
  268. }
  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. #endregion
  283. public IEnumerable<ClassInfoEntity> GetAllClass()
  284. {
  285. try
  286. {
  287. return this.BaseRepository("CollegeMIS").FindList<ClassInfoEntity>(m => m.CheckMark == true);
  288. }
  289. catch (Exception ex)
  290. {
  291. if (ex is ExceptionEx)
  292. {
  293. throw;
  294. }
  295. else
  296. {
  297. throw ExceptionEx.ThrowServiceException(ex);
  298. }
  299. }
  300. }
  301. public IEnumerable<ClassInfoEntity> GetClassByMajorNo(string MajorNo)
  302. {
  303. try
  304. {
  305. return this.BaseRepository("CollegeMIS").FindList<ClassInfoEntity>(m => m.CheckMark == true && m.MajorNo == MajorNo);
  306. }
  307. catch (Exception ex)
  308. {
  309. if (ex is ExceptionEx)
  310. {
  311. throw;
  312. }
  313. else
  314. {
  315. throw ExceptionEx.ThrowServiceException(ex);
  316. }
  317. }
  318. }
  319. }
  320. }