123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Data.Entity;
- using Bowin.Common.Utility;
- using Bowin.Common.Linq;
- using Bowin.Common.Linq.Entity;
- using EMIS.DataLogic.Repositories;
- using System.Linq.Expressions;
- using EMIS.Entities;
- using EMIS.DataLogic.SystemDAL;
- using EMIS.ViewModel.SystemView;
- using EMIS.Utility;
- using EMIS.DataLogic.Common.AdministrativeOrgan;
- using EMIS.DataLogic.Common.TeacherManagement;
- using EMIS.ViewModel;
- using EMIS.Utility.SSO;
- using EMIS.CommonLogic.Students;
- using EMIS.ViewModel.Students;
- using EMIS.DataLogic.Common.Students;
- using EMIS.DataLogic.Common.Specialtyclass;
- using System.Text.RegularExpressions;
- namespace EMIS.CommonLogic.SystemServices
- {
- public class UserServices : BaseServices, IUserServices
- {
- public UserDAL UserDAL { get; set; }
- public ClassmajorDAL ClassmajorDAL { get; set; }
- public StaffDAL StaffDAL { get; set; }
- public RoleDAL RoleDAL { get; set; }
- public CampusDAL CampusDAL { get; set; }
- public CollegeDAL CollegeDAL { get; set; }
- public StudentsDAL StudentsDAL { get; set; }
- public EMIS.DataLogic.Repositories.HRService.UsersRepository CommUserRepository { get; set; }
- public Lazy<IControlItemServices> ControlItemServices { get; set; }
- public bool Login(string loginID, string password)
- {
- var encryptPassword = password.ToUpper();
- //Bowin.Common.Utility.StringEx.MD5(password);
- //岭南不用姓名登陆
- //var userName = UserDAL.UserRepository.GetList(u => u.RecordStatus == (int)SYS_STATUS.USABLE && u.Name == loginID).ToList();
- //if(userName.Count>1)
- //{
- // throw new Exception("由于您的名字在系统中存在重名情况,请使用工号进行登录。");
- //}
- var user = UserDAL.UserRepository.GetList(u => u.RecordStatus == (int)SYS_STATUS.USABLE && (u.LoginID == loginID) && u.Password == encryptPassword)
- .Include(x => x.CF_Student).FirstOrDefault();
- if (user == null) return false;
- if (user.CF_Student != null)
- {
- ControlItemServices.Value.CheckLoginControlItems(user.UserID);
- }
- return true;
- }
- public Entities.Sys_User GetUserByLoginID(string loginID, bool isNeedEnable = true)
- {
- Expression<Func<Sys_User, bool>> user = (p => p.LoginID == loginID.Trim()||p.Name==loginID);
- if (isNeedEnable)
- {
- //user = user.And(p => p.RecordStatus == 1); 加了个方法代替,因为日后很可能会重用
- return UserDAL.GetSingleEnableUser(user);
- }
- else
- {
- return UserDAL.UserRepository.GetSingle(user,
- (x => x.CF_Staff.CF_College.CF_Campus.CF_University),
- (x => x.CF_Student.CF_Classmajor.CF_Grademajor.CF_Facultymajor.CF_College.CF_Campus.CF_University));
- }
- }
- public List<Sys_User> GetUserListByLoginID(IList<string> loginIDList, bool isNeedEnable = true)
- {
- Expression<Func<Sys_User, bool>> userExp = (x => loginIDList.Contains(x.LoginID));
- if (isNeedEnable)
- {
- userExp = userExp.And(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
- }
- return UserDAL.UserRepository.GetList(userExp).ToList();
- }
- public Sys_User GetUserByUserID(Guid? userID, bool isNeedEnable = true)
- {
- Expression<Func<Sys_User, bool>> user = (p => p.UserID == userID);
- if (isNeedEnable)
- {
- //user = user.And(p => p.RecordStatus == 1); 加了个方法代替,因为日后很可能会重用
- return UserDAL.GetSingleEnableUser(user);
- }
- else
- {
- return UserDAL.UserRepository.GetSingle(user,
- (x => x.CF_Staff.CF_College.CF_Campus.CF_University),
- (x => x.CF_Student.CF_Classmajor.CF_Grademajor.CF_Facultymajor.CF_College.CF_Campus.CF_University));
- }
- }
- public UserView GetUserViewByID(Guid userID)
- {
- Expression<Func<Sys_User, bool>> userExp = p => p.UserID == userID;
- return UserDAL.GetUserView(userExp, (x => true)).FirstOrDefault();
- }
- /// <summary>
- /// 教师用户列表(用于列表控键,分页)
- /// </summary>
- /// <param name="configuretView"></param>
- /// <param name="campusID"></param>
- /// <param name="collegeID"></param>
- /// <param name="departmentID"></param>
- /// <param name="roleID"></param>
- /// <param name="dataRangeID"></param>
- /// <param name="stauts"></param>
- /// <param name="pageIndex"></param>
- /// <param name="pageSize"></param>
- /// <returns></returns>
- public Bowin.Common.Linq.Entity.IGridResultSet<UserView> GetUserViewList(ViewModel.ConfiguretView configuretView,
- Guid? campusID, Guid? collegeID, Guid? departmentID, Guid? roleID, int? dataRangeID, int? stauts, int pageIndex, int pageSize)
- {
- Expression<Func<Sys_User, bool>> exp = (x => true);
- Expression<Func<Sys_Role, bool>> roleExp = (x => true);
- if (campusID.HasValue)
- {
- exp = exp.And(x => x.CF_Staff.CF_College.CampusID == campusID.Value);
- }
- if (collegeID.HasValue)
- {
- exp = exp.And(x => x.CF_Staff.CollegeID == collegeID.Value);
- }
- if (departmentID.HasValue)
- {
- exp = exp.And(x => x.CF_Staff.DepartmentID == departmentID.Value);
- }
- //if (roleID.HasValue)
- //{
- // exp = exp.And(x => x.Sys_Role.Any(w => w.RoleID == roleID));
- // //roleExp = roleExp.And(x => x.RoleID == roleID.Value);
- //}
- //if (dataRangeID.HasValue)
- //{
- // exp = exp.And(x => x.Sys_Role.Any(w => w.DefaultDataRange == dataRangeID.Value));
- // //roleExp = roleExp.And(x => x.DefaultDataRange == dataRangeID.Value);
- //}
- if (stauts.HasValue)
- {
- exp = exp.And(x => x.RecordStatus == stauts);
- }
- IQueryable<UserView> q = UserDAL.GetUserView(exp, roleExp);
- //
- if (roleID.HasValue)
- {
- q = q.Where(x => x.RoleID == roleID);
- }
- if (dataRangeID.HasValue)
- {
- q = q.Where(x => x.DataRange == dataRangeID);
- }
- if (!string.IsNullOrEmpty(configuretView.ConditionValue) && !string.IsNullOrEmpty(configuretView.Attribute))
- q = q.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue);
- q = this.GetQueryByDataRangeByDepartment(q);
- return q.OrderBy(x => x.CollegeCode).ThenBy(x => x.LoginID).ToGridResultSet(pageIndex, pageSize);
- }
- /// <summary>
- /// 教师用户列表(用于列表控键,不分页)
- /// </summary>
- /// <param name="configuretView"></param>
- /// <param name="campusID"></param>
- /// <param name="collegeID"></param>
- /// <param name="departmentID"></param>
- /// <param name="roleID"></param>
- /// <param name="dataRangeID"></param>
- /// <returns></returns>
- public IList<ViewModel.SystemView.UserView> GetUserViewList(ViewModel.ConfiguretView configuretView,
- Guid? campusID, Guid? collegeID, Guid? departmentID, Guid? roleID, int? dataRangeID)
- {
- Expression<Func<Sys_User, bool>> exp = (x => true);
- Expression<Func<Sys_Role, bool>> roleExp = (x => true);
- if (campusID.HasValue)
- {
- exp = exp.And(x => x.CF_Staff.CF_Department.CF_College.CampusID == campusID.Value);
- }
- if (collegeID.HasValue)
- {
- exp = exp.And(x => x.CF_Staff.CF_Department.CollegeID == collegeID.Value);
- }
- if (departmentID.HasValue)
- {
- exp = exp.And(x => x.CF_Staff.DepartmentID == departmentID.Value);
- }
- if (roleID.HasValue)
- {
- roleExp = roleExp.And(x => x.RoleID == roleID.Value);
- }
- if (dataRangeID.HasValue)
- {
- roleExp = roleExp.And(x => x.DefaultDataRange == dataRangeID.Value);
- }
- IQueryable<UserView> q = UserDAL.GetUserView(exp, roleExp);
- if (!string.IsNullOrEmpty(configuretView.ConditionValue) && !string.IsNullOrEmpty(configuretView.Attribute))
- q = q.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue);
- return q.OrderBy(x => x.CollegeCode).ThenBy(x => x.LoginID).ToList();
- }
- /// <summary>
- /// 学生用户列表(用于列表控键,分页)
- /// </summary>
- /// <param name="configuretView"></param>
- /// <param name="campusID"></param>
- /// <param name="collegeID"></param>
- /// <param name="educationID"></param>
- /// <param name="schoolYearID"></param>
- /// <param name="standardID"></param>
- /// <param name="learnFormID"></param>
- /// <param name="classMajorID"></param>
- /// <param name="pageIndex"></param>
- /// <param name="pageSize"></param>
- /// <returns></returns>
- public Bowin.Common.Linq.Entity.IGridResultSet<StudentUserView> GetStudentUserViewList(ViewModel.ConfiguretView configuretView,
- Guid? campusID, Guid? collegeID, int? educationID, int? schoolYearID, int? standardID, int? learnFormID,
- Guid? classMajorID,string LearnSystem, int pageIndex, int pageSize)
- {
- Expression<Func<Sys_User, bool>> exp = (x => true);
- Expression<Func<Sys_Role, bool>> roleExp = (x => true);
- if (campusID.HasValue)
- {
- exp = exp.And(x => x.CF_Student.CF_Classmajor.CF_Grademajor.CF_Facultymajor.CF_College.CampusID == campusID.Value);
- }
- if (collegeID.HasValue)
- {
- exp = exp.And(x => x.CF_Student.CF_Classmajor.CF_Grademajor.CF_Facultymajor.CollegeID == collegeID.Value);
- }
- if (educationID.HasValue)
- {
- exp = exp.And(x => x.CF_Student.CF_Classmajor.CF_Grademajor.CF_Facultymajor.EducationID == educationID.Value);
- }
- if (schoolYearID.HasValue)
- {
- exp = exp.And(x => x.CF_Student.CF_Classmajor.CF_Grademajor.SchoolyearID == schoolYearID.Value);
- }
- if (standardID.HasValue)
- {
- exp = exp.And(x => x.CF_Student.CF_Classmajor.CF_Grademajor.CF_Facultymajor.StandardID == standardID.Value);
- }
- if (learnFormID.HasValue)
- {
- exp = exp.And(x => x.CF_Student.CF_Classmajor.CF_Grademajor.CF_Facultymajor.LearningformID == learnFormID.Value);
- }
- if (classMajorID.HasValue)
- {
- exp = exp.And(x => x.CF_Student.ClassmajorID == classMajorID);
- }
- if (!string.IsNullOrEmpty(LearnSystem) && LearnSystem != "-1")
- {
- var LearnSystems = Convert.ToDecimal(LearnSystem);
- exp = exp.And(x => x.CF_Student.CF_Classmajor.CF_Grademajor.CF_Facultymajor.LearnSystem == LearnSystems);
- }
- IQueryable<StudentUserView> q = UserDAL.GetStudentUserView(exp, roleExp);
- if (!string.IsNullOrEmpty(configuretView.ConditionValue) && !string.IsNullOrEmpty(configuretView.Attribute))
- q = q.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue);
- return this.GetQueryByDataRangeByCollege(q).OrderBy(x => x.Grade).ThenBy(x => x.ClassNo).ThenBy(x => x.LoginID).ToGridResultSet(pageIndex, pageSize);
- }
- /// <summary>
- /// 学生用户列表(用于列表控键,不分页)
- /// </summary>
- /// <param name="configuretView"></param>
- /// <param name="campusID"></param>
- /// <param name="collegeID"></param>
- /// <param name="educationID"></param>
- /// <param name="schoolYearID"></param>
- /// <param name="standardID"></param>
- /// <param name="learnFormID"></param>
- /// <param name="classMajorID"></param>
- /// <returns></returns>
- public IList<ViewModel.SystemView.StudentUserView> GetStudentUserViewList(ViewModel.ConfiguretView configuretView,
- Guid? campusID, Guid? collegeID, int? educationID, int? schoolYearID, int? standardID, int? learnFormID,
- Guid? classMajorID, string LearnSystem)
- {
- Expression<Func<Sys_User, bool>> exp = (x => true);
- Expression<Func<Sys_Role, bool>> roleExp = (x => true);
- if (campusID.HasValue)
- {
- exp = exp.And(x => x.CF_Student.CF_Classmajor.CF_Grademajor.CF_Facultymajor.CF_College.CampusID == campusID.Value);
- }
- if (collegeID.HasValue)
- {
- exp = exp.And(x => x.CF_Student.CF_Classmajor.CF_Grademajor.CF_Facultymajor.CollegeID == collegeID.Value);
- }
- if (educationID.HasValue)
- {
- exp = exp.And(x => x.CF_Student.CF_Classmajor.CF_Grademajor.CF_Facultymajor.EducationID == educationID.Value);
- }
- if (schoolYearID.HasValue)
- {
- exp = exp.And(x => x.CF_Student.CF_Classmajor.CF_Grademajor.SchoolyearID == schoolYearID.Value);
- }
- if (standardID.HasValue)
- {
- exp = exp.And(x => x.CF_Student.CF_Classmajor.CF_Grademajor.CF_Facultymajor.StandardID == standardID.Value);
- }
- if (learnFormID.HasValue)
- {
- exp = exp.And(x => x.CF_Student.CF_Classmajor.CF_Grademajor.CF_Facultymajor.LearningformID == learnFormID.Value);
- }
- if (!string.IsNullOrEmpty(LearnSystem) && LearnSystem != "-1")
- {
- var LearnSystems = Convert.ToDecimal(LearnSystem);
- exp = exp.And(x => x.CF_Student.CF_Classmajor.CF_Grademajor.CF_Facultymajor.LearnSystem == LearnSystems);
- }
- IQueryable<StudentUserView> q = UserDAL.GetStudentUserView(exp, roleExp);
- if (!string.IsNullOrEmpty(configuretView.ConditionValue) && !string.IsNullOrEmpty(configuretView.Attribute))
- q = q.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue);
- return q.OrderBy(x => x.Grade).ThenBy(x => x.ClassNo).ThenBy(x => x.LoginID).ToList();
- }
- /// <summary>
- /// 批量初始化密码
- /// </summary>
- /// <param name="userID">主键ID</param>
- /// <returns></returns>
- public void BatchInitPassword(IList<Guid?> userID, bool isChange,string pwd)
- {
- if (userID.Count > 0)
- {
- if (isChange == false)
- {
- List<Sys_User> list = UserDAL.UserRepository.Entities.Where(x => userID.Contains(x.UserID)).ToList();
- List<CF_Student> studentList = StudentsDAL.StudentRepository.Entities.Where(x => userID.Contains(x.UserID)).ToList();
- List<CF_Staff> staffList = StaffDAL.staffRepository.Entities.Where(x => userID.Contains(x.UserID)).ToList();
- List<Sys_User> userList = new List<Sys_User>();
- if (studentList.Count > 0)
- {
- foreach (var user in list)
- {
- var student = studentList.Where(x => x.UserID == user.UserID).FirstOrDefault();
- var passwordstr = "A" + student.IDNumber.Substring(student.IDNumber.Length - 6);
- user.Password = passwordstr.MD5();
- SetModifyStatus(user);
- userList.Add(user);
- }
- }
- if (staffList.Count > 0)
- {
- foreach (var user in list)
- {
- var staff = staffList.Where(x => x.UserID == user.UserID).FirstOrDefault();
- var passwordstr = "A" + staff.CertificatesNum.Substring(staff.CertificatesNum.Length - 6, staff.CertificatesNum.Length);
- user.Password = ("888888").MD5();
- SetModifyStatus(user);
- userList.Add(user);
- }
- }
- UnitOfWork.BatchUpdate(userList);
- UnitOfWork.Commit();
- }
- else
- {
- List<Sys_User> list = UserDAL.UserRepository.Entities.Where(x => userID.Contains(x.UserID)).ToList();
- List<Sys_User> userList = new List<Sys_User>();
- foreach (var user in list)
- {
- user.Password = pwd.MD5();
- SetModifyStatus(user);
- userList.Add(user);
- }
- UnitOfWork.BatchUpdate(userList);
- UnitOfWork.Commit();
- }
- }
- }
- /// <summary>
- /// 启用
- /// </summary>
- /// <param name="userID">主键ID</param>
- /// <returns></returns>
- public void Usable(IList<Guid?> userID)
- {
- if (userID.Count > 0)
- {
- UnitOfWork.Update<Sys_User>(
- x => new Sys_User { RecordStatus = (int)SYS_STATUS.USABLE },
- x => userID.Contains(x.UserID)
- );
- List<Sys_User> list = UserDAL.UserRepository.Entities.Where(x => userID.Contains(x.UserID)).ToList();
- foreach (var user in list)
- {
- SetModifyStatus(user);
- UnitOfWork.Update(user);
- UnitOfWork.Commit();
- }
- }
- }
- /// <summary>
- /// 禁用
- /// </summary>
- /// <param name="userID">主键ID</param>
- /// <returns></returns>
- public void UnUsable(IList<Guid?> userID)
- {
- if (userID.Count > 0)
- {
- UnitOfWork.Update<Sys_User>(
- x => new Sys_User { RecordStatus = (int)SYS_STATUS.UNUSABLE },
- x => userID.Contains(x.UserID)
- );
- List<Sys_User> list = UserDAL.UserRepository.Entities.Where(x => userID.Contains(x.UserID)).ToList();
- foreach (var user in list)
- {
- SetModifyStatus(user);
- UnitOfWork.Update(user);
- UnitOfWork.Commit();
- }
- }
- }
- /// <summary>
- /// 保存用户角色
- /// </summary>
- /// <param name="userID"></param>
- /// <param name="roleID"></param>
- public void SaveUserRoles(Guid userID, IList<Guid?> roleID)
- {
- var user = this.UserDAL.UserRepository.GetSingle(x => x.UserID == userID, (x => x.Sys_Role));
- var roleList = this.RoleDAL.RoleRepository.GetList(x => roleID.Contains(x.RoleID)).ToList();
- user.Sys_Role = new HashSet<Sys_Role>();
- roleList.ForEach(x => user.Sys_Role.Add(x));
- this.UnitOfWork.Commit();
- }
- public IList<CF_Campus> GetUserInchargeCampus(Guid userID)
- {
- var campusList = this.StaffDAL.GetUserInChargeCampus(x => x.UserID == userID).ToList();
- return campusList;
- }
- public IList<CF_College> GetUserInchargeCollege(Guid userID)
- {
- var collegeList = this.StaffDAL.GetUserInChargeCollege(x => x.UserID == userID).ToList();
- return collegeList;
- }
- public IList<CF_Department> GetUserInchargeDepartment(Guid userID)
- {
- var departmentList = this.StaffDAL.GetUserInChargeDepartment(x => x.UserID == userID).ToList();
- return departmentList;
- }
- public IList<Sys_Role> GetUserRoles(Guid userID)
- {
- var user = this.UserDAL.UserRepository.GetSingle(x => x.UserID == userID, (x => x.Sys_Role));
- var roleList = user.Sys_Role.ToList();
- return roleList;
- }
- public Sys_Role GetMaxPrivilegeRoleByUserID(Guid userID)
- {
- var role = RoleDAL.RoleRepository.GetList(x => x.Sys_User.Any(w => w.UserID == userID))
- .OrderByDescending(x => x.Sys_FunctionCode.Count())
- .FirstOrDefault();
- return role;
- }
- /// <summary>
- /// 保存用户所属校区
- /// </summary>
- /// <param name="userID"></param>
- /// <param name="roleID"></param>
- public void SaveUserCampus(Guid userID, IList<Guid?> campusID)
- {
- var user = this.UserDAL.UserRepository.GetSingle(x => x.UserID == userID, (x => x.CF_Staff.CF_StaffManageCampus));
- if (user.CF_Staff == null) throw new Exception("该用户并非教职工用户,请补全该用户的教职工信息再进行操作,或选择其他用户进行操作。");
- //var campusList = this.CampusDAL.campusRepository.GetList(x => campusID.Contains(x.CampusID)).ToList();
- user.CF_Staff.CF_StaffManageCampus.ToList().ForEach(x => this.UnitOfWork.Remove(x));
- campusID.ForEach(x => {
- CF_StaffManageCampus staffManageCampus = new CF_StaffManageCampus();
- staffManageCampus.StaffManageCampusID = Guid.NewGuid();
- staffManageCampus.UserID = userID;
- staffManageCampus.CampusID = x;
- this.SetNewStatus(staffManageCampus);
- this.UnitOfWork.Add(staffManageCampus);
- });
- this.UnitOfWork.Commit();
- }
- /// <summary>
- /// 保存用户所属学院
- /// </summary>
- /// <param name="userID"></param>
- /// <param name="roleID"></param>
- public void SaveUserCollege(Guid userID, IList<Guid?> collegeID)
- {
- var user = this.UserDAL.UserRepository.GetSingle(x => x.UserID == userID, (x => x.CF_Staff.CF_StaffManageCollege));
- if (user.CF_Staff == null) throw new Exception("该用户并非教职工用户,请补全该用户的教职工信息再进行操作,或选择其他用户进行操作。");
- user.CF_Staff.CF_StaffManageCollege.ToList().ForEach(x => this.UnitOfWork.Remove(x));
- collegeID.ForEach(x =>
- {
- CF_StaffManageCollege staffManageCollege = new CF_StaffManageCollege();
- staffManageCollege.StaffManageCollegeID = Guid.NewGuid();
- staffManageCollege.UserID = userID;
- staffManageCollege.CollegeID = x;
- this.SetNewStatus(staffManageCollege);
- this.UnitOfWork.Add(staffManageCollege);
- });
- this.UnitOfWork.Commit();
- }
- /// <summary>
- /// 保存用户所属教研室
- /// </summary>
- /// <param name="userID"></param>
- /// <param name="departmentID"></param>
- public void SaveUserDepartment(Guid userID, IList<Guid?> departmentID)
- {
- var user = this.UserDAL.UserRepository.GetSingle(x => x.UserID == userID, (x => x.CF_Staff.CF_StaffManageDepartment));
- if (user.CF_Staff == null) throw new Exception("该用户并非教职工用户,请补全该用户的教职工信息再进行操作,或选择其他用户进行操作。");
- user.CF_Staff.CF_StaffManageDepartment.ToList().ForEach(x => this.UnitOfWork.Remove(x));
- departmentID.ForEach(x =>
- {
- CF_StaffManageDepartment staffManageDepartment = new CF_StaffManageDepartment();
- staffManageDepartment.StaffManageDepartmentID = Guid.NewGuid();
- staffManageDepartment.UserID = userID;
- staffManageDepartment.DepartmentID = x;
- this.SetNewStatus(staffManageDepartment);
- this.UnitOfWork.Add(staffManageDepartment);
- });
- this.UnitOfWork.Commit();
- }
- public IList<RoleView> GetUserRolesView(Guid userID)
- {
- return RoleDAL.GetRoleView(x => x.Sys_User.Any(w => w.UserID == userID)).OrderBy(x => x.TypeID).ThenBy(x => x.OrderNo).ToList();
- }
- public string GetUserEmail(Guid userID)
- {
- var user = UserDAL.UserRepository.GetSingle(x => x.UserID == userID, (x => x.CF_Staff.CF_StaffProfile), (x => x.CF_Student.CF_StudentContact));
- if (user == null) throw new Exception("指定的用户信息不存在。");
- if (user.CF_Student != null && user.CF_Student.CF_StudentContact != null)
- {
- return user.CF_Student.CF_StudentContact.Email;
- }
- else if (user.CF_Staff != null && user.CF_Staff.CF_StaffProfile != null)
- {
- return user.CF_Staff.CF_StaffProfile.Email;
- }
- else
- {
- throw new Exception("用户并没有注册电子邮箱信息。");
- }
- }
- public void ChangePassword(ChangePasswordView password, Guid userID)
- {
- var user = this.UserDAL.UserRepository.GetSingle(x => x.UserID == userID, (x => x.Sys_MailVerifyCode));
- user.Password = password.Password.MD5();
- user.Sys_MailVerifyCode = null;
- UnitOfWork.Commit();
- }
- public Sys_User GetUserByID(Guid userID)
- {
- return this.UserDAL.UserRepository.Entities.Where(x => x.UserID == userID).FirstOrDefault();
- }
- public void SynHRServices()
- {
- var exceptUser = new string[] { "admin" };
- var hrUsers = CommUserRepository.GetList(x => !exceptUser.Contains(x.userid)).ToList();
- var staffs = StaffDAL.staffRepository.GetList(x => !exceptUser.Contains(x.Sys_User.LoginID))
- .Include(x => x.Sys_User).Include(x => x.CF_StaffProfile).ToList();
- hrUsers.ForEach(x => x.status = "D");
- foreach (var staff in staffs)
- {
- var hrUser = hrUsers.FirstOrDefault(x => x.userid == staff.Sys_User.LoginID);
- if (hrUser == null)
- {
- hrUser = new Entities.HRServices.Comm_Users();
- hrUser.userid = staff.Sys_User.LoginID;
- hrUser.loginid = staff.Sys_User.LoginID;
- hrUser.createdt = DateTime.Now;
- this.HRUnitOfWork.Add(hrUser);
- }
- hrUser.username = staff.Sys_User.Name;
- if (staff.DepartmentID.HasValue)
- {
- hrUser.dpid = staff.DepartmentID.ToString();
- }
- else
- {
- hrUser.dpid = staff.CollegeID.ToString();
- }
- hrUser.telephone = staff.CF_StaffProfile.Telephone;
- hrUser.mobile = staff.CF_StaffProfile.Mobile;
- hrUser.email = staff.CF_StaffProfile.Email;
- hrUser.cardid = staff.Sys_User.LoginID;
- hrUser.employeeclassid = "";
- hrUser.jobtypeid = "教师";
- hrUser.birthday = staff.BirthDate;
- switch (staff.Sex)
- {
- case (int)CF_Sex.Male:
- hrUser.sex = "1";
- break;
- case (int)CF_Sex.Female:
- hrUser.sex = "2";
- break;
- default:
- hrUser.sex = "0";
- break;
- }
- hrUser.orderNo = "1";
- hrUser.userrole = "";
- hrUser.userligion = "";
- hrUser.password = staff.Sys_User.Password;
- hrUser.status = "A";
- hrUser.updatedt = DateTime.Now;
- hrUser.istmpuser = false;
- }
- this.HRUnitOfWork.Commit();
- }
- public virtual string SSOLogin()
- {
- return SSO.SSOLogin();
- }
- public Guid? StudentRegist(RegistView registView)
- {
- string reg = @"(^\d{15}$)|(^\d{18}$)|(^\d{17}\d|X|x)$";
- if (registView.CertificatesType == (int)CF_CertificatesType.IdCrad && !Regex.IsMatch(registView.LoginID, reg, RegexOptions.IgnoreCase))
- {
- throw new Exception("证件号码格式不正确,请检查并修改正确后重试。");
- }
- var dupUser = UserDAL.UserRepository.GetSingle(x => x.LoginID == registView.LoginID && x.UserID != registView.UserID);
- if (dupUser != null)
- {
- throw new Exception("该证件号码已经注册,请不要重复注册。");
- }
- var userID = this.SaveStudentByRegistView(registView);
- return userID;
- }
- private Guid? SaveStudentByRegistView(RegistView registView)
- {
- var classmajor = this.ClassmajorDAL.GetSocialClassmajor(x => x.SchoolAreaID == registView.SchoolAreaID).FirstOrDefault();
- CF_Student student = StudentsDAL.StudentRepository.GetSingle(x => x.UserID == registView.UserID,
- (x => x.CF_StudentAccount),
- (x => x.CF_StudentProfile),
- (x => x.CF_StudentContact),
- (x => x.CF_Recruitstudents),
- (x => x.Sys_User.Sys_Role),
- (x => x.Sys_User.Sys_Announcement),
- (x => x.Sys_User.Sys_MailVerifyCode),
- (x => x.Sys_User.EX_ExaminationRegistrationConfirm));
- CF_StudentAccount account;
- CF_StudentProfile profile;
- CF_StudentContact contact;
- CF_Recruitstudents recruits;
- Sys_User user;
- if (student != null)
- {
- account = student.CF_StudentAccount;
- profile = student.CF_StudentProfile;
- contact = student.CF_StudentContact;
- recruits = student.CF_Recruitstudents;
- user = student.Sys_User;
- }
- else
- {
- student = new CF_Student();
- account = new CF_StudentAccount();
- profile = new CF_StudentProfile();
- contact = new CF_StudentContact();
- recruits = new CF_Recruitstudents();
- user = new Sys_User();
- Sys_Role role = RoleDAL.RoleRepository.GetSingle(x => x.CF_StudentRole != null && x.CF_StudentRole.StudentType != null, (x => x.CF_StudentRole));
- student.UserID = Guid.NewGuid();
- student.ClassmajorID = classmajor.ClassmajorID;
- student.StudentCardNo = registView.LoginID;
- student.StudentType = role.CF_StudentRole.StudentType;
- student.RecordStatus = (int)SYS_STATUS.USABLE;
- student.CreateTime = DateTime.Now;
- student.CreateUserID = student.UserID;
- //提供返回值
- registView.UserID = student.UserID;
- account.UserID = student.UserID;
- account.RecordStatus = (int)SYS_STATUS.USABLE;
- account.CreateTime = DateTime.Now;
- account.CreateUserID = student.UserID;
- profile.UserID = student.UserID;
- profile.RecordStatus = (int)SYS_STATUS.USABLE;
- profile.CreateTime = DateTime.Now;
- profile.CreateUserID = student.UserID;
- contact.UserID = student.UserID;
- contact.WorkUnit = registView.WorkUnit;
- contact.RecordStatus = (int)SYS_STATUS.USABLE;
- contact.CreateTime = DateTime.Now;
- contact.CreateUserID = student.UserID;
- recruits.UserID = student.UserID;
- recruits.RecordStatus = (int)SYS_STATUS.USABLE;
- recruits.CreateTime = DateTime.Now;
- recruits.CreateUserID = student.UserID;
- user.UserID = student.UserID;
- user.LoginID = registView.LoginID;
- user.Password = registView.PCode.MD5();
- user.RecordStatus = (int)SYS_STATUS.USABLE;
- user.CreateTime = DateTime.Now;
- user.CreateUserID = student.UserID;
- user.Sys_Role.Add(role);
- UnitOfWork.Add(user);
- UnitOfWork.Add(student);
- UnitOfWork.Add(account);
- UnitOfWork.Add(profile);
- UnitOfWork.Add(contact);
- UnitOfWork.Add(recruits);
- }
- student.CertificatesType = registView.CertificatesType;
- student.IDNumber = registView.LoginID;
- if (!string.IsNullOrEmpty(registView.PhotoUrl))
- {
- student.PhotoUrl = registView.PhotoUrl;
- }
- student.Sex = registView.Sex;
- student.ModifyTime = DateTime.Now;
- student.ModifyUserID = student.UserID;
- account.ModifyTime = DateTime.Now;
- account.ModifyUserID = student.UserID;
- profile.BirthDate = registView.BirthDate;
- profile.ModifyTime = DateTime.Now;
- profile.ModifyUserID = student.UserID;
- contact.Mobile = registView.Mobile;
- contact.Email = registView.Email;
- contact.ModifyTime = DateTime.Now;
- contact.ModifyUserID = student.UserID;
- recruits.ModifyTime = DateTime.Now;
- recruits.ModifyUserID = student.UserID;
- user.Name = registView.UserName;
- user.ModifyTime = DateTime.Now;
- user.ModifyUserID = student.UserID;
- UnitOfWork.Commit();
- return student.UserID;
- }
- public bool LoginHistory(string LoginID, bool isSuccess)
- {
- var today = DateTime.Now.Day;
- int? failCount = 0;
- bool status = true;
- Sys_LoginHistory todayLoginHistorie = new Sys_LoginHistory();
- Sys_LoginHistory addloginHistories = new Sys_LoginHistory();
- //无论什么情况登陆,先删除当前登陆账号非当天的登陆历史记录
- List<Sys_LoginHistory> oldLoginHistories = UserDAL.LoginHistoryRepository.Entities.Where(x => x.LoginID == LoginID && x.LoginFailTime.Value.Day != today).ToList();
- UnitOfWork.Delete<Sys_LoginHistory>(oldLoginHistories);
- todayLoginHistorie = UserDAL.LoginHistoryRepository.Entities.Where(x => x.LoginID == LoginID && x.LoginFailTime.Value.Day == today).FirstOrDefault();
- if (todayLoginHistorie == null)
- {
- if (!isSuccess)//当天第一次登陆失败
- {
- addloginHistories.LoginHistoryID = Guid.NewGuid();
- addloginHistories.LoginID = LoginID;
- addloginHistories.LoginFailTime = DateTime.Now;
- addloginHistories.Count = failCount + 1;
- UnitOfWork.Add(addloginHistories);
- }
- status = true;
- }
- else if (todayLoginHistorie.Count < 5)
- {
- failCount = todayLoginHistorie.Count;
- UnitOfWork.Delete<Sys_LoginHistory>(x => x.LoginHistoryID == todayLoginHistorie.LoginHistoryID);
- if (!isSuccess)//当天登陆失败次数大于1,小于5,且本次登陆失败
- {
- addloginHistories.LoginHistoryID = Guid.NewGuid();
- addloginHistories.LoginID = LoginID;
- addloginHistories.LoginFailTime = DateTime.Now;
- addloginHistories.Count = failCount + 1;
- UnitOfWork.Add(addloginHistories);
- }
- status = true;
- }
- else if (todayLoginHistorie.Count >= 5)
- {
- status = false;
- }
- UnitOfWork.Commit();
- return status;
- }
- }
- }
|