| | |
| | | using SqlSugar; |
| | | using WIDESEA_Common.Constants; |
| | | using WIDESEA_Common.StockEnum; |
| | | using WIDESEA_Core; |
| | | using WIDESEA_DTO.MES; |
| | |
| | | public IStockInfo_HtyService StockInfo_HtyService { get; } |
| | | |
| | | /// <summary> |
| | | /// 仓库服务 |
| | | /// </summary> |
| | | public IWarehouseService _warehouseService { get; } |
| | | |
| | | /// <summary> |
| | | /// Mes接口服务 |
| | | /// </summary> |
| | | public IMesService _mesService { get; } |
| | |
| | | IStockInfoService stockInfoService, |
| | | IStockInfoDetail_HtyService stockInfoDetail_HtyService, |
| | | IStockInfo_HtyService stockInfo_HtyService, |
| | | IMesService mesService) |
| | | IMesService mesService, |
| | | IWarehouseService warehouseService) |
| | | { |
| | | StockInfoDetailService = stockInfoDetailService; |
| | | StockInfoService = stockInfoService; |
| | | StockInfoDetail_HtyService = stockInfoDetail_HtyService; |
| | | StockInfo_HtyService = stockInfo_HtyService; |
| | | _mesService = mesService; |
| | | _warehouseService = warehouseService; |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | var now = DateTime.Now; |
| | | var details = stock.Details.Select(item => new Dt_StockInfoDetail |
| | | { |
| | | MaterielCode = "电芯", |
| | | MaterielName = "电芯", |
| | | MaterielCode = StockConstants.MATERIAL_CODE, |
| | | MaterielName = StockConstants.MATERIAL_NAME, |
| | | StockQuantity = item.Quantity, |
| | | Unit = "PCS", |
| | | Creater = "system", |
| | | OrderNo = "111", |
| | | Unit = StockConstants.UNIT, |
| | | Creater = StockConstants.SYSTEM_USER, |
| | | OrderNo = StockConstants.DEFAULT_ORDER_NO, |
| | | ProductionDate = now.ToString(), |
| | | EffectiveDate = now.AddYears(1).ToString(), |
| | | SerialNumber = item.CellBarcode, |
| | |
| | | var bindRequest = new BindContainerRequest |
| | | { |
| | | ContainerCode = stock?.TargetPalletNo, |
| | | EquipmentCode = "STK-GROUP-001", |
| | | ResourceCode = "STK-GROUP-001", |
| | | EquipmentCode = StockConstants.MES_EQUIPMENT_CODE, |
| | | ResourceCode = StockConstants.MES_RESOURCE_CODE, |
| | | LocalTime = now, |
| | | OperationType = 0, // 0代表组盘 |
| | | OperationType = StockConstants.MES_BIND_OPERATION_TYPE, |
| | | ContainerSfcList = details.Select(d => new ContainerSfcItem |
| | | { |
| | | Sfc = d.SerialNumber, |
| | |
| | | var entity = new Dt_StockInfo |
| | | { |
| | | PalletCode = stock.TargetPalletNo, |
| | | //WarehouseId = stock.WarehouseId > 0 ? stock.WarehouseId : 1, |
| | | WarehouseId = 1, |
| | | WarehouseId = stock.Roadway == "注液组盘机械手" ? (await _warehouseService.Db.Queryable<Dt_Warehouse>().FirstAsync(w => w.WarehouseCode == "GW1")).WarehouseId : 0, |
| | | StockStatus = StockStatusEmun.组盘暂存.GetHashCode(), |
| | | Creater = "system", |
| | | Creater = StockConstants.SYSTEM_USER, |
| | | Details = details |
| | | }; |
| | | result = StockInfoService.Repository.AddData(entity, x => x.Details); |
| | | if (!result) return content.Error("组盘失败"); |
| | | |
| | | var mesResult = _mesService.BindContainer(bindRequest); |
| | | if (mesResult == null || mesResult.Data == null || !mesResult.Data.IsSuccess) |
| | | { |
| | | return content.Error($"组盘成功,但MES绑定失败: {mesResult?.Data?.Msg ?? mesResult?.ErrorMessage ?? "未知错误"}"); |
| | | } |
| | | //var mesResult = _mesService.BindContainer(bindRequest); |
| | | //if (mesResult == null || mesResult.Data == null || !mesResult.Data.IsSuccess) |
| | | //{ |
| | | // return content.Error($"组盘成功,但MES绑定失败: {mesResult?.Data?.Msg ?? mesResult?.ErrorMessage ?? "未知错误"}"); |
| | | //} |
| | | return content.OK("组盘成功"); |
| | | }); |
| | | } |
| | |
| | | PalletCode = stock.TargetPalletNo, |
| | | WarehouseId = sourceStock.WarehouseId, |
| | | StockStatus = StockStatusEmun.组盘暂存.GetHashCode(), |
| | | Creater = "system", |
| | | Creater = StockConstants.SYSTEM_USER, |
| | | }; |
| | | |
| | | var newId = StockInfoService.Repository.AddData(newStock); |
| | |
| | | if (await StockInfo_HtyService.Repository.AddDataAsync(CreateStockHistory(new[] { sourceStock, targetStock }, "换盘")) <= 0) |
| | | return content.Error("换盘历史记录保存失败"); |
| | | |
| | | // 调用MES解绑源托盘电芯 |
| | | var unbindRequest = new UnBindContainerRequest |
| | | { |
| | | EquipmentCode = StockConstants.MES_EQUIPMENT_CODE, |
| | | ResourceCode = StockConstants.MES_RESOURCE_CODE, |
| | | LocalTime = DateTime.Now, |
| | | ContainCode = stock.SourcePalletNo, |
| | | SfcList = detailEntities.Select(d => d.SerialNumber).ToList() |
| | | }; |
| | | var unbindResult = _mesService.UnBindContainer(unbindRequest); |
| | | if (unbindResult == null || unbindResult.Data == null || !unbindResult.Data.IsSuccess) |
| | | { |
| | | return content.Error($"换盘成功,但MES解绑失败: {unbindResult?.Data?.Msg ?? unbindResult?.ErrorMessage ?? "未知错误"}"); |
| | | } |
| | | |
| | | detailEntities.ForEach(d => d.StockId = targetStock.Id); |
| | | var result = await StockInfoDetailService.Repository.UpdateDataAsync(detailEntities); |
| | | if (!result) return content.Error("换盘失败"); |
| | | |
| | | // 调用MES绑定目标托盘电芯 |
| | | var bindRequest = new BindContainerRequest |
| | | { |
| | | ContainerCode = stock.TargetPalletNo, |
| | | EquipmentCode = StockConstants.MES_EQUIPMENT_CODE, |
| | | ResourceCode = StockConstants.MES_RESOURCE_CODE, |
| | | LocalTime = DateTime.Now, |
| | | OperationType = StockConstants.MES_BIND_OPERATION_TYPE, |
| | | ContainerSfcList = detailEntities.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("换盘成功"); |
| | | }); |
| | | } |
| | |
| | | if (await StockInfo_HtyService.Repository.AddDataAsync(CreateStockHistory(new[] { sourceStock }, "拆盘")) <= 0) |
| | | return content.Error("拆盘历史记录保存失败"); |
| | | |
| | | // 调用MES解绑电芯 |
| | | var unbindRequest = new UnBindContainerRequest |
| | | { |
| | | EquipmentCode = StockConstants.MES_EQUIPMENT_CODE, |
| | | ResourceCode = StockConstants.MES_RESOURCE_CODE, |
| | | LocalTime = DateTime.Now, |
| | | ContainCode = stock.SourcePalletNo, |
| | | SfcList = detailEntities.Select(d => d.SerialNumber).ToList() |
| | | }; |
| | | var unbindResult = _mesService.UnBindContainer(unbindRequest); |
| | | if (unbindResult == null || unbindResult.Data == null || !unbindResult.Data.IsSuccess) |
| | | { |
| | | return content.Error($"拆盘成功,但MES解绑失败: {unbindResult?.Data?.Msg ?? unbindResult?.ErrorMessage ?? "未知错误"}"); |
| | | } |
| | | |
| | | var result = await StockInfoDetailService.Repository.DeleteDataAsync(detailEntities); |
| | | if (!result) return content.Error("拆盘失败"); |
| | | return content.OK("拆盘成功"); |