服务端的TigerApi 框架,基于.NET6 2024 版本
Ben Lin
2025-04-12 b57fb8b61bd053601035694470ac4e79fbf99bf8
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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
using Rhea.Common;
using System.Net;
using System.Linq;
using Newtonsoft.Json;
using Tiger.IBusiness;
using Tiger.Model.Entitys.MES.U9C;
 
namespace Tiger.Business.WMS
{
    public partial class WMS_U9C : IWMS_U9C
    {
        public static string U9CAuthLoginUrl { get; set; } = ApiConfig.IsTestServer ? Cache.SysParam["U9CAuthLoginUrl_Test", "U9CUrl"].PARAM_VALUE : Cache.SysParam["U9CAuthLoginUrl", "U9CUrl"].PARAM_VALUE; // "http://172.16.80.20/U9C/webapi/OAuth2/AuthLogin?"; 测试
        //public static string U9CAuthLoginUrl { get; set; } = Cache.SysParam["U9CAuthLoginUrl", "U9CUrl"].PARAM_VALUE; //正式
        public static string secret = "&entcode=02&orgcode=101&clientid=mes&clientsecret=12c8ee7e9bb74ad2a6a0fb3315c8af20";
        /// <summary>
        /// 审核人
        /// </summary>
        public static string Reviewer = Cache.SysParam["Reviewer", "U9CUrl"].PARAM_VALUE; 
        public static string CreateRcvBySrcASNUrl
        { get; set; } = "http://172.16.80.20/U9C/webapi/Receivement/CreateRcvBySrcASN"; //ApiConfig.IsTestServer ? Cache.SysParam["CreateRcvBySrcASNUrl_Test", "U9CUrl"].PARAM_VALUE : Cache.SysParam["CreateRcvBySrcASNUrl", "U9CUrl"].PARAM_VALUE;  //"http://172.16.80.20/U9C/webapi/Receivement/CreateRcvBySrcASN"; 测试
        public static string CreateReceivementUrl
        { get; set; } = "http://172.16.80.20/U9C/webapi/Receivement/CreateReceivement"; // ApiConfig.IsTestServer ? Cache.SysParam["CreateReceivementUrl_Test", "U9CUrl"].PARAM_VALUE : Cache.SysParam["CreateReceivementUrl", "U9CUrl"].PARAM_VALUE;  //"http://172.16.80.20/U9C/webapi/Receivement/CreateReceivement"; 测试
        public static string SubmitLineUrl
        { get; set; } = "http://172.16.80.20/u9c/webapi/Receivement/SubmitLine";  // ApiConfig.IsTestServer ? Cache.SysParam["SubmitLineUrl_Test", "U9CUrl"].PARAM_VALUE : Cache.SysParam["SubmitLineUrl", "U9CUrl"].PARAM_VALUE;  //http://172.16.80.20/u9c/webapi/Receivement/SubmitLine; 测试
        public static string ApproveLineUrl
        { get; set; } = "http://172.16.80.20/u9c/webapi/Receivement/ApproveLine"; // ApiConfig.IsTestServer ? Cache.SysParam["ApproveLineUrl_Test", "U9CUrl"].PARAM_VALUE : Cache.SysParam["ApproveLineUrl", "U9CUrl"].PARAM_VALUE;  //http://172.16.80.20/u9c/webapi/Receivement/ApproveLine; 测试
        /// <summary>
        /// 创建生产退料单-按行退料
        /// </summary>
        public static string CreateProdReturnOrderNewUrl
        { get; set; } = "http://172.16.80.20/u9c/webapi/IssueDoc/CreateRecedeIssueDocNew"; // ApiConfig.IsTestServer ? Cache.SysParam["CreateProdReturnOrderUrl_Test", "U9CUrl"].PARAM_VALUE : Cache.SysParam["CreateProdReturnOrderUrl", "U9CUrl"].PARAM_VALUE; //http://172.16.80.20/u9c/webapi/IssueDoc/CreateRecedeIssueDocNew
        /// <summary>
        /// 创建委外生产退料单
        /// </summary>
        public static string CreateOutProdReturnOrderUrl
        { get; set; } = "http://172.16.80.20/u9c/webapi/PMIssueDoc/CreateRecedeIssueDoc"; // ApiConfig.IsTestServer ? Cache.SysParam["CreateOutProdReturnOrderUrl_Test", "U9CUrl"].PARAM_VALUE : Cache.SysParam["CreateOutProdReturnOrderUrl", "U9CUrl"].PARAM_VALUE; //http://172.16.80.20/u9c/webapi/PMIssueDoc/CreateRecedeIssueDoc
        /// <summary>
        /// 创建调入单
        /// </summary>
        public static string CreateTransferInUrl
        { get; set; } = "http://172.16.80.20/u9c/webapi/TransferIn/Create"; // ApiConfig.IsTestServer ? Cache.SysParam["CreateTransferInUrl_Test", "U9CUrl"].PARAM_VALUE : Cache.SysParam["CreateTransferInUrl", "U9CUrl"].PARAM_VALUE; //http://172.16.80.20/u9c/webapi/TransferIn/Create
 
        
        /// <summary>
        /// 新增收货单-来源ASN单接口
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task<ApiAction<List<U9CReturnData2>>> CreateRcvBySrcASN(CreateRcvBySrcASNInput input)
        {
            Logger.Interface.Info($"/**\r\n *进入新增收货单-来源ASN单接口....\r\n */\r\n"); //固定写法
            var action = new ApiAction<List<U9CReturnData2>>();
            try
            {
                //如果已经登录则不需要再次登录,直接使用传入的token
                if (input.IsLogin)
                {
                    var u9CLoginResult = await HttpHelper.GetAsync<U9CLoginResult>($"{U9CAuthLoginUrl}userCode={input.userId}{secret}");
                    if (u9CLoginResult.Success)
                    {
                        input.token = u9CLoginResult.Data;
                        Logger.Interface.Info($"U9C登录token: {input.token}");
                    }
                }
                List<CreateRcvBySrcASNParam> param = new();
                param.Add(input.CreateRcvBySrcASNParam);
                var response = await HttpHelper.PostAsync(CreateRcvBySrcASNUrl, JsonConvert.SerializeObject(param), new Dictionary<string, string>() { { "token", input.token } });
                //var response = new ApiAction("{\"ResCode\":0,\"Success\":true,\"ResMsg\":null,\"Data\":[{\"IsSucess\":true,\"U9CVersion\":null,\"OtherID\":\"WMS\",\"ID\":1002503210000100,\"Code\":\"YDRC250300003\",\"ErrorMsg\":null}]}");
 
                var result = JsonConvert.DeserializeObject<U9CResult2>(response.Message);
                if (result != null)
                {
                    if (result.Success && result.Data[0].IsSucess)
                    {
                        action.Data = result.Data;
                       Logger.Interface.Info($"新增收货单-来源ASN单接口提交Json: {JsonConvert.SerializeObject(param)},返回Json: {response.Message}");
                    }
                    else
                    {
                        action.IsSuccessed = false;
                        action.LocaleMsg = new($"{action.Message}; {result.Data[0].ErrorMsg}");
                        Logger.Interface.Info($"新增收货单-来源ASN单失败,提交Json: {JsonConvert.SerializeObject(param)},错误信息:{result.Data[0].ErrorMsg}");
                    }
                }
            }
            catch (System.Exception ex)
            {
                action.CatchExceptionWithLog(ex, "新增收货单-来源ASN单异常");
            }
            Logger.Interface.Info($"/* 新增收货单-来源ASN单接口结束 */\r\n"); //固定写法
            return action;
        }
 
