|
|
|
@ -7,6 +7,11 @@ using System.IO;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc.Rendering;
|
|
|
|
|
using SqlSugar;
|
|
|
|
|
using static System.Net.Mime.MediaTypeNames;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
|
|
|
|
|
namespace DS.WMS.PrintApi.Service
|
|
|
|
|
{
|
|
|
|
@ -205,7 +210,11 @@ namespace DS.WMS.PrintApi.Service
|
|
|
|
|
return await Task.FromResult(PrintDataResult.Failed(ex.Message));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// sql 打印
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="req"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
|
|
|
|
public async Task<PrintDataResult> GetOpenSqlPrintInfo(OpenSqlPrintReq req)
|
|
|
|
|
{
|
|
|
|
@ -213,10 +222,14 @@ namespace DS.WMS.PrintApi.Service
|
|
|
|
|
{
|
|
|
|
|
using (var db = SqlSugarUtil.GetInstance())
|
|
|
|
|
{
|
|
|
|
|
var template = db.Queryable<SysPrintTemplate>().Filter(null, true).Where(x => x.TenantId == req.TenantId)
|
|
|
|
|
.WhereIF(req.TemplateId!= 0,x=>x.Id ==req.TemplateId)
|
|
|
|
|
if (req.TenantId == 0 || req.TenantId == null)
|
|
|
|
|
{
|
|
|
|
|
return await Task.FromResult(PrintDataResult.Failed("缺失关键参数租户id!"));
|
|
|
|
|
}
|
|
|
|
|
var template = await db.Queryable<SysPrintTemplate>().Filter(null, true).Where(x => x.TenantId == req.TenantId)
|
|
|
|
|
.WhereIF(req.TemplateId!= 0,x=>x.Id == req.TemplateId)
|
|
|
|
|
.WhereIF(!string.IsNullOrEmpty(req.TemplateCode), x => x.Id == req.TemplateId)
|
|
|
|
|
.First();
|
|
|
|
|
.FirstAsync();
|
|
|
|
|
if (template == null)
|
|
|
|
|
{
|
|
|
|
|
return await Task.FromResult(PrintDataResult.Failed("打印模板不存在!"));
|
|
|
|
@ -225,10 +238,21 @@ namespace DS.WMS.PrintApi.Service
|
|
|
|
|
{
|
|
|
|
|
return await Task.FromResult(PrintDataResult.Failed("非Sql打印接口!"));
|
|
|
|
|
}
|
|
|
|
|
if (template == null) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(template.SourceSql))
|
|
|
|
|
{
|
|
|
|
|
return await Task.FromResult(PrintDataResult.Failed("打印数据源不能为空!"));
|
|
|
|
|
}
|
|
|
|
|
if (!template.SourceSql.Contains(';'))
|
|
|
|
|
{
|
|
|
|
|
return await Task.FromResult(PrintDataResult.Failed("数据源必须包含分号!"));
|
|
|
|
|
}
|
|
|
|
|
if (template.SourceSql.Substring(template.SourceSql.Length - 1, 1) != ";")
|
|
|
|
|
{
|
|
|
|
|
return await Task.FromResult(PrintDataResult.Failed("数据源最后必须包含分号!"));
|
|
|
|
|
}
|
|
|
|
|
if (SqlUtil.IsSqlInjection(template.SourceSql))
|
|
|
|
|
{
|
|
|
|
|
return await Task.FromResult(PrintDataResult.Failed("sql数据源包含非法字符,请检查!"));
|
|
|
|
|
}
|
|
|
|
|
if (String.IsNullOrEmpty(template.PrintJsonContent))
|
|
|
|
|
{
|
|
|
|
@ -236,6 +260,39 @@ namespace DS.WMS.PrintApi.Service
|
|
|
|
|
}
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var tenantDb = db.GetConnection(req.TenantId);
|
|
|
|
|
|
|
|
|
|
var data = new Dictionary<string, List<dynamic>>();
|
|
|
|
|
var sugarParams = new List<SugarParameter>();
|
|
|
|
|
if (!string.IsNullOrEmpty(req.ParamJsonStr))
|
|
|
|
|
{
|
|
|
|
|
var param = JsonHelper.Instance.Deserialize<Dictionary<string, string>>(req.ParamJsonStr);
|
|
|
|
|
foreach (var p in param)
|
|
|
|
|
{
|
|
|
|
|
sugarParams.Add(new SugarParameter($"@{p.Key}", p.Value));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (template.SourceSql.Contains(';'))
|
|
|
|
|
{
|
|
|
|
|
var sqlArr = template.SourceSql.Split(';');
|
|
|
|
|
if (sqlArr.Length > 0)
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < sqlArr.Length; i++)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(sqlArr[i]))
|
|
|
|
|
{
|
|
|
|
|
var temp = tenantDb.Ado.SqlQuery<dynamic>(sqlArr[i], sugarParams);
|
|
|
|
|
data.Add("sql" + i, temp);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var basePath = String.Empty;
|
|
|
|
|
var savePath = "wwwroot/PrintTempFile";
|
|
|
|
|
|
|
|
|
@ -256,7 +313,7 @@ namespace DS.WMS.PrintApi.Service
|
|
|
|
|
|
|
|
|
|
var dataSource = report.Dictionary.Connections[0] as JsonDataSourceConnection;
|
|
|
|
|
var str = new FastReport.Data.JsonConnection.JsonDataSourceConnectionStringBuilder();
|
|
|
|
|
//str.Json = req.JsonDataStr;
|
|
|
|
|
str.Json = JsonConvert.SerializeObject(data);
|
|
|
|
|
dataSource.ConnectionString = str.ConnectionString;
|
|
|
|
|
|
|
|
|
|
report.Prepare();
|
|
|
|
@ -268,22 +325,7 @@ namespace DS.WMS.PrintApi.Service
|
|
|
|
|
printName = $"{fileName}.pdf";
|
|
|
|
|
saveFile = Path.Combine(savePath, printName);
|
|
|
|
|
PDFExport pdfExport = new PDFExport();
|
|
|
|
|
pdfExport.Export(report, saveFile);
|
|
|
|
|
|
|
|
|
|
#region 处理托书挂载附件
|
|
|
|
|
|
|
|
|
|
if (template.TemplateCode == "bill_of_lading")
|
|
|
|
|
{
|
|
|
|
|
System.IO.FileStream file = new System.IO.FileStream(saveFile, FileMode.Open, FileAccess.Read);
|
|
|
|
|
var movePath = Path.Combine(AppSetting.Configuration["FileSettings:MovePath"], printName);
|
|
|
|
|
using (var fileStream = File.Create(movePath))
|
|
|
|
|
{
|
|
|
|
|
await file.CopyToAsync(fileStream);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
file.Close();
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
pdfExport.Export(report, saveFile);
|
|
|
|
|
}
|
|
|
|
|
else if (req.PrintType == "2")
|
|
|
|
|
{
|
|
|
|
|