/// <summary> /// 下载附件 /// </summary> /// <param name="fileId"></param> public void DownLoad(string fileId) { fileId = UtilsHelper.Decrypt(fileId); AttachmentModel fileMode = Global.Business.ServiceProvider.AttachmentService.GetById(int.Parse(fileId)); UtilsHelper.FileDownload(fileMode.FileAccessPrefix, fileMode.FileVirtualPath, fileMode.FileName, (UtilConstants.ServerType)fileMode.FileServerType); }
/// <summary> ///保存知识库 /// </summary> /// <param name="model"></param> /// <param name="Files"></param> public void Save(KnowledgesModel model, HttpFileCollectionBase Files) { if (Files.Count > 0 && Files[0].ContentLength > 0) { int fileServerType = Convert.ToInt32(WebUtils.GetSettingsValue("WebFileType") == null ? "1" : WebUtils.GetSettingsValue("WebFileType")); HttpPostedFileBase file = Files[0]; string targetPath = WebUtils.GetSettingsValue("KnowledgesPDFFilePath"); string SwfFilePath = WebUtils.GetSettingsValue("KnowledgesSwfFilePath"); string targetFileName = StrUtils.GetUniqueFileName(null); string targetFile = string.Format(@"{0}/{1}{2}", targetPath, targetFileName, Path.GetExtension(Files[0].FileName)); string targetSwfPath, pdfFilestr, srcSwfFile, tempFileName; AttachmentModel attModel = null; Stream fileStream = null; try { attModel = UtilsHelper.FileUpload(WebUtils.GetSettingsValue("WebFileServer"), Files[0], targetFile, (UtilConstants.ServerType)fileServerType); fileStream = UtilsHelper.FileDownload(WebUtils.GetSettingsValue("WebFileServer"), attModel.FileVirtualPath, (UtilConstants.ServerType)fileServerType); tempFileName = Guid.NewGuid().ToString(); pdfFilestr = CommonUtils.GetPhysicsPath(string.Format("{0}/{1}.pdf", "/tempFile", tempFileName)); ToolsLib.FileService.NormalFile.SaveInfoToFile(fileStream, pdfFilestr); srcSwfFile = UtilsHelper.PdfToSwf(pdfFilestr, tempFileName + ".swf"); targetSwfPath = string.Format("{0}/{1}.swf", Path.GetDirectoryName(attModel.FileVirtualPath).Replace("Pdf", "Swf"), Path.GetFileNameWithoutExtension(attModel.FileVirtualPath)); if (fileServerType == 1) { fileStream = new FileStream(srcSwfFile, FileMode.Open); ToolsLib.FileService.NormalFile.SaveInfoToFile(fileStream, targetSwfPath); } else { UtilsHelper.FileUpload(WebUtils.GetSettingsValue("WebFileServer"), srcSwfFile, targetSwfPath, (UtilConstants.ServerType)fileServerType); } File.Delete(pdfFilestr); File.Delete(srcSwfFile); } catch (Exception e) { } attModel.FileType = (int)Instrument.Common.Constants.AttachmentBusinessType.本地知识库.GetHashCode(); attModel.UserId = LoginHelper.LoginUser.UserId; attModel.UserName = LoginHelper.LoginUser.UserName; if (model.FileId != 0)//重新上传删除原来文件 { Global.Business.ServiceProvider.AttachmentService.DeleteById(model.FileId); } Global.Business.ServiceProvider.AttachmentService.Save(attModel); model.FileId = attModel.FileId;//新文件位置 } if (model.KnowledgeId == 0) { model.Creator = LoginHelper.LoginUser.UserName; DBProvider.KnowledgesDao.Add(model); } else { DBProvider.KnowledgesDao.Update(model); } }
public ActionResult Send(string contactId) { ContactModel model = ServiceProvider.ContactService.GetById(UtilsHelper.Decrypt2Int(contactId)); //同步到业务系统 IList <BusinessAttachmentModel> businessAttachList = ServiceProvider.BusinessAttachmentService.GetByBusinessTypeAndId(Constants.AttachmentBusinessType.联络单.GetHashCode(), model.ContactId); byte[] fileData = new byte[0]; string fileName = ""; AttachmentModel attach = null; if (businessAttachList.Count > 0 && businessAttachList.First() != null) { attach = Global.Business.ServiceProvider.AttachmentService.GetById(businessAttachList.First().FileId); if (attach != null) { Stream fileStream = UtilsHelper.FileDownload(attach.FileAccessPrefix, attach.FileVirtualPath, (UtilConstants.ServerType)attach.FileServerType); fileData = new byte[fileStream.Length]; fileStream.Read(fileData, 0, (int)fileStream.Length); fileName = attach.FileName + Path.GetExtension(attach.FileVirtualPath); } } model.State = Constants.ContactState.已提交.GetHashCode(); IList <ParamModel> paramList = Global.Business.ServiceProvider.ParamService.GetAll(); ParamModel pCaseType = paramList.SingleOrDefault(p => p.ParamCode.Equals(Common.Constants.SysParamType.ContactCaseType)); if (pCaseType == null) { pCaseType = new ParamModel(); } ParamItemModel itemCaseType = null; itemCaseType = pCaseType.itemsList.SingleOrDefault(c => c.ParamItemValue.Equals(model.CaseType.ToString())); model.CaseTypeStr = itemCaseType == null ? "" : itemCaseType.ParamItemName; string jsonData = WSProvider.EbusinessProvider.SynInsertContact(ToolsLib.Utility.CommonUtils.JsonSerialize(model), fileData, fileName, Global.Business.ServiceProvider.ParamService.GetaccessToken(Instrument.Common.Constants.SysParamType.CompanyInfo)); Dictionary <string, object> dic = ToolsLib.Utility.CommonUtils.JsonDeserialize(jsonData, typeof(Dictionary <string, object>)) as Dictionary <string, object>; if (dic["Msg"].ToString() == "OK") { ServiceProvider.ContactService.UpdateState(model); } return(Content(dic["Msg"].ToString())); }
public ActionResult ReadCert(string Id) { int certId = UtilsHelper.Decrypt2Int(Id); Global.Common.Models.AttachmentModel model = Global.Business.ServiceProvider.AttachmentService.GetById(certId); string tempPath = "/tempFile/"; string tempFileName = string.Format("{0}.swf", Guid.NewGuid().ToString()); string webFileServer = WebUtils.GetSettingsValue("WebFileServer"); string userId = WebUtils.GetSettingsValue("WebFileServerUser"); string pwd = WebUtils.GetSettingsValue("WebFileServerPwd"); string oldFileSwf = model.FileVirtualPath.Replace(".pdf", ".swf"); try { if (!UtilsHelper.IsExistInFSServer(webFileServer, oldFileSwf, userId, pwd)) { if (UtilsHelper.IsExistInFSServer(webFileServer, model.FileVirtualPath, userId, pwd)) { Stream swfStream = UtilsHelper.FileDownload(model.FileAccessPrefix, model.FileVirtualPath, UtilConstants.ServerType.WebFileService); string pdfFilestr = CommonUtils.GetPhysicsPath(string.Format("{0}{1}.pdf", tempPath, Guid.NewGuid())); ToolsLib.FileService.NormalFile.SaveInfoToFile(swfStream, pdfFilestr); string swfSourceFile = UtilsHelper.PdfToSwf(pdfFilestr, tempFileName); model.FileVirtualPath = string.Format("{0}{1}", tempPath, Path.GetFileName(swfSourceFile)); UtilsHelper.FileUpload(model.FileAccessPrefix, swfSourceFile, oldFileSwf, UtilConstants.ServerType.WebFileService); } } else { Stream swfStream = UtilsHelper.FileDownload(model.FileAccessPrefix, oldFileSwf, UtilConstants.ServerType.WebFileService); string swfFilestr = CommonUtils.GetPhysicsPath(string.Format("{0}{1}", tempPath, tempFileName)); ToolsLib.FileService.NormalFile.SaveInfoToFile(swfStream, swfFilestr); model.FileVirtualPath = string.Format("{0}{1}", tempPath, tempFileName); } } catch (Exception e) { return(Content("浏览的文件已经顺坏或者加密")); } return(RedirectToAction("ReadPdf", "SysManage/Common", new { filePath = model.FileVirtualPath })); }
/// <summary> /// 根据本地知识库标识获取知识库信息和业务附件表信息、PDF文件地址信息 /// </summary> /// <param name="knowledgeId"></param> /// <returns></returns> public KnowledgesModel GetKnowledgeDetailInfo(int knowledgeId) { KnowledgesModel model = ServiceProvider.KnowledgesService.GetById(knowledgeId); //组装业务附件表信息 IList <BusinessAttachmentModel> attachList = ServiceProvider.BusinessAttachmentService.GetByBusinessTypeAndId(Instrument.Common.Constants.AttachmentBusinessType.本地知识库.GetHashCode(), knowledgeId); if (attachList.Count > 0) { model.businessAttachList = new List <Hashtable>(); foreach (BusinessAttachmentModel item in attachList) { Hashtable ht = new Hashtable(); AttachmentModel attach = Global.Business.ServiceProvider.AttachmentService.GetById(item.FileId); ht["FileId"] = attach.FileId; ht["FileName"] = attach.FileName; model.businessAttachList.Add(ht); } } //组装flash文件地址信息 if (model.FileId != 0) { AttachmentModel attach = Global.Business.ServiceProvider.AttachmentService.GetById(model.FileId); model.swfFileByte = new byte[] { }; if (attach != null) { string filepath; filepath = string.Format("{0}/{1}.swf", Path.GetDirectoryName(attach.FileVirtualPath).Replace("Pdf", "Swf"), Path.GetFileNameWithoutExtension(attach.FileVirtualPath)); Stream stream = UtilsHelper.FileDownload(attach.FileAccessPrefix, filepath, (UtilConstants.ServerType)attach.FileServerType); int count = Convert.ToInt32(stream.Length); Byte[] bytes = new Byte[count]; stream.Read(bytes, 0, count); model.swfFileByte = bytes; } } return(model); }