schangxiang@126.com
2025-09-18 49a51c068d62084bc4c3e77c4be94a20de556c4a
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
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Security.Cryptography;
using System.Web.Http;
using siemensPda.ORM;
using logtxtWrite;
using Newtonsoft.Json;
using siemensPda.Models;
 
namespace siemensPda.Controllers
{
    public class pdaController : ApiController
    {
        // sendToSap.ISapWcfService
        sendToSap.IapitestClient wmsApi = new sendToSap.IapitestClient();
        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="loginInfo"></param>
        /// <returns></returns>
        [HttpPost]
        public msgs login([FromBody]user loginInfo)
        {
            msgs meta = new msgs();
            try
            {
                using (dbModel mod = new dbModel())
                {
 
                    var logUser = mod.Sys_User.FirstOrDefault(x => x.UserName == loginInfo.UserName);
                    // var logUser = users.FirstOrDefault(x => x.UserName == loginInfo.UserName);
                    if (logUser != null)
                    {
 
 
                        string password = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(loginInfo.PassWord + "{MINGpin365}", "MD5").ToLower();
                        // if (logUser.UserPwd == password) 
                        if (logUser.UserPwd == password)
                        {
                            meta.msg = "登录成功";
                            meta.status = 200;
                            meta.token = Encode(loginInfo.UserName + loginInfo.PassWord);
                        }
                        else
                        {
                            meta.msg = "密码错误";
                            meta.status = 400;
                            logtxt.txtWrite("类名:pdaController/函数名:login密码错误 用户名:" + loginInfo.UserName + " 密码:" + loginInfo.PassWord, 2);
                        }
                    }
                    else
                    {
                        meta.msg = "无此用户";
                        meta.status = 400;
                        logtxt.txtWrite("类名:pdaController/函数名:login无此用户  用户名:" + loginInfo.UserName + " 密码:" + loginInfo.PassWord, 2);
                    }
 
                }
            }
            catch (Exception)
            {
                logtxt.txtWrite("类名:pdaController/函数名:login登录异常  用户名:" + loginInfo.UserName + " 密码:" + loginInfo.PassWord, 2);
            }
 
            return meta;
        }
        /// <summary>
        /// 分拣信息
        /// </summary>
        /// <param name="sortingInfos"></param>
        /// <returns></returns>
 
