刘磊
2026-01-22 1924bdeca6414b6fec314c37260b44f20865d593
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
using AngleSharp.Common;
using Newtonsoft.Json;
using OfficeOpenXml.ConditionalFormatting;
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 bindWorkOrder(string stationNo, string rfid)
        {
            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 stationInfo = _stationManagerRepository.QueryFirst(x => x.stationChildCode == stationNo);
 
                var carBodyInfo = _carBodyRepository.QueryFirst(x => x.PVI == rfid);
 
                if (carBodyInfo == null) throw new Exception($"未找到PVI{rfid}的车身数据");
 
                BindWorkOrder passPoint = new BindWorkOrder()
                {
                    unionKey = Guid.NewGuid().ToString(),
                    stationCode = "",
                    messageTime = DateTime.Now.ToString(),
                    plantCode = "1052",
                    pvi = rfid,
                    workOrderNo = carBodyInfo.workOrderNo,
                    workOrderType = carBodyInfo.workOrderType,
                    workshopCode = ""
                };
 
                var MESrespon = HttpHelper.PostAsync(wmsIpAddress, passPoint.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());
                var paintingOrderInfo = _paintingOrderInfoRepository.QueryFirst(x => x.workOrderNo == characterRespon.workOrderNo);
 
                if (paintingOrderInfo == null) throw new Exception($"绑定失败:未找到涂装工单信息{characterRespon.workOrderNo}");
 
                paintingOrderInfo.pvi = characterRespon.pvi;
                _paintingOrderInfoRepository.UpdateData(paintingOrderInfo);
 
 
                LogFactory.GetLog("BDC请求绑定工单信息").Info(true, $"\r\r--------------------------------------");
                LogFactory.GetLog("BDC请求绑定工单信息").Info(true, $"工位号:{stationNo},RFID:{rfid}");
 
                return content.OK();
            }
            catch (Exception ex)
            {
                LogFactory.GetLog("BDC请求绑定工单信息").Info(true, $"绑定失败:{ex.Message}");
                return content.Error(ex.Message);
            }
        }
    }
}