bugfix:修复附件bug

This commit is contained in:
路 范
2021-10-12 17:17:14 +08:00
parent 30892a757e
commit d9db7d2602
25 changed files with 59 additions and 11 deletions

View File

@@ -17,6 +17,8 @@ using System.IO;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using Furion.RemoteRequest.Extensions;
using Microsoft.AspNetCore.Hosting;
namespace Ewide.NbzsZheliban.Service namespace Ewide.NbzsZheliban.Service
{ {
@@ -26,11 +28,12 @@ namespace Ewide.NbzsZheliban.Service
private readonly ISqlSugarRepository repository; private readonly ISqlSugarRepository repository;
private readonly SqlSugarClient db; private readonly SqlSugarClient db;
private readonly IJsonSerializerProvider _jsonSerializer; private readonly IJsonSerializerProvider _jsonSerializer;
public DataService(ISqlSugarRepository sqlSugarRepository, IJsonSerializerProvider jsonSerializer) public DataService(ISqlSugarRepository sqlSugarRepository, IJsonSerializerProvider jsonSerializer, IHostingEnvironment hostingEnvironment)
{ {
repository = sqlSugarRepository; repository = sqlSugarRepository;
db = repository.Context; db = repository.Context;
_jsonSerializer = jsonSerializer; _jsonSerializer = jsonSerializer;
this._hostingEnvironment = hostingEnvironment;
} }
/// <summary> /// <summary>
@@ -330,22 +333,26 @@ namespace Ewide.NbzsZheliban.Service
throw Oops.Oh("ID错误"); throw Oops.Oh("ID错误");
} }
if (string.IsNullOrEmpty(XyFile)) if (string.IsNullOrEmpty(XyFile))
throw Oops.Oh("未上传附件"); throw Oops.Oh(-2001, "无附件");
var pics = new List<string>(); var pics = new List<string>();
var nbzs_file_path = App.Configuration["nbzs_file_path"]; //var nbzs_file_path = App.Configuration["nbzs_file_path"];
var nbzs_domain = App.Configuration["nbzs_domain"]; var nbzs_domain = App.Configuration["nbzs_domain"];
var filePath = nbzs_file_path + XyFile; var current_domain = App.Configuration["current_domain"];
var filePath = GetCurrentRootPath() + XyFile;
var pdfFile = new FileInfo(filePath); var pdfFile = new FileInfo(filePath);
if (File.Exists(pdfFile.Directory + "\\lock")) if (File.Exists(pdfFile.Directory + "\\lock"))
{ {
var picCount = pdfFile.Directory.GetFiles(pdfFile.Name + "-*.jpg").Length; var picCount = pdfFile.Directory.GetFiles(pdfFile.Name + "-*.jpg").Length;
for (int i = 0; i < picCount; i++) for (int i = 0; i < picCount; i++)
{ {
pics.Add(nbzs_domain + XyFile + "-" + i + ".jpg"); pics.Add(current_domain + XyFile + "-" + i + ".jpg");
} }
} }
else else
{ {
var s = (nbzs_domain + XyFile).GetAsStreamAsync().Result;
StreamToFile(s, XyFile);
MagickReadSettings settings = new MagickReadSettings(); MagickReadSettings settings = new MagickReadSettings();
settings.Density = new Density(400, 400); //设置质量 settings.Density = new Density(400, 400); //设置质量
using (MagickImageCollection images = new MagickImageCollection()) using (MagickImageCollection images = new MagickImageCollection())
@@ -359,7 +366,7 @@ namespace Ewide.NbzsZheliban.Service
image.Format = MagickFormat.Jpg; image.Format = MagickFormat.Jpg;
var imagename = filePath + "-" + i + ".jpg"; var imagename = filePath + "-" + i + ".jpg";
image.Write(imagename); image.Write(imagename);
pics.Add(nbzs_domain + XyFile + "-" + i + ".jpg"); pics.Add(current_domain + XyFile + "-" + i + ".jpg");
if (i == 0) if (i == 0)
{ {
File.WriteAllText(pdfFile.Directory.FullName + "\\lock", "lock"); File.WriteAllText(pdfFile.Directory.FullName + "\\lock", "lock");
@@ -368,11 +375,47 @@ namespace Ewide.NbzsZheliban.Service
} }
catch (Exception ex) catch (Exception ex)
{ {
throw Oops.Oh(ex.Message); //throw Oops.Oh(ex.Message);
throw Oops.Oh(-2002, "无附件文件[" + nbzs_domain + XyFile + "]");
} }
} }
} }
return new { pics, pdf = nbzs_domain + XyFile }; return new { pics, pdf = current_domain + XyFile };
}
private readonly IHostingEnvironment _hostingEnvironment;
private string GetCurrentRootPath()
{
return _hostingEnvironment.WebRootPath;
//return Path.GetDirectoryName(this.GetType().Assembly.Location);
}
private string StreamToFile(Stream s, string filename)
{
var d = GetCurrentRootPath() + filename;
FileInfo f = new(d);
if (!f.Directory.Exists)
f.Directory.Create();
using (MemoryStream stmMemory = new MemoryStream())
{
byte[] buffer = new byte[s.Length];
int i;
//将字节逐个放入到Byte中
while ((i = s.Read(buffer, 0, buffer.Length)) > 0)
{
stmMemory.Write(buffer, 0, i);
}
var fileBytes = stmMemory.ToArray();//文件流Byte需要文件流可直接return不需要下面的保存代码
stmMemory.Close();
using (MemoryStream m = new(fileBytes))
{
using (FileStream fs = new(d, FileMode.OpenOrCreate))
{
m.WriteTo(fs);
fs.Close();
}
m.Close();
}
}
return d;
} }
/// <summary> /// <summary>
/// 分布评估详细 /// 分布评估详细

