|
|
|
@ -51,11 +51,12 @@ namespace Myshipping.Application
|
|
|
|
|
[HttpGet("/BookingPrintTemplate/page")]
|
|
|
|
|
public async Task<dynamic> Page([FromQuery] QueryBookingPrintTemplateInput input)
|
|
|
|
|
{
|
|
|
|
|
_rep.Context.QueryFilter.Clear();
|
|
|
|
|
var entities = await _rep.AsQueryable()
|
|
|
|
|
var entities = await _rep.AsQueryable().Filter(null, true)
|
|
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.TypeName), u => u.TypeName.Contains(input.TypeName.Trim()))
|
|
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.FileName), u => u.FileName.Contains(input.FileName.Trim()))
|
|
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.TenantName), u => u.FileName.Contains(input.TenantName.Trim()))
|
|
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.TenantName), u => u.TenantName.Contains(input.TenantName.Trim()))
|
|
|
|
|
.WhereIF(input.IsMain.HasValue, u => u.IsMain == input.IsMain)
|
|
|
|
|
.WhereIF(input.IsSub.HasValue, u => u.IsSub == input.IsSub)
|
|
|
|
|
.ToPagedListAsync(input.PageNo, input.PageSize);
|
|
|
|
|
return entities.XnPagedResult();
|
|
|
|
|
}
|
|
|
|
@ -116,6 +117,8 @@ namespace Myshipping.Application
|
|
|
|
|
TypeName = input.TypeName,
|
|
|
|
|
TenantId = input.TenantId,
|
|
|
|
|
TenantName = input.TenantName,
|
|
|
|
|
IsMain = input.IsMain,
|
|
|
|
|
IsSub = input.IsSub,
|
|
|
|
|
};
|
|
|
|
|
await _rep.InsertAsync(newFile);
|
|
|
|
|
using (var stream = File.Create(fileAbsPath))
|
|
|
|
@ -134,20 +137,6 @@ namespace Myshipping.Application
|
|
|
|
|
[HttpPost("/BookingPrintTemplate/edit")]
|
|
|
|
|
public async Task Update(IFormFile file, [FromForm] UpdateBookingPrintTemplateInput input)
|
|
|
|
|
{
|
|
|
|
|
//未上传打印模板文件
|
|
|
|
|
if (file == null || file.Length == 0)
|
|
|
|
|
{
|
|
|
|
|
throw Oops.Bah(BookingErrorCode.BOOK113);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var opt = App.GetOptions<PrintTemplateOptions>();
|
|
|
|
|
var originalFilename = file.FileName; // 文件原始名称
|
|
|
|
|
var fileSuffix = Path.GetExtension(file.FileName).ToLower(); // 文件后缀
|
|
|
|
|
if (!opt.fileType.Contains(fileSuffix))
|
|
|
|
|
{
|
|
|
|
|
throw Oops.Bah(BookingErrorCode.BOOK114);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var cc = _rep.AsQueryable().Filter(null, true).Count(c => c.TenantId == input.TenantId && c.TypeCode == input.TypeCode && c.Id != input.Id);
|
|
|
|
|
if (cc > 0)
|
|
|
|
|
{
|
|
|
|
@ -162,33 +151,44 @@ namespace Myshipping.Application
|
|
|
|
|
|
|
|
|
|
entity = input.Adapt(entity);
|
|
|
|
|
|
|
|
|
|
var dirAbs = string.Empty;
|
|
|
|
|
if (string.IsNullOrEmpty(opt.basePath))
|
|
|
|
|
if (file != null)
|
|
|
|
|
{
|
|
|
|
|
dirAbs = Path.Combine(App.WebHostEnvironment.WebRootPath, opt.relativePath);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
dirAbs = Path.Combine(opt.basePath, opt.relativePath);
|
|
|
|
|
}
|
|
|
|
|
var opt = App.GetOptions<PrintTemplateOptions>();
|
|
|
|
|
var originalFilename = file.FileName; // 文件原始名称
|
|
|
|
|
var fileSuffix = Path.GetExtension(file.FileName).ToLower(); // 文件后缀
|
|
|
|
|
if (!opt.fileType.Contains(fileSuffix))
|
|
|
|
|
{
|
|
|
|
|
throw Oops.Bah(BookingErrorCode.BOOK114);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!Directory.Exists(dirAbs))
|
|
|
|
|
Directory.CreateDirectory(dirAbs);
|
|
|
|
|
var dirAbs = string.Empty;
|
|
|
|
|
if (string.IsNullOrEmpty(opt.basePath))
|
|
|
|
|
{
|
|
|
|
|
dirAbs = Path.Combine(App.WebHostEnvironment.WebRootPath, opt.relativePath);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
dirAbs = Path.Combine(opt.basePath, opt.relativePath);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!Directory.Exists(dirAbs))
|
|
|
|
|
Directory.CreateDirectory(dirAbs);
|
|
|
|
|
|
|
|
|
|
// 先存库获取Id
|
|
|
|
|
var fileSaveName = $"{entity.Id}{fileSuffix}".ToLower();
|
|
|
|
|
var fileRelaPath = Path.Combine(opt.relativePath, fileSaveName).ToLower();
|
|
|
|
|
var fileAbsPath = Path.Combine(dirAbs, fileSaveName).ToLower();
|
|
|
|
|
|
|
|
|
|
// 先存库获取Id
|
|
|
|
|
var fileSaveName = $"{entity.Id}{fileSuffix}".ToLower();
|
|
|
|
|
var fileRelaPath = Path.Combine(opt.relativePath, fileSaveName).ToLower();
|
|
|
|
|
var fileAbsPath = Path.Combine(dirAbs, fileSaveName).ToLower();
|
|
|
|
|
entity.FileName = originalFilename;
|
|
|
|
|
entity.FilePath = fileRelaPath;
|
|
|
|
|
|
|
|
|
|
entity.FileName = originalFilename;
|
|
|
|
|
entity.FilePath = fileRelaPath;
|
|
|
|
|
await _rep.UpdateAsync(entity);
|
|
|
|
|
using (var stream = File.Create(fileAbsPath))
|
|
|
|
|
{
|
|
|
|
|
await file.CopyToAsync(stream);
|
|
|
|
|
using (var stream = File.Create(fileAbsPath))
|
|
|
|
|
{
|
|
|
|
|
await file.CopyToAsync(stream);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await _rep.UpdateAsync(entity);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|