对接IDP系统项目开车数据

This commit is contained in:
2025-08-06 15:27:50 +08:00
parent 0a061ce206
commit 268c6b7a14
33 changed files with 6226 additions and 91 deletions
+582 -48
View File
@@ -9,9 +9,11 @@ using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Net;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
namespace BLL
{
@@ -20,9 +22,9 @@ namespace BLL
/// </summary>
public static class IDPDataService
{
/// <summary>
/// 测试环境api地址
/// </summary>
///// <summary>
///// 测试环境api地址
///// </summary>
//private static readonly string IDPApiUrl = "http://10.5.6.151:8100/";
/// <summary>
/// 正式环境api地址
@@ -32,70 +34,602 @@ namespace BLL
#region
#region
/// <summary>
/// 项目试车工作包
/// 项目试车工作包——管道一览表
/// </summary>
/// <param name="session">session</param>
/// <param name="projectId">项目Id</param>
/// <param name="startDate">获取指定时间之后到现在的异动数据</param>
public static void GetIDPProjectPreRunData(string projectId = "")
public static string GetIDPProjectPreRunDataPiping(SessionItem session, string projectId)
{
string mainProjectId = string.Empty;//五环主数据项目Id
string wbsCode = string.Empty;//五环主数据wbs编码
string workitemCode = string.Empty;//五环主数据文件类别码
if (!string.IsNullOrWhiteSpace(projectId))
string result = string.Empty;
if (string.IsNullOrWhiteSpace(projectId))
{
result = "请传项目Id";
}
else
{
var project = BLL.ProjectService.GetProjectByProjectId(projectId);
var mainProject = BLL.PMPDataService.GetPMPProjectByCode(project.ProjectCode);
if (mainProject != null)
var mainProjects = BLL.PMPDataService.GetPMPProjectListByCode(project.ProjectCode);
List<string> idpPipingIds = IDPPreRunDataService.GetIDPPreRunDataPipingIds(projectId);
List<IDP_PreRunData_Piping> addItems = new List<IDP_PreRunData_Piping>();
List<IDP_PreRunData_Piping> modifyItems = new List<IDP_PreRunData_Piping>();
int all = 0;
foreach (var pro in mainProjects)
{
mainProjectId = mainProject.Code;
string url = $"{IDPApiUrl}OSS/projects/{pro.Code}/workitems/CP2600/objects/latest";
//string url = $"{IDPApiUrl}OSS/projects/100168/workitems/CP2600/objects/latest";
try
{
//var session = GetAuthenticationSession();
//ErrLogInfo.WriteLog($"Session——name{session.name}value{session.value}");
Hashtable newToken = new Hashtable { { "Cookie", $"{session.name}={session.value}" } };
var returndata = BLL.APIGetHttpService.OutsideHttp(url, "GET", null, newToken, null);
if (!string.IsNullOrEmpty(returndata))
{
if (returndata.Contains("\"code\":404,\"message\":\"资源不存在\""))
{
result += $"失败!{returndata}|";
}
else if (returndata.Contains("\"status\":404,\"error\":\"Not Found\""))
{
result += $"失败!{returndata}|";
}
else
{
List<IDPPreRunPiping> responseDatas = IDPPreRunPiping.FromJson(returndata);
all += responseDatas.Count();
foreach (var item in responseDatas)
{
IDP_PreRunData_Piping newItem = new IDP_PreRunData_Piping();
newItem.ItemId = item.ItemId;
newItem.ProjId = pro.Code;//主数据项目Id
newItem.ProjCode = pro.StNum;//主数据项目Code
newItem.ProjectId = project.ProjectId;//智慧施工项目Id
newItem.LastTime = DateTime.Now;//入库时间
newItem.WbsCode = item.WbsCode;//装置工序主项码
newItem.DeviceCode = item.DeviceCode;//装置码
newItem.ProcessesCode = item.ProcessesCode;//工序码
newItem.SubjectCode = item.SubjectCode;//主项码
newItem.Category = item.Category;
newItem.Category = item.Category;
newItem.Tag = item.Tag;
newItem.PipingCode = item.PipingCode;
newItem.Diameter = item.Diameter;
newItem.DiameterUnit = item.DiameterUnit;
newItem.MaterialLevel = item.MaterialLevel;
newItem.AdiabatType = item.AdiabatType;
newItem.AdiabatThickness = item.AdiabatThickness;
newItem.AdiabatThicknessUnit = item.AdiabatThicknessUnit;
newItem.MediumState = item.MediumState;
newItem.DrawingStartNo = item.DrawingStartNo;
newItem.DrawingEndNo = item.DrawingEndNo;
newItem.PipingStart = item.PipingStart;
newItem.PipingEnd = item.PipingEnd;
newItem.PipingLevel = item.PipingLevel;
newItem.NormalTemperature = item.NormalTemperature;
newItem.NormalTemperatureUnit = item.NormalTemperatureUnit;
newItem.NormalPressure = item.NormalPressure;
newItem.NormalPressureUnit = item.NormalPressureUnit;
newItem.DesignTemperature = item.DesignTemperature;
newItem.DesignTemperatureUnit = item.DesignTemperatureUnit;
newItem.DesignPressure = item.DesignPressure;
newItem.DesignPressureUnit = item.DesignPressureUnit;
newItem.PaintLevel = item.PaintLevel;
newItem.Remark = item.Remark;
newItem.DetailInfo = JsonConvert.SerializeObject(item, Formatting.Indented);
if (!string.IsNullOrWhiteSpace(item.ItemId) && idpPipingIds.Contains(item.ItemId))
{//编辑
modifyItems.Add(newItem);
}
else
{//新增
addItems.Add(newItem);
idpPipingIds.Add(item.ItemId);
}
}
}
}
else
{
result = "失败!";
}
}
catch (WebException ex)
{
result = $"程序异常:{ex.Message}";
}
}
if (addItems.Any()) { AddIDPPreRunPiping(addItems); }
if (modifyItems.Any()) { ModifyIDPPreRunPiping(modifyItems); }
result = $"成功!总数:{all}条;新增:{addItems.Count()}条,维护:{(all - addItems.Count())}条";
}
return result;
}
//https://idp.cwcec.com/OSS/projects/100168/wbs/040101/workitems/CP2100/objects/latest
//string url = $"{IDPApiUrl}/OSS/projects/{mainProjectId}/wbs/{wbsCode}/workitems/{workitemCode}/objects/latest";
string url = $"{IDPApiUrl}OSS/projects/100168/wbs/040101/workitems/CP2100/objects/latest";
/// <summary>
/// 批量插入数据
/// </summary>
/// <param name="list"></param>
public static void AddIDPPreRunPiping(List<Model.IDP_PreRunData_Piping> list)
{
Model.SGGLDB db = Funs.DB;
db.IDP_PreRunData_Piping.InsertAllOnSubmit(list);
db.SubmitChanges();
}
try
/// <summary>
/// 更新数据
/// </summary>
/// <param name="list"></param>
public static void ModifyIDPPreRunPiping(List<Model.IDP_PreRunData_Piping> list)
{
Model.SGGLDB db = Funs.DB;
foreach (var obj in list)
{
var session = GetAuthenticationSession();
ErrLogInfo.WriteLog($"Session——name{session.name}value{session.value}");
Hashtable newToken = new Hashtable { { "Cookie", $"{session.name}={session.value}" } };
var returndata = BLL.APIGetHttpService.OutsideHttp(url, "GET", null, newToken, null);
if (!string.IsNullOrEmpty(returndata))
IDP_PreRunData_Piping newItem = db.IDP_PreRunData_Piping.FirstOrDefault(x => x.ItemId == obj.ItemId);
if (newItem != null)
{
IDPPreRunData responseData = IDPPreRunData.FromJson(returndata);
newItem.ProjId = obj.ProjId;//主数据项目Id
newItem.ProjCode = obj.ProjCode;//主数据项目Code
newItem.ProjectId = obj.ProjectId;//智慧施工项目Id
newItem.LastTime = DateTime.Now;//入库时间
newItem.WbsCode = obj.WbsCode;//装置工序主项码
newItem.DeviceCode = obj.DeviceCode;//装置码
newItem.ProcessesCode = obj.ProcessesCode;//工序码
newItem.SubjectCode = obj.SubjectCode;//主项码
newItem.Category = obj.Category;
newItem.Tag = obj.Tag;
newItem.PipingCode = obj.PipingCode;
newItem.Diameter = obj.Diameter;
newItem.DiameterUnit = obj.DiameterUnit;
newItem.MaterialLevel = obj.MaterialLevel;
newItem.AdiabatType = obj.AdiabatType;
newItem.AdiabatThickness = obj.AdiabatThickness;
newItem.AdiabatThicknessUnit = obj.AdiabatThicknessUnit;
newItem.MediumState = obj.MediumState;
newItem.DrawingStartNo = obj.DrawingStartNo;
newItem.DrawingEndNo = obj.DrawingEndNo;
newItem.PipingStart = obj.PipingStart;
newItem.PipingEnd = obj.PipingEnd;
newItem.PipingLevel = obj.PipingLevel;
newItem.NormalTemperature = obj.NormalTemperature;
newItem.NormalTemperatureUnit = obj.NormalTemperatureUnit;
newItem.NormalPressure = obj.NormalPressure;
newItem.NormalPressureUnit = obj.NormalPressureUnit;
newItem.DesignTemperature = obj.DesignTemperature;
newItem.DesignTemperatureUnit = obj.DesignTemperatureUnit;
newItem.DesignPressure = obj.DesignPressure;
newItem.DesignPressureUnit = obj.DesignPressureUnit;
newItem.PaintLevel = obj.PaintLevel;
newItem.Remark = obj.Remark;
newItem.DetailInfo = obj.DetailInfo;
db.SubmitChanges();
}
}
catch (WebException ex)
{
}
finally
{
}
}
#endregion
//public static void AddPMP_Project(List<Model.PMP_Project> newtables)
//{
// Model.SGGLDB db = Funs.DB;
// db.PMP_Project.InsertAllOnSubmit(newtables);
// db.SubmitChanges();
//}
#region
//public static void DeleteAllPMP_Project()
//{
// Model.SGGLDB db = Funs.DB;
// if (db.PMP_Project.FirstOrDefault() != null)
// {
// db.PMP_Project.DeleteAllOnSubmit(db.PMP_Project);
// db.SubmitChanges();
// }
//}
/// <summary>
/// 项目试车工作包——设备一览表
/// </summary>
/// <param name="session"></param>
/// <param name="projectId"></param>
public static string GetIDPProjectPreRunDataEquipment(SessionItem session, string projectId)
{
string result = string.Empty;
if (string.IsNullOrWhiteSpace(projectId))
{
result = "请传项目Id";
}
else
{
var project = BLL.ProjectService.GetProjectByProjectId(projectId);
var mainProjects = BLL.PMPDataService.GetPMPProjectListByCode(project.ProjectCode);
List<string> idpEquipmentIds = IDPPreRunDataService.GetIDPPreRunDataEquipmentIds(projectId);
List<IDP_PreRunData_Equipment> addItems = new List<IDP_PreRunData_Equipment>();
List<IDP_PreRunData_Equipment> modifyItems = new List<IDP_PreRunData_Equipment>();
int all = 0;
foreach (var pro in mainProjects)
{
string url = $"{IDPApiUrl}OSS/projects/{pro.Code}/workitems/CP2100/objects/latest";
//string url = $"{IDPApiUrl}OSS/projects/100168/workitems/CP2100/objects/latest";
try
{
Hashtable newToken = new Hashtable { { "Cookie", $"{session.name}={session.value}" } };
var returndata = BLL.APIGetHttpService.OutsideHttp(url, "GET", null, newToken, null);
if (!string.IsNullOrEmpty(returndata))
{
if (returndata.Contains("\"code\":404,\"message\":\"资源不存在\""))
{
result += $"失败!{returndata}|";
}
else if (returndata.Contains("\"status\":404,\"error\":\"Not Found\""))
{
result += $"失败!{returndata}|";
}
else
{
List<IDPPreRunEquipment> responseDatas = IDPPreRunEquipment.FromJson(returndata);
all += responseDatas.Count();
foreach (var item in responseDatas)
{
Type type = typeof(IDPPreRunEquipment);
IDP_PreRunData_Equipment newItem = new IDP_PreRunData_Equipment();
newItem.ItemId = item.ItemId;
newItem.ProjId = pro.Code;//主数据项目Id
newItem.ProjCode = pro.StNum;//主数据项目Code
newItem.ProjectId = project.ProjectId;//智慧施工项目Id
newItem.LastTime = DateTime.Now;//入库时间
newItem.WbsCode = item.WbsCode;//装置工序主项码
newItem.DeviceCode = item.DeviceCode;//装置码
newItem.ProcessesCode = item.ProcessesCode;//工序码
newItem.SubjectCode = item.SubjectCode;//主项码
newItem.Category = item.Category;
newItem.Tag = item.Tag;
newItem.TagNumber = item.TagNumber;
string nameSpecifications = !string.IsNullOrWhiteSpace(item.NameSpecifications)? $"{item.NameSpecifications}。":string.Empty;
if (!string.IsNullOrWhiteSpace(item.DrivingType))
{
nameSpecifications = $"{nameSpecifications} {type.GetProperty("DrivingType").GetCustomAttribute<JsonPropertyAttribute>().PropertyName}{item.DrivingType}";
}
if (!string.IsNullOrWhiteSpace(item.EquipmentType))
{
nameSpecifications = $"{nameSpecifications} {type.GetProperty("EquipmentType").GetCustomAttribute<JsonPropertyAttribute>().PropertyName}{item.EquipmentType}";
}
if (!string.IsNullOrWhiteSpace(item.EquipmentTypeModel))
{
nameSpecifications = $"{nameSpecifications} {type.GetProperty("EquipmentTypeModel").GetCustomAttribute<JsonPropertyAttribute>().PropertyName}{item.EquipmentTypeModel}";
}
if (!string.IsNullOrWhiteSpace(item.EquipmentForm))
{
nameSpecifications = $"{nameSpecifications} {type.GetProperty("EquipmentForm").GetCustomAttribute<JsonPropertyAttribute>().PropertyName}{item.EquipmentForm}";
}
if (!string.IsNullOrWhiteSpace(item.MPaG))
{
nameSpecifications = $"{nameSpecifications} {type.GetProperty("MPaG").GetCustomAttribute<JsonPropertyAttribute>().PropertyName}{item.MPaG} {item.MPaGUnit}";
}
if (!string.IsNullOrWhiteSpace(item.KPa))
{
nameSpecifications = $"{nameSpecifications} {type.GetProperty("KPa").GetCustomAttribute<JsonPropertyAttribute>().PropertyName}{item.KPa} {item.KPaUnit}";
}
if (!string.IsNullOrWhiteSpace(item.DimensionsID))
{
nameSpecifications = $"{nameSpecifications} {type.GetProperty("DimensionsID").GetCustomAttribute<JsonPropertyAttribute>().PropertyName}{item.DimensionsID} {item.DimensionsIDUnit}";
}
if (!string.IsNullOrWhiteSpace(item.DimensionsHTT))
{
nameSpecifications = $"{nameSpecifications} {type.GetProperty("DimensionsHTT").GetCustomAttribute<JsonPropertyAttribute>().PropertyName}{item.DimensionsHTT} {item.DimensionsHTTUnit}";
}
if (!string.IsNullOrWhiteSpace(item.DesignFlow))
{
nameSpecifications = $"{nameSpecifications} {type.GetProperty("DesignFlow").GetCustomAttribute<JsonPropertyAttribute>().PropertyName}{item.DesignFlow} {item.DesignFlowUnit}";
}
if (!string.IsNullOrWhiteSpace(item.ShaftPower))
{
nameSpecifications = $"{nameSpecifications} {type.GetProperty("ShaftPower").GetCustomAttribute<JsonPropertyAttribute>().PropertyName}{item.ShaftPower} {item.ShaftPowerUnit}";
}
if (!string.IsNullOrWhiteSpace(item.RatedPower))
{
nameSpecifications = $"{nameSpecifications} {type.GetProperty("RatedPower").GetCustomAttribute<JsonPropertyAttribute>().PropertyName}{item.RatedPower} {item.RatedPowerUnit}";
}
string materials = string.Empty;
if (!string.IsNullOrWhiteSpace(item.Materials))
{
materials = $"{type.GetProperty("Materials").GetCustomAttribute<JsonPropertyAttribute>().PropertyName}{item.Materials}";
}
if (!string.IsNullOrWhiteSpace(item.ImpellerMaterial))
{
materials = $"{materials} {type.GetProperty("ImpellerMaterial").GetCustomAttribute<JsonPropertyAttribute>().PropertyName}{item.ImpellerMaterial}";
}
if (!string.IsNullOrWhiteSpace(item.ShellMaterial))
{
materials = $"{materials} {type.GetProperty("ShellMaterial").GetCustomAttribute<JsonPropertyAttribute>().PropertyName}{item.ShellMaterial}";
}
if (!string.IsNullOrWhiteSpace(item.CylinderMaterial))
{
materials = $"{materials} {type.GetProperty("CylinderMaterial").GetCustomAttribute<JsonPropertyAttribute>().PropertyName}{item.CylinderMaterial}";
}
if (!string.IsNullOrWhiteSpace(item.TrayMaterial))
{
materials = $"{materials} {type.GetProperty("TrayMaterial").GetCustomAttribute<JsonPropertyAttribute>().PropertyName}{item.TrayMaterial}";
}
if (!string.IsNullOrWhiteSpace(item.PackingMaterial))
{
materials = $"{materials} {type.GetProperty("PackingMaterial").GetCustomAttribute<JsonPropertyAttribute>().PropertyName}{item.PackingMaterial}";
}
if (!string.IsNullOrWhiteSpace(item.PlateMaterial))
{
materials = $"{materials} {type.GetProperty("PlateMaterial").GetCustomAttribute<JsonPropertyAttribute>().PropertyName}{item.PlateMaterial}";
}
if (!string.IsNullOrWhiteSpace(item.TrimMaterial))
{
materials = $"{materials} {type.GetProperty("TrimMaterial").GetCustomAttribute<JsonPropertyAttribute>().PropertyName}{item.TrimMaterial}";
}
if (!string.IsNullOrWhiteSpace(item.CoilMaterial))
{
materials = $"{materials} {type.GetProperty("CoilMaterial").GetCustomAttribute<JsonPropertyAttribute>().PropertyName}{item.CoilMaterial}";
}
if (!string.IsNullOrWhiteSpace(item.PreheaterMaterial))
{
materials = $"{materials} {type.GetProperty("PreheaterMaterial").GetCustomAttribute<JsonPropertyAttribute>().PropertyName}{item.PreheaterMaterial}";
}
newItem.NameSpecifications = nameSpecifications;
newItem.Materials = materials;
newItem.NumOperate = item.DeviceNum;
newItem.WeightSingle = item.WeightSingle;
newItem.WeightSingleUnit = item.WeightSingleUnit;
newItem.Remark = item.Remark;
newItem.DetailInfo = JsonConvert.SerializeObject(item, Formatting.Indented);
if (!string.IsNullOrWhiteSpace(item.ItemId) && idpEquipmentIds.Contains(item.ItemId))
{//编辑
modifyItems.Add(newItem);
}
else
{//新增
addItems.Add(newItem);
idpEquipmentIds.Add(item.ItemId);
}
}
}
}
else
{
result = "失败!";
}
}
catch (WebException ex)
{
result = $"程序异常:{ex.Message}";
}
}
if (addItems.Any()) { AddIDPPreRunEquipment(addItems); }
if (modifyItems.Any()) { ModifyIDPPreRunEquipment(modifyItems); }
result = $"成功!总数:{all}条;新增:{addItems.Count()}条,维护:{(all - addItems.Count())}条";
}
return result;
}
/// <summary>
/// 批量插入数据
/// </summary>
/// <param name="list"></param>
public static void AddIDPPreRunEquipment(List<Model.IDP_PreRunData_Equipment> list)
{
Model.SGGLDB db = Funs.DB;
db.IDP_PreRunData_Equipment.InsertAllOnSubmit(list);
db.SubmitChanges();
}
/// <summary>
/// 更新数据
/// </summary>
/// <param name="list"></param>
public static void ModifyIDPPreRunEquipment(List<Model.IDP_PreRunData_Equipment> list)
{
Model.SGGLDB db = Funs.DB;
foreach (var obj in list)
{
IDP_PreRunData_Equipment newItem = db.IDP_PreRunData_Equipment.FirstOrDefault(x => x.ItemId == obj.ItemId);
if (newItem != null)
{
newItem.ProjId = obj.ProjId;//主数据项目Id
newItem.ProjCode = obj.ProjCode;//主数据项目Code
newItem.ProjectId = obj.ProjectId;//智慧施工项目Id
newItem.LastTime = DateTime.Now;//入库时间
newItem.WbsCode = obj.WbsCode;//装置工序主项码
newItem.DeviceCode = obj.DeviceCode;//装置码
newItem.ProcessesCode = obj.ProcessesCode;//工序码
newItem.SubjectCode = obj.SubjectCode;//主项码
newItem.Category = obj.Category;
newItem.Tag = obj.Tag;
newItem.TagNumber = obj.TagNumber;
newItem.NameSpecifications = obj.NameSpecifications;
newItem.Materials = obj.Materials;
newItem.WeightSingle = obj.WeightSingle;
newItem.WeightSingleUnit = obj.WeightSingleUnit;
newItem.Remark = obj.Remark;
newItem.DetailInfo = obj.DetailInfo;
db.SubmitChanges();
}
}
}
#endregion
#region
/// <summary>
/// 项目试车工作包——仪表索引
/// </summary>
/// <param name="session"></param>
/// <param name="projectId"></param>
public static string GetIDPProjectPreRunDataInstrumentation(SessionItem session, string projectId)
{
string result = string.Empty;
if (string.IsNullOrWhiteSpace(projectId))
{
result = "请传项目Id";
}
else
{
var project = BLL.ProjectService.GetProjectByProjectId(projectId);
var mainProjects = BLL.PMPDataService.GetPMPProjectListByCode(project.ProjectCode);
List<string> idpInstrumentationIds = IDPPreRunDataService.GetIDPPreRunDataInstrumentationIds(projectId);
List<IDP_PreRunData_Instrumentation> addItems = new List<IDP_PreRunData_Instrumentation>();
List<IDP_PreRunData_Instrumentation> modifyItems = new List<IDP_PreRunData_Instrumentation>();
int all = 0;
foreach (var pro in mainProjects)
{
string urlCP7601 = $"{IDPApiUrl}OSS/projects/{pro.Code}/workitems/CP7601/objects/latest";
string urlCP7603 = $"{IDPApiUrl}OSS/projects/{pro.Code}/workitems/CP7603/objects/latest";
//string url = $"{IDPApiUrl}OSS/projects/{pro.Code}/workitems/IN1000/objects/latest";
//string url = $"{IDPApiUrl}OSS/projects/100168/workitems/IN1000/objects/latest";
//string urlCP7601 = $"{IDPApiUrl}OSS/projects/100168/workitems/CP7601/objects/latest";
//string urlCP7603 = $"{IDPApiUrl}OSS/projects/100168/workitems/CP7603/objects/latest";
try
{
Hashtable newToken = new Hashtable { { "Cookie", $"{session.name}={session.value}" } };
var returndataCP7601 = BLL.APIGetHttpService.OutsideHttp(urlCP7601, "GET", null, newToken, null);
var returndataCP7603 = BLL.APIGetHttpService.OutsideHttp(urlCP7603, "GET", null, newToken, null);
List<IDPPreRunInstrumentation> results = new List<IDPPreRunInstrumentation>();
if (!string.IsNullOrEmpty(returndataCP7601))
{
if (returndataCP7601.Contains("\"code\":404,\"message\":\"资源不存在\""))
{
result += $"失败!{returndataCP7601}|";
}
else if (returndataCP7601.Contains("\"status\":404,\"error\":\"Not Found\""))
{
result += $"失败!{returndataCP7601}|";
}
else
{
List<IDPPreRunInstrumentation> responseDatas = IDPPreRunInstrumentation.FromJson(returndataCP7601);
results.AddRange(responseDatas);
}
}
if (!string.IsNullOrEmpty(returndataCP7603))
{
if (returndataCP7603.Contains("\"code\":404,\"message\":\"资源不存在\""))
{
result += $"失败!{returndataCP7603}|";
}
else if (returndataCP7603.Contains("\"status\":404,\"error\":\"Not Found\""))
{
result += $"失败!{returndataCP7603}|";
}
else
{
List<IDPPreRunInstrumentation> responseDatas = IDPPreRunInstrumentation.FromJson(returndataCP7603);
results.AddRange(responseDatas);
}
}
if (results.Any())
{
all += results.Count();
foreach (var item in results)
{
Type type = typeof(IDPPreRunInstrumentation);
IDP_PreRunData_Instrumentation newItem = new IDP_PreRunData_Instrumentation();
newItem.ItemId = item.ItemId;
newItem.ProjId = pro.Code;//主数据项目Id
newItem.ProjCode = pro.StNum;//主数据项目Code
newItem.ProjectId = project.ProjectId;//智慧施工项目Id
newItem.LastTime = DateTime.Now;//入库时间
newItem.WbsCode = item.WbsCode;//装置工序主项码
newItem.DeviceCode = item.DeviceCode;//装置码
newItem.ProcessesCode = item.ProcessesCode;//工序码
newItem.SubjectCode = item.SubjectCode;//主项码
newItem.Category = item.Category;
newItem.Tag = item.Tag;
newItem.InstrumentTag = item.InstrumentTag;
newItem.UseTo = item.UseTo;
newItem.InstrumentName = item.InstrumentName;
newItem.Supplier = item.Supplier;
newItem.InstallationPosition = item.InstallationPosition;
newItem.SignalType = item.SignalType;
newItem.AssociatedSystem = item.AssociatedSystem;
newItem.Cp25 = item.Cp25;
newItem.In11 = item.In11;
newItem.In40 = item.In40;
newItem.Remark = item.Remark;
newItem.DetailInfo = JsonConvert.SerializeObject(item, Formatting.Indented);
if (!string.IsNullOrWhiteSpace(item.ItemId) && idpInstrumentationIds.Contains(item.ItemId))
{//编辑
modifyItems.Add(newItem);
}
else
{//新增
addItems.Add(newItem);
idpInstrumentationIds.Add(item.ItemId);
}
}
}
}
catch (WebException ex)
{
result = $"程序异常:{ex.Message}";
}
}
if (addItems.Any()) { AddIDPPreRunInstrumentation(addItems); }
if (modifyItems.Any()) { ModifyIDPPreRunInstrumentation(modifyItems); }
result = $"成功!总数:{all}条;新增:{addItems.Count()}条,维护:{(all - addItems.Count())}条";
}
return result;
}
/// <summary>
/// 批量插入数据
/// </summary>
/// <param name="list"></param>
public static void AddIDPPreRunInstrumentation(List<Model.IDP_PreRunData_Instrumentation> list)
{
Model.SGGLDB db = Funs.DB;
db.IDP_PreRunData_Instrumentation.InsertAllOnSubmit(list);
db.SubmitChanges();
}
/// <summary>
/// 更新数据
/// </summary>
/// <param name="list"></param>
public static void ModifyIDPPreRunInstrumentation(List<Model.IDP_PreRunData_Instrumentation> list)
{
Model.SGGLDB db = Funs.DB;
foreach (var obj in list)
{
IDP_PreRunData_Instrumentation newItem = db.IDP_PreRunData_Instrumentation.FirstOrDefault(x => x.ItemId == obj.ItemId);
if (newItem != null)
{
newItem.ProjId = obj.ProjId;//主数据项目Id
newItem.ProjCode = obj.ProjCode;//主数据项目Code
newItem.ProjectId = obj.ProjectId;//智慧施工项目Id
newItem.LastTime = DateTime.Now;//入库时间
newItem.WbsCode = obj.WbsCode;//装置工序主项码
newItem.DeviceCode = obj.DeviceCode;//装置码
newItem.ProcessesCode = obj.ProcessesCode;//工序码
newItem.SubjectCode = obj.SubjectCode;//主项码
newItem.Category = obj.Category;
newItem.Tag = obj.Tag;
newItem.InstrumentTag = obj.InstrumentTag;
newItem.UseTo = obj.UseTo;
newItem.InstrumentName = obj.InstrumentName;
newItem.Supplier = obj.Supplier;
newItem.InstallationPosition = obj.InstallationPosition;
newItem.SignalType = obj.SignalType;
newItem.AssociatedSystem = obj.AssociatedSystem;
newItem.Cp25 = obj.Cp25;
newItem.In11 = obj.In11;
newItem.In40 = obj.In40;
newItem.Remark = obj.Remark;
newItem.DetailInfo = obj.DetailInfo;
db.SubmitChanges();
}
}
}
#endregion
#endregion
@@ -650,7 +1184,7 @@ namespace BLL
#endregion
#region
#region IDP平台接口授权认证
/// <summary>
/// 加密公钥