TeachersOrderDAL.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using EMIS.DataLogic.Repositories;
  6. using EMIS.ViewModel.TeachingMaterial;
  7. using System.Linq.Expressions;
  8. using EMIS.Entities;
  9. using EMIS.ViewModel;
  10. namespace EMIS.DataLogic.Common.TeachingMaterial
  11. {
  12. public class TeachersOrderDAL
  13. {
  14. public TeachersOrderRepository TeachersOrderRepository { get; set; }
  15. public TeachersPreOrderRepository TeachersPreOrderRepository { get; set; }
  16. public TeachingMaterialPoolRepository TeachingMaterialPoolRepository { get; set; }
  17. public TeachersConfirmOrderRepository TeachersConfirmOrderRepository { get; set; }
  18. public UserRepository UserRepository { get; set; }
  19. public CoursematerialRepository CoursematerialRepository { get; set; }
  20. public PublishRepository PublishRepository { get; set; }
  21. public SchoolyearRepository SchoolyearRepository { get; set; }
  22. public CollegeRepository CollegeRepository { get; set; }
  23. public DictionaryItemRepository DictionaryItemRepository { get; set; }
  24. /// <summary>
  25. /// 获取征订信息列表
  26. /// </summary>
  27. /// <param name="exp"></param>
  28. /// <returns></returns>
  29. public IQueryable<TeachersOrderView> GetTeachingOrderGridView(Expression<Func<ET_TeachersOrder, bool>> exporder)
  30. {
  31. var view = (from to in TeachersOrderRepository.Entities.Where(exporder)
  32. join tm in TeachingMaterialPoolRepository.Entities on to.TeachingMaterialPoolID equals tm.TeachingMaterialPoolID
  33. join u in UserRepository.Entities on to.OrderUserID equals u.UserID
  34. join p in PublishRepository.Entities on tm.PublishID equals (Guid)p.PublishID
  35. join sl in SchoolyearRepository.Entities on to.SchoolyearID equals sl.SchoolyearID
  36. join cr in CollegeRepository.Entities on to.CollegeID equals cr.CollegeID
  37. select new TeachersOrderView
  38. {
  39. SchoolyearID = sl.SchoolyearID,
  40. SchoolyearName = sl.Code,
  41. TeachingMaterialCode = tm.TeachingMaterialCode,
  42. Author = tm.Author,
  43. CollegeID = cr.CollegeID,
  44. CollegeName = cr.Name,
  45. TeachingMaterialName = tm.TeachingMaterialName,
  46. TeachingMaterialTypeID = tm.TeachingMaterialTypeID,
  47. PublishTime = tm.PublishTime,
  48. TeachersOrderID = to.TeachersOrderID,
  49. TeachingMaterialPoolID = tm.TeachingMaterialPoolID,
  50. PublishName = p.UnitName,
  51. OrderLoginID = u.LoginID,
  52. OrderUserName = u.Name,
  53. OrderDate = to.OrderDate,
  54. OrderQty = to.OrderQty,
  55. OrderDesc = to.OrderDesc,
  56. ApproveStatus = (int)to.ApprovalStatus,
  57. CoursematerialEntityList = tm.EM_Coursematerial,
  58. PublishID = p.PublishID,
  59. CreateTime = to.CreateTime,
  60. CreateUserID = to.CreateUserID,
  61. ISBN = tm.ISBN,
  62. Price = tm.Price
  63. });
  64. return view;
  65. }
  66. /// <summary>
  67. /// 获取教材及征订信息列表
  68. /// </summary>
  69. /// <param name="exp"></param>
  70. /// <returns></returns>
  71. public IQueryable<TeachingMaterialPoolView> GetTeachingOrderByTeachingMaterialPoolGridView(Guid? teachersOrderID, Expression<Func<CF_TeachingMaterialPool, bool>> teachingMaterialPoolExp)
  72. {
  73. var view = (from to in TeachersOrderRepository.Entities.Where(x => x.TeachersOrderID == teachersOrderID)
  74. join tm in TeachingMaterialPoolRepository.GetList(teachingMaterialPoolExp) on to.TeachingMaterialPoolID equals tm.TeachingMaterialPoolID
  75. join u in UserRepository.Entities on to.OrderUserID equals u.UserID
  76. join p in PublishRepository.Entities on tm.PublishID equals (Guid)p.PublishID
  77. join sl in SchoolyearRepository.Entities on to.SchoolyearID equals sl.SchoolyearID
  78. join cr in CollegeRepository.Entities on to.CollegeID equals cr.CollegeID
  79. //join ct in DictionaryItemRepository.Entities on c.CourseScienceID equals ct.Value
  80. //join cl in DictionaryItemRepository.Entities on c.CourseLevelID equals cl.Value
  81. //join s in DictionaryItemRepository.Entities on to.ApprovalStatus equals s.Value
  82. select new TeachingMaterialPoolView
  83. {
  84. TeachingMaterialPoolID = tm.TeachingMaterialPoolID,
  85. TeachingMaterialCode = tm.TeachingMaterialCode,
  86. TeachingMaterialName = tm.TeachingMaterialName,
  87. TeachingMaterialShorName = tm.TeachingMaterialShorName,
  88. CoursematerialEntityList = tm.EM_Coursematerial,
  89. ISBN = tm.ISBN,
  90. PublishTime = tm.PublishTime,
  91. PublishName = p.UnitName,
  92. Author = tm.Author,
  93. Price = tm.Price,
  94. OrderQty = to.OrderQty,
  95. });
  96. return view;
  97. }
  98. /// <summary>
  99. /// 获取教师征订视图
  100. /// </summary>
  101. /// <returns></returns>
  102. public TeachersOrderView GetSingleTeachersOrderView(Guid teachersOrderID)
  103. {
  104. var teachersOrder = TeachersOrderRepository.GetSingle(x => x.TeachersOrderID == teachersOrderID,
  105. (x => x.CF_College), (x => x.CF_Schoolyear), (x => x.CF_TeachingMaterialPool),(x=>x.CF_TeachingMaterialPool.EM_Coursematerial));
  106. var teachersOrderView = new TeachersOrderView()
  107. {
  108. TeachingMaterialCode = teachersOrder.CF_TeachingMaterialPool.TeachingMaterialCode,
  109. CoursematerialEntityList = teachersOrder.CF_TeachingMaterialPool.EM_Coursematerial,
  110. TeachingMaterialName = teachersOrder.CF_TeachingMaterialPool.TeachingMaterialName,
  111. PublishTime = teachersOrder.CF_TeachingMaterialPool.PublishTime,
  112. PublishID = teachersOrder.CF_TeachingMaterialPool.PublishID,
  113. Author = teachersOrder.CF_TeachingMaterialPool.Author,
  114. ISBN = teachersOrder.CF_TeachingMaterialPool.ISBN,
  115. Price = teachersOrder.CF_TeachingMaterialPool.Price,
  116. OrderQty = teachersOrder.OrderQty,
  117. OrderDesc = teachersOrder.OrderDesc,
  118. SchoolyearID = teachersOrder.SchoolyearID,
  119. CollegeID = teachersOrder.CollegeID,
  120. CollegeName = teachersOrder.CF_College.Name,
  121. SchoolyearName=teachersOrder.CF_Schoolyear.Code,
  122. ApproveStatus=(int)teachersOrder.ApprovalStatus
  123. };
  124. return teachersOrderView;
  125. }
  126. /// <summary>
  127. /// 获取单个基本信息
  128. /// </summary>
  129. /// <returns></returns>
  130. public TeachersOrderView GetSingleTeachersOrderOneView(Guid teachersOrderID)
  131. {
  132. var teachersOrder = TeachersOrderRepository.GetSingle(x => x.TeachersOrderID == teachersOrderID,
  133. (x => x.CF_College), (x => x.CF_Schoolyear), (x => x.CF_TeachingMaterialPool));
  134. var teachersOrderView = new TeachersOrderView()
  135. {
  136. TeachingMaterialCode = teachersOrder.CF_TeachingMaterialPool.TeachingMaterialCode,
  137. CoursematerialEntityList = teachersOrder.CF_TeachingMaterialPool.EM_Coursematerial,
  138. TeachingMaterialName = teachersOrder.CF_TeachingMaterialPool.TeachingMaterialName,
  139. PublishTime = teachersOrder.CF_TeachingMaterialPool.PublishTime,
  140. PublishID = teachersOrder.CF_TeachingMaterialPool.PublishID,
  141. Author = teachersOrder.CF_TeachingMaterialPool.Author,
  142. ISBN = teachersOrder.CF_TeachingMaterialPool.ISBN,
  143. Price = teachersOrder.CF_TeachingMaterialPool.Price,
  144. OrderQty = teachersOrder.OrderQty
  145. };
  146. return teachersOrderView;
  147. }
  148. /// <summary>
  149. /// 获取单个教师征订记录
  150. /// </summary>
  151. /// <param name="teachersOrderID"></param>
  152. /// <returns></returns>
  153. public ET_TeachersOrder GetSingleTeachersOrder(Guid teachersOrderID)
  154. {
  155. return TeachersOrderRepository.GetSingle(x => x.TeachersOrderID == teachersOrderID);
  156. }
  157. /// <summary>
  158. /// 获取单个教师征订View
  159. /// </summary>
  160. /// <param name="teachersOrderID"></param>
  161. /// <returns></returns>
  162. public TeachersOrderView GetSingleTeachersOrderById(Guid teachersOrderID)
  163. {
  164. var teachersOrder = TeachersOrderRepository.GetSingle(x => x.TeachersOrderID == teachersOrderID);
  165. var teachersOrderView = new TeachersOrderView()
  166. {
  167. OrderQty = teachersOrder.OrderQty,
  168. TeachersOrderID = teachersOrder.TeachersOrderID,
  169. CollegeID = teachersOrder.CollegeID,
  170. CreateTime = teachersOrder.CreateTime,
  171. CreateUserID = teachersOrder.CreateUserID,
  172. OrderDate = teachersOrder.OrderDate,
  173. OrderDesc = teachersOrder.OrderDesc,
  174. OrderUserID = teachersOrder.OrderUserID,
  175. TeachingMaterialPoolID = teachersOrder.TeachingMaterialPoolID,
  176. SchoolyearID = teachersOrder.SchoolyearID
  177. };
  178. return teachersOrderView;
  179. }
  180. #region 复制征订数据到征订清单表(废弃)
  181. ///// <summary>
  182. ///// 复制征订数据到征订清单表
  183. ///// </summary>
  184. ///// <param name="teachersOrderIDs"></param>
  185. //public void CopyTeachersOrderInTeachersConfirmOrder(Guid teachersOrderID)
  186. //{
  187. // try
  188. // {
  189. // if (teachersOrderID != null && teachersOrderID != Guid.Empty)
  190. // {
  191. // ET_TeachersOrder teachersOrder = TeachersOrderRepository.GetSingle(x => x.TeachersOrderID == teachersOrderID && x.ApprovalStatus == (int)CF_TeachersOrderStatus.Completed);
  192. // if (teachersOrder != null)
  193. // {
  194. // ET_TeachersConfirmOrder teachersConfirmOrder = new ET_TeachersConfirmOrder
  195. // {
  196. // PreAddedValue = 5,//设置预加值、
  197. // TeachersOrderID = teachersOrder.TeachersOrderID,
  198. // CollegeID = teachersOrder.CollegeID,
  199. // CreateTime = DateTime.Now,
  200. // CreateUserID = teachersOrder.CreateUserID,
  201. // Desc = teachersOrder.Desc,
  202. // ModifyTime = DateTime.Now,
  203. // ModifyUserID = teachersOrder.ModifyUserID,
  204. // OrderDate = teachersOrder.OrderDate,
  205. // OrderDesc = teachersOrder.OrderDesc,
  206. // OrderQty = teachersOrder.OrderQty,
  207. // OrderUserID = teachersOrder.OrderUserID,
  208. // SchoolyearID = teachersOrder.SchoolyearID,
  209. // TeachingMaterialPoolID = teachersOrder.TeachingMaterialPoolID
  210. // };
  211. // TeachersConfirmOrderRepository.UnitOfWork.Add(teachersConfirmOrder);
  212. // TeachersConfirmOrderRepository.UnitOfWork.Commit();
  213. // }
  214. // }
  215. // }
  216. // catch (Exception ex)
  217. // {
  218. // throw ex;
  219. // }
  220. //}
  221. #endregion
  222. /// <summary>
  223. /// 获取教材总库信息列表、排除在教师征订表已存在的教材
  224. /// </summary>
  225. /// <param name="exp"></param>
  226. /// <returns></returns>
  227. public IQueryable<TeachingMaterialPoolView> GetTeachersOrderByTeachingMaterial(Expression<Func<CF_TeachingMaterialPool, bool>> exp)
  228. {
  229. //教材所有信息以教材总库表为准 其他都左联 --- 兵良提出
  230. var view = (from l in TeachingMaterialPoolRepository.Entities.Where(exp)
  231. //关联字典导致数据重复
  232. //join d in DictionaryItemRepository.Entities on l.TeachingMaterialTypeID equals d.Value
  233. // into td
  234. //from ctd in td.DefaultIfEmpty()
  235. join u in UserRepository.Entities on l.CreateUserID equals u.UserID
  236. into user
  237. from uu in user.DefaultIfEmpty()
  238. join p in PublishRepository.Entities on l.PublishID equals p.PublishID
  239. into pp
  240. from ppp in pp.DefaultIfEmpty()
  241. // join g in TeachersOrderRepository.Entities on l.TeachingMaterialPoolID equals g.TeachingMaterialPoolID
  242. // into teachingMaterialPool
  243. // from gteachingMaterialPool in teachingMaterialPool.DefaultIfEmpty()
  244. // where gteachingMaterialPool.TeachingMaterialPoolID ==null //在征订表不存在记录
  245. select new TeachingMaterialPoolView
  246. {
  247. Author = l.Author,
  248. ISBN = l.ISBN,
  249. CoursematerialEntityList = l.EM_Coursematerial,
  250. Price = l.Price,
  251. TeachingMaterialCode = l.TeachingMaterialCode,
  252. TeachingMaterialName = l.TeachingMaterialName,
  253. TeachingMaterialShorName = l.TeachingMaterialShorName,
  254. TeachingMaterialPoolID = l.TeachingMaterialPoolID,
  255. TeachingMaterialTypeID = l.TeachingMaterialTypeID,
  256. //TeachingMaterialTypeName = ctd.Name,
  257. PublishID = l.PublishID,
  258. PublishName = ppp.UnitName,
  259. PublishTime = l.PublishTime,
  260. CreateTime = l.CreateTime,
  261. CreateUserName = uu.Name,
  262. Desc = l.Desc,
  263. IsLate = l.IsLate.Value,
  264. ModifyTime = l.ModifyTime,
  265. IsLateName = l.IsLate == true ? "是" : "否",
  266. OrderQty = 1
  267. });
  268. return view;
  269. }
  270. public IQueryable<ET_TeachersPreOrder> GetPreOrderByTeachersOrderIDList(List<Guid> teacherOrderIDList)
  271. {
  272. var query = (from tpo in TeachersPreOrderRepository.Entities
  273. join to in TeachersOrderRepository.GetList(x => teacherOrderIDList.Contains(x.TeachersOrderID))
  274. on new { tpo.SchoolyearID, tpo.TeachingMaterialPoolID }
  275. equals new { to.SchoolyearID, to.TeachingMaterialPoolID }
  276. select tpo);
  277. return query;
  278. }
  279. }
  280. }