|
- 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
- {
- /// <summary>
- /// 版 本 Learun-ADMS V7.0.6 力软敏捷开发框架
- /// Copyright (c) 2013-2020 力软信息技术(苏州)有限公司
- /// 创 建:超级管理员
- /// 日 期:2022-01-24 12:19
- /// 描 述:教材信息管理
- /// </summary>
- public class TextBookInfoService : RepositoryFactory
- {
- #region 获取数据
-
- /// <summary>
- /// 获取页面显示列表数据
- /// </summary>
- /// <param name="pagination">查询参数</param>
- /// <param name="queryJson">查询参数</param>
- /// <returns></returns>
- public IEnumerable<TextBookInfoEntity> GetPageList(Pagination pagination, string queryJson)
- {
- try
- {
- var strSql = new StringBuilder();
- strSql.Append("SELECT ");
- strSql.Append(@" * ");
- strSql.Append(" FROM TextBookInfo t ");
- strSql.Append(" WHERE 1=1 ");
- var queryParam = queryJson.ToJObject();
- // 虚拟参数
- var dp = new DynamicParameters(new { });
- if (!queryParam["TextBookName"].IsEmpty())
- {
- dp.Add("TextBookName", "%" + queryParam["TextBookName"].ToString() + "%", DbType.String);
- strSql.Append(" AND t.TextBookName Like @TextBookName ");
- }
- if (!queryParam["DeptNo"].IsEmpty())
- {
- dp.Add("DeptNo", queryParam["DeptNo"].ToString(), DbType.String);
- strSql.Append(" AND t.DeptNo = @DeptNo ");
- }
- if (!queryParam["TextBookType"].IsEmpty())
- {
- dp.Add("TextBookType", queryParam["TextBookType"].ToString(), DbType.String);
- strSql.Append(" AND t.TextBookType = @TextBookType ");
- }
- if (!queryParam["TextBookNature"].IsEmpty())
- {
- dp.Add("TextBookNature", queryParam["TextBookNature"].ToString(), DbType.String);
- strSql.Append(" AND t.TextBookNature = @TextBookNature ");
- }
-
- if (!queryParam["SqlParameter"].IsEmpty())
- {
- strSql.Append(queryParam["SqlParameter"].ToString());
- }
- return this.BaseRepository("CollegeMIS").FindList<TextBookInfoEntity>(strSql.ToString(), dp, pagination);
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowServiceException(ex);
- }
- }
- }
-
- /// <summary>
- /// 获取TextBookInfo表实体数据
- /// </summary>
- /// <param name="keyValue">主键</param>
- /// <returns></returns>
- public TextBookInfoEntity GetTextBookInfoEntity(string keyValue)
- {
- try
- {
- return this.BaseRepository("CollegeMIS").FindEntity<TextBookInfoEntity>(keyValue);
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowServiceException(ex);
- }
- }
- }
-
- #endregion
-
- #region 提交数据
-
- /// <summary>
- /// 删除实体数据
- /// </summary>
- /// <param name="keyValue">主键</param>
- public void DeleteEntity(string keyValue)
- {
- var db = this.BaseRepository("CollegeMIS").BeginTrans();
- try
- {
- var keyValueArr = keyValue.Split(',');
- foreach (var item in keyValueArr)
- {
- var entity = BaseRepository("CollegeMIS").FindEntity<TextBookInfoEntity>(x => x.ID == item);
- entity.IsDel = 1;
- db.Update(entity);
- }
- db.Commit();
- }
- catch (Exception ex)
- {
- db.Rollback();
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowServiceException(ex);
- }
- }
- }
-
- /// <summary>
- /// 保存实体数据(新增、修改)
- /// </summary>
- /// <param name="keyValue">主键</param>
- /// <param name="entity">实体</param>
- public void SaveEntity(string keyValue, TextBookInfoEntity 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
-
- #region 扩展数据
- /// <summary>
- /// 启用或禁用
- /// </summary>
- /// <param name="keyValue"></param>
- public void EnabOrDisabEntity(string keyValue, string IsValid)
- {
- var db = this.BaseRepository("CollegeMIS").BeginTrans();
- try
- {
- var keyValueArr = keyValue.Split(',');
- foreach (var item in keyValueArr)
- {
- var entity = BaseRepository("CollegeMIS").FindEntity<TextBookInfoEntity>(x => x.ID == item);
- entity.IsValid = IsValid.ToString() == "1" ? true : false;
- db.Update(entity);
- }
- db.Commit();
- }
- catch (Exception ex)
- {
- db.Rollback();
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowServiceException(ex);
- }
- }
- }
- /// <summary>
- /// 去重
- /// </summary>
- /// <param name="keyValue"></param>
- /// <param name="TextBookNo"></param>
- /// <param name="TextBookName"></param>
- /// <param name="PublishNo"></param>
- /// <param name="DeptNo"></param>
- /// <param name="Publisher"></param>
- /// <param name="TextBookNature"></param>
- /// <param name="TextBookType"></param>
- /// <param name="Edition"></param>
- /// <param name="Impression"></param>
- /// <returns></returns>
- public TextBookInfoEntity GetRepetitions(string keyValue, string TextBookNo, string TextBookName, string PublishNo, string DeptNo, string Publisher, string TextBookNature, string TextBookType, string Edition, string Impression)
- {
- try
- {
- if (!string.IsNullOrEmpty(keyValue))
- {
- return this.BaseRepository("CollegeMIS").FindEntity<TextBookInfoEntity>(
- x => x.ID != keyValue && x.TextBookNo == TextBookNo && x.TextBookName == TextBookName && x.PublishNo == PublishNo &&
- x.DeptNo == DeptNo && x.PublishNo == Publisher && x.TextBookNature == TextBookNature && x.TextBookType == TextBookType
- && x.Edition == Edition && x.Impression == Impression && x.IsDel == 0);
- }
- else
- {
- return this.BaseRepository("CollegeMIS").FindEntity<TextBookInfoEntity>(
- x => x.TextBookNo == TextBookNo && x.TextBookName == TextBookName && x.PublishNo == PublishNo &&
- x.DeptNo == DeptNo && x.PublishNo == Publisher && x.TextBookNature == TextBookNature && x.TextBookType == TextBookType
- && x.Edition == Edition && x.Impression == Impression && x.IsDel == 0);
- }
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowServiceException(ex);
- }
- }
- }
-
- #endregion
- }
- }
|