Browse Source

[fix] 调整ASN服务返回的数据类型

master
贾荣国 3 years ago
parent
commit
26ad51b995
  1. 12
      WebApiService/src/Win_in.Sfs.Scp.WebApi.Application.Contracts/Asns/IX12AsnAppService.cs
  2. 29
      WebApiService/src/Win_in.Sfs.Scp.WebApi.Application/Asns/X12AsnAppService.cs
  3. 12
      WebApiService/src/Win_in.Sfs.Scp.WebApi.HttpApi.Host/AsnBackgroundWorker/AsnBackgroundWorker.cs
  4. 1
      WebApiService/src/Win_in.Sfs.Scp.WebApi.HttpApi.Host/AsnBackgroundWorker/AsnBgWorker.cs
  5. 18
      WebApiService/src/Win_in.Sfs.Scp.WebApi.HttpApi.Host/AsnBackgroundWorker/AsnFactory.cs
  6. 3
      WebApiService/src/Win_in.Sfs.Scp.WebApi.HttpApi.Host/appsettings.json

12
WebApiService/src/Win_in.Sfs.Scp.WebApi.Application.Contracts/Asns/IX12AsnAppService.cs

@ -14,17 +14,17 @@ namespace Win_in.Sfs.Scp.WebApi
/// </summary> /// </summary>
public interface IX12AsnAppService : IReadOnlyAppService<X12AsnDTO,Guid,RequestDTO> public interface IX12AsnAppService : IReadOnlyAppService<X12AsnDTO,Guid,RequestDTO>
{ {
Task<List<X12AsnDTO>> GetUnreadListAsync(string site, int count,bool autoUpdateStatus); Task<ListResultDto<X12AsnDTO>> GetUnreadListAsync(string site, int count,bool autoUpdateStatus);
Task<List<X12AsnDTO>> GetListAsync(string site, long beginUid,long endUid); Task<ListResultDto<X12AsnDTO>> GetListAsync(string site, long beginUid,long endUid);
Task<List<X12AsnDTO>> GetListAsync(string site, DateTime beginDate, DateTime endDate); Task<ListResultDto<X12AsnDTO>> GetListAsync(string site, DateTime beginDate, DateTime endDate);
Task<X12AsnDTO> GetAsync(string site, long uid); Task<ActionResult<X12AsnDTO>> GetAsync(string site, long uid);
Task<X12AsnDTO> GetAsync(string site, string number); Task<ActionResult<X12AsnDTO>> GetAsync(string site, string number);
Task<X12AsnDTO> UpdateStatusAsync(string site, string number, EnumExchangeDataStatus status); Task<ActionResult<X12AsnDTO>> UpdateStatusAsync(string site, string number, EnumExchangeDataStatus status);
} }

29
WebApiService/src/Win_in.Sfs.Scp.WebApi.Application/Asns/X12AsnAppService.cs

