From a32e5a5b296cab5ccc20953ca4e801ca4f27bd85 Mon Sep 17 00:00:00 2001
From: schangxiang@126.com <schangxiang@126.com>
Date: 周三, 17 9月 2025 11:13:15 +0800
Subject: [PATCH] 优化方法
---
DEmon/WebWIPAPI/Controllers/MesIntegrController.cs | 163 ++++++++++++++++++++++++++++++++++++------------------
1 files changed, 108 insertions(+), 55 deletions(-)
diff --git a/DEmon/WebWIPAPI/Controllers/MesIntegrController.cs b/DEmon/WebWIPAPI/Controllers/MesIntegrController.cs
index 9cd7465..7a70f5b 100644
--- a/DEmon/WebWIPAPI/Controllers/MesIntegrController.cs
+++ b/DEmon/WebWIPAPI/Controllers/MesIntegrController.cs
@@ -28,29 +28,41 @@
public ActionResult syncMaterialInfo()
{
var responseMessage = new ApiResponse<List<PlaceMaterialViewEntity>>();
- var msg = "";
- var datalist = PlaceMaterialViewService.GetInstance().GetPlacePreview(out msg);
- if (!string.IsNullOrEmpty(msg))
+ try
+ {
+ var msg = "";
+ var datalist = PlaceMaterialViewService.GetInstance().GetPlacePreview(out msg);
+ if (!string.IsNullOrEmpty(msg))
+ {
+ responseMessage = new ApiResponse<List<PlaceMaterialViewEntity>>()
+ {
+ Code = 500,
+ Success = false,
+ Message = "鑾峰彇寮傚父:" + msg,
+ Data = null,
+ };
+ }
+ else
+ {
+ responseMessage = new ApiResponse<List<PlaceMaterialViewEntity>>()
+ {
+ Code = 200,
+ Success = true,
+ Message = "鎴愬姛",
+ Data = datalist,
+ };
+ }
+ }
+ catch (Exception ex)
{
responseMessage = new ApiResponse<List<PlaceMaterialViewEntity>>()
{
Code = 500,
Success = false,
- Message = "寮傚父:" + msg,
+ Message = "寮傚父:" + ex.Message,
Data = null,
};
}
- else
- {
- responseMessage = new ApiResponse<List<PlaceMaterialViewEntity>>()
- {
- Code = 200,
- Success = true,
- Message = "鎴愬姛",
- Data = datalist,
- };
- }
-
//灏嗗璞¤浆鍖栦负json鏍煎紡
var responseStr = JsonConvert.SerializeObject(responseMessage);
LogTextHelper.WriteLine(Resources.LogDir, "WIPAPI:{0},{1}, {2}", "syncMaterialInfo", "璇锋眰鍙傛暟锛�" + "", "鍝嶅簲淇℃伅;" + responseStr);
@@ -68,42 +80,69 @@
var responseMessage = new ApiResponse<string>();
var msg = "";
- #region 涓氬姟澶勭悊
+ try
+ {
+ #region 涓氬姟澶勭悊
- //绗竴姝ワ細鍏堟柊澧炲埌鐗╂枡鍩虹琛�
- List<MaterialViewEntity> materials = new List<MaterialViewEntity>();
- materials = ClassHelper.RotationMapping<List<MaterialViewEntity>, List<MaterialViewForMesEntity>>(importMaterials);
- MaterialViewService.GetInstance().ImportExcelFromMes(materials, out msg);
+ //绗竴姝ワ細鍏堟柊澧炲埌鐗╂枡鍩虹琛�
+ List<MaterialViewEntity> materials = new List<MaterialViewEntity>();
+ materials = ClassHelper.RotationMapping<List<MaterialViewEntity>, List<MaterialViewForMesEntity>>(importMaterials);
+ MaterialViewService.GetInstance().ImportExcelFromMes(materials, out msg);
+ if (!string.IsNullOrEmpty(msg))
+ {
+ responseMessage = new ApiResponse<string>()
+ {
+ Code = 500,
+ Success = false,
+ Message = "鏂板鍒扮墿鏂欏熀纭�琛ㄥ紓甯�:" + msg,
+ Data = null,
+ };
+ }
+ else
+ {
+ Thread.Sleep(400);//娉ㄦ剰锛氫紤鐪犳绉掞紝鐢ㄤ簬鏁版嵁搴撲簨鍔℃彁浜�
- Thread.Sleep(400);//娉ㄦ剰锛氫紤鐪犳绉掞紝鐢ㄤ簬鏁版嵁搴撲簨鍔℃彁浜�
+ string typeName = "鍏ュ簱";
+ List<InputMaterialEntity> inputmaterials = new List<InputMaterialEntity>();
+ inputmaterials = ClassHelper.RotationMapping<List<InputMaterialEntity>, List<MaterialViewForMesEntity>>(importMaterials);
+ handler_importOutOrder(typeName, inputmaterials, out msg);
- string typeName = "鍏ュ簱";
- List<InputMaterialEntity> inputmaterials = new List<InputMaterialEntity>();
- inputmaterials = ClassHelper.RotationMapping<List<InputMaterialEntity>, List<MaterialViewForMesEntity>>(importMaterials);
- handler_importOutOrder(typeName, inputmaterials, out msg);
+ #endregion
- #endregion
+ if (!string.IsNullOrEmpty(msg))
+ {
+ responseMessage = new ApiResponse<string>()
+ {
+ Code = 500,
+ Success = false,
+ Message = "鐢熸垚鍏ュ簱浠诲姟寮傚父:" + msg,
+ Data = null,
+ };
+ }
+ else
+ {
+ responseMessage = new ApiResponse<string>()
+ {
+ Code = 200,
+ Success = true,
+ Message = "鎴愬姛",
+ Data = null,
+ };
+ }
+ }
- if (!string.IsNullOrEmpty(msg))
+ }
+ catch (Exception ex)
{
responseMessage = new ApiResponse<string>()
{
Code = 500,
Success = false,
- Message = "寮傚父:" + msg,
+ Message = "寮傚父:" + ex.Message,
Data = null,
};
}
- else
- {
- responseMessage = new ApiResponse<string>()
- {
- Code = 200,
- Success = true,
- Message = "鎴愬姛",
- Data = null,
- };
- }
+
//灏嗗璞¤浆鍖栦负json鏍煎紡
var responseStr = JsonConvert.SerializeObject(responseMessage);
@@ -121,32 +160,46 @@
public ActionResult importOutOrder(List<InputMaterialEntity> inputmaterials)
{
var responseMessage = new ApiResponse<string>();
- var msg = "";
+ try
+ {
+ var msg = "";
- #region 涓氬姟澶勭悊
+ #region 涓氬姟澶勭悊
- string typeName = "鍑哄簱";
- handler_importOutOrder(typeName, inputmaterials, out msg);
+ string typeName = "鍑哄簱";
+ handler_importOutOrder(typeName, inputmaterials, out msg);
- #endregion
+ #endregion
- if (!string.IsNullOrEmpty(msg))
+ if (!string.IsNullOrEmpty(msg))
+ {
+ responseMessage = new ApiResponse<string>()
+ {
+ Code = 500,
+ Success = false,
+ Message = "鐢熸垚鍑哄簱浠诲姟寮傚父:" + msg,
+ Data = null,
+ };
+ }
+ else
+ {
+ responseMessage = new ApiResponse<string>()
+ {
+ Code = 200,
+ Success = true,
+ Message = "鎴愬姛",
+ Data = null,
+ };
+ }
+
+ }
+ catch (Exception ex)
{
responseMessage = new ApiResponse<string>()
{
Code = 500,
Success = false,
- Message = "寮傚父:" + msg,
- Data = null,
- };
- }
- else
- {
- responseMessage = new ApiResponse<string>()
- {
- Code = 200,
- Success = true,
- Message = "鎴愬姛",
+ Message = "寮傚父:" + ex.Message,
Data = null,
};
}
--
Gitblit v1.9.3