Browse Source

[fix]校验错误统一返回数据格式

master
贾荣国Home 3 years ago
parent
commit
b64266073f
  1. 4
      WebApiService/src/Win_in.Sfs.Scp.WebApi.Application.Contracts/Parts/PartCreateDtoValidator.cs
  2. 6
      WebApiService/src/Win_in.Sfs.Scp.WebApi.Application.Contracts/PurchaseOrders/PurchaseOrderDetailCreateDtoValidator.cs
  3. 4
      WebApiService/src/Win_in.Sfs.Scp.WebApi.Application.Contracts/Receipts/ReceiptCreateDtoValidator.cs
  4. 15
      WebApiService/src/Win_in.Sfs.Scp.WebApi.Application/Parts/PartAppService.cs
  5. 14
      WebApiService/src/Win_in.Sfs.Scp.WebApi.Application/PurchaseOrders/PurchaseOrderAppService.cs
  6. 14
      WebApiService/src/Win_in.Sfs.Scp.WebApi.Application/Receipts/ReceiptAppService.cs
  7. 4
      WebApiService/src/Win_in.Sfs.Scp.WebApi.Application/ScpV1AutoMapperProfile.cs
  8. 16
      WebApiService/src/Win_in.Sfs.Scp.WebApi.Application/Suppliers/SuppliersAppService.cs
  9. 16
      WebApiService/src/Win_in.Sfs.Scp.WebApi.Application/UnplannedReceipts/UnplannedReceiptAppService.cs
  10. 2
      WebApiService/src/Win_in.Sfs.Scp.WebApi.EntityFrameworkCore/DbContext/WebApiDbContextModelCreatingExtensions.cs

4
WebApiService/src/Win_in.Sfs.Scp.WebApi.Application.Contracts/Parts/PartCreateDtoValidator.cs