View File

@@ -38,5 +38,7 @@ namespace Ewide.NbzsZheliban
{ {
return await repository.Ado.GetDataTableAsync("select * from TCodeScore"); ; return await repository.Ado.GetDataTableAsync("select * from TCodeScore"); ;
} }
} }
} }

View File

@@ -46,6 +46,6 @@ http://118.178.224.202:3000/ewide/zsxt_nbzs_h5
https://mapi.zjzwfw.gov.cn/web/mgop/gov-open/zj/2001833218/reserved/index.html#/?1=1&ticket= https://mapi.zjzwfw.gov.cn/web/mgop/gov-open/zj/2001833218/reserved/index.html#/?1=1&ticket=
部署命令 部署命令
dotnet DockerRelease.dll --urls=http://*:9002 --ip="127.0.0.1" --port=9001 dotnet DockerRelease.dll --urls=http://*:9001 --ip="127.0.0.1" --port=9001
dotnet DockerRelease.dll --urls=http://*:9002 --ip="127.0.0.1" --port=9003
dotnet DockerRelease.dll --urls=http://*:9002 --ip="127.0.0.1" --port=9003 dotnet DockerRelease.dll --urls=http://*:9002 --ip="127.0.0.1" --port=9003
dotnet DockerRelease.dll --urls=http://*:9003 --ip="127.0.0.1" --port=9003

View File

@@ -34,7 +34,9 @@
}, },
"AllowedHosts": "*", "AllowedHosts": "*",
"nbzs_file_path": "D:\\1_发布程序", "nbzs_file_path": "D:\\1_发布程序",
"nbzs_domain": "https://zsxt.nbzs.org.cn", "nbzs_domain-bak": "https://zsxt.nbzs.org.cn",
"nbzs_domain": "http://118.178.224.202:2258/",
"current_domain": "http://localhost:5566/",
"CorsAccessorSettings": { "CorsAccessorSettings": {
"PolicyName": "自定义跨域策略名", "PolicyName": "自定义跨域策略名",
"WithOrigins": [ "http://localhost:8080", "https://mapi.zjzwfw.gov.cn" ] "WithOrigins": [ "http://localhost:8080", "https://mapi.zjzwfw.gov.cn" ]