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.
 
 
 
 
 
 

194 lines
5.5 KiB

  1. using Learun.DataBase.Repository;
  2. using Learun.Util;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Text;
  6. namespace Learun.Application.Base.SystemModule
  7. {
  8. /// <summary>
  9. /// 版 本 Learun-ADMS-Ultimate V7.0.0 数字化智慧校园
  10. /// Copyright (c) 2013-2018 北京泉江科技有限公司
  11. /// 创建人:陈彬彬
  12. /// 日 期:2017.04.01
  13. /// 描 述:行政区域
  14. /// </summary>
  15. public class AreaService : RepositoryFactory
  16. {
  17. #region 构造函数和属性
  18. private string fieldSql;
  19. public AreaService()
  20. {
  21. fieldSql = @"
  22. t.F_AreaId,
  23. t.F_ParentId,
  24. t.F_AreaCode,
  25. t.F_AreaName,
  26. t.F_QuickQuery,
  27. t.F_SimpleSpelling,
  28. t.F_Layer,
  29. t.F_SortCode,
  30. t.F_DeleteMark,
  31. t.F_EnabledMark,
  32. t.F_Description,
  33. t.F_CreateDate,
  34. t.F_CreateUserId,
  35. t.F_CreateUserName,
  36. t.F_ModifyDate,
  37. t.F_ModifyUserId,
  38. t.F_ModifyUserName ";
  39. }
  40. #endregion
  41. #region 获取数据
  42. /// <summary>
  43. /// 区域列表
  44. /// </summary>
  45. /// <param name="parentId">父节点Id</param>
  46. /// <returns></returns>
  47. public IEnumerable<AreaEntity> GetList(string parentId)
  48. {
  49. try
  50. {
  51. var strSql = new StringBuilder();
  52. strSql.Append("SELECT ");
  53. strSql.Append(fieldSql);
  54. strSql.Append(" FROM LR_Base_Area t WHERE t.F_EnabledMark = 1 AND t.F_DeleteMark = 0 ");
  55. if (parentId == "2")
  56. {
  57. strSql.Append(" AND t.F_Layer=2 ");
  58. }
  59. else
  60. if (!string.IsNullOrEmpty(parentId))
  61. {
  62. strSql.Append(" AND F_ParentId = @F_ParentId ");
  63. }
  64. strSql.Append(" ORDER BY t.F_AreaCode ");
  65. return this.BaseRepository().FindList<AreaEntity>(strSql.ToString(), new { F_ParentId = parentId });
  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 AreaEntity GetEntity(string keyValue)
  85. {
  86. try
  87. {
  88. return this.BaseRepository().FindEntity<AreaEntity>(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. public AreaEntity GetEntityByCode(string code)
  103. {
  104. try
  105. {
  106. return this.BaseRepository().FindEntity<AreaEntity>(x => x.F_AreaCode == code);
  107. }
  108. catch (Exception ex)
  109. {
  110. if (ex is ExceptionEx)
  111. {
  112. throw;
  113. }
  114. else
  115. {
  116. throw ExceptionEx.ThrowServiceException(ex);
  117. }
  118. }
  119. }
  120. #endregion
  121. #region 提交数据
  122. /// <summary>
  123. /// 虚拟删除区域
  124. /// </summary>
  125. /// <param name="keyValue">主键</param>
  126. public void VirtualDelete(string keyValue)
  127. {
  128. try
  129. {
  130. AreaEntity entity = new AreaEntity()
  131. {
  132. F_AreaId = keyValue,
  133. F_DeleteMark = 1
  134. };
  135. this.BaseRepository().Update(entity);
  136. }
  137. catch (Exception ex)
  138. {
  139. if (ex is ExceptionEx)
  140. {
  141. throw;
  142. }
  143. else
  144. {
  145. throw ExceptionEx.ThrowServiceException(ex);
  146. }
  147. }
  148. }
  149. /// <summary>
  150. /// 保存区域表单(新增、修改)
  151. /// </summary>
  152. /// <param name="keyValue">主键值</param>
  153. /// <param name="{">区域实体</param>
  154. /// <returns></returns>
  155. public void SaveEntity(string keyValue, AreaEntity areaEntity)
  156. {
  157. try
  158. {
  159. if (!string.IsNullOrEmpty(keyValue))
  160. {
  161. areaEntity.Modify(keyValue);
  162. this.BaseRepository().Update(areaEntity);
  163. }
  164. else
  165. {
  166. areaEntity.Create();
  167. this.BaseRepository().Insert(areaEntity);
  168. }
  169. }
  170. catch (Exception ex)
  171. {
  172. if (ex is ExceptionEx)
  173. {
  174. throw;
  175. }
  176. else
  177. {
  178. throw ExceptionEx.ThrowServiceException(ex);
  179. }
  180. }
  181. }
  182. #endregion
  183. }
  184. }