FileInfoService.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. using LeaRun.Application.Entity.PublicInfoManage;
  2. using LeaRun.Application.IService.PublicInfoManage;
  3. using LeaRun.Data;
  4. using LeaRun.Data.Repository;
  5. using LeaRun.Util.Extension;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Data.Common;
  9. using System.Text;
  10. namespace LeaRun.Application.Service.PublicInfoManage
  11. {
  12. /// <summary>
  13. /// 版 本 6.1
  14. /// Copyright (c) 2013-2016 上海力软信息技术有限公司
  15. /// 创建人:佘赐雄
  16. /// 日 期:2015.12.15 10:56
  17. /// 描 述:文件信息
  18. /// </summary>
  19. public class FileInfoService : RepositoryFactory<FileInfoEntity>, IFileInfoService
  20. {
  21. #region 获取数据
  22. /// <summary>
  23. /// 所有文件(夹)列表
  24. /// </summary>
  25. /// <param name="folderId">文件夹Id</param>
  26. /// <param name="userId">用户Id</param>
  27. /// <returns></returns>
  28. public IEnumerable<FileInfoEntity> GetList(string folderId, string userId)
  29. {
  30. var strSql = new StringBuilder();
  31. strSql.Append(@"SELECT *
  32. FROM ( SELECT FolderId AS FileId ,
  33. ParentId AS FolderId ,
  34. FolderName AS FileName ,
  35. '' AS FileSize ,
  36. 'folder' AS FileType ,
  37. CreateUserId,
  38. ModifyDate,
  39. IsShare
  40. FROM Base_FileFolder where DeleteMark = 0
  41. UNION
  42. SELECT FileId ,
  43. FolderId ,
  44. FileName ,
  45. FileSize ,
  46. FileType ,
  47. CreateUserId,
  48. ModifyDate,
  49. IsShare
  50. FROM Base_FileInfo where DeleteMark = 0
  51. ) t WHERE CreateUserId = @userId");
  52. var parameter = new List<DbParameter>();
  53. parameter.Add(DbParameters.CreateDbParameter("@userId", userId));
  54. if (!folderId.IsEmpty())
  55. {
  56. strSql.Append(" AND FolderId = @folderId");
  57. parameter.Add(DbParameters.CreateDbParameter("@folderId", folderId));
  58. }
  59. else
  60. {
  61. strSql.Append(" AND FolderId = '0'");
  62. }
  63. strSql.Append(" ORDER BY ModifyDate ASC");
  64. return this.BaseRepository().FindList(strSql.ToString(), parameter.ToArray());
  65. }
  66. /// <summary>
  67. /// 文档列表
  68. /// </summary>
  69. /// <param name="userId">用户Id</param>
  70. /// <returns></returns>
  71. public IEnumerable<FileInfoEntity> GetDocumentList(string userId)
  72. {
  73. var strSql = new StringBuilder();
  74. strSql.Append(@"SELECT FileId ,
  75. FolderId ,
  76. FileName ,
  77. FileSize ,
  78. FileType ,
  79. CreateUserId ,
  80. ModifyDate,
  81. IsShare
  82. FROM Base_FileInfo
  83. WHERE DeleteMark = 0
  84. AND FileType IN ( 'log', 'txt', 'pdf', 'doc', 'docx', 'ppt', 'pptx',
  85. 'xls', 'xlsx' )
  86. AND CreateUserId = @userId");
  87. var parameter = new List<DbParameter>();
  88. parameter.Add(DbParameters.CreateDbParameter("@userId", userId));
  89. strSql.Append(" ORDER BY ModifyDate ASC");
  90. return this.BaseRepository().FindList(strSql.ToString(), parameter.ToArray());
  91. }
  92. /// <summary>
  93. /// 图片列表
  94. /// </summary>
  95. /// <param name="userId">用户Id</param>
  96. /// <returns></returns>
  97. public IEnumerable<FileInfoEntity> GetImageList(string userId)
  98. {
  99. var strSql = new StringBuilder();
  100. strSql.Append(@"SELECT FileId ,
  101. FolderId ,
  102. FileName ,
  103. FileSize ,
  104. FileType ,
  105. CreateUserId ,
  106. ModifyDate
  107. IsShare
  108. FROM Base_FileInfo
  109. WHERE DeleteMark = 0
  110. AND FileType IN ( 'ico', 'gif', 'jpeg', 'jpg', 'png', 'psd' )
  111. AND CreateUserId = @userId");
  112. var parameter = new List<DbParameter>();
  113. parameter.Add(DbParameters.CreateDbParameter("@userId", userId));
  114. strSql.Append(" ORDER BY ModifyDate ASC");
  115. return this.BaseRepository().FindList(strSql.ToString(), parameter.ToArray());
  116. }
  117. /// <summary>
  118. /// 回收站文件(夹)列表
  119. /// </summary>
  120. /// <param name="userId">用户Id</param>
  121. /// <returns></returns>
  122. public IEnumerable<FileInfoEntity> GetRecycledList(string userId)
  123. {
  124. var strSql = new StringBuilder();
  125. strSql.Append(@"SELECT *
  126. FROM ( SELECT FolderId AS FileId ,
  127. ParentId AS FolderId ,
  128. FolderName AS FileName ,
  129. '' AS FileSize ,
  130. 'folder' AS FileType ,
  131. CreateUserId,
  132. ModifyDate
  133. FROM Base_FileFolder where DeleteMark = 1
  134. UNION
  135. SELECT FileId ,
  136. FolderId ,
  137. FileName ,
  138. FileSize ,
  139. FileType ,
  140. CreateUserId,
  141. ModifyDate
  142. FROM Base_FileInfo where DeleteMark = 1
  143. ) t WHERE CreateUserId = @userId");
  144. var parameter = new List<DbParameter>();
  145. parameter.Add(DbParameters.CreateDbParameter("@userId", userId));
  146. strSql.Append(" ORDER BY ModifyDate DESC");
  147. return this.BaseRepository().FindList(strSql.ToString(), parameter.ToArray());
  148. }
  149. /// <summary>
  150. /// 我的文件(夹)共享列表
  151. /// </summary>
  152. /// <param name="userId">用户Id</param>
  153. /// <returns></returns>
  154. public IEnumerable<FileInfoEntity> GetMyShareList(string userId)
  155. {
  156. var strSql = new StringBuilder();
  157. strSql.Append(@"SELECT *
  158. FROM ( SELECT FolderId AS FileId ,
  159. ParentId AS FolderId ,
  160. FolderName AS FileName ,
  161. '' AS FileSize ,
  162. 'folder' AS FileType ,
  163. CreateUserId,
  164. ModifyDate
  165. FROM Base_FileFolder WHERE DeleteMark = 0 AND IsShare = 1
  166. UNION
  167. SELECT FileId ,
  168. FolderId ,
  169. FileName ,
  170. FileSize ,
  171. FileType ,
  172. CreateUserId,
  173. ModifyDate
  174. FROM Base_FileInfo WHERE DeleteMark = 0 AND IsShare = 1
  175. ) t WHERE CreateUserId = @userId");
  176. var parameter = new List<DbParameter>();
  177. parameter.Add(DbParameters.CreateDbParameter("@userId", userId));
  178. strSql.Append(" ORDER BY ModifyDate DESC");
  179. return this.BaseRepository().FindList(strSql.ToString(), parameter.ToArray());
  180. }
  181. /// <summary>
  182. /// 他人文件(夹)共享列表
  183. /// </summary>
  184. /// <param name="userId">用户Id</param>
  185. /// <returns></returns>
  186. public IEnumerable<FileInfoEntity> GetOthersShareList(string userId)
  187. {
  188. var strSql = new StringBuilder();
  189. strSql.Append(@"SELECT *
  190. FROM ( SELECT FolderId AS FileId ,
  191. ParentId AS FolderId ,
  192. FolderName AS FileName ,
  193. '' AS FileSize ,
  194. 'folder' AS FileType ,
  195. CreateUserId,
  196. CreateUserName,
  197. ShareTime AS ModifyDate
  198. FROM Base_FileFolder WHERE DeleteMark = 0 AND IsShare = 1
  199. UNION
  200. SELECT FileId ,
  201. FolderId ,
  202. FileName ,
  203. FileSize ,
  204. FileType ,
  205. CreateUserId,
  206. CreateUserName,
  207. ShareTime AS ModifyDate
  208. FROM Base_FileInfo WHERE DeleteMark = 0 AND IsShare = 1
  209. ) t WHERE CreateUserId != @userId");
  210. var parameter = new List<DbParameter>();
  211. parameter.Add(DbParameters.CreateDbParameter("@userId", userId));
  212. strSql.Append(" ORDER BY ModifyDate DESC");
  213. return this.BaseRepository().FindList(strSql.ToString(), parameter.ToArray());
  214. }
  215. /// <summary>
  216. /// 文件实体
  217. /// </summary>
  218. /// <param name="keyValue">主键值</param>
  219. /// <returns></returns>
  220. public FileInfoEntity GetEntity(string keyValue)
  221. {
  222. return this.BaseRepository().FindEntity(keyValue);
  223. }
  224. #endregion
  225. #region 提交数据
  226. /// <summary>
  227. /// 还原文件
  228. /// </summary>
  229. /// <param name="keyValue">主键</param>
  230. public void RestoreFile(string keyValue)
  231. {
  232. FileInfoEntity fileInfoEntity = new FileInfoEntity();
  233. fileInfoEntity.Modify(keyValue);
  234. fileInfoEntity.DeleteMark = 0;
  235. this.BaseRepository().Update(fileInfoEntity);
  236. }
  237. /// <summary>
  238. /// 删除文件
  239. /// </summary>
  240. /// <param name="keyValue">主键</param>
  241. public void RemoveForm(string keyValue)
  242. {
  243. FileInfoEntity fileInfoEntity = new FileInfoEntity();
  244. fileInfoEntity.Modify(keyValue);
  245. fileInfoEntity.DeleteMark = 1;
  246. this.BaseRepository().Update(fileInfoEntity);
  247. }
  248. /// <summary>
  249. /// 彻底删除文件
  250. /// </summary>
  251. /// <param name="keyValue">主键</param>
  252. public void ThoroughRemoveForm(string keyValue)
  253. {
  254. this.BaseRepository().Delete(keyValue);
  255. }
  256. /// <summary>
  257. /// 保存文件表单(新增、修改)
  258. /// </summary>
  259. /// <param name="keyValue">主键值</param>
  260. /// <param name="fileInfoEntity">文件信息实体</param>
  261. /// <returns></returns>
  262. public void SaveForm(string keyValue, FileInfoEntity fileInfoEntity)
  263. {
  264. if (!string.IsNullOrEmpty(keyValue))
  265. {
  266. fileInfoEntity.Modify(keyValue);
  267. this.BaseRepository().Update(fileInfoEntity);
  268. }
  269. else
  270. {
  271. fileInfoEntity.Create();
  272. this.BaseRepository().Insert(fileInfoEntity);
  273. }
  274. }
  275. /// <summary>
  276. /// 共享文件
  277. /// </summary>
  278. /// <param name="keyValue">主键</param>
  279. /// <param name="IsShare">是否共享:1-共享 0取消共享</param>
  280. public void ShareFile(string keyValue, int IsShare)
  281. {
  282. FileInfoEntity fileInfoEntity = new FileInfoEntity();
  283. fileInfoEntity.FileId = keyValue;
  284. fileInfoEntity.IsShare = IsShare;
  285. fileInfoEntity.ShareTime = DateTime.Now;
  286. this.BaseRepository().Update(fileInfoEntity);
  287. }
  288. #endregion
  289. }
  290. }