Browse Source

[fix]无PO ASN提供专用格式

master
贾荣国 2 years ago
parent
commit
bb6dbabc8c
  1. 149
      WebApiService/src/Win_in.Sfs.Scp.WebApi.Agent/AsnBackgroundWorker/AsnBackgroundWorker.cs
  2. 113
      WebApiService/src/Win_in.Sfs.Scp.WebApi.Application.Contracts/Asns/AsnDetDTO.cs
  3. 98
      WebApiService/src/Win_in.Sfs.Scp.WebApi.Application.Contracts/Asns/AsnMstrDTO.cs
  4. 26
      WebApiService/src/Win_in.Sfs.Scp.WebApi.Application.Contracts/Asns/IAsnAppService.cs
  5. 1
      WebApiService/src/Win_in.Sfs.Scp.WebApi.Application.Contracts/Asns/IX12AsnAppService.cs
  6. 1
      WebApiService/src/Win_in.Sfs.Scp.WebApi.Application.Contracts/RouteConsts.cs
  7. 325
      WebApiService/src/Win_in.Sfs.Scp.WebApi.Application/Asns/AsnAppService.cs
  8. 29
      WebApiService/src/Win_in.Sfs.Scp.WebApi.Application/Asns/X12AsnAppService.cs
  9. 4
      WebApiService/src/Win_in.Sfs.Scp.WebApi.Application/Win_in.Sfs.Scp.WebApi.Application.csproj
  10. 118
      WebApiService/src/Win_in.Sfs.Scp.WebApi.Domain.Shared/NoPoASN/AsnDet.cs
  11. 96
      WebApiService/src/Win_in.Sfs.Scp.WebApi.Domain.Shared/NoPoASN/AsnMstr.cs
  12. 8
      WebApiService/src/Win_in.Sfs.Scp.WebApi.Domain.Shared/ScpWebApiConsts.cs
  13. 35
      WebApiService/src/Win_in.Sfs.Scp.WebApi.Domain.Shared/Win_in - Backup.Sfs.Scp.WebApi.Domain.Shared.csproj
  14. 16
      WebApiService/src/Win_in.Sfs.Scp.WebApi.Domain/Asns/IAsnRepository.cs
  15. 2
      WebApiService/src/Win_in.Sfs.Scp.WebApi.Domain/Asns/IX12AsnRepository.cs
  16. 4
      WebApiService/src/Win_in.Sfs.Scp.WebApi.Domain/Asns/X12Asn.cs
  17. 2
      WebApiService/src/Win_in.Sfs.Scp.WebApi.EntityFrameworkCore/DbContext/IWebApiDbContext.cs
  18. 1
      WebApiService/src/Win_in.Sfs.Scp.WebApi.EntityFrameworkCore/DbContext/WebApiDbContext.cs
  19. 66
      WebApiService/src/Win_in.Sfs.Scp.WebApi.EntityFrameworkCore/DbContext/WebApiDbContextModelCreatingExtensions.cs
  20. 69
      WebApiService/src/Win_in.Sfs.Scp.WebApi.EntityFrameworkCore/Repositories/AsnRepository.cs
  21. 24
      WebApiService/src/Win_in.Sfs.Scp.WebApi.EntityFrameworkCore/Repositories/X12AsnRepository.cs

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

