Browse Source

[fix] 增加单独的EdiString

master
贾荣国 3 years ago
parent
commit
b37d7431e1
  1. 10
      WebApiService/src/Win_in.Sfs.Scp.WebApi.Application.Contracts/Asns/IX12AsnAppService.cs
  2. 26
      WebApiService/src/Win_in.Sfs.Scp.WebApi.Application/Asns/X12AsnAppService.cs
  3. 10
      WebApiService/src/Win_in.Sfs.Scp.WebApi.Application/WebApiApplicationAutoMapperProfile.cs
  4. 14
      WebApiService/src/Win_in.Sfs.Scp.WebApi.Domain/Asns/X12Asn.cs
  5. 3
      WebApiService/src/Win_in.Sfs.Scp.WebApi.EntityFrameworkCore/DbContext/WebApiDbContextModelCreatingExtensions.cs
  6. 3011
      WebApiService/src/Win_in.Sfs.Scp.WebApi.EntityFrameworkCore/Migrations/20220520062632_X12Asn5.Designer.cs
  7. 33
      WebApiService/src/Win_in.Sfs.Scp.WebApi.EntityFrameworkCore/Migrations/20220520062632_X12Asn5.cs
  8. 9
      WebApiService/src/Win_in.Sfs.Scp.WebApi.EntityFrameworkCore/Migrations/WebApiDbContextModelSnapshot.cs
  9. 10
      WebApiService/src/Win_in.Sfs.Scp.WebApi.HttpApi.Host/AsnBackgroundWorker/AsnBackgroundWorker.cs

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

@ -16,15 +16,15 @@ namespace Win_in.Sfs.Scp.WebApi
{
Task<List<X12AsnDTO>> GetUnreadListAsync(string site, int count,bool autoUpdateStatus);
Task<List<X12AsnDTO>> GetListAsync(long beginUid,long endUid);
Task<List<X12AsnDTO>> GetListAsync(string site, long beginUid,long endUid);
Task<List<X12AsnDTO>> GetListAsync(DateTime beginDate, DateTime endDate);
Task<List<X12AsnDTO>> GetListAsync(string site, DateTime beginDate, DateTime endDate);
Task<X12AsnDTO> GetAsync(long uid);
Task<X12AsnDTO> GetAsync(string site, long uid);
Task<X12AsnDTO> GetAsync(string number);
Task<X12AsnDTO> GetAsync(string site, string number);
Task<X12AsnDTO> UpdateStatusAsync(string number, EnumExchangeDataStatus status);
Task<X12AsnDTO> UpdateStatusAsync(string site, string number, EnumExchangeDataStatus status);
}

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

