From 068a221025ffe209b25f00642f9bcd1e28861fe0 Mon Sep 17 00:00:00 2001
From: schangxiang@126.com <schangxiang@126.com>
Date: 周四, 16 10月 2025 15:58:42 +0800
Subject: [PATCH] 本次请求中物料号不能重复修复
---
DEmon/WebWIPAPI/Controllers/MesIntegrController.cs | 390 ++++++++++++++++++++++++++++++++++++++++++++++---------
1 files changed, 324 insertions(+), 66 deletions(-)
diff --git a/DEmon/WebWIPAPI/Controllers/MesIntegrController.cs b/DEmon/WebWIPAPI/Controllers/MesIntegrController.cs
index 9cd7465..ed7842f 100644
--- a/DEmon/WebWIPAPI/Controllers/MesIntegrController.cs
+++ b/DEmon/WebWIPAPI/Controllers/MesIntegrController.cs
@@ -1,15 +1,20 @@
-锘縰sing iWareCommon.Common.Entity;
+锘縰sing AutoMapper;
+using iWareCommon.Common.Entity;
using iWareCommon.Utils;
using iWareDataCore.BASE.Entity;
using iWareDataCore.BASE.Service;
+using iWareDataCore.TASK.Service;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
+using System.Web.Hosting;
using System.Web.Mvc;
using WebWIPAPI.Models;
using WebWIPAPI.Properties;
+using WebWIPAPI.Utils;
+using static System.Runtime.CompilerServices.RuntimeHelpers;
using LogTextHelper = WebWIPAPI.Utils.LogTextHelper;
namespace WebWIPAPI.Controllers
@@ -28,29 +33,42 @@
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);
+ datalist = datalist.Where(x => !string.IsNullOrEmpty(x.MaterialCode)).ToList();
+ 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,52 +86,196 @@
var responseMessage = new ApiResponse<string>();
var msg = "";
- #region 涓氬姟澶勭悊
+ try
+ {
+ #region 楠岃瘉
+ if (importMaterials?.Count() == 0)
+ {
+ responseMessage = new ApiResponse<string>()
+ {
+ Code = 500,
+ Success = false,
+ Message = "鏁版嵁鏉℃暟涓�0",
+ Data = null,
+ };
+ return ApiResponseHelper.ReturnApiResponse(responseMessage, "importInOrder", "");
+ }
+ if (importMaterials.Select(x => x.ListNo).Distinct().Count() != 1)
+ {
+ responseMessage = new ApiResponse<string>()
+ {
+ Code = 500,
+ Success = false,
+ Message = "鏈璇锋眰鍗曞彿蹇呴』涓哄悓涓�鍊�",
+ Data = null,
+ };
+ return ApiResponseHelper.ReturnApiResponse(responseMessage, "importInOrder", "");
+ }
+ if (importMaterials.GroupBy(x => x.Code).Any(g => g.Count() > 1))
+ {
+ responseMessage = new ApiResponse<string>()
+ {
+ Code = 500,
+ Success = false,
+ Message = "鏈璇锋眰涓墿鏂欏彿涓嶈兘閲嶅",
+ Data = null,
+ };
+ return ApiResponseHelper.ReturnApiResponse(responseMessage, "importOutOrder", "");
+ }
+ #endregion
- //绗竴姝ワ細鍏堟柊澧炲埌鐗╂枡鍩虹琛�
- List<MaterialViewEntity> materials = new List<MaterialViewEntity>();
- materials = ClassHelper.RotationMapping<List<MaterialViewEntity>, List<MaterialViewForMesEntity>>(importMaterials);
- MaterialViewService.GetInstance().ImportExcelFromMes(materials, out msg);
+ #region 涓氬姟澶勭悊
- Thread.Sleep(400);//娉ㄦ剰锛氫紤鐪犳绉掞紝鐢ㄤ簬鏁版嵁搴撲簨鍔℃彁浜�
+ //绗竴姝ワ細鍏堟柊澧炲埌鐗╂枡鍩虹琛�
+ List<MaterialViewEntity> materials = new List<MaterialViewEntity>();
- string typeName = "鍏ュ簱";
- List<InputMaterialEntity> inputmaterials = new List<InputMaterialEntity>();
- inputmaterials = ClassHelper.RotationMapping<List<InputMaterialEntity>, List<MaterialViewForMesEntity>>(importMaterials);
- handler_importOutOrder(typeName, inputmaterials, out msg);
+ materials = ClassHelper.RotationMapping_Json<List<MaterialViewEntity>, List<MaterialViewForMesEntity>>(importMaterials);
- #endregion
- if (!string.IsNullOrEmpty(msg))
+ 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);//娉ㄦ剰锛氫紤鐪犳绉掞紝鐢ㄤ簬鏁版嵁搴撲簨鍔℃彁浜�
+
+ string typeName = "鍏ュ簱";
+ List<InputMaterialEntity> inputmaterials = new List<InputMaterialEntity>();
+ inputmaterials = ClassHelper.RotationMapping_Json<List<InputMaterialEntity>, List<MaterialViewForMesEntity>>(importMaterials);
+ handler_importOutOrder(typeName, inputmaterials, out msg);
+
+ #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,
+ };
+ }
+ }
+
+ }
+ 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,
};
}
- //灏嗗璞¤浆鍖栦负json鏍煎紡
- var responseStr = JsonConvert.SerializeObject(responseMessage);
- LogTextHelper.WriteLine(Resources.LogDir, "WIPAPI:{0},{1}, {2}", "importInOrder", "璇锋眰鍙傛暟锛�" + "", "鍝嶅簲淇℃伅;" + responseStr);
- return Json(responseMessage, JsonRequestBehavior.DenyGet);
+ return ApiResponseHelper.ReturnApiResponse(responseMessage, "importInOrder", "");
}
+ ///// <summary>
+ ///// 瀵煎叆鍑哄簱鍗�-鐗堟湰1锛堜娇鐢ㄥ嚭搴撳崟鎹殑鐗堟湰锛�
+ ///// </summary>
+ ///// <param name="inputmaterials"></param>
+ ///// <returns></returns>
+ //[HttpPost]
+ //public ActionResult importOutOrder(List<InputMaterialEntity> inputmaterials)
+ //{
+ // var responseMessage = new ApiResponse<string>();
+ // try
+ // {
+ // var msg = "";
+
+ // #region 楠岃瘉
+ // if (inputmaterials?.Count() == 0)
+ // {
+ // responseMessage = new ApiResponse<string>()
+ // {
+ // Code = 500,
+ // Success = false,
+ // Message = "鏁版嵁鏉℃暟涓�0",
+ // Data = null,
+ // };
+ // return ApiResponseHelper.ReturnApiResponse(responseMessage, "importOutOrder", "");
+ // }
+ // if (inputmaterials.Select(x => x.ListNo).Distinct().Count() != 1)
+ // {
+ // responseMessage = new ApiResponse<string>()
+ // {
+ // Code = 500,
+ // Success = false,
+ // Message = "鏈璇锋眰鍗曞彿蹇呴』涓哄悓涓�鍊�",
+ // Data = null,
+ // };
+ // return ApiResponseHelper.ReturnApiResponse(responseMessage, "importOutOrder", "");
+ // }
+ // #endregion
+
+ // #region 涓氬姟澶勭悊
+
+ // string typeName = "鍑哄簱";
+ // handler_importOutOrder(typeName, inputmaterials, out msg);
+
+ // #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,
+ // };
+ // }
+
+ // }
+ // catch (Exception ex)
+ // {
+ // responseMessage = new ApiResponse<string>()
+ // {
+ // Code = 500,
+ // Success = false,
+ // Message = "寮傚父:" + ex.Message,
+ // Data = null,
+ // };
+ // }
+
+ // return ApiResponseHelper.ReturnApiResponse(responseMessage, "importOutOrder", "");
+ //}
+
+
/// <summary>
- /// 瀵煎叆鍑哄簱鍗�
+ /// 瀵煎叆鍑哄簱鍗�-鐗堟湰2锛堥�夋嫨搴撳瓨鍑哄簱鐨勭増鏈級
/// </summary>
/// <param name="inputmaterials"></param>
/// <returns></returns>
@@ -121,42 +283,89 @@
public ActionResult importOutOrder(List<InputMaterialEntity> inputmaterials)
{
var responseMessage = new ApiResponse<string>();
- var msg = "";
+ try
+ {
+ var msg = "";
- #region 涓氬姟澶勭悊
+ #region 楠岃瘉
+ if (inputmaterials?.Count() == 0)
+ {
+ responseMessage = new ApiResponse<string>()
+ {
+ Code = 500,
+ Success = false,
+ Message = "鏁版嵁鏉℃暟涓�0",
+ Data = null,
+ };
+ return ApiResponseHelper.ReturnApiResponse(responseMessage, "importOutOrder", "");
+ }
+ if (inputmaterials.Select(x => x.ListNo).Distinct().Count() != 1)
+ {
+ responseMessage = new ApiResponse<string>()
+ {
+ Code = 500,
+ Success = false,
+ Message = "鏈璇锋眰鍗曞彿蹇呴』涓哄悓涓�鍊�",
+ Data = null,
+ };
+ return ApiResponseHelper.ReturnApiResponse(responseMessage, "importOutOrder", "");
+ }
+ if (inputmaterials.GroupBy(x => x.Code).Any(g => g.Count() > 1))
+ {
+ responseMessage = new ApiResponse<string>()
+ {
+ Code = 500,
+ Success = false,
+ Message = "鏈璇锋眰涓墿鏂欏彿涓嶈兘閲嶅",
+ Data = null,
+ };
+ return ApiResponseHelper.ReturnApiResponse(responseMessage, "importOutOrder", "");
+ }
+ #endregion
- string typeName = "鍑哄簱";
- handler_importOutOrder(typeName, inputmaterials, out msg);
+ #region 涓氬姟澶勭悊
- #endregion
+ string typeName = "鍑哄簱";
+ handler_OutOrder(inputmaterials, out msg);
+ //handler_importOutOrder(typeName, inputmaterials, out msg);
- if (!string.IsNullOrEmpty(msg))
+ #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,
+ };
+ }
+
+ }
+ 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,
};
}
- //灏嗗璞¤浆鍖栦负json鏍煎紡
- var responseStr = JsonConvert.SerializeObject(responseMessage);
- LogTextHelper.WriteLine(Resources.LogDir, "WIPAPI:{0},{1}, {2}", "importOutOrder", "璇锋眰鍙傛暟锛�" + "", "鍝嶅簲淇℃伅;" + responseStr);
- return Json(responseMessage, JsonRequestBehavior.DenyGet);
+ return ApiResponseHelper.ReturnApiResponse(responseMessage, "importOutOrder", "");
}
-
/// <summary>
/// 鍏叡瀵煎叆 鍏ュ簱鍗曟垨鍑哄簱鍗�
@@ -181,6 +390,11 @@
List<int> ids = new List<int>();
var materials = InputMaterialService.GetInstance().GetIds(codes);
List<InOutListDetailEntity> detail = new List<InOutListDetailEntity>();
+ if (materials?.Count == 0)
+ {
+ msg = ("鐗╂枡鏄庣粏鏌ヨ涓虹┖锛�");
+ return;
+ }
for (int i = 0; i < materials.Count; i++)
{
if (typeName == "鍏ュ簱")
@@ -251,5 +465,49 @@
}
}
+
+ /// <summary>
+ /// 閫夋嫨搴撳瓨鍑哄簱鐨勭増鏈�
+ /// </summary>
+ /// <param name="inputmaterials"></param>
+ /// <param name="msg"></param>
+ private void handler_OutOrder(List<InputMaterialEntity> inputmaterials, out string msg)
+ {
+ msg = "";
+ //鏌ユ壘搴撳瓨琛ㄤ腑鐨刬d
+ var qList = inputmaterials.Select(x => x.Code).ToList();
+ List<int> ids = PlaceMaterialViewService.GetInstance().GetPlaceMaterialViewsByCodeList(qList, out msg);
+ if (!string.IsNullOrEmpty(msg))
+ {
+ return;
+ }
+ // List<int> ids = GetSelectedDataKeyIDs(PlaceGrid);
+ if (ids.Count > 0)
+ {
+ int count = MainTaskService.GetInstance().SaveOutMainTask(ids, out msg);
+ var retMsg = msg;
+ if (count > 0)
+ {
+ //鎴愬姛涓嶉渶瑕佸啓鏂囧瓧
+ //msg = "鍑哄簱浠诲姟鐢熸垚鎴愬姛:" + retMsg;
+ }
+ else if (count == 0)
+ {
+ msg = "鍑哄簱浠诲姟宸插湪浠诲姟闃熷垪涓�:" + retMsg;
+ }
+ else
+ {
+ msg = "鍑哄簱浠诲姟鐢熸垚澶辫触锛�:" + retMsg;
+ }
+
+ }
+ else
+ {
+ msg = "瑕佸嚭搴撶殑鐗╂枡娌℃湁鍙敤搴撳瓨";
+ }
+ //Alert.Show(msg);
+ //WriteLog("搴撲綅鐗╂枡鍑哄簱" + msg, "搴撳瓨绠$悊");
+ }
+
}
}
--
Gitblit v1.9.3