schangxiang@126.com
2025-09-04 e9269528ae01bc4572b68148b9c801b51f23b669
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
using iWareCommon.Utils;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using yunneiWCS.EnumDefine;
using yunneiWCS.ExtendFunction;
using yunneiWCS.SystemInteraction.mes2.dto;
using static WZ.Useful.Commons.NativeMethods;
 
namespace yunneiWCS.mes
{
    /// <summary>
    /// MES推送接口
    /// </summary>
    public class PushMesHandler
    {
        public static string mes_api_url = ConfigHelper.GetConfigString("MesUrl");//修改为配置文件 【EditBy shaocx,2022-01-27】
        static HTTPService mes_api = new HTTPService(mes_api_url);//mes基地址
 
        /// <summary>
        /// 给MES推送入库信息
        /// </summary>
        /// <param name="pushData"></param>
        /// <returns></returns>
        public static mesMsg Mes_InStockSend(List<InboundStockInfoToMes> pushData, LogType _logType)
        {
            mesMsg res = null;
            var funName = "Mes_InStockSend";
            try
            {
                MesRequest<List<InboundStockInfoToMes>> mesRequest = new MesRequest<List<InboundStockInfoToMes>>();
                mesRequest.Datas = pushData;
                mesRequest.TableName = "T_WMS_Inbound_Record";
                mesRequest.PrimaryKeys = "identifier";
 
                string paprm = JsonConvert.SerializeObject(mesRequest);
                Log4NetHelper.WriteInfoLog(_logType, $"{funName},准备参数:{paprm}");
                Guid guid = System.Guid.NewGuid();
 
                //模拟
                if (Form1.isvirtual)
                {//模拟环境
                    res = new mesMsg();
                    res.ErrorCode = 0;
                    res.ErrorMsg = "系统模拟完成";
                }
                else
                {
                    var resStr = mes_api.postContentForString("", paprm, guid);
                    Log4NetHelper.WriteInfoLog(_logType, $"{funName},结果返回:{resStr}");
                    res = JsonConvert.DeserializeObject<mesMsg>(resStr);
                }
 
                Log4NetHelper.WriteInfoLog(_logType, $"{funName},参数:{paprm},返回:{JsonConvert.SerializeObject(res)}");
            }
            catch (Exception ex)
            {
                Log4NetHelper.WriteErrorLog(_logType, $"{funName},异常:" + ex.Message, ex);
                res.ErrorCode = 4;
                res.ErrorMsg = "wms发送异常:" + ex.Message;
            }
            return res;
 
        }
 
 
        /// <summary>
        /// 给MES推送出库信息
        /// </summary>
        /// <param name="pushData"></param>
        /// <returns></returns>
        public static mesMsg Mes_OutStockSend(List<InboundStockInfoToMes> pushData, LogType _logType)
        {
            mesMsg res = null;
            var funName = "Mes_OutStockSend";
            try
            {
                MesRequest<List<InboundStockInfoToMes>> mesRequest = new MesRequest<List<InboundStockInfoToMes>>();
                mesRequest.Datas = pushData;
                mesRequest.TableName = "T_WMS_Outbound_Record";
                mesRequest.PrimaryKeys = "identifier";
 
                string paprm = JsonConvert.SerializeObject(mesRequest);
                Log4NetHelper.WriteInfoLog(_logType, $"{funName},准备参数:{paprm}");
                Guid guid = System.Guid.NewGuid();
                //模拟
                if (Form1.isvirtual)
                {//模拟环境
                    res = new mesMsg();
                    res.ErrorCode = 0;
                    res.ErrorMsg = "系统模拟完成";
                }
                else
                {
                    var resStr = mes_api.postContentForString("", paprm, guid);
                    Log4NetHelper.WriteInfoLog(_logType, $"{funName},结果返回:{resStr}");
                    res = JsonConvert.DeserializeObject<mesMsg>(resStr);
                }
 
                Log4NetHelper.WriteInfoLog(_logType, $"{funName},参数:{paprm},返回:{JsonConvert.SerializeObject(res)}");
            }
            catch (Exception ex)
            {
                Log4NetHelper.WriteErrorLog(_logType, $"{funName},异常:" + ex.Message, ex);
                res.ErrorCode = 4;
                res.ErrorMsg = "wms发送异常:" + ex.Message;
            }
            return res;
 
        }
 
 
        /// <summary>
        /// 给MES推送库存信息
        /// </summary>
        /// <param name="pushData"></param>
        /// <returns></returns>
        public static mesMsg Mes_StockSend(List<InboundStockInfoToMes> pushData, LogType _logType)
        {
            mesMsg res = null;
            var funName = "Mes_StockSend";
            try
            {
                MesRequest<List<InboundStockInfoToMes>> mesRequest = new MesRequest<List<InboundStockInfoToMes>>();
                mesRequest.Datas = pushData;
                mesRequest.TableName = "T_WMS_Realtime_Data";
                mesRequest.PrimaryKeys = "serialNumber,positionName";
 
                string paprm = JsonConvert.SerializeObject(mesRequest);
                Guid guid = System.Guid.NewGuid();
                Log4NetHelper.WriteInfoLog(_logType, $"{funName},准备参数:{paprm}");
                //模拟
                if (Form1.isvirtual)
                {//模拟环境
                    res = new mesMsg();
                    res.ErrorCode = 0;
                    res.ErrorMsg = "系统模拟完成";
                }
                else
                {
                    var resStr = mes_api.postContentForString("", paprm, guid);
                    Log4NetHelper.WriteInfoLog(_logType, $"{funName},结果返回:{resStr}");
                    res = JsonConvert.DeserializeObject<mesMsg>(resStr);
                }
 
 
                Log4NetHelper.WriteInfoLog(_logType, $"{funName},参数:{paprm},返回:{JsonConvert.SerializeObject(res)}");
            }
            catch (Exception ex)
            {
                Log4NetHelper.WriteErrorLog(_logType, $"{funName},异常:" + ex.Message, ex);
                res.ErrorCode = 4;
                res.ErrorMsg = "wms发送异常:" + ex.Message;
            }
            return res;
 
        }
    }
}