44673626 3 years ago
parent
commit
6dc910521a
  1. 187
      src/Modules/SettleAccount/src/SettleAccount.Application.Contracts/Entities/ERPShpping/ERPShppingDto.cs
  2. 273
      src/Modules/SettleAccount/src/SettleAccount.Application.Contracts/Entities/HQExtend/HQKBExtendDto.cs
  3. 4
      src/Modules/SettleAccount/src/SettleAccount.Application.Contracts/SettleAccount.Application.Contracts.csproj
  4. 334
      src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BTCarConsigns_HS/BTCarConsignAppService.cs
  5. 369
      src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BTCarKBFirsts_HS/BTCarKBFirstAppService.cs
  6. 398
      src/Modules/SettleAccount/src/SettleAccount.Application/Entities/ErpShipping/ErpShippingAppService.cs
  7. 347
      src/Modules/SettleAccount/src/SettleAccount.Application/Entities/HQExtend/HQKBExtendAppService.cs
  8. 346
      src/Modules/SettleAccount/src/SettleAccount.Application/Entities/HQExtend/HQKBSettleExtendAppService.cs
  9. 4
      src/Modules/SettleAccount/src/SettleAccount.Application/SettleAccount.Application.csproj
  10. 60
      src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/ERPShipping/ERPShippingDetail.cs
  11. 49
      src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/ERPShipping/ERPShippingVersion.cs
  12. 52
      src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/HQExtend/HQKBExtend.cs
  13. 55
      src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/HQExtend/HQKBExtendVersion.cs
  14. 52
      src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/HQExtend/HQKBSettleExtend.cs
  15. 55
      src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/HQExtend/HQKBSettleExtendVersion.cs

187
src/Modules/SettleAccount/src/SettleAccount.Application.Contracts/Entities/ERPShpping/ERPShppingDto.cs

@ -0,0 +1,187 @@
using Magicodes.ExporterAndImporter.Core;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Win.Sfs.Shared;
using Win.Sfs.Shared.DtoBase;
namespace Win.Sfs.SettleAccount.Entities.ERPShpping
{
public class ERPShippingDetailDto
{
[ImporterHeader(Name = "保管")]
public string Person { set; get; }
[ImporterHeader(Name = "成本")]
public decimal Cost { set; get; }
[ImporterHeader(Name = "单据编号")]
public string BillNum { set; get; }
[ImporterHeader(Name = "单位")]
public string Unit { set; get; }
[ImporterHeader(Name = "调拨数量")]
public decimal Qty { set; get; }
[ImporterHeader(Name = "调出仓库")]
public string Output { set; get; }
[ImporterHeader(Name = "调出仓库代码")]
public string OutputCode { set; get; }
[ImporterHeader(Name = "调入仓库")]
public string Input { set; get; }
[ImporterHeader(Name = "调入仓库代码")]
public string InputCode { set; get; }
[ImporterHeader(Name = "辅助出库关联数量")]
public decimal OutputAssQty { set; get; }
[ImporterHeader(Name = "规格型号")]
public string Model { set; get; }
[ImporterHeader(Name = "基本出库关联数量")]
public decimal OutputQty { set; get; }
[ImporterHeader(Name = "批号")]
public string BatchNum { set; get; }
[ImporterHeader(Name = "日期")]
public DateTime BillDate { set; get; }
[ImporterHeader(Name = "审核标志")]
public string Flag { get; set; }
[ImporterHeader(Name = "物料长代码")]
public string ErpMaterialCode { set; get; }
[ImporterHeader(Name = "期间")]
public string Version { get; set; }
}
public class ERPShippingDetailRequestDto: RequestDtoBase, IBranch<Guid>
{
[ImporterHeader(Name = "保管")]
public string Person { set; get; }
[ImporterHeader(Name = "成本")]
public decimal Cost { set; get; }
[ImporterHeader(Name = "单据编号")]
public string BillNum { set; get; }
[ImporterHeader(Name = "单位")]
public string Unit { set; get; }
[ImporterHeader(Name = "调拨数量")]
public decimal Qty { set; get; }
[ImporterHeader(Name = "调出仓库")]
public string Output { set; get; }
[ImporterHeader(Name = "调出仓库代码")]
public string OutputCode { set; get; }
[ImporterHeader(Name = "调入仓库")]
public string Input { set; get; }
[ImporterHeader(Name = "调入仓库代码")]
public string InputCode { set; get; }
[ImporterHeader(Name = "辅助出库关联数量")]
public decimal OutputAssQty { set; get; }
[ImporterHeader(Name = "规格型号")]
public string Model { set; get; }
[ImporterHeader(Name = "基本出库关联数量")]
public decimal OutputQty { set; get; }
[ImporterHeader(Name = "批号")]
public string BatchNum { set; get; }
[ImporterHeader(Name = "日期")]
public DateTime BillDate { set; get; }
[ImporterHeader(Name = "审核标志")]
public string Flag { get; set; }
[ImporterHeader(Name = "物料长代码")]
public string ErpMaterialCode { set; get; }
[ImporterHeader(Name = "期间")]
public string Version { get; set; }
public Guid BranchId { get; set; }
}
public class ERPShippingDetailExportDto
{
[Display(Name = "保管")]
public string Person { set; get; }
[Display(Name = "成本")]
public decimal Cost { set; get; }
[Display(Name = "单据编号")]
public string BillNum { set; get; }
[Display(Name = "单位")]
public string Unit { set; get; }
[Display(Name = "调拨数量")]
public decimal Qty { set; get; }
[Display(Name = "调出仓库")]
public string Output { set; get; }
[Display(Name = "调出仓库代码")]
public string OutputCode { set; get; }
[Display(Name = "调入仓库")]
public string Input { set; get; }
[Display(Name = "调入仓库代码")]
public string InputCode { set; get; }
[Display(Name = "辅助出库关联数量")]
public decimal OutputAssQty { set; get; }
[Display(Name = "规格型号")]
public string Model { set; get; }
[Display(Name = "基本出库关联数量")]
public decimal OutputQty { set; get; }
[Display(Name = "批号")]
public string BatchNum { set; get; }
[Display(Name = "日期")]
public DateTime BillDate { set; get; }
[Display(Name = "审核标志")]
public string Flag { get; set; }
[Display(Name = "物料长代码")]
public string ErpMaterialCode { set; get; }
[Display(Name = "期间")]
public string Version { get; set; }
}
public class ERPShippingVersionRequestDto : RequestDtoBase, IBranch<Guid>
{
public string Year { get; private set; }
/// <summary>
/// 期间
/// </summary>
public string Period { get; private set; }
/// <summary>
/// 版本号
/// </summary>
public string Version { get; private set; }
/// <summary>
/// 客户号
/// </summary>
public string CustomerCode { private set; get; }
public Guid BranchId { get; set; }
}
public class ERPShippingVersionDto
{
public string Year { get; set; }
/// <summary>
/// 期间
/// </summary>
public string Period { get; set; }
/// <summary>
/// 版本号
/// </summary>
public string Version { get; set; }
/// <summary>
/// 客户号
/// </summary>
public string CustomerCode { set; get; }
public string Factory { set; get; }
}
}

273
src/Modules/SettleAccount/src/SettleAccount.Application.Contracts/Entities/HQExtend/HQKBExtendDto.cs