@ -89,14 +89,14 @@ namespace Win_in.Sfs.Scp.WebApi
[HttpGet]
[Route("between-id")]
public async Task<List<X12AsnDTO>> GetListAsync(long beginUid, long endUid)
public async Task<List<X12AsnDTO>> GetListAsync(string site, long beginUid, long endUid)
{
if (endUid < beginUid)
{
throw new BadHttpRequestException("beginUid is bigger than endUid");
}
var entities = await _x12AsnRepository.GetListAsync(p => 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);
@ -106,14 +106,14 @@ namespace Win_in.Sfs.Scp.WebApi
[HttpGet]
[Route("between-date")]
public async Task<List<X12AsnDTO>> GetListAsync(DateTime beginDate, DateTime endDate)
public async Task<List<X12AsnDTO>> GetListAsync(string site, DateTime beginDate, DateTime endDate)
{
if (endDate < beginDate)
{
throw new BadHttpRequestException("beginDate is after endDate");
}
var entities = await _x12AsnRepository.GetListAsync(p => 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);
@ -122,13 +122,13 @@ namespace Win_in.Sfs.Scp.WebApi
[HttpGet]
[Route("by-id")]
public async Task<X12AsnDTO> GetAsync(long uid)
public async Task<X12AsnDTO> GetAsync(string site, long uid)
{
var entity = await _x12AsnRepository.FirstOrDefaultAsync(p => p.UID == uid);
var entity = await _x12AsnRepository.FirstOrDefaultAsync(p => p.Site == site && p.UID == uid);
if (entity == null)
{
throw new BadHttpRequestException($"ASN of {uid} is not found");
throw new BadHttpRequestException($"ASN of {uid} in {site} is not found");
}
var dto = BuildDto(entity);
@ -138,13 +138,13 @@ namespace Win_in.Sfs.Scp.WebApi
[HttpGet]
[Route("by-number")]
public async Task<X12AsnDTO> GetAsync(string number)
public async Task<X12AsnDTO> GetAsync(string site, string number)
{
var entity = await _x12AsnRepository.FirstOrDefaultAsync(p => p.BillNum == number);
var entity = await _x12AsnRepository.FirstOrDefaultAsync(p => p.Site == site && p.BillNum == number);
if (entity == null)
{
throw new BadHttpRequestException($"ASN of {number} is not found");
throw new BadHttpRequestException($"ASN of {number} in {site} is not found");
}
var dto = BuildDto(entity);
@ -155,14 +155,14 @@ namespace Win_in.Sfs.Scp.WebApi
[HttpPost]
[Route("update-status")]
public async Task<X12AsnDTO> UpdateStatusAsync(string number, EnumExchangeDataStatus status)
public async Task<X12AsnDTO> UpdateStatusAsync(string site, string number, EnumExchangeDataStatus status)
{
var entity = await _x12AsnRepository.FirstOrDefaultAsync(p => p.BillNum == number);
var entity = await _x12AsnRepository.FirstOrDefaultAsync(p => p.Site == site && p.BillNum == number);
if (entity == null)
{
throw new BadHttpRequestException($"ASN of {number} is not found");
throw new BadHttpRequestException($"ASN of {number} in {site} is not found");
}
var result = await _x12AsnRepository.UpdateStatusAsync(entity.Id, status);

10
WebApiService/src/Win_in.Sfs.Scp.WebApi.Application/WebApiApplicationAutoMapperProfile.cs

@ -106,15 +106,9 @@ namespace Win_in.Sfs.Scp.WebApi
{
CreateMap<X12Asn, X12AsnDTO>()
.Ignore(p => p.Scpedi)
.AfterMap(ConvertToScpEdi)
.AfterMap((src, dto) => dto.Scpedi = src.EdiString?.Split("\r\n").ToList())
;
}
private void ConvertToScpEdi(X12Asn src, X12AsnDTO dest)
{
var asnX12 = JsonSerializer.Deserialize<ASN_X12_856_3060>(src.DataContent)?.ToString();
var list = asnX12?.Split("\r\n").ToList();
dest.Scpedi = list;
}
}
}

14
WebApiService/src/Win_in.Sfs.Scp.WebApi.Domain/Asns/X12Asn.cs

@ -37,9 +37,14 @@ public class X12Asn: EntityBase<Guid>
public EnumExchangeDataStatus Status { get; protected internal set; } = 0;
/// <summary>
/// 数据内容
/// Json字符串
/// </summary>
public string DataContent { get; set; }
public string JsonString { get; set; }
/// <summary>
/// Edi字符串
/// </summary>
public string EdiString { get; set; }
/// <summary>
/// 目标系统
@ -83,13 +88,14 @@ public class X12Asn: EntityBase<Guid>
}
public X12Asn(long uid,string site,string billNum,string dataContent,DateTime effectiveDate)
public X12Asn(long uid,string site,string billNum,string jsonString,string ediString,DateTime effectiveDate)
{
UID = uid;
Site = site;
BillNum = billNum;
DataType = "ASN";
DataContent = dataContent;
JsonString = jsonString;
EdiString = ediString;
EffectiveDate = effectiveDate;
DestinationSystem = "QAD";
SourceSystem = "SCP";

3
WebApiService/src/Win_in.Sfs.Scp.WebApi.EntityFrameworkCore/DbContext/WebApiDbContextModelCreatingExtensions.cs

@ -292,7 +292,8 @@ namespace Win_in.Sfs.Scp.WebApi.EntityFrameworkCore
b.Property(q => q.Status).IsRequired();
b.Property(q => q.ErrorCode).IsRequired();
b.Property(q => q.ErrorMessage);
b.Property(q => q.DataContent);
b.Property(q => q.JsonString);
b.Property(q => q.EdiString);
b.Property(q => q.DataType).IsRequired().HasMaxLength(16);
b.Property(q => q.SourceSystem).IsRequired().HasMaxLength(16);
b.Property(q => q.WriteTime).IsRequired();

3011
WebApiService/src/Win_in.Sfs.Scp.WebApi.EntityFrameworkCore/Migrations/20220520062632_X12Asn5.Designer.cs

File diff suppressed because it is too large

33
WebApiService/src/Win_in.Sfs.Scp.WebApi.EntityFrameworkCore/Migrations/20220520062632_X12Asn5.cs

@ -0,0 +1,33 @@
using Microsoft.EntityFrameworkCore.Migrations;
namespace Win_in.Sfs.Scp.WebApi.Migrations
{
public partial class X12Asn5 : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.RenameColumn(
name: "DataContent",
table: "WebApi_X12Asn",
newName: "JsonString");
migrationBuilder.AddColumn<string>(
name: "EdiString",
table: "WebApi_X12Asn",
type: "nvarchar(max)",
nullable: true);
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "EdiString",
table: "WebApi_X12Asn");
migrationBuilder.RenameColumn(
name: "JsonString",
table: "WebApi_X12Asn",
newName: "DataContent");
}
}
}

