|
- using Dapper;
- using Learun.DataBase.Repository;
- using Learun.Util;
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Text;
- using Learun.Application.TwoDevelopment.LogisticsManagement;
-
- namespace Learun.Application.TwoDevelopment.EducationalAdministration
- {
- /// <summary>
- /// 版 本 Learun-ADMS V7.0.6 力软敏捷开发框架
- /// Copyright (c) 2013-2020 力软信息技术(苏州)有限公司
- /// 创 建:超级管理员
- /// 日 期:2022-03-03 10:15
- /// 描 述:教材入库
- /// </summary>
- public class TextBookInService : RepositoryFactory
- {
- #region 获取数据
-
- /// <summary>
- /// 获取页面显示列表数据
- /// </summary>
- /// <param name="pagination">查询参数</param>
- /// <param name="queryJson">查询参数</param>
- /// <returns></returns>
- public IEnumerable<TextBookInEntity> GetPageList(Pagination pagination, string queryJson)
- {
- try
- {
- var strSql = new StringBuilder();
- strSql.Append("SELECT ");
- strSql.Append(@" * ");
- strSql.Append(" FROM TextBookIn 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 = @TextBookName ");
- }
- return this.BaseRepository("CollegeMIS").FindList<TextBookInEntity>(strSql.ToString(), dp, pagination);
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowServiceException(ex);
- }
- }
- }
-
- /// <summary>
- /// 获取TextBookIn表实体数据
- /// </summary>
- /// <param name="keyValue">主键</param>
- /// <returns></returns>
- public TextBookInEntity GetTextBookInEntity(string keyValue)
- {
- try
- {
- return this.BaseRepository("CollegeMIS").FindEntity<TextBookInEntity>(keyValue);
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowServiceException(ex);
- }
- }
- }
-
- /// <summary>
- /// 获取TextBookIn表RK明细
- /// </summary>
- /// <param name="keyValue">主键</param>
- /// <returns></returns>
- public IEnumerable<TextBookInEntity> GetInEntity(string keyValue)
- {
- try
- {
- return this.BaseRepository("CollegeMIS").FindList<TextBookInEntity>(x => x.InOutCode == 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
- {
- decimal? Num = 0;
- var keyValueArr = keyValue.Split(',');
- foreach (var item in keyValueArr)
- {
- var entity = BaseRepository("CollegeMIS").FindEntity<TextBookInEntity>(x => x.ID == item);
- if (entity != null)
- {
- Num += entity.variate;
- var InOutEntity = db.FindEntity<TextbookInOutEntity>(x => x.BookCode == entity.InOutCode);
- if (InOutEntity != null)
- {
- InOutEntity.FinallyNum = InOutEntity.FinallyNum - Num;
- if (InOutEntity.FinallyNum == 0 || InOutEntity.FinallyNum > 0)
- {
- db.Delete(entity);
- db.Update(InOutEntity);
- }
- else
- {
- db.Rollback();
- }
- }
- else
- {
- db.Rollback();
- }
- }
- }
- 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, TextBookInEntity 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);
- }
- }
- }
-
- /// <summary>
- /// 保存
- /// </summary>
- /// <param name="keyValue"></param>
- /// <param name="entity">库存</param>
- /// <param name="textbookIndentDateil"></param>
- public void SaveEntity(string keyValue, TextbookInOutEntity entity, List<TextBookInEntity> textbookInList)
- {
- var db = this.BaseRepository("CollegeMIS").BeginTrans();
- try
- {
- decimal? variate = 0;
- if (textbookInList.Count > 0)
- {
- for (int i = 0; i < textbookInList.Count; i++)
- {
- textbookInList[i].InOutCode = entity.BookCode;
- textbookInList[i].LessonNo = entity.LessonNo;
- textbookInList[i].PublishNo = entity.PublishNo;
- textbookInList[i].TextBookNo = entity.TextBookNo;
- textbookInList[i].TextBookName = entity.TextBookName;
- textbookInList[i].FirstAuthor = entity.FirstAuthor;
- textbookInList[i].OtherAuthor = entity.OtherAuthor;
- textbookInList[i].Pubdate = entity.Pubdate;
- textbookInList[i].Publisher = entity.Publisher;
- textbookInList[i].Edition = entity.Edition;
- textbookInList[i].Impression = entity.Impression;
- textbookInList[i].Impression = entity.Impression;
- variate += textbookInList[i].variate;
- }
- db.Insert(textbookInList);
-
- if (variate != 0 && variate > 0)
- {
- var newtextInOutEntity = db.FindEntity<TextbookInOutEntity>(x => x.BookCode == entity.BookCode);
- if (newtextInOutEntity != null)
- {
- newtextInOutEntity.FinallyNum += variate;
- newtextInOutEntity.RKNum += variate;
- db.Update(newtextInOutEntity);
- }
- }
- }
- db.Commit();
- }
- catch (Exception ex)
- {
- db.Rollback();
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowServiceException(ex);
- }
- }
- }
- #endregion
-
- }
- }
|