2038 lines
93 KiB
C#
2038 lines
93 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using System.Configuration;
|
||
using System.IO;
|
||
using System.Linq;
|
||
using System.Net;
|
||
using System.Net.Http;
|
||
using System.Security.Policy;
|
||
using System.Web.Http;
|
||
using BLL;
|
||
using Model;
|
||
|
||
namespace WebAPI.Controllers
|
||
{
|
||
/// <summary>
|
||
/// 安全管理数据同步
|
||
/// </summary>
|
||
public class HsseController : ApiController
|
||
{
|
||
#region 查询接口
|
||
/// <summary>
|
||
/// 根据项目名称返回项目projectid
|
||
/// </summary>
|
||
/// <param name="ProjectName"></param>
|
||
/// <returns></returns>
|
||
private string getProjectIdByCode(string ProjectName) {
|
||
using (Model.SUBQHSEDB db = new Model.SUBQHSEDB(Funs.ConnString))
|
||
{
|
||
var model = db.Base_Project.FirstOrDefault(x => x.ProjectName == ProjectName);
|
||
if (model != null)
|
||
{
|
||
return model.ProjectId;
|
||
}
|
||
else {
|
||
return "";
|
||
}
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 根据单位名称获取单位id
|
||
/// </summary>
|
||
/// <param name="unitname"></param>
|
||
/// <returns></returns>
|
||
private string getUnitIdByUnitCollCropCode(string unitname) {
|
||
using (Model.SUBQHSEDB db = new Model.SUBQHSEDB(Funs.ConnString))
|
||
{
|
||
var model = db.Base_Unit.FirstOrDefault(x => x.UnitName == unitname);
|
||
if (model != null)
|
||
{
|
||
return model.UnitId;
|
||
}
|
||
else
|
||
{
|
||
return "";
|
||
}
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 根据身份证号码获取userid
|
||
/// </summary>
|
||
/// <param name="IdentityCard"></param>
|
||
/// <returns></returns>
|
||
private string getUserIdByIdentityCard(string IdentityCard)
|
||
{
|
||
using (Model.SUBQHSEDB db = new Model.SUBQHSEDB(Funs.ConnString))
|
||
{
|
||
var model = db.Sys_User.FirstOrDefault(x => x.IdentityCard == IdentityCard);
|
||
if (model != null)
|
||
{
|
||
return model.UserId;
|
||
}
|
||
else
|
||
{
|
||
return "";
|
||
}
|
||
}
|
||
}
|
||
|
||
private string getUrlByType(string type)
|
||
{
|
||
string folderUrl = "FileUpLoad/" + type + "/" + DateTime.Now.ToString("yyyy-MM") + "/";
|
||
string localRoot = ConfigurationManager.AppSettings["localRoot"] + folderUrl; //物理路径
|
||
if (!Directory.Exists(localRoot))
|
||
{
|
||
Directory.CreateDirectory(localRoot);
|
||
}
|
||
string url = localRoot + string.Format("{0:yyyyMMddHHmmssffff}", DateTime.Now) + ".jpg";
|
||
return url;
|
||
}
|
||
|
||
#endregion
|
||
/// <summary>
|
||
/// 人员信息档案同步
|
||
/// </summary>
|
||
/// <param name="dto"></param>
|
||
/// <returns></returns>
|
||
[Route("PersonSync")]
|
||
[HttpPost]
|
||
public Model.ResponeData PersonSync([FromBody] SitePersonPersonItem dto)
|
||
{
|
||
|
||
var responeData = new Model.ResponeData();
|
||
var mapper = EmitMapper.ObjectMapperManager.DefaultInstance.GetMapper<SitePersonPersonItem, Model.SitePerson_Person>();
|
||
var model = mapper.Map(dto);
|
||
using (Model.SUBQHSEDB db = new Model.SUBQHSEDB(Funs.ConnString))
|
||
{
|
||
#region 判断参数
|
||
if (string.IsNullOrEmpty(model.PersonName))
|
||
{
|
||
responeData.code = 0;
|
||
responeData.message = "人员姓名(PersonName)不能为空";
|
||
return responeData;
|
||
}
|
||
|
||
if (string.IsNullOrEmpty(model.IdentityCard))
|
||
{
|
||
responeData.code = 0;
|
||
responeData.message = "证件号码(IdentityCard)不能为空";
|
||
return responeData;
|
||
}
|
||
|
||
if (string.IsNullOrEmpty(model.WorkPostId))
|
||
{
|
||
responeData.code = 0;
|
||
responeData.message = "所属岗位(WorkPostId)不能为空";
|
||
return responeData;
|
||
}
|
||
else {
|
||
var pmodel = db.Base_WorkPost.FirstOrDefault(x => x.WorkPostName == model.WorkPostId);
|
||
if (pmodel == null)
|
||
{
|
||
responeData.code = 0;
|
||
responeData.message = "所属岗位(WorkPostId)未查询到数据,请检查是否正确。";
|
||
return responeData;
|
||
}
|
||
else
|
||
{
|
||
model.WorkPostId = pmodel.WorkPostId;
|
||
}
|
||
}
|
||
#region 系统参数判断
|
||
if (string.IsNullOrEmpty(model.ProjectId))
|
||
{
|
||
responeData.code = 0;
|
||
responeData.message = "项目名称ProjectId不能为空";
|
||
return responeData;
|
||
}
|
||
else
|
||
{
|
||
var pid = getProjectIdByCode(model.ProjectId);
|
||
if (pid == "")
|
||
{
|
||
responeData.code = 0;
|
||
responeData.message = "当前项目名称未查询到数据,请检查是否正确。";
|
||
return responeData;
|
||
}
|
||
else{
|
||
model.ProjectId = pid;
|
||
}
|
||
|
||
}
|
||
|
||
if (string.IsNullOrEmpty(model.UnitId))
|
||
{
|
||
responeData.code = 0;
|
||
responeData.message = "单位名称UnitId不能为空。";
|
||
return responeData;
|
||
}
|
||
else
|
||
{
|
||
var uid = getUnitIdByUnitCollCropCode(model.UnitId);
|
||
if (uid == "")
|
||
{
|
||
responeData.code = 0;
|
||
responeData.message = "单位名称UnitId未查询到数据,请检查是否正确。";
|
||
return responeData;
|
||
}
|
||
else {
|
||
model.UnitId = uid;
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
if (!string.IsNullOrEmpty(model.TeamGroupId))
|
||
{
|
||
var pmodel = db.ProjectData_TeamGroup.FirstOrDefault(x => x.TeamGroupName == model.TeamGroupId);
|
||
if (pmodel == null)
|
||
{
|
||
responeData.code = 0;
|
||
responeData.message = "所属班组(TeamGroupId)未查询到数据,请检查是否正确。";
|
||
return responeData;
|
||
}
|
||
else
|
||
{
|
||
model.TeamGroupId = pmodel.TeamGroupId;
|
||
}
|
||
}
|
||
if (!string.IsNullOrEmpty(model.MainCNProfessionalId))
|
||
{
|
||
var pmodel = db.Base_CNProfessional.FirstOrDefault(x => x.CNProfessionalId == model.MainCNProfessionalId);
|
||
if (pmodel == null)
|
||
{
|
||
responeData.code = 0;
|
||
responeData.message = "主专业(MainCNProfessionalId)未查询到数据,请检查是否正确。";
|
||
return responeData;
|
||
}
|
||
}
|
||
if (!string.IsNullOrEmpty(model.ViceCNProfessionalId))
|
||
{
|
||
var pmodel = db.Base_CNProfessional.FirstOrDefault(x =>model.MainCNProfessionalId.Split(',').Contains(x.CNProfessionalId));
|
||
if (pmodel == null)
|
||
{
|
||
responeData.code = 0;
|
||
responeData.message = "副专业(ViceCNProfessionalId)未查询到数据,请检查是否正确。";
|
||
return responeData;
|
||
}
|
||
}
|
||
if (!string.IsNullOrEmpty(model.WorkAreaId))
|
||
{
|
||
var WorkAreaId="";
|
||
foreach (var item in model.WorkAreaId.Split(','))
|
||
{
|
||
var pmodel = db.WBS_UnitWork.FirstOrDefault(x => x.UnitWorkName==item);
|
||
if (pmodel == null)
|
||
{
|
||
responeData.code = 0;
|
||
responeData.message = "单位工程(WorkAreaId)" + item + "未查询到数据,请检查是否正确。";
|
||
return responeData;
|
||
}
|
||
else {
|
||
WorkAreaId += pmodel.UnitWorkId + ",";
|
||
}
|
||
}
|
||
model.WorkAreaId= WorkAreaId.Substring(0, WorkAreaId.Length - 1);
|
||
}
|
||
|
||
if (string.IsNullOrEmpty(model.DepartId))
|
||
{
|
||
model.DepartId = null;
|
||
}
|
||
if (string.IsNullOrEmpty(model.PositionId))
|
||
{
|
||
model.PositionId = null;
|
||
}
|
||
if (string.IsNullOrEmpty(model.PostTitleId))
|
||
{
|
||
model.PostTitleId = null;
|
||
}
|
||
if (string.IsNullOrEmpty(model.AuditorId))
|
||
{
|
||
model.AuditorId = null;
|
||
}
|
||
#endregion
|
||
try
|
||
{
|
||
model.IdcardType = "SHENFEN_ZHENGJIAN";
|
||
//添加
|
||
if (!string.IsNullOrEmpty(model.CardNo))
|
||
{
|
||
int cardNoCount = BLL.PersonService.GetPersonCountByCardNo(model.ProjectId, model.CardNo);
|
||
|
||
if (cardNoCount > 0)
|
||
{
|
||
responeData.code = 0;
|
||
responeData.message = "此卡号已存在,不能重复!";
|
||
return responeData;
|
||
}
|
||
}
|
||
if (!string.IsNullOrEmpty(model.IdentityCard))
|
||
{
|
||
var identityCardCount = PersonService.GetPersonCountByIdentityCard(model.IdentityCard, model.ProjectId);
|
||
if (identityCardCount != null)
|
||
{
|
||
responeData.code = 0;
|
||
responeData.message = "此身份证号已存在,不能重复!";
|
||
return responeData;
|
||
}
|
||
}
|
||
model.PersonId = SQLHelper.GetNewID(typeof(Model.SitePerson_Person));
|
||
model.Isprint = "0";
|
||
BLL.PersonService.AddPerson(model);
|
||
responeData.message = "添加成功";
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
responeData.code = 0;
|
||
responeData.message = ex.Message;
|
||
}
|
||
|
||
return responeData;
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 人工时日报同步
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
[Route("DailyReportOfLaborHoursSync")]
|
||
[HttpPost]
|
||
public Model.ResponeData DailyReportOfLaborHoursSync([FromBody] SitePerson_DayReportItem dto)
|
||
{
|
||
var responeData = new Model.ResponeData();
|
||
|
||
try
|
||
{
|
||
using (var db = new Model.SUBQHSEDB(Funs.ConnString))
|
||
{
|
||
var mapper = EmitMapper.ObjectMapperManager.DefaultInstance.GetMapper<SitePerson_DayReportItem, Model.SitePerson_DayReport>();
|
||
var model = mapper.Map(dto);
|
||
#region 判断参数
|
||
if (string.IsNullOrEmpty(model.ProjectId))
|
||
{
|
||
responeData.code = 0;
|
||
responeData.message = "项目名称ProjectId不能为空";
|
||
return responeData;
|
||
}
|
||
else
|
||
{
|
||
//判断projectid是否有数据
|
||
var pid = getProjectIdByCode(model.ProjectId);
|
||
if (pid == "")
|
||
{
|
||
responeData.code = 0;
|
||
responeData.message = "当前项目名称未查询到数据,请检查是否正确。";
|
||
return responeData;
|
||
}
|
||
else
|
||
{
|
||
model.ProjectId = pid;
|
||
}
|
||
}
|
||
if (dto.ChildList.Count>0)
|
||
{
|
||
foreach (var item in dto.ChildList)
|
||
{
|
||
var uid = getUnitIdByUnitCollCropCode(item.UnitId);
|
||
if (uid == "")
|
||
{
|
||
responeData.code = 0;
|
||
responeData.message = "子表单位名称UnitId未查询到数据,请检查是否正确。";
|
||
return responeData;
|
||
}
|
||
else
|
||
{
|
||
item.UnitId = uid;
|
||
}
|
||
}
|
||
}
|
||
if (!string.IsNullOrEmpty(model.CompileMan))
|
||
{
|
||
var userid = getUserIdByIdentityCard(model.CompileMan);
|
||
if (userid == "")
|
||
{
|
||
responeData.code = 0;
|
||
responeData.message = "编制人身份证号码CompileMan未查询到数据,请检查是否正确。";
|
||
return responeData;
|
||
}
|
||
else
|
||
{
|
||
model.CompileMan = userid;
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
model.DayReportId = SQLHelper.GetNewID(typeof(Model.SitePerson_DayReport));
|
||
model.States = BLL.Const.State_2;
|
||
BLL.SitePerson_DayReportService.AddDayReport(model);
|
||
//插入子表
|
||
foreach (var item in dto.ChildList)
|
||
{
|
||
var mapperChild = EmitMapper.ObjectMapperManager.DefaultInstance.GetMapper<SitePerson_DayReportDetailItem, Model.SitePerson_DayReportDetail>();
|
||
var modelChild = mapperChild.Map(item);
|
||
modelChild.DayReportDetailId = SQLHelper.GetNewID(typeof(Model.SitePerson_DayReportDetail));
|
||
modelChild.DayReportId = model.DayReportId;
|
||
BLL.SitePerson_DayReportDetailService.AddDayReportDetail(modelChild);
|
||
|
||
var posts = (from x in Funs.DB.Base_WorkPost
|
||
join y in Funs.DB.SitePerson_Person
|
||
on x.WorkPostId equals y.WorkPostId
|
||
where y.UnitId == item.UnitId && y.ProjectId == model.ProjectId
|
||
orderby x.WorkPostCode
|
||
select x).Distinct().ToList();
|
||
foreach (var postItem in posts)
|
||
{
|
||
Model.SitePerson_DayReportUnitDetail newDayReportUnitDetail = new Model.SitePerson_DayReportUnitDetail
|
||
{
|
||
DayReportDetailId = modelChild.DayReportDetailId,
|
||
PostId = postItem.WorkPostId,
|
||
CheckPersonNum = GetCheckingCout(postItem.WorkPostId,model.CompileDate,model.ProjectId)
|
||
};
|
||
newDayReportUnitDetail.RealPersonNum = newDayReportUnitDetail.CheckPersonNum;
|
||
newDayReportUnitDetail.PersonWorkTime = newDayReportUnitDetail.RealPersonNum * modelChild.WorkTime;
|
||
BLL.SitePerson_DayReportUnitDetailService.AddDayReportUnitDetail(newDayReportUnitDetail);
|
||
}
|
||
}
|
||
responeData.message = "添加成功";
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
responeData.code = 0;
|
||
responeData.message = ex.Message;
|
||
}
|
||
return responeData;
|
||
}
|
||
|
||
#region 得到当前岗位考勤人数
|
||
/// <summary>
|
||
/// 得到当前岗位考勤人数
|
||
/// </summary>
|
||
/// <param name="workPostId"></param>
|
||
/// <param name="CompileDate"></param>
|
||
/// <param name="Projectid"></param>
|
||
/// <returns></returns>
|
||
private int GetCheckingCout(string workPostId,DateTime? CompileDate,string Projectid)
|
||
{
|
||
int count = 0;
|
||
DateTime? nowMont = CompileDate;
|
||
if (nowMont.HasValue)
|
||
{
|
||
var checks = from x in Funs.DB.SitePerson_Checking
|
||
join y in Funs.DB.SitePerson_Person on x.PersonId equals y.PersonId
|
||
join z in Funs.DB.Base_WorkPost on y.WorkPostId equals z.WorkPostId
|
||
where x.IntoOutTime > nowMont.Value.AddDays(-1) && x.IntoOutTime < nowMont.Value.AddDays(1) && y.ProjectId == Projectid
|
||
&& z.WorkPostId == workPostId
|
||
select x;
|
||
count = checks.Count();
|
||
}
|
||
|
||
return count;
|
||
}
|
||
#endregion
|
||
|
||
/// <summary>
|
||
/// 培训记录同步
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
[Route("TrainRecordSync")]
|
||
[HttpPost]
|
||
public Model.ResponeData TrainRecordSync([FromBody] EduTrain_TrainRecordItem dto)
|
||
{
|
||
var responeData = new Model.ResponeData();
|
||
var unitid = "";
|
||
try
|
||
{
|
||
using (var db = new Model.SUBQHSEDB(Funs.ConnString))
|
||
{
|
||
var mapper = EmitMapper.ObjectMapperManager.DefaultInstance.GetMapper<EduTrain_TrainRecordItem, Model.EduTrain_TrainRecord>();
|
||
var model = mapper.Map(dto);
|
||
#region 判断参数
|
||
if (!string.IsNullOrEmpty(model.ProjectId))
|
||
{
|
||
//判断projectid是否有数据
|
||
var pid = getProjectIdByCode(model.ProjectId);
|
||
if (pid == "")
|
||
{
|
||
responeData.code = 0;
|
||
responeData.message = "当前所属项目名称未查询到数据,请检查是否正确。";
|
||
return responeData;
|
||
}
|
||
else
|
||
{
|
||
model.ProjectId = pid;
|
||
}
|
||
}
|
||
if (!string.IsNullOrEmpty(model.TrainTypeId))
|
||
{
|
||
var pmodel = db.Base_TrainType.FirstOrDefault(x => x.TrainTypeName == model.TrainTypeId);
|
||
if (pmodel == null)
|
||
{
|
||
responeData.code = 0;
|
||
responeData.message = "培训类别名称未查询到数据,请检查是否正确。";
|
||
return responeData;
|
||
}
|
||
else {
|
||
model.TrainTypeId = pmodel.TrainTypeId;
|
||
}
|
||
}
|
||
if (!string.IsNullOrEmpty(model.TrainLevelId))
|
||
{
|
||
var pmodel = db.Base_TrainLevel.FirstOrDefault(x => x.TrainLevelName == model.TrainLevelId);
|
||
if (pmodel == null)
|
||
{
|
||
responeData.code = 0;
|
||
responeData.message = "培训级别名称未查询到数据,请检查是否正确。";
|
||
return responeData;
|
||
}
|
||
else {
|
||
model.TrainLevelId = pmodel.TrainLevelId;
|
||
}
|
||
}
|
||
if (!string.IsNullOrEmpty(model.UnitIds))
|
||
{
|
||
var unitIds = "";
|
||
foreach (var item in model.UnitIds.Split(','))
|
||
{
|
||
var uid = getUnitIdByUnitCollCropCode(item);
|
||
if (uid == "")
|
||
{
|
||
responeData.code = 0;
|
||
responeData.message = "单位名称UnitIds未查询到数据,请检查是否正确。";
|
||
return responeData;
|
||
}
|
||
else
|
||
{
|
||
unitIds += uid+",";
|
||
}
|
||
}
|
||
model.UnitIds = unitIds.Substring(0, unitIds.Length - 1);
|
||
|
||
var umodel = Funs.DB.Base_Unit.FirstOrDefault(x =>model.UnitIds.Split(',').Contains(x.UnitId));
|
||
if (umodel == null)
|
||
{
|
||
responeData.code = 0;
|
||
responeData.message = "单位名称UnitIds未查询到数据,请检查是否正确。";
|
||
return responeData;
|
||
}
|
||
}
|
||
if (!string.IsNullOrEmpty(model.CompileMan))
|
||
{
|
||
var userid = getUserIdByIdentityCard(model.CompileMan);
|
||
if (userid == "")
|
||
{
|
||
responeData.code = 0;
|
||
responeData.message = "编制人身份证号码CompileMan未查询到数据,请检查是否正确。";
|
||
return responeData;
|
||
}
|
||
else
|
||
{
|
||
model.CompileMan = userid;
|
||
}
|
||
|
||
var pmodel = db.Sys_User.FirstOrDefault(x => x.UserId == model.CompileMan);
|
||
unitid = pmodel.UnitId;
|
||
if (pmodel == null)
|
||
{
|
||
responeData.code = 0;
|
||
responeData.message = "编制人CompileMan未查询到数据,请检查是否正确。";
|
||
return responeData;
|
||
}
|
||
}
|
||
if (!string.IsNullOrEmpty(model.WorkPostIds))
|
||
{
|
||
var WorkPostIds = "";
|
||
foreach (var item in model.WorkPostIds.Split(','))
|
||
{
|
||
var pmodel = db.Base_WorkPost.FirstOrDefault(x => x.WorkPostName== item);
|
||
if (pmodel == null)
|
||
{
|
||
responeData.code = 0;
|
||
responeData.message = "培训岗位名称"+ item + "未查询到数据,请检查是否正确。";
|
||
return responeData;
|
||
}
|
||
else
|
||
{
|
||
WorkPostIds += item + ",";
|
||
}
|
||
}
|
||
model.WorkPostIds = WorkPostIds.Substring(0, WorkPostIds.Length - 1);
|
||
}
|
||
|
||
if (dto.ChildList.Count>0)
|
||
{
|
||
foreach (var item in dto.ChildList)
|
||
{
|
||
var sPmodel = db.SitePerson_Person.FirstOrDefault(x => x.IdentityCard == item.PersonId && x.ProjectId == model.ProjectId);
|
||
if (sPmodel == null)
|
||
{
|
||
responeData.code = 0;
|
||
responeData.message = "根据人员身份证号码(" + item + ")和项目名称未查询到该人员数据。";
|
||
return responeData;
|
||
}
|
||
else
|
||
{
|
||
item.PersonId = sPmodel.PersonId;
|
||
}
|
||
}
|
||
}
|
||
if (string.IsNullOrEmpty(model.TrainLevelId))
|
||
{
|
||
model.TrainLevelId = null;
|
||
}
|
||
#endregion
|
||
model.States= BLL.Const.State_2;
|
||
model.TrainingId = SQLHelper.GetNewID(typeof(Model.EduTrain_TrainRecord));
|
||
model.TrainPersonNum = dto.ChildList.Count;
|
||
model.TrainingCode= CodeRecordsService.ReturnCodeByMenuIdProjectId(Const.ProjectTrainRecordMenuId, model.ProjectId, unitid);
|
||
BLL.EduTrain_TrainRecordService.AddTraining(model);
|
||
if (dto.ChildList.Count>0)
|
||
{
|
||
foreach (var item in dto.ChildList)
|
||
{
|
||
var mapperChild = EmitMapper.ObjectMapperManager.DefaultInstance.GetMapper<EduTrain_TrainRecordDetailItem, Model.EduTrain_TrainRecordDetail>();
|
||
var modelChild = mapperChild.Map(item);
|
||
modelChild.TrainDetailId= SQLHelper.GetNewID(typeof(Model.EduTrain_TrainRecordDetail));
|
||
modelChild.TrainingId = model.TrainingId;
|
||
BLL.EduTrain_TrainRecordDetailService.AddTrainDetail(modelChild);
|
||
}
|
||
}
|
||
responeData.message = "添加成功。";
|
||
|
||
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
responeData.code = 0;
|
||
responeData.message = ex.Message;
|
||
}
|
||
return responeData;
|
||
}
|
||
|
||
|
||
|
||
/// <summary>
|
||
/// 培训计划同步
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
[Route("TrainPlanSync")]
|
||
[HttpPost]
|
||
public Model.ResponeData TrainPlanSync([FromBody] Training_PlanDto dto)
|
||
{
|
||
var unitid = "";
|
||
var responeData = new Model.ResponeData();
|
||
try
|
||
{
|
||
using (var db = new Model.SUBQHSEDB(Funs.ConnString))
|
||
{
|
||
var mapper = EmitMapper.ObjectMapperManager.DefaultInstance.GetMapper<Training_PlanDto, Model.Training_Plan>();
|
||
var model = mapper.Map(dto);
|
||
#region 判断参数
|
||
if (!string.IsNullOrEmpty(model.ProjectId))
|
||
{
|
||
var pid = getProjectIdByCode(model.ProjectId);
|
||
if (pid == "")
|
||
{
|
||
responeData.code = 0;
|
||
responeData.message = "当前所属项目名称未查询到数据,请检查是否正确。";
|
||
return responeData;
|
||
}
|
||
else
|
||
{
|
||
model.ProjectId = pid;
|
||
}
|
||
}
|
||
if (!string.IsNullOrEmpty(model.TrainTypeId))
|
||
{
|
||
var pmodel = db.Base_TrainType.FirstOrDefault(x => x.TrainTypeName == model.TrainTypeId);
|
||
if (pmodel == null)
|
||
{
|
||
responeData.code = 0;
|
||
responeData.message = "培训类别TrainTypeId未查询到数据,请检查是否正确。";
|
||
return responeData;
|
||
}
|
||
else {
|
||
model.TrainTypeId = pmodel.TrainTypeId;
|
||
}
|
||
}
|
||
if (!string.IsNullOrEmpty(model.TrainLevelId))
|
||
{
|
||
var pmodel = db.Base_TrainLevel.FirstOrDefault(x => x.TrainLevelName == model.TrainLevelId);
|
||
if (pmodel == null)
|
||
{
|
||
responeData.code = 0;
|
||
responeData.message = "培训级别TrainLevelId未查询到数据,请检查是否正确。";
|
||
return responeData;
|
||
}
|
||
else
|
||
{
|
||
model.TrainLevelId = pmodel.TrainLevelId;
|
||
}
|
||
}
|
||
if (!string.IsNullOrEmpty(model.UnitIds))
|
||
{
|
||
var unitids = "";
|
||
foreach (var item in model.UnitIds.Split(','))
|
||
{
|
||
var uid = getUnitIdByUnitCollCropCode(item);
|
||
if (uid == "")
|
||
{
|
||
responeData.code = 0;
|
||
responeData.message = "培训单位名称UnitIds(" + uid + ")未查询到数据,请检查是否正确。";
|
||
return responeData;
|
||
}
|
||
else
|
||
{
|
||
unitids += uid + ",";
|
||
}
|
||
}
|
||
|
||
model.UnitIds = unitids.Substring(0, unitids.Length - 1);
|
||
|
||
var umodel = Funs.DB.Base_Unit.FirstOrDefault(x => model.UnitIds.Split(',').Contains(x.UnitId));
|
||
if (umodel == null)
|
||
{
|
||
responeData.code = 0;
|
||
responeData.message = "培训单位名称UnitIds未查询到数据,请检查是否正确。";
|
||
return responeData;
|
||
}
|
||
}
|
||
if (!string.IsNullOrEmpty(model.DesignerId))
|
||
{
|
||
var userid = getUserIdByIdentityCard(model.DesignerId);
|
||
if (userid == "")
|
||
{
|
||
responeData.code = 0;
|
||
responeData.message = "计划制定人身份证号码DesignerId未查询到数据,请检查是否正确。";
|
||
return responeData;
|
||
}
|
||
else
|
||
{
|
||
model.DesignerId = userid;
|
||
}
|
||
|
||
var pmodel = db.Sys_User.FirstOrDefault(x => x.UserId == model.DesignerId);
|
||
|
||
if (pmodel == null)
|
||
{
|
||
responeData.code = 0;
|
||
responeData.message = "计划制定人DesignerId未查询到数据,请检查是否正确。";
|
||
return responeData;
|
||
}
|
||
else {
|
||
unitid = pmodel.UnitId;
|
||
}
|
||
}
|
||
if (!string.IsNullOrEmpty(model.WorkPostId))
|
||
{
|
||
var WorkPostId = "";
|
||
foreach (var item in model.WorkPostId.Split(','))
|
||
{
|
||
var pmodel = db.Base_WorkPost.FirstOrDefault(x => x.WorkPostName == item);
|
||
if (pmodel == null)
|
||
{
|
||
responeData.code = 0;
|
||
responeData.message = "岗位名称" + item + "未查询到数据,请检查是否正确。";
|
||
return responeData;
|
||
}
|
||
else
|
||
{
|
||
WorkPostId += item + ",";
|
||
}
|
||
}
|
||
model.WorkPostId = WorkPostId.Substring(0, WorkPostId.Length - 1);
|
||
|
||
//var pmodel = db.Base_WorkPost.FirstOrDefault(x => model.WorkPostId.Split(',').Contains(x.WorkPostId));
|
||
//if (pmodel == null)
|
||
//{
|
||
// responeData.code = 0;
|
||
// responeData.message = "适用岗位(WorkPostId)未查询到数据,请检查是否正确。";
|
||
// return responeData;
|
||
//}
|
||
}
|
||
if (!string.IsNullOrEmpty(dto.dpSysUser))
|
||
{
|
||
var personid = "";
|
||
foreach (var item in dto.dpSysUser.Split(',')) {
|
||
|
||
var dpSysUser = db.SitePerson_Person.FirstOrDefault(x=>x.IdentityCard== item && model.UnitIds.Split(',').Contains(x.UnitId));
|
||
if (dpSysUser == null)
|
||
{
|
||
responeData.code = 0;
|
||
responeData.message = "当前人员身份证(" + item + ")不在培训单位中。";
|
||
return responeData;
|
||
}
|
||
else {
|
||
personid += dpSysUser.PersonId + ",";
|
||
}
|
||
}
|
||
dto.dpSysUser = personid.Substring(0, personid.Length - 1);
|
||
|
||
var pmodel = db.SitePerson_Person.FirstOrDefault(x => dto.dpSysUser.Split(',').Contains(x.PersonId));
|
||
if (pmodel == null)
|
||
{
|
||
responeData.code = 0;
|
||
responeData.message = "人员dpSysUser未查询到数据,请检查是否正确。";
|
||
return responeData;
|
||
}
|
||
}
|
||
if (!string.IsNullOrEmpty(dto.dpCompanyTraining))
|
||
{
|
||
var dpCompanyTraining = "";
|
||
foreach (var item in dto.dpCompanyTraining.Split(','))
|
||
{
|
||
var pmodel = db.Training_CompanyTrainingItem.FirstOrDefault(x => x.CompanyTrainingItemName==item);
|
||
if (pmodel == null)
|
||
{
|
||
responeData.code = 0;
|
||
responeData.message = "教材" + item + "未查询到数据,请检查是否正确。";
|
||
return responeData;
|
||
}
|
||
else {
|
||
dpCompanyTraining += item + ",";
|
||
}
|
||
}
|
||
dto.dpCompanyTraining = dpCompanyTraining.Substring(0, dpCompanyTraining.Length - 1);
|
||
}
|
||
|
||
|
||
#endregion
|
||
model.PlanId = SQLHelper.GetNewID();
|
||
model.PlanCode = CodeRecordsService.ReturnCodeByMenuIdProjectId(Const.ProjectTrainingPlanMenuId, model.ProjectId, unitid);
|
||
//插入计划表
|
||
TrainingPlanService.AddPlan(model);
|
||
|
||
//新增培训人员明细
|
||
if (!string.IsNullOrEmpty(dto.dpSysUser))
|
||
{
|
||
////新增培训人员明细
|
||
foreach (var PersonId in dto.dpSysUser.Split(','))
|
||
{
|
||
if (!string.IsNullOrEmpty(PersonId))
|
||
{
|
||
Model.Training_Task newTrainDetail = new Model.Training_Task
|
||
{
|
||
TaskId = SQLHelper.GetNewID(),
|
||
ProjectId = model.ProjectId,
|
||
PlanId = model.PlanId,
|
||
UserId = PersonId,
|
||
TaskDate = DateTime.Now,
|
||
States = Const.State_0, ////未生成培训教材明细
|
||
};
|
||
db.Training_Task.InsertOnSubmit(newTrainDetail);
|
||
db.SubmitChanges();
|
||
|
||
|
||
}
|
||
}
|
||
}
|
||
|
||
//新增培训教材类型明细
|
||
if (!string.IsNullOrEmpty(dto.dpCompanyTraining))
|
||
{
|
||
////新增培训教材类型明细
|
||
foreach (var CompanyTrainingItemId in dto.dpCompanyTraining.Split(','))
|
||
{
|
||
if (!string.IsNullOrEmpty(CompanyTrainingItemId))
|
||
{
|
||
Model.Training_PlanItem newPlanItem = new Model.Training_PlanItem
|
||
{
|
||
PlanItemId = SQLHelper.GetNewID(),
|
||
PlanId = model.PlanId,
|
||
|
||
};
|
||
|
||
if (!string.IsNullOrEmpty(CompanyTrainingItemId))
|
||
{
|
||
newPlanItem.CompanyTrainingItemId = CompanyTrainingItemId;
|
||
|
||
var trainingItem = Funs.DB.Training_CompanyTrainingItem.FirstOrDefault(x => x.CompanyTrainingItemId == CompanyTrainingItemId);
|
||
if (trainingItem != null)
|
||
{
|
||
newPlanItem.CompanyTrainingId = trainingItem.CompanyTrainingId;
|
||
}
|
||
}
|
||
db.Training_PlanItem.InsertOnSubmit(newPlanItem);
|
||
db.SubmitChanges();
|
||
}
|
||
}
|
||
}
|
||
|
||
responeData.message = "添加成功。";
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
responeData.code = 0;
|
||
responeData.message = ex.Message;
|
||
}
|
||
return responeData;
|
||
}
|
||
|
||
#region 培训任务类
|
||
/// <summary>
|
||
/// 培训任务类
|
||
/// </summary>
|
||
public class TrainTaskClass {
|
||
/// <summary>
|
||
/// 项目名称
|
||
/// </summary>
|
||
public string projectName { get; set; }
|
||
/// <summary>
|
||
/// 培训计划名称
|
||
/// </summary>
|
||
public string planName { get; set; }
|
||
/// <summary>
|
||
/// 人员身份证号码(逗号分隔,最后一个不需要逗号)
|
||
/// </summary>
|
||
public string personIdCard { get; set; }
|
||
}
|
||
#endregion
|
||
|
||
/// <summary>
|
||
/// 培训任务同步
|
||
/// </summary>
|
||
/// <param name="dto"></param>
|
||
/// <returns></returns>
|
||
[Route("TrainTaskSync")]
|
||
[HttpPost]
|
||
public Model.ResponeData TrainTaskSync([FromBody] TrainTaskClass dto)
|
||
{
|
||
var responeData = new Model.ResponeData();
|
||
try
|
||
{
|
||
using (var db = new Model.SUBQHSEDB(Funs.ConnString))
|
||
{
|
||
var pid = getProjectIdByCode(dto.projectName);
|
||
if (pid == "")
|
||
{
|
||
responeData.code = 0;
|
||
responeData.message = "项目名称未查询到数据,请检查是否正确。";
|
||
return responeData;
|
||
}
|
||
//根据项目id和计划名称获取计划id
|
||
var pmodel = db.Training_Plan.FirstOrDefault(x => x.ProjectId == pid && x.PlanName == dto.planName);
|
||
if (pmodel == null)
|
||
{
|
||
responeData.code = 0;
|
||
responeData.message = "根据项目名称和培训计划名称未查询到培训计划数据。";
|
||
return responeData;
|
||
}
|
||
else {
|
||
var planId = pmodel.PlanId;
|
||
//根据人员名称返回人员personid
|
||
foreach (var item in dto.personIdCard.Split(','))
|
||
{
|
||
var sPmodel = db.SitePerson_Person.FirstOrDefault(x => x.IdentityCard == item && x.ProjectId == pid);
|
||
if (sPmodel == null)
|
||
{
|
||
responeData.code = 0;
|
||
responeData.message = "根据人员身份证号码(" + item + ")和项目名称未查询到该人员数据。";
|
||
return responeData;
|
||
}
|
||
else {
|
||
APITrainingTaskService.getTrainingTaskByPlanIdPersonId(planId, sPmodel.PersonId);
|
||
}
|
||
}
|
||
responeData.message = "培训任务同步成功。";
|
||
|
||
}
|
||
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
responeData.code = 0;
|
||
responeData.message = ex.Message;
|
||
}
|
||
return responeData;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 培训任务通知同步
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
[Route("TrainTaskNoticeSync")]
|
||
[HttpPost]
|
||
public Model.ResponeData TrainTaskNoticeSync([FromBody] EduTrain_TaskNoticeItem dto)
|
||
{
|
||
var responeData = new Model.ResponeData();
|
||
try
|
||
{
|
||
using (var db = new Model.SUBQHSEDB(Funs.ConnString))
|
||
{
|
||
var mapper = EmitMapper.ObjectMapperManager.DefaultInstance.GetMapper<EduTrain_TaskNoticeItem, Model.EduTrain_TaskNotice>();
|
||
var model = mapper.Map(dto);
|
||
#region 判断参数
|
||
if (!string.IsNullOrEmpty(model.ProjectId))
|
||
{
|
||
//判断projectid是否有数据
|
||
var pid = getProjectIdByCode(model.ProjectId);
|
||
if (pid == "")
|
||
{
|
||
responeData.code = 0;
|
||
responeData.message = "当前项目名称未查询到数据,请检查是否正确。";
|
||
return responeData;
|
||
}
|
||
else
|
||
{
|
||
model.ProjectId = pid;
|
||
}
|
||
}
|
||
|
||
if (!string.IsNullOrEmpty(model.TrainType))
|
||
{
|
||
var pmodel = db.Base_TrainType.FirstOrDefault(x => x.TrainTypeName == model.TrainType);
|
||
if (pmodel == null)
|
||
{
|
||
responeData.code = 0;
|
||
responeData.message = "培训类型TrainType未查询到数据,请检查是否正确。";
|
||
return responeData;
|
||
}
|
||
else {
|
||
model.TrainType = pmodel.TrainTypeId;
|
||
}
|
||
}
|
||
|
||
if (!string.IsNullOrEmpty(model.Units))
|
||
{
|
||
var units = "";
|
||
foreach (var item in model.Units.Split(','))
|
||
{
|
||
var uid = getUnitIdByUnitCollCropCode(item);
|
||
if (uid == "")
|
||
{
|
||
responeData.code = 0;
|
||
responeData.message = "单位名称UnitIds(" + item + ")未查询到数据,请检查是否正确。";
|
||
return responeData;
|
||
}
|
||
else
|
||
{
|
||
units += uid + ",";
|
||
}
|
||
}
|
||
model.Units = units.Substring(0, units.Length - 1);
|
||
}
|
||
if (!string.IsNullOrEmpty(model.TeachMan))
|
||
{
|
||
var userid = getUnitIdByUnitCollCropCode(model.TeachMan);
|
||
if (userid == "")
|
||
{
|
||
responeData.code = 0;
|
||
responeData.message = "授课人TeachMan未查询到数据,请检查是否正确。";
|
||
return responeData;
|
||
}
|
||
else
|
||
{
|
||
model.TeachMan = userid;
|
||
}
|
||
}
|
||
if (!string.IsNullOrEmpty(model.CreatMan))
|
||
{
|
||
var userid = getUnitIdByUnitCollCropCode(model.CreatMan);
|
||
if (userid == "")
|
||
{
|
||
responeData.code = 0;
|
||
responeData.message = "编制人CreatMan未查询到数据,请检查是否正确。";
|
||
return responeData;
|
||
}
|
||
else
|
||
{
|
||
model.CreatMan = userid;
|
||
}
|
||
|
||
}
|
||
if (!string.IsNullOrEmpty(model.State))
|
||
{
|
||
if (model.State!="0"&&model.State!="1")
|
||
{
|
||
responeData.code = 0;
|
||
responeData.message = "状态只能是0或者1,请检查是否正确。";
|
||
return responeData;
|
||
}
|
||
}
|
||
#endregion
|
||
model.TaskNoticeId= SQLHelper.GetNewID(typeof(Model.EduTrain_TaskNotice));
|
||
BLL.EduTrain_TaskNoticeService.AddEduTrain_TaskNotice(model);
|
||
responeData.message = "添加成功";
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
responeData.code = 0;
|
||
responeData.message = ex.Message;
|
||
}
|
||
return responeData;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 考试计划同步
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
[Route("TestPlanSync")]
|
||
[HttpPost]
|
||
public Model.ResponeData TestPlanSync([FromBody] Training_TestPlanItem dto)
|
||
{
|
||
var responeData = new Model.ResponeData();
|
||
try
|
||
{
|
||
using (var db = new Model.SUBQHSEDB(Funs.ConnString))
|
||
{
|
||
var mapper = EmitMapper.ObjectMapperManager.DefaultInstance.GetMapper<Training_TestPlanItem, Model.Training_TestPlan>();
|
||
var model = mapper.Map(dto);
|
||
#region 判断参数
|
||
if (!string.IsNullOrEmpty(model.ProjectId))
|
||
{
|
||
//判断projectid是否有数据
|
||
var pid = getProjectIdByCode(model.ProjectId);
|
||
if (pid == "")
|
||
{
|
||
responeData.code = 0;
|
||
responeData.message = "当前项目名称未查询到数据,请检查是否正确。";
|
||
return responeData;
|
||
}
|
||
else
|
||
{
|
||
model.ProjectId = pid;
|
||
}
|
||
|
||
|
||
}
|
||
if (!string.IsNullOrEmpty(model.PlanManId))
|
||
{
|
||
var userid = getUserIdByIdentityCard(model.PlanManId);
|
||
if (userid == "")
|
||
{
|
||
responeData.code = 0;
|
||
responeData.message = "计划人身份证号码PlanManId未查询到数据,请检查是否正确。";
|
||
return responeData;
|
||
}
|
||
else
|
||
{
|
||
model.PlanManId = userid;
|
||
}
|
||
}
|
||
|
||
|
||
if (!string.IsNullOrEmpty(model.WorkPostIds))
|
||
{
|
||
var WorkPostIds = "";
|
||
foreach (var item in model.WorkPostIds.Split(','))
|
||
{
|
||
var pmodel = db.Base_WorkPost.FirstOrDefault(x => x.WorkPostName == item);
|
||
if (pmodel == null)
|
||
{
|
||
responeData.code = 0;
|
||
responeData.message = "考生岗位" + item + "未查询到数据,请检查是否正确。";
|
||
return responeData;
|
||
}
|
||
else
|
||
{
|
||
WorkPostIds += item + ",";
|
||
}
|
||
}
|
||
model.WorkPostIds = WorkPostIds.Substring(0, WorkPostIds.Length - 1);
|
||
|
||
}
|
||
|
||
|
||
|
||
#endregion
|
||
model.TestPlanId = SQLHelper.GetNewID(typeof(Model.Training_TestPlan));
|
||
model.States = "3";
|
||
db.Training_TestPlan.InsertOnSubmit(model);
|
||
db.SubmitChanges();
|
||
responeData.message = "添加成功。";
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
responeData.code = 0;
|
||
responeData.message = ex.Message;
|
||
}
|
||
return responeData;
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 考试记录同步
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
[Route("TestRecordSync")]
|
||
[HttpPost]
|
||
public Model.ResponeData TestRecordSync([FromBody] Training_TestRecordDto dto)
|
||
{
|
||
var responeData = new Model.ResponeData();
|
||
try
|
||
{
|
||
using (var db = new Model.SUBQHSEDB(Funs.ConnString))
|
||
{
|
||
var mapper = EmitMapper.ObjectMapperManager.DefaultInstance.GetMapper<Training_TestRecordDto, Model.Training_TestRecord>();
|
||
var model = mapper.Map(dto);
|
||
#region 判断参数
|
||
if (!string.IsNullOrEmpty(model.ProjectId))
|
||
{
|
||
//判断projectid是否有数据
|
||
var pid = getProjectIdByCode(model.ProjectId);
|
||
if (pid == "")
|
||
{
|
||
responeData.code = 0;
|
||
responeData.message = "所属项目名称未查询到数据,请检查是否正确。";
|
||
return responeData;
|
||
}
|
||
else
|
||
{
|
||
model.ProjectId = pid;
|
||
}
|
||
}
|
||
|
||
if (!string.IsNullOrEmpty(model.TestPlanId))
|
||
{
|
||
var pmodel = db.Training_TestPlan.FirstOrDefault(x => x.PlanName == model.TestPlanId);
|
||
if (pmodel == null)
|
||
{
|
||
responeData.code = 0;
|
||
responeData.message = "考试计划名称 TestPlanId未查询到数据,请检查是否正确。";
|
||
return responeData;
|
||
}
|
||
else {
|
||
model.TestPlanId = pmodel.PlanId;
|
||
}
|
||
}
|
||
if (!string.IsNullOrEmpty(model.TestManId))
|
||
{
|
||
var pmodel = db.SitePerson_Person.FirstOrDefault(x => x.ProjectId == model.ProjectId && x.IdentityCard == model.TestManId);
|
||
if (pmodel == null)
|
||
{
|
||
responeData.code = 0;
|
||
responeData.message = "当前考生不在项目中,请检查是否正确。";
|
||
return responeData;
|
||
}
|
||
else {
|
||
model.TestManId = pmodel.PersonId;
|
||
}
|
||
}
|
||
#endregion
|
||
model.TestRecordId= SQLHelper.GetNewID(typeof(Model.Training_TestRecord));
|
||
db.Training_TestRecord.InsertOnSubmit(model);
|
||
db.SubmitChanges();
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
responeData.code = 0;
|
||
responeData.message = ex.Message;
|
||
}
|
||
return responeData;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 日常巡检同步
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
[Route("HiddenRectificationSync")]
|
||
[HttpPost]
|
||
public Model.ResponeData HiddenRectificationSync([FromBody] HSSE_Hazard_HazardRegisterDto dto)
|
||
{
|
||
var responeData = new Model.ResponeData();
|
||
try
|
||
{
|
||
using (var db = new Model.SUBQHSEDB(Funs.ConnString))
|
||
{
|
||
var mapper = EmitMapper.ObjectMapperManager.DefaultInstance.GetMapper<HSSE_Hazard_HazardRegisterDto, Model.HSSE_Hazard_HazardRegister>();
|
||
var model = mapper.Map(dto);
|
||
#region 判断参数
|
||
if (!string.IsNullOrEmpty(model.ProjectId))
|
||
{
|
||
var pid = getProjectIdByCode(model.ProjectId);
|
||
if (pid == "")
|
||
{
|
||
responeData.code = 0;
|
||
responeData.message = "当前项目名称未查询到数据,请检查是否正确。";
|
||
return responeData;
|
||
}
|
||
else
|
||
{
|
||
model.ProjectId = pid;
|
||
}
|
||
}
|
||
if (!string.IsNullOrEmpty(model.RegisterTypesId))
|
||
{
|
||
var pmodel = db.HSSE_Hazard_HazardRegisterTypes.FirstOrDefault(x => x.RegisterTypesName == model.RegisterTypesId);
|
||
if (pmodel == null)
|
||
{
|
||
responeData.code = 0;
|
||
responeData.message = "检查项RegisterTypesId未查询到数据,请检查是否正确。";
|
||
return responeData;
|
||
}
|
||
else {
|
||
model.RegisterTypesId = pmodel.RegisterTypesId;
|
||
}
|
||
}
|
||
if (!string.IsNullOrEmpty(model.ResponsibleUnit))
|
||
{
|
||
var uid = getUnitIdByUnitCollCropCode(model.ResponsibleUnit);
|
||
if (uid == "")
|
||
{
|
||
responeData.code = 0;
|
||
responeData.message = "责任单位名称UnitId未查询到数据,请检查是否正确。";
|
||
return responeData;
|
||
}
|
||
else
|
||
{
|
||
model.ResponsibleUnit = uid;
|
||
}
|
||
}
|
||
if (!string.IsNullOrEmpty(model.Place))
|
||
{
|
||
var umodel = Funs.DB.WBS_UnitWork.FirstOrDefault(x => x.UnitWorkName == model.Place);
|
||
if (umodel == null)
|
||
{
|
||
responeData.code = 0;
|
||
responeData.message = "单位工程(受检区域)Place未查询到数据,请检查是否正确。";
|
||
return responeData;
|
||
}
|
||
else {
|
||
model.Place = umodel.UnitWorkId;
|
||
}
|
||
}
|
||
if (model.Risk_Level!="一般"&&model.Risk_Level!="重大")
|
||
{
|
||
responeData.code = 0;
|
||
responeData.message = "级别必须为'一般'或者'重大',请检查是否正确。";
|
||
return responeData;
|
||
}
|
||
if (!string.IsNullOrEmpty(model.ResponsibleMan))
|
||
{
|
||
var userid = getUserIdByIdentityCard(model.ResponsibleMan);
|
||
if (userid == "")
|
||
{
|
||
responeData.code = 0;
|
||
responeData.message = "责任人身份证号码ResponsibleMan未查询到数据,请检查是否正确。";
|
||
return responeData;
|
||
}
|
||
else
|
||
{
|
||
model.ResponsibleMan = userid;
|
||
}
|
||
}
|
||
if (!string.IsNullOrEmpty(model.CheckManId))
|
||
{
|
||
var userid = getUserIdByIdentityCard(model.CheckManId);
|
||
if (userid == "")
|
||
{
|
||
responeData.code = 0;
|
||
responeData.message = "检查人身份证号码ResponsibleMan未查询到数据,请检查是否正确。";
|
||
return responeData;
|
||
}
|
||
else
|
||
{
|
||
model.CheckManId = userid;
|
||
}
|
||
}
|
||
|
||
|
||
|
||
#endregion
|
||
model.ProblemTypes = "1"; //安全隐患问题
|
||
model.CheckCycle = "D";
|
||
model.IsEffective = "1";
|
||
model.States = "3"; //已闭环
|
||
model.HazardRegisterId = SQLHelper.GetNewID(typeof(Model.HSSE_Hazard_HazardRegister));
|
||
string urlBefore = "";
|
||
string urlAfter = "";
|
||
BLL.HSSE_Hazard_HazardRegisterService.AddHazardRegister(model);
|
||
try
|
||
{
|
||
//整改前照片
|
||
if (!string.IsNullOrEmpty(model.ImageUrl))
|
||
{
|
||
// urlBefore = ConfigurationManager.AppSettings["localRoot"] + @"FileUpload\Registration\" + string.Format("{0:yyyyMMddHHmmssffff}", DateTime.Now) + ".jpg";
|
||
urlBefore = getUrlByType("Registration");
|
||
System.IO.File.WriteAllBytes(urlBefore, Convert.FromBase64String(model.ImageUrl));
|
||
urlBefore = urlBefore.Replace(ConfigurationManager.AppSettings["localRoot"], "");
|
||
UploadFileService.SaveAttachUrl(UploadFileService.GetSourceByAttachUrl(urlBefore, 10, null), urlBefore, Const.HSSE_HiddenRectificationListMenuId, model.HazardRegisterId);
|
||
|
||
}
|
||
//整改后照片
|
||
if (!string.IsNullOrEmpty(model.RectificationImageUrl))
|
||
{
|
||
//urlAfter = ConfigurationManager.AppSettings["localRoot"] + @"FileUpload\Registration\" + string.Format("{0:yyyyMMddHHmmssffff}", DateTime.Now) + "~r" + ".jpg";
|
||
urlAfter = getUrlByType("Registration");
|
||
System.IO.File.WriteAllBytes(urlAfter, Convert.FromBase64String(model.RectificationImageUrl));
|
||
urlAfter = urlAfter.Replace(ConfigurationManager.AppSettings["localRoot"], "");
|
||
UploadFileService.SaveAttachUrl(UploadFileService.GetSourceByAttachUrl(urlAfter, 10, null), urlAfter, Const.HSSE_HiddenRectificationListMenuId, model.HazardRegisterId + "r");
|
||
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
responeData.code = 0;
|
||
responeData.message = "图片上传出错" + ex.Message;
|
||
return responeData;
|
||
|
||
}
|
||
|
||
|
||
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
responeData.code = 0;
|
||
responeData.message = ex.Message;
|
||
}
|
||
return responeData;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 专项巡检同步
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
[Route("CheckSpecialSync")]
|
||
[HttpPost]
|
||
public Model.ResponeData CheckSpecialSync([FromBody] Check_CheckSpecialDto dto)
|
||
{
|
||
var responeData = new Model.ResponeData();
|
||
var unitid = "";
|
||
try
|
||
{
|
||
using (var db = new Model.SUBQHSEDB(Funs.ConnString))
|
||
{
|
||
var mapper = EmitMapper.ObjectMapperManager.DefaultInstance.GetMapper<Check_CheckSpecialDto, Model.Check_CheckSpecial>();
|
||
var model = mapper.Map(dto);
|
||
#region 判断参数
|
||
if (!string.IsNullOrEmpty(model.ProjectId))
|
||
{
|
||
var pid = getProjectIdByCode(model.ProjectId);
|
||
if (pid == "")
|
||
{
|
||
responeData.code = 0;
|
||
responeData.message = "所属项目名称未查询到数据,请检查是否正确。";
|
||
return responeData;
|
||
}
|
||
else
|
||
{
|
||
model.ProjectId = pid;
|
||
}
|
||
}
|
||
if (!string.IsNullOrEmpty(model.CompileMan))
|
||
{
|
||
var userid = getUserIdByIdentityCard(model.CompileMan);
|
||
if (userid == "")
|
||
{
|
||
responeData.code = 0;
|
||
responeData.message = "编制人身份证号码CompileMan未查询到数据,请检查是否正确。";
|
||
return responeData;
|
||
}
|
||
else
|
||
{
|
||
model.CompileMan = userid;
|
||
}
|
||
|
||
var pmodel = db.Sys_User.FirstOrDefault(x => x.UserId == model.CompileMan);
|
||
if (pmodel == null)
|
||
{
|
||
responeData.code = 0;
|
||
responeData.message = "编制人CompileMan未查询到数据,请检查是否正确。";
|
||
return responeData;
|
||
}
|
||
else {
|
||
unitid = pmodel.UnitId;
|
||
}
|
||
}
|
||
if (!string.IsNullOrEmpty(model.CheckType))
|
||
{
|
||
if (model.CheckType!="0"&& model.CheckType != "1" && model.CheckType != "2" && model.CheckType != "3")
|
||
{
|
||
responeData.code = 0;
|
||
responeData.message = "检查类型值错误,请检查是否正确。";
|
||
return responeData;
|
||
}
|
||
}
|
||
if (!string.IsNullOrEmpty(dto.CheckItemName))
|
||
{
|
||
var pmodel = db.Technique_CheckItemSet.FirstOrDefault(x => x.CheckItemName == dto.CheckItemName);
|
||
if (pmodel == null)
|
||
{
|
||
responeData.code = 0;
|
||
responeData.message = "检查类别CheckItemName未查询到数据,请检查是否正确。";
|
||
return responeData;
|
||
}
|
||
}
|
||
//检查组人员身份证
|
||
if (!string.IsNullOrEmpty(model.PartInPersonIds))
|
||
{
|
||
var PartInPersonIds = "";
|
||
foreach (var item in model.PartInPersonIds.Split(','))
|
||
{
|
||
var userid = getUserIdByIdentityCard(item);
|
||
if (userid == "")
|
||
{
|
||
responeData.code = 0;
|
||
responeData.message = "检查组身份证号码未查询到人员" + item + ",请检查是否正确。";
|
||
return responeData;
|
||
}
|
||
else {
|
||
PartInPersonIds += userid + ",";
|
||
}
|
||
}
|
||
model.PartInPersonIds = PartInPersonIds.Substring(0, PartInPersonIds.Length - 1);
|
||
}
|
||
|
||
if (dto.ChildList.Count>0)
|
||
{
|
||
foreach (var item in dto.ChildList)
|
||
{
|
||
if (!string.IsNullOrEmpty(item.CheckArea))
|
||
{
|
||
var pmodel = db.WBS_UnitWork.FirstOrDefault(x => x.UnitWorkName==item.CheckArea);
|
||
if (pmodel == null)
|
||
{
|
||
responeData.code = 0;
|
||
responeData.message = "单位工程名称(UnitWorkId)未查询到数据,请检查是否正确。";
|
||
return responeData;
|
||
}
|
||
else {
|
||
item.CheckArea = pmodel.UnitWorkId;
|
||
}
|
||
|
||
}
|
||
if (!string.IsNullOrEmpty(item.UnitId))
|
||
{
|
||
var uid = getUnitIdByUnitCollCropCode(item.UnitId);
|
||
if (uid == "")
|
||
{
|
||
responeData.code = 0;
|
||
responeData.message = "受检单位UnitId未查询到数据,请检查是否正确。";
|
||
return responeData;
|
||
}
|
||
else
|
||
{
|
||
item.UnitId = uid;
|
||
}
|
||
}
|
||
if (!string.IsNullOrEmpty(item.HSEManage))
|
||
{
|
||
var userid = getUserIdByIdentityCard(item.HSEManage);
|
||
if (userid == "")
|
||
{
|
||
responeData.code = 0;
|
||
responeData.message = "HSE经理身份证号码未查询到数据,请检查是否正确。";
|
||
return responeData;
|
||
}
|
||
else
|
||
{
|
||
item.HSEManage = userid;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
#endregion
|
||
model.CheckSpecialCode=CodeRecordsService.ReturnCodeByMenuIdProjectId(BLL.Const.ProjectCheckSpecialMenuId, model.ProjectId, unitid);
|
||
model.States = "3";
|
||
if (!string.IsNullOrEmpty(model.PartInPersonIds))
|
||
{
|
||
string partInPersonIds = string.Empty;
|
||
string partInPersons = string.Empty;
|
||
foreach (var item in model.PartInPersonIds.Split(','))
|
||
{
|
||
var user = BLL.UserService.GetUserByUserId(item);
|
||
if (user != null)
|
||
{
|
||
partInPersonIds += user.UserId + ",";
|
||
partInPersons += user.UserName + ",";
|
||
}
|
||
}
|
||
if (!string.IsNullOrEmpty(partInPersonIds))
|
||
{
|
||
model.PartInPersonIds = partInPersonIds.Substring(0, partInPersonIds.LastIndexOf(","));
|
||
model.PartInPersons = partInPersons.Substring(0, partInPersons.LastIndexOf(","));
|
||
}
|
||
}
|
||
var getCheckItem = Funs.DB.Technique_CheckItemSet.FirstOrDefault(x => x.CheckItemName == dto.CheckItemName);
|
||
if (getCheckItem != null)
|
||
{
|
||
model.CheckItemSetId = getCheckItem.CheckItemSetId;
|
||
}
|
||
model.CheckSpecialId = SQLHelper.GetNewID(typeof(Model.Check_CheckSpecial));
|
||
//新增专项检查主表
|
||
Check_CheckSpecialService.AddCheckSpecial(model);
|
||
//增加子表
|
||
int sortindex = 0;
|
||
foreach (var item in dto.ChildList)
|
||
{
|
||
var mapperChild = EmitMapper.ObjectMapperManager.DefaultInstance.GetMapper<Check_CheckSpecialDetailDto, Model.Check_CheckSpecialDetail>();
|
||
var modelChild = mapperChild.Map(item);
|
||
modelChild.CheckSpecialId = model.CheckSpecialId;
|
||
if (string.IsNullOrEmpty(modelChild.UnitId))
|
||
{
|
||
modelChild.UnitId = null;
|
||
}
|
||
if (string.IsNullOrEmpty(modelChild.WorkArea))
|
||
{
|
||
modelChild.WorkArea = null;
|
||
}
|
||
|
||
if (string.IsNullOrEmpty(modelChild.CheckArea))
|
||
{
|
||
modelChild.CheckArea = null;
|
||
}
|
||
if (modelChild.RectifyOpinion == "1")
|
||
{
|
||
modelChild.RectifyOpinion = "口头警告";
|
||
}
|
||
else {
|
||
modelChild.RectifyOpinion = "当场纠正";
|
||
}
|
||
var getHSSE_Hazard_HazardRegisterTypes = Funs.DB.HSSE_Hazard_HazardRegisterTypes.FirstOrDefault(x => x.RegisterTypesName == modelChild.CheckContent);
|
||
if (getHSSE_Hazard_HazardRegisterTypes != null)
|
||
{
|
||
modelChild.CheckItem = getHSSE_Hazard_HazardRegisterTypes.RegisterTypesId;
|
||
}
|
||
modelChild.SortIndex = sortindex;
|
||
modelChild.CheckSpecialDetailId = SQLHelper.GetNewID(typeof(Model.Check_CheckSpecialDetail));
|
||
Check_CheckSpecialDetailService.AddCheckSpecialDetail(modelChild);
|
||
|
||
if (!string.IsNullOrEmpty(item.ImgUrl))
|
||
{
|
||
|
||
var urlBefore = getUrlByType("checkspecial");
|
||
System.IO.File.WriteAllBytes(urlBefore, Convert.FromBase64String(item.ImgUrl));
|
||
urlBefore = urlBefore.Replace(ConfigurationManager.AppSettings["localRoot"], "");
|
||
UploadFileService.SaveAttachUrl(UploadFileService.GetSourceByAttachUrl(urlBefore, 10, null), urlBefore, Const.HSSE_APPCheckSpecialMenuId, modelChild.CheckSpecialDetailId);
|
||
}
|
||
sortindex += 1;
|
||
}
|
||
responeData.message = "添加成功";
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
responeData.code = 0;
|
||
responeData.message = ex.Message;
|
||
}
|
||
return responeData;
|
||
}
|
||
/// <summary>
|
||
/// 领导带班检查同步
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
[Route("LeaderCheckSync")]
|
||
[HttpPost]
|
||
public Model.ResponeData LeaderCheckSync([FromBody] Check_ProjectLeaderCheckDto dto)
|
||
{
|
||
var responeData = new Model.ResponeData();
|
||
try
|
||
{
|
||
using (var db = new Model.SUBQHSEDB(Funs.ConnString))
|
||
{
|
||
var mapper = EmitMapper.ObjectMapperManager.DefaultInstance.GetMapper<Check_ProjectLeaderCheckDto, Model.Check_ProjectLeaderCheck>();
|
||
var model = mapper.Map(dto);
|
||
#region 判断参数
|
||
if (!string.IsNullOrEmpty(model.ProjectId))
|
||
{
|
||
var pid = getProjectIdByCode(model.ProjectId);
|
||
if (pid == "")
|
||
{
|
||
responeData.code = 0;
|
||
responeData.message = "所属项目名称未查询到数据,请检查是否正确。";
|
||
return responeData;
|
||
}
|
||
else
|
||
{
|
||
model.ProjectId = pid;
|
||
}
|
||
}
|
||
if (!string.IsNullOrEmpty(model.UnitIds))
|
||
{
|
||
var unitIds = "";
|
||
foreach (var item in dto.UnitIds.Split(','))
|
||
{
|
||
var uid = getUnitIdByUnitCollCropCode(item);
|
||
if (uid == "")
|
||
{
|
||
responeData.code = 0;
|
||
responeData.message = "单位名称UnitIds"+item+"未查询到数据,请检查是否正确。";
|
||
return responeData;
|
||
}
|
||
else
|
||
{
|
||
unitIds += uid + ",";
|
||
}
|
||
}
|
||
model.UnitIds = unitIds.Substring(0, unitIds.Length - 1);
|
||
}
|
||
//带班领导身份证号码
|
||
if (!string.IsNullOrEmpty(model.LeaderIds))
|
||
{
|
||
var LeaderIds = "";
|
||
foreach (var item in dto.LeaderIds.Split(','))
|
||
{
|
||
var Userid = getUserIdByIdentityCard(item);
|
||
if (Userid=="")
|
||
{
|
||
responeData.code = 0;
|
||
responeData.message = "带班领导身份证LeaderIds"+item+"未查询到数据,请检查是否正确。";
|
||
return responeData;
|
||
}
|
||
else
|
||
{
|
||
LeaderIds += Userid + ",";
|
||
}
|
||
}
|
||
model.LeaderIds = LeaderIds;
|
||
}
|
||
|
||
|
||
#endregion
|
||
model.ProjectLeaderCheckId = SQLHelper.GetNewID(typeof(Model.Check_ProjectLeaderCheck));
|
||
model.IsHoldMeet = false;
|
||
db.Check_ProjectLeaderCheck.InsertOnSubmit(model);
|
||
db.SubmitChanges();
|
||
responeData.message = "领导带班检查同步成功";
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
responeData.code = 0;
|
||
responeData.message = ex.Message;
|
||
}
|
||
return responeData;
|
||
}
|
||
/// <summary>
|
||
/// 隐患整改单同步
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
[Route("RectifyNoticesSync")]
|
||
[HttpPost]
|
||
public Model.ResponeData RectifyNoticesSync([FromBody] Model.RectifyNoticesDto rectifyNotices)
|
||
{
|
||
var responeData = new Model.ResponeData();
|
||
try
|
||
{
|
||
using (Model.SUBQHSEDB db = new Model.SUBQHSEDB(Funs.ConnString))
|
||
{
|
||
#region 参数校验
|
||
|
||
if (BLL.UnitService.getUnitByUnitName(rectifyNotices.UnitId) == null)
|
||
{
|
||
responeData.code = 0;
|
||
responeData.message = "单位名称(UnitId)未查询到数据,请检查是否正确。";
|
||
return responeData;
|
||
}
|
||
else
|
||
{
|
||
rectifyNotices.UnitId = BLL.UnitService.getUnitByUnitName(rectifyNotices.UnitId).UnitId;
|
||
}
|
||
if (BLL.ProjectService.GetProjectByProjectName(rectifyNotices.ProjectId) == null)
|
||
{
|
||
responeData.code = 0;
|
||
responeData.message = "当前项目名称(ProjectId)未查询到数据,请检查是否正确!";
|
||
return responeData;
|
||
}
|
||
else
|
||
{
|
||
rectifyNotices.ProjectId = BLL.ProjectService.GetProjectByProjectName(rectifyNotices.ProjectId).ProjectId;
|
||
}
|
||
//检查组人员身份证
|
||
if (!string.IsNullOrEmpty(rectifyNotices.CheckManIds))
|
||
{
|
||
var PartInPersonIds = "";
|
||
foreach (var item in rectifyNotices.CheckManIds.Split(','))
|
||
{
|
||
var userid = getUserIdByIdentityCard(item);
|
||
if (userid == "")
|
||
{
|
||
responeData.code = 0;
|
||
responeData.message = "检查组身份证号码未查询到人员" + item + ",请检查是否正确。";
|
||
return responeData;
|
||
}
|
||
else
|
||
{
|
||
PartInPersonIds += userid + ",";
|
||
}
|
||
}
|
||
rectifyNotices.CheckManIds = PartInPersonIds.Substring(0, PartInPersonIds.Length - 1);
|
||
}
|
||
if (!string.IsNullOrEmpty(rectifyNotices.WorkAreaId) && BLL.UnitWorkService.GetUnitWorkByUnitWorkName(rectifyNotices.ProjectId, rectifyNotices.WorkAreaId) == null)
|
||
{
|
||
responeData.code = 0;
|
||
responeData.message = "单位工程(WorkAreaId)未查询到数据,请检查是否正确!";
|
||
return responeData;
|
||
}
|
||
else
|
||
{
|
||
rectifyNotices.WorkAreaId = (string.IsNullOrEmpty(rectifyNotices.WorkAreaId) ? rectifyNotices.WorkAreaId : UnitWorkService.GetUnitWorkByUnitWorkName(rectifyNotices.ProjectId, rectifyNotices.WorkAreaId).UnitWorkId);
|
||
|
||
}
|
||
|
||
if (!string.IsNullOrEmpty(rectifyNotices.CompleteManId))
|
||
{
|
||
if (BLL.UserService.GetUserByIdentityCard(rectifyNotices.CompleteManId)==null)
|
||
{
|
||
responeData.code = 0;
|
||
responeData.message = "该编制人身份证号码未查询到相关人员请检查是否正确。";
|
||
return responeData;
|
||
}
|
||
else
|
||
{
|
||
rectifyNotices.CompleteManId =
|
||
UserService.GetUserByIdentityCard(rectifyNotices.CompleteManId).UserId;
|
||
}
|
||
}
|
||
string[] a = { "1", "2", "3" };
|
||
if (!a.Contains(rectifyNotices.HiddenHazardType))
|
||
{
|
||
responeData.code = 0;
|
||
responeData.message = "隐患类别有误!";
|
||
return responeData;
|
||
}
|
||
#endregion
|
||
|
||
|
||
bool insertRectifyNoticesItemItem = false;
|
||
Model.Check_RectifyNotices newRectifyNotices = new Model.Check_RectifyNotices
|
||
{
|
||
RectifyNoticesId = SQLHelper.GetNewID(typeof(Check_RectifyNotices)),
|
||
ProjectId = rectifyNotices.ProjectId,
|
||
RectifyNoticesCode = rectifyNotices.RectifyNoticesCode,
|
||
UnitId = rectifyNotices.UnitId,
|
||
CheckManNames = UserService.getUserNamesUserIds(rectifyNotices.CheckManIds),
|
||
CheckManIds = rectifyNotices.CheckManIds,
|
||
CheckedDate = rectifyNotices.CheckedDate,
|
||
HiddenHazardType = rectifyNotices.HiddenHazardType,
|
||
States = rectifyNotices.States,
|
||
};
|
||
if (!string.IsNullOrEmpty(rectifyNotices.WorkAreaId))
|
||
{
|
||
newRectifyNotices.WorkAreaId = rectifyNotices.WorkAreaId;
|
||
}
|
||
if (!string.IsNullOrEmpty(rectifyNotices.CompleteManId))
|
||
{
|
||
newRectifyNotices.CompleteManId = rectifyNotices.CompleteManId;
|
||
}
|
||
//// 新增整改单
|
||
var isUpdate = db.Check_RectifyNotices.FirstOrDefault(x => x.RectifyNoticesId == newRectifyNotices.RectifyNoticesId);
|
||
if (isUpdate == null)
|
||
{
|
||
newRectifyNotices.RectifyNoticesId = SQLHelper.GetNewID();
|
||
if (string.IsNullOrEmpty(newRectifyNotices.RectifyNoticesCode))
|
||
{
|
||
newRectifyNotices.RectifyNoticesCode = CodeRecordsService.ReturnCodeByMenuIdProjectId(Const.ProjectRectifyNoticesMenuId, newRectifyNotices.ProjectId, newRectifyNotices.UnitId);
|
||
|
||
}
|
||
db.Check_RectifyNotices.InsertOnSubmit(newRectifyNotices);
|
||
db.SubmitChanges();
|
||
CodeRecordsService.InsertCodeRecordsByMenuIdProjectIdUnitId(Const.ProjectRectifyNoticesMenuId, newRectifyNotices.ProjectId, newRectifyNotices.UnitId, newRectifyNotices.RectifyNoticesId, newRectifyNotices.CheckedDate);
|
||
try
|
||
{
|
||
//// 整改单附件
|
||
if (!string.IsNullOrEmpty(rectifyNotices.BeAttachUrl))
|
||
{
|
||
string url = getUrlByType("RectifyNotices");
|
||
System.IO.File.WriteAllBytes(url, Convert.FromBase64String(rectifyNotices.BeAttachUrl));
|
||
url = url.Replace(ConfigurationManager.AppSettings["localRoot"], "");
|
||
APIUpLoadFileService.SaveAttachUrl(Const.ProjectRectifyNoticesMenuId, newRectifyNotices.RectifyNoticesId + "#0", url, "0");
|
||
}
|
||
//// 反馈单附件
|
||
if (!string.IsNullOrEmpty(rectifyNotices.AfAttachUrl))
|
||
{
|
||
var url = getUrlByType("RectifyNotices");
|
||
System.IO.File.WriteAllBytes(url, Convert.FromBase64String(rectifyNotices.BeAttachUrl));
|
||
url = url.Replace(ConfigurationManager.AppSettings["localRoot"], "");
|
||
APIUpLoadFileService.SaveAttachUrl(Const.ProjectRectifyNoticesMenuId, newRectifyNotices.RectifyNoticesId + "#1", url, "0");
|
||
}
|
||
//// 整个单据附件
|
||
if (!string.IsNullOrEmpty(rectifyNotices.AttachUrl))
|
||
{
|
||
var url = getUrlByType("RectifyNotices");
|
||
System.IO.File.WriteAllBytes(url, Convert.FromBase64String(rectifyNotices.BeAttachUrl));
|
||
url = url.Replace(ConfigurationManager.AppSettings["localRoot"], "");
|
||
APIUpLoadFileService.SaveAttachUrl(Const.ProjectRectifyNoticesMenuId, newRectifyNotices.RectifyNoticesId, url, "0");
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
RectifyNoticesService.DeleteRectifyNoticesById(newRectifyNotices.RectifyNoticesId);
|
||
responeData.code = 0;
|
||
responeData.message = "图片上传出错" + ex.Message;
|
||
return responeData;
|
||
}
|
||
|
||
insertRectifyNoticesItemItem = true;
|
||
}
|
||
if (insertRectifyNoticesItemItem)
|
||
{
|
||
//// 新增明细
|
||
if (rectifyNotices.RectifyNoticesDtoItem != null && rectifyNotices.RectifyNoticesDtoItem.Count() > 0)
|
||
{
|
||
foreach (var rItem in rectifyNotices.RectifyNoticesDtoItem)
|
||
{
|
||
Model.Check_RectifyNoticesItem newItem = new Model.Check_RectifyNoticesItem
|
||
{
|
||
RectifyNoticesItemId = SQLHelper.GetNewID(),
|
||
RectifyNoticesId = newRectifyNotices.RectifyNoticesId,
|
||
WrongContent = rItem.WrongContent,
|
||
Requirement = rItem.Requirement,
|
||
LimitTime = rItem.LimitTime,
|
||
RectifyResults = null,
|
||
IsRectify = null,
|
||
};
|
||
db.Check_RectifyNoticesItem.InsertOnSubmit(newItem);
|
||
db.SubmitChanges();
|
||
|
||
if (!string.IsNullOrEmpty(rItem.PhotoBeforeUrl))
|
||
{
|
||
string url = "";
|
||
url = getUrlByType("RectifyNotices");
|
||
System.IO.File.WriteAllBytes(url, Convert.FromBase64String(rectifyNotices.BeAttachUrl));
|
||
url = url.Replace(ConfigurationManager.AppSettings["localRoot"], "");
|
||
APIUpLoadFileService.SaveAttachUrl(Const.ProjectRectifyNoticesMenuId, newItem.RectifyNoticesItemId + "#1", url, "0");
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
responeData.code = 0;
|
||
responeData.message = ex.Message;
|
||
}
|
||
|
||
return responeData;
|
||
}
|
||
/// <summary>
|
||
/// 定稿作业票同步
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
[Route("LicenseManagerSync")]
|
||
[HttpPost]
|
||
public Model.ResponeData LicenseManagerSync(LicenseLicensemanagerDto dto)
|
||
{
|
||
var responeData = new Model.ResponeData();
|
||
try
|
||
{
|
||
using (var db = new Model.SUBQHSEDB(Funs.ConnString))
|
||
{
|
||
var mapper = EmitMapper.ObjectMapperManager.DefaultInstance.GetMapper<LicenseLicensemanagerDto, Model.License_LicenseManager>();
|
||
var model = mapper.Map(dto);
|
||
|
||
#region 参数校验
|
||
|
||
|
||
if (BLL.ProjectService.GetProjectByProjectName(model.ProjectId) == null)
|
||
{
|
||
responeData.code = 0;
|
||
responeData.message = "当前项目名称(ProjectId)未查询到数据,请检查是否正确!";
|
||
return responeData;
|
||
}
|
||
else
|
||
{
|
||
model.ProjectId = BLL.ProjectService.GetProjectByProjectName(model.ProjectId).ProjectId;
|
||
}
|
||
if (BLL.LicenseTypeService.GetLicenseTypeByName(model.LicenseTypeId) == null)
|
||
{
|
||
responeData.code = 0;
|
||
responeData.message = "许可证类型名称(LicenseTypeId)未查询到数据,请检查是否正确!";
|
||
return responeData;
|
||
}
|
||
else
|
||
{
|
||
model.LicenseTypeId= LicenseTypeService.GetLicenseTypeByName(model.LicenseTypeId).LicenseTypeId;
|
||
}
|
||
if (BLL.UnitService.getUnitByUnitName(model.UnitId) == null)
|
||
{
|
||
responeData.code = 0;
|
||
responeData.message = "单位名称(UnitId)未查询到数据,请检查是否正确!";
|
||
return responeData;
|
||
}
|
||
else
|
||
{
|
||
model.UnitId = BLL.UnitService.getUnitByUnitName(model.UnitId).UnitId;
|
||
}
|
||
if (!string.IsNullOrEmpty(model.WorkAreaId) && BLL.UnitWorkService.GetUnitWorkByUnitWorkName(model.ProjectId, model.WorkAreaId) == null)
|
||
{
|
||
responeData.code = 0;
|
||
responeData.message = "单位工程(WorkAreaId)未查询到数据,请检查是否正确!";
|
||
return responeData;
|
||
}
|
||
else
|
||
{
|
||
model.WorkAreaId = (string.IsNullOrEmpty(model.WorkAreaId) ? model.WorkAreaId : UnitWorkService.GetUnitWorkByUnitWorkName(model.ProjectId, model.WorkAreaId).UnitWorkId);
|
||
|
||
}
|
||
//if (BLL.LicenseManagerService.GetLicenseManagerByCode(model.ProjectId,model.LicenseManagerCode) != null)
|
||
//{
|
||
// responeData.code = 0;
|
||
// responeData.message = "许可证编号(LicenseManagerCode)已重复!";
|
||
// return responeData;
|
||
//}
|
||
if (!string.IsNullOrEmpty(model.CompileMan))
|
||
{
|
||
if (BLL.UserService.GetUserByIdentityCard(model.CompileMan) == null)
|
||
{
|
||
responeData.code = 0;
|
||
responeData.message = "该编制人身份证号码未查询到相关人员请检查是否正确。";
|
||
return responeData;
|
||
}
|
||
else
|
||
{
|
||
model.CompileMan =
|
||
UserService.GetUserByIdentityCard(model.CompileMan).UserId;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
model.CompileMan = null;
|
||
|
||
|
||
}
|
||
string[] a = { "0", "1", "2", "-1" };
|
||
if (!a.Contains(model.WorkStates))
|
||
{
|
||
responeData.code = 0;
|
||
responeData.message = "开工状态有误!";
|
||
return responeData;
|
||
}
|
||
#endregion
|
||
model.LicenseManagerId = SQLHelper.GetNewID();
|
||
model.States = BLL.Const.State_2;
|
||
BLL.LicenseManagerService.AddLicenseManager(model);
|
||
try
|
||
{
|
||
if (!string.IsNullOrEmpty(dto.AttachByte))
|
||
{
|
||
|
||
string urlBefore = getUrlByType("LicenseManagerAttachUrl");
|
||
System.IO.File.WriteAllBytes(urlBefore, Convert.FromBase64String(dto.AttachByte));
|
||
urlBefore = urlBefore.Replace(ConfigurationManager.AppSettings["localRoot"], "");
|
||
UploadFileService.SaveAttachUrl(UploadFileService.GetSourceByAttachUrl(urlBefore, 10, null), urlBefore, Const.ProjectLicenseManagerMenuId, model.LicenseManagerId);
|
||
|
||
}
|
||
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
LicenseManagerService.DeleteLicenseManagerById(model.LicenseManagerId);
|
||
responeData.code = 0;
|
||
responeData.message = "图片上次出错" + ex.Message;
|
||
return responeData;
|
||
|
||
}
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
responeData.code = 0;
|
||
responeData.message = ex.Message;
|
||
}
|
||
return responeData;
|
||
}
|
||
|
||
}
|
||
} |