273 lines
16 KiB
C#
273 lines
16 KiB
C#
|
|
using Model;
|
|||
|
|
using Newtonsoft.Json;
|
|||
|
|
using Newtonsoft.Json.Linq;
|
|||
|
|
using System;
|
|||
|
|
using System.Collections;
|
|||
|
|
using System.Linq;
|
|||
|
|
|
|||
|
|
namespace BLL
|
|||
|
|
{
|
|||
|
|
/// <summary>
|
|||
|
|
/// 安全会议数据共享互通
|
|||
|
|
/// </summary>
|
|||
|
|
public class APIMeetingSyncService
|
|||
|
|
{
|
|||
|
|
#region 分包单位推送数据到总包单位
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 推送分包班前会数据
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="projectId">项目Id</param>
|
|||
|
|
/// <param name="dataId">班前会数据Id(为空的时候推送全部)</param>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
public static ReturnData PushClassMeetingLists(string projectId, string dataId = "")
|
|||
|
|
{
|
|||
|
|
Model.ReturnData responeData = new Model.ReturnData();
|
|||
|
|
responeData.code = 0;
|
|||
|
|
responeData.message = string.Empty;
|
|||
|
|
using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString))
|
|||
|
|
{
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
var list = from x in db.Meeting_ClassMeeting where x.ProjectId == projectId select x;
|
|||
|
|
if (!string.IsNullOrWhiteSpace(dataId))
|
|||
|
|
{
|
|||
|
|
list = list.Where(x => x.ClassMeetingId == dataId);
|
|||
|
|
}
|
|||
|
|
var dataList = (from x in list
|
|||
|
|
join ptg in db.ProjectData_TeamGroup on x.TeamGroupId equals ptg.TeamGroupId into ptGroup
|
|||
|
|
from ptg in ptGroup.DefaultIfEmpty()
|
|||
|
|
join su in db.Sys_User on x.CompileMan equals su.UserId into sUser
|
|||
|
|
from su in sUser.DefaultIfEmpty()
|
|||
|
|
join att in db.AttachFile on x.ClassMeetingId equals att.ToKeyId into attTemp
|
|||
|
|
from att in attTemp.DefaultIfEmpty()
|
|||
|
|
join att1 in db.AttachFile on (x.ClassMeetingId + "#1") equals att1.ToKeyId into att1Temp
|
|||
|
|
from att1 in att1Temp.DefaultIfEmpty()
|
|||
|
|
join att2 in db.AttachFile on (x.ClassMeetingId + "#2") equals att2.ToKeyId into att2Temp
|
|||
|
|
from att2 in att2Temp.DefaultIfEmpty()
|
|||
|
|
orderby x.CompileDate descending
|
|||
|
|
select new ClassMeetingItem
|
|||
|
|
{
|
|||
|
|
ProjectId = x.ProjectId,
|
|||
|
|
UnitId = x.UnitId,
|
|||
|
|
ClassMeetingId = x.ClassMeetingId,
|
|||
|
|
ClassMeetingCode = x.ClassMeetingCode,
|
|||
|
|
ClassMeetingName = x.ClassMeetingName,
|
|||
|
|
ClassMeetingDate = x.ClassMeetingDate,
|
|||
|
|
ClassMeetingContents = x.ClassMeetingContents,
|
|||
|
|
CompileMan = x.CompileMan,
|
|||
|
|
CompileManName = su.UserName,
|
|||
|
|
TeamGroupId = x.TeamGroupId,
|
|||
|
|
TeamGroupName = ptg.TeamGroupName,
|
|||
|
|
CompileDate = x.CompileDate,
|
|||
|
|
States = x.States,
|
|||
|
|
MeetingPlace = x.MeetingPlace,
|
|||
|
|
MeetingHours = x.MeetingHours,
|
|||
|
|
MeetingHostMan = x.MeetingHostMan,
|
|||
|
|
AttentPerson = x.AttentPerson,
|
|||
|
|
AttentPersonNum = x.AttentPersonNum,
|
|||
|
|
//MeetingHostManOther = x.MeetingHostManOther,
|
|||
|
|
Remark = x.Remark,
|
|||
|
|
//AttachUrl = AttachFileService.getFileUrl(x.ClassMeetingId),//内容
|
|||
|
|
//AttachUrl1 = AttachFileService.getFileUrl(x.ClassMeetingId + "#1"),//签到表
|
|||
|
|
//AttachUrl2 = AttachFileService.getFileUrl(x.ClassMeetingId + "#2"),//会议过程
|
|||
|
|
AttachFileId = att.AttachFileId,
|
|||
|
|
ToKeyId = att.ToKeyId,
|
|||
|
|
AttachSource = att.AttachSource,
|
|||
|
|
AttachUrl = att.AttachUrl,
|
|||
|
|
AttachFileId1 = att1.AttachFileId,
|
|||
|
|
ToKeyId1 = att1.ToKeyId,
|
|||
|
|
AttachSource1 = att1.AttachSource,
|
|||
|
|
AttachUrl1 = att1.AttachUrl,
|
|||
|
|
AttachFileId2 = att2.AttachFileId,
|
|||
|
|
ToKeyId2 = att2.ToKeyId,
|
|||
|
|
AttachSource2 = att2.AttachSource,
|
|||
|
|
AttachUrl2 = att2.AttachUrl,
|
|||
|
|
}).ToList();
|
|||
|
|
|
|||
|
|
if (dataList.Count() > 0)
|
|||
|
|
{
|
|||
|
|
var thisUnit = CommonService.GetIsThisUnit();
|
|||
|
|
var porject = BLL.ProjectService.GetProjectByProjectId(projectId);
|
|||
|
|
var pushData = new ClassMeetingData
|
|||
|
|
{
|
|||
|
|
CollCropCode = thisUnit.CollCropCode,//分包单位社会统一信用码
|
|||
|
|
UnitId = thisUnit.UnitId,//分包单位Id
|
|||
|
|
UnitName = thisUnit.UnitName,//分包单位名称
|
|||
|
|
ShortUnitName = thisUnit.ShortUnitName,//分包单位简称
|
|||
|
|
UnitDomain = Funs.SGGLUrl,//分包单位域名地址【文件存储地址】
|
|||
|
|
SubjectUnit = porject.SubjectUnit,//主包单位Id
|
|||
|
|
SubjectProject = porject.SubjectProject,//主包项目Id
|
|||
|
|
Items = dataList//会议数据
|
|||
|
|
};
|
|||
|
|
var pushContent = JsonConvert.SerializeObject(pushData);
|
|||
|
|
|
|||
|
|
//获取总包单位接口apiurl地址
|
|||
|
|
var Url = BLL.UnitService.getUnitApiUrlByUnitId(porject.SubjectUnit);
|
|||
|
|
var ApiUrl = string.Empty;
|
|||
|
|
var WebUrl = string.Empty;
|
|||
|
|
if (Url != null)
|
|||
|
|
{
|
|||
|
|
var urls = Url.Split(',');
|
|||
|
|
ApiUrl = urls[0];
|
|||
|
|
if (urls.Length > 1)
|
|||
|
|
{
|
|||
|
|
WebUrl = urls[1];
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
var baseurl = $"{ApiUrl}/api/MeetingSync/ReceiveSaveProjectClassMeetingData";
|
|||
|
|
string contenttype = "application/json;charset=unicode";
|
|||
|
|
Hashtable newToken = new Hashtable
|
|||
|
|
{
|
|||
|
|
{ "token", ServerService.GetToken().Token }
|
|||
|
|
};
|
|||
|
|
//var returndata = APIGetHttpService.Http(baseurl, "Post", contenttype, newToken, pushContent);
|
|||
|
|
var returndata = "";
|
|||
|
|
if (!string.IsNullOrEmpty(returndata))
|
|||
|
|
{
|
|||
|
|
JObject obj = JObject.Parse(returndata);
|
|||
|
|
string mess = obj["message"].ToString();
|
|||
|
|
string code = obj["code"].ToString();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
responeData.message = "当前项目没有班前会数据";
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
catch (Exception ex)
|
|||
|
|
{
|
|||
|
|
responeData.message = "同步到总包单位失败!";
|
|||
|
|
ErrLogInfo.WriteLog("【班前会】同步到总包单位失败!", ex);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
return responeData;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
#endregion
|
|||
|
|
|
|||
|
|
#region 总包单位接收分包单位推送数据
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 总包单位接收保存分包单位推送的班前会数据
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="data"></param>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
public static string ReceiveSaveProjectClassMeetingData(ClassMeetingData data)
|
|||
|
|
{
|
|||
|
|
using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString))
|
|||
|
|
{
|
|||
|
|
string result = string.Empty;
|
|||
|
|
if (data.Items.Count() > 0)
|
|||
|
|
{
|
|||
|
|
//1、判断分包单位是否存在
|
|||
|
|
var unit = UnitService.getUnitByCollCropCodeUnitName(data.CollCropCode, data.UnitName);
|
|||
|
|
if (unit == null)
|
|||
|
|
{
|
|||
|
|
result = "总包单位不存在本单位,请登录总包系统检查维护本单位信息!";
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
//2、判断主包项目是否存在
|
|||
|
|
var porject = BLL.ProjectService.GetProjectByProjectId(data.SubjectProject);
|
|||
|
|
if (porject == null)
|
|||
|
|
{
|
|||
|
|
result = "总包单位不存在本项目,请检查总包项目关联是否正确!";
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
int succ = 0;
|
|||
|
|
//3、保存数据
|
|||
|
|
foreach (var item in data.Items)
|
|||
|
|
{
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
var model = ClassMeetingService.GetClassMeetingById(item.ClassMeetingId);
|
|||
|
|
if (model != null)
|
|||
|
|
{//编辑
|
|||
|
|
model.ProjectId = data.SubjectProject;
|
|||
|
|
model.UnitId = unit.UnitId;
|
|||
|
|
model.ClassMeetingCode = item.ClassMeetingCode;
|
|||
|
|
model.ClassMeetingName = item.ClassMeetingName;
|
|||
|
|
model.ClassMeetingDate = item.ClassMeetingDate;
|
|||
|
|
model.AttentPersonNum = item.AttentPersonNum;
|
|||
|
|
//model.TeamGroupId = item.TeamGroupId;
|
|||
|
|
model.TeamGroupId = APIDataShareSyncService.GetTeamGroupId(item.TeamGroupName, data.SubjectProject, unit.UnitId);
|
|||
|
|
model.AttentPersonNum = item.AttentPersonNum;
|
|||
|
|
//model.ClassMeetingContents = HttpUtility.HtmlEncode(item.ClassMeetingContents);
|
|||
|
|
model.ClassMeetingContents = item.ClassMeetingContents;
|
|||
|
|
//model.States = item.States;
|
|||
|
|
model.States = BLL.Const.State_2; ;//分包推送过来的班前会数据默认已完成
|
|||
|
|
model.MeetingPlace = item.MeetingPlace;
|
|||
|
|
model.MeetingHours = item.MeetingHours;
|
|||
|
|
model.MeetingHostMan = item.MeetingHostMan;
|
|||
|
|
model.AttentPerson = item.AttentPerson;
|
|||
|
|
model.AttentPersonNum = item.AttentPersonNum;
|
|||
|
|
//model.MeetingHostManOther = item.MeetingHostManOther;
|
|||
|
|
//model.Remark = item.Remark;
|
|||
|
|
model.Remark = $"{(!string.IsNullOrWhiteSpace(data.ShortUnitName) ? data.ShortUnitName : data.UnitName)}#{item.CompileManName}";
|
|||
|
|
model.CompileDate = item.CompileDate;
|
|||
|
|
//newModel.CompileMan = item.CompileMan;
|
|||
|
|
|
|||
|
|
db.SubmitChanges();
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{//新增
|
|||
|
|
Model.Meeting_ClassMeeting newModel = new Model.Meeting_ClassMeeting();
|
|||
|
|
newModel.ClassMeetingId = item.ClassMeetingId;
|
|||
|
|
newModel.ProjectId = data.SubjectProject;
|
|||
|
|
newModel.UnitId = unit.UnitId;
|
|||
|
|
newModel.ClassMeetingCode = item.ClassMeetingCode;
|
|||
|
|
newModel.ClassMeetingName = item.ClassMeetingName;
|
|||
|
|
newModel.ClassMeetingDate = item.ClassMeetingDate;
|
|||
|
|
newModel.AttentPersonNum = item.AttentPersonNum;
|
|||
|
|
//newModel.TeamGroupId = item.TeamGroupId;
|
|||
|
|
newModel.TeamGroupId = APIDataShareSyncService.GetTeamGroupId(item.TeamGroupName, data.SubjectProject, unit.UnitId);
|
|||
|
|
newModel.AttentPersonNum = item.AttentPersonNum;
|
|||
|
|
//newModel.ClassMeetingContents = HttpUtility.HtmlEncode(item.ClassMeetingContents);
|
|||
|
|
newModel.ClassMeetingContents = item.ClassMeetingContents;
|
|||
|
|
//newModel.States = item.States;
|
|||
|
|
newModel.States = BLL.Const.State_2; ;//分包推送过来的班前会数据默认已完成
|
|||
|
|
newModel.MeetingPlace = item.MeetingPlace;
|
|||
|
|
newModel.MeetingHours = item.MeetingHours;
|
|||
|
|
newModel.MeetingHostMan = item.MeetingHostMan;
|
|||
|
|
newModel.AttentPerson = item.AttentPerson;
|
|||
|
|
newModel.AttentPersonNum = item.AttentPersonNum;
|
|||
|
|
//newModel.MeetingHostManOther = item.MeetingHostManOther;
|
|||
|
|
//newModel.Remark = item.Remark;
|
|||
|
|
newModel.Remark = $"{(!string.IsNullOrWhiteSpace(data.ShortUnitName) ? data.ShortUnitName : data.UnitName)}#{item.CompileManName}";
|
|||
|
|
newModel.CompileDate = item.CompileDate;
|
|||
|
|
//newModel.CompileMan = item.CompileMan;
|
|||
|
|
|
|||
|
|
db.Meeting_ClassMeeting.InsertOnSubmit(newModel);
|
|||
|
|
db.SubmitChanges();
|
|||
|
|
}
|
|||
|
|
succ++;
|
|||
|
|
//附件处理:内容附件
|
|||
|
|
BLL.FileInsertService.SaveAttachFileRecords(data.UnitDomain, item.AttachFileId, item.ToKeyId, item.AttachSource, item.AttachUrl);
|
|||
|
|
//附件处理:签到表
|
|||
|
|
BLL.FileInsertService.SaveAttachFileRecords(data.UnitDomain, item.AttachFileId1, item.ToKeyId1, item.AttachSource1, item.AttachUrl1);
|
|||
|
|
//附件处理:会议过程
|
|||
|
|
BLL.FileInsertService.SaveAttachFileRecords(data.UnitDomain, item.AttachFileId2, item.ToKeyId2, item.AttachSource2, item.AttachUrl2);
|
|||
|
|
}
|
|||
|
|
catch (Exception ex)
|
|||
|
|
{
|
|||
|
|
BLL.ErrLogInfo.WriteLog($"【{porject.ProjectName}】班前会数据推送总包失败", ex.Message);
|
|||
|
|
continue;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
result = $"推送成功:总数{data.Items.Count()}条,成功{succ}条";
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
result = "推送数据对象为空!";
|
|||
|
|
}
|
|||
|
|
return result;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
#endregion
|
|||
|
|
}
|
|||
|
|
}
|