using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using BLL;
using Model;
namespace WebAPI.Controllers.HSSE
{
public class InformedConsentFormController:ApiController
{
#region 根据用户获取告知书
///
///
///
///
public Model.ResponeData getFormByWorkPostName(string PersonId)
{
var responeData = new Model.ResponeData();
try
{
var person = Funs.DB.View_SitePerson_Person.FirstOrDefault(x => x.PersonId == PersonId);
InformedConsentForm getData = new InformedConsentForm();
if (person != null)
{
string projectName = Funs.DB.Base_Project.First(z => z.ProjectId == person.ProjectId).ProjectName;
string name = person.PersonName;
string IdentityCard = person.IdentityCard;
string Telephone = person.Telephone;
string year = person.InTime.HasValue ? person.InTime.Value.Year.ToString() : "";
string month = person.InTime.HasValue ? person.InTime.Value.Month.ToString() : "";
string day = person.InTime.HasValue ? person.InTime.Value.Day.ToString() : "";
getData = (from x in Funs.DB.InformedConsentForm
where x.WorkPostName == person.WorkPostName
select x).FirstOrDefault();
if (getData != null)
{
// 替换$name占位符
getData.JobRiskNotice = getData.JobRiskNotice.Replace("$name", name);
// 替换多个占位符
getData.HealthCommitment = getData.HealthCommitment.Replace("$name", name)
.Replace("$IdentityCard", IdentityCard)
.Replace("$Telephone", Telephone)
.Replace("$year", year)
.Replace("$month", month)
.Replace("$day", day)
.Replace("$projectName", projectName);
}
}
responeData.data = new { getData = getData, person = person };
}
catch (Exception ex)
{
responeData.code = 0;
responeData.message = ex.Message;
}
return responeData;
}
#endregion
#region 签字保存后根据人员id修改签字时间
///
/// 保存签字图片的时格式是tokenkey=PersonId_1
///
///
[HttpPost]
public Model.ResponeData updateSignTime([FromBody] Item item)
{
using (Model.SUBQHSEDB db = new Model.SUBQHSEDB(Funs.ConnString))
{
var responeData = new Model.ResponeData();
try
{
// 查找要修改的记录
var person = db.SitePerson_Person.FirstOrDefault(x => x.PersonId == item.PersonId);
if (person != null)
{
person.SignTime = item.newSignTime.HasValue ? item.newSignTime.Value : DateTime.Now; // 更新签字时间
db.SubmitChanges();
Model.ToDoItem toDoItem = new Model.ToDoItem
{
MenuId = Const.PersonListMenuId,
DataId = item.PersonId + "_1",
UrlStr = item.AttachUrl1,
};
if (!string.IsNullOrEmpty(item.AttachUrl1))
{
APIUpLoadFileService.SaveAttachUrl(toDoItem);
}
toDoItem.DataId = item.PersonId + "_2";
toDoItem.UrlStr = item.AttachUrl2;
if (!string.IsNullOrEmpty(item.AttachUrl2))
{
APIUpLoadFileService.SaveAttachUrl(toDoItem);
}
toDoItem.DataId = item.PersonId + "_3";
toDoItem.UrlStr = item.AttachUrl3;
if (!string.IsNullOrEmpty(item.AttachUrl3))
{
APIUpLoadFileService.SaveAttachUrl(toDoItem);
}
toDoItem.DataId = item.PersonId + "_4";
toDoItem.UrlStr = item.AttachUrl4;
if (!string.IsNullOrEmpty(item.AttachUrl4))
{
APIUpLoadFileService.SaveAttachUrl(toDoItem);
}
responeData.code = 1;
responeData.message = "保存成功。";
}
}
catch (Exception ex)
{
responeData.code = 0;
responeData.message = ex.Message;
}
return responeData;
}
}
#endregion
}
public class Item
{
public string PersonId { get; set; }
public string AttachUrl1 { get; set; }
public string AttachUrl2 { get; set; }
public string AttachUrl3 { get; set; }
public string AttachUrl4 { get; set; }
public DateTime? newSignTime { get; set; }
}
}