OpenObjectServices.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Bowin.Common.Linq;
  6. using Bowin.Common.Linq.Entity;
  7. using EMIS.ViewModel;
  8. using EMIS.ViewModel.StudentManage.OnlineChecking;
  9. using EMIS.ViewModel.SystemView;
  10. using EMIS.DataLogic.StudentManage.OnlineChecking;
  11. using EMIS.Entities;
  12. using System.Linq.Expressions;
  13. namespace EMIS.CommonLogic.StudentManage.OnlineChecking
  14. {
  15. public class OpenObjectServices : BaseServices, IOpenObjectServices
  16. {
  17. public OpenObjectDAL OpenObjectDAL { get; set; }
  18. /// <summary>
  19. /// 查询对应的学生校对控制开放对象信息OpenObjectView
  20. /// </summary>
  21. /// <param name="configuretView"></param>
  22. /// <param name="educationID"></param>
  23. /// <param name="schoolyearNumID"></param>
  24. /// <param name="dateRange"></param>
  25. /// <param name="pageIndex"></param>
  26. /// <param name="pageSize"></param>
  27. /// <returns></returns>
  28. public IGridResultSet<OpenObjectView> GetStudentEditObjectViewGrid(ConfiguretView configuretView, int? educationID, int? schoolyearNumID, DateTime? dateRange, int pageIndex, int pageSize)
  29. {
  30. Expression<Func<CF_StudentEditObjects, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  31. if (educationID.HasValue)
  32. {
  33. exp = exp.And(x => x.EducationID == educationID);
  34. }
  35. if (schoolyearNumID.HasValue)
  36. {
  37. exp = exp.And(x => x.SchoolyearNumID == schoolyearNumID);
  38. }
  39. if (dateRange.HasValue)
  40. {
  41. exp = exp.And(x => x.Starttime <= dateRange);
  42. }
  43. if (dateRange.HasValue)
  44. {
  45. exp = exp.And(x => x.Endtime >= dateRange);
  46. }
  47. var query = OpenObjectDAL.GetStudentEditObjectQueryable(exp);
  48. //查询条件
  49. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  50. {
  51. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  52. }
  53. return query.OrderBy(x => x.EducationID).ThenBy(x => x.SchoolyearNumID).ToGridResultSet<OpenObjectView>(pageIndex, pageSize);
  54. }
  55. /// <summary>
  56. /// 查询对应的学生校对控制开放对象信息List
  57. /// </summary>
  58. /// <param name="configuretView"></param>
  59. /// <param name="educationID"></param>
  60. /// <param name="schoolyearNumID"></param>
  61. /// <param name="dateRange"></param>
  62. /// <returns></returns>
  63. public IList<OpenObjectView> GetStudentEditObjectViewList(ConfiguretView configuretView, int? educationID, int? schoolyearNumID, DateTime? dateRange)
  64. {
  65. Expression<Func<CF_StudentEditObjects, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  66. if (educationID.HasValue)
  67. {
  68. exp = exp.And(x => x.EducationID == educationID);
  69. }
  70. if (schoolyearNumID.HasValue)
  71. {
  72. exp = exp.And(x => x.SchoolyearNumID == schoolyearNumID);
  73. }
  74. if (dateRange.HasValue)
  75. {
  76. exp = exp.And(x => x.Starttime <= dateRange);
  77. }
  78. if (dateRange.HasValue)
  79. {
  80. exp = exp.And(x => x.Endtime >= dateRange);
  81. }
  82. var query = OpenObjectDAL.GetStudentEditObjectQueryable(exp);
  83. //查询条件
  84. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  85. {
  86. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  87. }
  88. return query.OrderBy(x => x.EducationID).ThenBy(x => x.SchoolyearNumID).ToList();
  89. }
  90. /// <summary>
  91. /// 查询对应的开放对象信息OpenObjectView
  92. /// </summary>
  93. /// <param name="studentEditObjectID"></param>
  94. /// <returns></returns>
  95. public OpenObjectView GetStudentEditObjectView(Guid? studentEditObjectID)
  96. {
  97. try
  98. {
  99. Expression<Func<CF_StudentEditObjects, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  100. exp = exp.And(x => x.StudentEditObjectsID == studentEditObjectID);
  101. var query = OpenObjectDAL.GetStudentEditObjectQueryable(exp).SingleOrDefault();
  102. return query;
  103. }
  104. catch (Exception ex)
  105. {
  106. throw new Exception(ex.Message);
  107. }
  108. }
  109. /// <summary>
  110. /// 编辑(新增、修改)
  111. /// </summary>
  112. /// <param name="openObjectView"></param>
  113. public void StudentEditObjectEdit(OpenObjectView openObjectView)
  114. {
  115. try
  116. {
  117. var studentEditObjectVerify = OpenObjectDAL.StudentEditObjectsRepository.GetList(x => x.StudentEditObjectsID != openObjectView.StudentEditObjectsID
  118. && x.EducationID == openObjectView.EducationID && x.SchoolyearNumID == openObjectView.SchoolyearNumID).SingleOrDefault();
  119. if (studentEditObjectVerify == null)
  120. {
  121. if (openObjectView.StudentEditObjectsID != Guid.Empty)
  122. {
  123. var studentEditObject = OpenObjectDAL.StudentEditObjectsRepository.GetList(x => x.StudentEditObjectsID == openObjectView.StudentEditObjectsID).SingleOrDefault();
  124. if (studentEditObject == null)
  125. {
  126. throw new Exception("数据有误,请核查。");
  127. }
  128. else
  129. {
  130. //表示修改
  131. studentEditObject.EducationID = openObjectView.EducationID;
  132. studentEditObject.SchoolyearNumID = openObjectView.SchoolyearNumID;
  133. studentEditObject.Starttime = openObjectView.Starttime;
  134. studentEditObject.Endtime = openObjectView.Endtime;
  135. studentEditObject.Remark = openObjectView.Remark;
  136. SetModifyStatus(studentEditObject);
  137. }
  138. }
  139. else
  140. {
  141. //表示新增
  142. var newStudentEditObject = new CF_StudentEditObjects();
  143. newStudentEditObject.StudentEditObjectsID = Guid.NewGuid();
  144. newStudentEditObject.EducationID = openObjectView.EducationID;
  145. newStudentEditObject.SchoolyearNumID = openObjectView.SchoolyearNumID;
  146. newStudentEditObject.Starttime = openObjectView.Starttime;
  147. newStudentEditObject.Endtime = openObjectView.Endtime;
  148. newStudentEditObject.Remark = openObjectView.Remark;
  149. SetNewStatus(newStudentEditObject);
  150. UnitOfWork.Add(newStudentEditObject);
  151. }
  152. }
  153. else
  154. {
  155. throw new Exception("已存在相同的开放对象信息,请核查。");
  156. }
  157. UnitOfWork.Commit();
  158. }
  159. catch (Exception ex)
  160. {
  161. throw new Exception(ex.Message);
  162. }
  163. }
  164. /// <summary>
  165. /// 开放对象批量新增
  166. /// </summary>
  167. /// <param name="schoolyearNumIDList"></param>
  168. /// <param name="openObjectView"></param>
  169. /// <returns></returns>
  170. public string StudentEditObjectBatchAdd(List<int?> schoolyearNumIDList, OpenObjectView openObjectView)
  171. {
  172. try
  173. {
  174. Expression<Func<CF_StudentEditObjects, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  175. exp = exp.And(x => schoolyearNumIDList.Contains(x.SchoolyearNumID));
  176. var studentEditObjectList = OpenObjectDAL.StudentEditObjectsRepository.GetList(exp).ToList();
  177. int success = 0;
  178. int fail = 0;
  179. string tipMessage = null;
  180. List<CF_StudentEditObjects> studentEditObjectInList = new List<CF_StudentEditObjects>();
  181. foreach (var schoolyearNumID in schoolyearNumIDList)
  182. {
  183. var studentEditObjectVerify = studentEditObjectList.Where(x => x.EducationID == openObjectView.EducationID &&
  184. x.SchoolyearNumID == schoolyearNumID).SingleOrDefault();
  185. if (studentEditObjectVerify == null)
  186. {
  187. //新增
  188. var newStudentEditObject = new CF_StudentEditObjects();
  189. newStudentEditObject.StudentEditObjectsID = Guid.NewGuid();
  190. newStudentEditObject.EducationID = openObjectView.EducationID;
  191. newStudentEditObject.SchoolyearNumID = schoolyearNumID;
  192. newStudentEditObject.Starttime = openObjectView.Starttime;
  193. newStudentEditObject.Endtime = openObjectView.Endtime;
  194. //newStudentEditObject.Remark = openObjectView.Remark;
  195. SetNewStatus(newStudentEditObject);
  196. studentEditObjectInList.Add(newStudentEditObject);
  197. success++;
  198. }
  199. else
  200. {
  201. //表示已存在相同的开放对象信息
  202. fail++;
  203. }
  204. }
  205. UnitOfWork.BulkInsert(studentEditObjectInList);
  206. if (success > 0 && fail <= 0)
  207. {
  208. tipMessage = success + "条";
  209. }
  210. else
  211. {
  212. tipMessage = success + "条," + fail + "条失败,原因:已存在相同的开放对象信息,请检查";
  213. }
  214. return tipMessage;
  215. }
  216. catch (Exception ex)
  217. {
  218. throw new Exception(ex.Message);
  219. }
  220. }
  221. /// <summary>
  222. /// 查询开放对象中未新增的培养层次信息DictionaryItemView
  223. /// </summary>
  224. /// <param name="configuretView"></param>
  225. /// <param name="educationID"></param>
  226. /// <param name="pageIndex"></param>
  227. /// <param name="pageSize"></param>
  228. /// <returns></returns>
  229. public IGridResultSet<DictionaryItemView> GetSchoolyearNumNoAddGrid(ConfiguretView configuretView, int? educationID, int pageIndex, int pageSize)
  230. {
  231. Expression<Func<CF_StudentEditObjects, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  232. if (educationID.HasValue)
  233. {
  234. exp = exp.And(x => x.EducationID == educationID);
  235. }
  236. var query = OpenObjectDAL.GetSchoolyearNumNoAddQueryable(exp);
  237. query = query.Where(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  238. //查询条件
  239. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  240. {
  241. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  242. }
  243. return query.OrderBy(x => x.DictionaryCode).ThenBy(x => x.OrderNo).ToGridResultSet<DictionaryItemView>(pageIndex, pageSize);
  244. }
  245. /// <summary>
  246. /// 查询开放对象中未新增的培养层次信息List
  247. /// </summary>
  248. /// <param name="configuretView"></param>
  249. /// <param name="educationID"></param>
  250. /// <returns></returns>
  251. public IList<DictionaryItemView> GetSchoolyearNumNoAddList(ConfiguretView configuretView, int? educationID)
  252. {
  253. Expression<Func<CF_StudentEditObjects, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  254. if (educationID.HasValue)
  255. {
  256. exp = exp.And(x => x.EducationID == educationID);
  257. }
  258. var query = OpenObjectDAL.GetSchoolyearNumNoAddQueryable(exp);
  259. query = query.Where(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  260. //查询条件
  261. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  262. {
  263. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  264. }
  265. return query.OrderBy(x => x.DictionaryCode).ThenBy(x => x.OrderNo).ToList();
  266. }
  267. /// <summary>
  268. /// 删除
  269. /// </summary>
  270. /// <param name="studentEditObjectIDs"></param>
  271. /// <returns></returns>
  272. public bool StudentEditObjectDelete(List<Guid?> studentEditObjectIDs)
  273. {
  274. try
  275. {
  276. UnitOfWork.Delete<CF_StudentEditObjects>(x => studentEditObjectIDs.Contains(x.StudentEditObjectsID));
  277. return true;
  278. }
  279. catch (Exception)
  280. {
  281. throw;
  282. }
  283. }
  284. }
  285. }