|
|
@ -3,12 +3,14 @@ using System.Collections.Generic; |
|
|
|
using System.Linq; |
|
|
|
using System.Threading.Tasks; |
|
|
|
using Microsoft.AspNetCore.Authorization; |
|
|
|
using Microsoft.AspNetCore.Http; |
|
|
|
using Microsoft.AspNetCore.Mvc; |
|
|
|
using Shouldly; |
|
|
|
using Volo.Abp.Application.Dtos; |
|
|
|
using Volo.Abp.Caching; |
|
|
|
using Win.Abp.Snowflakes; |
|
|
|
using Win.Sfs.BaseData.ImportExcelCommon; |
|
|
|
using Win.Sfs.SettleAccount.Bases; |
|
|
|
using Win.Sfs.SettleAccount.CommonManagers; |
|
|
|
using Win.Sfs.SettleAccount.Constant; |
|
|
|
using Win.Sfs.SettleAccount.Entities.BQ.Dtos; |
|
|
@ -17,436 +19,451 @@ using Win.Sfs.SettleAccount.ExportReports; |
|
|
|
using Win.Sfs.SettleAccount.MaterialRelationships; |
|
|
|
using Win.Sfs.Shared.RepositoryBase; |
|
|
|
|
|
|
|
namespace Win.Sfs.SettleAccount.Entities.MaterialRelationships |
|
|
|
namespace Win.Sfs.SettleAccount.Entities.MaterialRelationships; |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 客户零件关系
|
|
|
|
/// </summary>
|
|
|
|
[AllowAnonymous] |
|
|
|
[Route("api/settleaccount/[controller]/[action]")]
|
|
|
|
public class MaterialRelationshipAppService : SettleAccountApplicationBase<MaterialRelationship> |
|
|
|
{ |
|
|
|
/// <summary>
|
|
|
|
/// 客户零件关系
|
|
|
|
/// 客户零件关系仓储
|
|
|
|
/// </summary>
|
|
|
|
[AllowAnonymous] |
|
|
|
[Route("api/settleaccount/[controller]/[action]")]
|
|
|
|
public class MaterialRelationshipAppService : SettleAccountApplicationBase<MaterialRelationship> |
|
|
|
private readonly INormalEfCoreRepository<MaterialRelationship, Guid> _repository; |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 构造
|
|
|
|
/// </summary>
|
|
|
|
public MaterialRelationshipAppService( |
|
|
|
INormalEfCoreRepository<MaterialRelationship, Guid> repository, |
|
|
|
IDistributedCache<MaterialRelationship> cache, |
|
|
|
IExcelImportAppService excelImportService, |
|
|
|
ISnowflakeIdGenerator snowflakeIdGenerator, |
|
|
|
ICommonManager commonManager |
|
|
|
) : base(cache, excelImportService, snowflakeIdGenerator, commonManager) |
|
|
|
{ |
|
|
|
/// <summary>
|
|
|
|
/// 客户零件关系仓储
|
|
|
|
/// </summary>
|
|
|
|
private readonly INormalEfCoreRepository<MaterialRelationship, Guid> _repository; |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 构造
|
|
|
|
/// </summary>
|
|
|
|
public MaterialRelationshipAppService( |
|
|
|
INormalEfCoreRepository<MaterialRelationship, Guid> repository, |
|
|
|
IDistributedCache<MaterialRelationship> cache, |
|
|
|
IExcelImportAppService excelImportService, |
|
|
|
ISnowflakeIdGenerator snowflakeIdGenerator, |
|
|
|
ICommonManager commonManager |
|
|
|
) : base(cache, excelImportService, snowflakeIdGenerator, commonManager) |
|
|
|
{ |
|
|
|
_repository = repository; |
|
|
|
} |
|
|
|
_repository = repository; |
|
|
|
} |
|
|
|
|
|
|
|
#region 导入、导出
|
|
|
|
/// <summary>
|
|
|
|
/// 导入
|
|
|
|
/// </summary>
|
|
|
|
[HttpPost] |
|
|
|
public async Task<IActionResult> ImportAsync([FromForm] MaterialRelationshipImportRequestDto materialRelationshipImportRequestDto) |
|
|
|
{ |
|
|
|
var _exportImporter = new ExportImporter(); |
|
|
|
var result = await _exportImporter.UploadExcelImport<MaterialRelationshipImportDto>(materialRelationshipImportRequestDto.Files, _excelImportService).ConfigureAwait(false); |
|
|
|
var _ls = ObjectMapper.Map<List<MaterialRelationshipImportDto>, List<MaterialRelationship>>(result); |
|
|
|
List<string> _errorList = new List<string>(); |
|
|
|
var checkList = new List<ErrorExportDto>(); |
|
|
|
#region 导入、导出
|
|
|
|
/// <summary>
|
|
|
|
/// 导入
|
|
|
|
/// </summary>
|
|
|
|
[HttpPost] |
|
|
|
public async Task<IActionResult> ImportAsync([FromForm] MaterialRelationshipImportRequestDto materialRelationshipImportRequestDto) |
|
|
|
{ |
|
|
|
var exportImporter = new ExportImporter(); |
|
|
|
var inportDatas = await exportImporter.UploadExcelImport<MaterialRelationshipImportDto>(materialRelationshipImportRequestDto.Files, _excelImportService).ConfigureAwait(false); |
|
|
|
var entitys = ObjectMapper.Map<List<MaterialRelationshipImportDto>, List<MaterialRelationship>>(inportDatas); |
|
|
|
var errorList = new List<string>(); |
|
|
|
var checkList = new List<ErrorExportDto>(); |
|
|
|
|
|
|
|
if (_ls.Count > 0) |
|
|
|
{ |
|
|
|
var query = from arc in _ls |
|
|
|
group arc by new { arc.SettleMaterialCode } |
|
|
|
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.SettleMaterialCode), string.Empty)); |
|
|
|
} |
|
|
|
} |
|
|
|
if (checkList.Count > 0) |
|
|
|
if (entitys.Count > 0) |
|
|
|
{ |
|
|
|
var query = from arc in entitys |
|
|
|
group arc by new { arc.SettleMaterialCode } |
|
|
|
into g |
|
|
|
where g.Count() > 1 |
|
|
|
select g; |
|
|
|
foreach (var itm in query) |
|
|
|
{ |
|
|
|
string fileName = await ExportErrorReportAsync(checkList).ConfigureAwait(false); |
|
|
|
return new JsonResult(new { Code = ApplicationConsts.ImportFailCode, Message = "错误提示文件已下载,请打开文件查看", fileName = fileName }); |
|
|
|
checkList.Add(new ErrorExportDto(string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Format("客户物料号{0}有重复", itm.Key.SettleMaterialCode), string.Empty)); |
|
|
|
} |
|
|
|
foreach (var itm in _ls) |
|
|
|
} |
|
|
|
if (checkList.Count > 0) |
|
|
|
{ |
|
|
|
string fileName = await ExportErrorReportAsync(checkList).ConfigureAwait(false); |
|
|
|
return new JsonResult(new { Code = ApplicationConsts.ImportFailCode, Message = "错误提示文件已下载,请打开文件查看", fileName = fileName }); |
|
|
|
} |
|
|
|
foreach (var item in entitys) |
|
|
|
{ |
|
|
|
var entity = _repository.FirstOrDefault(p => p.ErpMaterialCode == item.ErpMaterialCode && p.BusinessType == EnumBusinessType.BeiJian && p.SettleMaterialCode == item.SettleMaterialCode); |
|
|
|
if (entity == null) |
|
|
|
{ |
|
|
|
var _first = _repository.FirstOrDefault(p => p.ErpMaterialCode == itm.ErpMaterialCode && p.BusinessType == EnumBusinessType.BeiJian); |
|
|
|
if (_first != null) |
|
|
|
{ |
|
|
|
_first.Update(itm.MaterialDesc, itm.SettleMaterialCode); |
|
|
|
await _repository.UpdateAsync(_first).ConfigureAwait(false); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
itm.BusinessType = EnumBusinessType.BeiJian; |
|
|
|
await _repository.InsertAsync(itm).ConfigureAwait(false); |
|
|
|
} |
|
|
|
item.BusinessType = EnumBusinessType.BeiJian; |
|
|
|
await _repository.InsertAsync(item).ConfigureAwait(false); |
|
|
|
} |
|
|
|
return new JsonResult(new { Code = 200, Message = "导入成功" }); |
|
|
|
} |
|
|
|
return new JsonResult(new { Code = 200, Message = "导入成功" }); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 导出
|
|
|
|
/// </summary>
|
|
|
|
[HttpPost] |
|
|
|
public async Task<string> ExportAsync(RequestDto input) |
|
|
|
{ |
|
|
|
string fileName = $"客户零件关系_{Guid.NewGuid()}.xlsx"; |
|
|
|
var entities = await _repository.GetListByFilterAsync(input.Filters, input.Sorting, int.MaxValue, 0, true).ConfigureAwait(false); |
|
|
|
var dtos = ObjectMapper.Map<List<MaterialRelationship>, List<MaterialRelationshipExportDto>>(entities); |
|
|
|
/// <summary>
|
|
|
|
/// 导出
|
|
|
|
/// </summary>
|
|
|
|
[HttpPost] |
|
|
|
public async Task<string> ExportAsync(RequestDto input) |
|
|
|
{ |
|
|
|
string fileName = $"客户零件关系_{Guid.NewGuid()}.xlsx"; |
|
|
|
var entities = await _repository.GetListByFilterAsync(input.Filters, input.Sorting, int.MaxValue, 0, true).ConfigureAwait(false); |
|
|
|
var dtos = ObjectMapper.Map<List<MaterialRelationship>, List<MaterialRelationshipExportDto>>(entities); |
|
|
|
|
|
|
|
ExportImporter _exportImporter = new ExportImporter(); |
|
|
|
var result = await _exportImporter.ExcelExporter(dtos).ConfigureAwait(false); |
|
|
|
result.ShouldNotBeNull(); |
|
|
|
ExportImporter _exportImporter = new ExportImporter(); |
|
|
|
var result = await _exportImporter.ExcelExporter(dtos).ConfigureAwait(false); |
|
|
|
result.ShouldNotBeNull(); |
|
|
|
|
|
|
|
await _excelImportService.SaveBlobAsync(new SaveExcelImportInputDto { Name = fileName, Content = result }).ConfigureAwait(false); |
|
|
|
return fileName; |
|
|
|
} |
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region CURD
|
|
|
|
/// <summary>
|
|
|
|
/// 获取列表
|
|
|
|
/// </summary>
|
|
|
|
[HttpPost] |
|
|
|
public async Task<PagedResultDto<MaterialRelationshipDto>> GetListAsync(RequestDto input) |
|
|
|
{ |
|
|
|
var entities = await _repository.GetListByFilterAsync(input.Filters, input.Sorting, input.MaxResultCount, input.SkipCount, true).ConfigureAwait(false); |
|
|
|
var totalCount = await _repository.GetCountByFilterAsync(input.Filters).ConfigureAwait(false); |
|
|
|
var dtos = ObjectMapper.Map<List<MaterialRelationship>, List<MaterialRelationshipDto>>(entities); |
|
|
|
return new PagedResultDto<MaterialRelationshipDto>(totalCount, dtos); |
|
|
|
} |
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region 原方法(废弃)
|
|
|
|
///// <summary>
|
|
|
|
///// 导入功能
|
|
|
|
///// </summary>
|
|
|
|
///// <param name="files">上传的文件(前端已经限制只能上传一个附件)</param>
|
|
|
|
///// <returns></returns>
|
|
|
|
//[HttpPost]
|
|
|
|
//[Route("ExcelImport-Map")]
|
|
|
|
//[DisableRequestSizeLimit]
|
|
|
|
//public async Task<string> MaterialRelationshipUploadExcelImportMap([FromForm] IFormFileCollection files)
|
|
|
|
//{
|
|
|
|
// ExportImporter _exportImporter = new ExportImporter();
|
|
|
|
// var mapList = _mapRepository.Where(p => p.ProjectName == SettleAccountModuleName.MaterialRelationship).ToList();
|
|
|
|
// var result = await _exportImporter.ExtendExcelImport<MaterialRelationshipImportDto>(files, _excelImportService, mapList);
|
|
|
|
// var _ls = ObjectMapper.Map<List<MaterialRelationshipImportDto>, List<MaterialRelationship>>(result);
|
|
|
|
// List<string> _errorList = new List<string>();
|
|
|
|
// var checkList = new List<ErrorExportDto>();
|
|
|
|
// if (_ls.Count > 0)
|
|
|
|
// {
|
|
|
|
// var query = from arc in _ls
|
|
|
|
// group arc by new { arc.ErpMaterialCode }
|
|
|
|
// 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("ERP物料号{0}有重复", itm.Key.ErpMaterialCode), string.Empty));
|
|
|
|
// // _errorList.Add(string.Format("ERP物料号{0}有重复",itm.Key.ErpMaterialCode));
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// foreach (var itm in _ls)
|
|
|
|
// {
|
|
|
|
// var _first = _repository.FirstOrDefault(p => p.ErpMaterialCode == itm.ErpMaterialCode);
|
|
|
|
// if (_first != null)
|
|
|
|
// {
|
|
|
|
// _first.Update(itm.MaterialDesc, itm.MaterialProperty, itm.SettleMaterialCode, itm.ShipMaterailCode);
|
|
|
|
// await _repository.UpdateAsync(_first);
|
|
|
|
// }
|
|
|
|
// else
|
|
|
|
// {
|
|
|
|
// checkList.Add(new ErrorExportDto(string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Format("关系表中不存在ERP物料号{0}!", itm.ErpMaterialCode), string.Empty));
|
|
|
|
// //_errorList.Add(string.Format("关系表中不存在ERP物料号{0}!", itm.ErpMaterialCode));
|
|
|
|
// //itm.SetId(GuidGenerator.Create(), GuidGenerator.Create());
|
|
|
|
// //await _repository.InsertAsync(itm);
|
|
|
|
// }
|
|
|
|
// //itm.SetId(GuidGenerator.Create(), GuidGenerator.Create());
|
|
|
|
|
|
|
|
// }
|
|
|
|
// if (checkList.Count > 0)
|
|
|
|
// {
|
|
|
|
// return await ExportErrorReportAsync(checkList);
|
|
|
|
// }
|
|
|
|
|
|
|
|
// return ApplicationConsts.SuccessStr;
|
|
|
|
//}
|
|
|
|
|
|
|
|
///// <summary>
|
|
|
|
///// 导入功能
|
|
|
|
///// </summary>
|
|
|
|
///// <param name="files">上传的文件(前端已经限制只能上传一个附件)</param>
|
|
|
|
///// <returns></returns>
|
|
|
|
//[HttpPost]
|
|
|
|
//[Route("ExcelImport")]
|
|
|
|
//[DisableRequestSizeLimit]
|
|
|
|
//public async Task<string> MaterialRelationshipUploadExcelImport([FromForm] IFormFileCollection files)
|
|
|
|
//{
|
|
|
|
|
|
|
|
// ExportImporter _exportImporter = new ExportImporter();
|
|
|
|
// var result = await _exportImporter.UploadExcelImport<MaterialRelationshipImportDto>(files, _excelImportService);
|
|
|
|
// var _ls = ObjectMapper.Map<List<MaterialRelationshipImportDto>, List<MaterialRelationship>>(result);
|
|
|
|
// List<string> _errorList = new List<string>();
|
|
|
|
// var checkList = new List<ErrorExportDto>();
|
|
|
|
|
|
|
|
// if (_ls.Count > 0)
|
|
|
|
// {
|
|
|
|
// var query = from arc in _ls
|
|
|
|
// group arc by new { arc.ErpMaterialCode }
|
|
|
|
// 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("ERP物料号{0}有重复", itm.Key.ErpMaterialCode), string.Empty));
|
|
|
|
// // _errorList.Add(string.Format("ERP物料号{0}有重复",itm.Key.ErpMaterialCode));
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// foreach (var itm in _ls)
|
|
|
|
// {
|
|
|
|
// var _first = _repository.FirstOrDefault(p => p.ErpMaterialCode == itm.ErpMaterialCode);
|
|
|
|
// if (_first != null)
|
|
|
|
// {
|
|
|
|
// _first.Update(itm.MaterialDesc, itm.MaterialProperty, itm.SettleMaterialCode, itm.ShipMaterailCode);
|
|
|
|
// await _repository.UpdateAsync(_first);
|
|
|
|
// }
|
|
|
|
// else
|
|
|
|
// {
|
|
|
|
// checkList.Add(new ErrorExportDto(string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Format("关系表中不存在ERP物料号{0}!", itm.ErpMaterialCode), string.Empty));
|
|
|
|
// //_errorList.Add(string.Format("关系表中不存在ERP物料号{0}!", itm.ErpMaterialCode));
|
|
|
|
// //itm.SetId(GuidGenerator.Create(), GuidGenerator.Create());
|
|
|
|
// //await _repository.InsertAsync(itm);
|
|
|
|
// }
|
|
|
|
// //itm.SetId(GuidGenerator.Create(), GuidGenerator.Create());
|
|
|
|
|
|
|
|
// }
|
|
|
|
// if (checkList.Count > 0)
|
|
|
|
// {
|
|
|
|
// return await ExportErrorReportAsync(checkList);
|
|
|
|
// }
|
|
|
|
|
|
|
|
// return ApplicationConsts.SuccessStr;
|
|
|
|
//}
|
|
|
|
|
|
|
|
///// <summary>
|
|
|
|
///// 按ID获取唯一实体
|
|
|
|
///// </summary>
|
|
|
|
///// <remarks>
|
|
|
|
///// 返回实体全部属性
|
|
|
|
///// </remarks>
|
|
|
|
///// <param name="id">ID</param>
|
|
|
|
///// <returns>实体DTO</returns>
|
|
|
|
//[HttpGet]
|
|
|
|
//[Route("{id}")]
|
|
|
|
//virtual public async Task<MaterialRelationshipDto> GetAsync(Guid id)
|
|
|
|
//{
|
|
|
|
// var result = await GetFromCacheAsync(id);
|
|
|
|
// var dto = ObjectMapper.Map<MaterialRelationship, MaterialRelationshipDto>(result);
|
|
|
|
// return dto;
|
|
|
|
//}
|
|
|
|
|
|
|
|
//private async Task<MaterialRelationship> GetFromCacheAsync(Guid id)
|
|
|
|
//{
|
|
|
|
// var result = await _repository.GetAsync(id);
|
|
|
|
|
|
|
|
// return result;
|
|
|
|
//}
|
|
|
|
|
|
|
|
//private async Task<long> GetCountAsync(MaterialRelationshipRequestDto 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<MaterialRelationshipDto>> GetListAsync(MaterialRelationshipRequestDto 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<MaterialRelationship>, List<MaterialRelationshipDto>>(entities);
|
|
|
|
|
|
|
|
// return new PagedResultDto<MaterialRelationshipDto>(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<MaterialRelationshipDto>> GetAllAsync(Guid branchId)
|
|
|
|
//{
|
|
|
|
// var entities = await _repository.GetAllAsync(branchId, true);
|
|
|
|
|
|
|
|
// var dtos = ObjectMapper.Map<List<MaterialRelationship>, List<MaterialRelationshipDto>>(entities);
|
|
|
|
|
|
|
|
// return new ListResultDto<MaterialRelationshipDto>(dtos);
|
|
|
|
//}
|
|
|
|
|
|
|
|
///// <summary>
|
|
|
|
///// 新增实体
|
|
|
|
///// </summary>
|
|
|
|
///// <param name="input">新增实体DTO</param>
|
|
|
|
///// <returns>实体DTO</returns>
|
|
|
|
|
|
|
|
//[HttpPost]
|
|
|
|
//[Route("")]
|
|
|
|
//virtual public async Task<MaterialRelationshipDto> CreateAsync(MaterialRelationshipCreateDto input)
|
|
|
|
//{
|
|
|
|
|
|
|
|
// var _first = _repository.Where(p => p.ErpMaterialCode == input.ErpMaterialCode).FirstOrDefault();
|
|
|
|
|
|
|
|
// if (_first != null)
|
|
|
|
// {
|
|
|
|
// throw new BusinessException("001", "已经存数据请修改后创建");
|
|
|
|
// }
|
|
|
|
|
|
|
|
// var entity = new MaterialRelationship(
|
|
|
|
// GuidGenerator.Create(),
|
|
|
|
// input.BranchId,
|
|
|
|
// input.ErpMaterialCode,
|
|
|
|
|
|
|
|
// input.MaterialDesc,
|
|
|
|
// input.MaterialProperty,
|
|
|
|
// input.SettleMaterialCode,
|
|
|
|
// input.ShipMaterailCode,
|
|
|
|
// input.AppraisalCategory
|
|
|
|
|
|
|
|
// );
|
|
|
|
|
|
|
|
// await _repository.InsertAsync(entity);
|
|
|
|
|
|
|
|
// ////create cache
|
|
|
|
// //await Cache.SetAsync(entity.Id.ToString(), entity,
|
|
|
|
// // CacheStrategyConst.FIVE_MINUTES);
|
|
|
|
|
|
|
|
// var dto = ObjectMapper.Map<MaterialRelationship, MaterialRelationshipDto>(entity);
|
|
|
|
// return dto;
|
|
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
///// <summary>
|
|
|
|
///// 修改实体
|
|
|
|
///// </summary>
|
|
|
|
///// <param name="id">ID</param>
|
|
|
|
///// <param name="input">修改实体DTO</param>
|
|
|
|
///// <returns>实体DTO</returns>
|
|
|
|
//[HttpPut]
|
|
|
|
//[Route("{id}")]
|
|
|
|
//virtual public async Task<MaterialRelationshipDto> UpdateAsync(Guid id, MaterialRelationshipUpdateDto input)
|
|
|
|
//{
|
|
|
|
// var entity = await _repository.GetAsync(id);
|
|
|
|
// if (entity != null)
|
|
|
|
// {
|
|
|
|
// entity.Update(input.MaterialDesc, input.MaterialProperty, input.SettleMaterialCode, input.ShipMaterailCode);
|
|
|
|
|
|
|
|
// await _repository.UpdateAsync(entity);
|
|
|
|
|
|
|
|
// var dto = ObjectMapper.Map<MaterialRelationship, MaterialRelationshipDto>(entity);
|
|
|
|
// return dto;
|
|
|
|
// }
|
|
|
|
// else
|
|
|
|
// {
|
|
|
|
// return null;
|
|
|
|
// }
|
|
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
///// <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<MaterialRelationship>(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(MaterialRelationshipRequestDto input)
|
|
|
|
//{
|
|
|
|
// //var _userId = CurrentUser.Id.Value.ToString();
|
|
|
|
// string _fileName = string.Format("零件关系_{0}.xlsx", Guid.NewGuid().ToString());
|
|
|
|
// var entities = await _repository.GetListByFilterAsync(input.BranchId, input.Filters, input.Sorting, int.MaxValue,
|
|
|
|
// 0, true);
|
|
|
|
|
|
|
|
// var dtoDetails = ObjectMapper.Map<List<MaterialRelationship>, List<MaterialRelationshipExportDto>>(entities);
|
|
|
|
|
|
|
|
// //声明导出容器
|
|
|
|
// ExportImporter _exportImporter = new ExportImporter();
|
|
|
|
|
|
|
|
// var result = await _exportImporter.ExcelExporter(dtoDetails);
|
|
|
|
|
|
|
|
// result.ShouldNotBeNull();
|
|
|
|
|
|
|
|
// //保存导出文件到服务器存成二进制
|
|
|
|
// await _excelImportService.SaveBlobAsync(
|
|
|
|
// new SaveExcelImportInputDto
|
|
|
|
// {
|
|
|
|
// Name = _fileName,
|
|
|
|
// Content = result
|
|
|
|
// }
|
|
|
|
// );
|
|
|
|
// return _fileName;
|
|
|
|
//}
|
|
|
|
#endregion
|
|
|
|
await _excelImportService.SaveBlobAsync(new SaveExcelImportInputDto { Name = fileName, Content = result }).ConfigureAwait(false); |
|
|
|
return fileName; |
|
|
|
} |
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region CURD
|
|
|
|
/// <summary>
|
|
|
|
/// 获取列表
|
|
|
|
/// </summary>
|
|
|
|
[HttpPost] |
|
|
|
public async Task<PagedResultDto<MaterialRelationshipDto>> GetListAsync(RequestDto input) |
|
|
|
{ |
|
|
|
var entities = await _repository.GetListByFilterAsync(input.Filters, input.Sorting, input.MaxResultCount, input.SkipCount, true).ConfigureAwait(false); |
|
|
|
var totalCount = await _repository.GetCountByFilterAsync(input.Filters).ConfigureAwait(false); |
|
|
|
var dtos = ObjectMapper.Map<List<MaterialRelationship>, List<MaterialRelationshipDto>>(entities); |
|
|
|
return new PagedResultDto<MaterialRelationshipDto>(totalCount, dtos); |
|
|
|
} |
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region 原方法(废弃)
|
|
|
|
///// <summary>
|
|
|
|
///// 导入功能
|
|
|
|
///// </summary>
|
|
|
|
///// <param name="files">上传的文件(前端已经限制只能上传一个附件)</param>
|
|
|
|
///// <returns></returns>
|
|
|
|
//[HttpPost]
|
|
|
|
//[Route("ExcelImport-Map")]
|
|
|
|
//[DisableRequestSizeLimit]
|
|
|
|
//public async Task<string> MaterialRelationshipUploadExcelImportMap([FromForm] IFormFileCollection files)
|
|
|
|
//{
|
|
|
|
// ExportImporter _exportImporter = new ExportImporter();
|
|
|
|
// var mapList = _mapRepository.Where(p => p.ProjectName == SettleAccountModuleName.MaterialRelationship).ToList();
|
|
|
|
// var result = await _exportImporter.ExtendExcelImport<MaterialRelationshipImportDto>(files, _excelImportService, mapList);
|
|
|
|
// var _ls = ObjectMapper.Map<List<MaterialRelationshipImportDto>, List<MaterialRelationship>>(result);
|
|
|
|
// List<string> _errorList = new List<string>();
|
|
|
|
// var checkList = new List<ErrorExportDto>();
|
|
|
|
// if (_ls.Count > 0)
|
|
|
|
// {
|
|
|
|
// var query = from arc in _ls
|
|
|
|
// group arc by new { arc.ErpMaterialCode }
|
|
|
|
// 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("ERP物料号{0}有重复", itm.Key.ErpMaterialCode), string.Empty));
|
|
|
|
// // _errorList.Add(string.Format("ERP物料号{0}有重复",itm.Key.ErpMaterialCode));
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// foreach (var itm in _ls)
|
|
|
|
// {
|
|
|
|
// var _first = _repository.FirstOrDefault(p => p.ErpMaterialCode == itm.ErpMaterialCode);
|
|
|
|
// if (_first != null)
|
|
|
|
// {
|
|
|
|
// _first.Update(itm.MaterialDesc, itm.MaterialProperty, itm.SettleMaterialCode, itm.ShipMaterailCode);
|
|
|
|
// await _repository.UpdateAsync(_first);
|
|
|
|
// }
|
|
|
|
// else
|
|
|
|
// {
|
|
|
|
// checkList.Add(new ErrorExportDto(string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Format("关系表中不存在ERP物料号{0}!", itm.ErpMaterialCode), string.Empty));
|
|
|
|
// //_errorList.Add(string.Format("关系表中不存在ERP物料号{0}!", itm.ErpMaterialCode));
|
|
|
|
// //itm.SetId(GuidGenerator.Create(), GuidGenerator.Create());
|
|
|
|
// //await _repository.InsertAsync(itm);
|
|
|
|
// }
|
|
|
|
// //itm.SetId(GuidGenerator.Create(), GuidGenerator.Create());
|
|
|
|
|
|
|
|
// }
|
|
|
|
// if (checkList.Count > 0)
|
|
|
|
// {
|
|
|
|
// return await ExportErrorReportAsync(checkList);
|
|
|
|
// }
|
|
|
|
|
|
|
|
// return ApplicationConsts.SuccessStr;
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
///// <summary>
|
|
|
|
///// 导入功能
|
|
|
|
///// </summary>
|
|
|
|
///// <param name="files">上传的文件(前端已经限制只能上传一个附件)</param>
|
|
|
|
///// <returns></returns>
|
|
|
|
//[HttpPost]
|
|
|
|
//[Route("ExcelImport")]
|
|
|
|
//[DisableRequestSizeLimit]
|
|
|
|
//public async Task<string> MaterialRelationshipUploadExcelImport([FromForm] IFormFileCollection files)
|
|
|
|
//{
|
|
|
|
|
|
|
|
|
|
|
|
// ExportImporter _exportImporter = new ExportImporter();
|
|
|
|
// var result = await _exportImporter.UploadExcelImport<MaterialRelationshipImportDto>(files, _excelImportService);
|
|
|
|
// var _ls = ObjectMapper.Map<List<MaterialRelationshipImportDto>, List<MaterialRelationship>>(result);
|
|
|
|
// List<string> _errorList = new List<string>();
|
|
|
|
// var checkList = new List<ErrorExportDto>();
|
|
|
|
|
|
|
|
// if (_ls.Count > 0)
|
|
|
|
// {
|
|
|
|
// var query = from arc in _ls
|
|
|
|
// group arc by new { arc.ErpMaterialCode }
|
|
|
|
// 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("ERP物料号{0}有重复", itm.Key.ErpMaterialCode), string.Empty));
|
|
|
|
// // _errorList.Add(string.Format("ERP物料号{0}有重复",itm.Key.ErpMaterialCode));
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// foreach (var itm in _ls)
|
|
|
|
// {
|
|
|
|
// var _first = _repository.FirstOrDefault(p => p.ErpMaterialCode == itm.ErpMaterialCode);
|
|
|
|
// if (_first != null)
|
|
|
|
// {
|
|
|
|
// _first.Update(itm.MaterialDesc, itm.MaterialProperty, itm.SettleMaterialCode, itm.ShipMaterailCode);
|
|
|
|
// await _repository.UpdateAsync(_first);
|
|
|
|
// }
|
|
|
|
// else
|
|
|
|
// {
|
|
|
|
// checkList.Add(new ErrorExportDto(string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Format("关系表中不存在ERP物料号{0}!", itm.ErpMaterialCode), string.Empty));
|
|
|
|
// //_errorList.Add(string.Format("关系表中不存在ERP物料号{0}!", itm.ErpMaterialCode));
|
|
|
|
// //itm.SetId(GuidGenerator.Create(), GuidGenerator.Create());
|
|
|
|
// //await _repository.InsertAsync(itm);
|
|
|
|
// }
|
|
|
|
// //itm.SetId(GuidGenerator.Create(), GuidGenerator.Create());
|
|
|
|
|
|
|
|
// }
|
|
|
|
// if (checkList.Count > 0)
|
|
|
|
// {
|
|
|
|
// return await ExportErrorReportAsync(checkList);
|
|
|
|
// }
|
|
|
|
|
|
|
|
// return ApplicationConsts.SuccessStr;
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
///// <summary>
|
|
|
|
///// 按ID获取唯一实体
|
|
|
|
///// </summary>
|
|
|
|
///// <remarks>
|
|
|
|
///// 返回实体全部属性
|
|
|
|
///// </remarks>
|
|
|
|
///// <param name="id">ID</param>
|
|
|
|
///// <returns>实体DTO</returns>
|
|
|
|
//[HttpGet]
|
|
|
|
//[Route("{id}")]
|
|
|
|
//virtual public async Task<MaterialRelationshipDto> GetAsync(Guid id)
|
|
|
|
//{
|
|
|
|
// var result = await GetFromCacheAsync(id);
|
|
|
|
// var dto = ObjectMapper.Map<MaterialRelationship, MaterialRelationshipDto>(result);
|
|
|
|
// return dto;
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
//private async Task<MaterialRelationship> GetFromCacheAsync(Guid id)
|
|
|
|
//{
|
|
|
|
// var result = await _repository.GetAsync(id);
|
|
|
|
|
|
|
|
|
|
|
|
// return result;
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
//private async Task<long> GetCountAsync(MaterialRelationshipRequestDto 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<MaterialRelationshipDto>> GetListAsync(MaterialRelationshipRequestDto 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<MaterialRelationship>, List<MaterialRelationshipDto>>(entities);
|
|
|
|
|
|
|
|
// return new PagedResultDto<MaterialRelationshipDto>(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<MaterialRelationshipDto>> GetAllAsync(Guid branchId)
|
|
|
|
//{
|
|
|
|
// var entities = await _repository.GetAllAsync(branchId, true);
|
|
|
|
|
|
|
|
|
|
|
|
// var dtos = ObjectMapper.Map<List<MaterialRelationship>, List<MaterialRelationshipDto>>(entities);
|
|
|
|
|
|
|
|
|
|
|
|
// return new ListResultDto<MaterialRelationshipDto>(dtos);
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
///// <summary>
|
|
|
|
///// 新增实体
|
|
|
|
///// </summary>
|
|
|
|
///// <param name="input">新增实体DTO</param>
|
|
|
|
///// <returns>实体DTO</returns>
|
|
|
|
|
|
|
|
//[HttpPost]
|
|
|
|
//[Route("")]
|
|
|
|
//virtual public async Task<MaterialRelationshipDto> CreateAsync(MaterialRelationshipCreateDto input)
|
|
|
|
//{
|
|
|
|
|
|
|
|
|
|
|
|
// var _first = _repository.Where(p => p.ErpMaterialCode == input.ErpMaterialCode).FirstOrDefault();
|
|
|
|
|
|
|
|
// if (_first != null)
|
|
|
|
// {
|
|
|
|
// throw new BusinessException("001", "已经存数据请修改后创建");
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
// var entity = new MaterialRelationship(
|
|
|
|
// GuidGenerator.Create(),
|
|
|
|
// input.BranchId,
|
|
|
|
// input.ErpMaterialCode,
|
|
|
|
|
|
|
|
// input.MaterialDesc,
|
|
|
|
// input.MaterialProperty,
|
|
|
|
// input.SettleMaterialCode,
|
|
|
|
// input.ShipMaterailCode,
|
|
|
|
// input.AppraisalCategory
|
|
|
|
|
|
|
|
|
|
|
|
// );
|
|
|
|
|
|
|
|
// await _repository.InsertAsync(entity);
|
|
|
|
|
|
|
|
// ////create cache
|
|
|
|
// //await Cache.SetAsync(entity.Id.ToString(), entity,
|
|
|
|
// // CacheStrategyConst.FIVE_MINUTES);
|
|
|
|
|
|
|
|
// var dto = ObjectMapper.Map<MaterialRelationship, MaterialRelationshipDto>(entity);
|
|
|
|
// return dto;
|
|
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
///// <summary>
|
|
|
|
///// 修改实体
|
|
|
|
///// </summary>
|
|
|
|
///// <param name="id">ID</param>
|
|
|
|
///// <param name="input">修改实体DTO</param>
|
|
|
|
///// <returns>实体DTO</returns>
|
|
|
|
//[HttpPut]
|
|
|
|
//[Route("{id}")]
|
|
|
|
//virtual public async Task<MaterialRelationshipDto> UpdateAsync(Guid id, MaterialRelationshipUpdateDto input)
|
|
|
|
//{
|
|
|
|
// var entity = await _repository.GetAsync(id);
|
|
|
|
// if (entity != null)
|
|
|
|
// {
|
|
|
|
// entity.Update(input.MaterialDesc, input.MaterialProperty, input.SettleMaterialCode, input.ShipMaterailCode);
|
|
|
|
|
|
|
|
// await _repository.UpdateAsync(entity);
|
|
|
|
|
|
|
|
|
|
|
|
// var dto = ObjectMapper.Map<MaterialRelationship, MaterialRelationshipDto>(entity);
|
|
|
|
// return dto;
|
|
|
|
// }
|
|
|
|
// else
|
|
|
|
// {
|
|
|
|
// return null;
|
|
|
|
// }
|
|
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
///// <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<MaterialRelationship>(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(MaterialRelationshipRequestDto input)
|
|
|
|
//{
|
|
|
|
// //var _userId = CurrentUser.Id.Value.ToString();
|
|
|
|
// string _fileName = string.Format("零件关系_{0}.xlsx", Guid.NewGuid().ToString());
|
|
|
|
// var entities = await _repository.GetListByFilterAsync(input.BranchId, input.Filters, input.Sorting, int.MaxValue,
|
|
|
|
// 0, true);
|
|
|
|
|
|
|
|
// var dtoDetails = ObjectMapper.Map<List<MaterialRelationship>, List<MaterialRelationshipExportDto>>(entities);
|
|
|
|
|
|
|
|
// //声明导出容器
|
|
|
|
// ExportImporter _exportImporter = new ExportImporter();
|
|
|
|
|
|
|
|
// var result = await _exportImporter.ExcelExporter(dtoDetails);
|
|
|
|
|
|
|
|
// result.ShouldNotBeNull();
|
|
|
|
|
|
|
|
// //保存导出文件到服务器存成二进制
|
|
|
|
// await _excelImportService.SaveBlobAsync(
|
|
|
|
// new SaveExcelImportInputDto
|
|
|
|
// {
|
|
|
|
// Name = _fileName,
|
|
|
|
// Content = result
|
|
|
|
// }
|
|
|
|
// );
|
|
|
|
// return _fileName;
|
|
|
|
//}
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
} |
|
|
|