123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293 |
- using LeaRun.Application.Entity.PublicInfoManage;
- using LeaRun.Application.IService.PublicInfoManage;
- using LeaRun.Data;
- using LeaRun.Data.Repository;
- using LeaRun.Util.Extension;
- using System;
- using System.Collections.Generic;
- using System.Data.Common;
- using System.Text;
- namespace LeaRun.Application.Service.PublicInfoManage
- {
- /// <summary>
- /// 版 本 6.1
- /// Copyright (c) 2013-2016 上海力软信息技术有限公司
- /// 创建人:佘赐雄
- /// 日 期:2015.12.15 10:56
- /// 描 述:文件信息
- /// </summary>
- public class FileInfoService : RepositoryFactory<FileInfoEntity>, IFileInfoService
- {
- #region 获取数据
- /// <summary>
- /// 所有文件(夹)列表
- /// </summary>
- /// <param name="folderId">文件夹Id</param>
- /// <param name="userId">用户Id</param>
- /// <returns></returns>
- public IEnumerable<FileInfoEntity> GetList(string folderId, string userId)
- {
- var strSql = new StringBuilder();
- strSql.Append(@"SELECT *
- FROM ( SELECT FolderId AS FileId ,
- ParentId AS FolderId ,
- FolderName AS FileName ,
- '' AS FileSize ,
- 'folder' AS FileType ,
- CreateUserId,
- ModifyDate,
- IsShare
- FROM Base_FileFolder where DeleteMark = 0
- UNION
- SELECT FileId ,
- FolderId ,
- FileName ,
- FileSize ,
- FileType ,
- CreateUserId,
- ModifyDate,
- IsShare
- FROM Base_FileInfo where DeleteMark = 0
- ) t WHERE CreateUserId = @userId");
- var parameter = new List<DbParameter>();
- parameter.Add(DbParameters.CreateDbParameter("@userId", userId));
- if (!folderId.IsEmpty())
- {
- strSql.Append(" AND FolderId = @folderId");
- parameter.Add(DbParameters.CreateDbParameter("@folderId", folderId));
- }
- else
- {
- strSql.Append(" AND FolderId = '0'");
- }
- strSql.Append(" ORDER BY ModifyDate ASC");
- return this.BaseRepository().FindList(strSql.ToString(), parameter.ToArray());
- }
- /// <summary>
- /// 文档列表
- /// </summary>
- /// <param name="userId">用户Id</param>
- /// <returns></returns>
- public IEnumerable<FileInfoEntity> GetDocumentList(string userId)
- {
- var strSql = new StringBuilder();
- strSql.Append(@"SELECT FileId ,
- FolderId ,
- FileName ,
- FileSize ,
- FileType ,
- CreateUserId ,
- ModifyDate,
- IsShare
- FROM Base_FileInfo
- WHERE DeleteMark = 0
- AND FileType IN ( 'log', 'txt', 'pdf', 'doc', 'docx', 'ppt', 'pptx',
- 'xls', 'xlsx' )
- AND CreateUserId = @userId");
- var parameter = new List<DbParameter>();
- parameter.Add(DbParameters.CreateDbParameter("@userId", userId));
- strSql.Append(" ORDER BY ModifyDate ASC");
- return this.BaseRepository().FindList(strSql.ToString(), parameter.ToArray());
- }
- /// <summary>
- /// 图片列表
- /// </summary>
- /// <param name="userId">用户Id</param>
- /// <returns></returns>
- public IEnumerable<FileInfoEntity> GetImageList(string userId)
- {
- var strSql = new StringBuilder();
- strSql.Append(@"SELECT FileId ,
- FolderId ,
- FileName ,
- FileSize ,
- FileType ,
- CreateUserId ,
- ModifyDate
- IsShare
- FROM Base_FileInfo
- WHERE DeleteMark = 0
- AND FileType IN ( 'ico', 'gif', 'jpeg', 'jpg', 'png', 'psd' )
- AND CreateUserId = @userId");
- var parameter = new List<DbParameter>();
- parameter.Add(DbParameters.CreateDbParameter("@userId", userId));
- strSql.Append(" ORDER BY ModifyDate ASC");
- return this.BaseRepository().FindList(strSql.ToString(), parameter.ToArray());
- }
- /// <summary>
- /// 回收站文件(夹)列表
- /// </summary>
- /// <param name="userId">用户Id</param>
- /// <returns></returns>
- public IEnumerable<FileInfoEntity> GetRecycledList(string userId)
- {
- var strSql = new StringBuilder();
- strSql.Append(@"SELECT *
- FROM ( SELECT FolderId AS FileId ,
- ParentId AS FolderId ,
- FolderName AS FileName ,
- '' AS FileSize ,
- 'folder' AS FileType ,
- CreateUserId,
- ModifyDate
- FROM Base_FileFolder where DeleteMark = 1
- UNION
- SELECT FileId ,
- FolderId ,
- FileName ,
- FileSize ,
- FileType ,
- CreateUserId,
- ModifyDate
- FROM Base_FileInfo where DeleteMark = 1
- ) t WHERE CreateUserId = @userId");
- var parameter = new List<DbParameter>();
- parameter.Add(DbParameters.CreateDbParameter("@userId", userId));
- strSql.Append(" ORDER BY ModifyDate DESC");
- return this.BaseRepository().FindList(strSql.ToString(), parameter.ToArray());
- }
- /// <summary>
- /// 我的文件(夹)共享列表
- /// </summary>
- /// <param name="userId">用户Id</param>
- /// <returns></returns>
- public IEnumerable<FileInfoEntity> GetMyShareList(string userId)
- {
- var strSql = new StringBuilder();
- strSql.Append(@"SELECT *
- FROM ( SELECT FolderId AS FileId ,
- ParentId AS FolderId ,
- FolderName AS FileName ,
- '' AS FileSize ,
- 'folder' AS FileType ,
- CreateUserId,
- ModifyDate
- FROM Base_FileFolder WHERE DeleteMark = 0 AND IsShare = 1
- UNION
- SELECT FileId ,
- FolderId ,
- FileName ,
- FileSize ,
- FileType ,
- CreateUserId,
- ModifyDate
- FROM Base_FileInfo WHERE DeleteMark = 0 AND IsShare = 1
- ) t WHERE CreateUserId = @userId");
- var parameter = new List<DbParameter>();
- parameter.Add(DbParameters.CreateDbParameter("@userId", userId));
- strSql.Append(" ORDER BY ModifyDate DESC");
- return this.BaseRepository().FindList(strSql.ToString(), parameter.ToArray());
- }
- /// <summary>
- /// 他人文件(夹)共享列表
- /// </summary>
- /// <param name="userId">用户Id</param>
- /// <returns></returns>
- public IEnumerable<FileInfoEntity> GetOthersShareList(string userId)
- {
- var strSql = new StringBuilder();
- strSql.Append(@"SELECT *
- FROM ( SELECT FolderId AS FileId ,
- ParentId AS FolderId ,
- FolderName AS FileName ,
- '' AS FileSize ,
- 'folder' AS FileType ,
- CreateUserId,
- CreateUserName,
- ShareTime AS ModifyDate
- FROM Base_FileFolder WHERE DeleteMark = 0 AND IsShare = 1
- UNION
- SELECT FileId ,
- FolderId ,
- FileName ,
- FileSize ,
- FileType ,
- CreateUserId,
- CreateUserName,
- ShareTime AS ModifyDate
- FROM Base_FileInfo WHERE DeleteMark = 0 AND IsShare = 1
- ) t WHERE CreateUserId != @userId");
- var parameter = new List<DbParameter>();
- parameter.Add(DbParameters.CreateDbParameter("@userId", userId));
- strSql.Append(" ORDER BY ModifyDate DESC");
- return this.BaseRepository().FindList(strSql.ToString(), parameter.ToArray());
- }
- /// <summary>
- /// 文件实体
- /// </summary>
- /// <param name="keyValue">主键值</param>
- /// <returns></returns>
- public FileInfoEntity GetEntity(string keyValue)
- {
- return this.BaseRepository().FindEntity(keyValue);
- }
- #endregion
- #region 提交数据
- /// <summary>
- /// 还原文件
- /// </summary>
- /// <param name="keyValue">主键</param>
- public void RestoreFile(string keyValue)
- {
- FileInfoEntity fileInfoEntity = new FileInfoEntity();
- fileInfoEntity.Modify(keyValue);
- fileInfoEntity.DeleteMark = 0;
- this.BaseRepository().Update(fileInfoEntity);
- }
- /// <summary>
- /// 删除文件
- /// </summary>
- /// <param name="keyValue">主键</param>
- public void RemoveForm(string keyValue)
- {
- FileInfoEntity fileInfoEntity = new FileInfoEntity();
- fileInfoEntity.Modify(keyValue);
- fileInfoEntity.DeleteMark = 1;
- this.BaseRepository().Update(fileInfoEntity);
- }
- /// <summary>
- /// 彻底删除文件
- /// </summary>
- /// <param name="keyValue">主键</param>
- public void ThoroughRemoveForm(string keyValue)
- {
- this.BaseRepository().Delete(keyValue);
- }
- /// <summary>
- /// 保存文件表单(新增、修改)
- /// </summary>
- /// <param name="keyValue">主键值</param>
- /// <param name="fileInfoEntity">文件信息实体</param>
- /// <returns></returns>
- public void SaveForm(string keyValue, FileInfoEntity fileInfoEntity)
- {
- if (!string.IsNullOrEmpty(keyValue))
- {
- fileInfoEntity.Modify(keyValue);
- this.BaseRepository().Update(fileInfoEntity);
- }
- else
- {
- fileInfoEntity.Create();
- this.BaseRepository().Insert(fileInfoEntity);
- }
- }
- /// <summary>
- /// 共享文件
- /// </summary>
- /// <param name="keyValue">主键</param>
- /// <param name="IsShare">是否共享:1-共享 0取消共享</param>
- public void ShareFile(string keyValue, int IsShare)
- {
- FileInfoEntity fileInfoEntity = new FileInfoEntity();
- fileInfoEntity.FileId = keyValue;
- fileInfoEntity.IsShare = IsShare;
- fileInfoEntity.ShareTime = DateTime.Now;
- this.BaseRepository().Update(fileInfoEntity);
- }
- #endregion
- }
- }
|