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.
442 lines
17 KiB
442 lines
17 KiB
using EFCore.BulkExtensions;
|
|
using Magicodes.ExporterAndImporter.Core;
|
|
using Magicodes.ExporterAndImporter.Excel;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Shouldly;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using Volo.Abp;
|
|
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 Win.Sfs.Shared.Filter;
|
|
using WY.NewJit.Extends.PaiGe.WMS;
|
|
|
|
namespace Win.Sfs.SettleAccount.Entities.WMS
|
|
{
|
|
[Route("api/settleaccount/WmsOneTimeSaleOutput")]
|
|
//[AllowAnonymous]
|
|
[Authorize(SettleAccountPermissions.WMSJIT.Default)]
|
|
public class WmsOneTimeSaleOutputAppService : SettleAccountApplicationBase<WmsOneTimeSaleOutPutDetial>
|
|
{
|
|
|
|
private readonly ISettleAccountBranchEfCoreRepository<WmsOneTimeSaleOutPutDetial, Guid> _wmsRepository;
|
|
private readonly ISettleAccountBranchEfCoreRepository<WmsOneTimeSaleOutPut, 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 WmsOneTimeSaleOutputAppService(
|
|
|
|
IExcelImportAppService excelImportService,
|
|
ISettleAccountBranchEfCoreRepository<WmsOneTimeSaleOutPutDetial, Guid> wmsRepository,
|
|
ISettleAccountBranchEfCoreRepository<TaskJob, Guid> job,
|
|
ISettleAccountBranchEfCoreRepository<WmsOneTimeSaleOutPut, Guid> wmsVersionRepository,
|
|
WMSEfCoreRepository<WmsKanbanOutPutDetial> wmsefRespository,
|
|
KanbanUnSettledDapperRepository dapper,
|
|
WMSEfCoreRepository<TB_BILL> wmstbRespository,
|
|
IDistributedCache<WmsOneTimeSaleOutPutDetial> 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(WmsOneTimeSaleOutPutDetialRequestDto 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<WmsOneTimeSaleOutPut>> 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<WmsOneTimeSaleOutPut>(totalCount, entities);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 准时化出库明细
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
[Route("WmsKanbanDetailList")]
|
|
[UnitOfWork(false)]
|
|
//[Authorize(SettleAccountPermissions.SettleAccounts.Default)]
|
|
virtual public async Task<PagedResultDto<WmsOneTimeSaleOutPutDetial>> GetListAsync(WmsOneTimeSaleOutPutDetialRequestDto 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 WmsOneTimeSaleOutPutDetial(
|
|
GuidGenerator.Create(),
|
|
"无看板发货",
|
|
itm.SapMaterialCode,
|
|
itm.MaterialDesc,
|
|
itm.Version,
|
|
itm.IsBack,
|
|
string.Empty,
|
|
itm.Qty,
|
|
tm1 == null ? 0 : tm1.Qty,
|
|
itm.Qty,
|
|
itm.Extend,
|
|
itm.BillNum,
|
|
itm.State,
|
|
itm.RealityNumber,
|
|
itm.Price,
|
|
itm.Amt
|
|
);
|
|
|
|
return new PagedResultDto<WmsOneTimeSaleOutPutDetial>(totalCount, entities);
|
|
}
|
|
|
|
/// <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="files">上传的文件(前端已经限制只能上传一个附件)</param>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
[Route("WmsSharePartOutPutModify")]
|
|
[DisableRequestSizeLimit]
|
|
|
|
public async Task<bool> WmsSharePartUpdate(WmsOneTimeSaleOutPutDetial 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 _billNum = "OTS" + DateTime.Now.ToString("yyyyMMddhhmmss");
|
|
|
|
|
|
//var _list = _dapper.GetNoKanbanSettleDetail(input.Version);
|
|
|
|
ExportImporter _exportImporter = new ExportImporter();
|
|
//只取导入模板第一个页签
|
|
var _list = await _exportImporter.ExtendExcelOfSheetOneImport<WmsOneTimeSaleOutPutDetial>(files, _excelImportService);
|
|
|
|
if (_list == null || _list.Count == 0)
|
|
{
|
|
throw new BusinessException("导入模板数据不能为空!");
|
|
}
|
|
|
|
////插入数据前检验
|
|
//var checkList = new List<ErrorExportDto>();
|
|
//var _group = _list.GroupBy(x => new { x.Qty,x.SapMaterialCode, x.Version }).Select(p => new { Count = p.Count(), Qty = p.Key.Qty, SapMaterialCode = p.Key.SapMaterialCode });
|
|
//foreach (var itm in _group)
|
|
//{
|
|
// if (itm.Qty==null)
|
|
// {
|
|
// checkList.Add(new ErrorExportDto(version, "OneTiemSale", string.Empty, string.Empty, string.Empty, string.Empty, string.Format("导入的平台数据不是{0}平台的,请检查!", itm.Factory), string.Empty));
|
|
// break;
|
|
// }
|
|
//}
|
|
|
|
|
|
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 WmsOneTimeSaleOutPutDetial(
|
|
GuidGenerator.Create(),
|
|
"无看板发货",
|
|
itm.SapMaterialCode,
|
|
itm.MaterialDesc,
|
|
version,
|
|
itm.IsBack,//是否备件
|
|
string.Empty,
|
|
itm.Qty,
|
|
tm1 == null ? 0 : tm1.Qty,
|
|
itm.Qty,
|
|
itm.Extend,//客户信息
|
|
_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 WmsOneTimeSaleOutPut(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<string> WmsKanbanOutPutPass(WmsJitRequestDto input)
|
|
{
|
|
if (input.Guids != null)
|
|
{
|
|
List<WmsOneTimeSaleOutPutDetial> _ls = new List<WmsOneTimeSaleOutPutDetial>();
|
|
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 && p.State!=4).ToListAsync();
|
|
}
|
|
else
|
|
{
|
|
_ls = await _wmsRepository.Where(p => p.Version == input.Version && p.BillNum == input.BillNum && p.State != 2 && p.State != 4).ToListAsync();
|
|
}
|
|
//_ls = _ls.Where(p => p.SockQty < p.OutputQty || p.Qty < p.OutputQty).ToList();
|
|
//var checkList = new List<ErrorExportDto>();
|
|
|
|
//foreach (var itm in _ls)
|
|
//{
|
|
// checkList.Add(new ErrorExportDto() { Message = string.Format("物料号:{0}出库数量大于结算数量或寄售库存数量!",itm.SapMaterialCode) });
|
|
//}
|
|
//if (checkList.Count > 0)
|
|
//{
|
|
|
|
// return await ExportErrorReportAsync(checkList,"校验失败.xlsx");
|
|
//}
|
|
|
|
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 = 22,\n" +
|
|
" @date = N'{1}'\n" +
|
|
"SELECT 'Return Value' = @return_value";
|
|
await _wmsRepository.GetDbContext().Database.ExecuteSqlRawAsync(
|
|
string.Format(sql, input.BillNum, input.AccountDate.ToShortDateString()));
|
|
|
|
}
|
|
}
|
|
return ApplicationConsts.SuccessStr;
|
|
}
|
|
/// <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 = 22,\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 = 22\n" +
|
|
"SELECT 'Return Value' = @return_value";
|
|
await _wmsRepository.GetDbContext().Database.ExecuteSqlRawAsync(
|
|
string.Format(sql, input.BillNum)
|
|
);
|
|
|
|
return true;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 导出
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
[Route("Export")]
|
|
//[Authorize(SettleAccountPermissions.SettleAccounts.Default)]
|
|
virtual public async Task<string> ExportAsync(WmsOneTimeSaleOutPutDetialRequestDto 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);
|
|
|
|
var dtos = ObjectMapper.Map<List<WmsOneTimeSaleOutPutDetial>, List<WmsOneTimeSaleOutPutDetialDto>>(entities);
|
|
|
|
IExporter _excel = new ExcelExporter();
|
|
byte[] result = null;
|
|
|
|
var _fileName = string.Format("一次性寄售销售出库单_{0}.xlsx", Guid.NewGuid().ToString());
|
|
result = await _excel.ExportAsByteArray(dtos);
|
|
|
|
|
|
result.ShouldNotBeNull();
|
|
|
|
//保存导出文件到服务器存成二进制
|
|
await _excelImportService.SaveBlobAsync(
|
|
new SaveExcelImportInputDto
|
|
{
|
|
Name = _fileName,
|
|
Content = result
|
|
}
|
|
);
|
|
return _fileName;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
// 物料 物料组 物料描述 物料号 期间 单位 出库数量 结算数量
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|