|
- 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-02 10:37
- /// 描 述:教材库存表
- /// </summary>
- public class TextbookInOutService : RepositoryFactory
- {
- #region 获取数据
-
- /// <summary>
- /// 获取列表数据
- /// </summary>
- /// <param name="queryJson">条件参数</param>
- /// <returns></returns>
- public IEnumerable<TextbookInOutEntity> GetList(string queryJson)
- {
- try
- {
- //参考写法
- var queryParam = queryJson.ToJObject();
- //虚拟参数
- var dp = new DynamicParameters(new { });
- dp.Add("startTime", queryParam["StartTime"].ToDate(), DbType.DateTime);
- var strSql = new StringBuilder();
- strSql.Append("SELECT *");
- strSql.Append(" FROM TextbookInOut t where 1=1 and ISDEl = 0 ");
- return this.BaseRepository("CollegeMIS").FindList<TextbookInOutEntity>(strSql.ToString());
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowServiceException(ex);
- }
- }
- }
-
- /// <summary>
- /// 获取列表分页数据
- /// </summary>
- /// <param name="pagination">分页参数</param>
- /// <param name="queryJson">条件参数</param>
- /// <returns></returns>
- public IEnumerable<TextbookInOutEntity> GetPageList(Pagination pagination, string queryJson)
- {
- try
- {
- var strSql = new StringBuilder();
- strSql.Append("SELECT *");
- strSql.Append(" FROM TextbookInOut t 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["SqlParameter"].IsEmpty())
- {
- string SqlParameter = queryParam["SqlParameter"].ToString();
- strSql.Append(SqlParameter);
- }
- if (!queryParam["keyword"].IsEmpty())
- {
- strSql.Append(" and ( t.TextBookNo like @keyword or t.TextBookName like @keyword or t.FirstAuthor like @keyword )");
- dp.Add("keyword", "%" + queryParam["keyword"].ToString() + "%", DbType.String);
- }
- if (!queryParam["TextBookName"].IsEmpty())
- {
- strSql.Append(" and TextBookName like @TextBookName ");
- dp.Add("TextBookName", "%" + queryParam["TextBookName"].ToString() + "%", DbType.String);
- }
- return this.BaseRepository("CollegeMIS").FindList<TextbookInOutEntity>(strSql.ToString(), dp, pagination);
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowServiceException(ex);
- }
- }
- }
-
- /// <summary>
- /// 获取实体数据
- /// </summary>
- /// <param name="keyValue">主键</param>
- /// <returns></returns>
- public TextbookInOutEntity GetEntity(string keyValue)
- {
- try
- {
- return this.BaseRepository("CollegeMIS").FindEntity<TextbookInOutEntity>(x => x.ID == keyValue && x.IsDel == 0);
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowServiceException(ex);
- }
- }
- }
- /// <summary>
- /// 获取实体数据
- /// </summary>
- /// <param name="keyValue">主键</param>
- /// <returns></returns>
- public IEnumerable<TextbookInOutEntity> GetInOrOutEntity(string keyValue)
- {
- try
- {
- List<TextbookInOutEntity> returnList = new List<TextbookInOutEntity>();
- //TextbookInOutEntity InOutList = new TextbookInOutEntity();
- List<TextBookInEntity> InEntity = this.BaseRepository("CollegeMIS").FindList<TextBookInEntity>(x => x.InOutCode == keyValue).ToList();
- List<TextBookOutEntity> OutEntity = this.BaseRepository("CollegeMIS").FindList<TextBookOutEntity>(x => x.InOutCode == keyValue).ToList();
- if (InEntity.Count() > 0 || OutEntity.Count() > 0)
- {
- for (int i = 0; i < InEntity.Count(); i++)
- {
- TextbookInOutEntity InOutList = new TextbookInOutEntity();
- InOutList.CKORRK = "入库";
- InOutList.InorOut = InEntity[i].InOutCode;
- InOutList.BookCode = InEntity[i].BookCode;
- InOutList.variate = InEntity[i].variate;
- InOutList.CreateTime = InEntity[i].CreateTime;
- InOutList.CrateUserID = InEntity[i].CrateUserID;
- InOutList.Remark = InEntity[i].Remark;
- returnList.Add(InOutList);
- }
- for (int j = 0; j < OutEntity.Count(); j++)
- {
- TextbookInOutEntity InOutList = new TextbookInOutEntity();
- InOutList.CKORRK = "出库";
- InOutList.InorOut = OutEntity[j].InOutCode;
- InOutList.BookCode = OutEntity[j].BookCode;
- InOutList.variate = OutEntity[j].Variate;
- InOutList.CreateTime = OutEntity[j].CreateTime;
- InOutList.CrateUserID = OutEntity[j].CrateUserID;
- InOutList.Remark = OutEntity[j].Remark;
- returnList.Add(InOutList);
- }
- }
- return returnList;
- }
- 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<TextbookInOutEntity>(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>
- /// 保存实体数据(新增、修改)
- /// <param name="keyValue">主键</param>
- /// <param name="entity">实体</param>
- /// </summary>
- public void SaveEntity(string keyValue, TextbookInOutEntity entity)
- {
- try
- {
- if (!string.IsNullOrEmpty(keyValue))
- {
- entity.Modify(keyValue);
- this.BaseRepository("CollegeMIS").Update(entity);
- }
- else
- {
- entity.Create();
- entity.CKNum = 0;
- entity.RKNum = 0;
- this.BaseRepository("CollegeMIS").Insert(entity);
- }
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowServiceException(ex);
- }
- }
- }
-
- /// <summary>
- /// 提交
- /// </summary>
- /// <param name="keyValue"></param>
- public void SubmitEntity(string keyValue)
- {
- var db = this.BaseRepository("CollegeMIS").BeginTrans();
- try
- {
- var keyValueArr = keyValue.Split(',');
- foreach (var item in keyValueArr)
- {
- var entity = BaseRepository("CollegeMIS").FindEntity<TextbookInOutEntity>(x => x.ID == item);
- entity.IsSubmit = 1;
- //添加入库总数
- entity.RKNum += entity.FinallyNum;
- db.Update(entity);
- #region 将本次记录保存出库单
- TextBookInEntity InEntity = new TextBookInEntity
- {
- ID = Guid.NewGuid().ToString(),
- BookCode = "RK" + DateTime.Now.ToString("yyyyMMddHHmmss"),
- InOutCode = entity.BookCode,
- LessonNo = entity.LessonNo,
- PublishNo = entity.PublishNo,
- TextBookNo = entity.TextBookNo,
- TextBookName = entity.TextBookName,
- FirstAuthor = entity.FirstAuthor,
- OtherAuthor = entity.OtherAuthor,
- Pubdate = entity.Pubdate,
- Publisher = entity.Publisher,
- Edition = entity.Edition,
- Impression = entity.Impression,
- variate = entity.FinallyNum,
- CreateTime = DateTime.Now,
- CrateUserID = "system",
- Remark = "初始数据删除需谨慎"
- };
- #endregion
- db.Insert(InEntity);
- }
- db.Commit();
- }
- catch (Exception ex)
- {
- db.Rollback();
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowServiceException(ex);
- }
- }
- }
- #endregion
-
- /// <summary>
- /// 去重
- /// </summary>
- /// <param name="keyValue"></param>
- /// <param name="TextBookNo"></param>
- /// <param name="TextBookName"></param>
- /// <param name="PublishNo"></param>
- /// <param name="Publisher"></param>
- /// <param name="Edition"></param>
- /// <param name="Impression"></param>
- /// <returns></returns>
- public int GetRepetitions(string keyValue, string LessonNo, string TextBookNo, string TextBookName, string PublishNo, string Publisher, string Edition, string Impression)
- {
- try
- {
- var HistoryList = new List<TextbookInOutEntity>();
-
- if (!string.IsNullOrEmpty(keyValue))
- {
- HistoryList = BaseRepository("CollegeMIS").FindList<TextbookInOutEntity>(
- x => x.ID == keyValue && x.LessonNo == LessonNo && x.TextBookNo == TextBookNo && x.TextBookName == TextBookName && x.PublishNo == PublishNo &&
- x.Publisher == Publisher && x.Edition == Edition && x.Impression == Impression && x.IsDel == 0).ToList();
- }
- else
- {
- HistoryList = BaseRepository("CollegeMIS").FindList<TextbookInOutEntity>(
- x => x.LessonNo == LessonNo && x.TextBookNo == TextBookNo && x.TextBookName == TextBookName && x.PublishNo == PublishNo &&
- x.Publisher == Publisher && x.Edition == Edition && x.Impression == Impression && x.IsDel == 0).ToList();
- }
-
- return HistoryList.Count;
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowServiceException(ex);
- }
- }
- }
- }
- }
|