DownloadController.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.Mvc;
  6. using AirWheel.Cycling.Domain;
  7. using AirWheel.Cycling.Common;
  8. using AirWheel.Cycling.Service.IService;
  9. using AirWheel.Cycling.Common.Enums;
  10. using AirWheel.Cycling.WebPage.Controllers;
  11. namespace AirWheel.Cycling.WebPage.Areas.ComManage.Controllers
  12. {
  13. public class DownloadController : BaseController
  14. {
  15. #region 声明容器
  16. /// <summary>
  17. /// 下载管理
  18. /// </summary>
  19. IDownloadManage DownloadManage { get; set; }
  20. /// <summary>
  21. /// 上传的文件记录
  22. /// </summary>
  23. IUploadManage UploadManage { get; set; }
  24. #endregion
  25. #region 公共变量
  26. //文件ID
  27. string fileid = string.Empty;
  28. #endregion
  29. #region 基本视图
  30. /// <summary>
  31. /// 加载首页
  32. /// </summary>
  33. [UserAuthorizeAttribute(ModuleAlias = "Download", OperaAction = "View")]
  34. public ActionResult Index()
  35. {
  36. ViewBag.Search = base.keywords;
  37. return View(BindList());
  38. }
  39. /// <summary>
  40. /// 查询列表方法
  41. /// </summary>
  42. private PageInfo BindList()
  43. {
  44. var config = this.DownloadManage.Config;
  45. var query = (from r in config.COM_DOWNLOAD
  46. join u in config.COM_UPLOAD on r.FK_UPID equals u.ID
  47. select new
  48. {
  49. r.ID,
  50. r.DLDATE,
  51. r.DLIP,
  52. r.DLNUM,
  53. r.DLOPERATOR,
  54. r.FK_UPID,
  55. r.FK_USERID,
  56. FILENAME = u.UPOLDNAME,
  57. u.UPFILEPATH
  58. });
  59. if (!string.IsNullOrEmpty(base.keywords))
  60. {
  61. query = query.Where(p => p.DLOPERATOR.Contains(keywords));
  62. }
  63. return this.DownloadManage.Query(query, base.page, base.pagesize);
  64. }
  65. /// <summary>
  66. /// 加载详情
  67. /// </summary>
  68. [UserAuthorizeAttribute(ModuleAlias = "Download", OperaAction = "Detail")]
  69. public ActionResult Detail(string id)
  70. {
  71. var entity = this.DownloadManage.Get(p => p.ID == id) ?? new COM_DOWNLOAD();
  72. return View(entity);
  73. }
  74. #endregion
  75. #region 其他调用
  76. /// <summary>
  77. /// 用户下载功能
  78. /// </summary>
  79. [UserAuthorizeAttribute(ModuleAlias = "Download", OperaAction = "Download")]
  80. public ActionResult DownLoadFile()
  81. {
  82. fileid = Request.QueryString["file"];
  83. //文件ID
  84. if (string.IsNullOrEmpty(fileid))
  85. {
  86. Response.Write("<script>alert('^未找到要下载的文件');window.opener=null;window.open('', '_self', ''); window.close();</script>");
  87. Response.End();
  88. }
  89. //查找文件ID是否存在
  90. var file = this.UploadManage.Get(p => p.ID == fileid);
  91. if (file == null)
  92. {
  93. Response.Write("<script>alert('未找到要下载的文件');window.opener=null;window.open('', '_self', ''); window.close();</script>");
  94. Response.End();
  95. }
  96. //根据文件路径判断文件是否存在
  97. if (!System.IO.File.Exists(Server.MapPath(file.UPFILEPATH)))
  98. {
  99. Response.Write("<script>alert('下载的文件不存在');window.opener=null;window.open('', '_self', ''); window.close();</script>");
  100. //记录日志,文件缺失
  101. WriteLog(enumOperator.Files, "文件丢失,文件原始名称:" + file.UPOLDNAME + "路径" + file.UPFILEPATH,enumLog4net.ERROR);
  102. Response.End();
  103. }
  104. //记录下载数据
  105. this.DownloadManage.Save(new COM_DOWNLOAD()
  106. {
  107. ID = Guid.NewGuid().ToString(),
  108. FK_UPID = fileid,
  109. FK_USERID = this.CurrentUser.Id,
  110. DLDATE = DateTime.Now,
  111. DLIP = Utils.GetIP(),
  112. DLOPERATOR = this.CurrentUser.Name,
  113. DLNUM = 1
  114. });
  115. //跳转文件路径,进行浏览器下载
  116. Response.Redirect(file.UPFILEURL + file.UPFILEPATH, true);
  117. return new EmptyResult();
  118. }
  119. #endregion
  120. }
  121. }