using FineUIPro;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
namespace BLL
{
///
/// WBS分析
///
public static class WBSAnalysisService
{
#region WBS分析
///
/// 记录数
///
public static int count
{
get;
set;
}
///
/// 定义变量
///
private static IQueryable getDataLists = from x in Funs.DB.WBS_WorkPackageInit
select x;
///
/// 合同管理数据仓库
///
///
///
///
///
///
public static IEnumerable getDataDWList(string workPackageId, Grid Grid1)
{
var getDataList = getDataLists;
if (string.IsNullOrEmpty(workPackageId))
{
List listWork = new List();
Model.WBS_WorkPackageInit work1 = new Model.WBS_WorkPackageInit
{
WorkPackageCode = "Type1",
PackageContent = "建筑工程",
};
listWork.Add(work1);
Model.WBS_WorkPackageInit work2 = new Model.WBS_WorkPackageInit
{
WorkPackageCode = "Type2",
PackageContent = "安装工程",
};
listWork.Add(work2);
getDataList = listWork.AsQueryable();
}
else
{
if (workPackageId != "1" && workPackageId != "2")
{
getDataList = getDataList.Where(x => x.SuperWorkPack == workPackageId);
if (getDataList.Count() == 0)
{
getDataList = getDataLists.Where(x => x.WorkPackageCode == workPackageId);
}
}
else
{
getDataList = getDataList.Where(x => x.ProjectType == workPackageId && x.SuperWorkPack == null);
}
}
count = getDataList.Count();
if (count == 0)
{
return null;
}
getDataList = SortConditionHelper.SortingAndPaging(getDataList, Grid1.SortField, Grid1.SortDirection, Grid1.PageIndex, Grid1.PageSize);
return from x in getDataList
select new
{
x.WorkPackageCode,
x.PackageContent,
Count1 = getWBSExpertArgumentCount(null, x.WorkPackageCode),
Count2 = getWBSAccidentCount(null, x.WorkPackageCode),
Count3 = getWBSHSEProblemCount(null, x.WorkPackageCode),
Count4 = getWBSSpotCheckRate(null, x.WorkPackageCode),
Count5 = getWBSSpotCheckDataRate(null, x.WorkPackageCode),
Count6 = getWBSCheckControlCount(null, x.WorkPackageCode),
};
}
#endregion
///
/// 危大工程数量
///
///
///
public static int getWBSExpertArgumentCount(string projectId, string workPackageId)
{
var getLargerHazardListItem = from x in Funs.DB.Solution_LargerHazardListItem
join y in Funs.DB.Solution_LargerHazardList on x.LargerHazardListId equals y.LargerHazardListId
where x.WorkPackageId.Contains(workPackageId)
&& y.States == Const.State_1
select new { x.LargerHazardListItemId, y.LargerHazardListId, y.ProjectId, x.WorkPackageId };
if (!string.IsNullOrEmpty(projectId))
{
getLargerHazardListItem = getLargerHazardListItem.Where(x => x.ProjectId == projectId);
}
return getLargerHazardListItem.Count();
}
///
/// 安全事故数量
///
///
///
public static int getWBSAccidentCount(string projectId, string workPackageId)
{
var getAccidentPersonRecord = from x in Funs.DB.Accident_AccidentPersonRecord
where x.WorkPackageId.Contains(workPackageId)
&& x.States == Const.State_2
select x;
if (!string.IsNullOrEmpty(projectId))
{
getAccidentPersonRecord = getAccidentPersonRecord.Where(x => x.ProjectId == projectId);
}
return getAccidentPersonRecord.Count();
}
///
/// 安全巡检问题总数
///
///
///
public static int getWBSHSEProblemCount(string projectId, string workPackageId)
{
var getHazardRegister = from x in Funs.DB.HSSE_Hazard_HazardRegister
where x.States != "4" && x.States != "0"
&& x.WorkPackageId.Contains(workPackageId)
select x;
if (!string.IsNullOrEmpty(projectId))
{
getHazardRegister = getHazardRegister.Where(x => x.ProjectId == projectId);
}
return getHazardRegister.Count();
}
///
/// 实体验收一次合格率
///
///
///
public static string getWBSSpotCheckRate(string projectId, string workPackageId)
{
var getSpotCheckDetail = from x in Funs.DB.Check_SpotCheckDetail
join y in Funs.DB.Check_SpotCheck on x.SpotCheckCode equals y.SpotCheckCode
where x.WorkPackageId.Contains(workPackageId) && (projectId == null || y.ProjectId == projectId)
&& y.State == "8"
select new { x.SpotCheckCode, y.ProjectId, x.IsDataOK, x.IsOnesOK };
if (!string.IsNullOrEmpty(projectId))
{
getSpotCheckDetail = getSpotCheckDetail.Where(x => x.ProjectId == projectId);
}
int all = getSpotCheckDetail.Count();
// this.lbSpotCheck1.Text = all.ToString();
int onesOKCount = getSpotCheckDetail.Where(x => x.IsOnesOK == true).Count(); //一次合格
return (all > 0 ? Math.Round(onesOKCount * 100.0 / (all * 1.0)).ToString() + "%" : "0%");
}
///
/// 施工资料同步率
///
///
///
public static string getWBSSpotCheckDataRate(string projectId, string workPackageId)
{
//// 实体验收 资料验收
var getSpotCheckDetail = from x in Funs.DB.Check_SpotCheckDetail
join y in Funs.DB.Check_SpotCheck on x.SpotCheckCode equals y.SpotCheckCode
where x.WorkPackageId.Contains(workPackageId)
&& y.State == "8"
select new { x.SpotCheckCode, y.ProjectId, x.IsDataOK, x.IsOnesOK, x.IsOK };
if (!string.IsNullOrEmpty(projectId))
{
getSpotCheckDetail = getSpotCheckDetail.Where(x => x.ProjectId == projectId);
}
/// 资料验收合格项目
var getOKSpotCheckDetail = getSpotCheckDetail.Where(x => x.IsOK == true);
int okYSCount = getOKSpotCheckDetail.Count(); //验收合格
int okDateCount = getSpotCheckDetail.Where(x => x.IsDataOK == "1").Count(); //资料合格
return (okYSCount > 0 ? Math.Round(okDateCount * 100.0 / (okYSCount * 1.0)).ToString() + "%" : "0%");
}
///
/// 质量问题数
///
///
///
public static int getWBSCheckControlCount(string projectId, string workPackageId)
{
var getCheck_CheckControl = from x in Funs.DB.Check_CheckControl
where x.WorkPackageId.Contains(workPackageId)
select x;
if (!string.IsNullOrEmpty(projectId))
{
getCheck_CheckControl = getCheck_CheckControl.Where(x => x.ProjectId == projectId);
}
return getCheck_CheckControl.Count();
}
}
}