using learun.iapplication; 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.24 /// 描 述:部门管理 /// public class DepartmentService : ServiceBase { #region 构造函数和属性 private readonly string fieldSql; /// /// /// public DepartmentService() { fieldSql = @" t.F_DepartmentId, t.F_CompanyId, t.F_ParentId, t.F_EnCode, t.F_FullName, t.F_ShortName, t.F_Nature, t.F_Manager, t.F_OuterPhone, t.F_InnerPhone, t.F_Email, t.F_Fax, 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 companyId) { var strSql = new StringBuilder(); strSql.Append("SELECT "); strSql.Append(fieldSql); strSql.Append(" FROM LR_Base_Department t WHERE t.F_EnabledMark = 1 AND t.F_DeleteMark = 0 AND F_CompanyId = @companyId ORDER BY t.F_ParentId,t.F_FullName "); return this.BaseRepository().FindList(strSql.ToString(), new { companyId }); } /// /// 获取部门列表信息(根据公司Id 和 父级 id) /// /// 公司主键 /// 父级 id /// public Task> GetListByPid(string companyId, string pid) { var strSql = new StringBuilder(); strSql.Append("SELECT "); strSql.Append(fieldSql); strSql.Append(" FROM LR_Base_Department t WHERE t.F_EnabledMark = 1 AND t.F_DeleteMark = 0 AND F_CompanyId = @companyId AND F_ParentId = @pid ORDER BY t.F_FullName "); return this.BaseRepository().FindList(strSql.ToString(), new { companyId, pid }); } /// /// 获取部门列表信息(根据公司Id) /// /// 公司主键 /// public Task> GetAllList(string keyWord) { var strSql = new StringBuilder(); strSql.Append("SELECT "); strSql.Append(fieldSql); strSql.Append(" FROM LR_Base_Department t WHERE t.F_EnabledMark = 1 AND t.F_DeleteMark = 0 "); if (!string.IsNullOrEmpty(keyWord)) { keyWord = "%" + keyWord + "%"; strSql.Append("AND ( F_FullName like @keyWord OR F_EnCode like @keyWord OR F_ShortName like @keyWord ) "); } strSql.Append(" ORDER BY t.F_ParentId,t.F_FullName "); return this.BaseRepository().FindList(strSql.ToString(), new { keyWord }); } /// /// 获取部门列表信息(根据部门ID集合) /// /// 部门ID集合 /// public Task> GetListByKeys(List keyValues) { var strSql = new StringBuilder(); strSql.Append("SELECT "); strSql.Append(fieldSql); strSql.Append(" FROM LR_Base_Department t WHERE t.F_EnabledMark = 1 AND t.F_DeleteMark = 0 "); if (keyValues.Count > 0) { strSql.Append(" AND ( "); int num = 0; foreach (var item in keyValues) { if (num > 0) { strSql.Append(" OR "); } strSql.Append(" F_DepartmentId = '" + item + "'"); num++; } strSql.Append(" ) "); } return this.BaseRepository().FindList(strSql.ToString()); } /// /// 获取部门列表信息(根据公司Id) /// /// public Task> GetAllList() { var strSql = new StringBuilder(); strSql.Append("SELECT "); strSql.Append(fieldSql); strSql.Append(" FROM LR_Base_Department t WHERE t.F_EnabledMark = 1 AND t.F_DeleteMark = 0 "); return this.BaseRepository().FindList(strSql.ToString()); } /// /// 获取部门数据实体 /// /// 主键 /// public Task GetEntity(string keyValue) { return this.BaseRepository().FindEntityByKey(keyValue); } #endregion 获取数据 #region 提交数据 /// /// 删除部门 /// /// 主键 public async Task Delete(string keyValue) { await this.BaseRepository().DeleteAny(new { F_DepartmentId = keyValue }); } /// /// 保存部门表单(新增、修改) /// /// 主键值 /// 部门实体 /// public async Task SaveEntity(string keyValue, DepartmentEntity departmentEntity) { if (!string.IsNullOrEmpty(keyValue)) { departmentEntity.F_DepartmentId = keyValue; departmentEntity.F_ModifyDate = DateTime.Now; departmentEntity.F_ModifyUserId = this.GetUserId(); departmentEntity.F_ModifyUserName = this.GetUserName(); await this.BaseRepository().Update(departmentEntity); } else { departmentEntity.F_DepartmentId = Guid.NewGuid().ToString(); departmentEntity.F_CreateDate = DateTime.Now; departmentEntity.F_DeleteMark = 0; departmentEntity.F_EnabledMark = 1; departmentEntity.F_CreateUserId = this.GetUserId(); departmentEntity.F_CreateUserName = this.GetUserName(); await this.BaseRepository().Insert(departmentEntity); } } #endregion 提交数据 } }