SGGL_JT/SUBQHSE/BLL/Customization/ZJ/API/APIUnitHazardRegisterServic...

174 lines
9.4 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using EmitMapper;
using System.Collections.Generic;
using System.Linq;
using System;
namespace BLL
{
public class APIUnitHazardRegisterService
{
/// <summary>
/// 根据HazardRegisterId获取风险巡检信息
/// </summary>
/// <param name="hazardRegisterId"></param>
/// <returns></returns>
public static Model.HazardRegisterItem getHazardRegisterByHazardRegisterId(string hazardRegisterId)
{
using (Model.SUBQHSEDB db = new Model.SUBQHSEDB(Funs.ConnString))
{
var getHazardRegister = db.View_Hazard_HazardRegister_Unit.FirstOrDefault(x => x.HazardRegisterId == hazardRegisterId);
return ObjectMapperManager.DefaultInstance.GetMapper<Model.View_Hazard_HazardRegister_Unit, Model.HazardRegisterItem>().Map(getHazardRegister);
}
}
/// <summary>
/// 根据projectId、states获取风险信息状态 1待整改2已整改待确认3已确认即已闭环4已作废
/// </summary>
/// <param name="projectId"></param>
/// <param name="states"></param>
/// <returns></returns>
public static List<Model.HazardRegisterItem> getHazardRegisterByProjectIdStates(string projectId, string states, int pageIndex ,int pageSize ,string ProblemTypes)
{
using (Model.SUBQHSEDB db = new Model.SUBQHSEDB(Funs.ConnString))
{
var hazardRegisters = (from x in db.View_Hazard_HazardRegister_Unit
where (x.ProjectId == projectId || projectId == null) && (x.States == states || states == null) && (x.ProblemTypes == ProblemTypes)
orderby x.CheckTime descending
select x).Skip(pageSize * (pageIndex - 1)).Take(pageSize).ToList();
return ObjectMapperManager.DefaultInstance.GetMapper<List<Model.View_Hazard_HazardRegister_Unit>, List<Model.HazardRegisterItem>>().Map(hazardRegisters.ToList());
}
}
/// <summary>
/// 安全巡检
/// </summary>
/// <param name="pageIndex"></param>
/// <returns></returns>
public static List<Model.HazardRegisterItem> getHazardRegisterByProjectIdStates(int pageIndex)
{
string unitName = null, unitId = null;
var getUnit = CommonService.GetIsThisUnit();
if (getUnit != null)
{
unitId = getUnit.UnitId;
unitName = getUnit.UnitName;
}
using (Model.SUBQHSEDB db = new Model.SUBQHSEDB(Funs.ConnString))
{
var hazardRegisters = (from x in db.HSSE_Hazard_HazardRegister_Unit
join y in db.Base_Project on x.ProjectId equals y.ProjectId
join u in db.Base_Unit on x.ResponsibleUnit equals u.UnitId
join user in db.Sys_User on x.ResponsibleMan equals user.UserId
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 = db.Sys_User.First(User => x.ResponsibleMan == User.UserId).UserName,
RectificationTime = x.RectificationTime,
Risk_Level = x.Risk_Level,
}).OrderBy(x => x.CheckTime).Skip(Funs.PageSize * (pageIndex - 1)).Take(Funs.PageSize).ToList();
return hazardRegisters;
}
}
/// <summary>
/// 保存HazardRegister
/// </summary>
/// <param name="userInfo"></param>
/// <returns></returns>
public static void SaveHazardRegister(Model.HazardRegisterItem hazardRegister)
{
using (Model.SUBQHSEDB db = new Model.SUBQHSEDB(Funs.ConnString))
{
Model.HSSE_Hazard_HazardRegister_Unit newHazardRegister = new Model.HSSE_Hazard_HazardRegister_Unit
{
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 = hazardRegister.RegisterTypesId,
CheckCycle = hazardRegister.CheckCycle,
SafeSupervisionIsOK = hazardRegister.SafeSupervisionIsOK,
IsWx = "Y",
CCManIds = hazardRegister.CCManIds,
Requirements = hazardRegister.Requirements,
Risk_Level = hazardRegister.Risk_Level
};
var isUpdate = db.HSSE_Hazard_HazardRegister_Unit.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_Unit.InsertOnSubmit(newHazardRegister);
}
else
{
if (newHazardRegister.States == "2")
{
isUpdate.RectificationTime = DateTime.Now;
isUpdate.Rectification = newHazardRegister.Rectification;
isUpdate.RectificationImageUrl = newHazardRegister.RectificationImageUrl;
}
else
{
isUpdate.ConfirmDate = DateTime.Now;
isUpdate.ConfirmMan = newHazardRegister.ConfirmMan;
isUpdate.HandleIdea = newHazardRegister.HandleIdea;
isUpdate.SafeSupervisionIsOK = newHazardRegister.SafeSupervisionIsOK;
}
isUpdate.States = newHazardRegister.States;
isUpdate.Risk_Level = newHazardRegister.Risk_Level;
}
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));
}
}
}
}
}