using Learun.DataBase.Repository; using Learun.Util; using System; using System.Collections.Generic; using System.Text; namespace Learun.Application.Base.SystemModule { /// /// 版 本 Learun-ADMS-Ultimate V7.0.0 数字化智慧校园 /// Copyright (c) 2013-2018 北京泉江科技有限公司 /// 创建人:陈彬彬 /// 日 期:2017.03.08 /// 描 述:功能模块 /// public class ModuleService : RepositoryFactory { #region 属性 构造函数 private string fieldSql; private string btnfieldSql; private string colfieldSql; private string formfieldSql; public ModuleService() { fieldSql = @" t.F_ModuleId, t.F_ParentId, t.F_EnCode, t.F_FullName, t.F_Icon, t.F_UrlAddress, t.F_Target, t.F_IsMenu, t.F_AllowExpand, t.F_IsPublic, t.F_AllowEdit, t.F_AllowDelete, t.F_SortCode, t.F_DeleteMark, t.F_EnabledMark "; btnfieldSql = @" t.F_ModuleButtonId, t.F_ModuleId, t.F_ParentId, t.F_Icon, t.F_EnCode, t.F_FullName, t.F_ActionAddress, t.F_SortCode "; colfieldSql = @" t.F_ModuleColumnId, t.F_ModuleId, t.F_ParentId, t.F_EnCode, t.F_FullName, t.F_SortCode, t.F_Description "; formfieldSql = @" t.F_ModuleFormId, t.F_ModuleId, t.F_EnCode, t.F_FullName, t.F_SortCode "; } #endregion #region 功能模块 /// /// 功能列表 /// /// public IEnumerable GetList() { try { StringBuilder strSql = new StringBuilder(); strSql.Append("SELECT " + fieldSql + " FROM LR_Base_Module t WHERE t.F_DeleteMark = 0 Order By t.F_ParentId,t.F_SortCode "); return this.BaseRepository().FindList(strSql.ToString()); } catch (Exception ex) { if (ex is ExceptionEx) { throw; } else { throw ExceptionEx.ThrowServiceException(ex); } } } /// /// 功能实体 /// /// 主键值 /// public ModuleEntity GetEntity(string keyValue) { try { return this.BaseRepository().FindEntity(keyValue); } catch (Exception ex) { if (ex is ExceptionEx) { throw; } else { throw ExceptionEx.ThrowServiceException(ex); } } } #endregion #region 模块按钮 /// /// 获取按钮列表数据 /// /// 模块Id /// public IEnumerable GetButtonList(string moduleId) { try { StringBuilder strSql = new StringBuilder(); strSql.Append("SELECT " + btnfieldSql + " FROM LR_Base_ModuleButton t WHERE t.F_ModuleId = @moduleId ORDER BY t.F_SortCode "); return this.BaseRepository().FindList(strSql.ToString(), new { moduleId = moduleId }); } catch (Exception ex) { if (ex is ExceptionEx) { throw; } else { throw ExceptionEx.ThrowServiceException(ex); } } } #endregion #region 模块视图列表 /// /// 获取视图列表数据 /// /// 模块Id /// public IEnumerable GetColumnList(string moduleId) { try { StringBuilder strSql = new StringBuilder(); strSql.Append("SELECT " + colfieldSql + " FROM LR_Base_ModuleColumn t WHERE t.F_ModuleId = @moduleId ORDER BY t.F_SortCode "); return this.BaseRepository().FindList(strSql.ToString(), new { moduleId = moduleId }); } catch (Exception ex) { if (ex is ExceptionEx) { throw; } else { throw ExceptionEx.ThrowServiceException(ex); } } } #endregion #region 模块表单字段 /// /// 获取表单字段数据 /// /// 模块Id /// public IEnumerable GetFormList(string moduleId) { try { StringBuilder strSql = new StringBuilder(); strSql.Append("SELECT " + formfieldSql + " FROM LR_Base_ModuleForm t WHERE t.F_ModuleId = @moduleId ORDER BY t.F_SortCode "); return this.BaseRepository().FindList(strSql.ToString(), new { moduleId = moduleId }); } catch (Exception ex) { if (ex is ExceptionEx) { throw; } else { throw ExceptionEx.ThrowServiceException(ex); } } } #endregion #region 提交数据 /// /// 虚拟删除模块功能 /// /// 主键 public void Delete(string keyValue) { var db = this.BaseRepository().BeginTrans(); try { db.Delete(t => t.F_ModuleId.Equals(keyValue)); db.Delete(t => t.F_ModuleId.Equals(keyValue)); db.Delete(t => t.F_ModuleId.Equals(keyValue)); db.Delete(t => t.F_ModuleId.Equals(keyValue)); db.Commit(); } catch (Exception ex) { db.Rollback(); if (ex is ExceptionEx) { throw; } else { throw ExceptionEx.ThrowServiceException(ex); } } } /// /// 保存模块功能实体(新增、修改) /// /// 主键值 /// 实体 /// public void SaveEntity(string keyValue, ModuleEntity moduleEntity) { try { if (!string.IsNullOrEmpty(keyValue)) { moduleEntity.Modify(keyValue); this.BaseRepository().Update(moduleEntity); } else { moduleEntity.Create(); this.BaseRepository().Insert(moduleEntity); } } catch (Exception ex) { if (ex is ExceptionEx) { throw; } else { throw ExceptionEx.ThrowServiceException(ex); } } } /// /// 保存模块功能实体(新增、修改) /// /// 主键值 /// 实体 /// 按钮列表 /// 视图列集合 public void SaveEntity(string keyValue, ModuleEntity moduleEntity, List moduleButtonEntitys, List moduleColumnEntitys, List moduleFormEntitys) { var db = this.BaseRepository().BeginTrans(); try { if (string.IsNullOrEmpty(moduleEntity.F_ParentId) || moduleEntity.F_ParentId == "-1") { moduleEntity.F_ParentId = "0"; } if (string.IsNullOrEmpty(keyValue)) { // 新增 moduleEntity.Create(); db.Insert(moduleEntity); } else { // 编辑 moduleEntity.Modify(keyValue); db.Update(moduleEntity); db.Delete(t => t.F_ModuleId.Equals(keyValue)); db.Delete(t => t.F_ModuleId.Equals(keyValue)); db.Delete(t => t.F_ModuleId.Equals(keyValue)); } int num = 0; if (moduleButtonEntitys != null) { foreach (var item in moduleButtonEntitys) { item.F_SortCode = num; item.F_ModuleId = moduleEntity.F_ModuleId; if (moduleButtonEntitys.Find(t => t.F_ModuleButtonId == item.F_ParentId) == null) { item.F_ParentId = "0"; } db.Insert(item); num++; } } if (moduleColumnEntitys != null) { num = 0; foreach (var item in moduleColumnEntitys) { item.F_SortCode = num; item.F_ModuleId = moduleEntity.F_ModuleId; db.Insert(item); num++; } } if (moduleFormEntitys != null) { num = 0; foreach (var item in moduleFormEntitys) { item.F_SortCode = num; item.F_ModuleId = moduleEntity.F_ModuleId; db.Insert(item); num++; } } db.Commit(); } catch (Exception ex) { db.Rollback(); if (ex is ExceptionEx) { throw; } else { throw ExceptionEx.ThrowServiceException(ex); } } } #endregion } }