using Learun.Util; using Learun.Util.SqlSugar; using SqlSugar; using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Text; using DbType = System.Data.DbType; namespace Learun.Application.Organization { /// /// 版 本 PIT-ADMS V7.0.3 敏捷开发框架 /// Copyright (c) 2013-2018 Hexagon PPM /// 创建人:研发部 /// 日 期:2017.03.04 /// 描 述:岗位管理 /// public class PostService { #region 仓储 Repository _postRepository => new Repository(); #endregion #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 List GetList(string companyId) { try { return _postRepository.GetList().Where(t => t.F_DeleteMark == 0 && t.F_CompanyId == companyId). OrderBy(t => t.F_DepartmentId).OrderBy(t => t.F_ParentId).OrderBy(t => t.F_EnCode).ToList(); } catch (Exception ex) { if (ex is ExceptionEx) { throw; } else { throw ExceptionEx.ThrowServiceException(ex); } } } /// /// 获取岗位数据列表 /// /// 公司主键 /// public List GetPostList(Pagination paginationobj, string queryJson) { try { var queryParam = queryJson.ToJObject(); //var dp = new DynamicParameters(new { }); var list = _postRepository.GetList().Where(t => t.F_DeleteMark == 0); var dp = new List(); if (!queryParam["keyword"].IsEmpty()) { list = list.Where(x => x.F_Name.Contains(queryParam["keyword"].ToString())); } if (!queryParam["ProjectId"].IsEmpty()) { list = list.Where(x => x.ProjectId == queryParam["ProjectId"].ToString()); } //return this.BaseRepository().FindList(strSql.ToString(), dp); return list.OrderBy(x => x.F_EnCode).ToList(); } catch (Exception ex) { if (ex is ExceptionEx) { throw; } else { throw ExceptionEx.ThrowServiceException(ex); } } } /// /// 获取所有岗位数据 /// /// 公司主键 /// public List GetPostListByProjectId(string ProjectId) { try { var strSql = new StringBuilder(); strSql.Append("SELECT "); strSql.Append("t.* , (SELECT COUNT(1) FROM LR_Base_UserRelation t1 WHERE 1=1 AND IFNULL(t1.ProjectId,'') = @ProjectId AND t1.F_ObjectId = t.F_PostId) AS UserCount"); strSql.Append(" FROM LR_Base_Post t WHERE t.F_DeleteMark = 0 AND IFNULL(t.ProjectId,'') = @ProjectId "); //return this.BaseRepository().FindList(strSql.ToString(), new { ProjectId = ProjectId }); return SqlSugarHelper.Db.SqlQueryable(strSql.ToString()).AddParameters(new { ProjectId = ProjectId }).ToList(); } catch (Exception ex) { if (ex is ExceptionEx) { throw; } else { throw ExceptionEx.ThrowServiceException(ex); } } } /// /// 获取岗位数据列表(根据主键串) /// /// 根据主键串 /// public IEnumerable GetListByPostIds(string postIds) { try { return _postRepository.GetList(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 _postRepository.GetById(keyValue); } catch (Exception ex) { if (ex is ExceptionEx) { throw; } else { throw ExceptionEx.ThrowServiceException(ex); } } } //查找具体项目下公司人员对应的岗位 public DataTable GetPostByProjectId(string ProjectId) { string sqlstr = @"SELECT u.F_UserId,p.F_Name FROM lr_base_post p JOIN lr_base_userrelation u ON u.F_Category = 1 AND u.ProjectId = '" + ProjectId + "' AND u.F_ObjectId = p.F_PostId"; var data = SqlSugarHelper.Db.Ado.GetDataTable(sqlstr); return data; } /// /// 获取下级岗位id集合 /// /// 父级Id集合 /// public List GetIdList(List parentIds) { try { List res = new List(); var list = _postRepository.GetList(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); } } } #endregion #region 提交数据 /// /// 虚拟删除 /// /// 主键 public void VirtualDelete(string keyValue) { SqlSugarHelper.Db.BeginTran(); try { PostEntity entity = new PostEntity() { F_PostId = keyValue, F_DeleteMark = 1 }; _postRepository.Update(entity); SqlSugarHelper.Db.Ado.ExecuteCommand(" Delete From LR_BASE_USERRELATION where F_OBJECTID = @keyValue ", new { keyValue = keyValue }); //db.Delete(t=>t.F_ObjectId == keyValue); SqlSugarHelper.Db.CommitTran(); } catch (Exception ex) { SqlSugarHelper.Db.RollbackTran(); 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); _postRepository.Update(postEntity); } else { postEntity.Create(); _postRepository.Insert(postEntity); } } catch (Exception ex) { if (ex is ExceptionEx) { throw; } else { throw ExceptionEx.ThrowServiceException(ex); } } } #endregion } }