using DS.WMS.PrintApi.Model;
using DS.WMS.PrintApi.Service;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System.IO;
using System;
using System.Threading.Tasks;
namespace DS.WMS.PrintApi.Controllers
{
[Route("printApi/[controller]")]
[ApiController]
public class OpenPrintController : Controller
{
private readonly IOpenPrintService _invokeService;
///
/// 构造函数
///
///
public OpenPrintController(IOpenPrintService invokeService)
{
_invokeService = invokeService;
}
///
/// 根据模板Id获取Json打印信息
///
///
///
[HttpPost]
[AllowAnonymous]
[Route("GetOpenJsonPrintInfoAsync")]
public async Task GetOpenJsonPrintInfo([FromBody] OpenJsonPrintReq req)
{
var res = await _invokeService.GetOpenJsonPrintInfo(req);
return res;
}
///
/// 根据模板Code获取Json打印信息
///
///
///
[HttpPost]
[AllowAnonymous]
[Route("GetOpenJsonPrintInfoByTemplateCode")]
public async Task GetOpenJsonPrintInfoByTemplateCode([FromBody] OpenJsonPrintByCodeReq req)
{
var res = await _invokeService.GetOpenJsonPrintInfoByTemplateCode(req);
return res;
}
///
/// sql数据源打印
///
///
///
[HttpPost]
[AllowAnonymous]
[Route("GetOpenSqlPrintInfo")]
public async Task GetOpenSqlPrintInfo([FromBody] OpenSqlPrintReq req)
{
var res = await _invokeService.GetOpenSqlPrintInfo(req);
return res;
}
///
/// 下载sql打印源文件
///
///
/// 返回打印frx文件
[HttpPost]
[Route("DownloadSqlPrintFile")]
[ProducesResponseType(typeof(FileResult), StatusCodes.Status200OK)]
public async Task DownloadSqlPrintFile([FromBody] OpenSqlPrintReq req)
{
var res = await _invokeService.DownloadSqlPrintFile(req);
var path = res.FilePath;
var fileName = res.FileName;
byte[] byteArr = System.IO.File.ReadAllBytes(res.FilePath);
string mimeType = "application/octet-stream";
return new FileContentResult(byteArr, mimeType)
{
FileDownloadName = fileName
};
//return await _invokeService.DownloadSqlPrintFile(req);
}
}
}