using BLL;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Http;
namespace WebAPI
{
public class UnitHazardRegisterController : ApiController
{
// GET
#region 根据hazardRegisterId获取风险信息
///
/// 根据hazardRegisterId获取风险信息
///
///
///
public Model.ResponeData getHazardRegisterByHazardRegisterId(string hazardRegisterId)
{
var responeData = new Model.ResponeData();
try
{
var hazardRegisterItem = BLL.APIUnitHazardRegisterService.getHazardRegisterByHazardRegisterId(hazardRegisterId);
var project = ProjectService.GetProjectByProjectId(hazardRegisterItem.ProjectId);
if (project!=null)
{
hazardRegisterItem.ProjectName = project.ProjectName;
}
responeData.data = hazardRegisterItem;
}
catch (Exception ex)
{
responeData.code = 0;
responeData.message = ex.Message;
}
return responeData;
}
#endregion
#region 根据projectId、states获取风险信息
///
/// 根据projectId、states获取风险信息
///
///
///
/// 页码
///
public Model.ResponeData getHazardRegisterByProjectIdStates(string projectId, string states, int pageIndex)
{
var responeData = new Model.ResponeData();
try
{
if (string.IsNullOrEmpty(projectId) || projectId.Length == 0)
{
projectId = null;
}
List getDataList = new List();
int pageCount = Funs.DB.HSSE_Hazard_HazardRegister.Count(x => (x.ProjectId == projectId || projectId == null) && (x.States == states || states == null));
if (pageCount > 0 && pageIndex > 0)
{
getDataList = APIUnitHazardRegisterService.getHazardRegisterByProjectIdStates(projectId, states, pageIndex);
}
responeData.data = new { pageCount, getDataList };
}
catch (Exception ex)
{
responeData.code = 0;
responeData.message = ex.Message;
}
return responeData;
}
#endregion
#region 根据projectId获取各状态风险数
///
/// 根据projectId获取各状态风险数
///
///
///
public Model.ResponeData getHazardRegisterCount(string projectId)
{
var responeData = new Model.ResponeData();
try
{
if (string.IsNullOrEmpty(projectId) || projectId.Length == 0)
{
projectId = null;
}
//总数
var getDataList = Funs.DB.HSSE_Hazard_HazardRegister.Where(x => (x.ProjectId == projectId || projectId == null));
int tatalCount = getDataList.Count();
//待整改
int count1 = getDataList.Where(x => x.States == "1").Count();
//待确认
int count2 = getDataList.Where(x => x.States == "2").Count();
//已闭环
int count3 = getDataList.Where(x => x.States == "3").Count();
//已作废
int count4 = getDataList.Where(x => x.States == "4").Count();
responeData.data = new { tatalCount, count1, count2, count3, count4 };
}
catch (Exception ex)
{
responeData.code = 0;
responeData.message = ex.Message;
}
return responeData;
}
#endregion
#region 获取总安全巡检
///
/// 获取总安全巡检
///
///
public Model.ResponeData getHazardRegisterTotalCount()
{
var responeData = new Model.ResponeData();
try
{
//总数
responeData.data = Funs.DB.HSSE_Hazard_HazardRegister.Where(x => x.ProjectId != null && x.States != null).Count();
}
catch (Exception ex)
{
responeData.code = 0;
responeData.message = ex.Message;
}
return responeData;
}
#endregion
#region 获取总安全巡检
///
/// 获取总安全巡检
///
/// 页码
///
public Model.ResponeData getHazardRegisterByProjectIdStates(int pageIndex)
{
var responeData = new Model.ResponeData();
try
{
responeData.data = APIUnitHazardRegisterService.getHazardRegisterByProjectIdStates(pageIndex);
}
catch (Exception ex)
{
responeData.code = 0;
responeData.message = ex.Message;
}
return responeData;
}
#endregion
#region 保存HazardRegister
///
/// 保存HazardRegister
///
///
///
[HttpPost]
public Model.ResponeData SaveHazardRegister([FromBody] Model.HazardRegisterItem hazardRegister)
{
var responeData = new Model.ResponeData();
try
{
BLL.APIUnitHazardRegisterService.SaveHazardRegister(hazardRegister);
}
catch (Exception ex)
{
responeData.code = 0;
responeData.message = ex.Message;
}
return responeData;
}
#endregion
}
}