Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 
 
 
 

240 rindas
7.0 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.03.04
  14. /// 描 述:岗位管理
  15. /// </summary>
  16. public class PostService : RepositoryFactory
  17. {
  18. #region 构造函数和属性
  19. private string fieldSql;
  20. public PostService()
  21. {
  22. fieldSql = @"
  23. t.F_PostId,
  24. t.F_ParentId,
  25. t.F_Name,
  26. t.F_EnCode,
  27. t.F_CompanyId,
  28. t.F_DepartmentId,
  29. t.F_DeleteMark,
  30. t.F_Description,
  31. t.F_CreateDate,
  32. t.F_CreateUserId,
  33. t.F_CreateUserName,
  34. t.F_ModifyDate,
  35. t.F_ModifyUserId,
  36. t.F_ModifyUserName
  37. ";
  38. }
  39. #endregion
  40. #region 获取数据
  41. /// <summary>
  42. /// 获取岗位数据列表(根据公司列表)
  43. /// </summary>
  44. /// <param name="companyId">公司主键</param>
  45. /// <returns></returns>
  46. public IEnumerable<PostEntity> GetList(string companyId)
  47. {
  48. try
  49. {
  50. var strSql = new StringBuilder();
  51. strSql.Append("SELECT ");
  52. strSql.Append(fieldSql);
  53. strSql.Append(" FROM LR_Base_Post t WHERE t.F_DeleteMark = 0 AND t.F_CompanyId =@companyId ORDER BY t.F_DepartmentId,t.F_ParentId,t.F_EnCode ");
  54. return this.BaseRepository().FindList<PostEntity>(strSql.ToString(), new { companyId = companyId });
  55. }
  56. catch (Exception ex)
  57. {
  58. if (ex is ExceptionEx)
  59. {
  60. throw;
  61. }
  62. else
  63. {
  64. throw ExceptionEx.ThrowServiceException(ex);
  65. }
  66. }
  67. }
  68. /// <summary>
  69. /// 获取岗位数据列表(根据主键串)
  70. /// </summary>
  71. /// <param name="postIds">根据主键串</param>
  72. /// <returns></returns>
  73. public IEnumerable<PostEntity> GetListByPostIds(string postIds)
  74. {
  75. try
  76. {
  77. return this.BaseRepository().FindList<PostEntity>(t => postIds.Contains(t.F_PostId));
  78. }
  79. catch (Exception ex)
  80. {
  81. if (ex is ExceptionEx)
  82. {
  83. throw;
  84. }
  85. else
  86. {
  87. throw ExceptionEx.ThrowServiceException(ex);
  88. }
  89. }
  90. }
  91. /// <summary>
  92. /// 获取岗位的实体数据
  93. /// </summary>
  94. /// <param name="keyValue">主键</param>
  95. /// <returns></returns>
  96. public PostEntity GetEntity(string keyValue)
  97. {
  98. try
  99. {
  100. return this.BaseRepository().FindEntity<PostEntity>(keyValue);
  101. }
  102. catch (Exception ex)
  103. {
  104. if (ex is ExceptionEx)
  105. {
  106. throw;
  107. }
  108. else
  109. {
  110. throw ExceptionEx.ThrowServiceException(ex);
  111. }
  112. }
  113. }
  114. #endregion
  115. #region 提交数据
  116. /// <summary>
  117. /// 虚拟删除
  118. /// </summary>
  119. /// <param name="keyValue">主键</param>
  120. public void VirtualDelete(string keyValue)
  121. {
  122. var db = this.BaseRepository().BeginTrans();
  123. try
  124. {
  125. PostEntity entity = new PostEntity()
  126. {
  127. F_PostId = keyValue,
  128. F_DeleteMark = 1
  129. };
  130. db.Update(entity);
  131. db.ExecuteBySql(" Delete From LR_BASE_USERRELATION where F_OBJECTID = @keyValue ", new { keyValue = keyValue });
  132. //db.Delete<UserRelationEntity>(t=>t.F_ObjectId == keyValue);
  133. db.Commit();
  134. }
  135. catch (Exception ex)
  136. {
  137. db.Rollback();
  138. if (ex is ExceptionEx)
  139. {
  140. throw;
  141. }
  142. else
  143. {
  144. throw ExceptionEx.ThrowServiceException(ex);
  145. }
  146. }
  147. }
  148. /// <summary>
  149. /// 保存岗位(新增、修改)
  150. /// </summary>
  151. /// <param name="keyValue">主键值</param>
  152. /// <param name="postEntity">岗位实体</param>
  153. /// <returns></returns>
  154. public void SaveEntity(string keyValue, PostEntity postEntity)
  155. {
  156. try
  157. {
  158. if (!string.IsNullOrEmpty(keyValue))
  159. {
  160. postEntity.Modify(keyValue);
  161. this.BaseRepository().Update(postEntity);
  162. }
  163. else
  164. {
  165. postEntity.Create();
  166. this.BaseRepository().Insert(postEntity);
  167. }
  168. }
  169. catch (Exception ex)
  170. {
  171. if (ex is ExceptionEx)
  172. {
  173. throw;
  174. }
  175. else
  176. {
  177. throw ExceptionEx.ThrowServiceException(ex);
  178. }
  179. }
  180. }
  181. internal bool GetAny()
  182. {
  183. try
  184. {
  185. return this.BaseRepository().FindList<PostEntity>().ToList().Count() > 0 ? true : false;
  186. }
  187. catch (Exception ex)
  188. {
  189. if (ex is ExceptionEx)
  190. {
  191. throw;
  192. }
  193. else
  194. {
  195. throw ExceptionEx.ThrowServiceException(ex);
  196. }
  197. }
  198. }
  199. #endregion
  200. /// <summary>
  201. /// 获取下级岗位id集合
  202. /// </summary>
  203. /// <param name="parentIds">父级Id集合</param>
  204. /// <returns></returns>
  205. public List<string> GetIdList(List<string> parentIds)
  206. {
  207. try
  208. {
  209. List<string> res = new List<string>();
  210. var list = this.BaseRepository().FindList<PostEntity>(t => parentIds.Contains(t.F_ParentId));
  211. foreach (var item in list)
  212. {
  213. res.Add(item.F_PostId);
  214. }
  215. return res;
  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. }
  230. }