@ -1,8 +1,10 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text.Json;
using System.Threading.Tasks;
using AutoMapper;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
@ -13,26 +15,33 @@ using Volo.Abp.Data;
using Volo.Abp.Domain.Entities;
using Volo.Abp.Domain.Repositories;
using Volo.Abp.MultiTenancy;
using Volo.Abp.ObjectMapping;
using Volo.Abp.TenantManagement;
using Volo.Abp.Threading;
using Volo.Abp.Uow;
using Win_in.Sfs.Scp.v1.Domain;
using Win_in.Sfs.Scp.v1.Domain.Asns;
using Win_in.Sfs.Scp.WebApi.Agent;
using Win_in.Sfs.Scp.WebApi.Asns;
using Win_in.Sfs.Scp.WebApi.EntityFrameworkCore;
using IObjectMapper = Volo.Abp.ObjectMapping.IObjectMapper;
namespace Win_in.Sfs.Scp.WebApi
{
public class AsnBackgroundWorker : AsyncPeriodicBackgroundWorkerBase
{
private readonly IOptions<AsnOptions> _options;
private readonly IObjectMapper _objectMapper;
public AsnBackgroundWorker(
AbpAsyncTimer timer,
IOptions<AsnOptions> options,
IServiceScopeFactory serviceScopeFactory
IServiceScopeFactory serviceScopeFactory,
IObjectMapper objectMapper
) : base(timer, serviceScopeFactory)
{
_options = options;
_objectMapper = objectMapper;
Timer.Period = options.Value.PeriodSeconds * 1000; //default 5 minutes
}
@ -49,15 +58,16 @@ namespace Win_in.Sfs.Scp.WebApi
//Resolve dependencies
var scpAsnManager = workerContext.ServiceProvider.GetRequiredService<IScpAsnManager>();
var x12AsnRepository = workerContext.ServiceProvider.GetRequiredService<IX12AsnRepository>();
// var noPoAsnRepository = workerContext.ServiceProvider.GetRequiredService<IAsnRepository>();
var tenantStore = workerContext.ServiceProvider.GetRequiredService<ITenantStore>();
var currentTenant = workerContext.ServiceProvider.GetRequiredService<ICurrentTenant>();
var dataFilter = workerContext.ServiceProvider.GetRequiredService<IDataFilter>();
//Do the work
var asnX12List = new List<X12Asn>();
foreach (var site in _options.Value.Sites)
{
var asnX12List = new List<X12Asn>();
// var noPoAsnList = new List<AsnMstr>();
var siteCode = site.Code;
var siteMinUid = site.MinUid;
try
@ -90,14 +100,17 @@ namespace Win_in.Sfs.Scp.WebApi
foreach (var asn in scpAsns)
{
var barcodes = await scpAsnManager.GetBarcodesAsync(siteCode, asn.AsnBillNum);
var asnFactory = new AsnFactory();
var asnX128563060 =
asnFactory.CreateAsnX128563060(site.Receiver, asn, barcodes);
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);
if (string.IsNullOrEmpty(asn.PoBillNum)) //without PO
{
var noPoAsn = CreateNoPoAsn(asn, barcodes);
asnX12List.Add(noPoAsn);
}
else //with PO
{
var asnX12 = CreateX12Asn(site, asn, barcodes);
asnX12List.Add(asnX12);
}
Logger.LogInformation($"{siteCode}:{asn.Id} {asn.AsnBillNum} was loaded");
}
}
@ -108,9 +121,117 @@ namespace Win_in.Sfs.Scp.WebApi
Logger.LogException(ex);
}
await AddX12AsnsAsync(asnX12List, x12AsnRepository);
// await AddNoPoAsnsAsync(noPoAsnList,noPoAsnRepository);
}
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.AskBillNum,
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,
};
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,
};
asnMstr.Details.Add(det);
}
var jsonString = JsonSerializer.Serialize(asnMstr);
var ediString = asnMstr.ToString();
var asnX12 = new X12Asn(asn.Id, asn.Site, asn.AsnBillNum, ScpWebApiConsts.NO_PO_ASN, jsonString, ediString,
asn.ShipTime ?? DateTime.Today);
return asnX12;
}
private static X12Asn CreateX12Asn(AsnOptions.Site site, TB_ASN asn, List<TS_BARCODE> barcodes)
{
var asnFactory = new AsnFactory();
var asnX128563060 =
asnFactory.CreateAsnX128563060(site.Receiver, asn, barcodes);
var jsonString = JsonSerializer.Serialize(asnX128563060);
var ediString = asnX128563060.ToString();
var asnX12 = new X12Asn(asn.Id, asn.Site, asn.AsnBillNum, ScpWebApiConsts.ASN, jsonString, ediString,
asn.ShipTime ?? DateTime.Today);
return asnX12;
}
/*
private async Task AddNoPoAsnsAsync(List<AsnMstr> noPoAsnList, IAsnRepository noPoAsnRepository)
{
foreach (var asn in noPoAsnList)
{
var exist = await noPoAsnRepository.FirstOrDefaultAsync(
p => p.UID == asn.UID && p.Site == asn.Site);
if (exist == null)
{
await noPoAsnRepository.InsertAsync(asn);
}
else
{
exist.RpNbr = asn.RpNbr;
exist.Contacts = asn.Contacts;
exist.Phone = asn.Phone;
exist.TruckNbr = asn.TruckNbr;
exist.Whse = asn.Whse;
exist.Dock = asn.Dock;
exist.ShipDate = asn.ShipDate;
exist.DueDate = asn.DueDate;
exist.TimeWindow = asn.TimeWindow;
exist.Remark = asn.Remark;
exist.Details = asn.Details;
exist.SetEffectiveDate(asn.EffectiveDate);
exist.Reset();
await noPoAsnRepository.UpdateAsync(exist);
}
}
}
*/
private static async Task AddX12AsnsAsync(List<X12Asn> asnX12List, IX12AsnRepository x12AsnRepository)
{
foreach (var x12Asn in asnX12List)
{
var exist = await x12AsnRepository.FirstOrDefaultAsync(
@ -122,15 +243,11 @@ namespace Win_in.Sfs.Scp.WebApi
else
{
exist.JsonString = x12Asn.JsonString;
exist.EdiString = x12Asn.EdiString;
exist.Reset();
await x12AsnRepository.UpdateAsync(exist);
}
}
await x12AsnRepository.InsertManyAsync(asnX12List, true);
Logger.LogInformation("Get ASN from SCP: Complete");
}
}
}

113
WebApiService/src/Win_in.Sfs.Scp.WebApi.Application.Contracts/Asns/AsnDetDTO.cs

