525 lines
24 KiB
C#
525 lines
24 KiB
C#
using Newtonsoft.Json.Linq;
|
|
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Configuration;
|
|
using System.IO;
|
|
using System.Net.Http;
|
|
using System.Threading.Tasks;
|
|
using Model;
|
|
using Newtonsoft.Json;
|
|
using RestSharp;
|
|
using System.Net;
|
|
|
|
|
|
namespace BLL;
|
|
|
|
public class APICheckSpecialSyncService
|
|
{
|
|
#region 根据项目、单位获取专项检查列表
|
|
|
|
public static List<Model.CheckSpecialSyncItem> GetCheckSpecialLitsByprojectIdUnitId(string projectId,
|
|
string unitId, string dataId = "")
|
|
{
|
|
using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString))
|
|
{
|
|
var list = from x in db.Check_CheckSpecialPro where x.ProjectId == projectId select x;
|
|
if (!string.IsNullOrEmpty(unitId))
|
|
{
|
|
// 通过关联明细表来筛选包含指定单位的主表数据
|
|
var specialIdsWithUnit = (from detail in db.Check_CheckSpecialProDetail
|
|
where detail.UnitId == unitId
|
|
select detail.CheckSpecialId).Distinct();
|
|
|
|
list = list.Where(x => specialIdsWithUnit.Contains(x.CheckSpecialId));
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(dataId))
|
|
{
|
|
list = list.Where(x => x.CheckSpecialId == dataId);
|
|
}
|
|
|
|
var dataList = (from x in list
|
|
join cis in db.Technique_CheckItemSet on x.CheckItemSetId equals cis.CheckItemSetId into cisTemp
|
|
from cis in cisTemp.DefaultIfEmpty()
|
|
join att in db.AttachFile on x.CheckSpecialId equals att.ToKeyId into attTemp
|
|
from att in attTemp.DefaultIfEmpty()
|
|
select new CheckSpecialSyncItem
|
|
{
|
|
CheckSpecialId = x.CheckSpecialId,
|
|
CheckSpecialCode = x.CheckSpecialCode,
|
|
ProjectId = x.ProjectId,
|
|
CheckPerson = x.CheckPerson,
|
|
CheckTime = x.CheckTime,
|
|
ScanUrl = x.ScanUrl,
|
|
DaySummary = x.DaySummary,
|
|
PartInUnits = x.PartInUnits,
|
|
PartInPersons = x.PartInPersons,
|
|
CheckAreas = x.CheckAreas,
|
|
States = x.States,
|
|
CompileMan = x.CompileMan,
|
|
CheckType = x.CheckType,
|
|
PartInPersonIds = x.PartInPersonIds,
|
|
PartInPersonNames = x.PartInPersonNames,
|
|
CheckItemSetId = x.CheckItemSetId,
|
|
CheckItemName = cis.CheckItemName,
|
|
AttachFileId1 = att.AttachFileId,
|
|
ToKeyId1 = att.ToKeyId,
|
|
AttachSource1 = att.AttachSource,
|
|
AttachUrl1 = att.AttachUrl,
|
|
CheckSpecialDetails = GetCheckSpecialDetailLists(x.CheckSpecialId),
|
|
}).ToList();
|
|
|
|
return dataList;
|
|
}
|
|
}
|
|
|
|
|
|
//根据专项检查id获取专项检查明细数据
|
|
public static List<Model.CheckSpecialDetailSyncItem> GetCheckSpecialDetailLists(string checkSpecialId)
|
|
{
|
|
var detailLists = (from x in Funs.DB.Check_CheckSpecialProDetail
|
|
join ht in Funs.DB.HSSE_Hazard_HazardRegisterTypes on x.CheckItem equals ht.RegisterTypesId into htTemp
|
|
from ht in htTemp.DefaultIfEmpty()
|
|
join uw in Funs.DB.WBS_UnitWork on x.CheckArea equals uw.UnitWorkId into uwTemp
|
|
from uw in uwTemp.DefaultIfEmpty()
|
|
join u1 in Funs.DB.Sys_User on x.HSEManage equals u1.UserId into u1Temp
|
|
from u1 in u1Temp.DefaultIfEmpty()
|
|
join att in Funs.DB.AttachFile on x.CheckSpecialDetailId equals att.ToKeyId into attTemp
|
|
from att in attTemp.DefaultIfEmpty()
|
|
where x.CheckSpecialId == checkSpecialId
|
|
select new CheckSpecialDetailSyncItem
|
|
{
|
|
CheckSpecialDetailId = x.CheckSpecialDetailId,
|
|
CheckSpecialId = x.CheckSpecialId,
|
|
CheckItem = x.CheckItem,
|
|
CheckItemName = ht.RegisterTypesName,
|
|
CheckItemType = x.CheckItemType,
|
|
Unqualified = x.Unqualified,
|
|
CheckArea = x.CheckArea,
|
|
CheckAreaName = uw.UnitWorkName,
|
|
UnitId = x.UnitId,
|
|
CompleteStatus = x.CompleteStatus,
|
|
LimitedDate = x.LimitedDate,
|
|
CompletedDate = x.CompletedDate,
|
|
Suggestions = x.Suggestions,
|
|
HandleStep = x.HandleStep,
|
|
RectifyNoticeId = x.RectifyNoticeId,
|
|
CheckContent = x.CheckContent,
|
|
WorkArea = x.WorkArea,
|
|
DataId = x.DataId,
|
|
DataType = x.DataType,
|
|
SortIndex = x.SortIndex,
|
|
HiddenHazardType = x.HiddenHazardType,
|
|
HSEManage = x.HSEManage,
|
|
HSEManageName = u1.UserName,
|
|
RiskLevel = x.RiskLevel,
|
|
LimitDate = x.LimitDate,
|
|
AttachUrl = x.AttachUrl,
|
|
HandleWay = x.HandleWay,
|
|
RectifyOpinion = x.RectifyOpinion,
|
|
RectifyDate = x.RectifyDate,
|
|
ReAttachUrl = x.ReAttachUrl,
|
|
State = x.State,
|
|
ProposeUnitId = x.ProposeUnitId,
|
|
SaveHandleMan = x.SaveHandleMan,
|
|
AttachFileId1 = att.AttachFileId,
|
|
ToKeyId1 = att.ToKeyId,
|
|
AttachSource1 = att.AttachSource,
|
|
AttachUrl1 = att.AttachUrl,
|
|
})
|
|
.ToList();
|
|
|
|
return detailLists;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region 拉取项目专项检查数据
|
|
|
|
public static async Task<string> getCheckSpecialLists()
|
|
{
|
|
int code = 0;
|
|
string message = "";
|
|
try
|
|
{
|
|
string CollCropCode = string.Empty;
|
|
string unitId = string.Empty;
|
|
var thisUnit = CommonService.GetIsThisUnit(); //当前单位
|
|
if (thisUnit != null)
|
|
{
|
|
CollCropCode = thisUnit.CollCropCode; //社会统一信用代码
|
|
unitId = thisUnit.UnitId;
|
|
}
|
|
|
|
var ProjectList = (from x in Funs.DB.Base_Project
|
|
where (x.IsDelete == null || x.IsDelete == false) && x.SubjectUnit != null &&
|
|
x.SubjectProject != null
|
|
select x).ToList();
|
|
if (ProjectList.Count > 0)
|
|
{
|
|
foreach (var project in ProjectList)
|
|
{
|
|
string SubjectUnitId = project.SubjectUnit; //集团的单位id
|
|
string SubjectProjectId = project.SubjectProject; //集团的单位id
|
|
//获取对应单位的apiurl地址
|
|
var Url = BLL.UnitService.getUnitApiUrlByUnitId(SubjectUnitId);
|
|
var ApiUrl = "";
|
|
var WebUrl = "";
|
|
if (!string.IsNullOrEmpty(Url))
|
|
{
|
|
var urls = Url.Split(',');
|
|
ApiUrl = urls[0];
|
|
if (urls.Length > 1)
|
|
{
|
|
WebUrl = urls[1];
|
|
}
|
|
}
|
|
|
|
// CollCropCode = "913404001520228377Y"; //三化建 测试使用
|
|
// SubjectProjectId = "B409A8D7-48C7-486E-84C7-E3E7B2C0E5B7";//测试使用
|
|
|
|
string url = "/api/CheckSpecialSync/getCheckSpecialListByProjectIdAndCollCropCode?projectId=" +
|
|
SubjectProjectId + "&collCropCode=" + CollCropCode;
|
|
string baseurl = ApiUrl + url;
|
|
|
|
string contenttype = "application/json;charset=unicode";
|
|
var strJosn = APIGetHttpService.Http(baseurl, "GET", contenttype, null, null);
|
|
if (!string.IsNullOrEmpty(strJosn))
|
|
{
|
|
JObject obj = JObject.Parse(strJosn);
|
|
code = Funs.GetNewIntOrZero(obj["code"].ToString());
|
|
message = obj["message"].ToString();
|
|
if (code == 1)
|
|
{
|
|
var getData =
|
|
JsonConvert.DeserializeObject<List<CheckSpecialSyncItem>>(obj["data"].ToString());
|
|
if (getData.Count() > 0)
|
|
{
|
|
ProcessCheckSpecialData(getData, project.ProjectId, unitId, WebUrl);
|
|
}
|
|
|
|
message = "获取成功:同步专项检查数" + getData.Count().ToString() + "条";
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
message = "获取失败:" + ex.Message;
|
|
ErrLogInfo.WriteLog("专项检查获取!", ex);
|
|
}
|
|
|
|
return message;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region 推送专项检查数据
|
|
|
|
public static ReturnData pushCheckSpecialLists(string projectId, string dataId = "")
|
|
{
|
|
Model.ReturnData responeData = new Model.ReturnData();
|
|
responeData.code = 0;
|
|
responeData.message = string.Empty;
|
|
try
|
|
{
|
|
var project = Funs.DB.Base_Project.FirstOrDefault(x => x.ProjectId == projectId);
|
|
if (project != null)
|
|
{
|
|
//获取专项检查数据
|
|
var items = GetCheckSpecialLitsByprojectIdUnitId(projectId, "", dataId);
|
|
//总包地址推送
|
|
if (items.Count() > 0)
|
|
{
|
|
var thisUnit = CommonService.GetIsThisUnit(); //当前单位
|
|
var apiurl = "/api/CheckSpecialSync/SaveCheckSpecialSyncData";
|
|
//总包单位接口地址
|
|
var Url = BLL.UnitService.getUnitApiUrlByUnitId(project.SubjectUnit);
|
|
var ApiUrl = "";
|
|
var WebUrl = "";
|
|
if (!string.IsNullOrEmpty(Url))
|
|
{
|
|
var urls = Url.Split(',');
|
|
ApiUrl = urls[0];
|
|
if (urls.Length > 1)
|
|
{
|
|
WebUrl = urls[1];
|
|
}
|
|
}
|
|
|
|
// thisUnit.CollCropCode = "913404001520228377Y";//测试使用
|
|
// project.SubjectProject = "B409A8D7-48C7-486E-84C7-E3E7B2C0E5B7";//测试使用
|
|
|
|
var pushData = new CheckSpecialSyncData
|
|
{
|
|
CollCropCode = thisUnit.CollCropCode, //分包单位社会统一信用码
|
|
ProjectId = project.SubjectProject, //主包项目Id
|
|
UnitDomain = Funs.SGGLUrl, //分包单位域名地址【文件存储地址】
|
|
Items = items //专项检查数据
|
|
};
|
|
var pushContent = JsonConvert.SerializeObject(pushData);
|
|
string baseurl = ApiUrl + apiurl;
|
|
string contenttype = "application/json;charset=unicode";
|
|
var returndata = APIGetHttpService.Http(baseurl, "Post", contenttype, null, pushContent);
|
|
if (!string.IsNullOrEmpty(returndata))
|
|
{
|
|
JObject obj = JObject.Parse(returndata);
|
|
string code = obj["code"].ToString();
|
|
string message = obj["message"].ToString();
|
|
responeData.code = int.Parse(code);
|
|
responeData.message = message;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
responeData.code = 0;
|
|
responeData.message = "当前没有项目专项检查数据";
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
responeData.message = "同步到总包单位失败!";
|
|
ErrLogInfo.WriteLog("【项目专项检查】同步到总包单位失败!", ex);
|
|
}
|
|
|
|
return responeData;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region 接收保存项目专项检查数据
|
|
|
|
public static async Task<string> SaveCheckSpecialSyncData(Model.CheckSpecialSyncData items)
|
|
{
|
|
int code = 0;
|
|
string message = "";
|
|
try
|
|
{
|
|
if (items.Items.Count > 0 || items.Items.Count > 0)
|
|
{
|
|
//获取CollCropCode
|
|
var CollCropCode = items.CollCropCode;
|
|
var ProjectId = items.ProjectId;
|
|
var UnitDomain = items.UnitDomain; //分包单位域名地址【文件存储地址】
|
|
//根据CollCropCode获取单位id
|
|
var unit = Funs.DB.Base_Unit.FirstOrDefault(x => x.CollCropCode == CollCropCode);
|
|
if (unit == null)
|
|
{
|
|
message = "总包单位不存在本单位,请登录总包系统检查维护本单位信息!";
|
|
}
|
|
else
|
|
{
|
|
//2、判断主包项目是否存在
|
|
var porject = BLL.ProjectService.GetProjectByProjectId(ProjectId);
|
|
if (porject == null)
|
|
{
|
|
message = "总包单位不存在本项目,请检查总包项目关联是否正确!";
|
|
}
|
|
else
|
|
{
|
|
ProcessCheckSpecialData(items.Items, ProjectId, unit.UnitId, UnitDomain);
|
|
message = "数据推送成功!";
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
message = "暂无项目专项检查数据!";
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
|
|
return message;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region 处理单项目专项检查数据的新增或更新逻辑
|
|
|
|
/// <summary>
|
|
/// 处理单项目专项检查数据的新增或更新逻辑
|
|
/// </summary>
|
|
/// <param name="item">专项检查数据项</param>
|
|
/// <param name="projectId">项目id</param>
|
|
/// <param name="unitId">单位ID</param>
|
|
/// <param name="WebUrl">Web地址</param>
|
|
private static async void ProcessCheckSpecialData(List<Model.CheckSpecialSyncItem> getData, string projectId,
|
|
string unitId, string WebUrl)
|
|
{
|
|
using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString))
|
|
{
|
|
foreach (var item in getData)
|
|
{
|
|
var model = db.Check_CheckSpecialPro.FirstOrDefault(e => e.CheckSpecialId == item.CheckSpecialId);
|
|
if (model == null)
|
|
{
|
|
Model.Check_CheckSpecialPro newModel = new Model.Check_CheckSpecialPro
|
|
{
|
|
CheckSpecialId = item.CheckSpecialId,
|
|
CheckSpecialCode = item.CheckSpecialCode,
|
|
ProjectId = projectId,
|
|
CheckPerson = item.CheckPerson,
|
|
CheckTime = item.CheckTime,
|
|
ScanUrl = item.ScanUrl,
|
|
DaySummary = item.DaySummary,
|
|
PartInUnits = item.PartInUnits,
|
|
PartInPersons = item.PartInPersons,
|
|
CheckAreas = item.CheckAreas,
|
|
States = item.States,
|
|
CompileMan = item.CompileMan,
|
|
CheckType = item.CheckType,
|
|
PartInPersonIds = item.PartInPersonIds,
|
|
PartInPersonNames = item.PartInPersonNames,
|
|
CheckItemSetId = APIDataShareSyncService.getCheckItemSetId(item.CheckItemName),
|
|
};
|
|
|
|
db.Check_CheckSpecialPro.InsertOnSubmit(newModel);
|
|
db.SubmitChanges();
|
|
}
|
|
else
|
|
{
|
|
model.CheckSpecialId = item.CheckSpecialId;
|
|
model.CheckSpecialCode = item.CheckSpecialCode;
|
|
model.ProjectId = projectId;
|
|
model.CheckPerson = item.CheckPerson;
|
|
model.CheckTime = item.CheckTime;
|
|
model.ScanUrl = item.ScanUrl;
|
|
model.DaySummary = item.DaySummary;
|
|
model.PartInUnits = item.PartInUnits;
|
|
model.PartInPersons = item.PartInPersons;
|
|
model.CheckAreas = item.CheckAreas;
|
|
model.States = item.States;
|
|
model.CompileMan = item.CompileMan;
|
|
model.CheckType = item.CheckType;
|
|
model.PartInPersonIds = item.PartInPersonIds;
|
|
model.PartInPersonNames = item.PartInPersonNames;
|
|
model.CheckItemSetId = APIDataShareSyncService.getCheckItemSetId(item.CheckItemName);
|
|
db.SubmitChanges();
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(item.AttachUrl1)) //主表附件
|
|
{
|
|
APIDataShareSyncService.OperationAttachFile(WebUrl, item.CheckSpecialId,
|
|
BLL.Const.ProjectCheckSpecialMenuId, item.AttachUrl1);
|
|
}
|
|
|
|
//处理专项检查明细数据
|
|
ProcessCheckSpecialDetailData(item.CheckSpecialDetails, projectId, unitId, WebUrl);
|
|
}
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region 处理单项目专项检查明细数据的新增或更新逻辑
|
|
|
|
/// <summary>
|
|
/// 处理单项目专项检查明细数据的新增或更新逻辑
|
|
/// </summary>
|
|
/// <param name="item">专项检查数据项</param>
|
|
/// <param name="projectId">项目id</param>
|
|
/// <param name="unitId">单位ID</param>
|
|
/// <param name="WebUrl">Web地址</param>
|
|
private static async void ProcessCheckSpecialDetailData(List<Model.CheckSpecialDetailSyncItem> getData,
|
|
string projectId,
|
|
string unitId, string WebUrl)
|
|
{
|
|
using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString))
|
|
{
|
|
foreach (var item in getData)
|
|
{
|
|
var model = db.Check_CheckSpecialProDetail.FirstOrDefault(e =>
|
|
e.CheckSpecialDetailId == item.CheckSpecialDetailId);
|
|
if (model == null)
|
|
{
|
|
Model.Check_CheckSpecialProDetail newModel = new Model.Check_CheckSpecialProDetail
|
|
{
|
|
CheckSpecialDetailId = item.CheckSpecialDetailId,
|
|
CheckSpecialId = item.CheckSpecialId,
|
|
CheckItem = APIDataShareSyncService.getRegisterTypesId(item.CheckItemName),
|
|
CheckItemType = item.CheckItemType,
|
|
Unqualified = item.Unqualified,
|
|
CheckArea = APIDataShareSyncService.getUnitWorkId(item.CheckAreaName, projectId),
|
|
UnitId = unitId,
|
|
CompleteStatus = item.CompleteStatus,
|
|
LimitedDate = item.LimitedDate,
|
|
CompletedDate = item.CompletedDate,
|
|
Suggestions = item.Suggestions,
|
|
HandleStep = item.HandleStep,
|
|
RectifyNoticeId = item.RectifyNoticeId,
|
|
CheckContent = item.CheckContent,
|
|
WorkArea = item.WorkArea,
|
|
DataId = item.DataId,
|
|
DataType = item.DataType,
|
|
SortIndex = item.SortIndex,
|
|
HiddenHazardType = item.HiddenHazardType,
|
|
HSEManage = APIDataShareSyncService.getUserId(item.HSEManageName),
|
|
RiskLevel = item.RiskLevel,
|
|
LimitDate = item.LimitDate,
|
|
AttachUrl = item.AttachUrl,
|
|
HandleWay = item.HandleWay,
|
|
RectifyOpinion = item.RectifyOpinion,
|
|
RectifyDate = item.RectifyDate,
|
|
ReAttachUrl = item.ReAttachUrl,
|
|
State = item.State,
|
|
ProposeUnitId = item.ProposeUnitId,
|
|
SaveHandleMan = item.SaveHandleMan,
|
|
};
|
|
|
|
db.Check_CheckSpecialProDetail.InsertOnSubmit(newModel);
|
|
db.SubmitChanges();
|
|
}
|
|
else
|
|
{
|
|
model.CheckSpecialDetailId = item.CheckSpecialDetailId;
|
|
model.CheckSpecialId = item.CheckSpecialId;
|
|
model.CheckItem = APIDataShareSyncService.getRegisterTypesId(item.CheckItemName);
|
|
model.CheckItemType = item.CheckItemType;
|
|
model.Unqualified = item.Unqualified;
|
|
model.CheckArea = APIDataShareSyncService.getUnitWorkId(item.CheckAreaName, projectId);
|
|
model.UnitId = unitId;
|
|
model.CompleteStatus = item.CompleteStatus;
|
|
model.LimitedDate = item.LimitedDate;
|
|
model.CompletedDate = item.CompletedDate;
|
|
model.Suggestions = item.Suggestions;
|
|
model.HandleStep = item.HandleStep;
|
|
model.RectifyNoticeId = item.RectifyNoticeId;
|
|
model.CheckContent = item.CheckContent;
|
|
model.WorkArea = item.WorkArea;
|
|
model.DataId = item.DataId;
|
|
model.DataType = item.DataType;
|
|
model.SortIndex = item.SortIndex;
|
|
model.HiddenHazardType = item.HiddenHazardType;
|
|
model.HSEManage = APIDataShareSyncService.getUserId(item.HSEManageName);
|
|
model.RiskLevel = item.RiskLevel;
|
|
model.LimitDate = item.LimitDate;
|
|
model.AttachUrl = item.AttachUrl;
|
|
model.HandleWay = item.HandleWay;
|
|
model.RectifyOpinion = item.RectifyOpinion;
|
|
model.RectifyDate = item.RectifyDate;
|
|
model.ReAttachUrl = item.ReAttachUrl;
|
|
model.State = item.State;
|
|
model.ProposeUnitId = item.ProposeUnitId;
|
|
model.SaveHandleMan = item.SaveHandleMan;
|
|
|
|
db.SubmitChanges();
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(item.AttachUrl1)) //整改前图片
|
|
{
|
|
APIDataShareSyncService.OperationAttachFile(WebUrl, item.CheckSpecialDetailId,
|
|
BLL.Const.ProjectCheckSpecialMenuId, item.AttachUrl1);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
} |