Browse Source

结果导入

bjmzak
DESKTOP-G961P6V\Zhh 1 year ago
parent
commit
42fb774d5b
  1. 8
      ThirdPlugIns/Shentun.Peis.PlugIns.Gem/ImportPacsResultPlugInsGem.cs
  2. 2
      src/Shentun.Peis.Application/ImportPacsResults/ImportPacsResultAppService.cs
  3. 96
      src/Shentun.Peis.Domain/ImageHelper.cs

8
ThirdPlugIns/Shentun.Peis.PlugIns.Gem/ImportPacsResultPlugInsGem.cs

@ -73,11 +73,11 @@ namespace Shentun.Peis.PlugIns.Gem
new CreateImportPacsResultPictureDto()
{
IsPrint = 'Y',
FileTransMode = "0",//0-json,1-url
FileTransMode = "1",//0-json,1-url
FileName = firstData.reportUrl,
FileFormat = "0",//0-图片,1-pdf
FileUrl = Guid.NewGuid().ToString(),
FileBase64 = Shentun.Utilities.FileHelper.ToBase64(firstData.reportUrl)
FileFormat = "1",//0-图片,1-pdf
FileUrl = firstData.reportUrl,
//FileBase64 = Shentun.Utilities.FileHelper.ToBase64(firstData.reportUrl)
},
}

2
src/Shentun.Peis.Application/ImportPacsResults/ImportPacsResultAppService.cs

@ -247,7 +247,7 @@ namespace Shentun.Peis.ImportPacsResults
//0-图片,1-PDF
if (file.FileFormat == "0")
{
pictureUrl = ImageHelper.Base64ToImageInAbsolutePath(absolutePath, fileName, file.FileBase64, firstEntity.patientRegister.Id.ToString(),
pictureUrl = ImageHelper.Base64ToImageUseAbsolutePath(absolutePath, fileName, file.FileBase64, firstEntity.patientRegister.Id.ToString(),
firstEntity.registerCheck.Id.ToString());
}

96
src/Shentun.Peis.Domain/ImageHelper.cs

@ -275,86 +275,46 @@ namespace Shentun.Peis
}
public static string Base64ToImageInAbsolutePath(string AbsolutePath, string fileName, string base64Str, string PatientRegisterId, string RegisterCheckId)
public static string Base64ToImageUseAbsolutePath(string absolutePath, string fileName, string base64Str, string patientRegisterId, string registerCheckId)
{
var ret = "";
try
if (string.IsNullOrWhiteSpace(absolutePath))
{
throw new UserFriendlyException("absolutePath不能为空");
}
base64Str = base64Str.Substring(base64Str.IndexOf(",") + 1);
string savePath = "";
string hostPath = "";
var bitmap = Base64StrToImage(base64Str);
if (bitmap != null)
if (string.IsNullOrWhiteSpace(fileName))
{
string ImageSuffix = "";
if (ImageFormat.Png.Guid == bitmap.RawFormat.Guid)
{
ImageSuffix = ".png";
throw new UserFriendlyException("文件名不能为空");
}
else if (ImageFormat.Gif.Guid == bitmap.RawFormat.Guid)
if (string.IsNullOrWhiteSpace(base64Str))
{
ImageSuffix = ".gif";
throw new UserFriendlyException("base64Str不能为空");
}
else if (ImageFormat.Bmp.Guid == bitmap.RawFormat.Guid)
if (string.IsNullOrWhiteSpace(patientRegisterId))
{
ImageSuffix = ".bmp";
throw new UserFriendlyException("PatientRegisterId不能为空");
}
else
if (string.IsNullOrWhiteSpace(registerCheckId))
{
ImageSuffix = ".jpg";
throw new UserFriendlyException("RegisterCheckId不能为空");
}
string savaDirectory = $"{AbsolutePath}\\pacs\\{DateTime.Now.Year}\\{DateTime.Now.Month}\\{DateTime.Now.Day}\\{PatientRegisterId}\\{RegisterCheckId}";
savePath = $"{savaDirectory}\\{fileName + ImageSuffix}";
hostPath = $"/CheckPictureImg/pacs/{DateTime.Now.Year}/{DateTime.Now.Month}/{DateTime.Now.Day}/{PatientRegisterId}/{RegisterCheckId}/{fileName + ImageSuffix}";
string savaDirectory = $"{absolutePath}\\pacs\\{DateTime.Now.Year}\\{DateTime.Now.Month}\\{DateTime.Now.Day}\\{patientRegisterId}\\{registerCheckId}";
if (!Directory.Exists(savaDirectory))
{
Directory.CreateDirectory(savaDirectory);
}
//图片后缀格式
var suffix = savePath.Substring(savePath.LastIndexOf('.') + 1, savePath.Length - savePath.LastIndexOf('.') - 1).ToLower();
var suffixName = suffix == "png" ? ImageFormat.Png :
suffix == "jpg" || suffix == "jpeg" ? ImageFormat.Jpeg :
suffix == "bmp" ? ImageFormat.Bmp :
suffix == "gif" ? ImageFormat.Gif : ImageFormat.Jpeg;
//这里复制一份对图像进行保存,否则会出现“GDI+ 中发生一般性错误”的错误提示
var bmpNew = new Bitmap(bitmap);
// bmpNew.Save(_hostingEnvironment.ContentRootPath + savePath, suffixName);
var s1 = Directory.GetCurrentDirectory();
string saveurl = Path.Combine(s1, savePath);
bmpNew.Save(saveurl, suffixName);
bmpNew.Dispose();
bitmap.Dispose();
var savePath = $"{savaDirectory}\\{fileName}";
var fullFileName = Base64ToImage(base64Str, savePath);
var ImageSuffix = Path.GetExtension(fullFileName);
var hostPath = $"/CheckPictureImg/pacs/{DateTime.Now.Year}/{DateTime.Now.Month}/{DateTime.Now.Day}/{patientRegisterId}/{registerCheckId}/{fileName + ImageSuffix}";
ret = hostPath;
}
else
{
ret = "";
}
}
catch (Exception ex)
{
ret = "";
}
return ret;
}
@ -482,8 +442,19 @@ namespace Shentun.Peis
return bitmap;
}
public static void ConvertFromBase64(string base64String, string filePath)
public static string Base64ToImage(string base64String, string filePath)
{
if (string.IsNullOrWhiteSpace(filePath))
{
throw new UserFriendlyException("文件名不能为空");
}
if (string.IsNullOrWhiteSpace(base64String))
{
throw new UserFriendlyException("base64Str不能为空");
}
byte[] imageBytes = Convert.FromBase64String(base64String);
using (MemoryStream ms = new MemoryStream(imageBytes, 0, imageBytes.Length))
{
@ -508,7 +479,8 @@ namespace Shentun.Peis
{
ImageSuffix = ".jpg";
}
image.Save(filePath);
image.Save(filePath + ImageSuffix);
return filePath + ImageSuffix;
}
}
}

Loading…
Cancel
Save