using Cksoft.Data; using Cksoft.Data.Repository; using Cksoft.Unity; using Cksoft.Unity.Log4NetConfig; using DllEapCommon.Notice; using DllEapEntity; using DllEapEntity.Dtos; using DllEapEntity.OFILM; using Microsoft.Extensions.Logging; using Newtonsoft.Json; using Newtonsoft.Json.Schema; using SharpCifs.Util.Sharpen; using System; using System.Collections.Generic; using System.Data; using System.Diagnostics; using System.Linq; using System.Text; using System.Threading.Tasks; namespace DllEapDal.OFILM { /// /// BI系统数据推送 /// public class BICollectDal { private IDatabase CurrDb = null; public BICollectDal(IDatabase db) { CurrDb = db; } public BICollectDal() { } /// /// 获取未推送到BI的报警数据 /// /// private IEnumerable GetAlarms() { string sql = $@"select a.Id,f.FCode as Manufacturer,a.EventCode, b.RegionId,b.FactoryId,g.Factory, a.AlarmCode,a.AlarmDesc,a.McaCode,b.FName as McaName, e.FName as MacModelName,a.StartTime,a.EndTime,a.TimeSpan,a.IsInProducing,a.IsHandled, e.FCode as MacModel,e.SoftVersion,c.PCode,d.FName as PName,b.IpAddress from McaEventStatisticByDay a left join Machine b on a.McaCode=b.FCode left join MacTProcess c on b.id=c.MacID left join TProcess d on c.PCode=d.FCode left join MacModel e on b.MModeId=e.id left join Supplier f on e.SupplierId=f.id left join FactoryRegion g on b.FactoryId=g.id " + $" where 1=1 and a.EventCode='C00007' and a.IsBICollect=0 "; return CurrDb.FindList(sql); } /// /// 获取当前关机的机台 /// /// private IEnumerable GetShutdownConnMacs(IDatabase db) { var sql = "select * from macstatus where statusid=204906"; return db.FindList(sql); } /// /// 获取机台状态 /// /// private IEnumerable GetMacStatuses(DateTime dateStart, ref string errorinfo) { string sql = $@"select a.*,d.FName as Supplier,b.IpAddress,b.RegionId, g.FName as Factory,c.SoftVersion,f.FCode as ProcessCode,h.Project, c.FCode as MacModel,c.FName as MacModelName from macstatus a left join machine b on a.maccode=b.fcode left join macmodel c on b.mmodeid=c.id left join supplier d on c.supplierid =d.id left join MacTProcess e on b.id=e.MacID left join TProcess f on e.PCode=f.FCode left join FactoryRegion g on b.factoryId=g.Id left join projectandprogram h on {OfilmRecipeProvider.GenRecipeString("a")} = h.Recipe where (a.etime>='{dateStart}' or a.etime='0001-01-01 00:00:00') "; return CurrDb.FindList(sql); } /// /// 获取产量数据 /// /// private IEnumerable GetOutputDatas(DateTime start, DateTime end, IDatabase db) { string sql = $@"select a.fcount as count,e.fcode as pcode,e.fname as pname,f.fcode as macmodel, f.fname as macmodelname,c.fcode as code,c.fname as name, b.timelen as TimeLen,a.Id as DetailId,b.EDate as Fdate, {OfilmRecipeProvider.GenRecipeString("b", "pName")} programName, g.fName as factory,h.FName as line,i.FName as floor,k.FName Plant, e.fCode Work_Process,f.FCode Dev_Type,j.Project from maccountdetail a left join maccountmst b on a.mstid=b.id left join machine c on b.macid=c.id left join mactprocess d on c.id=d.macid left join tprocess e on d.pcode=e.fcode left join macmodel f on c.mmodeid=f.id left join factoryregion g on c.FactoryId = g.id left join factoryregion h on c.RegionId=h.id left join factoryregion i on h.ParentId=i.id left join factoryregion k on i.ParentId=k.id left join projectandprogram j on j.Recipe = {OfilmRecipeProvider.GenRecipeString("b", "PName")} where a.typeid=0 and b.EDate>'{start.ToString("yyyy-MM-dd HH:mm:ss")}' and b.EDate<='{end.ToString("yyyy-MM-dd HH:mm:ss")}' and a.paramcode='{DllHsms.StandardCode.SVID_FinishUnit}' "; return db.FindList(sql); } /// /// 推送机台状态信息 /// /// /// public int CollectMacStatus(ref string errorinfo) { var lastHistory = CurrDb.FindListForCondition($" " + $"and a.Type=1 and a.Status=1 order by fdate desc", ref errorinfo).FirstOrDefault(); DateTime dateStart; if (lastHistory == null) { dateStart = Convert.ToDateTime("2020-08-25 17:00:00"); } else { dateStart = lastHistory.FDate; } Stopwatch watch = new Stopwatch(); watch.Start(); var statuses = this.GetMacStatuses(dateStart, ref errorinfo).OrderBy(c => c.RecTime); long ticks = watch.ElapsedMilliseconds; watch.Reset(); watch.Restart(); DateTime now = DateTime.Now; var biStatuses = new List(); var regionDal = new FactoryRegionDal(CurrDb); var ids = new List(); var machines = CurrDb.FindListForCondition(string.Empty, ref errorinfo); var allRegions = regionDal.Get(1, 10000, "ID", "asc", string.Empty, errorinfo); foreach (var item in machines) { var floor = string.Empty; var line = string.Empty; // 获取楼层及产线 if (item.RegionId != 0) { var fullRegionName = regionDal.GetFullRegionName(item.RegionId, allRegions); var arr = fullRegionName.Split('/'); if (arr.Count() == 2) { floor = arr[1]; } else if (arr.Count() == 3) { floor = arr[1]; line = arr[2]; } item.Floor = floor; item.Line = line; } } if (statuses != null && statuses.Count() > 0) { foreach (var item in statuses) { var mac = machines.FirstOrDefault(c => c.FCode.ToUpper() == item.MacCode.ToUpper()); if (mac == null) { continue; } var recipe = ""; if (item.Remark != null) { recipe = item.Remark.Split(new char[] { '-', '_', ' ' }, StringSplitOptions.RemoveEmptyEntries)[0]; } var status = 5; #region 将EAP的状态码转换为BI大数据通用状态码 if (item.StatusID == 1) // 未连接 { status = 1; } else if (item.StatusID == 2) // 准备 { status = 33; } else if (item.StatusID == 3) // 空闲 { status = 2049; } else if (item.StatusID == 4) // 运行 { status = 3; } else if (item.StatusID == 6) { status = 5; } else if (item.StatusID == 204906) { status = 2; } else { status = item.StatusID; } #endregion var fdate = now; if (item.ETime.ToString("yyyy-MM-dd HH:mm:ss") == "0001-01-01 00:00:00") { if (item.STime >= dateStart) { fdate = item.STime; } else { fdate = dateStart; } } else { if (item.STime >= dateStart) { fdate = item.STime; } else { fdate = dateStart; } } var entity = new BIMachineStatus { Description = item.AlarmDescribe == "报警解除" ? "" : item.AlarmDescribe, Device_Code = item.MacCode, Dev_IP = item.IpAddress, Dev_Type = item.MacModelName, Status_Code = item.AlarmCode, Factory = item.Factory, FDate = fdate, Floor = mac.Floor, Line = mac.Line, Recipe = recipe, Status = status, Version = item.SoftVersion, Work_Process = item.ProcessCode, Project = item.Project ?? "异常" }; biStatuses.Add(entity); ids.Add(item.ID); } watch.Stop(); long t2 = watch.ElapsedMilliseconds; long count = statuses.Count(); watch.Reset(); watch.Restart(); var sb = new StringBuilder("insert into BIMachineStatus (Device_Code,FDate,Status,Status_Code,Description," + "Factory,Floor,Project,Recipe,Work_Process,Dev_Type,Line,Version," + "Dev_IP) Values"); foreach (var item in biStatuses) { sb.Append($@"('{item.Device_Code}','{item.FDate}','{item.Status}','{item.Status_Code}', '{item.Description}','{item.Factory}','{item.Floor}','{item.Project}','{item.Recipe}', '{item.Work_Process}','{item.Dev_Type}','{item.Line}','{item.Version}','{item.Dev_IP}'),"); } sb.Remove(sb.Length - 1, 1); sb.Append(";"); if (CurrDb.ExecuteBySql(sb.ToString()) < 0) { errorinfo = "数据汇总失败"; return -1; } watch.Stop(); long t3 = watch.ElapsedMilliseconds; var history = new BIHistory { FDate = now, Status = 1, Type = 1 }; CurrDb.InsertFor(history, string.Empty); } return 1; } /// /// 推送机台 /// /// /// public int CollectOutput(int delay, ref string errorinfo) { var now = DateTime.Now.AddMinutes(-delay); var lastPushDate = CurrDb.FindListForCondition(" and 1=1 order by id desc limit 0,1", ref errorinfo).FirstOrDefault(); var lastTime = now.AddMinutes(-10); if (lastPushDate != null && lastPushDate.FDate > now.AddHours(-5)) { lastTime = lastPushDate.FDate; } //lastTime = now.AddMinutes(-30); var times = Math.Floor((now - lastTime).TotalMinutes / 10); for (int i = 0; i < times; i++) { var start = lastTime.AddMinutes(i * 10); var end = start.AddMinutes(10); using (IDatabase db = DbFactory.Base("eap")) { var shutdownMacs = this.GetShutdownConnMacs(db); var datas = this.GetOutputDatas(start, end, db); if (datas != null && datas.Count() > 0) { var macRecipeGroups = datas.GroupBy(c => new { c.Code, c.ProgramName }); var list = new List(); foreach (var item in macRecipeGroups) { var entity = new BIOutput { All_Product = item.Sum(c => c.Count), Device_Code = item.Key.Code, FDate = end, Goods = item.Sum(c => c.Count), Recipe = item.Key.ProgramName, Factory = item.FirstOrDefault().Factory, Plant = item.FirstOrDefault()?.Plant, Floor = item.FirstOrDefault().Floor, Line = item.FirstOrDefault().Line, Project = item.FirstOrDefault().Project, Dev_Type = item.FirstOrDefault().Dev_Type, Work_Process = item.FirstOrDefault().Work_Process }; list.Add(entity); } if (list != null && list.Count > 0) { foreach (var item in list) { if (string.IsNullOrEmpty(item.Device_Code) || item.Device_Code.Length != 7) { continue; } var status = db.FindListForCondition($" and a.maccode='{item.Device_Code}' order by id desc", ref errorinfo).FirstOrDefault(); if (status != null && (status.StatusID == 1 || status.StatusID == 204906) && item.Goods == 0) { continue; } CallEESServiceOutput(item); } } var pushHistory = new BIHistory { FDate = end, Type = 1 }; if (db.InsertFor(pushHistory, string.Empty) < 0) { errorinfo = "新增推送历史失败"; continue; } //} } } } return 1; } /// /// 推送产量数据到BI接口 /// /// private void CallEESServiceOutput(BIOutput bIOutput) { string errorinfo = string.Empty; EES.EESDeviceReportServiceClient client = null; try { client = new EES.EESDeviceReportServiceClient(); var str = JsonConvert.SerializeObject(bIOutput, new JsonSerializerSettings { DateFormatString = "yyyy-MM-dd HH:mm:ss" }); var res = client.eesProductSumReport(str); if (!string.IsNullOrEmpty(res)) { var dictionary = JsonConvert.DeserializeObject>(res); if (dictionary != null && dictionary.ContainsKey("resultCode") && dictionary["resultCode"] == "OK") { LogHelper.LogError($"推送产量BI数据成功-->{JsonConvert.SerializeObject(bIOutput)}", "BI大数据", string.Empty); } else { var msg = dictionary.ContainsKey("msg") ? dictionary["msg"] : "推送失败"; var content = $"推送BI数据失败[{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}],异常为:{msg}"; ServiceErrorNoticeHelper.Notice(content, ref errorinfo); LogHelper.LogError($"推送BI产量数据成功-->{JsonConvert.SerializeObject(bIOutput)}", "BI大数据", string.Empty); } } } catch (Exception ex) { var content = $"推送BI数据失败[{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}],异常为:{ex.Message}"; ServiceErrorNoticeHelper.Notice(content, ref errorinfo); LogHelper.LogError($"推送BI产量数据失败-->{ex.ToString()}", "BI大数据", string.Empty); } finally { client.CloseAsync(); } } /// /// 将机台状态转换成BI接口接收的实体并调用接口推送 /// /// /// public void PushStatusToBI(IEnumerable macStatuses, string errorinfo) { Task.Run(() => { if (macStatuses != null && macStatuses.Count() > 0) { var list = new List(); foreach (var macStatus in macStatuses) { var recipe = string.Empty; if (!string.IsNullOrEmpty(macStatus.Remark)) { recipe = macStatus.Remark.Replace(".", "-").Replace("_", "-").Replace(" ", "-").Split("-")?[0]; } var sql = $@"select a.FCode Device_Code,a.IpAddress Dev_IP,b.FCode Dev_Type,b.SoftVersion Version, c.FCode Work_Process,d.FName Factory,e.FName Floor,f.FName Line,h.FName Plant from Machine a left join MacModel b on a.MModeID=b.Id left join MacTProcess g on a.id=g.macid left join TProcess c on g.PCode=c.FCode left join FactoryRegion d on a.FactoryId=d.id left join FactoryRegion f on a.RegionId=f.id left join FactoryRegion e on f.ParentId=e.id left join FactoryRegion h on e.ParentId=h.id where a.FCode='{macStatus.MacCode}'"; var biStatus = CurrDb.FindList(sql).FirstOrDefault(); var project = "未维护"; if (!string.IsNullOrEmpty(recipe)) { sql = $"select project from projectandprogram where recipe='{recipe}'"; project = CurrDb.FindList(sql).FirstOrDefault() ?? "未维护"; } biStatus.Recipe = recipe; // biStatus.Status = macStatus.StatusID; biStatus.Status_Code = macStatus.AlarmCode; biStatus.Description = macStatus.AlarmDescribe; biStatus.Project = project; var standard = CurrDb.FindListForCondition($" and a.StatusVal={macStatus.StatusID}", ref errorinfo) .FirstOrDefault(); var status = 1; #region 将EAP的状态码转换为BI大数据通用状态码 if (macStatus.StatusID == 1) // 未连接 { status = 1; } else if (macStatus.StatusID == 4) // 运行 { status = 3; } else if (macStatus.StatusID == 6) { if (string.IsNullOrEmpty(macStatus.AlarmDescribe)) { biStatus.Description = "故障"; biStatus.Status_Code = "0"; } status = 5; } else if (macStatus.StatusID == 204906) { status = 2; } else if (macStatus.StatusID == 3 || macStatus.StatusID == 10 || (macStatus.StatusID > 200000 && macStatus.StatusID != 204906)) // 空闲 { status = 2049; biStatus.Status_Code = macStatus.StatusID.ToString(); if (macStatus.StatusID == 204907) { biStatus.Status_Code = "204906"; } else if (macStatus.StatusID == 204908) { biStatus.Status_Code = "204907"; } else if (macStatus.StatusID == 204999) { biStatus.Status_Code = "204908"; } biStatus.Description = standard.FName; if (macStatus.StatusID == 3) { biStatus.Status_Code = "0"; } } else { status = 2049; biStatus.Status_Code = "204908"; biStatus.Description = "其他"; } #endregion biStatus.Status = status; biStatus.FDate = macStatus.STime; if (biStatus.Status != 2049 && biStatus.Status != 5) { biStatus.Status_Code = "0"; biStatus.Description = standard.FName; } if (biStatus.Description == "运行") biStatus.Description = "稼动"; if (biStatus.Description == "空闲") biStatus.Description = "待机"; list.Add(biStatus); } CallEESServiceMacStatus(list); } }); } public async Task PushStatusToBIBatch(IEnumerable macStatuses, string errorinfo) { if (macStatuses != null && macStatuses.Count() > 0) { var list = new List(); foreach (var macStatus in macStatuses) { var recipe = string.Empty; if (!string.IsNullOrEmpty(macStatus.Remark)) { recipe = macStatus.Remark.Replace(".", "-").Replace("_", "-").Replace(" ", "-").Split("-")?[0]; } var sql = $@"select a.FCode Device_Code,a.IpAddress Dev_IP,b.FCode Dev_Type,b.SoftVersion Version, c.FCode Work_Process,d.FName Factory,e.FName Floor,f.FName Line,h.FName Plant from Machine a left join MacModel b on a.MModeID=b.Id left join MacTProcess g on a.id=g.macid left join TProcess c on g.PCode=c.FCode left join FactoryRegion d on a.FactoryId=d.id left join FactoryRegion f on a.RegionId=f.id left join FactoryRegion e on f.ParentId=e.id left join FactoryRegion h on e.ParentId=h.id where a.FCode='{macStatus.MacCode}'"; var biStatus = CurrDb.FindList(sql).FirstOrDefault(); if (biStatus == null) continue; var project = "未维护"; if (!string.IsNullOrEmpty(recipe)) { sql = $"select project from projectandprogram where recipe='{recipe}'"; project = CurrDb.FindList(sql).FirstOrDefault() ?? "未维护"; } biStatus.Recipe = recipe; // biStatus.Status = macStatus.StatusID; biStatus.Status_Code = macStatus.AlarmCode; biStatus.Description = macStatus.AlarmDescribe; biStatus.Project = project; var standard = CurrDb.FindListForCondition($" and a.StatusVal={macStatus.StatusID}", ref errorinfo) .FirstOrDefault(); var status = 1; #region 将EAP的状态码转换为BI大数据通用状态码 if (macStatus.StatusID == 1) // 未连接 { status = 1; } else if (macStatus.StatusID == 4) // 运行 { status = 3; } else if (macStatus.StatusID == 6) { if (string.IsNullOrEmpty(macStatus.AlarmDescribe)) { biStatus.Description = "故障"; biStatus.Status_Code = "0"; } status = 5; if (macStatus.AlarmCode == "SVID") { status = 2049; biStatus.Status_Code = "0"; biStatus.Description = "空闲"; } } else if (macStatus.StatusID == 204906) { status = 2; } else if (macStatus.StatusID == 3 || macStatus.StatusID == 10 || (macStatus.StatusID > 200000 && macStatus.StatusID != 204906)) // 空闲 { status = 2049; biStatus.Status_Code = macStatus.StatusID.ToString(); if (macStatus.StatusID == 204907) { biStatus.Status_Code = "204906"; } else if (macStatus.StatusID == 204908) { biStatus.Status_Code = "204907"; } else if (macStatus.StatusID == 204999) { biStatus.Status_Code = "204908"; } biStatus.Description = standard.FName; if (macStatus.StatusID == 3) { biStatus.Status_Code = "0"; } } else { status = 2049; biStatus.Status_Code = "204908"; biStatus.Description = "其他"; } #endregion biStatus.Status = status; biStatus.FDate = macStatus.STime; if (biStatus.Status != 2049 && biStatus.Status != 5) { biStatus.Status_Code = "0"; biStatus.Description = standard.FName; } if (biStatus.Description == "运行") biStatus.Description = "稼动"; if (biStatus.Description == "空闲") biStatus.Description = "待机"; list.Add(biStatus); } await CallEESServiceMacStatusBatch(list); } } /// /// 推送机台状态到BI接口 /// /// private async Task CallEESServiceMacStatus(IEnumerable bIMachineStatus) { EES.EESDeviceReportServiceClient client = null; var str = JsonConvert.SerializeObject(bIMachineStatus.First(), new JsonSerializerSettings { DateFormatString = "yyyy-MM-dd HH:mm:ss" }); try { client = new EES.EESDeviceReportServiceClient(); var body = await client.eesDeviceStatusReportAsync(str); // var body = client.eesDeviceStatusReport(str); var res = body.Body.@return; if (!string.IsNullOrEmpty(res)) { var dictionary = JsonConvert.DeserializeObject>(res); if (dictionary != null && dictionary.ContainsKey("resultCode") && dictionary["resultCode"] == "OK") { LogHelper.LogError($"推送BI数据成功-->{JsonConvert.SerializeObject(bIMachineStatus)}", "BI大数据", string.Empty); } else { var msg = dictionary.ContainsKey("msg") ? dictionary["msg"] : "推送失败"; LogHelper.LogError($"推送BI数据失败-->{msg}", "BI大数据", string.Empty); using (IDatabase eapDb = DbFactory.Base("eap")) { if (CurrDb.InsertFor(bIMachineStatus.First(), string.Empty) < 0) { LogHelper.LogError($"保存推送失败数据错误-->{str}", "BI大数据", string.Empty); } else { LogHelper.LogError($"保存推送失败数据成功-->{str}", "BI大数据", string.Empty); } } } } else { LogHelper.LogError($"推送BI数据失败-->接口返回NULL", "BI大数据", string.Empty); using (IDatabase eapDb = DbFactory.Base("eap")) { if (CurrDb.InsertFor(bIMachineStatus.First(), string.Empty) < 0) { LogHelper.LogError($"保存推送失败数据错误-->{str}", "BI大数据", string.Empty); } else { LogHelper.LogError($"保存推送失败数据成功-->{str}", "BI大数据", string.Empty); } } } } catch (Exception ex) { LogHelper.LogError($"推送BI数据失败-->{ex.Message}", "BI大数据", string.Empty); using (IDatabase eapDb = DbFactory.Base("eap")) { if (CurrDb.InsertFor(bIMachineStatus.First(), string.Empty) < 0) { LogHelper.LogError($"保存推送失败数据错误-->{str}", "BI大数据", string.Empty); } else { LogHelper.LogError($"保存推送失败数据成功-->{str}", "BI大数据", string.Empty); } } } finally { await client.CloseAsync(); } } private DataTable GetMesMacID(string maccode, ref string errorinfo) { IDatabase db = null; try { db = DbFactory.Base("ofilmoracle"); //string sqlstr = $"select * from APPSERVER"; string sqlstr = $@"select t.EQUIPMENT_NAME from ccmmesprd.ccm_equipset_v t where t.ORG_RRN=10000 and t.EQUIPMENT_ID='{maccode}' and t.IS_ACTIVE='Y'"; DataTable dt = db.FindTable(sqlstr); return dt; } catch (Exception ex) { errorinfo = ex.ToString(); return null; } finally { if (db != null) db.Close(); } } /// /// 调用改机接口 /// /// /// public int CallQis(MacStatus status, string oldRecipe, ref string errorinfo) { try { var maccode = status.MacCode; DataTable tempdt = GetMesMacID(maccode, ref errorinfo); if (tempdt == null) { errorinfo = $"读取MES库错误:{errorinfo}"; return -1; } if (tempdt.Rows.Count <= 0) { errorinfo = $"MES库中未找到机台编号={maccode}对应的信息"; return -1; } if (string.IsNullOrEmpty(tempdt.Rows[0]["EQUIPMENT_NAME"].ToString())) { errorinfo = $"MES库中找到机台编号={maccode}对应的信息为:{tempdt.Rows[0]["EQUIPMENT_NAME"].ToString()}"; return -1; } var alarmInfo = string.Empty; var recipe = status.Remark.Replace(" ", "-").Replace("_", "-").Split("-")[0]; alarmInfo = $"{status.STime.ToString("yyyy-MM-dd HH:mm")}未来城园区一楼,生产机台编号{tempdt.Rows[0]["EQUIPMENT_NAME"].ToString()}," + $"因由{oldRecipe}机种切换到{recipe}机种自动触发停机单"; string jsonstr = "{ \"businessUnitCode\": \"751754\",\"businessUnitName\": \"未来城园区\",\"model\": \"" + recipe + "\",\"floor\": \"一楼\",\"equipmentName\": \"" + tempdt.Rows[0]["EQUIPMENT_NAME"].ToString() + "\",\"stopMachineDesc\": \"" + alarmInfo + "\",\"stopType\": \"改机首件停机\"}"; LogHelper.LogError(jsonstr, "改机", string.Empty); // var body = await client.eesDeviceStatusListReportAsync(str); Qis.ReceiveStopMachineFromMesClient clinet = new Qis.ReceiveStopMachineFromMesClient(); string result = clinet.receive(jsonstr); if (string.IsNullOrEmpty(result)) { errorinfo = $"机台编号={maccode}调用改机接口失败,未知错误......"; return -1; } var dictionary = JsonConvert.DeserializeObject>(result); if (dictionary != null && dictionary.ContainsKey("code") && dictionary["code"] == "1") { LogHelper.LogError($"调用QIS接口成功-->机台编号={maccode}", "改机", string.Empty); return 1; } else { var msg = dictionary.ContainsKey("message") ? dictionary["message"] : "调用改机失败"; LogHelper.LogError($"调用改机失败-->机台编号={maccode}", "改机", string.Empty); LogHelper.LogError(JsonConvert.SerializeObject(dictionary), "改机", string.Empty); errorinfo = msg; return -1; } } catch (Exception ex) { LogHelper.LogError($"调用改机发生异常-->{ex.ToString()}", "改机", string.Empty); errorinfo = ex.ToString(); return -1; } } private async Task CallEESServiceMacStatusBatch(IEnumerable bIMachineStatuses) { EES.EESDeviceReportServiceClient client = null; string errorinfo = string.Empty; try { client = new EES.EESDeviceReportServiceClient(); var obj = new EqpStatusDataList() { EesEqpDataList = bIMachineStatuses.ToList() }; var str = JsonConvert.SerializeObject(obj, new JsonSerializerSettings { DateFormatString = "yyyy-MM-dd HH:mm:ss" }); // var body = await client.eesDeviceStatusListReportAsync(str); var body = client.eesDeviceStatusListReport(str); var res = body; if (!string.IsNullOrEmpty(res)) { var dictionary = JsonConvert.DeserializeObject>(res); if (dictionary != null && dictionary.ContainsKey("resultCode") && dictionary["resultCode"] == "OK") { LogHelper.LogError($"推送BI数据成功-->{str}", "BI大数据", string.Empty); return true; } else { var msg = dictionary.ContainsKey("msg") ? dictionary["msg"] : "推送失败"; var content = $"推送BI状态数据失败[{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}],服务器:[{AppConfigurtaionServices.Configuration["SystemCode"]}],异常为:{msg}"; ServiceErrorNoticeHelper.Notice(content, ref errorinfo); LogHelper.LogError($"推送BI数据失败-->{msg}", "BI大数据", string.Empty); return false; } } return false; } catch (Exception ex) { LogHelper.LogError($"推送BI数据失败-->{ex.ToString()}", "BI大数据", string.Empty); var content = $"推送BI数据失败[{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}],服务器:[{AppConfigurtaionServices.Configuration["SystemCode"]}],异常为:{ex.Message}"; ServiceErrorNoticeHelper.Notice(content, ref errorinfo); return false; } finally { await client.CloseAsync(); } } public async Task PushFailedDatas(string errorifo) { var datas = CurrDb.FindListForCondition(string.Empty, ref errorifo); if (datas == null || datas.Count() <= 0) { return true; } var idArray = datas.Select(c => c.Id).ToList(); var res = await CallEESServiceMacStatusBatch(datas); if (res) { var sql = $"DELETE FROM bimachinestatus where id in ({string.Join(",", idArray)})"; if (CurrDb.ExecuteBySql(sql) < 0) { LogHelper.LogError($"更新临时表数据失败-->", "BI大数据", string.Empty); return false; } LogHelper.LogError($"更新临时表数据成功-->", "BI大数据", string.Empty); return true; } return false; } } }