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.

CdDeptService.cs 8.2 KiB

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