        /// <summary>
        /// 新增收货单-无来源接口
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task<ApiAction<List<U9CReturnData2>>> CreateReceivement(CreateReceivementInput input)
        {
            Logger.Interface.Info($"/**\r\n *进入新增收货单-无来源接口....\r\n */\r\n"); //固定写法
            var action = new ApiAction<List<U9CReturnData2>>();
            try
            {
                //如果已经登录则不需要再次登录,直接使用传入的token
                if (input.IsLogin)
                {
                    var u9CLoginResult = await HttpHelper.GetAsync<U9CLoginResult>($"{U9CAuthLoginUrl}userCode={input.userId}{secret}");
                    if (u9CLoginResult.Success)
                    {
                        input.token = u9CLoginResult.Data;
                        Logger.Interface.Info($"U9C登录token: {input.token}");
                    }
                }
 
                var response = await HttpHelper.PostAsync(CreateReceivementUrl, JsonConvert.SerializeObject(input.CreateReceivementParam), new Dictionary<string, string>() { { "token", input.token } });
                var result = JsonConvert.DeserializeObject<U9CResult2>(response.Message);
                if (result != null)
                {
                    if (result.Success && result.Data[0].IsSucess)
                    {
                        action.Data = result.Data;
                        Logger.Interface.Info($"新增收货单-无来源接口提交Json: {JsonConvert.SerializeObject(input.CreateReceivementParam)},返回Json: {response.Message}");
                    }
                    else
                    {
                        action.IsSuccessed = false;
                        action.LocaleMsg = new($"{action.Message}; {result.Data[0].ErrorMsg}");
                        Logger.Interface.Info($"新增收货-单无来源失败,提交Json: {JsonConvert.SerializeObject(input.CreateReceivementParam)},错误信息:{result.Data[0].ErrorMsg}");
                    }
                }
            }
            catch (System.Exception ex)
            {
                action.CatchExceptionWithLog(ex, $"新增收货单-无来源异常,提交Json: {JsonConvert.SerializeObject(input.CreateReceivementParam)}");
            }
            Logger.Interface.Info($"/* 新增收货单-无来源接口结束 */\r\n"); //固定写法
            return action;
        }
 
