Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

4 лет назад
4 лет назад
4 лет назад
4 лет назад
4 лет назад
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. using Learun.Application.Base.SystemModule;
  2. using Learun.Application.OA.File.FilePreview;
  3. using Learun.Util;
  4. using System.Web;
  5. using System.Web.Mvc;
  6. namespace Learun.Application.Web.Areas.LR_SystemModule.Controllers
  7. {
  8. /// <summary>
  9. /// 版 本 Learun-ADMS-Ultimate V7.0.0 数字化智慧校园
  10. /// Copyright (c) 2013-2018 北京泉江科技有限公司
  11. /// 创建人:陈彬彬
  12. /// 日 期:2017.03.08
  13. /// 描 述:附件管理
  14. /// </summary>
  15. public class AnnexesController : MvcControllerBase
  16. {
  17. private AnnexesFileIBLL annexesFileIBLL = new AnnexesFileBLL();
  18. #region 视图功能
  19. /// <summary>
  20. /// 上传列表页面
  21. /// </summary>
  22. /// <returns></returns>
  23. [HttpGet]
  24. public ActionResult UploadForm()
  25. {
  26. return View();
  27. }
  28. /// <summary>
  29. /// 下载列表页面
  30. /// </summary>
  31. /// <returns></returns>
  32. [HttpGet]
  33. public ActionResult DownForm()
  34. {
  35. return View();
  36. }
  37. #endregion
  38. #region 提交数据
  39. /// <summary>
  40. /// 上传附件分片数据
  41. /// </summary>
  42. /// <param name="fileGuid">文件主键</param>
  43. /// <param name="chunk">分片序号</param>
  44. /// <param name="Filedata">文件数据</param>
  45. /// <returns></returns>
  46. [HttpPost]
  47. [ValidateAntiForgeryToken]
  48. public ActionResult UploadAnnexesFileChunk(string fileGuid, int chunk, int chunks, HttpPostedFileBase Filedata)
  49. {
  50. //没有文件上传,直接返回
  51. if (Filedata == null || string.IsNullOrEmpty(Filedata.FileName) || Filedata.ContentLength == 0)
  52. {
  53. if (Request.Files.Count > 0)
  54. {
  55. Filedata = Request.Files[0];
  56. }
  57. else
  58. {
  59. return HttpNotFound();
  60. }
  61. }
  62. annexesFileIBLL.SaveChunkAnnexes(fileGuid, chunk, Filedata.InputStream);
  63. return Success("保存成功");
  64. }
  65. /// <summary>
  66. /// 移除附件分片数据
  67. /// </summary>
  68. /// <param name="fileGuid">文件主键</param>
  69. /// <param name="chunks">总分片数</param>
  70. /// <returns></returns>
  71. [HttpPost]
  72. [ValidateAntiForgeryToken]
  73. public ActionResult RemoveAnnexesFileChunk(string fileGuid, int chunks)
  74. {
  75. annexesFileIBLL.RemoveChunkAnnexes(fileGuid, chunks);
  76. return Success("移除成功");
  77. }
  78. /// <summary>
  79. /// 合并上传附件的分片数据
  80. /// </summary>
  81. /// <param name="folderId">附件夹主键</param>
  82. /// <param name="fileGuid">文件主键</param>
  83. /// <param name="fileName">文件名</param>
  84. /// <param name="chunks">文件总分片数</param>
  85. /// <returns></returns>
  86. [HttpPost]
  87. [ValidateAntiForgeryToken]
  88. public ActionResult MergeAnnexesFile(string folderId, string fileGuid, string fileName, int chunks, string filePath)
  89. {
  90. UserInfo userInfo = LoginUserInfo.Get();
  91. string path = "";
  92. if (!string.IsNullOrEmpty(filePath))
  93. {
  94. path = Config.GetValue(filePath);
  95. //如果是相对路径先转换成绝对路径
  96. if (path.Contains("~"))
  97. {
  98. path = Server.MapPath(path);
  99. }
  100. }
  101. bool res = annexesFileIBLL.SaveAnnexes(folderId, fileGuid, fileName, chunks, userInfo, path);
  102. if (res)
  103. {
  104. return Success("保存文件成功");
  105. }
  106. else
  107. {
  108. return Fail("保存文件失败");
  109. }
  110. }
  111. /// <summary>
  112. /// 删除文件
  113. /// </summary>
  114. /// <param name="fileId">文件主键</param>
  115. /// <returns></returns>
  116. [HttpPost]
  117. [ValidateAntiForgeryToken]
  118. public ActionResult DeleteAnnexesFile(string fileId)
  119. {
  120. AnnexesFileEntity fileInfoEntity = annexesFileIBLL.GetEntity(fileId);
  121. annexesFileIBLL.DeleteEntity(fileId);
  122. //删除文件
  123. if (System.IO.File.Exists(fileInfoEntity.F_FilePath))
  124. {
  125. System.IO.File.Delete(fileInfoEntity.F_FilePath);
  126. }
  127. return Success("删除附件成功");
  128. }
  129. #endregion
  130. #region 获取数据
  131. /// <summary>
  132. /// 下载文件
  133. /// </summary>
  134. /// <param name="fileId">文件id</param>
  135. /// <returns></returns>
  136. [HttpPost]
  137. public void DownAnnexesFile(string fileId)
  138. {
  139. var data = annexesFileIBLL.GetEntity(fileId);
  140. string filename = Server.UrlDecode(data.F_FileName);//返回客户端文件名称
  141. string filepath = data.F_FilePath;
  142. if (FileDownHelper.FileExists(filepath))
  143. {
  144. FileDownHelper.DownLoadold(filepath, filename);
  145. }
  146. }
  147. /// <summary>
  148. /// 获取附件列表
  149. /// </summary>
  150. /// <param name="folderId">附件夹主键</param>
  151. /// <returns></returns>
  152. [HttpGet]
  153. public ActionResult GetAnnexesFileList(string folderId)
  154. {
  155. var data = annexesFileIBLL.GetList(folderId);
  156. return JsonResult(data);
  157. }
  158. /// <summary>
  159. /// 获取附件夹信息
  160. /// </summary>
  161. /// <param name="folderId">附件夹主键</param>
  162. /// <returns></returns>
  163. [HttpGet]
  164. public ActionResult GetFileNames(string folderId)
  165. {
  166. var data = annexesFileIBLL.GetFileNames(folderId);
  167. return Success(data);
  168. }
  169. #endregion
  170. #region 预览附件
  171. /// <summary>
  172. /// 文件预览
  173. /// </summary>
  174. /// <param name="fileId">文件ID</param>
  175. /// <returns></returns>
  176. public void PreviewFile(string fileId)
  177. {
  178. FilePreviewIBLL filePreviewIBLL = new FilePreviewBLL();
  179. var data = annexesFileIBLL.GetEntity(fileId);
  180. if (data == null)
  181. {
  182. return;
  183. }
  184. string filename = data.F_FileName;//客户端保存的文件名
  185. string filepath = data.F_FilePath;//路径
  186. if (data.F_FileType == "xlsx" || data.F_FileType == "xls")
  187. {
  188. filepath = filepath.Substring(0, filepath.LastIndexOf(".")) + ".pdf";//文件名
  189. if (!DirFileHelper.IsExistFile(filepath))
  190. {
  191. filePreviewIBLL.GetExcelData(data.F_FilePath);
  192. }
  193. }
  194. if (data.F_FileType == "docx" || data.F_FileType == "doc")
  195. {
  196. filepath = filepath.Substring(0, filepath.LastIndexOf(".")) + ".pdf";//文件名
  197. if (!DirFileHelper.IsExistFile(filepath))
  198. {
  199. filePreviewIBLL.GetWordData(data.F_FilePath);
  200. }
  201. }
  202. if (data.F_FileType == "ppt" || data.F_FileType == "pptx")
  203. {
  204. filepath = filepath.Substring(0, filepath.LastIndexOf(".")) + ".pdf";//文件名
  205. if (!DirFileHelper.IsExistFile(filepath))
  206. {
  207. filePreviewIBLL.GetPptData(data.F_FilePath);
  208. }
  209. }
  210. Response.ClearContent();
  211. switch (data.F_FileType)
  212. {
  213. case "jpg":
  214. Response.ContentType = "image/jpeg";
  215. break;
  216. case "gif":
  217. Response.ContentType = "image/gif";
  218. break;
  219. case "png":
  220. Response.ContentType = "image/png";
  221. break;
  222. case "bmp":
  223. Response.ContentType = "application/x-bmp";
  224. break;
  225. case "jpeg":
  226. Response.ContentType = "image/jpeg";
  227. break;
  228. case "doc":
  229. Response.ContentType = "application/pdf";
  230. break;
  231. case "docx":
  232. Response.ContentType = "application/pdf";
  233. break;
  234. case "ppt":
  235. Response.ContentType = "application/pdf";
  236. break;
  237. case "pptx":
  238. Response.ContentType = "application/pdf";
  239. break;
  240. case "xls":
  241. Response.ContentType = "application/pdf";
  242. break;
  243. case "xlsx":
  244. Response.ContentType = "application/pdf";
  245. break;
  246. case "pdf":
  247. Response.ContentType = "application/pdf";
  248. break;
  249. case "txt":
  250. Response.ContentType = "text/plain";
  251. break;
  252. case "csv":
  253. Response.ContentType = "";
  254. break;
  255. default:
  256. Response.ContentType = "application/pdf";
  257. break;
  258. }
  259. Response.Charset = "GB2312";
  260. Response.WriteFile(filepath);
  261. //Response.BinaryWrite(ms.ToArray());
  262. }
  263. #endregion
  264. }
  265. }