AndonUpMom.cs
5.34 KB
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
using Hh.Mes.Common.config;
using Hh.Mes.Common.log;
using Hh.Mes.Pojo.System;
using Hh.Mes.POJO.ApiEntity;
using Hh.Mes.POJO.Entity;
using Hh.Mes.POJO.EnumEntitys;
using Hh.Mes.POJO.Response;
using Newtonsoft.Json;
using NPOI.POIFS.FileSystem;
using SqlSugar;
using System;
namespace Hh.Mes.Service.ApiService
{
public partial class UpstreamService
{
/// <summary>
/// ANDON信息反馈
/// </summary>
/// <remarks>
/// <para><a href="https://kdocs.cn/l/caBR6DBb2LpP">MOM-产线中控接口文档</a></para>
/// <para><a href="https://www.bejson.com/">Josn在线解析工具</a></para>
/// </remarks>
/// <returns><see cref="Response"/></returns>
public Response AndonUpMom(AndonUpMomEntity andonUpMomEntity)
{
var response = new Response();
return ExceptionsHelp.Instance.ExecuteT(() =>
{
var resultToken = GetMomToken();
if (!resultToken.Item1) return response.ResponseError(resultToken.Item2);
var urlDic = "UrlAndonUpMom" + ConfigRead.GetInstance.GetAppsetConnection().AppCustomExtend1;
var url = GetDictionaryDictValue(urlDic, "GetUrl");
//var url = "http://10.77.101.247:51001/mom/intf/intfMbosLineTaskAndon/receive";
#region 测试数据
//var sendData = new AndonUpMomEntity();
//var item = new AndonUpMomDetail()
//{
// id = "01",
// line_code = "TZTTHW",
// device_information = "xxx",
// device_fault_type = "xxx",
// device_fault_description = "xxx",
// device_status = "1",
// start_time = DateTime.Now.AddDays(-7).ToString("yyyy-MM-dd HH:mm:ss"),
// end_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
// ylzd1 = "1",
// type = EnumAction.I.ToString()
//};
//sendData.andon_list.Add(item);
#endregion
var json = JsonConvert.SerializeObject(andonUpMomEntity);
//var json = "{\"andon_list\":[{\"id\":\"01\",\"line_code\":\"zjqzzz\",\"device_information\":\"xxx\",\"device_fault_type\":\"xxx\",\"device_fault_description\":\"xxx\",\"device_status\":\"1\",\"start_time\":\"2008-02-21 12:00:00\",\"end_time\":\"2014-02-21 12:00:00\",\"ylzd1\":\"1\",\"type\":\"i\"}]}";
response = HttpMan(url, json, EnumLog.ANDON报警.ToString(), token: resultToken.Item2);
if (response.Code == 200)
{
return response.ResponseSuccess();
}
//Log4NetHelper.Instance.Error($"【MOM返回结果】" + response.Result);
MOMResult momResult = JsonConvert.DeserializeObject<MOMResult>(response.Result);
response.Message = $"【MOM】PLMEID:{momResult.PLMEID},错误原因:{momResult.MSG},STATUS:{momResult.STATUS}";
response.Result = "";
return response;
});
}
/// <summary>
/// ANDON信息反馈
/// </summary>
/// <remarks>
/// </remarks>
/// <returns><see cref="Response"/></returns>
public Response AndonUpMomNew()
{
var response = new Response();
return ExceptionsHelp.Instance.ExecuteT(() =>
{
var url = GetDictionaryDictValue("UrlAndonUpMom_off", "GetUrl");
#region 数据
// 获取当前时间并计算1小时之后的时间点
DateTime nowTime = DateTime.Now;
DateTime endTime = nowTime.AddHours(-1);
var equipmentalarmList= Context.Queryable<wcs_equipmentalarm>().Where(it => it.createTime >= endTime && it.createTime <= nowTime).ToList();
if (equipmentalarmList.Count==0)
return response.ResponseError($"没有可以上报报警信息!");
var sendData = new AndonUpMomEntity();
foreach (var item in equipmentalarmList)
{
var andonUpMomDetail = new AndonUpMomDetail()
{
plmeid = item.id.ToString(),
line_code = "Line4",
device_information_name = item.equipmentName,
device_information_code = item.equipmentCode,
device_fault_type = item.equipmentPropCode,
device_fault_description = item.equipmentPropName,
device_status = item.isEnd ? 1 : 0,
start_time = item.createTime.ToString(),
end_time = item.updateTime.ToString(),
type = EnumAction.I.ToString()
};
sendData.andon_list.Add(andonUpMomDetail);
}
#endregion
//var json = JsonConvert.SerializeObject(sendData);
response = HttpMan(url, sendData, EnumLog.ANDON报警.ToString(), method: "post");
if (response.Code == 200) {
response.Message = "上传设备报警信息成功!";
}
return response;
});
}
}
}