        /// <summary>
        /// 收货单-行审核总入口接口
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task<ApiAction<List<U9CReturnData2>>> ReceivementApproveLine(SubmitLineInput input) {
            Logger.Interface.Info($"/**\r\n *进入收货单-行审核总入口接口....\r\n */\r\n"); //固定写法
            var action = new ApiAction<List<U9CReturnData2>>();
            try
            {
                //action = await SubmitLine(input);
                //if (action.IsSuccessed) {
                //    input.IsLogin = false;
                //    action = await ApproveLine(input);
                //}
                action = await ApproveLine(input);
            }
            catch (System.Exception ex)
            {
                action.CatchExceptionWithLog(ex, "收货单-行审核总入口异常");
            }
            Logger.Interface.Info($"/* 收货单-行审核总方法接口结束 */\r\n"); //固定写法
            return action;
        }
 
        /// <summary>
        /// 收货单-行提交
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        private async Task<ApiAction<List<U9CReturnData2>>> SubmitLine(SubmitLineInput input)
        {
            Logger.Interface.Info($"/**\r\n *进入收货单-行提交接口....\r\n */\r\n"); //固定写法
            var action = new ApiAction<List<U9CReturnData2>>();
            try
            {
                //如果已经登录则不需要再次登录,直接使用传入的token
                if (input.IsLogin)
                {
                    var u9CLoginResult = await HttpHelper.GetAsync<U9CLoginResult>($"{U9CAuthLoginUrl}userCode={input.userId}{secret}");
                    if (u9CLoginResult.Success)
                    {
                        input.token = u9CLoginResult.Data;
                        Logger.Interface.Info($"U9C登录token: {input.token}");
                    }
                }
                var _params = new List<SubmitLineInputParam>();
                _params.Add(input.param);
                var response = await HttpHelper.PostAsync(SubmitLineUrl, JsonConvert.SerializeObject(_params), new Dictionary<string, string>() { { "token", input.token } });
                var result = JsonConvert.DeserializeObject<U9CResult2>(response.Message);
                if (result != null)
                {
                    if (result.Success && result.Data[0].IsSucess)
                    {
                        action.Data = result.Data;
                        Logger.Interface.Info($"收货单-行提交接口提交Json: {JsonConvert.SerializeObject(_params)},返回Json: {response.Message}");
                    }
                    else
                    {
                        action.IsSuccessed = false;
                        action.LocaleMsg = new($"收货单-行提交接口失败: {result.Data[0].ErrorMsg}");
                        Logger.Interface.Info($"收货单-行提交接口失败:{result.Data[0].ErrorMsg}");
                    }
                }
            }
            catch (System.Exception ex)
            {
                action.CatchExceptionWithLog(ex, "收货单-行提交异常");
            }
            Logger.Interface.Info($"/* 收货单-行提交接口结束 */\r\n"); //固定写法
            return action;
        }
 
        /// <summary>
        /// 收货单-行审核
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        private async Task<ApiAction<List<U9CReturnData2>>> ApproveLine(SubmitLineInput input)
        {
            Logger.Interface.Info($"/**\r\n *进入收货单-行审核接口....\r\n */\r\n"); //固定写法
            var action = new ApiAction<List<U9CReturnData2>>();
            try
            {
                //如果已经登录则不需要再次登录,直接使用传入的token
                if (input.IsLogin)
                {
                    var u9CLoginResult = await HttpHelper.GetAsync<U9CLoginResult>($"{U9CAuthLoginUrl}userCode={Reviewer}{secret}");
                    if (u9CLoginResult.Success)
                    {
                        input.token = u9CLoginResult.Data;
                        Logger.Interface.Info($"U9C登录token: {input.token}");
                    }
                }
                var _params = new List<SubmitLineInputParam>();
                _params.Add(input.param);
                var response = await HttpHelper.PostAsync(ApproveLineUrl, JsonConvert.SerializeObject(_params), new Dictionary<string, string>() { { "token", input.token } });
                var result = JsonConvert.DeserializeObject<U9CResult2>(response.Message);
                if (result != null)
                {
                    if (result.Success && result.Data[0].IsSucess)
                    {
                        action.Data = result.Data;
                        Logger.Interface.Info($"收货单-行审核接口提交Json: {JsonConvert.SerializeObject(_params)},返回Json: {response.Message}");
                    }
                    else
                    {
                        action.IsSuccessed = false;
                        action.LocaleMsg = new($"收货单 - 行审核接口失败:{result.Data[0].ErrorMsg}");
                        Logger.Interface.Info($"收货单-行审核接口提交Json: {JsonConvert.SerializeObject(_params)},失败:{result.Data[0].ErrorMsg}");
                    }
                }
            }
            catch (System.Exception ex)
            {
                action.CatchExceptionWithLog(ex, "收货单-行审核异常");
            }
            Logger.Interface.Info($"/* 收货单-行审核接口结束 */\r\n"); //固定写法
            return action;
        }
    }
}