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
using AngleSharp.Io;
using LogLibrary.Log;
using Masuit.Tools;
using Newtonsoft.Json;
using WIDESEA_Common;
using WIDESEA_Core;
using WIDESEA_Core.Const;
using WIDESEA_DTO;
using WIDESEA_DTO.MOM;
using WIDESEA_IServices;
using WIDESEA_IStoragIntegrationServices;
 
namespace WIDESEA_StoragIntegrationServices;
 
public class AgingInOrOutInputService : IAgingInOrOutInputService
{
    private readonly LogFactory LogFactory = new LogFactory();
    private readonly ISys_ConfigService _configService;
 
    public AgingInOrOutInputService(ISys_ConfigService configRepository)
    {
        _configService = configRepository;
    }
 
    /// <summary>
    /// 静置\陈化入库(整托盘)
    /// </summary>
    /// <param name="input">入库数据</param>
    /// <returns></returns>
    public async Task<WebResponseContent> GetOCVInputAsync(AgingInputDto 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); // Specify the namespace explicitly
            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.AgingInput)?.ConfigValue;
            if (wmsBase == null || ipAddress == null)
            {
                throw new InvalidOperationException("WMS IP 未配置");
            }
            var wmsIpAddress = wmsBase + ipAddress;
 
            var result =await HttpsClient.PostAsync(wmsIpAddress, inputJson);
            content.OK(data: result);
 
            var respone = JsonConvert.DeserializeObject<ResponeAgingInputDto>(result.ToString());
            if (!respone.Success)
            {
                MoMErrorMsg.AddMoMErrorMsg(0, input.TrayBarcode, respone.MOMMessage, SysConfigConst.AgingInput);
            }
            else
            {
                MoMErrorMsg.DeleteMoMErrorMsg(0, input.TrayBarcode);
            }
 
            LogFactory.GetLog("静置陈化入库(整托盘)").Info(true, $"\r\r--------------------------------------");
            LogFactory.GetLog("静置陈化入库(整托盘)").Info(true, input.TrayBarcode);
            LogFactory.GetLog("静置陈化入库(整托盘)").Info(true, result);
        }
        catch (Exception err)
        {
            //MoMErrorMsg.AddMoMErrorMsg(0, input.TrayBarcode, err.Message, SysConfigConst.AgingInput);
            //Console.WriteLine(err.Message.ToString());
            LogFactory.GetLog("静置陈化入库(整托盘)").Error(true, $"\r\r--------------------------------------");
            LogFactory.GetLog("静置陈化入库(整托盘)").Error(true, err.StackTrace);
        }
        return content;
    }
 
    /// <summary>
    /// 静置\陈化出库(整托盘)
    /// </summary>
    /// <param name="input">出库数据</param>
    /// <returns></returns>
    public async Task<WebResponseContent> GetOCVOutputAsync(AgingOutputDto 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); // Specify the namespace explicitly
            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.AgingOutput)?.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<ResponeAgingInputDto>(result.ToString());
            if (!respone.Success)
            {
                MoMErrorMsg.AddMoMErrorMsg(0, input.TrayBarcode, respone.MOMMessage, SysConfigConst.AgingOutput);
            }
            else
            {
                MoMErrorMsg.DeleteMoMErrorMsg(0, input.TrayBarcode);
            }
 
            content.OK(data: result);
            LogFactory.GetLog("静置陈化出库(整托盘)").Info(true, $"\r\r--------------------------------------");
            LogFactory.GetLog("静置陈化出库(整托盘)").Info(true, input.TrayBarcode);
            LogFactory.GetLog("静置陈化出库(整托盘)").Info(true, result);
        }
        catch (Exception err)
        {
            //MoMErrorMsg.AddMoMErrorMsg(0, input.TrayBarcode, err.Message, SysConfigConst.AgingOutput);
            //Console.WriteLine(err.Message.ToString());
            LogFactory.GetLog("静置陈化出库(整托盘)").Error(true, $"\r\r--------------------------------------");
            LogFactory.GetLog("静置陈化出库(整托盘)").Error(true, err.StackTrace);
            content.Error(err.Message);
        }
        return content;
    }
 
 
    public async Task<WebResponseContent> Change(EqptRunDto 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); // Specify the namespace explicitly
            var configs = _configService.GetConfigsByCategory(CateGoryConst.SYS_MOMIPAddress);
            var MOMBase = configs.FirstOrDefault(x => x.ConfigKey == SysConfigConst.MOMBaseIP)?.ConfigValue;
            var ipAddress = configs.FirstOrDefault(x => x.ConfigKey == SysConfigConst.EqptRun)?.ConfigValue;
            if (MOMBase == null || ipAddress == null)
            {
                throw new InvalidOperationException("WMS IP 未配置");
            }
            var MOMIpAddress = MOMBase + ipAddress;
 
            var result = HttpsClient.PostAsync(MOMIpAddress, inputJson).Result;
 
            //var respone = JsonConvert.DeserializeObject<EqptRunDTO>(result.ToString());
            
            content.OK(data: result);
            LogFactory.GetLog("换型").Info(true, $"\r\r--------------------------------------");
            LogFactory.GetLog("换型").Info(true, input.EquipmentCode);
            LogFactory.GetLog("换型").Info(true, result);
        }
        catch (Exception err)
        {
            LogFactory.GetLog("换型").Error(true, $"\r\r--------------------------------------");
            LogFactory.GetLog("换型").Error(true, err.StackTrace);
            content.Error(err.Message);
        }
        return content;
    }
}