Administrator
3 years ago
4 changed files with 603 additions and 2 deletions
@ -0,0 +1,425 @@ |
|||
using EFCore.BulkExtensions; |
|||
using Microsoft.AspNetCore.Authorization; |
|||
using Microsoft.AspNetCore.Http; |
|||
using Microsoft.AspNetCore.Mvc; |
|||
using Microsoft.EntityFrameworkCore; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.Application.Dtos; |
|||
using Volo.Abp.Caching; |
|||
using Volo.Abp.Domain.Repositories; |
|||
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.TaskJobs; |
|||
using Win.Sfs.SettleAccount.Entities.Wms; |
|||
using Win.Sfs.SettleAccount.ExcelImporter; |
|||
using Win.Sfs.SettleAccount.ExportReports; |
|||
using Win.Sfs.SettleAccount.Repository; |
|||
using Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report; |
|||
using WY.NewJit.Extends.PaiGe.WMS; |
|||
|
|||
namespace Win.Sfs.SettleAccount.Entities.WMS |
|||
{ |
|||
/// <summary>
|
|||
/// wms出库-一汽轿车
|
|||
/// </summary>
|
|||
|
|||
[AllowAnonymous] |
|||
[Route("api/settleaccount/WmsHQCaroutput")] |
|||
public class WmsHQCarAppService : |
|||
SettleAccountApplicationBase<WmsHQCarOutPutDetial> |
|||
{ |
|||
private readonly ISettleAccountBranchEfCoreRepository<WmsHQCarOutPutDetial, Guid> _wmsRepository; |
|||
private readonly ISettleAccountBranchEfCoreRepository<WmsHQCarOutPut, Guid> _wmsVersionRepository; |
|||
private readonly WMSEfCoreRepository<WmsHQCarOutPutDetial> _wmsefRespository; |
|||
private readonly WmsDapperRepository _wmsDapper; |
|||
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 WmsHQCarAppService( |
|||
|
|||
ISettleAccountBranchEfCoreRepository<WmsHQCarOutPutDetial, Guid> wmsRepository, |
|||
ISettleAccountBranchEfCoreRepository<TaskJob, Guid> job, |
|||
ISettleAccountBranchEfCoreRepository<WmsHQCarOutPut, Guid> wmsVersionRepository, |
|||
WMSEfCoreRepository<WmsHQCarOutPutDetial> wmsefRespository, |
|||
WMSEfCoreRepository<TB_BILL> wmstbRespository, |
|||
IExcelImportAppService excelImportService, |
|||
IDistributedCache<WmsHQCarOutPutDetial> cache, |
|||
ISnowflakeIdGenerator snowflakeIdGenerator, |
|||
ICommonManager commonManager, |
|||
WmsDapperRepository wmsDapper |
|||
) : base(cache, excelImportService, snowflakeIdGenerator, commonManager) |
|||
{ |
|||
_excelImportService = excelImportService; |
|||
_job = job; |
|||
_wmstbRespository = wmstbRespository; |
|||
_wmsRepository = wmsRepository; |
|||
_wmsVersionRepository = wmsVersionRepository; |
|||
_wmsefRespository = wmsefRespository; |
|||
_wmsDapper = wmsDapper; |
|||
} |
|||
|
|||
private async Task<long> GetCountAsync(WmsSharePartOutPutDetialRequestDto input) |
|||
{ |
|||
return await _wmsRepository.GetCountByFilterAsync(GuidGenerator.Create(), input.Filters); |
|||
} |
|||
|
|||
private async Task<long> GetCountAsync(WmsSharePartOutPutRequestDto input) |
|||
{ |
|||
return await _wmsVersionRepository.GetCountByFilterAsync(GuidGenerator.Create(), input.Filters); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 准时化出库主表
|
|||
/// </summary>
|
|||
/// <param name="input"></param>
|
|||
/// <returns></returns>
|
|||
[HttpPost] |
|||
[Route("WmsSharePartList")] |
|||
//[Authorize(SettleAccountPermissions.SettleAccounts.Default)]
|
|||
virtual public async Task<PagedResultDto<WmsHQCarOutPut>> GetListAsync(WmsSharePartOutPutRequestDto 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<WmsHQCarOutPut>(totalCount, entities); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 准时化出库明细
|
|||
/// </summary>
|
|||
/// <param name="input"></param>
|
|||
/// <returns></returns>
|
|||
[HttpPost] |
|||
[Route("WmsSharePartDetailList")] |
|||
//[Authorize(SettleAccountPermissions.SettleAccounts.Default)]
|
|||
virtual public async Task<PagedResultDto<WmsHQCarOutPutDetial>> GetListAsync(WmsSharePartOutPutDetialRequestDto input) |
|||
{ |
|||
var entities = await _wmsRepository.GetListByFilterAsync(GuidGenerator.Create(), input.Filters, input.Sorting, input.MaxResultCount, |
|||
input.SkipCount, true); |
|||
|
|||
var totalCount = await GetCountAsync(input); |
|||
var stockList = _wmsDapper.GetSalesStock(); |
|||
|
|||
|
|||
|
|||
var query = from itm in entities |
|||
join itm1 in stockList on itm.MaterialCode equals itm1.SapCode |
|||
into temp1 |
|||
from tm1 in temp1.DefaultIfEmpty() |
|||
select new WmsHQCarOutPutDetial( |
|||
itm.Id, |
|||
itm.WmsBillNum, |
|||
itm.OrderBillNum, |
|||
itm.MaterialCode, |
|||
itm.MaterialDesc, |
|||
itm.MaterialGroup, |
|||
itm.OutPut, |
|||
itm.InPut, |
|||
itm.State, |
|||
itm.Extend1, |
|||
itm.Extend2, |
|||
itm.Version, |
|||
itm.ParentMaterialCode, |
|||
itm.BillNum, |
|||
itm.TaskId, |
|||
itm.Remark, |
|||
itm.Qty, |
|||
tm1.Qty |
|||
); |
|||
|
|||
|
|||
|
|||
|
|||
return new PagedResultDto<WmsHQCarOutPutDetial>(totalCount, query.ToList()); |
|||
} |
|||
/// <summary>
|
|||
/// 任务明细标记已确认
|
|||
/// </summary>
|
|||
/// <param name="files">上传的文件(前端已经限制只能上传一个附件)</param>
|
|||
/// <returns></returns>
|
|||
[HttpPost] |
|||
[Route("WmsSharePartOutPutAudit")] |
|||
[DisableRequestSizeLimit] |
|||
|
|||
public async Task<bool> WmsSharePartAudit(List<Guid> ids) |
|||
{ |
|||
var _joblist = await _job.Where(p => ids.Contains(p.Id)).ToListAsync(); |
|||
foreach (var itm in _joblist) |
|||
{ |
|||
itm.FileName = "已确认"; |
|||
} |
|||
foreach (var itm in _joblist) |
|||
{ |
|||
await _job.UpdateAsync(itm); |
|||
} |
|||
var _count = await _job.BatchUpdateAsync(_joblist.ToList()); |
|||
if (_count > 0) |
|||
{ |
|||
return true; |
|||
} |
|||
return false; |
|||
} |
|||
/// <summary>
|
|||
/// 选择任务,生成出库单,只包含已确认的单据
|
|||
/// </summary>
|
|||
/// <param name="ids"></param>
|
|||
/// <param name="version"></param>
|
|||
/// <returns></returns>
|
|||
[HttpPost] |
|||
[Route("WmsSharePartOutPut")] |
|||
public async Task<string> WmsSharePartOutPut(WmsJitRequestDto input) |
|||
{ |
|||
var _billNum = "BHQ" + 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<WmsHQCarOutPutDetial> _lst = new List<WmsHQCarOutPutDetial>(); |
|||
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<HQFSharePartSettledDetailDiff>(); |
|||
if (_list.Count() > 0) |
|||
{ |
|||
var _lsAry = _list.Select(p => new |
|||
WmsHQCarOutPutDetial( |
|||
GuidGenerator.Create(), |
|||
"", |
|||
string.Empty, |
|||
p.结算物料号, |
|||
p.物料描述, |
|||
p.物料组, |
|||
string.Empty, |
|||
string.Empty, |
|||
0, |
|||
string.Empty, |
|||
string.Empty, |
|||
input.Version, |
|||
p.Sap编码, |
|||
_billNum, |
|||
GuidGenerator.Create(), |
|||
string.Empty, |
|||
p.结算数量, |
|||
0 |
|||
)); |
|||
_lst.AddRange(_lsAry.ToArray()); |
|||
} |
|||
} |
|||
foreach (var itm in _lst) |
|||
{ |
|||
itm.BillNum = _billNum; |
|||
} |
|||
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 WmsHQCarOutPut(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 _billNum;
|
|||
//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("WmsSharePartOutPut-Pass")] |
|||
[UnitOfWork(false)] |
|||
public async Task<bool> WmsSharePartOutPutPass(WmsJitRequestDto input) |
|||
{ |
|||
if (input.Guids != null) |
|||
{ |
|||
List<WmsHQCarOutPutDetial> _ls = new List<WmsHQCarOutPutDetial>(); |
|||
if (input.Guids.Count() > 0) |
|||
{ |
|||
_ls = await _wmsRepository.Where(p => input.Guids.Contains(p.Id) && p.Version == input.Version && p.BillNum == input.BillNum && p.State != 2).ToListAsync(); |
|||
} |
|||
else |
|||
{ |
|||
_ls = await _wmsRepository.Where(p => p.Version == input.Version && p.BillNum == input.BillNum && p.State != 2).ToListAsync(); |
|||
} |
|||
if (_ls.Count() > 0) |
|||
{ |
|||
var sql = "DECLARE @return_value int\n" + |
|||
"EXEC @return_value = [dbo].[p_wms_output]\n" + |
|||
" @billnum = N'{0}',\n" + |
|||
" @type = 4\n" + |
|||
"SELECT 'Return Value' = @return_value"; |
|||
await _wmsRepository.GetDbContext().Database.ExecuteSqlRawAsync( |
|||
string.Format(sql, input.BillNum)); |
|||
|
|||
} |
|||
} |
|||
return true; |
|||
} |
|||
/// <summary>
|
|||
///出库界面功能, 撤销核准出库
|
|||
/// </summary>
|
|||
/// <param name="ids"></param>
|
|||
/// <param name="version"></param>
|
|||
/// <returns></returns>
|
|||
[HttpPost] |
|||
[Route("WmsSharePartOutPut-Cancel")] |
|||
public async Task<bool> WmsSharePartOutPutCancel(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 = 4,\n" + |
|||
" @accountdate = N'{2}'\n" + |
|||
"SELECT 'Return Value' = @return_value"; |
|||
|
|||
sql = string.Format(sql, str, input.BillNum, input.AccountDate); |
|||
|
|||
await _wmsRepository.GetDbContext().Database.ExecuteSqlRawAsync( |
|||
sql |
|||
); |
|||
} |
|||
return true; |
|||
} |
|||
[HttpPost] |
|||
[Route("ExcelImport")] |
|||
[DisableRequestSizeLimit] |
|||
//[Authorize(SettleAccountPermissions.SettleAccounts.Default)]
|
|||
public async Task<string> ExcelImport([FromForm] IFormFileCollection files, string version) |
|||
{ |
|||
var _billNum = "BHQ" + DateTime.Now.ToString("yyyyMMddhhmmss"); |
|||
ExportImporter _exportImporter = new ExportImporter(); |
|||
var result = await _exportImporter.ExtendExcelImport<WmsHQCarOutPutDetial>(files, _excelImportService); |
|||
List<WmsHQCarOutPutDetial> _lst = new List<WmsHQCarOutPutDetial>(); |
|||
|
|||
var _lsCopy = new List<WmsHQCarOutPutDetial>(); |
|||
foreach (var itm in result) |
|||
{ |
|||
WmsHQCarOutPutDetial _detail = new WmsHQCarOutPutDetial( |
|||
GuidGenerator.Create(), |
|||
itm.WmsBillNum, |
|||
itm.OrderBillNum, |
|||
itm.MaterialCode, |
|||
itm.MaterialDesc, |
|||
itm.MaterialGroup, |
|||
string.Empty, |
|||
string.Empty, |
|||
0, |
|||
string.Empty, |
|||
string.Empty, |
|||
version, |
|||
itm.ParentMaterialCode, |
|||
itm.BillNum, |
|||
GuidGenerator.Create() |
|||
, string.Empty |
|||
, itm.Qty |
|||
, 0 |
|||
); |
|||
_lsCopy.Add(_detail); |
|||
} |
|||
_lst.AddRange(_lsCopy.ToArray()); |
|||
|
|||
|
|||
var outPutDetail = await _wmsRepository.Where(p => p.Version == version).ToListAsync(); |
|||
|
|||
var error = from itm1 in outPutDetail |
|||
join itm2 in _lst on |
|||
new { itm1.MaterialCode } |
|||
equals |
|||
new { itm2.MaterialCode } |
|||
select itm1; |
|||
var errList = error.GroupBy(p => new { p.BillNum }).Select(p => new { BillNum = p.Key.BillNum, Number = p.Sum(itm => itm.Qty) }); |
|||
|
|||
var checkList = new List<ErrorExportDto>(); |
|||
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 } |
|||
equals |
|||
new { itm2.MaterialCode } 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 WmsHQCarOutPut(GuidGenerator.Create(), version, _billNum, CurrentUser.Email); |
|||
await _wmsVersionRepository.InsertAsync(_version, true); |
|||
} |
|||
return _billNum; |
|||
} |
|||
} |
|||
} |
Loading…
Reference in new issue