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.
 
 
 
 
 
 

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