using EmitMapper; using System; using System.Collections.Generic; using System.Linq; namespace BLL { public static class APIHazardRegisterService { /// /// 根据HazardRegisterId获取风险巡检信息 /// /// /// public static Model.HazardRegisterItem getHazardRegisterByHazardRegisterId(string hazardRegisterId) { using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString)) { var getHazardRegister = db.View_Hazard_HazardRegister.FirstOrDefault(x => x.HazardRegisterId == hazardRegisterId); return ObjectMapperManager.DefaultInstance.GetMapper().Map(getHazardRegister); } } /// /// 根据projectId、states获取风险信息(状态 1:待整改;2:已整改,待确认;3:已确认,即已闭环;4:已作废) /// /// /// /// public static List getHazardRegisterByProjectIdStates(string projectId, string states, int pageIndex) { using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString)) { var hazardRegisters = (from x in db.View_Hazard_HazardRegister where x.ProjectId == projectId && (x.States == states || states == null) orderby x.CheckTime descending select x).Skip(Funs.PageSize * (pageIndex - 1)).Take(Funs.PageSize).ToList(); return ObjectMapperManager.DefaultInstance.GetMapper, List>().Map(hazardRegisters.ToList()); } } /// /// 保存HazardRegister /// /// /// public static void SaveHazardRegister(Model.HazardRegisterItem hazardRegister) { using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString)) { Model.HSSE_Hazard_HazardRegister newHazardRegister = new Model.HSSE_Hazard_HazardRegister { HazardRegisterId = hazardRegister.HazardRegisterId, HazardCode = hazardRegister.HazardCode, RegisterDef = hazardRegister.RegisterDef, Rectification = hazardRegister.Rectification, Place = hazardRegister.Place, ResponsibleUnit = hazardRegister.ResponsibleUnit, ProjectId = hazardRegister.ProjectId, States = hazardRegister.States, IsEffective = "1", ResponsibleMan = hazardRegister.ResponsibleMan, CheckManId = hazardRegister.CheckManId, CheckTime = hazardRegister.CheckTime, RectificationPeriod = hazardRegister.RectificationPeriod, ImageUrl = hazardRegister.ImageUrl, RectificationImageUrl = hazardRegister.RectificationImageUrl, RectificationTime = hazardRegister.RectificationTime, ConfirmMan = hazardRegister.ConfirmMan, ConfirmDate = hazardRegister.ConfirmDate, HandleIdea = hazardRegister.HandleIdea, CutPayment = hazardRegister.CutPayment, ProblemTypes = hazardRegister.ProblemTypes, RegisterTypesId = string.IsNullOrEmpty(hazardRegister.RegisterTypesId) ? null : hazardRegister.RegisterTypesId, CheckCycle = hazardRegister.CheckCycle, SafeSupervisionIsOK = hazardRegister.SafeSupervisionIsOK, IsWx = "Y", CCManIds = hazardRegister.CCManIds, Requirements = hazardRegister.Requirements, HazardValue = string.IsNullOrEmpty(hazardRegister.HazardValue) ? null : hazardRegister.HazardValue, RegisterTypes2Id = string.IsNullOrEmpty(hazardRegister.RegisterTypes2Id) ? null : hazardRegister.RegisterTypes2Id, RegisterTypes3Id = string.IsNullOrEmpty(hazardRegister.RegisterTypes3Id) ? null : hazardRegister.RegisterTypes3Id, RegisterTypes4Id = string.IsNullOrEmpty(hazardRegister.RegisterTypes4Id) ? null : hazardRegister.RegisterTypes4Id, WorkPackageId=WorkPackageService.getWorkPageIdsByControlItemAndCycle(hazardRegister.WorkPackageId, null), WorkPackageName= WorkPackageService.getWorkPageNamesByControlItemAndCycle(hazardRegister.WorkPackageId, null), }; var isUpdate = db.HSSE_Hazard_HazardRegister.FirstOrDefault(x => x.HazardRegisterId == newHazardRegister.HazardRegisterId); if (isUpdate == null) { newHazardRegister.RegisterDate = DateTime.Now; newHazardRegister.CheckTime = DateTime.Now; if (string.IsNullOrEmpty(newHazardRegister.HazardRegisterId)) { newHazardRegister.HazardRegisterId = SQLHelper.GetNewID(); } db.HSSE_Hazard_HazardRegister.InsertOnSubmit(newHazardRegister); if (!string.IsNullOrEmpty(newHazardRegister.ImageUrl)) { APIUpLoadFileService.SaveAttachUrl(Const.HSSE_HiddenRectificationListMenuId, newHazardRegister.HazardRegisterId, newHazardRegister.ImageUrl, "0"); } } else { if (newHazardRegister.States == "2") { isUpdate.RectificationTime = DateTime.Now; isUpdate.Rectification = newHazardRegister.Rectification; isUpdate.RectificationImageUrl = newHazardRegister.RectificationImageUrl; if (!string.IsNullOrEmpty(newHazardRegister.RectificationImageUrl)) { APIUpLoadFileService.SaveAttachUrl(Const.HSSE_HiddenRectificationListMenuId, newHazardRegister.HazardRegisterId + "-R", newHazardRegister.RectificationImageUrl, "0"); } } else { isUpdate.ConfirmDate = DateTime.Now; isUpdate.ConfirmMan = newHazardRegister.ConfirmMan; isUpdate.HandleIdea = newHazardRegister.HandleIdea; isUpdate.SafeSupervisionIsOK = newHazardRegister.SafeSupervisionIsOK; } isUpdate.States = newHazardRegister.States; } db.SubmitChanges(); if (hazardRegister.States == Const.State_1) { APICommonService.SendSubscribeMessage(hazardRegister.ResponsibleMan, "安全巡检问题待整改", hazardRegister.CheckManName, string.Format("{0:yyyy-MM-dd HH:mm:ss}", hazardRegister.CheckTime)); } else if (hazardRegister.States == Const.State_2) { APICommonService.SendSubscribeMessage(hazardRegister.CheckManId, "安全巡检待复查验收", hazardRegister.ResponsibilityManName, string.Format("{0:yyyy-MM-dd HH:mm:ss}", hazardRegister.RectificationTime)); } } } /// /// 安全巡检 /// /// /// public static List getHazardRegisterByProjectIdStates(int pageIndex) { string unitName = null, unitId = null; var getUnit = CommonService.GetIsThisUnit(); if (getUnit != null) { unitId = getUnit.UnitId; unitName = getUnit.UnitName; } using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString)) { var hazardRegisters = (from x in db.HSSE_Hazard_HazardRegister join y in db.Base_Project on x.ProjectId equals y.ProjectId join u in db.Base_Unit on x.ResponsibleUnit equals u.UnitId where x.ProjectId != null && x.States != null select new Model.HazardRegisterItem { HazardRegisterId = x.HazardRegisterId, ProjectId = x.ProjectId, ProjectName = y.ProjectName, ProjectAddress = y.ProjectAddress, UnitId = unitId, UnitName = unitName, PUnitId = y.UnitId, PUnitName = db.Base_Unit.First(U => y.UnitId == U.UnitId).UnitName, States = x.States, WorkAreaName = db.WBS_UnitWork.First(w => x.Place == w.UnitWorkId).UnitWorkName, CheckTime = x.CheckTime, RegisterDef = x.RegisterDef, RegisterTypesName = db.HSSE_Hazard_HazardRegisterTypes.First(T => x.RegisterTypesId == T.RegisterTypesId).RegisterTypesName, Rectification = x.Rectification, ResponsibilityUnitName = db.Base_Unit.First(U => x.ResponsibleUnit == U.UnitId).UnitName, ResponsibilityManName = "", RectificationTime = x.RectificationTime, Risk_Level = (x.HazardValue =="3"?"重大":"一般"), }).OrderBy(x => x.CheckTime).Skip(Funs.PageSize * (pageIndex - 1)).Take(Funs.PageSize).ToList(); return hazardRegisters; } } } }