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
{
///
/// 版 本 Learun-ADMS V7.0.6 力软敏捷开发框架
/// Copyright (c) 2013-2020 力软信息技术(苏州)有限公司
/// 创 建:超级管理员
/// 日 期:2022-02-18 14:27
/// 描 述:教材订单管理
///
public class TextBookIndentService : RepositoryFactory
{
#region 获取数据
///
/// 获取页面显示列表数据
///
/// 分页参数
/// 查询参数
///
public IEnumerable 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(strSql.ToString(), dp, pagination);
}
catch (Exception ex)
{
if (ex is ExceptionEx)
{
throw;
}
else
{
throw ExceptionEx.ThrowServiceException(ex);
}
}
}
///
/// 获取TextBookIndent表实体数据
///
/// 主键
///
public TextBookIndentEntity GetTextBookIndentEntity(string keyValue)
{
try
{
return this.BaseRepository("CollegeMIS").FindEntity(keyValue);
}
catch (Exception ex)
{
if (ex is ExceptionEx)
{
throw;
}
else
{
throw ExceptionEx.ThrowServiceException(ex);
}
}
}
///
/// 获取主表实体数据
///
/// 流程实例ID
///
public TextBookIndentEntity GetEntityByProcessId(string processId)
{
try
{
return this.BaseRepository("CollegeMIS").FindEntity(t => t.processId == processId);
}
catch (Exception ex)
{
if (ex is ExceptionEx)
{
throw;
}
else
{
throw ExceptionEx.ThrowServiceException(ex);
}
}
}
///
/// 获取Ass_AssetsInfoApply表实体数据
/// 主键
///
///
public IEnumerable TextBookIndentDetailList(string keyValue)
{
try
{
return this.BaseRepository("CollegeMIS").FindList(t => t.IndentId == keyValue);
}
catch (Exception ex)
{
if (ex is ExceptionEx)
{
throw;
}
else
{
throw ExceptionEx.ThrowServiceException(ex);
}
}
}
#endregion
#region 提交数据
///
/// 删除实体数据
///
/// 主键
public void DeleteEntity(string keyValue)
{
var db = this.BaseRepository("CollegeMIS").BeginTrans();
try
{
db.Delete(t => t.IndentId == keyValue);
db.Delete(t => t.ID == keyValue);
db.Commit();
}
catch (Exception ex)
{
db.Rollback();
if (ex is ExceptionEx)
{
throw;
}
else
{
throw ExceptionEx.ThrowServiceException(ex);
}
}
}
///
/// 保存实体数据(新增、修改)
///
/// 主键
/// 实体
///
public void SaveEntity(string keyValue, TextBookIndentEntity entity, List textbookIndentDateil)
{
var db = this.BaseRepository("CollegeMIS").BeginTrans();
try
{
if (!string.IsNullOrEmpty(keyValue))
{
entity.Modify(keyValue);
db.Update(entity);
db.Delete(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(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);
}
}
}
///
/// 审批后修改状态
///
///
///
public void ChangeStatusByProcessId(int pastatus, string processId)
{
var db = this.BaseRepository("CollegeMIS");
try
{
db.BeginTrans();
var entity = this.BaseRepository("CollegeMIS").FindEntity(a => a.processId == processId);
entity.Status = pastatus;
db.Update(entity);
if (pastatus == 2)
{
//教材订单明细
var detailList = db.FindList(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
}
}