175 lines
10 KiB
C#
175 lines
10 KiB
C#
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();
|
|
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 = "";
|
|
projectDataItem.constructionco= string .Join(",", getSGName) ?? "";
|
|
projectDataItem.remains = "";
|
|
projectDataItem.contractdurition = "";
|
|
projectDataItem.contractenddate = "";
|
|
projectDataItem.supervisoryco = "";
|
|
projectDataItem.onsiteworkers = "";
|
|
projectDataItem.risknum = "";
|
|
projectDataItem.accidentsnum = "";
|
|
projectDataItem.constructionnum = "";
|
|
|
|
string unit_JL = ProjectService.getProjectUnitNameByUnitType(item.ProjectId, Const.ProjectUnitType_3);
|
|
string unit_yz = ProjectService.getProjectUnitNameByUnitType(item.ProjectId, Const.ProjectUnitType_4);
|
|
|
|
if (!string.IsNullOrEmpty(unit_JL))
|
|
{
|
|
projectDataItem.supervisoryco = unit_JL ?? "";
|
|
}
|
|
if (!string.IsNullOrEmpty(unit_yz))
|
|
{
|
|
projectDataItem.buildco = unit_yz ?? "";
|
|
|
|
}
|
|
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 ?? "";
|
|
|
|
var safehoursData = (from x in Funs.DB.HSSE_MonthReportItem
|
|
join y in Funs.DB.HSSE_MonthReport on x.MonthReportId equals y.MonthReportId
|
|
// where ("成达公司HSE管理人数" == x.ReportItem || "分包商HSE管理人数" == x.ReportItem) && y.Years == DateTime.Now.Year && y.ProjectId==CurrUser.LoginProjectId
|
|
where ("安全生产人工时数" == x.ReportItem) && y.Years == DateTime.Now.Year && y.ProjectId == item.ProjectId
|
|
select x.YearTotal).Sum();
|
|
projectDataItem.safehours = safehoursData.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() ?? "";
|
|
|
|
var ProjectTotal1 = (from x in Funs.DB.HSSE_MonthReportItem
|
|
join y in Funs.DB.HSSE_MonthReport on x.MonthReportId equals y.MonthReportId
|
|
// where ("成达公司HSE管理人数" == x.ReportItem || "分包商HSE管理人数" == x.ReportItem) && y.Years == DateTime.Now.Year && y.ProjectId==CurrUser.LoginProjectId
|
|
where ("成达公司现场人数" == x.ReportItem) && y.Years == DateTime.Now.Year && y.ProjectId == item.ProjectId
|
|
select x.YearTotal).Sum();
|
|
var ProjectTotal2 = (from x in Funs.DB.HSSE_MonthReportItem
|
|
join y in Funs.DB.HSSE_MonthReport on x.MonthReportId equals y.MonthReportId
|
|
// where ("成达公司现场人数" == x.ReportItem || "分包商现场人数" == x.ReportItem) && y.Years == DateTime.Now.Year && y.ProjectId == CurrUser.LoginProjectId
|
|
where ("分包商现场人数" == x.ReportItem) && y.Years == DateTime.Now.Year && y.ProjectId == item.ProjectId
|
|
select x.YearTotal).Sum();
|
|
|
|
if (ProjectTotal2.HasValue && ProjectTotal1.HasValue)
|
|
{
|
|
projectDataItem.onsiteworkers = (ProjectTotal1.Value + ProjectTotal2.Value).ToString();//项目现场总人数
|
|
}
|
|
|
|
// 获取当前月份
|
|
int currentMonth = DateTime.Now.Month;
|
|
int currentYear = DateTime.Now.Year;
|
|
int ProjectTotal3Value = 0;
|
|
int ProjectTotal4Value = 0;
|
|
projectDataItem.onsiteperson = "";
|
|
projectDataItem.maxperson = "";
|
|
var ProjectTotal3 = (from x in Funs.DB.HSSE_MonthReportItem
|
|
join y in Funs.DB.HSSE_MonthReport on x.MonthReportId equals y.MonthReportId
|
|
where ("成达公司现场人数" == x.ReportItem)&& y.Years == currentYear && y.ProjectId == item.ProjectId
|
|
select x).FirstOrDefault();
|
|
if (ProjectTotal3 !=null)
|
|
{
|
|
ProjectTotal3Value = int.Parse((ProjectTotal3.GetType().GetProperty("Month" + currentMonth)?.GetValue(ProjectTotal3, null)?.ToString() ?? "0") );
|
|
projectDataItem.onsiteperson = ProjectTotal3Value.ToString() ?? ""; // 本月现场人数
|
|
|
|
}
|
|
|
|
var ProjectTotal4 = (from x in Funs.DB.HSSE_MonthReportItem
|
|
join y in Funs.DB.HSSE_MonthReport on x.MonthReportId equals y.MonthReportId
|
|
where ("成达公司HSE管理人数" == x.ReportItem) && y.Years == currentYear && y.ProjectId == item.ProjectId
|
|
select x).FirstOrDefault();
|
|
if (ProjectTotal4 != null)
|
|
{
|
|
ProjectTotal4Value = int.Parse((ProjectTotal4.GetType().GetProperty("Month" + currentMonth)?.GetValue(ProjectTotal4, null)?.ToString() ?? "0"));
|
|
projectDataItem.maxperson = (ProjectTotal4Value + ProjectTotal3Value).ToString() ?? ""; //现场高峰人数
|
|
|
|
}
|
|
|
|
|
|
|
|
var getHazards = from x in Funs.DB.Hazard_HazardSelectedItem
|
|
join y in Funs.DB.Base_RiskLevel on x.HazardLevel equals y.RiskLevelId
|
|
where x.ProjectId == item.ProjectId && x.IsStart == true
|
|
select new { x.HazardSelectedItemId, y.RiskLevel };
|
|
projectDataItem.risknum = getHazards.Count(x => x.RiskLevel == 1).ToString();//一级风险预警数量
|
|
|
|
var accidentNum1 = (from x in Funs.DB.Accident_AccidentPersonRecord
|
|
join y in Funs.DB.Base_AccidentType on x.AccidentTypeId equals y.AccidentTypeId
|
|
where x.ProjectId == item.ProjectId
|
|
select x).Count();
|
|
|
|
var accidentNum2 = (from x in Funs.DB.Accident_AccidentReport
|
|
where x.ProjectId == item.ProjectId
|
|
select x).Count();
|
|
projectDataItem.accidentsnum = (accidentNum1 + accidentNum2).ToString() ?? "";//安全事故数量
|
|
|
|
projectDataItem.constructionnum= ProjectService.GetProjectWorkList().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;
|
|
//return null;
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|