/// <summary> /// 附件文件分片全部上传好后保存 /// </summary> /// <param name="addFileName"></param> /// <param name="flowId"></param> /// <returns></returns> public FileUploadInfo SavePressDetailFileOrdinaryChunk(string addFileName) { if (!addFileName.HasRealValue()) { throw new Exception("请选择文件"); } string fileName = Request["filename"]; if (string.IsNullOrEmpty(fileName)) { fileName = Server.UrlDecode(fileName); } var locationid = Request["locationid"]; var location = Request["location"]; var LocationType = Request["LocationType"]; if (!LocationType.HasRealValue()) { LocationType = location; } var basePath = HMSUtil.GetDocPath(LocationType); var filePath = basePath + DateTime.Today.ToString("yyyyMMdd"); DicCreate(filePath); int sysMaxLength = HMSUtil.GetConfig(EnuInitCode.MaxAttFileSize.ToString()).ToInt(30); int MaxFileLength = 1024 * 1024 * sysMaxLength; FileInfo file = new FileInfo(addFileName); var userToken = AMSAuthentication.GetAuthToken(); var service = new HMSServiceBase(); var db = service.Init(); long fileSize = 0; try { if (!fileName.HasRealValue()) { throw new Exception("文件不能为空"); } if (file.Length > MaxFileLength) { file.Delete(); throw new Exception($"上传的文件的大小超过限制{sysMaxLength}M"); } var fileNameSplits = fileName.Split('.'); fileSize = file.Length; var newFileName = fileNameSplits.FirstOrDefault() + "-" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + Path.GetExtension(fileName); string destinationPath = Path.Combine(filePath, newFileName); file.MoveTo(destinationPath); //对指定格式才会对其进行缩略图的整合 if (new Regex(@"\.(?:jpg|bmp|gif|png)$", RegexOptions.IgnoreCase).IsMatch(fileName.Trim())) { var targetfilename = destinationPath.Insert(destinationPath.LastIndexOf("."), "-Thum"); if (System.IO.File.Exists(targetfilename)) { System.IO.File.Delete(targetfilename); } ImageHelper.MakeThumbnail(destinationPath, targetfilename, 100, 100, "Cut", fileNameSplits.LastOrDefault()); } var accessoryService = new AccessoryService(); var accessory = accessoryService.GetBy(location, locationid, "签收证明", fileNameSplits.FirstOrDefault(), fileNameSplits.LastOrDefault()); if (accessory == null || !accessory.AccessoryId.HasRealValue()) { accessory = new AccessoryEntity() { AccessoryLocation = location, AccessoryLocationId = locationid, AccessoryName = "签收证明", CreateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), CreateUser = AMSAuthentication.GetAuthToken().UserId, CreateUserName = AMSAuthentication.GetAuthToken().RealName, OwnerId = "12345678" }; } else { // 如果已经存在,是修改,则删除之前的文件 var deletePath = basePath + accessory.FileName; if (System.IO.File.Exists(deletePath)) { System.IO.File.Delete(deletePath); } } // 修改和更新都需要的共用部分 accessory.FileName = DateTime.Today.ToString("yyyyMMdd") + "/" + newFileName; accessory.FileSize = fileSize; accessory.LastestAccessDateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); return(accessoryService.SavePresstbDetailAccessory(accessory)); } catch (Exception ex) { file.Delete(); WebLogger.Log($"FileExp:{ex.Message}"); // return JResult.Error("上传未成功,请联系网站管理员"); throw new Exception(ex.Message); } }
/// <summary> /// 附件文件分片全部上传好后保存 /// </summary> /// <param name="addFileName"></param> /// <param name="flowId"></param> /// <returns></returns> public FileUploadInfo SaveAccessoryFileOrdinaryChunk(string addFileName) { if (!addFileName.HasRealValue()) { throw new Exception("请选择文件"); } string fileName = Request["filename"]; if (string.IsNullOrEmpty(fileName)) { fileName = Server.UrlDecode(fileName); } var locationid = Request["locationid"]; var location = Request["location"]; var LocationType = Request["LocationType"]; if (!LocationType.HasRealValue()) { LocationType = location; } var basePath = HMSUtil.GetDocPath(LocationType); var filePath = basePath + DateTime.Today.ToString("yyyyMMdd"); DicCreate(filePath); int sysMaxLength = HMSUtil.GetConfig(EnuInitCode.MaxAttFileSize.ToString()).ToInt(30); int MaxFileLength = 1024 * 1024 * sysMaxLength; FileInfo file = new FileInfo(addFileName); var userToken = AMSAuthentication.GetAuthToken(); var service = new HMSServiceBase(); var db = service.Init(); long fileSize = 0; try { if (file.Length > MaxFileLength) { file.Delete(); throw new Exception($"上传的文件的大小超过限制{sysMaxLength}M"); } fileSize = file.Length; var newFileName = fileName.Split('.').FirstOrDefault() + "-" + DateTime.Now.ToString("yyyyMMddHHmmss") + Path.GetExtension(fileName); string destinationPath = Path.Combine(filePath, newFileName); if (System.IO.File.Exists(destinationPath)) { System.IO.File.Delete(destinationPath); } file.MoveTo(destinationPath); var accessoryService = new AccessoryService(); var accessory = accessoryService.GetBy(location, locationid, fileName); if (accessory == null || !accessory.AccessoryId.HasRealValue()) { accessory = new AccessoryEntity() { AccessoryLocation = location, AccessoryLocationId = locationid, AccessoryName = fileName, CreateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), CreateUser = AMSAuthentication.GetAuthToken().UserId, CreateUserName = AMSAuthentication.GetAuthToken().RealName, CompanyId = AMSAuthentication.GetAuthToken().CompanyId, OwnerId = "12345678" }; } else { // 如果已经存在,是修改,则删除之前的文件 var deletePath = basePath + accessory.FileName; if (System.IO.File.Exists(deletePath)) { System.IO.File.Delete(deletePath); } } // 修改和更新都需要的共用部分 accessory.FileName = DateTime.Today.ToString("yyyyMMdd") + "/" + newFileName; accessory.FileSize = fileSize; accessory.LastestAccessDateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); return(accessoryService.SaveAccessory(accessory)); } catch (Exception ex) { file.Delete(); WebLogger.Log($"FileExp:{ex.Message}"); throw new Exception(ex.Message); } }
/// <summary> /// 工作流附件文件分片全部上传好后保存 /// </summary> /// <param name="addFileName"></param> /// <param name="flowId"></param> /// <returns></returns> public FileUploadInfo SaveFlowFileOrdinaryChunk(string addFileName) { if (!addFileName.HasRealValue()) { throw new Exception("请选择文件"); } string fileName = Request["filename"]; if (string.IsNullOrEmpty(fileName)) { fileName = Server.UrlDecode(fileName); } string tempDirName = Request["tempDirName"]; bool isTemp = false; int sysMaxLength = HMSUtil.GetConfig(EnuInitCode.MaxAttFileSize.ToString()).ToInt(30); int MaxFileLength = 1024 * 1024 * sysMaxLength; FileInfo file = new FileInfo(addFileName); string dirName = tempDirName.HasRealValue() ? tempDirName : HMSUtil.GetFlowDirName(); var userToken = AMSAuthentication.GetAuthToken(); var service = new HMSServiceBase(); var db = service.Init(); decimal flowId = Request["flowId"].ToDecimal(0); var temp = db.Queryable <FlowTemporaryEntity>() .Where(x => x.CreateUser == userToken.UserId && x.FlowId == flowId) .First(); if (temp != null && temp.UploadFolder.HasRealValue()) { dirName = temp.UploadFolder; isTemp = true; } string direction = $@"{new FlowConfig().UploadRoot}\{dirName}\"; long fileSize = 0; try { if (file.Length > MaxFileLength) { file.Delete(); throw new Exception($"上传的文件的大小超过限制{sysMaxLength}M"); } fileSize = file.Length; if (!Directory.Exists(direction)) { FileHelper.CreateDirectory(direction); } string destinationPath = Path.Combine(direction, fileName); if (System.IO.File.Exists(destinationPath)) { System.IO.File.Delete(destinationPath); } file.MoveTo(destinationPath); } catch (Exception ex) { file.Delete(); WebLogger.Log($"FileExp:{ex.Message}"); throw new Exception(ex.Message); } var url = new FlowCommonService().GetAttrUrl(fileName, dirName); var result = new FileUploadInfo { FileName = fileName, DirectorName = dirName, FileSize = fileSize, CreateUser = userToken.RealName, CreateTime = DateTime.Now, Url = url, IsTemp = isTemp, }; return(result); }