[HttpPost]
public IHttpActionResult DownloadSampleDataExcel([FromBody]DownloadSampleDataExcelModel model)
{
if (model == null || string.IsNullOrEmpty(model.contractids))
{
return Ok(ApiResult.Failed("获取参数错误"));
}
string[] contractId = model.contractids.Split(new char[] { '|', ',', ',' }, StringSplitOptions.RemoveEmptyEntries);
//string[] contractId = new string[] { "84ecace6-31ab-4625-8d8b-5dc92e0e1700" };
//ContractService contractService = new ContractService();
//var result = contractService.GetContractSampleItems(contractId);
//var stream = contractService.CreateTaskExportExcel(result, contractId);
//var stream = contractService.CreateTaskExportExcel(contractId);
SampleItemExportService sampleItemExportService = new SampleItemExportService(contractId);
var stream = sampleItemExportService.CreateExcelStream();
stream.Position = 0;
HttpResponseMessage httpResponseMessage = new HttpResponseMessage();
httpResponseMessage.StatusCode = HttpStatusCode.OK;
httpResponseMessage.Content = new StreamContent(stream);
httpResponseMessage.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
httpResponseMessage.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
{
FileName = Guid.NewGuid()+ ".xls"
};
return ResponseMessage(httpResponseMessage);
}