Browse Source

接口程序修改

master
lvzb 5 months ago
parent
commit
b5f89b1e65
  1. 138
      WebApiService/src/Win_in.Sfs.Scp.WebApi.Agent/AsnBackgroundWorker/AsnBackgroundWorker.cs
  2. 8
      WebApiService/src/Win_in.Sfs.Scp.WebApi.Agent/PostService/AuthenticationOptions.cs
  3. 11
      WebApiService/src/Win_in.Sfs.Scp.WebApi.Agent/PostService/BoomiResult.cs
  4. 10
      WebApiService/src/Win_in.Sfs.Scp.WebApi.Agent/PostService/IPostService.cs
  5. 78
      WebApiService/src/Win_in.Sfs.Scp.WebApi.Agent/PostService/PostService.cs
  6. 17
      WebApiService/src/Win_in.Sfs.Scp.WebApi.Agent/appsettings.json
  7. 4
      WebApiService/src/Win_in.Sfs.Scp.WebApi.Domain.Shared/AsnOptions.cs
  8. 1
      WebApiService/src/Win_in.Sfs.Scp.WebApi.Domain.Shared/EnumExchangeDataErrorCode.cs
  9. 40
      WebApiService/src/Win_in.Sfs.Scp.WebApi.Domain.Shared/NoPoASN/AsnDet.cs
  10. 41
      WebApiService/src/Win_in.Sfs.Scp.WebApi.Domain.Shared/NoPoASN/AsnMstr.cs

138
WebApiService/src/Win_in.Sfs.Scp.WebApi.Agent/AsnBackgroundWorker/AsnBackgroundWorker.cs

