You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
304 lines
13 KiB
304 lines
13 KiB
using AutoMapper;
|
|
using DocumentFormat.OpenXml.Bibliography;
|
|
using DocumentFormat.OpenXml.Drawing.Charts;
|
|
using DocumentFormat.OpenXml.Office2010.Excel;
|
|
using EFCore.BulkExtensions;
|
|
using Magicodes.ExporterAndImporter.Core;
|
|
using Magicodes.ExporterAndImporter.Csv;
|
|
using Magicodes.ExporterAndImporter.Excel;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using SettleAccount.Bases;
|
|
using SettleAccount.Domain.BQ;
|
|
using SettleAccount.Job.Services;
|
|
using Shouldly;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel.DataAnnotations;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using TaskJob.EventArgs;
|
|
using TaskJob.Services;
|
|
using Volo.Abp;
|
|
using Volo.Abp.Application.Dtos;
|
|
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.BQ;
|
|
using Win.Sfs.SettleAccount.Entities.BQ.Dtos;
|
|
using Win.Sfs.SettleAccount.Entities.BQ.Syncs;
|
|
using Win.Sfs.SettleAccount.Entities.BQ.Vmi;
|
|
using Win.Sfs.SettleAccount.Entities.TaskJobs;
|
|
using Win.Sfs.SettleAccount.ExcelImporter;
|
|
using Win.Sfs.SettleAccount.ExportReports;
|
|
using Win.Sfs.Shared.RepositoryBase;
|
|
using static ICSharpCode.SharpZipLib.Zip.ExtendedUnixData;
|
|
|
|
namespace Win.Sfs.SettleAccount.Bases
|
|
{
|
|
public class PD_SERVICE<TEntity, TEntityDto, TEntityDetail, TEntityDetailDto, TRequestMainInput, TRequestDetailInput, TEntityDetailExportDto> : BASE_SERVICE
|
|
where TEntity : PD_BASE_MAIN
|
|
where TEntityDetail : PD_BASE
|
|
where TEntityDto : class, IEntityDto<Guid>, new()
|
|
where TEntityDetailDto : class, IEntityDto<Guid>, new()
|
|
where TRequestMainInput : RequestInputBase
|
|
where TRequestDetailInput : RequestInputBase
|
|
where TEntityDetailExportDto : class, new()
|
|
{
|
|
protected readonly VmiAppService _vimservice;
|
|
protected readonly INormalEfCoreRepository<TEntity, Guid> _repository;
|
|
protected readonly INormalEfCoreRepository<TEntityDetail, Guid> _detailRepository;
|
|
protected readonly INormalEfCoreRepository<BBAC_SEC_DETAIL, Guid> _bbacSecRepository;
|
|
protected readonly INormalEfCoreRepository<HBPO_SEC_DETAIL, Guid> _hbpoSecRepository;
|
|
protected readonly INormalEfCoreRepository<PUB_SEC_DETAIL, Guid> _pubSecRepository;
|
|
protected readonly INormalEfCoreRepository<INVOICE_GRP, Guid> _invRepository;
|
|
private readonly TaskJobService _service;
|
|
public PD_SERVICE(
|
|
|
|
INormalEfCoreRepository<BBAC_SEC_DETAIL, Guid> bbacSecRepository,
|
|
INormalEfCoreRepository<HBPO_SEC_DETAIL, Guid> hbpoSecRepository,
|
|
INormalEfCoreRepository<PUB_SEC_DETAIL, Guid> pubSecRepository,
|
|
IExcelImportAppService excelImportService,
|
|
ISnowflakeIdGenerator snowflakeIdGenerator,
|
|
ICommonManager commonManager,
|
|
INormalEfCoreRepository<TEntity, Guid> repository,
|
|
VmiAppService vimservice,
|
|
INormalEfCoreRepository<TEntityDetail, Guid> detailRepository,
|
|
TaskJobService service,
|
|
INormalEfCoreRepository<INVOICE_GRP, Guid> invRepository
|
|
) : base(excelImportService, snowflakeIdGenerator, commonManager)
|
|
{
|
|
_service = service;
|
|
_vimservice = vimservice;
|
|
_repository = repository;
|
|
_detailRepository = detailRepository;
|
|
_bbacSecRepository = bbacSecRepository;
|
|
_pubSecRepository = pubSecRepository;
|
|
_hbpoSecRepository = hbpoSecRepository;
|
|
_invRepository = invRepository;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 查询明细
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
//[Route("detailquery")]
|
|
public virtual async Task<PagedResultDto<TEntityDetailDto>> DetailQueryAsync(TRequestDetailInput input)
|
|
{
|
|
|
|
var entitys = await _detailRepository.GetListByFilterAsync(input.Filters, input.Sorting, input.MaxResultCount, input.SkipCount).ConfigureAwait(false);
|
|
var totalCount = await _detailRepository.GetCountByFilterAsync(input.Filters).ConfigureAwait(false);
|
|
var dtos = ObjectMapper.Map<List<TEntityDetail>, List<TEntityDetailDto>>(entitys);
|
|
return new PagedResultDto<TEntityDetailDto>(totalCount, dtos);
|
|
|
|
}
|
|
/// <summary>
|
|
/// 导出
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
//[Route("export")]
|
|
public virtual async Task<string> ExportAsync(TRequestDetailInput input)
|
|
{
|
|
IExporter _csv = new CsvExporter();
|
|
IExporter _excel = new ExcelExporter();
|
|
var entities = await _detailRepository.GetListByFilterAsync(input.Filters, input.Sorting, int.MaxValue, 0, true).ConfigureAwait(false);
|
|
var dtoDetails = ObjectMapper.Map<List<TEntityDetail>, List<TEntityDetailExportDto>>(entities);
|
|
var classDisplayName = typeof(TEntityDetailExportDto).GetCustomAttribute<DisplayAttribute>()?.Name ?? typeof(TEntityDetailExportDto).Name;
|
|
string _fileName = $"{classDisplayName}_{Guid.NewGuid().ToString()}.xlsx";
|
|
byte[] result = null;
|
|
|
|
switch (input.FileType)
|
|
{
|
|
case 0:
|
|
result = await _csv.ExportAsByteArray(dtoDetails).ConfigureAwait(false);
|
|
break;
|
|
case 1:
|
|
result = await _excel.ExportAsByteArray(dtoDetails).ConfigureAwait(false);
|
|
break;
|
|
}
|
|
result.ShouldNotBeNull();
|
|
|
|
//保存导出文件到服务器存成二进制
|
|
await _excelImportService.SaveBlobAsync(
|
|
new SaveExcelImportInputDto
|
|
{
|
|
Name = _fileName,
|
|
Content = result
|
|
}
|
|
).ConfigureAwait(false);
|
|
return _fileName;
|
|
}
|
|
[HttpPost]
|
|
[UnitOfWork(false)]
|
|
public virtual async Task<string> ApprovalPassed(List<string> p_list)
|
|
{
|
|
var invlist = _repository.Where(p => p_list.Contains(p.BillNum)).ToList();
|
|
var states = invlist.Select(p => p.State).Distinct().ToList();
|
|
if (states.Count > 1)
|
|
{
|
|
throw new UserFriendlyException($"扣减单不是同一状态", "400");
|
|
}
|
|
var first = invlist.FirstOrDefault();//发票状态
|
|
if (first.State != SettleBillState.客户已收票)
|
|
{
|
|
throw new UserFriendlyException($"扣减单状态不是【客户已收票】状态", "400");
|
|
|
|
}
|
|
|
|
|
|
return await InvokePD(invlist,p_list, _service, false);
|
|
}
|
|
[HttpPost]
|
|
[UnitOfWork(false)]
|
|
public virtual async Task<string> RejectAsync(List<string> p_list)
|
|
{
|
|
var invlist = _repository.Where(p => p_list.Contains(p.BillNum)).ToList();
|
|
var states = invlist.Select(p => p.State).Distinct().ToList();
|
|
if (states.Count > 1)
|
|
{
|
|
throw new UserFriendlyException($"扣减单不是同一状态", "400");
|
|
}
|
|
var first = invlist.FirstOrDefault();//发票状态
|
|
if (first.State == SettleBillState.客户已收票)
|
|
{
|
|
//var _taskid = await _service.ExportEnqueueAsync($"{first.BillNum}待扣减删除任务", ExportExtentsion.Excel, DateTime.Now.ToString("yyyyMM"), string.Empty, CurrentUser, typeof(PendingDeductionService), customConditionList, (rs) =>
|
|
//{
|
|
//});
|
|
var pdList = _repository.Where(p => p_list.Contains(p.BillNum)).ToList();//扣减单内容
|
|
var pdDetailList = _detailRepository.Where(p => p_list.Contains(p.BillNum)).ToList();//扣减单内容
|
|
var pdinvList = _invRepository.Where(p => p_list.Contains(p.InvbillNum)).ToList();
|
|
if (pdList.Count > 0)
|
|
{
|
|
await _repository.DbContext.BulkDeleteAsync(pdList);//删除待扣减
|
|
await _repository.DbContext.BulkDeleteAsync(pdDetailList);
|
|
foreach (var itm in pdinvList)
|
|
{
|
|
itm.State = SettleBillState.财务已审核;
|
|
}
|
|
await _repository.DbContext.BulkUpdateAsync(pdinvList);//更新发票为关联发票
|
|
}
|
|
return "OK";
|
|
}
|
|
else
|
|
{
|
|
if (first.State != SettleBillState.已扣减)
|
|
{
|
|
throw new UserFriendlyException($"扣减单状态不是【已扣减】状态", "400");
|
|
}
|
|
return await InvokePD(invlist,p_list, _service,true);
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// 调用扣减
|
|
/// </summary>
|
|
/// <param name="p_list"></param>
|
|
/// <param name="p_service"></param>
|
|
/// <param name="isback"></param>
|
|
/// <returns></returns>
|
|
/// <exception cref="UserFriendlyException"></exception>
|
|
[UnitOfWork(false)]
|
|
protected async Task<string> InvokePD<T>(List<T> p_invs,List<string> p_list, TaskJobService p_service, bool isback=false) where T:PD_BASE_MAIN
|
|
{
|
|
var invlist = p_invs;
|
|
// var invlist=_repository.Where(p=>p_list.Contains(p.BillNum)).ToList();
|
|
var states= invlist.Select(p => p.State).Distinct().ToList();
|
|
if (states.Count > 1)
|
|
{
|
|
throw new UserFriendlyException($"发票不是同一状态", "400");
|
|
}
|
|
var first = invlist.FirstOrDefault();//发票状态
|
|
|
|
if(first.State != SettleBillState.客户已收票 && first.State != SettleBillState.已扣减)
|
|
{
|
|
throw new UserFriendlyException($"当前发票状态不是【客户已收票】或【已扣减状态】不能进行出库扣减或撤销扣减操作", "400");
|
|
}
|
|
|
|
|
|
|
|
var detailist = _detailRepository.Where(p => p_list.Contains(p.BillNum)).ToList();
|
|
var first1=detailist.FirstOrDefault();
|
|
List<CustomCondition> customConditionList = new List<CustomCondition>();
|
|
customConditionList.Add(new CustomCondition() { Name = "BillNumList", Value = string.Join(",", p_list) });
|
|
customConditionList.Add(new CustomCondition() { Name = "Type", Value =first1.BusinessType.ToString() });
|
|
if (isback == false)
|
|
{
|
|
customConditionList.Add(new CustomCondition() { Name = "IsOut", Value = "out" });
|
|
}
|
|
else
|
|
{
|
|
customConditionList.Add(new CustomCondition() { Name = "IsOut", Value = "in" });
|
|
}
|
|
var ls = _repository.Where(p => p_list.Contains(p.BillNum)).ToList();
|
|
var lst=new List<TEntity>();
|
|
if (isback == false)
|
|
{
|
|
lst = ls.Where(p => (p.State == SettleBillState.已提交扣减 || p.State == SettleBillState.已扣减)).ToList();
|
|
}
|
|
else
|
|
{
|
|
lst = ls.Where(p => (p.State == SettleBillState.已提交撤销扣减|| p.State == SettleBillState.客户已收票)).ToList();
|
|
}
|
|
if (lst.Count() > 0)
|
|
{
|
|
throw new UserFriendlyException("当前状态是已提交状态,不能重复已提交", "400");
|
|
}
|
|
foreach (var item in ls)
|
|
{
|
|
if (isback == false)
|
|
{
|
|
item.State = SettleBillState.已提交扣减;
|
|
}
|
|
else
|
|
{
|
|
item.State = SettleBillState.已提交撤销扣减;
|
|
}
|
|
}
|
|
await _repository.DbContext.BulkUpdateAsync(ls);
|
|
var _taskid = await p_service.ExportEnqueueAsync($"{first1.BusinessType.ToString()}待扣减任务", ExportExtentsion.Excel, DateTime.Now.ToString("yyyyMM"), string.Empty, CurrentUser, typeof(PendingDeductionService), customConditionList, (rs) =>
|
|
{
|
|
});
|
|
|
|
return _taskid;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 查询主表
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
//[Route("mainquery")]
|
|
public virtual async Task<PagedResultDto<TEntityDto>> MainQueryAsync(TRequestMainInput input)
|
|
{
|
|
var entitys = await _repository.GetListByFilterAsync(input.Filters, input.Sorting, input.MaxResultCount, input.SkipCount).ConfigureAwait(false);
|
|
var totalCount = await _repository.GetCountByFilterAsync(input.Filters).ConfigureAwait(false);
|
|
var dtos = ObjectMapper.Map<List<TEntity>, List<TEntityDto>>(entitys);
|
|
return new PagedResultDto<TEntityDto>(totalCount, dtos);
|
|
}
|
|
|
|
protected virtual async Task<TEntity> GetMainAsync([FromBody] string billNum)
|
|
{
|
|
return await _repository.Where(p => p.InvGroupNum == billNum).FirstOrDefaultAsync().ConfigureAwait(false);
|
|
}
|
|
|
|
protected virtual async Task<List<TEntityDetail>> GetDetailAsync([FromBody] string billNum)
|
|
{
|
|
return await _detailRepository.Where(p => p.InvGroupNum == billNum).ToListAsync().ConfigureAwait(false);
|
|
}
|
|
|
|
}
|
|
}
|
|
|