using AutoMapper;
|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Text;
|
using System.Text.RegularExpressions;
|
using System.Threading.Tasks;
|
using WIDESEA_Common.MaterielEnum;
|
using WIDESEA_Common.OrderEnum;
|
using WIDESEA_Common.WareHouseEnum;
|
using WIDESEA_Core;
|
using WIDESEA_Core.BaseServices;
|
using WIDESEA_Core.Helper;
|
using WIDESEA_DTO.MES;
|
using WIDESEA_External.MESService;
|
using WIDESEA_External.Model;
|
using WIDESEA_IBasicRepository;
|
using WIDESEA_IInboundRepository;
|
using WIDESEA_IInboundService;
|
using WIDESEA_Model.Models;
|
|
namespace WIDESEA_InboundService
|
{
|
public class MESProInOrderInfoService : ServiceBase<Dt_MESProInOrderInfo, IMESProInOrderInfoRepository>, IMESProInOrderInfoService
|
{
|
public IMESProInOrderInfoRepository Repository => BaseDal;
|
private readonly IBasicRepository _basicRepository;
|
private readonly IAGVStationInfoRepository _agvStationInfoRepository;
|
private readonly IMapper _mapper;
|
private readonly IInvokeMESService _invokeMESService;
|
public MESProInOrderInfoService(IMESProInOrderInfoRepository BaseDal,IBasicRepository basicRepository,IMapper mapper, IAGVStationInfoRepository agvStationInfoRepository,IInvokeMESService invokeMESService) : base(BaseDal)
|
{
|
_basicRepository = basicRepository;
|
_mapper = mapper;
|
_agvStationInfoRepository = agvStationInfoRepository;
|
_invokeMESService = invokeMESService;
|
}
|
|
/// <summary>
|
/// MES工单停止接口
|
/// </summary>
|
/// <summary>
|
public WebResponseContent ReceiveProOrderStop(MESOrderStopDTO orderStopDTO)
|
{
|
WebResponseContent content = new WebResponseContent();
|
try
|
{
|
if (orderStopDTO == null)
|
{
|
return content.Error("传入信息不能为空");
|
}
|
//获取对应单据
|
List<Dt_MESProInOrderInfo>? mESProInOrderInfos = BaseDal.QueryData(x => x.ProductOrderNo == orderStopDTO.ProductOrderNo && x.MESProInStatus != InOrderStatusEnum.关闭.ObjToInt());
|
if (mESProInOrderInfos == null || mESProInOrderInfos.Count <= 0)
|
{
|
return content.Error($"成品或半成品工单{nameof(MESOrderStopDTO.ProductOrderNo)}{orderStopDTO.ProductOrderNo}不存在或已关闭");
|
}
|
mESProInOrderInfos.ForEach(x =>
|
{
|
x.MESProInStatus = InOrderStatusEnum.关闭.ObjToInt();
|
});
|
BaseDal.UpdateData(mESProInOrderInfos);
|
content.OK($"工单{nameof(MESOrderStopDTO.ProductOrderNo)}{orderStopDTO.ProductOrderNo}停止成功");
|
}
|
catch (Exception ex)
|
{
|
content.Error(ex.Message);
|
}
|
return content;
|
}
|
/// <summary>
|
/// MES工单停止接口
|
/// </summary>
|
/// <summary>
|
public WebResponseContent MESBoxCode(string boxCode)
|
{
|
WebResponseContent content = new WebResponseContent();
|
try
|
{
|
if (boxCode.IsNullOrEmpty())
|
{
|
return content.Error("传入信息不能为空");
|
}
|
//获取对应单据
|
Dt_MESProInOrderInfo mESProInOrderInfo = BaseDal.QueryFirst(x => x.BarCode == boxCode);
|
if (mESProInOrderInfo == null)
|
{
|
return content.Error($"成品条码{boxCode}不存在");
|
}
|
if (mESProInOrderInfo.MESProInStatus==InOrderStatusEnum.入库完成.ObjToInt())
|
{
|
return content.Error($"成品条码{boxCode}已入库");
|
}
|
mESProInOrderInfo.MESProInStatus = InOrderStatusEnum.入库完成.ObjToInt();
|
MESResponse response = _invokeMESService.MESBoxCodeNotice(boxCode).DeserializeObject<MESResponse>() ?? throw new Exception("未获取到MES返回信息");
|
if (!response.Result)
|
{
|
throw new Exception($"MES配送出发接口调用报错,MES返回信息{DecodeUnicode(response.Msg)}");
|
}
|
BaseDal.UpdateData(mESProInOrderInfo);
|
content.OK($"成品条码{boxCode}扫码入库");
|
}
|
catch (Exception ex)
|
{
|
content.Error(ex.Message);
|
}
|
return content;
|
}
|
public static string DecodeUnicode(string input)
|
{
|
return Regex.Replace(input, @"\\u([0-9a-fA-F]{4})", match => {
|
return ((char)Convert.ToInt32(match.Groups[1].Value, 16)).ToString();
|
});
|
}
|
}
|
}
|