From 544014da344afc67f1671cdc38f4f732890e10c8 Mon Sep 17 00:00:00 2001
From: huangxiaoqiang <huangxiaoqiang@hnkhzn.com>
Date: 星期四, 25 十二月 2025 09:35:30 +0800
Subject: [PATCH] 1
---
项目代码/WMS无仓储版/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs | 178 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 170 insertions(+), 8 deletions(-)
diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs"
index a1ea0b2..b5af0e3 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs"
@@ -21,6 +21,7 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
+using Newtonsoft.Json.Serialization;
using Org.BouncyCastle.Asn1.Ocsp;
using Org.BouncyCastle.Asn1.Pkcs;
using SqlSugar;
@@ -43,6 +44,7 @@
using WIDESEA_Core.Helper;
using WIDESEA_Core.Util;
using WIDESEA_DTO.Allocate;
+using WIDESEA_DTO.Base;
using WIDESEA_DTO.Basic;
using WIDESEA_DTO.Inbound;
using WIDESEA_DTO.Outbound;
@@ -91,6 +93,7 @@
private readonly IRepository<Dt_AllocateMaterialInfo> _allocateMaterialInfo;
private readonly IRepository<Dt_AllocateMaterialInfo_Hty> _allocateMaterialInfo_Hty;
private readonly HttpClientHelper _httpClientHelper;
+ private readonly IBasicService _basicService;
public IRepository<Dt_Task> Repository => BaseDal;
private Dictionary<string, SqlSugar.OrderByType> _taskOrderBy = new()
@@ -110,7 +113,7 @@
public List<int> TaskOutboundTypes => typeof(TaskTypeEnum).GetEnumIndexList();
- public TaskService(IRepository<Dt_Task> BaseDal, IMapper mapper, IUnitOfWorkManage unitOfWorkManage, IRepository<Dt_StockInfo> stockRepository, ILocationInfoService locationInfoService, IInboundOrderService inboundOrderService, ILocationStatusChangeRecordService locationStatusChangeRecordService, IESSApiService eSSApiService, ILogger<TaskService> logger, IStockService stockService, IRecordService recordService, IInboundOrderDetailService inboundOrderDetailService, IOutboundOrderService outboundOrderService, IOutboundOrderDetailService outboundOrderDetailService, IInvokeMESService invokeMESService, IOutStockLockInfoService outStockLockInfoService, IAllocateService allocateService, IRepository<Dt_OutboundBatch> outboundBatchRepository, IRepository<Dt_ReCheckOrder> reCheckOrderRepository, IRepository<Dt_AllocateOrderDetail> allocateOrderDetailRepository, IRepository<Dt_AllocateOrder> allocateOrderRepository, IMaterialUnitService materialUnitService, ITask_HtyService task_HtyService, IRepository<Dt_AllocateMaterialInfo> allocateMaterialInfo, IRepository<Dt_AllocateMaterialInfo_Hty> allocateMaterialInfo_Hty, HttpClientHelper httpClientHelper) : base(BaseDal)
+ public TaskService(IRepository<Dt_Task> BaseDal, IMapper mapper, IUnitOfWorkManage unitOfWorkManage, IRepository<Dt_StockInfo> stockRepository, ILocationInfoService locationInfoService, IInboundOrderService inboundOrderService, ILocationStatusChangeRecordService locationStatusChangeRecordService, IESSApiService eSSApiService, ILogger<TaskService> logger, IStockService stockService, IRecordService recordService, IInboundOrderDetailService inboundOrderDetailService, IOutboundOrderService outboundOrderService, IOutboundOrderDetailService outboundOrderDetailService, IInvokeMESService invokeMESService, IOutStockLockInfoService outStockLockInfoService, IAllocateService allocateService, IRepository<Dt_OutboundBatch> outboundBatchRepository, IRepository<Dt_ReCheckOrder> reCheckOrderRepository, IRepository<Dt_AllocateOrderDetail> allocateOrderDetailRepository, IRepository<Dt_AllocateOrder> allocateOrderRepository, IMaterialUnitService materialUnitService, ITask_HtyService task_HtyService, IRepository<Dt_AllocateMaterialInfo> allocateMaterialInfo, IRepository<Dt_AllocateMaterialInfo_Hty> allocateMaterialInfo_Hty, HttpClientHelper httpClientHelper, IBasicService basicService) : base(BaseDal)
{
_mapper = mapper;
_unitOfWorkManage = unitOfWorkManage;
@@ -137,6 +140,7 @@
_allocateMaterialInfo = allocateMaterialInfo;
_allocateMaterialInfo_Hty = allocateMaterialInfo_Hty;
_httpClientHelper = httpClientHelper;
+ _basicService = basicService;
}
public async Task TaskStatusChange(string taskNum, TaskStatusEnum taskStatusEnum)
@@ -362,7 +366,7 @@
//var feedbackresult = await _invokeMESService.FeedbackAllocate(allocatefeedmodel);
- var response = responseModel(inboundOrder, 3, "http://127.0.0.1:450/api/AldAllocationOperation/AllocationOperation", null, allocatefeedmodel);
+ var response = responseModel(inboundOrder, 3, null, allocatefeedmodel);
if (response != null && response.IsSuccess)
{
_inboundOrderService.Db.Updateable<Dt_InboundOrder>().SetColumns(it => new Dt_InboundOrder { ReturnToMESStatus = 1 })
@@ -468,7 +472,7 @@
//var feedbackresult = await _invokeMESService.FeedbackInbound(feedmodel);
- var response= responseModel(inboundOrder,2, "http://127.0.0.1:450/api/AldMaterialWarehousing/MaterialWarehousing", feedmodel);
+ var response= responseModel(inboundOrder,2, feedmodel);
if (response != null && response.IsSuccess)
{
@@ -497,24 +501,24 @@
return WebResponseContent.Instance.OK();
}
- public HttpResponseResult<MesResponseDTO> responseModel(Dt_InboundOrder order, int InterfaceType, string url, FeedbackInboundRequestModel model = null, AllocateDto allocateDto = null)
+ public HttpResponseResult<MesResponseDTO> responseModel(Dt_InboundOrder order, int InterfaceType, FeedbackInboundRequestModel model = null, AllocateDto allocateDto = null)
{
HttpResponseResult<MesResponseDTO> httpResponseResult = new HttpResponseResult<MesResponseDTO>();
string reqCode = Guid.NewGuid().ToString();
string reqTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
string requestData = string.Empty;
- //string apiUrl = AppSettings.GetValue("AllocationFeedbackUrl");
- //string apiUrl = "http://127.0.0.1:450/api/AldMaterialWarehousing/MaterialWarehousing";
- string apiUrl = url;
+ string apiUrl = string.Empty;
if (model != null)
{
+ apiUrl = AppSettings.GetValue("AldMaterialWarehousing");
httpResponseResult = _httpClientHelper.Post<MesResponseDTO>(apiUrl, model.Serialize());
requestData = model.Serialize();
}
else
{
+ apiUrl = AppSettings.GetValue("AldAllocationOperation");
httpResponseResult = _httpClientHelper.Post<MesResponseDTO>(apiUrl, allocateDto.Serialize());
- requestData = allocateDto.Serialize();
+ requestData = allocateDto.Serialize();
}
httpResponseResult.ApiUrl = apiUrl;
bool isSuccess = httpResponseResult.IsSuccess && httpResponseResult.Data.Code == "200";
@@ -587,6 +591,7 @@
_stockService.StockInfoService.Db.UpdateNav(stock).IncludesAllFirstLayer().ExecuteCommand();
+ task.TaskStatus = (int)TaskStatusEnum.Finish;
var result = _task_HtyService.DeleteAndMoveIntoHty(task, OperateTypeEnum.鑷姩瀹屾垚);
if (!result)
{
@@ -714,6 +719,9 @@
{
return content.Error("鏈壘鍒板叆鏅轰粨鐨勭墿鏂欎俊鎭�");
}
+
+ string Operator = allocateMaterialInfos.FirstOrDefault().Creater;
+
_unitOfWorkManage.BeginTran();
var alldelete = _allocateMaterialInfo.DeleteAndMoveIntoHty(allocateMaterialInfos ,OperateTypeEnum.鑷姩鍒犻櫎);
if (!alldelete)
@@ -738,6 +746,105 @@
{
await Db.Deleteable(task).ExecuteCommandAsync();
}
+ Dt_OutboundOrder outboundOrder = _outboundOrderService.Db.Queryable<Dt_OutboundOrder>().Where(x => x.OrderNo == stockInfo.Details.FirstOrDefault().OrderNo).Includes(x=>x.Details).First();
+
+ ///鍥炶皟MES
+ HttpResponseResult<MesResponseDTO> httpResponseResult = new HttpResponseResult<MesResponseDTO>();
+ string reqCode = Guid.NewGuid().ToString();
+ string reqTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
+ string requestData = string.Empty;
+ List<string> lineNos = new List<string>();
+ if (outboundOrder.OrderStatus == OutOrderStatusEnum.鍑哄簱瀹屾垚.ObjToInt())
+ {
+
+ Dt_AllocateOrder allocateOrder = _allocateOrderRepository.QueryFirst(x => x.OrderNo == outboundOrder.OrderNo);
+ if (allocateOrder == null)
+ {
+ return WebResponseContent.Instance.Error($"鏈壘鍒板搴旂殑璋冩嫧鍗�");
+ }
+ AllocationReturnDTO? returnDTO = BuildAllocationFeedbackData(outboundOrder, allocateOrder.FromWarehouse, allocateOrder.ToWarehouse, Operator);
+ if (returnDTO == null)
+ {
+ return WebResponseContent.Instance.Error($"鏋勫缓鍥炶皟瀵硅薄澶辫触");
+ }
+ string apiUrl = AppSettings.GetValue("AllocationFeedbackUrl"); ;
+ returnDTO.ReqCode = reqCode;
+ returnDTO.ReqTime = reqTime;
+ JsonSerializerSettings settings = new JsonSerializerSettings
+ {
+ ContractResolver = new CamelCasePropertyNamesContractResolver()
+ };
+ requestData = JsonConvert.SerializeObject(returnDTO, settings);
+ lineNos = returnDTO.Details.Select(x => x.LineNo).ToList();
+ httpResponseResult = _httpClientHelper.Post<MesResponseDTO>(apiUrl, requestData);
+ httpResponseResult.ApiUrl = apiUrl;
+ }
+ bool isSuccess = httpResponseResult.IsSuccess && httpResponseResult.Data.Code == "200";
+ string message = "鎴愬姛";
+ if (!isSuccess)
+ {
+ if (!httpResponseResult.IsSuccess)
+ {
+ message = $"MES鎺ュ彛杩斿洖閿欒锛孒TTP浠g爜锛歿httpResponseResult.StatusCode}锛屼俊鎭細{httpResponseResult.ErrorMessage}";
+ }
+ else if (httpResponseResult?.Data?.Code != "200")
+ {
+ message = $"璋冪敤MES鎺ュ彛澶辫触锛屼唬鐮侊細{httpResponseResult?.Data?.Code}锛屼俊鎭細{httpResponseResult?.Data?.Message}";
+ }
+ }
+
+ Dt_MesReturnRecord mesReturnRecord = new Dt_MesReturnRecord()
+ {
+ ApiUrl = httpResponseResult.ApiUrl,
+ InterfaceType = outboundOrder.OrderType == 0 ? 1 : 3,
+ OrderId = outboundOrder.Id,
+ OrderNo = outboundOrder.OrderNo,
+ RequestCode = reqCode,
+ RequestData = requestData,
+ FailureReason = message,
+ LastReturnTime = DateTime.Now,
+ HttpStatusCode = httpResponseResult.StatusCode.ObjToInt(),
+ ResponseData = httpResponseResult.Content,
+ ReturnType = 0,
+ ReturnCount = 1,
+ ReturnStatus = isSuccess ? 1 : 2,
+ SuccessTime = isSuccess ? DateTime.Now : null
+ };
+
+ _unitOfWorkManage.BeginTran();
+ _unitOfWorkManage.Db.Insertable(mesReturnRecord).ExecuteCommand();
+
+ List<Dt_OutboundOrderDetail> outboundOrderDetails = outboundOrder.Details.Where(x => lineNos.Contains(x.lineNo)).ToList();
+ outboundOrderDetails.ForEach(x =>
+ {
+ if (x.OverOutQuantity == x.OrderQuantity - x.MoveQty)
+ {
+ x.ReturnToMESStatus = isSuccess ? 1 : 2;
+ }
+ else
+ {
+ x.ReturnToMESStatus = isSuccess ? 3 : 4;
+ }
+ x.CurrentDeliveryQty = 0;
+ x.ReturnJsonData = "";
+ });
+
+ mesReturnRecord.ReturnType = outboundOrder.Details.Count == outboundOrderDetails.Count ? 1 : 2;
+
+ if (outboundOrder.Details.Count == outboundOrderDetails.Count && outboundOrderDetails.All(x => x.ReturnToMESStatus == 1 || x.ReturnToMESStatus == 2))
+ {
+ outboundOrder.ReturnToMESStatus = isSuccess ? 1 : 2;
+ }
+ else
+ {
+ outboundOrder.ReturnToMESStatus = isSuccess ? 3 : 4;
+ }
+
+ _outboundOrderService.Db.Updateable(outboundOrderDetails).ExecuteCommand();
+ _outboundOrderService.UpdateData(outboundOrder);
+
+ _unitOfWorkManage.CommitTran();
+
try
{
_locationStatusChangeRecordService.AddLocationStatusChangeRecord(locationInfo, beforelocationStatus, StockChangeType.Inbound.ObjToInt(), "", task.TaskNum);
@@ -752,6 +859,56 @@
{
_unitOfWorkManage.RollbackTran();
return await Task.FromResult(WebResponseContent.Instance.Error(ex.Message));
+ }
+ }
+
+ public AllocationReturnDTO? BuildAllocationFeedbackData(Dt_OutboundOrder outboundOrder, string fromWarehouse, string toWarehouse,string Operator)
+ {
+ try
+ {
+ List<Dt_OutboundOrderDetail> details = outboundOrder.Details;
+
+ List<AllocationDetail> returnDetails = new List<AllocationDetail>();
+
+ foreach (var detail in details)
+ {
+ List<Barcodes>? barcodes = JsonConvert.DeserializeObject<List<Barcodes>>(detail.ReturnJsonData);
+ if (barcodes != null && barcodes.Any())
+ {
+ UnitConvertResultDTO currentResult = _basicService.UnitQuantityConvert(detail.MaterielCode, detail.Unit, detail.BarcodeUnit, detail.CurrentDeliveryQty);
+ UnitConvertResultDTO totalResult = _basicService.UnitQuantityConvert(detail.MaterielCode, detail.Unit, detail.BarcodeUnit, detail.OrderQuantity);
+
+ returnDetails.Add(new AllocationDetail
+ {
+ Barcodes = barcodes,
+ BatchNo = detail.BatchNo,
+ LineNo = detail.lineNo,
+ MaterialCode = detail.MaterielCode,
+ Qty = totalResult.ToQuantity,
+ WarehouseCode = detail.WarehouseCode,
+ Unit = detail.BarcodeUnit
+ });
+ }
+ }
+
+ AllocationReturnDTO outboundReturnDTO = new AllocationReturnDTO()
+ {
+ Business_type = outboundOrder.BusinessType,
+ Details = returnDetails,
+ FactoryArea = outboundOrder.FactoryArea,
+ OperationType = 1,
+ OrderNo = outboundOrder.UpperOrderNo,
+ FromWarehouse = fromWarehouse,
+ ToWarehouse = toWarehouse,
+ Operator = Operator
+ };
+
+ return outboundReturnDTO;
+
+ }
+ catch (Exception ex)
+ {
+ return null;
}
}
@@ -1688,5 +1845,10 @@
}
}
+ public Task<WebResponseContent> HandCompleteTask(string TaskNum)
+ {
+ return TaskCompleted(TaskNum);
+ }
+
}
}
--
Gitblit v1.9.3