From 6790d94f39e4cecfbc05b703e6996c0311b19a5e Mon Sep 17 00:00:00 2001 From: hehaibing-1996 Date: Fri, 24 Jan 2025 17:41:24 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E7=9B=98=E7=82=B9=E4=BF=A1?= =?UTF-8?q?=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Services/IService/IStockTakingService.cs | 2 + .../Services/Service/StockTakingService.cs | 90 +++++++++++++++++-- .../Controllers/PDAStocktakingController.cs | 15 ++++ .../ViewModels/MatDetailStocktakingInfoViewModel.cs | 61 +++++++++---- .../Views/MatDetailStocktakingInfoView.xaml | 2 +- 5 files changed, 144 insertions(+), 26 deletions(-) diff --git a/WCS.BLL/Services/IService/IStockTakingService.cs b/WCS.BLL/Services/IService/IStockTakingService.cs index fbad8b7..e02dc44 100644 --- a/WCS.BLL/Services/IService/IStockTakingService.cs +++ b/WCS.BLL/Services/IService/IStockTakingService.cs @@ -44,6 +44,8 @@ namespace WCS.BLL.Services.IService public Task> updateStocktakingInfo(UpdateStocktakingInfoRequest request); public Task> deleteStocktakingInfos(DeleteInfosRequest request); + + public Task> commitStocktakingInfos(DeleteInfosRequest request); #endregion } } diff --git a/WCS.BLL/Services/Service/StockTakingService.cs b/WCS.BLL/Services/Service/StockTakingService.cs index 835b985..ca7886d 100644 --- a/WCS.BLL/Services/Service/StockTakingService.cs +++ b/WCS.BLL/Services/Service/StockTakingService.cs @@ -1,10 +1,4 @@ -using Microsoft.Data.SqlClient; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using WCS.BLL.Config; +using WCS.BLL.Config; using WCS.BLL.DbModels; using WCS.BLL.Manager; using WCS.BLL.Services.IService; @@ -13,7 +7,6 @@ using WCS.DAL.DbModels; using WCS.Model; using WCS.Model.ApiModel.InOutRecord; using WCS.Model.ApiModel.MatBaseInfo; -using WCS.Model.ApiModel.MatDetailCurrentInfo; using WCS.Model.ApiModel.Stocktaking; using WCS.Model.WebSocketModel; @@ -1260,6 +1253,87 @@ namespace WCS.BLL.Services.Service return response; } } + + public async Task> commitStocktakingInfos(DeleteInfosRequest request) + { + try + { + //先查询出具体的Id + var stocktakingInfos = await DbHelp.db.Queryable() + .Where(t => request.needDeleteIds.Contains(t.Id)) + .ToListAsync(); + if (stocktakingInfos == null || stocktakingInfos.Count < request.needDeleteIds.Count) + { + return new ResponseCommon + { + Code = 201, + Message = $"操作失败:请刷新后重试!", + Data = null + }; + } + + if (stocktakingInfos.Where(t => t.StocktakingStatus == StocktakingStatusEnum.已提交).Any()) + { + return new ResponseCommon + { + Code = 201, + Message = $"操作失败:存在已提交的盘点数据!", + Data = null + }; + } + + var marCurrentInfoIds = stocktakingInfos.Select(t => t.MatDetailCurrentId) + .Distinct() + .ToList(); + var matCurrentInfos = await DbHelp.db.Queryable() + .Where(t => marCurrentInfoIds.Contains(t.Id)) + .ToListAsync(); + DbHelp.db.BeginTran(); + foreach (var matCurrentInfo in matCurrentInfos) + { + var stocktakingInfo = stocktakingInfos.Where(t => t.MatDetailCurrentId == matCurrentInfo.Id) + .FirstOrDefault(); + if (stocktakingInfo == null) + { + continue; + } + if (stocktakingInfo.StocktakingQty != 0) + { + //TO DO 形成数据更新记录 + matCurrentInfo.MatQty = stocktakingInfo.StocktakingQty; + matCurrentInfo.ModifyUser = request.UserName; + matCurrentInfo.ModifyTime = DateTime.Now; + + DbHelp.db.Updateable(matCurrentInfo).ExecuteCommand(); + } + else + { + //TO DO 形成数据更新记录 + + DbHelp.db.Deleteable(matCurrentInfo).ExecuteCommand(); + } + stocktakingInfo.StocktakingStatus = StocktakingStatusEnum.已提交; + DbHelp.db.Updateable(stocktakingInfo).ExecuteCommand(); + } + DbHelp.db.CommitTran(); + return new ResponseCommon() + { + Code = 200, + Message = "success", + Data = null, + }; + } + catch (Exception ex) + { + var response = new ResponseCommon + { + Code = 300, + Message = $"操作失败:{ex.Message}", + Data = null + }; + return response; + } + } #endregion } } diff --git a/WCS.WebApi/Controllers/PDAStocktakingController.cs b/WCS.WebApi/Controllers/PDAStocktakingController.cs index e498dc5..fcda727 100644 --- a/WCS.WebApi/Controllers/PDAStocktakingController.cs +++ b/WCS.WebApi/Controllers/PDAStocktakingController.cs @@ -101,5 +101,20 @@ namespace WCS.WebApi.Controllers } return await _stockTakingService.deleteStocktakingInfos(request); } + + [HttpPost("commitStocktakingInfos")] + public async Task> commitStocktakingInfos(DeleteInfosRequest request) + { + //校验 + if (request.needDeleteIds == null || request.needDeleteIds.Count == 0) + { + return new ResponseCommon() + { + Code = 201, + Message = "操作失败:参数校验失败(ID)." + }; + } + return await _stockTakingService.commitStocktakingInfos(request); + } } } diff --git a/货架标准上位机/ViewModels/MatDetailStocktakingInfoViewModel.cs b/货架标准上位机/ViewModels/MatDetailStocktakingInfoViewModel.cs index 540fcd1..3f61662 100644 --- a/货架标准上位机/ViewModels/MatDetailStocktakingInfoViewModel.cs +++ b/货架标准上位机/ViewModels/MatDetailStocktakingInfoViewModel.cs @@ -1,31 +1,16 @@ using HandyControl.Controls; -using MiniExcelLibs; using Ping9719.WpfEx.Mvvm; using System; using System.Collections.Generic; using System.Linq; -using System.Runtime.CompilerServices; -using System.Text; -using System.Threading; -using System.Threading.Tasks; using System.Windows.Input; -using System.Windows.Media; using SqlSugar; -using HandyControl.Data; -using System.Windows; -using Newtonsoft.Json.Linq; using 智慧物流软件系统.Views.Controls; -using WCS.Model.ApiModel.User; using 智慧物流软件系统.Api; using WCS.Model; using WCS.Model.ApiModel; -using System.Windows.Controls; -using WCS.Model.ApiModel.InterfaceRecord; -using WCS.BLL.DbModels; using WCS.Model.ApiModel.MatBaseInfo; using System.Collections.ObjectModel; -using HandyControl.Tools.Extension; -using 智慧物流软件系统.Tool; using WCS.Model.ApiModel.Stocktaking; namespace 智慧物流软件系统.ViewModel @@ -45,7 +30,7 @@ namespace 智慧物流软件系统.ViewModel StocktakingStatuses.Add(status.ToString()); } - selectedStocktakingStatus = StocktakingStatuses.First(); + SelectedStocktakingStatus = StocktakingStatuses.First(); } #region Property @@ -140,7 +125,7 @@ namespace 智慧物流软件系统.ViewModel MatCode = string.Empty; MatName = string.Empty; StocktakingUser = string.Empty; - + SelectedStocktakingStatus = StocktakingStatuses.First(); } public ICommand BtnSearchCommand { get => new DelegateCommand(BtnSearchReset); } @@ -193,6 +178,48 @@ namespace 智慧物流软件系统.ViewModel } + /// + /// 物料删除操作 + /// + public ICommand BtnCommitCommand { get => new DelegateCommand(BtnCommit); } + public async void BtnCommit() + { + Growl.Ask($"是否提交所有勾选得数据]!", isConfirmed => + { + if (isConfirmed) + { + //查询勾选的第一个数据 + var needDeleteIds = DataGridItemSource?.Where(t => t.IsSelected == true) + .Select(t => t.Id) + .ToList(); + if (needDeleteIds == null) + { + Growl.Warning("请选择需要提交的数据!"); + } + else + { + var body = new DeleteInfosRequest() + { + UserName = LocalStatic.CurrentUser, + DeviceType = LocalFile.Config.DeviceType, + needDeleteIds = needDeleteIds, + }; + var Result = ApiHelp.GetDataFromHttp>(LocalFile.Config.ApiIpHost + "PDAStocktaking/commitStocktakingInfos", body, "POST"); + if (Result != null && Result.Code == 200) + { + CurrentPage = 1; + Growl.Success("提交成功!" + Result?.Message); + } + else + { + Growl.Error($"{Result?.Message?.ToString()}"); + } + } + } + return true; + }); + } + /// /// 物料修改操作 /// diff --git a/货架标准上位机/Views/MatDetailStocktakingInfoView.xaml b/货架标准上位机/Views/MatDetailStocktakingInfoView.xaml index 35c059c..d8a1260 100644 --- a/货架标准上位机/Views/MatDetailStocktakingInfoView.xaml +++ b/货架标准上位机/Views/MatDetailStocktakingInfoView.xaml @@ -120,7 +120,7 @@ FontFamily="{StaticResource IconFont}" Foreground="WhiteSmoke" Background="HotPink" - Command="{Binding BtnAddCommand}"> + Command="{Binding BtnCommitCommand}">