@ -0,0 +1,113 @@
using System;
using System.ComponentModel.DataAnnotations;
using Win_in.Sfs.Scp.WebApi.Domain.Shared;
namespace Win_in.Sfs.Scp.WebApi
{
/// <summary>
/// QAD发货单明细(ASN detail) SupplierAsnDetailInput
/// </summary>
public class AsnDetDTO :EntityDtoBase<Guid>
{
/// <summary>
/// 送货单号(ASN number)(Asn number)
/// </summary>
public virtual string AsnNbr { get; set; }
/// <summary>
/// 采购订单号(Purchase order number)
/// </summary>
public virtual string PoNbr { get; set; }
/// <summary>
/// 采购订单行(Purchase order line)
/// </summary>
public virtual int PoLine { get; set; }
/// <summary>
/// 物料号(Part number)(Part number)
/// </summary>
public virtual string PartCode { get; set; }
/// <summary>
/// 批次(Lot number)
/// </summary>
public virtual string Lot { get; set; }
/// <summary>
/// 送货总量(Quantity)
/// </summary>
public virtual decimal Qty { get; set; }
/// <summary>
/// 生产日期(Production date)
/// </summary>
public virtual DateTime? ProductionDate { get; set; }
/// <summary>
/// 器具型号(Ware class)
/// </summary>
public virtual string WareClass { get; set; }
/// <summary>
/// 器具号(Ware code)
/// </summary>
public virtual string WareCode { get; set; }
/// <summary>
/// 标准包装量(Standard pack quantity)
/// </summary>
public virtual decimal StdPackQty { get; set; }
/// <summary>
/// 采购单位(Purchase um)
/// </summary>
public virtual string PoUm { get; set; }
/// <summary>
/// 基本单位(Base um)
/// </summary>
public virtual string LocUm { get; set; }
/// <summary>
/// 转换率(Um conversion)
/// </summary>
public virtual decimal UmConv { get; set; }
/// <summary>
/// 物料类型(Part type)
/// </summary>
public virtual string PartType { get; set; }
/// <summary>
/// 供应商批号(Vendor batch)
/// </summary>
public virtual string Supplierlot { get; set; }
/// <summary>
/// 状态(Status)
/// </summary>
public virtual string Status { get; set; }
/// <summary>
/// 标签代码(Label code)
/// </summary>
public virtual string LabelCode { get; set; }
/// <summary>
/// 完整条码数据(Full barcode string)
/// </summary>
public virtual string EntireBarCode { get; set; }
/// <summary>
/// 托盘标签代码(Pallet label code)
/// </summary>
public virtual string PalletLabelCode { get; set; }
/// <summary>
/// 备注(Remark)
/// </summary>
public virtual string Remark { get; set; }
}
}

98
WebApiService/src/Win_in.Sfs.Scp.WebApi.Application.Contracts/Asns/AsnMstrDTO.cs

@ -0,0 +1,98 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using Win_in.Sfs.Scp.WebApi.Asns;
using Win_in.Sfs.Scp.WebApi.Domain.Shared;
namespace Win_in.Sfs.Scp.WebApi
{
/// <summary>
/// QAD发货单主表(ASN Master) SupplierAsnCreateInput ISupplierAsnAppService
/// </summary>
public class AsnMstrDTO:EntityDtoBase<Guid>
{
/// <summary>
///
/// </summary>
public virtual long UID { get; set; }
/// <summary>
/// 公司(Company code)
/// </summary>
public virtual string Company { get; set; }
/// <summary>
/// 工厂(Site)
/// </summary>
public virtual string Site { get; set; }
/// <summary>
/// 送货单号(ASN number)
/// </summary>
public virtual string AsnNbr { get; set; }
/// <summary>
/// 采购订单号(Purchase order number)
/// </summary>
public virtual string PoNbr { get; set; }
/// <summary>
/// 供应商(Vendor)
/// </summary>
public virtual string VendorCode { get; set; }
/// <summary>
/// 联系人(Contacts name)
/// </summary>
public virtual string Contacts { get; set; }
/// <summary>
/// 联系电话(Phone)
/// </summary>
public virtual string Phone { get; set; }
/// <summary>
/// 车牌号(Truck license plate number)
/// </summary>
public virtual string TruckNbr { get; set; }
/// <summary>
/// 仓库(Warehouse)(Warehouse)
/// </summary>
public virtual string Whse { get; set; }
/// <summary>
/// 收货口(Dock)
/// </summary>
public virtual string Dock { get; set; }
/// <summary>
/// 发货日期(Shipping date)
/// </summary>
public virtual DateTime? ShipDate { get; set; }
/// <summary>
/// 采购单到期日(Due date)
/// </summary>
public virtual DateTime? DueDate { get; set; }
/// <summary>
/// 时间窗口
/// </summary>
public string TimeWindow { get; set; }
/// <summary>
/// 状态
/// </summary>
public string Status { get; set; }
/// <summary>
/// 备注(Remark)
/// </summary>
public virtual string Remark { get; set; }
public virtual List<AsnDetDTO> Details { get; set; } = new List<AsnDetDTO>();
}
}

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

@ -0,0 +1,26 @@
using System;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services;
namespace Win_in.Sfs.Scp.WebApi.Asns
{
/// <summary>
/// QAD发货单(ASN Master)
/// </summary>
public interface IAsnAppService : IApplicationService
{
Task<ListResultDto<AsnMstrDTO>> GetUnreadListAsync(string site, int count, bool autoUpdateStatus);
Task<ListResultDto<AsnMstrDTO>> GetListAsync(string site, long beginUid, long endUid);
Task<ListResultDto<AsnMstrDTO>> GetListAsync(string site, DateTime beginDate, DateTime endDate);
Task<ActionResult<AsnMstrDTO>> GetAsync(string site, long uid);
Task<ActionResult<AsnMstrDTO>> GetAsync(string site, string number);
Task<ActionResult<AsnMstrDTO>> UpdateStatusAsync(string site, string number, EnumExchangeDataStatus status);
}
}

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

