xxyy
2025-03-10 85fd548c3948b4ded198f304204e9ce602761edc
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
using AngleSharp.Io;
using LogLibrary.Log;
using Masuit.Tools;
using Newtonsoft.Json;
using WIDESEA_Common;
using WIDESEA_Core;
using WIDESEA_Core.Const;
using WIDESEA_Core.Helper;
using WIDESEA_DTO;
using WIDESEA_DTO.MOM;
using WIDESEA_IRepository;
using WIDESEA_IServices;
using WIDESEA_IStorageBasicService;
using WIDESEA_IStoragIntegrationServices;
using static Org.BouncyCastle.Math.EC.ECCurve;
 
namespace WIDESEA_StoragIntegrationServices;
 
public class CellStateService : ICellStateService
{
    private readonly LogFactory LogFactory = new LogFactory();
 
    private readonly IBoxingInfoService _boxingInfoService;
    private readonly ISys_ConfigService _configService;
 
    public CellStateService(IBoxingInfoService boxingInfoService, ISys_ConfigService configRepository)
    {
        _boxingInfoService = boxingInfoService;
        _configService = configRepository;
    }
 
    /// <summary>
    /// 单电芯属性获取
    /// </summary>
    /// <param name="input">电芯数据</param>
    /// <returns></returns>
    public async Task<dynamic> GetCellStateAsync(CellStateDto input)
    {
        WebResponseContent content = new WebResponseContent();
        try
        {
            input.SessionId = Guid.NewGuid().ToString();
            input.EmployeeNo = "MITest";
            input.RequestTime = TimeZoneInfo.ConvertTimeToUtc(DateTime.Now).ToString("yyyy-MM-ddTHH:mm:ss.fffZ");
            var inputJson = Masuit.Tools.ObjectExtensions.ToDictionary(input);
            var configs = _configService.GetConfigsByCategory(CateGoryConst.SYS_MOMIPAddress);
            var wmsBase = configs.FirstOrDefault(x => x.ConfigKey == SysConfigConst.MOMBaseIP)?.ConfigValue;
            var ipAddress = configs.FirstOrDefault(x => x.ConfigKey == SysConfigConst.CellState)?.ConfigValue; 
            if (wmsBase == null || ipAddress == null)
            {
                throw new InvalidOperationException("WMS IP 未配置");
            }
            var wmsIpAddress = wmsBase + ipAddress;
 
            var result = HttpsClient.PostAsync(wmsIpAddress, inputJson).Result;
 
            LogFactory.GetLog("单电芯属性获取").Info(true, $"\r\r--------------------------------------");
            LogFactory.GetLog("单电芯属性获取").Info(true, result);
            return result;
        }
        catch (Exception err)
        {
            //Console.WriteLine(err.Message.ToString());
            LogFactory.GetLog("单电芯属性获取").Error(true, $"\r\r--------------------------------------");
            LogFactory.GetLog("单电芯属性获取").Error(true, $"请求参数: {JsonConvert.SerializeObject(input)}");
            LogFactory.GetLog("单电芯属性获取").Error(true, err.Message);
            LogFactory.GetLog("单电芯属性获取").Error(true, err.StackTrace);
        }
        return Task.FromResult<dynamic>(null);
    }
 
    /// <summary>
    /// 整盘电芯属性获取
    /// </summary>
    /// <param name="input">电芯数据</param>
    /// <returns></returns>
    public async Task<WebResponseContent> GetTrayCellStatusAsync(TrayCellsStatusDto input)
    {
        WebResponseContent content = new WebResponseContent();
        try
        {
            input.SessionId = Guid.NewGuid().ToString();
            input.EmployeeNo = "MITest";
            input.RequestTime = TimeZoneInfo.ConvertTimeToUtc(DateTime.Now).ToString("yyyy-MM-ddTHH:mm:ss.fffZ");
            var inputJson = Masuit.Tools.ObjectExtensions.ToDictionary(input);
            var configs = _configService.GetConfigsByCategory(CateGoryConst.SYS_MOMIPAddress);
            var wmsBase = configs.FirstOrDefault(x => x.ConfigKey == SysConfigConst.MOMBaseIP)?.ConfigValue;
            var ipAddress = configs.FirstOrDefault(x => x.ConfigKey == SysConfigConst.TrayCellsStatus)?.ConfigValue;
            if (wmsBase == null || ipAddress == null)
            {
                throw new InvalidOperationException("WMS IP 未配置");
            }
            var wmsIpAddress = wmsBase + ipAddress;
 
            var result = HttpsClient.PostAsync(wmsIpAddress, inputJson).Result;
 
            var respone = JsonConvert.DeserializeObject<ResultTrayCellsStatus>(result.ToString());
 
            if (!respone.Success)
            {
                MoMErrorMsg.AddMoMErrorMsg(0, input.TrayBarcode, respone.MOMMessage, SysConfigConst.TrayCellsStatus);
            }
            else
            {
                MoMErrorMsg.DeleteMoMErrorMsg(0, input.TrayBarcode);
            }
 
            LogFactory.GetLog("整盘电芯属性获取").Info(true, $"\r\r--------------------------------------");
            LogFactory.GetLog("整盘电芯属性获取").Info(true, result);
            content.OK(data: result);
        }
        catch (Exception err)
        {
            //MoMErrorMsg.AddMoMErrorMsg(0, input.TrayBarcode, err.Message, SysConfigConst.TrayCellsStatus);
 
            //Console.WriteLine(err.Message.ToString());
            LogFactory.GetLog("整盘电芯属性获取").Error(true, $"\r\r--------------------------------------");
            LogFactory.GetLog("整盘电芯属性获取").Error(true, $"请求参数: {JsonConvert.SerializeObject(input)}");
            LogFactory.GetLog("整盘电芯属性获取").Error(true, err.Message);
            LogFactory.GetLog("整盘电芯属性获取").Error(true, err.StackTrace);
        }
        return content;
    }
}