@ -0,0 +1,273 @@
using Magicodes.ExporterAndImporter.Core;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Win.Sfs.Shared;
using Win.Sfs.Shared.DtoBase;
namespace Win.Sfs.SettleAccount.Entities.HQExtend
{
public class HQKBExtendDto
{
[ImporterHeader(Name = "试制任务单编号")]
public string TaskBillNum { get; set; }
[ImporterHeader(Name = "采购申请单号")]
public string BillNum { get; set; }
[ImporterHeader(Name = "零件名称")]
public string MaterialDesc { get; set; }
[ImporterHeader(Name = "零件号")]
public string MaterialCode { get; set; }
[ImporterHeader(Name = "数量")]
public decimal Qty { get; set; }
[ImporterHeader(Name = "无税单价")]
public decimal Price { get; set; }
[ImporterHeader(Name = "无税金额")]
public decimal Amt { get; set; }
[ImporterHeader(Name = "税率")]
public decimal Tax { get; set; }
[ImporterHeader(Name = "税额合计")]
public decimal TaxAmt { get; set; }
[ImporterHeader(Name = "价税合计")]
public decimal TotalAmt { get; set; }
[ImporterHeader(Name = "版本号", IsIgnore = false)]
public string Version { get; set; }
}
public class HQKBExtendRequestDto : RequestDtoBase, IBranch<Guid>
{
[ImporterHeader(Name = "试制任务单编号")]
public string TaskBillNum { get; set; }
[ImporterHeader(Name = "采购申请单号")]
public string BillNum { get; set; }
[ImporterHeader(Name = "零件名称")]
public string MaterialDesc { get; set; }
[ImporterHeader(Name = "零件号")]
public string MaterialCode { get; set; }
[ImporterHeader(Name = "数量")]
public decimal Qty { get; set; }
[ImporterHeader(Name = "无税单价")]
public decimal Price { get; set; }
[ImporterHeader(Name = "无税金额")]
public decimal Amt { get; set; }
[ImporterHeader(Name = "税率")]
public decimal Tax { get; set; }
[ImporterHeader(Name = "税额合计")]
public decimal TaxAmt { get; set; }
[ImporterHeader(Name = "价税合计")]
public decimal TotalAmt { get; set; }
[ImporterHeader(Name = "版本号", IsIgnore = false)]
public string Version { get; set; }
public Guid BranchId { get; set; }
}
public class HQKBExtendExportDto
{
[ExporterHeader(DisplayName = "试制任务单编号")]
public string TaskBillNum { get; set; }
[ExporterHeader(DisplayName = "采购申请单号")]
public string BillNum { get; set; }
[ExporterHeader(DisplayName = "零件名称")]
public string MaterialDesc { get; set; }
[ExporterHeader(DisplayName = "零件号")]
public string MaterialCode { get; set; }
[ExporterHeader(DisplayName = "数量")]
public decimal Qty { get; set; }
[ExporterHeader(DisplayName = "无税单价")]
public decimal Price { get; set; }
[ExporterHeader(DisplayName = "无税金额")]
public decimal Amt { get; set; }
[ExporterHeader(DisplayName = "税率")]
public decimal Tax { get; set; }
[ExporterHeader(DisplayName = "税额合计")]
public decimal TaxAmt { get; set; }
[ExporterHeader(DisplayName = "价税合计")]
public decimal TotalAmt { get; set; }
[ExporterHeader(DisplayName = "版本号")]
public string Version { get; set; }
}
public class HQKBExtendVersionRequestDto : RequestDtoBase, IBranch<Guid>
{
public string Year { get; private set; }
/// <summary>
/// 期间
/// </summary>
public string Period { get; private set; }
/// <summary>
/// 版本号
/// </summary>
public string Version { get; private set; }
/// <summary>
/// 客户号
/// </summary>
public string CustomerCode { private set; get; }
public Guid BranchId { get; set; }
}
public class HQKBExtendVersionDto
{
public string Year { get; set; }
/// <summary>
/// 期间
/// </summary>
public string Period { get; set; }
/// <summary>
/// 版本号
/// </summary>
public string Version { get; set; }
/// <summary>
/// 客户号
/// </summary>
public string CustomerCode { set; get; }
public string Factory { set; get; }
}
public class HQKBSettleExtendDto
{
[ImporterHeader(Name = "试制任务单编号")]
public string TaskBillNum { get; set; }
[ImporterHeader(Name = "采购申请单号")]
public string BillNum { get; set; }
[ImporterHeader(Name = "零件名称")]
public string MaterialDesc { get; set; }
[ImporterHeader(Name = "零件号")]
public string MaterialCode { get; set; }
[ImporterHeader(Name = "数量")]
public decimal Qty { get; set; }
[ImporterHeader(Name = "无税单价")]
public decimal Price { get; set; }
[ImporterHeader(Name = "无税金额")]
public decimal Amt { get; set; }
[ImporterHeader(Name = "税率")]
public decimal Tax { get; set; }
[ImporterHeader(Name = "税额合计")]
public decimal TaxAmt { get; set; }
[ImporterHeader(Name = "价税合计")]
public decimal TotalAmt { get; set; }
[ImporterHeader(Name = "版本号", IsIgnore = false)]
public string Version { get; set; }
}
public class HQKBSettleExtendRequestDto : RequestDtoBase, IBranch<Guid>
{
[ImporterHeader(Name = "试制任务单编号")]
public string TaskBillNum { get; set; }
[ImporterHeader(Name = "采购申请单号")]
public string BillNum { get; set; }
[ImporterHeader(Name = "零件名称")]
public string MaterialDesc { get; set; }
[ImporterHeader(Name = "零件号")]
public string MaterialCode { get; set; }
[ImporterHeader(Name = "数量")]
public decimal Qty { get; set; }
[ImporterHeader(Name = "无税单价")]
public decimal Price { get; set; }
[ImporterHeader(Name = "无税金额")]
public decimal Amt { get; set; }
[ImporterHeader(Name = "税率")]
public decimal Tax { get; set; }
[ImporterHeader(Name = "税额合计")]
public decimal TaxAmt { get; set; }
[ImporterHeader(Name = "价税合计")]
public decimal TotalAmt { get; set; }
[ImporterHeader(Name = "版本号", IsIgnore = false)]
public string Version { get; set; }
public Guid BranchId { get; set; }
}
public class HQKBSettleExtendExportDto
{
[ExporterHeader(DisplayName = "试制任务单编号")]
public string TaskBillNum { get; set; }
[ExporterHeader(DisplayName = "采购申请单号")]
public string BillNum { get; set; }
[ExporterHeader(DisplayName = "零件名称")]
public string MaterialDesc { get; set; }
[ExporterHeader(DisplayName = "零件号")]
public string MaterialCode { get; set; }
[ExporterHeader(DisplayName = "数量")]
public decimal Qty { get; set; }
[ExporterHeader(DisplayName = "无税单价")]
public decimal Price { get; set; }
[ExporterHeader(DisplayName = "无税金额")]
public decimal Amt { get; set; }
[ExporterHeader(DisplayName = "税率")]
public decimal Tax { get; set; }
[ExporterHeader(DisplayName = "税额合计")]
public decimal TaxAmt { get; set; }
[ExporterHeader(DisplayName = "价税合计")]
public decimal TotalAmt { get; set; }
[ExporterHeader(DisplayName = "版本号")]
public string Version { get; set; }
}
public class HQKBSettleExtendVersionRequestDto : RequestDtoBase, IBranch<Guid>
{
public string Year { get; private set; }
/// <summary>
/// 期间
/// </summary>
public string Period { get; private set; }
/// <summary>
/// 版本号
/// </summary>
public string Version { get; private set; }
/// <summary>
/// 客户号
/// </summary>
public string CustomerCode { private set; get; }
public Guid BranchId { get; set; }
}
public class HQKBSettleExtendVersionDto
{
public string Year { get; set; }
/// <summary>
/// 期间
/// </summary>
public string Period { get; set; }
/// <summary>
/// 版本号
/// </summary>
public string Version { get; set; }
/// <summary>
/// 客户号
/// </summary>
public string CustomerCode { set; get; }
public string Factory { set; get; }
}
}

4
src/Modules/SettleAccount/src/SettleAccount.Application.Contracts/SettleAccount.Application.Contracts.csproj

@ -25,4 +25,8 @@
<ProjectReference Include="..\SettleAccount.Domain.Shared\SettleAccount.Domain.Shared.csproj" /> <ProjectReference Include="..\SettleAccount.Domain.Shared\SettleAccount.Domain.Shared.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<Folder Include="Entities\HQ\" />
</ItemGroup>
</Project> </Project>

334
src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BTCarConsigns_HS/BTCarConsignAppService.cs

