Administrator
2 years ago
4 changed files with 478 additions and 4 deletions
@ -0,0 +1,354 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.IO; |
|||
using System.Linq; |
|||
using System.Threading.Tasks; |
|||
using EFCore.BulkExtensions; |
|||
using Magicodes.ExporterAndImporter.Core; |
|||
using Magicodes.ExporterAndImporter.Excel; |
|||
using Microsoft.AspNetCore.Authorization; |
|||
using Microsoft.AspNetCore.Http; |
|||
using Microsoft.AspNetCore.Mvc; |
|||
using Microsoft.Extensions.Caching.Distributed; |
|||
using Shouldly; |
|||
using Volo.Abp; |
|||
using Volo.Abp.Application.Dtos; |
|||
using Volo.Abp.Application.Services; |
|||
using Volo.Abp.BackgroundJobs; |
|||
using Volo.Abp.Caching; |
|||
using Volo.Abp.Domain.Repositories; |
|||
using Volo.Abp.Guids; |
|||
using Volo.Abp.ObjectMapping; |
|||
using Volo.Abp.Uow; |
|||
using Win.Abp.Snowflakes; |
|||
using Win.Sfs.BaseData.ImportExcelCommon; |
|||
using Win.Sfs.SettleAccount.Boms; |
|||
using Win.Sfs.SettleAccount.CommonManagers; |
|||
using Win.Sfs.SettleAccount.Constant; |
|||
using Win.Sfs.SettleAccount.Entities.Boms; |
|||
using Win.Sfs.SettleAccount.Entities.Errors; |
|||
using Win.Sfs.SettleAccount.Entities.EstimatedInventories; |
|||
using Win.Sfs.SettleAccount.Entities.ImportMap; |
|||
using Win.Sfs.SettleAccount.Entities.Prices; |
|||
using Win.Sfs.SettleAccount.Entities.TaskJobs; |
|||
using Win.Sfs.SettleAccount.Errors; |
|||
using Win.Sfs.SettleAccount.EstimatedInventories; |
|||
using Win.Sfs.SettleAccount.ExcelImporter; |
|||
using Win.Sfs.SettleAccount.ExportReports; |
|||
|
|||
|
|||
using Win.Sfs.Shared.CacheBase; |
|||
using Win.Utils; |
|||
namespace Win.Sfs.SettleAccount.Entities.ErrorBills |
|||
{ |
|||
|
|||
/// <summary>
|
|||
/// 物料主数据应用服务
|
|||
/// </summary>
|
|||
// [Authorize(SettleAccountPermissions.ErrorBills.Default)]
|
|||
//[AllowAnonymous]
|
|||
[Route("api/settleaccount/ErrorBill")] |
|||
public class ErrorBillAppService : SettleAccountApplicationBase<ErrorBill> |
|||
{ |
|||
|
|||
|
|||
private readonly IExcelImportAppService _excelImportService; |
|||
private readonly ISettleAccountBranchEfCoreRepository<ErrorBill, Guid> _repository; |
|||
private readonly ISettleAccountBranchEfCoreRepository<Bom, Guid> _bomRepository; |
|||
private readonly ISettleAccountBranchEfCoreRepository<BomVersion, Guid> _bomversionRepository; |
|||
private readonly ISettleAccountBranchEfCoreRepository<PriceList, Guid> _priceRepository; |
|||
private readonly ISettleAccountBranchEfCoreRepository<PriceListVersion, Guid> _priceversionRepository; |
|||
private readonly ISettleAccountBranchEfCoreRepository<ImportColumnMap, Guid> _mapRepository; |
|||
//private readonly ISettleAccountBranchEfCoreRepository<ErrorBillRelationship, Guid> _relationshipRepository;
|
|||
/// <summary>
|
|||
/// 构建方法
|
|||
/// </summary>
|
|||
/// <param name="guidGenerator">构建UID</param>
|
|||
/// <param name="objectMapper">自动map</param>
|
|||
/// <param name="repository">仓储接口</param>
|
|||
/// <param name="cache">缓存</param>
|
|||
public ErrorBillAppService( |
|||
|
|||
ISettleAccountBranchEfCoreRepository<ErrorBill, Guid> repository, |
|||
ISettleAccountBranchEfCoreRepository<ImportColumnMap, Guid> mapRepository, |
|||
ISettleAccountBranchEfCoreRepository<Bom, Guid> bomRepository, |
|||
ISettleAccountBranchEfCoreRepository<BomVersion, Guid> bomversionRepository, |
|||
TaskJobService service, |
|||
//ISettleAccountBranchEfCoreRepository<ErrorBillRelationship, Guid> relationshipRepository,
|
|||
ISettleAccountBranchEfCoreRepository<PriceList, Guid> priceRepository, |
|||
ISettleAccountBranchEfCoreRepository<PriceListVersion, Guid> priceversionRepository, |
|||
|
|||
IDistributedCache<ErrorBill> cache, |
|||
IExcelImportAppService excelImportService, |
|||
ISnowflakeIdGenerator snowflakeIdGenerator, |
|||
ICommonManager commonManager |
|||
|
|||
) : base(cache,excelImportService,snowflakeIdGenerator,commonManager) |
|||
{ |
|||
_priceRepository = priceRepository; |
|||
_priceversionRepository = priceversionRepository; |
|||
_bomRepository = bomRepository; |
|||
_excelImportService = excelImportService; |
|||
_repository = repository; |
|||
//_relationshipRepository = relationshipRepository;
|
|||
_mapRepository = mapRepository; |
|||
_bomversionRepository = bomversionRepository; |
|||
|
|||
} |
|||
|
|||
|
|||
/// <summary>
|
|||
/// 导入功能
|
|||
/// </summary>
|
|||
/// <param name="files">上传的文件(前端已经限制只能上传一个附件)</param>
|
|||
/// <returns></returns>
|
|||
[HttpPost] |
|||
[Route("ExcelImport")] |
|||
[DisableRequestSizeLimit] |
|||
|
|||
public async Task<string> ErrorBillUploadExcelImportMap([FromForm] IFormFileCollection files,string version) |
|||
{ |
|||
ExportImporter _exportImporter = new ExportImporter(); |
|||
var result = await _exportImporter.ExtendExcelImport<ErrorBill>(files, _excelImportService); |
|||
return ApplicationConsts.SuccessStr; |
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
/// <summary>
|
|||
/// 导入功能
|
|||
/// </summary>
|
|||
/// <param name="files">上传的文件(前端已经限制只能上传一个附件)</param>
|
|||
/// <returns></returns>
|
|||
[HttpPost] |
|||
[Route("ExcelImport")] |
|||
[DisableRequestSizeLimit] |
|||
|
|||
public async Task<string> ErrorBillUploadExcelImport([FromForm] IFormFileCollection files) |
|||
{ |
|||
ExportImporter _exportImporter = new ExportImporter(); |
|||
var result = await _exportImporter.UploadExcelImport<ErrorBillImportDto>(files, _excelImportService); |
|||
var _ls = ObjectMapper.Map<List<ErrorBillImportDto>, List<ErrorBill>>(result); |
|||
var checkList = new List<ErrorExportDto>(); |
|||
foreach (var itm in _ls) |
|||
{ |
|||
|
|||
|
|||
|
|||
//var _first = await _repository.FirstOrDefaultAsync(p => p.ErrorBillCode == itm.ErrorBillCode);
|
|||
//if (_first == null)
|
|||
//{
|
|||
//var entity = new ErrorBill(
|
|||
// GuidGenerator.Create(),
|
|||
// GuidGenerator.Create(),
|
|||
// itm.Factory,
|
|||
// itm.ErrorBillCode,
|
|||
// itm.ErrorBillDesc,
|
|||
// itm.Unit,
|
|||
// itm.EstimateType,
|
|||
// itm.EstimateTypeDesc
|
|||
// );
|
|||
// await _repository.InsertAsync(entity);
|
|||
//}
|
|||
//else
|
|||
//{
|
|||
//_first.Update(itm.ErrorBillDesc, itm.Unit, itm.EstimateType, itm.EstimateTypeDesc, itm.Factory
|
|||
// );
|
|||
//await _repository.UpdateAsync(_first);
|
|||
//}
|
|||
//var _f = await _relationshipRepository.FirstOrDefaultAsync(p => p.ErpErrorBillCode == itm.ErrorBillCode);
|
|||
//if (_f != null)
|
|||
//{
|
|||
// _f.Update(itm.ErrorBillDesc, _f.ErrorBillProperty, _f.SettleErrorBillCode, _f.ShipMaterailCode);
|
|||
// await _relationshipRepository.UpdateAsync(_f);
|
|||
//}
|
|||
//else
|
|||
//{
|
|||
// var _r = new ErrorBillRelationship(GuidGenerator.Create(), GuidGenerator.Create(), itm.ErrorBillCode, itm.ErrorBillDesc, string.Empty, string.Empty, string.Empty, itm.EstimateType);
|
|||
// await _relationshipRepository.InsertAsync(_r);
|
|||
//}
|
|||
|
|||
|
|||
|
|||
|
|||
} |
|||
return ApplicationConsts.SuccessStr; |
|||
} |
|||
|
|||
|
|||
|
|||
/// <summary>
|
|||
/// 按ID获取唯一实体
|
|||
/// </summary>
|
|||
/// <remarks>
|
|||
/// 返回实体全部属性
|
|||
/// </remarks>
|
|||
/// <param name="id">ID</param>
|
|||
/// <returns>实体DTO</returns>
|
|||
[HttpGet] |
|||
[Route("{id}")] |
|||
|
|||
virtual public async Task<ErrorBillDto> GetAsync(Guid id) |
|||
{ |
|||
|
|||
|
|||
var result = await GetFromCacheAsync(id); |
|||
var dto = ObjectMapper.Map<ErrorBill, ErrorBillDto>(result); |
|||
return dto; |
|||
} |
|||
|
|||
|
|||
private async Task<ErrorBill> GetFromCacheAsync(Guid id) |
|||
{ |
|||
var result = await _repository.GetAsync(id); |
|||
|
|||
return result; |
|||
} |
|||
|
|||
|
|||
private async Task<long> GetCountAsync(ErrorBillRequestDto input) |
|||
{ |
|||
return await _repository.GetCountByFilterAsync(input.BranchId, input.Filters); |
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
///// <summary>
|
|||
|
|||
/// <summary>
|
|||
/// 根据筛选条件获取实体列表
|
|||
/// </summary>
|
|||
/// <remarks>
|
|||
/// 请求条件包括:筛选条件列表,排序条件,数据数量,页码
|
|||
/// </remarks>
|
|||
/// <param name="input">请求条件</param>
|
|||
/// <returns>实体DTO列表</returns>
|
|||
[HttpPost] |
|||
[Route("list")] |
|||
|
|||
virtual public async Task<PagedResultDto<ErrorBillDto>> GetListAsync(ErrorBillRequestDto input) |
|||
{ |
|||
var entities = await _repository.GetListByFilterAsync(input.BranchId, input.Filters, input.Sorting, input.MaxResultCount, |
|||
input.SkipCount, true); |
|||
|
|||
var totalCount = await GetCountAsync(input); |
|||
var dtos = ObjectMapper.Map<List<ErrorBill>, List<ErrorBillDto>>(entities); |
|||
|
|||
return new PagedResultDto<ErrorBillDto>(totalCount, dtos); |
|||
} |
|||
|
|||
|
|||
/// <summary>
|
|||
/// 获取实体总数
|
|||
/// </summary>
|
|||
/// <returns>实体总数</returns>
|
|||
[HttpGet] |
|||
[Route("count")] |
|||
|
|||
virtual public async Task<long> GetTotalCountAsync(Guid branchId) |
|||
{ |
|||
return await _repository.GetCountAsync(branchId); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 获取全部实体列表
|
|||
/// </summary>
|
|||
/// <returns>实体DTO列表</returns>
|
|||
[HttpGet] |
|||
[Route("all")] |
|||
|
|||
virtual public async Task<ListResultDto<ErrorBillDto>> GetAllAsync(Guid branchId) |
|||
{ |
|||
var entities = await _repository.GetAllAsync(branchId, true); |
|||
var dtos = ObjectMapper.Map<List<ErrorBill>, List<ErrorBillDto>>(entities); |
|||
return new ListResultDto<ErrorBillDto>(dtos); |
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
/// <summary>
|
|||
/// 新增实体
|
|||
/// </summary>
|
|||
/// <param name="input">新增实体DTO</param>
|
|||
/// <returns>实体DTO</returns>
|
|||
|
|||
|
|||
|
|||
|
|||
/// <summary>
|
|||
/// 删除实体
|
|||
/// </summary>
|
|||
/// <param name="id">ID</param>
|
|||
/// <returns>无</returns>
|
|||
[HttpDelete] |
|||
[Route("{id}")] |
|||
|
|||
virtual public async Task DeleteAsync(Guid id) |
|||
{ |
|||
var entity = await GetFromCacheAsync(id); |
|||
await Cache.DeleteAsync<ErrorBill>(id.ToString()); |
|||
await _repository.DeleteAsync(id); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 按IDs删除实体列表
|
|||
/// </summary>
|
|||
/// <param name="ids">IDs</param>
|
|||
/// <returns>是否执行成功</returns>
|
|||
[HttpPost] |
|||
[Route("delete")] |
|||
|
|||
virtual public async Task<bool> DeleteListAsync(List<Guid> ids) |
|||
{ |
|||
var _query = _repository.Where(p => ids.Contains(p.Id)); |
|||
int i = await _query.BatchDeleteAsync(); |
|||
|
|||
if (i == 0) |
|||
{ |
|||
return false; |
|||
} |
|||
return true; |
|||
} |
|||
[HttpPost] |
|||
[Route("Export")] |
|||
|
|||
virtual public async Task<string> ExportAsync(ErrorBillRequestDto input) |
|||
{ |
|||
string _fileName = string.Format("错误单据_{0}.xlsx", DateTime.Now.ToString("yyyyMMdd")); |
|||
var entities = await _repository.GetListByFilterAsync(input.BranchId, input.Filters, input.Sorting, int.MaxValue, |
|||
0, true); |
|||
|
|||
var dtoDetails = ObjectMapper.Map<List<ErrorBill>, List<ErrorBillExportDto>>(entities); |
|||
|
|||
//声明导出容器
|
|||
ExportImporter _exportImporter = new ExportImporter(); |
|||
|
|||
var result = await _exportImporter.ExcelExporter(dtoDetails); |
|||
|
|||
result.ShouldNotBeNull(); |
|||
|
|||
//保存导出文件到服务器存成二进制
|
|||
await _excelImportService.SaveBlobAsync( |
|||
new SaveExcelImportInputDto |
|||
{ |
|||
Name = _fileName, |
|||
Content = result |
|||
} |
|||
); |
|||
return _fileName; |
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
} |
|||
} |
@ -0,0 +1,31 @@ |
|||
using System; |
|||
using System.ComponentModel.DataAnnotations; |
|||
using Win.Sfs.Shared.DomainBase; |
|||
|
|||
using Win.Sfs.Shared.Constant; |
|||
|
|||
namespace Win.Sfs.SettleAccount.Errors |
|||
{ |
|||
/// <summary>
|
|||
/// 错误单据
|
|||
/// </summary>
|
|||
public class ErrorBill : FullAuditedAggregateRootBase<Guid> |
|||
{ |
|||
/// <summary>
|
|||
///错误单据号
|
|||
/// </summary>
|
|||
public string BillNum { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 物料号
|
|||
/// </summary>
|
|||
public string MaterialCode { set; get; } |
|||
|
|||
/// <summary>
|
|||
/// 发货单号
|
|||
/// </summary>
|
|||
public string WmsBillNum { set; get; } |
|||
|
|||
|
|||
} |
|||
} |
Loading…
Reference in new issue