using Dapper; using Learun.Application.Organization; using Learun.DataBase.Repository; using Learun.Util; using System; using System.Collections.Generic; using System.Data; using System.Text; namespace Learun.Application.TwoDevelopment.EducationalAdministration { /// /// 版 本 Learun-ADMS-Ultimate V7.0.0 数字化智慧校园 /// Copyright (c) 2013-2018 北京泉江科技有限公司 /// 创 建:超级管理员 /// 日 期:2019-10-28 11:48 /// 描 述:学籍异动 /// public class StuInfoBasicChangeService : RepositoryFactory { #region 获取数据 /// /// 获取页面显示列表数据 /// /// 查询参数 /// public IEnumerable GetPageList(Pagination pagination, string queryJson) { try { var strSql = new StringBuilder(); strSql.Append("SELECT t.* FROM StuInfoBasicChange t "); strSql.Append(" WHERE 1=1 "); var queryParam = queryJson.ToJObject(); // 虚拟参数 var dp = new DynamicParameters(new { }); if (!queryParam["StuName"].IsEmpty()) { dp.Add("StuName", "%" + queryParam["StuName"].ToString() + "%", DbType.String); strSql.Append(" AND t.StuName Like @StuName "); } return this.BaseRepository("CollegeMIS").FindList(strSql.ToString(), dp, pagination); } catch (Exception ex) { if (ex is ExceptionEx) { throw; } else { throw ExceptionEx.ThrowServiceException(ex); } } } /// /// 获取StuInfoBasicChange表实体数据 /// 主键 /// /// public StuInfoBasicChangeEntity GetStuInfoBasicChangeEntity(string keyValue) { try { return this.BaseRepository("CollegeMIS").FindEntity(keyValue); } catch (Exception ex) { if (ex is ExceptionEx) { throw; } else { throw ExceptionEx.ThrowServiceException(ex); } } } #endregion #region 提交数据 /// /// 删除实体数据 /// 主键 /// /// public void DeleteEntity(string keyValue) { try { this.BaseRepository("CollegeMIS").Delete(t => t.Id == keyValue); } catch (Exception ex) { if (ex is ExceptionEx) { throw; } else { throw ExceptionEx.ThrowServiceException(ex); } } } /// /// 保存实体数据(新增、修改) /// 主键 /// /// public void SaveEntity(string keyValue, StuInfoBasicChangeEntity entity) { try { if (!string.IsNullOrEmpty(keyValue)) { entity.Modify(keyValue); this.BaseRepository("CollegeMIS").Update(entity); } else { entity.Create(); this.BaseRepository("CollegeMIS").Insert(entity); } } catch (Exception ex) { if (ex is ExceptionEx) { throw; } else { throw ExceptionEx.ThrowServiceException(ex); } } } /// /// 审核实体数据 /// 主键 /// /// public void DoCheck(string keyValue) { var db = this.BaseRepository("CollegeMIS").BeginTrans(); var dbbase = this.BaseRepository().BeginTrans(); try { var loginUserInfo = LoginUserInfo.Get(); var now = DateTime.Now; var logList = new List(); var entity = this.BaseRepository("CollegeMIS").FindEntity(x => x.Id == keyValue); if (entity != null) { var stuInfoBasicEntity = this.BaseRepository("CollegeMIS").FindEntity(x => x.StuNo == entity.StuNo); if (stuInfoBasicEntity != null) { //处理数据 if (entity.StuChangeType == "01" || entity.StuChangeType == "07") //降级、转班、 { if (stuInfoBasicEntity.ClassNo != entity.NewClassNo) { var classInfoEntity = db.FindEntity(x => x.ClassNo == entity.NewClassNo); if (classInfoEntity != null) { if (stuInfoBasicEntity.Grade != classInfoEntity.Grade) { //增加异动日志表:年级 var logentity2 = new StuInfoBasic_ChangeLogEntity() { FieldName = "年级", BeforeChange = stuInfoBasicEntity.Grade, AfterChange = classInfoEntity.Grade, UpdateBy = loginUserInfo.userId, UpdateTime = now, StuID = stuInfoBasicEntity.StuId, StuChangeType = entity.StuChangeType, StuChangeRemark = entity.StuChangeRemark, StuChangeId = entity.Id }; logentity2.Create(); logList.Add(logentity2); } //改学籍信息表; db.ExecuteBySql($"update StuInfoBasic set ClassNo='{entity.NewClassNo}',Grade='{classInfoEntity.Grade}' where StuNo='{entity.StuNo}' "); //增加异动日志表:班级 var logentity = new StuInfoBasic_ChangeLogEntity() { FieldName = "班级", BeforeChange = entity.ClassNo, AfterChange = entity.NewClassNo, UpdateBy = loginUserInfo.userId, UpdateTime = now, StuID = stuInfoBasicEntity.StuId, StuChangeType = entity.StuChangeType, StuChangeRemark = entity.StuChangeRemark, StuChangeId = entity.Id }; logentity.Create(); logList.Add(logentity); } } } else if (entity.StuChangeType == "02" || entity.StuChangeType == "05" || entity.StuChangeType == "06") //转校、退学、休学、 { //增加异动日志表:学籍id被删除 var logentity = new StuInfoBasic_ChangeLogEntity() { FieldName = "学籍表主键", BeforeChange = stuInfoBasicEntity.StuId, AfterChange = null, UpdateBy = loginUserInfo.userId, UpdateTime = now, StuID = stuInfoBasicEntity.StuId, StuChangeType = entity.StuChangeType, StuChangeRemark = entity.StuChangeRemark, StuChangeId = entity.Id }; logentity.Create(); logList.Add(logentity); //增加退学表 db.ExecuteBySql($"insert into StuInfoDrop select * from StuInfoBasic where StuId='{stuInfoBasicEntity.StuId}' "); //修改异动表:退学表id entity.StuIdInDrop = stuInfoBasicEntity.StuId; //删除学籍表 db.ExecuteBySql($"delete from StuInfoBasic where StuId='{stuInfoBasicEntity.StuId}' "); //删除账户表 var userEntity = this.BaseRepository().FindEntity(x => x.F_Account == stuInfoBasicEntity.StuNo); if (userEntity != null) { dbbase.Delete(userEntity); } } else if (entity.StuChangeType == "08") //转专业、 { if (stuInfoBasicEntity.MajorNo != entity.NewMajorNo) { var classInfoEntity2 = db.FindEntity(x => x.ClassNo == entity.NewClassNo); if (classInfoEntity2 != null) { if (stuInfoBasicEntity.Grade != classInfoEntity2.Grade) { //增加异动日志表:年级 var logentity3 = new StuInfoBasic_ChangeLogEntity() { FieldName = "年级", BeforeChange = stuInfoBasicEntity.Grade, AfterChange = classInfoEntity2.Grade, UpdateBy = loginUserInfo.userId, UpdateTime = now, StuID = stuInfoBasicEntity.StuId, StuChangeType = entity.StuChangeType, StuChangeRemark = entity.StuChangeRemark, StuChangeId = entity.Id }; logentity3.Create(); logList.Add(logentity3); } //改学籍信息; db.ExecuteBySql($"update StuInfoBasic set MajorNo='{entity.NewMajorNo}',ClassNo='{entity.NewClassNo}',Grade='{classInfoEntity2.Grade}' where StuNo='{entity.StuNo}' "); //增加异动日志表:专业 var logentity = new StuInfoBasic_ChangeLogEntity() { FieldName = "专业", BeforeChange = entity.MajorNo, AfterChange = entity.NewMajorNo, UpdateBy = loginUserInfo.userId, UpdateTime = now, StuID = stuInfoBasicEntity.StuId, StuChangeType = entity.StuChangeType, StuChangeRemark = entity.StuChangeRemark, StuChangeId = entity.Id }; logentity.Create(); logList.Add(logentity); //增加异动日志表:班级 var logentity2 = new StuInfoBasic_ChangeLogEntity() { FieldName = "班级", BeforeChange = entity.ClassNo, AfterChange = entity.NewClassNo, UpdateBy = loginUserInfo.userId, UpdateTime = now, StuID = stuInfoBasicEntity.StuId, StuChangeType = entity.StuChangeType, StuChangeRemark = entity.StuChangeRemark, StuChangeId = entity.Id }; logentity2.Create(); logList.Add(logentity2); } } else { if (stuInfoBasicEntity.ClassNo != entity.NewClassNo) { var classInfoEntity2 = db.FindEntity(x => x.ClassNo == entity.NewClassNo); if (classInfoEntity2 != null) { if (stuInfoBasicEntity.Grade != classInfoEntity2.Grade) { //增加异动日志表:年级 var logentity2 = new StuInfoBasic_ChangeLogEntity() { FieldName = "年级", BeforeChange = stuInfoBasicEntity.Grade, AfterChange = classInfoEntity2.Grade, UpdateBy = loginUserInfo.userId, UpdateTime = now, StuID = stuInfoBasicEntity.StuId, StuChangeType = entity.StuChangeType, StuChangeRemark = entity.StuChangeRemark, StuChangeId = entity.Id }; logentity2.Create(); logList.Add(logentity2); } //改学籍信息表; db.ExecuteBySql($"update StuInfoBasic set MajorNo='{entity.NewMajorNo}',ClassNo='{entity.NewClassNo}',Grade='{classInfoEntity2.Grade}' where StuNo='{entity.StuNo}' "); //增加异动日志表:班级 var logentity = new StuInfoBasic_ChangeLogEntity() { FieldName = "班级", BeforeChange = entity.ClassNo, AfterChange = entity.NewClassNo, UpdateBy = loginUserInfo.userId, UpdateTime = now, StuID = stuInfoBasicEntity.StuId, StuChangeType = entity.StuChangeType, StuChangeRemark = entity.StuChangeRemark, StuChangeId = entity.Id }; logentity.Create(); logList.Add(logentity); } } } } db.Insert(logList); //修改异动表:审批状态、审批人、 entity.CheckTime = now; entity.CheckUserId = loginUserInfo.userId; entity.CheckStatus = 1; db.Update(entity); } } db.Commit(); dbbase.Commit(); } catch (Exception ex) { db.Rollback(); dbbase.Rollback(); if (ex is ExceptionEx) { throw; } else { throw ExceptionEx.ThrowServiceException(ex); } } } /// /// 去审核实体数据 /// 主键 /// /// public void DoUnCheck(string keyValue) { var db = this.BaseRepository("CollegeMIS").BeginTrans(); try { var entity = db.FindEntity(x => x.Id == keyValue); if (entity != null) { //处理数据 if (entity.StuChangeType == "01" || entity.StuChangeType == "07" || entity.StuChangeType == "08") //降级、转班、转专业、 { //改学籍信息; var classInfoEntity = db.FindEntity(x => x.ClassNo == entity.ClassNo); if (classInfoEntity != null) { db.ExecuteBySql($"update StuInfoBasic set DeptNo='{entity.DeptNo}',MajorNo='{entity.MajorNo}',ClassNo='{entity.ClassNo}',Grade='{classInfoEntity.Grade}' where StuNo='{entity.StuNo}' "); } } else if (entity.StuChangeType == "02" || entity.StuChangeType == "05" || entity.StuChangeType == "06") //转校、退学、休学 { //增加学籍表 db.ExecuteBySql($"insert into StuInfoBasic select * from StuInfoDrop where StuId='{entity.StuIdInDrop}' "); //删除退学表 db.ExecuteBySql($"delete from StuInfoDrop where StuId='{entity.StuIdInDrop}' "); //修改异动表:退学表id 为空 } //修改异动表:审批状态、审批人、 db.ExecuteBySql($"update StuInfoBasicChange set CheckTime=null,CheckUserId=null,CheckStatus=0,StuIdInDrop=null where Id='" + keyValue + "' "); //删除异动日志表:学籍异动主键id db.ExecuteBySql("delete from StuInfoBasic_ChangeLog where StuChangeId='" + keyValue + "' "); } db.Commit(); } catch (Exception ex) { db.Rollback(); if (ex is ExceptionEx) { throw; } else { throw ExceptionEx.ThrowServiceException(ex); } } } /// /// 复学 /// 主键 /// /// public void DoGoBack(string keyValue) { var db = this.BaseRepository("CollegeMIS").BeginTrans(); try { var loginUserInfo = LoginUserInfo.Get(); var now = DateTime.Now; var logList = new List(); var entity = this.BaseRepository("CollegeMIS").FindEntity(x => x.Id == keyValue); if (entity != null) { var stuInfoDropEntity = this.BaseRepository("CollegeMIS").FindEntity(x => x.StuId == entity.StuIdInDrop); if (stuInfoDropEntity != null) { //增加异动日志表:学籍id增加 var logentity = new StuInfoBasic_ChangeLogEntity() { FieldName = "学籍表主键", BeforeChange = null, AfterChange = stuInfoDropEntity.StuId, UpdateBy = loginUserInfo.userId, UpdateTime = now, StuID = stuInfoDropEntity.StuId, StuChangeType = "03", StuChangeRemark = "复学", StuChangeId = entity.Id }; logentity.Create(); logList.Add(logentity); //增加学籍表 db.ExecuteBySql($"insert into StuInfoBasic select * from StuInfoDrop where StuId='{entity.StuIdInDrop}' "); //删除退学表 db.ExecuteBySql($"delete from StuInfoDrop where StuId='{entity.StuIdInDrop}' "); //修改异动表:复学状态、复学时间、 entity.GoBackStatus = 1; entity.GoBackTime = now; db.Update(entity); db.Insert(logList); } } db.Commit(); } catch (Exception ex) { db.Rollback(); if (ex is ExceptionEx) { throw; } else { throw ExceptionEx.ThrowBusinessException(ex); } } } #endregion } }