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.
 
 
 
 
 
 

262 lines
8.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.03.08
  13. /// 描 述:数据字典管理服务类
  14. /// </summary>
  15. public class DataItemService : RepositoryFactory
  16. {
  17. #region 属性 构造函数
  18. private string fieldSql;
  19. private string detailFieldSql;
  20. public DataItemService()
  21. {
  22. fieldSql = @"
  23. t.F_ItemId,
  24. t.F_ParentId,
  25. t.F_ItemCode,
  26. t.F_ItemName,
  27. t.F_IsTree,
  28. t.F_IsNav,
  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. detailFieldSql = @"
  41. t.F_ItemDetailId,
  42. t.F_ItemId,
  43. t.F_ParentId,
  44. t.F_ItemCode,
  45. t.F_ItemName,
  46. t.F_ItemValue,
  47. t.F_QuickQuery,
  48. t.F_SimpleSpelling,
  49. t.F_IsDefault,
  50. t.F_SortCode,
  51. t.F_DeleteMark,
  52. t.F_EnabledMark,
  53. t.F_Description,
  54. t.F_CreateDate,
  55. t.F_CreateUserId,
  56. t.F_CreateUserName,
  57. t.F_ModifyDate,
  58. t.F_ModifyUserId,
  59. t.F_ModifyUserName
  60. ";
  61. }
  62. #endregion
  63. #region 数据字典分类管理
  64. /// <summary>
  65. /// 分类列表
  66. /// </summary>
  67. /// <returns></returns>
  68. public IEnumerable<DataItemEntity> GetClassifyList()
  69. {
  70. try
  71. {
  72. StringBuilder strSql = new StringBuilder();
  73. strSql.Append("SELECT " + fieldSql + " FROM LR_Base_DataItem t WHERE t.F_DeleteMark = 0 Order By t.F_ParentId,t.F_SortCode ");
  74. return this.BaseRepository().FindList<DataItemEntity>(strSql.ToString());
  75. }
  76. catch (Exception ex)
  77. {
  78. if (ex is ExceptionEx)
  79. {
  80. throw;
  81. }
  82. else
  83. {
  84. throw ExceptionEx.ThrowServiceException(ex);
  85. }
  86. }
  87. }
  88. /// <summary>
  89. /// 虚拟删除分类数据
  90. /// </summary>
  91. /// <param name="keyValue">主键</param>
  92. public void VirtualDeleteClassify(string keyValue)
  93. {
  94. try
  95. {
  96. DataItemEntity entity = new DataItemEntity()
  97. {
  98. F_ItemId = keyValue,
  99. F_DeleteMark = 1
  100. };
  101. this.BaseRepository().Update(entity);
  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. /// 保存分类数据实体
  117. /// </summary>
  118. /// <param name="keyValue">主键</param>
  119. /// <param name="entity">实体</param>
  120. public void SaveClassifyEntity(string keyValue, DataItemEntity entity) {
  121. try
  122. {
  123. if (string.IsNullOrEmpty(keyValue))
  124. {
  125. entity.Create();
  126. this.BaseRepository().Insert(entity);
  127. }
  128. else {
  129. entity.Modify(keyValue);
  130. this.BaseRepository().Update(entity);
  131. }
  132. }
  133. catch (Exception ex)
  134. {
  135. if (ex is ExceptionEx)
  136. {
  137. throw;
  138. }
  139. else
  140. {
  141. throw ExceptionEx.ThrowServiceException(ex);
  142. }
  143. }
  144. }
  145. #endregion
  146. #region 数据字典明细
  147. /// <summary>
  148. /// 获取数据字典明显根据分类编号
  149. /// </summary>
  150. /// <param name="itemCode">分类编号</param>
  151. /// <returns></returns>
  152. public IEnumerable<DataItemDetailEntity> GetDetailList(string itemCode)
  153. {
  154. try
  155. {
  156. StringBuilder strSql = new StringBuilder();
  157. strSql.Append("SELECT " + detailFieldSql + @" FROM LR_Base_DataItemDetail t
  158. INNER JOIN LR_Base_DataItem t2 ON t.F_ItemId = t2.F_ItemId
  159. WHERE t2.F_ItemCode = @itemCode AND t.F_DeleteMark = 0 Order By t.F_SortCode
  160. ");
  161. return this.BaseRepository().FindList<DataItemDetailEntity>(strSql.ToString(), new { itemCode = itemCode });
  162. }
  163. catch (Exception ex)
  164. {
  165. if (ex is ExceptionEx)
  166. {
  167. throw;
  168. }
  169. else
  170. {
  171. throw ExceptionEx.ThrowServiceException(ex);
  172. }
  173. }
  174. }
  175. /// <summary>
  176. /// 获取数据字典明细实体类
  177. /// </summary>
  178. /// <param name="keyValue">主键</param>
  179. /// <returns></returns>
  180. public DataItemDetailEntity GetDetailEntity(string keyValue) {
  181. try
  182. {
  183. return this.BaseRepository().FindEntity<DataItemDetailEntity>(keyValue);
  184. }
  185. catch (Exception ex)
  186. {
  187. if (ex is ExceptionEx)
  188. {
  189. throw;
  190. }
  191. else
  192. {
  193. throw ExceptionEx.ThrowServiceException(ex);
  194. }
  195. }
  196. }
  197. /// <summary>
  198. /// 虚拟删除明细数据
  199. /// </summary>
  200. /// <param name="keyValue">主键</param>
  201. public void VirtualDeleteDetail(string keyValue)
  202. {
  203. try
  204. {
  205. DataItemDetailEntity entity = new DataItemDetailEntity()
  206. {
  207. F_ItemDetailId = keyValue,
  208. F_DeleteMark = 1
  209. };
  210. this.BaseRepository().Update(entity);
  211. }
  212. catch (Exception ex)
  213. {
  214. if (ex is ExceptionEx)
  215. {
  216. throw;
  217. }
  218. else
  219. {
  220. throw ExceptionEx.ThrowServiceException(ex);
  221. }
  222. }
  223. }
  224. /// <summary>
  225. /// 保存明细数据实体
  226. /// </summary>
  227. /// <param name="keyValue">主键</param>
  228. /// <param name="entity">实体</param>
  229. public void SaveDetailEntity(string keyValue, DataItemDetailEntity entity)
  230. {
  231. try
  232. {
  233. if (string.IsNullOrEmpty(keyValue))
  234. {
  235. entity.Create();
  236. this.BaseRepository().Insert(entity);
  237. }
  238. else
  239. {
  240. entity.Modify(keyValue);
  241. this.BaseRepository().Update(entity);
  242. }
  243. }
  244. catch (Exception ex)
  245. {
  246. if (ex is ExceptionEx)
  247. {
  248. throw;
  249. }
  250. else
  251. {
  252. throw ExceptionEx.ThrowServiceException(ex);
  253. }
  254. }
  255. }
  256. #endregion
  257. }
  258. }