StaffServices.cs 62 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Data.Entity;
  6. using EMIS.DataLogic.Common.TeacherManagement;
  7. using Bowin.Common.Linq.Entity;
  8. using EMIS.ViewModel.TeacherManagement;
  9. using EMIS.ViewModel;
  10. using EMIS.Entities;
  11. using Bowin.Common.Linq;
  12. using System.Linq.Expressions;
  13. using EMIS.CommonLogic.AdministrativeOrgan;
  14. using EMIS.Utility;
  15. using EMIS.CommonLogic.SystemServices;
  16. using Bowin.Common.Utility;
  17. using EMIS.ViewModel.Cache;
  18. using EMIS.DataLogic.Repositories;
  19. using Bowin.Common.DataTime;
  20. using EMIS.DataLogic.SystemDAL;
  21. namespace EMIS.CommonLogic.TeacherManagement
  22. {
  23. public class StaffServices : BaseServices, IStaffServices
  24. {
  25. public Lazy<StaffDAL> staffDAL { get; set; }
  26. public ParameterDAL ParameterDAL { get; set; }
  27. public Lazy<ICollegeServices> collegeServices { get; set; }
  28. public Lazy<IUserServices> userServices { get; set; }
  29. public CollegeRepository CollegeRepository { get; set; }
  30. public DepartmentRepository DepartmentRepository { get; set; }
  31. public Lazy<DataTimeHelper> TimeHelper { get; set; }
  32. public RoleDAL RoleDAL { get; set; }
  33. /// <summary>
  34. /// 查询教师列表
  35. /// </summary>
  36. /// <param name="configuretView">查询条件实体</param>
  37. /// <param name="campusID">校区ID</param>
  38. /// <param name="collegeID">学院ID</param>
  39. /// <param name="DepartmentID">教研室ID</param>
  40. /// <param name="isPhoto">是否显示照片</param>
  41. /// <param name="pageIndex">页码</param>
  42. /// <param name="pageSize">显示码</param>
  43. /// <returns></returns>
  44. public Bowin.Common.Linq.Entity.IGridResultSet<ViewModel.TeacherManagement.StaffView> GetStaffViewGrid(ViewModel.ConfiguretView configuretView, Guid? campusID, Guid? collegeID, Guid? departmentID, int? isPhoto, Guid? userID, int pageIndex, int pageSize)
  45. {
  46. var query = staffDAL.Value.GetStaffViewQueryable(x => true);
  47. if (campusID.HasValue)
  48. query = query.Where(x => x.CampusID == campusID);
  49. if (collegeID.HasValue)
  50. query = query.Where(x => x.CollegeID == collegeID);
  51. if (userID.HasValue)
  52. query = query.Where(x => x.UserID == userID);
  53. if (departmentID.HasValue)
  54. query = query.Where(x => x.DepartmentID == departmentID);
  55. if (isPhoto > 0)
  56. query = query.Where(x => x.PhotoUrl != null && x.PhotoUrl != "");
  57. if (isPhoto == 0)
  58. query = query.Where(x => x.PhotoUrl == null || x.PhotoUrl == "");
  59. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  60. {
  61. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue);
  62. }
  63. query = this.GetQueryByDataRangeByCollege(query).OrderBy(x => x.CollegeNo.Length).ThenBy(x => x.CollegeNo)
  64. .ThenBy(x => x.StaffCode.Length).ThenBy(x => x.StaffCode);
  65. try
  66. {
  67. return query
  68. .ToGridResultSet<StaffView>(pageIndex, pageSize);
  69. }
  70. catch (Exception ex)
  71. {
  72. throw ex;
  73. }
  74. }
  75. /// <summary>
  76. /// 查询教师列表
  77. /// </summary>
  78. /// <param name="configuretView">查询条件实体</param>
  79. /// <param name="campusID">校区ID</param>
  80. /// <param name="collegeID">学院ID</param>
  81. /// <param name="DepartmentID">教研室ID</param>
  82. /// <param name="isPhoto">是否显示照片</param>
  83. /// <param name="pageIndex">页码</param>
  84. /// <param name="pageSize">显示码</param>
  85. /// <returns></returns>
  86. public IGridResultSet<StaffView> GetStaffViewGridWithNoDataRange(ConfiguretView configuretView,
  87. Guid? campusID, Guid? collegeID, Guid? departmentID, int? isPhoto, Guid? userID, int pageIndex, int pageSize)
  88. {
  89. var query = staffDAL.Value.GetStaffViewQueryable(x => true);
  90. if (campusID.HasValue)
  91. query = query.Where(x => x.CampusID == campusID);
  92. if (collegeID.HasValue)
  93. query = query.Where(x => x.CollegeID == collegeID);
  94. if (userID.HasValue)
  95. query = query.Where(x => x.UserID == userID);
  96. if (departmentID.HasValue)
  97. query = query.Where(x => x.DepartmentID == departmentID);
  98. if (isPhoto > 0)
  99. query = query.Where(x => x.PhotoUrl != null && x.PhotoUrl != "");
  100. if (isPhoto == 0)
  101. query = query.Where(x => x.PhotoUrl == null || x.PhotoUrl == "");
  102. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  103. {
  104. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue);
  105. }
  106. query = query.OrderBy(x => x.CollegeNo.Length).ThenBy(x => x.CollegeNo)
  107. .ThenBy(x => x.StaffCode.Length).ThenBy(x => x.StaffCode);
  108. try
  109. {
  110. return query
  111. .ToGridResultSet<StaffView>(pageIndex, pageSize);
  112. }
  113. catch (Exception ex)
  114. {
  115. throw ex;
  116. }
  117. }
  118. public Bowin.Common.Linq.Entity.IGridResultSet<ViewModel.TeacherManagement.StaffView> GetStaffViewGrid(Guid? campusID, Guid? collegeID, string loginID, string name, int pageIndex, int pageSize)
  119. {
  120. Expression<Func<CF_Staff, bool>> exp = (x => true);
  121. if (campusID.HasValue)
  122. exp = exp.And(x => x.CF_College.CampusID == campusID);
  123. if (collegeID.HasValue)
  124. exp = exp.And(x => x.CollegeID == collegeID);
  125. if (!string.IsNullOrEmpty(loginID))
  126. exp = exp.And(x => x.Sys_User.LoginID.Contains(loginID));
  127. if (!string.IsNullOrEmpty(name))
  128. exp = exp.And(x => x.Sys_User.Name.Contains(name));
  129. var query = staffDAL.Value.GetStaffViewQueryable(exp);
  130. return this.GetQueryByDataRangeByCollege(query).OrderBy(x => x.StaffCode.Length).ThenBy(x => x.StaffCode)
  131. .ToGridResultSet<StaffView>(pageIndex, pageSize);
  132. }
  133. /// <summary>
  134. /// 查询教师列表
  135. /// </summary>
  136. /// <param name="configuretView">查询条件实体</param>
  137. /// <param name="campusID">校区ID</param>
  138. /// <param name="collegeID">学院ID</param>
  139. /// <param name="DepartmentID">教研室ID</param>
  140. /// <param name="isPhoto">是否显示照片</param>
  141. /// <returns></returns>
  142. public List<ViewModel.TeacherManagement.StaffView> GetStaffViewList(ViewModel.ConfiguretView configuretView, Guid? campusID, Guid? collegeID, Guid? departmentID, int? isPhoto)
  143. {
  144. var query = staffDAL.Value.GetStaffViewQueryable(x => true);
  145. if (campusID.HasValue)
  146. query = query.Where(x => x.CampusID == campusID);
  147. if (collegeID.HasValue)
  148. query = query.Where(x => x.CollegeID == collegeID);
  149. if (departmentID.HasValue)
  150. query = query.Where(x => x.DepartmentID == departmentID);
  151. if (isPhoto > 0)
  152. query = query.Where(x => x.PhotoUrl != null && x.PhotoUrl != "");
  153. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  154. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue);
  155. return this.GetQueryByDataRangeByCollege(query).OrderBy(x => x.CollegeNo.Length)
  156. .ThenBy(x => x.CollegeNo).ThenBy(x => x.StaffCode.Length)
  157. .ThenBy(x => x.StaffCode).ToList();
  158. }
  159. /// <summary>
  160. /// 获取全部教师列表详细信息
  161. /// </summary>
  162. /// <returns></returns>
  163. public List<ViewModel.TeacherManagement.StaffView> GetListStaffView()
  164. {
  165. var query = staffDAL.Value.GetStaffViewQueryable(x => true);
  166. return this.GetQueryByDataRangeByCollege(query).OrderBy(x => x.StaffCode.Length).ThenBy(x => x.StaffCode)
  167. .ToList();
  168. }
  169. /// <summary>
  170. /// 获取全部教师主表列表信息
  171. /// </summary>
  172. /// <returns></returns>
  173. public List<Entities.CF_Staff> GetStaffList()
  174. {
  175. return this.GetQueryByDataRangeByCollege(staffDAL.Value.staffRepository.Entities)
  176. .OrderBy(x => x.Sys_User.LoginID.Length).ThenBy(x => x.Sys_User.LoginID)
  177. .ToList();
  178. }
  179. /// <summary>
  180. /// 获取教师主表信息
  181. /// </summary>
  182. /// <param name="userID">用户ID</param>
  183. /// <returns></returns>
  184. public Entities.CF_Staff GetStaff(Guid? userID)
  185. {
  186. //查询条件
  187. System.Linq.Expressions.Expression<Func<CF_Staff, bool>> expression = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  188. expression = (x => x.UserID == userID);
  189. return staffDAL.Value.staffRepository.GetSingle(expression, (x => x.CF_StaffManageCampus), (x => x.CF_StaffManageCollege), (x => x.CF_StaffProfile), (x => x.Sys_User));
  190. }
  191. /// <summary>
  192. /// 获取教师主表信息
  193. /// </summary>
  194. /// <param name="userID">Expression查询条件</param>
  195. /// <returns></returns>
  196. public Entities.CF_Staff GetStaff(System.Linq.Expressions.Expression<Func<Entities.CF_Staff, bool>> exp)
  197. {
  198. return staffDAL.Value.staffRepository.GetSingle(exp);
  199. }
  200. /// <summary>
  201. /// 获取教师扩展表信息
  202. /// </summary>
  203. /// <param name="userID">用户ID</param>
  204. /// <returns></returns>
  205. public Entities.CF_StaffProfile GetStaffProfile(Guid? userID)
  206. {
  207. //查询条件
  208. System.Linq.Expressions.Expression<Func<CF_StaffProfile, bool>> expression = (x => true);
  209. if (userID.HasValue)
  210. expression = (x => x.UserID == userID);
  211. return staffDAL.Value.staffProfileRepository.GetSingle(expression);
  212. }
  213. /// <summary>
  214. /// 获取教师详细信息
  215. /// </summary>
  216. /// <param name="userID">用户ID</param>
  217. /// <returns></returns>
  218. public ViewModel.TeacherManagement.StaffView GetStaffView(Guid? userID)
  219. {
  220. var query = staffDAL.Value.GetStaffViewQueryable(x => true);
  221. if (userID.HasValue)
  222. query = query.Where(x => x.UserID == userID);
  223. return query.FirstOrDefault();
  224. }
  225. /// <summary>
  226. /// 获取教师详细信息
  227. /// </summary>
  228. /// <param name="exp">Expression查询条件</param>
  229. /// <returns></returns>
  230. public ViewModel.TeacherManagement.StaffView GetStaffView(System.Linq.Expressions.Expression<Func<Entities.CF_Staff, bool>> exp)
  231. {
  232. var query = staffDAL.Value.GetStaffViewQueryable(exp);
  233. return query.FirstOrDefault();
  234. }
  235. /// <summary>
  236. /// 添加
  237. /// </summary>
  238. /// <param name="staff">主表实体</param>
  239. /// <param name="staffProfile">扩展表实体</param>
  240. /// <returns></returns>
  241. public void StaffAdd(StaffView staffView, string photoUrl)
  242. {
  243. try
  244. {
  245. Sys_User sys_user = new Sys_User();
  246. CF_Staff staff = new CF_Staff();
  247. CF_StaffProfile staffProfile = new CF_StaffProfile();
  248. CF_Department department = new CF_Department();
  249. CF_College college = collegeServices.Value.GetCollegeInfo(staffView.CollegeID);
  250. var parameter = ParameterDAL.ParameterRepository.GetSingle(x => x.ParameterTypeID == (int)ViewModel.CF_ParameterType.TeacherInitPassword);
  251. if (staffView.UserID == null || staffView.UserID == Guid.Empty)
  252. {
  253. sys_user.UserID = Guid.NewGuid();
  254. sys_user.LoginID = staffView.StaffCode;
  255. sys_user.Name = staffView.Name;
  256. if (parameter == null)
  257. {
  258. sys_user.Password = ("A" + staffView.StaffCode).MD5();
  259. }
  260. else
  261. {
  262. if (parameter.Value != null)
  263. {
  264. sys_user.Password = parameter.Value;
  265. }
  266. else
  267. {
  268. sys_user.Password = ("A" + staffView.StaffCode).MD5();
  269. }
  270. }
  271. //sys_user.Password = Const.USER_INIT_PASSWORD;
  272. SetNewStatus(sys_user);
  273. UnitOfWork.Add(sys_user);
  274. var role = RoleDAL.RoleRepository.GetSingle(x => x.RoleName.Contains("教师"));
  275. if (role != null)
  276. {
  277. sys_user.Sys_Role.Add(role);
  278. }
  279. staff.UserID = sys_user.UserID;
  280. staff.DepartmentID = staffView.DepartmentID;
  281. staff.CollegeID = staffView.CollegeID;
  282. staff.StaffCode = staffView.StaffCode;
  283. if (staffView.BirthDate == null)
  284. {
  285. staff.BirthDate = DateTime.Now;
  286. }
  287. else
  288. {
  289. staff.BirthDate = staffView.BirthDate;
  290. }
  291. staff.Sex = staffView.Sex;
  292. staff.TeacherType = staffView.TeacherType;
  293. staff.IncumbencyState = staffView.IncumbencyState;
  294. staff.CertificatesType = staffView.CertificatesType;
  295. staff.CertificatesNum = staffView.CertificatesNum;
  296. staff.Situation = staffView.Situation;
  297. staff.LiteracyLevels = staffView.LiteracyLevels;
  298. staff.DegreeState = staffView.DegreeState;
  299. staff.LearnPosition = staffView.LearnPosition;
  300. staff.Title = staffView.Title;
  301. staff.WorkDate = staffView.WorkDate;
  302. staff.ComeSchoolDate = staffView.ComeSchoolDate;
  303. staff.TeachingDate = staffView.TeachingDate;
  304. if (!string.IsNullOrEmpty(photoUrl))
  305. {
  306. staff.PhotoUrl = photoUrl;
  307. }
  308. staff.Profile = staffView.Profile;
  309. staff.Remarks = staffView.Remarks;
  310. staff.PaymentLevelID = staffView.PaymentLevelID;
  311. staff.IsDualTeacher = staffView.IsDualTeacher;
  312. SetNewStatus(staff);
  313. UnitOfWork.Add(staff);
  314. staffProfile.UserID = sys_user.UserID;
  315. staffProfile.UsedName = staffView.UsedName;
  316. staffProfile.Nation = staffView.Nation;
  317. staffProfile.Place = staffView.Place;
  318. staffProfile.EducationCode = staffView.EducationCode;
  319. staffProfile.Telephone = staffView.Telephone;
  320. staffProfile.OfficeTelephone = staffView.OfficeTelephone;
  321. staffProfile.Mobile = staffView.Mobile;
  322. staffProfile.Email = staffView.Email;
  323. staffProfile.QQ = staffView.QQ;
  324. staffProfile.Nationality = staffView.Nationality;
  325. staffProfile.HealthState = staffView.HealthState;
  326. staffProfile.HousePhone = staffView.HousePhone;
  327. staffProfile.Address = staffView.Address;
  328. staffProfile.Postcode = staffView.Postcode;
  329. staffProfile.HomeAddress = staffView.HomeAddress;
  330. staffProfile.NowAddress = staffView.NowAddress;
  331. staffProfile.Residence = staffView.Residence;
  332. staffProfile.Speciality = staffView.Speciality;
  333. staffProfile.WeChatNum = staffView.WeChatNum;
  334. staffProfile.Religion = staffView.Religion;
  335. staffProfile.Account = staffView.Account;
  336. UnitOfWork.Add(staffProfile);
  337. CF_StaffManageCampus staffManageCampus = new CF_StaffManageCampus();
  338. staffManageCampus.StaffManageCampusID = Guid.NewGuid();
  339. staffManageCampus.UserID = sys_user.UserID;
  340. staffManageCampus.CampusID = college.CampusID;
  341. this.SetNewStatus(staffManageCampus);
  342. this.UnitOfWork.Add(staffManageCampus);
  343. CF_StaffManageCollege staffManageCollege = new CF_StaffManageCollege();
  344. staffManageCollege.StaffManageCollegeID = Guid.NewGuid();
  345. staffManageCollege.UserID = sys_user.UserID;
  346. staffManageCollege.CollegeID = staff.CollegeID;
  347. this.SetNewStatus(staffManageCollege);
  348. this.UnitOfWork.Add(staffManageCollege);
  349. }
  350. else
  351. {
  352. sys_user = userServices.Value.GetUserByID(staffView.UserID);
  353. staff = GetStaff(staffView.UserID);
  354. staffProfile = staff.CF_StaffProfile;
  355. sys_user.Name = staffView.Name;
  356. sys_user.LoginID = staffView.StaffCode;
  357. SetModifyStatus(sys_user);
  358. var lastCollegeID = staff.CollegeID;
  359. staff.DepartmentID = staffView.DepartmentID;
  360. staff.CollegeID = staffView.CollegeID;
  361. staff.StaffCode = staffView.StaffCode;
  362. staff.BirthDate = staffView.BirthDate;
  363. staff.Sex = staffView.Sex;
  364. staff.TeacherType = staffView.TeacherType;
  365. staff.IncumbencyState = staffView.IncumbencyState;
  366. staff.CertificatesType = staffView.CertificatesType;
  367. staff.CertificatesNum = staffView.CertificatesNum;
  368. staff.Situation = staffView.Situation;
  369. staff.LiteracyLevels = staffView.LiteracyLevels;
  370. staff.DegreeState = staffView.DegreeState;
  371. staff.LearnPosition = staffView.LearnPosition;
  372. staff.Title = staffView.Title;
  373. staff.WorkDate = staffView.WorkDate;
  374. staff.ComeSchoolDate = staffView.ComeSchoolDate;
  375. staff.TeachingDate = staffView.TeachingDate;
  376. if (photoUrl != null)
  377. {
  378. staff.PhotoUrl = photoUrl;
  379. }
  380. staff.Profile = staffView.Profile;
  381. staff.Remarks = staffView.Remarks;
  382. staff.PaymentLevelID = staffView.PaymentLevelID;
  383. staff.IsDualTeacher = staffView.IsDualTeacher;
  384. SetModifyStatus(staff);
  385. if (lastCollegeID != college.CollegeID)
  386. {
  387. staff.CF_StaffManageCampus = new HashSet<CF_StaffManageCampus>();
  388. staff.CF_StaffManageCollege = new HashSet<CF_StaffManageCollege>();
  389. CF_StaffManageCampus staffManageCampus = new CF_StaffManageCampus();
  390. staffManageCampus.StaffManageCampusID = Guid.NewGuid();
  391. staffManageCampus.UserID = sys_user.UserID;
  392. staffManageCampus.CampusID = college.CampusID;
  393. this.SetNewStatus(staffManageCampus);
  394. this.UnitOfWork.Add(staffManageCampus);
  395. CF_StaffManageCollege staffManageCollege = new CF_StaffManageCollege();
  396. staffManageCollege.StaffManageCollegeID = Guid.NewGuid();
  397. staffManageCollege.UserID = sys_user.UserID;
  398. staffManageCollege.CollegeID = staff.CollegeID;
  399. this.SetNewStatus(staffManageCollege);
  400. this.UnitOfWork.Add(staffManageCollege);
  401. }
  402. if (staffProfile == null)
  403. {
  404. staffProfile = new CF_StaffProfile();
  405. UnitOfWork.Add(staffProfile);
  406. }
  407. staffProfile.UserID = staff.UserID;
  408. staffProfile.UsedName = staffView.UsedName;
  409. staffProfile.Nation = staffView.Nation;
  410. staffProfile.Place = staffView.Place;
  411. staffProfile.EducationCode = staffView.EducationCode;
  412. staffProfile.Telephone = staffView.Telephone;
  413. staffProfile.OfficeTelephone = staffView.OfficeTelephone;
  414. staffProfile.Mobile = staffView.Mobile;
  415. staffProfile.Email = staffView.Email;
  416. staffProfile.QQ = staffView.QQ;
  417. staffProfile.Nationality = staffView.Nationality;
  418. staffProfile.HealthState = staffView.HealthState;
  419. staffProfile.HousePhone = staffView.HousePhone;
  420. staffProfile.Address = staffView.Address;
  421. staffProfile.Postcode = staffView.Postcode;
  422. staffProfile.HomeAddress = staffView.HomeAddress;
  423. staffProfile.NowAddress = staffView.NowAddress;
  424. staffProfile.Residence = staffView.Residence;
  425. staffProfile.Speciality = staffView.Speciality;
  426. staffProfile.WeChatNum = staffView.WeChatNum;
  427. staffProfile.Religion = staffView.Religion;
  428. staffProfile.Account = staffView.Account;
  429. }
  430. UnitOfWork.Commit();
  431. }
  432. catch (Exception)
  433. {
  434. throw;
  435. }
  436. }
  437. /// <summary>
  438. /// 删除
  439. /// </summary>
  440. /// <param name="userIDs"></param>
  441. /// <returns></returns>
  442. public bool StaffDelete(List<Guid> userIDs)
  443. {
  444. try
  445. {
  446. var staffList = staffDAL.Value.staffRepository.GetList(x => userIDs.Contains(x.UserID),
  447. (x => x.CF_StaffProfile), (x => x.Sys_User.Sys_Role)).ToList();
  448. var UserList=staffDAL.Value.UserRepository.GetList(x => userIDs.Contains(x.UserID)).ToList();
  449. UnitOfWork.Delete(staffList);
  450. UnitOfWork.Delete( UserList, (x=>x.Sys_Role));
  451. UnitOfWork.Delete(UserList);
  452. UnitOfWork.Commit();
  453. return true;
  454. }
  455. catch (Exception)
  456. {
  457. throw;
  458. }
  459. }
  460. /// <summary>
  461. /// 获取全部教师列表详细信息
  462. /// </summary>
  463. /// <returns></returns>
  464. public List<StaffView> GetListStaffView(Guid? userID)
  465. {
  466. //查询条件
  467. System.Linq.Expressions.Expression<Func<CF_Staff, bool>> expression = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  468. if (userID.HasValue)
  469. expression = (x => x.UserID == userID);
  470. var query = staffDAL.Value.GetStaffViewQueryable(expression);
  471. return query.ToList();
  472. }
  473. /// <summary>
  474. /// 获取全部教师不带数据范围
  475. /// </summary>
  476. /// <returns></returns>
  477. public Bowin.Common.Linq.Entity.IGridResultSet<ViewModel.TeacherManagement.StaffView> GetAllStaffView(ViewModel.ConfiguretView configuretView, int pageIndex, int pageSize)
  478. {
  479. //查询条件
  480. System.Linq.Expressions.Expression<Func<CF_Staff, bool>> expression = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  481. var query = staffDAL.Value.GetStaffViewQueryable(expression);
  482. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  483. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue);
  484. return query.OrderBy(x => x.StaffCode.Length).ThenBy(x => x.StaffCode).ToGridResultSet(pageIndex, pageSize);
  485. }
  486. /// <summary>
  487. /// 教师信息验证
  488. /// </summary>
  489. /// <param name="userID">教职工ID</param>
  490. /// <param name="Code">代码</param>
  491. /// <returns></returns>
  492. public string GetVerification(Guid? userID, string Code, Guid? CollegeID, Guid? DepartmentID)
  493. {
  494. if (!DepartmentRepository.Entities.Any(x => x.CollegeID == CollegeID && x.DepartmentID == DepartmentID) && DepartmentID != null)
  495. {
  496. return ("教研室和" + RSL.Get("College") + "不匹配。");
  497. }
  498. Sys_User userNo = null;
  499. Sys_User userInfo = null;
  500. if (!string.IsNullOrEmpty(Code))
  501. {
  502. userNo = userServices.Value.GetUserByLoginID(Code.Trim());
  503. if (!string.IsNullOrEmpty(Code) && userID != Guid.Empty)
  504. {
  505. userInfo = GetStaff(userID).Sys_User;
  506. if (userNo == userInfo)
  507. return "成功。";
  508. else
  509. {
  510. if (userNo != null)
  511. return "保存失败,教职工号已存在。";
  512. }
  513. }
  514. else
  515. {
  516. if (userNo != null)
  517. return "保存失败,教职工号已存在。";
  518. }
  519. }
  520. if (userID.HasValue && userID != Guid.Empty)
  521. {
  522. userInfo = GetStaff(userID).Sys_User;
  523. if (userInfo == null)
  524. return "保存失败,数据有误,请核查。";
  525. }
  526. return "成功。";
  527. }
  528. public void DeletePhoto(Guid userID)
  529. {
  530. var staff = this.GetStaff(userID);
  531. if (!string.IsNullOrEmpty(staff.PhotoUrl))
  532. {
  533. FileUploadHelper.DeleteFile(staff.PhotoUrl);
  534. staff.PhotoUrl = null;
  535. this.UnitOfWork.Commit();
  536. }
  537. }
  538. /// <summary>
  539. /// 教师信息导入
  540. /// </summary>
  541. /// <param name="dataList">导入的数据集合</param>
  542. /// <param name="errdataList">返回的操作失败集合</param>
  543. /// <param name="successCount">操作成功记录条数</param>
  544. /// <returns></returns>
  545. public virtual void StaffImport(out int OkCount, out List<StaffView> errdataList, out int successCount, string sourcePhysicalPath,string sourceWebPath,out string errorWebPath,out string Errinfo)
  546. {
  547. var excel = new NpoiExcelHelper();
  548. #region 1.0 单元格抬头
  549. Dictionary<string, string> cellheader = new Dictionary<string, string>
  550. {
  551. { "StaffCode", "教职工号" }, { "Name", "姓名" },
  552. { "CollegeName", RSL.Get("College") },{ "TeachingDateStr", "从教年月" },
  553. { "DepartmentName", "教研室" },{ "BirthDateStr", "出生日期" },
  554. { "IncumbencyStateStr", "在职状态" },{ "TeacherTypeStr", "教师类型" },
  555. { "SexStr", "性别" },{ "UsedName", "曾用名" },// { "Politics", "政治面貌" },
  556. { "NationStr", "民族" },{ "Place", "籍贯" },
  557. {"EducationCodeStr","学历"},{ "Telephone", "家庭电话" },
  558. { "OfficeTelephone", "办公电话" },{ "Mobile", "移动电话" },
  559. { "Email", "电子邮箱" },{ "QQ", "QQ" },
  560. { "Nationality", "国籍" }, { "HealthStateStr", "健康状态" },
  561. {"HousePhone","住宅电话"},{ "Address", "通信地址" },
  562. { "Postcode", "邮政编码" }, { "HomeAddress", "家族住址" },
  563. { "NowAddress", "现住地址" },{ "Residence", "户口所在地" },
  564. { "ReligionStr", "宗教信仰" }, { "CertificatesTypeStr", "证件类型" },
  565. { "CertificatesNum", "证件号码" },{ "SituationStr", "任课状况名称" },
  566. { "LiteracyLevelsStr", "文化程度" }, { "DegreeStateStr", "学位状况" },
  567. { "LearnPositionStr", "学位" },{ "TitleStr", "职称" },
  568. { "PaymentLevelStr", "课酬级别" },{ "IsDualTeacherStr", "是否双师型教师" },
  569. { "WorkDateStr", "参加工作年月" }, { "ComeSchoolDateStr", "来校年月" },
  570. { "Speciality", "特长" },{ "WeChatNum", "微信号码" },
  571. { "Profile", "简介" },{ "Remarks", "备注" } ,
  572. { "ErrorMessage", "错误信息" }
  573. };
  574. #endregion
  575. StringBuilder errorMsg = new StringBuilder(); // 错误信息
  576. List<StaffView> errList = new List<StaffView>();
  577. DataTimeHelper dth = new DataTimeHelper();
  578. #region 1.1解析文件,存放到一个List集合里
  579. // 1.1解析文件,存放到一个List集合里
  580. cellheader.Remove("ErrorMessage");//去除异常列、导入操作不需要
  581. List<StaffView> enlist =
  582. NpoiExcelHelper.ExcelToEntityList<StaffView>(cellheader, sourcePhysicalPath, out errorMsg, out errList);
  583. cellheader.Add("ErrorMessage", "错误信息");//还原字典项
  584. #endregion
  585. #region 1.2 将Excel数据写入数据库中
  586. #region 1.2.1 对List集合进行有效性校验
  587. if (enlist.Count() <= 0)
  588. {
  589. throw new Exception("请填写Excel模板信息数据。");
  590. }
  591. #region 1.2.1.1检测必填项是否必填
  592. for (int i = 0; i < enlist.Count; i++)
  593. {
  594. StaffView en = enlist[i];
  595. string errorMsgStr = "第" + (i + 2) + "行数据检测异常:";
  596. bool isHaveNoInputValue = false; // 是否含有未输入项
  597. if (string.IsNullOrEmpty(en.StaffCode))
  598. {
  599. errorMsgStr += "教职工号不能为空;";
  600. en.ErrorMessage = errorMsgStr;
  601. isHaveNoInputValue = true;
  602. }
  603. if (string.IsNullOrEmpty(en.BirthDateStr))
  604. {
  605. errorMsgStr += "出生日期不能为空;";
  606. en.ErrorMessage = errorMsgStr;
  607. isHaveNoInputValue = true;
  608. }
  609. if (string.IsNullOrEmpty(en.Name))
  610. {
  611. errorMsgStr += "姓名不能为空;";
  612. en.ErrorMessage = errorMsgStr;
  613. isHaveNoInputValue = true;
  614. }
  615. if (string.IsNullOrEmpty(en.CollegeName))
  616. {
  617. errorMsgStr += RSL.Get("College") + "不能为空;";
  618. en.ErrorMessage = errorMsgStr;
  619. isHaveNoInputValue = true;
  620. }
  621. if (string.IsNullOrEmpty(en.SexStr))
  622. {
  623. errorMsgStr += "性别不能为空;";
  624. en.ErrorMessage = errorMsgStr;
  625. isHaveNoInputValue = true;
  626. }
  627. if (string.IsNullOrEmpty(en.TeacherTypeStr))
  628. {
  629. errorMsgStr += "教师类型不能为空;";
  630. en.ErrorMessage = errorMsgStr;
  631. isHaveNoInputValue = true;
  632. }
  633. if (string.IsNullOrEmpty(en.IncumbencyStateStr))
  634. {
  635. errorMsgStr += "在职状态不能为空;";
  636. en.ErrorMessage = errorMsgStr;
  637. isHaveNoInputValue = true;
  638. }
  639. DateTime BirthDate;
  640. if (!string.IsNullOrEmpty(en.BirthDateStr))
  641. {
  642. if (!DateTime.TryParse(en.BirthDateStr, out BirthDate))
  643. {
  644. errorMsgStr += "出生日期填写错误;";
  645. en.ErrorMessage = errorMsgStr;
  646. isHaveNoInputValue = true;
  647. }
  648. }
  649. if (!string.IsNullOrEmpty(en.TeachingDateStr))
  650. {
  651. if (!DateTime.TryParse(en.TeachingDateStr, out BirthDate))
  652. {
  653. errorMsgStr += "从教年月填写错误;";
  654. en.ErrorMessage = errorMsgStr;
  655. isHaveNoInputValue = true;
  656. }
  657. }
  658. if (!string.IsNullOrEmpty(en.ComeSchoolDateStr))
  659. {
  660. if (!DateTime.TryParse(en.ComeSchoolDateStr, out BirthDate))
  661. {
  662. errorMsgStr += "来校年月填写错误;";
  663. en.ErrorMessage = errorMsgStr;
  664. isHaveNoInputValue = true;
  665. }
  666. }
  667. if (!string.IsNullOrEmpty(en.WorkDateStr))
  668. {
  669. if(!DateTime.TryParse(en.WorkDateStr,out BirthDate) )
  670. {
  671. errorMsgStr += "参加工作年月填写错误;";
  672. en.ErrorMessage = errorMsgStr;
  673. isHaveNoInputValue = true;
  674. }
  675. }
  676. #region 1.2.1.2 检测(数据唯一性、)
  677. #region 教研室
  678. if (!string.IsNullOrEmpty(en.DepartmentName))
  679. {
  680. if (!DepartmentRepository.Entities.Any(x => x.Name == en.DepartmentName.Trim()))
  681. {
  682. errorMsgStr += "教研室不存在;";
  683. en.ErrorMessage = errorMsgStr;
  684. isHaveNoInputValue = true;
  685. }
  686. }
  687. #endregion
  688. #region 在职状态
  689. if (!string.IsNullOrEmpty(en.IncumbencyStateStr))
  690. {
  691. if (!IdNameExt.GetDictionaryItem(DictionaryItem.CF_IncumbencyState.ToString())
  692. .Any(x => x.Name == en.IncumbencyStateStr.Trim()))
  693. {
  694. errorMsgStr += "在职状态不存在;";
  695. en.ErrorMessage = errorMsgStr;
  696. isHaveNoInputValue = true;
  697. }
  698. }
  699. #endregion
  700. #region 政治面貌 由于教职工表暂时没有政治面貌字段、先行屏蔽
  701. //if (!string.IsNullOrEmpty(en.Politics))
  702. //{
  703. // if (!IdNameExt.GetDictionaryItem(DictionaryItem.CF_Politics.ToString())
  704. // .Any(x => x.Name == en.Politics.Trim()))
  705. // {
  706. // errorMsgStr += "政治面貌不存在;";
  707. // en.ErrorMessage = errorMsgStr;
  708. // isHaveNoInputValue = true;
  709. // }
  710. //}
  711. #endregion
  712. #region 教师类型
  713. if (!string.IsNullOrEmpty(en.TeacherTypeStr))
  714. {
  715. if (!IdNameExt.GetDictionaryItem(DictionaryItem.CF_TeacherType.ToString())
  716. .Any(x => x.Name == en.TeacherTypeStr.Trim()))
  717. {
  718. errorMsgStr += "教师类型不存在;";
  719. en.ErrorMessage = errorMsgStr;
  720. isHaveNoInputValue = true;
  721. }
  722. }
  723. #endregion
  724. #region 性别
  725. if (!string.IsNullOrEmpty(en.SexStr))
  726. {
  727. if (!IdNameExt.GetDictionaryItem(DictionaryItem.CF_Sex.ToString())
  728. .Any(x => x.Name == en.SexStr.Trim()))
  729. {
  730. errorMsgStr += "性别不存在;";
  731. en.ErrorMessage = errorMsgStr;
  732. isHaveNoInputValue = true;
  733. }
  734. }
  735. #endregion
  736. #region 民族
  737. if (!string.IsNullOrEmpty(en.NationStr))
  738. {
  739. if (!IdNameExt.GetDictionaryItem(DictionaryItem.CF_Nation.ToString())
  740. .Any(x => x.Name == en.NationStr.Trim()))
  741. {
  742. errorMsgStr += "民族不存在;";
  743. en.ErrorMessage = errorMsgStr;
  744. isHaveNoInputValue = true;
  745. }
  746. }
  747. #endregion
  748. #region 学历
  749. if (!string.IsNullOrEmpty(en.EducationCodeStr))
  750. {
  751. if (!IdNameExt.GetDictionaryItem(DictionaryItem.CF_EducationCode.ToString())
  752. .Any(x => x.Name == en.EducationCodeStr.Trim()))
  753. {
  754. errorMsgStr += "学历不存在;";
  755. en.ErrorMessage = errorMsgStr;
  756. isHaveNoInputValue = true;
  757. }
  758. }
  759. #endregion
  760. #region 健康状况
  761. if (!string.IsNullOrEmpty(en.HealthStateStr))
  762. {
  763. if (!IdNameExt.GetDictionaryItem(DictionaryItem.CF_HealthState.ToString())
  764. .Any(x => x.Name == en.HealthStateStr.Trim()))
  765. {
  766. errorMsgStr += "健康状况不存在;";
  767. en.ErrorMessage = errorMsgStr;
  768. isHaveNoInputValue = true;
  769. }
  770. }
  771. #endregion
  772. #region 宗教信仰
  773. if (!string.IsNullOrEmpty(en.ReligionStr))
  774. {
  775. if (!IdNameExt.GetDictionaryItem(DictionaryItem.CF_Religion.ToString())
  776. .Any(x => x.Name == en.ReligionStr.Trim()))
  777. {
  778. errorMsgStr += "宗教信仰不存在;";
  779. en.ErrorMessage = errorMsgStr;
  780. isHaveNoInputValue = true;
  781. }
  782. }
  783. #endregion
  784. #region 证件类型
  785. if (!string.IsNullOrEmpty(en.CertificatesTypeStr))
  786. {
  787. if (!IdNameExt.GetDictionaryItem(DictionaryItem.CF_CertificatesType.ToString())
  788. .Any(x => x.Name == en.CertificatesTypeStr.Trim()))
  789. {
  790. errorMsgStr += "证件类型不存在;";
  791. en.ErrorMessage = errorMsgStr;
  792. isHaveNoInputValue = true;
  793. }
  794. }
  795. #endregion
  796. #region 任课状况
  797. if (!string.IsNullOrEmpty(en.SituationStr))
  798. {
  799. if (!IdNameExt.GetDictionaryItem(DictionaryItem.CF_Situation.ToString())
  800. .Any(x => x.Name == en.SituationStr.Trim()))
  801. {
  802. errorMsgStr += "任课类型不存在;";
  803. en.ErrorMessage = errorMsgStr;
  804. isHaveNoInputValue = true;
  805. }
  806. }
  807. #endregion
  808. #region 文化程度
  809. if (!string.IsNullOrEmpty(en.LiteracyLevelsStr))
  810. {
  811. if (!IdNameExt.GetDictionaryItem(DictionaryItem.CF_LiteracyLevels.ToString())
  812. .Any(x => x.Name == en.LiteracyLevelsStr.Trim()))
  813. {
  814. errorMsgStr += "文化程度不存在;";
  815. en.ErrorMessage = errorMsgStr;
  816. isHaveNoInputValue = true;
  817. }
  818. }
  819. #endregion
  820. #region 学位状况
  821. if (!string.IsNullOrEmpty(en.DegreeStateStr))
  822. {
  823. if (!IdNameExt.GetDictionaryItem(DictionaryItem.CF_DegreeState.ToString())
  824. .Any(x => x.Name == en.DegreeStateStr.Trim()))
  825. {
  826. errorMsgStr += "学位状态不存在;";
  827. en.ErrorMessage = errorMsgStr;
  828. isHaveNoInputValue = true;
  829. }
  830. }
  831. #endregion
  832. #region 学位
  833. if (!string.IsNullOrEmpty(en.LearnPositionStr))
  834. {
  835. if (!IdNameExt.GetDictionaryItem(DictionaryItem.CF_LearnPosition.ToString())
  836. .Any(x => x.Name == en.LearnPositionStr.Trim()))
  837. {
  838. errorMsgStr += "学位不存在;";
  839. en.ErrorMessage = errorMsgStr;
  840. isHaveNoInputValue = true;
  841. }
  842. }
  843. #endregion
  844. #region 学历
  845. if (!string.IsNullOrEmpty(en.EducationCodeStr))
  846. {
  847. if (!IdNameExt.GetDictionaryItem(DictionaryItem.CF_EducationCode.ToString())
  848. .Any(x => x.Name == en.EducationCodeStr.Trim()))
  849. {
  850. errorMsgStr += "学历不存在;";
  851. en.ErrorMessage = errorMsgStr;
  852. isHaveNoInputValue = true;
  853. }
  854. }
  855. #endregion
  856. #region 职称
  857. if (!string.IsNullOrEmpty(en.TitleStr))
  858. {
  859. if (!IdNameExt.GetDictionaryItem(DictionaryItem.CF_Title.ToString())
  860. .Any(x => x.Name == en.TitleStr.Trim()))
  861. {
  862. errorMsgStr += "职称不存在;";
  863. en.ErrorMessage = errorMsgStr;
  864. isHaveNoInputValue = true;
  865. }
  866. }
  867. #endregion
  868. #region 课酬级别
  869. if (!string.IsNullOrEmpty(en.PaymentLevelStr))
  870. {
  871. if (!IdNameExt.GetDictionaryItem(DictionaryItem.TP_PaymentLevel.ToString())
  872. .Any(x => x.Name == en.PaymentLevelStr.Trim()))
  873. {
  874. errorMsgStr += "课酬级别不存在;";
  875. en.ErrorMessage = errorMsgStr;
  876. isHaveNoInputValue = true;
  877. }
  878. }
  879. #endregion
  880. #region 院系名称检查
  881. if (!string.IsNullOrEmpty(en.CollegeName))
  882. {
  883. if (CollegeRepository.GetList(x => x.Name == en.CollegeName.Trim()).FirstOrDefault() == null)
  884. {
  885. errorMsgStr += RSL.Get("College") + "填写不正确;";
  886. en.ErrorMessage = errorMsgStr;
  887. isHaveNoInputValue = true;
  888. }
  889. }
  890. #endregion
  891. #region 教职工号检查
  892. if (!string.IsNullOrEmpty(en.StaffCode))
  893. {
  894. if (staffDAL.Value.staffRepository.GetList(x => x.StaffCode == en.StaffCode.Trim()).Count() > 0)
  895. {
  896. errorMsgStr += "教职工号已存在;";
  897. en.ErrorMessage = errorMsgStr;
  898. isHaveNoInputValue = true;
  899. }
  900. }
  901. #endregion
  902. #endregion
  903. if (isHaveNoInputValue) // 若必填项有值未填
  904. {
  905. en.IsExcelVaildateOK = false;
  906. en.ErrorMessage = errorMsgStr;
  907. errList.Add(en);
  908. errorMsg.AppendLine(errorMsgStr);
  909. }
  910. }
  911. #endregion
  912. // TODO:其他检测
  913. #region 1.2.1.3 循环写入验证成功的数据
  914. List<CF_Staff> staffList = new List<CF_Staff>();
  915. List<Sys_User> userList = new List<Sys_User>();
  916. List<CF_StaffProfile> staffProfileList = new List<CF_StaffProfile>();
  917. List<CF_StaffManageCampus> staffManageCampusList = new List<CF_StaffManageCampus>();
  918. List<CF_StaffManageCollege> staffManageCollegeList = new List<CF_StaffManageCollege>();
  919. for (int i = 0; i < enlist.Count; i++)
  920. {
  921. StaffView enA = enlist[i];
  922. if (enA.IsExcelVaildateOK == false) // 上面验证不通过,不进行此步验证
  923. {
  924. continue;
  925. }
  926. //for (int j = i + 1; j < enlist.Count; j++)
  927. //{
  928. // StaffView enB = enlist[j];
  929. // // 判断必填列是否全部重复
  930. // if (enA.StaffCode == enB.StaffCode)
  931. // {
  932. // enA.IsExcelVaildateOK = false;
  933. // enB.IsExcelVaildateOK = false;
  934. // enA.ErrorMessage = "第" + (i + 2) + "行与第" + (j + 2) + "行的必填列重复了";
  935. // errList.Add(enA);
  936. // }
  937. //}
  938. try
  939. {
  940. //先删除旧数据、重新创建新数据
  941. Sys_User sys_user = new Sys_User();
  942. CF_Staff staff = new CF_Staff();
  943. CF_StaffProfile staffProfile = new CF_StaffProfile();
  944. if (enA != null) //有数据开始组装数据
  945. {
  946. sys_user.UserID = Guid.NewGuid();
  947. sys_user.LoginID = enA.StaffCode.Trim();
  948. sys_user.Name = enA.Name;
  949. sys_user.Password = Const.USER_INIT_PASSWORD;
  950. SetNewStatus(sys_user);
  951. userList.Add(sys_user);
  952. // UnitOfWork.Add(sys_user);
  953. staff.UserID = sys_user.UserID;
  954. if (!string.IsNullOrEmpty(enA.DepartmentName))
  955. {
  956. CF_Department department = DepartmentRepository.GetList(x => x.Name == enA.DepartmentName.Trim()).FirstOrDefault();
  957. if (department != null)
  958. {
  959. staff.DepartmentID = department.DepartmentID;
  960. }
  961. }
  962. CF_College college = CollegeRepository.GetList(x => x.Name == enA.CollegeName.Trim()).FirstOrDefault();
  963. staff.CollegeID = college.CollegeID;
  964. staff.StaffCode = enA.StaffCode.Trim();
  965. if (!string.IsNullOrEmpty(enA.BirthDateStr))
  966. {
  967. if (dth.ToDateTimeValue(enA.BirthDateStr) != string.Empty)
  968. staff.BirthDate = Convert.ToDateTime(dth.ToDateTimeValue(enA.BirthDateStr));
  969. else
  970. staff.BirthDate = Convert.ToDateTime(enA.BirthDateStr);
  971. }
  972. if (!string.IsNullOrEmpty(enA.TeachingDateStr))
  973. {
  974. if (dth.ToDateTimeValue(enA.TeachingDateStr) != string.Empty)
  975. staff.TeachingDate = Convert.ToDateTime(dth.ToDateTimeValue(enA.TeachingDateStr));
  976. else
  977. staff.TeachingDate = Convert.ToDateTime(enA.TeachingDateStr);
  978. }
  979. if (!string.IsNullOrEmpty(enA.ComeSchoolDateStr))
  980. {
  981. if (dth.ToDateTimeValue(enA.ComeSchoolDateStr) != string.Empty)
  982. staff.ComeSchoolDate = Convert.ToDateTime(dth.ToDateTimeValue(enA.ComeSchoolDateStr));
  983. else
  984. staff.ComeSchoolDate = Convert.ToDateTime(enA.ComeSchoolDateStr);
  985. }
  986. if (!string.IsNullOrEmpty(enA.WorkDateStr))
  987. {
  988. if (dth.ToDateTimeValue(enA.WorkDateStr) != string.Empty)
  989. staff.WorkDate = Convert.ToDateTime(dth.ToDateTimeValue(enA.WorkDateStr));
  990. else
  991. staff.WorkDate = Convert.ToDateTime(enA.WorkDateStr);
  992. }
  993. if (!string.IsNullOrEmpty(enA.SexStr))
  994. {
  995. staff.Sex = IdNameExt.GetDictionaryItem(DictionaryItem.CF_Sex.ToString())
  996. .Where(x => x.Name == enA.SexStr.Trim()).FirstOrDefault().Value;
  997. }
  998. if (!string.IsNullOrEmpty(enA.TeacherTypeStr))
  999. {
  1000. staff.TeacherType = IdNameExt.GetDictionaryItem(DictionaryItem.CF_TeacherType.ToString())
  1001. .Where(x => x.Name == enA.TeacherTypeStr.Trim()).FirstOrDefault().Value;
  1002. }
  1003. if (!string.IsNullOrEmpty(enA.IncumbencyStateStr))
  1004. {
  1005. staff.IncumbencyState = IdNameExt.GetDictionaryItem(DictionaryItem.CF_IncumbencyState.ToString())
  1006. .Where(x => x.Name == enA.IncumbencyStateStr.Trim()).FirstOrDefault().Value;
  1007. }
  1008. if (!string.IsNullOrEmpty(enA.CertificatesTypeStr))
  1009. {
  1010. staff.CertificatesType = IdNameExt.GetDictionaryItem(DictionaryItem.CF_CertificatesType.ToString())
  1011. .Where(x => x.Name == enA.CertificatesTypeStr.Trim()).FirstOrDefault().Value;
  1012. }
  1013. if (!string.IsNullOrEmpty(enA.LiteracyLevelsStr))
  1014. {
  1015. staff.LiteracyLevels = IdNameExt.GetDictionaryItem(DictionaryItem.CF_LiteracyLevels.ToString())
  1016. .Where(x => x.Name == enA.LiteracyLevelsStr.Trim()).FirstOrDefault().Value;
  1017. }
  1018. if (!string.IsNullOrEmpty(enA.SituationStr))
  1019. {
  1020. staff.Situation = IdNameExt.GetDictionaryItem(DictionaryItem.CF_Situation.ToString())
  1021. .Where(x => x.Name == enA.SituationStr.Trim()).FirstOrDefault().Value;
  1022. }
  1023. if (!string.IsNullOrEmpty(enA.DegreeStateStr))
  1024. {
  1025. staff.DegreeState = IdNameExt.GetDictionaryItem(DictionaryItem.CF_DegreeState.ToString())
  1026. .Where(x => x.Name == enA.DegreeStateStr.Trim()).FirstOrDefault().Value;
  1027. }
  1028. if (!string.IsNullOrEmpty(enA.LearnPositionStr))
  1029. {
  1030. staff.LearnPosition = IdNameExt.GetDictionaryItem(DictionaryItem.CF_LearnPosition.ToString())
  1031. .Where(x => x.Name == enA.LearnPositionStr.Trim()).FirstOrDefault().Value;
  1032. }
  1033. if (!string.IsNullOrEmpty(enA.TitleStr))
  1034. {
  1035. staff.Title = IdNameExt.GetDictionaryItem(DictionaryItem.CF_Title.ToString())
  1036. .Where(x => x.Name == enA.TitleStr.Trim()).FirstOrDefault().Value;
  1037. }
  1038. if (!string.IsNullOrEmpty(enA.PaymentLevelStr))
  1039. {
  1040. staff.PaymentLevelID = IdNameExt.GetDictionaryItem(DictionaryItem.TP_PaymentLevel.ToString())
  1041. .Where(x => x.Name == enA.PaymentLevelStr.Trim()).FirstOrDefault().Value;
  1042. }
  1043. staff.IsDualTeacher = (enA.IsDualTeacherStr.Trim() == "是");
  1044. staff.CertificatesNum = enA.CertificatesNum;
  1045. if (!string.IsNullOrEmpty(enA.PhotoUrl))
  1046. {
  1047. staff.PhotoUrl = enA.PhotoUrl;
  1048. }
  1049. staff.Profile = enA.Profile;
  1050. staff.Remarks = enA.Remarks;
  1051. SetNewStatus(staff);
  1052. staffList.Add(staff);
  1053. // UnitOfWork.Add(staff);
  1054. staffProfile.UserID = sys_user.UserID;
  1055. staffProfile.UsedName = enA.UsedName;
  1056. if (!string.IsNullOrEmpty(enA.NationStr))
  1057. {
  1058. staffProfile.Nation = IdNameExt.GetDictionaryItem(DictionaryItem.CF_Nation.ToString())
  1059. .Where(x => x.Name == enA.NationStr.Trim()).FirstOrDefault().Value;
  1060. }
  1061. // staffProfile.Nation = enA.Nation;
  1062. staffProfile.Place = enA.Place;
  1063. if (!string.IsNullOrEmpty(enA.EducationCodeStr))
  1064. {
  1065. staffProfile.EducationCode = IdNameExt.GetDictionaryItem(DictionaryItem.CF_EducationCode.ToString())
  1066. .Where(x => x.Name == enA.EducationCodeStr.Trim()).FirstOrDefault().Value;
  1067. }
  1068. // staffProfile.EducationCode = enA.EducationCode;
  1069. staffProfile.Telephone = enA.Telephone;
  1070. staffProfile.OfficeTelephone = enA.OfficeTelephone;
  1071. staffProfile.Mobile = enA.Mobile;
  1072. staffProfile.Email = enA.Email;
  1073. staffProfile.QQ = enA.QQ;
  1074. staffProfile.Nationality = enA.Nationality;
  1075. if (!string.IsNullOrEmpty(enA.HealthStateStr))
  1076. {
  1077. staffProfile.HealthState = IdNameExt.GetDictionaryItem(DictionaryItem.CF_HealthState.ToString())
  1078. .Where(x => x.Name == enA.HealthStateStr.Trim()).FirstOrDefault().Value;
  1079. }
  1080. //staffProfile.HealthState = enA.HealthState;
  1081. staffProfile.HousePhone = enA.HousePhone;
  1082. staffProfile.Address = enA.Address;
  1083. staffProfile.Postcode = enA.Postcode;
  1084. staffProfile.HomeAddress = enA.HomeAddress;
  1085. staffProfile.NowAddress = enA.NowAddress;
  1086. staffProfile.Residence = enA.Residence;
  1087. staffProfile.Speciality = enA.Speciality;
  1088. staffProfile.WeChatNum = enA.WeChatNum;
  1089. if (!string.IsNullOrEmpty(enA.ReligionStr))
  1090. {
  1091. staffProfile.Religion = IdNameExt.GetDictionaryItem(DictionaryItem.CF_Religion.ToString())
  1092. .Where(x => x.Name == enA.ReligionStr.Trim()).FirstOrDefault().Value;
  1093. }
  1094. // staffProfile.Religion = enA.Religion;
  1095. // UnitOfWork.Add(staffProfile);
  1096. staffProfileList.Add(staffProfile);
  1097. CF_StaffManageCampus staffManageCampus = new CF_StaffManageCampus();
  1098. staffManageCampus.StaffManageCampusID = Guid.NewGuid();
  1099. staffManageCampus.UserID = sys_user.UserID;
  1100. staffManageCampus.CampusID = college.CampusID;
  1101. this.SetNewStatus(staffManageCampus);
  1102. staffManageCampusList.Add(staffManageCampus);
  1103. // this.UnitOfWork.Add(staffManageCampus);
  1104. CF_StaffManageCollege staffManageCollege = new CF_StaffManageCollege();
  1105. staffManageCollege.StaffManageCollegeID = Guid.NewGuid();
  1106. staffManageCollege.UserID = sys_user.UserID;
  1107. staffManageCollege.CollegeID = staff.CollegeID;
  1108. this.SetNewStatus(staffManageCollege);
  1109. staffManageCollegeList.Add(staffManageCollege);
  1110. // this.UnitOfWork.Add(staffManageCollege);
  1111. }
  1112. }
  1113. catch (Exception)
  1114. {
  1115. throw;
  1116. }
  1117. }
  1118. #endregion
  1119. if (userList.Count() > 0)
  1120. {
  1121. userList.ForEach(w =>
  1122. {
  1123. UnitOfWork.Delete<Sys_User>(x => x.LoginID == w.LoginID);//插入前先删除一次
  1124. });
  1125. }
  1126. #region 教师信息统一写入
  1127. UnitOfWork.BulkInsert(userList);//统一写入
  1128. UnitOfWork.BulkInsert(staffList);//统一写入
  1129. UnitOfWork.BulkInsert(staffProfileList);//统一写入
  1130. UnitOfWork.BulkInsert(staffManageCampusList);//统一写入
  1131. UnitOfWork.BulkInsert(staffManageCollegeList);//统一写入
  1132. #endregion
  1133. #endregion
  1134. #endregion
  1135. #region 1.3 返回各项数据值
  1136. errorWebPath = string.Format("{0}", NpoiExcelHelper.EntityListToExcel2003(cellheader, errList, "教师信息操作失败文件", sourceWebPath));
  1137. successCount = enlist.Distinct().Count() - errList.Distinct().Count();//共条数减去失败条数
  1138. errdataList = errList.Distinct().ToList();
  1139. OkCount = errList.Distinct().Count();
  1140. Errinfo = string.Format("提示:成功导入{0}条记录,失败{1}条,详情请点击错误数据下载查看。", successCount < 1 ? 0 : successCount, OkCount < 1 ? 0 : OkCount);
  1141. #endregion
  1142. }
  1143. /// <summary>
  1144. /// 教师自己信息保存
  1145. /// </summary>
  1146. /// <param name="staffView"></param>
  1147. public void UpdateForSelf(StaffView staffView)
  1148. {
  1149. try
  1150. {
  1151. Sys_User sys_user = new Sys_User();
  1152. CF_Staff staff = new CF_Staff();
  1153. CF_StaffProfile staffProfile = new CF_StaffProfile();
  1154. //CF_Department department = new CF_Department();
  1155. //CF_College college = collegeServices.Value.GetCollegeInfo(staffView.CollegeID);
  1156. //var parameter = ParameterDAL.ParameterRepository.GetSingle(x => x.ParameterTypeID == (int)ViewModel.CF_ParameterType.TeacherInitPassword);
  1157. sys_user = userServices.Value.GetUserByID(staffView.UserID);
  1158. staff = GetStaff(staffView.UserID);
  1159. staffProfile = staff.CF_StaffProfile;
  1160. //sys_user.Name = staffView.Name;
  1161. //sys_user.LoginID = staffView.StaffCode;
  1162. SetModifyStatus(sys_user);
  1163. staff.DepartmentID = staffView.DepartmentID;
  1164. //staff.CollegeID = staffView.CollegeID;
  1165. //staff.StaffCode = staffView.StaffCode;
  1166. //staff.BirthDate = staffView.BirthDate;
  1167. //staff.Sex = staffView.Sex;
  1168. //staff.TeacherType = staffView.TeacherType;
  1169. //staff.IncumbencyState = staffView.IncumbencyState;
  1170. staff.CertificatesType = staffView.CertificatesType;
  1171. staff.CertificatesNum = staffView.CertificatesNum;
  1172. staff.Situation = staffView.Situation;
  1173. staff.LiteracyLevels = staffView.LiteracyLevels;
  1174. staff.DegreeState = staffView.DegreeState;
  1175. staff.LearnPosition = staffView.LearnPosition;
  1176. staff.WorkDate = staffView.WorkDate;
  1177. staff.ComeSchoolDate = staffView.ComeSchoolDate;
  1178. staff.TeachingDate = staffView.TeachingDate;
  1179. staff.Profile = staffView.Profile;
  1180. staff.Remarks = staffView.Remarks;
  1181. SetModifyStatus(staff);
  1182. if (staffProfile == null)
  1183. {
  1184. staffProfile = new CF_StaffProfile();
  1185. UnitOfWork.Add(staffProfile);
  1186. }
  1187. staffProfile.UserID = staff.UserID;
  1188. staffProfile.UsedName = staffView.UsedName;
  1189. staffProfile.Nation = staffView.Nation;
  1190. staffProfile.Place = staffView.Place;
  1191. staffProfile.EducationCode = staffView.EducationCode;
  1192. staffProfile.Telephone = staffView.Telephone;
  1193. staffProfile.OfficeTelephone = staffView.OfficeTelephone;
  1194. staffProfile.Mobile = staffView.Mobile;
  1195. staffProfile.Email = staffView.Email;
  1196. staffProfile.QQ = staffView.QQ;
  1197. staffProfile.Nationality = staffView.Nationality;
  1198. staffProfile.HealthState = staffView.HealthState;
  1199. staffProfile.HousePhone = staffView.HousePhone;
  1200. staffProfile.Address = staffView.Address;
  1201. staffProfile.Postcode = staffView.Postcode;
  1202. staffProfile.HomeAddress = staffView.HomeAddress;
  1203. staffProfile.NowAddress = staffView.NowAddress;
  1204. staffProfile.Residence = staffView.Residence;
  1205. staffProfile.Speciality = staffView.Speciality;
  1206. staffProfile.WeChatNum = staffView.WeChatNum;
  1207. staffProfile.Religion = staffView.Religion;
  1208. staffProfile.Account = staffView.Account;
  1209. UnitOfWork.Commit();
  1210. }
  1211. catch (Exception)
  1212. {
  1213. throw;
  1214. }
  1215. }
  1216. }
  1217. }