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.
 
 
 
 
 
 

276 lines
7.9 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.Text;
  8. using System.Linq;
  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-22 10:53
  16. /// 描 述:系部信息管理
  17. /// </summary>
  18. public class CdDeptService : RepositoryFactory
  19. {
  20. #region 获取数据
  21. /// <summary>
  22. /// 获取页面显示列表数据
  23. /// <summary>
  24. /// <param name="queryJson">查询参数</param>
  25. /// <returns></returns>
  26. public IEnumerable<CdDeptEntity> GetPageList(Pagination pagination, string queryJson)
  27. {
  28. try
  29. {
  30. var strSql = new StringBuilder();
  31. strSql.Append("SELECT * ");
  32. strSql.Append(" FROM CdDept t ");
  33. strSql.Append(" WHERE 1=1 ");
  34. var queryParam = queryJson.ToJObject();
  35. // 虚拟参数
  36. var dp = new DynamicParameters(new { });
  37. if (!queryParam["DeptName"].IsEmpty())
  38. {
  39. dp.Add("DeptName", "%" + queryParam["DeptName"].ToString() + "%", DbType.String);
  40. strSql.Append(" AND t.DeptName Like @DeptName ");
  41. }
  42. if (!queryParam["DeptNo"].IsEmpty())
  43. {
  44. dp.Add("DeptNo", "%" + queryParam["DeptNo"].ToString() + "%", DbType.String);
  45. strSql.Append(" AND t.DeptNo Like @DeptNo ");
  46. }
  47. return this.BaseRepository("CollegeMIS").FindList<CdDeptEntity>(strSql.ToString(), dp, pagination);
  48. }
  49. catch (Exception ex)
  50. {
  51. if (ex is ExceptionEx)
  52. {
  53. throw;
  54. }
  55. else
  56. {
  57. throw ExceptionEx.ThrowServiceException(ex);
  58. }
  59. }
  60. }
  61. internal bool GetAny()
  62. {
  63. try
  64. {
  65. return this.BaseRepository("CollegeMIS").FindList<CdDeptEntity>().ToList().Count() > 0 ? true : false;
  66. }
  67. catch (Exception ex)
  68. {
  69. if (ex is ExceptionEx)
  70. {
  71. throw;
  72. }
  73. else
  74. {
  75. throw ExceptionEx.ThrowServiceException(ex);
  76. }
  77. }
  78. }
  79. /// <summary>
  80. /// 获取CdDept表实体数据
  81. /// <param name="keyValue">主键</param>
  82. /// <summary>
  83. /// <returns></returns>
  84. public CdDeptEntity GetCdDeptEntity(string keyValue)
  85. {
  86. try
  87. {
  88. return this.BaseRepository("CollegeMIS").FindEntity<CdDeptEntity>(keyValue);
  89. }
  90. catch (Exception ex)
  91. {
  92. if (ex is ExceptionEx)
  93. {
  94. throw;
  95. }
  96. else
  97. {
  98. throw ExceptionEx.ThrowServiceException(ex);
  99. }
  100. }
  101. }
  102. /// <summary>
  103. /// 获取CdDept表实体数据
  104. /// <param name="deptNo">系部编号</param>
  105. /// <summary>
  106. /// <returns></returns>
  107. public CdDeptEntity GetCdDeptEntityByNo(string deptNo)
  108. {
  109. try
  110. {
  111. return this.BaseRepository("CollegeMIS").FindEntity<CdDeptEntity>(x => x.DeptNo == deptNo);
  112. }
  113. catch (Exception ex)
  114. {
  115. if (ex is ExceptionEx)
  116. {
  117. throw;
  118. }
  119. else
  120. {
  121. throw ExceptionEx.ThrowServiceException(ex);
  122. }
  123. }
  124. }
  125. #endregion
  126. #region 提交数据
  127. /// <summary>
  128. /// 删除实体数据
  129. /// <param name="keyValue">主键</param>
  130. /// <summary>
  131. /// <returns></returns>
  132. public void DeleteEntity(string keyValue)
  133. {
  134. var db = this.BaseRepository("CollegeMIS").BeginTrans();
  135. try
  136. {
  137. //单个删除
  138. //this.BaseRepository("CollegeMIS").Delete<CdDeptEntity>(t => t.DeptId == keyValue);
  139. //多个删除
  140. var keyValueArr = keyValue.Split(',');
  141. foreach (var item in keyValueArr)
  142. {
  143. db.Delete<CdDeptEntity>(t => t.DeptId == item);
  144. }
  145. db.Commit();
  146. }
  147. catch (Exception ex)
  148. {
  149. db.Rollback();
  150. if (ex is ExceptionEx)
  151. {
  152. throw;
  153. }
  154. else
  155. {
  156. throw ExceptionEx.ThrowServiceException(ex);
  157. }
  158. }
  159. }
  160. /// <summary>
  161. /// 保存实体数据(新增、修改)
  162. /// <param name="keyValue">主键</param>
  163. /// <summary>
  164. /// <returns></returns>
  165. public void SaveEntity(string keyValue, CdDeptEntity entity)
  166. {
  167. try
  168. {
  169. if (!string.IsNullOrEmpty(keyValue))
  170. {
  171. entity.Modify(keyValue);
  172. this.BaseRepository("CollegeMIS").Update(entity);
  173. }
  174. else
  175. {
  176. entity.Create();
  177. this.BaseRepository("CollegeMIS").Insert(entity);
  178. }
  179. }
  180. catch (Exception ex)
  181. {
  182. if (ex is ExceptionEx)
  183. {
  184. throw;
  185. }
  186. else
  187. {
  188. throw ExceptionEx.ThrowServiceException(ex);
  189. }
  190. }
  191. }
  192. #endregion
  193. public IEnumerable<CdDeptEntity> GetListBySchoolId(string schoolId)
  194. {
  195. try
  196. {
  197. return this.BaseRepository("CollegeMIS").FindList<CdDeptEntity>().Where(m => m.F_SchoolId == schoolId);
  198. }
  199. catch (Exception ex)
  200. {
  201. if (ex is ExceptionEx)
  202. {
  203. throw;
  204. }
  205. else
  206. {
  207. throw ExceptionEx.ThrowServiceException(ex);
  208. }
  209. }
  210. }
  211. public IEnumerable<CdDeptEntity> GetAllList()
  212. {
  213. try
  214. {
  215. return this.BaseRepository("CollegeMIS").FindList<CdDeptEntity>();
  216. }
  217. catch (Exception ex)
  218. {
  219. if (ex is ExceptionEx)
  220. {
  221. throw;
  222. }
  223. else
  224. {
  225. throw ExceptionEx.ThrowServiceException(ex);
  226. }
  227. }
  228. }
  229. #region 扩展数据
  230. /// <summary>
  231. /// 获取公司列表信息(全部)
  232. /// </summary>
  233. /// <returns></returns>
  234. public IEnumerable<CdDeptEntity> GetList()
  235. {
  236. try
  237. {
  238. var strSql = new StringBuilder();
  239. strSql.Append("SELECT ");
  240. strSql.Append(" * ");
  241. strSql.Append(" FROM CdDept t WHERE 1=1 order by t.deptSort ");
  242. return this.BaseRepository("CollegeMIS").FindList<CdDeptEntity>(strSql.ToString());
  243. }
  244. catch (Exception ex)
  245. {
  246. if (ex is ExceptionEx)
  247. {
  248. throw;
  249. }
  250. else
  251. {
  252. throw ExceptionEx.ThrowServiceException(ex);
  253. }
  254. }
  255. }
  256. #endregion
  257. }
  258. }