@ -15,6 +15,7 @@ namespace Win_in.Sfs.Scp.WebApi
public interface IX12AsnAppService : IReadOnlyAppService<X12AsnDTO,Guid,RequestDTO>
{
Task<ListResultDto<X12AsnDTO>> GetUnreadListAsync(string site, int count,bool autoUpdateStatus);
Task<ListResultDto<X12AsnDTO>> GetNoPoUnreadListAsync(string site, int count, bool autoUpdateStatus);
Task<ListResultDto<X12AsnDTO>> GetListAsync(string site, long beginUid,long endUid);

1
WebApiService/src/Win_in.Sfs.Scp.WebApi.Application.Contracts/RouteConsts.cs

@ -11,5 +11,6 @@ namespace Win_in.Sfs.Scp.WebApi
public const string Supplier = "api/scp/supplier";
public const string UnplannedReceipt = "api/scp/unplanned-receipt";
public const string X12Asn = "api/scp/asn";
public const string AsnMstr = "api/scp/nopo-asn";
}
}

325
WebApiService/src/Win_in.Sfs.Scp.WebApi.Application/Asns/AsnAppService.cs

@ -0,0 +1,325 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text.Json;
using System.Threading.Tasks;
using System.Threading.Tasks.Dataflow;
using AutoMapper;
using AutoMapper.Configuration;
using FluentValidation;
using Microsoft.AspNetCore.Http;
using Microsoft.EntityFrameworkCore;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services;
using Volo.Abp.Domain.Repositories;
using Volo.Abp.Uow;
using Win_in.Sfs.Scp.v1.Domain;
using Microsoft.Extensions.Configuration;
using Volo.Abp.Clients;
using Volo.Abp.MultiTenancy;
using Volo.Abp.Validation;
using IConfiguration = Microsoft.Extensions.Configuration.IConfiguration;
using Volo.Abp.TenantManagement;
using Win_in.Sfs.Scp.WebApi.Asns;
using Volo.Abp.Domain.Entities;
using System.Security.Cryptography;
using IdentityModel;
using Microsoft.Extensions.Options;
using Volo.Abp;
namespace Win_in.Sfs.Scp.WebApi
{
/// <summary>
/// ASN服务(AsnMstr Service)
/// </summary>
[Authorize]
[Route(RouteConsts.AsnMstr)]
[ApiExplorerSettings(GroupName = SwaggerGroupConsts.ScpWebApi)]
public class AsnAppService : ReadOnlyAppService<AsnMstr, AsnMstrDTO, Guid, RequestDTO>, IAsnAppService
{
private readonly IAsnRepository _asnRepository;
private readonly ITenantRepository _tenantRepository;
private readonly IOptions<AsnOptions> _options;
public AsnAppService(
IAsnRepository repository
, ITenantRepository tenantRepository
, IOptions<AsnOptions> options
) : base(repository)
{
_asnRepository = repository;
_tenantRepository = tenantRepository;
_options = options;
}
/// <summary>
/// 按ID获取ASN (Get AsnMstr by ID)
/// </summary>
/// <param name="id">唯一ID(unique ID)</param>
/// <returns></returns>
[HttpGet]
[Route("{id}")]
[HiddenApi]
public override async Task<AsnMstrDTO> GetAsync(Guid id)
{
return await base.GetAsync(id);
}
/// <summary>
/// 按条件获取ASN分页列表 (Get AsnMstr paged list by request condition)
/// </summary>
/// <param name="requestDTO">请求条件DTO(Request condition DTO)</param>
/// <returns></returns>
[HttpGet]
[Route("paged-list")]
[HiddenApi]
public override async Task<PagedResultDto<AsnMstrDTO>> GetListAsync(RequestDTO requestDTO)
{
return await base.GetListAsync(requestDTO);
}
/// <summary>
/// 获取未读ASN列表(Get unread AsnMstr list)
/// </summary>
/// <param name="site">地点(Site)</param>
/// <param name="count">数量(Count)</param>
/// <param name="autoUpdateStatus">是否自动更新状态(Auto update data status to finish)</param>
/// <returns></returns>
[HttpGet]
[Route("unread-list")]
public async Task<ListResultDto<AsnMstrDTO>> GetUnreadListAsync(string site, int count, bool autoUpdateStatus)
{
try
{
Validator.CheckSite(_tenantRepository, site);
if (count < 1 || count > _options.Value.MaxCount)
{
throw new UserFriendlyException($"Count must between 1 and {_options.Value.MaxCount}");
}
}
catch (Exception ex)
{
throw new AbpValidationException(new List<ValidationResult>
{
new(ex.Message)
});
}
var entities = await _asnRepository.GetUnreadListAsync(site, count, autoUpdateStatus);
var dtos = BuildDtos(entities);
return new ListResultDto<AsnMstrDTO>(dtos);
}
/// <summary>
/// 根据UID范围获取ASN列表(Get AsnMstr list by UID range)
/// </summary>
/// <param name="site">地点(Site)</param>
/// <param name="beginUid">开始UID(Begin UID)</param>
/// <param name="endUid">结束UID(End UID)</param>
/// <returns></returns>
/// <exception cref="BadHttpRequestException"></exception>
[HttpGet]
[Route("between-uid")]
public async Task<ListResultDto<AsnMstrDTO>> GetListAsync(string site, long beginUid, long endUid)
{
try
{
Validator.CheckSite(_tenantRepository, site);
if (endUid < beginUid)
{
throw new UserFriendlyException("beginUid can not bigger than endUid");
}
}
catch (Exception ex)
{
throw new AbpValidationException(new List<ValidationResult>
{
new(ex.Message)
});
}
var entities = await _asnRepository.GetListAsync(p => p.Site == site && p.UID >= beginUid && p.UID <= endUid);
var dtos = BuildDtos(entities);
return new ListResultDto<AsnMstrDTO>(dtos);
}
/// <summary>
/// 根据日期范围获取ASN列表(Get AsnMstr list by date range)
/// </summary>
/// <param name="site">地点(Site)</param>
/// <param name="beginDate">开始日期(Begin date)</param>
/// <param name="endDate">结束日期(End date)</param>
/// <returns></returns>
/// <exception cref="BadHttpRequestException"></exception>
[HttpGet]
[Route("between-date")]
public async Task<ListResultDto<AsnMstrDTO>> GetListAsync(string site, DateTime beginDate, DateTime endDate)
{
try
{
Validator.CheckSite(_tenantRepository, site);
if (endDate < beginDate)
{
throw new UserFriendlyException("beginDate can not after endDate");
}
}
catch (Exception ex)
{
throw new AbpValidationException(new List<ValidationResult>
{
new(ex.Message)
});
}
var entities = await _asnRepository.GetListAsync(p => p.Site == site && p.EffectiveDate >= beginDate && p.EffectiveDate <= endDate);
var dtos = BuildDtos(entities);
return new ListResultDto<AsnMstrDTO>(dtos);
}
/// <summary>
/// 根据UID获取ASN(Get AsnMstr by UID)
/// </summary>
/// <param name="site">地点(Site)</param>
/// <param name="uid">UID(UID)</param>
/// <returns></returns>
/// <exception cref="BadHttpRequestException"></exception>
[HttpGet]
[Route("by-uid")]
public async Task<ActionResult<AsnMstrDTO>> GetAsync(string site, long uid)
{
AsnMstr entity;
try
{
Validator.CheckSite(_tenantRepository, site);
entity = await _asnRepository.FirstOrDefaultAsync(p => p.Site == site && p.UID == uid);
if (entity == null)
{
throw new UserFriendlyException($"ASN of {uid} in {site} is not found");
}
}
catch (Exception ex)
{
throw new AbpValidationException(new List<ValidationResult>
{
new(ex.Message)
});
}
var dto = BuildDto(entity);
return dto;
}
/// <summary>
/// 根据单据编号获取ANS(Get AsnMstr by asn number)
/// </summary>
/// <param name="site">地点(Site)</param>
/// <param name="number">单据编号(Asn number)</param>
/// <returns></returns>
/// <exception cref="BadHttpRequestException"></exception>
[HttpGet]
[Route("by-number")]
public async Task<ActionResult<AsnMstrDTO>> GetAsync(string site, string number)
{
AsnMstr entity;
try
{
Validator.CheckSite(_tenantRepository, site);
entity = await _asnRepository.FirstOrDefaultAsync(p => p.Site == site && p.AsnNbr == number);
if (entity == null)
{
throw new UserFriendlyException($"ASN of {number} in {site} is not found");
}
}
catch (Exception ex)
{
throw new AbpValidationException(new List<ValidationResult>
{
new(ex.Message)
});
}
var dto = BuildDto(entity);
return dto;
}
/// <summary>
/// 根据单据编号更新ASN状态(Update AsnMstr Status by asn number)
/// </summary>
/// <param name="site">地点(Site)</param>
/// <param name="number">单据编号(Asn number)</param>
/// <param name="status">状态(Status)
/// 0: 新增(new)
/// 1: 处理中(Processing)
/// 2: 完成(Finish)
/// 9: 搁置(Hold)
/// -1: 错误(Error)
/// </param>
/// <returns></returns>
/// <exception cref="BadHttpRequestException"></exception>
[HttpPost]
[Route("update-status")]
public async Task<ActionResult<AsnMstrDTO>> UpdateStatusAsync(string site, string number, EnumExchangeDataStatus status)
{
AsnMstr entity;
try
{
Validator.CheckSite(_tenantRepository, site);
entity = await _asnRepository.FirstOrDefaultAsync(p => p.Site == site && p.AsnNbr == number);
if (entity == null)
{
throw new UserFriendlyException($"ASN of {number} in {site} is not found");
}
}
catch (Exception ex)
{
throw new AbpValidationException(new List<ValidationResult>
{
new(ex.Message)
});
}
var result = await _asnRepository.UpdateStatusAsync(entity.Id, status);
var dto = BuildDto(result);
return dto;
}
private List<AsnMstrDTO> BuildDtos(List<AsnMstr> entities)
{
var dtos = ObjectMapper.Map<List<AsnMstr>, List<AsnMstrDTO>>(entities);
return dtos;
}
private AsnMstrDTO BuildDto(AsnMstr entity)
{
var dto = ObjectMapper.Map<AsnMstr, AsnMstrDTO>(entity);
return dto;
}
}
}

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

