liulijun
2025-11-24 9086b238cd9fbb9fbeae7cab11d59576cd9d2853
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
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();
            });
        }
    }
}