From 88724eca51a5863f20ee0a552af741aeebf4e8f2 Mon Sep 17 00:00:00 2001
From: wanshenmean <cathay_xy@163.com>
Date: 星期三, 11 二月 2026 17:31:45 +0800
Subject: [PATCH] 添加堆垛机配置并重构任务
---
Code/WMS/WIDESEA_WMSServer/WIDESEA_StockService/StockSerivce.cs | 191 +++++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 181 insertions(+), 10 deletions(-)
diff --git a/Code/WMS/WIDESEA_WMSServer/WIDESEA_StockService/StockSerivce.cs b/Code/WMS/WIDESEA_WMSServer/WIDESEA_StockService/StockSerivce.cs
index 5747dac..64f19fc 100644
--- a/Code/WMS/WIDESEA_WMSServer/WIDESEA_StockService/StockSerivce.cs
+++ b/Code/WMS/WIDESEA_WMSServer/WIDESEA_StockService/StockSerivce.cs
@@ -1,27 +1,198 @@
-锘縰sing System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
+锘縰sing WIDESEA_Common.StockEnum;
+using WIDESEA_DTO.Stock;
using WIDESEA_IStockService;
+using WIDESEA_Model.Models;
namespace WIDESEA_StockService
{
- public class StockSerivce:IStockService
+ /// <summary>
+ /// 搴撳瓨鏈嶅姟
+ /// </summary>
+ public class StockSerivce : IStockService
{
public IStockInfoDetailService StockInfoDetailService { get; }
-
public IStockInfoService StockInfoService { get; }
public IStockInfoDetail_HtyService StockInfoDetail_HtyService { get; }
-
public IStockInfo_HtyService StockInfo_HtyService { get; }
- public StockSerivce(IStockInfoDetailService stockInfoDetailService, IStockInfoService stockInfoService, IStockInfoDetail_HtyService stockInfoDetail_HtyService, IStockInfo_HtyService stockInfo_HtyService)
+ public StockSerivce(
+ IStockInfoDetailService stockInfoDetailService,
+ IStockInfoService stockInfoService,
+ IStockInfoDetail_HtyService stockInfoDetail_HtyService,
+ IStockInfo_HtyService stockInfo_HtyService)
{
StockInfoDetailService = stockInfoDetailService;
StockInfoService = stockInfoService;
StockInfoDetail_HtyService = stockInfoDetail_HtyService;
StockInfo_HtyService = stockInfo_HtyService;
}
+
+ /// <summary>
+ /// 缁勭洏
+ /// </summary>
+ public async Task<bool> GroupPallet(StockDTO stock)
+ {
+ var now = DateTime.Now;
+ var details = stock.Details.Select(item => new Dt_StockInfoDetail
+ {
+ MaterielCode = "鐢佃姱",
+ MaterielName = "鐢佃姱",
+ StockQuantity = item.Quantity,
+ Unit = "PCS",
+ Creater = "system",
+ OrderNo = "111",
+ ProductionDate = now.ToString(),
+ EffectiveDate = now.AddYears(1).ToString(),
+ SerialNumber = item.CellBarcode,
+ InboundOrderRowNo = item.Channel,
+ Status = StockStatusEmun.缁勭洏鏆傚瓨.GetHashCode(),
+ }).ToList();
+
+ var existingStock = StockInfoService.Repository.QueryFirst(s => s.PalletCode == stock.TargetPalletNo);
+ if (existingStock != null)
+ {
+ details.ForEach(d => d.StockId = existingStock.Id);
+ return await StockInfoDetailService.Repository.AddDataAsync(details) > 0;
+ }
+
+ var entity = new Dt_StockInfo
+ {
+ PalletCode = stock.TargetPalletNo,
+ WarehouseId = 1,
+ StockStatus = 1,
+ Creater = "system",
+ Details = details
+ };
+
+ return StockInfoService.Repository.AddData(entity, x => x.Details);
+ }
+
+ /// <summary>
+ /// 鎹㈢洏
+ /// </summary>
+ public async Task<bool> ChangePallet(StockDTO stock)
+ {
+ if (stock == null ||
+ string.IsNullOrWhiteSpace(stock.TargetPalletNo) ||
+ string.IsNullOrWhiteSpace(stock.SourcePalletNo) ||
+ string.Equals(stock.SourcePalletNo, stock.TargetPalletNo, StringComparison.OrdinalIgnoreCase))
+ {
+ return false;
+ }
+
+ var sourceStock = StockInfoService.Repository.QueryFirst(s => s.PalletCode == stock.SourcePalletNo);
+ if (sourceStock == null) return false;
+
+ var targetStock = StockInfoService.Repository.QueryFirst(s => s.PalletCode == stock.TargetPalletNo);
+ if (targetStock == null)
+ {
+ var newStock = new Dt_StockInfo
+ {
+ PalletCode = stock.TargetPalletNo,
+ WarehouseId = sourceStock.WarehouseId,
+ StockStatus = sourceStock.StockStatus,
+ Creater = "system"
+ };
+
+ var newId = StockInfoService.Repository.AddData(newStock);
+ if (newId <= 0) return false;
+
+ targetStock = newStock;
+ targetStock.Id = newId;
+ }
+
+ var serialNumbers = stock.Details.Select(d => d.CellBarcode).Distinct().ToList();
+ if (!serialNumbers.Any()) return false;
+
+ var detailEntities = StockInfoDetailService.Repository.QueryData(
+ d => d.StockId == sourceStock.Id && serialNumbers.Contains(d.SerialNumber));
+ if (!detailEntities.Any()) return false;
+
+ if (await StockInfoDetail_HtyService.Repository.AddDataAsync(CreateDetailHistory(detailEntities, "鎹㈢洏")) <= 0)
+ return false;
+
+ if (await StockInfo_HtyService.Repository.AddDataAsync(CreateStockHistory(new[] { sourceStock, targetStock }, "鎹㈢洏")) <= 0)
+ return false;
+
+ detailEntities.ForEach(d => d.StockId = targetStock.Id);
+ return await StockInfoDetailService.Repository.UpdateDataAsync(detailEntities);
+ }
+
+ /// <summary>
+ /// 鎷嗙洏
+ /// </summary>
+ public async Task<bool> SplitPallet(StockDTO stock)
+ {
+ if (stock == null || string.IsNullOrWhiteSpace(stock.SourcePalletNo))
+ return false;
+
+ var sourceStock = StockInfoService.Repository.QueryFirst(s => s.PalletCode == stock.SourcePalletNo);
+ if (sourceStock == null) return false;
+
+ var serialNumbers = stock.Details.Select(d => d.CellBarcode).Distinct().ToList();
+ if (!serialNumbers.Any()) return false;
+
+ var detailEntities = StockInfoDetailService.Repository.QueryData(
+ d => d.StockId == sourceStock.Id && serialNumbers.Contains(d.SerialNumber));
+ if (!detailEntities.Any()) return false;
+
+ if (await StockInfoDetail_HtyService.Repository.AddDataAsync(CreateDetailHistory(detailEntities, "鎷嗙洏")) <= 0)
+ return false;
+
+ if (await StockInfo_HtyService.Repository.AddDataAsync(CreateStockHistory(new[] { sourceStock }, "鎷嗙洏")) <= 0)
+ return false;
+
+ return await StockInfoDetailService.Repository.DeleteDataAsync(detailEntities);
+ }
+
+ private static List<Dt_StockInfoDetail_Hty> CreateDetailHistory(IEnumerable<Dt_StockInfoDetail> details, string operateType)
+ {
+ var now = DateTime.Now;
+ return details.Select(d => new Dt_StockInfoDetail_Hty
+ {
+ SourceId = d.Id,
+ OperateType = operateType,
+ InsertTime = now,
+ StockId = d.StockId,
+ MaterielCode = d.MaterielCode,
+ MaterielName = d.MaterielName,
+ OrderNo = d.OrderNo,
+ BatchNo = d.BatchNo,
+ ProductionDate = d.ProductionDate,
+ EffectiveDate = d.EffectiveDate,
+ SerialNumber = d.SerialNumber,
+ StockQuantity = d.StockQuantity,
+ OutboundQuantity = d.OutboundQuantity,
+ Status = d.Status,
+ Unit = d.Unit,
+ InboundOrderRowNo = d.InboundOrderRowNo,
+ Remark = d.Remark,
+ Creater = d.Creater,
+ CreateDate = d.CreateDate,
+ Modifier = d.Modifier,
+ ModifyDate = d.ModifyDate
+ }).ToList();
+ }
+
+ private static List<Dt_StockInfo_Hty> CreateStockHistory(IEnumerable<Dt_StockInfo> stocks, string operateType)
+ {
+ var now = DateTime.Now;
+ return stocks.Select(s => new Dt_StockInfo_Hty
+ {
+ SourceId = s.Id,
+ OperateType = operateType,
+ InsertTime = now,
+ PalletCode = s.PalletCode,
+ PalletType = s.PalletType,
+ LocationCode = s.LocationCode,
+ WarehouseId = s.WarehouseId,
+ StockStatus = s.StockStatus,
+ Remark = s.Remark,
+ Creater = s.Creater,
+ CreateDate = s.CreateDate,
+ Modifier = s.Modifier,
+ ModifyDate = s.ModifyDate
+ }).ToList();
+ }
}
-}
+}
\ No newline at end of file
--
Gitblit v1.9.3