|
1
2
3
4
5
6
7
8
|
using Hh.Mes.Common.log;
using System;
using Hh.Mes.Pojo.System;
using Hh.Mes.POJO.Entity;
using Hh.Mes.POJO.EnumEntitys;
using Hh.Mes.POJO.ApiEntity;
using Hh.Mes.POJO.Response;
using static Microsoft.AspNetCore.Hosting.Internal.HostingApplication;
|
|
9
|
using System.Xml.Schema;
|
|
10
11
12
13
14
15
16
17
18
19
|
namespace Hh.Mes.Service.ApiService
{
public partial class UpstreamService
{
public dynamic SendMaterial(MaterialEntity entity)
{
var response = new ResponseUpstream<string>(entity.plmeid);
return ExceptionsHelp.Instance.ExecuteT(() =>
{
|
|
20
21
|
if (!typeValidation(entity.type, response).Status) return response;
|
|
22
23
24
25
26
27
28
29
|
int resultCount = 0;
var material = new base_material
{
keys = Guid.NewGuid(),
plmeId = entity.plmeid,
factoryCode = entity.factory_code,
materialCode = entity.mater_code,
materialName = entity.mater_name,
|
|
30
|
unitCode = entity.unit,
|
|
31
|
mtClassify = entity.mtClassify,
|
|
32
33
|
mtTypeCode= "material",//默认物料
|
|
34
|
specifications = entity.format,
|
|
35
36
37
|
diameter=entity.diameter,
thickness=entity.thickness,
types= entity.types,
|
|
38
39
40
41
|
isDelete = AddOrUpdateFlag
};
if (entity.type == EnumAction.I.ToString())
{
|
|
42
43
44
|
if (base.Context.Queryable<base_factory>().Any(x => x.otherCode != material.factoryCode))
return response.ResponseError($"【上位系统】物料信息工厂编码[{nameof(material.factoryCode)}]“{material.factoryCode}”不存在产线系统,请核实后再发送!");
|
|
45
|
if (base.Context.Queryable<base_material>().Any(x => x.materialCode == material.materialCode && x.isDelete == AddOrUpdateFlag))
|
|
46
|
return response.ResponseError($"【上位系统】物料信息[{nameof(material.materialCode)}]“{material.materialCode}”已存在,请勿重复发送!");
|
|
47
48
49
|
material.createTime = DateTime.Now;
material.createBy = SystemVariable.DefaultCreated;
|
|
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
var rate = new base_material_rate
{
materialCode = material.materialCode,
materialName = material.materialName,
mtClassify = entity.mtClassify,
unitCode = material.unitCode,
specifications = material.specifications,
materialKeys = material.keys,
quantityRate = 1,
createTime = DateTime.Now,
createBy = SystemVariable.DefaultCreated
};
base.Context.Insertable(material).AddQueue();
base.Context.Insertable(rate).AddQueue();
resultCount = base.Context.SaveQueues();
|
|
67
68
69
|
}
else if (entity.type == EnumAction.U.ToString())
{
|
|
70
71
72
|
if (base.Context.Queryable<base_factory>().Any(x => x.otherCode != material.factoryCode))
return response.ResponseError($"【上位系统】物料信息工厂编码[{nameof(material.factoryCode)}]“{material.factoryCode}”不存在产线系统,请核实后再发送!");
|
|
73
74
75
|
material.updateTime = DateTime.Now;
material.updateBy = SystemVariable.DefaultCreated;
resultCount = base.Context.Updateable(material)
|
|
76
|
.IgnoreColumns(it => new { it.keys, it.typesPlcCode, it.createBy, it.createTime })
|
|
77
78
79
|
.Where(x => x.materialCode == material.materialCode && x.isDelete == AddOrUpdateFlag)
.ExecuteCommand();
}
|
|
80
|
|
|
81
82
83
84
85
|
return resultCount > 0 ? response.ResponseSuccess() : response.ResponseError();
});
}
}
}
|