MaterialUpCict.cs
4.14 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
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 System;
using System.Collections.Generic;
namespace Hh.Mes.Service.ApiService
{
public partial class UpstreamService
{
/// <summary>
/// 信科物料数据反馈
/// </summary>
/// <param name=""></param>
/// <returns></returns>
public Response MaterialUpCict(MaterialUpCictEntity materialEntity)
{
var response = new Response();
return ExceptionsHelp.Instance.ExecuteT(() =>
{
var resultToken = GetCictToken();
if (!resultToken.Item1) return response.ResponseError(resultToken.Item2);
var urlDic = "UrlMaterialCict" + ConfigRead.GetInstance.GetAppsetConnection().AppCustomExtend1;//AppCustomExtend1:"_onLine/_off"
var url = GetDictionaryDictValue(urlDic, "GetUrl");//获取配置的url
//var url = "信科api url";
#region 测试数据
var sendData = new MaterialUpCictEntity();
var item = new base_material()
{
materialCode = "300181",
materialName = "压板111",
mtClassify = "elbow",
mtTypeCode = "material",
unitCode = "PCS",
plmeId = "",
isDelete = 1,
createTime = DateTime.Now,
createBy = "Cict"
};
sendData.materials.Add(item);
var json = JsonConvert.SerializeObject(sendData);
#endregion
//var json = JsonConvert.SerializeObject(materialEntity);
response = HttpMan(url, json, EnumLog.Cict物料信息反馈.ToString(), token: resultToken.Item2);
if (response.Code == 200)
{
return response.ResponseSuccess();
}
//Log4NetHelper.Instance.Error($"【返回结果】" + response.Result);
CICTResult cictResult = JsonConvert.DeserializeObject<CICTResult>(response.Result);
response.Message = $"【信科】PLMEID:{cictResult.PLMEID},错误原因:{cictResult.MSG},STATUS:{cictResult.STATUS}";
response.Result = "";
return response;
});
}
private dynamic HandleData(List<base_material> list)
{
var response = new Response();
return ExceptionsHelp.Instance.ExecuteT(() =>
{
foreach (var model in list)
{
var isExist = Context.Queryable<base_material>().Where(i => i.id == model.id).ToList();
if (isExist.Count < 0)
{
var rate = new base_material_rate
{
materialCode = model.materialCode,
materialName = model.materialName,
mtClassify = model.mtClassify,
unitCode = model.unitCode,
specifications = model.specifications,
materialKeys = model.keys,
quantityRate = 1,
createBy = model.createBy,
createTime = DateTime.Now,//?
};
Context.Insertable<base_material>(model).AddQueue();
Context.Insertable<base_material_rate>(model).AddQueue();
Context.SaveQueues();
}
else
{
response.Status = Context.Updateable(model).Where(u => u.id == model.id).ExecuteCommand() > 0;
if (!response.Status) response.Message = "更新失败";
}
}
return response;
});
}
}
}