From ab4498f9390202dc4a9dd602d55bf1eb9385d9ab Mon Sep 17 00:00:00 2001
From: wankeda <Administrator@DESKTOP-HAU3ST3>
Date: 星期二, 28 四月 2026 16:25:31 +0800
Subject: [PATCH] 出入库流程
---
WMS/WIDESEA_WMSServer/WIDESEA_InboundService/Base/InboundOrderService.cs | 301 +++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 296 insertions(+), 5 deletions(-)
diff --git a/WMS/WIDESEA_WMSServer/WIDESEA_InboundService/Base/InboundOrderService.cs b/WMS/WIDESEA_WMSServer/WIDESEA_InboundService/Base/InboundOrderService.cs
index 7d9f3e5..3e0832a 100644
--- a/WMS/WIDESEA_WMSServer/WIDESEA_InboundService/Base/InboundOrderService.cs
+++ b/WMS/WIDESEA_WMSServer/WIDESEA_InboundService/Base/InboundOrderService.cs
@@ -4,19 +4,23 @@
using System;
using System.Collections.Generic;
using System.Data;
+using System.Globalization;
using System.Linq;
using System.Reflection.Metadata;
using System.Text;
using System.Threading.Tasks;
using WIDESEA_BasicRepository;
using WIDESEA_Common;
+using WIDESEA_Common.OrderEnum;
using WIDESEA_Core;
using WIDESEA_Core.BaseRepository;
using WIDESEA_Core.BaseServices;
+using WIDESEA_Core.CodeConfigEnum;
using WIDESEA_Core.Enums;
using WIDESEA_Core.Helper;
using WIDESEA_Core.Utilities;
using WIDESEA_DTO;
+using WIDESEA_DTO.Basic;
using WIDESEA_DTO.Inbound;
using WIDESEA_DTO.Outbound;
using WIDESEA_IBasicRepository;
@@ -24,6 +28,7 @@
using WIDESEA_IInboundRepository;
using WIDESEA_IInboundService;
using WIDESEA_InboundRepository;
+using WIDESEA_IStockRepository;
using WIDESEA_IStockService;
using WIDESEA_ITaskInfoRepository;
using WIDESEA_Model.Models;
@@ -43,10 +48,13 @@
private IInboundOrderDetailService _inboundOrderDetailService;
private IInboundOrder_HtyService _inboundOrderHtyService;
private IInboundOrderDetail_HtyService _inboundOrderDetail_HtyService;
+ private IWarehouseService _warehouseService;
+ private readonly IStockRepository _stockRepository;
+ private IPalletTypeInfoRepository _palletTypeInfoRepository;
public IInboundOrderRepository Repository => BaseDal;
- public InboundOrderService(IInboundOrderRepository BaseDal, IMapper mapper, IBasicService basicService, IBasicRepository basicRepository, IInboundRepository inboundRepository, IUnitOfWorkManage unitOfWorkManage, ITaskRepository taskRepository, IStockService stockService, IInboundOrderDetailService inboundOrderDetailService, IInboundOrder_HtyService inboundOrderHtyService, IInboundOrderDetail_HtyService inboundOrderDetail_HtyService) : base(BaseDal)
+ public InboundOrderService(IInboundOrderRepository BaseDal, IMapper mapper, IBasicService basicService, IBasicRepository basicRepository, IInboundRepository inboundRepository, IUnitOfWorkManage unitOfWorkManage, ITaskRepository taskRepository, IStockService stockService, IInboundOrderDetailService inboundOrderDetailService, IInboundOrder_HtyService inboundOrderHtyService, IInboundOrderDetail_HtyService inboundOrderDetail_HtyService, IWarehouseService warehouseService, IStockRepository stockRepository, IPalletTypeInfoRepository palletTypeInfoRepository) : base(BaseDal)
{
_mapper = mapper;
_unitOfWorkManage = unitOfWorkManage;
@@ -58,6 +66,288 @@
_inboundOrderHtyService = inboundOrderHtyService;
_inboundOrderDetail_HtyService = inboundOrderDetail_HtyService;
_basicService = basicService;
+ _warehouseService = warehouseService;
+ _stockRepository = stockRepository;
+ _palletTypeInfoRepository = palletTypeInfoRepository;
+ }
+
+ /// <summary>
+ /// 缁勭洏
+ /// </summary>
+ /// <param name="materielGroupDTO"></param>
+ /// <returns></returns>
+ public WebResponseContent MaterielGroup(SaveModel saveModel)
+ {
+ WebResponseContent content = new WebResponseContent();
+ try
+ {
+
+ var orderNo = saveModel.MainData["orderNo"].ToString();
+ var palletCode = saveModel.MainData["palletCode"].ToString();
+ var warehouseId = saveModel.MainData["warehouseId"].ObjToInt();
+ var Initiallife = saveModel.MainData["initiallife"].ObjToInt();
+ var serNums = saveModel.DelKeys.Select(x => x.ToString()).ToList();
+ Dt_Warehouse warehouse = _warehouseService.Repository.QueryFirst(x => x.WarehouseId == warehouseId);
+ if (warehouse == null)
+ {
+ return WebResponseContent.Instance.Error($"鏈壘鍒拌浠撳簱淇℃伅");
+ }
+
+ Dt_InboundOrder inboundOrder = BaseDal.Db.Queryable<Dt_InboundOrder>().Where(x => x.OrderNo == orderNo && x.WarehouseId == warehouse.WarehouseId).Includes(x => x.Details).First();
+ if (inboundOrder == null)
+ {
+ return WebResponseContent.Instance.Error($"鏈壘鍒板叆搴撳崟淇℃伅");
+ }
+ if (inboundOrder.Details == null || inboundOrder.Details.Count <= 0)
+ {
+ return WebResponseContent.Instance.Error($"鏈壘鍒板叆搴撳崟鏄庣粏淇℃伅");
+ }
+ List<MatSerNumAnalysisModel> models = CodeAnalysisHelper.CodeAnalysis<MatSerNumAnalysisModel>(AnalysisCodeEnum.MatSerNumAnalysis, serNums);
+ //楠岃瘉鍒ゆ柇鏃堕棿鏍煎紡
+ WebResponseContent IsValidContent = IsValidMCDates(models);
+ if (!IsValidContent.Status)
+ {
+ return content.Error(IsValidContent.Message);
+ }
+
+ string materielCode = models.FirstOrDefault()?.MaterielCode ?? "";
+ Dt_MaterielInfo materielInfo = _basicRepository.MaterielInfoRepository.QueryFirst(x => x.MaterielCode == materielCode);
+ if (materielInfo == null)
+ {
+ return WebResponseContent.Instance.Error($"鏈壘鍒拌鐗╂枡鐨勪俊鎭�");
+ }
+
+ List<Dt_InboundOrderDetail> inboundOrderDetails = inboundOrder.Details.Where(x => x.MaterielCode == materielCode && x.BatchNo == (models.FirstOrDefault()?.LotNo ?? "")).ToList();
+
+ if (inboundOrderDetails == null || inboundOrderDetails.Count <= 0)
+ {
+ return WebResponseContent.Instance.Error($"鏈湪鍏ュ簱鍗曟槑缁嗕腑鎵惧埌璇ョ墿鏂欎俊鎭�");
+ }
+ var inboundOrderDet = inboundOrderDetails.FirstOrDefault();
+ //Dt_StockInfo? stockInfo = _stockService.StockInfoService.GetStockByPalletCode(palletCode);
+
+ decimal beforeQuantity = 0;
+
+ Dt_StockInfo stockInfo = _stockRepository.StockInfoRepository.Db.Queryable<Dt_StockInfo>().Where(x => x.PalletCode == palletCode).Includes(x => x.Details).First();
+ if (stockInfo == null)
+ {
+ stockInfo = new Dt_StockInfo()
+ {
+ BatchNo = inboundOrderDet.BatchNo,
+ PalletCode = palletCode,
+ PalletType = GetPalletType(warehouse, palletCode),//GetPalletType(warehouse, palletCode)
+ IsFull = true,
+ StockStatus = (int)StockStatusEmun.缁勭洏鏆傚瓨,
+ Creater = "WMS",
+ CreateDate = DateTime.Now,
+ MaterialType = (int)InventoryMaterialType.鎴愬搧,
+ Materialweight = 0,
+ Wlstatus = (int)InventoryMaterialStatus.鍚堟牸,
+ Mgeneratetime = DateTime.Now,
+ WarehouseId = warehouse.WarehouseId,
+ Details = new List<Dt_StockInfoDetail>()
+ };
+ }
+ else
+ {
+ if (stockInfo.StockStatus != StockStatusEmun.缁勭洏鏆傚瓨.ObjToInt())
+ {
+ return WebResponseContent.Instance.Error($"鎵樼洏鍙烽噸澶�");
+ }
+ beforeQuantity = stockInfo.Details.Sum(x => x.StockQuantity);
+ }
+
+ if (warehouse.WarehouseCode == WarehouseEnum.SC01_BC.ToString())
+ {
+ stockInfo.Remark = Initiallife.ToString();
+ string batchNo = models.FirstOrDefault()?.LotNo ?? "";
+ //Dt_StockInfoDetail existDetail = _stockRepository.StockInfoDetailRepository.QueryFirst(x => x.BatchNo == batchNo);
+ //if (existDetail != null)
+ //{
+ // return WebResponseContent.Instance.Error($"{batchNo}娴嬭瘯鏋跺凡瀛樺湪");
+ //}
+ if (models.Count >= 2)
+ {
+ return WebResponseContent.Instance.Error($"缁勭洏鏄庣粏涓嶅敮涓�");
+ }
+ //if (palletCode.Substring(0, 1) == "6")
+ //{
+ // stockInfo.PalletType = PalletTypeEnum.MediumPallet.ObjToInt();
+ //}
+ //else
+ //{
+ // stockInfo.PalletType = PalletTypeEnum.LargestPallet.ObjToInt();
+ //}
+ }
+ else if (warehouse.WarehouseCode == WarehouseEnum.SC01_BC.ToString())
+ {
+ if (models.Count >= 2)
+ {
+ return WebResponseContent.Instance.Error($"缁勭洏鏄庣粏涓嶅敮涓�");
+ }
+ }
+
+ List<Dt_StockInfoDetail> stockInfoDetails = new List<Dt_StockInfoDetail>();
+ foreach (var model in models)
+ {
+ Dt_InboundOrderDetail? notGroupDetail = inboundOrderDetails.Where(x => x.OrderDetailStatus <= OrderDetailStatusEnum.Inbounding.ObjToInt() && x.MaterielCode == model.MaterielCode && x.BatchNo == model.LotNo && x.OrderQuantity > x.ReceiptQuantity).FirstOrDefault();
+
+ if (notGroupDetail == null)
+ {
+ return WebResponseContent.Instance.Error($"璇ョ墿鏂欏湪璇ュ叆搴撳崟涓凡鍏ㄩ儴缁勭洏瀹屾垚");
+ }
+ Dt_StockInfoDetail stockInfoDetail = new Dt_StockInfoDetail()
+ {
+ MaterielCode = inboundOrderDet.MaterielCode,
+ MaterielName = inboundOrderDet.MaterielName,
+ OrderNo = inboundOrder.OrderNo,
+ BatchNo = inboundOrderDet.BatchNo,
+ LinId = inboundOrderDet.LinId,
+ StockQuantity = model.Quantity,
+ Status = (int)StockStatusEmun.缁勭洏鏆傚瓨,
+ Creater = "WMS",
+ CreateDate = DateTime.Now,
+ Id = inboundOrderDet.LinId.ObjToInt(),
+ };
+
+ if (stockInfo.Id > 0)
+ {
+ stockInfoDetail.StockId = stockInfo.Id;
+ }
+ stockInfo.Details.Add(stockInfoDetail);
+
+ stockInfoDetails.Add(stockInfoDetail);
+
+ decimal decimalReceiptQuantity = Convert.ToDecimal(notGroupDetail.ReceiptQuantity);
+ decimal decimalModelQuantity = Convert.ToDecimal(model.Quantity);
+ decimal decimalOrderQuantity = Convert.ToDecimal(notGroupDetail.OrderQuantity);
+ decimalReceiptQuantity += decimalModelQuantity;
+ // 妫�鏌ユ槸鍚﹁秴鍑鸿鍗曟暟閲�
+ if (decimalReceiptQuantity > decimalOrderQuantity)
+ {
+ return WebResponseContent.Instance.Error($"缁勭洏鏁伴噺婧㈠嚭{decimalReceiptQuantity - decimalOrderQuantity}");
+ }
+ // 杞洖float绫诲瀷瀛樺偍锛屼絾姣旇緝鍜岃绠楅兘浣跨敤decimal瀹屾垚
+ notGroupDetail.ReceiptQuantity = Convert.ToDecimal(decimalReceiptQuantity);
+ if (notGroupDetail.OrderDetailStatus == OrderDetailStatusEnum.New.ObjToInt())
+ {
+ notGroupDetail.OrderDetailStatus = OrderDetailStatusEnum.GroupAndInbound.ObjToInt();
+ }
+ }
+
+ decimal totalQuantity = stockInfo.Details.Sum(x => x.StockQuantity);
+
+ inboundOrder.OrderStatus = InOrderStatusEnum.鍏ュ簱涓�.ObjToInt();
+
+ _unitOfWorkManage.BeginTran();
+ if (stockInfo.Id == 0)
+ {
+ _stockRepository.StockInfoRepository.Db.InsertNav(stockInfo).Include(x => x.Details).ExecuteCommand();
+ }
+ else
+ {
+ _stockRepository.StockInfoRepository.Db.UpdateNav(stockInfo).Include(x => x.Details, new UpdateNavOptions() { OneToManyInsertOrUpdate = true }).ExecuteCommand();
+ }
+ _inboundRepository.InboundOrderDetailRepository.UpdateData(inboundOrderDetails);
+ _inboundRepository.InboundOrderRepository.UpdateData(inboundOrder);
+ _unitOfWorkManage.CommitTran();
+ content.OK();
+ }
+ catch (Exception ex)
+ {
+ content = WebResponseContent.Instance.Error(ex.Message);
+ }
+ finally
+ {
+
+ }
+ return content;
+ }
+ public int GetPalletType(Dt_Warehouse warehouse, string palletCode)
+ {
+
+ if (warehouse.WarehouseCode == WarehouseEnum.SC01_BC.ObjToString())
+ {
+ Dt_PalletTypeInfo palletTypeInfo = _palletTypeInfoRepository.QueryFirst(x => x.CodeStartStr == palletCode.Substring(0, 3));
+ if (palletTypeInfo == null)
+ {
+ throw new Exception($"鎵樼洏鍙烽敊璇�");
+ }
+ return palletTypeInfo.PalletType;
+ }
+ //else if (warehouse.WarehouseCode == WarehouseEnum.HA152.ObjToString())
+ //{
+ // Dt_PalletTypeInfo palletTypeInfo = _palletTypeInfoRepository.QueryFirst(x => x.CodeStartStr == palletCode.Substring(0, 2));
+ // if (palletTypeInfo == null)
+ // {
+ // throw new Exception($"鎵樼洏鍙烽敊璇�");
+ // }
+ // return palletTypeInfo.PalletType;
+ //}
+ //else if (warehouse.WarehouseCode == WarehouseEnum.HA57.ObjToString())
+ //{
+ // Dt_PalletTypeInfo palletTypeInfo = _palletTypeInfoRepository.QueryFirst(x => x.CodeStartStr == palletCode.Substring(0, 3));
+ // if (palletTypeInfo == null)
+ // {
+ // throw new Exception($"鎵樼洏鍙烽敊璇�");
+ // }
+ // return palletTypeInfo.PalletType;
+ //}
+ //else if (warehouse.WarehouseCode == WarehouseEnum.HA58.ObjToString())
+ //{
+ // Dt_PalletTypeInfo palletTypeInfo = _palletTypeInfoRepository.QueryFirst(x => x.CodeStartStr == palletCode.Substring(0, 2));
+ // if (palletTypeInfo == null)
+ // {
+ // throw new Exception($"鎵樼洏鍙烽敊璇�");
+ // }
+ // return palletTypeInfo.PalletType;
+ //}
+ return -1;
+ }
+ /// <summary>
+ /// 鍒ゆ柇姝g‘鏃堕棿鏍煎紡
+ /// </summary>
+ public WebResponseContent IsValidMCDates(List<MatSerNumAnalysisModel> analysisModels)
+ {
+ string[] effDates = analysisModels.Select(x => x.EffectiveDate).Distinct().ToArray();
+ string[] ProDates = analysisModels.Select(x => x.ProductionDate).Distinct().ToArray();
+ foreach (string effDate in effDates)
+ {
+ string format = "yyyy-MM-dd"; // 鐩爣鏍煎紡
+ DateTime parsedDate;
+ // 瑙f瀽骞堕獙璇佹牸寮�
+ bool isValid = DateTime.TryParseExact(
+ effDate,
+ format,
+ CultureInfo.InvariantCulture,
+ DateTimeStyles.None,
+ out parsedDate
+ );
+
+ if (!isValid)
+ {
+ return WebResponseContent.Instance.Error("鏍煎紡鏃犳晥鎴栨棩鏈熶笉鍚堟硶");
+ }
+ }
+ foreach (string ProDate in ProDates)
+ {
+ string format = "yyyy-MM-dd"; // 鐩爣鏍煎紡
+ DateTime parsedDate;
+ // 瑙f瀽骞堕獙璇佹牸寮�
+ bool isValid = DateTime.TryParseExact(
+ ProDate,
+ format,
+ CultureInfo.InvariantCulture,
+ DateTimeStyles.None,
+ out parsedDate
+ );
+
+ if (!isValid)
+ {
+ return WebResponseContent.Instance.Error("鏍煎紡鏃犳晥鎴栨棩鏈熶笉鍚堟硶");
+ }
+ }
+ return WebResponseContent.Instance.OK();
}
/// <summary>
@@ -100,16 +390,17 @@
{
Dt_InboundOrderDetail orderDetail = new Dt_InboundOrderDetail()
{
- OrderId = inboundOrderOld.Id,
MaterielCode = item.MaterielCode,
- BatchNo = "",
+ BatchNo = item.BatchNo,
OrderQuantity = item.OrderQuantity,
ReceiptQuantity = 0,
OverInQuantity = 0,
OrderDetailStatus = OrderDetailStatusEnum.New.ObjToInt(),
LinId = item.LinId,
- MaterielName = materielInfo.MaterielName,
- MaterieSpec = materielInfo.MaterieSpec
+ LPNNo = item.LPN_No,
+ MaterielName = item.MaterielName,
+ MaterieSpec = item.MaterieSpec,
+ Creater = "涓婃父WMS"
};
_inboundRepository.InboundOrderDetailRepository.AddData(orderDetail);
}
--
Gitblit v1.9.3