ChengDa_English/SGGL/BLL/API/APICdPuService.cs

89 lines
4.4 KiB
C#
Raw Normal View History

2024-06-18 10:32:39 +08:00
using Microsoft.SqlServer.Dts.Runtime;
using Model;
using NPOI.SS.Formula.Functions;
using Pipelines.Sockets.Unofficial.Arenas;
using RestSharp;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.PeerToPeer;
using System.Runtime.InteropServices.ComTypes;
using System.Text;
using System.Threading.Tasks;
namespace BLL
{
public static class APICdPuService
{
public static string PushData()
{
using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString))
{
List<ProjectDataItem> projectDataItems = new List<ProjectDataItem>();
var projectlist = ProjectService.GetProjectWorkList().Where(x=>x.ProjectCode== "E21028");
foreach (var item in projectlist)
{
var getSGName = (from x in db.Project_ProjectUnit
join y in db.Base_Unit on x.UnitId equals y.UnitId
where x.ProjectId == item.ProjectId && x.UnitType == Const.ProjectUnitType_2
select y.UnitName);
ProjectDataItem projectDataItem = new ProjectDataItem();
projectDataItem.projectnumber = item.ProjectCode;
projectDataItem.projectname = item.ProjectName;
projectDataItem.projcost = item.ProjectMoney.ToString();
projectDataItem.buildco = item.WorkRange;
projectDataItem.constructionco= string .Join(",", getSGName);
string unit_JL = ProjectService.getProjectUnitNameByUnitType(item.ProjectId, Const.ProjectUnitType_3);
if (!string.IsNullOrEmpty(unit_JL))
{
projectDataItem.supervisoryco = unit_JL;
}
if (item.EndDate.HasValue)
{
projectDataItem.contractenddate = string.Format("{0:yyyy-MM-dd}", item.EndDate);
if (item.StartDate.HasValue)
{
int pdays = (item.EndDate.Value - item.StartDate.Value).Days;
if (pdays >= 0)
{
projectDataItem.contractdurition = pdays.ToString();
}
}
}
projectDataItem.location = item.ProjectAddress;
projectDataItem.safehours = Project_HSSEData_HSSEService.GetSafeWorkingHour(item.ProjectId).ToString();
projectDataItem.losshours = Project_HSSEData_HSSEService.GetLostWorkingHour(item.ProjectId).ToString();
List<Model.Comprehensive_NCRManagement> NondestructiveTestList = (from x in db.Comprehensive_NCRManagement
where x.ProjectId == item.ProjectId && (x.IssuedDate ==null || x.IssuedDate >DateTime.Now) select x).ToList();
projectDataItem.ncr = NondestructiveTestList.Count.ToString();
projectDataItems.Add(projectDataItem);
}
var JsonBody = Newtonsoft.Json.JsonConvert.SerializeObject(projectDataItems);
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
string Baseurl = "https://pu.chengda.com/cdpu//report/saveNbdData";
var client = new RestClient(Baseurl);
client.Timeout = -1;
var request = new RestRequest(Method.POST);
//request.AddHeader("ClientId", SysConstSetService.ClientId);
request.AddHeader("OperationCode", Baseurl.Substring(Baseurl.LastIndexOf("/", StringComparison.Ordinal) + 1));
if (!string.IsNullOrEmpty(JsonBody))
{
request.AddJsonBody(JsonBody);
}
APICommonService.SaveSysHttpLog("CDPU", Baseurl, " Body :" + JsonBody, "Request|" + request.Method.ToString());
IRestResponse response = client.Execute(request);
APICommonService.SaveSysHttpLog("CDPU", Baseurl, "Header :" + response.Headers + "| Body :" + response.Content, "Response|" + request.Method.ToString());
return response.Content;
}
}
}
}