@ -0,0 +1,334 @@
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.BTCarConsigns;
using Win.Sfs.SettleAccount.CommonManagers;
using Win.Sfs.SettleAccount.Constant;
using Win.Sfs.SettleAccount.Entities.BTCarConsigns;
using Win.Sfs.SettleAccount.ExcelImporter;
using Win.Sfs.Shared.CacheBase;
using Win.Sfs.Shared.Filter;
using Win.Utils;
namespace Win.Sfs.SettleAccount.BTCarConsigns
{
/// <summary>
/// 区域相关应用服务
/// </summary>
//[AuthorizeSettleAccountPermissions.BTCarConsigns.Default)]
[Route("api/settleaccount/BTCarConsign")]
public class BTCarConsignAppService : SettleAccountApplicationBase<BTCarConsign>, IBTCarConsignAppService
{
private readonly IGuidGenerator _guidGenerator;
private readonly IObjectMapper _objectMapper;
private readonly IExcelImportAppService _excelImportService;
private readonly ISettleAccountBranchEfCoreRepository<BTCarConsign, Guid> _repository;
private readonly ISettleAccountBranchEfCoreRepository<BTCarConsignVersion, Guid> _versionRepository;
/// <summary>
/// 构建方法
/// </summary>
/// <param name="guidGenerator">构建UID</param>
/// <param name="objectMapper">自动map</param>
/// <param name="repository">仓储接口</param>
/// <param name="cache">缓存</param>
public BTCarConsignAppService(IGuidGenerator guidGenerator,
IObjectMapper objectMapper,
IExcelImportAppService excelImportService,
ISnowflakeIdGenerator snowflakeIdGenerator,
ICommonManager commonManager,
ISettleAccountBranchEfCoreRepository<BTCarConsign, Guid> repository,
ISettleAccountBranchEfCoreRepository<BTCarConsignVersion, Guid> versionRepository,
IDistributedCache<BTCarConsign> 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.BTCarConsigns.Default)]
public async Task<string> BTCarConsignUploadExcelImport([FromForm] IFormFileCollection files, Guid branchId, string year, string period, string version, string customerCode,DateTime datetime)
{
ExportImporter _exportImporter = new ExportImporter();
var result = await _exportImporter.UploadExcelImport<ImportBTCarConsignDto>(files, _excelImportService);
var entityList = ObjectMapper.Map<List<ImportBTCarConsignDto>, List<BTCarConsign>>(result);
var _versionQuery = _versionRepository.Where(p => p.Version == version && p.CustomerCode==customerCode);
await _versionQuery.BatchDeleteAsync();
var _query = _repository.Where(p => p.Version == version && p.CustomerCode==customerCode);
await _query.BatchDeleteAsync();
var _id = GuidGenerator.Create();
var _BTCarConsignList = new List<BTCarConsignVersion>();
_BTCarConsignList.Add(new BTCarConsignVersion(_id, branchId, period, version, customerCode, datetime));
foreach (var itm in entityList)
{
itm.SetValue(GuidGenerator.Create(), branchId, period, version, customerCode, datetime, _id);
}
var bulkConfig = new BulkConfig { SetOutputIdentity = true, BatchSize = 10000 };
await _repository.GetDbContext().BulkInsertAsync<BTCarConsign>(entityList);
await _versionRepository.GetDbContext().BulkInsertAsync(_BTCarConsignList);
return ApplicationConsts.SuccessStr;
}
#endregion
/// <summary>
/// 按ID获取唯一实体
/// </summary>
/// <remarks>
/// 返回实体全部属性
/// </remarks>
/// <param name="id">ID</param>
/// <returns>实体DTO</returns>
[HttpGet]
[Route("{id}")]
//[AuthorizeSettleAccountPermissions.BTCarConsigns.Default)]
virtual public async Task<BTCarConsignDto> GetAsync(Guid id)
{
var result = await _repository.GetAsync(id);
var dto = _objectMapper.Map<BTCarConsign, BTCarConsignDto>(result);
return dto;
}
private async Task<BTCarConsign> GetFromCacheAsync(Guid id)
{
var result =
await _repository.GetAsync(id)
;
return result;
}
private async Task<long> GetCountAsync(BTCarConsignRequestDto input)
{
return await _repository.GetCountByFilterAsync(input.BranchId, input.Filters);
}
private async Task<long> GetCountAsync(BTCarConsignVersionRequestDto input)
{
return await _versionRepository.GetCountByFilterAsync(input.BranchId, input.Filters);
}
/// <summary>
/// 获取实体总数
/// </summary>
/// <returns>实体总数</returns>
[HttpGet]
[Route("count")]
//[AuthorizeSettleAccountPermissions.BTCarConsigns.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.BTCarConsigns.Delete)]
virtual public async Task DeleteAsync(Guid id)
{
//var entity = await GetFromCacheAsync(id);
//await Cache.DeleteAsync<BTCarConsign>(id.ToString());
await _repository.DeleteAsync(id);
}
/// <summary>
/// 按IDs删除实体列表
/// </summary>
/// <param name="ids">IDs</param>
/// <returns>是否执行成功</returns>
[HttpPost]
[Route("delete")]
//[AuthorizeSettleAccountPermissions.BTCarConsigns.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.BTCarConsigns.Default)]
public async Task<PagedResultDto<BTCarConsignDto>> GetListAsync(Guid parentId,BTCarConsignRequestDto 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<BTCarConsignDto>(0, new List<BTCarConsignDto>());
}
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<BTCarConsign>, List<BTCarConsignDto>>(entities);
return new PagedResultDto<BTCarConsignDto>(totalCount, dtos);
}
///// <summary>
/// <summary>
/// 根据筛选条件获取实体列表
/// </summary>
/// <remarks>
/// 请求条件包括:筛选条件列表,排序条件,数据数量,页码
/// </remarks>
/// <param name="input">请求条件</param>
/// <returns>实体DTO列表</returns>
[HttpPost]
[Route("listVersion")]
//[AuthorizeSettleAccountPermissions.BTCarConsigns.Default)]
public async Task<PagedResultDto<BTCarConsignVersionDto>> GetVersionListAsync(BTCarConsignVersionRequestDto 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<BTCarConsignVersion>, List<BTCarConsignVersionDto>>(entities);
foreach (var itm in dtos)
{
itm.Version = itm.Version + string.Format("({0})", itm.CustomerCode);
}
return new PagedResultDto<BTCarConsignVersionDto>(totalCount, dtos);
}
/// <summary>
/// 导出文件
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost]
[Route("Export")]
//[AuthorizeSettleAccountPermissions.BTCarConsigns.Default)]
virtual public async Task<string> ExportAsync(BTCarConsignRequestDto 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<BTCarConsign>, List<ExportBTCarConsignDto>>(entities);
string _fileName = string.Empty;
//声明导出容器
//byte[] result = null;
//_fileName = CommonMethod.GetExcelFileNameByUserID(ApplicationConsts.Sec_BTCarConsignFileName, CurrentUser.Id?.ToString(), ApplicationConsts.FileExtension);
byte[] result = null;
switch (input.FileType)
{
case 0:
_fileName = CommonMethod.GetExcelFileNameByUserID(ApplicationConsts.Sec_BTCarConsignFileName, CurrentUser.Id?.ToString(), ".csv");
result = await _csv.ExportAsByteArray(dtoDetails);
break;
case 1:
_fileName = CommonMethod.GetExcelFileNameByUserID(ApplicationConsts.Sec_BTCarConsignFileName, CurrentUser.Id?.ToString(),ApplicationConsts.FileExtension);
result = await _excel.ExportAsByteArray(dtoDetails);
break;
}
result.ShouldNotBeNull();
//保存导出文件到服务器存成二进制
await _excelImportService.SaveBlobAsync(
new SaveExcelImportInputDto
{
Name = _fileName,
Content = result
}
);
return _fileName;
}
[HttpPost]
[Route("btupdate")]
[UnitOfWork(isTransactional: false)]
public async Task<bool> UPdateFisAsync()
{
await _repository.GetDbContext().Database.ExecuteSqlRawAsync(
"EXEC sp_bt_update"
);
return true;
}
}
}

369
src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BTCarKBFirsts_HS/BTCarKBFirstAppService.cs

