From 5af11cc200dd5ebe474b9c0475883b0e6d1e3759 Mon Sep 17 00:00:00 2001
From: wanshenmean <cathay_xy@163.com>
Date: 星期三, 11 三月 2026 10:00:49 +0800
Subject: [PATCH] 重构整个项目:改进代码质量和架构
---
Code/WMS/WIDESEA_WMSServer/WIDESEA_WMSServer/Controllers/PDAController.cs | 102 +++++++++++++++++++++++++++++++-------------------
1 files changed, 63 insertions(+), 39 deletions(-)
diff --git a/Code/WMS/WIDESEA_WMSServer/WIDESEA_WMSServer/Controllers/PDAController.cs b/Code/WMS/WIDESEA_WMSServer/WIDESEA_WMSServer/Controllers/PDAController.cs
index 33d6641..59c277f 100644
--- a/Code/WMS/WIDESEA_WMSServer/WIDESEA_WMSServer/Controllers/PDAController.cs
+++ b/Code/WMS/WIDESEA_WMSServer/WIDESEA_WMSServer/Controllers/PDAController.cs
@@ -1,6 +1,7 @@
锘縰sing Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
+using System.IO;
using WIDESEA_Core;
using WIDESEA_Core.BaseController;
using WIDESEA_Core.Helper;
@@ -8,14 +9,12 @@
using WIDESEA_IInboundService;
using WIDESEA_IOutboundService;
using WIDESEA_ITaskInfoService;
-using System.IO;
using WIDESEA_Model.Models;
-using System;
namespace WIDESEA_WMSServer.Controllers
{
/// <summary>
- /// PDA
+ /// PDA 鎺у埗鍣� - 鎻愪緵PDA搴旂敤涓嬭浇銆佷笂浼犲拰鐗堟湰妫�鏌ュ姛鑳�
/// </summary>
[Route("api/PDA")]
[Authorize, ApiController]
@@ -25,6 +24,9 @@
private readonly IOutboundService _outboundService;
private readonly ITaskService _taskService;
+ /// <summary>
+ /// 鏋勯�犲嚱鏁�
+ /// </summary>
public PDAController(ITaskService taskService, IInboundService inboundService, IOutboundService outboundService)
{
_inboundService = inboundService;
@@ -33,37 +35,30 @@
}
/// <summary>
- /// 涓嬭浇PDA
+ /// 涓嬭浇PDA搴旂敤瀹夎鍖�
/// </summary>
- /// <returns></returns>
+ /// <returns>APK鏂囦欢鎴栭敊璇俊鎭�</returns>
[HttpPost, HttpGet, Route("DownLoadApp"), AllowAnonymous]
public virtual ActionResult DownLoadApp()
{
- string path = $"{AppDomain.CurrentDomain.BaseDirectory}Upload/App/";
- if (!Directory.Exists(path)) Directory.CreateDirectory(path);
- path += "WMS-PDA.apk";
+ const string appDirectory = "Upload/App/";
+ const string appFileName = "WMS-PDA.apk";
+ string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, appDirectory, appFileName);
- if (System.IO.File.Exists(path))
+ if (!System.IO.File.Exists(path))
{
- byte[] fileBytes = System.IO.File.ReadAllBytes(path);
- return File(
- fileBytes,
- System.Net.Mime.MediaTypeNames.Application.Octet,
- System.IO.Path.GetFileName(path)
- );
- }
- else
- {
- return Json(WebResponseContent.Instance.Error($"鏈壘鍒板畨瑁呭寘"));
+ return Json(WebResponseContent.Instance.Error("鏈壘鍒板畨瑁呭寘"));
}
+ byte[] fileBytes = System.IO.File.ReadAllBytes(path);
+ return File(fileBytes, System.Net.Mime.MediaTypeNames.Application.Octet, appFileName);
}
/// <summary>
- /// 涓婁紶PDA
+ /// 涓婁紶PDA搴旂敤瀹夎鍖�
/// </summary>
- /// <param name="fileInput"></param>
- /// <returns></returns>
+ /// <param name="fileInput">涓婁紶鐨勬枃浠�</param>
+ /// <returns>涓婁紶缁撴灉</returns>
[HttpPost, HttpGet, Route("UploadApp"), AllowAnonymous]
[Consumes("multipart/form-data")]
public WebResponseContent UploadApp(IEnumerable<IFormFile> fileInput)
@@ -71,43 +66,72 @@
try
{
List<IFormFile> files = fileInput.ToList();
- if (files == null || files.Count() == 0)
- return new WebResponseContent { Status = true, Message = "璇烽�夋嫨涓婁紶鐨勬枃浠�" };
- IFormFile formFile = files[0];
- string dicPath = $"{AppDomain.CurrentDomain.BaseDirectory}Upload/App/";
- if (!Directory.Exists(dicPath)) Directory.CreateDirectory(dicPath);
- string path = $"{dicPath}WMS-PDA{DateTime.Now:yyyyMMddhhmmss}.apk";
- dicPath = $"{dicPath}WMS-PDA.apk";
- if (System.IO.File.Exists(dicPath))
- System.IO.File.Move(dicPath, path);
+ if (files == null || files.Count == 0)
+ {
+ return new WebResponseContent { Status = false, Message = "璇烽�夋嫨涓婁紶鐨勬枃浠�" };
+ }
- using (var stream = new FileStream(dicPath, FileMode.Create))
+ IFormFile formFile = files[0];
+ const string appDirectory = "Upload/App/";
+ const string appFileName = "WMS-PDA.apk";
+ string directoryPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, appDirectory);
+
+ if (!Directory.Exists(directoryPath))
+ {
+ Directory.CreateDirectory(directoryPath);
+ }
+
+ string backupPath = Path.Combine(directoryPath, $"WMS-PDA{DateTime.Now:yyyyMMddhhmmss}.apk");
+ string targetPath = Path.Combine(directoryPath, appFileName);
+
+ // 澶囦唤鐜版湁鏂囦欢
+ if (System.IO.File.Exists(targetPath))
+ {
+ System.IO.File.Move(targetPath, backupPath);
+ }
+
+ // 淇濆瓨鏂版枃浠�
+ using (var stream = new FileStream(targetPath, FileMode.Create))
{
formFile.CopyTo(stream);
}
+
return new WebResponseContent { Status = true, Message = "鏂囦欢涓婁紶鎴愬姛" };
}
catch (Exception ex)
{
- return WebResponseContent.Instance.Error(ex.Message);
+ return WebResponseContent.Instance.Error($"鏂囦欢涓婁紶澶辫触锛歿ex.Message}");
}
}
+ /// <summary>
+ /// 鑾峰彇PDA鐗堟湰鍙峰苟妫�鏌ユ槸鍚﹂渶瑕佹洿鏂�
+ /// </summary>
+ /// <param name="version">褰撳墠PDA鐗堟湰鍙�</param>
+ /// <returns>鏄惁闇�瑕佹洿鏂扮殑鏍囧織</returns>
[HttpPost, HttpGet, Route("GetPDAVersion"), AllowAnonymous]
public WebResponseContent GetPDAVersion(string version)
{
try
{
- string versionP = AppSettings.Get("PDAVersion");
- if (Convert.ToInt32(versionP) > Convert.ToInt32(version))
- return WebResponseContent.Instance.OK(data: true);
- else return WebResponseContent.Instance.OK(data: false);
+ if (string.IsNullOrEmpty(version))
+ {
+ return WebResponseContent.Instance.Error("鐗堟湰鍙蜂笉鑳戒负绌�");
+ }
+
+ string serverVersion = AppSettings.Get("PDAVersion");
+ if (int.TryParse(serverVersion, out int serverVersionNum) && int.TryParse(version, out int clientVersionNum))
+ {
+ bool needUpdate = serverVersionNum > clientVersionNum;
+ return WebResponseContent.Instance.OK(data: needUpdate);
+ }
+
+ return WebResponseContent.Instance.Error("鐗堟湰鍙锋牸寮忛敊璇�");
}
catch (Exception ex)
{
- return WebResponseContent.Instance.Error(ex.Message);
+ return WebResponseContent.Instance.Error($"鐗堟湰妫�鏌ュけ璐ワ細{ex.Message}");
}
-
}
}
}
--
Gitblit v1.9.3