Files
SGGL_JT/SUBQHSE/WebAPI/Controllers/DataPenetrate/AccidentPenetrateController.cs
T
2025-04-07 17:43:30 +08:00

342 lines
13 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 System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using BLL;
namespace WebAPI.Controllers.DataPenetrate
{
/// <summary>
/// 事故事件数据Api控制器
/// </summary>
public class AccidentPenetrateController : ApiController
{
Model.Sys_User CurrUser = new Model.Sys_User();
#region
/// <summary>
/// 添加事故未遂数据
/// </summary>
/// <param name="model">事故未遂数据</param>
/// <returns></returns>
[HttpPost]
public Model.ResponeData SaveAccidentPersonRecord([FromBody] Model.Accident_AccidentPersonRecord model)
{
var responeData = new Model.ResponeData();
#region
if (string.IsNullOrEmpty(model.ProjectId))
{
responeData.code = 0;
responeData.message = "项目idProjectId)不能为空";
return responeData;
}
else {
//判断projectid是否有数据
var pmodel = Funs.DB.Base_Project.FirstOrDefault(x => x.ProjectId == model.ProjectId);
if (pmodel == null)
{
responeData.code = 0;
responeData.message = "项目id未查询到数据,请检查是否正确。";
return responeData;
}
}
if (string.IsNullOrEmpty(model.AccidentTypeId))
{
responeData.code = 0;
responeData.message = "事故类型idAccidentTypeId)不能为空";
return responeData;
}
else {
//判断AccidentTypeId是否有数据
var pmodel = Funs.DB.Base_AccidentType.FirstOrDefault(x => x.AccidentTypeId == model.AccidentTypeId);
if (pmodel == null)
{
responeData.code = 0;
responeData.message = "事故类型id未查询到数据,请检查是否正确。";
return responeData;
}
}
if (string.IsNullOrEmpty(model.WorkAreaId))
{
responeData.code = 0;
responeData.message = "单位工程idWorkAreaId)不能为空";
return responeData;
}
else {
var pmodel = Funs.DB.WBS_UnitWork.FirstOrDefault(x => x.UnitWorkId == model.WorkAreaId);
if (pmodel == null)
{
responeData.code = 0;
responeData.message = "单位工程id未查询到数据,请检查是否正确。";
return responeData;
}
}
if (string.IsNullOrEmpty(model.AccidentDate.ToShortDateString()))
{
responeData.code = 0;
responeData.message = "发生时间(AccidentDate)不能为空";
return responeData;
}
if (string.IsNullOrEmpty(model.PersonId))
{
responeData.code = 0;
responeData.message = "人员idPersonId)不能为空";
return responeData;
}
if (string.IsNullOrEmpty(model.IsAttempt))
{
responeData.code = 0;
responeData.message = "是否未遂(IsAttempt)不能为空";
return responeData;
}
if (string.IsNullOrEmpty(model.CompileMan))
{
responeData.code = 0;
responeData.message = "编制人idCompileMan)不能为空";
return responeData;
}
else {
var umodel = Funs.DB.Sys_User.FirstOrDefault(x => x.UserId == model.CompileMan);
if (umodel == null)
{
responeData.code = 0;
responeData.message = "编制人id未查询到数据,请检查是否正确。";
return responeData;
}
}
#endregion
model.CompileDate = DateTime.Now;
model.States = BLL.Const.State_2;
try
{
if (!string.IsNullOrEmpty(model.AccidentPersonRecordId))
{
//判断是否有数据
var pmodel = Funs.DB.Accident_AccidentPersonRecord.FirstOrDefault(x => x.AccidentPersonRecordId == model.AccidentPersonRecordId);
if (model==null)
{
responeData.code = 0;
responeData.message = "该事故idAccidentPersonRecordId)未查询到数据,无法修改,请检查是否正确。";
return responeData;
}
BLL.AccidentPersonRecordService.UpdateAccidentPersonRecord(model);
responeData.message = "修改成功";
}
else
{
model.AccidentPersonRecordId = SQLHelper.GetNewID(typeof(Model.Accident_AccidentPersonRecord));
BLL.AccidentPersonRecordService.AddAccidentPersonRecord(model);
responeData.message = "添加成功";
}
}
catch (Exception ex)
{
responeData.code = 0;
responeData.message = ex.Message;
}
return responeData;
}
#endregion
#region
/// <summary>
/// 保存事故报告登记
/// </summary>
/// <param name="model">事故报告登记数据</param>
/// <returns></returns>
[HttpPost]
public Model.ResponeData SaveAccidentReportEdit([FromBody] Model.Accident_AccidentReport model)
{
var responeData = new Model.ResponeData();
#region
if (string.IsNullOrEmpty(model.ProjectId))
{
responeData.code = 0;
responeData.message = "项目idProjectId)不能为空";
return responeData;
}
else
{
//判断projectid是否有数据
var pmodel = Funs.DB.Base_Project.FirstOrDefault(x => x.ProjectId == model.ProjectId);
if (pmodel == null)
{
responeData.code = 0;
responeData.message = "项目id未查询到数据,请检查是否正确。";
return responeData;
}
}
if (string.IsNullOrEmpty(model.AccidentReportCode))
{
responeData.code = 0;
responeData.message = "事故编号(AccidentReportCode)不能为空";
return responeData;
}
if (string.IsNullOrEmpty(model.AccidentTypeId))
{
responeData.code = 0;
responeData.message = "事故类型(AccidentTypeId)不能为空";
return responeData;
}
if (string.IsNullOrEmpty(model.Abstract))
{
responeData.code = 0;
responeData.message = "提要(Abstract)不能为空";
return responeData;
}
if (string.IsNullOrEmpty(model.AccidentDate.ToString()))
{
responeData.code = 0;
responeData.message = "发生时间(AccidentDate)不能为空";
return responeData;
}
if (string.IsNullOrEmpty(model.PeopleNum.ToString()))
{
responeData.code = 0;
responeData.message = "人数(PeopleNum)不能为空";
return responeData;
}
if (string.IsNullOrEmpty(model.UnitId))
{
responeData.code = 0;
responeData.message = "事故责任单位idUnitId)不能为空";
return responeData;
}
else {
//判断userid是否有数据
var umodel = Funs.DB.Base_Unit.FirstOrDefault(x => x.UnitId == model.UnitId);
if (umodel == null)
{
responeData.code = 0;
responeData.message = "事故责任单位id未查询到数据,请检查是否正确。";
return responeData;
}
}
if (string.IsNullOrEmpty(model.CompileMan))
{
responeData.code = 0;
responeData.message = "报告编制人用户id(CompileMan)不能为空。";
return responeData;
}
else
{
//判断userid是否有数据
var umodel = Funs.DB.Sys_User.FirstOrDefault(x => x.UserId == model.CompileMan);
if (umodel == null)
{
responeData.code = 0;
responeData.message = "报告编制人用户id未查询到数据,请检查是否正确。";
return responeData;
}
}
#endregion
try
{
if (!string.IsNullOrEmpty(model.AccidentReportId))
{
var pmodel = Funs.DB.Accident_AccidentReport.FirstOrDefault(x => x.AccidentReportId == model.AccidentReportId);
if (pmodel==null)
{
responeData.code = 0;
responeData.message = "事故idAccidentReportId)未查询到数据,无法修改,请检查是否正确。";
return responeData;
}
BLL.AccidentReportService.UpdateAccidentReport(model);
responeData.message = "修改成功";
}
else
{
model.AccidentReportId = SQLHelper.GetNewID(typeof(Model.Accident_AccidentPersonRecord));
BLL.AccidentReportService.AddAccidentReport(model);
responeData.message = "添加成功";
}
}
catch (Exception ex)
{
responeData.code = 0;
responeData.message = ex.Message;
}
return responeData;
}
#endregion
#region
/// <summary>
/// 事故类型查询
/// </summary>
/// <returns></returns>
public Model.ResponeData getAccidentTypeInfo() {
var responeData = new Model.ResponeData();
try
{
var getDataList = Funs.DB.Base_AccidentType.ToList();
responeData.data = new { getDataList };
}
catch (Exception ex)
{
responeData.code = 0;
responeData.message = ex.Message;
}
return responeData;
}
#endregion
#region
/// <summary>
/// 编辑保存事故类型
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
[HttpPost]
public Model.ResponeData SaveAccidentTypeEdit([FromBody] Model.Base_AccidentType model) {
var responeData = new Model.ResponeData();
try
{
if (string.IsNullOrEmpty(model.AccidentTypeId))
{
model.AccidentTypeId = SQLHelper.GetNewID(typeof(Model.Base_AccidentType));
BLL.AccidentTypeService.AddAccidentType(model);
}
else
{
var pmodel = Funs.DB.Base_AccidentType.FirstOrDefault(x => x.AccidentTypeId == model.AccidentTypeId);
if (pmodel == null)
{
responeData.code = 0;
responeData.message = "事故类型idAccidentTypeId)未查询到数据,无法修改,请检查是否正确。";
return responeData;
}
BLL.AccidentTypeService.UpdateAccidentType(model);
}
responeData.message = "操作成功";
}
catch (Exception ex)
{
responeData.code = 0;
responeData.message = ex.Message;
}
return responeData;
}
#endregion
}
}