@ -8,8 +8,8 @@ public class PartCreateDtoValidator : AbstractValidator<PartCreateDto>
public PartCreateDtoValidator() public PartCreateDtoValidator()
{ {
RuleFor(x => x.Code).MaximumLength(64).NotEmpty(); RuleFor(x => x.Code).MaximumLength(64).NotEmpty();
RuleFor(x => x.Name).MaximumLength(64).NotNull(); RuleFor(x => x.Name).MaximumLength(1024).NotNull();
RuleFor(x => x.Desc1).MaximumLength(1024); RuleFor(x => x.Desc1).MaximumLength(1024).NotNull();
RuleFor(x => x.Desc2).MaximumLength(1024); RuleFor(x => x.Desc2).MaximumLength(1024);
RuleFor(x => x.Status).MaximumLength(64).NotNull(); RuleFor(x => x.Status).MaximumLength(64).NotNull();
RuleFor(x => x.IsMakePart).NotNull(); RuleFor(x => x.IsMakePart).NotNull();

6
WebApiService/src/Win_in.Sfs.Scp.WebApi.Application.Contracts/PurchaseOrders/CreatePurchaseOrderDetailValidator.cs → WebApiService/src/Win_in.Sfs.Scp.WebApi.Application.Contracts/PurchaseOrders/PurchaseOrderDetailCreateDtoValidator.cs

@ -2,9 +2,9 @@ using FluentValidation;
namespace Win_in.Sfs.Scp.WebApi; namespace Win_in.Sfs.Scp.WebApi;
public class CreatePurchaseOrderDetailValidator : AbstractValidator<PurchaseOrderDetailCreateDTO> public class PurchaseOrderDetailCreateDtoValidator : AbstractValidator<PurchaseOrderDetailCreateDTO>
{ {
public CreatePurchaseOrderDetailValidator() public PurchaseOrderDetailCreateDtoValidator()
{ {
RuleFor(q => q.PoNumber).MaximumLength(64).NotEmpty(); RuleFor(q => q.PoNumber).MaximumLength(64).NotEmpty();
RuleFor(q => q.PoLine).MaximumLength(64).NotNull(); RuleFor(q => q.PoLine).MaximumLength(64).NotNull();
@ -12,7 +12,7 @@ public class CreatePurchaseOrderDetailValidator : AbstractValidator<PurchaseOrde
RuleFor(q => q.Uom).MaximumLength(64).NotNull(); RuleFor(q => q.Uom).MaximumLength(64).NotNull();
RuleFor(q => q.OrderQty).NotNull(); RuleFor(q => q.OrderQty).NotNull();
RuleFor(q => q.StdPackQty).NotNull(); RuleFor(q => q.StdPackQty).NotNull();
RuleFor(q => q.SupplierPackConvertRate).NotNull(); RuleFor(q => q.SupplierPackConvertRate);
RuleFor(q => q.IsConsignment).NotNull(); RuleFor(q => q.IsConsignment).NotNull();
RuleFor(q => q.LineStatus).NotNull(); RuleFor(q => q.LineStatus).NotNull();
RuleFor(q => q.Remark).MaximumLength(4096); RuleFor(q => q.Remark).MaximumLength(4096);

4
WebApiService/src/Win_in.Sfs.Scp.WebApi.Application.Contracts/Receipts/ReceiptCreateDtoValidator.cs

@ -17,8 +17,8 @@ public class ReceiptCreateDtoValidator : AbstractValidator<ReceiptCreateDTO>
RuleFor(q => q.ReceiveTime); RuleFor(q => q.ReceiveTime);
RuleFor(q => q.PoLine).MaximumLength(64); RuleFor(q => q.PoLine).MaximumLength(64);
RuleFor(q => q.PartCode).MaximumLength(64).NotEmpty(); RuleFor(q => q.PartCode).MaximumLength(64).NotEmpty();
RuleFor(q => q.Lot).MaximumLength(64); RuleFor(q => q.Lot).MaximumLength(64).NotNull();
RuleFor(q => q.SupplierLot); RuleFor(q => q.SupplierLot).MaximumLength(64).NotNull();
RuleFor(q => q.Uom).MaximumLength(64).NotNull(); RuleFor(q => q.Uom).MaximumLength(64).NotNull();
RuleFor(q => q.ReceiveQty).NotNull(); RuleFor(q => q.ReceiveQty).NotNull();
RuleFor(q => q.SupplierPackConvertRate).NotNull(); RuleFor(q => q.SupplierPackConvertRate).NotNull();

15
WebApiService/src/Win_in.Sfs.Scp.WebApi.Application/Parts/PartAppService.cs

@ -2,15 +2,18 @@
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Threading.Tasks; using System.Threading.Tasks;
using AutoMapper; using AutoMapper;
using AutoMapper.Configuration; using AutoMapper.Configuration;
using FluentValidation;
using Volo.Abp.Application.Dtos; using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services; using Volo.Abp.Application.Services;
using Volo.Abp.Domain.Repositories; using Volo.Abp.Domain.Repositories;
using Volo.Abp.Uow; using Volo.Abp.Uow;
using Win_in.Sfs.Scp.v1.Domain; using Win_in.Sfs.Scp.v1.Domain;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Volo.Abp.Validation;
using IConfiguration = Microsoft.Extensions.Configuration.IConfiguration; using IConfiguration = Microsoft.Extensions.Configuration.IConfiguration;
namespace Win_in.Sfs.Scp.WebApi namespace Win_in.Sfs.Scp.WebApi
@ -93,7 +96,17 @@ namespace Win_in.Sfs.Scp.WebApi
var dto = ObjectMapper.Map<Part, PartDTO>(ret); var dto = ObjectMapper.Map<Part, PartDTO>(ret);
return dto.ErrorCode != 0 ? new BadRequestObjectResult(dto) : new OkObjectResult(dto); if (dto.ErrorCode != 0)
{
throw new AbpValidationException(new List<ValidationResult>
{
new(dto.ErrorMessage)
});
}
else
{
return new OkObjectResult(dto);
}
} }
private async Task UpsertTaPartAsync(Part entity) private async Task UpsertTaPartAsync(Part entity)

14
WebApiService/src/Win_in.Sfs.Scp.WebApi.Application/PurchaseOrders/PurchaseOrderAppService.cs

@ -2,10 +2,12 @@ using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Volo.Abp.Application.Dtos; using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services; using Volo.Abp.Application.Services;
using Volo.Abp.Validation;
using Win_in.Sfs.Scp.v1.Domain; using Win_in.Sfs.Scp.v1.Domain;
namespace Win_in.Sfs.Scp.WebApi namespace Win_in.Sfs.Scp.WebApi
@ -102,7 +104,17 @@ namespace Win_in.Sfs.Scp.WebApi
} }
var ret = await _purchaseOrderRepository.InsertAsync(entity); var ret = await _purchaseOrderRepository.InsertAsync(entity);
var dto = ObjectMapper.Map<PurchaseOrder, PurchaseOrderDTO>(ret); var dto = ObjectMapper.Map<PurchaseOrder, PurchaseOrderDTO>(ret);
return dto.ErrorCode != 0 ? new BadRequestObjectResult(dto) : new OkObjectResult(dto); if (dto.ErrorCode != 0)
{
throw new AbpValidationException(new List<ValidationResult>
{
new(dto.ErrorMessage)
});
}
else
{
return new OkObjectResult(dto);
}
} }
private async Task UpsertTbPoAndTbPoDetailAsync(PurchaseOrder entity) private async Task UpsertTbPoAndTbPoDetailAsync(PurchaseOrder entity)

14
WebApiService/src/Win_in.Sfs.Scp.WebApi.Application/Receipts/ReceiptAppService.cs