@ -121,6 +121,35 @@ namespace Win_in.Sfs.Scp.WebApi
}
[HttpGet]
[Route("nopo-unread-list")]
public async Task<ListResultDto<X12AsnDTO>> GetNoPoUnreadListAsync(string site, int count, bool autoUpdateStatus)
{
try
{
Validator.CheckSite(_tenantRepository, site);
if (count < 1 || count > _options.Value.MaxCount)
{
throw new UserFriendlyException($"Count must between 1 and {_options.Value.MaxCount}");
}
}
catch (Exception ex)
{
throw new AbpValidationException(new List<ValidationResult>
{
new(ex.Message)
});
}
var entities = await _x12AsnRepository.GetNoPoUnreadListAsync(site, count, autoUpdateStatus);
var dtos = BuildDtos(entities);
return new ListResultDto<X12AsnDTO>(dtos);
}
/// <summary>
/// 根据UID范围获取ASN列表(Get X12Asn list by UID range)
/// </summary>

4
WebApiService/src/Win_in.Sfs.Scp.WebApi.Application/Win_in.Sfs.Scp.WebApi.Application.csproj

@ -12,6 +12,10 @@
<DocumentationFile>..\Win_in.Sfs.Scp.WebApi.HttpApi.Host\bin\Debug\net5.0\Win_in.Sfs.Scp.WebApi.Application.xml</DocumentationFile>
</PropertyGroup>
<ItemGroup>
<Compile Remove="Asns\AsnAppService.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Win_in.Sfs.Scp.v1.Domain\Win_in.Sfs.Scp.v1.Domain.csproj" />

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