@ -0,0 +1,369 @@
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.BTCarKBs;
using Win.Sfs.SettleAccount.CommonManagers;
using Win.Sfs.SettleAccount.Constant;
using Win.Sfs.SettleAccount.Entities.BTCarKBFirsts;
using Win.Sfs.SettleAccount.Entities.BTCarKBs;
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.Filter;
using Win.Utils;
namespace Win.Sfs.SettleAccount.BTCarKBFirsts
{
/// <summary>
/// 区域相关应用服务
/// </summary>
//[AuthorizeSettleAccountPermissions.BTCarKBFirsts.Default)]
[Route("api/settleaccount/BTCarKBFirst")]
public class BTCarKBFirstAppService : SettleAccountApplicationBase<BTCarKB>, IBTCarKBFirstAppService
{
private readonly IGuidGenerator _guidGenerator;
private readonly IObjectMapper _objectMapper;
private readonly IExcelImportAppService _excelImportService;
private readonly ISettleAccountBranchEfCoreRepository<BTCarKB, Guid> _repository;
private readonly ISettleAccountBranchEfCoreRepository<BTCarKBVersion, 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 BTCarKBFirstAppService(IGuidGenerator guidGenerator,
IObjectMapper objectMapper,
IExcelImportAppService excelImportService,
ISnowflakeIdGenerator snowflakeIdGenerator,
ICommonManager commonManager,
ISettleAccountBranchEfCoreRepository<BTCarKB, Guid> repository,
ISettleAccountBranchEfCoreRepository<BTCarKBVersion, Guid> versionRepository,
ISettleAccountBranchEfCoreRepository<MaterialRelationship, Guid> MaterialRepository,
IDistributedCache<BTCarKB> 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.BTCarKBFirsts.Default)]
public async Task<string> BTCarKBFirstUploadExcelImport([FromForm] IFormFileCollection files, Guid branchId, string year, string period, string version, string customerCode)
{
ExportImporter _exportImporter = new ExportImporter();
var result = await _exportImporter.UploadExcelImport<ImportBTCarKBFirstDto>(files, _excelImportService);
var entityList = ObjectMapper.Map<List<ImportBTCarKBFirstDto>, List<BTCarKB>>(result);
var checkList = new List<ErrorExportDto>();
bool _iscreate = false;
var _versionQuery = _versionRepository.FirstOrDefault(p => p.Version == version && p.CustomerCode == customerCode);
if (_versionQuery == null)
{
_iscreate = true;
}
Guid _id = Guid.Empty;
if (_iscreate == true)
{
_id = GuidGenerator.Create();
}
else
{
_id = _versionQuery.Id;
}
//List<String> errorList = new List<string>();
DateTime datetime= entityList[0].DeliveryDateTime;
foreach (var itm in entityList)
{
//通过《零件关系匹配设置表》验证物料号
if (!_MaterialRepository.Any(p => p.ShipMaterailCode == itm.MaterialCode))
{
checkList.Add(new ErrorExportDto(version, customerCode, string.Empty, string.Empty, string.Empty, string.Empty, string.Format("发货看板物料号:{0}在《零件关系匹配设置表》中不存在!", itm.MaterialCode), string.Empty));
//errorList.Add(string.Format("发货看板物料号:{0}在《零件关系匹配设置表》中不存在!", itm.MaterialCode));
}
else
{
datetime = itm.DeliveryDateTime;
var _entity = _repository.FirstOrDefault(p => p.CustomerCode == customerCode && p.Version == version && p.MaterialCode == itm.MaterialCode && p.OrderKBCode == itm.OrderKBCode);
if (_entity == null)
{
_entity = new BTCarKB(GuidGenerator.Create(), GuidGenerator.Create(), period, customerCode, datetime, version, itm.MaterialCode, itm.MaterialDesc
, itm.NeedQty, itm.OrderKBCode, itm.ReceiveAreaCode, itm.ReceiveAreaName, itm.DeliveryDateTime, itm.ConsignQty, itm.State, _id);
await _repository.InsertAsync(_entity);
}
else
{
_entity.SetValue(_entity.Id, branchId, period, version, customerCode, datetime, _id);
await _repository.UpdateAsync(_entity);
}
}
}
if (checkList.Count > 0)
{
return await ExportErrorReportAsync(checkList);
}
//var bulkConfig = new BulkConfig { SetOutputIdentity = true, BatchSize = 10000 };
// await _repository.GetDbContext().BulkInsertAsync<BTCarKB>(entityList);
if (_iscreate == true)
{
var _BTCarKBFirstList = new List<BTCarKBVersion>();
_BTCarKBFirstList.Add(new BTCarKBVersion(_id, branchId, period, version, customerCode, datetime));
await _versionRepository.GetDbContext().BulkInsertAsync(_BTCarKBFirstList);
}
//st.Stop();
return ApplicationConsts.SuccessStr;
}
#endregion
/// <summary>
/// 按ID获取唯一实体
/// </summary>
/// <remarks>
/// 返回实体全部属性
/// </remarks>
/// <param name="id">ID</param>
/// <returns>实体DTO</returns>
[HttpGet]
[Route("{id}")]
//[AuthorizeSettleAccountPermissions.BTCarKBFirsts.Default)]
virtual public async Task<BTCarKBFirstDto> GetAsync(Guid id)
{
var result = await _repository.GetAsync(id);
var dto = _objectMapper.Map<BTCarKB, BTCarKBFirstDto>(result);
return dto;
}
private async Task<BTCarKB> GetFromCacheAsync(Guid id)
{
var result =
await _repository.GetAsync(id)
;
return result;
}
private async Task<long> GetCountAsync(BTCarKBRequestDto input)
{
return await _repository.GetCountByFilterAsync(input.BranchId, input.Filters);
}
private async Task<long> GetCountAsync(BTCarKBVersionRequestDto input)
{
return await _versionRepository.GetCountByFilterAsync(input.BranchId, input.Filters);
}
/// <summary>
/// 获取实体总数
/// </summary>
/// <returns>实体总数</returns>
[HttpGet]
[Route("count")]
//[AuthorizeSettleAccountPermissions.BTCarKBFirsts.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.BTCarKBFirsts.Delete)]
virtual public async Task DeleteAsync(Guid id)
{
//var entity = await GetFromCacheAsync(id);
//await Cache.DeleteAsync<BTCarKBFirst>(id.ToString());
await _repository.DeleteAsync(id);
}
/// <summary>
/// 按IDs删除实体列表
/// </summary>
/// <param name="ids">IDs</param>
/// <returns>是否执行成功</returns>
[HttpPost]
[Route("delete")]
//[AuthorizeSettleAccountPermissions.BTCarKBFirsts.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.BTCarKBFirsts.Default)]
public async Task<PagedResultDto<BTCarKBDto>> GetListAsync(Guid parentId, BTCarKBRequestDto 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<BTCarKBDto>(0, new List<BTCarKBDto>());
}
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<BTCarKB>, List<BTCarKBDto>>(entities);
return new PagedResultDto<BTCarKBDto>(totalCount, dtos);
}
///// <summary>
/// <summary>
/// 根据筛选条件获取实体列表
/// </summary>
/// <remarks>
/// 请求条件包括:筛选条件列表,排序条件,数据数量,页码
/// </remarks>
/// <param name="input">请求条件</param>
/// <returns>实体DTO列表</returns>
[HttpPost]
[Route("listVersion")]
//[AuthorizeSettleAccountPermissions.BTCarKBFirsts.Default)]
public async Task<PagedResultDto<BTCarKBVersionDto>> GetVersionListAsync(BTCarKBVersionRequestDto 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<BTCarKBVersion>, List<BTCarKBVersionDto>>(entities);
foreach (var itm in dtos)
{
itm.Version = itm.Version + string.Format("({0})", itm.CustomerCode);
}
return new PagedResultDto<BTCarKBVersionDto>(totalCount, dtos);
}
/// <summary>
/// 导出文件
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost]
[Route("Export")]
//[AuthorizeSettleAccountPermissions.BTCarKBFirsts.Default)]
virtual public async Task<string> ExportAsync(BTCarKBRequestDto 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<BTCarKB>, List<ExportBTCarKBFirstDto>>(entities);
string _fileName = string.Empty;
//声明导出容器
byte[] result = null;
switch (input.FileType)
{
case 0:
_fileName = CommonMethod.GetExcelFileNameByUserID(ApplicationConsts.Sec_BTCarFirstKBFileName, CurrentUser.Id?.ToString(),".csv" );
result = await _csv.ExportAsByteArray(dtoDetails);
break;
case 1:
_fileName = CommonMethod.GetExcelFileNameByUserID(ApplicationConsts.Sec_BTCarFirstKBFileName, CurrentUser.Id?.ToString(), ApplicationConsts.FileExtension);
result = await _excel.ExportAsByteArray(dtoDetails);
break;
}
//_fileName = CommonMethod.GetExcelFileNameByUserID(ApplicationConsts.Sec_BTCarFirstKBFileName, CurrentUser.Id?.ToString(), ApplicationConsts.FileExtension);
//result = await _excel.ExportAsByteArray(dtoDetails);
result.ShouldNotBeNull();
//保存导出文件到服务器存成二进制
await _excelImportService.SaveBlobAsync(
new SaveExcelImportInputDto
{
Name = _fileName,
Content = result
}
);
return _fileName;
}
}
}

398
src/Modules/SettleAccount/src/SettleAccount.Application/Entities/ErpShipping/ErpShippingAppService.cs

