UniversityServices.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  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.Entity;
  7. using EMIS.Entities;
  8. using EMIS.ViewModel;
  9. using EMIS.ViewModel.UniversityManage.AdministrativeOrgan;
  10. using EMIS.DataLogic.UniversityManage.AdministrativeOrgan;
  11. namespace EMIS.CommonLogic.UniversityManage.AdministrativeOrgan
  12. {
  13. public class UniversityServices : BaseServices, IUniversityServices
  14. {
  15. public UniversityDAL UniversityDAL { get; set; }
  16. /// <summary>
  17. /// 查询学校信息View
  18. /// </summary>
  19. /// <param name="configuretView"></param>
  20. /// <param name="pageIndex"></param>
  21. /// <param name="pageSize"></param>
  22. /// <returns></returns>
  23. public IGridResultSet<UniversityView> GetUniversityViewGrid(ConfiguretView configuretView, int pageIndex, int pageSize)
  24. {
  25. Expression<Func<CF_University, bool>> expUniversity = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  26. var query = UniversityDAL.GetUniversityViewQueryable(expUniversity);
  27. //查询条件
  28. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  29. {
  30. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  31. }
  32. return query.OrderBy(x => x.Code.Length).ThenBy(x => x.Code).ToGridResultSet<UniversityView>(pageIndex, pageSize);
  33. }
  34. /// <summary>
  35. /// 查询学校信息List
  36. /// </summary>
  37. /// <param name="configuretView"></param>
  38. /// <returns></returns>
  39. public IList<UniversityView> GetUniversityViewList(ConfiguretView configuretView)
  40. {
  41. Expression<Func<CF_University, bool>> expUniversity = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  42. var query = UniversityDAL.GetUniversityViewQueryable(expUniversity);
  43. //查询条件
  44. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  45. {
  46. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  47. }
  48. return query.OrderBy(x => x.Code.Length).ThenBy(x => x.Code).ToList();
  49. }
  50. /// <summary>
  51. /// 查询全部学校信息CF_University
  52. /// </summary>
  53. /// <returns></returns>
  54. public List<CF_University> GetUniversityList()
  55. {
  56. Expression<Func<CF_University, bool>> expUniversity = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  57. var query = UniversityDAL.UniversityRepository.GetList(expUniversity);
  58. return query.OrderBy(x => x.Code.Length).ThenBy(x => x.Code).ToList();
  59. }
  60. /// <summary>
  61. /// 查询对应的学校信息UniversityView
  62. /// </summary>
  63. /// <param name="universityID"></param>
  64. /// <returns></returns>
  65. public UniversityView GetUniversityView(Guid? universityID)
  66. {
  67. try
  68. {
  69. var query = UniversityDAL.GetUniversityViewQueryable(x => x.UniversityID == universityID).SingleOrDefault();
  70. return query;
  71. }
  72. catch (Exception ex)
  73. {
  74. throw new Exception(ex.Message);
  75. }
  76. }
  77. /// <summary>
  78. /// 编辑(新增、修改,业务主键:学校代码或学校名称)
  79. /// </summary>
  80. /// <param name="universityView"></param>
  81. public void UniversityEdit(UniversityView universityView)
  82. {
  83. try
  84. {
  85. //查询数据库进行验证
  86. var universityVerify = UniversityDAL.UniversityRepository.GetList(x => x.UniversityID != universityView.UniversityID
  87. && (x.Code == universityView.Code || x.Name == universityView.Name)).FirstOrDefault();
  88. if (universityVerify == null)
  89. {
  90. //数据有误验证
  91. if (universityView.UniversityID != Guid.Empty)
  92. {
  93. var university = UniversityDAL.UniversityRepository.GetList(x => x.UniversityID == universityView.UniversityID, (x => x.CF_UniversityProfile)).SingleOrDefault();
  94. if (university == null)
  95. {
  96. throw new Exception("数据有误,请核查。");
  97. }
  98. else
  99. {
  100. //表示修改
  101. university.Code = universityView.Code;
  102. university.Name = universityView.Name;
  103. university.SimpleName = universityView.SimpleName;
  104. university.EnglishName = universityView.EnglishName;
  105. university.Remark = universityView.Remark;
  106. SetModifyStatus(university);
  107. //学校信息扩展表
  108. if (university.CF_UniversityProfile == null)
  109. {
  110. //新增
  111. var newUniversityProfile = new CF_UniversityProfile();
  112. newUniversityProfile.UniversityID = universityView.UniversityID;
  113. newUniversityProfile.ProvinceID = universityView.ProvinceID;
  114. newUniversityProfile.CityID = universityView.CityID;
  115. newUniversityProfile.DistrictID = universityView.DistrictID;
  116. newUniversityProfile.PropertyID = universityView.PropertyID;
  117. newUniversityProfile.SchoolTypeID = universityView.SchoolTypeID;
  118. newUniversityProfile.ManagerID = universityView.ManagerID;
  119. newUniversityProfile.FounderTypeID = universityView.FounderTypeID;
  120. newUniversityProfile.SchoolLevelID = universityView.SchoolLevelID;
  121. newUniversityProfile.HeadMasterName = universityView.HeadMasterName;
  122. newUniversityProfile.PartyManageID = universityView.PartyManageID;
  123. newUniversityProfile.LegalPersonName = universityView.LegalPersonName;
  124. newUniversityProfile.BuildDate = universityView.BuildDate;
  125. newUniversityProfile.AnniversaryDate = universityView.AnniversaryDate;
  126. newUniversityProfile.SchoolBasis = universityView.SchoolBasis;
  127. newUniversityProfile.SchoolMotto = universityView.SchoolMotto;
  128. newUniversityProfile.SubjectCount = universityView.SubjectCount;
  129. newUniversityProfile.Is211University = universityView.Is211University;
  130. newUniversityProfile.IsKeyUniversity = universityView.IsKeyUniversity;
  131. newUniversityProfile.IsAdultCollege = universityView.IsAdultCollege;
  132. newUniversityProfile.IsPostCollege = universityView.IsPostCollege;
  133. newUniversityProfile.IsNetCollege = universityView.IsNetCollege;
  134. newUniversityProfile.Telephone = universityView.Telephone;
  135. newUniversityProfile.ZIPCode = universityView.ZIPCode;
  136. newUniversityProfile.Email = universityView.Email;
  137. newUniversityProfile.FAX = universityView.FAX;
  138. newUniversityProfile.PublicNum = universityView.PublicNum;
  139. newUniversityProfile.HomePage = universityView.HomePage;
  140. newUniversityProfile.Address = universityView.Address;
  141. newUniversityProfile.EnglishAddress = universityView.EnglishAddress;
  142. newUniversityProfile.HistoryEvolution = universityView.HistoryEvolution;
  143. SetNewStatus(newUniversityProfile);
  144. UnitOfWork.Add(newUniversityProfile);
  145. }
  146. else
  147. {
  148. //修改
  149. university.CF_UniversityProfile.ProvinceID = universityView.ProvinceID;
  150. university.CF_UniversityProfile.CityID = universityView.CityID;
  151. university.CF_UniversityProfile.DistrictID = universityView.DistrictID;
  152. university.CF_UniversityProfile.PropertyID = universityView.PropertyID;
  153. university.CF_UniversityProfile.SchoolTypeID = universityView.SchoolTypeID;
  154. university.CF_UniversityProfile.ManagerID = universityView.ManagerID;
  155. university.CF_UniversityProfile.FounderTypeID = universityView.FounderTypeID;
  156. university.CF_UniversityProfile.SchoolLevelID = universityView.SchoolLevelID;
  157. university.CF_UniversityProfile.HeadMasterName = universityView.HeadMasterName;
  158. university.CF_UniversityProfile.PartyManageID = universityView.PartyManageID;
  159. university.CF_UniversityProfile.LegalPersonName = universityView.LegalPersonName;
  160. university.CF_UniversityProfile.BuildDate = universityView.BuildDate;
  161. university.CF_UniversityProfile.AnniversaryDate = universityView.AnniversaryDate;
  162. university.CF_UniversityProfile.SchoolBasis = universityView.SchoolBasis;
  163. university.CF_UniversityProfile.SchoolMotto = universityView.SchoolMotto;
  164. university.CF_UniversityProfile.SubjectCount = universityView.SubjectCount;
  165. university.CF_UniversityProfile.Is211University = universityView.Is211University;
  166. university.CF_UniversityProfile.IsKeyUniversity = universityView.IsKeyUniversity;
  167. university.CF_UniversityProfile.IsAdultCollege = universityView.IsAdultCollege;
  168. university.CF_UniversityProfile.IsPostCollege = universityView.IsPostCollege;
  169. university.CF_UniversityProfile.IsNetCollege = universityView.IsNetCollege;
  170. university.CF_UniversityProfile.Telephone = universityView.Telephone;
  171. university.CF_UniversityProfile.ZIPCode = universityView.ZIPCode;
  172. university.CF_UniversityProfile.Email = universityView.Email;
  173. university.CF_UniversityProfile.FAX = universityView.FAX;
  174. university.CF_UniversityProfile.PublicNum = universityView.PublicNum;
  175. university.CF_UniversityProfile.HomePage = universityView.HomePage;
  176. university.CF_UniversityProfile.Address = universityView.Address;
  177. university.CF_UniversityProfile.EnglishAddress = universityView.EnglishAddress;
  178. university.CF_UniversityProfile.HistoryEvolution = universityView.HistoryEvolution;
  179. SetModifyStatus(university.CF_UniversityProfile);
  180. }
  181. }
  182. }
  183. else
  184. {
  185. //表示新增(CF_University主表)
  186. CF_University university = new CF_University();
  187. university.UniversityID = Guid.NewGuid();
  188. university.Code = universityView.Code;
  189. university.Name = universityView.Name;
  190. university.SimpleName = universityView.SimpleName;
  191. university.EnglishName = universityView.EnglishName;
  192. university.Remark = universityView.Remark;
  193. SetNewStatus(university);
  194. UnitOfWork.Add(university);
  195. //表示新增(CF_UniversityProfile扩展表)
  196. CF_UniversityProfile universityProfile = new CF_UniversityProfile();
  197. universityProfile.UniversityID = university.UniversityID;
  198. universityProfile.ProvinceID = universityView.ProvinceID;
  199. universityProfile.CityID = universityView.CityID;
  200. universityProfile.DistrictID = universityView.DistrictID;
  201. universityProfile.PropertyID = universityView.PropertyID;
  202. universityProfile.SchoolTypeID = universityView.SchoolTypeID;
  203. universityProfile.ManagerID = universityView.ManagerID;
  204. universityProfile.FounderTypeID = universityView.FounderTypeID;
  205. universityProfile.SchoolLevelID = universityView.SchoolLevelID;
  206. universityProfile.HeadMasterName = universityView.HeadMasterName;
  207. universityProfile.PartyManageID = universityView.PartyManageID;
  208. universityProfile.LegalPersonName = universityView.LegalPersonName;
  209. universityProfile.BuildDate = universityView.BuildDate;
  210. universityProfile.AnniversaryDate = universityView.AnniversaryDate;
  211. universityProfile.SchoolBasis = universityView.SchoolBasis;
  212. universityProfile.SchoolMotto = universityView.SchoolMotto;
  213. universityProfile.SubjectCount = universityView.SubjectCount;
  214. universityProfile.Is211University = universityView.Is211University;
  215. universityProfile.IsKeyUniversity = universityView.IsKeyUniversity;
  216. universityProfile.IsAdultCollege = universityView.IsAdultCollege;
  217. universityProfile.IsPostCollege = universityView.IsPostCollege;
  218. universityProfile.IsNetCollege = universityView.IsNetCollege;
  219. universityProfile.Telephone = universityView.Telephone;
  220. universityProfile.ZIPCode = universityView.ZIPCode;
  221. universityProfile.Email = universityView.Email;
  222. universityProfile.FAX = universityView.FAX;
  223. universityProfile.PublicNum = universityView.PublicNum;
  224. universityProfile.HomePage = universityView.HomePage;
  225. universityProfile.Address = universityView.Address;
  226. universityProfile.EnglishAddress = universityView.EnglishAddress;
  227. universityProfile.HistoryEvolution = universityView.HistoryEvolution;
  228. SetNewStatus(universityProfile);
  229. UnitOfWork.Add(universityProfile);
  230. }
  231. }
  232. else
  233. {
  234. throw new Exception("已存在相同的学校代码或学校名称,请核查。");
  235. }
  236. //事务提交
  237. UnitOfWork.Commit();
  238. }
  239. catch (Exception ex)
  240. {
  241. throw new Exception(ex.Message);
  242. }
  243. }
  244. /// <summary>
  245. /// 删除
  246. /// </summary>
  247. /// <param name="universityIDList"></param>
  248. /// <returns></returns>
  249. public bool UniversityDelete(List<Guid?> universityIDList)
  250. {
  251. try
  252. {
  253. UnitOfWork.Remove<CF_UniversityProfile>(x => universityIDList.Contains(x.UniversityID));
  254. UnitOfWork.Remove<CF_University>(x => universityIDList.Contains(x.UniversityID));
  255. UnitOfWork.Commit();
  256. return true;
  257. }
  258. catch (Exception)
  259. {
  260. throw;
  261. }
  262. }
  263. }
  264. }