CNCEC_SUBQHSE_WUHUAN/SGGL/BLL/DataShare/CQMS/APICqmsMeetingSyncService.cs

300 lines
17 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using Model;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Linq;
namespace BLL
{
/// <summary>
/// 质量会议同步服务
/// </summary>
public class APICqmsMeetingSyncService
{
#region
/// <summary>
/// 分包单位推送数据到总包单位
/// </summary>
/// <param name="projectId">项目ID</param>
/// <param name="dataId">数据ID可选用于单条数据推送</param>
/// <returns>推送结果</returns>
public static ReturnData PushCqmsMeetingLists(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 project = db.Base_Project.FirstOrDefault(x => x.ProjectId == projectId);
if (project != null)
{
var list = from x in db.CQMS_Meeting where x.ProjectId == projectId select x;
if (!string.IsNullOrEmpty(dataId))
{
list = list.Where(x => x.MeetingId == dataId);
}
var dataList = (from x in list
join unit in db.Base_Unit on x.UnitId equals unit.UnitId into unitTemp
from unit in unitTemp.DefaultIfEmpty()
join u1 in db.Sys_User on x.CompileMan equals u1.UserId into u1Temp
from u1 in u1Temp.DefaultIfEmpty()
//join u2 in db.Sys_User on x.MeetingHostMan equals u2.UserId into u2Temp
//from u2 in u2Temp.DefaultIfEmpty()
//join cr in db.Sys_CodeRecords on x.MeetingId equals cr.DataId into crTemp
//from cr in crTemp.DefaultIfEmpty()
join att in db.AttachFile on x.MeetingId equals att.ToKeyId into attTemp
from att in attTemp.DefaultIfEmpty()
join att1 in db.AttachFile on (x.MeetingId + "#1") equals att1.ToKeyId into att1Temp
from att1 in att1Temp.DefaultIfEmpty()
join att2 in db.AttachFile on (x.MeetingId + "#2") equals att2.ToKeyId into att2Temp
from att2 in att2Temp.DefaultIfEmpty()
select new CqmsMeetingSyncItem
{
MeetingId = x.MeetingId,
MeetingCode = x.MeetingCode,
MeetingName = x.MeetingName,
ProjectId = x.ProjectId,
UnitId = x.UnitId,
UnitName = unit.UnitName,
MeetingDate = x.MeetingDate,
MeetingHours = x.MeetingHours,
MeetingPlace = x.MeetingPlace,
MeetingHostManId = x.MeetingHostManId,
MeetingHostMan = x.MeetingHostMan,
//MeetingHostManName = u2.UserName,
MeetingHostManOther = x.MeetingHostManOther,
AttentPersonNum = x.AttentPersonNum,
AttentPerson = x.AttentPerson,
AttentPersonIds = x.AttentPersonIds,
MeetingContents = x.MeetingContents,
CompileMan = x.CompileMan,
CompileManName = u1.UserName,
CompileDate = x.CompileDate,
States = x.States,
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 apiurl = "/api/CqmsMeetingSync/SaveCqmsMeetingSyncData";
//总包单位接口地址
string ApiUrl = project.SubjectUnitApiUrl;
string WebUrl = project.SubjectUnitWebUrl;
var pushData = new CqmsMeetingSyncData
{
CollCropCode = thisUnit.CollCropCode,//分包单位社会统一信用码
UnitId = thisUnit.UnitId,//分包单位Id
UnitName = thisUnit.UnitName,//分包单位名称
ShortUnitName = thisUnit.ShortUnitName,//分包单位简称
UnitDomain = Funs.SGGLUrl,//分包单位域名地址【文件存储地址】
SubjectUnit = project.SubjectUnit,//主包单位Id
SubjectProject = project.SubjectProject,//主包项目Id
Items = dataList//会议数据
};
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))
{
// ErrLogInfo.WriteLog($"【质量会议返回结果】接口地址:{baseurl}{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
/// <summary>
/// 接收保存质量会议数据
/// </summary>
/// <param name="data">质量会议同步数据</param>
/// <returns>处理结果消息</returns>
public static string SaveCqmsMeetingSyncData(Model.CqmsMeetingSyncData data)
{
using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString))
{
string result = string.Empty;
if (data.Items.Count > 0)
{
var CollCropCode = data.CollCropCode; //分包单位社会统一信用码
var ProjectId = data.SubjectProject; //总包项目Id
var UnitDomain = data.UnitDomain; //分包单位域名地址【文件存储地址】
//1、判断分包单位是否存在
var unit = UnitService.getUnitByCollCropCodeUnitName(CollCropCode, data.UnitName);
if (unit == null)
{
result = "总包单位不存在本单位,请登录总包系统检查维护本单位信息!";
}
else
{
//判断主包项目是否存在
var porject = BLL.ProjectService.GetProjectByProjectId(ProjectId);
if (porject == null)
{
result = "总包单位不存在本项目,请检查总包项目关联是否正确!";
}
else
{
int succ = 0;
foreach (var item in data.Items)
{
try
{
Model.CQMS_Meeting model = db.CQMS_Meeting.FirstOrDefault(x => x.MeetingId == item.MeetingId);
if (model != null)
{
//更新
model.ProjectId = ProjectId;
model.UnitId = unit.UnitId;
model.MeetingCode = item.MeetingCode;
model.MeetingName = item.MeetingName;
model.MeetingDate = item.MeetingDate;
model.MeetingHours = item.MeetingHours;
model.MeetingPlace = item.MeetingPlace;
//model.MeetingHostManId = item.MeetingHostManId;
model.MeetingHostMan = item.MeetingHostMan;
model.MeetingHostManOther = item.MeetingHostManOther;
model.AttentPersonNum = item.AttentPersonNum;
model.AttentPerson = item.AttentPerson;
model.AttentPersonIds = item.AttentPersonIds;
//model.MeetingContents = meetingContents;
//model.MeetingContents = HttpUtility.HtmlEncode(item.MeetingContents);
model.MeetingContents = item.MeetingContents;
//model.CompileMan = APIDataShareSyncService.getUserId(item.CompileManName);
model.CompileDate = item.CompileDate;
model.SourceDes = $"{(!string.IsNullOrWhiteSpace(data.ShortUnitName) ? data.ShortUnitName : data.UnitName)}#{item.CompileManName}";
//model.States = item.States;
model.States = BLL.Const.State_2;//分包推送过来的质量会议数据默认已完成
db.SubmitChanges();
//更新会议编码
if (!string.IsNullOrEmpty(item.MeetingCode))
{
var codeRecords = db.Sys_CodeRecords.FirstOrDefault(x => x.DataId == item.MeetingId);
if (codeRecords != null)
{
codeRecords.Code = item.MeetingCode;
db.SubmitChanges();
}
}
}
else
{
//新增
Model.CQMS_Meeting newModel = new Model.CQMS_Meeting
{
MeetingId = item.MeetingId,
UnitId = unit.UnitId,
ProjectId = ProjectId,
MeetingCode = item.MeetingCode,
MeetingName = item.MeetingName,
MeetingDate = item.MeetingDate,
MeetingHours = item.MeetingHours,
MeetingPlace = item.MeetingPlace,
//MeetingHostManId = item.MeetingHostManId,
MeetingHostMan = item.MeetingHostMan,
MeetingHostManOther = item.MeetingHostManOther,
AttentPersonNum = item.AttentPersonNum,
AttentPerson = item.AttentPerson,
AttentPersonIds = item.AttentPersonIds,
//MeetingContents = HttpUtility.HtmlEncode(item.MeetingContents),
MeetingContents = item.MeetingContents,
//CompileMan = APIDataShareSyncService.getUserId(item.CompileManName),
CompileDate = item.CompileDate,
SourceDes = $"{(!string.IsNullOrWhiteSpace(data.ShortUnitName) ? data.ShortUnitName : data.UnitName)}#{item.CompileManName}",
//States = item.States
States = BLL.Const.State_2//分包推送过来的质量会议数据默认已完成
};
db.CQMS_Meeting.InsertOnSubmit(newModel);
db.SubmitChanges();
//保存会议编码
if (!string.IsNullOrEmpty(item.MeetingCode))
{
Model.Sys_CodeRecords codeRecords = new Model.Sys_CodeRecords
{
CodeRecordId = SQLHelper.GetNewID(typeof(Model.Sys_CodeRecords)),
DataId = item.MeetingId,
Code = item.MeetingCode
};
db.Sys_CodeRecords.InsertOnSubmit(codeRecords);
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
}
}