UserServices.cs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Data.Entity;
  6. using Bowin.Common.Utility;
  7. using Bowin.Common.Linq;
  8. using Bowin.Common.Linq.Entity;
  9. using EMIS.DataLogic.Repositories;
  10. using System.Linq.Expressions;
  11. using EMIS.Entities;
  12. using EMIS.DataLogic.SystemDAL;
  13. using EMIS.ViewModel.SystemView;
  14. using EMIS.Utility;
  15. using EMIS.DataLogic.UniversityManage.AdministrativeOrgan;
  16. using EMIS.DataLogic.UniversityManage.TeacherManage;
  17. using EMIS.ViewModel;
  18. using EMIS.Utility.SSO;
  19. using EMIS.ViewModel.SystemManage.UserManage;
  20. namespace EMIS.CommonLogic.SystemServices
  21. {
  22. public class UserServices : BaseServices, IUserServices
  23. {
  24. public UserDAL UserDAL { get; set; }
  25. public StaffDAL StaffDAL { get; set; }
  26. public RoleDAL RoleDAL { get; set; }
  27. public CampusDAL CampusDAL { get; set; }
  28. public CollegeDAL CollegeDAL { get; set; }
  29. public Lazy<IControlItemServices> ControlItemServices { get; set; }
  30. public EMIS.DataLogic.Repositories.HRService.UsersRepository CommUserRepository { get; set; }
  31. public bool Login(string loginID, string password)
  32. {
  33. var encryptPassword = password.ToUpper();
  34. //var encryptPassword = Bowin.Common.Utility.StringEx.MD5(password);
  35. var userName = UserDAL.UserRepository.GetList(u => u.RecordStatus == (int)SYS_STATUS.USABLE && u.Name == loginID).ToList();
  36. if(userName.Count>1)
  37. {
  38. throw new Exception("由于您的名字在系统中存在重名情况,请使用工号进行登录。");
  39. }
  40. var user = UserDAL.UserRepository.GetList(u => u.RecordStatus == (int)SYS_STATUS.USABLE && (u.LoginID == loginID||u.Name==loginID) && u.Password == encryptPassword)
  41. .Include(x => x.CF_Student).FirstOrDefault();
  42. if (user == null) return false;
  43. if (user.CF_Student != null)
  44. {
  45. ControlItemServices.Value.CheckLoginControlItems(user.UserID);
  46. }
  47. return true;
  48. }
  49. public Entities.Sys_User GetUserByLoginID(string loginID, bool isNeedEnable = true)
  50. {
  51. Expression<Func<Sys_User, bool>> user = (p => p.LoginID == loginID.Trim()||p.Name==loginID);
  52. if (isNeedEnable)
  53. {
  54. //user = user.And(p => p.RecordStatus == 1); 加了个方法代替,因为日后很可能会重用
  55. return UserDAL.GetSingleEnableUser(user);
  56. }
  57. else
  58. {
  59. return UserDAL.UserRepository.GetSingle(user,
  60. (x => x.CF_Staff.CF_College.CF_Campus.CF_University),
  61. (x => x.CF_Student.CF_Classmajor.CF_Grademajor.CF_Facultymajor.CF_College.CF_Campus.CF_University));
  62. }
  63. }
  64. public List<Sys_User> GetUserListByLoginID(IList<string> loginIDList, bool isNeedEnable = true)
  65. {
  66. Expression<Func<Sys_User, bool>> userExp = (x => loginIDList.Contains(x.LoginID));
  67. if (isNeedEnable)
  68. {
  69. userExp = userExp.And(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  70. }
  71. return UserDAL.UserRepository.GetList(userExp).ToList();
  72. }
  73. public UserView GetUserViewByID(Guid userID)
  74. {
  75. Expression<Func<Sys_User, bool>> userExp = p => p.UserID == userID;
  76. return UserDAL.GetUserView(userExp, (x => true)).FirstOrDefault();
  77. }
  78. /// <summary>
  79. /// 教师用户列表
  80. /// </summary>
  81. /// <param name="configuretView"></param>
  82. /// <param name="campusID"></param>
  83. /// <param name="collegeID"></param>
  84. /// <param name="departmentID"></param>
  85. /// <param name="roleID"></param>
  86. /// <param name="dataRangeID"></param>
  87. /// <param name="stauts"></param>
  88. /// <param name="pageIndex"></param>
  89. /// <param name="pageSize"></param>
  90. /// <returns></returns>
  91. public IGridResultSet<UserView> GetUserViewList(ConfiguretView configuretView,
  92. Guid? campusID, Guid? collegeID, Guid? departmentID, Guid? roleID, int? dataRangeID, int? stauts, int pageIndex, int pageSize)
  93. {
  94. Expression<Func<Sys_User, bool>> exp = (x => true);
  95. Expression<Func<Sys_Role, bool>> roleExp = (x => true);
  96. if (campusID.HasValue)
  97. {
  98. exp = exp.And(x => x.CF_Staff.CF_College.CampusID == campusID.Value);
  99. }
  100. if (collegeID.HasValue)
  101. {
  102. exp = exp.And(x => x.CF_Staff.CollegeID == collegeID.Value);
  103. }
  104. if (departmentID.HasValue)
  105. {
  106. exp = exp.And(x => x.CF_Staff.DepartmentID == departmentID.Value);
  107. }
  108. //if (roleID.HasValue)
  109. //{
  110. // exp = exp.And(x => x.Sys_Role.Any(w => w.RoleID == roleID));
  111. // //roleExp = roleExp.And(x => x.RoleID == roleID.Value);
  112. //}
  113. //if (dataRangeID.HasValue)
  114. //{
  115. // exp = exp.And(x => x.Sys_Role.Any(w => w.DefaultDataRange == dataRangeID.Value));
  116. // //roleExp = roleExp.And(x => x.DefaultDataRange == dataRangeID.Value);
  117. //}
  118. if (stauts.HasValue)
  119. {
  120. exp = exp.And(x => x.RecordStatus == stauts);
  121. }
  122. IQueryable<UserView> q = UserDAL.GetUserView(exp, roleExp);
  123. if (roleID.HasValue)
  124. {
  125. q = q.Where(x => x.RoleID == roleID);
  126. }
  127. if (dataRangeID.HasValue)
  128. {
  129. q = q.Where(x => x.DataRange == dataRangeID);
  130. }
  131. if (!string.IsNullOrEmpty(configuretView.ConditionValue) && !string.IsNullOrEmpty(configuretView.Attribute))
  132. q = q.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue);
  133. q = this.GetQueryByDataRangeByDepartment(q);
  134. return q.OrderBy(x => x.CollegeCode).ThenBy(x => x.LoginID).ToGridResultSet(pageIndex, pageSize);
  135. }
  136. /// <summary>
  137. /// 教师用户列表
  138. /// </summary>
  139. /// <param name="configuretView"></param>
  140. /// <param name="campusID"></param>
  141. /// <param name="collegeID"></param>
  142. /// <param name="departmentID"></param>
  143. /// <param name="roleID"></param>
  144. /// <param name="dataRangeID"></param>
  145. /// <returns></returns>
  146. public IList<UserView> GetUserViewList(ConfiguretView configuretView,
  147. Guid? campusID, Guid? collegeID, Guid? departmentID, Guid? roleID, int? dataRangeID)
  148. {
  149. Expression<Func<Sys_User, bool>> exp = (x => true);
  150. Expression<Func<Sys_Role, bool>> roleExp = (x => true);
  151. if (campusID.HasValue)
  152. {
  153. exp = exp.And(x => x.CF_Staff.CF_Department.CF_College.CampusID == campusID.Value);
  154. }
  155. if (collegeID.HasValue)
  156. {
  157. exp = exp.And(x => x.CF_Staff.CF_Department.CollegeID == collegeID.Value);
  158. }
  159. if (departmentID.HasValue)
  160. {
  161. exp = exp.And(x => x.CF_Staff.DepartmentID == departmentID.Value);
  162. }
  163. if (roleID.HasValue)
  164. {
  165. roleExp = roleExp.And(x => x.RoleID == roleID.Value);
  166. }
  167. if (dataRangeID.HasValue)
  168. {
  169. roleExp = roleExp.And(x => x.DefaultDataRange == dataRangeID.Value);
  170. }
  171. IQueryable<UserView> q = UserDAL.GetUserView(exp, roleExp);
  172. if (!string.IsNullOrEmpty(configuretView.ConditionValue) && !string.IsNullOrEmpty(configuretView.Attribute))
  173. q = q.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue);
  174. return q.OrderBy(x => x.CollegeCode).ThenBy(x => x.LoginID).ToList();
  175. }
  176. /// <summary>
  177. /// 学生用户列表
  178. /// </summary>
  179. /// <param name="configuretView"></param>
  180. /// <param name="campusID"></param>
  181. /// <param name="collegeID"></param>
  182. /// <param name="educationID"></param>
  183. /// <param name="schoolYearID"></param>
  184. /// <param name="standardID"></param>
  185. /// <param name="learnFormID"></param>
  186. /// <param name="classMajorID"></param>
  187. /// <param name="pageIndex"></param>
  188. /// <param name="pageSize"></param>
  189. /// <returns></returns>
  190. public IGridResultSet<StudentUserView> GetStudentUserViewList(ViewModel.ConfiguretView configuretView,
  191. Guid? campusID, Guid? collegeID, int? educationID, int? schoolYearID, int? standardID, int? learnFormID,
  192. Guid? classMajorID,string LearnSystem, int pageIndex, int pageSize)
  193. {
  194. Expression<Func<Sys_User, bool>> exp = (x => true);
  195. Expression<Func<Sys_Role, bool>> roleExp = (x => true);
  196. if (campusID.HasValue)
  197. {
  198. exp = exp.And(x => x.CF_Student.CF_Classmajor.CF_Grademajor.CF_Facultymajor.CF_College.CampusID == campusID.Value);
  199. }
  200. if (collegeID.HasValue)
  201. {
  202. exp = exp.And(x => x.CF_Student.CF_Classmajor.CF_Grademajor.CF_Facultymajor.CollegeID == collegeID.Value);
  203. }
  204. if (educationID.HasValue)
  205. {
  206. exp = exp.And(x => x.CF_Student.CF_Classmajor.CF_Grademajor.CF_Facultymajor.EducationID == educationID.Value);
  207. }
  208. if (schoolYearID.HasValue)
  209. {
  210. exp = exp.And(x => x.CF_Student.CF_Classmajor.CF_Grademajor.GradeID == schoolYearID.Value);
  211. }
  212. if (standardID.HasValue)
  213. {
  214. exp = exp.And(x => x.CF_Student.CF_Classmajor.CF_Grademajor.CF_Facultymajor.StandardID == standardID.Value);
  215. }
  216. if (learnFormID.HasValue)
  217. {
  218. exp = exp.And(x => x.CF_Student.CF_Classmajor.CF_Grademajor.CF_Facultymajor.LearningformID == learnFormID.Value);
  219. }
  220. if (classMajorID.HasValue)
  221. {
  222. exp = exp.And(x => x.CF_Student.ClassmajorID == classMajorID);
  223. }
  224. if (!string.IsNullOrEmpty(LearnSystem) && LearnSystem != "-1")
  225. {
  226. var LearnSystems = Convert.ToDecimal(LearnSystem);
  227. exp = exp.And(x => x.CF_Student.CF_Classmajor.CF_Grademajor.CF_Facultymajor.LearnSystem == LearnSystems);
  228. }
  229. IQueryable<StudentUserView> q = UserDAL.GetStudentUserView(exp, roleExp);
  230. if (!string.IsNullOrEmpty(configuretView.ConditionValue) && !string.IsNullOrEmpty(configuretView.Attribute))
  231. q = q.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue);
  232. return this.GetQueryByDataRangeByCollege(q).OrderBy(x => x.Grade).ThenBy(x => x.ClassNo).ThenBy(x => x.LoginID).ToGridResultSet(pageIndex, pageSize);
  233. }
  234. /// <summary>
  235. /// 学生用户列表
  236. /// </summary>
  237. /// <param name="configuretView"></param>
  238. /// <param name="campusID"></param>
  239. /// <param name="collegeID"></param>
  240. /// <param name="educationID"></param>
  241. /// <param name="schoolYearID"></param>
  242. /// <param name="standardID"></param>
  243. /// <param name="learnFormID"></param>
  244. /// <param name="classMajorID"></param>
  245. /// <returns></returns>
  246. public IList<StudentUserView> GetStudentUserViewList(ViewModel.ConfiguretView configuretView,
  247. Guid? campusID, Guid? collegeID, int? educationID, int? schoolYearID, int? standardID, int? learnFormID,
  248. Guid? classMajorID, string LearnSystem)
  249. {
  250. Expression<Func<Sys_User, bool>> exp = (x => true);
  251. Expression<Func<Sys_Role, bool>> roleExp = (x => true);
  252. if (campusID.HasValue)
  253. {
  254. exp = exp.And(x => x.CF_Student.CF_Classmajor.CF_Grademajor.CF_Facultymajor.CF_College.CampusID == campusID.Value);
  255. }
  256. if (collegeID.HasValue)
  257. {
  258. exp = exp.And(x => x.CF_Student.CF_Classmajor.CF_Grademajor.CF_Facultymajor.CollegeID == collegeID.Value);
  259. }
  260. if (educationID.HasValue)
  261. {
  262. exp = exp.And(x => x.CF_Student.CF_Classmajor.CF_Grademajor.CF_Facultymajor.EducationID == educationID.Value);
  263. }
  264. if (schoolYearID.HasValue)
  265. {
  266. exp = exp.And(x => x.CF_Student.CF_Classmajor.CF_Grademajor.GradeID == schoolYearID.Value);
  267. }
  268. if (standardID.HasValue)
  269. {
  270. exp = exp.And(x => x.CF_Student.CF_Classmajor.CF_Grademajor.CF_Facultymajor.StandardID == standardID.Value);
  271. }
  272. if (learnFormID.HasValue)
  273. {
  274. exp = exp.And(x => x.CF_Student.CF_Classmajor.CF_Grademajor.CF_Facultymajor.LearningformID == learnFormID.Value);
  275. }
  276. if (!string.IsNullOrEmpty(LearnSystem) && LearnSystem != "-1")
  277. {
  278. var LearnSystems = Convert.ToDecimal(LearnSystem);
  279. exp = exp.And(x => x.CF_Student.CF_Classmajor.CF_Grademajor.CF_Facultymajor.LearnSystem == LearnSystems);
  280. }
  281. IQueryable<StudentUserView> q = UserDAL.GetStudentUserView(exp, roleExp);
  282. if (!string.IsNullOrEmpty(configuretView.ConditionValue) && !string.IsNullOrEmpty(configuretView.Attribute))
  283. q = q.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue);
  284. return q.OrderBy(x => x.Grade).ThenBy(x => x.ClassNo).ThenBy(x => x.LoginID).ToList();
  285. }
  286. /// <summary>
  287. /// 批量初始化密码
  288. /// </summary>
  289. /// <param name="userID">主键ID</param>
  290. /// <returns></returns>
  291. public virtual void BatchInitPassword(IList<Guid?> userID, bool isChange, string pwd)
  292. {
  293. if (userID.Count > 0)
  294. {
  295. if (isChange == false)
  296. {
  297. List<Sys_User> list = UserDAL.UserRepository.Entities.Where(x => userID.Contains(x.UserID)).ToList();
  298. List<Sys_User> userList = new List<Sys_User>();
  299. foreach (var user in list)
  300. {
  301. user.Password = ("A" + user.LoginID).MD5();
  302. SetModifyStatus(user);
  303. userList.Add(user);
  304. }
  305. UnitOfWork.BatchUpdate(userList);
  306. UnitOfWork.Commit();
  307. }
  308. else
  309. {
  310. List<Sys_User> list = UserDAL.UserRepository.Entities.Where(x => userID.Contains(x.UserID)).ToList();
  311. List<Sys_User> userList = new List<Sys_User>();
  312. foreach (var user in list)
  313. {
  314. user.Password = pwd.MD5();
  315. SetModifyStatus(user);
  316. userList.Add(user);
  317. }
  318. UnitOfWork.BatchUpdate(userList);
  319. UnitOfWork.Commit();
  320. }
  321. }
  322. }
  323. /// <summary>
  324. /// 启用
  325. /// </summary>
  326. /// <param name="userID">主键ID</param>
  327. /// <returns></returns>
  328. public void Usable(IList<Guid?> userID)
  329. {
  330. if (userID.Count > 0)
  331. {
  332. UnitOfWork.Update<Sys_User>(
  333. x => new Sys_User { RecordStatus = (int)SYS_STATUS.USABLE },
  334. x => userID.Contains(x.UserID)
  335. );
  336. List<Sys_User> list = UserDAL.UserRepository.Entities.Where(x => userID.Contains(x.UserID)).ToList();
  337. foreach (var user in list)
  338. {
  339. SetModifyStatus(user);
  340. UnitOfWork.Update(user);
  341. UnitOfWork.Commit();
  342. }
  343. }
  344. }
  345. /// <summary>
  346. /// 禁用
  347. /// </summary>
  348. /// <param name="userID">主键ID</param>
  349. /// <returns></returns>
  350. public void UnUsable(IList<Guid?> userID)
  351. {
  352. if (userID.Count > 0)
  353. {
  354. UnitOfWork.Update<Sys_User>(
  355. x => new Sys_User { RecordStatus = (int)SYS_STATUS.UNUSABLE },
  356. x => userID.Contains(x.UserID)
  357. );
  358. List<Sys_User> list = UserDAL.UserRepository.Entities.Where(x => userID.Contains(x.UserID)).ToList();
  359. foreach (var user in list)
  360. {
  361. SetModifyStatus(user);
  362. UnitOfWork.Update(user);
  363. UnitOfWork.Commit();
  364. }
  365. }
  366. }
  367. /// <summary>
  368. /// 保存用户角色
  369. /// </summary>
  370. /// <param name="userID"></param>
  371. /// <param name="roleID"></param>
  372. public void SaveUserRoles(Guid userID, IList<Guid?> roleID)
  373. {
  374. var user = this.UserDAL.UserRepository.GetSingle(x => x.UserID == userID, (x => x.Sys_Role));
  375. var roleList = this.RoleDAL.RoleRepository.GetList(x => roleID.Contains(x.RoleID)).ToList();
  376. user.Sys_Role = new HashSet<Sys_Role>();
  377. roleList.ForEach(x => user.Sys_Role.Add(x));
  378. this.UnitOfWork.Commit();
  379. }
  380. public IList<CF_Campus> GetUserInchargeCampus(Guid userID)
  381. {
  382. var campusList = this.StaffDAL.GetUserInChargeCampus(x => x.UserID == userID).ToList();
  383. return campusList;
  384. }
  385. public IList<CF_College> GetUserInchargeCollege(Guid userID)
  386. {
  387. var collegeList = this.StaffDAL.GetUserInChargeCollege(x => x.UserID == userID).ToList();
  388. return collegeList;
  389. }
  390. public IList<CF_Department> GetUserInchargeDepartment(Guid userID)
  391. {
  392. var departmentList = StaffDAL.GetUserInChargeDepartment(x => x.UserID == userID).ToList();
  393. return departmentList;
  394. }
  395. public IList<Sys_Role> GetUserRoles(Guid userID)
  396. {
  397. var user = this.UserDAL.UserRepository.GetSingle(x => x.UserID == userID, (x => x.Sys_Role));
  398. var roleList = user.Sys_Role.ToList();
  399. return roleList;
  400. }
  401. public Sys_Role GetMaxPrivilegeRoleByUserID(Guid userID)
  402. {
  403. var role = RoleDAL.RoleRepository.GetList(x => x.Sys_User.Any(w => w.UserID == userID))
  404. .OrderByDescending(x => x.Sys_FunctionCode.Count())
  405. .FirstOrDefault();
  406. return role;
  407. }
  408. /// <summary>
  409. /// 保存用户所属校区
  410. /// </summary>
  411. /// <param name="userID"></param>
  412. /// <param name="roleID"></param>
  413. public void SaveUserCampus(Guid userID, IList<Guid?> campusID)
  414. {
  415. var user = this.UserDAL.UserRepository.GetSingle(x => x.UserID == userID, (x => x.CF_Staff.CF_StaffManageCampus));
  416. if (user.CF_Staff == null) throw new Exception("该用户并非教职工用户,请补全该用户的教职工信息再进行操作,或选择其他用户进行操作。");
  417. //var campusList = this.CampusDAL.campusRepository.GetList(x => campusID.Contains(x.CampusID)).ToList();
  418. user.CF_Staff.CF_StaffManageCampus.ToList().ForEach(x => this.UnitOfWork.Remove(x));
  419. campusID.ForEach(x => {
  420. CF_StaffManageCampus staffManageCampus = new CF_StaffManageCampus();
  421. staffManageCampus.StaffManageCampusID = Guid.NewGuid();
  422. staffManageCampus.UserID = userID;
  423. staffManageCampus.CampusID = x;
  424. this.SetNewStatus(staffManageCampus);
  425. this.UnitOfWork.Add(staffManageCampus);
  426. });
  427. this.UnitOfWork.Commit();
  428. }
  429. /// <summary>
  430. /// 保存用户所属学院
  431. /// </summary>
  432. /// <param name="userID"></param>
  433. /// <param name="roleID"></param>
  434. public void SaveUserCollege(Guid userID, IList<Guid?> collegeID)
  435. {
  436. var user = this.UserDAL.UserRepository.GetSingle(x => x.UserID == userID, (x => x.CF_Staff.CF_StaffManageCollege));
  437. if (user.CF_Staff == null) throw new Exception("该用户并非教职工用户,请补全该用户的教职工信息再进行操作,或选择其他用户进行操作。");
  438. user.CF_Staff.CF_StaffManageCollege.ToList().ForEach(x => this.UnitOfWork.Remove(x));
  439. collegeID.ForEach(x =>
  440. {
  441. CF_StaffManageCollege staffManageCollege = new CF_StaffManageCollege();
  442. staffManageCollege.StaffManageCollegeID = Guid.NewGuid();
  443. staffManageCollege.UserID = userID;
  444. staffManageCollege.CollegeID = x;
  445. this.SetNewStatus(staffManageCollege);
  446. this.UnitOfWork.Add(staffManageCollege);
  447. });
  448. this.UnitOfWork.Commit();
  449. }
  450. /// <summary>
  451. /// 保存用户所属教研室
  452. /// </summary>
  453. /// <param name="userID"></param>
  454. /// <param name="departmentID"></param>
  455. public void SaveUserDepartment(Guid userID, IList<Guid?> departmentID)
  456. {
  457. var user = this.UserDAL.UserRepository.GetSingle(x => x.UserID == userID, (x => x.CF_Staff.CF_StaffManageDepartment));
  458. if (user.CF_Staff == null) throw new Exception("该用户并非教职工用户,请补全该用户的教职工信息再进行操作,或选择其他用户进行操作。");
  459. user.CF_Staff.CF_StaffManageDepartment.ToList().ForEach(x => this.UnitOfWork.Remove(x));
  460. departmentID.ForEach(x =>
  461. {
  462. CF_StaffManageDepartment staffManageDepartment = new CF_StaffManageDepartment();
  463. staffManageDepartment.StaffManageDepartmentID = Guid.NewGuid();
  464. staffManageDepartment.UserID = userID;
  465. staffManageDepartment.DepartmentID = x;
  466. this.SetNewStatus(staffManageDepartment);
  467. this.UnitOfWork.Add(staffManageDepartment);
  468. });
  469. this.UnitOfWork.Commit();
  470. }
  471. public IList<RoleView> GetUserRolesView(Guid userID)
  472. {
  473. return RoleDAL.GetRoleView(x => x.Sys_User.Any(w => w.UserID == userID)).OrderBy(x => x.TypeID).ThenBy(x => x.OrderNo).ToList();
  474. }
  475. public string GetUserEmail(Guid userID)
  476. {
  477. var user = UserDAL.UserRepository.GetSingle(x => x.UserID == userID, (x => x.CF_Staff.CF_StaffProfile), (x => x.CF_Student.CF_StudentContact));
  478. if (user == null) throw new Exception("指定的用户信息不存在。");
  479. if (user.CF_Student != null && user.CF_Student.CF_StudentContact != null)
  480. {
  481. return user.CF_Student.CF_StudentContact.Email;
  482. }
  483. else if (user.CF_Staff != null && user.CF_Staff.CF_StaffProfile != null)
  484. {
  485. return user.CF_Staff.CF_StaffProfile.Email;
  486. }
  487. else
  488. {
  489. throw new Exception("用户并没有注册电子邮箱信息。");
  490. }
  491. }
  492. public void ChangePassword(ChangePasswordView password, Guid userID)
  493. {
  494. var user = this.UserDAL.UserRepository.GetSingle(x => x.UserID == userID, (x => x.Sys_MailVerifyCode));
  495. user.Password = password.Password.MD5();
  496. user.Sys_MailVerifyCode = null;
  497. UnitOfWork.Commit();
  498. }
  499. public Sys_User GetUserByID(Guid userID)
  500. {
  501. return this.UserDAL.UserRepository.Entities.Where(x => x.UserID == userID).FirstOrDefault();
  502. }
  503. public void SynHRServices()
  504. {
  505. var exceptUser = new string[] { "admin" };
  506. var hrUsers = CommUserRepository.GetList(x => !exceptUser.Contains(x.userid)).ToList();
  507. var staffs = StaffDAL.staffRepository.GetList(x => !exceptUser.Contains(x.Sys_User.LoginID))
  508. .Include(x => x.Sys_User).Include(x => x.CF_StaffProfile).ToList();
  509. hrUsers.ForEach(x => x.status = "D");
  510. foreach (var staff in staffs)
  511. {
  512. var hrUser = hrUsers.FirstOrDefault(x => x.userid == staff.Sys_User.LoginID);
  513. if (hrUser == null)
  514. {
  515. hrUser = new Entities.HRServices.Comm_Users();
  516. hrUser.userid = staff.Sys_User.LoginID;
  517. hrUser.loginid = staff.Sys_User.LoginID;
  518. hrUser.createdt = DateTime.Now;
  519. this.HRUnitOfWork.Add(hrUser);
  520. }
  521. hrUser.username = staff.Sys_User.Name;
  522. if (staff.DepartmentID.HasValue)
  523. {
  524. hrUser.dpid = staff.DepartmentID.ToString();
  525. }
  526. else
  527. {
  528. hrUser.dpid = staff.CollegeID.ToString();
  529. }
  530. hrUser.telephone = staff.CF_StaffProfile.Telephone;
  531. hrUser.mobile = staff.CF_StaffProfile.Mobile;
  532. hrUser.email = staff.CF_StaffProfile.Email;
  533. hrUser.cardid = staff.Sys_User.LoginID;
  534. hrUser.employeeclassid = "";
  535. hrUser.jobtypeid = "教师";
  536. hrUser.birthday = staff.BirthDate;
  537. switch (staff.SexID)
  538. {
  539. case (int)CF_Sex.Male:
  540. hrUser.sex = "1";
  541. break;
  542. case (int)CF_Sex.Female:
  543. hrUser.sex = "2";
  544. break;
  545. default:
  546. hrUser.sex = "0";
  547. break;
  548. }
  549. hrUser.orderNo = "1";
  550. hrUser.userrole = "";
  551. hrUser.userligion = "";
  552. hrUser.password = staff.Sys_User.Password;
  553. hrUser.status = "A";
  554. hrUser.updatedt = DateTime.Now;
  555. hrUser.istmpuser = false;
  556. }
  557. this.HRUnitOfWork.Commit();
  558. }
  559. public virtual string SSOLogin()
  560. {
  561. return SSO.SSOLogin();
  562. }
  563. }
  564. }