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.
 
 
 
 
 
 

497 lines
23 KiB

  1. using Dapper;
  2. using Learun.Application.Organization;
  3. using Learun.DataBase.Repository;
  4. using Learun.Util;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Data;
  8. using System.Text;
  9. namespace Learun.Application.TwoDevelopment.EducationalAdministration
  10. {
  11. /// <summary>
  12. /// 版 本 Learun-ADMS-Ultimate V7.0.0 数字化智慧校园
  13. /// Copyright (c) 2013-2018 北京泉江科技有限公司
  14. /// 创 建:超级管理员
  15. /// 日 期:2019-10-28 11:48
  16. /// 描 述:学籍异动
  17. /// </summary>
  18. public class StuInfoBasicChangeService : RepositoryFactory
  19. {
  20. #region 获取数据
  21. /// <summary>
  22. /// 获取页面显示列表数据
  23. /// <summary>
  24. /// <param name="queryJson">查询参数</param>
  25. /// <returns></returns>
  26. public IEnumerable<StuInfoBasicChangeEntity> GetPageList(Pagination pagination, string queryJson)
  27. {
  28. try
  29. {
  30. var strSql = new StringBuilder();
  31. strSql.Append("SELECT t.* FROM StuInfoBasicChange t ");
  32. strSql.Append(" WHERE 1=1 ");
  33. var queryParam = queryJson.ToJObject();
  34. // 虚拟参数
  35. var dp = new DynamicParameters(new { });
  36. if (!queryParam["StuName"].IsEmpty())
  37. {
  38. dp.Add("StuName", "%" + queryParam["StuName"].ToString() + "%", DbType.String);
  39. strSql.Append(" AND t.StuName Like @StuName ");
  40. }
  41. return this.BaseRepository("CollegeMIS").FindList<StuInfoBasicChangeEntity>(strSql.ToString(), dp, pagination);
  42. }
  43. catch (Exception ex)
  44. {
  45. if (ex is ExceptionEx)
  46. {
  47. throw;
  48. }
  49. else
  50. {
  51. throw ExceptionEx.ThrowServiceException(ex);
  52. }
  53. }
  54. }
  55. /// <summary>
  56. /// 获取StuInfoBasicChange表实体数据
  57. /// <param name="keyValue">主键</param>
  58. /// <summary>
  59. /// <returns></returns>
  60. public StuInfoBasicChangeEntity GetStuInfoBasicChangeEntity(string keyValue)
  61. {
  62. try
  63. {
  64. return this.BaseRepository("CollegeMIS").FindEntity<StuInfoBasicChangeEntity>(keyValue);
  65. }
  66. catch (Exception ex)
  67. {
  68. if (ex is ExceptionEx)
  69. {
  70. throw;
  71. }
  72. else
  73. {
  74. throw ExceptionEx.ThrowServiceException(ex);
  75. }
  76. }
  77. }
  78. #endregion
  79. #region 提交数据
  80. /// <summary>
  81. /// 删除实体数据
  82. /// <param name="keyValue">主键</param>
  83. /// <summary>
  84. /// <returns></returns>
  85. public void DeleteEntity(string keyValue)
  86. {
  87. try
  88. {
  89. this.BaseRepository("CollegeMIS").Delete<StuInfoBasicChangeEntity>(t => t.Id == keyValue);
  90. }
  91. catch (Exception ex)
  92. {
  93. if (ex is ExceptionEx)
  94. {
  95. throw;
  96. }
  97. else
  98. {
  99. throw ExceptionEx.ThrowServiceException(ex);
  100. }
  101. }
  102. }
  103. /// <summary>
  104. /// 保存实体数据(新增、修改)
  105. /// <param name="keyValue">主键</param>
  106. /// <summary>
  107. /// <returns></returns>
  108. public void SaveEntity(string keyValue, StuInfoBasicChangeEntity entity)
  109. {
  110. try
  111. {
  112. if (!string.IsNullOrEmpty(keyValue))
  113. {
  114. entity.Modify(keyValue);
  115. this.BaseRepository("CollegeMIS").Update(entity);
  116. }
  117. else
  118. {
  119. entity.Create();
  120. this.BaseRepository("CollegeMIS").Insert(entity);
  121. }
  122. }
  123. catch (Exception ex)
  124. {
  125. if (ex is ExceptionEx)
  126. {
  127. throw;
  128. }
  129. else
  130. {
  131. throw ExceptionEx.ThrowServiceException(ex);
  132. }
  133. }
  134. }
  135. /// <summary>
  136. /// 审核实体数据
  137. /// <param name="keyValue">主键</param>
  138. /// <summary>
  139. /// <returns></returns>
  140. public void DoCheck(string keyValue)
  141. {
  142. var db = this.BaseRepository("CollegeMIS").BeginTrans();
  143. var dbbase = this.BaseRepository().BeginTrans();
  144. try
  145. {
  146. var loginUserInfo = LoginUserInfo.Get();
  147. var now = DateTime.Now;
  148. var logList = new List<StuInfoBasic_ChangeLogEntity>();
  149. var entity = this.BaseRepository("CollegeMIS").FindEntity<StuInfoBasicChangeEntity>(x => x.Id == keyValue);
  150. if (entity != null)
  151. {
  152. var stuInfoBasicEntity = this.BaseRepository("CollegeMIS").FindEntity<StuInfoBasicEntity>(x => x.StuNo == entity.StuNo);
  153. if (stuInfoBasicEntity != null)
  154. {
  155. //处理数据
  156. if (entity.StuChangeType == "01" || entity.StuChangeType == "07") //降级、转班、
  157. {
  158. if (stuInfoBasicEntity.ClassNo != entity.NewClassNo)
  159. {
  160. var classInfoEntity = db.FindEntity<ClassInfoEntity>(x => x.ClassNo == entity.NewClassNo);
  161. if (classInfoEntity != null)
  162. {
  163. if (stuInfoBasicEntity.Grade != classInfoEntity.Grade)
  164. {
  165. //增加异动日志表:年级
  166. var logentity2 = new StuInfoBasic_ChangeLogEntity()
  167. {
  168. FieldName = "年级",
  169. BeforeChange = stuInfoBasicEntity.Grade,
  170. AfterChange = classInfoEntity.Grade,
  171. UpdateBy = loginUserInfo.userId,
  172. UpdateTime = now,
  173. StuID = stuInfoBasicEntity.StuId,
  174. StuChangeType = entity.StuChangeType,
  175. StuChangeRemark = entity.StuChangeRemark,
  176. StuChangeId = entity.Id
  177. };
  178. logentity2.Create();
  179. logList.Add(logentity2);
  180. }
  181. //改学籍信息表;
  182. db.ExecuteBySql($"update StuInfoBasic set ClassNo='{entity.NewClassNo}',Grade='{classInfoEntity.Grade}' where StuNo='{entity.StuNo}' ");
  183. //增加异动日志表:班级
  184. var logentity = new StuInfoBasic_ChangeLogEntity()
  185. {
  186. FieldName = "班级",
  187. BeforeChange = entity.ClassNo,
  188. AfterChange = entity.NewClassNo,
  189. UpdateBy = loginUserInfo.userId,
  190. UpdateTime = now,
  191. StuID = stuInfoBasicEntity.StuId,
  192. StuChangeType = entity.StuChangeType,
  193. StuChangeRemark = entity.StuChangeRemark,
  194. StuChangeId = entity.Id
  195. };
  196. logentity.Create();
  197. logList.Add(logentity);
  198. }
  199. }
  200. }
  201. else if (entity.StuChangeType == "02" || entity.StuChangeType == "05" || entity.StuChangeType == "06") //转校、退学、休学、
  202. {
  203. //增加异动日志表:学籍id被删除
  204. var logentity = new StuInfoBasic_ChangeLogEntity()
  205. {
  206. FieldName = "学籍表主键",
  207. BeforeChange = stuInfoBasicEntity.StuId,
  208. AfterChange = null,
  209. UpdateBy = loginUserInfo.userId,
  210. UpdateTime = now,
  211. StuID = stuInfoBasicEntity.StuId,
  212. StuChangeType = entity.StuChangeType,
  213. StuChangeRemark = entity.StuChangeRemark,
  214. StuChangeId = entity.Id
  215. };
  216. logentity.Create();
  217. logList.Add(logentity);
  218. //增加退学表
  219. db.ExecuteBySql($"insert into StuInfoDrop select * from StuInfoBasic where StuId='{stuInfoBasicEntity.StuId}' ");
  220. //修改异动表:退学表id
  221. entity.StuIdInDrop = stuInfoBasicEntity.StuId;
  222. //删除学籍表
  223. db.ExecuteBySql($"delete from StuInfoBasic where StuId='{stuInfoBasicEntity.StuId}' ");
  224. //删除账户表
  225. var userEntity = this.BaseRepository().FindEntity<UserEntity>(x => x.F_Account == stuInfoBasicEntity.StuNo);
  226. if (userEntity != null)
  227. {
  228. dbbase.Delete(userEntity);
  229. }
  230. }
  231. else if (entity.StuChangeType == "08") //转专业、
  232. {
  233. if (stuInfoBasicEntity.MajorNo != entity.NewMajorNo)
  234. {
  235. var classInfoEntity2 = db.FindEntity<ClassInfoEntity>(x => x.ClassNo == entity.NewClassNo);
  236. if (classInfoEntity2 != null)
  237. {
  238. if (stuInfoBasicEntity.Grade != classInfoEntity2.Grade)
  239. {
  240. //增加异动日志表:年级
  241. var logentity3 = new StuInfoBasic_ChangeLogEntity()
  242. {
  243. FieldName = "年级",
  244. BeforeChange = stuInfoBasicEntity.Grade,
  245. AfterChange = classInfoEntity2.Grade,
  246. UpdateBy = loginUserInfo.userId,
  247. UpdateTime = now,
  248. StuID = stuInfoBasicEntity.StuId,
  249. StuChangeType = entity.StuChangeType,
  250. StuChangeRemark = entity.StuChangeRemark,
  251. StuChangeId = entity.Id
  252. };
  253. logentity3.Create();
  254. logList.Add(logentity3);
  255. }
  256. //改学籍信息;
  257. db.ExecuteBySql($"update StuInfoBasic set MajorNo='{entity.NewMajorNo}',ClassNo='{entity.NewClassNo}',Grade='{classInfoEntity2.Grade}' where StuNo='{entity.StuNo}' ");
  258. //增加异动日志表:专业
  259. var logentity = new StuInfoBasic_ChangeLogEntity()
  260. {
  261. FieldName = "专业",
  262. BeforeChange = entity.MajorNo,
  263. AfterChange = entity.NewMajorNo,
  264. UpdateBy = loginUserInfo.userId,
  265. UpdateTime = now,
  266. StuID = stuInfoBasicEntity.StuId,
  267. StuChangeType = entity.StuChangeType,
  268. StuChangeRemark = entity.StuChangeRemark,
  269. StuChangeId = entity.Id
  270. };
  271. logentity.Create();
  272. logList.Add(logentity);
  273. //增加异动日志表:班级
  274. var logentity2 = new StuInfoBasic_ChangeLogEntity()
  275. {
  276. FieldName = "班级",
  277. BeforeChange = entity.ClassNo,
  278. AfterChange = entity.NewClassNo,
  279. UpdateBy = loginUserInfo.userId,
  280. UpdateTime = now,
  281. StuID = stuInfoBasicEntity.StuId,
  282. StuChangeType = entity.StuChangeType,
  283. StuChangeRemark = entity.StuChangeRemark,
  284. StuChangeId = entity.Id
  285. };
  286. logentity2.Create();
  287. logList.Add(logentity2);
  288. }
  289. }
  290. else
  291. {
  292. if (stuInfoBasicEntity.ClassNo != entity.NewClassNo)
  293. {
  294. var classInfoEntity2 = db.FindEntity<ClassInfoEntity>(x => x.ClassNo == entity.NewClassNo);
  295. if (classInfoEntity2 != null)
  296. {
  297. if (stuInfoBasicEntity.Grade != classInfoEntity2.Grade)
  298. {
  299. //增加异动日志表:年级
  300. var logentity2 = new StuInfoBasic_ChangeLogEntity()
  301. {
  302. FieldName = "年级",
  303. BeforeChange = stuInfoBasicEntity.Grade,
  304. AfterChange = classInfoEntity2.Grade,
  305. UpdateBy = loginUserInfo.userId,
  306. UpdateTime = now,
  307. StuID = stuInfoBasicEntity.StuId,
  308. StuChangeType = entity.StuChangeType,
  309. StuChangeRemark = entity.StuChangeRemark,
  310. StuChangeId = entity.Id
  311. };
  312. logentity2.Create();
  313. logList.Add(logentity2);
  314. }
  315. //改学籍信息表;
  316. db.ExecuteBySql($"update StuInfoBasic set MajorNo='{entity.NewMajorNo}',ClassNo='{entity.NewClassNo}',Grade='{classInfoEntity2.Grade}' where StuNo='{entity.StuNo}' ");
  317. //增加异动日志表:班级
  318. var logentity = new StuInfoBasic_ChangeLogEntity()
  319. {
  320. FieldName = "班级",
  321. BeforeChange = entity.ClassNo,
  322. AfterChange = entity.NewClassNo,
  323. UpdateBy = loginUserInfo.userId,
  324. UpdateTime = now,
  325. StuID = stuInfoBasicEntity.StuId,
  326. StuChangeType = entity.StuChangeType,
  327. StuChangeRemark = entity.StuChangeRemark,
  328. StuChangeId = entity.Id
  329. };
  330. logentity.Create();
  331. logList.Add(logentity);
  332. }
  333. }
  334. }
  335. }
  336. db.Insert(logList);
  337. //修改异动表:审批状态、审批人、
  338. entity.CheckTime = now;
  339. entity.CheckUserId = loginUserInfo.userId;
  340. entity.CheckStatus = 1;
  341. db.Update(entity);
  342. }
  343. }
  344. db.Commit();
  345. dbbase.Commit();
  346. }
  347. catch (Exception ex)
  348. {
  349. db.Rollback();
  350. dbbase.Rollback();
  351. if (ex is ExceptionEx)
  352. {
  353. throw;
  354. }
  355. else
  356. {
  357. throw ExceptionEx.ThrowServiceException(ex);
  358. }
  359. }
  360. }
  361. /// <summary>
  362. /// 去审核实体数据
  363. /// <param name="keyValue">主键</param>
  364. /// <summary>
  365. /// <returns></returns>
  366. public void DoUnCheck(string keyValue)
  367. {
  368. var db = this.BaseRepository("CollegeMIS").BeginTrans();
  369. try
  370. {
  371. var entity = db.FindEntity<StuInfoBasicChangeEntity>(x => x.Id == keyValue);
  372. if (entity != null)
  373. {
  374. //处理数据
  375. if (entity.StuChangeType == "01" || entity.StuChangeType == "07" || entity.StuChangeType == "08") //降级、转班、转专业、
  376. {
  377. //改学籍信息;
  378. var classInfoEntity = db.FindEntity<ClassInfoEntity>(x => x.ClassNo == entity.ClassNo);
  379. if (classInfoEntity != null)
  380. {
  381. db.ExecuteBySql($"update StuInfoBasic set DeptNo='{entity.DeptNo}',MajorNo='{entity.MajorNo}',ClassNo='{entity.ClassNo}',Grade='{classInfoEntity.Grade}' where StuNo='{entity.StuNo}' ");
  382. }
  383. }
  384. else if (entity.StuChangeType == "02" || entity.StuChangeType == "05" || entity.StuChangeType == "06") //转校、退学、休学
  385. {
  386. //增加学籍表
  387. db.ExecuteBySql($"insert into StuInfoBasic select * from StuInfoDrop where StuId='{entity.StuIdInDrop}' ");
  388. //删除退学表
  389. db.ExecuteBySql($"delete from StuInfoDrop where StuId='{entity.StuIdInDrop}' ");
  390. //修改异动表:退学表id 为空
  391. }
  392. //修改异动表:审批状态、审批人、
  393. db.ExecuteBySql($"update StuInfoBasicChange set CheckTime=null,CheckUserId=null,CheckStatus=0,StuIdInDrop=null where Id='" + keyValue + "' ");
  394. //删除异动日志表:学籍异动主键id
  395. db.ExecuteBySql("delete from StuInfoBasic_ChangeLog where StuChangeId='" + keyValue + "' ");
  396. }
  397. db.Commit();
  398. }
  399. catch (Exception ex)
  400. {
  401. db.Rollback();
  402. if (ex is ExceptionEx)
  403. {
  404. throw;
  405. }
  406. else
  407. {
  408. throw ExceptionEx.ThrowServiceException(ex);
  409. }
  410. }
  411. }
  412. /// <summary>
  413. /// 复学
  414. /// <param name="keyValue">主键</param>
  415. /// <summary>
  416. /// <returns></returns>
  417. public void DoGoBack(string keyValue)
  418. {
  419. var db = this.BaseRepository("CollegeMIS").BeginTrans();
  420. try
  421. {
  422. var loginUserInfo = LoginUserInfo.Get();
  423. var now = DateTime.Now;
  424. var logList = new List<StuInfoBasic_ChangeLogEntity>();
  425. var entity = this.BaseRepository("CollegeMIS").FindEntity<StuInfoBasicChangeEntity>(x => x.Id == keyValue);
  426. if (entity != null)
  427. {
  428. var stuInfoDropEntity = this.BaseRepository("CollegeMIS").FindEntity<StuInfoDropEntity>(x => x.StuId == entity.StuIdInDrop);
  429. if (stuInfoDropEntity != null)
  430. {
  431. //增加异动日志表:学籍id增加
  432. var logentity = new StuInfoBasic_ChangeLogEntity()
  433. {
  434. FieldName = "学籍表主键",
  435. BeforeChange = null,
  436. AfterChange = stuInfoDropEntity.StuId,
  437. UpdateBy = loginUserInfo.userId,
  438. UpdateTime = now,
  439. StuID = stuInfoDropEntity.StuId,
  440. StuChangeType = "03",
  441. StuChangeRemark = "复学",
  442. StuChangeId = entity.Id
  443. };
  444. logentity.Create();
  445. logList.Add(logentity);
  446. //增加学籍表
  447. db.ExecuteBySql($"insert into StuInfoBasic select * from StuInfoDrop where StuId='{entity.StuIdInDrop}' ");
  448. //删除退学表
  449. db.ExecuteBySql($"delete from StuInfoDrop where StuId='{entity.StuIdInDrop}' ");
  450. //修改异动表:复学状态、复学时间、
  451. entity.GoBackStatus = 1;
  452. entity.GoBackTime = now;
  453. db.Update(entity);
  454. db.Insert(logList);
  455. }
  456. }
  457. db.Commit();
  458. }
  459. catch (Exception ex)
  460. {
  461. db.Rollback();
  462. if (ex is ExceptionEx)
  463. {
  464. throw;
  465. }
  466. else
  467. {
  468. throw ExceptionEx.ThrowBusinessException(ex);
  469. }
  470. }
  471. }
  472. #endregion
  473. }
  474. }