CollegeServices.cs 36 KB

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