/// <summary> /// 清空组织结构 /// </summary> private void ClearOrg_Old() { //人员 BP.DA.DBAccess.RunSQL("DELETE FROM Port_Emp"); //部门 BP.DA.DBAccess.RunSQL("DELETE FROM Port_Dept"); //部门人员 BP.DA.DBAccess.RunSQL("DELETE FROM Port_DeptEmp"); //部门人员岗位 BP.DA.DBAccess.RunSQL("DELETE FROM Port_DeptEmpStation"); //admin 是必须存在的 Emp emp = new Emp(); emp.No = "admin"; emp.Pass = "******"; emp.Name = "管理员"; emp.FK_Dept = "1"; emp.DirectInsert(); //部门人员关联表 DeptEmp deptEmp = new DeptEmp(); deptEmp.FK_Dept = "1"; deptEmp.FK_Emp = "admin"; deptEmp.DirectInsert(); }
public IActionResult Post(DeptEmp deptEmp) { var dept = serv1.CreateAsync(deptEmp.Department).Result; foreach (var e in deptEmp.Employees) { var res = serv2.CreateAsync(e).Result; } return(Ok()); }
public async Task <ActionResult> Edit(DeptEmp dept_emp) { try { if (ModelState.IsValid) { await _deptEmpService.UpdateDeptEmp(dept_emp); return(RedirectToAction("Index")); } var departments = Common.GetDepartments(_departmentService); ViewBag.DepartmentList = departments; var employees = Common.GetEmployees(_employeeService); ViewBag.EmployeeList = employees; return(View(dept_emp)); } catch (Exception ex) { if (ex.InnerException != null) { int index = ex.InnerException.Message.IndexOf("UC_"); string message = ex.InnerException.Message; if (index > 0) { message = message.Substring(0, index - 1); } ModelState.AddModelError("Error", "There was an error during: " + message); } else { ModelState.AddModelError("Error", "There was an error during: " + ex.ToString()); } var departments = Common.GetDepartments(_departmentService); ViewBag.DepartmentList = departments; var employees = Common.GetEmployees(_employeeService); ViewBag.EmployeeList = employees; return(View(dept_emp)); } }
/// <summary> /// 当前提交人的直线领导 /// </summary> /// <returns></returns> private DataTable GenerHisLeader(string empNo, string empDept) { DeptEmp de = new DeptEmp(); DataTable dt = new DataTable(); string leader = null; string tempDeptNo = ""; switch (this.HisFindLeaderModel) { case FindLeaderModel.DirLeader: // 直接领导. sql = "SELECT Leader FROM Port_DeptEmp WHERE FK_Emp='" + empNo + "' AND FK_Dept='" + empDept + "'"; dt = BP.DA.DBAccess.RunSQLReturnTable(sql); leader = dt.Rows[0][0] as string; if (string.IsNullOrEmpty(leader)) { throw new Exception("@系统管理员没有给(" + empNo + ")在部门(" + empDept + ")中设置直接领导."); } break; case FindLeaderModel.SpecDutyLevelLeader: // 特定职务级别的领导. tempDeptNo = empDept.Clone() as string; while (true) { sql = "SELECT FK_Emp FROM Port_DeptEmp WHERE DutyLevel='" + this.TagVal2 + "' AND FK_Dept='" + tempDeptNo + "'"; DataTable mydt = DBAccess.RunSQLReturnTable(sql); if (mydt.Rows.Count != 0) { return(mydt); /*直接反回.*/ } Dept d = new Dept(tempDeptNo); if (d.ParentNo == "0") { return(null); /*如果到了跟节点.*/ } tempDeptNo = d.ParentNo; } break; case FindLeaderModel.DutyLeader: // 特定职务的领导. tempDeptNo = empDept.Clone() as string; while (true) { sql = "SELECT FK_Emp FROM Port_DeptEmp WHERE FK_Duty='" + this.TagVal2 + "' AND FK_Dept='" + tempDeptNo + "'"; DataTable mydt = DBAccess.RunSQLReturnTable(sql); if (mydt.Rows.Count != 0) { return(mydt); /*直接反回.*/ } Dept d = new Dept(tempDeptNo); if (d.ParentNo == "0") { return(null); /*如果到了跟节点.*/ } tempDeptNo = d.ParentNo; } break; case FindLeaderModel.SpecStation: // 特定岗位的领导. tempDeptNo = empDept.Clone() as string; while (true) { sql = "SELECT FK_Emp FROM Port_DeptEmpStation WHERE FK_Station='" + this.TagVal2 + "' AND FK_Dept='" + tempDeptNo + "'"; DataTable mydt = DBAccess.RunSQLReturnTable(sql); if (mydt.Rows.Count != 0) { return(mydt); /*直接反回.*/ } Dept d = new Dept(tempDeptNo); if (d.ParentNo == "0") { /* 在直线领导中没有找到 */ return(null); /*如果到了跟节点.*/ } tempDeptNo = d.ParentNo; } break; default: break; } // 增加列. dt.Columns.Add(new DataColumn("No", typeof(string))); DataRow dr = dt.NewRow(); dr[0] = leader; dt.Rows.Add(dr); return(dt); }
public async Task <IActionResult> Generate() { var existingEmployess = await _employeeService.GetAll(); if (existingEmployess.Count > 0) { return(View()); } var daysGenerator = new RandomGenerator(); string[] gender = { "M", "F" }; var employees = Builder <Employee> .CreateListOfSize(10000) .All() .With(c => c.Ssn = Faker.Identification.SocialSecurityNumber()) .With(c => c.FirstName = Faker.Name.First()) .With(c => c.MiddleName = Faker.Name.Middle()) .With(c => c.LastName = Faker.Name.Last()) .With(c => c.Gender = Faker.Extensions.ArrayExtensions.Random(gender)) .With(c => c.HireDate = DateTime.Now.AddDays(-daysGenerator.Next(1, 3650))) // HireDate within last 10 years .With(c => c.BirthDate = DateTime.Now.AddDays(-daysGenerator.Next(6750, 21170))) // Age between 18 to 58 Years .With(c => c.Address1 = Faker.Address.StreetAddress()) .With(c => c.Address2 = Faker.Address.StreetName()) .With(c => c.City = Faker.Address.City()) .With(c => c.State = Faker.Address.UsStateAbbr()) .With(c => c.Zipcode = Faker.Address.ZipCode()) .With(c => c.HomePhone = Faker.Phone.Number()) .With(c => c.MobilePhone = Faker.Phone.Number()) .With(c => c.Email = Faker.Internet.Email()) .Build(); foreach (var employee in employees) { try { employee.HomePhone = employee.HomePhone.Replace("(", "").Replace(")", "").Replace("-", ""); if (employee.HomePhone.Length > 12) { employee.HomePhone = employee.HomePhone.Substring(0, 12); } else { employee.HomePhone = employee.HomePhone.Substring(0, employee.HomePhone.Length); } employee.MobilePhone = employee.MobilePhone.Replace("(", "").Replace(")", "").Replace("-", ""); if (employee.MobilePhone.Length > 12) { employee.MobilePhone = employee.MobilePhone.Substring(0, 12); } else { employee.MobilePhone = employee.MobilePhone.Substring(0, employee.MobilePhone.Length); } await _employeeService.AddEmployee(employee); } catch (Exception ex) { } } string[] departments = { "Transport", "Security", "Research and development", "Product development", "Learning and development", "IT services", "Infrastructures", "Engineering", "Business development", "Admin", "Accounts and Finance" }; string[] titles = { "Vice-President", "Senior Account Manager", "Account Manager", "Senior Project Manager", "Project Manager", "Senior Technical Lead", "Technical Lead", "Project Lead", "Senior Team Lead", "Team Lead", "Module Lead", "Senior Software Engineer", "Software Engineer", "Associate Software Engineer", "Intern" }; for (int i = 0; i < departments.Length; i++) { Department dept = new Department(); dept.DeptNo = "D" + i; dept.Name = departments[i]; await _departmentService.AddDepartment(dept); var flag = false; while (!flag) { try { var index = daysGenerator.Next(1, employees.Count); var emp = employees[index - 1]; DeptManager deptManager = new DeptManager(); deptManager.DeptNo = dept.DeptNo; deptManager.EmpNo = emp.EmpNo; deptManager.FromDate = DateTime.Now.AddDays(-daysGenerator.Next(1, 3650)); deptManager.ToDate = deptManager.FromDate.Value.AddDays(daysGenerator.Next(1, 3650)); await _deptManagerService.AddDeptManager(deptManager); flag = true; } catch (Exception) { flag = false; } } } foreach (var employee in employees) { try { var index = daysGenerator.Next(1, departments.Length); var dept = departments[index - 1]; DeptEmp deptEmp = new DeptEmp(); deptEmp.DeptNo = "D" + (index - 1).ToString(); deptEmp.EmpNo = employee.EmpNo; deptEmp.FromDate = DateTime.Now.AddDays(-daysGenerator.Next(1, 3650)); deptEmp.ToDate = deptEmp.FromDate.Value.AddDays(daysGenerator.Next(1, 3650)); Expression <Func <DeptEmp, bool> > deptEmpPred = d => (d.EmpNo == employee.EmpNo && d.DeptNo == deptEmp.DeptNo); var dept_emp = _deptEmpService.FindDeptEmp(deptEmpPred).Result.FirstOrDefault(); if (dept_emp == null) { await _deptEmpService.AddDeptEmp(deptEmp); } Salary salary = new Salary(); salary.EmpNo = employee.EmpNo; salary.Salary1 = daysGenerator.Next(25000, 200000); salary.FromDate = DateTime.Now.AddDays(-daysGenerator.Next(1, 3650)); salary.ToDate = salary.FromDate.Value.AddDays(daysGenerator.Next(1, 3650)); await _salaryService.AddSalary(salary); index = daysGenerator.Next(1, titles.Length); var sTitle = titles[index - 1]; Title title = new Title(); title.EmpNo = employee.EmpNo; title.Title1 = sTitle; title.FromDate = DateTime.Now.AddDays(-daysGenerator.Next(1, 3650)); title.ToDate = title.FromDate.Value.AddDays(daysGenerator.Next(1, 3650)); await _titleService.AddTitle(title); } catch (Exception ex) { } } return(View()); }
async public Task DeleteDeptEmp(DeptEmp deptEmp) { _unitOfWork.RepositoryFor <DeptEmp>().Delete(deptEmp); await _unitOfWork.RepositoryFor <DeptEmp>().SaveAsync(); }
async public Task AddDeptEmp(DeptEmp newDeptEmp) { await _unitOfWork.RepositoryFor <DeptEmp>().AddAsync(newDeptEmp); await _unitOfWork.RepositoryFor <DeptEmp>().SaveAsync(); }
/// <summary> /// 增量同步组织结构 /// </summary> /// <returns></returns> public string AnsyIncrementOrgToGPM() { string access_token = getAccessToken(); string url = "https://oapi.dingtalk.com/department/list?access_token=" + access_token; try { StringBuilder append = new StringBuilder(); string str = new HttpWebResponseUtility().HttpResponseGet(url); DepartMent_List departMentList = FormatToJson.ParseFromJson <DepartMent_List>(str); if (departMentList == null || departMentList.department == null || departMentList.department.Count == 0) { return("钉钉获取部门出错。"); } #region 获取钉钉组织结构,进行更新与新增 //增加跟部门 int deptIdx = 0; bool doSomeThing = false; //部门信息 foreach (DepartMentDetailInfo deptMentInfo in departMentList.department) { deptIdx++; doSomeThing = false; //增加部门,排除根目录 if (deptMentInfo.id != "1") { Dept dept = new Dept(); if (dept.IsExit(DeptAttr.No, deptMentInfo.id) == true) { if (dept.No == deptMentInfo.id && !dept.Name.Equals(deptMentInfo.name)) { doSomeThing = true; append.Append("\r\n部门名称发生变化:" + dept.Name + " --> " + deptMentInfo.name); } if (!dept.ParentNo.Equals(deptMentInfo.parentid)) { doSomeThing = true; append.Append("\r\n部门父级发生变化:" + dept.ParentNo + " --> " + deptMentInfo.parentid); } //有变化,更新 if (doSomeThing == true) { dept.No = deptMentInfo.id; dept.Name = deptMentInfo.name; dept.ParentNo = deptMentInfo.parentid; dept.DirectUpdate(); } } else { //不存在则新增 dept.No = deptMentInfo.id; dept.Name = deptMentInfo.name; dept.ParentNo = deptMentInfo.parentid; dept.DirectInsert(); append.Append("\r\n新增部门:" + deptMentInfo.id + " - " + deptMentInfo.name); } } //部门人员 DepartMentUser_List userList = GenerDeptUser_List(access_token, deptMentInfo.id); if (userList != null) { foreach (DepartMentUserInfo userInfo in userList.userlist) { Emp emp = new Emp(); emp.No = userInfo.userid; DeptEmp deptEmp = new DeptEmp(); //如果账户存在则人员信息不添加,添加关联表 if (emp.RetrieveFromDBSources() > 0) { if (!emp.Name.Equals(userInfo.name)) { emp.Name = userInfo.name; emp.DirectUpdate(); append.Append("\r\n人员名称发生变化:" + emp.Name + " --> " + userInfo.name); } deptEmp.MyPK = deptMentInfo.id + "_" + emp.No; if (deptEmp.RetrieveFromDBSources() > 0) { continue; } //增加人员归属部门 deptEmp.FK_Dept = deptMentInfo.id; deptEmp.FK_Emp = emp.No; deptEmp.DirectInsert(); append.Append("\r\n增加人员归属部门:" + emp.Name + " - " + deptMentInfo.name); continue; } //增加人员 emp.No = userInfo.userid; emp.Name = userInfo.name; emp.FK_Dept = deptMentInfo.id; emp.Tel = userInfo.mobile; emp.Email = userInfo.email; //emp.Idx = DataType.IsNullOrEmpty(userInfo.order) == true ? 0 : Int32.Parse(userInfo.order); emp.DirectInsert(); append.Append("\r\n增加人员:" + emp.Name + " 所属部门:" + deptMentInfo.name); //增加人员与部门对应表 deptEmp.MyPK = deptMentInfo.id + "_" + emp.No; deptEmp.FK_Dept = deptMentInfo.id; deptEmp.FK_Emp = emp.No; deptEmp.DirectInsert(); } } } #endregion #region GPM组织结构,在钉钉不存在进行删除部门与人员关系表,人员表不进行删除,删除业务人员表WF_Emp Depts gpm_Depts = new Depts(); gpm_Depts.RetrieveAllFromDBSource(); foreach (Dept gpm_Dept in gpm_Depts) { bool isHave = false; foreach (DepartMentDetailInfo ding_Dept in departMentList.department) { if (gpm_Dept.No.Equals(ding_Dept.id)) { isHave = true; break; } } //部门在钉钉不存在则进行删除:部门表、部门人员、部门人员岗位、部门职位、部门岗位 if (isHave == false) { //部门岗位 DeptStation deptStation = new DeptStation(); int iDeptStation = deptStation.Delete(DeptStationAttr.FK_Dept, gpm_Dept.No); //部门人员岗位 DeptEmpStation deptEmpStation = new DeptEmpStation(); int iDeptEmpStation = deptEmpStation.Delete(DeptEmpStationAttr.FK_Dept, gpm_Dept.No); //部门人员 DeptEmp deptEmp = new DeptEmp(); int iDeptEmp = deptEmp.Delete(DeptEmpAttr.FK_Dept, gpm_Dept.No); //部门表 Dept dt = new Dept(gpm_Dept.No); dt.Delete(); append.Append("\r\n删除部门:" + gpm_Dept.Name + " 部门全路径:" + gpm_Dept.NameOfPath); append.Append("\r\n 部门岗位 " + iDeptStation + " 条记录"); append.Append("\r\n 部门人员岗位 " + iDeptEmpStation + " 条记录"); append.Append("\r\n 部门人员 " + iDeptEmp + " 条记录"); } else { //组织结构人员 DeptEmps deptEmps = new DeptEmps(); QueryObject obj = new QueryObject(deptEmps); obj.AddWhere(DeptEmpAttr.FK_Dept, gpm_Dept.No); obj.addAnd(); obj.AddWhereNotIn(DeptEmpAttr.FK_Emp, "'admin'"); obj.DoQuery(); //部门下没有人员不需要处理 if (deptEmps == null || deptEmps.Count == 0) { continue; } //钉钉部门人员 DepartMentUser_List userList = GenerDeptUser_List(access_token, gpm_Dept.No); //部门下没有人员,清除部门下的所有人员 if (userList == null || userList.userlist.Count == 0) { append.Append("\r\n删除部门下的人员,部门:" + gpm_Dept.Name + " 部门全路径:" + gpm_Dept.NameOfPath); foreach (DeptEmp dt in deptEmps) { dt.Delete(); Emp ep = new Emp(); ep.No = dt.FK_Emp; ep.RetrieveFromDBSources(); append.Append("\r\n 人员编号:" + dt.FK_Emp + " 姓名:" + ep.Name); } continue; } //判断部门下的人员是否存在 foreach (DeptEmp deptEmp in deptEmps) { isHave = false; foreach (DepartMentUserInfo userInfo in userList.userlist) { if (deptEmp.FK_Emp.Equals(userInfo.userid)) { isHave = true; break; } } //不存在,删除 if (isHave == false) { deptEmp.Delete(); Emp ep = new Emp(); ep.No = deptEmp.FK_Emp; ep.RetrieveFromDBSources(); append.Append("\r\n删除部门下的人员,部门:" + gpm_Dept.Name + " 部门全路径:" + gpm_Dept.NameOfPath); append.Append("\r\n 人员编号:" + deptEmp.FK_Emp + " 姓名:" + ep.Name); } } } } //删除没包含在部门的人员 #endregion #region 处理部门名称全程 //OrgInit_NameOfPath nameOfPath = new OrgInit_NameOfPath(); //if (nameOfPath.IsCanDo) // nameOfPath.Do(); #endregion return(append.ToString()); } catch (Exception ex) { BP.DA.Log.DefaultLogWriteLineError(ex.Message); } return(null); }
/// <summary> /// 同步钉钉通讯录到CCGPM /// </summary> /// <returns></returns> public bool AnsyOrgToCCGPM() { string access_token = getAccessToken(); string url = "https://oapi.dingtalk.com/department/list?access_token=" + access_token; try { string str = new HttpWebResponseUtility().HttpResponseGet(url); DepartMent_List departMentList = FormatToJson.ParseFromJson <DepartMent_List>(str); //部门集合 if (departMentList != null && departMentList.department != null && departMentList.department.Count > 0) { //删除旧数据 ClearOrg_Old(); //获取根部门 DepartMentDetailInfo rootDepartMent = new DepartMentDetailInfo(); foreach (DepartMentDetailInfo deptMenInfo in departMentList.department) { if (deptMenInfo.id == "1") { rootDepartMent = deptMenInfo; break; } } //增加跟部门 int deptIdx = 0; Dept rootDept = new Dept(); rootDept.No = rootDepartMent.id; rootDept.Name = rootDepartMent.name; rootDept.ParentNo = "0"; rootDept.DirectInsert(); //部门信息 foreach (DepartMentDetailInfo deptMentInfo in departMentList.department) { //增加部门,排除根目录 if (deptMentInfo.id != "1") { Dept dept = new Dept(); dept.No = deptMentInfo.id; dept.Name = deptMentInfo.name; dept.ParentNo = deptMentInfo.parentid; dept.DirectInsert(); } //部门人员 DepartMentUser_List userList = GenerDeptUser_List(access_token, deptMentInfo.id); if (userList != null) { foreach (DepartMentUserInfo userInfo in userList.userlist) { Emp emp = new Emp(); DeptEmp deptEmp = new DeptEmp(); //如果账户存在则人员信息不添加,添加关联表 if (emp.IsExit(EmpAttr.No, userInfo.userid) == true) { deptEmp.MyPK = deptMentInfo.id + "_" + emp.No; deptEmp.FK_Dept = deptMentInfo.id; deptEmp.FK_Emp = emp.No; deptEmp.DirectInsert(); continue; } //增加人员 emp.No = userInfo.userid; emp.Name = userInfo.name; emp.FK_Dept = deptMentInfo.id; emp.Tel = userInfo.mobile; emp.Email = userInfo.email; //emp.Idx = DataType.IsNullOrEmpty(userInfo.order) == true ? 0 : Int32.Parse(userInfo.order); emp.DirectInsert(); //增加人员与部门对应表 deptEmp.MyPK = deptMentInfo.id + "_" + emp.No; deptEmp.FK_Dept = deptMentInfo.id; deptEmp.FK_Emp = emp.No; deptEmp.DirectInsert(); } } } #region 处理部门名称全程 //OrgInit_NameOfPath nameOfPath = new OrgInit_NameOfPath(); //if (nameOfPath.IsCanDo) // nameOfPath.Do(); #endregion return(true); } } catch (Exception ex) { BP.DA.Log.DefaultLogWriteLineError(ex.Message); } return(false); }