Administrator
3 years ago
10 changed files with 617 additions and 81 deletions
@ -0,0 +1,405 @@ |
|||
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.WMS |
|||
{ |
|||
|
|||
[Route("api/settleaccount/WmsHQKBOutput")] |
|||
[AllowAnonymous] |
|||
//[Authorize(SettleAccountPermissions.WMSJIT.Default)]
|
|||
public class WmsHQKBOutputAppService : SettleAccountApplicationBase<WmsHQWithOutKanbanOutPutDetial> |
|||
{ |
|||
/// <summary>
|
|||
/// 大众看板-出库
|
|||
/// </summary>
|
|||
|
|||
|
|||
|
|||
|
|||
//private readonly ISettleAccountBranchEfCoreRepository<WmsKanbanOutPutDetial, Guid> _wmsRepository;
|
|||
//private readonly ISettleAccountBranchEfCoreRepository<WmsKanbanOutPut, Guid> _wmsVersionRepository;
|
|||
|
|||
private readonly ISettleAccountBranchEfCoreRepository<WmsHQWithOutKanbanOutPutDetial, Guid> _wmsRepository; |
|||
private readonly ISettleAccountBranchEfCoreRepository<WmsHQWithOutKanbanOutPut, Guid> _wmsVersionRepository; |
|||
|
|||
private readonly KanbanUnSettledDapperRepository _dapper; |
|||
private readonly WMSEfCoreRepository<WmsKanbanOutPutDetial> _wmsefRespository; |
|||
|
|||
private readonly WMSEfCoreRepository<TB_BILL> _wmstbRespository; |
|||
private readonly ISettleAccountBranchEfCoreRepository<TaskJob, Guid> _job; |
|||
private readonly IExcelImportAppService _excelImportService; |
|||
|
|||
|
|||
private readonly TaskJobService _service; |
|||
private readonly WmsDapperRepository _wmsDapper; |
|||
/// <summary>
|
|||
///
|
|||
/// </summary>
|
|||
/// <param name="wmsRepository"></param>
|
|||
/// <param name="job"></param>
|
|||
/// <param name="wmsVersionRepository"></param>
|
|||
/// <param name="wmsefRespository"></param>
|
|||
/// <param name="wmstbRespository"></param>
|
|||
public WmsHQKBOutputAppService( |
|||
|
|||
|
|||
IExcelImportAppService excelImportService, |
|||
|
|||
ISettleAccountBranchEfCoreRepository<WmsHQWithOutKanbanOutPutDetial, Guid> wmsRepository, |
|||
ISettleAccountBranchEfCoreRepository<TaskJob, Guid> job, |
|||
ISettleAccountBranchEfCoreRepository<WmsHQWithOutKanbanOutPut, Guid> wmsVersionRepository, |
|||
WMSEfCoreRepository<WmsKanbanOutPutDetial> wmsefRespository, |
|||
KanbanUnSettledDapperRepository dapper, |
|||
WMSEfCoreRepository<TB_BILL> wmstbRespository, |
|||
IDistributedCache<WmsHQWithOutKanbanOutPutDetial> cache, |
|||
ISnowflakeIdGenerator snowflakeIdGenerator, |
|||
ICommonManager commonManager, |
|||
WmsDapperRepository wmsDapper |
|||
) : base(cache, excelImportService, snowflakeIdGenerator, commonManager) |
|||
{ |
|||
_job = job; |
|||
_wmstbRespository = wmstbRespository; |
|||
_wmsRepository = wmsRepository; |
|||
_wmsVersionRepository = wmsVersionRepository; |
|||
_wmsefRespository = wmsefRespository; |
|||
_excelImportService = excelImportService; |
|||
_dapper = dapper; |
|||
_wmsDapper = wmsDapper; |
|||
} |
|||
|
|||
private async Task<long> GetCountAsync(WmsKanbanOutPutDetialRequestDto input) |
|||
{ |
|||
input.Filters.Add(new FilterCondition() { Action = EnumFilterAction.Equal, Column = "BillNum", Logic = EnumFilterLogic.And, Value = input.BillNum }); |
|||
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("WmsKanbanList")] |
|||
//[Authorize(SettleAccountPermissions.SettleAccounts.Default)]
|
|||
virtual public async Task<PagedResultDto<WmsHQWithOutKanbanOutPut>> GetListAsync(WmsKanbanOutPutRequestDto input) |
|||
{ |
|||
|
|||
|
|||
|
|||
//input.Filters.Add(new FilterCondition() { Action = EnumFilterAction.Equal, Column = "BillNum", Logic = EnumFilterLogic.And, Value = input.BillNum });
|
|||
var entities = await _wmsVersionRepository.GetListByFilterAsync(GuidGenerator.Create(), input.Filters, input.Sorting, input.MaxResultCount, |
|||
input.SkipCount, true); |
|||
|
|||
var totalCount = await GetCountAsync(input); |
|||
|
|||
return new PagedResultDto<WmsHQWithOutKanbanOutPut>(totalCount, entities); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 准时化出库明细
|
|||
/// </summary>
|
|||
/// <param name="input"></param>
|
|||
/// <returns></returns>
|
|||
[HttpPost] |
|||
[Route("WmsKanbanDetailList")] |
|||
[UnitOfWork(false)] |
|||
//[Authorize(SettleAccountPermissions.SettleAccounts.Default)]
|
|||
virtual public async Task<PagedResultDto<WmsHQWithOutKanbanOutPutDetial>> GetListAsync(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, 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.SapMaterialCode equals itm1.SapCode |
|||
into temp1 |
|||
from tm1 in temp1.DefaultIfEmpty() |
|||
select new WmsHQWithOutKanbanOutPutDetial( |
|||
GuidGenerator.Create(), |
|||
"无看板发货", |
|||
itm.SapMaterialCode, |
|||
itm.MaterialDesc, |
|||
itm.Version, |
|||
string.Empty, |
|||
string.Empty, |
|||
itm.Qty, |
|||
tm1 == null ? 0 : tm1.Qty, |
|||
itm.OutputQty, |
|||
string.Empty, |
|||
itm.BillNum, |
|||
itm.State, |
|||
itm.RealityNumber, |
|||
itm.Price, |
|||
itm.Amt |
|||
); |
|||
|
|||
return new PagedResultDto<WmsHQWithOutKanbanOutPutDetial>(totalCount, entities); |
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
/// <summary>
|
|||
/// 任务明细标记已确认
|
|||
/// </summary>
|
|||
/// <param name="files">上传的文件(前端已经限制只能上传一个附件)</param>
|
|||
/// <returns></returns>
|
|||
[HttpPost] |
|||
[Route("WmsSharePartOutPutModify")] |
|||
[DisableRequestSizeLimit] |
|||
|
|||
public async Task<bool> WmsSharePartUpdate(WmsHQWithOutKanbanOutPutDetial detial) |
|||
{ |
|||
var _entityList = _wmsRepository.Where(p => p.Id == detial.BranchId).ToList(); |
|||
if (_entityList.Count() > 0) |
|||
{ |
|||
foreach (var itm in _entityList) |
|||
{ |
|||
itm.OutputQty = detial.OutputQty; |
|||
await _wmsRepository.UpdateAsync(itm); |
|||
} |
|||
} |
|||
return true; |
|||
|
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 选择任务,生成出库单,只包含已确认的单据
|
|||
/// </summary>
|
|||
/// <param name="ids"></param>
|
|||
/// <param name="version"></param>
|
|||
/// <returns></returns>
|
|||
[HttpPost] |
|||
[Route("ExcelImport")] |
|||
[UnitOfWork(false)] |
|||
public async Task<string> WmsKanbanOutPut([FromForm] IFormFileCollection files, string version) |
|||
{ |
|||
|
|||
var _count1 = _wmsVersionRepository.Count(p => p.Version == version); |
|||
if (_count1 > 0) |
|||
{ |
|||
var checkList = new List<ErrorExportDto>(); |
|||
checkList.Add(new ErrorExportDto() { Message = "有重复期间数据" }); |
|||
if (checkList.Count > 0) |
|||
{ |
|||
|
|||
return await ExportErrorReportAsync(checkList); |
|||
} |
|||
} |
|||
var _billNum = "HQKB" + DateTime.Now.ToString("yyyyMMddhhmmss"); |
|||
|
|||
|
|||
//var _list = _dapper.GetNoKanbanSettleDetail(input.Version);
|
|||
|
|||
ExportImporter _exportImporter = new ExportImporter(); |
|||
var _list = await _exportImporter.ExtendExcelImport<WmsHQWithOutKanbanOutPutDetial>(files, _excelImportService); |
|||
var stockList = _wmsDapper.GetSalesStock(); |
|||
var query = from itm in _list |
|||
join itm1 in stockList on itm.SapMaterialCode equals itm1.SapCode |
|||
into temp1 |
|||
from tm1 in temp1.DefaultIfEmpty() |
|||
select new WmsHQWithOutKanbanOutPutDetial( |
|||
GuidGenerator.Create(), |
|||
"无看板发货", |
|||
itm.SapMaterialCode, |
|||
itm.MaterialDesc, |
|||
itm.Version, |
|||
string.Empty, |
|||
string.Empty, |
|||
itm.Qty, |
|||
tm1 == null ? 0 : tm1.Qty, |
|||
itm.Qty, |
|||
string.Empty, |
|||
_billNum, |
|||
0, |
|||
0, |
|||
itm.Price, |
|||
itm.Amt |
|||
); |
|||
|
|||
await _wmsRepository.GetDbContext().BulkInsertAsync(query.ToList(), new BulkConfig() { BulkCopyTimeout = 0, BatchSize = 10000 }); |
|||
int _count = _wmsVersionRepository.Count(p => p.Version == version && p.BillNum == _billNum); |
|||
if (_count == 0) |
|||
{ |
|||
var _version = new WmsHQWithOutKanbanOutPut(GuidGenerator.Create(), version, _billNum, CurrentUser.Email); |
|||
await _wmsVersionRepository.InsertAsync(_version, true); |
|||
} |
|||
return ApplicationConsts.SuccessStr; ; |
|||
} |
|||
/// <summary>
|
|||
/// 出库界面功能,核准出库功能
|
|||
/// </summary>
|
|||
/// <param name="version"></param>
|
|||
/// <param name="p_list"></param>
|
|||
/// <returns></returns>
|
|||
[HttpPost] |
|||
[Route("WmsKanbanOutPut-Pass")] |
|||
[UnitOfWork(false)] |
|||
public async Task<bool> WmsKanbanOutPutPass(WmsJitRequestDto input) |
|||
{ |
|||
if (input.Guids != null) |
|||
{ |
|||
List<WmsHQWithOutKanbanOutPutDetial> _ls = new List<WmsHQWithOutKanbanOutPutDetial>(); |
|||
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(); |
|||
} |
|||
_ls = _ls.Where(p => p.SockQty >= p.OutputQty).ToList(); |
|||
if (_ls.Count() > 0) |
|||
{ |
|||
var sql = "DECLARE @return_value int\n" + |
|||
"EXEC @return_value = [dbo].[p_wms_ou" + |
|||
"tput]\n" + |
|||
" @billnum = N'{0}',\n" + |
|||
" @type = 21,\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("WmsKanbanOutPut-Cancel")] |
|||
public async Task<bool> WmsKanbanOutPutCancel(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 = 21,\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 = 21\n" + |
|||
"SELECT 'Return Value' = @return_value"; |
|||
await _wmsRepository.GetDbContext().Database.ExecuteSqlRawAsync( |
|||
string.Format(sql, input.BillNum) |
|||
); |
|||
|
|||
return true; |
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
// 物料 物料组 物料描述 物料号 开始日期 结束日期 单位 出库数量 结算数量 寄售库存数量
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
} |
|||
|
|||
|
|||
} |
Loading…
Reference in new issue