| | |
| | | using Microsoft.AspNetCore.Http; |
| | | using Microsoft.AspNetCore.Mvc; |
| | | using Microsoft.AspNetCore.Mvc; |
| | | using WIDESEA_Common.Constants; |
| | | using WIDESEA_Common.StockEnum; |
| | | using WIDESEA_Core; |
| | | using WIDESEA_Core.BaseController; |
| | | using WIDESEA_DTO.MES; |
| | | using WIDESEA_IStockService; |
| | | using WIDESEA_IBasicService; |
| | | using WIDESEA_IStockService; |
| | | using WIDESEA_ISystemService; |
| | | using WIDESEA_Model.Models; |
| | | using WIDESEA_Common.Constants; |
| | | using WIDESEA_Common.StockEnum; |
| | | using System.Diagnostics; |
| | | |
| | | namespace WIDESEA_WMSServer.Controllers.Stock |
| | | { |
| | |
| | | [ApiController] |
| | | public class StockInfoDetailController : ApiBaseController<IStockInfoDetailService, Dt_StockInfoDetail> |
| | | { |
| | | private readonly IMesLogService _mesLogService; |
| | | private readonly IMesService _mesService; |
| | | private readonly ISys_DictionaryService _sysDictionaryService; |
| | | private readonly IStockInfoService _stockInfoService; |
| | | private readonly IMESDeviceConfigService _mesDeviceConfigService; |
| | | private readonly IMesUploadHelper _mesUploadHelper; |
| | | |
| | | public StockInfoDetailController( |
| | | IStockInfoDetailService service, |
| | | IMesLogService mesLogService, |
| | | IMesService mesService, |
| | | ISys_DictionaryService sysDictionaryService, |
| | | IStockInfoService stockInfoService, |
| | | IMESDeviceConfigService mesDeviceConfigService) : base(service) |
| | | IMESDeviceConfigService mesDeviceConfigService, |
| | | IMesUploadHelper mesUploadHelper) : base(service) |
| | | { |
| | | _mesLogService = mesLogService; |
| | | _mesService = mesService; |
| | | _sysDictionaryService = sysDictionaryService; |
| | | _stockInfoService = stockInfoService; |
| | | _mesDeviceConfigService = mesDeviceConfigService; |
| | | _mesUploadHelper = mesUploadHelper; |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | |
| | | try |
| | | { |
| | | // 1. 参数验证 |
| | | if (dto.SfcList == null || !dto.SfcList.Any()) |
| | | { |
| | | return response.Error("电芯码列表不能为空"); |
| | | } |
| | | //// 1. 参数验证 |
| | | //if (dto.SfcList == null || !dto.SfcList.Any()) |
| | | //{ |
| | | // return response.Error("电芯码列表不能为空"); |
| | | //} |
| | | |
| | | // 2. 验证电芯状态(非'已锁定'状态允许绑定) |
| | | var stockDetail = await Service.Repository.QueryFirstAsync(x => dto.SfcList.Contains(x.SerialNumber)); |
| | | if (stockDetail != null && stockDetail.Status == 99) |
| | | { |
| | | return response.Error("当前库存明细包含已锁定状态,不允许执行绑定操作"); |
| | | } |
| | | var stockInfo = await _stockInfoService.Repository.QueryFirstAsync(x => stockDetail.StockId == x.Id); |
| | | //var stockDetail = await Service.Repository.QueryFirstAsync(x => dto.SfcList.Contains(x.SerialNumber)); |
| | | //if (stockDetail != null && stockDetail.Status == 99) |
| | | //{ |
| | | // return response.Error("当前库存明细包含已锁定状态,不允许执行绑定操作"); |
| | | //} |
| | | var stockInfo = await _stockInfoService.Repository.QueryDataNavFirstAsync(x => x.PalletCode == dto.PalletCode); |
| | | |
| | | // 3. 动态获取MES凭证 |
| | | var mesConfig = _mesDeviceConfigService.GetByDeviceName("组盘机械手"); |
| | |
| | | ResourceCode = resourceCode, |
| | | LocalTime = DateTime.Now, |
| | | ContainerCode = stockInfo.PalletCode, |
| | | ContainerSfcList = dto.SfcList.Select(sfc => new ContainerSfcItem |
| | | ContainerSfcList = stockInfo.Details.Select(sfc => new ContainerSfcItem |
| | | { |
| | | Sfc = sfc, |
| | | Location = dto.Location ?? "" |
| | | Sfc = sfc.SerialNumber, |
| | | Location = sfc.InboundOrderRowNo.ToString() ?? "" |
| | | }).ToList(), |
| | | OperationType = dto.OperationType |
| | | }; |
| | |
| | | string requestJson = System.Text.Json.JsonSerializer.Serialize(mesRequest); |
| | | |
| | | // 5. 异步调用MES接口(fire-and-forget) |
| | | var localToken = token; |
| | | _ = Task.Run(async () => |
| | | { |
| | | var localStopwatch = Stopwatch.StartNew(); |
| | | try |
| | | _mesUploadHelper.FireAndForget( |
| | | stockInfo.PalletCode, |
| | | MesUploadStatusEnum.组盘上传成功, |
| | | "BindContainer", |
| | | requestJson, |
| | | () => |
| | | { |
| | | var result = string.IsNullOrWhiteSpace(localToken) |
| | | var result = string.IsNullOrWhiteSpace(token) |
| | | ? _mesService.BindContainer(mesRequest) |
| | | : _mesService.BindContainer(mesRequest, localToken); |
| | | localStopwatch.Stop(); |
| | | |
| | | bool isSuccess = result?.IsSuccess ?? false; |
| | | int status = isSuccess |
| | | ? (int)MesUploadStatusEnum.组盘上传成功 |
| | | : (int)MesUploadStatusEnum.组盘上传失败; |
| | | |
| | | await _stockInfoService.UpdateMesUploadStatusAsync(stockInfo.PalletCode, status); |
| | | |
| | | await _mesLogService.LogAsync(new MesApiLogDto |
| | | { |
| | | PalletCode = stockInfo.PalletCode, |
| | | ApiType = "BindContainer", |
| | | RequestJson = requestJson, |
| | | ResponseJson = System.Text.Json.JsonSerializer.Serialize(result), |
| | | IsSuccess = isSuccess, |
| | | ErrorMessage = result?.ErrorMessage ?? "未知错误", |
| | | ElapsedMs = (int)localStopwatch.ElapsedMilliseconds, |
| | | Creator = App.User.UserName |
| | | }); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | localStopwatch.Stop(); |
| | | await _stockInfoService.UpdateMesUploadStatusAsync(stockInfo.PalletCode, (int)MesUploadStatusEnum.组盘上传失败); |
| | | await _mesLogService.LogAsync(new MesApiLogDto |
| | | { |
| | | PalletCode = stockInfo.PalletCode, |
| | | ApiType = "BindContainer", |
| | | IsSuccess = false, |
| | | ErrorMessage = ex.Message, |
| | | ElapsedMs = (int)localStopwatch.ElapsedMilliseconds, |
| | | Creator = App.User.UserName |
| | | }); |
| | | } |
| | | }); |
| | | : _mesService.BindContainer(mesRequest, token); |
| | | return ( |
| | | result?.Data?.IsSuccess ?? false, |
| | | System.Text.Json.JsonSerializer.Serialize(result), |
| | | result?.Data?.Msg ?? result?.ErrorMessage ?? "未知错误" |
| | | ); |
| | | }, |
| | | App.User.UserName); |
| | | |
| | | // 6. 立即返回成功响应 |
| | | return response.OK("托盘电芯绑定成功"); |
| | |
| | | try |
| | | { |
| | | // 1. 参数验证 |
| | | if (dto.SfcList == null || !dto.SfcList.Any()) |
| | | { |
| | | return response.Error("电芯码列表不能为空"); |
| | | } |
| | | //if (dto.SfcList == null || !dto.SfcList.Any()) |
| | | //{ |
| | | // return response.Error("电芯码列表不能为空"); |
| | | //} |
| | | |
| | | // 2. 验证电芯状态(非'已锁定'状态允许解绑) |
| | | var stockDetail = await Service.Repository.QueryFirstAsync(x => dto.SfcList.Contains(x.SerialNumber)); |
| | | if (stockDetail != null && stockDetail.Status == 99) |
| | | { |
| | | return response.Error("当前库存明细包含已锁定状态,不允许执行解绑操作"); |
| | | } |
| | | var stockInfo = await _stockInfoService.Repository.QueryFirstAsync(x => stockDetail.StockId == x.Id); |
| | | //// 2. 验证电芯状态(非'已锁定'状态允许解绑) |
| | | //var stockDetail = await Service.Repository.QueryFirstAsync(x => dto.SfcList.Contains(x.SerialNumber)); |
| | | //if (stockDetail != null && stockDetail.Status == 99) |
| | | //{ |
| | | // return response.Error("当前库存明细包含已锁定状态,不允许执行解绑操作"); |
| | | //} |
| | | var stockInfo = await _stockInfoService.Repository.QueryDataNavFirstAsync(x => dto.PalletCode == x.PalletCode); |
| | | |
| | | // 3. 动态获取MES凭证 |
| | | var mesConfig = _mesDeviceConfigService.GetByDeviceName("组盘机械手"); |
| | |
| | | ResourceCode = resourceCode, |
| | | LocalTime = DateTime.Now, |
| | | ContainCode = stockInfo.PalletCode, |
| | | SfcList = dto.SfcList |
| | | SfcList = stockInfo.Details.Select(x => x.SerialNumber).ToList(), |
| | | }; |
| | | |
| | | string requestJson = System.Text.Json.JsonSerializer.Serialize(mesRequest); |
| | | |
| | | // 5. 异步调用MES接口(fire-and-forget) |
| | | var localToken = token; |
| | | _ = Task.Run(async () => |
| | | { |
| | | var localStopwatch = Stopwatch.StartNew(); |
| | | try |
| | | _mesUploadHelper.FireAndForget( |
| | | stockInfo.PalletCode, |
| | | MesUploadStatusEnum.拆盘上传成功, |
| | | "UnbindContainer", |
| | | requestJson, |
| | | () => |
| | | { |
| | | var result = string.IsNullOrWhiteSpace(localToken) |
| | | var result = string.IsNullOrWhiteSpace(token) |
| | | ? _mesService.UnBindContainer(mesRequest) |
| | | : _mesService.UnBindContainer(mesRequest, localToken); |
| | | localStopwatch.Stop(); |
| | | |
| | | bool isSuccess = result?.IsSuccess ?? false; |
| | | int status = isSuccess |
| | | ? (int)MesUploadStatusEnum.拆盘上传成功 |
| | | : (int)MesUploadStatusEnum.拆盘上传失败; |
| | | |
| | | await _stockInfoService.UpdateMesUploadStatusAsync(stockInfo.PalletCode, status); |
| | | |
| | | await _mesLogService.LogAsync(new MesApiLogDto |
| | | { |
| | | PalletCode = stockInfo.PalletCode, |
| | | ApiType = "UnbindContainer", |
| | | RequestJson = requestJson, |
| | | ResponseJson = System.Text.Json.JsonSerializer.Serialize(result), |
| | | IsSuccess = isSuccess, |
| | | ErrorMessage = result?.ErrorMessage ?? "未知错误", |
| | | ElapsedMs = (int)localStopwatch.ElapsedMilliseconds, |
| | | Creator = App.User.UserName |
| | | }); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | localStopwatch.Stop(); |
| | | await _stockInfoService.UpdateMesUploadStatusAsync(stockInfo.PalletCode, (int)MesUploadStatusEnum.拆盘上传失败); |
| | | await _mesLogService.LogAsync(new MesApiLogDto |
| | | { |
| | | PalletCode = stockInfo.PalletCode, |
| | | ApiType = "UnbindContainer", |
| | | IsSuccess = false, |
| | | ErrorMessage = ex.Message, |
| | | ElapsedMs = (int)localStopwatch.ElapsedMilliseconds, |
| | | Creator = App.User.UserName |
| | | }); |
| | | } |
| | | }); |
| | | : _mesService.UnBindContainer(mesRequest, token); |
| | | return ( |
| | | result?.Data?.IsSuccess ?? false, |
| | | System.Text.Json.JsonSerializer.Serialize(result), |
| | | result?.Data?.Msg ?? result?.ErrorMessage ?? "未知错误" |
| | | ); |
| | | }, |
| | | App.User.UserName); |
| | | |
| | | // 6. 立即返回成功响应 |
| | | return response.OK("托盘电芯解绑成功"); |
| | |
| | | string requestJson = System.Text.Json.JsonSerializer.Serialize(mesRequest); |
| | | |
| | | // 5. 异步调用MES接口(fire-and-forget) |
| | | _ = Task.Run(async () => |
| | | { |
| | | var localStopwatch = Stopwatch.StartNew(); |
| | | try |
| | | _mesUploadHelper.FireAndForget( |
| | | stockInfo.PalletCode, |
| | | MesUploadStatusEnum.NG上报成功, |
| | | "ContainerNgReport", |
| | | requestJson, |
| | | () => |
| | | { |
| | | var result = _mesService.ContainerNgReport(mesRequest); |
| | | localStopwatch.Stop(); |
| | | |
| | | bool isSuccess = result?.IsSuccess ?? false; |
| | | int status = isSuccess |
| | | ? (int)MesUploadStatusEnum.NG上报成功 |
| | | : (int)MesUploadStatusEnum.NG上报失败; |
| | | |
| | | await _stockInfoService.UpdateMesUploadStatusAsync(stockInfo.PalletCode, status); |
| | | |
| | | await _mesLogService.LogAsync(new MesApiLogDto |
| | | { |
| | | PalletCode = stockInfo.PalletCode, |
| | | ApiType = "ContainerNgReport", |
| | | RequestJson = requestJson, |
| | | ResponseJson = System.Text.Json.JsonSerializer.Serialize(result), |
| | | IsSuccess = isSuccess, |
| | | ErrorMessage = result?.ErrorMessage ?? "未知错误", |
| | | ElapsedMs = (int)localStopwatch.ElapsedMilliseconds, |
| | | Creator = App.User.UserName |
| | | }); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | localStopwatch.Stop(); |
| | | await _stockInfoService.UpdateMesUploadStatusAsync(stockInfo.PalletCode, (int)MesUploadStatusEnum.NG上报失败); |
| | | await _mesLogService.LogAsync(new MesApiLogDto |
| | | { |
| | | PalletCode = stockInfo.PalletCode, |
| | | ApiType = "ContainerNgReport", |
| | | IsSuccess = false, |
| | | ErrorMessage = ex.Message, |
| | | ElapsedMs = (int)localStopwatch.ElapsedMilliseconds, |
| | | Creator = App.User.UserName |
| | | }); |
| | | } |
| | | }); |
| | | return ( |
| | | result?.IsSuccess ?? false, |
| | | System.Text.Json.JsonSerializer.Serialize(result), |
| | | result?.ErrorMessage ?? "未知错误" |
| | | ); |
| | | }, |
| | | App.User.UserName); |
| | | |
| | | // 6. 立即返回成功响应 |
| | | return response.OK("NG电芯上报成功"); |
| | |
| | | return defaultValue; |
| | | } |
| | | } |
| | | } |
| | | } |