mahao 1 year ago
parent
commit
cd5c09d908
  1. 6
      code/src/Modules/SettleAccount/src/SettleAccount.Application.Contracts/Entities/BQ/Dtos/TB_RePartsRelationship_DTO.cs
  2. 169
      code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/TB_RePartsRelationship_SERVICE.cs
  3. 5
      code/src/Modules/SettleAccount/src/SettleAccount.Application/SettleAccountApplicationAutoMapperProfile.cs

6
code/src/Modules/SettleAccount/src/SettleAccount.Application.Contracts/Entities/BQ/Dtos/TB_RePartsRelationship_DTO.cs

@ -27,6 +27,12 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Dtos
/// </summary> /// </summary>
[Display(Name = "业务类型")] [Display(Name = "业务类型")]
public EnumBusinessType BusinessType { get; set; } public EnumBusinessType BusinessType { get; set; }
/// <summary>
/// 业务类型
/// </summary>
[Display(Name = "业务类型")]
public string BusinessTypeDisplayName { get; set; }
} }
/// <summary> /// <summary>

169
code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/TB_RePartsRelationship_SERVICE.cs

@ -18,109 +18,108 @@ using Win.Sfs.SettleAccount.ExcelImporter;
using Win.Sfs.SettleAccount.ExportReports; using Win.Sfs.SettleAccount.ExportReports;
using Win.Sfs.Shared.RepositoryBase; using Win.Sfs.Shared.RepositoryBase;
namespace Win.Sfs.SettleAccount.Entities.BQ namespace Win.Sfs.SettleAccount.Entities.BQ;
/// <summary>
/// 客户替换件关系
/// </summary>
[AllowAnonymous]
[Route("api/settleaccount/[controller]/[action]")]
public class TB_RePartsRelationship_SERVICE : SettleAccountApplicationBase<TB_RePartsRelationship>
{ {
/// <summary> /// <summary>
/// 客户替换件关系 /// 客户替换件关系仓储
/// </summary> /// </summary>
[AllowAnonymous] private readonly INormalEfCoreRepository<TB_RePartsRelationship, Guid> _repository;
[Route("api/settleaccount/[controller]/[action]")]
public class TB_RePartsRelationship_SERVICE : SettleAccountApplicationBase<TB_RePartsRelationship> public TB_RePartsRelationship_SERVICE(
INormalEfCoreRepository<TB_RePartsRelationship, Guid> repository,
IDistributedCache<TB_RePartsRelationship> cache,
IExcelImportAppService excelImportService,
ISnowflakeIdGenerator snowflakeIdGenerator,
ICommonManager commonManager
) : base(cache, excelImportService, snowflakeIdGenerator, commonManager)
{ {
/// <summary> _repository = repository;
/// 客户替换件关系仓储 }
/// </summary>
private readonly INormalEfCoreRepository<TB_RePartsRelationship, Guid> _repository;
public TB_RePartsRelationship_SERVICE( #region 导入、导出
INormalEfCoreRepository<TB_RePartsRelationship, Guid> repository, /// <summary>
IDistributedCache<TB_RePartsRelationship> cache, /// 导入
IExcelImportAppService excelImportService, /// </summary>
ISnowflakeIdGenerator snowflakeIdGenerator, [HttpPost]
ICommonManager commonManager public async Task<string> ImportAsync([FromForm] IFormFileCollection files)
) : base(cache, excelImportService, snowflakeIdGenerator, commonManager) {
{ ExportImporter _exportImporter = new ExportImporter();
_repository = repository; var result = await _exportImporter.UploadExcelImport<TB_RePartsRelationship_IMPORT_DTO>(files, _excelImportService);
} var _ls = ObjectMapper.Map<List<TB_RePartsRelationship_IMPORT_DTO>, List<TB_RePartsRelationship>>(result);
List<string> _errorList = new List<string>();
var checkList = new List<ErrorExportDto>();
#region 导入、导出 if (_ls.Count > 0)
/// <summary>
/// 导入
/// </summary>
[HttpPost]
public async Task<string> ImportAsync([FromForm] IFormFileCollection files)
{ {
ExportImporter _exportImporter = new ExportImporter(); var query = from arc in _ls
var result = await _exportImporter.UploadExcelImport<TB_RePartsRelationship_IMPORT_DTO>(files, _excelImportService); group arc by new { arc.LU }
var _ls = ObjectMapper.Map<List<TB_RePartsRelationship_IMPORT_DTO>, List<TB_RePartsRelationship>>(result); into g
List<string> _errorList = new List<string>(); where g.Count() > 1
var checkList = new List<ErrorExportDto>();
if (_ls.Count > 0) select g;
foreach (var itm in query)
{ {
var query = from arc in _ls checkList.Add(new ErrorExportDto(string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Format("客户物料号{0}有重复", itm.Key.LU), string.Empty));
group arc by new { arc.LU }
into g
where g.Count() > 1
select g;
foreach (var itm in query)
{
checkList.Add(new ErrorExportDto(string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Format("客户物料号{0}有重复", itm.Key.LU), string.Empty));
}
} }
if (checkList.Count > 0) }
if (checkList.Count > 0)
{
return await ExportErrorReportAsync(checkList);
}
foreach (var itm in _ls)
{
var _first = _repository.FirstOrDefault(p => p.LU == itm.LU);
if (_first != null)
{ {
return await ExportErrorReportAsync(checkList); _first.Update(itm.LU, itm.RepLU, itm.ClientCode, itm.BusinessType);
await _repository.UpdateAsync(_first);
} }
foreach (var itm in _ls) else
{ {
var _first = _repository.FirstOrDefault(p => p.LU == itm.LU); await _repository.InsertAsync(itm);
if (_first != null)
{
_first.Update(itm.LU, itm.RepLU, itm.ClientCode, itm.BusinessType);
await _repository.UpdateAsync(_first);
}
else
{
await _repository.InsertAsync(itm);
}
} }
return ApplicationConsts.SuccessStr;
} }
return ApplicationConsts.SuccessStr;
}
/// <summary> /// <summary>
/// 导出 /// 导出
/// </summary> /// </summary>
[HttpPost] [HttpPost]
public async Task<string> ExportAsync(RequestDto input) public async Task<string> ExportAsync(RequestDto input)
{ {
string fileName = $"客户替换件关系_{Guid.NewGuid()}.xlsx"; string fileName = $"客户替换件关系_{Guid.NewGuid()}.xlsx";
var entities = await _repository.GetListByFilterAsync(input.Filters, input.Sorting, int.MaxValue, 0, true); var entities = await _repository.GetListByFilterAsync(input.Filters, input.Sorting, int.MaxValue, 0, true);
var dtos = ObjectMapper.Map<List<TB_RePartsRelationship>, List<TB_RePartsRelationship_EXPORT_DTO>>(entities); var dtos = ObjectMapper.Map<List<TB_RePartsRelationship>, List<TB_RePartsRelationship_EXPORT_DTO>>(entities);
ExportImporter _exportImporter = new ExportImporter();
var result = await _exportImporter.ExcelExporter(dtos);
result.ShouldNotBeNull();
await _excelImportService.SaveBlobAsync(new SaveExcelImportInputDto { Name = fileName, Content = result }); ExportImporter _exportImporter = new ExportImporter();
return fileName; var result = await _exportImporter.ExcelExporter(dtos);
} result.ShouldNotBeNull();
#endregion
#region CURD await _excelImportService.SaveBlobAsync(new SaveExcelImportInputDto { Name = fileName, Content = result });
/// <summary> return fileName;
/// 获取列表 }
/// </summary> #endregion
[HttpPost]
public async Task<PagedResultDto<TB_RePartsRelationship_DTO>> GetListAsync(RequestDto input)
{
var entities = await _repository.GetListByFilterAsync(input.Filters, input.Sorting, input.MaxResultCount, input.SkipCount, true);
var totalCount = await _repository.GetCountByFilterAsync(input.Filters);
var dtos = ObjectMapper.Map<List<TB_RePartsRelationship>, List<TB_RePartsRelationship_DTO>>(entities);
return new PagedResultDto<TB_RePartsRelationship_DTO>(totalCount, dtos);
}
#endregion
#region CURD
/// <summary>
/// 获取列表
/// </summary>
[HttpPost]
public async Task<PagedResultDto<TB_RePartsRelationship_DTO>> GetListAsync(RequestDto input)
{
var entities = await _repository.GetListByFilterAsync(input.Filters, input.Sorting, input.MaxResultCount, input.SkipCount, true);
var totalCount = await _repository.GetCountByFilterAsync(input.Filters);
var dtos = ObjectMapper.Map<List<TB_RePartsRelationship>, List<TB_RePartsRelationship_DTO>>(entities);
return new PagedResultDto<TB_RePartsRelationship_DTO>(totalCount, dtos);
} }
#endregion
} }

5
code/src/Modules/SettleAccount/src/SettleAccount.Application/SettleAccountApplicationAutoMapperProfile.cs

@ -56,6 +56,8 @@ using Win.Sfs.SettleAccount.Errors;
using Win.Sfs.SettleAccount.Entities.Errors; using Win.Sfs.SettleAccount.Entities.Errors;
using Win.Sfs.SettleAccount.Entities.BQ.Dtos; using Win.Sfs.SettleAccount.Entities.BQ.Dtos;
using SettleAccount.Domain.BQ; using SettleAccount.Domain.BQ;
using System.ComponentModel.DataAnnotations;
using System.Reflection;
namespace Win.Sfs.SettleAccount namespace Win.Sfs.SettleAccount
{ {
@ -923,7 +925,8 @@ namespace Win.Sfs.SettleAccount
/// </summary> /// </summary>
private void CreateMapTB_RePartsRelationship() private void CreateMapTB_RePartsRelationship()
{ {
CreateMap<TB_RePartsRelationship, TB_RePartsRelationship_DTO>(); CreateMap<TB_RePartsRelationship, TB_RePartsRelationship_DTO>()
.ForMember(x => x.BusinessTypeDisplayName, y => y.MapFrom(t => t.BusinessType.GetType().GetField(t.BusinessType.ToString()).GetCustomAttribute<DisplayAttribute>().Name));
CreateMap<TB_RePartsRelationship, TB_RePartsRelationship_EXPORT_DTO>(); CreateMap<TB_RePartsRelationship, TB_RePartsRelationship_EXPORT_DTO>();
CreateMap<TB_RePartsRelationship_IMPORT_DTO, TB_RePartsRelationship>(); CreateMap<TB_RePartsRelationship_IMPORT_DTO, TB_RePartsRelationship>();
} }

Loading…
Cancel
Save