using Dapper;
using Learun.DataBase.Repository;
using Learun.Util;
using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
namespace Learun.Application.TwoDevelopment.EducationalAdministration
{
///
/// 版 本 Learun-ADMS V7.0.6 力软敏捷开发框架
/// Copyright (c) 2013-2020 力软信息技术(苏州)有限公司
/// 创 建:超级管理员
/// 日 期:2022-03-01 17:26
/// 描 述:教材征订管理
///
public class TextBookSolSubService : RepositoryFactory
{
#region 获取数据
///
/// 获取页面显示列表数据
///
/// 查询参数
/// 查询参数
///
public IEnumerable GetPageList(Pagination pagination, string queryJson)
{
try
{
var strSql = new StringBuilder();
strSql.Append("SELECT ");
strSql.Append(@"
t.*
");
strSql.Append(" FROM TextBookSolSub 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);
}
}
}
///
/// 获取TextBookSolSub表实体数据
///
/// 主键
///
public TextBookSolSubEntity GetTextBookSolSubEntity(string keyValue)
{
try
{
return this.BaseRepository("CollegeMIS").FindEntity(keyValue);
}
catch (Exception ex)
{
if (ex is ExceptionEx)
{
throw;
}
else
{
throw ExceptionEx.ThrowServiceException(ex);
}
}
}
///
/// 获取页面显示列表数据
///
/// 查询参数
/// 查询参数
///
public IEnumerable GetStatistics(Pagination pagination, string queryJson)
{
try
{
var strSql = new StringBuilder();
strSql.Append(@"select t.AcademicYearNo,t.Semester,tbi.PublishNo,t.TextBookName,t.Edition,t.Price,
t.FirstAuthor,t.OtherAuthor,tbi.Impression,tbi.TextBookType,tbi.TextBookNature,tbi.IsWorkBook,tbi.IsTeachConsult,tbi.Pubdate,tbi.Publisher,sum(OrderNum) as DGNum
");
strSql.Append(" from TextBookSolSub t left join TextBookInfo tbi on tbi. PublishNo =t.PublishNo ");
strSql.Append(" where 1=1 ");
var queryParam = queryJson.ToJObject();
// 虚拟参数
if (!queryParam["AcademicYearNo"].IsEmpty())
{
strSql.Append(" AND t.AcademicYearNo = " + queryParam["AcademicYearNo"].ToString() + " ");
}
if (!queryParam["Semester"].IsEmpty())
{
strSql.Append(" AND t.Semester = " + queryParam["Semester"].ToString() + " ");
}
if (!queryParam["TextBookName"].IsEmpty())
{
strSql.Append(" AND t.TextBookName like '%" + queryParam["TextBookName"].ToString() + "%' ");
}
strSql.Append(@" Group By t.AcademicYearNo,t.Semester,tbi.PublishNo,t.TextBookName,t.Edition,t.Price,
t.FirstAuthor,t.OtherAuthor,tbi.Impression,tbi.TextBookType,tbi.TextBookNature,tbi.IsWorkBook,tbi.IsTeachConsult,tbi.Pubdate,tbi.Publisher
");
return this.BaseRepository("CollegeMIS").FindList(strSql.ToString(), pagination);
}
catch (Exception ex)
{
if (ex is ExceptionEx)
{
throw;
}
else
{
throw ExceptionEx.ThrowServiceException(ex);
}
}
}
#endregion
#region 提交数据
///
/// 删除实体数据
///
/// 主键
public void DeleteEntity(string keyValue)
{
try
{
this.BaseRepository("CollegeMIS").Delete(t => t.ID == keyValue);
}
catch (Exception ex)
{
if (ex is ExceptionEx)
{
throw;
}
else
{
throw ExceptionEx.ThrowServiceException(ex);
}
}
}
///
/// 保存实体数据(新增、修改)
///
/// 主键
/// 实体
public void SaveEntity(string keyValue, TextBookSolSubEntity 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);
}
}
}
#endregion
}
}