SpecialtyClassSettingServices.cs 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Linq.Expressions;
  5. using System.Text;
  6. using Bowin.Common.Utility;
  7. using Bowin.Common.Linq;
  8. using Bowin.Common.Linq.Entity;
  9. using EMIS.Entities;
  10. using EMIS.ViewModel;
  11. using EMIS.ViewModel.EnrollManage.SpecialtyManage;
  12. using EMIS.DataLogic.EnrollManage.SpecialtyManage;
  13. namespace EMIS.CommonLogic.EnrollManage.SpecialtyManage
  14. {
  15. public class SpecialtyClassSettingServices : BaseServices, ISpecialtyClassSettingServices
  16. {
  17. public SpecialtyClassSettingDAL SpecialtyClassSettingDAL { get; set; }
  18. /// <summary>
  19. /// 查询对应的专业分班信息View
  20. /// </summary>
  21. /// <param name="configuretView"></param>
  22. /// <param name="standardID"></param>
  23. /// <param name="educationID"></param>
  24. /// <param name="learningformID"></param>
  25. /// <param name="learnSystem"></param>
  26. /// <param name="pageIndex"></param>
  27. /// <param name="pageSize"></param>
  28. /// <returns></returns>
  29. public IGridResultSet<SpecialtyClassSettingView> GetSpecialtyClassSettingViewGrid(ConfiguretView configuretView, int? standardID, int? educationID, int? learningformID, string learnSystem, int pageIndex, int pageSize)
  30. {
  31. //专业分班
  32. Expression<Func<CF_SpecialtyClassSetting, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  33. var query = SpecialtyClassSettingDAL.GetSpecialtyClassSettingViewQueryable(exp);
  34. if (standardID.HasValue)
  35. {
  36. //专业ID(Value)
  37. query = query.Where(x => x.StandardID == standardID);
  38. }
  39. if (educationID.HasValue)
  40. {
  41. //培养层次
  42. query = query.Where(x => x.EducationID == educationID);
  43. }
  44. if (learningformID.HasValue)
  45. {
  46. //学习形式
  47. query = query.Where(x => x.LearningformID == learningformID);
  48. }
  49. if (!string.IsNullOrEmpty(learnSystem) && learnSystem != "-1")
  50. {
  51. //学制
  52. var LearnSystems = Convert.ToDecimal(learnSystem);
  53. query = query.Where(x => x.LearnSystem == LearnSystems);
  54. }
  55. //查询条件
  56. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  57. {
  58. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  59. }
  60. return query.OrderBy(x => x.StandardName).ThenBy(x => x.EducationID).ThenBy(x => x.LearningformID).ThenBy(x => x.LearnSystem).ToGridResultSet<SpecialtyClassSettingView>(pageIndex, pageSize);
  61. }
  62. /// <summary>
  63. /// 查询对应的专业分班信息List
  64. /// </summary>
  65. /// <param name="configuretView"></param>
  66. /// <param name="standardID"></param>
  67. /// <param name="educationID"></param>
  68. /// <param name="learningformID"></param>
  69. /// <param name="learnSystem"></param>
  70. /// <returns></returns>
  71. public IList<SpecialtyClassSettingView> GetSpecialtyClassSettingViewList(ConfiguretView configuretView, int? standardID, int? educationID, int? learningformID, string learnSystem)
  72. {
  73. //专业分班
  74. Expression<Func<CF_SpecialtyClassSetting, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  75. var query = SpecialtyClassSettingDAL.GetSpecialtyClassSettingViewQueryable(exp);
  76. if (standardID.HasValue)
  77. {
  78. //专业ID(Value)
  79. query = query.Where(x => x.StandardID == standardID);
  80. }
  81. if (educationID.HasValue)
  82. {
  83. //培养层次
  84. query = query.Where(x => x.EducationID == educationID);
  85. }
  86. if (learningformID.HasValue)
  87. {
  88. //学习形式
  89. query = query.Where(x => x.LearningformID == learningformID);
  90. }
  91. if (!string.IsNullOrEmpty(learnSystem) && learnSystem != "-1")
  92. {
  93. //学制
  94. var LearnSystems = Convert.ToDecimal(learnSystem);
  95. query = query.Where(x => x.LearnSystem == LearnSystems);
  96. }
  97. //查询条件
  98. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  99. {
  100. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  101. }
  102. return query.OrderBy(x => x.StandardName).ThenBy(x => x.EducationID).ThenBy(x => x.LearningformID).ThenBy(x => x.LearnSystem).ToList();
  103. }
  104. /// <summary>
  105. /// 根据专业分班ID查询对应的专业分班信息SpecialtyClassSettingView
  106. /// </summary>
  107. /// <param name="specialtyClassSettingID"></param>
  108. /// <returns></returns>
  109. public SpecialtyClassSettingView GetSpecialtyClassSettingView(Guid? specialtyClassSettingID)
  110. {
  111. try
  112. {
  113. var query = SpecialtyClassSettingDAL.GetSpecialtyClassSettingViewQueryable(x => x.SpecialtyClassSettingID == specialtyClassSettingID).SingleOrDefault();
  114. return query;
  115. }
  116. catch (Exception ex)
  117. {
  118. throw new Exception(ex.Message);
  119. }
  120. }
  121. /// <summary>
  122. /// 专业分班批量新增(业务主键:专业信息ID)
  123. /// </summary>
  124. /// <param name="specialtyIDList"></param>
  125. /// <param name="specialtyClassSettingView"></param>
  126. /// <returns></returns>
  127. public string SpecialtyClassSettingBatchAdd(List<Guid?> specialtyIDList, SpecialtyClassSettingView specialtyClassSettingView)
  128. {
  129. try
  130. {
  131. //专业分班
  132. Expression<Func<CF_SpecialtyClassSetting, bool>> expSpecialtyClassSetting = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  133. expSpecialtyClassSetting = expSpecialtyClassSetting.And(x => specialtyIDList.Contains(x.SpecialtyID));
  134. //查询对应的专业分班信息List
  135. var specialtyClassSettingList = SpecialtyClassSettingDAL.SpecialtyClassSettingRepository.GetList(expSpecialtyClassSetting).ToList();
  136. int success = 0; //成功
  137. int fail = 0; //失败
  138. string tipMessage = null; //提示消息
  139. List<CF_SpecialtyClassSetting> specialtyClassSettingInList = new List<CF_SpecialtyClassSetting>();
  140. foreach (var specialtyID in specialtyIDList)
  141. {
  142. var specialtyClassSettingVerify = specialtyClassSettingList.Where(x => x.SpecialtyID == specialtyID).SingleOrDefault();
  143. if (specialtyClassSettingVerify == null)
  144. {
  145. //新增
  146. var specialtyClassSetting = new CF_SpecialtyClassSetting();
  147. specialtyClassSetting.SpecialtyClassSettingID = Guid.NewGuid();
  148. specialtyClassSetting.SpecialtyID = specialtyID;
  149. specialtyClassSetting.PlanRecruitStudentCount = 0;
  150. specialtyClassSetting.ClassArrangeStudentCount = 0;
  151. specialtyClassSetting.ClassMaxStudentCount = 0;
  152. specialtyClassSetting.ClassNumber = 1;
  153. SetNewStatus(specialtyClassSetting);
  154. specialtyClassSettingInList.Add(specialtyClassSetting);
  155. success++;
  156. }
  157. else
  158. {
  159. //表示已存在相同的专业分班信息
  160. fail++;
  161. }
  162. }
  163. //批量插入
  164. UnitOfWork.BulkInsert<CF_SpecialtyClassSetting>(specialtyClassSettingInList);
  165. if (success > 0 && fail <= 0)
  166. {
  167. tipMessage = success + "条";
  168. }
  169. else
  170. {
  171. tipMessage = success + "条," + fail + "条失败,原因:已存在相同的专业分班信息,请检查";
  172. }
  173. return tipMessage;
  174. }
  175. catch (Exception ex)
  176. {
  177. throw new Exception(ex.Message);
  178. }
  179. }
  180. /// <summary>
  181. /// 查询专业分班中未新增的专业信息SpecialtyView
  182. /// </summary>
  183. /// <param name="configuretView"></param>
  184. /// <param name="standardID"></param>
  185. /// <param name="educationID"></param>
  186. /// <param name="learningformID"></param>
  187. /// <param name="learnSystem"></param>
  188. /// <param name="scienceclassID"></param>
  189. /// <param name="pageIndex"></param>
  190. /// <param name="pageSize"></param>
  191. /// <returns></returns>
  192. public IGridResultSet<SpecialtyView> GetSpecialtyViewNoAdd(ConfiguretView configuretView, int? standardID, int? educationID, int? learningformID, string learnSystem, int? scienceclassID, int pageIndex, int pageSize)
  193. {
  194. //专业信息(只查询启用状态的专业信息)
  195. Expression<Func<CF_Specialty, bool>> expSpecialty = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  196. if (standardID.HasValue)
  197. {
  198. expSpecialty = expSpecialty.And(x => x.StandardID == standardID);
  199. }
  200. if (educationID.HasValue)
  201. {
  202. expSpecialty = expSpecialty.And(x => x.EducationID == educationID);
  203. }
  204. if (learningformID.HasValue)
  205. {
  206. expSpecialty = expSpecialty.And(x => x.LearningformID == learningformID);
  207. }
  208. if (!string.IsNullOrEmpty(learnSystem) && learnSystem != "-1")
  209. {
  210. var LearnSystems = Convert.ToDecimal(learnSystem);
  211. expSpecialty = expSpecialty.And(x => x.LearnSystem == LearnSystems);
  212. }
  213. if (scienceclassID.HasValue)
  214. {
  215. expSpecialty = expSpecialty.And(x => x.ScienceclassID == scienceclassID);
  216. }
  217. //专业分班
  218. Expression<Func<CF_SpecialtyClassSetting, bool>> expSpecialtyClassSetting = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  219. var query = SpecialtyClassSettingDAL.GetSpecialtyViewNoAddQueryable(expSpecialty, expSpecialtyClassSetting);
  220. //查询条件
  221. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  222. {
  223. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  224. }
  225. return query.OrderBy(x => x.StandardName).ThenBy(x => x.EducationID).ThenBy(x => x.LearningformID).ThenBy(x => x.LearnSystem).ToGridResultSet<SpecialtyView>(pageIndex, pageSize);
  226. }
  227. /// <summary>
  228. /// 编辑(新增、修改,业务主键:专业信息ID)
  229. /// </summary>
  230. /// <param name="specialtyClassSettingView"></param>
  231. public void SpecialtyClassSettingEdit(SpecialtyClassSettingView specialtyClassSettingView)
  232. {
  233. try
  234. {
  235. //查询数据库进行验证
  236. var specialtyClassSettingVerification = SpecialtyClassSettingDAL.SpecialtyClassSettingRepository.GetList(x => x.SpecialtyClassSettingID != specialtyClassSettingView.SpecialtyClassSettingID
  237. && x.SpecialtyID == specialtyClassSettingView.SpecialtyID).SingleOrDefault();
  238. if (specialtyClassSettingVerification == null)
  239. {
  240. //数据有误验证
  241. if (specialtyClassSettingView.SpecialtyClassSettingID != Guid.Empty)
  242. {
  243. var specialtyClassSetting = SpecialtyClassSettingDAL.SpecialtyClassSettingRepository
  244. .GetList(x => x.SpecialtyClassSettingID == specialtyClassSettingView.SpecialtyClassSettingID).SingleOrDefault();
  245. if (specialtyClassSetting == null)
  246. {
  247. throw new Exception("数据有误,请核查");
  248. }
  249. else
  250. {
  251. //表示修改
  252. specialtyClassSetting.SpecialtyID = specialtyClassSettingView.SpecialtyID;
  253. specialtyClassSetting.PlanRecruitStudentCount = specialtyClassSettingView.PlanRecruitStudentCount;
  254. specialtyClassSetting.ClassArrangeStudentCount = specialtyClassSettingView.ClassArrangeStudentCount;
  255. specialtyClassSetting.ClassMaxStudentCount = specialtyClassSettingView.ClassMaxStudentCount;
  256. specialtyClassSetting.ClassNumber = specialtyClassSettingView.ClassNumber;
  257. SetModifyStatus(specialtyClassSetting);
  258. }
  259. }
  260. else
  261. {
  262. //表示新增
  263. CF_SpecialtyClassSetting specialtyClassSetting = new CF_SpecialtyClassSetting();
  264. specialtyClassSetting.SpecialtyClassSettingID = Guid.NewGuid();
  265. specialtyClassSetting.SpecialtyID = specialtyClassSettingView.SpecialtyID;
  266. specialtyClassSetting.PlanRecruitStudentCount = specialtyClassSettingView.PlanRecruitStudentCount;
  267. specialtyClassSetting.ClassArrangeStudentCount = specialtyClassSettingView.ClassArrangeStudentCount;
  268. specialtyClassSetting.ClassMaxStudentCount = specialtyClassSettingView.ClassMaxStudentCount;
  269. specialtyClassSetting.ClassNumber = specialtyClassSettingView.ClassNumber;
  270. SetNewStatus(specialtyClassSetting);
  271. UnitOfWork.Add(specialtyClassSetting);
  272. }
  273. }
  274. else
  275. {
  276. throw new Exception("已存在相同的专业分班信息,请核查");
  277. }
  278. //事务提交
  279. UnitOfWork.Commit();
  280. }
  281. catch (Exception ex)
  282. {
  283. throw new Exception(ex.Message);
  284. }
  285. }
  286. /// <summary>
  287. /// 批量修改(计划招生人数、每班预招人数、每班最大人数)
  288. /// </summary>
  289. /// <param name="specialtyClassSettingIDList"></param>
  290. /// <param name="planRecruitStudentCount"></param>
  291. /// <param name="classArrangeStudentCount"></param>
  292. /// <param name="classMaxStudentCount"></param>
  293. /// <returns></returns>
  294. public string BatchModify(List<Guid?> specialtyClassSettingIDList, int? planRecruitStudentCount, int? classArrangeStudentCount, int? classMaxStudentCount)
  295. {
  296. try
  297. {
  298. //查询对应的专业分班信息
  299. var specialtyClassSettingList = SpecialtyClassSettingDAL.SpecialtyClassSettingRepository.GetList(x => specialtyClassSettingIDList.Contains(x.SpecialtyClassSettingID)).ToList();
  300. int fail = 0;
  301. int success = 0;
  302. string tipMessage = null; //提示消息
  303. List<CF_SpecialtyClassSetting> specialtyClassSettingUpList = new List<CF_SpecialtyClassSetting>();
  304. foreach (var specialtyClassSetting in specialtyClassSettingList)
  305. {
  306. if (planRecruitStudentCount != null)
  307. {
  308. if (specialtyClassSetting.ClassArrangeStudentCount > specialtyClassSetting.ClassMaxStudentCount)
  309. {
  310. fail++;
  311. continue;
  312. }
  313. else if (planRecruitStudentCount <= 0)
  314. {
  315. specialtyClassSetting.PlanRecruitStudentCount = planRecruitStudentCount;
  316. specialtyClassSetting.ClassNumber = 1;
  317. }
  318. else if (specialtyClassSetting.ClassArrangeStudentCount <= 0)
  319. {
  320. specialtyClassSetting.PlanRecruitStudentCount = planRecruitStudentCount;
  321. specialtyClassSetting.ClassNumber = 1;
  322. }
  323. else if (specialtyClassSetting.ClassMaxStudentCount <= 0)
  324. {
  325. specialtyClassSetting.PlanRecruitStudentCount = planRecruitStudentCount;
  326. specialtyClassSetting.ClassNumber = 1;
  327. }
  328. else
  329. {
  330. specialtyClassSetting.PlanRecruitStudentCount = planRecruitStudentCount;
  331. var classNumber = planRecruitStudentCount.Value / specialtyClassSetting.ClassArrangeStudentCount.Value;
  332. var total = classNumber * specialtyClassSetting.ClassMaxStudentCount;
  333. if (total >= planRecruitStudentCount)
  334. {
  335. specialtyClassSetting.ClassNumber = classNumber;
  336. }
  337. else
  338. {
  339. specialtyClassSetting.ClassNumber = classNumber + 1;
  340. }
  341. }
  342. SetModifyStatus(specialtyClassSetting);
  343. }
  344. if (classArrangeStudentCount != null)
  345. {
  346. if (classArrangeStudentCount > specialtyClassSetting.ClassMaxStudentCount)
  347. {
  348. fail++;
  349. continue;
  350. }
  351. else if (classArrangeStudentCount <= 0)
  352. {
  353. specialtyClassSetting.ClassArrangeStudentCount = classArrangeStudentCount;
  354. specialtyClassSetting.ClassNumber = 1;
  355. }
  356. else if (specialtyClassSetting.PlanRecruitStudentCount <= 0)
  357. {
  358. specialtyClassSetting.ClassArrangeStudentCount = classArrangeStudentCount;
  359. specialtyClassSetting.ClassNumber = 1;
  360. }
  361. else if (specialtyClassSetting.ClassMaxStudentCount <= 0)
  362. {
  363. specialtyClassSetting.ClassArrangeStudentCount = classArrangeStudentCount;
  364. specialtyClassSetting.ClassNumber = 1;
  365. }
  366. else
  367. {
  368. specialtyClassSetting.ClassArrangeStudentCount = classArrangeStudentCount;
  369. var classNumber = specialtyClassSetting.PlanRecruitStudentCount.Value / classArrangeStudentCount.Value;
  370. var total = classNumber * specialtyClassSetting.ClassMaxStudentCount;
  371. if (total >= specialtyClassSetting.PlanRecruitStudentCount)
  372. {
  373. specialtyClassSetting.ClassNumber = classNumber;
  374. }
  375. else
  376. {
  377. specialtyClassSetting.ClassNumber = classNumber + 1;
  378. }
  379. }
  380. SetModifyStatus(specialtyClassSetting);
  381. }
  382. if (classMaxStudentCount != null)
  383. {
  384. if (specialtyClassSetting.ClassArrangeStudentCount > classMaxStudentCount)
  385. {
  386. fail++;
  387. continue;
  388. }
  389. else if (classMaxStudentCount <= 0)
  390. {
  391. specialtyClassSetting.ClassMaxStudentCount = classMaxStudentCount;
  392. specialtyClassSetting.ClassNumber = 1;
  393. }
  394. else if (specialtyClassSetting.PlanRecruitStudentCount <= 0)
  395. {
  396. specialtyClassSetting.ClassMaxStudentCount = classMaxStudentCount;
  397. specialtyClassSetting.ClassNumber = 1;
  398. }
  399. else if (specialtyClassSetting.ClassArrangeStudentCount <= 0)
  400. {
  401. specialtyClassSetting.ClassMaxStudentCount = classMaxStudentCount;
  402. specialtyClassSetting.ClassNumber = 1;
  403. }
  404. else
  405. {
  406. specialtyClassSetting.ClassMaxStudentCount = classMaxStudentCount;
  407. var classNumber = specialtyClassSetting.PlanRecruitStudentCount.Value / specialtyClassSetting.ClassArrangeStudentCount.Value;
  408. var total = classNumber * classMaxStudentCount;
  409. if (total >= specialtyClassSetting.PlanRecruitStudentCount)
  410. {
  411. specialtyClassSetting.ClassNumber = classNumber;
  412. }
  413. else
  414. {
  415. specialtyClassSetting.ClassNumber = classNumber + 1;
  416. }
  417. }
  418. SetModifyStatus(specialtyClassSetting);
  419. }
  420. specialtyClassSettingUpList.Add(specialtyClassSetting);
  421. success++;
  422. }
  423. //批量统一提交更新
  424. if (specialtyClassSettingUpList != null && specialtyClassSettingUpList.Count() > 0)
  425. {
  426. UnitOfWork.BatchUpdate(specialtyClassSettingUpList);
  427. }
  428. if (success > 0 && fail <= 0)
  429. {
  430. tipMessage = success + "条";
  431. }
  432. else
  433. {
  434. tipMessage = success + "条," + fail + "条失败,原因:每班预招人数不能大于每班最大人数";
  435. }
  436. return tipMessage;
  437. }
  438. catch (Exception ex)
  439. {
  440. throw new Exception(ex.Message);
  441. }
  442. }
  443. /// <summary>
  444. /// 删除
  445. /// </summary>
  446. /// <param name="specialtyClassSettingIDList"></param>
  447. /// <returns></returns>
  448. public bool SpecialtyClassSettingDelete(List<Guid?> specialtyClassSettingIDList)
  449. {
  450. try
  451. {
  452. UnitOfWork.Delete<CF_SpecialtyClassSetting>(x => specialtyClassSettingIDList.Contains(x.SpecialtyClassSettingID));
  453. return true;
  454. }
  455. catch (Exception)
  456. {
  457. throw;
  458. }
  459. }
  460. }
  461. }