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.
 
 
 
 
 
 

359 lines
12 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. {
  124. try
  125. {
  126. if (string.IsNullOrEmpty(keyValue))
  127. {
  128. entity.Create();
  129. this.BaseRepository().Insert(entity);
  130. }
  131. else
  132. {
  133. entity.Modify(keyValue);
  134. this.BaseRepository().Update(entity);
  135. }
  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. #endregion
  150. #region 数据字典明细
  151. /// <summary>
  152. /// 获取数据字典明细
  153. /// </summary>
  154. /// <returns></returns>
  155. public IEnumerable<DataItemDetailEntity> GetAllDetailList()
  156. {
  157. try
  158. {
  159. StringBuilder strSql = new StringBuilder();
  160. strSql.Append("SELECT " + @"t.F_ItemId,
  161. t.F_ParentId,
  162. t2.F_ItemCode,
  163. t.F_ItemName,
  164. t.F_ItemValue " + @" FROM LR_Base_DataItemDetail t
  165. INNER JOIN LR_Base_DataItem t2 ON t.F_ItemId = t2.F_ItemId
  166. WHERE t.F_DeleteMark = 0 and t.F_EnabledMark=1 Order By t.F_SortCode
  167. ");
  168. return this.BaseRepository().FindList<DataItemDetailEntity>(strSql.ToString());
  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. /// <summary>
  183. /// 获取数据字典明显根据分类编号
  184. /// </summary>
  185. /// <param name="itemCode">分类编号</param>
  186. /// <returns></returns>
  187. public IEnumerable<DataItemDetailEntity> GetDetailList(string itemCode)
  188. {
  189. try
  190. {
  191. StringBuilder strSql = new StringBuilder();
  192. strSql.Append("SELECT " + detailFieldSql + @" FROM LR_Base_DataItemDetail t
  193. INNER JOIN LR_Base_DataItem t2 ON t.F_ItemId = t2.F_ItemId
  194. WHERE t2.F_ItemCode = @itemCode AND t.F_DeleteMark = 0 and t.F_EnabledMark=1 Order By t.F_SortCode
  195. ");
  196. return this.BaseRepository().FindList<DataItemDetailEntity>(strSql.ToString(), new { itemCode = itemCode });
  197. }
  198. catch (Exception ex)
  199. {
  200. if (ex is ExceptionEx)
  201. {
  202. throw;
  203. }
  204. else
  205. {
  206. throw ExceptionEx.ThrowServiceException(ex);
  207. }
  208. }
  209. }
  210. /// <summary>
  211. /// 获取数据字典明显根据分类编号
  212. /// </summary>
  213. /// <param name="itemCode">分类编号</param>
  214. /// <returns></returns>
  215. public IEnumerable<DataItemDetailEntity> GetDetailList2(string itemCode)
  216. {
  217. try
  218. {
  219. StringBuilder strSql = new StringBuilder();
  220. strSql.Append("SELECT " + detailFieldSql + @" FROM LR_Base_DataItemDetail t
  221. INNER JOIN LR_Base_DataItem t2 ON t.F_ItemId = t2.F_ItemId
  222. WHERE t2.F_ItemCode = @itemCode AND t.F_DeleteMark = 0 Order By t.F_SortCode
  223. ");
  224. return this.BaseRepository().FindList<DataItemDetailEntity>(strSql.ToString(), new { itemCode = itemCode });
  225. }
  226. catch (Exception ex)
  227. {
  228. if (ex is ExceptionEx)
  229. {
  230. throw;
  231. }
  232. else
  233. {
  234. throw ExceptionEx.ThrowServiceException(ex);
  235. }
  236. }
  237. }
  238. /// <summary>
  239. /// 获取数据字典明显根据分类编号 +条件
  240. /// </summary>
  241. /// <param name="itemCode"></param>
  242. /// <param name="strWhere"></param>
  243. /// <returns></returns>
  244. public IEnumerable<DataItemDetailEntity> GetDetailList3(string itemCode, string strWhere)
  245. {
  246. try
  247. {
  248. StringBuilder strSql = new StringBuilder();
  249. strSql.Append(" SELECT " + detailFieldSql + @" FROM LR_Base_DataItemDetail t
  250. INNER JOIN LR_Base_DataItem t2 ON t.F_ItemId = t2.F_ItemId
  251. WHERE t2.F_ItemCode = @itemCode AND t.F_DeleteMark = 0 ");
  252. if (!string.IsNullOrEmpty(strWhere))
  253. {
  254. strSql.Append(strWhere);
  255. }
  256. return this.BaseRepository().FindList<DataItemDetailEntity>(strSql.ToString(), new { itemCode = itemCode });
  257. }
  258. catch (Exception ex)
  259. {
  260. if (ex is ExceptionEx)
  261. {
  262. throw;
  263. }
  264. else
  265. {
  266. throw ExceptionEx.ThrowServiceException(ex);
  267. }
  268. }
  269. }
  270. /// <summary>
  271. /// 获取数据字典明细实体类
  272. /// </summary>
  273. /// <param name="keyValue">主键</param>
  274. /// <returns></returns>
  275. public DataItemDetailEntity GetDetailEntity(string keyValue)
  276. {
  277. try
  278. {
  279. return this.BaseRepository().FindEntity<DataItemDetailEntity>(keyValue);
  280. }
  281. catch (Exception ex)
  282. {
  283. if (ex is ExceptionEx)
  284. {
  285. throw;
  286. }
  287. else
  288. {
  289. throw ExceptionEx.ThrowServiceException(ex);
  290. }
  291. }
  292. }
  293. /// <summary>
  294. /// 虚拟删除明细数据
  295. /// </summary>
  296. /// <param name="keyValue">主键</param>
  297. public void VirtualDeleteDetail(string keyValue)
  298. {
  299. try
  300. {
  301. DataItemDetailEntity entity = new DataItemDetailEntity()
  302. {
  303. F_ItemDetailId = keyValue,
  304. F_DeleteMark = 1
  305. };
  306. this.BaseRepository().Update(entity);
  307. }
  308. catch (Exception ex)
  309. {
  310. if (ex is ExceptionEx)
  311. {
  312. throw;
  313. }
  314. else
  315. {
  316. throw ExceptionEx.ThrowServiceException(ex);
  317. }
  318. }
  319. }
  320. /// <summary>
  321. /// 保存明细数据实体
  322. /// </summary>
  323. /// <param name="keyValue">主键</param>
  324. /// <param name="entity">实体</param>
  325. public void SaveDetailEntity(string keyValue, DataItemDetailEntity entity)
  326. {
  327. try
  328. {
  329. if (string.IsNullOrEmpty(keyValue))
  330. {
  331. entity.Create();
  332. this.BaseRepository().Insert(entity);
  333. }
  334. else
  335. {
  336. entity.Modify(keyValue);
  337. this.BaseRepository().Update(entity);
  338. }
  339. }
  340. catch (Exception ex)
  341. {
  342. if (ex is ExceptionEx)
  343. {
  344. throw;
  345. }
  346. else
  347. {
  348. throw ExceptionEx.ThrowServiceException(ex);
  349. }
  350. }
  351. }
  352. #endregion
  353. }
  354. }