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.
 
 
 
 
 
 

296 lines
9.2 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_ItemCodeGB,
  27. t.F_ItemName,
  28. t.F_IsTree,
  29. t.F_IsNav,
  30. t.F_SortCode,
  31. t.F_DeleteMark,
  32. t.F_EnabledMark,
  33. t.F_Description,
  34. t.F_CreateDate,
  35. t.F_CreateUserId,
  36. t.F_CreateUserName,
  37. t.F_ModifyDate,
  38. t.F_ModifyUserId,
  39. t.F_ModifyUserName
  40. ";
  41. detailFieldSql = @"
  42. t.F_ItemDetailId,
  43. t.F_ItemId,
  44. t.F_ParentId,
  45. t.F_ItemCode,
  46. t.F_ItemCodeGB,
  47. t.F_ItemName,
  48. t.F_ItemValue,
  49. t.F_QuickQuery,
  50. t.F_SimpleSpelling,
  51. t.F_IsDefault,
  52. t.F_SortCode,
  53. t.F_DeleteMark,
  54. t.F_EnabledMark,
  55. t.F_Description,
  56. t.F_CreateDate,
  57. t.F_CreateUserId,
  58. t.F_CreateUserName,
  59. t.F_ModifyDate,
  60. t.F_ModifyUserId,
  61. t.F_ModifyUserName
  62. ";
  63. }
  64. #endregion
  65. #region 数据字典分类管理
  66. /// <summary>
  67. /// 分类列表
  68. /// </summary>
  69. /// <returns></returns>
  70. public IEnumerable<DataItemEntity> GetClassifyList()
  71. {
  72. try
  73. {
  74. StringBuilder strSql = new StringBuilder();
  75. strSql.Append("SELECT " + fieldSql + " FROM LR_Base_DataItem t WHERE t.F_DeleteMark = 0 and t.F_EnabledMark=1 Order By t.F_ParentId,t.F_SortCode ");
  76. return this.BaseRepository().FindList<DataItemEntity>(strSql.ToString());
  77. }
  78. catch (Exception ex)
  79. {
  80. if (ex is ExceptionEx)
  81. {
  82. throw;
  83. }
  84. else
  85. {
  86. throw ExceptionEx.ThrowServiceException(ex);
  87. }
  88. }
  89. }
  90. /// <summary>
  91. /// 虚拟删除分类数据
  92. /// </summary>
  93. /// <param name="keyValue">主键</param>
  94. public void VirtualDeleteClassify(string keyValue)
  95. {
  96. try
  97. {
  98. DataItemEntity entity = new DataItemEntity()
  99. {
  100. F_ItemId = keyValue,
  101. F_DeleteMark = 1
  102. };
  103. this.BaseRepository().Update(entity);
  104. }
  105. catch (Exception ex)
  106. {
  107. if (ex is ExceptionEx)
  108. {
  109. throw;
  110. }
  111. else
  112. {
  113. throw ExceptionEx.ThrowServiceException(ex);
  114. }
  115. }
  116. }
  117. /// <summary>
  118. /// 保存分类数据实体
  119. /// </summary>
  120. /// <param name="keyValue">主键</param>
  121. /// <param name="entity">实体</param>
  122. public void SaveClassifyEntity(string keyValue, DataItemEntity entity) {
  123. try
  124. {
  125. if (string.IsNullOrEmpty(keyValue))
  126. {
  127. entity.Create();
  128. this.BaseRepository().Insert(entity);
  129. }
  130. else {
  131. entity.Modify(keyValue);
  132. this.BaseRepository().Update(entity);
  133. }
  134. }
  135. catch (Exception ex)
  136. {
  137. if (ex is ExceptionEx)
  138. {
  139. throw;
  140. }
  141. else
  142. {
  143. throw ExceptionEx.ThrowServiceException(ex);
  144. }
  145. }
  146. }
  147. #endregion
  148. #region 数据字典明细
  149. /// <summary>
  150. /// 获取数据字典明细
  151. /// </summary>
  152. /// <returns></returns>
  153. public IEnumerable<DataItemDetailEntity> GetAllDetailList()
  154. {
  155. try
  156. {
  157. StringBuilder strSql = new StringBuilder();
  158. strSql.Append("SELECT " + @"t.F_ItemId,
  159. t.F_ParentId,
  160. t2.F_ItemCode,
  161. t.F_ItemName,
  162. t.F_ItemValue " + @" FROM LR_Base_DataItemDetail t
  163. INNER JOIN LR_Base_DataItem t2 ON t.F_ItemId = t2.F_ItemId
  164. WHERE t.F_DeleteMark = 0 and t.F_EnabledMark=1 Order By t.F_SortCode
  165. ");
  166. return this.BaseRepository().FindList<DataItemDetailEntity>(strSql.ToString());
  167. }
  168. catch (Exception ex)
  169. {
  170. if (ex is ExceptionEx)
  171. {
  172. throw;
  173. }
  174. else
  175. {
  176. throw ExceptionEx.ThrowServiceException(ex);
  177. }
  178. }
  179. }
  180. /// <summary>
  181. /// 获取数据字典明显根据分类编号
  182. /// </summary>
  183. /// <param name="itemCode">分类编号</param>
  184. /// <returns></returns>
  185. public IEnumerable<DataItemDetailEntity> GetDetailList(string itemCode)
  186. {
  187. try
  188. {
  189. StringBuilder strSql = new StringBuilder();
  190. strSql.Append("SELECT " + detailFieldSql + @" FROM LR_Base_DataItemDetail t
  191. INNER JOIN LR_Base_DataItem t2 ON t.F_ItemId = t2.F_ItemId
  192. WHERE t2.F_ItemCode = @itemCode AND t.F_DeleteMark = 0 and t.F_EnabledMark=1 Order By t.F_SortCode
  193. ");
  194. return this.BaseRepository().FindList<DataItemDetailEntity>(strSql.ToString(), new { itemCode = itemCode });
  195. }
  196. catch (Exception ex)
  197. {
  198. if (ex is ExceptionEx)
  199. {
  200. throw;
  201. }
  202. else
  203. {
  204. throw ExceptionEx.ThrowServiceException(ex);
  205. }
  206. }
  207. }
  208. /// <summary>
  209. /// 获取数据字典明细实体类
  210. /// </summary>
  211. /// <param name="keyValue">主键</param>
  212. /// <returns></returns>
  213. public DataItemDetailEntity GetDetailEntity(string keyValue) {
  214. try
  215. {
  216. return this.BaseRepository().FindEntity<DataItemDetailEntity>(keyValue);
  217. }
  218. catch (Exception ex)
  219. {
  220. if (ex is ExceptionEx)
  221. {
  222. throw;
  223. }
  224. else
  225. {
  226. throw ExceptionEx.ThrowServiceException(ex);
  227. }
  228. }
  229. }
  230. /// <summary>
  231. /// 虚拟删除明细数据
  232. /// </summary>
  233. /// <param name="keyValue">主键</param>
  234. public void VirtualDeleteDetail(string keyValue)
  235. {
  236. try
  237. {
  238. DataItemDetailEntity entity = new DataItemDetailEntity()
  239. {
  240. F_ItemDetailId = keyValue,
  241. F_DeleteMark = 1
  242. };
  243. this.BaseRepository().Update(entity);
  244. }
  245. catch (Exception ex)
  246. {
  247. if (ex is ExceptionEx)
  248. {
  249. throw;
  250. }
  251. else
  252. {
  253. throw ExceptionEx.ThrowServiceException(ex);
  254. }
  255. }
  256. }
  257. /// <summary>
  258. /// 保存明细数据实体
  259. /// </summary>
  260. /// <param name="keyValue">主键</param>
  261. /// <param name="entity">实体</param>
  262. public void SaveDetailEntity(string keyValue, DataItemDetailEntity entity)
  263. {
  264. try
  265. {
  266. if (string.IsNullOrEmpty(keyValue))
  267. {
  268. entity.Create();
  269. this.BaseRepository().Insert(entity);
  270. }
  271. else
  272. {
  273. entity.Modify(keyValue);
  274. this.BaseRepository().Update(entity);
  275. }
  276. }
  277. catch (Exception ex)
  278. {
  279. if (ex is ExceptionEx)
  280. {
  281. throw;
  282. }
  283. else
  284. {
  285. throw ExceptionEx.ThrowServiceException(ex);
  286. }
  287. }
  288. }
  289. #endregion
  290. }
  291. }