@ -0,0 +1,118 @@
using System;
using Volo.Abp.Domain.Entities.Auditing;
namespace Win_in.Sfs.Scp.WebApi
{
/// <summary>
/// QAD发货单明细(ASN detail) SupplierAsnDetailInput
/// </summary>
public class AsnDet : CreationAuditedEntity<Guid>
{
/// <summary>
/// 自增长数字主键
/// </summary>
//public virtual int uid { get; set; }
/// <summary>
/// 送货单号
/// </summary>
public virtual string AsnNbr { get; set; }
/// <summary>
/// 采购订单号
/// </summary>
public virtual string PoNbr { get; set; }
/// <summary>
/// 采购订单行
/// </summary>
public virtual int PoLine { get; set; }
/// <summary>
/// 物料号
/// </summary>
public virtual string PartCode { get; set; }
/// <summary>
/// 批次
/// </summary>
public virtual string Lot { get; set; }
/// <summary>
/// 送货总量
/// </summary>
public virtual decimal Qty { get; set; }
/// <summary>
/// 生产日期
/// </summary>
public virtual DateTime? ProductionDate { get; set; }
/// <summary>
/// 器具型号
/// </summary>
public virtual string WareClass { get; set; }
/// <summary>
/// 器具号
/// </summary>
public virtual string WareCode { get; set; }
/// <summary>
/// 标准包装量
/// </summary>
public virtual decimal StdPackQty { get; set; }
/// <summary>
/// 采购单位
/// </summary>
public virtual string PoUm { get; set; }
/// <summary>
/// 基本单位
/// </summary>
public virtual string LocUm { get; set; }
/// <summary>
/// 转换率
/// </summary>
public virtual decimal UmConv { get; set; }
/// <summary>
/// 物料类型
/// </summary>
public virtual string PartType { get; set; }
/// <summary>
/// 供应商批号
/// </summary>
public virtual string Supplierlot { get; set; }
/// <summary>
/// 状态(0:Closed,1:Open)
/// </summary>
public virtual string Status { get; set; }
/// <summary>
/// 标签代码
/// </summary>
public virtual string LabelCode { get; set; }
/// <summary>
/// 完整条码数据
/// </summary>
public virtual string EntireBarCode { get; set; }
/// <summary>
/// 托盘标签代码
/// </summary>
public virtual string PalletLabelCode { get; set; }
/// <summary>
/// 备注
/// </summary>
public virtual string Remark { get; set; }
}
}

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

@ -0,0 +1,96 @@
using System;
using System.Collections.Generic;
using Win_in.Sfs.Scp.WebApi.Domain.Shared;
namespace Win_in.Sfs.Scp.WebApi
{
/// <summary>
/// QAD发货单主表(ASN Master) SupplierAsnCreateInput ISupplierAsnAppService
/// </summary>
public class AsnMstr : EntityBase<Guid>
{
/// <summary>
/// 自增长数字主键
/// </summary>
public virtual long UID { get; set; }
/// <summary>
/// 公司
/// </summary>
public virtual string Company { get; set; }
/// <summary>
/// 工厂
/// </summary>
public virtual string Site { get; set; }
/// <summary>
/// 送货单号
/// </summary>
public virtual string AsnNbr { get; set; }
/// <summary>
/// 要货计划单号
/// </summary>
public virtual string RpNbr { get; set; }
/// <summary>
/// 采购订单号
/// </summary>
public virtual string PoNbr { get; set; }
/// <summary>
/// 供应商
/// </summary>
public virtual string VendorCode { get; set; }
/// <summary>
/// 联系人
/// </summary>
public virtual string Contacts { get; set; }
/// <summary>
/// 联系电话
/// </summary>
public virtual string Phone { get; set; }
/// <summary>
/// 车牌号
/// </summary>
public virtual string TruckNbr { get; set; }
/// <summary>
/// 仓库
/// </summary>
public virtual string Whse { get; set; }
/// <summary>
/// 收货口
/// </summary>
public virtual string Dock { get; set; }
/// <summary>
/// 发货日期
/// </summary>
public DateTime? ShipDate { get; set; }
/// <summary>
/// 到货日期
/// </summary>
public DateTime? DueDate { get; set; }
/// <summary>
/// 时间窗口
/// </summary>
public string TimeWindow { get; set; }
/// <summary>
/// 备注
/// </summary>
public virtual string Remark { get; set; }
public virtual List<AsnDet> Details { get; set; } = new List<AsnDet>();
}
}

8
WebApiService/src/Win_in.Sfs.Scp.WebApi.Domain.Shared/ScpWebApiConsts.cs

@ -0,0 +1,8 @@
namespace Win_in.Sfs.Scp.WebApi
{
public class ScpWebApiConsts
{
public const string ASN = "ASN";
public const string NO_PO_ASN = "NoPoASN";
}
}

