SGGL_JT/SUBQHSE/WebAPI/Controllers/DataPenetrate/AccidentPenetrateController.cs

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
}
}