@ -0,0 +1,398 @@
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.ERPShipping;
using Win.Sfs.SettleAccount.Entities.ERPShpping;
using Win.Sfs.SettleAccount.Entities.ImportMap;
using Win.Sfs.SettleAccount.Entities.Materials;
using Win.Sfs.SettleAccount.ExcelImporter;
using Win.Sfs.SettleAccount.ExportReports;
using Win.Sfs.Shared.CacheBase;
using Win.Sfs.Shared.Filter;
using Win.Utils;
namespace Win.Sfs.SettleAccount.ERPShippingDetails
{
/// <summary>
/// 区域相关应用服务
/// </summary>
[Authorize(SettleAccountPermissions.Boms.Default)]
//[AllowAnonymous]
[Route("api/settleaccount/ErpShipping")]
public class ErpShippingAppService : SettleAccountApplicationBase<ERPShippingDetail>
{
private readonly IGuidGenerator _guidGenerator;
private readonly IObjectMapper _objectMapper;
private readonly IExcelImportAppService _excelImportService;
private readonly ISettleAccountBranchEfCoreRepository<ERPShippingDetail, Guid> _repository;
private readonly ISettleAccountBranchEfCoreRepository<Material, Guid> _materialRepository;
private readonly ISettleAccountBranchEfCoreRepository<ImportColumnMap, Guid> _importColumnMapRepository;
private readonly ISettleAccountBranchEfCoreRepository<ERPShippingVersion, Guid> _versionRepository;
/// <summary>
/// 构建方法
/// </summary>
/// <param name="guidGenerator">构建UID</param>
/// <param name="objectMapper">自动map</param>
/// <param name="repository">仓储接口</param>
/// <param name="cache">缓存</param>
public ErpShippingAppService(IGuidGenerator guidGenerator,
IObjectMapper objectMapper,
IExcelImportAppService excelImportService,
ISnowflakeIdGenerator snowflakeIdGenerator,
ICommonManager commonManager,
ISettleAccountBranchEfCoreRepository<ERPShippingDetail, Guid> repository,
ISettleAccountBranchEfCoreRepository<ERPShippingVersion, Guid> versionRepository,
ISettleAccountBranchEfCoreRepository<Material, Guid> materialRepository,
ISettleAccountBranchEfCoreRepository<ImportColumnMap, Guid> importColumnMapRepository,
IDistributedCache<ERPShippingDetail> cache
) : base(cache,excelImportService,snowflakeIdGenerator,commonManager)
{
_guidGenerator = guidGenerator;
_objectMapper = objectMapper;
_repository = repository;
_excelImportService = excelImportService;
_versionRepository = versionRepository;
_materialRepository = materialRepository;
_importColumnMapRepository = importColumnMapRepository;
}
#region 导入导出功能
/// <summary>
/// 导入功能
/// </summary>
/// <param name="files">上传的文件(前端已经限制只能上传一个附件)</param>
/// <returns></returns>
//[HttpPost]
//[Route("ExcelImport-Map")]
//[DisableRequestSizeLimit]
//[Authorize(SettleAccountPermissions.ERPShippingDetails.Create)]
//public async Task<string> ERPShippingDetailUploadExcelImportMap([FromForm] IFormFileCollection files, Guid branchId, string year, string period, string version, string customerCode, string factory)
//{
// var _mapList=_importColumnMapRepository.Where(p => p.ProjectName ==SettleAccountModuleName.ERPShippingDetail ).ToList();
// ExportImporter _exportImporter = new ExportImporter();
// var result = await _exportImporter.ExtendExcelImport<ImportERPShippingDetailDto>(files, _excelImportService,_mapList);
// var entityList = ObjectMapper.Map<List<ImportERPShippingDetailDto>, List<ERPShippingDetail>>(result);
// var _versionQuery = _versionRepository.Where(p => p.Version == version && p.Factory == factory);
// await _versionQuery.BatchDeleteAsync();
// var _query = _repository.Where(p => p.Version == version && p.Factory == factory);
// await _query.BatchDeleteAsync();
// var checkList = new List<ErrorExportDto>();
// var _matList = await _materialRepository.GetAllAsync(GuidGenerator.Create());
// var _group = entityList.GroupBy(x => new { x.ParentItemCode, x.ChildItemCode, x.Version }).Select(p => new { Count = p.Count(), ParentItmeCode = p.Key.ParentItemCode, ChildItemCode = p.Key.ChildItemCode });
// foreach (var itm in _group)
// {
// if (itm.Count > 1)
// {
// checkList.Add(new ErrorExportDto(version, customerCode, string.Empty, string.Empty, string.Empty, string.Empty, string.Format("不能导入父编码{0},子编码{1}有重复数据", itm.ParentItmeCode, itm.ChildItemCode), string.Empty));
// }
// }
// var _id = GuidGenerator.Create();
// var _ERPShippingDetailList = new List<ERPShippingVersion>();
// _ERPShippingDetailList.Add(new ERPShippingVersion(_id, branchId, year, period, version, customerCode, factory));
// foreach (var itm in entityList)
// {
// if (!_matList.Any(p => p.MaterialCode == itm.ParentItemCode))
// {
// checkList.Add(new ErrorExportDto(version, customerCode, string.Empty, string.Empty, itm.ParentItemCode, string.Empty, string.Format("物料主数据不存在物料号{0}!", itm.ParentItemCode), string.Empty));
// continue;
// }
// itm.SetValue(GuidGenerator.Create(), branchId, year, period, version, _id, factory);
// }
// if (checkList.Count > 0)
// {
// return await ExportErrorReportAsync(checkList);
// }
// await _repository.GetDbContext().BulkInsertAsync<ERPShippingDetail>(entityList);
// await _versionRepository.GetDbContext().BulkInsertAsync(_ERPShippingDetailList);
// //st.Stop();
// return ApplicationConsts.SuccessStr;
//}
/// <summary>
/// 导入功能
/// </summary>
/// <param name="files">上传的文件(前端已经限制只能上传一个附件)</param>
/// <returns></returns>
[HttpPost]
[Route("ExcelImport")]
[DisableRequestSizeLimit]
public async Task<string> ERPShippingDetailUploadExcelImport([FromForm] IFormFileCollection files, Guid branchId, string year, string period, string version, string customerCode,string factory)
{
ExportImporter _exportImporter = new ExportImporter();
var result = await _exportImporter.UploadExcelImport<ERPShippingDetailDto>(files, _excelImportService);
var entityList = ObjectMapper.Map<List<ERPShippingDetailDto>, List<ERPShippingDetail>>(result);
var _versionQuery = _versionRepository.Where(p => p.Version == version );
await _versionQuery.BatchDeleteAsync();
var _query = _repository.Where(p => p.Version == version );
await _query.BatchDeleteAsync();
//var checkList = new List<ErrorExportDto>();
//var _matList =await _materialRepository.GetAllAsync(GuidGenerator.Create());
// var _group = entityList.GroupBy(x => new { x.ParentItemCode, x.ChildItemCode, x.Version }).Select(p => new { Count = p.Count(),ParentItmeCode=p.Key.ParentItemCode, ChildItemCode=p.Key.ChildItemCode });
//foreach (var itm in _group)
//{
// if (itm.Count > 1)
// {
// checkList.Add(new ErrorExportDto(version, customerCode, string.Empty, string.Empty, string.Empty, string.Empty, string.Format("不能导入父编码{0},子编码{1}有重复数据", itm.ParentItmeCode, itm.ChildItemCode), string.Empty));
// }
//}
//var _id = GuidGenerator.Create();
//var _ERPShippingDetailList = new List<ERPShippingVersion>();
//_ERPShippingDetailList.Add(new ERPShippingVersion(_id, branchId, year, period, version, customerCode,factory));
//foreach (var itm in entityList)
//{
// if (!_matList.Any(p => p.MaterialCode == itm.ParentItemCode))
// {
// checkList.Add(new ErrorExportDto(version, customerCode, string.Empty, string.Empty, itm.ParentItemCode, string.Empty, string.Format("物料主数据不存在物料号{0}!", itm.ParentItemCode), string.Empty));
// continue;
// }
// itm.SetValue(GuidGenerator.Create(),branchId,year,period,version,_id,factory);
//}
//if (checkList.Count > 0)
//{
// return await ExportErrorReportAsync(checkList);
//}
await _repository.GetDbContext().BulkInsertAsync<ERPShippingDetail>(entityList);
await _versionRepository.GetDbContext().BulkInsertAsync(new List<ERPShippingVersion> { new ERPShippingVersion(Guid.NewGuid(), branchId, year, period, version, customerCode, factory) });
//st.Stop();
return ApplicationConsts.SuccessStr;
}
/// <summary>
/// 导出文件
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost]
[Route("Export")]
virtual public async Task<string> ExportAsync(ERPShippingDetailRequestDto input)
{
IExporter _csv = new CsvExporter();
IExporter _excel = new ExcelExporter();
//导出加上版本过滤条件,不能全导出
if (!string.IsNullOrEmpty(input.Version ))
{
input.Filters.Add(new FilterCondition() { Action = EnumFilterAction.Equal, Column = "Version", Logic = EnumFilterLogic.And, Value = input.Version.ToString() });
}
//else
//{
// return new PagedResultDto<ERPShippingDetailDto>(0, new List<ERPShippingDetailDto>());
//}
var entities = await _repository.GetListByFilterAsync(input.BranchId, input.Filters, input.Sorting, int.MaxValue,
0, true);
var dtoDetails = ObjectMapper.Map<List<ERPShippingDetail>, List<ERPShippingDetailExportDto>>(entities);
string _fileName = string.Empty;
//声明导出容器
byte[] result = null;
_fileName = string.Format("ERP调拨_{0}.xlsx", Guid.NewGuid().ToString("N"));
result = await _excel.ExportAsByteArray(dtoDetails);
result.ShouldNotBeNull();
//保存导出文件到服务器存成二进制
await _excelImportService.SaveBlobAsync(
new SaveExcelImportInputDto
{
Name = _fileName,
Content = result
}
);
return _fileName;
}
#endregion
/// <summary>
/// 按ID获取唯一实体
/// </summary>
/// <remarks>
/// 返回实体全部属性
/// </remarks>
/// <param name="id">ID</param>
/// <returns>实体DTO</returns>
[HttpGet]
[Route("{id}")]
virtual public async Task<ERPShippingDetailDto> GetAsync(Guid id)
{
var result = await _repository.GetAsync(id);
var dto = _objectMapper.Map<ERPShippingDetail, ERPShippingDetailDto>(result);
return dto;
}
private async Task<ERPShippingDetail> GetFromCacheAsync(Guid id)
{
var result = await _repository.GetAsync(id);
return result;
}
private async Task<long> GetCountAsync(ERPShippingDetailRequestDto input)
{
return await _repository.GetCountByFilterAsync(input.BranchId, input.Filters);
}
private async Task<long> GetCountAsync(ERPShippingVersionRequestDto input)
{
return await _versionRepository.GetCountByFilterAsync(input.BranchId, input.Filters);
}
/// <summary>
/// 获取实体总数
/// </summary>
/// <returns>实体总数</returns>
[HttpGet]
[Route("count")]
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}")]
virtual public async Task DeleteAsync(Guid id)
{
//var entity = await GetFromCacheAsync(id);
//await Cache.DeleteAsync<ERPShippingDetail>(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)
{
//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")]
public async Task<PagedResultDto<ERPShippingDetailDto>> GetListAsync(Guid parentId, ERPShippingDetailRequestDto input)
{
if (!string.IsNullOrEmpty(input.Version) )
{
input.Filters.Add(new FilterCondition() { Action = EnumFilterAction.Equal, Column = "Version", Logic = EnumFilterLogic.And, Value = input.Version });
}
else
{
return new PagedResultDto<ERPShippingDetailDto>(0,new List<ERPShippingDetailDto>());
}
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<ERPShippingDetail>, List<ERPShippingDetailDto>>(entities);
return new PagedResultDto<ERPShippingDetailDto>(totalCount, dtos);
}
///// <summary>
/// <summary>
/// 根据筛选条件获取实体列表
/// </summary>
/// <remarks>
/// 请求条件包括:筛选条件列表,排序条件,数据数量,页码
/// </remarks>
/// <param name="input">请求条件</param>
/// <returns>实体DTO列表</returns>
[HttpPost]
[Route("listVersion")]
public async Task<PagedResultDto<ERPShippingVersionDto>> GetVersionListAsync(ERPShippingVersionRequestDto 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<ERPShippingVersion>, List<ERPShippingVersionDto>>(entities);
//foreach (var itm in dtos)
//{
// itm.Version = itm.Version + string.Format("({0})", itm.Factory);
//}
return new PagedResultDto<ERPShippingVersionDto>(totalCount, dtos);
}
}
}

347
src/Modules/SettleAccount/src/SettleAccount.Application/Entities/HQExtend/HQKBExtendAppService.cs

