| | |
| | | |
| | | return await ExecuteWithinTransactionAsync(async () => |
| | | { |
| | | // 幂等写入:检查临时表是否已有该托盘记录,无则写入 |
| | | 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(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | var sourceStock = await StockInfoService.Repository.QueryDataNavFirstAsync(s => s.PalletCode == stock.SourcePalletNo); |
| | | if (sourceStock == null) return content.Error("源托盘不存在"); |
| | | |
| | |
| | | detailEntities.ForEach(d => d.StockId = targetStock.Id); |
| | | var result = await StockInfoDetailService.Repository.UpdateDataAsync(detailEntities); |
| | | if (!result) return content.Error("换盘失败"); |
| | | |
| | | // 检查源托盘是否还有剩余库存明细,若无则删除源托盘库存头 |
| | | var remainingSourceDetails = StockInfoDetailService.Repository.QueryData(d => d.StockId == sourceStock.Id); |
| | | if (!remainingSourceDetails.Any()) |
| | | { |
| | | if (await StockInfoService.Repository.Db.Deleteable<Dt_StockInfo>().Where(s => s.Id == sourceStock.Id).ExecuteCommandAsync() <= 0) |
| | | return content.Error("删除源托盘库存失败"); |
| | | } |
| | | |
| | | return content.OK("换盘成功"); |
| | | }); |
| | |
| | | |
| | | if (await StockInfo_HtyService.Repository.AddDataAsync(CreateStockHistory(new[] { sourceStock }, "拆盘")) <= 0) |
| | | return content.Error("拆盘历史记录保存失败"); |
| | | |
| | | // 删除已拆出的库存明细 |
| | | var detailIds = detailEntities.Select(d => d.Id).ToList(); |
| | | if (await StockInfoDetailService.Repository.Db.Deleteable<Dt_StockInfoDetail>().In(detailIds).ExecuteCommandAsync() <= 0) |
| | | return content.Error("删除库存明细失败"); |
| | | |
| | | // 检查源托盘是否还有剩余库存明细,若无则删除源托盘库存头 |
| | | var remainingSourceDetails = StockInfoDetailService.Repository.QueryData(d => d.StockId == sourceStock.Id); |
| | | if (!remainingSourceDetails.Any()) |
| | | { |
| | | if (await StockInfoService.Repository.Db.Deleteable<Dt_StockInfo>().Where(s => s.Id == sourceStock.Id).ExecuteCommandAsync() <= 0) |
| | | return content.Error("删除源托盘库存失败"); |
| | | } |
| | | |
| | | return content.OK("拆盘成功"); |
| | | }); |
| | |
| | | return ( |
| | | result?.Data?.IsSuccess ?? false, |
| | | System.Text.Json.JsonSerializer.Serialize(result), |
| | | result?.Data?.Msg ?? result?.ErrorMessage ?? "未知错误" |
| | | result?.Data?.Msg ?? result?.ErrorMessage ?? "未知错误", |
| | | _mesService.BuildConfig(token ?? string.Empty).ToJson() |
| | | ); |
| | | }); |
| | | |
| | |
| | | return ( |
| | | result?.Data?.IsSuccess ?? false, |
| | | System.Text.Json.JsonSerializer.Serialize(result), |
| | | result?.Data?.Msg ?? result?.ErrorMessage ?? "未知错误" |
| | | result?.Data?.Msg ?? result?.ErrorMessage ?? "未知错误", |
| | | _mesService.BuildConfig(token ?? string.Empty).ToJson() |
| | | ); |
| | | }); |
| | | |
| | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 根据托盘号查询库存明细数量 |
| | | /// </summary> |
| | | /// <param name="palletCode">托盘号</param> |
| | | /// <returns>库存明细数量</returns> |
| | | public async Task<WebResponseContent> GetStockDetailCountByPalletCodeAsync(string palletCode) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | if (string.IsNullOrWhiteSpace(palletCode)) |
| | | return content.Error("托盘号不能为空"); |
| | | |
| | | var stockInfo = StockInfoService.Repository.QueryFirst(s => s.PalletCode == palletCode); |
| | | if (stockInfo == null) |
| | | return content.Error("托盘不存在"); |
| | | |
| | | var count = await StockInfoDetailService.Repository.Db.Queryable<Dt_StockInfoDetail>() |
| | | .CountAsync(d => d.StockId == stockInfo.Id); |
| | | return content.OK("查询成功", new { PalletCode = palletCode, DetailCount = count }); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 根据设备名称和托盘号解析MES设备配置 |
| | | /// </summary> |
| | | /// <param name="deviceName">设备名称</param> |