35
WebApiService/src/Win_in.Sfs.Scp.WebApi.Domain.Shared/Win_in - Backup.Sfs.Scp.WebApi.Domain.Shared.csproj

@ -0,0 +1,35 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\..\common.props" />
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<RootNamespace>Win_in.Sfs.Scp.WebApi</RootNamespace>
<GenerateEmbeddedFilesManifest>true</GenerateEmbeddedFilesManifest>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Volo.Abp.Ddd.Application.Contracts" Version="4.4.2" />
<PackageReference Include="Volo.Abp.Ddd.Domain" Version="4.4.2" />
<PackageReference Include="Volo.Abp.Validation" Version="4.4.2" />
<PackageReference Include="Volo.Abp.Identity.Domain.Shared" Version="4.4.2" />
<PackageReference Include="Volo.Abp.IdentityServer.Domain.Shared" Version="4.4.2" />
<PackageReference Include="Volo.Abp.BackgroundJobs.Domain.Shared" Version="4.4.2" />
<PackageReference Include="Volo.Abp.AuditLogging.Domain.Shared" Version="4.4.2" />
<PackageReference Include="Volo.Abp.TenantManagement.Domain.Shared" Version="4.4.2" />
<PackageReference Include="Volo.Abp.FeatureManagement.Domain.Shared" Version="4.4.2" />
<PackageReference Include="Volo.Abp.PermissionManagement.Domain.Shared" Version="4.4.2" />
<PackageReference Include="Volo.Abp.SettingManagement.Domain.Shared" Version="4.4.2" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Localization\WebApi\*.json" />
<Content Remove="Localization\WebApi\*.json" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.FileProviders.Embedded" Version="5.0.*" />
</ItemGroup>
</Project>

16
WebApiService/src/Win_in.Sfs.Scp.WebApi.Domain/Asns/IAsnRepository.cs

@ -0,0 +1,16 @@
/*
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Volo.Abp.Domain.Repositories;
namespace Win_in.Sfs.Scp.WebApi.Asns
{
public interface IAsnRepository : IRepository<AsnMstr, Guid>
{
Task<List<AsnMstr>> GetUnreadListAsync(string site, int count, bool autoUpdateStatus);
Task<AsnMstr> UpdateStatusAsync(Guid id, EnumExchangeDataStatus status);
}
}
*/

2
WebApiService/src/Win_in.Sfs.Scp.WebApi.Domain/Asns/IX12AsnRepository.cs

@ -9,5 +9,7 @@ public interface IX12AsnRepository : IRepository<X12Asn, Guid>
{
Task<List<X12Asn>> GetUnreadListAsync(string site, int count, bool autoUpdateStatus);
Task<List<X12Asn>> GetNoPoUnreadListAsync(string site, int count, bool autoUpdateStatus);
Task<X12Asn> UpdateStatusAsync(Guid id, EnumExchangeDataStatus status);
}

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

@ -90,12 +90,12 @@ public class X12Asn: EntityBase<Guid>
}
public X12Asn(long uid,string site,string billNum,string jsonString,string ediString,DateTime effectiveDate)
public X12Asn(long uid,string site,string billNum,string dataType,string jsonString,string ediString,DateTime effectiveDate)
{
UID = uid;
Site = site;
BillNum = billNum;
DataType = "ASN";
DataType = dataType;
JsonString = jsonString;
EdiString = ediString;
EffectiveDate = effectiveDate;

2
WebApiService/src/Win_in.Sfs.Scp.WebApi.EntityFrameworkCore/DbContext/IWebApiDbContext.cs

@ -19,5 +19,7 @@ namespace Win_in.Sfs.Scp.WebApi.EntityFrameworkCore
DbSet<UnplannedReceipt> UnplannedReceipts { get; set; }
DbSet<X12Asn> X12Asns { get; set; }
// DbSet<AsnMstr> AsnMstrs { get; set; }
}
}

1
WebApiService/src/Win_in.Sfs.Scp.WebApi.EntityFrameworkCore/DbContext/WebApiDbContext.cs

@ -36,6 +36,7 @@ namespace Win_in.Sfs.Scp.WebApi.EntityFrameworkCore
public virtual DbSet<X12Asn> X12Asns { get; set; }
// public virtual DbSet<AsnMstr> AsnMstrs { get; set; }
#region Entities from the modules

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

