Tiandele
2026-03-20 daea1a90c2fa1b5cc2f52e62be15bd95cc4155f6
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
using Microsoft.EntityFrameworkCore.Storage.ValueConversion.Internal;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IdentityModel.Tokens.Jwt;
using System.Linq;
using System.Runtime;
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 WIDESEA_DTO;
using WIDESEA_Model.Models;
 
namespace WIDESEA_StoragIntegrationServices
{
    /// <summary>
    /// BDC向MES请求车辆特征信息
    /// 接口描述: BDC在PBS01前一个工位通过(PVI+白车身后4位)向MES请求VIN+车辆特征信息写入tag
    /// </summary>
    public partial class MESService
    {
        /// <summary>
        ///  BDC请求车辆特征信息
        /// </summary>
        /// <param name="rfidPrint">RFID</param>
        /// <param name="stationNo">站台请求点位</param>
        /// <returns></returns>
        public WebResponseContent getCharacteristic(RequestTaskDto json)
        {
            WebResponseContent content = new WebResponseContent();
            try
            {
                var carBodyInfo = _carBodyRepository.QueryFirst(x => x.RFID == json.PVI);
 
                //if (carBodyInfo == null) throw new Exception($"未找到PVI{rfid}的车身数据");
 
                CarCharacteristicInfo characterInfo = new CarCharacteristicInfo()
                {
                    plantCode = "1052",
                    pvi = carBodyInfo.PVI,
                    //vin = "",
                    messageTime = DateTime.Now.ToString(),
                    unionKey = Guid.NewGuid().ToString(),
                };
 
                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.getCharacteristic)?.ConfigValue;
                if (wmsBase == null || ipAddress == null)
                {
                    throw new InvalidOperationException("WMS IP 未配置");
                }
                var wmsIpAddress = wmsBase + ipAddress;
 
                var MESrespon = HttpHelper.PostAsync(wmsIpAddress, characterInfo.ToJson(), contentType, headers).Result;
 
                GetCarCharacteristicInfo characterRespon = JsonConvert.DeserializeObject<GetCarCharacteristicInfo>(MESrespon.ToString());
                if (characterRespon.code != 200)
                {
                    throw new Exception($"{characterRespon.msg}");
                }
 
                if (string.IsNullOrEmpty(characterRespon.data)) throw new Exception("请求成功,但无VIN信息");
 
                carBodyInfo.VIN = characterRespon.data.ToString().Substring(35, 17);
                _carBodyRepository.UpdateData(carBodyInfo);
 
                LogFactory.GetLog("BDC请求车辆特征信息").Info(true, $"\r\r--------------------------------------");
                LogFactory.GetLog("BDC请求车辆特征信息").Info(true, $"工位号:{json.Position},RFID:{json.PVI},响应信息:{characterRespon.ToJson()}");
 
                return content.OK(data: characterRespon.data);
            }
            catch (Exception ex)
            {
                LogFactory.GetLog("BDC请求车辆特征信息").Info(true, $"\r\r--------------------------------------");
                LogFactory.GetLog("BDC请求车辆特征信息").Info(true, $"工位号:{json.Position},RFID:{json.PVI},错误信息:{ex.Message}");
                return content.Error($"BDC请求车辆特征信息::{ex.Message}");
            }
        }
    }
}