@ -2,11 +2,13 @@
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Volo.Abp.Application.Dtos; using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services; using Volo.Abp.Application.Services;
using Volo.Abp.Uow; using Volo.Abp.Uow;
using Volo.Abp.Validation;
using Win_in.Sfs.Scp.v1.Domain; using Win_in.Sfs.Scp.v1.Domain;
namespace Win_in.Sfs.Scp.WebApi namespace Win_in.Sfs.Scp.WebApi
@ -97,9 +99,19 @@ namespace Win_in.Sfs.Scp.WebApi
var ret = await _receiptRepository.InsertAsync(entity); var ret = await _receiptRepository.InsertAsync(entity);
var dto = ObjectMapper.Map<Receipt, ReceiptDTO>(ret); var dto = ObjectMapper.Map<Receipt, ReceiptDTO>(ret);
return dto.ErrorCode != 0 ? new BadRequestObjectResult(dto) : new OkObjectResult(dto); if (dto.ErrorCode != 0)
{
throw new AbpValidationException(new List<ValidationResult>
{
new(dto.ErrorMessage)
});
} }
else
{
return new OkObjectResult(dto);
}
}
private async Task UpsertTbReceiptAndTbReceiptDetailAsync(Receipt entity) private async Task UpsertTbReceiptAndTbReceiptDetailAsync(Receipt entity)
{ {

4
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.Site, p => p.MapFrom(q => q.Site))
.ForMember(p => p.PartCode, p => p.MapFrom(q => q.Code)) .ForMember(p => p.PartCode, p => p.MapFrom(q => q.Code))
.ForMember(p => p.ErpPartCode, 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.PartDesc1, p => p.MapFrom(q =>string.IsNullOrEmpty(q.Desc2)?"":q.Desc2))
.ForMember(p => p.PartDesc2, p => p.MapFrom(q => q.Desc1)) .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.ProjectId, p => p.MapFrom(q => q.ProductLine))
.ForMember(p => p.Unit, p => p.MapFrom(q => q.Uom)) .ForMember(p => p.Unit, p => p.MapFrom(q => q.Uom))
.ForMember(p => p.PartGroup, p => p.MapFrom(q => q.Group)) .ForMember(p => p.PartGroup, p => p.MapFrom(q => q.Group))

16
WebApiService/src/Win_in.Sfs.Scp.WebApi.Application/Suppliers/SuppliersAppService.cs

@ -2,11 +2,14 @@
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Threading.Tasks; using System.Threading.Tasks;
using FluentValidation;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Volo.Abp.Application.Dtos; using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services; using Volo.Abp.Application.Services;
using Volo.Abp.Uow; using Volo.Abp.Uow;
using Volo.Abp.Validation;
using Win_in.Sfs.Scp.v1.Domain; using Win_in.Sfs.Scp.v1.Domain;
@ -90,8 +93,17 @@ namespace Win_in.Sfs.Scp.WebApi
var ret = await _supplierRepository.InsertAsync(entity); var ret = await _supplierRepository.InsertAsync(entity);
var dto = ObjectMapper.Map<Supplier, SupplierDTO>(ret); var dto = ObjectMapper.Map<Supplier, SupplierDTO>(ret);
return dto.ErrorCode != 0 ? new BadRequestObjectResult(dto) : new OkObjectResult(dto); if (dto.ErrorCode != 0)
{
throw new AbpValidationException(new List<ValidationResult>
{
new(dto.ErrorMessage)
});
}
else
{
return new OkObjectResult(dto);
}
} }
private async Task UpsertTaVenderAsync(Supplier entity) private async Task UpsertTaVenderAsync(Supplier entity)

16
WebApiService/src/Win_in.Sfs.Scp.WebApi.Application/UnplannedReceipts/UnplannedReceiptAppService.cs

@ -2,11 +2,14 @@
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Threading.Tasks; using System.Threading.Tasks;
using FluentValidation;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Volo.Abp.Application.Dtos; using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services; using Volo.Abp.Application.Services;
using Volo.Abp.Uow; using Volo.Abp.Uow;
using Volo.Abp.Validation;
using Win_in.Sfs.Scp.v1.Domain; using Win_in.Sfs.Scp.v1.Domain;
namespace Win_in.Sfs.Scp.WebApi namespace Win_in.Sfs.Scp.WebApi
@ -98,8 +101,17 @@ namespace Win_in.Sfs.Scp.WebApi
var ret = await _unplannedReceiptRepository.InsertAsync(entity); var ret = await _unplannedReceiptRepository.InsertAsync(entity);
var dto = ObjectMapper.Map<UnplannedReceipt, UnplannedReceiptDTO>(ret); var dto = ObjectMapper.Map<UnplannedReceipt, UnplannedReceiptDTO>(ret);
return dto.ErrorCode != 0 ? new BadRequestObjectResult(dto) : new OkObjectResult(dto); if (dto.ErrorCode != 0)
{
throw new AbpValidationException(new List<ValidationResult>
{
new(dto.ErrorMessage)
});
}
else
{
return new OkObjectResult(dto);
}
} }
private async Task UpsertTbReceiptAndTbReceiptDetailAsync(UnplannedReceipt entity) private async Task UpsertTbReceiptAndTbReceiptDetailAsync(UnplannedReceipt entity)

2
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.ConfigureByConvention();
b.Property(x => x.Code).IsRequired().HasMaxLength(64); 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.Desc1).HasMaxLength(1024);
b.Property(x => x.Desc2).HasMaxLength(1024); b.Property(x => x.Desc2).HasMaxLength(1024);
b.Property(x => x.Status).IsRequired().HasMaxLength(64); b.Property(x => x.Status).IsRequired().HasMaxLength(64);

Loading…
Cancel
Save