@ -0,0 +1,347 @@
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.ERPShipping;
using Win.Sfs.SettleAccount.Entities.ERPShpping;
using Win.Sfs.SettleAccount.Entities.HQExtend;
using Win.Sfs.SettleAccount.Entities.ImportMap;
using Win.Sfs.SettleAccount.Entities.Materials;
using Win.Sfs.SettleAccount.ExcelImporter;
using Win.Sfs.SettleAccount.ExportReports;
using Win.Sfs.Shared.CacheBase;
using Win.Sfs.Shared.Filter;
using Win.Utils;
namespace Win.Sfs.SettleAccount.HQKBExtends
{
/// <summary>
/// 区域相关应用服务
/// </summary>
[Authorize(SettleAccountPermissions.Boms.Default)]
//[AllowAnonymous]
[Route("api/settleaccount/ErpShipping")]
public class HQKBExtendAppService : SettleAccountApplicationBase<HQKBExtend>
{
private readonly IGuidGenerator _guidGenerator;
private readonly IObjectMapper _objectMapper;
private readonly IExcelImportAppService _excelImportService;
private readonly ISettleAccountBranchEfCoreRepository<HQKBExtend, Guid> _repository;
private readonly ISettleAccountBranchEfCoreRepository<Material, Guid> _materialRepository;
private readonly ISettleAccountBranchEfCoreRepository<ImportColumnMap, Guid> _importColumnMapRepository;
private readonly ISettleAccountBranchEfCoreRepository<HQKBExtendVersion, Guid> _versionRepository;
/// <summary>
/// 构建方法
/// </summary>
/// <param name="guidGenerator">构建UID</param>
/// <param name="objectMapper">自动map</param>
/// <param name="repository">仓储接口</param>
/// <param name="cache">缓存</param>
public HQKBExtendAppService(IGuidGenerator guidGenerator,
IObjectMapper objectMapper,
IExcelImportAppService excelImportService,
ISnowflakeIdGenerator snowflakeIdGenerator,
ICommonManager commonManager,
ISettleAccountBranchEfCoreRepository<HQKBExtend, Guid> repository,
ISettleAccountBranchEfCoreRepository<HQKBExtendVersion, Guid> versionRepository,
ISettleAccountBranchEfCoreRepository<Material, Guid> materialRepository,
ISettleAccountBranchEfCoreRepository<ImportColumnMap, Guid> importColumnMapRepository,
IDistributedCache<HQKBExtend> cache
) : base(cache,excelImportService,snowflakeIdGenerator,commonManager)
{
_guidGenerator = guidGenerator;
_objectMapper = objectMapper;
_repository = repository;
_excelImportService = excelImportService;
_versionRepository = versionRepository;
_materialRepository = materialRepository;
_importColumnMapRepository = importColumnMapRepository;
}
#region 导入导出功能
/// <summary>
/// 导入功能
/// </summary>
/// <param name="files">上传的文件(前端已经限制只能上传一个附件)</param>
/// <returns></returns>
[HttpPost]
[Route("ExcelImport")]
[DisableRequestSizeLimit]
public async Task<string> HQKBExtendUploadExcelImport([FromForm] IFormFileCollection files, Guid branchId, string year, string period, string version, string customerCode,string factory)
{
ExportImporter _exportImporter = new ExportImporter();
var result = await _exportImporter.UploadExcelImport<HQKBExtendDto>(files, _excelImportService);
var entityList = ObjectMapper.Map<List<HQKBExtendDto>, List<HQKBExtend>>(result);
var _versionQuery = _versionRepository.Where(p => p.Version == version );
await _versionQuery.BatchDeleteAsync();
var _query = _repository.Where(p => p.Version == version );
await _query.BatchDeleteAsync();
//var checkList = new List<ErrorExportDto>();
//var _matList =await _materialRepository.GetAllAsync(GuidGenerator.Create());
// var _group = entityList.GroupBy(x => new { x.ParentItemCode, x.ChildItemCode, x.Version }).Select(p => new { Count = p.Count(),ParentItmeCode=p.Key.ParentItemCode, ChildItemCode=p.Key.ChildItemCode });
//foreach (var itm in _group)
//{
// if (itm.Count > 1)
// {
// checkList.Add(new ErrorExportDto(version, customerCode, string.Empty, string.Empty, string.Empty, string.Empty, string.Format("不能导入父编码{0},子编码{1}有重复数据", itm.ParentItmeCode, itm.ChildItemCode), string.Empty));
// }
//}
//var _id = GuidGenerator.Create();
//var _HQKBExtendList = new List<HQKBExtendVersion>();
//_HQKBExtendList.Add(new HQKBExtendVersion(_id, branchId, year, period, version, customerCode,factory));
//foreach (var itm in entityList)
//{
// if (!_matList.Any(p => p.MaterialCode == itm.ParentItemCode))
// {
// checkList.Add(new ErrorExportDto(version, customerCode, string.Empty, string.Empty, itm.ParentItemCode, string.Empty, string.Format("物料主数据不存在物料号{0}!", itm.ParentItemCode), string.Empty));
// continue;
// }
// itm.SetValue(GuidGenerator.Create(),branchId,year,period,version,_id,factory);
//}
//if (checkList.Count > 0)
//{
// return await ExportErrorReportAsync(checkList);
//}
await _repository.GetDbContext().BulkInsertAsync<HQKBExtend>(entityList);
await _versionRepository.GetDbContext().BulkInsertAsync(new List<HQKBExtendVersion> { new HQKBExtendVersion(Guid.NewGuid(), branchId, year, period, version, customerCode, factory) });
//st.Stop();
return ApplicationConsts.SuccessStr;
}
/// <summary>
/// 导出文件
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost]
[Route("Export")]
virtual public async Task<string> ExportAsync(HQKBExtendRequestDto input)
{
IExporter _csv = new CsvExporter();
IExporter _excel = new ExcelExporter();
//导出加上版本过滤条件,不能全导出
if (!string.IsNullOrEmpty(input.Version ))
{
input.Filters.Add(new FilterCondition() { Action = EnumFilterAction.Equal, Column = "Version", Logic = EnumFilterLogic.And, Value = input.Version.ToString() });
}
//else
//{
// return new PagedResultDto<HQKBExtendDto>(0, new List<HQKBExtendDto>());
//}
var entities = await _repository.GetListByFilterAsync(input.BranchId, input.Filters, input.Sorting, int.MaxValue,
0, true);
var dtoDetails = ObjectMapper.Map<List<HQKBExtend>, List<HQKBExtendExportDto>>(entities);
string _fileName = string.Empty;
//声明导出容器
byte[] result = null;
_fileName = string.Format("ERP调拨_{0}.xlsx", Guid.NewGuid().ToString("N"));
result = await _excel.ExportAsByteArray(dtoDetails);
result.ShouldNotBeNull();
//保存导出文件到服务器存成二进制
await _excelImportService.SaveBlobAsync(
new SaveExcelImportInputDto
{
Name = _fileName,
Content = result
}
);
return _fileName;
}
#endregion
/// <summary>
/// 按ID获取唯一实体
/// </summary>
/// <remarks>
/// 返回实体全部属性
/// </remarks>
/// <param name="id">ID</param>
/// <returns>实体DTO</returns>
[HttpGet]
[Route("{id}")]
virtual public async Task<HQKBExtendDto> GetAsync(Guid id)
{
var result = await _repository.GetAsync(id);
var dto = _objectMapper.Map<HQKBExtend, HQKBExtendDto>(result);
return dto;
}
private async Task<HQKBExtend> GetFromCacheAsync(Guid id)
{
var result = await _repository.GetAsync(id);
return result;
}
private async Task<long> GetCountAsync(HQKBExtendRequestDto input)
{
return await _repository.GetCountByFilterAsync(input.BranchId, input.Filters);
}
private async Task<long> GetCountAsync(HQKBExtendVersionRequestDto input)
{
return await _versionRepository.GetCountByFilterAsync(input.BranchId, input.Filters);
}
/// <summary>
/// 获取实体总数
/// </summary>
/// <returns>实体总数</returns>
[HttpGet]
[Route("count")]
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}")]
virtual public async Task DeleteAsync(Guid id)
{
//var entity = await GetFromCacheAsync(id);
//await Cache.DeleteAsync<HQKBExtend>(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)
{
//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")]
public async Task<PagedResultDto<HQKBExtendDto>> GetListAsync(Guid parentId, HQKBExtendRequestDto input)
{
if (!string.IsNullOrEmpty(input.Version) )
{
input.Filters.Add(new FilterCondition() { Action = EnumFilterAction.Equal, Column = "Version", Logic = EnumFilterLogic.And, Value = input.Version });
}
else
{
return new PagedResultDto<HQKBExtendDto>(0,new List<HQKBExtendDto>());
}
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<HQKBExtend>, List<HQKBExtendDto>>(entities);
return new PagedResultDto<HQKBExtendDto>(totalCount, dtos);
}
///// <summary>
/// <summary>
/// 根据筛选条件获取实体列表
/// </summary>
/// <remarks>
/// 请求条件包括:筛选条件列表,排序条件,数据数量,页码
/// </remarks>
/// <param name="input">请求条件</param>
/// <returns>实体DTO列表</returns>
[HttpPost]
[Route("listVersion")]
public async Task<PagedResultDto<HQKBExtendVersionDto>> GetVersionListAsync(HQKBExtendVersionRequestDto 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<HQKBExtendVersion>, List<HQKBExtendVersionDto>>(entities);
//foreach (var itm in dtos)
//{
// itm.Version = itm.Version + string.Format("({0})", itm.Factory);
//}
return new PagedResultDto<HQKBExtendVersionDto>(totalCount, dtos);
}
}
}

346
src/Modules/SettleAccount/src/SettleAccount.Application/Entities/HQExtend/HQKBSettleExtendAppService.cs

