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.
 
 
 
 
 
 

247 lines
7.2 KiB

  1. using Learun.DataBase.Repository;
  2. using Learun.Util;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Text;
  6. using System.Linq;
  7. namespace Learun.Application.Organization
  8. {
  9. /// <summary>
  10. /// 版 本 Learun-ADMS-Ultimate V7.0.0 数字化智慧校园
  11. /// Copyright (c) 2013-2018 北京泉江科技有限公司
  12. /// 创建人:陈彬彬
  13. /// 日 期:2017.04.17
  14. /// 描 述:部门管理
  15. /// </summary>
  16. public class DepartmentService : RepositoryFactory
  17. {
  18. #region 构造函数和属性
  19. private string fieldSql;
  20. public DepartmentService()
  21. {
  22. fieldSql = "*";
  23. }
  24. #endregion
  25. #region 获取数据
  26. /// <summary>
  27. /// 获取部门列表信息(根据公司Id)
  28. /// </summary>
  29. /// <param name="companyId">公司主键</param>
  30. /// <returns></returns>
  31. public IEnumerable<DepartmentEntity> GetList(string companyId)
  32. {
  33. try
  34. {
  35. var strSql = new StringBuilder();
  36. strSql.Append("SELECT ");
  37. strSql.Append(fieldSql);
  38. strSql.Append(" FROM LR_Base_Department t WHERE t.F_EnabledMark = 1 AND t.F_DeleteMark = 0 AND F_CompanyId = @companyId ORDER BY t.F_ParentId,t.F_FullName ");
  39. return this.BaseRepository().FindList<DepartmentEntity>(strSql.ToString(), new { companyId = companyId });
  40. }
  41. catch (Exception ex)
  42. {
  43. if (ex is ExceptionEx)
  44. {
  45. throw;
  46. }
  47. else
  48. {
  49. throw ExceptionEx.ThrowServiceException(ex);
  50. }
  51. }
  52. }
  53. /// <summary>
  54. /// 获取部门列表信息(根据公司Id)
  55. /// </summary>
  56. /// <returns></returns>
  57. public IEnumerable<DepartmentEntity> GetAllList()
  58. {
  59. try
  60. {
  61. var strSql = new StringBuilder();
  62. strSql.Append("SELECT ");
  63. strSql.Append(fieldSql);
  64. strSql.Append(" FROM LR_Base_Department t WHERE t.F_EnabledMark = 1 AND t.F_DeleteMark = 0 ");
  65. return this.BaseRepository().FindList<DepartmentEntity>(strSql.ToString());
  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. /// 获取部门数据实体
  81. /// </summary>
  82. /// <param name="keyValue">主键</param>
  83. /// <returns></returns>
  84. public DepartmentEntity GetEntity(string keyValue)
  85. {
  86. try
  87. {
  88. return this.BaseRepository().FindEntity<DepartmentEntity>(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. /// 获取部门名称列表
  104. /// </summary>
  105. /// <param name="keyValue">部门idList</param>
  106. /// <returns></returns>
  107. public string GetDepartmentList(string keyValue)
  108. {
  109. try
  110. {
  111. var idList = keyValue.Split(',').ToList();
  112. var data=this.BaseRepository().FindList<DepartmentEntity>(a=>idList.Contains(a.F_DepartmentId));
  113. var result =new StringBuilder();
  114. foreach (var item in data)
  115. {
  116. result.Append(item.F_FullName+",");
  117. }
  118. return result.ToString().TrimEnd(',');
  119. }
  120. catch (Exception ex)
  121. {
  122. if (ex is ExceptionEx)
  123. {
  124. throw;
  125. }
  126. else
  127. {
  128. throw ExceptionEx.ThrowServiceException(ex);
  129. }
  130. }
  131. }
  132. /// <summary>
  133. /// 获取部门数据实体
  134. /// </summary>
  135. /// <param name="code">部门编号</param>
  136. /// <returns></returns>
  137. public DepartmentEntity GetEntityByCode(string code)
  138. {
  139. try
  140. {
  141. return this.BaseRepository().FindEntity<DepartmentEntity>(x => x.F_EnCode == code);
  142. }
  143. catch (Exception ex)
  144. {
  145. if (ex is ExceptionEx)
  146. {
  147. throw;
  148. }
  149. else
  150. {
  151. throw ExceptionEx.ThrowServiceException(ex);
  152. }
  153. }
  154. }
  155. #endregion
  156. #region 提交数据
  157. /// <summary>
  158. /// 虚拟删除部门
  159. /// </summary>
  160. /// <param name="keyValue">主键</param>
  161. public void VirtualDelete(string keyValue)
  162. {
  163. try
  164. {
  165. DepartmentEntity entity = new DepartmentEntity()
  166. {
  167. F_DepartmentId = keyValue,
  168. F_DeleteMark = 1
  169. };
  170. this.BaseRepository().Update(entity);
  171. }
  172. catch (Exception ex)
  173. {
  174. if (ex is ExceptionEx)
  175. {
  176. throw;
  177. }
  178. else
  179. {
  180. throw ExceptionEx.ThrowServiceException(ex);
  181. }
  182. }
  183. }
  184. /// <summary>
  185. /// 保存部门表单(新增、修改)
  186. /// </summary>
  187. /// <param name="keyValue">主键值</param>
  188. /// <param name="departmentEntity">部门实体</param>
  189. /// <returns></returns>
  190. public void SaveEntity(string keyValue, DepartmentEntity departmentEntity)
  191. {
  192. try
  193. {
  194. if (!string.IsNullOrEmpty(keyValue))
  195. {
  196. departmentEntity.Modify(keyValue);
  197. this.BaseRepository().Update(departmentEntity);
  198. }
  199. else
  200. {
  201. departmentEntity.Create();
  202. this.BaseRepository().Insert(departmentEntity);
  203. }
  204. }
  205. catch (Exception ex)
  206. {
  207. if (ex is ExceptionEx)
  208. {
  209. throw;
  210. }
  211. else
  212. {
  213. throw ExceptionEx.ThrowServiceException(ex);
  214. }
  215. }
  216. }
  217. internal bool GetAny()
  218. {
  219. try
  220. {
  221. return this.BaseRepository().FindList<DepartmentEntity>().ToList().Count() > 0 ? true : false;
  222. }
  223. catch (Exception ex)
  224. {
  225. if (ex is ExceptionEx)
  226. {
  227. throw;
  228. }
  229. else
  230. {
  231. throw ExceptionEx.ThrowServiceException(ex);
  232. }
  233. }
  234. }
  235. #endregion
  236. }
  237. }