You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

128 lines
4.1 KiB
C#

using DS.Module.Core;
using DS.Module.ExcelModule;
using DS.Module.ExcelModule.Model;
using DS.Module.PrintModule;
using DS.WMS.Core.Code.Interface;
using LanguageExt.Common;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
namespace DS.WMS.MainApi.Controllers
{
/// <summary>
/// 打印服务 模块
/// </summary>
public class PrintController : ApiController
{
private readonly IPrintService _invokeService;
/// <summary>
/// 构造函数
/// </summary>
/// <param name="invokeService"></param>
public PrintController(IPrintService invokeService)
{
_invokeService = invokeService;
}
/// <summary>
/// 获取打印模块列表
/// </summary>
/// <returns></returns>
[HttpGet]
[Route("GetOpenPrintModuleList")]
public DataResult GetOpenPrintModuleList()
{
return _invokeService.GetOpenPrintModuleList();
}
/// <summary>
/// 获取打印模板列表
/// </summary>
/// <returns></returns>
[HttpGet]
[Route("GetOpenPrintTemplateList")]
public DataResult GetOpenPrintTemplateList([FromQuery] string id)
{
return _invokeService.GetOpenPrintTemplateList(id);
}
/// <summary>
/// 获取Json打印信息
/// </summary>
/// <param name="req"></param>
/// <returns></returns>
[HttpPost]
[Route("GetOpenJsonPrintInfo")]
6 months ago
public DataResult<PrintStreamRes> GetOpenJsonPrintInfo([FromBody] OpenJsonPrintReq req)
{
var res =_invokeService.GetOpenJsonPrintStream(req);
6 months ago
return res;
//if (res.Succeeded)
//{
// var printData = res.Data.PrintData;
// HttpContext.Response.Headers.Add("Content-Length", printData.Length.ToString());
// HttpContext.Response.Headers.Add("Content-Type", "charset=UTF-8");
// Byte[] info = Convert.FromBase64String(printData);
// if (res.Data.PrintType =="1")
// {
// return File(info, "application/octet-stream;charset=UTF-8", Guid.NewGuid() + ".pdf");
// }
// else if (res.Data.PrintType == "2")
// {
// return File(info, "application/octet-stream;charset=UTF-8", Guid.NewGuid() + ".xlsx");
// }
// else
// {
// return File(info, "application/octet-stream;charset=UTF-8", Guid.NewGuid() + ".doc");
// }
//}
//else
//{
// throw new Exception(res.Message);
//}
}
/// <summary>
/// 获取Json打印信息Stream
/// </summary>
/// <param name="req"></param>
/// <returns></returns>
[HttpPost]
[Route("GetOpenJsonPrintStream")]
public IActionResult GetOpenJsonPrintStream([FromBody] OpenJsonPrintReq req)
{
var res = _invokeService.GetOpenJsonPrintStream(req);
if (res.Succeeded)
{
var printData = res.Data.PrintData;
6 months ago
//HttpContext.Response.Headers.Add("Content-Length", printData.Length.ToString());
HttpContext.Response.Headers.Add("Content-Type", "charset=UTF-8");
6 months ago
Byte[] info = Convert.FromBase64String(printData);
if (res.Data.PrintType == "1")
{
6 months ago
return File(info, "application/octet-stream;charset=UTF-8", "test.pdf");
}
else if (res.Data.PrintType == "2")
{
6 months ago
return File(info, "application/octet-stream;charset=UTF-8", Guid.NewGuid() + ".xlsx");
}
else
{
6 months ago
return File(info, "application/octet-stream;charset=UTF-8", Guid.NewGuid() + ".doc");
}
6 months ago
}
else
{
6 months ago
throw new Exception(res.Message);
}
}
}
}