using learun.database; using learun.iapplication; using learun.util; using System; using System.Collections.Generic; using System.Text; using System.Threading.Tasks; namespace learun.application { /// /// 版 本 EasyCode EC管理后台 /// Copyright (c) 2019-present EC管理有限公司 /// 创建人:tobin /// 日 期:2020.04.07 /// 描 述:移动端功能管理 /// public class FunctionSerivce : ServiceBase { #region 属性 构造函数 private readonly string sql; /// /// /// public FunctionSerivce() { sql = @" t.F_Id, t.F_Type, t.F_FormId, t.F_CodeId, t.F_CreateDate, t.F_CreateUserId, t.F_CreateUserName, t.F_ModifyDate, t.F_ModifyUserId, t.F_ModifyUserName, t.F_Icon, t.F_Name, t.F_SchemeId, t.F_EnabledMark, t.F_SortCode, t.F_Url, t.F_IsSystem "; } #endregion 属性 构造函数 #region 获取数据 /// /// 获取分页列表 /// /// 分页参数 /// 关键字 /// 分类 /// public Task> GetPageList(Pagination pagination, string keyword, string type) { var strSql = new StringBuilder(); strSql.Append("SELECT "); strSql.Append(sql); strSql.Append(" FROM LR_App_Function t where 1=1 "); if (!string.IsNullOrEmpty(keyword)) { strSql.Append(" AND ( t.F_Name like @keyword ) "); keyword = "%" + keyword + "%"; } if (!string.IsNullOrEmpty(type)) { strSql.Append(" AND t.F_Type = @type "); } return this.BaseRepository().FindList(strSql.ToString(), new { keyword, type }, pagination); } /// /// 获取列表数据 /// /// public Task> GetList() { var strSql = new StringBuilder(); strSql.Append("SELECT "); strSql.Append(sql); strSql.Append(" ,s.F_Scheme FROM LR_App_Function t LEFT JOIN LR_App_FnScheme s on t.F_SchemeId = s.F_Id where t.F_EnabledMark = 1 ORDER BY F_SortCode "); return this.BaseRepository().FindList(strSql.ToString()); } /// /// 获取移动功能模板 /// /// 主键 /// public Task GetScheme(string keyValue) { return this.BaseRepository().FindEntityByKey(keyValue); } /// /// 获取实体对象 /// /// 主键 /// public Task GetEntity(string keyValue) { return this.BaseRepository().FindEntityByKey(keyValue); } #endregion 获取数据 #region 提交数据 /// /// 删除 /// /// 主键 public async Task Delete(string keyValue) { var db = this.BaseRepository().BeginTrans(); try { FunctionEntity entity = await db.FindEntityByKey(keyValue); string schemeId = entity.F_SchemeId; if (!string.IsNullOrEmpty(schemeId)) { await db.DeleteAny(new { F_Id = schemeId }); } await db.DeleteAny(new { F_Id = keyValue }); db.Commit(); } catch (Exception) { db.Rollback(); throw; } } /// /// 保存 /// /// 主键 /// 功能信息 /// 功能模板信息 /// public async Task SaveEntity(string keyValue, FunctionEntity functionEntity, FunctionSchemeEntity functionSchemeEntity) { IRepository db = this.BaseRepository().BeginTrans(); try { // 如果是代码开发功能 if (functionEntity.F_IsSystem == 1) { if (!string.IsNullOrEmpty(functionEntity.F_SchemeId)) { await db.DeleteAny(new { F_Id = functionEntity.F_SchemeId }); } } else { #region 模板信息 if (string.IsNullOrEmpty(functionEntity.F_SchemeId)) { functionSchemeEntity.F_Id = Guid.NewGuid().ToString(); await db.Insert(functionSchemeEntity); functionEntity.F_SchemeId = functionSchemeEntity.F_Id; } else { functionSchemeEntity.F_Id = functionEntity.F_SchemeId; await db.Update(functionSchemeEntity); } #endregion 模板信息 } if (string.IsNullOrEmpty(keyValue)) { functionEntity.F_Id = Guid.NewGuid().ToString(); functionEntity.F_CreateDate = DateTime.Now; functionEntity.F_EnabledMark = 1; functionEntity.F_CreateUserId = this.GetUserId(); functionEntity.F_CreateUserName = this.GetUserName(); await db.Insert(functionEntity); } else { functionEntity.F_Id = keyValue; functionEntity.F_ModifyDate = DateTime.Now; functionEntity.F_ModifyUserId = this.GetUserId(); functionEntity.F_ModifyUserName = this.GetUserName(); await db.Update(functionEntity); } db.Commit(); } catch (Exception) { db.Rollback(); throw; } } /// /// 更新状态 /// /// 模板信息主键 /// 状态1启用0禁用 public async Task UpdateState(string keyValue, int state) { FunctionEntity entity = new FunctionEntity { F_Id = keyValue, F_EnabledMark = state }; await this.BaseRepository().Update(entity); } #endregion 提交数据 } }