CampusServices.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  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.Linq;
  7. using Bowin.Common.Linq.Entity;
  8. using EMIS.Entities;
  9. using EMIS.Utility;
  10. using EMIS.ViewModel;
  11. using EMIS.ViewModel.UniversityManage.AdministrativeOrgan;
  12. using EMIS.DataLogic.UniversityManage.AdministrativeOrgan;
  13. namespace EMIS.CommonLogic.UniversityManage.AdministrativeOrgan
  14. {
  15. public class CampusServices : BaseServices, ICampusServices
  16. {
  17. public CampusDAL CampusDAL { get; set; }
  18. /// <summary>
  19. /// 查询校区信息View
  20. /// </summary>
  21. /// <param name="configuretView"></param>
  22. /// <param name="pageIndex"></param>
  23. /// <param name="pageSize"></param>
  24. /// <returns></returns>
  25. public IGridResultSet<CampusView> GetCampusViewGrid(ConfiguretView configuretView, int pageIndex, int pageSize)
  26. {
  27. Expression<Func<CF_Campus, bool>> expCampus = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  28. var query = CampusDAL.GetCampusViewQueryable(expCampus);
  29. //查询条件
  30. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  31. {
  32. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  33. }
  34. return this.GetQueryByDataRangeByCampus(query).OrderBy(x => x.No.Length).ThenBy(x => x.No).ToGridResultSet<CampusView>(pageIndex, pageSize);
  35. }
  36. /// <summary>
  37. /// 查询校区信息List
  38. /// </summary>
  39. /// <param name="configuretView"></param>
  40. /// <returns></returns>
  41. public IList<CampusView> GetCampusViewList(ConfiguretView configuretView)
  42. {
  43. Expression<Func<CF_Campus, bool>> expCampus = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  44. var query = CampusDAL.GetCampusViewQueryable(expCampus);
  45. //查询条件
  46. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  47. {
  48. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  49. }
  50. return this.GetQueryByDataRangeByCampus(query).OrderBy(x => x.No.Length).ThenBy(x => x.No).ToList();
  51. }
  52. /// <summary>
  53. /// 查询全部校区信息CF_Campus
  54. /// </summary>
  55. /// <returns></returns>
  56. public List<CF_Campus> GetCampusList()
  57. {
  58. Expression<Func<CF_Campus, bool>> expCampus = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  59. var query = CampusDAL.CampusRepository.GetList(expCampus);
  60. return this.GetQueryByDataRangeByCampus(query).OrderBy(x => x.No.Length).ThenBy(x => x.No).ToList();
  61. }
  62. /// <summary>
  63. /// 查询全部校区信息CF_Campus(不考虑状态列)
  64. /// </summary>
  65. /// <returns></returns>
  66. public List<CF_Campus> GetCampusListWithoutDataRange()
  67. {
  68. Expression<Func<CF_Campus, bool>> expCampus = (x => true);
  69. var query = CampusDAL.CampusRepository.GetList(expCampus);
  70. return query.OrderBy(x => x.No.Length).ThenBy(x => x.No).ToList();
  71. }
  72. /// <summary>
  73. /// 查询对应的校区信息CampusView
  74. /// </summary>
  75. /// <param name="campusID"></param>
  76. /// <returns></returns>
  77. public CampusView GetCampusView(Guid? campusID)
  78. {
  79. try
  80. {
  81. var query = CampusDAL.GetCampusViewQueryable(x => x.CampusID == campusID).SingleOrDefault();
  82. return query;
  83. }
  84. catch (Exception ex)
  85. {
  86. throw new Exception(ex.Message);
  87. }
  88. }
  89. /// <summary>
  90. /// 编辑(新增、修改,业务主键:校区代码或校区名称)
  91. /// </summary>
  92. /// <param name="campusView"></param>
  93. public void CampusEdit(CampusView campusView)
  94. {
  95. try
  96. {
  97. //查询数据库进行验证
  98. var campusVerify = CampusDAL.CampusRepository.GetList(x => x.CampusID != campusView.CampusID && (x.No == campusView.No || x.Name == campusView.Name)).FirstOrDefault();
  99. if (campusVerify == null)
  100. {
  101. //数据有误验证
  102. if (campusView.CampusID != Guid.Empty)
  103. {
  104. var campus = CampusDAL.CampusRepository.GetList(x => x.CampusID == campusView.CampusID, (x => x.CF_CampusProfile)).SingleOrDefault();
  105. if (campus == null)
  106. {
  107. throw new Exception("数据有误,请核查。");
  108. }
  109. else
  110. {
  111. //表示修改
  112. campus.UniversityID = campusView.UniversityID;
  113. campus.No = campusView.No;
  114. campus.Name = campusView.Name;
  115. campus.SimpleName = campusView.SimpleName;
  116. campus.EnglishName = campusView.EnglishName;
  117. campus.Remark = campusView.Remark;
  118. SetModifyStatus(campusView);
  119. //校区信息扩展表
  120. if (campus.CF_CampusProfile == null)
  121. {
  122. //新增
  123. var newCampusProfile = new CF_CampusProfile();
  124. newCampusProfile.CampusID = campusView.CampusID;
  125. newCampusProfile.Generalsuper = campusView.Generalsuper;
  126. newCampusProfile.Recruitstudents = campusView.Recruitstudents;
  127. newCampusProfile.Placesuper = campusView.Placesuper;
  128. newCampusProfile.Teachingsuper = campusView.Teachingsuper;
  129. newCampusProfile.Studentcharge = campusView.Studentcharge;
  130. newCampusProfile.ZIPCode = campusView.ZIPCode;
  131. newCampusProfile.Officephone = campusView.Officephone;
  132. newCampusProfile.FAX = campusView.FAX;
  133. newCampusProfile.Email = campusView.Email;
  134. newCampusProfile.Evolution = campusView.Evolution;
  135. SetNewStatus(newCampusProfile);
  136. UnitOfWork.Add(newCampusProfile);
  137. }
  138. else
  139. {
  140. //修改
  141. campus.CF_CampusProfile.Generalsuper = campusView.Generalsuper;
  142. campus.CF_CampusProfile.Recruitstudents = campusView.Recruitstudents;
  143. campus.CF_CampusProfile.Placesuper = campusView.Placesuper;
  144. campus.CF_CampusProfile.Teachingsuper = campusView.Teachingsuper;
  145. campus.CF_CampusProfile.Studentcharge = campusView.Studentcharge;
  146. campus.CF_CampusProfile.ZIPCode = campusView.ZIPCode;
  147. campus.CF_CampusProfile.Officephone = campusView.Officephone;
  148. campus.CF_CampusProfile.FAX = campusView.FAX;
  149. campus.CF_CampusProfile.Email = campusView.Email;
  150. campus.CF_CampusProfile.Evolution = campusView.Evolution;
  151. SetModifyStatus(campus.CF_CampusProfile);
  152. }
  153. }
  154. }
  155. else
  156. {
  157. //表示新增(CF_Campus主表)
  158. CF_Campus campus = new CF_Campus();
  159. campus.CampusID = Guid.NewGuid();
  160. campus.UniversityID = campusView.UniversityID;
  161. campus.No = campusView.No;
  162. campus.Name = campusView.Name;
  163. campus.SimpleName = campusView.SimpleName;
  164. campus.EnglishName = campusView.EnglishName;
  165. campus.Remark = campusView.Remark;
  166. SetNewStatus(campus);
  167. UnitOfWork.Add(campus);
  168. //表示新增(CF_CampusProfile扩展表)
  169. CF_CampusProfile campusProfile = new CF_CampusProfile();
  170. campusProfile.CampusID = campus.CampusID;
  171. campusProfile.Generalsuper = campusView.Generalsuper;
  172. campusProfile.Recruitstudents = campusView.Recruitstudents;
  173. campusProfile.Placesuper = campusView.Placesuper;
  174. campusProfile.Teachingsuper = campusView.Teachingsuper;
  175. campusProfile.Studentcharge = campusView.Studentcharge;
  176. campusProfile.ZIPCode = campusView.ZIPCode;
  177. campusProfile.Officephone = campusView.Officephone;
  178. campusProfile.FAX = campusView.FAX;
  179. campusProfile.Email = campusView.Email;
  180. campusProfile.Evolution = campusView.Evolution;
  181. SetNewStatus(campusProfile);
  182. UnitOfWork.Add(campusProfile);
  183. }
  184. }
  185. else
  186. {
  187. throw new Exception("已存在相同的" + RSL.Get("CampusCode") + "或" + RSL.Get("CampusName") + ",请核查。");
  188. }
  189. //事务提交
  190. UnitOfWork.Commit();
  191. }
  192. catch (Exception ex)
  193. {
  194. throw new Exception(ex.Message);
  195. }
  196. }
  197. /// <summary>
  198. /// 删除
  199. /// </summary>
  200. /// <param name="campusIDList"></param>
  201. /// <returns></returns>
  202. public bool CampusDelete(List<Guid?> campusIDList)
  203. {
  204. try
  205. {
  206. UnitOfWork.Remove<CF_CampusProfile>(x => campusIDList.Contains(x.CampusID));
  207. UnitOfWork.Remove<CF_Campus>(x => campusIDList.Contains(x.CampusID));
  208. UnitOfWork.Commit();
  209. return true;
  210. }
  211. catch (Exception)
  212. {
  213. throw;
  214. }
  215. }
  216. /// <summary>
  217. /// 查询校区对应的院系所信息CollegeView
  218. /// </summary>
  219. /// <param name="configuretView"></param>
  220. /// <param name="campusID"></param>
  221. /// <param name="unitCategoryID"></param>
  222. /// <param name="pageIndex"></param>
  223. /// <param name="pageSize"></param>
  224. /// <returns></returns>
  225. public IGridResultSet<CollegeView> GetCollegeListViewGrid(ConfiguretView configuretView, Guid? campusID, int? unitCategoryID, int pageIndex, int pageSize)
  226. {
  227. Expression<Func<CF_Campus, bool>> expCampus = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  228. expCampus = expCampus.And(x => x.CampusID == campusID);
  229. var query = CampusDAL.GetCollegeViewQueryable(expCampus);
  230. if (unitCategoryID.HasValue)
  231. {
  232. query = query.Where(x => x.UnitCategoryID == unitCategoryID);
  233. }
  234. //查询条件
  235. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  236. {
  237. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  238. }
  239. return query.OrderBy(x => x.No.Length).ThenBy(x => x.No).ToGridResultSet<CollegeView>(pageIndex, pageSize);
  240. }
  241. /// <summary>
  242. /// 查询校区对应的院系所信息List
  243. /// </summary>
  244. /// <param name="configuretView"></param>
  245. /// <param name="campusID"></param>
  246. /// <param name="unitCategoryID"></param>
  247. /// <returns></returns>
  248. public IList<CollegeView> GetCollegeListViewList(ConfiguretView configuretView, Guid? campusID, int? unitCategoryID)
  249. {
  250. Expression<Func<CF_Campus, bool>> expCampus = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  251. expCampus = expCampus.And(x => x.CampusID == campusID);
  252. var query = CampusDAL.GetCollegeViewQueryable(expCampus);
  253. if (unitCategoryID.HasValue)
  254. {
  255. query = query.Where(x => x.UnitCategoryID == unitCategoryID);
  256. }
  257. //查询条件
  258. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  259. {
  260. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  261. }
  262. return query.OrderBy(x => x.No.Length).ThenBy(x => x.No).ToList();
  263. }
  264. }
  265. }