1.出库单据、生成出库单据、计算物料时增加货架类型用于区分信息化货架和智能货架的物料 实现分开出
This commit is contained in:
83
WCS.WebApi/Controllers/FileDownLoadController.cs
Normal file
83
WCS.WebApi/Controllers/FileDownLoadController.cs
Normal file
@ -0,0 +1,83 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using NPOI.HPSF;
|
||||
using WCS.BLL.Services.IService;
|
||||
using WCS.Model;
|
||||
using WCS.Model.ApiModel;
|
||||
using WCS.Model.ApiModel.User;
|
||||
using WCS.Model.WebSocketModel;
|
||||
|
||||
namespace WCS.WebApi.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// 文件下载
|
||||
/// </summary>
|
||||
[ApiController]
|
||||
[Route("[controller]")]
|
||||
public class FileDownLoadController : ControllerBase
|
||||
{
|
||||
|
||||
public FileDownLoadController()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
[HttpGet("downloadApp")]
|
||||
public IActionResult downloadApp(string fileName)
|
||||
{
|
||||
// 这里是文件的物理路径,你需要根据实际情况提供
|
||||
var filePath = Path.Combine(Directory.GetCurrentDirectory(), $"Files/{fileName}");
|
||||
|
||||
// 检查文件是否存在
|
||||
if (!System.IO.File.Exists(filePath))
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
// 获取文件流
|
||||
var stream = System.IO.File.OpenRead(filePath);
|
||||
// 设置HTTP响应头,使浏览器知道这是一个附件,应该下载而不是打开
|
||||
Response.Headers.Add("Content-Disposition", "attachment; filename=\"" + fileName + "\"");
|
||||
// 返回文件流作为FileResult
|
||||
return File(stream, "application/octet-stream", fileName);
|
||||
}
|
||||
|
||||
[HttpGet("getLatestAppName")]
|
||||
public ResponseCommon<string> getLatestAppName()
|
||||
{
|
||||
string directoryPath = Path.Combine(Directory.GetCurrentDirectory(), $"Files");
|
||||
|
||||
// 获取目录下的所有文件信息
|
||||
FileInfo[] files = Directory.GetFiles(directoryPath, "*.app")
|
||||
.Select(file => new FileInfo(file))
|
||||
.ToArray();
|
||||
|
||||
if (files == null || files.Length == 0)
|
||||
{
|
||||
return new ResponseCommon<string>()
|
||||
{
|
||||
Code = 201,
|
||||
Message = "服务器不存在App安装包"
|
||||
};
|
||||
}
|
||||
//获取最后修改的一个
|
||||
FileInfo lastModifiedFile = files.OrderByDescending(f => f.LastWriteTime).First();
|
||||
if (lastModifiedFile != null)
|
||||
{
|
||||
return new ResponseCommon<string>()
|
||||
{
|
||||
Code = 200,
|
||||
Data = lastModifiedFile.Name
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
return new ResponseCommon<string>()
|
||||
{
|
||||
Code = 201,
|
||||
Message = "服务器不存在App安装包"
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user