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 | 500 +++++++++++++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 481 insertions(+), 19 deletions(-)
diff --git a/DEmon/WebWIPAPI/Controllers/MesIntegrController.cs b/DEmon/WebWIPAPI/Controllers/MesIntegrController.cs
index 1c2a566..ed7842f 100644
--- a/DEmon/WebWIPAPI/Controllers/MesIntegrController.cs
+++ b/DEmon/WebWIPAPI/Controllers/MesIntegrController.cs
@@ -1,12 +1,21 @@
-锘縰sing iWareDataCore.BASE.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
{
@@ -17,35 +26,488 @@
{
/// <summary>
- /// 鍚屾绔嬪簱鐨勭墿鏂欎俊鎭�
- /// WCS>>WIP:姣忓ぉ瀹氭椂WCS鎺ㄩ�佺珛搴撻噷鐨勭墿鏂欎俊鎭�
+ /// 鎻愪緵搴撳瓨淇℃伅
/// </summary>
- /// <param name="sysCode"></param>
- /// <param name="wareHouseInfo"></param>
- /// <param name="processCardNumber"></param>
- /// <param name="wareHouseId"></param>
- /// <param name="timestamp"></param>
/// <returns></returns>
[HttpPost]
public ActionResult syncMaterialInfo()
{
- var msg = "";
- var datalist = PlaceMaterialViewService.GetInstance().GetPlacePreview(out msg);
-
- var responseMessage = new ApiResponse<List<PlaceMaterialViewEntity>>()
+ var responseMessage = new ApiResponse<List<PlaceMaterialViewEntity>>();
+ try
{
- Code = 200,
- Success = true,
- Message = "鎴愬姛",
- Data = datalist,
- };
-
+ 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 = "寮傚父:" + ex.Message,
+ Data = null,
+ };
+ }
//灏嗗璞¤浆鍖栦负json鏍煎紡
var responseStr = JsonConvert.SerializeObject(responseMessage);
LogTextHelper.WriteLine(Resources.LogDir, "WIPAPI:{0},{1}, {2}", "syncMaterialInfo", "璇锋眰鍙傛暟锛�" + "", "鍝嶅簲淇℃伅;" + responseStr);
return Json(responseMessage, JsonRequestBehavior.DenyGet);
}
+ /// <summary>
+ /// 瀵煎叆鍏ュ簱鍗�
+ /// </summary>
+ /// <param name="inputmaterials"></param>
+ /// <returns></returns>
+ [HttpPost]
+ public ActionResult importInOrder(List<MaterialViewForMesEntity> importMaterials)
+ {
+ var responseMessage = new ApiResponse<string>();
+ var msg = "";
+
+ 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
+
+ #region 涓氬姟澶勭悊
+
+ //绗竴姝ワ細鍏堟柊澧炲埌鐗╂枡鍩虹琛�
+ List<MaterialViewEntity> materials = new List<MaterialViewEntity>();
+
+ materials = ClassHelper.RotationMapping_Json<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);//娉ㄦ剰锛氫紤鐪犳绉掞紝鐢ㄤ簬鏁版嵁搴撲簨鍔℃彁浜�
+
+ 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 = "寮傚父:" + ex.Message,
+ Data = null,
+ };
+ }
+
+ 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>
+ [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", "");
+ }
+ 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
+
+ #region 涓氬姟澶勭悊
+
+ string typeName = "鍑哄簱";
+ handler_OutOrder(inputmaterials, out msg);
+ //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>
+ /// 鍏叡瀵煎叆 鍏ュ簱鍗曟垨鍑哄簱鍗�
+ /// </summary>
+ /// <param name="typeName"></param>
+ /// <param name="inputmaterials"></param>
+ /// <param name="msg"></param>
+ private void handler_importOutOrder(string typeName, List<InputMaterialEntity> inputmaterials, out string msg)
+ {
+ try
+ {
+ #region 涓氬姟澶勭悊
+
+ msg = "";
+ //var inputmaterials = InputMaterialService.GetInstance().QueryByParam(new QueryParam { Filter = new Dictionary<string, object> { { "Status", "鏈敓鎴�" } } }, out msg);
+ if (inputmaterials != null && inputmaterials.Count > 0)
+ {
+ var placeMaterial = PlaceMaterialViewService.GetInstance().QueryByParam(new QueryParam { }, out msg);
+ var inoutdetails = InOutListDetailViewService.GetInstance().QueryByParam(new QueryParam { }, out msg);
+ List<string> codes = new List<string>();
+ inputmaterials.ForEach(x => codes.Add(x.Code));
+ 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 == "鍏ュ簱")
+ {
+
+ if (placeMaterial.Select(x => x.MaterialId).Contains(materials[i].id))
+ {
+ msg = materials[i].code + "宸插瓨鍦ㄧ珛搴撲腑锛屼笉鑳芥坊鍔犲埌鍏ュ簱鍗曟槑缁嗕腑锛�";
+ break;
+ }
+ if (inoutdetails.Select(x => x.MaterialId).Contains(materials[i].id))
+ {
+ msg = materials[i].code + "宸插瓨鍦ㄤ箣鍓嶇殑鍏ュ簱鍗曟槑缁嗕腑锛屼笉鑳芥坊鍔犲埌褰撳墠鍏ュ簱鍗曟槑缁嗕腑锛�";
+ break;
+ }
+
+ }
+ else
+ {
+ if (!placeMaterial.Select(x => x.MaterialId).Contains(materials[i].id))
+ {
+ msg = materials[i].code + "涓嶅湪绔嬪簱涓紝涓嶈兘娣诲姞鍒板嚭搴撳崟鏄庣粏涓紒";
+ break;
+ }
+ if (inoutdetails.Select(x => x.MaterialId).Contains(materials[i].id))
+ {
+ var inoutdeta = inoutdetails.FirstOrDefault(x => x.MaterialId == materials[i].id);
+ if (inoutdeta.TypeName == "鍑哄簱")
+ {
+ msg = materials[i].name + "宸插瓨鍦ㄤ箣鍓嶇殑鍑哄簱鍗曟槑缁嗕腑锛屼笉鑳芥坊鍔犲埌褰撳墠鍑哄簱鍗曟槑缁嗕腑锛�";
+ break;
+ }
+ }
+ }
+ InOutListDetailEntity inoutdetail = new InOutListDetailEntity()
+ {
+ MaterialId = materials[i].id,
+ IsFinish = 0
+ };
+ detail.Add(inoutdetail);
+ }
+ if (!string.IsNullOrEmpty(msg))
+ {
+ return;
+ }
+ InOutListService.GetInstance().CreateListAndDetial(
+ new InOutListEntity
+ {
+ ListNo = inputmaterials.First().ListNo,
+ CreateTime = DateTime.Now,
+ TypeName = typeName,
+ Status = 0,
+ Remark = "",
+ InOutListDetail = detail
+ }, out msg);
+ }
+ else
+ {
+ msg = ("璇峰厛纭繚鍑哄叆搴撳崟鐗╂枡鏄庣粏涓嶄负绌猴紒");
+ }
+
+
+ #endregion
+ }
+ catch (Exception)
+ {
+ throw;
+ }
+ }
+
+
+ /// <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