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 /// 日 期:2019.09.19 /// 描 述:数据字典管理服务类 /// public class DataItemService : ServiceBase { #region 属性 构造函数 private readonly string fieldSql; private readonly string detailFieldSql; /// /// /// public DataItemService() { fieldSql = @" t.F_ItemId, t.F_ParentId, t.F_ItemCode, t.F_ItemName, t.F_IsTree, t.F_IsNav, t.F_SortCode, t.F_DeleteMark, t.F_EnabledMark, t.F_Description, t.F_CreateDate, t.F_CreateUserId, t.F_CreateUserName, t.F_ModifyDate, t.F_ModifyUserId, t.F_ModifyUserName "; detailFieldSql = @" t.F_ItemDetailId, t.F_ItemId, t.F_ParentId, t.F_ItemCode, t.F_ItemName, t.F_ItemValue, t.F_QuickQuery, t.F_SimpleSpelling, t.F_IsDefault, t.F_SortCode, t.F_DeleteMark, t.F_EnabledMark, t.F_Description, t.F_CreateDate, t.F_CreateUserId, t.F_CreateUserName, t.F_ModifyDate, t.F_ModifyUserId, t.F_ModifyUserName "; } #endregion 属性 构造函数 #region 数据字典分类管理 /// /// 分类列表 /// /// public Task> GetClassifyList() { StringBuilder strSql = new StringBuilder(); strSql.Append("SELECT " + fieldSql + " FROM LR_Base_DataItem t WHERE t.F_DeleteMark = 0 Order By t.F_ParentId,t.F_SortCode "); return this.BaseRepository().FindList(strSql.ToString()); } /// /// 通过编号获取字典分类实体 /// /// 编码 /// public Task GetClassifyEntityByCode(string itemCode) { StringBuilder strSql = new StringBuilder(); strSql.Append("SELECT " + fieldSql + " FROM LR_Base_DataItem t WHERE t.F_DeleteMark = 0 AND F_ItemCode =@itemCode "); return this.BaseRepository().FindEntity(strSql.ToString(), new { itemCode }); } /// /// 通过编号获取字典分类实体 /// /// 主键 /// public Task GetClassifyEntityByKey(string keyValue) { StringBuilder strSql = new StringBuilder(); strSql.Append("SELECT " + fieldSql + " FROM LR_Base_DataItem t WHERE t.F_DeleteMark = 0 AND F_ItemId =@keyValue "); return this.BaseRepository().FindEntity(strSql.ToString(), new { keyValue }); } /// /// 删除分类数据 /// /// 主键 public async Task DeleteClassify(string keyValue) { var db = this.BaseRepository().BeginTrans(); try { await db.DeleteAny(new { F_ItemId = keyValue }); await db.DeleteAny(new { F_ItemId = keyValue }); db.Commit(); } catch (Exception) { db.Rollback(); throw; } } /// /// 保存分类数据实体 /// /// 主键 /// 实体 public async Task SaveClassifyEntity(string keyValue, DataItemEntity entity) { if (string.IsNullOrEmpty(keyValue)) { entity.F_ItemId = Guid.NewGuid().ToString(); entity.F_CreateDate = DateTime.Now; //entity.F_EnabledMark = 1; entity.F_DeleteMark = 0; entity.F_CreateUserId = this.GetUserId(); entity.F_CreateUserName = this.GetUserName(); await this.BaseRepository().Insert(entity); } else { entity.F_ItemId = keyValue; entity.F_ModifyDate = DateTime.Now; entity.F_ModifyUserId = this.GetUserId(); entity.F_ModifyUserName = this.GetUserName(); await this.BaseRepository().Update(entity); } } #endregion 数据字典分类管理 #region 数据字典明细 /// /// 获取数据字典明显根据分类编号 /// /// 分类编号 /// public Task> GetDetailList(string itemCode) { StringBuilder strSql = new StringBuilder(); strSql.Append("SELECT " + detailFieldSql + @" FROM LR_Base_DataItemDetail t INNER JOIN LR_Base_DataItem t2 ON t.F_ItemId = t2.F_ItemId WHERE t2.F_ItemCode = @itemCode AND t.F_DeleteMark = 0 Order By t.F_SortCode "); return this.BaseRepository().FindList(strSql.ToString(), new { itemCode }); } /// /// 获取数据字典明细实体类 /// /// 主键 /// public Task GetDetailEntity(string keyValue) { return this.BaseRepository().FindEntity(keyValue); } /// /// 删除明细数据 /// /// 主键 public async Task DeleteDetail(string keyValue) { await this.BaseRepository().DeleteAny(new { F_ItemDetailId = keyValue }); } /// /// 保存明细数据实体 /// /// 主键 /// 实体 public async Task SaveDetailEntity(string keyValue, DataItemDetailEntity entity) { entity.F_QuickQuery = Str.ConvertPinYin(entity.F_ItemName).ToUpper(); entity.F_SimpleSpelling = Str.PinYin(entity.F_ItemName); if (string.IsNullOrEmpty(keyValue)) { entity.F_ItemDetailId = Guid.NewGuid().ToString(); entity.F_CreateDate = DateTime.Now; entity.F_DeleteMark = 0; await this.BaseRepository().Insert(entity); } else { entity.F_ItemDetailId = keyValue; entity.F_ModifyDate = DateTime.Now; await this.BaseRepository().Update(entity); } } #endregion 数据字典明细 } }