@ -5,6 +5,7 @@ using System.Runtime.Serialization;
using System.Text.Json;
using System.Threading.Tasks;
using AutoMapper;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
@ -32,17 +33,20 @@ namespace Win_in.Sfs.Scp.WebApi
{
private readonly AsnOptions _options;
private readonly IObjectMapper _objectMapper;
private readonly IPostService _postService;
public AsnBackgroundWorker(
AbpAsyncTimer timer,
IOptions<AsnOptions> options,
IServiceScopeFactory serviceScopeFactory,
IObjectMapper objectMapper
IObjectMapper objectMapper,
IPostService postService
) : base(timer, serviceScopeFactory)
{
_options = options.Value;
_objectMapper = objectMapper;
Timer.Period = options.Value.PeriodSeconds * 1000; //default 5 minutes
_postService = postService;
}
[UnitOfWork]
@ -96,24 +100,60 @@ namespace Win_in.Sfs.Scp.WebApi
await scpAsnManager.GetUnreadAsnsAsync(siteCode, lastUid, _options.BatchSize);
Logger.LogInformation($"{siteCode}: {scpAsns.Count} ASNs were Found");
var baseUrl = _options.BaseUrl;
var username = _options.Username;
var password = _options.Password;
foreach (var asn in scpAsns)
{
var barcodes = await scpAsnManager.GetBarcodesAsync(siteCode, asn.AsnBillNum);
var noPoAsn = CreateNoPoAsn(asn, barcodes);
asnX12List.Add(noPoAsn);
asn.IsPort = 1;
var apiUrl = "";
if (asn.AsnBillNum.StartsWith(_options.QadAsnPrefix))//ASN to QAD
var jsonString = noPoAsn.JsonString;
try
{
//埃驰要求不传托盘信息 @20220905
barcodes.ForEach(p => p.PalletCode = "");
//埃驰要求不传托盘信息 @20220905
var asnX12 = CreateX12Asn(site, asn, barcodes);
asnX12List.Add(asnX12);
var a = 0;
var ss = 8 / a;
var result = await _postService.PostAsync(baseUrl, apiUrl, jsonString, username, password);
if (result == null)
{
noPoAsn.SetError("Boomi", EnumExchangeDataErrorCode.None, "Boomi没有返回值");
}
if (result?.Status == "SUCCESS")
{
noPoAsn.SetSuccess("Boomi", "Boomi接口执行成功");
}
else if (result?.Status == "EXCEPTION")
{
noPoAsn.SetError("Boomi", EnumExchangeDataErrorCode.Exception, "EXCEPTION" + result?.ErrorMessage);
}
else if (result?.Status == "FAIL")
{
noPoAsn.SetError("Boomi", EnumExchangeDataErrorCode.FAIL, "FAIL" + result?.ErrorMessage);
}
}
catch (Exception e)
{
Logger.LogException(e);
e = e.GetBaseException();
noPoAsn.SetError("Boomi", EnumExchangeDataErrorCode.Exception, "接口程序异常"+e.Message);
}
finally
{
asnX12List.Add(noPoAsn);
}
//if (asn.AsnBillNum.StartsWith(_options.QadAsnPrefix))//ASN to QAD
//{
// //埃驰要求不传托盘信息 @20220905
// barcodes.ForEach(p => p.PalletCode = "");
// //埃驰要求不传托盘信息 @20220905
// var asnX12 = CreateX12Asn(site, asn, barcodes);
// asnX12List.Add(asnX12);
//}
Logger.LogInformation($"{siteCode}:{asn.Id} {asn.AsnBillNum} was loaded");
}
@ -132,56 +172,57 @@ namespace Win_in.Sfs.Scp.WebApi
Logger.LogInformation("Get ASN from SCP: Complete");
}
private X12Asn CreateNoPoAsn(TB_ASN asn, List<TS_BARCODE> barcodes)
{
var asnMstr = new AsnMstr()
{
UID = asn.Id,
Company = asn.Site,
Site = asn.Site,
AsnNbr = asn.AsnBillNum,
RpNbr = asn.AskBillNum,
PoNbr = asn.PoBillNum,
VendorCode = asn.VendId,
Contacts = asn.ReceiveUser,
Phone = "",
TruckNbr = asn.PlateNumber,
Whse = "",
Dock = "",
ShipDate = asn.ShipTime,
DueDate = asn.ReceiveTime,
TimeWindow = asn.ReceivedPort,
Remark = asn.Remark,
traceId = asn.Site+"-"+ asn.Id .ToString()+ "-"+ Guid.NewGuid().ToString(),
uid = asn.Id,
company = asn.Site,
site = asn.Site,
asnNbr = asn.AsnBillNum,
rpNbr = asn.AskBillNum,
poNbr = asn.PoBillNum,
vendorCode = asn.VendId,
contacts = asn.ReceiveUser,
phone = "",
status = null,
truckNbr = asn.PlateNumber,
whse = "",
dock = "",
shipDate = asn.ShipTime,
dueDate = asn.ReceiveTime,
timeWindow = asn.ReceivedPort,
remark = asn.Remark,
};
foreach (var barcode in barcodes)
{
var det = new AsnDet()
{
AsnNbr = asn.AsnBillNum,
PoNbr = asn.PoBillNum,
PoLine = barcode.PoBillLine,
PartCode = barcode.PartCode,
Lot = barcode.Batch,
Qty = barcode.Qty,
ProductionDate = barcode.ProduceDate,
WareClass = "",
WareCode = "",
StdPackQty = barcode.PackQty,
PoUm = barcode.PoUnit,
LocUm = barcode.LocUnit,
UmConv = 1,
PartType = "",
Supplierlot = barcode.VendBatch,
Status = barcode.State.ToString(),
LabelCode = barcode.Extend2,
EntireBarCode = barcode.FullBarCode,
PalletLabelCode = barcode.PalletCode,
Remark = barcode.Remark,
asnNbr = asn.AsnBillNum,
poNbr = asn.PoBillNum,
poLine = barcode.PoBillLine,
partCode = barcode.PartCode,
lot = barcode.Batch,
qty = barcode.Qty,
productionDate = barcode.ProduceDate,
wareClass = "",
wareCode = "",
stdPackQty = barcode.PackQty,
poUm = barcode.PoUnit,
locUm = barcode.LocUnit,
umConv = 1,
partType = "",
supplierlot = barcode.VendBatch,
status = barcode.State.ToString(),
labelCode = barcode.Extend2,
entireBarCode = barcode.FullBarCode,
palletLabelCode = barcode.PalletCode,
remark = barcode.Remark,
};
asnMstr.Details.Add(det);
asnMstr.details.Add(det);
}
var jsonString = JsonSerializer.Serialize(asnMstr);
var ediString = jsonString;
@ -189,7 +230,6 @@ namespace Win_in.Sfs.Scp.WebApi
asn.ShipTime ?? DateTime.Today);
return asnX12;
}
private static X12Asn CreateX12Asn(AsnOptions.Site site, TB_ASN asn, List<TS_BARCODE> barcodes)
{
var asnFactory = new AsnFactory();

8
WebApiService/src/Win_in.Sfs.Scp.WebApi.Agent/PostService/AuthenticationOptions.cs

@ -0,0 +1,8 @@
namespace Win_in.Sfs.Scp.WebApi.Agent
{
public class AuthenticationOptions
{
public string Username { get; set; }
public string Password { get; set; }
}
}

11
WebApiService/src/Win_in.Sfs.Scp.WebApi.Agent/PostService/BoomiResult.cs

@ -0,0 +1,11 @@
namespace Win_in.Sfs.Scp.WebApi.Agent
{
public class BoomiResult
{
public string TraceId { get; set; }
// public int ErrorCode { get; set; }
public string ErrorMessage { get; set; }
// public string Information { get; set; }
public string Status { get; set; }
}
}

10
WebApiService/src/Win_in.Sfs.Scp.WebApi.Agent/PostService/IPostService.cs

@ -0,0 +1,10 @@
using System.Threading.Tasks;
using Volo.Abp.DependencyInjection;
namespace Win_in.Sfs.Scp.WebApi.Agent
{
public interface IPostService:ITransientDependency
{
Task<BoomiResult> PostAsync(string baseUrl, string apiUrl, string content, string username, string password);
}
}

78
WebApiService/src/Win_in.Sfs.Scp.WebApi.Agent/PostService/PostService.cs

@ -0,0 +1,78 @@
using System;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Net.Http.Json;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
using Serilog;
namespace Win_in.Sfs.Scp.WebApi.Agent
{
public class PostService : IPostService
{
private readonly System.Net.Http.IHttpClientFactory _httpClientFactory;
public PostService(System.Net.Http.IHttpClientFactory httpClientFactory)
{
_httpClientFactory = httpClientFactory;
}
public async Task<BoomiResult> PostAsync(string baseUrl, string apiUrl, string content, string username, string password)
{
var options = new AuthenticationOptions()
{
Username = username,
Password = password
};
var result = await PostAsync(baseUrl,apiUrl, content, options);
return result;
}
public async Task<BoomiResult> PostAsync(string baseUrl,string apiUrl, string content, AuthenticationOptions options)
{
//var client = new HttpClient();
var client = _httpClientFactory.CreateClient();
client.BaseAddress = new Uri(baseUrl);
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
var byteArray = Encoding.ASCII.GetBytes($"{options.Username}:{options.Password}");
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(byteArray));
var httpContent = new StringContent(content);
httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");
//var url = baseUrl + "/" + apiUrl;
var url = baseUrl;
Serilog.Log.Information(url);
Serilog.Log.Debug(content);
var response = await client.PostAsync(url, httpContent);
try
{
Log.Debug("before EnsureSuccessStatusCode() response content↓↓↓");
Log.Debug(await response.Content.ReadAsStringAsync());
}
catch (Exception e)
{
Console.WriteLine(e);
throw;
}
response.EnsureSuccessStatusCode();
HttpContent respCon = response.Content;
string resultContent = await respCon.ReadAsStringAsync();
resultContent = resultContent.Replace("\n", "").Replace(" ", "").Replace("\t", "").Replace("\r", "");
Serilog.Log.Debug("response content↓↓↓");
Serilog.Log.Debug(resultContent);
//var result = await respCon.ReadFromJsonAsync<BoomiResult>();
var result = JsonSerializer.Deserialize<BoomiResult>(resultContent);
return result;
}
}
}

