using FineUIPro;
using System;
using System.Collections;
using System.Linq;
namespace BLL
{
///
/// 安全数据仓库
///
public static class HSEDataDWService
{
#region 安全数据仓库
///
/// 记录数
///
public static int count
{
get;
set;
}
///
/// 定义变量
///
private static IQueryable getDataLists = from x in Funs.DB.Base_Project
where x.ProjectState == Const.ProjectState_1
select x;
///
/// 安全数据仓库
///
///
///
///
///
///
public static IEnumerable getDataDWList(string projectId, DateTime? startTime, DateTime? endTime, Grid Grid1)
{
IQueryable getDataList = getDataLists;
if (!string.IsNullOrEmpty(projectId) && projectId != Const._Null)
{
getDataList = getDataList.Where(x => x.ProjectId == projectId);
}
count = getDataList.Count();
if (count == 0)
{
return null;
}
getDataList = SortConditionHelper.SortingAndPaging(getDataList, Grid1.SortField, Grid1.SortDirection, Grid1.PageIndex, Grid1.PageSize);
var db1 = Funs.DB;
return from x in getDataList
select new
{
x.ProjectId,
x.ProjectName,
x.ProjectCode,
Count1 = db1.SitePerson_Person.Where(p => p.ProjectId == x.ProjectId && p.States == Const.ProjectPersonStates_1).Count(), //人员数量
Count2 = getProjecctSafeHours(x.ProjectId), //安全人工时
Count3 = db1.EduTrain_TrainRecord.Where(p => p.ProjectId == x.ProjectId && p.States == BLL.Const.State_2).Count(), //安全培训次数
ProblemRate = getProblemRate(x.ProjectId), //安全巡检整改率
};
}
#endregion
///
/// 安全人工时
///
///
///
public static int getProjecctSafeHours(string projectId)
{
int count = 0;
var getPersonInOutNumber = (from x in Funs.DB.SitePerson_PersonInOutNumber
where (x.ProjectId == projectId || projectId == null)
select x).OrderByDescending(x => x.InOutDate).FirstOrDefault();
if (getPersonInOutNumber != null)
{
count = getPersonInOutNumber.WorkHours ?? 0;
}
return count;
}
///
/// 安全问题整改率
///
///
///
public static string getProblemRate(string projectId)
{
var getAllHazardRegister = from x in Funs.DB.HSSE_Hazard_HazardRegister
where (x.ProjectId == projectId || projectId == null)
&& x.States != null && x.States != "4" && x.States != "0"
select x;
int allHazardCount = getAllHazardRegister.Count();
int cHazardCount = getAllHazardRegister.Where(x => x.States == "3").Count();
return allHazardCount > 0 ? Math.Round(cHazardCount * 100.0 / (allHazardCount * 1.0)).ToString() + "%" : "0%";
}
}
}