PlanApplicationApproveServices.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Linq.Expressions;
  6. using System.Transactions;
  7. using Bowin.Common.Linq;
  8. using Bowin.Common.Linq.Entity;
  9. using EMIS.Entities;
  10. using EMIS.ViewModel;
  11. using EMIS.ViewModel.WorkflowManage;
  12. using EMIS.ViewModel.CultureplanManage.PlanManagement;
  13. using EMIS.DataLogic.CultureplanManage.PlanManagement;
  14. using EMIS.CommonLogic.SystemServices;
  15. namespace EMIS.CommonLogic.CultureplanManage.PlanManagement
  16. {
  17. public class PlanApplicationApproveServices : BaseWorkflowServices<EM_PlanApplication>, IPlanApplicationApproveServices
  18. {
  19. public PlanApplicationDAL PlanApplicationDAL { get; set; }
  20. /// <summary>
  21. /// 查询对应的计划审核信息PlanApplicationView
  22. /// 注:普教版本(年级专业)
  23. /// </summary>
  24. /// <param name="configuretView"></param>
  25. /// <param name="schoolyearID"></param>
  26. /// <param name="campusID"></param>
  27. /// <param name="collegeID"></param>
  28. /// <param name="yearID"></param>
  29. /// <param name="standardID"></param>
  30. /// <param name="educationID"></param>
  31. /// <param name="learningformID"></param>
  32. /// <param name="learnSystem"></param>
  33. /// <param name="grademajorID"></param>
  34. /// <param name="coursematerialID"></param>
  35. /// <param name="handleModeID"></param>
  36. /// <param name="approvalStatus"></param>
  37. /// <param name="pageIndex"></param>
  38. /// <param name="pageSize"></param>
  39. /// <returns></returns>
  40. public IGridResultSet<PlanApplicationView> GetPlanApplicationApproveViewGrid(ConfiguretView configuretView, Guid? schoolyearID,
  41. Guid? campusID, Guid? collegeID, int? yearID, int? standardID, int? educationID, int? learningformID, string learnSystem,
  42. Guid? grademajorID, Guid? coursematerialID, int? handleModeID, int? approvalStatus, int pageIndex, int pageSize)
  43. {
  44. var approveStatusList = this.GetApproveStatusViewList();
  45. var approveStatusIDList = approveStatusList.Select(x => x.ID).ToList();
  46. //计划申请
  47. Expression<Func<EM_PlanApplication, bool>> expPlanApplication = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  48. expPlanApplication = expPlanApplication.And(x => approveStatusIDList.Contains(x.RecordStatus));
  49. if (schoolyearID.HasValue)
  50. {
  51. expPlanApplication = expPlanApplication.And(x => x.SchoolyearID == schoolyearID);
  52. }
  53. if (grademajorID.HasValue)
  54. {
  55. expPlanApplication = expPlanApplication.And(x => x.GrademajorID == grademajorID);
  56. }
  57. if (coursematerialID.HasValue)
  58. {
  59. expPlanApplication = expPlanApplication.And(x => x.CoursematerialID == coursematerialID);
  60. }
  61. if (handleModeID.HasValue)
  62. {
  63. expPlanApplication = expPlanApplication.And(x => x.HandleModeID == handleModeID);
  64. }
  65. if (approvalStatus.HasValue)
  66. {
  67. expPlanApplication = expPlanApplication.And(x => x.RecordStatus == approvalStatus);
  68. }
  69. var query = PlanApplicationDAL.GetPlanApplicationViewQueryable(expPlanApplication);
  70. if (campusID.HasValue)
  71. {
  72. query = query.Where(x => x.CampusID == campusID);
  73. }
  74. if (collegeID.HasValue)
  75. {
  76. query = query.Where(x => x.CollegeID == collegeID);
  77. }
  78. if (yearID.HasValue)
  79. {
  80. query = query.Where(x => x.GradeID == yearID);
  81. }
  82. if (standardID.HasValue)
  83. {
  84. query = query.Where(x => x.StandardID == standardID);
  85. }
  86. if (educationID.HasValue)
  87. {
  88. query = query.Where(x => x.EducationID == educationID);
  89. }
  90. if (learningformID.HasValue)
  91. {
  92. query = query.Where(x => x.LearningformID == learningformID);
  93. }
  94. if (!string.IsNullOrEmpty(learnSystem) && learnSystem != "-1")
  95. {
  96. var LearnSystems = Convert.ToDecimal(learnSystem);
  97. query = query.Where(x => x.LearnSystem == LearnSystems);
  98. }
  99. //查询条件
  100. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  101. {
  102. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  103. }
  104. var result = this.GetQueryByDataRangeByCollege(query)
  105. .OrderBy(x => x.GrademajorCode.Length).ThenBy(x => x.GrademajorCode)
  106. .ThenBy(x => x.Value).ThenBy(x => x.CourseTypeID)
  107. .ThenBy(x => x.CourseCode.Length).ThenBy(x => x.CourseCode)
  108. .ThenByDescending(x => x.CreateTime).ToGridResultSet<PlanApplicationView>(pageIndex, pageSize);
  109. result.rows.ForEach(x => x.ApprovalStatusName = approveStatusList.FirstOrDefault(w => w.ID == x.ApprovalStatus).Name);
  110. return result;
  111. }
  112. /// <summary>
  113. /// 查询对应的计划审核信息List
  114. /// 注:普教版本(年级专业)
  115. /// </summary>
  116. /// <param name="configuretView"></param>
  117. /// <param name="schoolyearID"></param>
  118. /// <param name="campusID"></param>
  119. /// <param name="collegeID"></param>
  120. /// <param name="yearID"></param>
  121. /// <param name="standardID"></param>
  122. /// <param name="educationID"></param>
  123. /// <param name="learningformID"></param>
  124. /// <param name="learnSystem"></param>
  125. /// <param name="grademajorID"></param>
  126. /// <param name="coursematerialID"></param>
  127. /// <param name="handleModeID"></param>
  128. /// <param name="approvalStatus"></param>
  129. /// <returns></returns>
  130. public IList<PlanApplicationView> GetPlanApplicationApproveViewList(ConfiguretView configuretView, Guid? schoolyearID,
  131. Guid? campusID, Guid? collegeID, int? yearID, int? standardID, int? educationID, int? learningformID, string learnSystem,
  132. Guid? grademajorID, Guid? coursematerialID, int? handleModeID, int? approvalStatus)
  133. {
  134. var approveStatusList = this.GetApproveStatusViewList();
  135. var approveStatusIDList = approveStatusList.Select(x => x.ID).ToList();
  136. //计划申请
  137. Expression<Func<EM_PlanApplication, bool>> expPlanApplication = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  138. expPlanApplication = expPlanApplication.And(x => approveStatusIDList.Contains(x.RecordStatus));
  139. if (schoolyearID.HasValue)
  140. {
  141. expPlanApplication = expPlanApplication.And(x => x.SchoolyearID == schoolyearID);
  142. }
  143. if (grademajorID.HasValue)
  144. {
  145. expPlanApplication = expPlanApplication.And(x => x.GrademajorID == grademajorID);
  146. }
  147. if (coursematerialID.HasValue)
  148. {
  149. expPlanApplication = expPlanApplication.And(x => x.CoursematerialID == coursematerialID);
  150. }
  151. if (handleModeID.HasValue)
  152. {
  153. expPlanApplication = expPlanApplication.And(x => x.HandleModeID == handleModeID);
  154. }
  155. if (approvalStatus.HasValue)
  156. {
  157. expPlanApplication = expPlanApplication.And(x => x.RecordStatus == approvalStatus);
  158. }
  159. var query = PlanApplicationDAL.GetPlanApplicationViewQueryable(expPlanApplication);
  160. if (campusID.HasValue)
  161. {
  162. query = query.Where(x => x.CampusID == campusID);
  163. }
  164. if (collegeID.HasValue)
  165. {
  166. query = query.Where(x => x.CollegeID == collegeID);
  167. }
  168. if (yearID.HasValue)
  169. {
  170. query = query.Where(x => x.GradeID == yearID);
  171. }
  172. if (standardID.HasValue)
  173. {
  174. query = query.Where(x => x.StandardID == standardID);
  175. }
  176. if (educationID.HasValue)
  177. {
  178. query = query.Where(x => x.EducationID == educationID);
  179. }
  180. if (learningformID.HasValue)
  181. {
  182. query = query.Where(x => x.LearningformID == learningformID);
  183. }
  184. if (!string.IsNullOrEmpty(learnSystem) && learnSystem != "-1")
  185. {
  186. var LearnSystems = Convert.ToDecimal(learnSystem);
  187. query = query.Where(x => x.LearnSystem == LearnSystems);
  188. }
  189. //查询条件
  190. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  191. {
  192. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  193. }
  194. var result = this.GetQueryByDataRangeByCollege(query)
  195. .OrderBy(x => x.GrademajorCode.Length).ThenBy(x => x.GrademajorCode)
  196. .ThenBy(x => x.Value).ThenBy(x => x.CourseTypeID)
  197. .ThenBy(x => x.CourseCode.Length).ThenBy(x => x.CourseCode)
  198. .ThenByDescending(x => x.CreateTime).ToList();
  199. result.ForEach(x => x.ApprovalStatusName = approveStatusList.FirstOrDefault(w => w.ID == x.ApprovalStatus).Name);
  200. return result;
  201. }
  202. /// <summary>
  203. /// 查询对应的计划审核信息PlanApplicationView(根据计划申请ID)
  204. /// </summary>
  205. /// <param name="planApplicationID"></param>
  206. /// <returns></returns>
  207. public PlanApplicationView GetPlanApplicationApproveView(Guid? planApplicationID)
  208. {
  209. try
  210. {
  211. var planApplicationView = PlanApplicationDAL.GetPlanApplicationViewQueryable(x => x.PlanApplicationID == planApplicationID).SingleOrDefault();
  212. return planApplicationView;
  213. }
  214. catch (Exception ex)
  215. {
  216. throw new Exception(ex.Message);
  217. }
  218. }
  219. /// <summary>
  220. /// 编辑(新增、修改)
  221. /// </summary>
  222. /// <param name="planApplicationView"></param>
  223. public void PlanApplicationApproveEdit(PlanApplicationView planApplicationView)
  224. {
  225. throw new NotImplementedException();
  226. }
  227. /// <summary>
  228. /// 查询对应的流程环节动作List(ActionView)
  229. /// </summary>
  230. /// <param name="formID"></param>
  231. /// <param name="userID"></param>
  232. /// <returns></returns>
  233. public List<ActionView> GetApproveActionView(Guid formID, Guid userID)
  234. {
  235. try
  236. {
  237. List<ActionView> listAction = this.GetActionView(formID, userID);
  238. return listAction;
  239. }
  240. catch (Exception ex)
  241. {
  242. throw new Exception(ex.Message);
  243. }
  244. }
  245. /// <summary>
  246. /// 删除
  247. /// </summary>
  248. /// <param name="planApplicationIDs"></param>
  249. /// <returns></returns>
  250. public bool PlanApplicationApproveDelete(List<Guid?> planApplicationIDs)
  251. {
  252. try
  253. {
  254. using (TransactionScope ts = new TransactionScope())
  255. {
  256. UnitOfWork.Delete<EM_PlanApplicationTeachingPlace>(x => planApplicationIDs.Contains(x.PlanApplicationID));
  257. UnitOfWork.Delete<EM_PlanApplicationTeachingModeType>(x => planApplicationIDs.Contains(x.PlanApplicationID));
  258. UnitOfWork.Delete<EM_PlanApplicationTeachingSetting>(x => planApplicationIDs.Contains(x.PlanApplicationID));
  259. UnitOfWork.Delete<EM_PlanApplication>(x => planApplicationIDs.Contains(x.PlanApplicationID));
  260. ts.Complete();
  261. return true;
  262. }
  263. }
  264. catch (Exception)
  265. {
  266. throw;
  267. }
  268. }
  269. /// <summary>
  270. /// 审核确定(批量)
  271. /// </summary>
  272. /// <param name="planApplicationIDs"></param>
  273. /// <param name="userID"></param>
  274. /// <param name="actionID"></param>
  275. /// <param name="comment"></param>
  276. /// <returns></returns>
  277. public string PlanApplicationApproveConfirm(List<Guid?> planApplicationIDs, Guid userID, Guid actionID, string comment)
  278. {
  279. try
  280. {
  281. //查询对应的工作流程环节状态信息View
  282. var approveStatusList = this.GetStatusViewList();
  283. if (approveStatusList == null || approveStatusList.Count() <= 0)
  284. {
  285. throw new Exception("工作流平台中,专业计划流程未配置,请核查。");
  286. }
  287. //查询工作流程结束环节状态
  288. var endStatusID = this.GetCorrectEndStatus();
  289. if (endStatusID == null)
  290. {
  291. throw new Exception("工作流平台中,专业计划流程结束环节未配置,请核查。");
  292. }
  293. //查询对应的计划申请信息List
  294. var planApplicationList = PlanApplicationDAL.PlanApplicationRepository
  295. .GetList(x => planApplicationIDs.Contains(x.PlanApplicationID), (x => x.EM_PlanApplicationTeachingSetting)).ToList();
  296. //计划申请信息对应的grademajorIDList
  297. var grademajorIDList = planApplicationList.Where(x => !string.IsNullOrEmpty(x.GrademajorID.ToString()))
  298. .Select(x => x.GrademajorID).ToList();
  299. //查询对应的专业计划信息
  300. var specialtyPlanList = PlanApplicationDAL.SpecialtyPlanRepository
  301. .GetList(x => grademajorIDList.Contains(x.GrademajorID), (x => x.EM_SpecialtyPlanTeachingSetting)).ToList();
  302. int success = 0; //成功
  303. int fail = 0; //失败
  304. string tipMessage = null; //提示消息
  305. var approveIDList = new List<Guid>();
  306. foreach (var planApplication in planApplicationList)
  307. {
  308. //查询对应的计划审核信息(业务主键:学年学期ID、年级专业ID、课程信息ID)
  309. var specialtyPlan = specialtyPlanList.Where(x => x.SchoolyearID == planApplication.SchoolyearID
  310. && x.GrademajorID == planApplication.GrademajorID
  311. && x.CoursematerialID == planApplication.CoursematerialID).SingleOrDefault();
  312. if (specialtyPlan == null)
  313. {
  314. approveIDList.Add(planApplication.PlanApplicationID);
  315. success++;
  316. }
  317. else
  318. {
  319. fail++;
  320. }
  321. }
  322. if (approveIDList.Count > 0)
  323. {
  324. //审核
  325. this.Approve(approveIDList, userID, actionID, comment);
  326. }
  327. if (success > 0 && fail <= 0)
  328. {
  329. tipMessage = success + "条";
  330. }
  331. else
  332. {
  333. tipMessage = success + "条," + fail + "条失败,原因:已存在相同的专业计划信息,请检查。";
  334. }
  335. return tipMessage;
  336. }
  337. catch (Exception ex)
  338. {
  339. throw new Exception(ex.Message);
  340. }
  341. }
  342. /// <summary>
  343. /// 查询计划审核对应的授课方式List
  344. /// </summary>
  345. /// <param name="planApplicationID"></param>
  346. /// <returns></returns>
  347. public List<string> GetTeachingModeTypeList(Guid? planApplicationID)
  348. {
  349. //计划申请
  350. Expression<Func<EM_PlanApplication, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  351. exp = exp.And(x => x.PlanApplicationID == planApplicationID);
  352. var query = PlanApplicationDAL.GetTeachingModeTypeQueryble(exp);
  353. return query.OrderBy(x => x.Value).Select(x => x.ToString()).ToList();
  354. }
  355. /// <summary>
  356. /// 查询计划审核对应的授课地点List
  357. /// </summary>
  358. /// <param name="planApplicationID"></param>
  359. /// <returns></returns>
  360. public List<string> GetTeachingPlaceList(Guid? planApplicationID)
  361. {
  362. //计划申请
  363. Expression<Func<EM_PlanApplication, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  364. exp = exp.And(x => x.PlanApplicationID == planApplicationID);
  365. var query = PlanApplicationDAL.GetTeachingPlaceQueryble(exp);
  366. return query.OrderBy(x => x.Value).Select(x => x.ToString()).ToList();
  367. }
  368. }
  369. }