using Model; using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; namespace BLL { public class MainSevice { /// /// 在建项目集合 /// private List _beUnderConstructionList; private HSSEData_HSSE _hsseData; private CQMSData_CQMS _cqmsData; private HJGLData_HJGL _hjglData; private string _unitId; private int _unitType; public MainSevice(string userid) { var userModel = UserService.GetUserByUserId(userid); int unitType = CommonService.GetUnitTypeByUserId(userid); var projectList = BaseDataService.GetBeUnderConstruction(); _unitId = userModel.UnitId; _unitType = unitType; if (unitType == 0) { _beUnderConstructionList = projectList.Select(x => x.ProjectId).ToList(); _unitId = CommonService.GetThisUnitId(); } else if (unitType == 1) { _beUnderConstructionList = projectList.Where(x => x.UnitId == userModel.UnitId).Select(x => x.ProjectId).ToList(); } else if (unitType == 2) { _beUnderConstructionList = new List() { "0" }; } } public MainSevice(string userid, string projectId) { var userModel = UserService.GetUserByUserId(userid); int unitType = 3; _unitId = userModel.UnitId ?? ""; _unitType = unitType; _beUnderConstructionList = new List() { projectId }; } /// /// 获取安全数据(项目统计数据直接取的统计表) /// /// public async Task GetHsseData() { HSSEData_HSSE result = new HSSEData_HSSE(); var getHseData = Funs.DB.HSSEData_HSSE.OrderByDescending(x => x.ReportDate).FirstOrDefault(); switch (_unitType) { case 0: //企业级 result = getHseData; break; case 1: //分公司级别 result = HSSEData_HSSEService.GetSubUnitCqmsDataByDate(_beUnderConstructionList, getHseData.ReportDate); ////涉及到企业级别的统计直接取值 //var BeUnderConstructionDic = BaseDataService.BeUnderConstructionDic; //result.BeUnderConstructionNum = BeUnderConstructionDic.Count(x => x.Value == _unitId); //result.ShutdownNum = BaseDataService.GetShutdown().Count(x => x.UnitId == _unitId); var beUnderConstructionTask = HSSEData_HSSEService.GetBeUnderConstructionAsync();//在建项目 var shutdownTask = HSSEData_HSSEService.GetShutdownAsync();//停工项目 // 统一获取异步方法的返回值 var beUnderConstructionList = await beUnderConstructionTask; var shutdownList = await shutdownTask; result.BeUnderConstructionNum = beUnderConstructionList.Count(x => x.UnitId == _unitId); result.ShutdownNum = shutdownList.Count(x => x.UnitId == _unitId); break; case 3: //项目级别 var projectHsseData = Funs.DB.Project_HSSEData_HSSE.OrderByDescending(x => x.ReportDate).FirstOrDefault(x => x.ProjectId == _beUnderConstructionList.FirstOrDefault()); if (projectHsseData != null) { result = HSSEData_HSSEService.GetSubUnitCqmsDataByDate(_beUnderConstructionList, projectHsseData.ReportDate); } break; } return result; } } }