You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ArrangeLessonTermOfElectiveService.cs 48 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922
  1. using Dapper;
  2. using Learun.DataBase.Repository;
  3. using Learun.Util;
  4. using Newtonsoft.Json;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Data;
  8. using System.Linq;
  9. using System.Net.Http;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. namespace Learun.Application.TwoDevelopment.EducationalAdministration
  13. {
  14. /// <summary>
  15. /// 版 本 Learun-ADMS-Ultimate V7.0.0 数字化智慧校园
  16. /// Copyright (c) 2013-2018 北京泉江科技有限公司
  17. /// 创 建:超级管理员
  18. /// 日 期:2019-05-14 09:49
  19. /// 描 述:选修课排课
  20. /// </summary>
  21. public class ArrangeLessonTermOfElectiveService : RepositoryFactory
  22. {
  23. private static readonly HttpClient Client;
  24. static ArrangeLessonTermOfElectiveService()
  25. {
  26. Client = new HttpClient();
  27. }
  28. #region 获取数据
  29. /// <summary>
  30. /// 获取页面显示列表数据
  31. /// <summary>
  32. /// <param name="queryJson">查询参数</param>
  33. /// <returns></returns>
  34. public IEnumerable<ArrangeLessonTermOfElectiveEntity> GetPageList(Pagination pagination, string queryJson)
  35. {
  36. try
  37. {
  38. var strSql = new StringBuilder();
  39. strSql.Append("SELECT ");
  40. strSql.Append(@"
  41. t.Id,
  42. t.PaiKeId,
  43. t.LessonDate,
  44. t.AcademicYearNo,
  45. t.Semester,
  46. t.LessonNo,
  47. t.LessonName,
  48. t.LessonSortNo,
  49. t.LessonSection,
  50. t.LessonTime,
  51. t.StudyScore,
  52. t.EmpNo,
  53. t.EmpName,
  54. t.ClassRoomNo,
  55. t.ClassRoomName,
  56. t.CheckMark
  57. ");
  58. strSql.Append(" FROM ArrangeLessonTermOfElective t ");
  59. strSql.Append(" WHERE 1=1 ");
  60. var queryParam = queryJson.ToJObject();
  61. // 虚拟参数
  62. var dp = new DynamicParameters(new { });
  63. return this.BaseRepository("CollegeMIS").FindList<ArrangeLessonTermOfElectiveEntity>(strSql.ToString(), dp, pagination);
  64. }
  65. catch (Exception ex)
  66. {
  67. if (ex is ExceptionEx)
  68. {
  69. throw;
  70. }
  71. else
  72. {
  73. throw ExceptionEx.ThrowServiceException(ex);
  74. }
  75. }
  76. }
  77. /// <summary>
  78. /// 获取ArrangeLessonTermOfElective表实体数据
  79. /// <param name="keyValue">主键</param>
  80. /// <summary>
  81. /// <returns></returns>
  82. public ArrangeLessonTermOfElectiveEntity GetArrangeLessonTermOfElectiveEntity(string keyValue)
  83. {
  84. try
  85. {
  86. return this.BaseRepository("CollegeMIS").FindEntity<ArrangeLessonTermOfElectiveEntity>(keyValue);
  87. }
  88. catch (Exception ex)
  89. {
  90. if (ex is ExceptionEx)
  91. {
  92. throw;
  93. }
  94. else
  95. {
  96. throw ExceptionEx.ThrowServiceException(ex);
  97. }
  98. }
  99. }
  100. #endregion
  101. #region 提交数据
  102. /// <summary>
  103. /// 删除实体数据
  104. /// <param name="keyValue">主键</param>
  105. /// <summary>
  106. /// <returns></returns>
  107. public void DeleteEntity(string keyValue)
  108. {
  109. try
  110. {
  111. this.BaseRepository("CollegeMIS").Delete<ArrangeLessonTermOfElectiveEntity>(t => t.Id == keyValue);
  112. }
  113. catch (Exception ex)
  114. {
  115. if (ex is ExceptionEx)
  116. {
  117. throw;
  118. }
  119. else
  120. {
  121. throw ExceptionEx.ThrowServiceException(ex);
  122. }
  123. }
  124. }
  125. /// <summary>
  126. /// 保存实体数据(新增、修改)
  127. /// <param name="keyValue">主键</param>
  128. /// <summary>
  129. /// <returns></returns>
  130. public void SaveEntity(string keyValue, ArrangeLessonTermOfElectiveEntity entity)
  131. {
  132. try
  133. {
  134. if (!string.IsNullOrEmpty(keyValue))
  135. {
  136. entity.Modify(keyValue);
  137. this.BaseRepository("CollegeMIS").Update(entity);
  138. }
  139. else
  140. {
  141. entity.Create();
  142. this.BaseRepository("CollegeMIS").Insert(entity);
  143. }
  144. }
  145. catch (Exception ex)
  146. {
  147. if (ex is ExceptionEx)
  148. {
  149. throw;
  150. }
  151. else
  152. {
  153. throw ExceptionEx.ThrowServiceException(ex);
  154. }
  155. }
  156. }
  157. #endregion
  158. #region 扩展数据
  159. /// <summary>
  160. /// 按条件同步选修排课系统数据
  161. /// </summary>
  162. /// <returns></returns>
  163. public async Task<bool> AsyncArrangeLessonOfElectiveDataByCondition(ArrangeLessonTermOfElectiveEntity entity)
  164. {
  165. bool result = false;
  166. try
  167. {
  168. HttpContent httpContent = new StringContent("{\"school\":\"" + entity.F_SchoolId + "\",\"year\":\"" + entity.AcademicYearNo + "\",\"number\":\"" + entity.Semester + "\"}");
  169. httpContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json");
  170. string apiData = await Client.PostAsync(Config.GetValue("ArrangeLessonOfElectiveAPI"), httpContent).Result.Content.ReadAsStringAsync();
  171. if (!string.IsNullOrEmpty(apiData))
  172. {
  173. var data = JsonConvert.DeserializeObject<Root>(apiData);
  174. if (!data.success)
  175. {
  176. return result;
  177. }
  178. var dataList = data.entity.list;
  179. if (dataList.Any())
  180. {
  181. //ArrangeLessonTermOfElective数据处理
  182. var insertDataList = new List<ArrangeLessonTermOfElectiveEntity>();
  183. var lessonData = (await BaseRepository("CollegeMIS").FindListAsync<LessonInfoEntity>()).ToList();
  184. var oldArrangeLessonTermOfElectiveDataList = BaseRepository("CollegeMIS")
  185. .FindList<ArrangeLessonTermOfElectiveEntity>(m => m.F_SchoolId == entity.F_SchoolId
  186. && m.AcademicYearNo == entity.AcademicYearNo && m.Semester == entity.Semester).ToList();
  187. foreach (var item in dataList)
  188. {
  189. if (!string.IsNullOrEmpty(item.paike.timeText))
  190. {
  191. foreach (var lessontime in item.paike.timeText.TrimEnd(',').Split(','))
  192. {
  193. string tmplessontime = "";
  194. if (item.paike.section == "7")
  195. {
  196. tmplessontime = "18:00-18:45";
  197. }
  198. if (item.paike.section == "8")
  199. {
  200. tmplessontime = "18:45-19:30";
  201. }
  202. if (item.paike.section == "9")
  203. {
  204. tmplessontime = "20:30-21:15";
  205. }
  206. if (item.paike.section == "10")
  207. {
  208. tmplessontime = "21:15-22:00";
  209. }
  210. var insertData = new ArrangeLessonTermOfElectiveEntity
  211. {
  212. Id = Guid.NewGuid().ToString(),
  213. PaiKeId = item.paike.id,
  214. LessonDate = DateTime.Parse(lessontime),
  215. AcademicYearNo = item.paike.year,
  216. Semester = item.paike.number,
  217. LessonNo = item.paike.curriculunNumber,
  218. LessonName = item.paike.curriculunName,
  219. LessonSortNo = "2",
  220. LessonTime = tmplessontime,
  221. LessonSection = item.paike.week + item.paike.section,
  222. StudyScore = lessonData.FirstOrDefault(x => x.LessonNo == item.paike.curriculunNumber)?.StudyScore,
  223. EmpNo = item.paike.teacherNumber,
  224. EmpName = item.paike.teacherName,
  225. ClassRoomNo = item.paike.classRoomNumber,
  226. ClassRoomName = item.paike.classRoomName,
  227. F_SchoolId = entity.F_SchoolId,
  228. CheckMark = "1"
  229. };
  230. if (oldArrangeLessonTermOfElectiveDataList.Count(m => m.AcademicYearNo == insertData.AcademicYearNo
  231. && m.Semester == insertData.Semester && m.LessonNo == insertData.LessonNo
  232. && m.LessonSection == insertData.LessonSection && m.EmpNo == insertData.EmpNo
  233. && m.ClassRoomNo == insertData.ClassRoomNo) == 0)
  234. {
  235. insertDataList.Add(insertData);
  236. }
  237. }
  238. }
  239. }
  240. var insertResult = await BaseRepository("CollegeMIS").InsertAsync(insertDataList);
  241. //OpenLessonPlanOfElective数据处理
  242. var strAcademicYear = entity.AcademicYearNo;
  243. var strSemester = entity.Semester;
  244. var schoolId = entity.F_SchoolId;
  245. var ArrangeLessonTermOfElectiveData = (await BaseRepository("CollegeMIS").FindListAsync<ArrangeLessonTermOfElectiveEntity>(@"select * from ArrangeLessonTermOfElective where AcademicYearNo='" + strAcademicYear + "' and Semester='" + strSemester + "' and F_SchoolId='" + schoolId + "'")).ToList();
  246. var arrangeLessonTermData = (await BaseRepository("CollegeMIS").FindListAsync<ArrangeLessonTermOfElectiveEntity>(@"select PaiKeId,AcademicYearNo,Semester,LessonNo,LessonName,LessonSection,EmpNo,EmpName,ClassRoomNo,ClassRoomName,F_SchoolId from ArrangeLessonTermOfElective where AcademicYearNo='" + strAcademicYear + "' and Semester='" + strSemester + "' and F_SchoolId='" + schoolId + "' group by PaiKeId, AcademicYearNo, Semester, LessonNo, LessonName, LessonSection, EmpNo, EmpName, ClassRoomNo, ClassRoomName,F_SchoolId ")).ToList();
  247. var OpenLessonPlanOfElectiveData = (await BaseRepository("CollegeMIS").FindListAsync<OpenLessonPlanOfElectiveEntity>(@"select * from OpenLessonPlanOfElective where AcademicYearNo='" + strAcademicYear + "' and Semester='" + strSemester + "' and F_SchoolId='" + schoolId + "'")).ToList();
  248. var insertOpenLessonPlanOfElectiveDataList = new List<OpenLessonPlanOfElectiveEntity>();
  249. if (arrangeLessonTermData.Any())
  250. {
  251. foreach (var item in arrangeLessonTermData)
  252. {
  253. var insertOpenLessonPlanOfElectiveData = new OpenLessonPlanOfElectiveEntity()
  254. {
  255. Id = item.PaiKeId,
  256. MakeDate = DateTime.Now,
  257. AcademicYearNo = item.AcademicYearNo,
  258. Semester = item.Semester,
  259. LessonNo = item.LessonNo,
  260. PartCode = "",
  261. LessonName = item.LessonName,
  262. LessonSortNo = lessonData.FirstOrDefault(x => x.LessonNo == item.LessonNo)?.LessonSortNo,
  263. LessonSortDetailNo = lessonData.FirstOrDefault(x => x.LessonNo == item.LessonNo)?.LessonSortDetailNo,
  264. LessonSection = item.LessonSection,
  265. LessonTime = ArrangeLessonTermOfElectiveData.FirstOrDefault(x => x.PaiKeId == item.PaiKeId)?.LessonTime,
  266. StudyScore = lessonData.FirstOrDefault(x => x.LessonNo == item.LessonNo)?.StudyScore,
  267. StartWeek = 1,
  268. EndWeek = ArrangeLessonTermOfElectiveData.Count(x => x.PaiKeId == item.PaiKeId),
  269. StartDate = ArrangeLessonTermOfElectiveData.Where(x => x.PaiKeId == item.PaiKeId).OrderBy(x => x.LessonDate).FirstOrDefault()?.LessonDate,
  270. EndDate = ArrangeLessonTermOfElectiveData.Where(x => x.PaiKeId == item.PaiKeId).OrderBy(x => x.LessonDate).LastOrDefault()?.LessonDate,
  271. CheckStyleNo = "1",
  272. ScoreRecordStyleNo = "1",
  273. EmpNo = item.EmpNo,
  274. EmpName = item.EmpName,
  275. ClassRoomNo = item.ClassRoomNo,
  276. ClassRoomName = item.ClassRoomName,
  277. CheckMark = "1",
  278. StuNumMax = 0,
  279. StuNum = 0,
  280. F_SchoolId = item.F_SchoolId
  281. };
  282. //非空判断
  283. if (OpenLessonPlanOfElectiveData.Count(x =>
  284. x.AcademicYearNo == insertOpenLessonPlanOfElectiveData.AcademicYearNo &&
  285. x.Semester == insertOpenLessonPlanOfElectiveData.Semester &&
  286. x.LessonNo == insertOpenLessonPlanOfElectiveData.LessonNo &&
  287. x.LessonSortNo == insertOpenLessonPlanOfElectiveData.LessonSortNo &&
  288. x.LessonSection == insertOpenLessonPlanOfElectiveData.LessonSection &&
  289. x.EmpNo == insertOpenLessonPlanOfElectiveData.EmpNo &&
  290. x.ClassRoomNo == insertOpenLessonPlanOfElectiveData.ClassRoomNo &&
  291. x.F_SchoolId == insertOpenLessonPlanOfElectiveData.F_SchoolId) == 0 && insertOpenLessonPlanOfElectiveDataList.Count(x =>
  292. x.AcademicYearNo == insertOpenLessonPlanOfElectiveData.AcademicYearNo &&
  293. x.Semester == insertOpenLessonPlanOfElectiveData.Semester &&
  294. x.LessonNo == insertOpenLessonPlanOfElectiveData.LessonNo &&
  295. x.LessonSortNo == insertOpenLessonPlanOfElectiveData.LessonSortNo &&
  296. x.LessonSection == insertOpenLessonPlanOfElectiveData.LessonSection &&
  297. x.EmpNo == insertOpenLessonPlanOfElectiveData.EmpNo &&
  298. x.ClassRoomNo == insertOpenLessonPlanOfElectiveData.ClassRoomNo &&
  299. x.F_SchoolId == insertOpenLessonPlanOfElectiveData.F_SchoolId) == 0)
  300. {
  301. if (BaseRepository("CollegeMIS").FindEntity<OpenLessonPlanOfElectiveEntity>(m => m.Id == insertOpenLessonPlanOfElectiveData.Id) == null
  302. && BaseRepository("CollegeMIS").FindEntity<OpenLessonPlanOfElectiveDelEntity>(m => m.Id == insertOpenLessonPlanOfElectiveData.Id) == null)
  303. {
  304. insertOpenLessonPlanOfElectiveDataList.Add(insertOpenLessonPlanOfElectiveData);
  305. }
  306. }
  307. }
  308. await BaseRepository("CollegeMIS").InsertAsync(insertOpenLessonPlanOfElectiveDataList);
  309. }
  310. if (insertResult > 0)
  311. {
  312. result = true;
  313. }
  314. }
  315. }
  316. }
  317. catch (Exception ex)
  318. {
  319. if (ex is ExceptionEx)
  320. {
  321. throw;
  322. }
  323. else
  324. {
  325. throw ExceptionEx.ThrowServiceException(ex);
  326. }
  327. }
  328. return result;
  329. }
  330. /// <summary>
  331. /// 按条件清空选修排课数据
  332. /// </summary>
  333. /// <returns></returns>
  334. public async Task<bool> AsyncModifyArrangeLessonOfElectiveDataByCondition(ArrangeLessonTermOfElectiveEntity entity)
  335. {
  336. var db = BaseRepository("CollegeMIS");
  337. bool result = false;
  338. try
  339. {
  340. db.BeginTrans();
  341. HttpContent httpContent = new StringContent("{\"school\":\"" + entity.F_SchoolId + "\",\"year\":\"" + entity.AcademicYearNo + "\",\"number\":\"" + entity.Semester + "\"}");
  342. httpContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json");
  343. string apiData = await Client.PostAsync(Config.GetValue("ModifyArrangeLessonOfElectiveAPI"), httpContent).Result.Content.ReadAsStringAsync();
  344. if (!string.IsNullOrEmpty(apiData))
  345. {
  346. var data = JsonConvert.DeserializeObject<Root>(apiData);
  347. if (data.success)
  348. {
  349. var strAcademicYear = entity.AcademicYearNo;
  350. var strSemester = entity.Semester;
  351. var schoolId = entity.F_SchoolId;
  352. await db.ExecuteAsyncBySql(
  353. $"delete from ElectiveMajor where OLPOEId in(select id from OpenLessonPlanOfElective where AcademicYearNo='{strAcademicYear}' and Semester='{strSemester}' and F_SchoolId='{schoolId}' ) or OLPOEId in (select id from OpenLessonPlanOfElectiveDel where AcademicYearNo='{strAcademicYear}' and Semester='{strSemester}' and F_SchoolId='{schoolId}' ) ");
  354. var executeResult = await db.ExecuteAsyncBySql(
  355. $"delete from ArrangeLessonTermOfElective where AcademicYearNo='{strAcademicYear}' and Semester='{strSemester}' and F_SchoolId='{schoolId}'");
  356. await db.ExecuteAsyncBySql(
  357. $"delete from OpenLessonPlanOfElective where AcademicYearNo='{strAcademicYear}' and Semester='{strSemester}' and F_SchoolId='{schoolId}'");
  358. await db.ExecuteAsyncBySql(
  359. $"delete from ElectiveMergeItem where emid in (select emid from ElectiveMerge where AcademicYearNo='{strAcademicYear}' and Semester='{strSemester}' and F_SchoolId='{schoolId}')");
  360. await db.ExecuteAsyncBySql(
  361. $"delete from ElectiveMerge where AcademicYearNo='{strAcademicYear}' and Semester='{strSemester}' and F_SchoolId='{schoolId}'");
  362. await db.ExecuteAsyncBySql(
  363. $"delete from OpenLessonPlanOfElectiveDel where AcademicYearNo='{strAcademicYear}' and Semester='{strSemester}' and F_SchoolId='{schoolId}'");
  364. await db.ExecuteAsyncBySql(
  365. $"delete from StuSelectLessonListOfElective where AcademicYearNo='{strAcademicYear}' and Semester='{strSemester}' and F_SchoolId='{schoolId}'");
  366. if (executeResult > 0)
  367. {
  368. result = true;
  369. }
  370. db.Commit();
  371. }
  372. }
  373. }
  374. catch (Exception ex)
  375. {
  376. db.Rollback();
  377. if (ex is ExceptionEx)
  378. {
  379. throw;
  380. }
  381. else
  382. {
  383. throw ExceptionEx.ThrowServiceException(ex);
  384. }
  385. }
  386. return result;
  387. }
  388. /// <summary>
  389. /// 同步当前学期选修排课系统数据
  390. /// </summary>
  391. /// <returns></returns>
  392. public async Task<bool> AsyncArrangeLessonOfElectiveData()
  393. {
  394. bool result = false;
  395. try
  396. {
  397. var apiData = await Client.GetStringAsync(Config.GetValue("ArrangeLessonOfElectiveAPI"));
  398. if (!string.IsNullOrEmpty(apiData))
  399. {
  400. var data = JsonConvert.DeserializeObject<Root>(apiData);
  401. if (!data.success)
  402. {
  403. return result;
  404. }
  405. var dataList = data.entity.list;
  406. if (dataList.Any())
  407. {
  408. //ArrangeLessonTermOfElective数据处理
  409. var insertDataList = new List<ArrangeLessonTermOfElectiveEntity>();
  410. var lessonData = (await BaseRepository("CollegeMIS").FindListAsync<LessonInfoEntity>()).ToList();
  411. foreach (var item in dataList)
  412. {
  413. var insertData = new ArrangeLessonTermOfElectiveEntity
  414. {
  415. Id = Guid.NewGuid().ToString(),
  416. PaiKeId = item.paike.id,
  417. LessonDate = DateTime.Parse(item.times),
  418. AcademicYearNo = item.schoolYear,
  419. Semester = item.paike.semester,
  420. LessonNo = item.paike.curriculunId,
  421. LessonName = item.paike.curriculunName,
  422. LessonSortNo = lessonData.FirstOrDefault(m => m.LessonNo == item.paike.curriculunId)?.LessonSortNo,
  423. LessonTime = item.paike.curriculunTime,
  424. LessonSection = item.paike.week + item.paike.section,
  425. StudyScore = lessonData.FirstOrDefault(x => x.LessonNo == item.paike.curriculunId)?.StudyScore,
  426. EmpNo = item.paike.teacherId,
  427. EmpName = item.paike.teacherName,
  428. ClassRoomNo = item.paike.classRoomId,
  429. ClassRoomName = item.paike.classRoomName,
  430. CheckMark = "1"
  431. };
  432. insertDataList.Add(insertData);
  433. }
  434. var insertResult = await BaseRepository("CollegeMIS").InsertAsync(insertDataList);
  435. //OpenLessonPlanOfElective数据处理
  436. var strAcademicYear = insertDataList.First().AcademicYearNo;
  437. var strSemester = insertDataList.First().Semester;
  438. var ArrangeLessonTermOfElectiveData = (await BaseRepository("CollegeMIS").FindListAsync<ArrangeLessonTermOfElectiveEntity>(@"select * from ArrangeLessonTermOfElective where AcademicYearNo='" + strAcademicYear + "' and Semester='" + strSemester + "'")).ToList();
  439. var arrangeLessonTermData = (await BaseRepository("CollegeMIS").FindListAsync<ArrangeLessonTermOfElectiveEntity>(@"select PaiKeId,AcademicYearNo,Semester,LessonNo,LessonName,LessonSection,EmpNo,EmpName,ClassRoomNo,ClassRoomName from ArrangeLessonTermOfElective where AcademicYearNo='" + strAcademicYear + "' and Semester='" + strSemester + "' group by PaiKeId, AcademicYearNo, Semester, LessonNo, LessonName, LessonSection, EmpNo, EmpName, ClassRoomNo, ClassRoomName")).ToList();
  440. var OpenLessonPlanOfElectiveData = (await BaseRepository("CollegeMIS").FindListAsync<OpenLessonPlanOfElectiveEntity>(@"select * from OpenLessonPlanOfElective where AcademicYearNo='" + strAcademicYear + "' and Semester='" + strSemester + "'")).ToList();
  441. var insertOpenLessonPlanOfElectiveDataList = new List<OpenLessonPlanOfElectiveEntity>();
  442. if (arrangeLessonTermData.Any())
  443. {
  444. foreach (var item in arrangeLessonTermData)
  445. {
  446. var insertOpenLessonPlanOfElectiveData = new OpenLessonPlanOfElectiveEntity()
  447. {
  448. Id = item.PaiKeId,
  449. MakeDate = DateTime.Now,
  450. AcademicYearNo = item.AcademicYearNo,
  451. Semester = item.Semester,
  452. LessonNo = item.LessonNo,
  453. PartCode = "",
  454. LessonName = item.LessonName,
  455. LessonSortNo = lessonData.FirstOrDefault(x => x.LessonNo == item.LessonNo)?.LessonSortNo,
  456. LessonSortDetailNo = lessonData.FirstOrDefault(x => x.LessonNo == item.LessonNo)?.LessonSortDetailNo,
  457. LessonSection = item.LessonSection,
  458. LessonTime = ArrangeLessonTermOfElectiveData.FirstOrDefault(x => x.PaiKeId == item.PaiKeId)?.LessonTime,
  459. StudyScore = lessonData.FirstOrDefault(x => x.LessonNo == item.LessonNo)?.StudyScore,
  460. StartWeek = 1,
  461. EndWeek = ArrangeLessonTermOfElectiveData.Count(x => x.PaiKeId == item.PaiKeId),
  462. StartDate = ArrangeLessonTermOfElectiveData.Where(x => x.PaiKeId == item.PaiKeId).OrderBy(x => x.LessonDate).FirstOrDefault()?.LessonDate,
  463. EndDate = ArrangeLessonTermOfElectiveData.Where(x => x.PaiKeId == item.PaiKeId).OrderBy(x => x.LessonDate).LastOrDefault()?.LessonDate,
  464. CheckStyleNo = "1",
  465. ScoreRecordStyleNo = "1",
  466. EmpNo = item.EmpNo,
  467. EmpName = item.EmpName,
  468. ClassRoomNo = item.ClassRoomNo,
  469. ClassRoomName = item.ClassRoomName,
  470. CheckMark = "1",
  471. StuNumMax = 0,
  472. StuNum = 0
  473. };
  474. //非空判断
  475. if (OpenLessonPlanOfElectiveData.Count(x =>
  476. x.AcademicYearNo == insertOpenLessonPlanOfElectiveData.AcademicYearNo &&
  477. x.Semester == insertOpenLessonPlanOfElectiveData.Semester &&
  478. x.LessonNo == insertOpenLessonPlanOfElectiveData.LessonNo &&
  479. x.LessonSortNo == insertOpenLessonPlanOfElectiveData.LessonSortNo &&
  480. x.LessonSection == insertOpenLessonPlanOfElectiveData.LessonSection &&
  481. x.EmpNo == insertOpenLessonPlanOfElectiveData.EmpNo &&
  482. x.ClassRoomNo == insertOpenLessonPlanOfElectiveData.ClassRoomNo) == 0 && insertOpenLessonPlanOfElectiveDataList.Count(x =>
  483. x.AcademicYearNo == insertOpenLessonPlanOfElectiveData.AcademicYearNo &&
  484. x.Semester == insertOpenLessonPlanOfElectiveData.Semester &&
  485. x.LessonNo == insertOpenLessonPlanOfElectiveData.LessonNo &&
  486. x.LessonSortNo == insertOpenLessonPlanOfElectiveData.LessonSortNo &&
  487. x.LessonSection == insertOpenLessonPlanOfElectiveData.LessonSection &&
  488. x.EmpNo == insertOpenLessonPlanOfElectiveData.EmpNo &&
  489. x.ClassRoomNo == insertOpenLessonPlanOfElectiveData.ClassRoomNo) == 0)
  490. {
  491. insertOpenLessonPlanOfElectiveDataList.Add(insertOpenLessonPlanOfElectiveData);
  492. }
  493. }
  494. await BaseRepository("CollegeMIS").InsertAsync(insertOpenLessonPlanOfElectiveDataList);
  495. }
  496. if (insertResult > 0)
  497. {
  498. result = true;
  499. }
  500. }
  501. }
  502. }
  503. catch (Exception ex)
  504. {
  505. if (ex is ExceptionEx)
  506. {
  507. throw;
  508. }
  509. else
  510. {
  511. throw ExceptionEx.ThrowServiceException(ex);
  512. }
  513. }
  514. return result;
  515. }
  516. /// <summary>
  517. /// 清空当前学期选修排课数据
  518. /// </summary>
  519. /// <returns></returns>
  520. public async Task<bool> AsyncModifyArrangeLessonOfElectiveData()
  521. {
  522. var db = BaseRepository("CollegeMIS");
  523. bool result = false;
  524. try
  525. {
  526. db.BeginTrans();
  527. var apiData = await Client.GetStringAsync(Config.GetValue("ModifyArrangeLessonOfElectiveAPI"));
  528. if (!string.IsNullOrEmpty(apiData))
  529. {
  530. var data = JsonConvert.DeserializeObject<Root>(apiData);
  531. if (data.success)
  532. {
  533. var semesterAndYear = Common.GetSemesterAndYear();
  534. var strAcademicYear = semesterAndYear.AcademicYearShort;
  535. var strSemester = semesterAndYear.Semester;
  536. await db.ExecuteAsyncBySql(
  537. $"delete from ElectiveMajor where OLPOEId in(select id from OpenLessonPlanOfElective where AcademicYearNo='{strAcademicYear}' and Semester='{strSemester}') or OLPOEId in (select id from OpenLessonPlanOfElectiveDel where AcademicYearNo='{strAcademicYear}' and Semester='{strSemester}') ");
  538. var executeResult = await db.ExecuteAsyncBySql(
  539. $"delete from ArrangeLessonTermOfElective where AcademicYearNo='{strAcademicYear}' and Semester='{strSemester}' ");
  540. await db.ExecuteAsyncBySql(
  541. $"delete from OpenLessonPlanOfElective where AcademicYearNo='{strAcademicYear}' and Semester='{strSemester}' ");
  542. await db.ExecuteAsyncBySql(
  543. $"delete from ElectiveMergeItem where emid in (select emid from ElectiveMerge where AcademicYearNo='{strAcademicYear}' and Semester='{strSemester}') ");
  544. await db.ExecuteAsyncBySql(
  545. $"delete from ElectiveMerge where AcademicYearNo='{strAcademicYear}' and Semester='{strSemester}' ");
  546. await db.ExecuteAsyncBySql(
  547. $"delete from OpenLessonPlanOfElectiveDel where AcademicYearNo='{strAcademicYear}' and Semester='{strSemester}' ");
  548. await db.ExecuteAsyncBySql(
  549. $"delete from StuSelectLessonListOfElective where AcademicYearNo='{strAcademicYear}' and Semester='{strSemester}' ");
  550. if (executeResult > 0)
  551. {
  552. result = true;
  553. }
  554. db.Commit();
  555. }
  556. }
  557. }
  558. catch (Exception ex)
  559. {
  560. db.Rollback();
  561. if (ex is ExceptionEx)
  562. {
  563. throw;
  564. }
  565. else
  566. {
  567. throw ExceptionEx.ThrowServiceException(ex);
  568. }
  569. }
  570. return result;
  571. }
  572. /// <summary>
  573. /// 选修课课程表
  574. /// </summary>
  575. /// <param name="userAccount">账号</param>
  576. /// <param name="userType">用户类型 学生 教师</param>
  577. /// <param name="startDate">查询开始时间</param>
  578. /// <param name="endDate">查询截止时间</param>
  579. /// <returns></returns>
  580. public IEnumerable<TimeTable> GetTimeTable(string userAccount, string userType, string startDate, string endDate)
  581. {
  582. var semesterAndYear = Common.GetSemesterAndYear(startDate);
  583. var strAcademicYear = semesterAndYear.AcademicYearShort;
  584. var strSemester = semesterAndYear.Semester;
  585. string sql;
  586. if (userType == "学生")
  587. {
  588. //sql = @"select a.LessonDate,a.AcademicYearNo as AcademicYear,a.Semester,a.LessonNo,a.LessonName+'[选修]' as LessonName,a.LessonSection as LessonTime,a.EmpNo,a.EmpName,a.ClassRoomName as ClassroomName,a.ClassRoomNo,a.LessonSortNo,b.OLPEId
  589. // from StuSelectLessonListOfElective b
  590. // left join ArrangeLessonTermOfElective a on b.OLPEId=a.PaiKeId
  591. // where b.StuNo=@userAccount and b.Status=2
  592. // and b.AcademicYearNo=@strAcademicYear and b.Semester=@strSemester
  593. // and a.AcademicYearNo=@strAcademicYear and a.Semester=@strSemester
  594. // and a.LessonDate >= @startDate and a.LessonDate <=@endDate
  595. // and a.CheckMark='1'";
  596. sql = @" select e.EnName,a.LessonDate,a.AcademicYearNo as AcademicYear,a.Semester,a.LessonNo,e.LessonName,a.LessonSection as LessonTime,a.EmpNo,emp.EmpName,cr.ClassroomName,a.ClassRoomNo,a.LessonSortNo,ccc.olpoeid as OLPEId
  597. from
  598. (select olpoeid from ElectiveMergeItem
  599. where emid in (select emid from ElectiveMergeItem aa left
  600. join StuSelectLessonListOfElective bb on aa.olpoeid = bb.olpeid
  601. where bb.StuNo = @userAccount and bb.Status = 2
  602. and bb.AcademicYearNo = @strAcademicYear and bb.Semester = @strSemester
  603. )) as ccc
  604. left join
  605. ArrangeLessonTermOfElective a on ccc.olpoeid = a.PaiKeId
  606. left join LessonInfo e on a.LessonNo=e.LessonNo
  607. left join EmpInfo emp on a.EmpNo=emp.EmpNo
  608. left join ClassroomInfo cr on a.ClassRoomNo=cr.ClassroomNo
  609. where
  610. a.AcademicYearNo = @strAcademicYear and a.Semester = @strSemester
  611. and a.LessonDate >= @startDate and a.LessonDate <=@endDate
  612. and a.CheckMark = '1'
  613. union
  614. select e.EnName,a.LessonDate,a.AcademicYearNo as AcademicYear,a.Semester,a.LessonNo,e.LessonName,a.LessonSection as LessonTime,a.EmpNo,emp.EmpName,cr.ClassroomName,a.ClassRoomNo,a.LessonSortNo,b.OLPEId
  615. from StuSelectLessonListOfElective b
  616. left join ArrangeLessonTermOfElective a on b.OLPEId=a.PaiKeId
  617. left join LessonInfo e on a.LessonNo=e.LessonNo
  618. left join EmpInfo emp on a.EmpNo=emp.EmpNo
  619. left join ClassroomInfo cr on a.ClassRoomNo=cr.ClassroomNo
  620. where b.StuNo=@userAccount and b.Status=2
  621. and b.AcademicYearNo=@strAcademicYear and b.Semester=@strSemester
  622. and a.AcademicYearNo=@strAcademicYear and a.Semester=@strSemester
  623. and a.LessonDate >= @startDate and a.LessonDate <=@endDate
  624. and a.CheckMark='1'
  625. ";
  626. }
  627. else
  628. {
  629. sql = @"select e.EnName,a.LessonDate,a.AcademicYearNo as AcademicYear,a.Semester,a.LessonNo,e.LessonName,a.LessonSection as LessonTime,a.EmpNo,emp.EmpName,cr.ClassroomName,a.ClassRoomNo,a.LessonSortNo
  630. from ArrangeLessonTermOfElective a
  631. left join LessonInfo e on a.LessonNo=e.LessonNo
  632. left join EmpInfo emp on a.EmpNo=emp.EmpNo
  633. left join ClassroomInfo cr on a.ClassRoomNo=cr.ClassroomNo
  634. where a.EmpNo=@userAccount
  635. and a.AcademicYearNo=@strAcademicYear and a.Semester=@strSemester
  636. and a.LessonDate >= @startDate and a.LessonDate <=@endDate
  637. and a.CheckMark='1'";
  638. }
  639. try
  640. {
  641. var result = BaseRepository("CollegeMIS").FindList<TimeTable>(sql, new { userAccount, startDate, endDate, strAcademicYear, strSemester });
  642. return result;
  643. }
  644. catch (Exception ex)
  645. {
  646. if (ex is ExceptionEx)
  647. {
  648. throw;
  649. }
  650. else
  651. {
  652. throw ExceptionEx.ThrowServiceException(ex);
  653. }
  654. }
  655. }
  656. /// <summary>
  657. /// 选修课课程表【教务】
  658. /// </summary>
  659. /// <param name="startDate">查询开始时间</param>
  660. /// <param name="endDate">查询截止时间</param>
  661. /// <param name="classNo">班级编号</param>
  662. /// <param name="empNo">教师编号</param>
  663. /// <returns></returns>
  664. public IEnumerable<TimeTable> GetTimeTableInEducation(string startDate, string endDate, string classNo, string empNo, string schoolId)
  665. {
  666. var semesterAndYear = Common.GetSemesterAndYear(startDate);
  667. var strAcademicYear = semesterAndYear.AcademicYearShort;
  668. var strSemester = semesterAndYear.Semester;
  669. string sql = @"select e.EnName,a.F_SchoolId,a.LessonDate,a.AcademicYearNo as AcademicYear,a.Semester,a.LessonNo,e.LessonName,a.LessonSection as LessonTime,a.EmpNo,emp.EmpName,cr.ClassroomName,a.ClassRoomNo,a.LessonSortNo
  670. from ArrangeLessonTermOfElective a
  671. left join LessonInfo e on a.LessonNo=e.LessonNo
  672. left join EmpInfo emp on a.EmpNo=emp.EmpNo
  673. left join ClassroomInfo cr on a.ClassRoomNo=cr.ClassroomNo
  674. where a.AcademicYearNo=@strAcademicYear and a.Semester=@strSemester
  675. and a.LessonDate>=@startDate and a.LessonDate<=@endDate
  676. and a.CheckMark=1";
  677. try
  678. {
  679. var result = BaseRepository("CollegeMIS").FindList<TimeTable>(sql, new { startDate, endDate, strAcademicYear, strSemester });
  680. if (!string.IsNullOrEmpty(classNo))
  681. {
  682. result = result.Where(x => x.TeachClassNo == classNo);
  683. }
  684. if (!string.IsNullOrEmpty(empNo))
  685. {
  686. result = result.Where(x => x.EmpNo == empNo);
  687. }
  688. if (!string.IsNullOrEmpty(schoolId))
  689. {
  690. result = result.Where(x => x.F_SchoolId == schoolId);
  691. }
  692. return result;
  693. }
  694. catch (Exception ex)
  695. {
  696. if (ex is ExceptionEx)
  697. {
  698. throw;
  699. }
  700. else
  701. {
  702. throw ExceptionEx.ThrowServiceException(ex);
  703. }
  704. }
  705. }
  706. /// <summary>
  707. /// 获取相关课程考勤的学生信息--选修课
  708. /// </summary>
  709. /// <param name="year"></param>
  710. /// <param name="semester"></param>
  711. /// <param name="empno"></param>
  712. /// <param name="lessonNo"></param>
  713. /// <param name="teachClassNo"></param>
  714. /// <param name="lessonSortNo"></param>
  715. /// <param name="classRoomNo"></param>
  716. /// <param name="lessonTime"></param>
  717. /// <returns></returns>
  718. public IEnumerable<StuSelectLessonListEntity> AttendanceStudents(Pagination pagination, string queryJson)
  719. {
  720. try
  721. {
  722. var queryParam = queryJson.ToJObject();
  723. var strSql = new StringBuilder();
  724. strSql.Append("SELECT ");
  725. strSql.Append(@"
  726. a.[StuNo]
  727. ,a.[DeptNo]
  728. ,a.[MajorNo]
  729. ,a.[ClassNo]
  730. ,a.[StuName]
  731. ,a.[GenderNo]
  732. ,a.[AcademicYearNo]
  733. ,a.[Semester]
  734. ,a.[LessonNo]
  735. ,a.[LessonName]
  736. ,a.[LessonSortNo]
  737. ,a.[Grade]
  738. ,a.[EmpNo],a.Id as StuSelectLessonListOfElectiveId,b.ID as StuAttendanceNo,b.AttendOrNo,b.Sort,b.AttenCondition,b.AttenScore
  739. ");
  740. strSql.Append(" FROM StuSelectLessonListOfElective a left join StuAttendance b on a.AcademicYearNo=b.AcademicYearNo and a.StuNo=b.StuNo and a.Semester=b.Semester and a.EmpNo=b.EmpNo and a.LessonNo=b.LessonNo and a.ClassRoomNo=b.ClassRoomNo and a.LessonSection=b.LessonTime ");
  741. strSql.Append(" WHERE 1=1 ");
  742. strSql.Append($"and a.AcademicYearNo='{ queryParam["year"]}' and a.Semester='{queryParam["semester"]}' and a.Status=2 and a.EmpNo='{queryParam["empno"]}' and a.LessonNo='{queryParam["lessonNo"]}' and a.ClassRoomNo='{queryParam["classRoomNo"]}' and a.LessonSection like '%{queryParam["lessonTime"]}%'");
  743. return this.BaseRepository("CollegeMIS").FindList<StuSelectLessonListEntity>(strSql.ToString(), pagination);
  744. }
  745. catch (Exception ex)
  746. {
  747. if (ex is ExceptionEx)
  748. {
  749. throw;
  750. }
  751. else
  752. {
  753. throw ExceptionEx.ThrowServiceException(ex);
  754. }
  755. }
  756. }
  757. /// <summary>
  758. /// 考试系统中获取学生成绩数据
  759. /// </summary>
  760. /// <returns></returns>
  761. public async Task<bool> AsyncStuScoreData()
  762. {
  763. bool result = false;
  764. var db = this.BaseRepository("CollegeMIS").BeginTrans();
  765. try
  766. {
  767. var values = new List<KeyValuePair<string, string>>();
  768. values.Add(new KeyValuePair<string, string>("scoolYear", "18-19"));
  769. values.Add(new KeyValuePair<string, string>("term ", "2"));
  770. var content = new FormUrlEncodedContent(values);
  771. var response = await Client.PostAsync("http://192.168.2.125:8088/app/stuScore", content);
  772. response.EnsureSuccessStatusCode();
  773. var responseString = await response.Content.ReadAsStringAsync();
  774. if (!string.IsNullOrEmpty(responseString))
  775. {
  776. var data = JsonConvert.DeserializeObject<StuScoreRoot>(responseString);
  777. if (data.success)
  778. {
  779. var dataList = data.entity.stuScoreList;
  780. if (dataList.Any())
  781. {
  782. foreach (var item in dataList)
  783. {
  784. if (item.lessonno.IndexOf(',') == -1)//单课程
  785. {
  786. //todo:测试是否能找到对应的成绩记录
  787. var aa = this.BaseRepository("CollegeMIS").FindObject("select * from StuScore where where StuNo='" + item.stuno + "' and AcademicYearNo='" + item.scoolYear + "' and Semester='" + item.term + "' and LessonNo='" + item.lessonno + "' and TeachClassNo='" + item.teachclassno + "' and LessonSortNo='1' and CheckMark='0' ");
  788. this.BaseRepository("CollegeMIS").ExecuteBySql("update StuScore set TermEndScore='" + Convert.ToDecimal(item.termendscore) + "' where StuNo='" + item.stuno + "' and AcademicYearNo='" + item.scoolYear + "' and Semester='" + item.term + "' and LessonNo='" + item.lessonno + "' and TeachClassNo='" + item.teachclassno + "' and LessonSortNo='1' and CheckMark='0' ");
  789. }
  790. else//多课程
  791. {
  792. var lessonnoList = item.lessonno.Split(',');
  793. foreach (var lessonnoItem in lessonnoList)
  794. {
  795. this.BaseRepository("CollegeMIS").ExecuteBySql("update StuScore set TermEndScore='" + Convert.ToDecimal(item.termendscore) + "' where StuNo='" + item.stuno + "' and AcademicYearNo='" + item.scoolYear + "' and Semester='" + item.term + "' and LessonNo='" + lessonnoItem + "' and TeachClassNo='" + item.teachclassno + "' and LessonSortNo='1' and CheckMark='0' ");
  796. }
  797. }
  798. }
  799. db.Commit();
  800. result = true;
  801. }
  802. }
  803. }
  804. }
  805. catch (Exception ex)
  806. {
  807. db.Rollback();
  808. if (ex is ExceptionEx)
  809. {
  810. throw;
  811. }
  812. else
  813. {
  814. throw ExceptionEx.ThrowServiceException(ex);
  815. }
  816. }
  817. return result;
  818. }
  819. #endregion
  820. #region 学生成绩数据
  821. public class StuScoreList
  822. {
  823. public string id { get; set; }
  824. public string examname { get; set; }
  825. public string stuno { get; set; }
  826. public string stuname { get; set; }
  827. public string classno { get; set; }
  828. public string classname { get; set; }
  829. public string teachclassno { get; set; }
  830. public string termendscore { get; set; }
  831. public string examtime { get; set; }
  832. public string lessonno { get; set; }
  833. public string lessonname { get; set; }
  834. public string scoolYear { get; set; }
  835. public string term { get; set; }
  836. }
  837. public class StuScoreEntity
  838. {
  839. /// <summary>
  840. /// true
  841. /// </summary>
  842. public string opflag { get; set; }
  843. /// <summary>
  844. /// 1000
  845. /// </summary>
  846. public string opCode { get; set; }
  847. /// <summary>
  848. /// OK!
  849. /// </summary>
  850. public string message { get; set; }
  851. /// <summary>
  852. /// List
  853. /// </summary>
  854. public List<StuScoreList> stuScoreList { get; set; }
  855. }
  856. public class StuScoreRoot
  857. {
  858. /// <summary>
  859. /// 操作成功
  860. /// </summary>
  861. public string message { get; set; }
  862. /// <summary>
  863. /// Success
  864. /// </summary>
  865. public bool success { get; set; }
  866. /// <summary>
  867. /// Entity
  868. /// </summary>
  869. public StuScoreEntity entity { get; set; }
  870. }
  871. #endregion
  872. }
  873. }