|
- 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 V7.0.6 力软敏捷开发框架
- /// Copyright (c) 2013-2020 力软信息技术(苏州)有限公司
- /// 创 建:超级管理员
- /// 日 期:2022-03-05 11:17
- /// 描 述:TextBookOut
- /// </summary>
- public class TextBookOutService : RepositoryFactory
- {
- #region 获取数据
-
- /// <summary>
- /// 获取页面显示列表数据
- /// </summary>
- /// <param name="pagination">查询参数</param>
- /// <param name="queryJson">查询参数</param>
- /// <returns></returns>
- public IEnumerable<TextBookOutEntity> GetPageList(Pagination pagination, string queryJson)
- {
- try
- {
- var strSql = new StringBuilder();
- strSql.Append("SELECT ");
- strSql.Append(@"
- t.Id,
- t.AcademicYearNo,
- t.Semester,
- t.DeptNo,
- t.MajorNo,
- t.ClassNo,
- t.LessonNo,
- t.Variate,
- t.Recipient,
- t.CreateTime,
- t.CrateUserID
- ");
- strSql.Append(" FROM TextBookOut t ");
- strSql.Append(" WHERE 1=1 ");
- var queryParam = queryJson.ToJObject();
- // 虚拟参数
- var dp = new DynamicParameters(new { });
- if (!queryParam["StartTime"].IsEmpty() && !queryParam["EndTime"].IsEmpty())
- {
- dp.Add("startTime", queryParam["StartTime"].ToDate(), DbType.DateTime);
- dp.Add("endTime", queryParam["EndTime"].ToDate(), DbType.DateTime);
- strSql.Append(" AND ( t.CreateTime >= @startTime AND t.CreateTime <= @endTime ) ");
- }
- if (!queryParam["AcademicYearNo"].IsEmpty())
- {
- dp.Add("AcademicYearNo", queryParam["AcademicYearNo"].ToString(), DbType.String);
- strSql.Append(" AND t.AcademicYearNo = @AcademicYearNo ");
- }
- if (!queryParam["Semester"].IsEmpty())
- {
- dp.Add("Semester", queryParam["Semester"].ToString(), DbType.String);
- strSql.Append(" AND t.Semester = @Semester ");
- }
- 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 ");
- }
- if (!queryParam["ClassNo"].IsEmpty())
- {
- dp.Add("ClassNo", queryParam["ClassNo"].ToString(), DbType.String);
- strSql.Append(" AND t.ClassNo = @ClassNo ");
- }
- if (!queryParam["LessonNo"].IsEmpty())
- {
- dp.Add("LessonNo", queryParam["LessonNo"].ToString(), DbType.String);
- strSql.Append(" AND t.LessonNo = @LessonNo ");
- }
- if (!queryParam["Recipient"].IsEmpty())
- {
- dp.Add("Recipient", "%" + queryParam["Recipient"].ToString() + "%", DbType.String);
- strSql.Append(" AND t.Recipient Like @Recipient ");
- }
- return this.BaseRepository("CollegeMIS").FindList<TextBookOutEntity>(strSql.ToString(), dp, pagination);
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowServiceException(ex);
- }
- }
- }
-
- public IEnumerable<TextBookOutEntity> GetListByCode(string code)
- {
- try
- {
- return this.BaseRepository("CollegeMIS").FindList<TextBookOutEntity>(x => x.InOutCode == code);
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowServiceException(ex);
- }
- }
- }
- /// <summary>
- /// 获取TextBookOut表实体数据
- /// </summary>
- /// <param name="keyValue">主键</param>
- /// <returns></returns>
- public TextBookOutEntity GetTextBookOutEntity(string keyValue)
- {
- try
- {
- return this.BaseRepository("CollegeMIS").FindEntity<TextBookOutEntity>(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<TextBookOutEntity>(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 += Num;
- db.Delete(entity);
- db.Update(InOutEntity);
- }
- 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, TextBookOutEntity entity)
- {
- try
- {
- if (keyValue != null)
- {
- 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<TextBookOutEntity> textbookOutList)
- {
- var db = this.BaseRepository("CollegeMIS").BeginTrans();
- try
- {
- var newtextInOutEntity = db.FindEntity<TextbookInOutEntity>(x => x.BookCode == entity.BookCode);
- if (newtextInOutEntity != null)
- {
- decimal? variate = 0;//出库单数量之和,临时
- for (int i = 0; i < textbookOutList.Count; i++)
- {
- textbookOutList[i].InOutCode = entity.BookCode;
- textbookOutList[i].LessonNo = entity.LessonNo;
- textbookOutList[i].PublishNo = entity.PublishNo;
- textbookOutList[i].TextBookNo = entity.TextBookNo;
- textbookOutList[i].TextBookName = entity.TextBookName;
- textbookOutList[i].FirstAuthor = entity.FirstAuthor;
- textbookOutList[i].OtherAuthor = entity.OtherAuthor;
- textbookOutList[i].Publisher = entity.Publisher;
- textbookOutList[i].Edition = entity.Edition;
- textbookOutList[i].Impression = entity.Impression;
- textbookOutList[i].Impression = entity.Impression;
- variate += textbookOutList[i].Variate;
- }
- if (variate > 0 && newtextInOutEntity.FinallyNum >= variate)
- {
- //写入出库单
- db.Insert(textbookOutList);
- //更新出库
- newtextInOutEntity.FinallyNum -= variate;
- newtextInOutEntity.CKNum += variate;
- db.Update(newtextInOutEntity);
- }
- }
- db.Commit();
- }
- catch (Exception ex)
- {
- db.Rollback();
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowServiceException(ex);
- }
- }
- }
- #endregion
-
- }
- }
|