UniversityServices.cs 16 KB

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