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.
 
 
 
 
 
 

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