17
WebApiService/src/Win_in.Sfs.Scp.WebApi.Agent/appsettings.json

@ -1,6 +1,6 @@
{
"ConnectionStrings": {
"Default": "Server=127.0.0.1;Database=Scp_WebApi;User ID=sa;Password=Microsoft2008;connection timeout=600;"
"Default": "Server=dev.ccwin-in.com,6207;Database=Scp_WebApi_UAT;User ID=sa;Password=ChangkeTec@2021;connection timeout=600;"
},
"Serilog": {
"Using": [ "Serilog.Sinks.File", "Serilog.Sinks.Async", "Serilog.Sinks.Console", "Serilog.Sinks.MSSqlServer" ],
@ -38,7 +38,7 @@
{
"Name": "MSSqlServer",
"Args": {
"connectionString": "Server=127.0.0.1;Database=Scp_WebApi;User ID=sa;Password=Microsoft2008;connection timeout=600;",
"connectionString": "Server=dev.ccwin-in.com,6207;Database=Scp_WebApi_UAT;User ID=sa;Password=ChangkeTec@2021;connection timeout=600;",
"tableName": "AgentLogs",
"autoCreateSqlTable": true
}
@ -54,17 +54,20 @@
"MaxCount": 100,
"QadAsnPrefix": "B",
"NoPoAsnPrefix": "T",
"BaseUrl": "https://api.iacgroup.com:9100/ws/simple/createWMSSupplierASN",
"Username": "SCP-CH@iac-PJL8W6",
"Password": "f0475092-c891-4d36-b2c1-dfd39fa0e436",
"Sites": [
{
"Code": "T8",
"Receiver": "00T8USUPPU",
"MinUid": 1024
},
{
"Code": "T5",
"Receiver": "00T5USUPPU",
"MinUid": 100
}
//{
// "Code": "T5",
// "Receiver": "00T5USUPPU",
// "MinUid": 100
//}
]
}

4
WebApiService/src/Win_in.Sfs.Scp.WebApi.Domain.Shared/AsnOptions.cs

@ -12,7 +12,9 @@ public class AsnOptions
public string ValidPoPre { get; set; } = "PO";
public string QadAsnPrefix { get; set; } = "B";
public string NoPoAsnPrefix { get; set; } = "T";
public string BaseUrl { get; set; } = "https://api.iacgroup.com:9100/ws/simple/createWMSSupplierASN";
public string Username { get; set; } = "SCP-CH@iac-PJL8W6";
public string Password { get; set; } = "f0475092-c891-4d36-b2c1-dfd39fa0e436";
public List<Site> Sites { get; set; } =new() ;
public class Site

1
WebApiService/src/Win_in.Sfs.Scp.WebApi.Domain.Shared/EnumExchangeDataErrorCode.cs

@ -6,4 +6,5 @@ public enum EnumExchangeDataErrorCode
UnknownDataType = 1,
WrongDataFormat = 2,
Exception = 9,
FAIL=8
}

40
WebApiService/src/Win_in.Sfs.Scp.WebApi.Domain.Shared/NoPoASN/AsnDet.cs

@ -16,102 +16,102 @@ namespace Win_in.Sfs.Scp.WebApi
/// <summary>
/// 送货单号
/// </summary>
public virtual string AsnNbr { get; set; }
public virtual string asnNbr { get; set; }
/// <summary>
/// 采购订单号
/// </summary>
public virtual string PoNbr { get; set; }
public virtual string poNbr { get; set; }
/// <summary>
/// 采购订单行
/// </summary>
public virtual int PoLine { get; set; }
public virtual int poLine { get; set; }
/// <summary>
/// 物料号
/// </summary>
public virtual string PartCode { get; set; }
public virtual string partCode { get; set; }
/// <summary>
/// 批次
/// </summary>
public virtual string Lot { get; set; }
public virtual string lot { get; set; }
/// <summary>
/// 送货总量
/// </summary>
public virtual decimal Qty { get; set; }
public virtual decimal qty { get; set; }
/// <summary>
/// 生产日期
/// </summary>
public virtual DateTime? ProductionDate { get; set; }
public virtual DateTime? productionDate { get; set; }
/// <summary>
/// 器具型号
/// </summary>
public virtual string WareClass { get; set; }
public virtual string wareClass { get; set; }
/// <summary>
/// 器具号
/// </summary>
public virtual string WareCode { get; set; }
public virtual string wareCode { get; set; }
/// <summary>
/// 标准包装量
/// </summary>
public virtual decimal StdPackQty { get; set; }
public virtual decimal stdPackQty { get; set; }
/// <summary>
/// 采购单位
/// </summary>
public virtual string PoUm { get; set; }
public virtual string poUm { get; set; }
/// <summary>
/// 基本单位
/// </summary>
public virtual string LocUm { get; set; }
public virtual string locUm { get; set; }
/// <summary>
/// 转换率
/// </summary>
public virtual decimal UmConv { get; set; }
public virtual decimal umConv { get; set; }
/// <summary>
/// 物料类型
/// </summary>
public virtual string PartType { get; set; }
public virtual string partType { get; set; }
/// <summary>
/// 供应商批号
/// </summary>
public virtual string Supplierlot { get; set; }
public virtual string supplierlot { get; set; }
/// <summary>
/// 状态(0:Closed,1:Open)
/// </summary>
public virtual string Status { get; set; }
public virtual string status { get; set; }
/// <summary>
/// 标签代码
/// </summary>
public virtual string LabelCode { get; set; }
public virtual string labelCode { get; set; }
/// <summary>
/// 完整条码数据
/// </summary>
public virtual string EntireBarCode { get; set; }
public virtual string entireBarCode { get; set; }
/// <summary>
/// 托盘标签代码
/// </summary>
public virtual string PalletLabelCode { get; set; }
public virtual string palletLabelCode { get; set; }
/// <summary>
/// 备注
/// </summary>
public virtual string Remark { get; set; }
public virtual string remark { get; set; }
}

