陈勇
2026-04-06 9de6c7c6d835ba5161d64114d154bfc7676244a1
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
using AngleSharp.Common;
using Masuit.Tools;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WIDESEA_Common;
using WIDESEA_Common.MES;
using WIDESEA_Common.MES.Request;
using WIDESEA_Core;
using WIDESEA_Core.Const;
using WIDESEA_Core.Helper;
using WIDESEAWCS_BasicInfoService;
using WIDESEAWCS_Model.Models;
 
namespace WIDESEA_StoragIntegrationServices
{
    /// <summary>
    /// 锁车上报
    /// </summary>
    public partial class MESService
    {
        public WebResponseContent Lock(object jsondata)
        {
            WebResponseContent content = new WebResponseContent();
            try
            {
                var configs = _configService.GetConfigsByCategory(CateGoryConst.CONFIG_SYS_MESIPAddress);
                var wmsBase = configs.FirstOrDefault(x => x.ConfigKey == SysConfigConst.MESIPAddress)?.ConfigValue;
                var ipAddress = configs.FirstOrDefault(x => x.ConfigKey == SysConfigConst.bindWorkOrder)?.ConfigValue;
                if (wmsBase == null || ipAddress == null)
                {
                    throw new InvalidOperationException("WMS IP 未配置");
                }
                var wmsIpAddress = wmsBase + ipAddress;
 
                var carBodyInfo = _carBodyRepository.QueryFirst(x => x.RFID == "");
 
                if (carBodyInfo == null) throw new Exception($"未找到PVI的车身数据");
 
                BindWorkOrder bindOrder = new BindWorkOrder()
                {
                    unionKey = Guid.NewGuid().ToString(),
                    stationCode = "",
                    messageTime = DateTime.Now.ToString(),
                    plantCode = "1052",
                    pvi = carBodyInfo.PVI,
                };
 
                var MESrespon = HttpHelper.PostAsync(wmsIpAddress, bindOrder.ToJson(), contentType, headers).Result;
 
                Console.WriteLine(MESrespon);
                WebResponseContent webResponse = JsonConvert.DeserializeObject<WebResponseContent>(MESrespon.ToString());
                if (webResponse.Code != 200)
                {
                    throw new Exception($"{webResponse.msg}");
                }
 
                BindWorkOrderRespon characterRespon = JsonConvert.DeserializeObject<BindWorkOrderRespon>(webResponse.Data.ToJson());
 
                _unitOfWorkManage.BeginTran();
 
                LogFactory.GetLog("锁车上报").Info(true, $"\r\r--------------------------------------");
                LogFactory.GetLog("锁车上报").Info(true, jsondata.ToJsonString());
 
                _unitOfWorkManage.CommitTran();
                return content.OK();
            }
            catch (Exception ex)
            {
                return content.Error(ex.Message);
            }
        }
    }
}