6 changed files with 1386 additions and 1 deletions
@ -0,0 +1,361 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Diagnostics; |
||||
|
using System.Linq; |
||||
|
using System.Threading.Tasks; |
||||
|
using EFCore.BulkExtensions; |
||||
|
using Magicodes.ExporterAndImporter.Core; |
||||
|
using Magicodes.ExporterAndImporter.Csv; |
||||
|
using Magicodes.ExporterAndImporter.Excel; |
||||
|
using Microsoft.AspNetCore.Authorization; |
||||
|
using Microsoft.AspNetCore.Http; |
||||
|
using Microsoft.AspNetCore.Mvc; |
||||
|
using Microsoft.EntityFrameworkCore; |
||||
|
using Microsoft.Extensions.Caching.Distributed; |
||||
|
using Shouldly; |
||||
|
using Volo.Abp; |
||||
|
using Volo.Abp.Application.Dtos; |
||||
|
using Volo.Abp.Application.Services; |
||||
|
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.CommonManagers; |
||||
|
using Win.Sfs.SettleAccount.Constant; |
||||
|
using Win.Sfs.SettleAccount.Entities.JFCarConsigns; |
||||
|
using Win.Sfs.SettleAccount.Entities.Materials; |
||||
|
using Win.Sfs.SettleAccount.ExcelImporter; |
||||
|
using Win.Sfs.SettleAccount.ExportReports; |
||||
|
using Win.Sfs.SettleAccount.MaterialRelationships; |
||||
|
using Win.Sfs.Shared.CacheBase; |
||||
|
using Win.Sfs.Shared.Enums.SettleAccount; |
||||
|
using Win.Sfs.Shared.Filter; |
||||
|
using Win.Utils; |
||||
|
|
||||
|
namespace Win.Sfs.SettleAccount.JFCarConsigns |
||||
|
{ |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 区域相关应用服务
|
||||
|
/// </summary>
|
||||
|
//[AuthorizeSettleAccountPermissions.JFCarConsigns.Default)]
|
||||
|
[AllowAnonymous] |
||||
|
[Route("api/settleaccount/JFCarConsign")] |
||||
|
public class JFCarConsignAppService : SettleAccountApplicationBase<JFCarConsign>, IJFCarConsignAppService |
||||
|
{ |
||||
|
private readonly IGuidGenerator _guidGenerator; |
||||
|
|
||||
|
private readonly IObjectMapper _objectMapper; |
||||
|
|
||||
|
private readonly IExcelImportAppService _excelImportService; |
||||
|
|
||||
|
|
||||
|
private readonly ISettleAccountBranchEfCoreRepository<JFCarConsign, Guid> _repository; |
||||
|
|
||||
|
private readonly ISettleAccountBranchEfCoreRepository<JFCarConsignVersion, Guid> _versionRepository; |
||||
|
private readonly ISettleAccountBranchEfCoreRepository<MaterialRelationship, Guid> _MaterialRepository; |
||||
|
/// <summary>
|
||||
|
/// 构建方法
|
||||
|
/// </summary>
|
||||
|
/// <param name="guidGenerator">构建UID</param>
|
||||
|
/// <param name="objectMapper">自动map</param>
|
||||
|
/// <param name="repository">仓储接口</param>
|
||||
|
/// <param name="cache">缓存</param>
|
||||
|
public JFCarConsignAppService(IGuidGenerator guidGenerator, |
||||
|
IObjectMapper objectMapper, |
||||
|
IExcelImportAppService excelImportService, |
||||
|
ISnowflakeIdGenerator snowflakeIdGenerator, |
||||
|
ICommonManager commonManager, |
||||
|
ISettleAccountBranchEfCoreRepository<JFCarConsign, Guid> repository, |
||||
|
ISettleAccountBranchEfCoreRepository<JFCarConsignVersion, Guid> versionRepository, |
||||
|
ISettleAccountBranchEfCoreRepository<MaterialRelationship, Guid> MaterialRepository, |
||||
|
IDistributedCache<JFCarConsign> cache |
||||
|
) : base(cache,excelImportService,snowflakeIdGenerator,commonManager) |
||||
|
{ |
||||
|
_guidGenerator = guidGenerator; |
||||
|
_objectMapper = objectMapper; |
||||
|
_repository = repository; |
||||
|
_excelImportService = excelImportService; |
||||
|
_versionRepository = versionRepository; |
||||
|
_MaterialRepository = MaterialRepository; |
||||
|
} |
||||
|
|
||||
|
#region 导入导出功能
|
||||
|
/// <summary>
|
||||
|
/// 导入功能
|
||||
|
/// </summary>
|
||||
|
/// <param name="files">上传的文件(前端已经限制只能上传一个附件)</param>
|
||||
|
/// <returns></returns>
|
||||
|
[HttpPost] |
||||
|
[Route("ExcelImport")] |
||||
|
[DisableRequestSizeLimit] |
||||
|
//[AuthorizeSettleAccountPermissions.JFCarConsigns.Default)]
|
||||
|
|
||||
|
public async Task<string> JFCarConsignUploadExcelImport([FromForm] IFormFileCollection files, Guid branchId, string year, string period, string version, string customerCode,DateTime datetime) |
||||
|
{ |
||||
|
ExportImporter _exportImporter = new ExportImporter(); |
||||
|
var result = await _exportImporter.UploadExcelImport<ImportJFCarConsignDto>(files, _excelImportService); |
||||
|
var entityList = ObjectMapper.Map<List<ImportJFCarConsignDto>, List<JFCarConsign>>(result); |
||||
|
var _versionQuery = _versionRepository.Where(p => p.Version == version ); |
||||
|
await _versionQuery.BatchDeleteAsync(); |
||||
|
var _query = _repository.Where(p => p.Version == version); |
||||
|
await _query.BatchDeleteAsync(); |
||||
|
//List<String> errorList = new List<string>();
|
||||
|
var checkList = new List<ErrorExportDto>(); |
||||
|
//通过《零件关系匹配设置表》验证物料号
|
||||
|
foreach (var itm in entityList) |
||||
|
{ |
||||
|
if (!_MaterialRepository.Any(p => p.ShipMaterailCode == itm.MaterialCode)) |
||||
|
{ |
||||
|
checkList.Add(new ErrorExportDto(version,string.Empty, string.Empty, string.Empty,itm.MaterialCode, string.Empty, string.Format("发货看板物料号:{0}在《零件关系匹配设置表》中不存在!", itm.MaterialCode), string.Empty)); |
||||
|
//errorList.Add(string.Format("发货看板物料号:{0}在《零件关系匹配设置表》中不存在!", itm.MaterialCode));
|
||||
|
} |
||||
|
} |
||||
|
if (checkList.Count > 0) |
||||
|
{ |
||||
|
return await ExportErrorReportAsync(checkList); |
||||
|
} |
||||
|
var _id = GuidGenerator.Create(); |
||||
|
var _JFCarConsignList = new List<JFCarConsignVersion>(); |
||||
|
|
||||
|
_JFCarConsignList.Add(new JFCarConsignVersion(_id, branchId, period, version, customerCode, datetime)); |
||||
|
foreach (var itm in entityList) |
||||
|
{ |
||||
|
itm.State = (int)EnumSettleStatus.未结算; |
||||
|
itm.SetValue(GuidGenerator.Create(), branchId, period, version, customerCode, datetime,_id); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
await _repository.GetDbContext().BulkInsertAsync<JFCarConsign>(entityList); |
||||
|
|
||||
|
await _versionRepository.GetDbContext().BulkInsertAsync(_JFCarConsignList); |
||||
|
|
||||
|
//st.Stop();
|
||||
|
return ApplicationConsts.SuccessStr; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
#endregion
|
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 按ID获取唯一实体
|
||||
|
/// </summary>
|
||||
|
/// <remarks>
|
||||
|
/// 返回实体全部属性
|
||||
|
/// </remarks>
|
||||
|
/// <param name="id">ID</param>
|
||||
|
/// <returns>实体DTO</returns>
|
||||
|
[HttpGet] |
||||
|
[Route("{id}")] |
||||
|
////[AuthorizeSettleAccountPermissions.JFCarConsigns.Default)]
|
||||
|
virtual public async Task<JFCarConsignDto> GetAsync(Guid id) |
||||
|
{ |
||||
|
var result = await _repository.GetAsync(id); |
||||
|
var dto = _objectMapper.Map<JFCarConsign, JFCarConsignDto>(result); |
||||
|
return dto; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
private async Task<JFCarConsign> GetFromCacheAsync(Guid id) |
||||
|
{ |
||||
|
var result = |
||||
|
await _repository.GetAsync(id) |
||||
|
; |
||||
|
|
||||
|
return result; |
||||
|
} |
||||
|
|
||||
|
private async Task<long> GetCountAsync(JFCarConsignRequestDto input) |
||||
|
{ |
||||
|
return await _repository.GetCountByFilterAsync(input.BranchId, input.Filters); |
||||
|
} |
||||
|
|
||||
|
private async Task<long> GetCountAsync(JFCarConsignVersionRequestDto input) |
||||
|
{ |
||||
|
return await _versionRepository.GetCountByFilterAsync(input.BranchId, input.Filters); |
||||
|
} |
||||
|
/// <summary>
|
||||
|
/// 获取实体总数
|
||||
|
/// </summary>
|
||||
|
/// <returns>实体总数</returns>
|
||||
|
[HttpGet] |
||||
|
[Route("count")] |
||||
|
////[AuthorizeSettleAccountPermissions.JFCarConsigns.Default)]
|
||||
|
virtual public async Task<long> GetTotalCountAsync(Guid branchId) |
||||
|
{ |
||||
|
return await _repository.GetCountAsync(branchId); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 删除实体
|
||||
|
/// </summary>
|
||||
|
/// <param name="id">ID</param>
|
||||
|
/// <returns>无</returns>
|
||||
|
[HttpDelete] |
||||
|
[Route("{id}")] |
||||
|
////[AuthorizeSettleAccountPermissions.JFCarConsigns.Delete)]
|
||||
|
virtual public async Task DeleteAsync(Guid id) |
||||
|
{ |
||||
|
//var entity = await GetFromCacheAsync(id);
|
||||
|
//await Cache.DeleteAsync<JFCarConsign>(id.ToString());
|
||||
|
await _repository.DeleteAsync(id); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 按IDs删除实体列表
|
||||
|
/// </summary>
|
||||
|
/// <param name="ids">IDs</param>
|
||||
|
/// <returns>是否执行成功</returns>
|
||||
|
[HttpPost] |
||||
|
[Route("delete")] |
||||
|
////[AuthorizeSettleAccountPermissions.JFCarConsigns.Delete)]
|
||||
|
virtual public async Task<bool> DeleteListAsync(List<Guid> ids) |
||||
|
{ |
||||
|
//foreach (var id in ids)
|
||||
|
//{
|
||||
|
// var entity = await GetFromCacheAsync(id);
|
||||
|
|
||||
|
//}
|
||||
|
|
||||
|
return await _repository.DeleteListAsync(ids); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
///// <summary>
|
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 根据筛选条件获取实体列表
|
||||
|
/// </summary>
|
||||
|
/// <remarks>
|
||||
|
/// 请求条件包括:筛选条件列表,排序条件,数据数量,页码
|
||||
|
/// </remarks>
|
||||
|
/// <param name="input">请求条件</param>
|
||||
|
/// <returns>实体DTO列表</returns>
|
||||
|
[HttpPost] |
||||
|
[Route("list")] |
||||
|
////[AuthorizeSettleAccountPermissions.JFCarConsigns.Default)]
|
||||
|
|
||||
|
|
||||
|
public async Task<PagedResultDto<JFCarConsignDto>> GetListAsync(Guid parentId, JFCarConsignRequestDto input) |
||||
|
{ |
||||
|
if (input.ParentId != Guid.Empty) |
||||
|
{ |
||||
|
input.Filters.Add(new FilterCondition() { Action = EnumFilterAction.Equal, Column = "ParentId", Logic = EnumFilterLogic.And, Value = input.ParentId.ToString() }); |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
return new PagedResultDto<JFCarConsignDto>(0, new List<JFCarConsignDto>()); |
||||
|
} |
||||
|
|
||||
|
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<JFCarConsign>, List<JFCarConsignDto>>(entities); |
||||
|
|
||||
|
return new PagedResultDto<JFCarConsignDto>(totalCount, dtos); |
||||
|
} |
||||
|
|
||||
|
///// <summary>
|
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 根据筛选条件获取实体列表
|
||||
|
/// </summary>
|
||||
|
/// <remarks>
|
||||
|
/// 请求条件包括:筛选条件列表,排序条件,数据数量,页码
|
||||
|
/// </remarks>
|
||||
|
/// <param name="input">请求条件</param>
|
||||
|
/// <returns>实体DTO列表</returns>
|
||||
|
[HttpPost] |
||||
|
[Route("listVersion")] |
||||
|
//[AuthorizeSettleAccountPermissions.JFCarConsigns.Default)]
|
||||
|
public async Task<PagedResultDto<JFCarConsignVersionDto>> GetVersionListAsync(JFCarConsignVersionRequestDto input) |
||||
|
{ |
||||
|
var entities = await _versionRepository.GetListByFilterAsync(input.BranchId, input.Filters, input.Sorting, int.MaxValue, |
||||
|
input.SkipCount, true); |
||||
|
|
||||
|
var totalCount = await GetCountAsync(input); |
||||
|
var dtos = _objectMapper.Map<List<JFCarConsignVersion>, List<JFCarConsignVersionDto>>(entities); |
||||
|
|
||||
|
return new PagedResultDto<JFCarConsignVersionDto>(totalCount, dtos); |
||||
|
} |
||||
|
/// <summary>
|
||||
|
/// 导出文件
|
||||
|
/// </summary>
|
||||
|
/// <param name="input"></param>
|
||||
|
/// <returns></returns>
|
||||
|
[HttpPost] |
||||
|
[Route("Export")] |
||||
|
//[AuthorizeSettleAccountPermissions.JFCarConsigns.Default)]
|
||||
|
virtual public async Task<string> ExportAsync(JFCarConsignRequestDto input) |
||||
|
{ |
||||
|
|
||||
|
IExporter _csv = new CsvExporter(); |
||||
|
|
||||
|
IExporter _excel = new ExcelExporter(); |
||||
|
if (input.ParentId != Guid.Empty) |
||||
|
{ |
||||
|
input.Filters.Add(new FilterCondition() { Action = EnumFilterAction.Equal, Column = "ParentId", Logic = EnumFilterLogic.And, Value = input.ParentId.ToString() }); |
||||
|
} |
||||
|
|
||||
|
var entities = await _repository.GetListByFilterAsync(input.BranchId, input.Filters, input.Sorting, int.MaxValue, |
||||
|
0, true); |
||||
|
|
||||
|
var dtoDetails = ObjectMapper.Map<List<JFCarConsign>, List<ExportJFCarConsignDto>>(entities); |
||||
|
|
||||
|
string _fileName = string.Empty; |
||||
|
//声明导出容器
|
||||
|
|
||||
|
byte[] result = null; |
||||
|
|
||||
|
|
||||
|
switch (input.FileType) |
||||
|
{ |
||||
|
case 0: |
||||
|
_fileName = string.Format("解放结算_{0}.csv", System.DateTime.Now.ToString("yyyyMMddHHmmss")); |
||||
|
result = await _csv.ExportAsByteArray(dtoDetails); |
||||
|
|
||||
|
|
||||
|
|
||||
|
break; |
||||
|
case 1: |
||||
|
_fileName = string.Format("解放结算_{0}.xlsx", System.DateTime.Now.ToString("yyyyMMddHHmmss")); |
||||
|
result = await _excel.ExportAsByteArray(dtoDetails); |
||||
|
break; |
||||
|
} |
||||
|
|
||||
|
result.ShouldNotBeNull(); |
||||
|
|
||||
|
//保存导出文件到服务器存成二进制
|
||||
|
await _excelImportService.SaveBlobAsync( |
||||
|
new SaveExcelImportInputDto |
||||
|
{ |
||||
|
Name = _fileName, |
||||
|
Content = result |
||||
|
} |
||||
|
); |
||||
|
return _fileName; |
||||
|
} |
||||
|
|
||||
|
[HttpPost] |
||||
|
[Route("jfupdate")] |
||||
|
|
||||
|
[UnitOfWork(isTransactional: false)] |
||||
|
public async Task<bool> UPdateFisAsync() |
||||
|
{ |
||||
|
|
||||
|
await _repository.GetDbContext().Database.ExecuteSqlRawAsync( |
||||
|
"EXEC sp_jf_update" |
||||
|
); |
||||
|
return true; |
||||
|
|
||||
|
|
||||
|
|
||||
|
} |
||||
|
|
||||
|
|
||||
|
} |
||||
|
} |
@ -0,0 +1,361 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Diagnostics; |
||||
|
using System.Linq; |
||||
|
using System.Threading.Tasks; |
||||
|
using EFCore.BulkExtensions; |
||||
|
using Magicodes.ExporterAndImporter.Core; |
||||
|
using Magicodes.ExporterAndImporter.Csv; |
||||
|
using Magicodes.ExporterAndImporter.Excel; |
||||
|
using Microsoft.AspNetCore.Authorization; |
||||
|
using Microsoft.AspNetCore.Http; |
||||
|
using Microsoft.AspNetCore.Mvc; |
||||
|
using Microsoft.EntityFrameworkCore; |
||||
|
using Microsoft.Extensions.Caching.Distributed; |
||||
|
using Shouldly; |
||||
|
using Volo.Abp; |
||||
|
using Volo.Abp.Application.Dtos; |
||||
|
using Volo.Abp.Application.Services; |
||||
|
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.CommonManagers; |
||||
|
using Win.Sfs.SettleAccount.Constant; |
||||
|
using Win.Sfs.SettleAccount.Entities.JFCarConsigns; |
||||
|
using Win.Sfs.SettleAccount.Entities.Materials; |
||||
|
using Win.Sfs.SettleAccount.ExcelImporter; |
||||
|
using Win.Sfs.SettleAccount.ExportReports; |
||||
|
using Win.Sfs.SettleAccount.MaterialRelationships; |
||||
|
using Win.Sfs.Shared.CacheBase; |
||||
|
using Win.Sfs.Shared.Enums.SettleAccount; |
||||
|
using Win.Sfs.Shared.Filter; |
||||
|
using Win.Utils; |
||||
|
|
||||
|
namespace Win.Sfs.SettleAccount.JFCarConsigns |
||||
|
{ |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 区域相关应用服务
|
||||
|
/// </summary>
|
||||
|
//[AuthorizeSettleAccountPermissions.JFCarConsigns.Default)]
|
||||
|
[AllowAnonymous] |
||||
|
[Route("api/settleaccount/JFCarConsign")] |
||||
|
public class JFCarConsignAppService : SettleAccountApplicationBase<JFCarConsign>, IJFCarConsignAppService |
||||
|
{ |
||||
|
private readonly IGuidGenerator _guidGenerator; |
||||
|
|
||||
|
private readonly IObjectMapper _objectMapper; |
||||
|
|
||||
|
private readonly IExcelImportAppService _excelImportService; |
||||
|
|
||||
|
|
||||
|
private readonly ISettleAccountBranchEfCoreRepository<JFCarConsign, Guid> _repository; |
||||
|
|
||||
|
private readonly ISettleAccountBranchEfCoreRepository<JFCarConsignVersion, Guid> _versionRepository; |
||||
|
private readonly ISettleAccountBranchEfCoreRepository<MaterialRelationship, Guid> _MaterialRepository; |
||||
|
/// <summary>
|
||||
|
/// 构建方法
|
||||
|
/// </summary>
|
||||
|
/// <param name="guidGenerator">构建UID</param>
|
||||
|
/// <param name="objectMapper">自动map</param>
|
||||
|
/// <param name="repository">仓储接口</param>
|
||||
|
/// <param name="cache">缓存</param>
|
||||
|
public JFCarConsignAppService(IGuidGenerator guidGenerator, |
||||
|
IObjectMapper objectMapper, |
||||
|
IExcelImportAppService excelImportService, |
||||
|
ISnowflakeIdGenerator snowflakeIdGenerator, |
||||
|
ICommonManager commonManager, |
||||
|
ISettleAccountBranchEfCoreRepository<JFCarConsign, Guid> repository, |
||||
|
ISettleAccountBranchEfCoreRepository<JFCarConsignVersion, Guid> versionRepository, |
||||
|
ISettleAccountBranchEfCoreRepository<MaterialRelationship, Guid> MaterialRepository, |
||||
|
IDistributedCache<JFCarConsign> cache |
||||
|
) : base(cache,excelImportService,snowflakeIdGenerator,commonManager) |
||||
|
{ |
||||
|
_guidGenerator = guidGenerator; |
||||
|
_objectMapper = objectMapper; |
||||
|
_repository = repository; |
||||
|
_excelImportService = excelImportService; |
||||
|
_versionRepository = versionRepository; |
||||
|
_MaterialRepository = MaterialRepository; |
||||
|
} |
||||
|
|
||||
|
#region 导入导出功能
|
||||
|
/// <summary>
|
||||
|
/// 导入功能
|
||||
|
/// </summary>
|
||||
|
/// <param name="files">上传的文件(前端已经限制只能上传一个附件)</param>
|
||||
|
/// <returns></returns>
|
||||
|
[HttpPost] |
||||
|
[Route("ExcelImport")] |
||||
|
[DisableRequestSizeLimit] |
||||
|
//[AuthorizeSettleAccountPermissions.JFCarConsigns.Default)]
|
||||
|
|
||||
|
public async Task<string> JFCarConsignUploadExcelImport([FromForm] IFormFileCollection files, Guid branchId, string year, string period, string version, string customerCode,DateTime datetime) |
||||
|
{ |
||||
|
ExportImporter _exportImporter = new ExportImporter(); |
||||
|
var result = await _exportImporter.UploadExcelImport<ImportJFCarConsignDto>(files, _excelImportService); |
||||
|
var entityList = ObjectMapper.Map<List<ImportJFCarConsignDto>, List<JFCarConsign>>(result); |
||||
|
var _versionQuery = _versionRepository.Where(p => p.Version == version ); |
||||
|
await _versionQuery.BatchDeleteAsync(); |
||||
|
var _query = _repository.Where(p => p.Version == version); |
||||
|
await _query.BatchDeleteAsync(); |
||||
|
//List<String> errorList = new List<string>();
|
||||
|
var checkList = new List<ErrorExportDto>(); |
||||
|
//通过《零件关系匹配设置表》验证物料号
|
||||
|
foreach (var itm in entityList) |
||||
|
{ |
||||
|
if (!_MaterialRepository.Any(p => p.ShipMaterailCode == itm.MaterialCode)) |
||||
|
{ |
||||
|
checkList.Add(new ErrorExportDto(version,string.Empty, string.Empty, string.Empty,itm.MaterialCode, string.Empty, string.Format("发货看板物料号:{0}在《零件关系匹配设置表》中不存在!", itm.MaterialCode), string.Empty)); |
||||
|
//errorList.Add(string.Format("发货看板物料号:{0}在《零件关系匹配设置表》中不存在!", itm.MaterialCode));
|
||||
|
} |
||||
|
} |
||||
|
if (checkList.Count > 0) |
||||
|
{ |
||||
|
return await ExportErrorReportAsync(checkList); |
||||
|
} |
||||
|
var _id = GuidGenerator.Create(); |
||||
|
var _JFCarConsignList = new List<JFCarConsignVersion>(); |
||||
|
|
||||
|
_JFCarConsignList.Add(new JFCarConsignVersion(_id, branchId, period, version, customerCode, datetime)); |
||||
|
foreach (var itm in entityList) |
||||
|
{ |
||||
|
itm.State = (int)EnumSettleStatus.未结算; |
||||
|
itm.SetValue(GuidGenerator.Create(), branchId, period, version, customerCode, datetime,_id); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
await _repository.GetDbContext().BulkInsertAsync<JFCarConsign>(entityList); |
||||
|
|
||||
|
await _versionRepository.GetDbContext().BulkInsertAsync(_JFCarConsignList); |
||||
|
|
||||
|
//st.Stop();
|
||||
|
return ApplicationConsts.SuccessStr; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
#endregion
|
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 按ID获取唯一实体
|
||||
|
/// </summary>
|
||||
|
/// <remarks>
|
||||
|
/// 返回实体全部属性
|
||||
|
/// </remarks>
|
||||
|
/// <param name="id">ID</param>
|
||||
|
/// <returns>实体DTO</returns>
|
||||
|
[HttpGet] |
||||
|
[Route("{id}")] |
||||
|
////[AuthorizeSettleAccountPermissions.JFCarConsigns.Default)]
|
||||
|
virtual public async Task<JFCarConsignDto> GetAsync(Guid id) |
||||
|
{ |
||||
|
var result = await _repository.GetAsync(id); |
||||
|
var dto = _objectMapper.Map<JFCarConsign, JFCarConsignDto>(result); |
||||
|
return dto; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
private async Task<JFCarConsign> GetFromCacheAsync(Guid id) |
||||
|
{ |
||||
|
var result = |
||||
|
await _repository.GetAsync(id) |
||||
|
; |
||||
|
|
||||
|
return result; |
||||
|
} |
||||
|
|
||||
|
private async Task<long> GetCountAsync(JFCarConsignRequestDto input) |
||||
|
{ |
||||
|
return await _repository.GetCountByFilterAsync(input.BranchId, input.Filters); |
||||
|
} |
||||
|
|
||||
|
private async Task<long> GetCountAsync(JFCarConsignVersionRequestDto input) |
||||
|
{ |
||||
|
return await _versionRepository.GetCountByFilterAsync(input.BranchId, input.Filters); |
||||
|
} |
||||
|
/// <summary>
|
||||
|
/// 获取实体总数
|
||||
|
/// </summary>
|
||||
|
/// <returns>实体总数</returns>
|
||||
|
[HttpGet] |
||||
|
[Route("count")] |
||||
|
////[AuthorizeSettleAccountPermissions.JFCarConsigns.Default)]
|
||||
|
virtual public async Task<long> GetTotalCountAsync(Guid branchId) |
||||
|
{ |
||||
|
return await _repository.GetCountAsync(branchId); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 删除实体
|
||||
|
/// </summary>
|
||||
|
/// <param name="id">ID</param>
|
||||
|
/// <returns>无</returns>
|
||||
|
[HttpDelete] |
||||
|
[Route("{id}")] |
||||
|
////[AuthorizeSettleAccountPermissions.JFCarConsigns.Delete)]
|
||||
|
virtual public async Task DeleteAsync(Guid id) |
||||
|
{ |
||||
|
//var entity = await GetFromCacheAsync(id);
|
||||
|
//await Cache.DeleteAsync<JFCarConsign>(id.ToString());
|
||||
|
await _repository.DeleteAsync(id); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 按IDs删除实体列表
|
||||
|
/// </summary>
|
||||
|
/// <param name="ids">IDs</param>
|
||||
|
/// <returns>是否执行成功</returns>
|
||||
|
[HttpPost] |
||||
|
[Route("delete")] |
||||
|
////[AuthorizeSettleAccountPermissions.JFCarConsigns.Delete)]
|
||||
|
virtual public async Task<bool> DeleteListAsync(List<Guid> ids) |
||||
|
{ |
||||
|
//foreach (var id in ids)
|
||||
|
//{
|
||||
|
// var entity = await GetFromCacheAsync(id);
|
||||
|
|
||||
|
//}
|
||||
|
|
||||
|
return await _repository.DeleteListAsync(ids); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
///// <summary>
|
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 根据筛选条件获取实体列表
|
||||
|
/// </summary>
|
||||
|
/// <remarks>
|
||||
|
/// 请求条件包括:筛选条件列表,排序条件,数据数量,页码
|
||||
|
/// </remarks>
|
||||
|
/// <param name="input">请求条件</param>
|
||||
|
/// <returns>实体DTO列表</returns>
|
||||
|
[HttpPost] |
||||
|
[Route("list")] |
||||
|
////[AuthorizeSettleAccountPermissions.JFCarConsigns.Default)]
|
||||
|
|
||||
|
|
||||
|
public async Task<PagedResultDto<JFCarConsignDto>> GetListAsync(Guid parentId, JFCarConsignRequestDto input) |
||||
|
{ |
||||
|
if (input.ParentId != Guid.Empty) |
||||
|
{ |
||||
|
input.Filters.Add(new FilterCondition() { Action = EnumFilterAction.Equal, Column = "ParentId", Logic = EnumFilterLogic.And, Value = input.ParentId.ToString() }); |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
return new PagedResultDto<JFCarConsignDto>(0, new List<JFCarConsignDto>()); |
||||
|
} |
||||
|
|
||||
|
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<JFCarConsign>, List<JFCarConsignDto>>(entities); |
||||
|
|
||||
|
return new PagedResultDto<JFCarConsignDto>(totalCount, dtos); |
||||
|
} |
||||
|
|
||||
|
///// <summary>
|
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 根据筛选条件获取实体列表
|
||||
|
/// </summary>
|
||||
|
/// <remarks>
|
||||
|
/// 请求条件包括:筛选条件列表,排序条件,数据数量,页码
|
||||
|
/// </remarks>
|
||||
|
/// <param name="input">请求条件</param>
|
||||
|
/// <returns>实体DTO列表</returns>
|
||||
|
[HttpPost] |
||||
|
[Route("listVersion")] |
||||
|
//[AuthorizeSettleAccountPermissions.JFCarConsigns.Default)]
|
||||
|
public async Task<PagedResultDto<JFCarConsignVersionDto>> GetVersionListAsync(JFCarConsignVersionRequestDto input) |
||||
|
{ |
||||
|
var entities = await _versionRepository.GetListByFilterAsync(input.BranchId, input.Filters, input.Sorting, int.MaxValue, |
||||
|
input.SkipCount, true); |
||||
|
|
||||
|
var totalCount = await GetCountAsync(input); |
||||
|
var dtos = _objectMapper.Map<List<JFCarConsignVersion>, List<JFCarConsignVersionDto>>(entities); |
||||
|
|
||||
|
return new PagedResultDto<JFCarConsignVersionDto>(totalCount, dtos); |
||||
|
} |
||||
|
/// <summary>
|
||||
|
/// 导出文件
|
||||
|
/// </summary>
|
||||
|
/// <param name="input"></param>
|
||||
|
/// <returns></returns>
|
||||
|
[HttpPost] |
||||
|
[Route("Export")] |
||||
|
//[AuthorizeSettleAccountPermissions.JFCarConsigns.Default)]
|
||||
|
virtual public async Task<string> ExportAsync(JFCarConsignRequestDto input) |
||||
|
{ |
||||
|
|
||||
|
IExporter _csv = new CsvExporter(); |
||||
|
|
||||
|
IExporter _excel = new ExcelExporter(); |
||||
|
if (input.ParentId != Guid.Empty) |
||||
|
{ |
||||
|
input.Filters.Add(new FilterCondition() { Action = EnumFilterAction.Equal, Column = "ParentId", Logic = EnumFilterLogic.And, Value = input.ParentId.ToString() }); |
||||
|
} |
||||
|
|
||||
|
var entities = await _repository.GetListByFilterAsync(input.BranchId, input.Filters, input.Sorting, int.MaxValue, |
||||
|
0, true); |
||||
|
|
||||
|
var dtoDetails = ObjectMapper.Map<List<JFCarConsign>, List<ExportJFCarConsignDto>>(entities); |
||||
|
|
||||
|
string _fileName = string.Empty; |
||||
|
//声明导出容器
|
||||
|
|
||||
|
byte[] result = null; |
||||
|
|
||||
|
|
||||
|
switch (input.FileType) |
||||
|
{ |
||||
|
case 0: |
||||
|
_fileName = string.Format("解放结算_{0}.csv", System.DateTime.Now.ToString("yyyyMMddHHmmss")); |
||||
|
result = await _csv.ExportAsByteArray(dtoDetails); |
||||
|
|
||||
|
|
||||
|
|
||||
|
break; |
||||
|
case 1: |
||||
|
_fileName = string.Format("解放结算_{0}.xlsx", System.DateTime.Now.ToString("yyyyMMddHHmmss")); |
||||
|
result = await _excel.ExportAsByteArray(dtoDetails); |
||||
|
break; |
||||
|
} |
||||
|
|
||||
|
result.ShouldNotBeNull(); |
||||
|
|
||||
|
//保存导出文件到服务器存成二进制
|
||||
|
await _excelImportService.SaveBlobAsync( |
||||
|
new SaveExcelImportInputDto |
||||
|
{ |
||||
|
Name = _fileName, |
||||
|
Content = result |
||||
|
} |
||||
|
); |
||||
|
return _fileName; |
||||
|
} |
||||
|
|
||||
|
[HttpPost] |
||||
|
[Route("jfupdate")] |
||||
|
|
||||
|
[UnitOfWork(isTransactional: false)] |
||||
|
public async Task<bool> UPdateFisAsync() |
||||
|
{ |
||||
|
|
||||
|
await _repository.GetDbContext().Database.ExecuteSqlRawAsync( |
||||
|
"EXEC sp_jf_update" |
||||
|
); |
||||
|
return true; |
||||
|
|
||||
|
|
||||
|
|
||||
|
} |
||||
|
|
||||
|
|
||||
|
} |
||||
|
} |
@ -0,0 +1,328 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Diagnostics; |
||||
|
using System.Linq; |
||||
|
using System.Threading.Tasks; |
||||
|
using EFCore.BulkExtensions; |
||||
|
using Magicodes.ExporterAndImporter.Core; |
||||
|
using Magicodes.ExporterAndImporter.Csv; |
||||
|
using Magicodes.ExporterAndImporter.Excel; |
||||
|
using Microsoft.AspNetCore.Authorization; |
||||
|
using Microsoft.AspNetCore.Http; |
||||
|
using Microsoft.AspNetCore.Mvc; |
||||
|
using Microsoft.EntityFrameworkCore; |
||||
|
using Microsoft.Extensions.Caching.Distributed; |
||||
|
using Shouldly; |
||||
|
using Volo.Abp; |
||||
|
using Volo.Abp.Application.Dtos; |
||||
|
using Volo.Abp.Application.Services; |
||||
|
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.CommonManagers; |
||||
|
using Win.Sfs.SettleAccount.Constant; |
||||
|
using Win.Sfs.SettleAccount.Entities.JFCarKBs; |
||||
|
using Win.Sfs.SettleAccount.ExcelImporter; |
||||
|
using Win.Sfs.Shared.CacheBase; |
||||
|
using Win.Sfs.Shared.Enums.SettleAccount; |
||||
|
using Win.Sfs.Shared.Filter; |
||||
|
using Win.Utils; |
||||
|
|
||||
|
namespace Win.Sfs.SettleAccount.JFCarKBs |
||||
|
{ |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 区域相关应用服务
|
||||
|
/// </summary>
|
||||
|
//[AuthorizeSettleAccountPermissions.JFCarKBs.Default)]
|
||||
|
|
||||
|
[Route("api/settleaccount/JFCarKB")] |
||||
|
public class JFCarKBAppService : SettleAccountApplicationBase<JFCarKB>, IJFCarKBAppService |
||||
|
{ |
||||
|
private readonly IGuidGenerator _guidGenerator; |
||||
|
|
||||
|
private readonly IObjectMapper _objectMapper; |
||||
|
|
||||
|
private readonly IExcelImportAppService _excelImportService; |
||||
|
|
||||
|
|
||||
|
private readonly ISettleAccountBranchEfCoreRepository<JFCarKB, Guid> _repository; |
||||
|
|
||||
|
private readonly ISettleAccountBranchEfCoreRepository<JFCarKBVersion, Guid> _versionRepository; |
||||
|
/// <summary>
|
||||
|
/// 构建方法
|
||||
|
/// </summary>
|
||||
|
/// <param name="guidGenerator">构建UID</param>
|
||||
|
/// <param name="objectMapper">自动map</param>
|
||||
|
/// <param name="repository">仓储接口</param>
|
||||
|
/// <param name="cache">缓存</param>
|
||||
|
public JFCarKBAppService(IGuidGenerator guidGenerator, |
||||
|
IObjectMapper objectMapper, |
||||
|
IExcelImportAppService excelImportService, |
||||
|
ISnowflakeIdGenerator snowflakeIdGenerator, |
||||
|
ICommonManager commonManager, |
||||
|
ISettleAccountBranchEfCoreRepository<JFCarKB, Guid> repository, |
||||
|
ISettleAccountBranchEfCoreRepository<JFCarKBVersion, Guid> versionRepository, |
||||
|
IDistributedCache<JFCarKB> cache |
||||
|
) : base(cache,excelImportService,snowflakeIdGenerator,commonManager) |
||||
|
{ |
||||
|
_guidGenerator = guidGenerator; |
||||
|
_objectMapper = objectMapper; |
||||
|
_repository = repository; |
||||
|
_excelImportService = excelImportService; |
||||
|
_versionRepository = versionRepository; |
||||
|
} |
||||
|
|
||||
|
#region 导入导出功能
|
||||
|
/// <summary>
|
||||
|
/// 导入功能
|
||||
|
/// </summary>
|
||||
|
/// <param name="files">上传的文件(前端已经限制只能上传一个附件)</param>
|
||||
|
/// <returns></returns>
|
||||
|
[HttpPost] |
||||
|
[Route("ExcelImport")] |
||||
|
[DisableRequestSizeLimit] |
||||
|
|
||||
|
//[AuthorizeSettleAccountPermissions.JFCarKBs.Default)]
|
||||
|
public async Task<string> JFCarKBUploadExcelImport([FromForm] IFormFileCollection files, Guid branchId, string year, string period, string version, string customerCode,DateTime datetime) |
||||
|
{ |
||||
|
ExportImporter _exportImporter = new ExportImporter(); |
||||
|
var result = await _exportImporter.UploadExcelImport<ImportJFCarKBDto>(files, _excelImportService); |
||||
|
var entityList = ObjectMapper.Map<List<ImportJFCarKBDto>, List<JFCarKB>>(result); |
||||
|
var _versionQuery = _versionRepository.Where(p => p.Version == version); |
||||
|
await _versionQuery.BatchDeleteAsync(); |
||||
|
var _query = _repository.Where(p => p.Version == version); |
||||
|
await _query.BatchDeleteAsync(); |
||||
|
|
||||
|
|
||||
|
var _id = GuidGenerator.Create(); |
||||
|
var _JFCarKBList = new List<JFCarKBVersion>(); |
||||
|
|
||||
|
_JFCarKBList.Add(new JFCarKBVersion(_id, branchId, period, version, customerCode, datetime)); |
||||
|
foreach (var itm in entityList) |
||||
|
{ |
||||
|
itm.State= (int)EnumSettleStatus.未结算; |
||||
|
itm.SetValue(GuidGenerator.Create(), branchId, period, version, customerCode, datetime,_id); |
||||
|
} |
||||
|
var bulkConfig = new BulkConfig { SetOutputIdentity = true, BatchSize = 10000 }; |
||||
|
|
||||
|
await _repository.GetDbContext().BulkInsertAsync<JFCarKB>(entityList); |
||||
|
|
||||
|
await _versionRepository.GetDbContext().BulkInsertAsync(_JFCarKBList); |
||||
|
|
||||
|
return ApplicationConsts.SuccessStr; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
#endregion
|
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 按ID获取唯一实体
|
||||
|
/// </summary>
|
||||
|
/// <remarks>
|
||||
|
/// 返回实体全部属性
|
||||
|
/// </remarks>
|
||||
|
/// <param name="id">ID</param>
|
||||
|
/// <returns>实体DTO</returns>
|
||||
|
[HttpGet] |
||||
|
[Route("{id}")] |
||||
|
////[AuthorizeSettleAccountPermissions.JFCarKBs.Default)]
|
||||
|
virtual public async Task<JFCarKBDto> GetAsync(Guid id) |
||||
|
{ |
||||
|
var result = await _repository.GetAsync(id); |
||||
|
var dto = _objectMapper.Map<JFCarKB, JFCarKBDto>(result); |
||||
|
return dto; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
private async Task<JFCarKB> GetFromCacheAsync(Guid id) |
||||
|
{ |
||||
|
var result = |
||||
|
await _repository.GetAsync(id) |
||||
|
; |
||||
|
|
||||
|
return result; |
||||
|
} |
||||
|
|
||||
|
private async Task<long> GetCountAsync(JFCarKBRequestDto input) |
||||
|
{ |
||||
|
return await _repository.GetCountByFilterAsync(input.BranchId, input.Filters); |
||||
|
} |
||||
|
|
||||
|
private async Task<long> GetCountAsync(JFCarKBVersionRequestDto input) |
||||
|
{ |
||||
|
return await _versionRepository.GetCountByFilterAsync(input.BranchId, input.Filters); |
||||
|
} |
||||
|
/// <summary>
|
||||
|
/// 获取实体总数
|
||||
|
/// </summary>
|
||||
|
/// <returns>实体总数</returns>
|
||||
|
[HttpGet] |
||||
|
[Route("count")] |
||||
|
////[AuthorizeSettleAccountPermissions.JFCarKBs.Default)]
|
||||
|
virtual public async Task<long> GetTotalCountAsync(Guid branchId) |
||||
|
{ |
||||
|
return await _repository.GetCountAsync(branchId); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 删除实体
|
||||
|
/// </summary>
|
||||
|
/// <param name="id">ID</param>
|
||||
|
/// <returns>无</returns>
|
||||
|
[HttpDelete] |
||||
|
[Route("{id}")] |
||||
|
////[AuthorizeSettleAccountPermissions.JFCarKBs.Delete)]
|
||||
|
virtual public async Task DeleteAsync(Guid id) |
||||
|
{ |
||||
|
//var entity = await GetFromCacheAsync(id);
|
||||
|
//await Cache.DeleteAsync<JFCarKB>(id.ToString());
|
||||
|
await _repository.DeleteAsync(id); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 按IDs删除实体列表
|
||||
|
/// </summary>
|
||||
|
/// <param name="ids">IDs</param>
|
||||
|
/// <returns>是否执行成功</returns>
|
||||
|
[HttpPost] |
||||
|
[Route("delete")] |
||||
|
////[AuthorizeSettleAccountPermissions.JFCarKBs.Delete)]
|
||||
|
virtual public async Task<bool> DeleteListAsync(List<Guid> ids) |
||||
|
{ |
||||
|
//foreach (var id in ids)
|
||||
|
//{
|
||||
|
// var entity = await GetFromCacheAsync(id);
|
||||
|
|
||||
|
//}
|
||||
|
|
||||
|
return await _repository.DeleteListAsync(ids); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
///// <summary>
|
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 根据筛选条件获取实体列表
|
||||
|
/// </summary>
|
||||
|
/// <remarks>
|
||||
|
/// 请求条件包括:筛选条件列表,排序条件,数据数量,页码
|
||||
|
/// </remarks>
|
||||
|
/// <param name="input">请求条件</param>
|
||||
|
/// <returns>实体DTO列表</returns>
|
||||
|
[HttpPost] |
||||
|
[Route("list")] |
||||
|
////[AuthorizeSettleAccountPermissions.JFCarKBs.Default)]
|
||||
|
|
||||
|
|
||||
|
public async Task<PagedResultDto<JFCarKBDto>> GetListAsync(Guid parentId, JFCarKBRequestDto input) |
||||
|
{ |
||||
|
if (input.ParentId != Guid.Empty) |
||||
|
{ |
||||
|
input.Filters.Add(new FilterCondition() { Action = EnumFilterAction.Equal, Column = "ParentId", Logic = EnumFilterLogic.And, Value = input.ParentId.ToString() }); |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
return new PagedResultDto<JFCarKBDto>(0, new List<JFCarKBDto>()); |
||||
|
} |
||||
|
|
||||
|
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<JFCarKB>, List<JFCarKBDto>>(entities); |
||||
|
|
||||
|
return new PagedResultDto<JFCarKBDto>(totalCount, dtos); |
||||
|
} |
||||
|
|
||||
|
///// <summary>
|
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 根据筛选条件获取实体列表
|
||||
|
/// </summary>
|
||||
|
/// <remarks>
|
||||
|
/// 请求条件包括:筛选条件列表,排序条件,数据数量,页码
|
||||
|
/// </remarks>
|
||||
|
/// <param name="input">请求条件</param>
|
||||
|
/// <returns>实体DTO列表</returns>
|
||||
|
[HttpPost] |
||||
|
[Route("listVersion")] |
||||
|
//[AuthorizeSettleAccountPermissions.JFCarKBs.Default)]
|
||||
|
public async Task<PagedResultDto<JFCarKBVersionDto>> GetVersionListAsync(JFCarKBVersionRequestDto input) |
||||
|
{ |
||||
|
var entities = await _versionRepository.GetListByFilterAsync(input.BranchId, input.Filters, input.Sorting, int.MaxValue, |
||||
|
input.SkipCount, true); |
||||
|
|
||||
|
var totalCount = await GetCountAsync(input); |
||||
|
var dtos = _objectMapper.Map<List<JFCarKBVersion>, List<JFCarKBVersionDto>>(entities); |
||||
|
|
||||
|
return new PagedResultDto<JFCarKBVersionDto>(totalCount, dtos); |
||||
|
} |
||||
|
/// <summary>
|
||||
|
/// 导出文件
|
||||
|
/// </summary>
|
||||
|
/// <param name="input"></param>
|
||||
|
/// <returns></returns>
|
||||
|
[HttpPost] |
||||
|
[Route("Export")] |
||||
|
//[AuthorizeSettleAccountPermissions.JFCarKBs.Default)]
|
||||
|
virtual public async Task<string> ExportAsync(JFCarKBRequestDto input) |
||||
|
{ |
||||
|
|
||||
|
IExporter _csv = new CsvExporter(); |
||||
|
|
||||
|
IExporter _excel = new ExcelExporter(); |
||||
|
|
||||
|
if (input.ParentId != Guid.Empty) |
||||
|
{ |
||||
|
input.Filters.Add(new FilterCondition() { Action = EnumFilterAction.Equal, Column = "ParentId", Logic = EnumFilterLogic.And, Value = input.ParentId.ToString() }); |
||||
|
} |
||||
|
|
||||
|
var entities = await _repository.GetListByFilterAsync(input.BranchId, input.Filters, input.Sorting, int.MaxValue, |
||||
|
0, true); |
||||
|
|
||||
|
var dtoDetails = ObjectMapper.Map<List<JFCarKB>, List<ExportJFCarKBDto>>(entities); |
||||
|
|
||||
|
string _fileName = string.Empty; |
||||
|
//声明导出容器
|
||||
|
|
||||
|
byte[] result = null; |
||||
|
|
||||
|
//_fileName = CommonMethod.GetExcelFileNameByUserID(ApplicationConsts.Sec_JFCarKBFileName, CurrentUser.Id?.ToString(), ApplicationConsts.FileExtension);
|
||||
|
//result = await _excel.ExportAsByteArray(dtoDetails);
|
||||
|
switch (input.FileType) |
||||
|
{ |
||||
|
case 0: |
||||
|
|
||||
|
|
||||
|
_fileName = string.Format("解放看板_{0}.csv", System.DateTime.Now.ToString("yyyyMMddHHmmss")); |
||||
|
result = await _csv.ExportAsByteArray(dtoDetails); |
||||
|
|
||||
|
break; |
||||
|
case 1: |
||||
|
_fileName = string.Format("解放看板_{0}.xlsx", System.DateTime.Now.ToString("yyyyMMddHHmmss")); |
||||
|
result = await _excel.ExportAsByteArray(dtoDetails); |
||||
|
|
||||
|
break; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
|
||||
|
result.ShouldNotBeNull(); |
||||
|
|
||||
|
//保存导出文件到服务器存成二进制
|
||||
|
await _excelImportService.SaveBlobAsync( |
||||
|
new SaveExcelImportInputDto |
||||
|
{ |
||||
|
Name = _fileName, |
||||
|
Content = result |
||||
|
} |
||||
|
); |
||||
|
return _fileName; |
||||
|
} |
||||
|
} |
||||
|
} |
@ -0,0 +1,328 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Diagnostics; |
||||
|
using System.Linq; |
||||
|
using System.Threading.Tasks; |
||||
|
using EFCore.BulkExtensions; |
||||
|
using Magicodes.ExporterAndImporter.Core; |
||||
|
using Magicodes.ExporterAndImporter.Csv; |
||||
|
using Magicodes.ExporterAndImporter.Excel; |
||||
|
using Microsoft.AspNetCore.Authorization; |
||||
|
using Microsoft.AspNetCore.Http; |
||||
|
using Microsoft.AspNetCore.Mvc; |
||||
|
using Microsoft.EntityFrameworkCore; |
||||
|
using Microsoft.Extensions.Caching.Distributed; |
||||
|
using Shouldly; |
||||
|
using Volo.Abp; |
||||
|
using Volo.Abp.Application.Dtos; |
||||
|
using Volo.Abp.Application.Services; |
||||
|
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.CommonManagers; |
||||
|
using Win.Sfs.SettleAccount.Constant; |
||||
|
using Win.Sfs.SettleAccount.Entities.JFCarKBs; |
||||
|
using Win.Sfs.SettleAccount.ExcelImporter; |
||||
|
using Win.Sfs.Shared.CacheBase; |
||||
|
using Win.Sfs.Shared.Enums.SettleAccount; |
||||
|
using Win.Sfs.Shared.Filter; |
||||
|
using Win.Utils; |
||||
|
|
||||
|
namespace Win.Sfs.SettleAccount.JFCarKBs |
||||
|
{ |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 区域相关应用服务
|
||||
|
/// </summary>
|
||||
|
//[AuthorizeSettleAccountPermissions.JFCarKBs.Default)]
|
||||
|
|
||||
|
[Route("api/settleaccount/JFCarKB")] |
||||
|
public class JFCarKBAppService : SettleAccountApplicationBase<JFCarKB>, IJFCarKBAppService |
||||
|
{ |
||||
|
private readonly IGuidGenerator _guidGenerator; |
||||
|
|
||||
|
private readonly IObjectMapper _objectMapper; |
||||
|
|
||||
|
private readonly IExcelImportAppService _excelImportService; |
||||
|
|
||||
|
|
||||
|
private readonly ISettleAccountBranchEfCoreRepository<JFCarKB, Guid> _repository; |
||||
|
|
||||
|
private readonly ISettleAccountBranchEfCoreRepository<JFCarKBVersion, Guid> _versionRepository; |
||||
|
/// <summary>
|
||||
|
/// 构建方法
|
||||
|
/// </summary>
|
||||
|
/// <param name="guidGenerator">构建UID</param>
|
||||
|
/// <param name="objectMapper">自动map</param>
|
||||
|
/// <param name="repository">仓储接口</param>
|
||||
|
/// <param name="cache">缓存</param>
|
||||
|
public JFCarKBAppService(IGuidGenerator guidGenerator, |
||||
|
IObjectMapper objectMapper, |
||||
|
IExcelImportAppService excelImportService, |
||||
|
ISnowflakeIdGenerator snowflakeIdGenerator, |
||||
|
ICommonManager commonManager, |
||||
|
ISettleAccountBranchEfCoreRepository<JFCarKB, Guid> repository, |
||||
|
ISettleAccountBranchEfCoreRepository<JFCarKBVersion, Guid> versionRepository, |
||||
|
IDistributedCache<JFCarKB> cache |
||||
|
) : base(cache,excelImportService,snowflakeIdGenerator,commonManager) |
||||
|
{ |
||||
|
_guidGenerator = guidGenerator; |
||||
|
_objectMapper = objectMapper; |
||||
|
_repository = repository; |
||||
|
_excelImportService = excelImportService; |
||||
|
_versionRepository = versionRepository; |
||||
|
} |
||||
|
|
||||
|
#region 导入导出功能
|
||||
|
/// <summary>
|
||||
|
/// 导入功能
|
||||
|
/// </summary>
|
||||
|
/// <param name="files">上传的文件(前端已经限制只能上传一个附件)</param>
|
||||
|
/// <returns></returns>
|
||||
|
[HttpPost] |
||||
|
[Route("ExcelImport")] |
||||
|
[DisableRequestSizeLimit] |
||||
|
|
||||
|
//[AuthorizeSettleAccountPermissions.JFCarKBs.Default)]
|
||||
|
public async Task<string> JFCarKBUploadExcelImport([FromForm] IFormFileCollection files, Guid branchId, string year, string period, string version, string customerCode,DateTime datetime) |
||||
|
{ |
||||
|
ExportImporter _exportImporter = new ExportImporter(); |
||||
|
var result = await _exportImporter.UploadExcelImport<ImportJFCarKBDto>(files, _excelImportService); |
||||
|
var entityList = ObjectMapper.Map<List<ImportJFCarKBDto>, List<JFCarKB>>(result); |
||||
|
var _versionQuery = _versionRepository.Where(p => p.Version == version); |
||||
|
await _versionQuery.BatchDeleteAsync(); |
||||
|
var _query = _repository.Where(p => p.Version == version); |
||||
|
await _query.BatchDeleteAsync(); |
||||
|
|
||||
|
|
||||
|
var _id = GuidGenerator.Create(); |
||||
|
var _JFCarKBList = new List<JFCarKBVersion>(); |
||||
|
|
||||
|
_JFCarKBList.Add(new JFCarKBVersion(_id, branchId, period, version, customerCode, datetime)); |
||||
|
foreach (var itm in entityList) |
||||
|
{ |
||||
|
itm.State= (int)EnumSettleStatus.未结算; |
||||
|
itm.SetValue(GuidGenerator.Create(), branchId, period, version, customerCode, datetime,_id); |
||||
|
} |
||||
|
var bulkConfig = new BulkConfig { SetOutputIdentity = true, BatchSize = 10000 }; |
||||
|
|
||||
|
await _repository.GetDbContext().BulkInsertAsync<JFCarKB>(entityList); |
||||
|
|
||||
|
await _versionRepository.GetDbContext().BulkInsertAsync(_JFCarKBList); |
||||
|
|
||||
|
return ApplicationConsts.SuccessStr; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
#endregion
|
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 按ID获取唯一实体
|
||||
|
/// </summary>
|
||||
|
/// <remarks>
|
||||
|
/// 返回实体全部属性
|
||||
|
/// </remarks>
|
||||
|
/// <param name="id">ID</param>
|
||||
|
/// <returns>实体DTO</returns>
|
||||
|
[HttpGet] |
||||
|
[Route("{id}")] |
||||
|
////[AuthorizeSettleAccountPermissions.JFCarKBs.Default)]
|
||||
|
virtual public async Task<JFCarKBDto> GetAsync(Guid id) |
||||
|
{ |
||||
|
var result = await _repository.GetAsync(id); |
||||
|
var dto = _objectMapper.Map<JFCarKB, JFCarKBDto>(result); |
||||
|
return dto; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
private async Task<JFCarKB> GetFromCacheAsync(Guid id) |
||||
|
{ |
||||
|
var result = |
||||
|
await _repository.GetAsync(id) |
||||
|
; |
||||
|
|
||||
|
return result; |
||||
|
} |
||||
|
|
||||
|
private async Task<long> GetCountAsync(JFCarKBRequestDto input) |
||||
|
{ |
||||
|
return await _repository.GetCountByFilterAsync(input.BranchId, input.Filters); |
||||
|
} |
||||
|
|
||||
|
private async Task<long> GetCountAsync(JFCarKBVersionRequestDto input) |
||||
|
{ |
||||
|
return await _versionRepository.GetCountByFilterAsync(input.BranchId, input.Filters); |
||||
|
} |
||||
|
/// <summary>
|
||||
|
/// 获取实体总数
|
||||
|
/// </summary>
|
||||
|
/// <returns>实体总数</returns>
|
||||
|
[HttpGet] |
||||
|
[Route("count")] |
||||
|
////[AuthorizeSettleAccountPermissions.JFCarKBs.Default)]
|
||||
|
virtual public async Task<long> GetTotalCountAsync(Guid branchId) |
||||
|
{ |
||||
|
return await _repository.GetCountAsync(branchId); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 删除实体
|
||||
|
/// </summary>
|
||||
|
/// <param name="id">ID</param>
|
||||
|
/// <returns>无</returns>
|
||||
|
[HttpDelete] |
||||
|
[Route("{id}")] |
||||
|
////[AuthorizeSettleAccountPermissions.JFCarKBs.Delete)]
|
||||
|
virtual public async Task DeleteAsync(Guid id) |
||||
|
{ |
||||
|
//var entity = await GetFromCacheAsync(id);
|
||||
|
//await Cache.DeleteAsync<JFCarKB>(id.ToString());
|
||||
|
await _repository.DeleteAsync(id); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 按IDs删除实体列表
|
||||
|
/// </summary>
|
||||
|
/// <param name="ids">IDs</param>
|
||||
|
/// <returns>是否执行成功</returns>
|
||||
|
[HttpPost] |
||||
|
[Route("delete")] |
||||
|
////[AuthorizeSettleAccountPermissions.JFCarKBs.Delete)]
|
||||
|
virtual public async Task<bool> DeleteListAsync(List<Guid> ids) |
||||
|
{ |
||||
|
//foreach (var id in ids)
|
||||
|
//{
|
||||
|
// var entity = await GetFromCacheAsync(id);
|
||||
|
|
||||
|
//}
|
||||
|
|
||||
|
return await _repository.DeleteListAsync(ids); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
///// <summary>
|
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 根据筛选条件获取实体列表
|
||||
|
/// </summary>
|
||||
|
/// <remarks>
|
||||
|
/// 请求条件包括:筛选条件列表,排序条件,数据数量,页码
|
||||
|
/// </remarks>
|
||||
|
/// <param name="input">请求条件</param>
|
||||
|
/// <returns>实体DTO列表</returns>
|
||||
|
[HttpPost] |
||||
|
[Route("list")] |
||||
|
////[AuthorizeSettleAccountPermissions.JFCarKBs.Default)]
|
||||
|
|
||||
|
|
||||
|
public async Task<PagedResultDto<JFCarKBDto>> GetListAsync(Guid parentId, JFCarKBRequestDto input) |
||||
|
{ |
||||
|
if (input.ParentId != Guid.Empty) |
||||
|
{ |
||||
|
input.Filters.Add(new FilterCondition() { Action = EnumFilterAction.Equal, Column = "ParentId", Logic = EnumFilterLogic.And, Value = input.ParentId.ToString() }); |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
return new PagedResultDto<JFCarKBDto>(0, new List<JFCarKBDto>()); |
||||
|
} |
||||
|
|
||||
|
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<JFCarKB>, List<JFCarKBDto>>(entities); |
||||
|
|
||||
|
return new PagedResultDto<JFCarKBDto>(totalCount, dtos); |
||||
|
} |
||||
|
|
||||
|
///// <summary>
|
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 根据筛选条件获取实体列表
|
||||
|
/// </summary>
|
||||
|
/// <remarks>
|
||||
|
/// 请求条件包括:筛选条件列表,排序条件,数据数量,页码
|
||||
|
/// </remarks>
|
||||
|
/// <param name="input">请求条件</param>
|
||||
|
/// <returns>实体DTO列表</returns>
|
||||
|
[HttpPost] |
||||
|
[Route("listVersion")] |
||||
|
//[AuthorizeSettleAccountPermissions.JFCarKBs.Default)]
|
||||
|
public async Task<PagedResultDto<JFCarKBVersionDto>> GetVersionListAsync(JFCarKBVersionRequestDto input) |
||||
|
{ |
||||
|
var entities = await _versionRepository.GetListByFilterAsync(input.BranchId, input.Filters, input.Sorting, int.MaxValue, |
||||
|
input.SkipCount, true); |
||||
|
|
||||
|
var totalCount = await GetCountAsync(input); |
||||
|
var dtos = _objectMapper.Map<List<JFCarKBVersion>, List<JFCarKBVersionDto>>(entities); |
||||
|
|
||||
|
return new PagedResultDto<JFCarKBVersionDto>(totalCount, dtos); |
||||
|
} |
||||
|
/// <summary>
|
||||
|
/// 导出文件
|
||||
|
/// </summary>
|
||||
|
/// <param name="input"></param>
|
||||
|
/// <returns></returns>
|
||||
|
[HttpPost] |
||||
|
[Route("Export")] |
||||
|
//[AuthorizeSettleAccountPermissions.JFCarKBs.Default)]
|
||||
|
virtual public async Task<string> ExportAsync(JFCarKBRequestDto input) |
||||
|
{ |
||||
|
|
||||
|
IExporter _csv = new CsvExporter(); |
||||
|
|
||||
|
IExporter _excel = new ExcelExporter(); |
||||
|
|
||||
|
if (input.ParentId != Guid.Empty) |
||||
|
{ |
||||
|
input.Filters.Add(new FilterCondition() { Action = EnumFilterAction.Equal, Column = "ParentId", Logic = EnumFilterLogic.And, Value = input.ParentId.ToString() }); |
||||
|
} |
||||
|
|
||||
|
var entities = await _repository.GetListByFilterAsync(input.BranchId, input.Filters, input.Sorting, int.MaxValue, |
||||
|
0, true); |
||||
|
|
||||
|
var dtoDetails = ObjectMapper.Map<List<JFCarKB>, List<ExportJFCarKBDto>>(entities); |
||||
|
|
||||
|
string _fileName = string.Empty; |
||||
|
//声明导出容器
|
||||
|
|
||||
|
byte[] result = null; |
||||
|
|
||||
|
//_fileName = CommonMethod.GetExcelFileNameByUserID(ApplicationConsts.Sec_JFCarKBFileName, CurrentUser.Id?.ToString(), ApplicationConsts.FileExtension);
|
||||
|
//result = await _excel.ExportAsByteArray(dtoDetails);
|
||||
|
switch (input.FileType) |
||||
|
{ |
||||
|
case 0: |
||||
|
|
||||
|
|
||||
|
_fileName = string.Format("解放看板_{0}.csv", System.DateTime.Now.ToString("yyyyMMddHHmmss")); |
||||
|
result = await _csv.ExportAsByteArray(dtoDetails); |
||||
|
|
||||
|
break; |
||||
|
case 1: |
||||
|
_fileName = string.Format("解放看板_{0}.xlsx", System.DateTime.Now.ToString("yyyyMMddHHmmss")); |
||||
|
result = await _excel.ExportAsByteArray(dtoDetails); |
||||
|
|
||||
|
break; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
|
||||
|
result.ShouldNotBeNull(); |
||||
|
|
||||
|
//保存导出文件到服务器存成二进制
|
||||
|
await _excelImportService.SaveBlobAsync( |
||||
|
new SaveExcelImportInputDto |
||||
|
{ |
||||
|
Name = _fileName, |
||||
|
Content = result |
||||
|
} |
||||
|
); |
||||
|
return _fileName; |
||||
|
} |
||||
|
} |
||||
|
} |
Loading…
Reference in new issue