|
- using Dapper;
- using Learun.DataBase.Repository;
- using Learun.Util;
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Linq;
- using System.Text;
-
- namespace Learun.Application.TwoDevelopment.EducationalAdministration
- {
- /// <summary>
- /// 版 本 Learun-ADMS-Ultimate V7.0.0 数字化智慧校园
- /// Copyright (c) 2013-2018 北京泉江科技有限公司
- /// 创 建:超级管理员
- /// 日 期:2019-01-29 11:08
- /// 描 述:班级信息管理
- /// </summary>
- public class ClassInfoService : RepositoryFactory
- {
- #region 获取数据
-
- /// <summary>
- /// 获取页面显示列表数据
- /// <summary>
- /// <param name="queryJson">查询参数</param>
- /// <returns></returns>
- public IEnumerable<ClassInfoEntity> GetPageList(Pagination pagination, string queryJson)
- {
- try
- {
- var strSql = new StringBuilder();
- strSql.Append(" select t.*,fb1.Mobile as MobileOne,fb2.Mobile as MobileTwo from classinfo t ");
- strSql.Append(" left join empinfo fb1 on t.classdiredctorno = fb1.EmpNo");
- strSql.Append(" left join empinfo fb2 on t.ClassTutorNo = fb2.EmpNo");
- strSql.Append(" WHERE 1=1 ");
- var queryParam = queryJson.ToJObject();
- // 虚拟参数
- var dp = new DynamicParameters(new { });
- if (!queryParam["ClassName"].IsEmpty())
- {
- dp.Add("ClassName", "%" + queryParam["ClassName"].ToString() + "%", DbType.String);
- strSql.Append(" AND t.ClassName Like @ClassName ");
- }
- if (!queryParam["ClassNo"].IsEmpty())
- {
- dp.Add("ClassNo", "%" + queryParam["ClassNo"].ToString() + "%", DbType.String);
- strSql.Append(" AND t.ClassNo Like @ClassNo ");
- }
- if (!queryParam["DeptNo"].IsEmpty())
- {
- dp.Add("DeptNo", queryParam["DeptNo"].ToString(), DbType.String);
- strSql.Append(" AND t.DeptNo = @DeptNo ");
- }
- if (!queryParam["MajorNo"].IsEmpty())
- {
- dp.Add("MajorNo", queryParam["MajorNo"].ToString(), DbType.String);
- strSql.Append(" AND t.MajorNo = @MajorNo ");
- }
- return this.BaseRepository("CollegeMIS").FindList<ClassInfoEntity>(strSql.ToString(), dp, pagination);
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowServiceException(ex);
- }
- }
- }
-
- internal bool GetAny()
- {
- try
- {
- return this.BaseRepository("CollegeMIS").FindList<ClassInfoEntity>().ToList().Count > 0 ? true : false;
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowServiceException(ex);
- }
- }
- }
-
- /// <summary>
- /// 获取ClassInfo表实体数据
- /// <param name="keyValue">主键</param>
- /// <summary>
- /// <returns></returns>
- public ClassInfoEntity GetClassInfoEntity(string keyValue)
- {
- try
- {
- return this.BaseRepository("CollegeMIS").FindEntity<ClassInfoEntity>(keyValue);
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowServiceException(ex);
- }
- }
- }
- /// <summary>
- /// 获取ClassInfo表实体数据
- /// <param name="classNo">班级编号</param>
- /// <summary>
- /// <returns></returns>
- public ClassInfoEntity GetClassInfoEntityByClassNo(string classNo)
- {
- try
- {
- return this.BaseRepository("CollegeMIS").FindEntity<ClassInfoEntity>(x => x.ClassNo == classNo);
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowServiceException(ex);
- }
- }
- }
-
- /// <summary>
- /// 获取ClassInfo表实体数据
- /// <param name="className">班级名称</param>
- /// <summary>
- /// <returns></returns>
- public ClassInfoEntity GetClassInfoEntityByClassName(string className)
- {
- try
- {
- return this.BaseRepository("CollegeMIS").FindEntity<ClassInfoEntity>(x => x.ClassName == className);
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowServiceException(ex);
- }
- }
- }
-
- /// <summary>
- /// 根据班主任或辅导员账号查询班级
- /// <param name="account">班主任或辅导员账号</param>
- /// <summary>
- /// <returns></returns>
- public IEnumerable<ClassInfoEntity> GetListByAccount(string account)
- {
- try
- {
- return this.BaseRepository("CollegeMIS").FindList<ClassInfoEntity>(x => (x.ClassDiredctorNo == account || x.ClassTutorNo == account) && x.CheckMark == true);
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowServiceException(ex);
- }
- }
- }
-
- #endregion
-
- #region 提交数据
- public void Lock(string keyValue)
- {
- var db = this.BaseRepository("CollegeMIS").BeginTrans();
- try
- {
- //单个启用
- //this.BaseRepository("CollegeMIS").ExecuteBySql("update ClassInfo set CheckMark=1 where ClassId='" + keyValue + "'");
-
- //多个启用
- var keyValueArr = keyValue.Split(',');
- foreach (var item in keyValueArr)
- {
- db.ExecuteBySql("update ClassInfo set CheckMark=1 where ClassId='" + item + "'");
- }
- db.Commit();
- }
- catch (Exception ex)
- {
- db.Rollback();
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowServiceException(ex);
- }
- }
- }
-
- public void UnLock(string keyValue)
- {
- var db = this.BaseRepository("CollegeMIS").BeginTrans();
- try
- {
- //单个停用
- //this.BaseRepository("CollegeMIS").ExecuteBySql("update ClassInfo set CheckMark=0 where ClassId='" + keyValue + "'");
-
- //多个停用
- var keyValueArr = keyValue.Split(',');
- foreach (var item in keyValueArr)
- {
- db.ExecuteBySql("update ClassInfo set CheckMark=0 where ClassId='" + item + "'");
- }
- db.Commit();
- }
- catch (Exception ex)
- {
- db.Rollback();
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowServiceException(ex);
- }
- }
- }
- /// <summary>
- /// 删除实体数据
- /// <param name="keyValue">主键</param>
- /// <summary>
- /// <returns></returns>
- public void DeleteEntity(string keyValue)
- {
- var db = this.BaseRepository("CollegeMIS").BeginTrans();
- try
- {
- //单个删除
- //this.BaseRepository("CollegeMIS").Delete<ClassInfoEntity>(t => t.ClassId == keyValue);
-
- //多个删除
- var keyValueArr = keyValue.Split(',');
- foreach (var item in keyValueArr)
- {
- db.Delete<ClassInfoEntity>(t => t.ClassId == item);
- }
- db.Commit();
- }
- catch (Exception ex)
- {
- db.Rollback();
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowServiceException(ex);
- }
- }
- }
-
- /// <summary>
- /// 保存实体数据(新增、修改)
- /// <param name="keyValue">主键</param>
- /// <summary>
- /// <returns></returns>
- public void SaveEntity(string keyValue, ClassInfoEntity 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);
- }
- }
- }
-
- #endregion
-
- public IEnumerable<ClassInfoEntity> GetAllClass()
- {
- try
- {
- return this.BaseRepository("CollegeMIS").FindList<ClassInfoEntity>(m => m.CheckMark == true);
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowServiceException(ex);
- }
- }
- }
- public IEnumerable<ClassInfoEntity> GetClassByMajorNo(string MajorNo)
- {
- try
- {
- return this.BaseRepository("CollegeMIS").FindList<ClassInfoEntity>(m => m.CheckMark == true && m.MajorNo == MajorNo);
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowServiceException(ex);
- }
- }
- }
- }
- }
|