using Apache.NMS.ActiveMQ;
using Model;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Quartz.Util;
using System;
using System.Collections;
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
{
///
/// IDP平台接口服务
///
public static class IDPDataService
{
/////
///// 测试环境api地址
/////
//private static readonly string IDPApiUrl = "http://10.5.6.151:8100/";
///
/// 正式环境api地址
///
//private static readonly string IDPApiUrl = "https://idp.cwcec.com/";
private static readonly string IDPApiUrl = SysConstSetService.WuHuanIDPPath;
#region 试车工作包
#region 管道一览表
///
/// 项目试车工作包——管道一览表
///
/// session
/// 项目Id
public static string GetIDPProjectPreRunDataPiping(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 idpPipingIds = IDPPreRunDataService.GetIDPPreRunDataPipingIds(projectId);
List addItems = new List();
List modifyItems = new List();
int all = 0;
foreach (var pro in mainProjects)
{
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 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;
}
///
/// 批量插入数据
///
///
public static void AddIDPPreRunPiping(List list)
{
Model.SGGLDB db = Funs.DB;
db.IDP_PreRunData_Piping.InsertAllOnSubmit(list);
db.SubmitChanges();
}
///
/// 更新数据
///
///
public static void ModifyIDPPreRunPiping(List list)
{
Model.SGGLDB db = Funs.DB;
foreach (var obj in list)
{
IDP_PreRunData_Piping newItem = db.IDP_PreRunData_Piping.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.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();
}
}
}
#endregion
#region 设备一览表
///
/// 项目试车工作包——设备一览表
///
///
///
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 idpEquipmentIds = IDPPreRunDataService.GetIDPPreRunDataEquipmentIds(projectId);
List addItems = new List();
List modifyItems = new List();
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 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().PropertyName}:{item.DrivingType};";
}
if (!string.IsNullOrWhiteSpace(item.EquipmentType))
{
nameSpecifications = $"{nameSpecifications} {type.GetProperty("EquipmentType").GetCustomAttribute().PropertyName}:{item.EquipmentType};";
}
if (!string.IsNullOrWhiteSpace(item.EquipmentTypeModel))
{
nameSpecifications = $"{nameSpecifications} {type.GetProperty("EquipmentTypeModel").GetCustomAttribute().PropertyName}:{item.EquipmentTypeModel};";
}
if (!string.IsNullOrWhiteSpace(item.EquipmentForm))
{
nameSpecifications = $"{nameSpecifications} {type.GetProperty("EquipmentForm").GetCustomAttribute().PropertyName}:{item.EquipmentForm};";
}
if (!string.IsNullOrWhiteSpace(item.MPaG))
{
nameSpecifications = $"{nameSpecifications} {type.GetProperty("MPaG").GetCustomAttribute().PropertyName}:{item.MPaG} {item.MPaGUnit};";
}
if (!string.IsNullOrWhiteSpace(item.KPa))
{
nameSpecifications = $"{nameSpecifications} {type.GetProperty("KPa").GetCustomAttribute().PropertyName}:{item.KPa} {item.KPaUnit};";
}
if (!string.IsNullOrWhiteSpace(item.DimensionsID))
{
nameSpecifications = $"{nameSpecifications} {type.GetProperty("DimensionsID").GetCustomAttribute().PropertyName}:{item.DimensionsID} {item.DimensionsIDUnit};";
}
if (!string.IsNullOrWhiteSpace(item.DimensionsHTT))
{
nameSpecifications = $"{nameSpecifications} {type.GetProperty("DimensionsHTT").GetCustomAttribute().PropertyName}:{item.DimensionsHTT} {item.DimensionsHTTUnit};";
}
if (!string.IsNullOrWhiteSpace(item.DesignFlow))
{
nameSpecifications = $"{nameSpecifications} {type.GetProperty("DesignFlow").GetCustomAttribute().PropertyName}:{item.DesignFlow} {item.DesignFlowUnit};";
}
if (!string.IsNullOrWhiteSpace(item.ShaftPower))
{
nameSpecifications = $"{nameSpecifications} {type.GetProperty("ShaftPower").GetCustomAttribute().PropertyName}:{item.ShaftPower} {item.ShaftPowerUnit};";
}
if (!string.IsNullOrWhiteSpace(item.RatedPower))
{
nameSpecifications = $"{nameSpecifications} {type.GetProperty("RatedPower").GetCustomAttribute().PropertyName}:{item.RatedPower} {item.RatedPowerUnit};";
}
string materials = string.Empty;
if (!string.IsNullOrWhiteSpace(item.Materials))
{
materials = $"{type.GetProperty("Materials").GetCustomAttribute().PropertyName}:{item.Materials};";
}
if (!string.IsNullOrWhiteSpace(item.ImpellerMaterial))
{
materials = $"{materials} {type.GetProperty("ImpellerMaterial").GetCustomAttribute().PropertyName}:{item.ImpellerMaterial};";
}
if (!string.IsNullOrWhiteSpace(item.ShellMaterial))
{
materials = $"{materials} {type.GetProperty("ShellMaterial").GetCustomAttribute().PropertyName}:{item.ShellMaterial};";
}
if (!string.IsNullOrWhiteSpace(item.CylinderMaterial))
{
materials = $"{materials} {type.GetProperty("CylinderMaterial").GetCustomAttribute().PropertyName}:{item.CylinderMaterial};";
}
if (!string.IsNullOrWhiteSpace(item.TrayMaterial))
{
materials = $"{materials} {type.GetProperty("TrayMaterial").GetCustomAttribute().PropertyName}:{item.TrayMaterial};";
}
if (!string.IsNullOrWhiteSpace(item.PackingMaterial))
{
materials = $"{materials} {type.GetProperty("PackingMaterial").GetCustomAttribute().PropertyName}:{item.PackingMaterial};";
}
if (!string.IsNullOrWhiteSpace(item.PlateMaterial))
{
materials = $"{materials} {type.GetProperty("PlateMaterial").GetCustomAttribute().PropertyName}:{item.PlateMaterial};";
}
if (!string.IsNullOrWhiteSpace(item.TrimMaterial))
{
materials = $"{materials} {type.GetProperty("TrimMaterial").GetCustomAttribute().PropertyName}:{item.TrimMaterial};";
}
if (!string.IsNullOrWhiteSpace(item.CoilMaterial))
{
materials = $"{materials} {type.GetProperty("CoilMaterial").GetCustomAttribute().PropertyName}:{item.CoilMaterial};";
}
if (!string.IsNullOrWhiteSpace(item.PreheaterMaterial))
{
materials = $"{materials} {type.GetProperty("PreheaterMaterial").GetCustomAttribute().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;
}
///
/// 批量插入数据
///
///
public static void AddIDPPreRunEquipment(List list)
{
Model.SGGLDB db = Funs.DB;
db.IDP_PreRunData_Equipment.InsertAllOnSubmit(list);
db.SubmitChanges();
}
///
/// 更新数据
///
///
public static void ModifyIDPPreRunEquipment(List 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 仪表索引
///
/// 项目试车工作包——仪表索引
///
///
///
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 idpInstrumentationIds = IDPPreRunDataService.GetIDPPreRunDataInstrumentationIds(projectId);
List addItems = new List();
List modifyItems = new List();
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 results = new List();
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 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 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;
}
///
/// 批量插入数据
///
///
public static void AddIDPPreRunInstrumentation(List list)
{
Model.SGGLDB db = Funs.DB;
db.IDP_PreRunData_Instrumentation.InsertAllOnSubmit(list);
db.SubmitChanges();
}
///
/// 更新数据
///
///
public static void ModifyIDPPreRunInstrumentation(List 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
#region 质量管理设计图纸
#region IDP
///
/// 质量管理设计图纸
///
/// 项目Id
/// 获取指定时间之后到现在的异动数据
public static void GetIDPProjectDesignDrawingData(string projectId = "", string startDate = "")
{
try
{
//五环主数据项目Code
string projectCode = string.Empty;
if (!string.IsNullOrWhiteSpace(projectId))
{//根据施工平台项目Id获取主数据项目Code
var getPro = ProjectService.GetProjectByProjectId(projectId);
projectCode = getPro.ProjectCode;
}
string timeStampStr = string.Empty;
if (!string.IsNullOrWhiteSpace(startDate))
{
string format = "yyyy-MM-dd";
DateTimeOffset dateTimeOffset = DateTimeOffset.ParseExact(startDate, format, CultureInfo.InvariantCulture);
long timeStamp = Funs.GetDateTimeStamp(dateTimeOffset, 13);
timeStampStr = timeStamp.ToString();
}
var session = GetAuthenticationSession();
//ErrLogInfo.WriteLog($"【Session】name:{session.name};value:{session.value}");
Hashtable newToken = new Hashtable { { "Cookie", $"{session.name}={session.value}" } };
List listAdd = new List();
List listModify = new List();
int pageSize = 1000;//一次性最多返回1000条数据
int maxPageNum = 100;
List idpFileIds = DesignDrawingService.GetIDPDesignDrawingFileId();
List idpFiles = DesignDrawingService.GetIDPDesignDrawingFile();
for (int pageNum = 1; pageNum < 100000; pageNum++)
{
if (pageNum > maxPageNum) { break; }
string url = $"{IDPApiUrl}EDC/third/workitems?pageNum={pageNum}&pageSize={pageSize}";
if (!string.IsNullOrWhiteSpace(timeStampStr)) { url = $"{url}&lastTimestamp={timeStampStr}"; }
if (!string.IsNullOrWhiteSpace(projectCode)) { url = $"{url}&projectCode={projectCode}"; }
var returndata = BLL.APIGetHttpService.OutsideHttp(url, "GET", null, newToken, null);
if (!string.IsNullOrEmpty(returndata))
{
IDPDesignDrawingResponseData responseData = IDPDesignDrawingResponseData.FromJson(returndata);
maxPageNum = responseData.page.pages;
foreach (var item in responseData.page.results)
{
IDP_DesignDrawing newItem = new IDP_DesignDrawing();
if (!string.IsNullOrWhiteSpace(projectId))
{
newItem.ProjectId = projectId;
}
else
{
if (string.IsNullOrWhiteSpace(item.projectCode))
{
continue;
}
var getProject = ProjectService.GetProjectByProjectCode(item.projectCode);
if (getProject == null)
{
continue;
}
newItem.ProjectId = getProject.ProjectId;
}
newItem.IdpfileId = item.fileId;
newItem.StockId = item.stockId;
newItem.ThirdId = item.thirdId;
newItem.ProjectCode = item.projectCode;
newItem.DisplayProjectName = item.displayProjectName;
newItem.ProjectDeviceProcedureSubjectCode = item.projectDeviceProcedureSubjectCode;
newItem.WbsFullPath = item.wbsFullPath;
newItem.FormatFileCode = item.formatFileCode;
newItem.FormatFileName = item.formatFileName;
newItem.FileVersion = item.fileVersion;
newItem.MajorNo = item.majorNo;
newItem.MajorName = item.majorName;
newItem.Status = item.status;
newItem.DesignUserName = item.designUserName;
newItem.JiaoheUserName = item.jiaoheUserName;
newItem.ShenheUserName = item.shenheUserName;
newItem.ShendingUserName = item.shendingUserName;
newItem.MajorResponsibleUserName = item.majorResponsibleUserName;
newItem.ClassificationLevelInProject = item.classificationLevelInProject;
newItem.UpdateTime = item.updateTime;
newItem.Remark = item.remark;
if (!string.IsNullOrWhiteSpace(item.fileId) && idpFileIds.Contains(item.fileId))
{//编辑
newItem.Id = idpFiles.Where(x => x.IdpfileId == item.fileId).FirstOrDefault().Id;
listModify.Add(newItem);
}
else
{//新增
newItem.Id = SQLHelper.GetNewID(typeof(IDP_DesignDrawing));
listAdd.Add(newItem);
}
}
}
else
{
break;
}
}
if (listAdd.Any())
{
AddIDP_DesignDrawing(listAdd);
}
if (listModify.Any())
{
ModifyIDP_DesignDrawing(listModify);
}
}
catch (WebException ex)
{
}
}
///
/// 批量插入数据
///
///
public static void AddIDP_DesignDrawing(List list)
{
Model.SGGLDB db = Funs.DB;
db.IDP_DesignDrawing.InsertAllOnSubmit(list);
db.SubmitChanges();
}
///
/// 更新数据
///
///
public static void ModifyIDP_DesignDrawing(List list)
{
Model.SGGLDB db = Funs.DB;
foreach (var obj in list)
{
IDP_DesignDrawing newItem = db.IDP_DesignDrawing.FirstOrDefault(x => x.Id == obj.Id);
if (newItem != null)
{
newItem.StockId = obj.StockId;
newItem.ThirdId = obj.ThirdId;
newItem.ProjectId = obj.ProjectId;
newItem.ProjectCode = obj.ProjectCode;
newItem.DisplayProjectName = obj.DisplayProjectName;
newItem.ProjectDeviceProcedureSubjectCode = obj.ProjectDeviceProcedureSubjectCode;
newItem.WbsFullPath = obj.WbsFullPath;
newItem.FormatFileCode = obj.FormatFileCode;
newItem.FormatFileName = obj.FormatFileName;
newItem.FileVersion = obj.FileVersion;
newItem.MajorNo = obj.MajorNo;
newItem.MajorName = obj.MajorName;
newItem.Status = obj.Status;
newItem.DesignUserName = obj.DesignUserName;
newItem.JiaoheUserName = obj.JiaoheUserName;
newItem.ShenheUserName = obj.ShenheUserName;
newItem.ShendingUserName = obj.ShendingUserName;
newItem.MajorResponsibleUserName = obj.MajorResponsibleUserName;
newItem.ClassificationLevelInProject = obj.ClassificationLevelInProject;
newItem.UpdateTime = obj.UpdateTime;
newItem.Remark = obj.Remark;
db.SubmitChanges();
}
}
}
#endregion
#region 数字档案馆
///
/// 数字档案馆webApi地址
///
private static readonly string GetApiUrl = "https://getapi.cwcec.com/api/WebApi";
///
/// 接收保存数据
///
///
public static string SaveDesignDrawingData(List items)
{
try
{
string message = string.Empty;
int succ = 0;
int err = 0;
using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString))
{
foreach (var item in items)
{
if (!string.IsNullOrWhiteSpace(item.RdpId) && !string.IsNullOrWhiteSpace(item.fileid))
{
IDP_DesignDrawing newItem = db.IDP_DesignDrawing.FirstOrDefault(x => x.StockId == item.RdpId && x.ThirdId == item.fileid);
if (newItem != null)
{
newItem.RdpId = item.RdpId;
newItem.Fileid = item.fileid;
newItem.Upfileid = item.upfileid;
newItem.Maintitle = item.maintitle;
newItem.Doc_no = item.doc_no;
newItem.Bc = item.bc;
newItem.Archnumber = item.archnumber;
newItem.Sendtime = item.sendtime;
newItem.Printtime = item.printtime;
newItem.Ifmail = item.ifmail;
db.SubmitChanges();
succ++;
}
else
{
err++;
}
}
else
{
err++;
}
}
message = $"总数{(succ + err)}条;失败{err}条,成功{succ}条!";
}
return message;
}
catch (WebException ex)
{
return ex.Message;
}
}
///
/// 质量管理设计图纸——更新蓝图寄出信息
///
/// 项目Id
/// 开始时间
/// 结束时间
public static string GetDesignDrawingDataBlueprintInfo(string projectId = "", string startDate = "", string endDate = "")
{
try
{
string message = string.Empty;
//五环主数据项目Code
string projectCode = string.Empty;
if (!string.IsNullOrWhiteSpace(projectId))
{//根据施工平台项目Id获取主数据项目Code
var getPro = ProjectService.GetProjectByProjectId(projectId);
projectCode = getPro.ProjectCode;
}
if (string.IsNullOrWhiteSpace(startDate))
{
startDate = DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd");
}
if (string.IsNullOrWhiteSpace(endDate))
{
endDate = DateTime.Now.AddDays(+1).ToString("yyyy-MM-dd");
}
string url = $"{GetApiUrl}/GetBlueprintInfo?BeginTime={startDate}&EndTime={endDate}";
if (!string.IsNullOrWhiteSpace(projectCode)) { url = $"{url}&item_id={projectCode}"; }
////folderNo:文件包号(示例:18063-40401-AR15)
//if (!string.IsNullOrWhiteSpace(folderNo)) { url = $"{url}&folderNo={folderNo}"; }
////IsUpgrade:文件版次(示例:9)
//if (!string.IsNullOrWhiteSpace(IsUpgrade)) { url = $"{url}&IsUpgrade={IsUpgrade}"; }
//ErrLogInfo.WriteLog($"接口地址{url}");
//var returndata = "[{\"item_id\":\"22150\",\"modifiedTime\":\"2022/3/9 15:21:32\",\"folderNo\":\"22150-21000-WT2501-001\",\"isUpgrade\":\"D00\",\"fileType\":\"非设备蓝图\",\"senderName\":\"吴荟\",\"receiverAddress\":\"新疆哈密市伊吾县淖毛湖镇广汇生活区12号楼\",\"receiverName\":\"李娟\",\"receiverType\":\"业主\",\"receiverUnit\":\"哈密广汇环保科技有限公司\"},{\"item_id\":\"22150\",\"modifiedTime\":\"2022/3/9 15:21:33\",\"folderNo\":\"22150-21000-WT4401-001\",\"isUpgrade\":\"D00\",\"fileType\":\"非设备蓝图\",\"senderName\":\"吴荟\",\"receiverAddress\":\"新疆哈密市伊吾县淖毛湖镇广汇生活区12号楼\",\"receiverName\":\"李娟\",\"receiverType\":\"业主\",\"receiverUnit\":\"哈密广汇环保科技有限公司\"},{\"item_id\":\"22150\",\"modifiedTime\":\"2022/3/19 15:23:33\",\"folderNo\":\"22150-21000-WT4401-001\",\"isUpgrade\":\"D00\",\"fileType\":\"非设备蓝图\",\"senderName\":\"吴荟\",\"receiverAddress\":\"新疆哈密市伊吾县淖毛湖镇广汇生活区12号楼\",\"receiverName\":\"李娟\",\"receiverType\":\"业主\",\"receiverUnit\":\"哈密广汇环保科技有限公司\"}]";
var returndata = BLL.APIGetHttpService.OutsideHttp(url, "GET", null, null, null);
//ErrLogInfo.WriteLog($"返回结果:{returndata}");
if (!string.IsNullOrEmpty(returndata))
{
int succ = 0;
int err = 0;
using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString))
{
List responseData = BlueprintInfoItems.FromJson(returndata);
if (responseData.Any())
{
//ErrLogInfo.WriteLog($"序列化对象:ok");
responseData = responseData.OrderByDescending(x => x.modifiedTime).ToList();
responseData = responseData.GroupBy(p => new { p.item_id, p.folderNo, p.isUpgrade }).Select(g => g.First()).ToList();
foreach (var item in responseData)
{
IDP_DesignDrawing newItem = db.IDP_DesignDrawing.FirstOrDefault(x => x.ProjectCode == item.item_id && x.FormatFileCode == item.folderNo && x.FileVersion == item.isUpgrade);
if (newItem == null)
{
err++;
continue;
}
newItem.Sendtime = item.modifiedTime;
db.SubmitChanges();
succ++;
}
}
}
message = $"成功。总数:{(succ + err)}条;成功更新{succ}条,失败{err}条。";
}
else
{
message = "无数据";
}
return message;
}
catch (WebException ex)
{
return ex.Message;
}
}
///
/// 质量管理设计图纸——更新蓝图打印信息
///
/// 项目Id
/// 开始时间
/// 结束时间
public static string GetDesignDrawingDataPrintInfo(string projectId = "", string startDate = "", string endDate = "")
{
try
{
string message = string.Empty;
//五环主数据项目Code
string projectCode = string.Empty;
if (!string.IsNullOrWhiteSpace(projectId))
{//根据施工平台项目Id获取主数据项目Code
var getPro = ProjectService.GetProjectByProjectId(projectId);
projectCode = getPro.ProjectCode;
}
if (string.IsNullOrWhiteSpace(startDate))
{
startDate = DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd");
}
if (string.IsNullOrWhiteSpace(endDate))
{
endDate = DateTime.Now.AddDays(+1).ToString("yyyy-MM-dd");
}
string url = $"{GetApiUrl}/GetPrintInfo?BeginTime={startDate}&EndTime={endDate}";
if (!string.IsNullOrWhiteSpace(projectCode)) { url = $"{url}&item_id={projectCode}"; }
////folderNo:文件包号(示例:18063-40401-AR15)
//if (!string.IsNullOrWhiteSpace(folderNo)) { url = $"{url}&folderNo={folderNo}"; }
////IsUpgrade:文件版次(示例:9)
//if (!string.IsNullOrWhiteSpace(IsUpgrade)) { url = $"{url}&IsUpgrade={IsUpgrade}"; }
//var returndata = "[{\"recorder\":\"姚曙光\",\"item_id\":\"22150\",\"item_name\":\"哈密广汇环保科技有限公司荒煤气综合利用年产40万吨乙二醇项目\",\"folderNo\":\"22150-21000-WT2501-001\",\"folder_name\":\"文件目录-202203091052472988\",\"isUpgrade\":\"D00\",\"createTime\":\"2022/3/10 10:52:47\",\"doc_printtime\":\"2022/3/10 15:30:46\",\"isPrint\":\"是\",\"project_id\":\"3288\"},{\"recorder\":\"姚曙光\",\"item_id\":\"22150\",\"item_name\":\"哈密广汇环保科技有限公司荒煤气综合利用年产40万吨乙二醇项目\",\"folderNo\":\"22150-21000-WT4401-001\",\"folder_name\":\"门窗表-202203091052527479\",\"isUpgrade\":\"D00\",\"createTime\":\"2022/3/12 10:52:53\",\"doc_printtime\":\"2022/3/12 15:30:46\",\"isPrint\":\"是\",\"project_id\":\"3288\"}]";
var returndata = BLL.APIGetHttpService.OutsideHttp(url, "GET", null, null, null);
if (!string.IsNullOrEmpty(returndata))
{
int succ = 0;
int err = 0;
using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString))
{
List responseData = PrintInfoItems.FromJson(returndata);
if (responseData.Any())
{
responseData = responseData.OrderByDescending(x => x.doc_printtime).ToList();
responseData = responseData.GroupBy(p => new { p.item_id, p.folderNo, p.isUpgrade }).Select(g => g.First()).ToList();
foreach (var item in responseData)
{
IDP_DesignDrawing newItem = db.IDP_DesignDrawing.FirstOrDefault(x => x.ProjectCode == item.item_id && x.FormatFileCode == item.folderNo && x.FileVersion == item.isUpgrade);
if (newItem == null)
{
err++;
continue;
}
newItem.Printtime = item.doc_printtime;
db.SubmitChanges();
succ++;
}
}
}
message = $"成功。总数:{(succ + err)}条;成功更新{succ}条,失败{err}条。";
}
else
{
message = "无数据";
}
return message;
}
catch (WebException ex)
{
return ex.Message;
}
}
///
/// 质量管理设计图纸——更新蓝图寄出信息【暂时不用,同步历史数据时,可调整方法】
///
/// 项目Id
/// 开始时间
/// 结束时间
public static void GetDesignDrawingDataBlueprintInfo1(DateTime startDate, DateTime endDate)
{
try
{
string message = string.Empty;
string url = $"{GetApiUrl}/GetBlueprintInfo?BeginTime={startDate}&EndTime={endDate}";
//if (!string.IsNullOrWhiteSpace(projectCode)) { url = $"{url}&item_id={projectCode}"; }
////folderNo:文件包号(示例:18063-40401-AR15)
//if (!string.IsNullOrWhiteSpace(folderNo)) { url = $"{url}&folderNo={folderNo}"; }
////IsUpgrade:文件版次(示例:9)
//if (!string.IsNullOrWhiteSpace(IsUpgrade)) { url = $"{url}&IsUpgrade={IsUpgrade}"; }
//ErrLogInfo.WriteLog($"接口地址{url}");
//var returndata = "[{\"item_id\":\"22150\",\"modifiedTime\":\"2022/3/9 15:21:32\",\"folderNo\":\"22150-21000-WT2501-001\",\"isUpgrade\":\"D00\",\"fileType\":\"非设备蓝图\",\"senderName\":\"吴荟\",\"receiverAddress\":\"新疆哈密市伊吾县淖毛湖镇广汇生活区12号楼\",\"receiverName\":\"李娟\",\"receiverType\":\"业主\",\"receiverUnit\":\"哈密广汇环保科技有限公司\"},{\"item_id\":\"22150\",\"modifiedTime\":\"2022/3/9 15:21:33\",\"folderNo\":\"22150-21000-WT4401-001\",\"isUpgrade\":\"D00\",\"fileType\":\"非设备蓝图\",\"senderName\":\"吴荟\",\"receiverAddress\":\"新疆哈密市伊吾县淖毛湖镇广汇生活区12号楼\",\"receiverName\":\"李娟\",\"receiverType\":\"业主\",\"receiverUnit\":\"哈密广汇环保科技有限公司\"},{\"item_id\":\"22150\",\"modifiedTime\":\"2022/3/19 15:23:33\",\"folderNo\":\"22150-21000-WT4401-001\",\"isUpgrade\":\"D00\",\"fileType\":\"非设备蓝图\",\"senderName\":\"吴荟\",\"receiverAddress\":\"新疆哈密市伊吾县淖毛湖镇广汇生活区12号楼\",\"receiverName\":\"李娟\",\"receiverType\":\"业主\",\"receiverUnit\":\"哈密广汇环保科技有限公司\"}]";
var returndata = BLL.APIGetHttpService.OutsideHttp(url, "GET", null, null, null);
//ErrLogInfo.WriteLog($"返回结果:{returndata}");
if (!string.IsNullOrEmpty(returndata))
{
int succ = 0;
int err = 0;
using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString))
{
List responseData = BlueprintInfoItems.FromJson(returndata);
if (responseData.Any())
{
//ErrLogInfo.WriteLog($"序列化对象:ok");
responseData = responseData.OrderByDescending(x => x.modifiedTime).ToList();
responseData = responseData.GroupBy(p => new { p.item_id, p.folderNo, p.isUpgrade }).Select(g => g.First()).ToList();
foreach (var item in responseData)
{
IDP_DesignDrawing newItem = db.IDP_DesignDrawing.FirstOrDefault(x => x.ProjectCode == item.item_id && x.FormatFileCode == item.folderNo && x.FileVersion == item.isUpgrade);
if (newItem == null)
{
err++;
continue;
}
newItem.Sendtime = item.modifiedTime;
db.SubmitChanges();
succ++;
}
}
}
message = $"成功。总数:{(succ + err)}条;成功更新{succ}条,失败{err}条。";
}
else
{
message = "无数据";
}
if (startDate > DateTime.Now)
{
//return message;
}
else
{
GetDesignDrawingDataBlueprintInfo1(startDate.AddDays(1), startDate.AddDays(2));
}
}
catch (WebException ex)
{
//return ex.Message;
}
}
///
/// 质量管理设计图纸——更新蓝图打印信息【暂时不用,同步历史数据时,可调整方法】
///
/// 项目Id
/// 开始时间
/// 结束时间
public static string GetDesignDrawingDataPrintInfo1(string projectId = "", string startDate = "", string endDate = "")
{
try
{
string message = string.Empty;
//五环主数据项目Code
string projectCode = string.Empty;
if (!string.IsNullOrWhiteSpace(projectId))
{//根据施工平台项目Id获取主数据项目Code
var getPro = ProjectService.GetProjectByProjectId(projectId);
projectCode = getPro.ProjectCode;
}
if (string.IsNullOrWhiteSpace(startDate))
{
startDate = DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd");
}
else
if (string.IsNullOrWhiteSpace(endDate))
{
endDate = DateTime.Now.AddDays(+1).ToString("yyyy-MM-dd");
}
string url = $"{GetApiUrl}/GetPrintInfo?BeginTime={startDate}&EndTime={endDate}";
if (!string.IsNullOrWhiteSpace(projectCode)) { url = $"{url}&item_id={projectCode}"; }
////folderNo:文件包号(示例:18063-40401-AR15)
//if (!string.IsNullOrWhiteSpace(folderNo)) { url = $"{url}&folderNo={folderNo}"; }
////IsUpgrade:文件版次(示例:9)
//if (!string.IsNullOrWhiteSpace(IsUpgrade)) { url = $"{url}&IsUpgrade={IsUpgrade}"; }
//var returndata = "[{\"recorder\":\"姚曙光\",\"item_id\":\"22150\",\"item_name\":\"哈密广汇环保科技有限公司荒煤气综合利用年产40万吨乙二醇项目\",\"folderNo\":\"22150-21000-WT2501-001\",\"folder_name\":\"文件目录-202203091052472988\",\"isUpgrade\":\"D00\",\"createTime\":\"2022/3/10 10:52:47\",\"doc_printtime\":\"2022/3/10 15:30:46\",\"isPrint\":\"是\",\"project_id\":\"3288\"},{\"recorder\":\"姚曙光\",\"item_id\":\"22150\",\"item_name\":\"哈密广汇环保科技有限公司荒煤气综合利用年产40万吨乙二醇项目\",\"folderNo\":\"22150-21000-WT4401-001\",\"folder_name\":\"门窗表-202203091052527479\",\"isUpgrade\":\"D00\",\"createTime\":\"2022/3/12 10:52:53\",\"doc_printtime\":\"2022/3/12 15:30:46\",\"isPrint\":\"是\",\"project_id\":\"3288\"}]";
var returndata = BLL.APIGetHttpService.OutsideHttp(url, "GET", null, null, null);
if (!string.IsNullOrEmpty(returndata))
{
int succ = 0;
int err = 0;
using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString))
{
List responseData = PrintInfoItems.FromJson(returndata);
if (responseData.Any())
{
responseData = responseData.OrderByDescending(x => x.doc_printtime).ToList();
responseData = responseData.GroupBy(p => new { p.item_id, p.folderNo, p.isUpgrade }).Select(g => g.First()).ToList();
foreach (var item in responseData)
{
IDP_DesignDrawing newItem = db.IDP_DesignDrawing.FirstOrDefault(x => x.ProjectCode == item.item_id && x.FormatFileCode == item.folderNo && x.FileVersion == item.isUpgrade);
if (newItem == null)
{
err++;
continue;
}
newItem.Printtime = item.doc_printtime;
db.SubmitChanges();
succ++;
}
}
}
message = $"成功。总数:{(succ + err)}条;成功更新{succ}条,失败{err}条。";
}
else
{
message = "无数据";
}
return message;
}
catch (WebException ex)
{
return ex.Message;
}
}
#endregion
#endregion
#region IDP平台接口授权认证
///
/// 加密公钥
///
private static readonly string publicKey = "g1sk7Xtc1TJouHdY4+FAe5atGCu2n17NhoKVDV57pki1IL+9+S7BY4gxAjmMkUU2/cbCCdbPoUJLBrCBCjX7yI3UJW6FZwQWkn3kVoeulLEwdPCIq/GUjMXaWf3Iaaad5wBUFbfXAzv15VN6z48Nt1IY/O8YEzhIpuZdtEgDdos=AQAB";
//private static readonly string publicKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQChnc2YD0YzJPx6QTh+/n7XzjR1ugFzrsmPolJhpCfWMKrSGbT7iX/Kgcm1AI+T95K4Jzv3KS42QTecZ1ziJ4Rr9Luzw+9ZCSjMZgrmAUbY5IeBaA6GzaSk8UWHZ4n5PL+GUGq+2f+COL7+KCS2AxEpaqDZVrJrIfg/UektdgNyzwIDAQAB";
///
/// 第三方加密认证接口
///
/// 五环IDP系统SessionId有效期30分钟
///
public static SessionItem GetAuthenticationSession()
{
SessionItem session = new SessionItem();
try
{
//// 创建RSA加密服务提供者
////using (RSA rsa = RSA.Create())
//using (RSACryptoServiceProvider rsa = new RSACryptoServiceProvider())
//{
//// 获取公钥false表示只导出公钥
//string publicKey = rsa.ToXmlString(false);
//// 获取私钥true表示导出公钥和私钥
//string privateKey = rsa.ToXmlString(true);
////用户名加密
//string encryptedUsername = EncryptData("dataviewer", publicKey);
////密码加密
//string encryptedPassword = EncryptData("a3365$!", publicKey);
//用户名加密后的密文
string encryptedUsername = "k0N0tx/hfRPY0v2lq1G8eH6hCO+UiMqlSZi1PD6bhGf4YpP/koJq5hfMsDSzdn3dZjzExrwyrjFWp/1jZLde0+gRbQ0D7tzm0R5D6AmriodD2cJvrEiwtDy7SeGNloSaNmpTEMuycpuueiOeGhMkKnTwWfRkEw73lxEpTmaahq4=";
//密码加密后的密文
string encryptedPassword = "HLLroiNJJzyTWJt9td1xgChbVzyQkoxWCGGXqdwI2cvlUF/A30FAPaInszSwEhNRQlJZZ01EODElemkgv36DMF+XGwfDi0BfIq9jKG+/+wq0TVOHNhiu2NPzpn5Ji2X3yXIXpH1zv6XEtkvx/qiLToZYfRQCufsl5vH1cZxk2fQ=";
string url = $"{IDPApiUrl}UAMS/authEncrypt";
//string url = $"http://10.5.6.151:8100/UAMS/authEncrypt";
string contenttype = "application/json;charset=utf-8";
var body = new
{
encryptedUsername = encryptedUsername,
encryptedPassword = encryptedPassword
};
string pushContent = JsonConvert.SerializeObject(body);
string strJosn = APIGetHttpService.Http(url, "POST", contenttype, null, pushContent);
//string strJosn = HttpHelper.Post(url, null, pushContent);
JObject obj = JObject.Parse(strJosn);
if (!string.IsNullOrEmpty(strJosn))
{
string value = obj["value"].ToString();
string name = obj["name"].ToString();
session.value = value;
session.name = name;
}
//}
}
catch (WebException ex)
{
return null;
}
finally
{
}
return session;
}
///
/// 加密字符串
///
/// 加密信息
/// 公钥
///
public static string EncryptData(string data, string publicKey)
{
using (RSACryptoServiceProvider rsa = new RSACryptoServiceProvider())
{
string result = string.Empty;
try
{
rsa.FromXmlString(publicKey); //从字符串加载公钥
byte[] dataBytes = Encoding.UTF8.GetBytes(data);
byte[] encryptedBytes = rsa.Encrypt(dataBytes, false); //使用公钥加密数据,false表示使用OAEP填充方式
result = Convert.ToBase64String(encryptedBytes); //返回Base64编码的加密数据
}
catch (Exception ex)
{
Console.WriteLine("Error encrypting: {0}", ex.Message);
}
return result;
}
}
#endregion
}
}