xinjiang/SGGL/FineUIPro.Web/HSSE/KqShowScreen/JZYScreen.aspx.cs

403 lines
17 KiB
C#

using BLL;
using Microsoft.Office.Interop.Word;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.UI.WebControls;
namespace FineUIPro.Web.HSSE.KqShowScreen
{
public partial class JZYScreen : PageBase
{
#region
/// <summary>
/// 项目主键
/// </summary>
public string ProjectId
{
get
{
return (string)ViewState["ProjectId"];
}
set
{
ViewState["ProjectId"] = value;
}
}
public string ProjectName
{
get
{
return (string)ViewState["ProjectName"];
}
set
{
ViewState["ProjectName"] = value;
}
}
#endregion
#region
/// <summary>
/// 加载页面
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.ProjectId = this.CurrUser.LoginProjectId;
var project = Funs.DB.Base_Project.FirstOrDefault(x=>x.ProjectId==ProjectId);
if (project != null)
{
if (!string.IsNullOrEmpty(project.ShortName))
{
ProjectName= project.ShortName;
}
else
{
ProjectName = project.ProjectName;
}
}
}
}
#endregion
[WebMethod]
public static object getData(string projectId)
{
//let leftLabel = ['施工人员', '十六化建管理人员', '天辰管理人员', '监理管理人员', '业主管理人员', '当前现场总人数', '当日最高人数']
int num1 = 0;
int num2 = 0;
int num3 = 0;
int num4 = 0;
int num5 = 0;
int num6 = 0;
int num7 = 0;
try
{
int total = 0;
HashSet<string> ids = new HashSet<string>();
HashSet<string> idsIn = new HashSet<string>();
HashSet<string> personAll = new HashSet<string>();
Dictionary<string, DateTime> inperson = new Dictionary<string, DateTime>();
Dictionary<string, DateTime> outPerson = new Dictionary<string, DateTime>();
DateTime dateTime = DateTime.Now.AddDays(-1);
var inout = Funs.DB.SitePerson_PersonInOut.Where(x => x.ProjectId == projectId && x.ChangeTime > dateTime).OrderByDescending(x => x.ChangeTime);
var unitid1 = Funs.DB.Project_ProjectUnit.Where(x => x.ProjectId == projectId && x.UnitType == Const.ProjectUnitType_3).Select(x => x.UnitId).ToArray();
var unitname1 = Funs.DB.Base_Unit.Where(x => unitid1.Contains(x.UnitId)).Select(x => x.UnitName).ToArray();
var unitid2 = Funs.DB.Project_ProjectUnit.Where(x => x.ProjectId == projectId && x.UnitType == Const.ProjectUnitType_4).Select(x => x.UnitId);
var unitname2 = Funs.DB.Base_Unit.Where(x => unitid2.Contains(x.UnitId)).Select(x => x.UnitName).ToArray();
Dictionary<string, int> company = new Dictionary<string, int>();
Dictionary<string, int> companySys = new Dictionary<string, int>();
Dictionary<string, int> workPost = new Dictionary<string, int>();
Dictionary<string, int> workPostSys = new Dictionary<string, int>();
foreach (var io in inout)
{
personAll.Add(io.PersonId);
ids.Add(io.PersonId);
if (io.IsIn.HasValue && io.IsIn.Value) //24小时内最晚的入场
{
if (inperson.ContainsKey(io.PersonId))
{
if (inperson[io.PersonId] < io.ChangeTime.Value)
{
inperson[io.PersonId] = io.ChangeTime.Value;
}
}
else
{
if (io.ChangeTime.HasValue)
{
inperson.Add(io.PersonId, io.ChangeTime.Value);
}
}
}
else //24小时内最晚的出场
{
if (outPerson.ContainsKey(io.PersonId))
{
if (outPerson[io.PersonId] < io.ChangeTime.Value)
{
outPerson[io.PersonId] = io.ChangeTime.Value;
}
}
else
{
if (io.ChangeTime.HasValue)
{
outPerson.Add(io.PersonId, io.ChangeTime.Value);
}
}
}
}
num7 = personAll.Count;
foreach (var id in ids)
{
if (inperson.ContainsKey(id) && !outPerson.ContainsKey(id))//只有入场没有出场 在场
{
idsIn.Add(id);
num6++;
}
else if (inperson.ContainsKey(id) && outPerson.ContainsKey(id))
{
if (inperson[id] > outPerson[id])//最晚入场时间 小于出场时间 在场
{
idsIn.Add(id);
num6++;
}
}
}
num1 = num6;
HashSet<string> keys1 = new HashSet<string>();
HashSet<string> keys2 = new HashSet<string>();
foreach (var io in inout)
{
if (idsIn.Contains(io.PersonId))
{
if (!string.IsNullOrEmpty(io.WorkPostName))
{
if (!keys1.Contains(io.PersonId))
{
keys1.Add(io.PersonId);
if (workPost.ContainsKey(io.UnitName + ";" + io.WorkPostName))
{
workPost[io.UnitName + ";" + io.WorkPostName] = workPost[io.UnitName + ";" + io.WorkPostName] + 1;
}
else
{
workPost[io.UnitName + ";" + io.WorkPostName] = 1;
}
}
}
if (!string.IsNullOrEmpty(io.UnitName))
{
if (!keys2.Contains(io.PersonId))
{
keys2.Add(io.PersonId);
if (company.ContainsKey(io.UnitName))
{
company[io.UnitName] = company[io.UnitName] + 1;
}
else
{
company[io.UnitName] = 1;
}
}
}
}
}
var workPosts = Funs.DB.Base_WorkPost.ToList();
string strSql = @"SELECT p.UnitId
,ISNULL((case when u.UnitName=''then null else u.UnitName end),'未知') AS UnitName
,p.WorkPostId as PostId
,w.PostType
,ISNULL((case when W.WorkPostName=''then null else W.WorkPostName end),'未知') AS PostName
,COUNT( distinct PersonId) AS PersonCountSum
FROM dbo.SitePerson_Person AS P
LEFT JOIN dbo.Base_Unit AS U ON P.UnitId=U.UnitId
LEFT JOIN dbo.Base_WorkPost AS W ON P.WorkPostId=W.WorkPostId
LEFT JOIN dbo.Project_ProjectUnit AS pu ON pu.UnitId=p.UnitId and pu.ProjectId=p.ProjectId
WHERE pu.ProjectId is not null and P.ProjectId = '" + projectId + @"' and P.InTime <=GETDATE() and ( P.OutTime is null or P.OutTime > GETDATE()) and p.IsUsed =1
GROUP BY P.ProjectId,P.UnitId,U.UnitName,P.WorkPostId,w.PostType,W.WorkPostName";
System.Data.DataTable tb = SQLHelper.GetDataTableRunText(strSql, null);
if (tb != null && tb.Rows.Count > 0)
{
foreach (DataRow row in tb.Rows)
{
if (!string.IsNullOrEmpty(row["PostName"].ToString()))
{
if (!workPostSys.ContainsKey(row["UnitName"].ToString() + ";" + row["PostName"].ToString()))
{
workPostSys.Add(row["UnitName"].ToString() + ";" + row["PostName"].ToString(), 0);
}
workPostSys[row["UnitName"].ToString() + ";" + row["PostName"].ToString()] = workPostSys[row["UnitName"].ToString() + ";" + row["PostName"].ToString()] + int.Parse(row["PersonCountSum"].ToString());
}
if (!string.IsNullOrEmpty(row["UnitName"].ToString()))
{
if (!companySys.ContainsKey(row["UnitName"].ToString()))
{
companySys.Add(row["UnitName"].ToString(), 0);
}
companySys[row["UnitName"].ToString()] = companySys[row["UnitName"].ToString()] + int.Parse(row["PersonCountSum"].ToString());
}
}
}
string html = "";
List<object> comStatic = new List<object>();
foreach (var key in company.Keys)
{
string unitName = key;
var unit = Funs.DB.Base_Unit.FirstOrDefault(x => x.UnitName == unitName);
if (unit != null && !string.IsNullOrEmpty(unit.ShortUnitName))
{
unitName = unit.ShortUnitName;
}
if (!unitname2.Contains(key)&&!unitname1.Contains(key )&& "中国天辰工程有限公司" != key)
{
html += @" <div class='tr'>
<div class='td' style='width: 20%;'><span>" + unitName + @"</span></div>
<div class='td' style='width: 20%;'>" + company[key] + "/" + (companySys.ContainsKey(key) ? companySys[key] : 0) + @"</div>
<div class='row-box' style='width: 60%;'> ";
}
int MPerson = 0;
int MPersonSys = 0;
int SPerson = 0;
int SPersonSys = 0;
string workPostName = "";
string workPostNum = "";
string workPostSysNum = "";
foreach (var key2 in workPost.Keys)
{
MPerson = 0;
SPerson = 0;
string[] keys = key2.Split(';');
if (key == keys[0])
{
if (unitname2.Contains(key))
{
num5 += workPost[key2];
}
else if ("中国天辰工程有限公司" == key)
{
num3 += workPost[key2];
}
else if (unitname1.Contains(key))
{
num4 += workPost[key2];
}
var workPostTemp = workPosts.FirstOrDefault(w => w.WorkPostName == keys[1]);
if (workPostTemp != null)
{
if (workPostTemp.PostType == Const.PostType_1)//管理人员
{
//if ("中国化学工程第十六建设有限公司" == key)//十六化建管理人员
//{
// num2 += workPost[key2];
//}
//else
num1 -= workPost[key2];
MPerson += workPost[key2];
MPersonSys += workPostSys.ContainsKey(key2) ? workPostSys[key2] : 0;
}
else if (workPostTemp.PostType == Const.PostType_2)//特种作业人员
{
SPerson += workPost[key2];
SPersonSys += workPostSys.ContainsKey(key2) ? workPostSys[key2] : 0;
workPostName += " <span> " + keys[1] + " </span> ";
workPostNum += " <span> " + workPost[key2] + " </span> ";
workPostSysNum += " <span> " + (workPostSys.ContainsKey(key2) ? workPostSys[key2] : 0) + " </span> ";
}
}
}
}
var ZPerson = company[key] - MPerson - SPerson;
var ZPersonSys = company[key] - MPersonSys - SPersonSys;
//workPostName += "<span>作业人员</span> ";
//workPostNum += " <span>" + ZPerson + "</span>";
//workPostSysNum += " <span>" + ZPersonSys + "</span>";
//workPostName += " <span>管理人员</span> ";
//workPostNum += " <span>" + MPerson + "</span>";
//workPostSysNum += " <span>" + MPersonSys + "</span>";
if (!unitname2.Contains(key) && !unitname1.Contains(key) && "中国天辰工程有限公司" != key)
{
html += @"<div class='td' style='width: 50%;align-items:start;'>"
+ workPostName +
@"</div>
<div class='td' style='width: 25%;'>"
+ workPostSysNum +
@"</div>
<div class='td' style='width: 25%;'>"
+ workPostNum +
@"</div>
</div>
</div>";
}
}
int safeTotal = 0;
int safeTotalWeek = 0;
var getMax = from x in Funs.DB.SitePerson_DayReportDetail
join y in Funs.DB.SitePerson_DayReport on x.DayReportId equals y.DayReportId
where y.ProjectId==projectId
select x;
if (getMax.Count() > 0)
{
safeTotal = Convert.ToInt32(getMax.Sum(x => x.PersonWorkTime) ?? 0);
}
var getWeek = from x in Funs.DB.SitePerson_DayReportDetail
join y in Funs.DB.SitePerson_DayReport on x.DayReportId equals y.DayReportId
where y.ProjectId == projectId
where y.CompileDate > DateTime.Now.AddDays(-7)
select x;
if (getWeek.Count() > 0)
{
safeTotalWeek = Convert.ToInt32(getWeek.Sum(x => x.PersonWorkTime) ?? 0);
}
num1 = num6 - num5 - num4 - num3;
return new { company = html, total, num = new int[] { num1, num3, num4, num5, num6, num7 }, safeTotal, safeTotalWeek };
}
catch (Exception e)
{
return new { company = e.Message };
}
}
}
}