| | |
| | | using WIDESEA_Common.StockEnum; |
| | | using SqlSugar; |
| | | using WIDESEA_Common.StockEnum; |
| | | using WIDESEA_Core; |
| | | using WIDESEA_DTO.Stock; |
| | | using WIDESEA_IStockService; |
| | |
| | | } |
| | | |
| | | /// <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> |
| | | public async Task<WebResponseContent> GroupPalletAsync(StockDTO stock) |
| | |
| | | Status = StockStatusEmun.组盘暂存.GetHashCode(), |
| | | }).ToList(); |
| | | |
| | | 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; |
| | | if (result) return content.OK("组盘成功"); |
| | | return content.Error("组盘失败"); |
| | | return result ? content.OK("组盘成功") : content.Error("组盘失败"); |
| | | } |
| | | |
| | | var entity = new Dt_StockInfo |
| | |
| | | }; |
| | | |
| | | result = StockInfoService.Repository.AddData(entity, x => x.Details); |
| | | if (result) return content.OK("组盘成功"); |
| | | return content.Error("组盘失败"); |
| | | return result ? content.OK("组盘成功") : content.Error("组盘失败"); |
| | | }); |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | /// </summary> |
| | | public async Task<WebResponseContent> ChangePalletAsync(StockDTO stock) |
| | | { |
| | | |
| | | WebResponseContent content = new WebResponseContent(); |
| | | if (stock == null || |
| | | string.IsNullOrWhiteSpace(stock.TargetPalletNo) || |
| | |
| | | return content.Error("源托盘号与目标托盘号相同"); |
| | | } |
| | | |
| | | return await ExecuteWithinTransactionAsync(async () => |
| | | { |
| | | var sourceStock = await StockInfoService.Repository.QueryDataNavFirstAsync(s => s.PalletCode == stock.SourcePalletNo); |
| | | if (sourceStock == null) return content.Error("源托盘不存在"); |
| | | |
| | |
| | | var result = await StockInfoDetailService.Repository.UpdateDataAsync(detailEntities); |
| | | if (!result) return content.Error("换盘失败"); |
| | | return content.OK("换盘成功"); |
| | | }); |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | if (stock == null || string.IsNullOrWhiteSpace(stock.SourcePalletNo)) |
| | | return content.Error("源托盘号不能为空"); |
| | | |
| | | return await ExecuteWithinTransactionAsync(async () => |
| | | { |
| | | var sourceStock = StockInfoService.Repository.QueryFirst(s => s.PalletCode == stock.SourcePalletNo); |
| | | if (sourceStock == null) return content.Error("源托盘不存在"); |
| | | |
| | |
| | | var result = await StockInfoDetailService.Repository.DeleteDataAsync(detailEntities); |
| | | if (!result) return content.Error("拆盘失败"); |
| | | return content.OK("拆盘成功"); |
| | | }); |
| | | } |
| | | |
| | | /// <summary> |