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.18 /// 描 述:行政区域 /// public class AreaService : ServiceBase { #region 构造函数和属性 private readonly string fieldSql; /// /// /// public AreaService() { fieldSql = @" t.F_AreaId, t.F_ParentId, t.F_AreaCode, t.F_AreaName, t.F_QuickQuery, t.F_SimpleSpelling, t.F_Layer, 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 获取数据 /// /// 区域列表 /// /// 父节点Id /// 关键词 /// public Task> GetList(string parentId, string keyword) { var strSql = new StringBuilder(); strSql.Append("SELECT "); strSql.Append(fieldSql); strSql.Append(" FROM LR_Base_Area t WHERE t.F_EnabledMark = 1"); strSql.Append(" AND F_ParentId = @parentId "); if (string.IsNullOrEmpty(parentId)) { parentId = "0"; } if (!string.IsNullOrEmpty(keyword)) { strSql.Append(" AND (F_AreaName like @keyword or F_AreaCode like @keyword)"); keyword = "%" + keyword + "%"; } strSql.Append(" ORDER BY t.F_AreaCode "); return this.BaseRepository().FindList(strSql.ToString(), new { parentId, keyword }); } /// /// 区域实体 /// /// 主键值 /// public Task GetEntity(string keyValue) { return this.BaseRepository().FindEntityByKey(keyValue); } #endregion 获取数据 #region 提交数据 /// /// 删除区域 /// /// 主键 public async Task Delete(string keyValue) { await this.BaseRepository().DeleteAny(new { F_AreaId = keyValue }); } /// /// 保存区域表单(新增、修改) /// /// 主键值 /// 区域实体 /// public async Task SaveEntity(string keyValue, AreaEntity areaEntity) { areaEntity.F_QuickQuery = Str.ConvertPinYin(areaEntity.F_AreaName).ToUpper(); areaEntity.F_SimpleSpelling = Str.PinYin(areaEntity.F_AreaName); if (!string.IsNullOrEmpty(keyValue)) { areaEntity.F_AreaId = keyValue; areaEntity.F_ModifyDate = DateTime.Now; areaEntity.F_ModifyUserId = this.GetUserId(); areaEntity.F_ModifyUserName = this.GetUserName(); await this.BaseRepository().Update(areaEntity); } else { areaEntity.F_AreaId = Guid.NewGuid().ToString(); areaEntity.F_CreateDate = DateTime.Now; areaEntity.F_DeleteMark = 0; areaEntity.F_EnabledMark = 1; areaEntity.F_CreateUserId = this.GetUserId(); areaEntity.F_CreateUserName = this.GetUserName(); await this.BaseRepository().Insert(areaEntity); } } #endregion 提交数据 } }