@ -49,6 +49,7 @@ namespace Win_in.Sfs.Scp.WebApi.EntityFrameworkCore
builder.ConfigurePurchaseOrderDetail(options);
builder.ConfigureUnplannedReceipt(options);
builder.ConfigureX12Asn(options);
// builder.ConfigureAsn(options);
}
/// <summary>
@ -308,6 +309,71 @@ namespace Win_in.Sfs.Scp.WebApi.EntityFrameworkCore
});
}
/*
private static void ConfigureAsn(this ModelBuilder builder, WebApiModelBuilderConfigurationOptions options)
{
builder.Entity<AsnMstr>(b =>
{
//Configure table & schema Name
b.ToTable(options.TablePrefix + nameof(AsnMstr), options.Schema);
//Configure ABP properties
b.ConfigureByConvention();
//Properties
//b.Property(q => q.Uid);
b.Property(q => q.Company).HasMaxLength(200);
b.Property(q => q.Site).HasMaxLength(200);
b.Property(q => q.AsnNbr).HasMaxLength(200);
b.Property(q => q.RpNbr).HasMaxLength(200);
b.Property(q => q.PoNbr).HasMaxLength(200);
b.Property(q => q.VendorCode).HasMaxLength(200);
b.Property(q => q.Status).HasMaxLength(200);
b.Property(q => q.Contacts).HasMaxLength(200);
b.Property(q => q.Phone).HasMaxLength(200);
b.Property(q => q.TruckNbr).HasMaxLength(200);
b.Property(q => q.Whse).HasMaxLength(200);
b.Property(q => q.Dock).HasMaxLength(200);
b.Property(q => q.ShipDate);
b.Property(q => q.DueDate);
b.Property(q => q.TimeWindow).HasMaxLength(200);
b.Property(q => q.Remark).HasMaxLength(4096);
});
builder.Entity<AsnDet>(b =>
{
//Configure table & schema Name
b.ToTable(options.TablePrefix + nameof(AsnDet), options.Schema);
//Configure ABP properties
b.ConfigureByConvention();
//b.Property(q => q.Uid);
b.Property(q => q.AsnNbr).HasMaxLength(50);
b.Property(q => q.PoNbr).HasMaxLength(50);
b.Property(q => q.PoLine); //INT
b.Property(q => q.PartCode).HasMaxLength(50);
b.Property(q => q.Lot).HasMaxLength(200);
b.Property(q => q.Qty); //DECIMAL
b.Property(q => q.ProductionDate); //DATETIME
b.Property(q => q.WareClass).HasMaxLength(200);
b.Property(q => q.WareCode).HasMaxLength(200);
b.Property(q => q.StdPackQty); //DECIMAL
b.Property(q => q.PoUm).HasMaxLength(200);
b.Property(q => q.LocUm).HasMaxLength(200);
b.Property(q => q.UmConv); //DECIMAL
b.Property(q => q.PartType).HasMaxLength(200);
b.Property(q => q.Supplierlot).HasMaxLength(200);
b.Property(q => q.Status).HasMaxLength(200);
b.Property(q => q.LabelCode).HasMaxLength(200);
b.Property(q => q.EntireBarCode).HasMaxLength(2000);
b.Property(q => q.PalletLabelCode).HasMaxLength(200);
b.Property(q => q.Remark).HasMaxLength(4096);
});
}
*/
/*
/// <summary>
/// 发货单主表

69
WebApiService/src/Win_in.Sfs.Scp.WebApi.EntityFrameworkCore/Repositories/AsnRepository.cs

@ -0,0 +1,69 @@
/*
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Volo.Abp.Domain.Repositories.EntityFrameworkCore;
using Volo.Abp.EntityFrameworkCore;
using Win_in.Sfs.Scp.WebApi.Asns;
namespace Win_in.Sfs.Scp.WebApi.EntityFrameworkCore;
public class AsnRepository : EfCoreRepository<WebApiDbContext, AsnMstr, Guid>, IAsnRepository
{
private const string Reader = "QAD Agent";
public AsnRepository(IDbContextProvider<WebApiDbContext> dbContextProvider) : base(dbContextProvider)
{
}
public async Task<List<AsnMstr>> GetUnreadListAsync(string site, int count, bool autoUpdateStatus)
{
var dbSet = await GetDbSetAsync();
var list = await dbSet
.Where(p => p.Site == site && p.Status == EnumExchangeDataStatus.New)
.OrderBy(p => p.Id)
.Take(count)
.ToListAsync();
if (autoUpdateStatus)
{
foreach (var entity in list)
{
entity.SetSuccess(Reader);
await UpdateAsync(entity);
}
}
return list;
}
public async Task<AsnMstr> UpdateStatusAsync(Guid id, EnumExchangeDataStatus status)
{
var entity = await base.GetAsync(id);
switch (status)
{
case EnumExchangeDataStatus.New:
entity.Reset();
break;
case EnumExchangeDataStatus.Processing:
entity.SetProcessing();
break;
case EnumExchangeDataStatus.Finish:
entity.SetSuccess(Reader);
break;
case EnumExchangeDataStatus.Hold:
entity.SetHold();
break;
case EnumExchangeDataStatus.Error:
entity.SetError(Reader, EnumExchangeDataErrorCode.Exception, "");
break;
default:
throw new ArgumentOutOfRangeException(nameof(status), status, null);
}
return await UpdateAsync(entity);
}
}
*/

24
WebApiService/src/Win_in.Sfs.Scp.WebApi.EntityFrameworkCore/Repositories/X12AsnRepository.cs

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Dynamic.Core;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
@ -22,7 +23,28 @@ public class X12AsnRepository : EfCoreRepository<WebApiDbContext, X12Asn, Guid>,
{
var dbSet = await GetDbSetAsync();
var list =await dbSet
.Where(p =>p.Site ==site && p.Status == EnumExchangeDataStatus.New)
.Where(p =>p.Site ==site && p.DataType== ScpWebApiConsts.ASN && p.Status == EnumExchangeDataStatus.New)
.OrderBy(p => p.UID)
.Take(count)
.ToListAsync();
if (autoUpdateStatus)
{
foreach (var entity in list)
{
entity.SetSuccess(Reader);
await UpdateAsync(entity);
}
}
return list;
}
public async Task<List<X12Asn>> GetNoPoUnreadListAsync(string site, int count, bool autoUpdateStatus)
{
var dbSet = await GetDbSetAsync();
var list = await dbSet
.Where(p => p.Site == site && p.DataType== ScpWebApiConsts.NO_PO_ASN && p.Status == EnumExchangeDataStatus.New)
.OrderBy(p => p.UID)
.Take(count)
.ToListAsync();

Loading…
Cancel
Save