@ -0,0 +1,346 @@
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.ERPShipping;
using Win.Sfs.SettleAccount.Entities.ERPShpping;
using Win.Sfs.SettleAccount.Entities.HQExtend;
using Win.Sfs.SettleAccount.Entities.ImportMap;
using Win.Sfs.SettleAccount.Entities.Materials;
using Win.Sfs.SettleAccount.ExcelImporter;
using Win.Sfs.SettleAccount.ExportReports;
using Win.Sfs.Shared.CacheBase;
using Win.Sfs.Shared.Filter;
using Win.Utils;
namespace Win.Sfs.SettleAccount.HQKBExtends
{
/// <summary>
/// 区域相关应用服务
/// </summary>
[Authorize(SettleAccountPermissions.Boms.Default)]
//[AllowAnonymous]
[Route("api/settleaccount/ErpShipping")]
public class HQKBSettleExtendAppService : SettleAccountApplicationBase<HQKBSettleExtend>
{
private readonly IGuidGenerator _guidGenerator;
private readonly IObjectMapper _objectMapper;
private readonly IExcelImportAppService _excelImportService;
private readonly ISettleAccountBranchEfCoreRepository<HQKBSettleExtend, Guid> _repository;
private readonly ISettleAccountBranchEfCoreRepository<Material, Guid> _materialRepository;
private readonly ISettleAccountBranchEfCoreRepository<ImportColumnMap, Guid> _importColumnMapRepository;
private readonly ISettleAccountBranchEfCoreRepository<HQKBSettleExtendVersion, Guid> _versionRepository;
/// <summary>
/// 构建方法
/// </summary>
/// <param name="guidGenerator">构建UID</param>
/// <param name="objectMapper">自动map</param>
/// <param name="repository">仓储接口</param>
/// <param name="cache">缓存</param>
public HQKBSettleExtendAppService(IGuidGenerator guidGenerator,
IObjectMapper objectMapper,
IExcelImportAppService excelImportService,
ISnowflakeIdGenerator snowflakeIdGenerator,
ICommonManager commonManager,
ISettleAccountBranchEfCoreRepository<HQKBSettleExtend, Guid> repository,
ISettleAccountBranchEfCoreRepository<HQKBSettleExtendVersion, Guid> versionRepository,
ISettleAccountBranchEfCoreRepository<Material, Guid> materialRepository,
ISettleAccountBranchEfCoreRepository<ImportColumnMap, Guid> importColumnMapRepository,
IDistributedCache<HQKBSettleExtend> cache
) : base(cache,excelImportService,snowflakeIdGenerator,commonManager)
{
_guidGenerator = guidGenerator;
_objectMapper = objectMapper;
_repository = repository;
_excelImportService = excelImportService;
_versionRepository = versionRepository;
_materialRepository = materialRepository;
_importColumnMapRepository = importColumnMapRepository;
}
#region 导入导出功能
/// <summary>
/// 导入功能
/// </summary>
/// <param name="files">上传的文件(前端已经限制只能上传一个附件)</param>
/// <returns></returns>
[HttpPost]
[Route("ExcelImport")]
[DisableRequestSizeLimit]
public async Task<string> HQKBSettleExtendUploadExcelImport([FromForm] IFormFileCollection files, Guid branchId, string year, string period, string version, string customerCode,string factory)
{
ExportImporter _exportImporter = new ExportImporter();
var result = await _exportImporter.UploadExcelImport<HQKBSettleExtendDto>(files, _excelImportService);
var entityList = ObjectMapper.Map<List<HQKBSettleExtendDto>, List<HQKBSettleExtend>>(result);
var _versionQuery = _versionRepository.Where(p => p.Version == version );
await _versionQuery.BatchDeleteAsync();
var _query = _repository.Where(p => p.Version == version );
await _query.BatchDeleteAsync();
//var checkList = new List<ErrorExportDto>();
//var _matList =await _materialRepository.GetAllAsync(GuidGenerator.Create());
// var _group = entityList.GroupBy(x => new { x.ParentItemCode, x.ChildItemCode, x.Version }).Select(p => new { Count = p.Count(),ParentItmeCode=p.Key.ParentItemCode, ChildItemCode=p.Key.ChildItemCode });
//foreach (var itm in _group)
//{
// if (itm.Count > 1)
// {
// checkList.Add(new ErrorExportDto(version, customerCode, string.Empty, string.Empty, string.Empty, string.Empty, string.Format("不能导入父编码{0},子编码{1}有重复数据", itm.ParentItmeCode, itm.ChildItemCode), string.Empty));
// }
//}
//var _id = GuidGenerator.Create();
//var _HQKBSettleExtendList = new List<HQKBSettleExtendVersion>();
//_HQKBSettleExtendList.Add(new HQKBSettleExtendVersion(_id, branchId, year, period, version, customerCode,factory));
//foreach (var itm in entityList)
//{
// if (!_matList.Any(p => p.MaterialCode == itm.ParentItemCode))
// {
// checkList.Add(new ErrorExportDto(version, customerCode, string.Empty, string.Empty, itm.ParentItemCode, string.Empty, string.Format("物料主数据不存在物料号{0}!", itm.ParentItemCode), string.Empty));
// continue;
// }
// itm.SetValue(GuidGenerator.Create(),branchId,year,period,version,_id,factory);
//}
//if (checkList.Count > 0)
//{
// return await ExportErrorReportAsync(checkList);
//}
await _repository.GetDbContext().BulkInsertAsync<HQKBSettleExtend>(entityList);
await _versionRepository.GetDbContext().BulkInsertAsync(new List<HQKBSettleExtendVersion> { new HQKBSettleExtendVersion(Guid.NewGuid(), branchId, year, period, version, customerCode, factory) });
//st.Stop();
return ApplicationConsts.SuccessStr;
}
/// <summary>
/// 导出文件
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost]
[Route("Export")]
virtual public async Task<string> ExportAsync(HQKBSettleExtendRequestDto input)
{
IExporter _csv = new CsvExporter();
IExporter _excel = new ExcelExporter();
//导出加上版本过滤条件,不能全导出
if (!string.IsNullOrEmpty(input.Version ))
{
input.Filters.Add(new FilterCondition() { Action = EnumFilterAction.Equal, Column = "Version", Logic = EnumFilterLogic.And, Value = input.Version.ToString() });
}
//else
//{
// return new PagedResultDto<HQKBSettleExtendDto>(0, new List<HQKBSettleExtendDto>());
//}
var entities = await _repository.GetListByFilterAsync(input.BranchId, input.Filters, input.Sorting, int.MaxValue,
0, true);
var dtoDetails = ObjectMapper.Map<List<HQKBSettleExtend>, List<HQKBSettleExtendExportDto>>(entities);
string _fileName = string.Empty;
//声明导出容器
byte[] result = null;
_fileName = string.Format("ERP调拨_{0}.xlsx", Guid.NewGuid().ToString("N"));
result = await _excel.ExportAsByteArray(dtoDetails);
result.ShouldNotBeNull();
//保存导出文件到服务器存成二进制
await _excelImportService.SaveBlobAsync(
new SaveExcelImportInputDto
{
Name = _fileName,
Content = result
}
);
return _fileName;
}
#endregion
/// <summary>
/// 按ID获取唯一实体
/// </summary>
/// <remarks>
/// 返回实体全部属性
/// </remarks>
/// <param name="id">ID</param>
/// <returns>实体DTO</returns>
[HttpGet]
[Route("{id}")]
virtual public async Task<HQKBSettleExtendDto> GetAsync(Guid id)
{
var result = await _repository.GetAsync(id);
var dto = _objectMapper.Map<HQKBSettleExtend, HQKBSettleExtendDto>(result);
return dto;
}
private async Task<HQKBSettleExtend> GetFromCacheAsync(Guid id)
{
var result = await _repository.GetAsync(id);
return result;
}
private async Task<long> GetCountAsync(HQKBSettleExtendRequestDto input)
{
return await _repository.GetCountByFilterAsync(input.BranchId, input.Filters);
}
private async Task<long> GetCountAsync(HQKBSettleExtendVersionRequestDto input)
{
return await _versionRepository.GetCountByFilterAsync(input.BranchId, input.Filters);
}
/// <summary>
/// 获取实体总数
/// </summary>
/// <returns>实体总数</returns>
[HttpGet]
[Route("count")]
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}")]
virtual public async Task DeleteAsync(Guid id)
{
//var entity = await GetFromCacheAsync(id);
//await Cache.DeleteAsync<HQKBSettleExtend>(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)
{
//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")]
public async Task<PagedResultDto<HQKBSettleExtendDto>> GetListAsync(Guid parentId, HQKBSettleExtendRequestDto input)
{
if (!string.IsNullOrEmpty(input.Version) )
{
input.Filters.Add(new FilterCondition() { Action = EnumFilterAction.Equal, Column = "Version", Logic = EnumFilterLogic.And, Value = input.Version });
}
else
{
return new PagedResultDto<HQKBSettleExtendDto>(0,new List<HQKBSettleExtendDto>());
}
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<HQKBSettleExtend>, List<HQKBSettleExtendDto>>(entities);
return new PagedResultDto<HQKBSettleExtendDto>(totalCount, dtos);
}
///// <summary>
/// <summary>
/// 根据筛选条件获取实体列表
/// </summary>
/// <remarks>
/// 请求条件包括:筛选条件列表,排序条件,数据数量,页码
/// </remarks>
/// <param name="input">请求条件</param>
/// <returns>实体DTO列表</returns>
[HttpPost]
[Route("listVersion")]
public async Task<PagedResultDto<HQKBSettleExtendVersionDto>> GetVersionListAsync(HQKBSettleExtendVersionRequestDto 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<HQKBSettleExtendVersion>, List<HQKBSettleExtendVersionDto>>(entities);
//foreach (var itm in dtos)
//{
// itm.Version = itm.Version + string.Format("({0})", itm.Factory);
//}
return new PagedResultDto<HQKBSettleExtendVersionDto>(totalCount, dtos);
}
}
}

4
src/Modules/SettleAccount/src/SettleAccount.Application/SettleAccount.Application.csproj

@ -163,8 +163,4 @@
</None> </None>
</ItemGroup> </ItemGroup>
<ItemGroup>
<Folder Include="Entities\ErpShipping\" />
</ItemGroup>
</Project> </Project>

60
src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/ERPShipping/ERPShippingDetail.cs