9
WebApiService/src/Win_in.Sfs.Scp.WebApi.EntityFrameworkCore/Migrations/WebApiDbContextModelSnapshot.cs

@ -1952,9 +1952,6 @@ namespace Win_in.Sfs.Scp.WebApi.Migrations
.HasColumnType("uniqueidentifier")
.HasColumnName("CreatorId");
b.Property<string>("DataContent")
.HasColumnType("nvarchar(max)");
b.Property<string>("DataType")
.IsRequired()
.HasMaxLength(16)
@ -1965,6 +1962,9 @@ namespace Win_in.Sfs.Scp.WebApi.Migrations
.HasMaxLength(16)
.HasColumnType("nvarchar(16)");
b.Property<string>("EdiString")
.HasColumnType("nvarchar(max)");
b.Property<DateTime>("EffectiveDate")
.HasColumnType("datetime2(7)");
@ -1978,6 +1978,9 @@ namespace Win_in.Sfs.Scp.WebApi.Migrations
.HasColumnType("nvarchar(max)")
.HasColumnName("ExtraProperties");
b.Property<string>("JsonString")
.HasColumnType("nvarchar(max)");
b.Property<DateTime?>("ReadTime")
.HasColumnType("datetime2");

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

@ -81,13 +81,13 @@ public class AsnBackgroundWorker : AsyncPeriodicBackgroundWorkerBase
foreach (var asn in scpAsns)
{
var barcodes = await scpAsnManager.GetBarcodesAsync(site,asn.AsnBillNum);
var asnFactory = new AsnFactory();
var asnX128563060 = asnFactory.CreateAsnX128563060(asn, barcodes);
var dataContent = JsonSerializer.Serialize(asnX128563060);
var asnX12 = new X12Asn(asn.Id, asn.Site, asn.AsnBillNum, dataContent, asn.ShipTime ?? DateTime.Today);
var jsonString = JsonSerializer.Serialize(asnX128563060);
var ediString = asnX128563060.ToString();
var asnX12 = new X12Asn(asn.Id, asn.Site, asn.AsnBillNum, jsonString,ediString, asn.ShipTime ?? DateTime.Today);
asnX12List.Add(asnX12);
Logger.LogInformation($"{site}:{asn.Id} {asn.AsnBillNum} was loaded");
}
}
}
@ -109,7 +109,7 @@ public class AsnBackgroundWorker : AsyncPeriodicBackgroundWorkerBase
}
else
{
exist.DataContent = x12Asn.DataContent;
exist.JsonString = x12Asn.JsonString;
exist.Reset();
await x12AsnRepository.UpdateAsync(exist);
}

Loading…
Cancel
Save