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.
 
 
 
 
 
 

174 lines
5.0 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. #endregion
  103. #region 提交数据
  104. /// <summary>
  105. /// 虚拟删除区域
  106. /// </summary>
  107. /// <param name="keyValue">主键</param>
  108. public void VirtualDelete(string keyValue)
  109. {
  110. try
  111. {
  112. AreaEntity entity = new AreaEntity()
  113. {
  114. F_AreaId = keyValue,
  115. F_DeleteMark = 1
  116. };
  117. this.BaseRepository().Update(entity);
  118. }
  119. catch (Exception ex)
  120. {
  121. if (ex is ExceptionEx)
  122. {
  123. throw;
  124. }
  125. else
  126. {
  127. throw ExceptionEx.ThrowServiceException(ex);
  128. }
  129. }
  130. }
  131. /// <summary>
  132. /// 保存区域表单(新增、修改)
  133. /// </summary>
  134. /// <param name="keyValue">主键值</param>
  135. /// <param name="{">区域实体</param>
  136. /// <returns></returns>
  137. public void SaveEntity(string keyValue, AreaEntity areaEntity)
  138. {
  139. try
  140. {
  141. if (!string.IsNullOrEmpty(keyValue))
  142. {
  143. areaEntity.Modify(keyValue);
  144. this.BaseRepository().Update(areaEntity);
  145. }
  146. else
  147. {
  148. areaEntity.Create();
  149. this.BaseRepository().Insert(areaEntity);
  150. }
  151. }
  152. catch (Exception ex)
  153. {
  154. if (ex is ExceptionEx)
  155. {
  156. throw;
  157. }
  158. else
  159. {
  160. throw ExceptionEx.ThrowServiceException(ex);
  161. }
  162. }
  163. }
  164. #endregion
  165. }
  166. }