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 PostService : ServiceBase { #region 构造函数和属性 private readonly string fieldSql; /// /// /// public PostService() { fieldSql = @" t.F_PostId, t.F_ParentId, t.F_Name, t.F_EnCode, t.F_CompanyId, t.F_DepartmentId, t.F_DeleteMark, 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> GetList(string companyId) { var strSql = new StringBuilder(); strSql.Append("SELECT "); strSql.Append(fieldSql); strSql.Append(" FROM LR_Base_Post t WHERE t.F_DeleteMark = 0 AND t.F_CompanyId =@companyId ORDER BY t.F_DepartmentId,t.F_ParentId,t.F_EnCode "); return this.BaseRepository().FindList(strSql.ToString(), new { companyId }); } /// /// 获取岗位数据列表(根据公司列表) /// /// 公司主键 /// 部门Id /// 关键词 /// public Task> GetList(string companyId, string departmentId, string keyword) { var strSql = new StringBuilder(); strSql.Append("SELECT "); strSql.Append(fieldSql); strSql.Append(" FROM LR_Base_Post t WHERE t.F_DeleteMark = 0 "); if (!string.IsNullOrEmpty(companyId)) { strSql.Append(" AND t.F_CompanyId =@companyId "); } if (!string.IsNullOrEmpty(departmentId)) { strSql.Append(" AND t.F_DepartmentId =@departmentId "); } if (!string.IsNullOrEmpty(keyword)) { keyword = "%" + keyword + "%"; strSql.Append(" AND t.F_Name like @keyword "); } strSql.Append("ORDER BY t.F_DepartmentId,t.F_ParentId,t.F_EnCode"); return this.BaseRepository().FindList(strSql.ToString(), new { companyId, departmentId, keyword }); } /// /// 获取岗位数据列表(根据主键串) /// /// 根据主键串 /// public Task> GetListByPostIds(string postIds) { var strSql = new StringBuilder(); strSql.Append("SELECT "); strSql.Append(fieldSql); strSql.Append(" FROM LR_Base_Post t WHERE t.F_DeleteMark = 0 "); strSql.Append(" AND F_PostId in ('" + postIds.Replace(",", "','") + "')"); return this.BaseRepository().FindList(strSql.ToString()); } /// /// 获取岗位的实体数据 /// /// 主键 /// public Task GetEntity(string keyValue) { return this.BaseRepository().FindEntityByKey(keyValue); } /// /// 获取下级岗位id集合 /// /// 父级Id集合 /// public async Task> GetIdList(List parentIds) { List res = new List(); var strSql = new StringBuilder(); strSql.Append("SELECT "); strSql.Append(fieldSql); strSql.Append(" FROM LR_Base_Post t WHERE t.F_DeleteMark = 0 "); if (parentIds.Count > 0) { strSql.Append(" AND ( "); int num = 0; foreach (var item in parentIds) { if (num > 0) { strSql.Append(" OR "); } strSql.Append(" F_ParentId = '" + item + "'"); num++; } strSql.Append(" ) "); } var list = await this.BaseRepository().FindList(strSql.ToString()); foreach (var item in list) { res.Add(item.F_PostId); } return res; } #endregion 获取数据 #region 提交数据 /// /// 删除 /// /// 主键 public async Task Delete(string keyValue) { var db = this.BaseRepository().BeginTrans(); try { await db.DeleteAny(new { F_PostId = keyValue }); await db.ExecuteSql(" Delete From LR_BASE_USERRELATION where F_OBJECTID = @keyValue ", new { keyValue }); db.Commit(); } catch (Exception) { db.Rollback(); throw; } } /// /// 保存岗位(新增、修改) /// /// 主键值 /// 岗位实体 /// public async Task SaveEntity(string keyValue, PostEntity postEntity) { if (!string.IsNullOrEmpty(keyValue)) { postEntity.F_PostId = keyValue; postEntity.F_ModifyDate = DateTime.Now; postEntity.F_ModifyUserId = this.GetUserId(); postEntity.F_ModifyUserName = this.GetUserName(); await this.BaseRepository().Update(postEntity); } else { postEntity.F_PostId = Guid.NewGuid().ToString(); postEntity.F_CreateDate = DateTime.Now; postEntity.F_DeleteMark = 0; postEntity.F_CreateUserId = this.GetUserId(); postEntity.F_CreateUserName = this.GetUserName(); await this.BaseRepository().Insert(postEntity); } } #endregion 提交数据 } }