342 lines
13 KiB
C#
342 lines
13 KiB
C#
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 = "项目id(ProjectId)不能为空";
|
||
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 = "事故类型id(AccidentTypeId)不能为空";
|
||
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 = "单位工程id(WorkAreaId)不能为空";
|
||
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 = "人员id(PersonId)不能为空";
|
||
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 = "编制人id(CompileMan)不能为空";
|
||
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 = "该事故id(AccidentPersonRecordId)未查询到数据,无法修改,请检查是否正确。";
|
||
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 = "项目id(ProjectId)不能为空";
|
||
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 = "事故责任单位id(UnitId)不能为空";
|
||
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 = "事故id(AccidentReportId)未查询到数据,无法修改,请检查是否正确。";
|
||
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 = "事故类型id(AccidentTypeId)未查询到数据,无法修改,请检查是否正确。";
|
||
return responeData;
|
||
}
|
||
BLL.AccidentTypeService.UpdateAccidentType(model);
|
||
}
|
||
responeData.message = "操作成功";
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
|
||
responeData.code = 0;
|
||
responeData.message = ex.Message;
|
||
}
|
||
|
||
return responeData;
|
||
}
|
||
|
||
#endregion
|
||
|
||
}
|
||
} |