|
- 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.AssetManagementSystem;
-
- namespace Learun.Application.TwoDevelopment.EducationalAdministration
- {
- /// <summary>
- /// 版 本 Learun-ADMS V7.0.6 力软敏捷开发框架
- /// Copyright (c) 2013-2020 力软信息技术(苏州)有限公司
- /// 创 建:超级管理员
- /// 日 期:2022-02-18 14:27
- /// 描 述:教材订单管理
- /// </summary>
- public class TextBookIndentService : RepositoryFactory
- {
- #region 获取数据
-
- /// <summary>
- /// 获取页面显示列表数据
- /// </summary>
- /// <param name="pagination">分页参数</param>
- /// <param name="queryJson">查询参数</param>
- /// <returns></returns>
- public IEnumerable<TextBookIndentEntity> GetPageList(Pagination pagination, string queryJson)
- {
- try
- {
- var strSql = new StringBuilder();
- strSql.Append("SELECT ");
- strSql.Append(@" * ");
- strSql.Append(" FROM TextBookIndent 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["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["LessonNo"].IsEmpty())
- {
- dp.Add("LessonNo", queryParam["LessonNo"].ToString(), DbType.String);
- strSql.Append(" AND t.LessonNo = @LessonNo ");
- }
- 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["PublishNo"].IsEmpty())
- {
- dp.Add("PublishNo", "%" + queryParam["PublishNo"].ToString() + "%", DbType.String);
- strSql.Append(" AND t.PublishNo Like @PublishNo ");
- }
- return this.BaseRepository("CollegeMIS").FindList<TextBookIndentEntity>(strSql.ToString(), dp, pagination);
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowServiceException(ex);
- }
- }
- }
-
- /// <summary>
- /// 获取TextBookIndent表实体数据
- /// </summary>
- /// <param name="keyValue">主键</param>
- /// <returns></returns>
- public TextBookIndentEntity GetTextBookIndentEntity(string keyValue)
- {
- try
- {
- return this.BaseRepository("CollegeMIS").FindEntity<TextBookIndentEntity>(keyValue);
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowServiceException(ex);
- }
- }
- }
-
- /// <summary>
- /// 获取主表实体数据
- /// </summary>
- /// <param name="processId">流程实例ID</param>
- /// <returns></returns>
- public TextBookIndentEntity GetEntityByProcessId(string processId)
- {
- try
- {
- return this.BaseRepository("CollegeMIS").FindEntity<TextBookIndentEntity>(t => t.processId == processId);
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowServiceException(ex);
- }
- }
- }
-
- /// <summary>
- /// 获取Ass_AssetsInfoApply表实体数据
- /// <param name="keyValue">主键</param>
- /// <summary>
- /// <returns></returns>
- public IEnumerable<TextBookIndentDetailEntity> TextBookIndentDetailList(string keyValue)
- {
- try
- {
- return this.BaseRepository("CollegeMIS").FindList<TextBookIndentDetailEntity>(t => t.IndentId == 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
- {
- db.Delete<TextBookIndentDetailEntity>(t => t.IndentId == keyValue);
- db.Delete<TextBookIndentEntity>(t => t.ID == keyValue);
- 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>
- /// <returns></returns>
- public void SaveEntity(string keyValue, TextBookIndentEntity entity, List<TextBookIndentDetailEntity> textbookIndentDateil)
- {
- var db = this.BaseRepository("CollegeMIS").BeginTrans();
- try
- {
- if (!string.IsNullOrEmpty(keyValue))
- {
- entity.Modify(keyValue);
- db.Update(entity);
- db.Delete<TextBookIndentDetailEntity>(t => t.IndentId == keyValue);
- foreach (TextBookIndentDetailEntity item in textbookIndentDateil)
- {
- item.Create();
- item.IndentId = keyValue;
- db.Insert(item);
- }
- }
- else
- {
- entity.Create();
- db.Insert(entity);
- foreach (TextBookIndentDetailEntity item in textbookIndentDateil)
- {
- item.Create();
- item.IndentId = entity.ID;
- db.Insert(item);
- }
- }
- db.Commit();
- }
- catch (Exception ex)
- {
- db.Rollback();
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowServiceException(ex);
- }
- }
- }
-
- public void ModifyStatus(string keyValue, string processId)
- {
- try
- {
- var entity = this.BaseRepository("CollegeMIS").FindEntity<TextBookIndentEntity>(a => a.ID == keyValue);
- entity.processId = processId;
- entity.Status = 1;
- this.BaseRepository("CollegeMIS").Update(entity);
- }
- catch (Exception e)
- {
- if (e is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowServiceException(e);
- }
- }
- }
-
- /// <summary>
- /// 审批后修改状态
- /// </summary>
- /// <param name="pastatus"></param>
- /// <param name="processId"></param>
- public void ChangeStatusByProcessId(int pastatus, string processId)
- {
- var db = this.BaseRepository("CollegeMIS");
- try
- {
- db.BeginTrans();
- var entity = this.BaseRepository("CollegeMIS").FindEntity<TextBookIndentEntity>(a => a.processId == processId);
- entity.Status = pastatus;
- db.Update(entity);
-
- if (pastatus == 2)
- {
- //教材订单明细
- var detailList = db.FindList<TextBookIndentDetailEntity>(x => x.IndentId == entity.ID);
-
- //审核通过,添加征订数据
- TextBookSolSubEntity textBookSolSub = new TextBookSolSubEntity();
- textBookSolSub.Create();
- textBookSolSub.TextBookIndentId = entity.ID;
- textBookSolSub.DeptNo = entity.DeptNo;
- textBookSolSub.MajorNo = entity.MajorNo;
- textBookSolSub.LessonNo = entity.LessonNo;
- textBookSolSub.AcademicYearNo = entity.AcademicYearNo;
- textBookSolSub.Semester = entity.Semester;
- textBookSolSub.PublishNo = entity.PublishNo;
- textBookSolSub.TextBookNo = entity.TextBookNo;
- textBookSolSub.TextBookName = entity.TextBookName;
- textBookSolSub.FirstAuthor = entity.FirstAuthor;
- textBookSolSub.OtherAuthor = entity.OtherAuthor;
- textBookSolSub.OrderNum = entity.OrderNum;
- textBookSolSub.Remark = entity.Remark;
- textBookSolSub.Publisher = entity.Publisher;
- textBookSolSub.Edition = entity.Edition;
- textBookSolSub.Price = entity.Price;
- textBookSolSub.ClassSum = entity.ClassSum;
- db.Insert(textBookSolSub);
-
- foreach (var detail in detailList)
- {
- TextBookSolSubDetailEntity textBookSolSubDetail = new TextBookSolSubDetailEntity();
- textBookSolSubDetail.Create();
- textBookSolSubDetail.SolSubId = textBookSolSub.ID;
- textBookSolSubDetail.ClassNo = detail.ClassNo;
- textBookSolSubDetail.TeachSum = detail.TeachSum;
- textBookSolSubDetail.StuSum = detail.StuSum;
- textBookSolSubDetail.Remark = detail.Remark;
- db.Insert(textBookSolSubDetail);
- }
- }
- db.Commit();
- }
- catch (Exception e)
- {
- db.Rollback();
- if (e is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowServiceException(e);
- }
- }
-
- }
- #endregion
-
- }
- }
|