From b698a2085fd090e90abedb1e91266ec496574b29 Mon Sep 17 00:00:00 2001
From: wanshenmean <cathay_xy@163.com>
Date: 星期四, 16 四月 2026 23:31:35 +0800
Subject: [PATCH] 1
---
Code/WMS/WIDESEA_WMSServer/WIDESEA_StockService/StockSerivce.cs | 612 +++++++++++++++++++++++++++++++++++++------------------
1 files changed, 412 insertions(+), 200 deletions(-)
diff --git a/Code/WMS/WIDESEA_WMSServer/WIDESEA_StockService/StockSerivce.cs b/Code/WMS/WIDESEA_WMSServer/WIDESEA_StockService/StockSerivce.cs
index db183dd..d2f1044 100644
--- a/Code/WMS/WIDESEA_WMSServer/WIDESEA_StockService/StockSerivce.cs
+++ b/Code/WMS/WIDESEA_WMSServer/WIDESEA_StockService/StockSerivce.cs
@@ -1,279 +1,491 @@
-锘縰sing WIDESEA_Common.StockEnum;
+锘縰sing Newtonsoft.Json;
+using SqlSugar;
+using WIDESEA_Common.Constants;
+using WIDESEA_Common.StockEnum;
+using WIDESEA_Core;
+using WIDESEA_DTO.MES;
using WIDESEA_DTO.Stock;
+using WIDESEA_IBasicService;
using WIDESEA_IStockService;
using WIDESEA_Model.Models;
namespace WIDESEA_StockService
{
/// <summary>
- /// 搴撳瓨鏈嶅姟
+ /// 搴撳瓨鏈嶅姟鑱氬悎瀹炵幇绫�
/// </summary>
- public class StockSerivce : IStockService
+ public class StockService : IStockService
{
+ /// <summary>
+ /// 搴撳瓨鏄庣粏鏈嶅姟
+ /// </summary>
public IStockInfoDetailService StockInfoDetailService { get; }
+ /// <summary>
+ /// 搴撳瓨淇℃伅鏈嶅姟
+ /// </summary>
public IStockInfoService StockInfoService { get; }
+
+ /// <summary>
+ /// 搴撳瓨鏄庣粏鍘嗗彶鏈嶅姟
+ /// </summary>
public IStockInfoDetail_HtyService StockInfoDetail_HtyService { get; }
+ /// <summary>
+ /// 搴撳瓨鍘嗗彶鏈嶅姟
+ /// </summary>
public IStockInfo_HtyService StockInfo_HtyService { get; }
+
+ /// <summary>
+ /// 浠撳簱鏈嶅姟
+ /// </summary>
+ public IWarehouseService _warehouseService { get; }
+
+ /// <summary>
+ /// SqlSugar瀹㈡埛绔紙鐢ㄤ簬涓存椂琛ㄦ搷浣滐級
+ /// </summary>
+ public ISqlSugarClient SqlSugarClient { get; }
+
+ /// <summary>
+ /// Mes鎺ュ彛鏈嶅姟
+ /// </summary>
+ public IMesService _mesService { get; }
/// <summary>
/// 鏋勯�犲嚱鏁�
/// </summary>
/// <param name="stockInfoDetailService">搴撳瓨鏄庣粏鏈嶅姟</param>
- /// <param name="stockInfoService">搴撳瓨鏈嶅姟</param>
+ /// <param name="stockInfoService">搴撳瓨淇℃伅鏈嶅姟</param>
/// <param name="stockInfoDetail_HtyService">搴撳瓨鏄庣粏鍘嗗彶鏈嶅姟</param>
/// <param name="stockInfo_HtyService">搴撳瓨鍘嗗彶鏈嶅姟</param>
- public StockSerivce(IStockInfoDetailService stockInfoDetailService, IStockInfoService stockInfoService, IStockInfoDetail_HtyService stockInfoDetail_HtyService, IStockInfo_HtyService stockInfo_HtyService)
+ public StockService(
+ IStockInfoDetailService stockInfoDetailService,
+ IStockInfoService stockInfoService,
+ IStockInfoDetail_HtyService stockInfoDetail_HtyService,
+ IStockInfo_HtyService stockInfo_HtyService,
+ IMesService mesService,
+ IWarehouseService warehouseService,
+ ISqlSugarClient sqlSugarClient)
{
StockInfoDetailService = stockInfoDetailService;
StockInfoService = stockInfoService;
StockInfoDetail_HtyService = stockInfoDetail_HtyService;
StockInfo_HtyService = stockInfo_HtyService;
+ _mesService = mesService;
+ _warehouseService = warehouseService;
+ SqlSugarClient = sqlSugarClient;
+ }
+
+ /// <summary>
+ /// 鍦ㄤ簨鍔′腑鎵ц鎿嶄綔
+ /// </summary>
+ private async Task<WebResponseContent> ExecuteWithinTransactionAsync(Func<Task<WebResponseContent>> operation)
+ {
+ var db = StockInfoService.Repository.Db as SqlSugarClient;
+ if (db == null)
+ {
+ return WebResponseContent.Instance.Error("Database context does not support transactions");
+ }
+
+ var ownsTransaction = db.Ado.Transaction == null;
+ try
+ {
+ if (ownsTransaction)
+ {
+ db.BeginTran();
+ }
+
+ var result = await operation();
+ if (result?.Status == true)
+ {
+ if (ownsTransaction)
+ {
+ db.CommitTran();
+ }
+ return result;
+ }
+
+ if (ownsTransaction)
+ {
+ db.RollbackTran();
+ }
+ return result ?? WebResponseContent.Instance.Error("Transaction failed");
+ }
+ catch
+ {
+ if (ownsTransaction)
+ {
+ db.RollbackTran();
+ }
+ throw;
+ }
}
/// <summary>
/// 缁勭洏
/// </summary>
- /// <param name="stock">缁勭洏鏁版嵁</param>
- /// <returns>鏄惁鎴愬姛</returns>
- public async Task<bool> GroupPallet(StockDTO stock)
+ public async Task<WebResponseContent> GroupPalletAsync(StockDTO stock)
{
- // 缁勮鏄庣粏鏁版嵁
- var now = DateTime.Now;
- var details = stock.Details.Select(item => new Dt_StockInfoDetail()
+ WebResponseContent content = new WebResponseContent();
+ try
{
- MaterielCode = "鐢佃姱",
- StockQuantity = item.Quantity,
- Unit = "PCS",
- Creater = "system",
- OrderNo = "111",
- ProductionDate = now.ToString(),
- EffectiveDate = now.AddYears(1).ToString(),
- SerialNumber = item.CellBarcode,
- InboundOrderRowNo = item.Channel,
- MaterielName = "鐢佃姱",
- Status = StockStatusEmun.缁勭洏鏆傚瓨.GetHashCode(),
- }).ToList();
+ var now = DateTime.Now;
+ var details = stock.Details.Select(item => new Dt_StockInfoDetail
+ {
+ MaterielCode = StockConstants.MATERIAL_CODE,
+ MaterielName = StockConstants.MATERIAL_NAME,
+ StockQuantity = item.Quantity,
+ Unit = StockConstants.UNIT,
+ Creater = StockConstants.SYSTEM_USER,
+ OrderNo = StockConstants.DEFAULT_ORDER_NO,
+ 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(detail => detail.StockId = existingStock.Id);
- return await StockInfoDetailService.Repository.AddDataAsync(details) > 0;
+ return await ExecuteWithinTransactionAsync(async () =>
+ {
+ var existingStock = StockInfoService.Repository.QueryFirst(s => s.PalletCode == stock.TargetPalletNo);
+ var result = false;
+ if (existingStock != null)
+ {
+ details.ForEach(d => d.StockId = existingStock.Id);
+ result = await StockInfoDetailService.Repository.AddDataAsync(details) > 0;
+ return result ? content.OK("缁勭洏鎴愬姛") : content.Error("缁勭洏澶辫触");
+ }
+
+ int WarehouseId = stock.Roadway switch
+ {
+ "娉ㄦ恫缁勭洏鏈烘鎵�" => (await _warehouseService.Db.Queryable<Dt_Warehouse>().FirstAsync(w => w.WarehouseCode == "GWSC1")).WarehouseId,
+ "鎹㈢洏鏈烘鎵�" => (await _warehouseService.Db.Queryable<Dt_Warehouse>().FirstAsync(w => w.WarehouseCode == "HCSC1")).WarehouseId
+ };
+
+ var entity = new Dt_StockInfo
+ {
+ PalletCode = stock.TargetPalletNo,
+ WarehouseId = WarehouseId,
+ StockStatus = StockStatusEmun.缁勭洏鏆傚瓨.GetHashCode(),
+ Creater = StockConstants.SYSTEM_USER,
+ Details = details
+ };
+ result = StockInfoService.Repository.AddData(entity, x => x.Details);
+ if (!result) return content.Error("缁勭洏澶辫触");
+
+ return content.OK("缁勭洏鎴愬姛");
+ });
}
-
- // 鎵樼洏涓嶅瓨鍦ㄥ垯鍒涘缓骞跺啓鍏ユ槑缁�
- var entity = new Dt_StockInfo()
+ catch (Exception ex)
{
- PalletCode = stock.TargetPalletNo,
- WarehouseId = 1,
- StockStatus = 1,
- Creater = "system",
- Details = details
- };
-
- //Dt_Task dt_Task = new Dt_Task()
- //{
- // TaskNum = 0,
- // PalletCode = stock.PalletNo,
- // PalletType = 1,
- // Roadway = "1",
- // TaskType = TaskTypeEnum.Inbound.GetHashCode(),
- // TaskStatus = TaskStatusEnum.New.GetHashCode(),
- // SourceAddress = stock.LineNo,
- // TargetAddress = "缁勭洏鍖�",
- // CurrentAddress = stock.LineNo,
- // NextAddress = "缁勭洏鍖�",
- // WarehouseId = 1,
- // Grade = 1,
- // Creater = "system",
- //};
-
- return StockInfoService.Repository.AddData(entity, x => x.Details);
+ return content.Error($"缁勭洏澶辫触: {ex.Message}");
+ }
}
/// <summary>
/// 鎹㈢洏
/// </summary>
- /// <param name="stock">闇�瑕佹崲鐩樼殑鏄庣粏鏁版嵁</param>
- /// <returns>鏄惁鎴愬姛</returns>
- public async Task<bool> ChangePallet(StockDTO stock)
+ public async Task<WebResponseContent> ChangePalletAsync(StockDTO stock)
{
- // 鍙傛暟鏍¢獙
- if (stock == null || string.IsNullOrWhiteSpace(stock.TargetPalletNo) || string.IsNullOrWhiteSpace(stock.SourcePalletNo))
+ WebResponseContent content = new WebResponseContent();
+ try
{
- return false;
- }
-
- // 鏂版棫鎵樼洏涓�鑷翠笉澶勭悊
- if (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()
+ if (stock == null ||
+ string.IsNullOrWhiteSpace(stock.TargetPalletNo) ||
+ string.IsNullOrWhiteSpace(stock.SourcePalletNo) ||
+ string.Equals(stock.SourcePalletNo, stock.TargetPalletNo, StringComparison.OrdinalIgnoreCase))
{
- PalletCode = stock.TargetPalletNo,
- WarehouseId = sourceStock.WarehouseId,
- StockStatus = sourceStock.StockStatus,
- Creater = "system"
- };
-
- var newId = StockInfoService.Repository.AddData(newStock);
- if (newId <= 0)
- {
- return false;
+ return content.Error("婧愭墭鐩樺彿涓庣洰鏍囨墭鐩樺彿鐩稿悓");
}
- targetStock = newStock;
- targetStock.Id = newId;
- }
+ return await ExecuteWithinTransactionAsync(async () =>
+ {
+ var sourceStock = await StockInfoService.Repository.QueryDataNavFirstAsync(s => s.PalletCode == stock.SourcePalletNo);
+ if (sourceStock == null) return content.Error("婧愭墭鐩樹笉瀛樺湪");
- // 鑾峰彇闇�瑕佽浆绉荤殑鏉$爜
- var serialNumbers = stock.Details.Select(d => d.CellBarcode).Distinct().ToList();
- if (!serialNumbers.Any())
+ 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 = StockStatusEmun.缁勭洏鏆傚瓨.GetHashCode(),
+ Creater = StockConstants.SYSTEM_USER,
+ };
+
+ var newId = StockInfoService.Repository.AddData(newStock);
+ if (newId <= 0) return content.Error("鎹㈢洏澶辫触");
+
+ targetStock = newStock;
+ targetStock.Id = newId;
+ }
+
+ var serialNumbers = stock.Details.Select(d => d.Channel).Distinct().ToList();
+ if (!serialNumbers.Any()) return content.Error("鏈壘鍒版湁鏁堢殑搴忓垪鍙�");
+
+ var detailEntities = StockInfoDetailService.Repository.QueryData(
+ d => d.StockId == sourceStock.Id && serialNumbers.Contains(d.InboundOrderRowNo));
+ if (!detailEntities.Any()) return content.Error("鏈壘鍒版湁鏁堢殑搴撳瓨鏄庣粏");
+
+ if (await StockInfoDetail_HtyService.Repository.AddDataAsync(CreateDetailHistory(detailEntities, "鎹㈢洏")) <= 0)
+ return content.Error("鎹㈢洏鍘嗗彶璁板綍淇濆瓨澶辫触");
+
+ if (await StockInfo_HtyService.Repository.AddDataAsync(CreateStockHistory(new[] { sourceStock, targetStock }, "鎹㈢洏")) <= 0)
+ return content.Error("鎹㈢洏鍘嗗彶璁板綍淇濆瓨澶辫触");
+
+ detailEntities.ForEach(d => d.StockId = targetStock.Id);
+ var result = await StockInfoDetailService.Repository.UpdateDataAsync(detailEntities);
+ if (!result) return content.Error("鎹㈢洏澶辫触");
+
+ return content.OK("鎹㈢洏鎴愬姛");
+ });
+ }
+ catch (Exception ex)
{
- return false;
+ return content.Error($"鎹㈢洏澶辫触: {ex.Message}");
}
-
- // 鏌ヨ婧愭墭鐩樺搴旂殑鏄庣粏
- var detailEntities = StockInfoDetailService.Repository.QueryData(d => d.StockId == sourceStock.Id && serialNumbers.Contains(d.SerialNumber));
-
- if (!detailEntities.Any())
- {
- return false;
- }
-
- // 鍐欏叆鍘嗗彶璁板綍
- var detailHistory = CreateDetailHistory(detailEntities, "鎹㈢洏");
- if (await StockInfoDetail_HtyService.Repository.AddDataAsync(detailHistory) <= 0)
- {
- return false;
- }
-
- var stockHistory = CreateStockHistory(new List<Dt_StockInfo> { sourceStock, targetStock }, "鎹㈢洏");
- if (await StockInfo_HtyService.Repository.AddDataAsync(stockHistory) <= 0)
- {
- return false;
- }
-
- // 鏇存柊鏄庣粏鐨勬墭鐩樹富閿�
- detailEntities.ForEach(detail => detail.StockId = targetStock.Id);
- return await StockInfoDetailService.Repository.UpdateDataAsync(detailEntities);
}
/// <summary>
/// 鎷嗙洏
/// </summary>
- /// <param name="stock">闇�瑕佹媶鐩樼殑鏄庣粏鏁版嵁</param>
- /// <returns>鏄惁鎴愬姛</returns>
- public async Task<bool> SplitPallet(StockDTO stock)
+ public async Task<WebResponseContent> SplitPalletAsync(StockDTO stock)
{
- // 鍙傛暟鏍¢獙
- if (stock == null || string.IsNullOrWhiteSpace(stock.SourcePalletNo))
+ WebResponseContent content = new WebResponseContent();
+ try
{
- return false;
- }
+ if (stock == null || string.IsNullOrWhiteSpace(stock.SourcePalletNo))
+ return content.Error("婧愭墭鐩樺彿涓嶈兘涓虹┖");
- // 鏌ヨ婧愭墭鐩�
- var sourceStock = StockInfoService.Repository.QueryFirst(s => s.PalletCode == stock.SourcePalletNo);
- if (sourceStock == null)
+ // 骞傜瓑鍐欏叆锛氭鏌ヤ复鏃惰〃鏄惁宸叉湁璇ユ墭鐩樿褰曪紝鏃犲垯鍐欏叆
+ var existingTemp = SqlSugarClient.Queryable<Dt_SplitTemp>()
+ .Where(t => t.PalletCode == stock.SourcePalletNo)
+ .First();
+ if (existingTemp == null)
+ {
+ // 鏌ヨ璇ユ墭鐩樺綋鍓嶆墍鏈夌數鑺紝瀛樺叆涓存椂琛�
+ var sourceStockForTemp = StockInfoService.Repository.QueryFirst(s => s.PalletCode == stock.SourcePalletNo);
+ if (sourceStockForTemp != null)
+ {
+ var allDetails = StockInfoDetailService.Repository.QueryData(d => d.StockId == sourceStockForTemp.Id);
+ if (allDetails != null && allDetails.Any())
+ {
+ var sfcListJson = JsonConvert.SerializeObject(allDetails.Select(d => d.SerialNumber).ToList());
+ await SqlSugarClient.Insertable(new Dt_SplitTemp
+ {
+ PalletCode = stock.SourcePalletNo,
+ SfcList = sfcListJson,
+ CreateTime = DateTime.Now
+ }).ExecuteCommandAsync();
+ }
+ }
+ }
+
+ return await ExecuteWithinTransactionAsync(async () =>
+ {
+ var sourceStock = StockInfoService.Repository.QueryFirst(s => s.PalletCode == stock.SourcePalletNo);
+ if (sourceStock == null) return content.Error("婧愭墭鐩樹笉瀛樺湪");
+
+ var serialNumbers = stock.Details.Select(d => d.CellBarcode).Distinct().ToList();
+ if (!serialNumbers.Any())
+ {
+ serialNumbers = sourceStock.Details
+ .Where(x => stock.Details.Any(d => d.Channel == x.InboundOrderRowNo))
+ .Select(x => x.SerialNumber)
+ .ToList();
+ }
+
+ var detailEntities = StockInfoDetailService.Repository.QueryData(
+ d => d.StockId == sourceStock.Id && serialNumbers.Contains(d.SerialNumber));
+ if (!detailEntities.Any()) return content.Error("鏈壘鍒版湁鏁堢殑搴撳瓨鏄庣粏");
+
+ if (await StockInfoDetail_HtyService.Repository.AddDataAsync(CreateDetailHistory(detailEntities, "鎷嗙洏")) <= 0)
+ return content.Error("鎷嗙洏鍘嗗彶璁板綍淇濆瓨澶辫触");
+
+ if (await StockInfo_HtyService.Repository.AddDataAsync(CreateStockHistory(new[] { sourceStock }, "鎷嗙洏")) <= 0)
+ return content.Error("鎷嗙洏鍘嗗彶璁板綍淇濆瓨澶辫触");
+
+ return content.OK("鎷嗙洏鎴愬姛");
+ });
+ }
+ catch (Exception ex)
{
- return false;
+ return content.Error($"鎷嗙洏澶辫触: {ex.Message}");
}
-
- // 鑾峰彇闇�瑕佹媶闄ょ殑鏉$爜
- 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;
- }
-
- // 鍐欏叆鍘嗗彶璁板綍
- var detailHistory = CreateDetailHistory(detailEntities, "鎷嗙洏");
- if (await StockInfoDetail_HtyService.Repository.AddDataAsync(detailHistory) <= 0)
- {
- return false;
- }
-
- var stockHistory = CreateStockHistory(new List<Dt_StockInfo> { sourceStock }, "鎷嗙洏");
- if (await StockInfo_HtyService.Repository.AddDataAsync(stockHistory) <= 0)
- {
- return false;
- }
-
- // 鍒犻櫎鏄庣粏
- return await StockInfoDetailService.Repository.DeleteDataAsync(detailEntities);
}
- private List<Dt_StockInfoDetail_Hty> CreateDetailHistory(IEnumerable<Dt_StockInfoDetail> details, string operateType)
+ /// <summary>
+ /// 鍫嗗灈鏈烘崲鐩樺悗鏇存柊搴撳瓨淇℃伅锛堟竻绌哄簱浣嶄俊鎭級
+ /// </summary>
+ /// <param name="stock"></param>
+ /// <returns></returns>
+ public async Task<WebResponseContent> UpdateStockInfoAsync(StockInfoDTO stock)
+ {
+ WebResponseContent content = new WebResponseContent();
+ if (string.IsNullOrWhiteSpace(stock.PalletCode)) return content.Error("鎵樼洏鍙蜂笉鑳戒负绌�");
+
+ var existingStock = StockInfoService.Repository.QueryFirst(s => s.PalletCode == stock.PalletCode);
+ if (existingStock == null) return content.Error("鎵樼洏淇℃伅涓嶅瓨鍦�");
+
+ existingStock.LocationCode = "";
+ existingStock.LocationId = 0;
+
+ var result = await StockInfoService.Repository.UpdateDataAsync(existingStock);
+ if (!result) return content.Error("鏇存柊搴撳瓨淇℃伅澶辫触");
+ return content.OK("鏇存柊搴撳瓨淇℃伅鎴愬姛");
+ }
+
+ private static List<Dt_StockInfoDetail_Hty> CreateDetailHistory(IEnumerable<Dt_StockInfoDetail> details, string operateType)
{
var now = DateTime.Now;
- return details.Select(detail => new Dt_StockInfoDetail_Hty
+ return details.Select(d => new Dt_StockInfoDetail_Hty
{
- SourceId = detail.Id,
+ SourceId = d.Id,
OperateType = operateType,
InsertTime = now,
- StockId = detail.StockId,
- MaterielCode = detail.MaterielCode,
- MaterielName = detail.MaterielName,
- OrderNo = detail.OrderNo,
- BatchNo = detail.BatchNo,
- ProductionDate = detail.ProductionDate,
- EffectiveDate = detail.EffectiveDate,
- SerialNumber = detail.SerialNumber,
- StockQuantity = detail.StockQuantity,
- OutboundQuantity = detail.OutboundQuantity,
- Status = detail.Status,
- Unit = detail.Unit,
- InboundOrderRowNo = detail.InboundOrderRowNo,
- Remark = detail.Remark,
- Creater = detail.Creater,
- CreateDate = detail.CreateDate,
- Modifier = detail.Modifier,
- ModifyDate = detail.ModifyDate
+ 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 List<Dt_StockInfo_Hty> CreateStockHistory(IEnumerable<Dt_StockInfo> stocks, string operateType)
+ private static List<Dt_StockInfo_Hty> CreateStockHistory(IEnumerable<Dt_StockInfo> stocks, string operateType)
{
var now = DateTime.Now;
- return stocks.Select(stock => new Dt_StockInfo_Hty
+ return stocks.Select(s => new Dt_StockInfo_Hty
{
- SourceId = stock.Id,
+ SourceId = s.Id,
OperateType = operateType,
InsertTime = now,
- PalletCode = stock.PalletCode,
- PalletType = stock.PalletType,
- LocationCode = stock.LocationCode,
- WarehouseId = stock.WarehouseId,
- StockStatus = stock.StockStatus,
- Remark = stock.Remark,
- Creater = stock.Creater,
- CreateDate = stock.CreateDate,
- Modifier = stock.Modifier,
- ModifyDate = stock.ModifyDate
+ 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,
+ LocationId = s.LocationId,
+ OutboundDate = s.OutboundDate
}).ToList();
}
+
+ /// <summary>
+ /// 鎵归噺鎷嗙洏纭 - 涓�娆℃�ц皟鐢∕ES瑙g粦鏁翠釜鎵樼洏
+ /// </summary>
+ /// <param name="palletCode">婧愭墭鐩樺彿</param>
+ /// <returns>鎿嶄綔缁撴灉</returns>
+ public async Task<WebResponseContent> SplitPalletConfirmAsync(string palletCode)
+ {
+ WebResponseContent content = new WebResponseContent();
+ try
+ {
+ if (string.IsNullOrWhiteSpace(palletCode))
+ return content.Error("鎵樼洏鍙蜂笉鑳戒负绌�");
+
+ // 1. 浠庝复鏃惰〃璇诲彇鐢佃姱鍒楄〃
+ var tempRecord = SqlSugarClient.Queryable<Dt_SplitTemp>()
+ .Where(t => t.PalletCode == palletCode)
+ .First();
+ if (tempRecord == null)
+ return content.Error("鏈壘鍒版媶鐩樹复鏃惰褰曪紝璇峰厛鎵ц鎷嗙洏鎿嶄綔");
+
+ var sfcList = JsonConvert.DeserializeObject<List<string>>(tempRecord.SfcList);
+ if (sfcList == null || !sfcList.Any())
+ return content.Error("涓存椂琛ㄤ腑鐢佃姱鍒楄〃涓虹┖");
+
+ // 2. 璋冪敤MES瑙g粦
+ var unbindRequest = new UnBindContainerRequest
+ {
+ EquipmentCode = StockConstants.MES_EQUIPMENT_CODE,
+ ResourceCode = StockConstants.MES_RESOURCE_CODE,
+ LocalTime = DateTime.Now,
+ ContainCode = palletCode,
+ SfcList = sfcList
+ };
+ var unbindResult = _mesService.UnBindContainer(unbindRequest);
+ if (unbindResult == null || unbindResult.Data == null || !unbindResult.Data.IsSuccess)
+ {
+ return content.Error($"MES瑙g粦澶辫触: {unbindResult?.Data?.Msg ?? unbindResult?.ErrorMessage ?? "鏈煡閿欒"}");
+ }
+
+ // 3. 鍒犻櫎涓存椂琛ㄨ褰�
+ await SqlSugarClient.Deleteable<Dt_SplitTemp>().Where(t => t.PalletCode == palletCode).ExecuteCommandAsync();
+
+ return content.OK("鎵归噺鎷嗙洏纭鎴愬姛");
+ }
+ catch (Exception ex)
+ {
+ return content.Error($"鎵归噺鎷嗙洏纭澶辫触: {ex.Message}");
+ }
+ }
+
+ /// <summary>
+ /// 鎵归噺缁勭洏纭 - 涓�娆℃�ц皟鐢∕ES缁戝畾鏁翠釜鎵樼洏
+ /// </summary>
+ /// <param name="palletCode">鐩爣鎵樼洏鍙�</param>
+ /// <returns>鎿嶄綔缁撴灉</returns>
+ public async Task<WebResponseContent> GroupPalletConfirmAsync(string palletCode)
+ {
+ WebResponseContent content = new WebResponseContent();
+ try
+ {
+ if (string.IsNullOrWhiteSpace(palletCode))
+ return content.Error("鎵樼洏鍙蜂笉鑳戒负绌�");
+
+ // 1. 鏌ヨ璇ユ墭鐩樹笅鐨勬墍鏈夌數鑺槑缁�
+ var stockInfo = StockInfoService.Repository.QueryFirst(s => s.PalletCode == palletCode);
+ if (stockInfo == null)
+ return content.Error("鎵樼洏涓嶅瓨鍦�");
+
+ var details = StockInfoDetailService.Repository.QueryData(d => d.StockId == stockInfo.Id);
+ if (details == null || !details.Any())
+ return content.Error("鎵樼洏涓嬫棤鐢佃姱鏁版嵁");
+
+ // 2. 璋冪敤MES缁戝畾
+ var bindRequest = new BindContainerRequest
+ {
+ ContainerCode = palletCode,
+ EquipmentCode = StockConstants.MES_EQUIPMENT_CODE,
+ ResourceCode = StockConstants.MES_RESOURCE_CODE,
+ LocalTime = DateTime.Now,
+ OperationType = StockConstants.MES_BIND_OPERATION_TYPE,
+ ContainerSfcList = details.Select(d => new ContainerSfcItem
+ {
+ Sfc = d.SerialNumber,
+ Location = d.InboundOrderRowNo.ToString()
+ }).ToList()
+ };
+ var bindResult = _mesService.BindContainer(bindRequest);
+ if (bindResult == null || bindResult.Data == null || !bindResult.Data.IsSuccess)
+ {
+ return content.Error($"MES缁戝畾澶辫触: {bindResult?.Data?.Msg ?? bindResult?.ErrorMessage ?? "鏈煡閿欒"}");
+ }
+
+ return content.OK("鎵归噺缁勭洏纭鎴愬姛");
+ }
+ catch (Exception ex)
+ {
+ return content.Error($"鎵归噺缁勭洏纭澶辫触: {ex.Message}");
+ }
+ }
}
}
\ No newline at end of file
--
Gitblit v1.9.3