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.

95 lines
3.0 KiB
C#

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;
/// <summary>
/// 构造函数
/// </summary>
/// <param name="invokeService"></param>
public OpenPrintController(IOpenPrintService invokeService)
{
_invokeService = invokeService;
}
/// <summary>
/// 根据模板Id获取Json打印信息
/// </summary>
/// <param name="req"></param>
/// <returns></returns>
[HttpPost]
[AllowAnonymous]
[Route("GetOpenJsonPrintInfoAsync")]
public async Task<PrintDataResult> GetOpenJsonPrintInfo([FromBody] OpenJsonPrintReq req)
{
var res = await _invokeService.GetOpenJsonPrintInfo(req);
return res;
}
/// <summary>
/// 根据模板Code获取Json打印信息
/// </summary>
/// <param name="req"></param>
/// <returns></returns>
[HttpPost]
[AllowAnonymous]
[Route("GetOpenJsonPrintInfoByTemplateCode")]
public async Task<PrintDataResult> GetOpenJsonPrintInfoByTemplateCode([FromBody] OpenJsonPrintByCodeReq req)
{
var res = await _invokeService.GetOpenJsonPrintInfoByTemplateCode(req);
return res;
}
/// <summary>
/// sql数据源打印
/// </summary>
/// <param name="req"></param>
/// <returns></returns>
[HttpPost]
[AllowAnonymous]
[Route("GetOpenSqlPrintInfo")]
public async Task<PrintDataResult> GetOpenSqlPrintInfo([FromBody] OpenSqlPrintReq req)
{
var res = await _invokeService.GetOpenSqlPrintInfo(req);
return res;
}
/// <summary>
/// 下载sql打印源文件
/// </summary>
/// <param name="req"></param>
/// <returns>返回打印frx文件</returns>
[HttpPost]
[Route("DownloadSqlPrintFile")]
[ProducesResponseType(typeof(FileResult), StatusCodes.Status200OK)]
public async Task<IActionResult> 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);
}
}
}