@ -1,4 +1,5 @@
using System; using Magicodes.ExporterAndImporter.Core;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
@ -9,6 +10,63 @@ namespace Win.Sfs.SettleAccount.Entities.ERPShipping
{ {
public class ERPShippingDetail : FullAuditedAggregateRootBase<Guid>, ISettleAccountEntityBase public class ERPShippingDetail : FullAuditedAggregateRootBase<Guid>, ISettleAccountEntityBase
{ {
public ERPShippingDetail(Guid id,string person, decimal cost, string billNum, string unit, decimal qty, string output, string outputCode, string input, string inputCode, decimal outputAssQty, string model, decimal outputQty, string batchNum, DateTime billDate, string flag, string erpMaterialCode, string version):base(id)
{
Person = person;
Cost = cost;
BillNum = billNum;
Unit = unit;
Qty = qty;
Output = output;
OutputCode = outputCode;
Input = input;
InputCode = inputCode;
OutputAssQty = outputAssQty;
Model = model;
OutputQty = outputQty;
BatchNum = batchNum;
BillDate = billDate;
Flag = flag;
ErpMaterialCode = erpMaterialCode;
Version = version;
}
[ImporterHeader(Name = "保管")]
public string Person { set; get; }
[ImporterHeader(Name = "成本")]
public decimal Cost { set; get; }
[ImporterHeader(Name = "单据编号")]
public string BillNum { set; get; }
[ImporterHeader(Name = "单位")]
public string Unit { set; get; }
[ImporterHeader(Name = "调拨数量")]
public decimal Qty { set; get; }
[ImporterHeader(Name = "调出仓库")]
public string Output { set; get; }
[ImporterHeader(Name = "调出仓库代码")]
public string OutputCode { set; get; }
[ImporterHeader(Name = "调入仓库")]
public string Input { set; get; }
[ImporterHeader(Name = "调入仓库代码")]
public string InputCode { set; get; }
[ImporterHeader(Name = "辅助出库关联数量")]
public decimal OutputAssQty { set; get; }
[ImporterHeader(Name = "规格型号")]
public string Model { set; get; }
[ImporterHeader(Name = "基本出库关联数量")]
public decimal OutputQty { set; get; }
[ImporterHeader(Name = "批号")]
public string BatchNum { set; get; }
[ImporterHeader(Name = "日期")]
public DateTime BillDate { set; get; }
[ImporterHeader(Name = "审核标志")]
public string Flag { get; set; }
[ImporterHeader(Name = "物料长代码")]
public string ErpMaterialCode { set; get; }
[ImporterHeader(Name = "期间")]
public string Version { get; set; } public string Version { get; set; }
} }
} }

49
src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/ERPShipping/ERPShippingVersion.cs

@ -7,8 +7,53 @@ using Win.Sfs.Shared.DomainBase;
namespace Win.Sfs.SettleAccount.Entities.ERPShipping namespace Win.Sfs.SettleAccount.Entities.ERPShipping
{ {
public class ERPShippingVersion : FullAuditedAggregateRootBase<Guid>, ISettleAccountEntityBase
public class ERPShippingVersion : FullAuditedAggregateRootBase<Guid>
{
public ERPShippingVersion()
{ }
public string Year { get; private set; }
/// <summary>
/// 期间
/// </summary>
public string Period { get; private set; }
/// <summary>
/// 版本号
/// </summary>
public string Version { get; private set; }
/// <summary>
/// 工厂
/// </summary>
public string Factory { set; get; }
/// <summary>
/// 客户号
/// </summary>
public string CustomerCode { private set; get; }
public ERPShippingVersion(
Guid id,
Guid branchId,
string year, string period, string version, string customerCode, string factory) : base(id)
{ {
public string Version { get; set; } BranchId = branchId;
Year = year;
Period = period;
Version = version;
CustomerCode = customerCode;
Factory = factory;
}
} }
} }

52
src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/HQExtend/HQKBExtend.cs

@ -0,0 +1,52 @@
using Magicodes.ExporterAndImporter.Core;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Win.Sfs.Shared.DomainBase;
namespace Win.Sfs.SettleAccount.Entities.HQExtend
{
public class HQKBExtend: FullAuditedAggregateRootBase<Guid>, ISettleAccountEntityBase
{
public HQKBExtend(string taskBillNum, string billNum, string materialDesc, string materialCode, decimal qty, decimal price, decimal amt, decimal tax, decimal taxAmt, decimal totalAmt)
{
TaskBillNum = taskBillNum;
BillNum = billNum;
MaterialDesc = materialDesc;
MaterialCode = materialCode;
Qty = qty;
Price = price;
Amt = amt;
Tax = tax;
TaxAmt = taxAmt;
TotalAmt = totalAmt;
}
[ImporterHeader(Name = "试制任务单编号")]
public string TaskBillNum { get; set; }
[ImporterHeader(Name = "采购申请单号")]
public string BillNum { get; set; }
[ImporterHeader(Name = "零件名称")]
public string MaterialDesc { get; set; }
[ImporterHeader(Name = "零件号")]
public string MaterialCode { get; set; }
[ImporterHeader(Name = "数量")]
public decimal Qty { get; set; }
[ImporterHeader(Name = "无税单价")]
public decimal Price { get; set; }
[ImporterHeader(Name = "无税金额")]
public decimal Amt { get; set; }
[ImporterHeader(Name = "税率")]
public decimal Tax { get; set; }
[ImporterHeader(Name = "税额合计")]
public decimal TaxAmt { get; set; }
[ImporterHeader(Name = "价税合计")]
public decimal TotalAmt { get; set; }
[ImporterHeader(Name = "版本号",IsIgnore =false)]
public string Version { get ; set ; }
}
}

55
src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/HQExtend/HQKBExtendVersion.cs

@ -0,0 +1,55 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Win.Sfs.Shared.DomainBase;
namespace Win.Sfs.SettleAccount.Entities.HQExtend
{
public class HQKBExtendVersion : FullAuditedAggregateRootBase<Guid>, ISettleAccountEntityBase
{
public HQKBExtendVersion()
{ }
public string Year { get; set; }
/// <summary>
/// 期间
/// </summary>
public string Period { get; set; }
/// <summary>
/// 版本号
/// </summary>
public string Version { get; set; }
/// <summary>
/// 工厂
/// </summary>
public string Factory { set; get; }
/// <summary>
/// 客户号
/// </summary>
public string CustomerCode { private set; get; }
public HQKBExtendVersion(
Guid id,
Guid branchId,
string year, string period, string version, string customerCode, string factory) : base(id)
{
BranchId = branchId;
Year = year;
Period = period;
Version = version;
CustomerCode = customerCode;
Factory = factory;
}
}
}

52
src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/HQExtend/HQKBSettleExtend.cs

@ -0,0 +1,52 @@
using Magicodes.ExporterAndImporter.Core;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Win.Sfs.Shared.DomainBase;
namespace Win.Sfs.SettleAccount.Entities.HQExtend
{
public class HQKBSettleExtend : FullAuditedAggregateRootBase<Guid>, ISettleAccountEntityBase
{
public HQKBSettleExtend(string taskBillNum, string billNum, string materialDesc, string materialCode, decimal qty, decimal price, decimal amt, decimal tax, decimal taxAmt, decimal totalAmt)
{
TaskBillNum = taskBillNum;
BillNum = billNum;
MaterialDesc = materialDesc;
MaterialCode = materialCode;
Qty = qty;
Price = price;
Amt = amt;
Tax = tax;
TaxAmt = taxAmt;
TotalAmt = totalAmt;
}
[ImporterHeader(Name = "试制任务单编号")]
public string TaskBillNum { get; set; }
[ImporterHeader(Name = "采购申请单号")]
public string BillNum { get; set; }
[ImporterHeader(Name = "零件名称")]
public string MaterialDesc { get; set; }
[ImporterHeader(Name = "零件号")]
public string MaterialCode { get; set; }
[ImporterHeader(Name = "数量")]
public decimal Qty { get; set; }
[ImporterHeader(Name = "无税单价")]
public decimal Price { get; set; }
[ImporterHeader(Name = "无税金额")]
public decimal Amt { get; set; }
[ImporterHeader(Name = "税率")]
public decimal Tax { get; set; }
[ImporterHeader(Name = "税额合计")]
public decimal TaxAmt { get; set; }
[ImporterHeader(Name = "价税合计")]
public decimal TotalAmt { get; set; }
[ImporterHeader(Name = "版本号", IsIgnore = false)]
public string Version { get; set; }
}
}

55
src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/HQExtend/HQKBSettleExtendVersion.cs

@ -0,0 +1,55 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Win.Sfs.Shared.DomainBase;
namespace Win.Sfs.SettleAccount.Entities.HQExtend
{
public class HQKBSettleExtendVersion : FullAuditedAggregateRootBase<Guid>, ISettleAccountEntityBase
{
public HQKBSettleExtendVersion()
{ }
public string Year { get; set; }
/// <summary>
/// 期间
/// </summary>
public string Period { get; set; }
/// <summary>
/// 版本号
/// </summary>
public string Version { get; set; }
/// <summary>
/// 工厂
/// </summary>
public string Factory { set; get; }
/// <summary>
/// 客户号
/// </summary>
public string CustomerCode { private set; get; }
public HQKBSettleExtendVersion(
Guid id,
Guid branchId,
string year, string period, string version, string customerCode, string factory) : base(id)
{
BranchId = branchId;
Year = year;
Period = period;
Version = version;
CustomerCode = customerCode;
Factory = factory;
}
}
}
Loading…
Cancel
Save