using Dapper;
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();
try
{
var loginUserInfo = LoginUserInfo.Get();
var now = DateTime.Now;
var logList = new List();
var entity = db.FindEntity(x => x.Id == keyValue);
if (entity != null)
{
var stuInfoBasicEntity = db.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") //转校、退学、休学、
{
//增加异动日志表:学籍异动状态
var logentity = new StuInfoBasic_ChangeLogEntity()
{
FieldName = "学籍异动状态",
BeforeChange = stuInfoBasicEntity.ChangeStatus?.ToString(),
AfterChange = "1",
UpdateBy = loginUserInfo.userId,
UpdateTime = now,
StuID = stuInfoBasicEntity.StuId,
StuChangeType = entity.StuChangeType,
StuChangeRemark = entity.StuChangeRemark,
StuChangeId = entity.Id
};
logentity.Create();
logList.Add(logentity);
//改学籍信息(异动状态为1表示不显示成绩);
db.ExecuteBySql($"update StuInfoBasic set ChangeStatus=1 where StuNo='{entity.StuNo}' ");
}
else if (entity.StuChangeType == "03") //复学
{
//增加异动日志表:学籍异动状态
var logentity = new StuInfoBasic_ChangeLogEntity()
{
FieldName = "学籍异动状态",
BeforeChange = stuInfoBasicEntity.ChangeStatus?.ToString(),
AfterChange = "0",
UpdateBy = loginUserInfo.userId,
UpdateTime = now,
StuID = stuInfoBasicEntity.StuId,
StuChangeType = entity.StuChangeType,
StuChangeRemark = entity.StuChangeRemark,
StuChangeId = entity.Id
};
logentity.Create();
logList.Add(logentity);
//改学籍信息(异动状态为0表示显示成绩);
db.ExecuteBySql($"update StuInfoBasic set ChangeStatus=null where StuNo='{entity.StuNo}' ");
}
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();
}
catch (Exception ex)
{
db.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") //转校、退学、休学
{
//改学籍信息(异动状态为null表示显示成绩);
db.ExecuteBySql($"update StuInfoBasic set ChangeStatus=null where StuNo='{entity.StuNo}' ");
}
else if (entity.StuChangeType == "03") //复学
{
//改学籍信息(异动状态为1表示不显示成绩);
db.ExecuteBySql($"update StuInfoBasic set ChangeStatus=1 where StuNo='{entity.StuNo}' ");
}
//修改异动表:审批状态、审批人、
db.ExecuteBySql("update StuInfoBasicChange set CheckTime=null,CheckUserId=null,CheckStatus=0 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);
}
}
}
#endregion
}
}