/// <summary> /// 打包下载文件 /// </summary> /// <param name="projectId"></param> /// <param name="bussinessType"></param> /// <param name="wideArea"></param> /// <param name="bigArea"></param> /// <param name="middleArea"></param> /// <param name="smallArea"></param> /// <param name="shopIdStr"></param> /// <param name="keyword"></param> /// <param name="reportFileType"></param> /// <param name="pageNum"></param> /// <param name="pageCount"></param> /// <returns></returns> public string ReportFileDownLoad(string userId, string projectId, string bussinessType, string wideArea, string bigArea, string middleArea, string smallArea, string shopIdStr, string keyword, string reportFileType, int pageNum, int pageCount) { List <ReportFileDto> list = ReportFileDownloadAllByPageSearch(projectId, bussinessType, wideArea, bigArea, middleArea, smallArea, shopIdStr, keyword, reportFileType, pageNum, pageCount); if (list == null || list.Count == 0) { return(""); } string fileStr = ""; string defaultPath = HostingEnvironment.MapPath(@"~/"); string basePath = defaultPath + "DownLoadFile"; //根目录 string downLoadfolder = DateTime.Now.ToString("yyyyMMddHHmmssfff"); //文件下载的文件夹 string folder = basePath + @"\" + downLoadfolder; // 文件下载的路径 string downLoadPath = basePath + @"\" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".zip"; //打包后的文件名 if (!Directory.Exists(basePath)) { Directory.CreateDirectory(basePath); } if (!Directory.Exists(folder)) { Directory.CreateDirectory(folder); } // 从OSS把文件下载到服务器 foreach (ReportFileDto reportFile in list) { fileStr += reportFile.ReportFileName + ";"; if (File.Exists(folder + @"\" + reportFile.ReportFileName)) { File.Delete(folder + @"\" + reportFile.ReportFileName); } try { OSSClientHelper.GetObject(reportFile.Url_OSS, folder + @"\" + reportFile.ReportFileName); } catch (Exception ex) { } } // 打包文件 if (!ZipInForFiles(list, downLoadfolder, basePath, downLoadPath, 9)) { return(""); } // 保存下载记录 if (!string.IsNullOrEmpty(fileStr)) { ReportFileActionLog log = new ReportFileActionLog(); log.Action = "批量下载"; log.InUserId = Convert.ToInt32(userId); log.ProjectId = Convert.ToInt32(projectId); log.ReportFileName = fileStr; ReportFileActionLogSave(log); } return(downLoadPath.Replace(defaultPath, "")); }
public APIResult ReportFileActionLogSave(ReportFileActionLog reportFileActionLog) { try { reportFileService.ReportFileActionLogSave(reportFileActionLog); return(new APIResult() { Status = true, Body = "" }); } catch (Exception ex) { return(new APIResult() { Status = false, Body = ex.Message.ToString() }); } }
public void ReportFileActionLogSave(ReportFileActionLog reportFileActionLog) { reportFileActionLog.InDateTime = DateTime.Now; db.ReportFileActionLog.Add(reportFileActionLog); db.SaveChanges(); }