From a754e362987bd0e0de55a23b22824ad4a3a166bb Mon Sep 17 00:00:00 2001
From: yanjinhui <3306209981@qq.com>
Date: 星期四, 16 十月 2025 16:44:24 +0800
Subject: [PATCH] 后端
---
新建文件夹/WIDESEA_WMSServer/ClassLibrary2/InventoryInfoService.cs | 157 ++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 156 insertions(+), 1 deletions(-)
diff --git "a/\346\226\260\345\273\272\346\226\207\344\273\266\345\244\271/WIDESEA_WMSServer/ClassLibrary2/InventoryInfoService.cs" "b/\346\226\260\345\273\272\346\226\207\344\273\266\345\244\271/WIDESEA_WMSServer/ClassLibrary2/InventoryInfoService.cs"
index e94edd1..baf64b9 100644
--- "a/\346\226\260\345\273\272\346\226\207\344\273\266\345\244\271/WIDESEA_WMSServer/ClassLibrary2/InventoryInfoService.cs"
+++ "b/\346\226\260\345\273\272\346\226\207\344\273\266\345\244\271/WIDESEA_WMSServer/ClassLibrary2/InventoryInfoService.cs"
@@ -1,12 +1,18 @@
-锘縰sing System;
+锘縰sing HslCommunication;
+using SqlSugar;
+using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
+using WIDESEA_Core;
using WIDESEA_Core.BaseRepository;
using WIDESEA_Core.BaseServices;
+using WIDESEA_Core.Helper;
+using WIDESEA_DTO.SquareCabin;
using WIDESEA_IWMsInfoServices;
using WIDESEA_Model.Models;
+using static WIDESEA_DTO.SquareCabin.TowcsDto;
namespace WIDESEA_WMsInfoServices
{
@@ -15,5 +21,154 @@
public InventoryInfoService(IRepository<Dt_InventoryInfo> BaseDal) : base(BaseDal)
{
}
+
+ /// <summary>
+ /// wcs鍥炰紶缁欐垜璋冪敤鎴戠殑鏂规硶
+ /// </summary>
+ /// <param name="request"></param>
+ /// <returns></returns>
+ public ApiResponse<Dt_InventoryInfo> OrderFeedback(EdiOrderCallbackRequest request)
+ {
+ try
+ {
+ if (request == null || request.details == null || !request.details.Any())
+ {
+ return new ApiResponse<Dt_InventoryInfo> { code = "500", msg = "璇锋眰鍙傛暟鏃犳晥" };
+ }
+
+ BaseDal.Db.Ado.BeginTran(); // 寮�鍚簨鍔�
+
+ foreach (var detail in request.details)
+ {
+ // 鑾峰彇鏄庣粏涓殑鎬诲叆搴撴暟閲忥紙鑷姩杞负姝f暟锛�
+ decimal orderQty = detail.orderDetails?
+ .Sum(x => decimal.TryParse(x.quantity, out var q) ? Math.Abs(q) : 0)
+ ?? 0;
+
+ //鐩樼偣
+ decimal diffQty = detail.stocktakingDetails?
+ .Sum(x => Convert.ToDecimal(x.differenceQuantity))
+ ?? 0;
+
+ // 鏍规嵁鐗╂枡缂栧彿 + 鎵规鍙� 鏌ユ壘鏄惁宸叉湁搴撳瓨
+ var entity = BaseDal.Db.Queryable<Dt_InventoryInfo>()
+ .First(x => x.MaterielCode == detail.productCode && x.BatchNo == detail.batchNo);
+
+ if (entity == null)
+ {
+ // 馃啎 涓嶅瓨鍦ㄥ垯鏂板缓搴撳瓨璁板綍
+ entity = new Dt_InventoryInfo
+ {
+ PalletCode = detail.orderDetails?.FirstOrDefault()?.palletCode ?? "",
+ WarehouseId = 001, // 榛樿搴撴埧缂栧彿锛屽彲鏍规嵁涓氬姟鏀�
+ LocationCode = "", // 鏆傛棤鍙┖
+ StockStatus = 1, // 绔嬪簱鍥哄畾涓� 1
+ MaterielCode = detail.productCode ?? detail.productName,
+ MaterielName = detail.productName ?? "",
+ MaterielSpec = detail.productSpecifications ?? "",
+ BatchNo = detail.batchNo,
+ // 鍒濇鍏ュ簱鏁伴噺 = 瀹為檯鍏ュ簱鏁伴噺
+ StockQuantity = 0,
+ OutboundQuantity = 0,
+ SupplyQuantity = 0,
+ InDate = DateTime.Now,
+ ProductionDate = detail.finishDate.ToString("yyyy-MM-dd"),
+ ShelfLife = 0,
+ ValidityPeriod = "",
+ Remark = "WCS鍥炰紶鍒涘缓"
+ };
+ }
+
+ switch (request.orderType)
+ {
+ case "1": // 鍏ュ簱
+ entity.StockQuantity += (float)orderQty;
+ entity.InDate = DateTime.Now;
+ entity.Remark = "鍏ュ簱鍗曞洖浼�";
+ break;
+
+ case "2": // 鍑哄簱
+ entity.OutboundQuantity += (float)orderQty;
+ entity.StockQuantity -= (float)orderQty;
+ if (entity.StockQuantity < 0) entity.StockQuantity = 0;
+ entity.Remark = "鍑哄簱鍗曞洖浼�";
+ break;
+
+ case "3": // 鐩樼偣
+ if (detail.stocktakingDetails != null && detail.stocktakingDetails.Any())
+ {
+ foreach (var stock in detail.stocktakingDetails)
+ {
+ decimal diff = Convert.ToDecimal(stock.differenceQuantity);
+ if (stock.IsProfit == "1") // 鐩樼泩
+ {
+ entity.SupplyQuantity += (float)Math.Abs(diff);
+ }
+ else // 鐩樹簭
+ {
+ entity.SupplyQuantity -= (float)Math.Abs(diff);
+ if (entity.SupplyQuantity < 0) entity.SupplyQuantity = 0;
+ }
+ entity.PalletCode = stock.palletCode;
+ entity.Remark = "鐩樼偣鍗曞洖浼�";
+ }
+ }
+ break;
+ }
+
+ // 鎻掑叆鎴栨洿鏂版暟鎹簱
+ if (entity.Id == 0)
+ {
+ BaseDal.Db.Insertable(entity).ExecuteCommand();
+ }
+ else
+ {
+ BaseDal.Db.Updateable(entity).ExecuteCommand();
+ }
+ }
+
+ BaseDal.Db.Ado.CommitTran();
+ return new ApiResponse<Dt_InventoryInfo> { code = "0", msg = "鎴愬姛" };
+ }
+ catch (Exception ex)
+ {
+ BaseDal.Db.Ado.RollbackTran();
+ return new ApiResponse<Dt_InventoryInfo> { code = "500", msg = ex.Message };
+ }
+ }
+
+
+
+
+
+
+
+
+ /// <summary>
+ /// 鎺ㄩ�佸紓甯镐俊鎭粰涓婃父绯荤粺1.鍏ュ簱鍗曟帴鍙o紱2.鍏ュ簱鍗曟姤瀹屾垚鎺ュ彛锛�3.鍑哄簱鍗曟帴鍙o紱4.鍑哄簱鎶ュ畬鎴愭帴鍙o紱5.鑽搧鍩虹淇℃伅鍚屾鎺ュ彛锛�6.渚涘簲鍟嗕俊鎭帴鍙o紱7.瀹㈡埛淇℃伅鎺ュ彛锛�8.搴撳瓨
+ /// </summary>
+ public void SendErrorToUpstream(int type, string code, string message, string remark)
+ {
+ try
+ {
+ var url = "http://121.37.118.63:80/GYZ2/95fck/exceptionLog";
+
+ var requestData = new
+ {
+ type = type.ToString(),
+ code = code,
+ message = message,
+ remark = remark
+ };
+
+ var result = HttpHelper.Post(url, requestData.ToJsonString());
+ // 鍙互鍙嶅簭鍒楀寲妫�鏌� resultCode 鏄惁涓�0
+ }
+ catch (Exception e)
+ {
+ // 杩欓噷涓嶈鍐嶆姏寮傚父浜嗭紝閬垮厤姝诲惊鐜�
+ Console.WriteLine("寮傚父鎺ュ彛鎺ㄩ�佸け璐ワ細" + e.Message);
+ }
+ }
}
}
--
Gitblit v1.9.3