CNCEC_SUBQHSE_WUHUAN/SGGL/BLL/IDP/IDPDataService.cs

445 lines
18 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using Apache.NMS.ActiveMQ.Commands;
using Aspose.Words.Lists;
using Microsoft.SqlServer.Dts.Runtime;
using Model;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Org.BouncyCastle.Ocsp;
using SgManager.AI;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Net;
using System.Security.Cryptography;
using System.Security.Policy;
using System.ServiceModel.Channels;
using System.Text;
namespace BLL
{
/// <summary>
/// IDP平台接口服务
/// </summary>
public static class IDPDataService
{
/// <summary>
/// 测试环境api地址
/// </summary>
private static readonly string IDPApiUrl = "http://10.5.6.151:8100/";
///// <summary>
///// 正式环境api地址
///// </summary>
//private static readonly string IDPApiUrl = "https://idp.cwcec.com/";
//private static readonly string IDPApiUrl = SysConstSetService.WuHuanIDPPath;
#region
/// <summary>
/// 加密公钥
/// </summary>
private static readonly string publicKey = "<RSAKeyValue><Modulus>g1sk7Xtc1TJouHdY4+FAe5atGCu2n17NhoKVDV57pki1IL+9+S7BY4gxAjmMkUU2/cbCCdbPoUJLBrCBCjX7yI3UJW6FZwQWkn3kVoeulLEwdPCIq/GUjMXaWf3Iaaad5wBUFbfXAzv15VN6z48Nt1IY/O8YEzhIpuZdtEgDdos=</Modulus><Exponent>AQAB</Exponent></RSAKeyValue>";
//private static readonly string publicKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQChnc2YD0YzJPx6QTh+/n7XzjR1ugFzrsmPolJhpCfWMKrSGbT7iX/Kgcm1AI+T95K4Jzv3KS42QTecZ1ziJ4Rr9Luzw+9ZCSjMZgrmAUbY5IeBaA6GzaSk8UWHZ4n5PL+GUGq+2f+COL7+KCS2AxEpaqDZVrJrIfg/UektdgNyzwIDAQAB";
/// <summary>
/// 第三方加密认证接口
/// </summary>
/// 五环IDP系统SessionId有效期30分钟
/// <returns></returns>
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;
}
/// <summary>
/// 加密字符串
/// </summary>
/// <param name="data">加密信息</param>
/// <param name="publicKey">公钥</param>
/// <returns></returns>
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
#region
#region IDP
/// <summary>
/// 质量管理设计图纸
/// </summary>
/// <param name="projectId">项目Id</param>
/// <param name="startDate">获取指定日期之后到现在的异动数据</param>
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<IDP_DesignDrawing> listAdd = new List<IDP_DesignDrawing>();
List<IDP_DesignDrawing> listModify = new List<IDP_DesignDrawing>();
int pageSize = 1000;//一次性最多返回1000条数据
int maxPageNum = 100;
List<string> idpFileIds = DesignDrawingService.GetIDPDesignDrawingFileId();
List<IDP_DesignDrawing> 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.FormatFileName = item.formatFileName;
newItem.FileVersion = item.fileVersion;
newItem.MajorNo = item.majorNo;
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)
{
}
finally
{
}
}
/// <summary>
/// 批量插入数据
/// </summary>
/// <param name="list"></param>
public static void AddIDP_DesignDrawing(List<Model.IDP_DesignDrawing> list)
{
Model.SGGLDB db = Funs.DB;
db.IDP_DesignDrawing.InsertAllOnSubmit(list);
db.SubmitChanges();
}
/// <summary>
/// 更新数据
/// </summary>
/// <param name="list"></param>
public static void ModifyIDP_DesignDrawing(List<Model.IDP_DesignDrawing> 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.FormatFileName = obj.FormatFileName;
newItem.FileVersion = obj.FileVersion;
newItem.MajorNo = obj.MajorNo;
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
/// <summary>
/// 接收保存数据
/// </summary>
/// <param name="newItem"></param>
public static string SaveDesignDrawingData(OADesignDrawingData newItems)
{
try
{
string message = string.Empty;
using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString))
{
foreach (var item in newItems.DataItems)
{
if (!string.IsNullOrWhiteSpace(item.RdpId))
{
IDP_DesignDrawing newItem = db.IDP_DesignDrawing.FirstOrDefault(x => x.StockId == item.RdpId);
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();
}
}
else
{
}
}
}
return message;
}
catch (WebException ex)
{
return ex.Message;
}
finally
{
}
}
#endregion
#endregion
#region
/// <summary>
/// 获取工作包结构化数据
/// </summary>
public static void GetIDPProjectMasterData()
{
string projectId = string.Empty;//五环主数据项目Id
string wbsCode = string.Empty;//五环主数据wbs编码
string workitemCode = string.Empty;//五环主数据文件类别码
//https://idp.cwcec.com/OSS/projects/9100168/wbs/000000/workitems/CP2100/objects/latest
//string url = $"{IDPApiUrl}/OSS/projects/{projectId}/wbs/{wbsCode}/workitems/{workitemCode}/objects/latest";
string url = $"{IDPApiUrl}/OSS/projects/9100168/wbs/000000/workitems/CP2100/objects/latest";
//测试环境接口地址
var testApiUrl = "http://10.5.6.151:8100/OSS/projects/9100168/wbs/000000/workitems/CP2100/objects/latest";
try
{
var session = GetAuthenticationSession();
ErrLogInfo.WriteLog($"Session——name{session.name}value{session.value}");
Hashtable newToken = new Hashtable { { session.name, session.value } };
var returndata = BLL.APIGetHttpService.OutsideHttp(url, "GET", null, newToken, null);
}
catch (WebException ex)
{
}
finally
{
}
}
//public static void AddPMP_Project(List<Model.PMP_Project> newtables)
//{
// Model.SGGLDB db = Funs.DB;
// db.PMP_Project.InsertAllOnSubmit(newtables);
// db.SubmitChanges();
//}
//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();
// }
//}
#endregion
}
public class SessionItem
{
/// <summary>
/// value
/// </summary>
public string value { get; set; }
/// <summary>
/// name
/// </summary>
public string name { get; set; }
}
}