| | |
| | | using System; |
| | | using SqlSugar.Extensions; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Reflection.Metadata; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using System.Transactions; |
| | | using WIDESEA_Core; |
| | | using WIDESEA_Core.BaseServices; |
| | | using WIDESEA_Core.Enums; |
| | | using WIDESEA_DTO.Inbound; |
| | | using WIDESEA_IStockRepository; |
| | | using WIDESEA_IStockService; |
| | | using WIDESEA_Model.Models; |
| | |
| | | { |
| | | public partial class StockInfoDetailService : ServiceBase<Dt_StockInfoDetail, IStockInfoDetailRepository>, IStockInfoDetailService |
| | | { |
| | | public StockInfoDetailService(IStockInfoDetailRepository BaseDal) : base(BaseDal) |
| | | private readonly IStockInfoDetailRepository _stockInfoDetailRepository; |
| | | private readonly IStockInfoService _stockInfoService; |
| | | public StockInfoDetailService(IStockInfoDetailRepository BaseDal, IStockInfoDetailRepository stockInfoDetailRepository, IStockInfoService stockInfoService) : base(BaseDal) |
| | | { |
| | | _stockInfoDetailRepository = stockInfoDetailRepository; |
| | | _stockInfoService = stockInfoService; |
| | | } |
| | | |
| | | public IStockInfoDetailRepository Repository => BaseDal; |
| | | |
| | | public override WebResponseContent DeleteData(object[] keys) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | var DelStockInfoDetails = BaseDal.QueryData(x => keys.Contains(x.Id)).ToList(); |
| | | if (DelStockInfoDetails == null || DelStockInfoDetails.Count < 1) throw new Exception($"æªæ¾å°ä¿¡æ¯"); |
| | | if (DelStockInfoDetails.FirstOrDefault(x => x.Status > StockStatusEmun.ç»çæå.ObjToInt()) != null) |
| | | throw new Exception($"åºåæç»ç¶æä¸ä¸ºç»çæåæä¸è½å é¤"); |
| | | var StockIds = DelStockInfoDetails.Select(x => x.StockId).ToList(); |
| | | var StockInfoDetails = BaseDal.QueryData(x => StockIds.Contains(x.StockId)).Select(x => x.StockId).GroupBy(x => x).ToList(); |
| | | List<Dt_StockInfo> StockInfos = new List<Dt_StockInfo>(); |
| | | foreach (var item in StockInfoDetails) |
| | | { |
| | | if (item.Count() == DelStockInfoDetails.Where(x => x.StockId == item.Key).Count()) |
| | | { |
| | | var StockInfo = Db.Queryable<Dt_StockInfo>().Where(x => item.Key == x.Id).First(); |
| | | StockInfos.Add(StockInfo); |
| | | } |
| | | } |
| | | List<Dt_InboundOrder> inboundOrders = new List<Dt_InboundOrder>(); |
| | | List<Dt_InboundOrderDetail> inboundOrderDetails = new List<Dt_InboundOrderDetail>(); |
| | | foreach (var DelStockInfoDetail in DelStockInfoDetails.GroupBy(x => x.OrderNo)) |
| | | { |
| | | var inboundOrder = BaseDal.Db.Queryable<Dt_InboundOrder>().Includes(x => x.Details).First(x => x.OrderNo == DelStockInfoDetail.Key); |
| | | if (inboundOrder != null) |
| | | { |
| | | foreach (var item in DelStockInfoDetail) |
| | | { |
| | | var inboundOrderDetail = inboundOrder.Details.FirstOrDefault(x => x.BatchNo == item.BatchNo); |
| | | if (inboundOrderDetail != null) |
| | | { |
| | | inboundOrderDetail.ReceiptQuantity -= 1;// item.StockQuantity; |
| | | if (inboundOrderDetail.ReceiptQuantity == 0) inboundOrderDetail.OrderDetailStatus = OrderDetailStatusEnum.New.ObjToInt(); |
| | | } |
| | | } |
| | | inboundOrderDetails.AddRange(inboundOrder.Details); |
| | | if (inboundOrder.Details.FirstOrDefault(x => x.OrderDetailStatus != OrderDetailStatusEnum.New.ObjToInt()) == null) |
| | | { |
| | | inboundOrder.OrderStatus = InboundStatusEnum.æªå¼å§.ObjToInt(); |
| | | inboundOrders.Add(inboundOrder); |
| | | } |
| | | } |
| | | } |
| | | Db.Ado.BeginTran(); |
| | | BaseDal.Db.Updateable(inboundOrderDetails).ExecuteCommand(); |
| | | BaseDal.Db.Updateable(inboundOrders).ExecuteCommand(); |
| | | _stockInfoService.DeleteData(StockInfos); |
| | | base.DeleteData(keys); |
| | | Db.Ado.CommitTran(); |
| | | content.OK(); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | Db.Ado.RollbackTran(); |
| | | content.Error(ex.Message); |
| | | } |
| | | return content; |
| | | } |
| | | } |
| | | } |