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.
866 lines
36 KiB
866 lines
36 KiB
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>
|
|
/// wms出库
|
|
/// </summary>
|
|
|
|
//[AllowAnonymous]
|
|
[Route("api/settleaccount/wmsSharePartoutput")]
|
|
[Authorize(SettleAccountPermissions.WMSJIT.Default)]
|
|
public class WMSSharePartAppService :
|
|
SettleAccountApplicationBase<WmsSharePartOutPutDetial>
|
|
{
|
|
private readonly ISettleAccountBranchEfCoreRepository<WmsSharePartOutPutDetial, Guid> _wmsRepository;
|
|
private readonly ISettleAccountBranchEfCoreRepository<WmsSharePartOutPut, Guid> _wmsVersionRepository;
|
|
|
|
private readonly ISettleAccountBranchEfCoreRepository<WmsSharePart90OutPutDetial, Guid> _wmsRepository90;
|
|
private readonly ISettleAccountBranchEfCoreRepository<WmsSharePart90OutPut, Guid> _wmsVersionRepository90;
|
|
|
|
|
|
private readonly WMSEfCoreRepository<WmsSharePartOutPutDetial> _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 WMSSharePartAppService(
|
|
|
|
ISettleAccountBranchEfCoreRepository<WmsSharePartOutPutDetial, Guid> wmsRepository,
|
|
ISettleAccountBranchEfCoreRepository<TaskJob, Guid> job,
|
|
ISettleAccountBranchEfCoreRepository<WmsSharePartOutPut, Guid> wmsVersionRepository,
|
|
WMSEfCoreRepository<WmsSharePartOutPutDetial> wmsefRespository,
|
|
WMSEfCoreRepository<TB_BILL> wmstbRespository,
|
|
IExcelImportAppService excelImportService,
|
|
IDistributedCache<WmsSharePartOutPutDetial> cache,
|
|
ISnowflakeIdGenerator snowflakeIdGenerator,
|
|
ICommonManager commonManager,
|
|
ISettleAccountBranchEfCoreRepository<WmsSharePart90OutPutDetial, Guid> wmsRepository90,
|
|
ISettleAccountBranchEfCoreRepository<WmsSharePart90OutPut, Guid> wmsVersionRepository90,
|
|
WmsDapperRepository wmsDapper
|
|
) : base(cache, excelImportService, snowflakeIdGenerator, commonManager)
|
|
{
|
|
_excelImportService = excelImportService;
|
|
_job = job;
|
|
_wmstbRespository = wmstbRespository;
|
|
_wmsRepository = wmsRepository;
|
|
_wmsVersionRepository = wmsVersionRepository;
|
|
_wmsDapper = wmsDapper;
|
|
_wmsefRespository = wmsefRespository;
|
|
|
|
_wmsRepository90 = wmsRepository90;
|
|
_wmsVersionRepository90 = wmsVersionRepository90;
|
|
}
|
|
|
|
private async Task<long> GetCountAsync(WmsSharePartOutPutDetialRequestDto 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(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<WmsSharePartOutPut>> 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<WmsSharePartOutPut>(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="input"></param>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
[Route("WmsSharePartDetailList")]
|
|
[UnitOfWork(false)]
|
|
//[Authorize(SettleAccountPermissions.SettleAccounts.Default)]
|
|
virtual public async Task<PagedResultDto<WmsSharePartOutPutDetial>> GetListAsync(WmsSharePartOutPutDetialRequestDto 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 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 WmsSharePartOutPutDetial(//少加个发货,由于零件有重复
|
|
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 == null ? 0 : tm1.Qty,
|
|
itm.OutPutQty,
|
|
itm.Price,
|
|
itm.Amt
|
|
);
|
|
|
|
|
|
var totalCount = await GetCountAsync(input);
|
|
return new PagedResultDto<WmsSharePartOutPutDetial>(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 = "已确认";
|
|
await _job.UpdateAsync(itm);
|
|
}
|
|
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 = "B" + DateTime.Now.ToString("yyyyMMddhhmmss");
|
|
var _billNoNum = "BNoBill" + 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<WmsSharePartOutPutDetial> _lst = new List<WmsSharePartOutPutDetial>();
|
|
List<WmsSharePart90OutPutDetial> _lstBill = new List<WmsSharePart90OutPutDetial>();
|
|
foreach (var filename in fileList)
|
|
{
|
|
string fileSavePath = Environment.CurrentDirectory + @"\wwwroot\files\host\my-file-container\" + filename;
|
|
ExcelHelper _excelHelper = new ExcelHelper(fileSavePath);
|
|
|
|
var _listSummary = _excelHelper.ExcelToListOne<WmsSharePartOutPutDetial>();//无单号
|
|
|
|
var _list90Summary = _excelHelper.ExcelToListOne<WmsSharePart90OutPutDetial>();//有单号
|
|
|
|
var _list = _listSummary.Where(p => p.OrderBillNum == "").ToList();//过滤 没有采购订单号为空的集合
|
|
var _listBill = _list90Summary.Where(p => p.OrderBillNum != "").ToList();//过滤 有采购订单号的集合
|
|
|
|
|
|
|
|
//var _list = _excelHelper.ExcelToList<WmsSharePartOutPutDetial>();
|
|
//没有 采购订单号
|
|
if (_list != null && _list.Count > 0)
|
|
{
|
|
var _lsAry = _list.Select(p => new
|
|
WmsSharePartOutPutDetial(
|
|
GuidGenerator.Create(),
|
|
string.Empty,
|
|
string.Empty,
|
|
p.MaterialCode,
|
|
p.MaterialDesc,
|
|
p.MaterialGroup,
|
|
string.Empty,
|
|
string.Empty,
|
|
0,
|
|
!string.IsNullOrEmpty(p.Extend1) ? p.Extend1 : string.Empty,
|
|
|
|
string.Empty,
|
|
string.Empty,
|
|
p.MaterialCode,
|
|
_billNoNum,
|
|
GuidGenerator.Create(),
|
|
string.Empty,
|
|
p.Qty,
|
|
p.StockQty,
|
|
p.Qty,
|
|
p.Price,
|
|
p.Amt
|
|
));
|
|
_lst.AddRange(_list.ToArray());
|
|
}
|
|
|
|
if (_listBill != null && _listBill.Count() > 0)
|
|
{
|
|
var _lsAry = _listBill.Select(p => new
|
|
WmsSharePartOutPutDetial(
|
|
GuidGenerator.Create(),
|
|
p.WmsBillNum,
|
|
p.OrderBillNum,
|
|
p.MaterialCode,
|
|
p.MaterialDesc,
|
|
p.MaterialGroup,
|
|
string.Empty,
|
|
string.Empty,
|
|
0,
|
|
!string.IsNullOrEmpty(p.Extend1) ? p.Extend1 : string.Empty,
|
|
|
|
string.Empty,
|
|
string.Empty,
|
|
p.MaterialCode,
|
|
_billNum,
|
|
GuidGenerator.Create(),
|
|
string.Empty,
|
|
p.Qty,
|
|
p.StockQty,
|
|
p.Qty,
|
|
p.Price,
|
|
p.Amt
|
|
));
|
|
_lstBill.AddRange(_listBill.ToArray());
|
|
}
|
|
}
|
|
|
|
|
|
if (_lst != null && _lst.Count>0)
|
|
{
|
|
//没有采购订单号
|
|
var outPutDetail = await _wmsRepository.Where(p => p.Version == input.Version && p.OrderBillNum == "").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) });
|
|
if (errList.Count() == 0)
|
|
{
|
|
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();
|
|
_wmslst = _wmslst.Select(p => new
|
|
WmsSharePartOutPutDetial(
|
|
GuidGenerator.Create(),
|
|
string.Empty,
|
|
string.Empty,
|
|
p.MaterialCode,
|
|
p.MaterialDesc,
|
|
p.MaterialGroup,
|
|
string.Empty,
|
|
string.Empty,
|
|
0,
|
|
!string.IsNullOrEmpty(p.Extend1) ? p.Extend1 : string.Empty,
|
|
string.Empty,
|
|
input.Version,
|
|
p.MaterialCode,
|
|
_billNoNum,
|
|
GuidGenerator.Create(),
|
|
string.Empty,
|
|
p.Qty,
|
|
p.StockQty,
|
|
p.Qty,
|
|
p.Price,
|
|
p.Amt
|
|
)).ToList();
|
|
await _wmsRepository.GetDbContext().BulkInsertAsync(_wmslst, new BulkConfig() { BulkCopyTimeout = 0, BatchSize = 10000 });
|
|
int _count = _wmsVersionRepository.Count(p => p.Version == input.Version && p.BillNum == _billNoNum);
|
|
if (_wmslst.Count() > 0 && _count == 0)
|
|
{
|
|
var _version = new WmsSharePartOutPut(GuidGenerator.Create(), input.Version, _billNoNum, 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 = _billNoNum;
|
|
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);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
//有采购订单号
|
|
//往Set_WmsSharePart90OutPutDetial表中存储
|
|
if (_lstBill != null && _lstBill.Count>0)
|
|
{
|
|
//有采购订单号
|
|
var outPutDetailBill = await _wmsRepository90.Where(p => p.Version == input.Version && p.OrderBillNum != "").ToListAsync();
|
|
|
|
var error = from itm1 in outPutDetailBill
|
|
join itm2 in _lstBill on
|
|
new { itm1.MaterialCode, itm1.OrderBillNum }
|
|
equals
|
|
new { itm2.MaterialCode, itm2.OrderBillNum }
|
|
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 queryBill = from itm1 in _lstBill
|
|
join itm2 in outPutDetailBill on
|
|
new { itm1.MaterialCode, itm1.OrderBillNum }
|
|
equals
|
|
new { itm2.MaterialCode, itm2.OrderBillNum } into temp1
|
|
from tm1 in temp1.DefaultIfEmpty()
|
|
where tm1 == null
|
|
select itm1;
|
|
var _wmslstBill = queryBill.ToList();
|
|
_wmslstBill = _wmslstBill.Select(p => new
|
|
WmsSharePart90OutPutDetial(
|
|
GuidGenerator.Create(),
|
|
p.WmsBillNum,
|
|
p.OrderBillNum,
|
|
p.MaterialCode,
|
|
p.MaterialDesc,
|
|
p.MaterialGroup,
|
|
string.Empty,
|
|
string.Empty,
|
|
0,
|
|
!string.IsNullOrEmpty(p.Extend1) ? p.Extend1 : string.Empty,
|
|
string.Empty,
|
|
input.Version,
|
|
p.MaterialCode,
|
|
_billNum,
|
|
GuidGenerator.Create(),
|
|
string.Empty,
|
|
p.Qty,
|
|
p.StockQty,
|
|
p.Qty,
|
|
p.Price,
|
|
p.Amt
|
|
)).ToList();
|
|
|
|
await _wmsRepository90.GetDbContext().BulkInsertAsync(_wmslstBill, new BulkConfig() { BulkCopyTimeout = 0, BatchSize = 10000 });
|
|
int _count = _wmsVersionRepository90.Count(p => p.Version == input.Version && p.BillNum == _billNum);
|
|
if (_wmslstBill.Count() > 0 && _count == 0)
|
|
{
|
|
var _version = new WmsSharePart90OutPut(GuidGenerator.Create(), input.Version, _billNum, CurrentUser.Email);
|
|
|
|
_version.Remark= !string.IsNullOrEmpty(_joblist.FirstOrDefault().Remark) ? _joblist.FirstOrDefault().Remark : string.Empty;
|
|
|
|
await _wmsVersionRepository90.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;
|
|
_billNoNum = 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<WmsSharePartOutPutDetial> _ls = new List<WmsSharePartOutPutDetial>();
|
|
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 = 10,\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;
|
|
}
|
|
|
|
|
|
|
|
[HttpPost]
|
|
[Route("WmsSharePartOutPutModify")]
|
|
[DisableRequestSizeLimit]
|
|
public async Task<bool> WmsSharePartUpdate(WmsSharePartOutPutDetial 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("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 = 2,\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 = 2\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)
|
|
{
|
|
|
|
ExportImporter _exportImporter = new ExportImporter();
|
|
var result = await _exportImporter.ExtendExcelOfSheetOneImport<WmsSharePartOutPutDetial>(files, _excelImportService);
|
|
|
|
if (result == null)
|
|
{
|
|
throw new BusinessException("导入的模板中没有数据,不能为空,请检查!");
|
|
}
|
|
|
|
var result90 = await _exportImporter.ExtendExcelOfSheetOneImport<WmsSharePart90OutPutDetial>(files, _excelImportService);
|
|
|
|
var result_nobill = result.Where(p => p.OrderBillNum == "").ToList();
|
|
var result_withbill = result90.Where(p => p.OrderBillNum != "").ToList();
|
|
|
|
|
|
//没有采购单号
|
|
if (result_nobill != null)
|
|
{
|
|
var _billNoNum = "BNoBill" + DateTime.Now.ToString("yyyyMMddhhmmss");
|
|
List<WmsSharePartOutPutDetial> _lst = new List<WmsSharePartOutPutDetial>();
|
|
|
|
var _lsCopy = new List<WmsSharePartOutPutDetial>();
|
|
foreach (var itm in result_nobill)
|
|
{
|
|
WmsSharePartOutPutDetial _detail = new WmsSharePartOutPutDetial(
|
|
GuidGenerator.Create(),
|
|
string.Empty,
|
|
string.Empty,
|
|
itm.MaterialCode,
|
|
itm.MaterialDesc,
|
|
itm.MaterialGroup,
|
|
string.Empty,
|
|
string.Empty,
|
|
0,
|
|
!string.IsNullOrEmpty(itm.Extend1) ? itm.Extend1 : string.Empty,
|
|
string.Empty,
|
|
version,
|
|
itm.ParentMaterialCode,
|
|
itm.BillNum,
|
|
GuidGenerator.Create()
|
|
, string.Empty
|
|
, itm.Qty
|
|
, 0
|
|
, itm.Qty
|
|
, itm.Price
|
|
, itm.Amt
|
|
);
|
|
_lsCopy.Add(_detail);
|
|
}
|
|
_lst.AddRange(_lsCopy.ToArray());
|
|
|
|
//var _ls1 = _lst.Where(p => p.ParentMaterialCode == p.MaterialCode).ToList();
|
|
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 = _billNoNum;
|
|
}
|
|
await _wmsRepository.GetDbContext().BulkInsertAsync(_wmslst, new BulkConfig() { BulkCopyTimeout = 0, BatchSize = 10000 });
|
|
int _count = _wmsVersionRepository.Count(p => p.Version == version && p.BillNum == _billNoNum);
|
|
if (_count == 0 && _wmslst.Count() > 0)
|
|
{
|
|
var _version = new WmsSharePartOutPut(GuidGenerator.Create(), version, _billNoNum, CurrentUser.Email);
|
|
await _wmsVersionRepository.InsertAsync(_version, true);
|
|
}
|
|
}
|
|
|
|
//有采购单号
|
|
if (result_withbill != null)
|
|
{
|
|
var _billNum = "B" + DateTime.Now.ToString("yyyyMMddhhmmss");
|
|
List<WmsSharePart90OutPutDetial> _lst = new List<WmsSharePart90OutPutDetial>();
|
|
|
|
var _lsCopy = new List<WmsSharePart90OutPutDetial>();
|
|
foreach (var itm in result_withbill)
|
|
{
|
|
WmsSharePart90OutPutDetial _detail = new WmsSharePart90OutPutDetial(
|
|
GuidGenerator.Create(),
|
|
itm.WmsBillNum,
|
|
itm.OrderBillNum,
|
|
itm.MaterialCode,
|
|
itm.MaterialDesc,
|
|
itm.MaterialGroup,
|
|
string.Empty,
|
|
string.Empty,
|
|
0,
|
|
!string.IsNullOrEmpty(itm.Extend1) ? itm.Extend1 : string.Empty,
|
|
string.Empty,
|
|
version,
|
|
itm.ParentMaterialCode,
|
|
itm.BillNum,
|
|
GuidGenerator.Create()
|
|
, string.Empty
|
|
, itm.Qty
|
|
, 0
|
|
, itm.Qty
|
|
, itm.Price
|
|
, itm.Amt
|
|
);
|
|
_lsCopy.Add(_detail);
|
|
}
|
|
_lst.AddRange(_lsCopy.ToArray());
|
|
|
|
var outPutDetail = await _wmsRepository90.Where(p => p.Version == version).ToListAsync();
|
|
|
|
|
|
var error = from itm1 in outPutDetail
|
|
join itm2 in _lst on
|
|
new { itm1.MaterialCode, itm1.OrderBillNum, itm1.WmsBillNum }
|
|
equals
|
|
new { itm2.MaterialCode, itm2.OrderBillNum, itm2.WmsBillNum }
|
|
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, itm1.OrderBillNum }
|
|
equals
|
|
new { itm2.MaterialCode, itm2.OrderBillNum } 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 _wmsRepository90.GetDbContext().BulkInsertAsync(_wmslst, new BulkConfig() { BulkCopyTimeout = 0, BatchSize = 10000 });
|
|
int _count = _wmsVersionRepository90.Count(p => p.Version == version && p.BillNum == _billNum);
|
|
if (_count == 0 && _wmslst.Count() > 0)
|
|
{
|
|
var _version = new WmsSharePart90OutPut(GuidGenerator.Create(), version, _billNum, CurrentUser.Email);
|
|
await _wmsVersionRepository90.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);
|
|
|
|
var dtos = ObjectMapper.Map<List<WmsSharePartOutPutDetial>, List<WmsSharePartOutPutDetialDto>>(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;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
}
|