南骏 池
2 天以前 ed670b6b4a44a11060a7527809c84ff4c32ba6a6
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
using System.Dynamic;
using Azure;
using Microsoft.AspNetCore.Mvc;
using NewPdaSqlServer.Dto.service;
using NewPdaSqlServer.entity;
using NewPdaSqlServer.util;
using Newtonsoft.Json.Linq;
using System.ServiceModel;
using System.IO;
 
namespace NewPdaSqlServer.Controllers.AGV;
 
[Route("api/[controller]")]
[ApiController]
public class AgvApiController : ControllerBase
{
    OaApiService m = new OaApiService();
 
    //在类内添加日志方法
    // private void LogToFile(string methodName, object request, string response)
    //{
    //    string logPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Logs", $"AgvLog_{DateTime.Now:yyyyMMdd}.log");
    //    Directory.CreateDirectory(Path.GetDirectoryName(logPath));
 
    //    string logContent = $"[{DateTime.Now:HH:mm:ss}] 方法:{methodName}\n" +
    //                       $"请求参数:{JObject.FromObject(request)}\n" +
    //                       $"响应结果:{response}\n\n";
 
    //    File.AppendAllText(logPath, logContent);
    //}
 
    // 修改现有方法(以AgvTest为例)
    [HttpPost("AgvTest")]
    public ResponseResult AgvTest(dynamic queryObj)
    {
        try
        {
            var binding = new BasicHttpBinding { /* 原有配置 */ };
            var endpoint = new EndpointAddress("http://192.168.35.251:8000/MesGet");
            var factory = new ChannelFactory<IImesInterface>(binding, endpoint);
            
            var channel = factory.CreateChannel();
            string result = channel.PrintHello();
            ((IClientChannel)channel).Close();
    
            // 记录日志
            //LogToFile(nameof(AgvTest), new { queryObj }, result);
    
            return new ResponseResult { status = 0, message = "OK", data = result };
        }
        catch (Exception ex)
        {
            //LogToFile(nameof(AgvTest), new { queryObj }, $"异常:{ex}");
            return ResponseResult.ResponseError(ex);
        }
    }
 
    //立库送检
    [HttpPost("DefineTask_001")]
    public ResponseResult DefineTask_001(dynamic queryObj)
    {
        try
        {
            var binding = new BasicHttpBinding
            {
                MaxReceivedMessageSize = 10485760, // 10MB
                TextEncoding = System.Text.Encoding.UTF8
            };
 
            var endpoint = new EndpointAddress("http://192.168.35.251:8000/MesGet");
            var factory = new ChannelFactory<IImesInterface>(binding, endpoint);
 
            var channel = factory.CreateChannel();
            string result = channel.DefineTask_001("GS2025070700001","TEST.01","AGV测试物料名称", "AGV测试物料规格",100,"台",1);
            ((IClientChannel)channel).Close();
 
            return new ResponseResult
            {
                status = 0,
                message = "OK",
                data = result
            };
        }
        catch (Exception ex)
        {
            return ResponseResult.ResponseError(ex);
        }
    }
 
    //立库检验
    [HttpPost("DefineTask_002")]
    public ResponseResult DefineTask_002(dynamic queryObj)
    {
        try
        {
            var binding = new BasicHttpBinding
            {
                MaxReceivedMessageSize = 10485760, // 10MB
                TextEncoding = System.Text.Encoding.UTF8
            };
 
            var endpoint = new EndpointAddress("http://192.168.35.251:8000/MesGet");
            var factory = new ChannelFactory<IImesInterface>(binding, endpoint);
 
            var channel = factory.CreateChannel();
            string result = channel.DefineTask_002("GS2025070900010", "合格");
            ((IClientChannel)channel).Close();
 
            return new ResponseResult
            {
                status = 0,
                message = "OK",
                data = result
            };
        }
        catch (Exception ex)
        {
            return ResponseResult.ResponseError(ex);
        }
    }
 
    //立库呼叫
    [HttpPost("DefineTask_005")]
    public ResponseResult DefineTask_005(dynamic queryObj)
    {
        try
        {
            var binding = new BasicHttpBinding
            {
                MaxReceivedMessageSize = 10485760, // 10MB
                TextEncoding = System.Text.Encoding.UTF8
            };
 
            var endpoint = new EndpointAddress("http://192.168.35.251:8000/MesGet");
            var factory = new ChannelFactory<IImesInterface>(binding, endpoint);
 
            var channel = factory.CreateChannel();
            string result = channel.DefineTask_005();
            ((IClientChannel)channel).Close();
 
            return new ResponseResult
            {
                status = 0,
                message = "OK",
                data = result
            };
        }
        catch (Exception ex)
        {
            return ResponseResult.ResponseError(ex);
        }
    }
 
 
    //立库入库
    [HttpPost("DefineTask_006")]
    public ResponseResult DefineTask_006(dynamic queryObj)
    {
        try
        {
            var binding = new BasicHttpBinding
            {
                MaxReceivedMessageSize = 10485760, // 10MB
                TextEncoding = System.Text.Encoding.UTF8
            };
 
            var endpoint = new EndpointAddress("http://192.168.35.251:8000/MesGet");
            var factory = new ChannelFactory<IImesInterface>(binding, endpoint);
 
            var channel = factory.CreateChannel();
            string result = channel.DefineTask_006("C2025070400040", "2.02.51.463", "管线饮水机", "C638-1HA(万和VGX-SR-1A-XM白)", 48, "台", 4);
            ((IClientChannel)channel).Close();
 
            return new ResponseResult
            {
                status = 0,
                message = "OK",
                data = result
            };
        }
        catch (Exception ex)
        {
            return ResponseResult.ResponseError(ex);
        }
    }
 
 
 
}
 
// 在类外部添加服务契约接口
[ServiceContract(Namespace = "http://tempuri.org/")]
public interface IImesInterface
{
    [OperationContract(Action = "http://tempuri.org/ImesInterface/PrintHello", 
                      ReplyAction = "http://tempuri.org/ImesInterface/PrintHelloResponse")]
    string PrintHello();
 
    //立库送检
    [OperationContract(Action = "http://tempuri.org/ImesInterface/DefineTask_001",
              ReplyAction = "http://tempuri.org/ImesInterface/DefineTask_001Response")]
    string DefineTask_001(string MesId, string MatId, string MatName, string MatStandard, int MatNumber, string MatUnit, int Postition);
 
    //立库检验
    [OperationContract(Action = "http://tempuri.org/ImesInterface/DefineTask_002",
          ReplyAction = "http://tempuri.org/ImesInterface/DefineTask_002Response")]
    string DefineTask_002(string MesId, string MatStatus);
 
    //立库呼叫
    [OperationContract(Action = "http://tempuri.org/ImesInterface/DefineTask_005",
                  ReplyAction = "http://tempuri.org/ImesInterface/DefineTask_005Response")]
    string DefineTask_005();
 
    //立库入库
    [OperationContract(Action = "http://tempuri.org/ImesInterface/DefineTask_006",
              ReplyAction = "http://tempuri.org/ImesInterface/DefineTask_006Response")]
    string DefineTask_006(string MesId,string MatId,string MatName,string MatStandard,int MatNumber,string MatUnit,int Postition);
}