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.LogisticsManagement
{
///
/// 版 本 Learun-ADMS-Ultimate V7.0.0 数字化智慧校园
/// Copyright (c) 2013-2018 北京泉江科技有限公司
/// 创 建:超级管理员
/// 日 期:2019-05-05 15:44
/// 描 述:宿舍卫生管理
///
public class SanitationService : RepositoryFactory
{
#region 获取数据
///
/// 获取页面显示列表数据
///
/// 查询参数
///
public IEnumerable GetPageList(Pagination pagination, string queryJson)
{
try
{
var strSql = new StringBuilder();
strSql.Append(@"select fb.* ,zb.ID zbid,zb.AType,zb.Grade,zb.GradedUser,zb.GradedTime,zb.Remark demo from Acc_Sanitation zb
left join(
select ci.*, ad.* from Acc_DormitoryBuild ad
left join (
select aa.classno ,aa.classname,fb1.empno as empnoone,fb1.Mobile as MobileOne,
fb2.empno empnoTwo,fb2.Mobile as MobileTwo from classinfo aa
left join empinfo fb1 on aa.classdiredctorno = fb1.EmpNo
left join empinfo fb2 on aa.ClassTutorNo = fb2.EmpNo
)ci on ci.classno = ad.class
)fb on zb.roomid = fb.id where 1=1 ");
var queryParam = queryJson.ToJObject();
// 虚拟参数
var dp = new DynamicParameters(new { });
if (!queryParam["RoomID"].IsEmpty())
{
dp.Add("RoomID", queryParam["RoomID"].ToString(), DbType.String);
strSql.Append(" AND zb.RoomID =@RoomID ");
}
return this.BaseRepository("CollegeMIS").FindList(strSql.ToString(), dp, pagination).OrderByDescending(a => a.GradedTime).ToList();
}
catch (Exception ex)
{
if (ex is ExceptionEx)
{
throw;
}
else
{
throw ExceptionEx.ThrowServiceException(ex);
}
}
}
///
/// 获取Acc_Sanitation表实体数据
/// 主键
///
///
public Acc_SanitationEntity GetAcc_SanitationEntity(string keyValue)
{
try
{
return this.BaseRepository("CollegeMIS").FindEntity(keyValue);
}
catch (Exception ex)
{
if (ex is ExceptionEx)
{
throw;
}
else
{
throw ExceptionEx.ThrowServiceException(ex);
}
}
}
///
/// 获取树形数据(不包含床位的树数据)
///
///
public List GetSqlTree()
{
try
{
return this.BaseRepository("CollegeMIS").FindList().Where(a => a.BuildType != "5").OrderBy(a => a.Name).ToList();
}
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, Acc_SanitationEntity entity)
{
try
{
var loginuser = LoginUserInfo.Get();
entity.CreateUser = loginuser.realName;
entity.CreateTime = DateTime.Now;
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
}
}