DepartmentServices.cs 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Linq.Expressions;
  5. using System.Data.Entity;
  6. using System.Text;
  7. using System.Text.RegularExpressions;
  8. using System.Transactions;
  9. using Bowin.Common.Linq;
  10. using Bowin.Common.Linq.Entity;
  11. using Bowin.Common.Utility;
  12. using EMIS.Entities;
  13. using EMIS.Utility;
  14. using EMIS.ViewModel;
  15. using EMIS.ViewModel.UniversityManage.AdministrativeOrgan;
  16. using EMIS.ViewModel.UniversityManage.TeacherManage;
  17. using EMIS.DataLogic.Repositories;
  18. using EMIS.DataLogic.UniversityManage.AdministrativeOrgan;
  19. using EMIS.CommonLogic.UniversityManage.TeacherManage;
  20. namespace EMIS.CommonLogic.UniversityManage.AdministrativeOrgan
  21. {
  22. public class DepartmentServices : BaseServices, IDepartmentServices
  23. {
  24. public DepartmentDAL DepartmentDAL { get; set; }
  25. public Lazy<IStaffServices> StaffServices { get; set; }
  26. public EMIS.DataLogic.Repositories.HRService.OrgInfoRepository OrgInfoRepository { get; set; }
  27. /// <summary>
  28. /// 查询部门信息View
  29. /// </summary>
  30. /// <param name="configuretView"></param>
  31. /// <param name="campusID"></param>
  32. /// <param name="collegeID"></param>
  33. /// <param name="pageIndex"></param>
  34. /// <param name="pageSize"></param>
  35. /// <returns></returns>
  36. public IGridResultSet<DepartmentView> GetDepartmentViewGrid(ConfiguretView configuretView, Guid? campusID, Guid? collegeID, int pageIndex, int pageSize)
  37. {
  38. Expression<Func<CF_Department, bool>> expDepartment = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  39. if (collegeID.HasValue)
  40. {
  41. expDepartment = expDepartment.And(x => x.CollegeID == collegeID);
  42. }
  43. var query = DepartmentDAL.GetDepartmentViewQueryable(expDepartment);
  44. if (campusID.HasValue)
  45. {
  46. query = query.Where(x => x.CampusID == campusID);
  47. }
  48. //查询条件
  49. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  50. {
  51. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  52. }
  53. return this.GetQueryByDataRangeByCollege(query).OrderBy(x => x.CollegeCode.Length).ThenBy(x => x.CollegeCode).ThenBy(x => x.No.Length).ThenBy(x => x.No).ToGridResultSet<DepartmentView>(pageIndex, pageSize);
  54. }
  55. /// <summary>
  56. /// 查询部门信息List
  57. /// </summary>
  58. /// <param name="configuretView"></param>
  59. /// <param name="campusID"></param>
  60. /// <param name="collegeID"></param>
  61. /// <returns></returns>
  62. public IList<DepartmentView> GetDepartmentViewList(ConfiguretView configuretView, Guid? campusID, Guid? collegeID)
  63. {
  64. Expression<Func<CF_Department, bool>> expDepartment = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  65. if (collegeID.HasValue)
  66. {
  67. expDepartment = expDepartment.And(x => x.CollegeID == collegeID);
  68. }
  69. var query = DepartmentDAL.GetDepartmentViewQueryable(expDepartment);
  70. if (campusID.HasValue)
  71. {
  72. query = query.Where(x => x.CampusID == campusID);
  73. }
  74. //查询条件
  75. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  76. {
  77. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  78. }
  79. return this.GetQueryByDataRangeByCollege(query).OrderBy(x => x.CollegeCode.Length).ThenBy(x => x.CollegeCode).ThenBy(x => x.No.Length).ThenBy(x => x.No).ToList();
  80. }
  81. /// <summary>
  82. /// 查询部门信息View(无数据范围)
  83. /// </summary>
  84. /// <param name="configuretView"></param>
  85. /// <param name="campusID"></param>
  86. /// <param name="collegeID"></param>
  87. /// <param name="pageIndex"></param>
  88. /// <param name="pageSize"></param>
  89. /// <returns></returns>
  90. public IGridResultSet<DepartmentView> GetDepartmentViewWithoutRange(ConfiguretView configuretView, Guid? campusID, Guid? collegeID, int pageIndex, int pageSize)
  91. {
  92. Expression<Func<CF_Department, bool>> expDepartment = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  93. if (collegeID.HasValue)
  94. {
  95. expDepartment = expDepartment.And(x => x.CollegeID == collegeID);
  96. }
  97. var query = DepartmentDAL.GetDepartmentViewQueryable(expDepartment);
  98. if (campusID.HasValue)
  99. {
  100. query = query.Where(x => x.CampusID == campusID);
  101. }
  102. //查询条件
  103. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  104. {
  105. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  106. }
  107. return query.OrderBy(x => x.CollegeCode.Length).ThenBy(x => x.CollegeCode).ThenBy(x => x.No.Length).ThenBy(x => x.No).ToGridResultSet<DepartmentView>(pageIndex, pageSize);
  108. }
  109. /// <summary>
  110. /// 根据院系所信息ID查询对应的部门信息CF_Department(带数据范围)
  111. /// </summary>
  112. /// <param name="collegeID"></param>
  113. /// <returns></returns>
  114. public List<CF_Department> GetDepartmentList(Guid? collegeID)
  115. {
  116. Expression<Func<CF_Department, bool>> expDepartment = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  117. var query = DepartmentDAL.DepartmentRepository.GetList(expDepartment);
  118. if (collegeID.HasValue)
  119. {
  120. query = query.Where(x => x.CollegeID == collegeID);
  121. }
  122. return this.GetQueryByDataRangeByCollege(query).OrderBy(x => x.No.Length).ThenBy(x => x.No).ToList();
  123. }
  124. /// <summary>
  125. /// 根据院系所信息ID查询对应的部门信息CF_Department(无数据范围)
  126. /// </summary>
  127. /// <param name="collegeID"></param>
  128. /// <returns></returns>
  129. public List<CF_Department> GetAllDepartmentList(Guid? collegeID)
  130. {
  131. Expression<Func<CF_Department, bool>> expDepartment = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  132. var query = DepartmentDAL.DepartmentRepository.GetList(expDepartment);
  133. if (collegeID.HasValue)
  134. {
  135. query = query.Where(x => x.CollegeID == collegeID);
  136. }
  137. return query.OrderBy(x => x.No.Length).ThenBy(x => x.No).ToList();
  138. }
  139. /// <summary>
  140. /// 查询全部部门信息DepartmentView(带数据范围)
  141. /// </summary>
  142. /// <returns></returns>
  143. public List<DepartmentView> GetDepartmentList()
  144. {
  145. Expression<Func<CF_Department, bool>> expDepartment = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  146. var query = DepartmentDAL.GetDepartmentViewQueryable(expDepartment);
  147. return this.GetQueryByDataRangeByCollege(query).OrderBy(x => x.No.Length).ThenBy(x => x.No).ToList();
  148. }
  149. /// <summary>
  150. /// 查询全部部门信息DepartmentView(无数据范围)
  151. /// </summary>
  152. /// <returns></returns>
  153. public List<DepartmentView> GetDepartmentViewListWithoutDataRange()
  154. {
  155. Expression<Func<CF_Department, bool>> expDepartment = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  156. var query = DepartmentDAL.GetDepartmentViewQueryable(expDepartment);
  157. return query.OrderBy(x => x.No.Length).ThenBy(x => x.No).ToList();
  158. }
  159. /// <summary>
  160. /// 查询对应的部门信息CF_Department
  161. /// </summary>
  162. /// <param name="departmentID"></param>
  163. /// <returns></returns>
  164. public CF_Department GetDepartmentInfo(Guid? departmentID)
  165. {
  166. try
  167. {
  168. var query = DepartmentDAL.DepartmentRepository.GetList(x => x.DepartmentID == departmentID).SingleOrDefault();
  169. return query;
  170. }
  171. catch (Exception ex)
  172. {
  173. throw new Exception(ex.Message);
  174. }
  175. }
  176. /// <summary>
  177. /// 查询对应的部门信息DepartmentView
  178. /// </summary>
  179. /// <param name="departmentID"></param>
  180. /// <returns></returns>
  181. public DepartmentView GetDepartmentView(Guid? departmentID)
  182. {
  183. try
  184. {
  185. var query = DepartmentDAL.GetDepartmentViewQueryable(x => x.DepartmentID == departmentID).SingleOrDefault();
  186. return query;
  187. }
  188. catch (Exception ex)
  189. {
  190. throw new Exception(ex.Message);
  191. }
  192. }
  193. /// <summary>
  194. /// 编辑(新增、修改,业务主键:部门代码或部门名称)
  195. /// </summary>
  196. /// <param name="departmentView"></param>
  197. public void DepartmentEdit(DepartmentView departmentView)
  198. {
  199. try
  200. {
  201. //查询数据库进行验证
  202. var departmentVerify = DepartmentDAL.DepartmentRepository.GetList(x => x.DepartmentID != departmentView.DepartmentID && (x.No == departmentView.No || x.Name == departmentView.Name)).FirstOrDefault();
  203. if (departmentVerify == null)
  204. {
  205. //数据有误验证
  206. if (departmentView.DepartmentID != Guid.Empty)
  207. {
  208. var department = DepartmentDAL.DepartmentRepository.GetList(x => x.DepartmentID == departmentView.DepartmentID, x => x.CF_DepartmentProfile).SingleOrDefault();
  209. if (department == null)
  210. {
  211. throw new Exception("数据有误,请核查。");
  212. }
  213. else
  214. {
  215. //表示修改
  216. department.CollegeID = departmentView.CollegeID;
  217. department.No = departmentView.No;
  218. department.Name = departmentView.Name;
  219. department.SimpleName = departmentView.SimpleName;
  220. department.EnglishName = departmentView.EnglishName;
  221. department.Remark = departmentView.Remark;
  222. SetModifyStatus(department);
  223. //部门信息扩展表
  224. if (department.CF_DepartmentProfile == null)
  225. {
  226. //新增
  227. var newDepartmentProfile = new CF_DepartmentProfile();
  228. newDepartmentProfile.DepartmentID = department.DepartmentID;
  229. newDepartmentProfile.DirectorID = departmentView.DirectorID;
  230. newDepartmentProfile.DeputyDirectorID = departmentView.DeputyDirectorID;
  231. newDepartmentProfile.FoundDate = departmentView.FoundDate;
  232. SetNewStatus(newDepartmentProfile);
  233. UnitOfWork.Add(newDepartmentProfile);
  234. }
  235. else
  236. {
  237. //修改
  238. department.CF_DepartmentProfile.DirectorID = departmentView.DirectorID;
  239. department.CF_DepartmentProfile.DeputyDirectorID = departmentView.DeputyDirectorID;
  240. department.CF_DepartmentProfile.FoundDate = departmentView.FoundDate;
  241. SetModifyStatus(department.CF_DepartmentProfile);
  242. }
  243. }
  244. }
  245. else
  246. {
  247. //表示新增(CF_Department主表)
  248. CF_Department department = new CF_Department();
  249. department.DepartmentID = Guid.NewGuid();
  250. department.CollegeID = departmentView.CollegeID;
  251. department.No = departmentView.No;
  252. department.Name = departmentView.Name;
  253. department.SimpleName = departmentView.SimpleName;
  254. department.EnglishName = departmentView.EnglishName;
  255. department.Remark = departmentView.Remark;
  256. SetNewStatus(department);
  257. UnitOfWork.Add(department);
  258. //表示新增(CF_DepartmentProfile扩展表)
  259. CF_DepartmentProfile departmentProfile = new CF_DepartmentProfile();
  260. departmentProfile.DepartmentID = department.DepartmentID;
  261. departmentProfile.DirectorID = departmentView.DirectorID;
  262. departmentProfile.DeputyDirectorID = departmentView.DeputyDirectorID;
  263. departmentProfile.FoundDate = departmentView.FoundDate;
  264. SetNewStatus(departmentProfile);
  265. UnitOfWork.Add(departmentProfile);
  266. }
  267. }
  268. else
  269. {
  270. throw new Exception("已存在相同的教研室代码或教研室名称,请核查。");
  271. }
  272. //事务提交
  273. UnitOfWork.Commit();
  274. }
  275. catch (Exception ex)
  276. {
  277. throw new Exception(ex.Message);
  278. }
  279. }
  280. /// <summary>
  281. /// 删除
  282. /// </summary>
  283. /// <param name="departmentIDList"></param>
  284. /// <returns></returns>
  285. public bool DepartmentDelete(List<Guid?> departmentIDList)
  286. {
  287. try
  288. {
  289. UnitOfWork.Remove<CF_DepartmentProfile>(x => departmentIDList.Contains(x.DepartmentID));
  290. UnitOfWork.Remove<CF_Department>(x => departmentIDList.Contains(x.DepartmentID));
  291. UnitOfWork.Commit();
  292. return true;
  293. }
  294. catch (Exception)
  295. {
  296. throw;
  297. }
  298. }
  299. /// <summary>
  300. /// 期末、补考设定教研室查询
  301. /// </summary>
  302. /// <param name="ClassmajorID"></param>
  303. /// <param name="CoursematerialID"></param>
  304. /// <returns></returns>
  305. public string GetDepartmentListForExamination(Guid? ClassmajorID, Guid? CoursematerialID)
  306. {
  307. //var ID = "";
  308. var query = DepartmentDAL.GetDepartmentViewQueryable(x => true);
  309. //if (ClassmajorID != null && ClassmajorID != Guid.Empty && CoursematerialID != null && CoursematerialID != Guid.Empty)
  310. //{
  311. // var StandardID = ClassmajorDAL.GetClassmajorViewQueryable(x => x.ClassmajorID == ClassmajorID, x => true).Select(w => w.StandardID).FirstOrDefault();
  312. // var departmentID = SpecialtyCourseDAL.GetSpecialtyCourseViewQueryable(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE
  313. // && x.CoursematerialID == CoursematerialID && x.CF_Specialty.StandardID == StandardID).Select(w => w.DepartmentID).FirstOrDefault();
  314. // if (departmentID.HasValue)
  315. // {
  316. // ID = departmentID.ToString();
  317. // }
  318. //}
  319. return query.FirstOrDefault().DepartmentID.ToString();
  320. }
  321. /// <summary>
  322. /// HRService工作流平台
  323. /// </summary>
  324. public void SynHRServices()
  325. {
  326. var hrOrgInfos = OrgInfoRepository.Entities.ToList();
  327. var universityList = DepartmentDAL.UniversityRepository.Entities.Include(x => x.CF_UniversityProfile).ToList();
  328. var campusList = DepartmentDAL.CampusRepository.Entities.Include(x => x.CF_CampusProfile).ToList();
  329. var collegeList = DepartmentDAL.CollegeRepository.Entities.Include(x => x.CF_CollegeProfile).ToList();
  330. var departmentList = DepartmentDAL.DepartmentRepository.Entities.Include(x => x.CF_DepartmentProfile).ToList();
  331. hrOrgInfos.ForEach(x => x.status = "D");
  332. foreach (var university in universityList)
  333. {
  334. var hrOrgInfo = hrOrgInfos.FirstOrDefault(x => x.dpid == university.UniversityID.ToString());
  335. if (hrOrgInfo == null)
  336. {
  337. hrOrgInfo = new Entities.HRServices.Comm_OrgInfo();
  338. hrOrgInfo.dpid = university.UniversityID.ToString();
  339. hrOrgInfo.createdt = DateTime.Now;
  340. this.HRUnitOfWork.Add(hrOrgInfo);
  341. }
  342. hrOrgInfo.parentdpid = null;
  343. hrOrgInfo.dpcode = university.UniversityID.ToString();
  344. hrOrgInfo.dplv = 1;
  345. hrOrgInfo.dpname = university.Name;
  346. hrOrgInfo.dpfullname = university.Name;
  347. hrOrgInfo.status = "A";
  348. hrOrgInfo.orderNo = university.Code;
  349. hrOrgInfo.isTmpDP = "N";
  350. hrOrgInfo.updatedt = DateTime.Now;
  351. hrOrgInfo.OrderNum = "9999";
  352. }
  353. foreach (var campus in campusList)
  354. {
  355. var hrOrgInfo = hrOrgInfos.FirstOrDefault(x => x.dpid == campus.CampusID.ToString());
  356. if (hrOrgInfo == null)
  357. {
  358. hrOrgInfo = new Entities.HRServices.Comm_OrgInfo();
  359. hrOrgInfo.dpid = campus.CampusID.ToString();
  360. hrOrgInfo.createdt = DateTime.Now;
  361. this.HRUnitOfWork.Add(hrOrgInfo);
  362. }
  363. hrOrgInfo.parentdpid = campus.UniversityID.ToString();
  364. hrOrgInfo.dpcode = campus.CampusID.ToString();
  365. hrOrgInfo.dplv = 1;
  366. hrOrgInfo.dpname = campus.Name;
  367. hrOrgInfo.dpfullname = campus.Name;
  368. hrOrgInfo.status = "A";
  369. hrOrgInfo.orderNo = campus.No;
  370. hrOrgInfo.isTmpDP = "N";
  371. hrOrgInfo.updatedt = DateTime.Now;
  372. hrOrgInfo.OrderNum = "9999";
  373. }
  374. foreach (var college in collegeList)
  375. {
  376. var hrOrgInfo = hrOrgInfos.FirstOrDefault(x => x.dpid == college.CollegeID.ToString());
  377. if (hrOrgInfo == null)
  378. {
  379. hrOrgInfo = new Entities.HRServices.Comm_OrgInfo();
  380. hrOrgInfo.dpid = college.CollegeID.ToString();
  381. hrOrgInfo.createdt = DateTime.Now;
  382. this.HRUnitOfWork.Add(hrOrgInfo);
  383. }
  384. hrOrgInfo.parentdpid = college.CampusID.ToString();
  385. hrOrgInfo.dpcode = college.CollegeID.ToString();
  386. hrOrgInfo.dplv = 1;
  387. hrOrgInfo.dpname = college.Name;
  388. hrOrgInfo.dpfullname = college.Name;
  389. hrOrgInfo.status = "A";
  390. hrOrgInfo.orderNo = college.No;
  391. hrOrgInfo.isTmpDP = "N";
  392. hrOrgInfo.updatedt = DateTime.Now;
  393. hrOrgInfo.OrderNum = "9999";
  394. }
  395. foreach (var department in departmentList)
  396. {
  397. var hrOrgInfo = hrOrgInfos.FirstOrDefault(x => x.dpid == department.DepartmentID.ToString());
  398. if (hrOrgInfo == null)
  399. {
  400. hrOrgInfo = new Entities.HRServices.Comm_OrgInfo();
  401. hrOrgInfo.dpid = department.DepartmentID.ToString();
  402. hrOrgInfo.createdt = DateTime.Now;
  403. this.HRUnitOfWork.Add(hrOrgInfo);
  404. }
  405. hrOrgInfo.parentdpid = department.CollegeID.ToString();
  406. hrOrgInfo.dpcode = department.DepartmentID.ToString();
  407. hrOrgInfo.dplv = 1;
  408. hrOrgInfo.dpname = department.Name;
  409. hrOrgInfo.dpfullname = department.Name;
  410. hrOrgInfo.status = "A";
  411. hrOrgInfo.orderNo = department.No;
  412. hrOrgInfo.isTmpDP = "N";
  413. hrOrgInfo.updatedt = DateTime.Now;
  414. hrOrgInfo.OrderNum = "9999";
  415. }
  416. this.HRUnitOfWork.Commit();
  417. }
  418. /// <summary>
  419. /// 查询教研室对应的教师信息StaffView
  420. /// </summary>
  421. /// <param name="configuretView"></param>
  422. /// <param name="collegeID"></param>
  423. /// <param name="departmentID"></param>
  424. /// <param name="isPhoto"></param>
  425. /// <param name="teacherTypeID"></param>
  426. /// <param name="incumbencyState"></param>
  427. /// <param name="titleID"></param>
  428. /// <param name="isDualTeacher"></param>
  429. /// <param name="pageIndex"></param>
  430. /// <param name="pageSize"></param>
  431. /// <returns></returns>
  432. public IGridResultSet<StaffView> GetStaffListViewGrid(ConfiguretView configuretView, Guid? collegeID, Guid? departmentID, int? isPhoto, int? teacherTypeID,
  433. int? incumbencyState, int? titleID, int? isDualTeacher, int pageIndex, int pageSize)
  434. {
  435. Expression<Func<CF_Department, bool>> expDepartment = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  436. expDepartment = expDepartment.And(x => x.DepartmentID == departmentID);
  437. var query = DepartmentDAL.GetStaffViewQueryable(expDepartment);
  438. if (collegeID.HasValue)
  439. {
  440. query = query.Where(x => x.CollegeID == collegeID);
  441. }
  442. if (isPhoto.HasValue)
  443. {
  444. if (isPhoto.Value == (int)CF_GeneralExist.Have)
  445. {
  446. query = query.Where(x => x.PhotoUrl != null && x.PhotoUrl != "");
  447. }
  448. if (isPhoto.Value == (int)CF_GeneralExist.No)
  449. {
  450. query = query.Where(x => x.PhotoUrl == null || x.PhotoUrl == "");
  451. }
  452. }
  453. if (teacherTypeID.HasValue)
  454. {
  455. query = query.Where(x => x.TeacherTypeID == teacherTypeID);
  456. }
  457. if (incumbencyState.HasValue)
  458. {
  459. query = query.Where(x => x.IncumbencyState == incumbencyState);
  460. }
  461. if (titleID.HasValue)
  462. {
  463. query = query.Where(x => x.TitleID == titleID);
  464. }
  465. if (isDualTeacher.HasValue)
  466. {
  467. if (isDualTeacher.Value == (int)CF_GeneralPurpose.IsYes)
  468. {
  469. query = query.Where(x => x.IsDualTeacher == true);
  470. }
  471. if (isDualTeacher.Value == (int)CF_GeneralPurpose.IsNo)
  472. {
  473. query = query.Where(x => x.IsDualTeacher != true);
  474. }
  475. }
  476. //查询条件
  477. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  478. {
  479. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  480. }
  481. return query.OrderBy(x => x.StaffCode.Length).ThenBy(x => x.StaffCode).ThenBy(x => x.CollegeNo.Length).ThenBy(x => x.CollegeNo).ToGridResultSet<StaffView>(pageIndex, pageSize);
  482. }
  483. /// <summary>
  484. /// 查询教研室对应的教师信息List
  485. /// </summary>
  486. /// <param name="configuretView"></param>
  487. /// <param name="collegeID"></param>
  488. /// <param name="departmentID"></param>
  489. /// <param name="isPhoto"></param>
  490. /// <param name="teacherTypeID"></param>
  491. /// <param name="incumbencyState"></param>
  492. /// <param name="titleID"></param>
  493. /// <param name="isDualTeacher"></param>
  494. /// <returns></returns>
  495. public IList<StaffView> GetStaffListViewList(ConfiguretView configuretView, Guid? collegeID, Guid? departmentID, int? isPhoto, int? teacherTypeID,
  496. int? incumbencyState, int? titleID, int? isDualTeacher)
  497. {
  498. Expression<Func<CF_Department, bool>> expDepartment = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  499. expDepartment = expDepartment.And(x => x.DepartmentID == departmentID);
  500. var query = DepartmentDAL.GetStaffViewQueryable(expDepartment);
  501. if (collegeID.HasValue)
  502. {
  503. query = query.Where(x => x.CollegeID == collegeID);
  504. }
  505. if (isPhoto.HasValue)
  506. {
  507. if (isPhoto.Value == (int)CF_GeneralExist.Have)
  508. {
  509. query = query.Where(x => x.PhotoUrl != null && x.PhotoUrl != "");
  510. }
  511. if (isPhoto.Value == (int)CF_GeneralExist.No)
  512. {
  513. query = query.Where(x => x.PhotoUrl == null || x.PhotoUrl == "");
  514. }
  515. }
  516. if (teacherTypeID.HasValue)
  517. {
  518. query = query.Where(x => x.TeacherTypeID == teacherTypeID);
  519. }
  520. if (incumbencyState.HasValue)
  521. {
  522. query = query.Where(x => x.IncumbencyState == incumbencyState);
  523. }
  524. if (titleID.HasValue)
  525. {
  526. query = query.Where(x => x.TitleID == titleID);
  527. }
  528. if (isDualTeacher.HasValue)
  529. {
  530. if (isDualTeacher.Value == (int)CF_GeneralPurpose.IsYes)
  531. {
  532. query = query.Where(x => x.IsDualTeacher == true);
  533. }
  534. if (isDualTeacher.Value == (int)CF_GeneralPurpose.IsNo)
  535. {
  536. query = query.Where(x => x.IsDualTeacher != true);
  537. }
  538. }
  539. //查询条件
  540. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  541. {
  542. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  543. }
  544. return query.OrderBy(x => x.StaffCode.Length).ThenBy(x => x.StaffCode).ThenBy(x => x.CollegeNo.Length).ThenBy(x => x.CollegeNo).ToList();
  545. }
  546. /// <summary>
  547. /// 部门信息Excel导入
  548. /// </summary>
  549. /// <param name="cellheader"></param>
  550. /// <param name="inCount"></param>
  551. /// <param name="upCount"></param>
  552. /// <param name="errdataList"></param>
  553. /// <param name="errCount"></param>
  554. /// <param name="sourcePhysicalPath"></param>
  555. public void DepartmentImport(Dictionary<string, string> cellheader, out int? inCount, out int? upCount, out List<DepartmentView> errdataList, out int? errCount, string sourcePhysicalPath)
  556. {
  557. try
  558. {
  559. StringBuilder errorMsg = new StringBuilder();
  560. List<DepartmentView> errList = new List<DepartmentView>();
  561. cellheader.Remove("ErrorMessage");
  562. List<DepartmentView> enlist = NpoiExcelHelper.ExcelToEntityList<DepartmentView>(cellheader, sourcePhysicalPath, out errorMsg, out errList);
  563. cellheader.Add("ErrorMessage", "未导入原因");
  564. //对List集合进行有效性校验
  565. if (enlist.Count() <= 0)
  566. {
  567. throw new Exception("Excel文件数据为空,请检查。");
  568. }
  569. Regex reg = null; //正则表达式
  570. DateTime result; //用于返回判断日期字段格式
  571. inCount = 0; //导入个数
  572. upCount = 0; //更新个数
  573. errCount = 0; //失败个数
  574. string errorMsgStr = ""; //错误信息
  575. List<CF_Department> newDepartmentInList = new List<CF_Department>();
  576. List<CF_DepartmentProfile> newDepartmentProfileInList = new List<CF_DepartmentProfile>();
  577. List<CF_Department> newDepartmentUpList = new List<CF_Department>();
  578. List<CF_DepartmentProfile> newDepartmentProfileUpList = new List<CF_DepartmentProfile>();
  579. //将循环中相关数据库查询统一查询出来进行匹配(尽量避免在循环中进行数据库查询)
  580. //部门信息
  581. var departmentList = DepartmentDAL.DepartmentRepository.GetList(x => true, x => x.CF_DepartmentProfile).ToList();
  582. //部门代码
  583. var departmentNoList = enlist.Where(x => !string.IsNullOrEmpty(x.No)).Select(x => x.No).ToList();
  584. //部门名称
  585. var departmentNameList = enlist.Where(x => !string.IsNullOrEmpty(x.Name)).Select(x => x.Name).ToList();
  586. //对比后的newDepartmentList
  587. var newDepartmentList = departmentList.Where(x => departmentNoList.Contains(x.No) || departmentNameList.Contains(x.Name)).ToList();
  588. //院系所信息
  589. var collegeList = DepartmentDAL.CollegeRepository.GetList(x => true).ToList();
  590. //院系所代码
  591. var collegeNoList = enlist.Where(x => !string.IsNullOrEmpty(x.CollegeCode)).Select(x => x.CollegeCode).ToList();
  592. //对比后的newCollegeList
  593. var newCollegeList = collegeList.Where(x => collegeNoList.Contains(x.No)).ToList();
  594. //教职工信息
  595. var staffViewList = StaffServices.Value.GetListStaffView();
  596. //教职工姓名(暂时不考虑,教职工号不同,姓名相同的情况)
  597. var staffNamePList = enlist.Where(x => !string.IsNullOrEmpty(x.DirectorName)).Select(x => x.DirectorName).ToList();
  598. var staffNameAList = enlist.Where(x => !string.IsNullOrEmpty(x.DeputyDirectorName)).Select(x => x.DeputyDirectorName).ToList();
  599. //对比后的newStaffViewList
  600. var newStaffViewList = staffViewList.Where(x => staffNamePList.Contains(x.Name) || staffNameAList.Contains(x.Name)).ToList();
  601. //循环检测数据列,对各数据列进行验证(必填、字典项验证、数据格式等)
  602. for (int i = 0; i < enlist.Count; i++)
  603. {
  604. DepartmentView en = enlist[i]; //Excel表数据视图
  605. CF_Department newDepartment = new CF_Department();
  606. CF_DepartmentProfile newDepartmentProfile = new CF_DepartmentProfile();
  607. //部门代码
  608. if (string.IsNullOrEmpty(en.No))
  609. {
  610. errCount++;
  611. errorMsgStr = "教研室代码不能为空";
  612. en.ErrorMessage = errorMsgStr;
  613. errList.Add(en);
  614. errorMsg.AppendLine(errorMsgStr);
  615. continue;
  616. }
  617. else
  618. {
  619. reg = new Regex(@"^[0-9a-zA-Z\s?]+$"); //正则表达式(请输入数字或英文字母)
  620. if (!reg.IsMatch(en.No))
  621. {
  622. errCount++;
  623. errorMsgStr = "教研室代码格式不正确,请检查(数字或英文字母)";
  624. en.ErrorMessage = errorMsgStr;
  625. errList.Add(en);
  626. errorMsg.AppendLine(errorMsgStr);
  627. continue;
  628. }
  629. else
  630. {
  631. //教研室代码
  632. newDepartment.No = en.No.Trim();
  633. }
  634. }
  635. //教研室名称
  636. if (string.IsNullOrEmpty(en.Name))
  637. {
  638. errCount++;
  639. errorMsgStr = "教研室名称不能为空";
  640. en.ErrorMessage = errorMsgStr;
  641. errList.Add(en);
  642. errorMsg.AppendLine(errorMsgStr);
  643. continue;
  644. }
  645. else
  646. {
  647. //教研室名称
  648. newDepartment.Name = en.Name.Trim();
  649. }
  650. //简称
  651. if (string.IsNullOrEmpty(en.SimpleName))
  652. {
  653. //不考虑
  654. }
  655. else
  656. {
  657. newDepartment.SimpleName = en.SimpleName;
  658. }
  659. //英文名称
  660. if (string.IsNullOrEmpty(en.EnglishName))
  661. {
  662. //不考虑
  663. }
  664. else
  665. {
  666. newDepartment.EnglishName = en.EnglishName;
  667. }
  668. //院系所代码
  669. if (string.IsNullOrEmpty(en.CollegeCode))
  670. {
  671. errCount++;
  672. errorMsgStr = RSL.Get("CollegeCode") + "不能为空";
  673. en.ErrorMessage = errorMsgStr;
  674. errList.Add(en);
  675. errorMsg.AppendLine(errorMsgStr);
  676. continue;
  677. }
  678. else
  679. {
  680. reg = new Regex(@"^[0-9a-zA-Z\s?]+$"); //正则表达式(请输入数字或英文字母)
  681. if (!reg.IsMatch(en.CollegeCode))
  682. {
  683. errCount++;
  684. errorMsgStr = RSL.Get("CollegeCode") + "格式不正确,请检查(数字或英文字母)";
  685. en.ErrorMessage = errorMsgStr;
  686. errList.Add(en);
  687. errorMsg.AppendLine(errorMsgStr);
  688. continue;
  689. }
  690. else
  691. {
  692. var college = newCollegeList.Where(x => x.No == en.CollegeCode.Trim()).SingleOrDefault();
  693. if (college == null)
  694. {
  695. errCount++;
  696. errorMsgStr = RSL.Get("CollegeCode") + "不存在,请检查";
  697. en.ErrorMessage = errorMsgStr;
  698. errList.Add(en);
  699. errorMsg.AppendLine(errorMsgStr);
  700. continue;
  701. }
  702. else
  703. {
  704. //院系所信息ID
  705. newDepartment.CollegeID = college.CollegeID;
  706. }
  707. }
  708. }
  709. //主任姓名
  710. if (string.IsNullOrEmpty(en.DirectorName))
  711. {
  712. //不考虑
  713. }
  714. else
  715. {
  716. var staffViewByP = newStaffViewList.Where(x => x.Name == en.DirectorName.Trim()).FirstOrDefault();
  717. if (staffViewByP == null)
  718. {
  719. ////暂不考虑
  720. //errCount++;
  721. //errorMsgStr = "主任姓名不存在,请检查";
  722. //en.ErrorMessage = errorMsgStr;
  723. //errList.Add(en);
  724. //errorMsg.AppendLine(errorMsgStr);
  725. //continue;
  726. }
  727. else
  728. {
  729. //主任姓名
  730. newDepartmentProfile.DirectorID = staffViewByP.UserID;
  731. }
  732. }
  733. //副主任姓名
  734. if (string.IsNullOrEmpty(en.DeputyDirectorName))
  735. {
  736. //不考虑
  737. }
  738. else
  739. {
  740. var staffViewByA = newStaffViewList.Where(x => x.Name == en.DeputyDirectorName.Trim()).FirstOrDefault();
  741. if (staffViewByA == null)
  742. {
  743. ////暂不考虑
  744. //errCount++;
  745. //errorMsgStr = "副主任姓名不存在,请检查";
  746. //en.ErrorMessage = errorMsgStr;
  747. //errList.Add(en);
  748. //errorMsg.AppendLine(errorMsgStr);
  749. //continue;
  750. }
  751. else
  752. {
  753. //副主任姓名
  754. newDepartmentProfile.DeputyDirectorID = staffViewByA.UserID;
  755. }
  756. }
  757. //创建年月
  758. if (string.IsNullOrEmpty(en.FoundDateStr))
  759. {
  760. //不考虑
  761. }
  762. else
  763. {
  764. //reg = new Regex(@"(\d{4})-(\d{1,2})-(\d{1,2})"); //日期正则表达式,2017-12-28
  765. if (!DateTime.TryParse(en.FoundDateStr, out result))
  766. {
  767. errCount++;
  768. errorMsgStr = "创建年月格式不正确,请检查";
  769. en.ErrorMessage = errorMsgStr;
  770. errList.Add(en);
  771. errorMsg.AppendLine(errorMsgStr);
  772. continue;
  773. }
  774. else
  775. {
  776. //创建年月
  777. newDepartmentProfile.FoundDate = Convert.ToDateTime(en.FoundDateStr);
  778. }
  779. }
  780. //备注
  781. if (string.IsNullOrEmpty(en.Remark))
  782. {
  783. //不考虑
  784. }
  785. else
  786. {
  787. newDepartment.Remark = en.Remark;
  788. }
  789. ////Excel表重复性验证(注:当数据表中没有此记录,但是Excel中有重复数据时的去掉)
  790. //for (int j = i + 1; j < enlist.Count; j++)
  791. //{
  792. // NewDepartmentView enA = enlist[j];
  793. // //根据Excel表中的业务主键进行去重(部门代码或部门名称唯一)
  794. // if (en.No == enA.No && en.Name == enA.Name)
  795. // {
  796. // //用于标识Excel表中的重复记录(由于是批量进行插入数据表)
  797. // }
  798. //}
  799. //数据表重复性验证(部门代码或部门名称唯一)
  800. var departmentVerify = newDepartmentList.Where(x => x.No == newDepartment.No || x.Name == newDepartment.Name).FirstOrDefault();
  801. if (departmentVerify == null)
  802. {
  803. //新增
  804. if (!newDepartmentInList.Any(x => x.No == newDepartment.No || x.Name == newDepartment.Name))
  805. {
  806. //CF_Department主表
  807. newDepartment.DepartmentID = Guid.NewGuid();
  808. SetNewStatus(newDepartment);
  809. newDepartmentInList.Add(newDepartment);
  810. //CF_DepartmentProfile扩展表
  811. newDepartmentProfile.DepartmentID = newDepartment.DepartmentID;
  812. SetNewStatus(newDepartmentProfile);
  813. newDepartmentProfileInList.Add(newDepartmentProfile);
  814. inCount++;
  815. }
  816. else
  817. {
  818. //Excel表重复性验证
  819. //(注:当数据表中没有此记录,但是Excel中有重复数据,可在此处进行抛出到失败数据文件中,目前暂不考虑)
  820. inCount++;
  821. }
  822. }
  823. else
  824. {
  825. //更新(Excel有重复时,以最后一条记录的更新为准)
  826. //更新CF_Department主表
  827. departmentVerify.SimpleName = newDepartment.SimpleName;
  828. departmentVerify.EnglishName = newDepartment.EnglishName;
  829. departmentVerify.Remark = newDepartment.Remark;
  830. SetModifyStatus(departmentVerify);
  831. newDepartmentUpList.Add(departmentVerify);
  832. //CF_DepartmentProfile扩展表
  833. if (departmentVerify.CF_DepartmentProfile == null)
  834. {
  835. newDepartmentProfile.DepartmentID = departmentVerify.DepartmentID;
  836. SetNewStatus(newDepartmentProfile);
  837. newDepartmentProfileInList.Add(newDepartmentProfile);
  838. }
  839. else
  840. {
  841. //更新CF_DepartmentProfile扩展表
  842. departmentVerify.CF_DepartmentProfile.DirectorID = newDepartmentProfile.DirectorID;
  843. departmentVerify.CF_DepartmentProfile.DeputyDirectorID = newDepartmentProfile.DeputyDirectorID;
  844. departmentVerify.CF_DepartmentProfile.FoundDate = newDepartmentProfile.FoundDate;
  845. SetModifyStatus(departmentVerify.CF_DepartmentProfile);
  846. newDepartmentProfileUpList.Add(departmentVerify.CF_DepartmentProfile);
  847. }
  848. upCount++;
  849. }
  850. }
  851. using (TransactionScope ts = new TransactionScope())
  852. {
  853. UnitOfWork.BulkInsert(newDepartmentInList);
  854. UnitOfWork.BulkInsert(newDepartmentProfileInList);
  855. //批量统一提交更新
  856. if (newDepartmentUpList != null && newDepartmentUpList.Count() > 0)
  857. {
  858. UnitOfWork.BatchUpdate(newDepartmentUpList);
  859. }
  860. //批量统一提交更新
  861. if (newDepartmentProfileUpList != null && newDepartmentProfileUpList.Count() > 0)
  862. {
  863. UnitOfWork.BatchUpdate(newDepartmentProfileUpList);
  864. }
  865. ts.Complete();
  866. }
  867. errdataList = errList.Distinct().ToList(); //错误列表List
  868. }
  869. catch (Exception)
  870. {
  871. throw;
  872. }
  873. }
  874. }
  875. }