using BLL;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Http;
namespace WebAPI.Controllers
{
///
/// 安全巡检
///
public class HazardRegisterController : ApiController
{
#region 根据hazardRegisterId获取风险信息
///
/// 根据hazardRegisterId获取风险信息
///
///
///
public Model.ResponeData getHazardRegisterByHazardRegisterId(string hazardRegisterId)
{
var responeData = new Model.ResponeData();
try
{
responeData.data = BLL.APIHazardRegisterService.getHazardRegisterByHazardRegisterId(hazardRegisterId);
}
catch (Exception ex)
{
responeData.code = 0;
responeData.message = ex.Message;
}
return responeData;
}
#endregion
#region 根据projectId、states获取风险信息
///
/// 根据projectId、states获取风险信息
///
///
///
/// 0 日常巡检 1 常规巡检
/// 页码
///
public Model.ResponeData getHazardRegisterByProjectIdStates(string projectId, string states,int type, int pageIndex )
{
var responeData = new Model.ResponeData();
try
{
List getDataList = new List();
int pageCount = Funs.DB.HSSE_Hazard_HazardRegister.Count(x => x.ProjectId == projectId && x.Type == type && (x.States == states || states == null));
if (pageCount > 0 && pageIndex > 0)
{
getDataList = APIHazardRegisterService.getHazardRegisterByProjectIdStates(projectId, states, type, 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
{
//总数
var getDataList = Funs.DB.HSSE_Hazard_HazardRegister.Where(x => x.ProjectId == projectId);
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 保存HazardRegister
///
/// 保存HazardRegister
///
///
///
[HttpPost]
public Model.ResponeData SaveHazardRegister([FromBody] Model.HazardRegisterItem hazardRegister)
{
var responeData = new Model.ResponeData();
try
{
BLL.APIHazardRegisterService.SaveHazardRegister(hazardRegister);
}
catch (Exception ex)
{
responeData.code = 0;
responeData.message = ex.Message;
}
return responeData;
}
#endregion
}
}