using Learun.DataBase.Repository; using Learun.Util; using System; using System.Collections.Generic; using System.Text; using System.Linq; namespace Learun.Application.Organization { /// /// 版 本 Learun-ADMS-Ultimate V7.0.0 数字化智慧校园 /// Copyright (c) 2013-2018 北京泉江科技有限公司 /// 创建人:陈彬彬 /// 日 期:2017.03.04 /// 描 述:岗位管理 /// public class PostService : RepositoryFactory { #region 构造函数和属性 private 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 IEnumerable GetList(string companyId) { try { 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 = companyId }); } catch (Exception ex) { if (ex is ExceptionEx) { throw; } else { throw ExceptionEx.ThrowServiceException(ex); } } } /// /// 获取岗位数据列表(根据主键串) /// /// 根据主键串 /// public IEnumerable GetListByPostIds(string postIds) { try { return this.BaseRepository().FindList(t => postIds.Contains(t.F_PostId)); } catch (Exception ex) { if (ex is ExceptionEx) { throw; } else { throw ExceptionEx.ThrowServiceException(ex); } } } /// /// 获取岗位的实体数据 /// /// 主键 /// public PostEntity GetEntity(string keyValue) { try { return this.BaseRepository().FindEntity(keyValue); } catch (Exception ex) { if (ex is ExceptionEx) { throw; } else { throw ExceptionEx.ThrowServiceException(ex); } } } #endregion #region 提交数据 /// /// 虚拟删除 /// /// 主键 public void VirtualDelete(string keyValue) { var db = this.BaseRepository().BeginTrans(); try { PostEntity entity = new PostEntity() { F_PostId = keyValue, F_DeleteMark = 1 }; db.Update(entity); db.ExecuteBySql(" Delete From LR_BASE_USERRELATION where F_OBJECTID = @keyValue ", new { keyValue = keyValue }); //db.Delete(t=>t.F_ObjectId == keyValue); db.Commit(); } catch (Exception ex) { db.Rollback(); if (ex is ExceptionEx) { throw; } else { throw ExceptionEx.ThrowServiceException(ex); } } } /// /// 保存岗位(新增、修改) /// /// 主键值 /// 岗位实体 /// public void SaveEntity(string keyValue, PostEntity postEntity) { try { if (!string.IsNullOrEmpty(keyValue)) { postEntity.Modify(keyValue); this.BaseRepository().Update(postEntity); } else { postEntity.Create(); this.BaseRepository().Insert(postEntity); } } catch (Exception ex) { if (ex is ExceptionEx) { throw; } else { throw ExceptionEx.ThrowServiceException(ex); } } } internal bool GetAny() { try { return this.BaseRepository().FindList().ToList().Count() > 0 ? true : false; } catch (Exception ex) { if (ex is ExceptionEx) { throw; } else { throw ExceptionEx.ThrowServiceException(ex); } } } #endregion /// /// 获取下级岗位id集合 /// /// 父级Id集合 /// public List GetIdList(List parentIds) { try { List res = new List(); var list = this.BaseRepository().FindList(t => parentIds.Contains(t.F_ParentId)); foreach (var item in list) { res.Add(item.F_PostId); } return res; } catch (Exception ex) { if (ex is ExceptionEx) { throw; } else { throw ExceptionEx.ThrowServiceException(ex); } } } /// /// 获取部门列表信息(根据公司Id) /// /// public IEnumerable GetAllList() { try { var strSql = new StringBuilder(); strSql.Append("SELECT "); strSql.Append(fieldSql); strSql.Append(" FROM LR_BASE_POST t WHERE t.F_DeleteMark = 0 "); return this.BaseRepository().FindList(strSql.ToString()); } catch (Exception ex) { if (ex is ExceptionEx) { throw; } else { throw ExceptionEx.ThrowServiceException(ex); } } } } }