using Learun.DataBase.Repository;
using Learun.Util;
using System;
using System.Collections.Generic;
using System.Text;
namespace Learun.Application.Base.SystemModule
{
///
/// 版 本 Learun-ADMS-Ultimate V7.0.0 数字化智慧校园
/// Copyright (c) 2013-2018 北京泉江科技有限公司
/// 创建人:陈彬彬
/// 日 期:2017.03.08
/// 描 述:附件管理
///
public class AnnexesFileService:RepositoryFactory
{
#region 属性 构造函数
private string fieldSql;
public AnnexesFileService()
{
fieldSql = @"
t.F_Id,
t.F_FolderId,
t.F_FileName,
t.F_FilePath,
t.F_FileSize,
t.F_FileExtensions,
t.F_FileType,
t.F_DownloadCount,
t.F_CreateDate,
t.F_CreateUserId,
t.F_CreateUserName
";
}
#endregion
#region 获取数据
///
/// 获取实体列表
///
/// 主键值串
///
public IEnumerable GetList(string folderId)
{
try
{
StringBuilder strSql = new StringBuilder();
strSql.Append("SELECT " + fieldSql + " FROM LR_Base_AnnexesFile t WHERE t.F_FolderId = (@folderId) Order By t.F_CreateDate ");
return this.BaseRepository().FindList(strSql.ToString(), new { folderId = folderId });
}
catch (Exception ex)
{
if (ex is ExceptionEx)
{
throw;
}
else
{
throw ExceptionEx.ThrowServiceException(ex);
}
}
}
///
/// 根据folderId获取图片
///
///
///
public AnnexesFileEntity GetEntityByFolderId(string folderId)
{
try
{
return BaseRepository().FindEntity(m => m.F_FolderId == folderId);
}
catch (Exception ex)
{
if (ex is ExceptionEx)
{
throw;
}
else
{
throw ExceptionEx.ThrowServiceException(ex);
}
}
}
///
/// 获取附件名称集合
///
/// 主键值
///
public string GetFileNames(string keyValue)
{
try
{
string res = "";
IEnumerable list = GetList(keyValue);
foreach (var item in list)
{
if (!string.IsNullOrEmpty(res))
{
res += ",";
}
res += item.F_FileName;
}
return res;
}
catch (Exception ex)
{
if (ex is ExceptionEx)
{
throw;
}
else
{
throw ExceptionEx.ThrowServiceException(ex);
}
}
}
///
/// 获取附件实体
///
/// 主键
///
public AnnexesFileEntity GetEntity(string keyValue)
{
try
{
var fileEntity = this.BaseRepository().FindEntity(keyValue);
if (fileEntity == null)
{
IEnumerable fileList = GetList(keyValue);
foreach (var item in fileList)
{
return item;
}
}
return fileEntity;
}
catch (Exception ex)
{
if (ex is ExceptionEx)
{
throw;
}
else
{
throw ExceptionEx.ThrowServiceException(ex);
}
}
}
#endregion
#region 提交数据
///
/// 保存数据实体
///
/// 附件夹主键
/// 附件实体数据
public void SaveEntity(string folderId, AnnexesFileEntity annexesFileEntity)
{
try
{
annexesFileEntity.Create();
annexesFileEntity.F_FolderId = folderId;
this.BaseRepository().Insert(annexesFileEntity);
}
catch (Exception ex)
{
if (ex is ExceptionEx)
{
throw;
}
else
{
throw ExceptionEx.ThrowServiceException(ex);
}
}
}
///
/// 删除附件
///
/// 文件主键
/// 文件夹主键
public void DeleteEntity(string fileId)
{
try
{
this.BaseRepository().Delete(new AnnexesFileEntity() { F_Id = fileId });
}
catch (Exception ex)
{
if (ex is ExceptionEx)
{
throw;
}
else
{
throw ExceptionEx.ThrowServiceException(ex);
}
}
}
#endregion
public void SaveEntityByKey(string fId, AnnexesFileEntity annexesFileEntity)
{
try
{
annexesFileEntity.F_Id = fId;
this.BaseRepository().Update(annexesFileEntity);
}
catch (Exception ex)
{
if (ex is ExceptionEx)
{
throw;
}
else
{
throw ExceptionEx.ThrowServiceException(ex);
}
}
}
}
}