@ -82,14 +82,14 @@ namespace Win_in.Sfs.Scp.WebApi
/// <returns></returns> /// <returns></returns>
[HttpGet] [HttpGet]
[Route("unread-list")] [Route("unread-list")]
public async Task<List<X12AsnDTO>> GetUnreadListAsync(string site, int count, bool autoUpdateStatus) public async Task<ListResultDto<X12AsnDTO>> GetUnreadListAsync(string site, int count, bool autoUpdateStatus)
{ {
var entities = await _x12AsnRepository.GetUnreadListAsync(site, count, autoUpdateStatus); var entities = await _x12AsnRepository.GetUnreadListAsync(site, count, autoUpdateStatus);
var dtos = BuildDtos(entities); var dtos = BuildDtos(entities);
return dtos; return new ListResultDto<X12AsnDTO>(dtos);
} }
@ -103,18 +103,18 @@ namespace Win_in.Sfs.Scp.WebApi
/// <exception cref="BadHttpRequestException"></exception> /// <exception cref="BadHttpRequestException"></exception>
[HttpGet] [HttpGet]
[Route("between-id")] [Route("between-id")]
public async Task<List<X12AsnDTO>> GetListAsync(string site, long beginUid, long endUid) public async Task<ListResultDto<X12AsnDTO>> GetListAsync(string site, long beginUid, long endUid)
{ {
if (endUid < beginUid) if (endUid < beginUid)
{ {
throw new BadHttpRequestException("beginUid is bigger than endUid"); throw new AbpValidationException("beginUid is bigger than endUid");
} }
var entities = await _x12AsnRepository.GetListAsync(p => p.Site == site && p.UID >= beginUid && p.UID <= endUid); var entities = await _x12AsnRepository.GetListAsync(p => p.Site == site && p.UID >= beginUid && p.UID <= endUid);
var dtos = BuildDtos(entities); var dtos = BuildDtos(entities);
return dtos; return new ListResultDto<X12AsnDTO>(dtos);
} }
/// <summary> /// <summary>
@ -127,18 +127,18 @@ namespace Win_in.Sfs.Scp.WebApi
/// <exception cref="BadHttpRequestException"></exception> /// <exception cref="BadHttpRequestException"></exception>
[HttpGet] [HttpGet]
[Route("between-date")] [Route("between-date")]
public async Task<List<X12AsnDTO>> GetListAsync(string site, DateTime beginDate, DateTime endDate) public async Task<ListResultDto<X12AsnDTO>> GetListAsync(string site, DateTime beginDate, DateTime endDate)
{ {
if (endDate < beginDate) if (endDate < beginDate)
{ {
throw new BadHttpRequestException("beginDate is after endDate"); throw new AbpValidationException("beginDate is after endDate");
} }
var entities = await _x12AsnRepository.GetListAsync(p => p.Site == site && p.EffectiveDate >= beginDate && p.EffectiveDate <= endDate); var entities = await _x12AsnRepository.GetListAsync(p => p.Site == site && p.EffectiveDate >= beginDate && p.EffectiveDate <= endDate);
var dtos = BuildDtos(entities); var dtos = BuildDtos(entities);
return dtos; return new ListResultDto<X12AsnDTO>(dtos);
} }
/// <summary> /// <summary>
@ -150,13 +150,14 @@ namespace Win_in.Sfs.Scp.WebApi
/// <exception cref="BadHttpRequestException"></exception> /// <exception cref="BadHttpRequestException"></exception>
[HttpGet] [HttpGet]
[Route("by-id")] [Route("by-id")]
public async Task<X12AsnDTO> GetAsync(string site, long uid) public async Task<ActionResult<X12AsnDTO>> GetAsync(string site, long uid)
{ {
var entity = await _x12AsnRepository.FirstOrDefaultAsync(p => p.Site == site && p.UID == uid); var entity = await _x12AsnRepository.FirstOrDefaultAsync(p => p.Site == site && p.UID == uid);
if (entity == null) if (entity == null)
{ {
throw new BadHttpRequestException($"ASN of {uid} in {site} is not found");
throw new AbpValidationException($"ASN of {uid} in {site} is not found");
} }
var dto = BuildDto(entity); var dto = BuildDto(entity);
@ -173,13 +174,13 @@ namespace Win_in.Sfs.Scp.WebApi
/// <exception cref="BadHttpRequestException"></exception> /// <exception cref="BadHttpRequestException"></exception>
[HttpGet] [HttpGet]
[Route("by-number")] [Route("by-number")]
public async Task<X12AsnDTO> GetAsync(string site, string number) public async Task<ActionResult<X12AsnDTO>> GetAsync(string site, string number)
{ {
var entity = await _x12AsnRepository.FirstOrDefaultAsync(p => p.Site == site && p.BillNum == number); var entity = await _x12AsnRepository.FirstOrDefaultAsync(p => p.Site == site && p.BillNum == number);
if (entity == null) if (entity == null)
{ {
throw new BadHttpRequestException($"ASN of {number} in {site} is not found"); throw new AbpValidationException($"ASN of {number} in {site} is not found");
} }
var dto = BuildDto(entity); var dto = BuildDto(entity);
@ -204,14 +205,14 @@ namespace Win_in.Sfs.Scp.WebApi
/// <exception cref="BadHttpRequestException"></exception> /// <exception cref="BadHttpRequestException"></exception>
[HttpPost] [HttpPost]
[Route("update-status")] [Route("update-status")]
public async Task<X12AsnDTO> UpdateStatusAsync(string site, string number, EnumExchangeDataStatus status) public async Task<ActionResult<X12AsnDTO>> UpdateStatusAsync(string site, string number, EnumExchangeDataStatus status)
{ {
var entity = await _x12AsnRepository.FirstOrDefaultAsync(p => p.Site == site && p.BillNum == number); var entity = await _x12AsnRepository.FirstOrDefaultAsync(p => p.Site == site && p.BillNum == number);
if (entity == null) if (entity == null)
{ {
throw new BadHttpRequestException($"ASN of {number} in {site} is not found"); throw new AbpValidationException($"ASN of {number} in {site} is not found");
} }
var result = await _x12AsnRepository.UpdateStatusAsync(entity.Id, status); var result = await _x12AsnRepository.UpdateStatusAsync(entity.Id, status);

12
WebApiService/src/Win_in.Sfs.Scp.WebApi.HttpApi.Host/AsnBackgroundWorker/AsnBackgroundWorker.cs

@ -39,10 +39,10 @@ public class AsnBackgroundWorker : AsyncPeriodicBackgroundWorkerBase
[UnitOfWork] [UnitOfWork]
protected override async Task DoWorkAsync(PeriodicBackgroundWorkerContext workerContext) protected override async Task DoWorkAsync(PeriodicBackgroundWorkerContext workerContext)
{ {
Logger.LogInformation("Starting: Get ASN from SCP"); Logger.LogInformation("Get ASN from SCP: Start");
if (!_options.Value.Active) if (!_options.Value.Active)
{ {
Logger.LogInformation("Switch is closed!"); Logger.LogInformation("Get ASN from SCP: Switch is closed!");
return; return;
} }
//Resolve dependencies //Resolve dependencies
@ -71,18 +71,20 @@ public class AsnBackgroundWorker : AsyncPeriodicBackgroundWorkerBase
{ {
var scpAsns = await scpAsnManager.GetUnreadAsnsAsync(site,maxUid, _options.Value.BatchSize); var scpAsns = await scpAsnManager.GetUnreadAsnsAsync(site,maxUid, _options.Value.BatchSize);
Logger.LogInformation($"{site}: {scpAsns.Count} records were Found");
if (scpAsns.Count <= 0) if (scpAsns.Count <= 0)
{ {
Logger.LogInformation($"{site}: no new ASN");
continue; continue;
} }
Logger.LogInformation($"{site}: {scpAsns.Count} ASNs were Found");
foreach (var asn in scpAsns) foreach (var asn in scpAsns)
{ {
var barcodes = await scpAsnManager.GetBarcodesAsync(site,asn.AsnBillNum); var barcodes = await scpAsnManager.GetBarcodesAsync(site,asn.AsnBillNum);
var asnFactory = new AsnFactory(); var asnFactory = new AsnFactory();
var asnX128563060 = asnFactory.CreateAsnX128563060(asn, barcodes); var asnX128563060 = asnFactory.CreateAsnX128563060(_options.Value.Receiver,asn, barcodes);
var jsonString = JsonSerializer.Serialize(asnX128563060); var jsonString = JsonSerializer.Serialize(asnX128563060);
var ediString = asnX128563060.ToString(); var ediString = asnX128563060.ToString();
var asnX12 = new X12Asn(asn.Id, asn.Site, asn.AsnBillNum, jsonString,ediString, asn.ShipTime ?? DateTime.Today); var asnX12 = new X12Asn(asn.Id, asn.Site, asn.AsnBillNum, jsonString,ediString, asn.ShipTime ?? DateTime.Today);
@ -117,7 +119,7 @@ public class AsnBackgroundWorker : AsyncPeriodicBackgroundWorkerBase
await x12AsnRepository.InsertManyAsync(asnX12List, true); await x12AsnRepository.InsertManyAsync(asnX12List, true);
Logger.LogInformation("Completed: Get ASN from SCP"); Logger.LogInformation("Get ASN from SCP: Completed");
} }
} }

1
WebApiService/src/Win_in.Sfs.Scp.WebApi.HttpApi.Host/AsnBackgroundWorker/AsnBgWorker.cs

@ -9,4 +9,5 @@ public class AsnBgWorker
public int RetryTimes { get; set; } = 3; public int RetryTimes { get; set; } = 3;
public int BatchSize { get; set; } = 10; public int BatchSize { get; set; } = 10;
public List<string> Sites { get; set; } =new() ; public List<string> Sites { get; set; } =new() ;
public string Receiver { get; set; } = "IACNA_ID";
} }

18
WebApiService/src/Win_in.Sfs.Scp.WebApi.HttpApi.Host/AsnBackgroundWorker/AsnFactory.cs

@ -8,12 +8,16 @@ namespace Win_in.Sfs.Scp.WebApi
{ {
public class AsnFactory public class AsnFactory
{ {
public ASN_X12_856_3060 CreateAsnX128563060(TB_ASN scpAsn,List<TS_BARCODE> barcodes) private const string IdentificationCode = "PSTV"; //TODO
private const string TruckNumber = "000000"; //TODO 车牌号
private const string PackagingCode = "PLT90"; //TODO 包装代码
public ASN_X12_856_3060 CreateAsnX128563060(string receiver,TB_ASN scpAsn,List<TS_BARCODE> barcodes)
{ {
var asnCode = scpAsn.AsnBillNum; var asnCode = scpAsn.AsnBillNum;
var senderId = scpAsn.VendId; var senderId = scpAsn.VendId;
var receiverId = "IACNA_ID"; var receiverId = receiver;
var shipTime = scpAsn.ShipTime ?? DateTime.Now; var shipTime = scpAsn.ShipTime ?? DateTime.Now;
var envType = ISA.EnvType.P; var envType = ISA.EnvType.P;
@ -22,7 +26,7 @@ namespace Win_in.Sfs.Scp.WebApi
//初始化ASN单 //初始化ASN单
var asn = CreateAsn(asnCode,senderId,receiverId,shipTime,envType,authorization,security); var asn = CreateAsn(asnCode,senderId,receiverId,shipTime,envType,authorization,security);
var functionalGroupCode = "123456789"; var functionalGroupCode = scpAsn.AsnBillNum.Right(9);//TODO
//初始化功能组 //初始化功能组
var functionalGroup = CreateFunctionalGroup(senderId,receiverId,shipTime,functionalGroupCode); var functionalGroup = CreateFunctionalGroup(senderId,receiverId,shipTime,functionalGroupCode);
@ -36,10 +40,10 @@ namespace Win_in.Sfs.Scp.WebApi
var nValue = 0; var nValue = 0;
var nUom = "KG"; var nUom = "KG";
var routeSequenceCode = "B"; var routeSequenceCode = "B";
var identificationCode = "PSTV"; var identificationCode = IdentificationCode;
var mode = "LT"; var mode = "LT";
var equipmentCode = "TL"; var equipmentCode = "TL";
var equipmentNumber = "123456";//TODO 车牌号 var equipmentNumber = TruckNumber;
//初始化发货明细 //初始化发货明细
var shipment = CreateShipment(shipNotice,gValue,gUom,nValue,nUom,routeSequenceCode,identificationCode,mode, var shipment = CreateShipment(shipNotice,gValue,gUom,nValue,nUom,routeSequenceCode,identificationCode,mode,
equipmentCode,equipmentNumber,functionalGroupCode,functionalGroupCode,senderId,receiverId); equipmentCode,equipmentNumber,functionalGroupCode,functionalGroupCode,senderId,receiverId);
@ -96,8 +100,8 @@ namespace Win_in.Sfs.Scp.WebApi
} }
//TODO 如何获取包装代码,或者规则是什么?
var packagingCode = "PLT90"; var packagingCode = PackagingCode;
//装载量需要在添加托盘和尾箱后再计算 //装载量需要在添加托盘和尾箱后再计算
var loadingQty = shipment.Tares.Count+shipment.OrphanItems.Count; var loadingQty = shipment.Tares.Count+shipment.OrphanItems.Count;
shipment.SetTD1(packagingCode, loadingQty); shipment.SetTD1(packagingCode, loadingQty);

3
WebApiService/src/Win_in.Sfs.Scp.WebApi.HttpApi.Host/appsettings.json

@ -39,7 +39,8 @@
"PeriodSeconds": 10, "PeriodSeconds": 10,
"RetryTimes": 3, "RetryTimes": 3,
"BatchSize": 10, "BatchSize": 10,
"Sites": ["T8","T9"] "Receiver": "IACNA_ID",
"Sites": [ "T8", "T9" ]
}, },
"AlwaysAllowAuthorization": true "AlwaysAllowAuthorization": true
} }
Loading…
Cancel
Save