public OperateResult Add(AssessmentInfo model) { using (SystemDB db = new SystemDB()) { try { var match = from m in db.assessmentInfoList where m.employeeId == model.employeeId && m.month == model.month select m; if (match.Count() > 0) { return(new OperateResult { content = "数据已经存在", }); } model.inputDate = DateTime.Now; db.assessmentInfoList.Add(model); db.SaveChanges(); return(new OperateResult { status = OperateStatus.Success, }); } catch (Exception ex) { return(new OperateResult { content = ex.Message, }); } } }
public static OperateResult Add(LogRecord model) { using (SystemDB db = new SystemDB()) { try { var match = from m in db.logRecordList select m; if (match.Count() > 0) { return(new OperateResult { content = "用户已经存在", }); } db.logRecordList.Add(model); db.SaveChanges(); return(new OperateResult { status = OperateStatus.Success, }); } catch (Exception ex) { return(new OperateResult { content = ex.Message, }); } } }
public static OperateResult GetByCode(string code) { try { using (SystemDB db = new SystemDB()) { var element = (from m in db.companyList where code == m.code select m ).FirstOrDefault(); if (element == null) { return(new OperateResult { content = "不存在该公司", }); } return(new OperateResult { status = OperateStatus.Success, data = element, }); } } catch (Exception ex) { return(new OperateResult { content = Model.Utility.Utility.GetExceptionMsg(ex), }); } }
public OperateResult Update(AssessmentInfo model) { using (SystemDB db = new SystemDB()) { try { db.Entry(model).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); return(new OperateResult { status = OperateStatus.Success, content = "更新成功" }); } catch (Exception ex) { return(new OperateResult { content = ex.Message, }); } } }
public static OperateResult Add(Company model) { try { using (SystemDB db = new SystemDB()) { var match = from m in db.companyList where m.name.Equals(model.name) || m.code.Equals(model.code) select m; if (match.Count() > 0) { return(new OperateResult { content = "该公司已经存在", }); } db.companyList.Add(model); db.SaveChanges(); return(new OperateResult { status = OperateStatus.Success, }); } } catch (Exception ex) { return(new OperateResult { content = Model.Utility.Utility.GetExceptionMsg(ex), }); } }
public static OperateResult GetById(long id) { try { using (SystemDB db = new SystemDB()) { var element = (from m in db.postInfoList where id == m.id select m ).FirstOrDefault(); if (element == null) { return(new OperateResult { content = "访问错误", }); } return(new OperateResult { status = OperateStatus.Success, data = element, }); } } catch (Exception ex) { return(new OperateResult { content = Model.Utility.Utility.GetExceptionMsg(ex), }); } }
private long GetPersons(long departmentId) { try { using (SystemDB db = new SystemDB()) { long p = db.employeeList.Count(x => x.departmentId == departmentId); var sons = from e in db.departmentList where e.parentId == departmentId select e; foreach (var d in sons) { p += GetPersons(d.id); } return(p); } } catch (Exception ex) { return(0); throw; } }
/// <summary> /// 当月低于该部门该岗位平均实发工资 /// </summary> /// <param name="employee"></param> /// <returns></returns> private static OperateResult CalSalaryInDepInPost(Employee employee) { if (employee.postInfo == null) { return(new OperateResult { content = "无岗位信息", }); } try { var db = new SystemDB(); //得到最近一次该员工的工资数据 var record = db.salaryRecordList.Where(m => m.assessmentInfo.employeeId == employee.id) .OrderByDescending(m => m.assessmentInfo.month) .Select(m => m).FirstOrDefault(); if (record == null) { return(new OperateResult { content = "还未存在工资数据,无法就行分析", }); } //得到最近一月部门内该岗位平均工资 var ave = db.salaryRecordList.Where(m => m.assessmentInfo.month == record.assessmentInfo.month && m.assessmentInfo.employee.departmentId == record.assessmentInfo.employee.departmentId && m.assessmentInfo.employee.postId == record.assessmentInfo.employee.postId) .Average(m => m.actualTotal); if (record.actualTotal < ave) { return(new OperateResult { status = OperateStatus.Success, data = true }); } else { return(new OperateResult { status = OperateStatus.Success, data = false }); } } catch (Exception ex) { return(new OperateResult { content = Model.Utility.Utility.GetExceptionMsg(ex), }); } }
public static OperateResult GetAll(QueryParam param = null) { try { using (SystemDB db = new SystemDB()) { var elements = (from e in db.logRecordList.Include("user") select new { e.id, e.time, e.content, e.type, e.user.name } ).ToList(); return(new OperateResult { status = OperateStatus.Success, data = elements, }); } } catch (Exception ex) { return(new OperateResult { content = Model.Utility.Utility.GetExceptionMsg(ex), }); } }
public OperateResult GetById(long id) { using (SystemDB db = new SystemDB()) { try { var element = (from m in db.userList where id == m.id select m ).FirstOrDefault(); if (element == null) { return(new OperateResult { content = "访问错误", }); } return(new OperateResult { status = OperateStatus.Success, data = element, }); } catch (Exception ex) { return(new OperateResult { content = ex.Message, }); } } }
public static OperateResult GetAll(QueryParam param = null) { try { using (SystemDB db = new SystemDB()) { var elements = (from e in db.postInfoList select e ).ToList(); return(new OperateResult { status = OperateStatus.Success, data = elements, }); } } catch (Exception ex) { return(new OperateResult { content = Model.Utility.Utility.GetExceptionMsg(ex), }); } }
public static OperateResult GetAll(QueryParam param = null) { try { using (SystemDB db = new SystemDB()) { var elements = (from e in db.departmentList let persons = db.employeeList.Count(x => x.departmentId == e.id) select new { e.id, e.name, e.code, _parentId = e.parentId, parentName = e.parent.name, persons = persons } ).ToList(); return(new OperateResult { status = OperateStatus.Success, data = elements, }); } } catch (Exception ex) { return(new OperateResult { content = Model.Utility.Utility.GetExceptionMsg(ex), }); } }
public OperateResult GetAll(QueryParam param = null) { using (SystemDB db = new SystemDB()) { try { var elements = (from e in db.userList select new { e.id, e.name, } ).ToList(); return(new OperateResult { status = OperateStatus.Success, data = elements, }); } catch (Exception ex) { return(new OperateResult { content = ex.Message, }); } } }
public OperateResult Add(Module model) { using (SystemDB db = new SystemDB()) { try { var match = from m in db.moduleList where m.name.Equals(model.name) select m; if (match.Count() > 0) { return(new OperateResult { content = "该模块已经存在", }); } db.moduleList.Add(model); db.SaveChanges(); return(new OperateResult { status = OperateStatus.Success, }); } catch (Exception ex) { return(new OperateResult { content = ex.Message, }); } } }
public static OperateResult RemoveAll() { try { using (SystemDB db = new SystemDB()) { db.postInfoList.RemoveRange(db.postInfoList.ToList()); db.SaveChanges(); LogManager.Add(new LogRecord { userId = SessionHelper.GetUserId(), time = DateTime.Now, type = "Info", content = "删除所有岗位信息" }); return(new OperateResult { status = OperateStatus.Success, content = "删除成功" }); } } catch (Exception ex) { return(new OperateResult { content = Model.Utility.Utility.GetExceptionMsg(ex), }); } }
public static OperateResult GetAll(QueryParam param = null) { try { using (SystemDB db = new SystemDB()) { var elements = (from e in db.moduleList orderby e.showIndex ascending select new { e.id, e.name, _parentId = e.parentId, parentName = e.parent.name } ).ToList(); return(new OperateResult { status = OperateStatus.Success, data = elements, }); } } catch (Exception ex) { return(new OperateResult { content = Model.Utility.Utility.GetExceptionMsg(ex), }); } }
public static OperateResult Update(AssessmentInfo model) { try { using (SystemDB db = new SystemDB()) { model.inputDate = DateTime.Now; db.Entry(model).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); LogManager.Add(new LogRecord { userId = SessionHelper.GetUserId(), time = DateTime.Now, type = "Info", content = "修改考核:" + model.billSerial }); return(new OperateResult { status = OperateStatus.Success, content = "更新成功" }); } } catch (Exception ex) { return(new OperateResult { content = Model.Utility.Utility.GetExceptionMsg(ex), }); } }
public static OperateResult Add(AssessmentInfo model) { try { using (SystemDB db = new SystemDB()) { var match = from m in db.assessmentInfoList where m.employeeId == model.employeeId && m.month == model.month select m; if (match.Count() > 0) { return(new OperateResult { content = "单号为(" + model.billSerial + ")的员工数据已经存在;", }); } var salary = (from s in db.employeeList where s.id == model.employeeId && s.salaryInfoId != null select s).FirstOrDefault(); if (salary == null) { return(new OperateResult { content = "单号为(" + model.billSerial + ")的员工还未设定薪酬;", }); } model.inputDate = DateTime.Now; model.status = "未审核"; db.assessmentInfoList.Add(model); db.SaveChanges(); LogManager.Add(new LogRecord { userId = SessionHelper.GetUserId(), time = DateTime.Now, type = "Info", content = "添加考核:" + model.billSerial }); return(new OperateResult { status = OperateStatus.Success, }); } } catch (Exception ex) { return(new OperateResult { content = "单号为(" + model.billSerial + ")的员工,保存发生错误:" + Model.Utility.Utility.GetExceptionMsg(ex) + ";", }); } }
public OperateResult GetByPager(QueryParam param = null) { using (SystemDB db = new SystemDB()) { try { var elements = from e in db.moduleList select new { e.id, e.name, _parentId = e.parentId }; int total = elements.Count(); /* * int pages = 0; * Pager pager = param.pager; * if (pager == null || pager.rows == 0) * { * pages = total > 0 ? 1 : 0; * } * else * { * pages = total / (pager.rows == 0 ? 10 : pager.rows); * pages = total % pager.rows == 0 ? pages : pages + 1; * if (pager.page <= 1) * { * elements = elements.Take(pager.rows); * } * else * { * elements = elements.Skip((pager.page - 1) * pager.rows).Take(pager.rows); * } * } */ var data = new { pages = 1, total, rows = elements.ToList() }; return(new OperateResult { status = OperateStatus.Success, data = data, }); } catch (Exception ex) { return(new OperateResult { content = ex.Message, }); } } }
public OperateResult GetByPager(QueryParam param = null) { using (SystemDB db = new SystemDB()) { try { var elements = from e in db.userList.Include("role") select new { e.id, e.name, roleName = e.role.name, e.status, e.lastLogin }; int total = elements.Count(); int pages = 0; Pager pager = param.pager; if (pager == null || pager.rows == 0) { pages = total > 0 ? 1 : 0; } else { pages = total / (pager.rows == 0 ? 10 : pager.rows); pages = total % pager.rows == 0 ? pages : pages + 1; if (pager.page <= 1) { elements = elements.Take(pager.rows); } else { elements = elements.Skip((pager.page - 1) * pager.rows).Take(pager.rows); } } var data = new { pages, total, rows = elements.ToList() }; return(new OperateResult { status = OperateStatus.Success, data = data, }); } catch (Exception ex) { return(new OperateResult { content = ex.Message, }); } } }
public static OperateResult ModifyPasswd(long id, string pwdOld, string pwd) { try { using (SystemDB db = new SystemDB()) { var element = (from m in db.userList where id == m.id select m ).FirstOrDefault(); if (element == null) { return(new OperateResult { content = "访问错误", }); } if (element.passwd != MD5Encode.Encode16(pwdOld)) { return(new OperateResult { content = "原密码错误", }); } element.passwd = MD5Encode.Encode16(pwd); db.Entry(element).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); LogManager.Add(new LogRecord { userId = SessionHelper.GetUserId(), time = DateTime.Now, type = "Info", content = "重置密码:" + element.name }); return(new OperateResult { status = OperateStatus.Success, content = "更新成功" }); } } catch (Exception ex) { return(new OperateResult { content = Model.Utility.Utility.GetExceptionMsg(ex), }); } }
public static OperateResult GetByPager(QueryParam param = null) { try { using (SystemDB db = new SystemDB()) { var elements = from e in db.performanceInfoList orderby e.id select new { e.id, e.code, e.performanceRewards, }; int total = elements.Count(); int pages = 0; Pager pager = param.pager; if (pager == null || pager.rows == 0) { pages = total > 0 ? 1 : 0; } else { pages = total / (pager.rows == 0 ? 20 : pager.rows); pages = total % pager.rows == 0 ? pages : pages + 1; if (pager.page <= 1) { elements = elements.Take(pager.rows); } else { elements = elements.Skip((pager.page - 1) * pager.rows).Take(pager.rows); } } var data = new { pages, total, rows = elements.ToList() }; return(new OperateResult { status = OperateStatus.Success, data = data, }); } } catch (Exception ex) { return(new OperateResult { content = Model.Utility.Utility.GetExceptionMsg(ex), }); } }
public static OperateResult Update(Department model) { try { using (SystemDB db = new SystemDB()) { var elements = (from e in db.departmentList where e.id != model.id && e.name == model.name select e ).ToList(); if (elements.Count() >= 1) { return(new OperateResult { content = "已经存在同名的部门", }); } var matchs = (from e in db.departmentList where e.id == model.parentId && e.parentId == model.id select e ).ToList(); if (matchs.Count() >= 1) { return(new OperateResult { content = "该部门与其上级部门互为上下部门", }); } db.Entry(model).State = EntityState.Modified; db.SaveChanges(); LogManager.Add(new LogRecord { userId = SessionHelper.GetUserId(), time = DateTime.Now, type = "Info", content = "修改部门:" + model.name }); return(new OperateResult { status = OperateStatus.Success, content = "更新成功" }); } } catch (Exception ex) { return(new OperateResult { content = Model.Utility.Utility.GetExceptionMsg(ex), }); } }
/// <summary> /// 当月实发工资小于或等于该岗位已离职员工平均工资 /// </summary> /// <param name="employee"></param> /// <returns></returns> private static OperateResult CalSalaryInHistoryPost(Employee employee) { if (employee.postInfo == null) { return(new OperateResult { content = "无岗位信息", }); } try { var db = new SystemDB(); //得到最近一次该员工的工资数据 var record = db.salaryRecordList.Where(m => m.assessmentInfo.employeeId == employee.id) .OrderByDescending(m => m.assessmentInfo.month) .Select(m => m).FirstOrDefault(); if (record == null) { return(new OperateResult { content = "还未存在工资数据,无法就行分析", }); } var ave = (from s in db.salaryRecordList join e in db.EmployeeLeaveList on s.assessmentInfo.employeeId equals e.employeeId where e.postId == employee.postId select s.actualTotal).Average(); if (record.actualTotal < ave) { return(new OperateResult { status = OperateStatus.Success, data = true }); } else { return(new OperateResult { status = OperateStatus.Success, data = false }); } } catch (Exception ex) { return(new OperateResult { content = Model.Utility.Utility.GetExceptionMsg(ex), }); } }
/// <summary> /// /// </summary> /// <param name="employee">实发工资</param> /// <returns>计算成功返回status返回success,如果成立则data返回true,否则返回false</returns> private static OperateResult CalSalaryActualTotal(Employee employee) { try { var db = new SystemDB(); var total = db.EmployeeLeaveList.Count(); var count = 0; var salaryInfo = db.salaryInfoList.Where(m => m.id == employee.salaryInfoId) .Select(m => m).FirstOrDefault(); if (salaryInfo == null) { return(new OperateResult { content = "无薪酬信息", }); } var actualTotal = salaryInfo.GetSalaryTotal(); var dimensionGroup = db.EmployeeLeaveList.GroupBy(g => g.salary) .Select(m => new { salary = m.Key, count = m.Count() }) .OrderByDescending(m => m.count) .ThenBy(m => m.salary); foreach (var item in dimensionGroup) { count += item.count; if (Math.Abs(item.salary - actualTotal) < 0.01) { double percent = count / (double)total; if (percent < LeaveLimitPercent) { return(new OperateResult { status = OperateStatus.Success, data = true, }); } } } } catch (Exception ex) { return(new OperateResult { content = Model.Utility.Utility.GetExceptionMsg(ex), }); } return(new OperateResult { status = OperateStatus.Success, data = false, }); }
/// <summary> /// 先移除role所有的权限,然后重新加入 /// </summary> /// <param name="roleId"></param> /// <param name="idList"></param> /// <returns></returns> public static OperateResult AssignRight(long roleId, List <long> idList) { try { using (SystemDB db = new SystemDB()) { var role = (from e in db.roleList.Include("rightList") where e.id == roleId select e).FirstOrDefault(); if (role == null) { return(new OperateResult { content = "找不到角色" }); } role.rightList.Clear(); foreach (var rid in idList) { var model = db.rightList.Find(rid); role.rightList.Add(model); } db.Entry(role).State = EntityState.Modified; //db.Configuration.ValidateOnSaveEnabled = false; db.SaveChanges(); //db.Configuration.ValidateOnSaveEnabled = true; LogManager.Add(new LogRecord { userId = SessionHelper.GetUserId(), time = DateTime.Now, type = "Info", content = "分配权限:" + role.name }); return(new OperateResult { status = OperateStatus.Success, content = "更新成功" }); } } catch (Exception ex) { return(new OperateResult { content = Model.Utility.Utility.GetExceptionMsg(ex), }); } }
public static OperateResult GetModuleTree(QueryParam param = null) { if (param == null || param.filters == null || !param.filters.Keys.Contains("roleId")) { return(new OperateResult { content = "没有权限" }); } var p = param.filters["roleId"]; long roleId = Convert.ToInt64(p.value ?? "0"); try { Dictionary <Module, IEnumerable <Module> > map = new Dictionary <Module, IEnumerable <Module> >(); var or = GetModulesByRoleId(roleId); if (or.status != OperateStatus.Success) { return(or); } IEnumerable <Module> elements = or.data as IEnumerable <Module>; using (SystemDB db = new SystemDB()) { var parents = from e in elements where e.parentId == null select e; foreach (var m in parents) { var suns = from s in elements where s.parentId == m.id select s; map.Add(m, suns); } return(new OperateResult { status = OperateStatus.Success, data = map, }); } } catch (Exception ex) { return(new OperateResult { content = Model.Utility.Utility.GetExceptionMsg(ex), }); } }
public OperateResult Remove(long id) { using (SystemDB db = new SystemDB()) { try { var element = db.departmentList.Find(id); var elements = db.departmentList.ToList(); if (element == null) { return(new OperateResult { content = "不存在该部门", }); } var query = from e in elements where e.parentId == element.id select e; if (query.Count() > 0) { return(new OperateResult { content = "该部门存在下级部门,不能删除", }); } db.departmentList.Remove(element); db.Entry(element).State = System.Data.Entity.EntityState.Deleted; db.SaveChanges(); LogManager.Add(new LogRecord { userId = SessionHelper.GetUserId(), time = DateTime.Now, type = "Info", content = "删除用户:" + element.name }); return(new OperateResult { status = OperateStatus.Success, content = "删除成功" }); } catch (Exception ex) { return(new OperateResult { content = ex.Message, }); } } }
/// <summary> /// 司龄月数离职率占比相加达60%的司龄段 /// 按照月为单元计算 /// </summary> /// <param name="employee"></param> /// <returns>计算成功返回status返回success,如果成立则data返回true,否则返回false</returns> private static OperateResult CalWorkAge(Employee employee) { if (employee.entryDate == null) { return(new OperateResult() { content = "入职日期有误" }); } try { SystemDB dbLeave = new SystemDB(); var total = dbLeave.EmployeeLeaveList.Count(); var count = 0; //按照月计算 int workAge = Model.Utility.Utility.CalMonths(employee.entryDate.Value, DateTime.Now); var dimensionGroup = dbLeave.EmployeeLeaveList.AsEnumerable().GroupBy(g => Model.Utility.Utility.CalMonths(g.entryDate.Value, g.leaveDate.Value)) .Select(m => new { workAge = m.Key, count = m.Count() }) .OrderBy(m => m.count); foreach (var item in dimensionGroup) { count += item.count; if (item.workAge == workAge) { double percent = count / (double)total; if (percent < LeaveLimitPercent) { return(new OperateResult { status = OperateStatus.Success, data = true, }); } } } } catch (Exception ex) { return(new OperateResult { content = Model.Utility.Utility.GetExceptionMsg(ex), }); } return(new OperateResult { status = OperateStatus.Success, data = false, }); }
public OperateResult Update(User model) { using (SystemDB db = new SystemDB()) { try { var element = (from e in db.userList where e.id != model.id && e.name == model.name select e ).FirstOrDefault(); if (element != null) { return(new OperateResult { content = "已经存在同名", }); } element = (from e in db.userList where e.id == model.id select e ).AsNoTracking().FirstOrDefault(); model.passwd = element.passwd; db.Configuration.ValidateOnSaveEnabled = false; db.Entry(model).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); LogManager.Add(new LogRecord { userId = SessionHelper.GetUserId(), time = DateTime.Now, type = "Info", content = "修改用户:" + model.name }); return(new OperateResult { status = OperateStatus.Success, content = "更新成功" }); } catch (Exception ex) { return(new OperateResult { content = ex.Message, }); } } }