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.
 
 
 
 
 
 

275 lines
7.8 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(@"
  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. public DataTable GetSqlTree()
  136. {
  137. try
  138. {
  139. return this.BaseRepository("CollegeMIS").FindTable("select * from CdDept order by DeptSort ");
  140. }
  141. catch (Exception ex)
  142. {
  143. if (ex is ExceptionEx)
  144. {
  145. throw;
  146. }
  147. else
  148. {
  149. throw ExceptionEx.ThrowServiceException(ex);
  150. }
  151. }
  152. }
  153. #endregion
  154. #region 提交数据
  155. /// <summary>
  156. /// 删除实体数据
  157. /// <param name="keyValue">主键</param>
  158. /// <summary>
  159. /// <returns></returns>
  160. public void DeleteEntity(string keyValue)
  161. {
  162. var db = this.BaseRepository("CollegeMIS").BeginTrans();
  163. try
  164. {
  165. //单个删除
  166. //this.BaseRepository("CollegeMIS").Delete<CdDeptEntity>(t => t.DeptId == keyValue);
  167. //多个删除
  168. var keyValueArr = keyValue.Split(',');
  169. foreach (var item in keyValueArr)
  170. {
  171. db.Delete<CdDeptEntity>(t => t.DeptId == item);
  172. }
  173. db.Commit();
  174. }
  175. catch (Exception ex)
  176. {
  177. db.Rollback();
  178. if (ex is ExceptionEx)
  179. {
  180. throw;
  181. }
  182. else
  183. {
  184. throw ExceptionEx.ThrowServiceException(ex);
  185. }
  186. }
  187. }
  188. /// <summary>
  189. /// 保存实体数据(新增、修改)
  190. /// <param name="keyValue">主键</param>
  191. /// <summary>
  192. /// <returns></returns>
  193. public void SaveEntity(string keyValue, CdDeptEntity entity)
  194. {
  195. try
  196. {
  197. if (!string.IsNullOrEmpty(keyValue))
  198. {
  199. entity.Modify(keyValue);
  200. this.BaseRepository("CollegeMIS").Update(entity);
  201. }
  202. else
  203. {
  204. entity.Create();
  205. this.BaseRepository("CollegeMIS").Insert(entity);
  206. }
  207. }
  208. catch (Exception ex)
  209. {
  210. if (ex is ExceptionEx)
  211. {
  212. throw;
  213. }
  214. else
  215. {
  216. throw ExceptionEx.ThrowServiceException(ex);
  217. }
  218. }
  219. }
  220. #endregion
  221. public IEnumerable<CdDeptEntity> GetListBySchoolId(string schoolId)
  222. {
  223. try
  224. {
  225. return this.BaseRepository("CollegeMIS").FindList<CdDeptEntity>().Where(m => m.F_SchoolId == schoolId);
  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. public IEnumerable<CdDeptEntity> GetAllList()
  240. {
  241. try
  242. {
  243. return this.BaseRepository("CollegeMIS").FindList<CdDeptEntity>();
  244. }
  245. catch (Exception ex)
  246. {
  247. if (ex is ExceptionEx)
  248. {
  249. throw;
  250. }
  251. else
  252. {
  253. throw ExceptionEx.ThrowServiceException(ex);
  254. }
  255. }
  256. }
  257. }
  258. }