        [HttpPost]
        public msgs sortingConfirm([FromBody]sorting sortingInfos)
        {
            msgs meta = new msgs();
            string Products = "";
            try
            {
 
                logtxt.txtWrite("类名:pdaController/函数名:sortingConfirm ,PDA接受完整数据: " + JsonConvert.SerializeObject(sortingInfos), 0);
                if (sortingInfos != null)
                {
                    List<sortingType> plates = new List<sortingType>();
 
                    //判断托盘号是否为空
                    if (!string.IsNullOrEmpty(sortingInfos.plateCode))
                    {
                        using (dbModel mod = new dbModel())
                        {
                            //判断分拣物料数据不能为空
                            if (sortingInfos.plates.Count > 0)
                            {
 
                                foreach (var item in sortingInfos.plates)
                                {
 
                                    sortingType plate = new sortingType();//moveMaterials
                                    //找到物料ID  可以改成物料编号少读一个表
                                    Base_ProductInfo material = mod.Base_ProductInfo.FirstOrDefault(x => x.ProductCode == item.materialCode);
                                    if (material != null)
                                    {
                                        plate.product_Id = (int)material.Product_Id;
                                        plate.finishedQuantity = Convert.ToDecimal(item.pickQty);
                                        plate.trankNumber = item.trankingNumber;
                                        plate.creator = sortingInfos.creator;
                                        plates.Add(plate);
                                    }
                                }
                                //转换成字符串
                                Products = JsonConvert.SerializeObject(plates);
 
                                string result = wmsApi.sortingConfirm(sortingInfos.plateCode, Products, sortingInfos.percentage);
                                resultMsg resultinfo = JsonConvert.DeserializeObject<resultMsg>(result);
                                if (resultinfo != null)
                                {
                                    if (resultinfo.result)
                                    {
                                        meta.status = 200;
                                        meta.msg = resultinfo.msg;
                                    }
                                    else
                                    {
                                        meta.status = 400;
                                        meta.msg = resultinfo.msg;
                                    }
                                }
                                //*/
 
                                logtxt.txtWrite("类名:pdaController/函数名:sortingConfirm ,PDA接受数据: " + Products, 0);
                            }
                            else
                            {
                                meta.status = 400;
                                meta.msg = "分拣数量不能为空";
                                logtxt.txtWrite("类名:pdaController/函数名:sortingConfirm ,PDA分拣数量为空: " + Products, 2);
                            }
 
                        }
 
                    }
                    else
                    {
                        meta.status = 400;
                        meta.msg = "托盘号不能为空";
                        logtxt.txtWrite("类名:pdaController/函数名:sortingConfirm ,PDA托盘号不能为空: " + Products, 2);
                    }
 
                }
                else
                {
                    meta.status = 400;
                    meta.msg = "参数为空";
                    logtxt.txtWrite("类名:pdaController/函数名:sortingConfirm ,PDA参数为空: " + Products, 2);
                }
            }
            catch (Exception ex)
            {
                logtxt.txtWrite("类名:pdaController/函数名:sortingConfirm 分拣异常,接受数据: " + Products + "异常信息:" + ex.Message, 2);
            }
            return meta;
        }
        /// <summary>
        /// 获取托盘信息
        /// </summary>
        /// <param name="plateInfo"></param>
        /// <returns></returns>
        [HttpPost]
        public IHttpActionResult getPlateInfo([FromBody]plate plateInfo)
        {
            msgs meta = new msgs();
            if (string.IsNullOrEmpty(plateInfo.plateCode))
            {
                meta.status = 400;
                meta.msg = "此托盘号不能为空";
                return Json(meta);
            }
            string plateCode = plateInfo.plateCode;
            List<plateInfo> materials = new List<plateInfo>();
 
            try
            {
                using (dbModel mod = new dbModel())
                {
                    List<Base_ProductPosition> plateMaterial = mod.Base_ProductPosition.Where(x => x.PlateCode == plateCode).ToList();
                    if (plateMaterial.Count == 0)
                    {
                        meta.status = 400;
                        meta.msg = "不需要分拣";
                        return Json(meta);
                    }
                    //获取库位的空间占比 [EditBy shaocx,2022-10-15]
                    var queryPositionName = plateMaterial.First().PositionName;
                    Base_Position position = mod.Base_Position.Where(x => x.PositionName == queryPositionName).First();
                    foreach (var item in plateMaterial)
                    {
                        plateInfo info = new plateInfo();
                        if (position.PositionLength == null)
                        {
                            info.positionLength = 100;//默认空间比是100
                        }
                        else
                        {
                            info.positionLength = Convert.ToDecimal(position.PositionLength);
                        }
 
                        info.materialCode = item.ProductCode;
                        info.materialName = item.ProductName;
                        info.moveType = item.Remark;
 
                        info.saleCode = item.SaleCode;
                        decimal stockqty = 0M;
                        try
                        {
                            stockqty = Convert.ToDecimal(item.ExtendField02);
                        }
                        catch (Exception)
                        {
                            stockqty = 0M;
                        }
                        info.pickQty = stockqty;
                        info.stockQty = (decimal)item.ProductStorage;
                        info.trankingNumber = item.ExtendField04;
                        info.unit = item.ExtendField05;
                        materials.Add(info);
                    }
                }
 
 
                meta.status = 200;
 
                meta.materials = materials;
                meta.msg = "获取成功";
            }
            catch (Exception)
            {
 
                throw;
            }
 
 
            return Json(meta);
 
        }
        /// <summary>
        /// 转换成token
        /// </summary>
        /// <param name="data">用户名加密码</param>
        /// <returns>返回用户名加密码的token</returns>
        private string Encode(string data)
        {
            byte[] byKey = System.Text.ASCIIEncoding.ASCII.GetBytes("qwertyui");
            byte[] byIV = System.Text.ASCIIEncoding.ASCII.GetBytes("qwertyui");
 
            DESCryptoServiceProvider cryptoProvider = new DESCryptoServiceProvider();
            int i = cryptoProvider.KeySize;
            MemoryStream ms = new MemoryStream();
            CryptoStream cst = new CryptoStream(ms, cryptoProvider.CreateEncryptor(byKey, byIV), CryptoStreamMode.Write);
            StreamWriter sw = new StreamWriter(cst);
            sw.Write(data);
            sw.Flush();
            cst.FlushFinalBlock();
            sw.Flush();
 
            return Convert.ToBase64String(ms.GetBuffer(), 0, (int)ms.Length);
 
        }
 
    }
    public class msgs
    {
        /// <summary>
        /// 状态
        /// </summary>
        public int status { get; set; }
        /// <summary>
        /// 返回信息
        /// </summary>
        public string msg { get; set; }
        /// <summary>
        /// 物料信息
        /// </summary>
        public List<plateInfo> materials { get; set; }
        /// <summary>
        /// token
        /// </summary>
        public string token { get; set; }
    }
 
    public class user
    {
        /// <summary>
        /// 用户名
        /// </summary>
        public string UserName { get; set; }
        /// <summary>
        /// 密码
        /// </summary>
        public string PassWord { get; set; }
    }
 
    public class sorting
    {
        public string creator { get; set; }
        public List<plateInfo> plates { get; set; }
        public string plateCode { get; set; }
        /// <summary>
        /// 百分比
        /// </summary>
        public string percentage { get; set; }
 
    }
    public class plateInfo
    {
 
        /// <summary>
        /// 销售单号
        /// </summary>
        public string saleCode { get; set; }
 
        /// <summary>
        /// 跟踪号
        /// </summary>
        public string trankingNumber { get; set; }
        /// <summary>
        /// 物料名称
        /// </summary>
        public string materialName { get; set; }
        /// <summary>
        /// 物料编号
        /// </summary>
        public string materialCode { get; set; }
        /// <summary>
        /// 移动类型
        /// </summary>
        public string moveType { get; set; }
        /// <summary>
        /// 库存单位
        /// </summary>
        public string unit { get; set; }
        /// <summary>
        /// 库存总数
        /// </summary>
        public decimal stockQty { get; set; }
        /// <summary>
        /// 分拣数量
        /// </summary>
        public decimal pickQty { get; set; }
 
        /// <summary>
        /// 占用空间 [EditBy shaocx,2022-10-15]
        /// </summary>
        public decimal positionLength { get; set; }
 
    }
    public class sortingType
    {
        //产品ID
        public int product_Id { get; set; }
        //完成数量
        public decimal finishedQuantity { get; set; }
        //跟踪号
        public string trankNumber { get; set; }
 
        public string creator { get; set; }
    }
    public class plate
    {
        /// <summary>
        /// 托盘编号
        /// </summary>
        public string plateCode { get; set; }
    }
}