Administrator
3 years ago
8 changed files with 1551 additions and 43 deletions
@ -0,0 +1,606 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Threading.Tasks; |
||||
|
using Microsoft.AspNetCore.Authorization; |
||||
|
using Microsoft.AspNetCore.Http; |
||||
|
using Microsoft.AspNetCore.Mvc; |
||||
|
using Microsoft.Extensions.Caching.Distributed; |
||||
|
using AutoMapper; |
||||
|
using System.Linq; |
||||
|
using System.Text; |
||||
|
using Volo.Abp.Guids; |
||||
|
using Volo.Abp.Application.Services; |
||||
|
using Volo.Abp.Caching; |
||||
|
|
||||
|
using Volo.Abp.ObjectMapping; |
||||
|
using Win.Sfs.SettleAccount.ExcelImporter; |
||||
|
using Win.Sfs.Shared.CacheBase; |
||||
|
using Win.Utils; |
||||
|
using Volo.Abp.Application.Dtos; |
||||
|
using Win.Sfs.BaseData.ImportExcelCommon; |
||||
|
using Volo.Abp.Domain.Repositories; |
||||
|
using EFCore.BulkExtensions; |
||||
|
using System.IO; |
||||
|
using Microsoft.EntityFrameworkCore; |
||||
|
using Win.Sfs.SettleAccount.Entities.SettleAccountVersion; |
||||
|
using Win.Sfs.SettleAccount.FISes; |
||||
|
using Win.Sfs.Shared.Enums.SettleAccount; |
||||
|
using Win.Sfs.Shared.Filter; |
||||
|
using Shouldly; |
||||
|
using Magicodes.ExporterAndImporter.Csv; |
||||
|
using Magicodes.ExporterAndImporter.Core; |
||||
|
using Magicodes.ExporterAndImporter.Excel; |
||||
|
using System.Data.Common; |
||||
|
using Volo.Abp.Uow; |
||||
|
using Volo.Abp; |
||||
|
using Win.Abp.Snowflakes; |
||||
|
using Win.Sfs.SettleAccount.CommonManagers; |
||||
|
using Win.Sfs.SettleAccount.ExportReports; |
||||
|
using Win.Sfs.SettleAccount.Constant; |
||||
|
using Win.Sfs.SettleAccount.MaterialRelationships; |
||||
|
using Win.Sfs.SettleAccount.Entities.TaskJobs; |
||||
|
using Magicodes.ExporterAndImporter.Core.Models; |
||||
|
|
||||
|
using TaskJob.Services; |
||||
|
using TaskJob.EventArgs; |
||||
|
using Win.Sfs.SettleAccount.Entities.WMS; |
||||
|
using Win.Sfs.SettleAccount.Entities.Wms; |
||||
|
using Win.Sfs.SettleAccount.Repository; |
||||
|
using WY.NewJit.Extends.PaiGe.WMS; |
||||
|
using Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report; |
||||
|
|
||||
|
namespace Win.Sfs.SettleAccount.Entities.SettleAccounts |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// 红旗H平台准时化-出库
|
||||
|
/// </summary>
|
||||
|
|
||||
|
//[AllowAnonymous]
|
||||
|
[Authorize(SettleAccountPermissions.WMSHQ.Default)] |
||||
|
[Route("api/settleaccount/WMSCusomerKanbanoutput")] |
||||
|
public class WMSCusomerKanbanAppService : |
||||
|
SettleAccountApplicationBase<WmsCustomerKanbanOutPutDetial> |
||||
|
{ |
||||
|
|
||||
|
private readonly ISettleAccountBranchEfCoreRepository<WmsCustomerKanbanOutPutDetial, Guid> _wmsRepository; |
||||
|
private readonly ISettleAccountBranchEfCoreRepository<WmsCustomerKanbanOutPut, Guid> _wmsVersionRepository; |
||||
|
private readonly WMSEfCoreRepository<WmsCustomerKanbanOutPutDetial> _wmsefRespository; |
||||
|
|
||||
|
private readonly WMSEfCoreRepository<TB_BILL> _wmstbRespository; |
||||
|
private readonly ISettleAccountBranchEfCoreRepository<TaskJob, Guid> _job; |
||||
|
private readonly IExcelImportAppService _excelImportService; |
||||
|
|
||||
|
|
||||
|
private readonly TaskJobService _service; |
||||
|
/// <summary>
|
||||
|
///
|
||||
|
/// </summary>
|
||||
|
/// <param name="wmsRepository"></param>
|
||||
|
/// <param name="job"></param>
|
||||
|
/// <param name="wmsVersionRepository"></param>
|
||||
|
/// <param name="wmsefRespository"></param>
|
||||
|
/// <param name="wmstbRespository"></param>
|
||||
|
public WMSCusomerKanbanAppService( |
||||
|
|
||||
|
|
||||
|
IExcelImportAppService excelImportService, |
||||
|
|
||||
|
ISettleAccountBranchEfCoreRepository<WmsCustomerKanbanOutPutDetial, Guid> wmsRepository, |
||||
|
ISettleAccountBranchEfCoreRepository<TaskJob, Guid> job, |
||||
|
ISettleAccountBranchEfCoreRepository<WmsCustomerKanbanOutPut, Guid> wmsVersionRepository, |
||||
|
WMSEfCoreRepository<WmsCustomerKanbanOutPutDetial> wmsefRespository, |
||||
|
WMSEfCoreRepository<TB_BILL> wmstbRespository, |
||||
|
IDistributedCache<WmsCustomerKanbanOutPutDetial> cache, |
||||
|
ISnowflakeIdGenerator snowflakeIdGenerator, |
||||
|
ICommonManager commonManager |
||||
|
) : base(cache, excelImportService, snowflakeIdGenerator, commonManager) |
||||
|
{ |
||||
|
_job = job; |
||||
|
_wmstbRespository = wmstbRespository; |
||||
|
_wmsRepository = wmsRepository; |
||||
|
_wmsVersionRepository = wmsVersionRepository; |
||||
|
_wmsefRespository = wmsefRespository; |
||||
|
_excelImportService = excelImportService; |
||||
|
} |
||||
|
|
||||
|
private async Task<long> GetCountAsync(WmsKanbanOutPutDetialRequestDto input) |
||||
|
{ |
||||
|
return await _wmsRepository.GetCountByFilterAsync(GuidGenerator.Create(), input.Filters); |
||||
|
} |
||||
|
|
||||
|
private async Task<long> GetCountAsync(WmsKanbanOutPutRequestDto input) |
||||
|
{ |
||||
|
return await _wmsVersionRepository.GetCountByFilterAsync(GuidGenerator.Create(), input.Filters); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 准时化出库主表
|
||||
|
/// </summary>
|
||||
|
/// <param name="input"></param>
|
||||
|
/// <returns></returns>
|
||||
|
[HttpPost] |
||||
|
[Route("WmsCustomerKanbanList")] |
||||
|
//[Authorize(SettleAccountPermissions.SettleAccounts.Default)]
|
||||
|
virtual public async Task<PagedResultDto<WmsCustomerKanbanOutPut>> GetListAsync( WmsKanbanOutPutRequestDto input) |
||||
|
{ |
||||
|
|
||||
|
var entities = await _wmsVersionRepository.GetListByFilterAsync(GuidGenerator.Create(), input.Filters, input.Sorting, input.MaxResultCount, |
||||
|
input.SkipCount, true); |
||||
|
|
||||
|
var totalCount = await GetCountAsync(input); |
||||
|
|
||||
|
|
||||
|
return new PagedResultDto<WmsCustomerKanbanOutPut>(totalCount, entities); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 准时化出库明细
|
||||
|
/// </summary>
|
||||
|
/// <param name="input"></param>
|
||||
|
/// <returns></returns>
|
||||
|
[HttpPost] |
||||
|
[Route("WmsCustomerKanbanDetailList")] |
||||
|
//[Authorize(SettleAccountPermissions.SettleAccounts.Default)]
|
||||
|
virtual public async Task<PagedResultDto<WmsCustomerKanbanOutPutDetial>> GetListAsync(WmsKanbanOutPutDetialRequestDto input) |
||||
|
{ |
||||
|
//不用传version 单号能保证唯一
|
||||
|
input.Filters.Add(new FilterCondition() { Action = EnumFilterAction.Equal, Column = "BillNum", Logic = EnumFilterLogic.And, Value = input.BillNum }); |
||||
|
var entities = await _wmsRepository.GetListByFilterAsync(GuidGenerator.Create(), input.Filters, input.Sorting, input.MaxResultCount, |
||||
|
input.SkipCount, true); |
||||
|
|
||||
|
var totalCount = await GetCountAsync(input); |
||||
|
return new PagedResultDto<WmsCustomerKanbanOutPutDetial>(totalCount, entities); |
||||
|
} |
||||
|
/// <summary>
|
||||
|
/// 任务明细标记已确认
|
||||
|
/// </summary>
|
||||
|
/// <param name="files">上传的文件(前端已经限制只能上传一个附件)</param>
|
||||
|
/// <returns></returns>
|
||||
|
[HttpPost] |
||||
|
[Route("WmsCustomerKanbanOutPutAudit")] |
||||
|
[DisableRequestSizeLimit] |
||||
|
|
||||
|
public async Task<bool> WmsHQHKanbanAudit(List<Guid> ids) |
||||
|
{ |
||||
|
var _joblist =await _job.Where(p => ids.Contains(p.Id)).ToListAsync(); |
||||
|
foreach (var itm in _joblist) |
||||
|
{ |
||||
|
itm.FileName = "已确认"; |
||||
|
await _job.UpdateAsync(itm); |
||||
|
} |
||||
|
|
||||
|
return true; |
||||
|
} |
||||
|
/// <summary>
|
||||
|
///更新备注
|
||||
|
/// </summary>
|
||||
|
/// <param name="input"></param>
|
||||
|
/// <returns></returns>
|
||||
|
[HttpGet] |
||||
|
[Route("UpdateRemark")] |
||||
|
|
||||
|
public async Task<bool> UpdateRemark(Guid id, string remark) |
||||
|
{ |
||||
|
var entity = _wmsVersionRepository.FirstOrDefault(p => p.Id == id); |
||||
|
if (entity != null) |
||||
|
{ |
||||
|
entity.Remark = remark; |
||||
|
await _wmsVersionRepository.UpdateAsync(entity); |
||||
|
|
||||
|
} |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
|
||||
|
///// <summary>
|
||||
|
///// 选择任务,生成出库单,只包含已确认的单据
|
||||
|
///// </summary>
|
||||
|
///// <param name="ids"></param>
|
||||
|
///// <param name="version"></param>
|
||||
|
///// <returns></returns>
|
||||
|
//[HttpPost]
|
||||
|
//[Route("WmsWithOutKanbanOutPut")]
|
||||
|
//public async Task<string> WmsWithOutKanbanOutPut(WmsJitRequestDto input)
|
||||
|
//{
|
||||
|
// var _billNum = "KA" + DateTime.Now.ToString("yyyyMMddhhmmss");
|
||||
|
|
||||
|
// var _joblist = _job.Where(p => input.Guids.Contains(p.Id) && p.FileName == "已确认").ToList();
|
||||
|
// if (_joblist.Count() > 0)
|
||||
|
// {
|
||||
|
// var fileList = _joblist.Select(p => p.RealDownFileName).ToList();
|
||||
|
// List<WmsCustomerKanbanOutPutDetial> _lst = new List<WmsCustomerKanbanOutPutDetial>();
|
||||
|
// foreach (var filename in fileList)
|
||||
|
// {
|
||||
|
// string fileSavePath = Environment.CurrentDirectory + @"\wwwroot\files\host\my-file-container\" + filename;
|
||||
|
// ExcelHelper _excelHelper = new ExcelHelper(fileSavePath);
|
||||
|
// var _list = _excelHelper.ExcelToList<SettleKBWithOutCode>();
|
||||
|
// foreach (var itm in _list)
|
||||
|
// {
|
||||
|
|
||||
|
// var _entity= new WmsCustomerKanbanOutPutDetial(GuidGenerator.Create(), string.Empty, string.Empty, itm.MaterialCode, itm.MaterialDesc
|
||||
|
// , itm.SapMaterialGroup, string.Empty, string.Empty, 0, string.Empty, string.Empty, itm.Version, itm.SapMaterialCode,
|
||||
|
// _billNum, Guid.Empty, string.Empty, itm.InvoiceQty,itm.
|
||||
|
// );
|
||||
|
|
||||
|
// _lst.Add(_entity);
|
||||
|
// }
|
||||
|
|
||||
|
// }
|
||||
|
|
||||
|
// var outPutDetail = await _wmsRepository.Where(p => p.Version == input.Version && p.Kanban==string.Empty).ToListAsync();
|
||||
|
|
||||
|
|
||||
|
// await _wmsRepository.GetDbContext().BulkInsertAsync(_lst, new BulkConfig() { BulkCopyTimeout = 0, BatchSize = 10000 });
|
||||
|
// int _count = _wmsVersionRepository.Count(p => p.Version == input.Version && p.BillNum == _billNum);
|
||||
|
// if (_count == 0)
|
||||
|
// {
|
||||
|
// var _version = new WmsCustomerKanbanOutPut(GuidGenerator.Create(), input.Version, _billNum, CurrentUser.Email);
|
||||
|
|
||||
|
// await _wmsVersionRepository.InsertAsync(_version, true);
|
||||
|
// }
|
||||
|
|
||||
|
// foreach (var job in _joblist)
|
||||
|
// {
|
||||
|
// job.FileName = _billNum;
|
||||
|
// await _job.UpdateAsync(job);
|
||||
|
// }
|
||||
|
// }
|
||||
|
|
||||
|
// return ApplicationConsts.SuccessStr; ;
|
||||
|
//}
|
||||
|
|
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 选择任务,生成出库单,只包含已确认的单据
|
||||
|
/// </summary>
|
||||
|
/// <param name="ids"></param>
|
||||
|
/// <param name="version"></param>
|
||||
|
/// <returns></returns>
|
||||
|
[HttpPost] |
||||
|
[Route("WmsCustomerKanbanOutPut")] |
||||
|
public async Task<string> WmsCustomerKanbanOutPut(WmsJitRequestDto input) |
||||
|
{ |
||||
|
var _billNum = "CKB" + DateTime.Now.ToString("yyyyMMddhhmmss"); |
||||
|
|
||||
|
var _joblist = _job.Where(p => input.Guids.Contains(p.Id) && p.FileName == "已确认").ToList(); |
||||
|
if (_joblist.Count() > 0) |
||||
|
{ |
||||
|
var fileList = _joblist.Select(p => p.RealDownFileName).ToList(); |
||||
|
List<WmsCustomerKanbanOutPutDetial> _lst = new List<WmsCustomerKanbanOutPutDetial>(); |
||||
|
foreach (var filename in fileList) |
||||
|
{ |
||||
|
string fileSavePath = Environment.CurrentDirectory + @"\wwwroot\files\host\my-file-container\" + filename; |
||||
|
ExcelHelper _excelHelper = new ExcelHelper(fileSavePath); |
||||
|
var _list = _excelHelper.ExcelToList<WmsCustomerKanbanOutPutDetial>(); |
||||
|
foreach (var itm in _list) |
||||
|
{ |
||||
|
itm.SetData(GuidGenerator.Create(),string.Empty,!string.IsNullOrEmpty(itm.WmsBillNum)? itm.WmsBillNum:string.Empty,input.Version,GuidGenerator.Create(),itm.CustomerCode); |
||||
|
} |
||||
|
_lst.AddRange(_list.ToArray()); |
||||
|
} |
||||
|
|
||||
|
var outPutDetail = await _wmsRepository.Where(p => p.Version == input.Version && p.State != 4 ).ToListAsync(); |
||||
|
|
||||
|
var error = from itm1 in outPutDetail |
||||
|
join itm2 in _lst on |
||||
|
new { itm1.MaterialCode, itm1.Kanban } |
||||
|
equals |
||||
|
new { itm2.MaterialCode, itm2.Kanban } |
||||
|
select itm1; |
||||
|
var errList = error.GroupBy(p => new { p.BillNum }).Select(p => new { BillNum = p.Key.BillNum, Number = p.Sum(itm => itm.Qty) }); |
||||
|
if (errList.Count() == 0) |
||||
|
{ |
||||
|
|
||||
|
var query = from itm1 in _lst |
||||
|
join itm2 in outPutDetail on |
||||
|
new { itm1.MaterialCode, itm1.Kanban } |
||||
|
equals |
||||
|
new { itm2.MaterialCode, itm2.Kanban } into temp1 |
||||
|
from tm1 in temp1.DefaultIfEmpty() |
||||
|
where tm1 == null |
||||
|
select itm1; |
||||
|
var _wmslst = query.ToList(); |
||||
|
foreach (var itm in _wmslst) |
||||
|
{ |
||||
|
itm.BillNum = _billNum; |
||||
|
} |
||||
|
await _wmsRepository.GetDbContext().BulkInsertAsync(_wmslst, new BulkConfig() { BulkCopyTimeout = 0, BatchSize = 10000 }); |
||||
|
int _count = _wmsVersionRepository.Count(p => p.Version == input.Version && p.BillNum == _billNum); |
||||
|
if (_count == 0) |
||||
|
{ |
||||
|
var _version = new WmsCustomerKanbanOutPut(GuidGenerator.Create(), input.Version, _billNum, CurrentUser.Email,""); |
||||
|
_version.Remark = !string.IsNullOrEmpty(_joblist.FirstOrDefault().Remark) ? _joblist.FirstOrDefault().Remark : string.Empty; |
||||
|
await _wmsVersionRepository.InsertAsync(_version, true); |
||||
|
} |
||||
|
|
||||
|
foreach (var job in _joblist) |
||||
|
{ |
||||
|
job.FileName = _billNum; |
||||
|
await _job.UpdateAsync(job); |
||||
|
} |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
StringBuilder _buffer = new StringBuilder(); |
||||
|
foreach (var itm in errList) |
||||
|
{ |
||||
|
_buffer.AppendFormat("出库单号:{0}重复记录数:{1}条", itm.BillNum, itm.Number); |
||||
|
} |
||||
|
var _errinfo = _buffer.ToString(); |
||||
|
|
||||
|
foreach (var job in _joblist) |
||||
|
{ |
||||
|
job.FileName = _errinfo; |
||||
|
await _job.UpdateAsync(job); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
_billNum = string.Empty; |
||||
|
} |
||||
|
return ApplicationConsts.SuccessStr; ; |
||||
|
} |
||||
|
/// <summary>
|
||||
|
/// 出库界面功能,核准出库功能
|
||||
|
/// </summary>
|
||||
|
/// <param name="version"></param>
|
||||
|
/// <param name="p_list"></param>
|
||||
|
/// <returns></returns>
|
||||
|
[HttpPost] |
||||
|
[Route("WmsCustomerKanbanOutPut-Pass")] |
||||
|
[UnitOfWork(false)] |
||||
|
public async Task<bool> WmsCustomerKanbanOutPutPass(WmsJitRequestDto input) |
||||
|
{ |
||||
|
var sql = "DECLARE @return_value int\n" + |
||||
|
"EXEC @return_value = [dbo].[p_wms_output]\n" + |
||||
|
" @billnum = N'{0}',\n" + |
||||
|
" @type = 23,\n" + |
||||
|
" @date = N'{1}'\n" + |
||||
|
"SELECT 'Return Value' = @return_value"; |
||||
|
await _wmsRepository.GetDbContext().Database.ExecuteSqlRawAsync( |
||||
|
string.Format(sql, input.BillNum, input.AccountDate.ToShortDateString()) |
||||
|
); |
||||
|
|
||||
|
|
||||
|
|
||||
|
return true; |
||||
|
|
||||
|
} |
||||
|
/// <summary>
|
||||
|
///出库界面功能, 撤销核准出库
|
||||
|
/// </summary>
|
||||
|
/// <param name="ids"></param>
|
||||
|
/// <param name="version"></param>
|
||||
|
/// <returns></returns>
|
||||
|
[HttpPost] |
||||
|
[Route("WmsCustomerKanbanOutPut-Cancel")] |
||||
|
[UnitOfWork(false)] |
||||
|
public async Task<bool> WmsCustomerKanbanOutPutCancel(WmsJitRequestDto input) |
||||
|
{ |
||||
|
if (input.Guids != null && input.Guids.Count() > 0) |
||||
|
{ |
||||
|
List<string> _ls = new List<string>(); |
||||
|
foreach (var itm in input.Guids) |
||||
|
{ |
||||
|
_ls.Add(string.Format("{0}", itm)); |
||||
|
} |
||||
|
|
||||
|
string str = string.Join(",", _ls.ToArray()); |
||||
|
|
||||
|
var sql = "DECLARE @return_value int\n" + |
||||
|
"EXEC @return_value = [dbo].[p_wms_output_cancel]\n" + |
||||
|
" @Guids ='{0}', \n" + |
||||
|
" @billnum = N'{1}',\n" + |
||||
|
" @type = 23,\n" + |
||||
|
" @accountdate = N'{2}'\n" + |
||||
|
"SELECT 'Return Value' = @return_value"; |
||||
|
|
||||
|
sql = string.Format(sql, str, input.BillNum, input.AccountDate.ToShortDateString()); |
||||
|
|
||||
|
await _wmsRepository.GetDbContext().Database.ExecuteSqlRawAsync( |
||||
|
sql |
||||
|
); |
||||
|
|
||||
|
} |
||||
|
|
||||
|
return true; |
||||
|
} |
||||
|
/// <summary>
|
||||
|
/// 出库界面功能删除
|
||||
|
/// </summary>
|
||||
|
/// <param name="version"></param>
|
||||
|
/// <param name="p_list"></param>
|
||||
|
/// <returns></returns>
|
||||
|
[HttpPost] |
||||
|
[Route("WmsOutPutDelete")] |
||||
|
[UnitOfWork(false)] |
||||
|
public async Task<bool> WmsOutPutDelete(WmsJitRequestDto input) |
||||
|
{ |
||||
|
var count = _wmsRepository.Count(p => p.BillNum == input.BillNum && p.State != 0); |
||||
|
|
||||
|
if (count > 0) |
||||
|
{ |
||||
|
return false; |
||||
|
} |
||||
|
var sql = "DECLARE @return_value int\n" + |
||||
|
"EXEC @return_value = [dbo].[p_wms_output_cancel_all]\n" + |
||||
|
" @billnum = N'{0}',\n" + |
||||
|
" @type = 23\n" + |
||||
|
"SELECT 'Return Value' = @return_value"; |
||||
|
await _wmsRepository.GetDbContext().Database.ExecuteSqlRawAsync( |
||||
|
string.Format(sql, input.BillNum) |
||||
|
); |
||||
|
|
||||
|
|
||||
|
|
||||
|
return true; |
||||
|
} |
||||
|
[HttpPost] |
||||
|
[Route("ExcelImport")] |
||||
|
[DisableRequestSizeLimit] |
||||
|
//[Authorize(SettleAccountPermissions.SettleAccounts.Default)]
|
||||
|
public async Task<string> ExcelImport([FromForm] IFormFileCollection files, string version,string customerCode) |
||||
|
{ |
||||
|
var _billNum = "CKB(" +customerCode+")"+ DateTime.Now.ToString("yyyyMMddhhmmss"); |
||||
|
var checkList = new List<ErrorExportDto>(); |
||||
|
ExportImporter _exportImporter = new ExportImporter(); |
||||
|
var result = await _exportImporter.ExtendExcelOfSheetOneImport<WmsCustomerKanbanOutPutDetial>(files, _excelImportService); |
||||
|
|
||||
|
//检验1:导入模板中的第一页签数据不能为空
|
||||
|
if (result == null || result.Count() == 0) |
||||
|
{ |
||||
|
checkList.Add(new ErrorExportDto(version, "红旗批量出库单导入", string.Empty, string.Empty, string.Empty, string.Empty, "导入模板中第一页签没有数据,请检查!", string.Empty)); |
||||
|
} |
||||
|
if (checkList.Count > 0) |
||||
|
{ |
||||
|
return await ExportErrorReportAsync(checkList); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
var filteResult = result.Where(p =>!string.IsNullOrEmpty(p.Kanban));//过滤掉看板号为空的数据
|
||||
|
|
||||
|
//检验2:导入模板中的结算数据是否为0
|
||||
|
foreach (var itm in filteResult) |
||||
|
{ |
||||
|
if (itm.Qty == 0) |
||||
|
{ |
||||
|
checkList.Add(new ErrorExportDto(version, "红旗批量出库单导入", string.Empty, string.Empty, string.Empty, string.Empty, string.Format("导入模板中看板号{0}的结算数量为0,影响出库请检查!", itm.Kanban), string.Empty)); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
|
||||
|
List<WmsCustomerKanbanOutPutDetial> _lst = new List<WmsCustomerKanbanOutPutDetial>(); |
||||
|
var _lsCopy = new List<WmsCustomerKanbanOutPutDetial>(); |
||||
|
foreach (var itm in filteResult) |
||||
|
{ |
||||
|
WmsCustomerKanbanOutPutDetial _detail = new WmsCustomerKanbanOutPutDetial( |
||||
|
GuidGenerator.Create(), |
||||
|
!string.IsNullOrEmpty(itm.WmsBillNum) ? itm.WmsBillNum : string.Empty, |
||||
|
itm.Kanban, |
||||
|
itm.MaterialCode, |
||||
|
itm.MaterialDesc, |
||||
|
itm.MaterialGroup, |
||||
|
string.Empty, |
||||
|
string.Empty, |
||||
|
0, |
||||
|
!string.IsNullOrEmpty(itm.Extend1)?itm.Extend1: string.Empty, |
||||
|
!string.IsNullOrEmpty(itm.Extend2) ? itm.Extend2 : string.Empty, |
||||
|
version, |
||||
|
itm.MaterialCode, |
||||
|
itm.BillNum, |
||||
|
GuidGenerator.Create() |
||||
|
, string.Empty |
||||
|
,itm.Qty |
||||
|
|
||||
|
,itm.Price |
||||
|
,itm.Amt |
||||
|
,itm.CustomerCode |
||||
|
); |
||||
|
_lsCopy.Add(_detail); |
||||
|
} |
||||
|
_lst.AddRange(_lsCopy.ToArray()); |
||||
|
|
||||
|
//检验3:导入模板中看板号+物料号,不能重复
|
||||
|
var _isRepeatOfReportList = from arc in _lst |
||||
|
group arc by new { arc.Kanban, arc.MaterialCode, arc.Version } |
||||
|
into g |
||||
|
where g.Count() > 1 |
||||
|
select g; |
||||
|
foreach (var itm in _isRepeatOfReportList) |
||||
|
{ |
||||
|
checkList.Add(new ErrorExportDto(version, "红旗批量出库单", string.Empty, string.Empty, string.Empty, string.Empty, string.Format("导入模板中看板号{0}组合物料号{1}有重复,请检查!", itm.Key.Kanban, itm.Key.MaterialCode), string.Empty)); |
||||
|
} |
||||
|
if (checkList.Count > 0) |
||||
|
{ |
||||
|
return await ExportErrorReportAsync(checkList); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
|
||||
|
var outPutDetail = await _wmsRepository.Where(p => p.Version == version && p.State != 4 ).ToListAsync(); |
||||
|
|
||||
|
|
||||
|
var error = from itm1 in outPutDetail |
||||
|
join itm2 in _lst on |
||||
|
new { itm1.MaterialCode, itm1.Kanban } |
||||
|
equals |
||||
|
new { itm2.MaterialCode, itm2.Kanban} |
||||
|
select itm1; |
||||
|
var errList = error.GroupBy(p => new { p.BillNum }).Select(p => new { BillNum = p.Key.BillNum, Number = p.Count() }); |
||||
|
|
||||
|
|
||||
|
foreach (var itm in errList) |
||||
|
{ |
||||
|
checkList.Add(new ErrorExportDto() { Message = string.Format("出库单号:{0}重复记录数:{1}条", itm.BillNum, itm.Number) }); |
||||
|
} |
||||
|
if (checkList.Count > 0) |
||||
|
{ |
||||
|
|
||||
|
return await ExportErrorReportAsync(checkList); |
||||
|
} |
||||
|
|
||||
|
var query = from itm1 in _lst |
||||
|
join itm2 in outPutDetail on |
||||
|
new { itm1.MaterialCode, itm1.Kanban } |
||||
|
equals |
||||
|
new { itm2.MaterialCode, itm2.Kanban } into temp1 |
||||
|
from tm1 in temp1.DefaultIfEmpty() |
||||
|
where tm1 == null |
||||
|
select itm1; |
||||
|
var _wmslst = query.ToList(); |
||||
|
foreach (var itm in _wmslst) |
||||
|
{ |
||||
|
itm.BillNum = _billNum; |
||||
|
} |
||||
|
await _wmsRepository.GetDbContext().BulkInsertAsync(_wmslst, new BulkConfig() { BulkCopyTimeout = 0, BatchSize = 10000 }); |
||||
|
int _count = _wmsVersionRepository.Count(p => p.Version == version && p.BillNum == _billNum); |
||||
|
if (_count == 0) |
||||
|
{ |
||||
|
var _version = new WmsCustomerKanbanOutPut(GuidGenerator.Create(), version, _billNum, CurrentUser.Email,customerCode); |
||||
|
|
||||
|
await _wmsVersionRepository.InsertAsync(_version, true); |
||||
|
} |
||||
|
return ApplicationConsts.SuccessStr; |
||||
|
} |
||||
|
/// <summary>
|
||||
|
/// 导出
|
||||
|
/// </summary>
|
||||
|
/// <param name="input"></param>
|
||||
|
/// <returns></returns>
|
||||
|
[HttpPost] |
||||
|
[Route("Export")] |
||||
|
//[Authorize(SettleAccountPermissions.SettleAccounts.Default)]
|
||||
|
virtual public async Task<string> ExportAsync(WmsKanbanOutPutDetialRequestDto input) |
||||
|
{ |
||||
|
input.Filters.Add(new FilterCondition() { Action = EnumFilterAction.Equal, Column = "BillNum", Logic = EnumFilterLogic.And, Value = input.BillNum }); |
||||
|
var entities = await _wmsRepository.GetListByFilterAsync(GuidGenerator.Create(), input.Filters, input.Sorting, int.MaxValue, |
||||
|
0, true); |
||||
|
|
||||
|
IExporter _excel = new ExcelExporter(); |
||||
|
byte[] result = null; |
||||
|
|
||||
|
var _fileName = string.Format("自定义客户出库单_{0}.xlsx", Guid.NewGuid().ToString()); |
||||
|
result = await _excel.ExportAsByteArray(entities); |
||||
|
|
||||
|
|
||||
|
result.ShouldNotBeNull(); |
||||
|
|
||||
|
//保存导出文件到服务器存成二进制
|
||||
|
await _excelImportService.SaveBlobAsync( |
||||
|
new SaveExcelImportInputDto |
||||
|
{ |
||||
|
Name = _fileName, |
||||
|
Content = result |
||||
|
} |
||||
|
); |
||||
|
return _fileName; |
||||
|
|
||||
|
|
||||
|
|
||||
|
} |
||||
|
|
||||
|
|
||||
|
} |
||||
|
} |
Loading…
Reference in new issue