huangxiaoqiang
2025-06-03 73a077d76b715aee6b9f384b087a6792a84989d8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
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));
        }
    }
}