UpstreamSendEquipment.cs
4.1 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
using Hh.Mes.Common;
using Hh.Mes.Common.config;
using Hh.Mes.Common.Json;
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.Request;
using Hh.Mes.POJO.Response;
using System;
using System.Collections.Generic;
namespace Hh.Mes.Service.ApiService
{
public partial class UpstreamService
{
public dynamic SendEquipment(List<EquipmentEntity> list)
{
return ExceptionsHelp.Instance.ExecuteT(() =>
{
//var reqData = DynamicJson.Parse(requestData); reqData.data
EquipmentEntity entity = new EquipmentEntity();
var response = new ResponseUpstream<string>("");
int resultCount = 0;
foreach (EquipmentEntity e in list)
{
entity = e;
response = new ResponseUpstream<string>(entity.plmeid);
if (!typeValidation(entity.type, response).Status) return response;
var equipment = new base_equipment()
{
factoryCode = entity.factory_code,
equipmentCode = entity.equipment_code,
equipmentName = entity.equipment_name,
equipmentTypeCode = entity.equipmentType_code,
equipmentTypeName = entity.equipmentType_Name,
ip = entity.ip,
destinationArea = entity.destination_area,
remark = entity.remark,
isDelete = entity.isDelete,
};
bool isExist = Context.Queryable<base_equipment>().Any(t => t.factoryCode == equipment.factoryCode && t.equipmentCode == equipment.equipmentCode);
if (entity.type == EnumAction.I.ToString())
{
if (isExist)
{
return response.ResponseError($"【上位系统】【唯一标识plmeId:{entity.plmeid}】【厂房factory_Code,设备编码equipment_code】设备基础信息[{entity.factory_code},{entity.equipment_name}]已经存在,请勿重复添加!");
}
equipment.createTime = DateTime.Now;
Context.Insertable(equipment).AddQueue();
}
else if (entity.type == EnumAction.U.ToString())
{
if (!isExist) return response.ResponseError($"【上位系统】【唯一标识plmeId:{entity.plmeid}】【厂房factory_Code,设备编码equipment_code】设备基础信息[{entity.factory_code},{entity.equipment_name}]不存在,无法修改!");
equipment.updateTime = DateTime.Now;
Context.Updateable(equipment)
.IgnoreColumns(it => new { it.createTime, it.createBy })
.Where(x => x.factoryCode == entity.factory_code && x.equipmentCode == entity.equipment_code)
.AddQueue();
}
else if (entity.type == EnumAction.D.ToString())
{
if (!isExist) return response.ResponseError($"【上位系统】【唯一标识plmeId:{entity.plmeid}】【厂房factory_Code,设备编码equipment_code】设备基础信息[{entity.factory_code},{entity.equipment_name}]不存在,无法删除!");
equipment.isDelete = 0;
equipment.updateTime = DateTime.Now;
Context.Updateable(equipment)
.IgnoreColumns(it => new { it.createTime, it.createBy })
.Where(x => x.factoryCode == entity.factory_code && x.equipmentCode == entity.equipment_code)
.AddQueue();
}
}
resultCount = ExecuteQueues(Context);
return resultCount > 0 ? response.ResponseSuccess() : response.ResponseError();
});
}
}
}