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.
 
 
 
 
 
 

364 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 ModuleService : RepositoryFactory
  16. {
  17. #region 属性 构造函数
  18. private string fieldSql;
  19. private string btnfieldSql;
  20. private string colfieldSql;
  21. private string formfieldSql;
  22. public ModuleService()
  23. {
  24. fieldSql = @"
  25. t.F_ModuleId,
  26. t.F_ParentId,
  27. t.F_EnCode,
  28. t.F_FullName,
  29. t.F_Icon,
  30. t.F_UrlAddress,
  31. t.F_Target,
  32. t.F_IsMenu,
  33. t.F_AllowExpand,
  34. t.F_IsPublic,
  35. t.F_AllowEdit,
  36. t.F_AllowDelete,
  37. t.F_SortCode,
  38. t.F_DeleteMark,
  39. t.F_EnabledMark
  40. ";
  41. btnfieldSql = @"
  42. t.F_ModuleButtonId,
  43. t.F_ModuleId,
  44. t.F_ParentId,
  45. t.F_Icon,
  46. t.F_EnCode,
  47. t.F_FullName,
  48. t.F_ActionAddress,
  49. t.F_SortCode
  50. ";
  51. colfieldSql = @"
  52. t.F_ModuleColumnId,
  53. t.F_ModuleId,
  54. t.F_ParentId,
  55. t.F_EnCode,
  56. t.F_FullName,
  57. t.F_SortCode,
  58. t.F_Description
  59. ";
  60. formfieldSql = @"
  61. t.F_ModuleFormId,
  62. t.F_ModuleId,
  63. t.F_EnCode,
  64. t.F_FullName,
  65. t.F_SortCode
  66. ";
  67. }
  68. #endregion
  69. #region 功能模块
  70. /// <summary>
  71. /// 功能列表
  72. /// </summary>
  73. /// <returns></returns>
  74. public IEnumerable<ModuleEntity> GetList()
  75. {
  76. try
  77. {
  78. StringBuilder strSql = new StringBuilder();
  79. strSql.Append("SELECT " + fieldSql + " FROM LR_Base_Module t WHERE t.F_DeleteMark = 0 Order By t.F_ParentId,t.F_SortCode ");
  80. return this.BaseRepository().FindList<ModuleEntity>(strSql.ToString());
  81. }
  82. catch (Exception ex)
  83. {
  84. if (ex is ExceptionEx)
  85. {
  86. throw;
  87. }
  88. else
  89. {
  90. throw ExceptionEx.ThrowServiceException(ex);
  91. }
  92. }
  93. }
  94. /// <summary>
  95. /// 功能实体
  96. /// </summary>
  97. /// <param name="keyValue">主键值</param>
  98. /// <returns></returns>
  99. public ModuleEntity GetEntity(string keyValue)
  100. {
  101. try
  102. {
  103. return this.BaseRepository().FindEntity<ModuleEntity>(keyValue);
  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. #endregion
  118. #region 模块按钮
  119. /// <summary>
  120. /// 获取按钮列表数据
  121. /// </summary>
  122. /// <param name="moduleId">模块Id</param>
  123. /// <returns></returns>
  124. public IEnumerable<ModuleButtonEntity> GetButtonList(string moduleId)
  125. {
  126. try
  127. {
  128. StringBuilder strSql = new StringBuilder();
  129. strSql.Append("SELECT " + btnfieldSql + " FROM LR_Base_ModuleButton t WHERE t.F_ModuleId = @moduleId ORDER BY t.F_SortCode ");
  130. return this.BaseRepository().FindList<ModuleButtonEntity>(strSql.ToString(), new { moduleId = moduleId });
  131. }
  132. catch (Exception ex)
  133. {
  134. if (ex is ExceptionEx)
  135. {
  136. throw;
  137. }
  138. else
  139. {
  140. throw ExceptionEx.ThrowServiceException(ex);
  141. }
  142. }
  143. }
  144. #endregion
  145. #region 模块视图列表
  146. /// <summary>
  147. /// 获取视图列表数据
  148. /// </summary>
  149. /// <param name="moduleId">模块Id</param>
  150. /// <returns></returns>
  151. public IEnumerable<ModuleColumnEntity> GetColumnList(string moduleId)
  152. {
  153. try
  154. {
  155. StringBuilder strSql = new StringBuilder();
  156. strSql.Append("SELECT " + colfieldSql + " FROM LR_Base_ModuleColumn t WHERE t.F_ModuleId = @moduleId ORDER BY t.F_SortCode ");
  157. return this.BaseRepository().FindList<ModuleColumnEntity>(strSql.ToString(), new { moduleId = moduleId });
  158. }
  159. catch (Exception ex)
  160. {
  161. if (ex is ExceptionEx)
  162. {
  163. throw;
  164. }
  165. else
  166. {
  167. throw ExceptionEx.ThrowServiceException(ex);
  168. }
  169. }
  170. }
  171. #endregion
  172. #region 模块表单字段
  173. /// <summary>
  174. /// 获取表单字段数据
  175. /// </summary>
  176. /// <param name="moduleId">模块Id</param>
  177. /// <returns></returns>
  178. public IEnumerable<ModuleFormEntity> GetFormList(string moduleId)
  179. {
  180. try
  181. {
  182. StringBuilder strSql = new StringBuilder();
  183. strSql.Append("SELECT " + formfieldSql + " FROM LR_Base_ModuleForm t WHERE t.F_ModuleId = @moduleId ORDER BY t.F_SortCode ");
  184. return this.BaseRepository().FindList<ModuleFormEntity>(strSql.ToString(), new { moduleId = moduleId });
  185. }
  186. catch (Exception ex)
  187. {
  188. if (ex is ExceptionEx)
  189. {
  190. throw;
  191. }
  192. else
  193. {
  194. throw ExceptionEx.ThrowServiceException(ex);
  195. }
  196. }
  197. }
  198. #endregion
  199. #region 提交数据
  200. /// <summary>
  201. /// 虚拟删除模块功能
  202. /// </summary>
  203. /// <param name="keyValue">主键</param>
  204. public void Delete(string keyValue)
  205. {
  206. var db = this.BaseRepository().BeginTrans();
  207. try
  208. {
  209. db.Delete<ModuleEntity>(t => t.F_ModuleId.Equals(keyValue));
  210. db.Delete<ModuleButtonEntity>(t => t.F_ModuleId.Equals(keyValue));
  211. db.Delete<ModuleColumnEntity>(t => t.F_ModuleId.Equals(keyValue));
  212. db.Delete<ModuleFormEntity>(t => t.F_ModuleId.Equals(keyValue));
  213. db.Commit();
  214. }
  215. catch (Exception ex)
  216. {
  217. db.Rollback();
  218. if (ex is ExceptionEx)
  219. {
  220. throw;
  221. }
  222. else
  223. {
  224. throw ExceptionEx.ThrowServiceException(ex);
  225. }
  226. }
  227. }
  228. /// <summary>
  229. /// 保存模块功能实体(新增、修改)
  230. /// </summary>
  231. /// <param name="keyValue">主键值</param>
  232. /// <param name="moduleEntity">实体</param>
  233. /// <returns></returns>
  234. public void SaveEntity(string keyValue, ModuleEntity moduleEntity)
  235. {
  236. try
  237. {
  238. if (!string.IsNullOrEmpty(keyValue))
  239. {
  240. moduleEntity.Modify(keyValue);
  241. this.BaseRepository().Update(moduleEntity);
  242. }
  243. else
  244. {
  245. moduleEntity.Create();
  246. this.BaseRepository().Insert(moduleEntity);
  247. }
  248. }
  249. catch (Exception ex)
  250. {
  251. if (ex is ExceptionEx)
  252. {
  253. throw;
  254. }
  255. else
  256. {
  257. throw ExceptionEx.ThrowServiceException(ex);
  258. }
  259. }
  260. }
  261. /// <summary>
  262. /// 保存模块功能实体(新增、修改)
  263. /// </summary>
  264. /// <param name="keyValue">主键值</param>
  265. /// <param name="moduleEntity">实体</param>
  266. /// <param name="moduleButtonEntitys">按钮列表</param>
  267. /// <param name="moduleColumnEntitys">视图列集合</param>
  268. public void SaveEntity(string keyValue, ModuleEntity moduleEntity, List<ModuleButtonEntity> moduleButtonEntitys, List<ModuleColumnEntity> moduleColumnEntitys, List<ModuleFormEntity> moduleFormEntitys)
  269. {
  270. var db = this.BaseRepository().BeginTrans();
  271. try
  272. {
  273. if (string.IsNullOrEmpty(moduleEntity.F_ParentId) || moduleEntity.F_ParentId == "-1")
  274. {
  275. moduleEntity.F_ParentId = "0";
  276. }
  277. if (string.IsNullOrEmpty(keyValue))
  278. {
  279. // 新增
  280. moduleEntity.Create();
  281. db.Insert(moduleEntity);
  282. }
  283. else
  284. {
  285. // 编辑
  286. moduleEntity.Modify(keyValue);
  287. db.Update(moduleEntity);
  288. db.Delete<ModuleButtonEntity>(t => t.F_ModuleId.Equals(keyValue));
  289. db.Delete<ModuleColumnEntity>(t => t.F_ModuleId.Equals(keyValue));
  290. db.Delete<ModuleFormEntity>(t => t.F_ModuleId.Equals(keyValue));
  291. }
  292. int num = 0;
  293. if (moduleButtonEntitys != null)
  294. {
  295. foreach (var item in moduleButtonEntitys)
  296. {
  297. item.F_SortCode = num;
  298. item.F_ModuleId = moduleEntity.F_ModuleId;
  299. if (moduleButtonEntitys.Find(t => t.F_ModuleButtonId == item.F_ParentId) == null)
  300. {
  301. item.F_ParentId = "0";
  302. }
  303. db.Insert(item);
  304. num++;
  305. }
  306. }
  307. if (moduleColumnEntitys != null)
  308. {
  309. num = 0;
  310. foreach (var item in moduleColumnEntitys)
  311. {
  312. item.F_SortCode = num;
  313. item.F_ModuleId = moduleEntity.F_ModuleId;
  314. db.Insert(item);
  315. num++;
  316. }
  317. }
  318. if (moduleFormEntitys != null)
  319. {
  320. num = 0;
  321. foreach (var item in moduleFormEntitys)
  322. {
  323. item.F_SortCode = num;
  324. item.F_ModuleId = moduleEntity.F_ModuleId;
  325. db.Insert(item);
  326. num++;
  327. }
  328. }
  329. db.Commit();
  330. }
  331. catch (Exception ex)
  332. {
  333. db.Rollback();
  334. if (ex is ExceptionEx)
  335. {
  336. throw;
  337. }
  338. else
  339. {
  340. throw ExceptionEx.ThrowServiceException(ex);
  341. }
  342. }
  343. }
  344. #endregion
  345. }
  346. }