|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Linq;
|
|
|
using System.Text;
|
|
|
using System.Threading.Tasks;
|
|
|
using Estsh.Core.Base;
|
|
|
using Estsh.Core.Wms.IRepositories;
|
|
|
using Estsh.Core.Wms.IServices;
|
|
|
using Estsh.Core.Model.Result;
|
|
|
using Estsh.Core.Services;
|
|
|
using Estsh.Core.Repositories;
|
|
|
using Estsh.Core.Models;
|
|
|
using Newtonsoft.Json.Linq;
|
|
|
using static Estsh.Core.Model.EnumUtil.WmsEnumUtil;
|
|
|
using Estsh.Core.Model.EnumUtil;
|
|
|
using Dapper;
|
|
|
|
|
|
namespace Estsh.Core.Wms.Services
|
|
|
{
|
|
|
public class NcScrapService : BaseService<BaseEntity>, INcScrapService
|
|
|
{
|
|
|
private readonly INcScrapRepository repository;
|
|
|
private readonly IMoveOrderRepository moveOrderRepository;
|
|
|
private readonly IStockRepository stockRepository;
|
|
|
public NcScrapService(INcScrapRepository _repository,
|
|
|
IMoveOrderRepository _moveOrderRepository, IStockRepository _stockRepository) : base(_repository)
|
|
|
{
|
|
|
this.repository = _repository;
|
|
|
this.moveOrderRepository = _moveOrderRepository;
|
|
|
this.stockRepository = _stockRepository;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// NC报废处理
|
|
|
/// </summary>
|
|
|
/// <param name="cartonNo"></param>
|
|
|
/// <param name="orderNo"></param>
|
|
|
/// <param name="loginId"></param>
|
|
|
/// <returns></returns>
|
|
|
public string DoScrap(string cartonNo, string orderNo, string loginId)
|
|
|
{
|
|
|
SysStock cartonInfo = stockRepository.GetCartonInfo(cartonNo) ;
|
|
|
|
|
|
if (cartonInfo == null)
|
|
|
{
|
|
|
return "包装条码不存在,请检查!";
|
|
|
}
|
|
|
if (cartonInfo.Enabled.Equals(Enabled.N))
|
|
|
{
|
|
|
return "包装条码已被冻结,不允许报废!";
|
|
|
}
|
|
|
if (cartonInfo.Status != (int)StockStatus.NC_INSTOCK)
|
|
|
{
|
|
|
return "包装条码状态不是NC状态,不允许报废!";
|
|
|
}
|
|
|
if (cartonInfo.Qty == 0)
|
|
|
{
|
|
|
return "包装条码数量为0,禁止操作!";
|
|
|
}
|
|
|
List<WmsMoveDetail> moveDetails = moveOrderRepository.GetMoveDetailList(orderNo);
|
|
|
WmsMoveDetail? moveDetail = moveDetails.SingleOrDefault(x => x.PartId == cartonInfo.PartId);
|
|
|
if (moveDetail == null)
|
|
|
{
|
|
|
return "报废单中不包含包装条码对应零件,不允许报废!";
|
|
|
}
|
|
|
if (moveDetail.Qty <= moveDetail.PickQty)
|
|
|
{
|
|
|
return "此零件对应的订单数量已满,无法再报废!";
|
|
|
}
|
|
|
if (moveDetail.Qty < moveDetail.PickQty + cartonInfo.Qty)
|
|
|
{
|
|
|
return "箱包装数量大于订单中此零件的剩余待报废数量,无法报废!";
|
|
|
}
|
|
|
|
|
|
List<WmsMoveSn> moveSns = moveOrderRepository.GetMoveSnList(orderNo);
|
|
|
List<WmsMoveSn> moveSnCreates = moveSns.Where(x => x.Status == (int)MoveOrderSnStatus.CREATE).ToList();
|
|
|
|
|
|
WmsMoveSn? moveSn = null;
|
|
|
if (moveSnCreates != null && moveSnCreates.Count > 0)
|
|
|
{
|
|
|
moveSn = moveSnCreates.SingleOrDefault(x => x.CartonNo.Equals(cartonInfo.CartonNo));
|
|
|
if (moveSn == null)
|
|
|
{
|
|
|
return "报废单中不包含此包装条码,不允许报废!";
|
|
|
}
|
|
|
}
|
|
|
string result = string.Empty;
|
|
|
if (repository.DoScrap(cartonInfo, moveDetail, moveSn, loginId))
|
|
|
{
|
|
|
result = this.SubmitOrder(orderNo, loginId);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
result = "操作失败,请重新尝试!";
|
|
|
}
|
|
|
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 提交报废单据
|
|
|
/// </summary>
|
|
|
/// <param name="orderNo"></param>
|
|
|
/// <param name="loginId"></param>
|
|
|
/// <returns></returns>
|
|
|
public string SubmitOrder(string orderNo,string loginId)
|
|
|
{
|
|
|
string result = string.Empty;
|
|
|
List<WmsMoveDetail> moveDetails = moveOrderRepository.GetMoveDetailList(orderNo);
|
|
|
var moveDetailsExist = moveDetails.Where(a => a.Qty > a.PickQty).ToList();
|
|
|
if (moveDetailsExist == null || moveDetailsExist.Count == 0)
|
|
|
{
|
|
|
// 完成单据并提交接口
|
|
|
if (moveOrderRepository.OrderComplete(orderNo, loginId))
|
|
|
{
|
|
|
repository.InsertInterfaceByNCScrap(orderNo);//添加到接口表
|
|
|
result = "ORDER_COMPLETED";
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
result = "操作失败,请重新尝试!";
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
result = "SCAN_OK";
|
|
|
//提交接口
|
|
|
}
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
}
|
|
|
}
|