DepartmentServices.cs 37 KB

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