From 06e0e3b7d61e95902a6129de2490461cd0693e1d Mon Sep 17 00:00:00 2001
From: huangxiaoqiang <huangxiaoqiang@hnkhzn.com>
Date: 星期三, 15 十月 2025 15:06:40 +0800
Subject: [PATCH] 新增异步方法并优化服务调用逻辑在多个数据库文件中进行了二进制文件的修改、删除和新增操作,可能涉及数据库内容的更新或重建。在 HttpsClient.cs文件中新增了 PostNotLimitAsync方法,用于发送支持 JSON 格式的异步 HTTP POST 请求,并记录请求和响应参数。在 AgingInOrOutInputService.cs文件中,将 HttpsClient.PostAsync替换为PostNotLimitAsync,以利用新方法的功能特性。同时删除了不再需要的注释代码。
---
Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StoragIntegrationServices/MOM/ProcessApply/ProcessApplyService.cs | 274 ++++++++++++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 263 insertions(+), 11 deletions(-)
diff --git a/Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StoragIntegrationServices/MOM/ProcessApply/ProcessApplyService.cs b/Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StoragIntegrationServices/MOM/ProcessApply/ProcessApplyService.cs
index de39802..78df137 100644
--- a/Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StoragIntegrationServices/MOM/ProcessApply/ProcessApplyService.cs
+++ b/Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StoragIntegrationServices/MOM/ProcessApply/ProcessApplyService.cs
@@ -1,41 +1,293 @@
锘縰sing LogLibrary.Log;
using Masuit.Tools;
+using Newtonsoft.Json;
using WIDESEA_Common;
+using WIDESEA_Core;
+using WIDESEA_Core.Const;
+using WIDESEA_Core.Helper;
using WIDESEA_DTO;
+using WIDESEA_DTO.MOM;
+using WIDESEA_IBusinessesRepository;
+using WIDESEA_IServices;
+using WIDESEA_IStorageBasicRepository;
+using WIDESEA_IStorageTaskRepository;
using WIDESEA_IStoragIntegrationServices;
+using WIDESEA_Model.Models;
namespace WIDESEA_StoragIntegrationServices;
public class ProcessApplyService : IProcessApplyService
{
private readonly LogFactory LogFactory = new LogFactory();
+ private readonly ISys_ConfigService _configService;
+ private readonly IDt_AreaInfoRepository _areaInfoRepository;
+ private readonly ICellStateService _cellStateService;
+ private readonly IStockInfoRepository _stockInfoRepository;
+ private readonly IAgingInOrOutInputService _gingInOrOutInputService;
+
+ public ProcessApplyService(ISys_ConfigService configRepository, IDt_AreaInfoRepository areaInfoRepository, ICellStateService cellStateService, IDt_TaskRepository taskRepository, IStockInfoRepository stockInfoRepository, IAgingInOrOutInputService gingInOrOutInputService)
+ {
+ _configService = configRepository;
+ _areaInfoRepository = areaInfoRepository;
+ _cellStateService = cellStateService;
+ _stockInfoRepository = stockInfoRepository;
+ _gingInOrOutInputService = gingInOrOutInputService;
+ }
/// <summary>
/// 宸ヨ壓璺嚎鐢宠
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
- public async Task<dynamic> ProcessApplyAsync(ProcessApplyDto input)
+ public async Task<WebResponseContent> GetProcessApplyAsync(ProcessApplyDto input)
{
- // TODO: Implement the logic to process the apply request
+ WebResponseContent content = new WebResponseContent();
try
{
input.SessionId = Guid.NewGuid().ToString();
- input.Software = "闄堝寲鏈�";
- input.EquipmentCode = "P1K10040";
- input.EmployeeNo = "T00001";
- input.RequestTime = DateTime.UtcNow.ToString();
- var inputIson = input.ToDictionary();
- var x = await HttpsClient.PostAsync("http://ts-momapp01:12020/", inputIson);
+ input.EmployeeNo = "MITest";
+ input.RequestTime = TimeZoneInfo.ConvertTimeToUtc(DateTime.Now).ToString("yyyy-MM-ddTHH:mm:ss.fffZ");
+ var inputJson = Masuit.Tools.ObjectExtensions.ToDictionary(input);
+ var configs = _configService.GetConfigsByCategory(CateGoryConst.SYS_MOMIPAddress);
+ var wmsBase = configs.FirstOrDefault(x => x.ConfigKey == SysConfigConst.MOMBaseIP)?.ConfigValue;
+ var ipAddress = configs.FirstOrDefault(x => x.ConfigKey == SysConfigConst.ProcessApply)?.ConfigValue;
+ if (wmsBase == null || ipAddress == null)
+ {
+ throw new InvalidOperationException("WMS IP 鏈厤缃�");
+ }
+ var wmsIpAddress = wmsBase + ipAddress;
+
+ var result = HttpsClient.PostAsync(wmsIpAddress, inputJson).Result;
+
+ if (result != null)
+ {
+ content.OK(data: result);
+
+ //var respone = JsonConvert.DeserializeObject<ResultProcessApply>(result.ToString());
+ //if (!respone.Success)
+ //{
+ // MoMErrorMsg.AddMoMErrorMsg(0, input.WipOrderNo, respone.MOMMessage, SysConfigConst.TrayCellsStatus);
+ //}
+ //else
+ //{
+ // MoMErrorMsg.DeleteMoMErrorMsg(0, input.WipOrderNo);
+ //}
+ }
LogFactory.GetLog("宸ヨ壓璺嚎鐢宠").Info(true, $"\r\r--------------------------------------");
- LogFactory.GetLog("宸ヨ壓璺嚎鐢宠").Info(true, x);
+ LogFactory.GetLog("宸ヨ壓璺嚎鐢宠").Info(true, result);
}
catch (Exception ex)
{
- Console.WriteLine(ex.Message);
+ //Console.WriteLine(ex.Message);
LogFactory.GetLog("宸ヨ壓璺嚎鐢宠").Error(true, $"\r\r--------------------------------------");
LogFactory.GetLog("宸ヨ壓璺嚎鐢宠").Error(true, ex.StackTrace);
}
- return Task.FromResult<dynamic>(null);
+ return content;
+ }
+
+ /// <summary>
+ /// 琛ュ綍鍑哄簱鏁版嵁
+ /// </summary>
+ /// <param name="palletCode"></param>
+ /// <returns></returns>
+ public async Task<WebResponseContent> StockOutDataBackfillInterfaceAsync(string palletCode, int areaID)
+ {
+ WebResponseContent content = new WebResponseContent();
+ try
+ {
+ var area = _areaInfoRepository.QueryFirst(x => x.AreaID == areaID);
+ var trayCells = new TrayCellsStatusDto()
+ {
+ Software = area.Spare3,
+ TrayBarcode = palletCode,
+ EquipmentCode = area.Spare2,
+ SceneType = area.Spare4
+ };
+ content = await _cellStateService.GetTrayCellStatusAsync(trayCells);
+ if (!content.Status) return content;
+
+ var result = JsonConvert.DeserializeObject<ResultTrayCellsStatus>(content.Data.ToString());
+ if (result.SerialNos.Count > 0)
+ {
+ var stock = await SqlSugarHelper.DbWMS.Queryable<DtStockInfo>().FirstAsync(x => x.PalletCode == palletCode);
+ if (stock != null)
+ {
+ var parameterInfo = JsonConvert.DeserializeObject<List<ParameterInfo>>(stock.ParameterInfos).FirstOrDefault(y => y.Description.Contains("鏃堕棿"));
+ if (parameterInfo == null) throw new Exception("");
+
+ var outHours = (DateTime.Now - (stock.LinedProcessFeedbackTime == null ? stock.ModifyDate.Value : stock.LinedProcessFeedbackTime.ToDateTime())).TotalHours;
+ var isNG = outHours > parameterInfo.LowerSpecificationsLimit.ToDouble() && outHours < parameterInfo.UpperSpecificationsLimit.ToDouble();
+
+ var defectCode = string.Empty;
+ if (!isNG) defectCode = "TQCK";
+ var outputDto = new AgingOutputDto
+ {
+ OpFlag = 1,
+ Software = area.Spare3,
+ EquipmentCode = area.Spare2,
+ TrayBarcode = palletCode,
+ SerialNos = result.SerialNos.Select(x => new SerialNoOutDto
+ {
+ SlotNo = x.PositionNo,
+ SerialNo = x.SerialNo,
+ SerialNoResult = true, //isNG,
+ ParameterInfo = new List<ParameterInfoOutput> {
+ new ParameterInfoOutput() {
+ Value = outHours.ToString(),
+ ParameterCode =parameterInfo.ParameterCode,
+ ParameterDesc = parameterInfo.Description,
+ ParameterResult = "OK", //isNG.ToString(),
+ TargetValue = parameterInfo.TargetValue,
+ LowerLimit = parameterInfo.LowerSpecificationsLimit,
+ UpperLimit = parameterInfo.UpperSpecificationsLimit,
+ DefectCode = defectCode,
+ UOMCode = parameterInfo.UOMCode,
+ }
+ }
+ }).ToList()
+ };
+ content = await _gingInOrOutInputService.GetOCVOutputAsync(outputDto);
+ }
+ else
+ {
+ var stockHty = await SqlSugarHelper.DbWMS.Queryable<DtStockInfo_Hty>().Where(x => x.PalletCode == palletCode).OrderByDescending(x => x.CreateDate).FirstAsync();
+ if (stockHty != null)
+ {
+ var parameterInfo = JsonConvert.DeserializeObject<List<ParameterInfo>>(stockHty.ParameterInfos).FirstOrDefault(y => y.Description.Contains("鏃堕棿"));
+ if (parameterInfo == null) throw new Exception("");
+
+ var outHours = (DateTime.Now - (stockHty.LinedProcessFeedbackTime == null ? "2025-01-08 15:59:34.310".ToDateTime() : stockHty.LinedProcessFeedbackTime.ToDateTime())).TotalHours;
+ var isNG = outHours > parameterInfo.LowerSpecificationsLimit.ToDouble() && outHours < parameterInfo.UpperSpecificationsLimit.ToDouble();
+
+ var defectCode = string.Empty;
+ if (!isNG) defectCode = "TQCK";
+ var outputDto = new AgingOutputDto
+ {
+ OpFlag = 1,
+ Software = area.Spare3,
+ EquipmentCode = area.Spare2,
+ TrayBarcode = palletCode,
+ SerialNos = result.SerialNos.Select(x => new SerialNoOutDto
+ {
+ SlotNo = x.PositionNo,
+ SerialNo = x.SerialNo,
+ SerialNoResult = true, //isNG,
+ ParameterInfo = new List<ParameterInfoOutput> {
+ new ParameterInfoOutput() {
+ Value = outHours.ToString(),
+ ParameterCode =parameterInfo.ParameterCode,
+ ParameterDesc = parameterInfo.Description,
+ ParameterResult = "OK", //isNG.ToString(),
+ TargetValue = parameterInfo.TargetValue,
+ LowerLimit = parameterInfo.LowerSpecificationsLimit,
+ UpperLimit = parameterInfo.UpperSpecificationsLimit,
+ DefectCode = defectCode,
+ UOMCode = parameterInfo.UOMCode,
+ }
+ }
+ }).ToList()
+ };
+ content = await _gingInOrOutInputService.GetOCVOutputAsync(outputDto);
+ }
+ else
+ {
+ content.Error("鏉�鏉�鏉�");
+ }
+ }
+ }
+ else
+ {
+ content.Error("鐢佃姱鏁版嵁涓虹┖");
+ }
+ }
+ catch (Exception ex)
+ {
+ }
+ return content;
+ }
+
+ /// <summary>
+ /// 琛ュ綍鍏ュ簱鏁版嵁
+ /// </summary>
+ /// <param name="palletCode"></param>
+ /// <param name="areaID"></param>
+ /// <returns></returns>
+ public async Task<WebResponseContent> StockInDataBackfillInterfaceAsync(string palletCode, int areaID)
+ {
+ WebResponseContent content = new WebResponseContent();
+ try
+ {
+ var area = _areaInfoRepository.QueryFirst(x => x.AreaID == areaID);
+ var trayCells = new TrayCellsStatusDto()
+ {
+ Software = area.Spare3,
+ TrayBarcode = palletCode,
+ EquipmentCode = area.Spare2,
+ SceneType = area.Spare4
+ };
+ content = await _cellStateService.GetTrayCellStatusAsync(trayCells);
+ if (!content.Status) return content;
+
+ var result = JsonConvert.DeserializeObject<ResultTrayCellsStatus>(content.Data.ToString());
+ if (result.SerialNos.Count > 0 && result.Success)
+ {
+ var stockInfo = await _stockInfoRepository.QueryFirstNavAsync(x => x.PalletCode == palletCode);
+ if (stockInfo != null)
+ {
+ stockInfo.IsFull = true;
+ stockInfo.StockInfoDetails = result.SerialNos.Select(serialNoObj => new DtStockInfoDetail
+ {
+ SerialNumber = serialNoObj.SerialNo,
+ OrderNo = serialNoObj.PositionNo.ToString(),
+ Status = serialNoObj.SerialNoStatus,
+ MaterielCode = result.BindCode,
+ Remark = result.TrayBarcodePropertys.ToJsonString(),
+ }).ToList();
+ stockInfo.Remark = stockInfo.StockInfoDetails.Count().ToString();
+
+ // 澶勭悊璇锋眰鍙傛暟
+ AgingInputDto agingInputDto = new AgingInputDto()
+ {
+ SerialNos = stockInfo.StockInfoDetails
+ .Select(item => new SerialNoInDto { SerialNo = item.SerialNumber, PositionNo = item.OrderNo })
+ .ToList(),
+ TrayBarcode = palletCode,
+ OpFlag = 1,
+ EquipmentCode = area.Spare2,
+ Software = area.Spare3
+ };
+
+ content = _gingInOrOutInputService.GetOCVInputAsync(agingInputDto).Result;
+ var respone = JsonConvert.DeserializeObject<ResponeAgingInputDto>(content.Data.ToString());
+
+ stockInfo.LinedProcessFeedbackTime = respone.LinedProcessFeedbackTime;
+ stockInfo.SpecialParameterDuration = respone.SpecialParameterDuration;
+ //2024骞�11鏈�16鏃ワ細鏂板瀛楁璁$畻搴斿嚭搴撴椂闂�
+ stockInfo.OutboundTime = Convert.ToDateTime(respone.LinedProcessFeedbackTime == null ? DateTime.Now : respone.LinedProcessFeedbackTime).AddHours(Convert.ToDouble(respone.SpecialParameterDuration));
+ stockInfo.ProductionLine = respone.ProductionLine;
+ stockInfo.ParameterInfos = respone.ParameterInfos.ToJsonString();
+ stockInfo.StockStatus = 1;
+
+ var isResult = await _stockInfoRepository.UpdateDataNavAsync(stockInfo);
+ if (isResult)
+ content.OK("鏇存柊鏁版嵁鎴愬姛");
+ else
+ content.Error("鏇存柊鏁版嵁澶辫触");
+ }
+ else
+ {
+ content.Error("鏈壘鍒板簱瀛�");
+ }
+ }
+ else
+ {
+ return content;
+ }
+ }
+ catch (Exception ex)
+ {
+ content.Error(ex.Message);
+ }
+ return content;
}
}
\ No newline at end of file
--
Gitblit v1.9.3