41
WebApiService/src/Win_in.Sfs.Scp.WebApi.Domain.Shared/NoPoASN/AsnMstr.cs

@ -9,88 +9,95 @@ namespace Win_in.Sfs.Scp.WebApi
/// </summary>
public class AsnMstr
{
public string traceId { get; set; }
/// <summary>
/// 自增长数字主键
/// </summary>
public virtual long UID { get; set; }
public virtual long uid { get; set; }
/// <summary>
/// 公司
/// </summary>
public virtual string Company { get; set; }
public virtual string company { get; set; }
/// <summary>
/// 工厂
/// </summary>
public virtual string Site { get; set; }
public virtual string site { get; set; }
/// <summary>
/// 送货单号
/// </summary>
public virtual string AsnNbr { get; set; }
public virtual string asnNbr { get; set; }
/// <summary>
/// 要货计划单号
/// </summary>
public virtual string RpNbr { get; set; }
public virtual string rpNbr { get; set; }
/// <summary>
/// 采购订单号
/// </summary>
public virtual string PoNbr { get; set; }
public virtual string poNbr { get; set; }
/// <summary>
/// 供应商
/// </summary>
public virtual string VendorCode { get; set; }
public virtual string vendorCode { get; set; }
/// <summary>
/// 状态
/// </summary>
public string status { get; set; }
/// <summary>
/// 联系人
/// </summary>
public virtual string Contacts { get; set; }
public virtual string contacts { get; set; }
/// <summary>
/// 联系电话
/// </summary>
public virtual string Phone { get; set; }
public virtual string phone { get; set; }
/// <summary>
/// 车牌号
/// </summary>
public virtual string TruckNbr { get; set; }
public virtual string truckNbr { get; set; }
/// <summary>
/// 仓库
/// </summary>
public virtual string Whse { get; set; }
public virtual string whse { get; set; }
/// <summary>
/// 收货口
/// </summary>
public virtual string Dock { get; set; }
public virtual string dock { get; set; }
/// <summary>
/// 发货日期
/// </summary>
public DateTime? ShipDate { get; set; }
public DateTime? shipDate { get; set; }
/// <summary>
/// 到货日期
/// </summary>
public DateTime? DueDate { get; set; }
public DateTime? dueDate { get; set; }
/// <summary>
/// 时间窗口
/// </summary>
public string TimeWindow { get; set; }
public string timeWindow { get; set; }
/// <summary>
/// 备注
/// </summary>
public virtual string Remark { get; set; }
public virtual string remark { get; set; }
public virtual List<AsnDet> Details { get; set; } = new List<AsnDet>();
public virtual List<AsnDet> details { get; set; } = new List<AsnDet>();
}
}

Loading…
Cancel
Save