wanshenmean
2024-11-03 a15d996584733d60d0adddcd791f029d608c4fae
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
using LogLibrary.Log;
using Masuit.Tools;
using Newtonsoft.Json;
using WIDESEA_Common;
using WIDESEA_Core;
using WIDESEA_DTO;
using WIDESEA_DTO.MOM;
using WIDESEA_IStorageBasicService;
using WIDESEA_IStoragIntegrationServices;
using WIDESEA_Model.Models;
 
namespace WIDESEA_StoragIntegrationServices;
 
public class CellStateService : ICellStateService
{
    private readonly LogFactory LogFactory = new LogFactory();
 
    private readonly IBoxingInfoService _boxingInfoService;
 
    public CellStateService(IBoxingInfoService boxingInfoService)
    {
        _boxingInfoService = boxingInfoService;
    }
 
    /// <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.Software = "陈化机";
            input.EquipmentCode = "P1K10040";
            input.EmployeeNo = "T00001";
            input.RequestTime = TimeZoneInfo.ConvertTimeToUtc(DateTime.Now).ToString("yyyy-MM-ddTHH:mm:ss.fffZ");
            var inputJson = input.ToDictionary();
            var x = await HttpsClient.PostAsync("http://ts-momapp01:12020/api/MachineIntegration/CellState", inputJson);
            if (x != null)
            {
                ResultCellState result = JsonConvert.DeserializeObject<ResultCellState>(x);
                DtBoxingInfo boxingInfo = new DtBoxingInfo()
                {
                    IsFull = true,
                    PalletCode = "",
                };
                var details = new List<DtBoxingInfoDetail>();
                foreach (var item in result.SerialNos)
                {
                    DtBoxingInfoDetail detail = new DtBoxingInfoDetail()
                    {
                        SerialNumber = item.SerialNo,
                        OrderNo = item.BindCode,
                        Status = item.SerialNoStatus,
                    };
                    details.Add(detail);
                }
                boxingInfo.BoxingInfoDetails = details;
                var abc = await _boxingInfoService.AddBoxingInfoAsync(boxingInfo);
                if (abc.Status)
                    return content.OK("组盘成功");
                else
                    return content.Error("组盘失败");
            }
            LogFactory.GetLog("单电芯属性获取").Info(true, $"\r\r--------------------------------------");
            LogFactory.GetLog("单电芯属性获取").Info(true, x);
        }
        catch (Exception err)
        {
            Console.WriteLine(err.Message.ToString());
            LogFactory.GetLog("单电芯属性获取").Error(true, $"\r\r--------------------------------------");
            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.Software = "陈化机";
            input.EquipmentCode = "P1K10040";
            input.EmployeeNo = "T00001";
            input.RequestTime = TimeZoneInfo.ConvertTimeToUtc(DateTime.Now).ToString("yyyy-MM-ddTHH:mm:ss.fffZ");
            var inputJson = input.ToDictionary();
            var x = await HttpsClient.PostAsync("http://ts-momapp01:12020/api/MachineIntegration/TrayCellsStatus", inputJson);
            if (x != null)
            {
                ResultTrayCellsStatus result = JsonConvert.DeserializeObject<ResultTrayCellsStatus>(x);
                DtBoxingInfo boxingInfo = new DtBoxingInfo()
                {
                    IsFull = true,
                    PalletCode = result.TrayBarcode,
                };
                var details = new List<DtBoxingInfoDetail>();
                foreach (var item in result.SerialNos)
                {
                    DtBoxingInfoDetail detail = new DtBoxingInfoDetail()
                    {
                        SerialNumber = item.SerialNo,
                        OrderNo = item.PositionNo.ToString(),
                        Status = item.SerialNoStatus,
                        Remark = result.TrayBarcodePropertys.ToJsonString(),
                        MaterielCode = result.BindCode,
                    };
                    details.Add(detail);
                }
                boxingInfo.BoxingInfoDetails = details;
                var abc = await _boxingInfoService.AddBoxingInfoAsync(boxingInfo);
                if (abc.Status)
                    content.OK("组盘成功", result);
                else
                    content.Error("组盘失败");
            }
            LogFactory.GetLog("整盘电芯属性获取").Info(true, $"\r\r--------------------------------------");
            LogFactory.GetLog("整盘电芯属性获取").Info(true, x);
        }
        catch (Exception err)
        {
            Console.WriteLine(err.Message.ToString());
            LogFactory.GetLog("整盘电芯属性获取").Error(true, $"\r\r--------------------------------------");
            LogFactory.GetLog("整盘电芯属性获取").Error(true, err.StackTrace);
        }
        return content;
    }
}