using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Mvc;
|
using WIDESEA_Core;
|
using WIDESEA_Core.BaseController;
|
using WIDESEA_Core.Helper;
|
using System.IO;
|
using WIDESEA_Model.Models;
|
using System;
|
using WIDESEA_StorageSocketServices;
|
using WIDESEAWCS_BasicInfoRepository;
|
using WIDESEAWCS_BasicInfoService;
|
using WIDESEA_DTO.WMS;
|
using WIDESEA_IBusinessServices;
|
|
namespace WIDESEA_WMSServer.Controllers
|
{
|
[Route("api/PDA")]
|
[Authorize, ApiController]
|
[Consumes("application/json")]
|
public class PDAController : Controller
|
{
|
|
private readonly IHttpContextAccessor _httpContextAccessor;
|
private readonly IDt_StationManagerService StationManager;
|
private readonly IDt_HandAutomaticService _handAutomaticService;
|
private readonly IDt_TaskService _taskService;
|
private readonly ILogger<SocketClientService> _logger;
|
public SocketClientService _Socketservice { get; set; }
|
|
public PDAController(IHttpContextAccessor httpContextAccessor, SocketClientService socketClientService, IDt_StationManagerService dt_StationManager, IDt_TaskService taskService, ILogger<SocketClientService> logger,IDt_HandAutomaticService handAutomaticService)
|
{
|
_httpContextAccessor = httpContextAccessor;
|
_Socketservice = socketClientService;
|
StationManager = dt_StationManager;
|
_taskService = taskService;
|
_logger = logger;
|
_handAutomaticService = handAutomaticService;
|
}
|
/// <summary>
|
/// 是否在线
|
/// </summary>
|
/// <returns></returns>
|
[HttpGet, HttpPost, Route("Socketonline"), AllowAnonymous]
|
public bool Socketonline()
|
{
|
return _Socketservice.Socketonline();
|
}
|
|
/// <summary>
|
/// 获取站台状态
|
/// </summary>
|
/// <returns></returns>
|
[HttpGet, HttpPost, Route("GetStationStatus"), AllowAnonymous]
|
public WebResponseContent GetStationStatus()
|
{
|
return StationManager.GetStationStatus();
|
}
|
|
/// <summary>
|
/// 入库
|
/// </summary>
|
/// <returns></returns>
|
[HttpGet, HttpPost, Route("InboundTask"), AllowAnonymous]
|
public WebResponseContent InboundTask([FromBody]TaskDTO taskDTO)
|
{
|
return _taskService.InboundTask(taskDTO);
|
}
|
|
/// <summary>
|
/// 抽检入库
|
/// </summary>
|
/// <returns></returns>
|
[HttpGet, HttpPost, Route("SamplingInboundTask"), AllowAnonymous]
|
public WebResponseContent SamplingInboundTask([FromBody] TaskDTO taskDTO)
|
{
|
return _taskService.SamplingInboundTask(taskDTO);
|
}
|
|
/// <summary>
|
/// 出库
|
/// </summary>
|
/// <returns></returns>
|
[HttpGet, HttpPost, Route("OutboundTask"), AllowAnonymous]
|
public WebResponseContent OutboundTask([FromBody] TaskDTO taskDTO)
|
{
|
return _taskService.OutboundTask(taskDTO);
|
}
|
|
/// <summary>
|
/// 抽检出库
|
/// </summary>
|
/// <returns></returns>
|
[HttpGet, HttpPost, Route("SamplingOutboundTask"), AllowAnonymous]
|
public WebResponseContent SamplingOutboundTask([FromBody] TaskDTO taskDTO)
|
{
|
return _taskService.SamplingOutboundTask(taskDTO);
|
}
|
|
/// <summary>
|
/// 手自动切换
|
/// </summary>
|
/// <returns></returns>
|
[HttpGet, HttpPost, Route("GetAutoStatus"), AllowAnonymous]
|
public bool GetAutoStatus()
|
{
|
return _handAutomaticService.GetAutoStatus();
|
}
|
|
/// <summary>
|
/// 手自动切换
|
/// </summary>
|
/// <returns></returns>
|
[HttpGet, HttpPost, Route("AutoStatus"), AllowAnonymous]
|
public WebResponseContent AutoStatus(string auto)
|
{
|
return _handAutomaticService.AutoStatus(auto);
|
}
|
|
[HttpPost,HttpGet, Route("GetTaskInfo"), AllowAnonymous]
|
public WebResponseContent GetTaskInfo()
|
{
|
return _taskService.GetTaskInfo();
|
}
|
[HttpPost, HttpGet, Route("GetHostError"), AllowAnonymous]
|
public WebResponseContent GetHostError()
|
{
|
return _taskService.GetHostError();
|
}
|
|
[HttpPost, HttpGet, Route("UploadApp"), AllowAnonymous]
|
public async Task<WebResponseContent> UploadApk(IEnumerable<IFormFile> fileInput)
|
{
|
// 检查是否有文件上传
|
if (fileInput == null || !fileInput.Any())
|
{
|
return WebResponseContent.Instance.Error("文件未上传");
|
}
|
|
var formFile = fileInput.First();
|
var uploadFolder = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "Upload");
|
Directory.CreateDirectory(uploadFolder);
|
|
var fileName = $"WMS-PDA.apk";
|
var filePath = Path.Combine(uploadFolder, fileName);
|
|
using (var stream = new FileStream(filePath, FileMode.Create))
|
{
|
await formFile.CopyToAsync(stream);
|
}
|
return WebResponseContent.Instance.OK("文件上传成功"); ;
|
}
|
|
[HttpPost, HttpGet, Route("GetPDAVersion"), AllowAnonymous]
|
public WebResponseContent GetPDAVersion(string version)
|
{
|
try
|
{
|
string versionPDA = AppSettings.Configuration["PDAVersion"];
|
if (Convert.ToInt32(versionPDA) > Convert.ToInt32(version))
|
return WebResponseContent.Instance.OK(data: true);
|
else return WebResponseContent.Instance.OK(data: false);
|
}
|
catch (Exception ex)
|
{
|
return WebResponseContent.Instance.Error(ex.Message);
|
}
|
|
}
|
[HttpPost, HttpGet, Route("DownLoadApp"), AllowAnonymous]
|
public virtual ActionResult DownLoadApp()
|
{
|
var filename = "WMS-PDA.apk";
|
var filePath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/Upload", filename);
|
|
var memory = new MemoryStream();
|
using (var stream = new FileStream(filePath, FileMode.Open))
|
{
|
stream.CopyTo(memory);
|
}
|
memory.Position = 0;
|
var ext = Path.GetExtension(filePath).ToLowerInvariant();
|
return File(memory, new Dictionary<string, string>{{ ".apk", "application/vnd.android.package-archive" }}[ext], Path.GetFileName(filePath));
|
}
|
}
|
}
|