From b64266073fd727f2def11b5fd0bf04c030de12b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B4=BE=E8=8D=A3=E5=9B=BDHome?= Date: Tue, 15 Mar 2022 15:32:32 +0800 Subject: [PATCH] =?UTF-8?q?[fix]=E6=A0=A1=E9=AA=8C=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E7=BB=9F=E4=B8=80=E8=BF=94=E5=9B=9E=E6=95=B0=E6=8D=AE=E6=A0=BC?= =?UTF-8?q?=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Parts/PartCreateDtoValidator.cs | 4 ++-- ... => PurchaseOrderDetailCreateDtoValidator.cs} | 6 +++--- .../Receipts/ReceiptCreateDtoValidator.cs | 4 ++-- .../Parts/PartAppService.cs | 15 ++++++++++++++- .../PurchaseOrders/PurchaseOrderAppService.cs | 14 +++++++++++++- .../Receipts/ReceiptAppService.cs | 14 +++++++++++++- .../ScpV1AutoMapperProfile.cs | 4 ++-- .../Suppliers/SuppliersAppService.cs | 16 ++++++++++++++-- .../UnplannedReceiptAppService.cs | 16 ++++++++++++++-- .../WebApiDbContextModelCreatingExtensions.cs | 2 +- 10 files changed, 78 insertions(+), 17 deletions(-) rename WebApiService/src/Win_in.Sfs.Scp.WebApi.Application.Contracts/PurchaseOrders/{CreatePurchaseOrderDetailValidator.cs => PurchaseOrderDetailCreateDtoValidator.cs} (72%) diff --git a/WebApiService/src/Win_in.Sfs.Scp.WebApi.Application.Contracts/Parts/PartCreateDtoValidator.cs b/WebApiService/src/Win_in.Sfs.Scp.WebApi.Application.Contracts/Parts/PartCreateDtoValidator.cs index d837ed8..3bfd929 100644 --- a/WebApiService/src/Win_in.Sfs.Scp.WebApi.Application.Contracts/Parts/PartCreateDtoValidator.cs +++ b/WebApiService/src/Win_in.Sfs.Scp.WebApi.Application.Contracts/Parts/PartCreateDtoValidator.cs @@ -8,8 +8,8 @@ public class PartCreateDtoValidator : AbstractValidator public PartCreateDtoValidator() { RuleFor(x => x.Code).MaximumLength(64).NotEmpty(); - RuleFor(x => x.Name).MaximumLength(64).NotNull(); - RuleFor(x => x.Desc1).MaximumLength(1024); + RuleFor(x => x.Name).MaximumLength(1024).NotNull(); + RuleFor(x => x.Desc1).MaximumLength(1024).NotNull(); RuleFor(x => x.Desc2).MaximumLength(1024); RuleFor(x => x.Status).MaximumLength(64).NotNull(); RuleFor(x => x.IsMakePart).NotNull(); diff --git a/WebApiService/src/Win_in.Sfs.Scp.WebApi.Application.Contracts/PurchaseOrders/CreatePurchaseOrderDetailValidator.cs b/WebApiService/src/Win_in.Sfs.Scp.WebApi.Application.Contracts/PurchaseOrders/PurchaseOrderDetailCreateDtoValidator.cs similarity index 72% rename from WebApiService/src/Win_in.Sfs.Scp.WebApi.Application.Contracts/PurchaseOrders/CreatePurchaseOrderDetailValidator.cs rename to WebApiService/src/Win_in.Sfs.Scp.WebApi.Application.Contracts/PurchaseOrders/PurchaseOrderDetailCreateDtoValidator.cs index 4ae320f..bc3cbc0 100644 --- a/WebApiService/src/Win_in.Sfs.Scp.WebApi.Application.Contracts/PurchaseOrders/CreatePurchaseOrderDetailValidator.cs +++ b/WebApiService/src/Win_in.Sfs.Scp.WebApi.Application.Contracts/PurchaseOrders/PurchaseOrderDetailCreateDtoValidator.cs @@ -2,9 +2,9 @@ using FluentValidation; namespace Win_in.Sfs.Scp.WebApi; -public class CreatePurchaseOrderDetailValidator : AbstractValidator +public class PurchaseOrderDetailCreateDtoValidator : AbstractValidator { - public CreatePurchaseOrderDetailValidator() + public PurchaseOrderDetailCreateDtoValidator() { RuleFor(q => q.PoNumber).MaximumLength(64).NotEmpty(); RuleFor(q => q.PoLine).MaximumLength(64).NotNull(); @@ -12,7 +12,7 @@ public class CreatePurchaseOrderDetailValidator : AbstractValidator q.Uom).MaximumLength(64).NotNull(); RuleFor(q => q.OrderQty).NotNull(); RuleFor(q => q.StdPackQty).NotNull(); - RuleFor(q => q.SupplierPackConvertRate).NotNull(); + RuleFor(q => q.SupplierPackConvertRate); RuleFor(q => q.IsConsignment).NotNull(); RuleFor(q => q.LineStatus).NotNull(); RuleFor(q => q.Remark).MaximumLength(4096); diff --git a/WebApiService/src/Win_in.Sfs.Scp.WebApi.Application.Contracts/Receipts/ReceiptCreateDtoValidator.cs b/WebApiService/src/Win_in.Sfs.Scp.WebApi.Application.Contracts/Receipts/ReceiptCreateDtoValidator.cs index d218fbe..5920a54 100644 --- a/WebApiService/src/Win_in.Sfs.Scp.WebApi.Application.Contracts/Receipts/ReceiptCreateDtoValidator.cs +++ b/WebApiService/src/Win_in.Sfs.Scp.WebApi.Application.Contracts/Receipts/ReceiptCreateDtoValidator.cs @@ -17,8 +17,8 @@ public class ReceiptCreateDtoValidator : AbstractValidator RuleFor(q => q.ReceiveTime); RuleFor(q => q.PoLine).MaximumLength(64); RuleFor(q => q.PartCode).MaximumLength(64).NotEmpty(); - RuleFor(q => q.Lot).MaximumLength(64); - RuleFor(q => q.SupplierLot); + RuleFor(q => q.Lot).MaximumLength(64).NotNull(); + RuleFor(q => q.SupplierLot).MaximumLength(64).NotNull(); RuleFor(q => q.Uom).MaximumLength(64).NotNull(); RuleFor(q => q.ReceiveQty).NotNull(); RuleFor(q => q.SupplierPackConvertRate).NotNull(); diff --git a/WebApiService/src/Win_in.Sfs.Scp.WebApi.Application/Parts/PartAppService.cs b/WebApiService/src/Win_in.Sfs.Scp.WebApi.Application/Parts/PartAppService.cs index 05d498b..c932e69 100644 --- a/WebApiService/src/Win_in.Sfs.Scp.WebApi.Application/Parts/PartAppService.cs +++ b/WebApiService/src/Win_in.Sfs.Scp.WebApi.Application/Parts/PartAppService.cs @@ -2,15 +2,18 @@ using Microsoft.AspNetCore.Mvc; using System; using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; using System.Threading.Tasks; using AutoMapper; using AutoMapper.Configuration; +using FluentValidation; 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.Validation; using IConfiguration = Microsoft.Extensions.Configuration.IConfiguration; namespace Win_in.Sfs.Scp.WebApi @@ -93,7 +96,17 @@ namespace Win_in.Sfs.Scp.WebApi var dto = ObjectMapper.Map(ret); - return dto.ErrorCode != 0 ? new BadRequestObjectResult(dto) : new OkObjectResult(dto); + if (dto.ErrorCode != 0) + { + throw new AbpValidationException(new List + { + new(dto.ErrorMessage) + }); + } + else + { + return new OkObjectResult(dto); + } } private async Task UpsertTaPartAsync(Part entity) diff --git a/WebApiService/src/Win_in.Sfs.Scp.WebApi.Application/PurchaseOrders/PurchaseOrderAppService.cs b/WebApiService/src/Win_in.Sfs.Scp.WebApi.Application/PurchaseOrders/PurchaseOrderAppService.cs index 1dedc2f..736288f 100644 --- a/WebApiService/src/Win_in.Sfs.Scp.WebApi.Application/PurchaseOrders/PurchaseOrderAppService.cs +++ b/WebApiService/src/Win_in.Sfs.Scp.WebApi.Application/PurchaseOrders/PurchaseOrderAppService.cs @@ -2,10 +2,12 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using System; using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; using System.Threading.Tasks; using Microsoft.Extensions.Configuration; using Volo.Abp.Application.Dtos; using Volo.Abp.Application.Services; +using Volo.Abp.Validation; using Win_in.Sfs.Scp.v1.Domain; namespace Win_in.Sfs.Scp.WebApi @@ -102,7 +104,17 @@ namespace Win_in.Sfs.Scp.WebApi } var ret = await _purchaseOrderRepository.InsertAsync(entity); var dto = ObjectMapper.Map(ret); - return dto.ErrorCode != 0 ? new BadRequestObjectResult(dto) : new OkObjectResult(dto); + if (dto.ErrorCode != 0) + { + throw new AbpValidationException(new List + { + new(dto.ErrorMessage) + }); + } + else + { + return new OkObjectResult(dto); + } } private async Task UpsertTbPoAndTbPoDetailAsync(PurchaseOrder entity) diff --git a/WebApiService/src/Win_in.Sfs.Scp.WebApi.Application/Receipts/ReceiptAppService.cs b/WebApiService/src/Win_in.Sfs.Scp.WebApi.Application/Receipts/ReceiptAppService.cs index d01d142..bf0defc 100644 --- a/WebApiService/src/Win_in.Sfs.Scp.WebApi.Application/Receipts/ReceiptAppService.cs +++ b/WebApiService/src/Win_in.Sfs.Scp.WebApi.Application/Receipts/ReceiptAppService.cs @@ -2,11 +2,13 @@ using Microsoft.AspNetCore.Mvc; using System; using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; using System.Threading.Tasks; using Microsoft.Extensions.Configuration; using Volo.Abp.Application.Dtos; using Volo.Abp.Application.Services; using Volo.Abp.Uow; +using Volo.Abp.Validation; using Win_in.Sfs.Scp.v1.Domain; namespace Win_in.Sfs.Scp.WebApi @@ -97,8 +99,18 @@ namespace Win_in.Sfs.Scp.WebApi var ret = await _receiptRepository.InsertAsync(entity); var dto = ObjectMapper.Map(ret); - return dto.ErrorCode != 0 ? new BadRequestObjectResult(dto) : new OkObjectResult(dto); + if (dto.ErrorCode != 0) + { + throw new AbpValidationException(new List + { + new(dto.ErrorMessage) + }); + } + else + { + return new OkObjectResult(dto); + } } private async Task UpsertTbReceiptAndTbReceiptDetailAsync(Receipt entity) diff --git a/WebApiService/src/Win_in.Sfs.Scp.WebApi.Application/ScpV1AutoMapperProfile.cs b/WebApiService/src/Win_in.Sfs.Scp.WebApi.Application/ScpV1AutoMapperProfile.cs index 5f3270f..3f062cf 100644 --- a/WebApiService/src/Win_in.Sfs.Scp.WebApi.Application/ScpV1AutoMapperProfile.cs +++ b/WebApiService/src/Win_in.Sfs.Scp.WebApi.Application/ScpV1AutoMapperProfile.cs @@ -31,8 +31,8 @@ namespace Win_in.Sfs.Scp.WebApi .ForMember(p => p.Site, p => p.MapFrom(q => q.Site)) .ForMember(p => p.PartCode, p => p.MapFrom(q => q.Code)) .ForMember(p => p.ErpPartCode, p => p.MapFrom(q => q.Code)) - .ForMember(p => p.PartDesc1, p => p.MapFrom(q => q.Desc2)) - .ForMember(p => p.PartDesc2, p => p.MapFrom(q => q.Desc1)) + .ForMember(p => p.PartDesc1, p => p.MapFrom(q =>string.IsNullOrEmpty(q.Desc2)?"":q.Desc2)) + .ForMember(p => p.PartDesc2, p => p.MapFrom(q =>string.IsNullOrEmpty(q.Desc1)?"":q.Desc1)) .ForMember(p => p.ProjectId, p => p.MapFrom(q => q.ProductLine)) .ForMember(p => p.Unit, p => p.MapFrom(q => q.Uom)) .ForMember(p => p.PartGroup, p => p.MapFrom(q => q.Group)) diff --git a/WebApiService/src/Win_in.Sfs.Scp.WebApi.Application/Suppliers/SuppliersAppService.cs b/WebApiService/src/Win_in.Sfs.Scp.WebApi.Application/Suppliers/SuppliersAppService.cs index a1320c1..c34b916 100644 --- a/WebApiService/src/Win_in.Sfs.Scp.WebApi.Application/Suppliers/SuppliersAppService.cs +++ b/WebApiService/src/Win_in.Sfs.Scp.WebApi.Application/Suppliers/SuppliersAppService.cs @@ -2,11 +2,14 @@ using Microsoft.AspNetCore.Mvc; using System; using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; using System.Threading.Tasks; +using FluentValidation; using Microsoft.Extensions.Configuration; using Volo.Abp.Application.Dtos; using Volo.Abp.Application.Services; using Volo.Abp.Uow; +using Volo.Abp.Validation; using Win_in.Sfs.Scp.v1.Domain; @@ -90,8 +93,17 @@ namespace Win_in.Sfs.Scp.WebApi var ret = await _supplierRepository.InsertAsync(entity); var dto = ObjectMapper.Map(ret); - return dto.ErrorCode != 0 ? new BadRequestObjectResult(dto) : new OkObjectResult(dto); - + if (dto.ErrorCode != 0) + { + throw new AbpValidationException(new List + { + new(dto.ErrorMessage) + }); + } + else + { + return new OkObjectResult(dto); + } } private async Task UpsertTaVenderAsync(Supplier entity) diff --git a/WebApiService/src/Win_in.Sfs.Scp.WebApi.Application/UnplannedReceipts/UnplannedReceiptAppService.cs b/WebApiService/src/Win_in.Sfs.Scp.WebApi.Application/UnplannedReceipts/UnplannedReceiptAppService.cs index b5f167a..44349dd 100644 --- a/WebApiService/src/Win_in.Sfs.Scp.WebApi.Application/UnplannedReceipts/UnplannedReceiptAppService.cs +++ b/WebApiService/src/Win_in.Sfs.Scp.WebApi.Application/UnplannedReceipts/UnplannedReceiptAppService.cs @@ -2,11 +2,14 @@ using Microsoft.AspNetCore.Mvc; using System; using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; using System.Threading.Tasks; +using FluentValidation; using Microsoft.Extensions.Configuration; using Volo.Abp.Application.Dtos; using Volo.Abp.Application.Services; using Volo.Abp.Uow; +using Volo.Abp.Validation; using Win_in.Sfs.Scp.v1.Domain; namespace Win_in.Sfs.Scp.WebApi @@ -98,8 +101,17 @@ namespace Win_in.Sfs.Scp.WebApi var ret = await _unplannedReceiptRepository.InsertAsync(entity); var dto = ObjectMapper.Map(ret); - return dto.ErrorCode != 0 ? new BadRequestObjectResult(dto) : new OkObjectResult(dto); - + if (dto.ErrorCode != 0) + { + throw new AbpValidationException(new List + { + new(dto.ErrorMessage) + }); + } + else + { + return new OkObjectResult(dto); + } } private async Task UpsertTbReceiptAndTbReceiptDetailAsync(UnplannedReceipt entity) diff --git a/WebApiService/src/Win_in.Sfs.Scp.WebApi.EntityFrameworkCore/DbContext/WebApiDbContextModelCreatingExtensions.cs b/WebApiService/src/Win_in.Sfs.Scp.WebApi.EntityFrameworkCore/DbContext/WebApiDbContextModelCreatingExtensions.cs index 68ccf34..c9c561d 100644 --- a/WebApiService/src/Win_in.Sfs.Scp.WebApi.EntityFrameworkCore/DbContext/WebApiDbContextModelCreatingExtensions.cs +++ b/WebApiService/src/Win_in.Sfs.Scp.WebApi.EntityFrameworkCore/DbContext/WebApiDbContextModelCreatingExtensions.cs @@ -64,7 +64,7 @@ namespace Win_in.Sfs.Scp.WebApi.EntityFrameworkCore b.ConfigureByConvention(); b.Property(x => x.Code).IsRequired().HasMaxLength(64); - b.Property(x => x.Name).IsRequired().HasMaxLength(64); + b.Property(x => x.Name).IsRequired().HasMaxLength(1024); b.Property(x => x.Desc1).HasMaxLength(1024); b.Property(x => x.Desc2).HasMaxLength(1024); b.Property(x => x.Status).IsRequired().HasMaxLength(64);