From 6b6c66cd99a4e73eea9bc68c8d7c63fd08180fb9 Mon Sep 17 00:00:00 2001
From: pan <antony1029@163.com>
Date: 星期二, 18 十一月 2025 16:12:46 +0800
Subject: [PATCH] 提交
---
项目代码/WMS无仓储版/WIDESEA_WMSServer/WIDESEA_BasicService/InvokeMESService.cs | 171 ++++++++++++++++++++++++++++++++++++++++++++++----------
1 files changed, 139 insertions(+), 32 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_BasicService/InvokeMESService.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_BasicService/InvokeMESService.cs"
index f946d44..328c761 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_BasicService/InvokeMESService.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_BasicService/InvokeMESService.cs"
@@ -1,6 +1,7 @@
锘縰sing Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using Org.BouncyCastle.Asn1.Ocsp;
+using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -9,10 +10,13 @@
using System.Security.Policy;
using System.Text;
using System.Threading.Tasks;
+using WIDESEA_Core;
+using WIDESEA_Core.BaseRepository;
using WIDESEA_DTO.Basic;
using WIDESEA_DTO.Inbound;
using WIDESEA_DTO.Outbound;
using WIDESEA_IBasicService;
+using WIDESEA_Model.Models;
namespace WIDESEA_BasicService
{
@@ -22,21 +26,58 @@
private readonly ILogger<InvokeMESService> _logger;
private string UserName = "12312";
private string Password = "1";
- public InvokeMESService(IHttpClientFactory httpClientFactory, ILogger<InvokeMESService> logger)
+
+ private readonly IRepository<Dt_FeedbackToMes> _feedbacktomesRepository;
+ private readonly IRepository<Dt_StockInfoDetail> _stockInfoDetailRepository;
+ private readonly IRepository<Dt_StockInfo> _stockInfoRepository;
+ private readonly IRepository<Dt_InboundOrder> _inboundOrderRepository;
+ public InvokeMESService(IHttpClientFactory httpClientFactory, ILogger<InvokeMESService> logger, IRepository<Dt_FeedbackToMes> feedbacktomesRepository, IRepository<Dt_StockInfoDetail> stockInfoDetailRepository, IRepository<Dt_StockInfo> stockInfoRepository, IRepository<Dt_InboundOrder> inboundOrderRepository)
{
_httpClientFactory = httpClientFactory;
_logger = logger;
+ _feedbacktomesRepository = feedbacktomesRepository;
+ _stockInfoDetailRepository = stockInfoDetailRepository;
+ _stockInfoRepository = stockInfoRepository;
+ _inboundOrderRepository = inboundOrderRepository;
}
- public async Task FeedbackInbound(string url, FeedbackInboundRequestModel model)
+ public async Task<ResponseModel> FeedbackInbound(FeedbackInboundRequestModel model)
{
- string json = JsonConvert.SerializeObject(model);
+ string json =JsonConvert.SerializeObject(model, new JsonSerializerSettings
+ {
+ ContractResolver = new Newtonsoft.Json.Serialization.CamelCasePropertyNamesContractResolver()
+ });
+ var content = new StringContent(json, Encoding.UTF8, "application/json");
+ var _client = _httpClientFactory.CreateClient("MESUrl");
+ _client.DefaultRequestHeaders.Clear();
+ _client.DefaultRequestHeaders.Add("Accept", "application/json");
+ _logger.LogInformation("InvokeMESService FeedbackInbound : " + json);
+ var response = await _client.PostAsync("AldMaterialWarehousing/MaterialWarehousing", content);
+ string body = await response.Content.ReadAsStringAsync();
+ _logger.LogInformation("InvokeMESService FeedbackInbound body: " + body);
+ if (!response.IsSuccessStatusCode)
+ {
+
+ throw new HttpRequestException(body);
+ }
+
+ return JsonConvert.DeserializeObject<ResponseModel>(body);
+ }
+
+ public async Task<ResponseModel> FeedbackOutbound(FeedbackOutboundRequestModel model)
+ {
+ string json = JsonConvert.SerializeObject(model, new JsonSerializerSettings
+ {
+ ContractResolver = new Newtonsoft.Json.Serialization.CamelCasePropertyNamesContractResolver()
+ });
var content = new StringContent(json, Encoding.UTF8, "application/json");
var _client = _httpClientFactory.CreateClient("MESUrl");
_client.DefaultRequestHeaders.Clear();
_client.DefaultRequestHeaders.Add("Accept", "application/json");
- var response = await _client.PostAsync(url, content);
+ _logger.LogInformation("InvokeMESService FeedbackOutbound : " + json);
+
+ var response = await _client.PostAsync("AldMaterialOutbound/MaterialOutbound", content);
string body = await response.Content.ReadAsStringAsync();
if (!response.IsSuccessStatusCode)
@@ -45,43 +86,27 @@
throw new HttpRequestException(body);
}
- // JsonConvert.DeserializeObject<ResponseModel>(body);
- }
- public async Task FeedbackOutbound(string url, FeedbackOutboundRequestModel model)
- {
- string json = JsonConvert.SerializeObject(model);
- var content = new StringContent(json, Encoding.UTF8, "application/json");
- var _client = _httpClientFactory.CreateClient("MESUrl");
- _client.DefaultRequestHeaders.Clear();
- _client.DefaultRequestHeaders.Add("Accept", "application/json");
-
- var response = await _client.PostAsync(url, content);
- string body = await response.Content.ReadAsStringAsync();
-
- if (!response.IsSuccessStatusCode)
- {
-
- throw new HttpRequestException(body);
- }
-
- // JsonConvert.DeserializeObject<ResponseModel>(body);
+ return JsonConvert.DeserializeObject<ResponseModel>(body);
}
public async Task<ResponseModel> NewMaterielToMes(MaterielToMesDTO model)
{
- string json = JsonConvert.SerializeObject(model);
+ string json = JsonConvert.SerializeObject(model, new JsonSerializerSettings
+ {
+ ContractResolver = new Newtonsoft.Json.Serialization.CamelCasePropertyNamesContractResolver()
+ });
- string userDataEncoded = Uri.EscapeDataString(json);
- //string baseUrl = "http://mestest.ald.com//OrBitWCFServiceR15/orbitwebapi.ashx?";
- string userTicket = await GetToken(UserName, Password);
- string api = "WMS_BarcodeInformation";
+ //string userDataEncoded = Uri.EscapeDataString(json);
+ ////string baseUrl = "http://mestest.ald.com//OrBitWCFServiceR15/orbitwebapi.ashx?";
+ //string userTicket = await GetToken(UserName, Password);
+ //string api = "WMS_BarcodeInformation";
var client = _httpClientFactory.CreateClient("MESUrl");
// 鎷兼帴 URL 鍙傛暟
- string url = $"{client.BaseAddress}UserTicket={userTicket}&API={api}&UserData={userDataEncoded}";
+ // string url = $"{client.BaseAddress}UserTicket={userTicket}&API={api}&UserData={userDataEncoded}";
client.DefaultRequestHeaders.Clear();
@@ -91,7 +116,9 @@
var content = new StringContent(json, Encoding.UTF8, "application/json");
- using var response = await client.PostAsync(url, content);
+ _logger.LogInformation("InvokeMESService FeedbackInbound : " + json);
+
+ using var response = await client.PostAsync("AldBarcodeInformation/BarcodeInformation", content);
var responseText = await response.Content.ReadAsStringAsync();
if (!response.IsSuccessStatusCode)
{
@@ -141,6 +168,86 @@
}
}
- }
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="orderNos"></param>
+ /// <param name="inout">鍏ュ簱浼�1 鍑哄簱浼�2</param>
+ /// <returns></returns>
+ public async Task<WebResponseContent> BatchOrderFeedbackToMes(List<string> orderNos, int inout)
+ {
+ if (inout == 1)
+ {
+ foreach (var orderNo in orderNos)
+ {
+ try
+ {
+ var stockinfos = _stockInfoRepository.Db.Queryable<Dt_StockInfo>("info").Where(info => info.StockStatus == 6)
+ .Where(it => SqlFunc.Subqueryable<Dt_StockInfoDetail>().Where(s => s.StockId == it.Id && s.OrderNo == orderNo).Any())
+ .ToList();
+ var feeds = _feedbacktomesRepository.Db.Queryable<Dt_FeedbackToMes>().Where(x => x.OrderNo == orderNo && x.ReportStatus == 1).Select(o => o.PalletCode).ToList();
+ var unreports = stockinfos.Where(x => !feeds.Contains(x.PalletCode)).ToList();
+ if (unreports!=null && !unreports.Any()) {
+ return WebResponseContent.Instance.Error("娌℃湁闇�瑕佸洖浼犵殑鏁版嵁");
+ }
+ foreach (var item in unreports)
+ {
+ var lists = _stockInfoDetailRepository.Db.Queryable<Dt_StockInfoDetail>().Where(x => x.StockId == item.Id).ToList();
+ if (lists.Any())
+ {
+ var inboundOrder = _inboundOrderRepository.Db.Queryable<Dt_InboundOrder>().First(x => x.InboundOrderNo == lists.FirstOrDefault().OrderNo);
+ if (inboundOrder != null)
+ {
+ var feedmodel = new FeedbackInboundRequestModel
+ {
+ reqCode = Guid.NewGuid().ToString(),
+ reqTime = DateTime.Now.ToString(),
+ business_type = inboundOrder.BusinessType,
+ factoryArea = inboundOrder.FactoryArea,
+ operationType=1,
+ Operator= inboundOrder.Operator,
+ orderNo = inboundOrder.UpperOrderNo,
+ status = inboundOrder.OrderStatus,
+ details = new List<FeedbackInboundDetailsModel>()
+ };
+
+ var groupedData = lists.GroupBy(item => new { item.MaterielCode, item.SupplyCode, item.BatchNo, item.InboundOrderRowNo, item.BarcodeUnit, item.WarehouseCode })
+ .Select(group => new FeedbackInboundDetailsModel
+ {
+ materialCode = group.Key.MaterielCode,
+ supplyCode = group.Key.SupplyCode,
+ batchNo = group.Key.BatchNo,
+ lineNo = group.Key.InboundOrderRowNo,
+ qty = group.Sum(x=>x.BarcodeQty),
+ // warehouseCode = group.Key.WarehouseCode=="0"?"1072": group.Key.WarehouseCode,
+ warehouseCode =group.Key.WarehouseCode,
+ unit = group.Key.BarcodeUnit,
+ barcodes = group.Select(row => new FeedbackBarcodesModel
+ {
+ barcode = row.Barcode,
+ qty = row.BarcodeQty
+ }).ToList()
+ }).ToList();
+ feedmodel.details = groupedData;
+ var result = await FeedbackInbound(feedmodel);
+ if (result != null && result.code == 200)
+ {
+ _feedbacktomesRepository.Db.Insertable(new Dt_FeedbackToMes { OrderNo = orderNo, PalletCode = item.PalletCode, ReportStatus = 1 }).ExecuteCommand();
+ }
+ }
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ _logger.LogInformation("InvokeMESService BatchOrderFeedbackToMes 鍥炲啓MES澶辫触: " + ex.Message);
+ return WebResponseContent.Instance.Error(ex.Message);
+ }
+
+ }
+ }
+ return WebResponseContent.Instance.OK();
+ }
+ }
}
--
Gitblit v1.9.3