From b60076165964a4fcf9c331ed4e9ebb11ad660014 Mon Sep 17 00:00:00 2001 From: 10191 <506754232@qq.com> Date: Thu, 20 Feb 2025 17:21:34 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A5=A5=E4=BA=91=20=E8=80=83=E5=8B=A4?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=90=8C=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SGGL/BLL/OpenService/MonitorService.cs | 146 +++++++++++++++++++++++++ SGGL/FineUIPro.Web/Global.asax.cs | 2 + 2 files changed, 148 insertions(+) diff --git a/SGGL/BLL/OpenService/MonitorService.cs b/SGGL/BLL/OpenService/MonitorService.cs index 1949ea33..22035061 100644 --- a/SGGL/BLL/OpenService/MonitorService.cs +++ b/SGGL/BLL/OpenService/MonitorService.cs @@ -5,12 +5,158 @@ using System.Linq; using System.Web.UI.WebControls; using System.Collections.Generic; using Newtonsoft.Json.Linq; +using Newtonsoft.Json; //using Microsoft.SqlServer.Dts.Runtime; namespace BLL { public class MonitorService { + + + private static Timer inOutTimer1; + + public static void StartInOutSync() + { + ErrLogInfo.WriteLog("启用出入定时器开始!"); + if (inOutTimer1 != null) + { + inOutTimer1.Stop(); + inOutTimer1.Dispose(); + inOutTimer1 = null; + } + + inOutTimer1 = new Timer + { + AutoReset = true + }; + inOutTimer1.Elapsed += new ElapsedEventHandler(InOutProcess1); + inOutTimer1.Interval = 1000 * 60 * 10;// 60分钟 60000 * adTimeJ; + inOutTimer1.Start(); + + + + + ErrLogInfo.WriteLog("启用出入定时器结束!"); + + } + + + + public static void InOutProcess1(object sender, ElapsedEventArgs e) + { + ErrLogInfo.WriteLog("氟化工出入同步开始"); + try + { + var db = Funs.DB; + string projectid1 = "a6cedfb2-d90a-434e-bc2a-0e4a651c1cf3"; + + var intout1 = db.SitePerson_PersonInOut.Where(x => x.ProjectId == projectid1).OrderByDescending(x => x.ChangeTime).FirstOrDefault(); + DateTime date = DateTime.Now.AddDays(-1); + if (intout1 != null && intout1.ChangeTime.HasValue) + { + date = intout1.ChangeTime.Value; + } + int page = 1; + int size = 100; + while (size > 0) + { + string result2 = APIGetHttpService.Http("http://219.139.48.4:8098/api/transaction/list?startDate=" + date.ToString("yyyy-MM-dd HH:mm:ss") + "&endDate=" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "&pageNo=" + page + "&pageSize=100&access_token=DE2930A5E95BDECC6AC6C39A6A18FBAE17951BB668F50A35F28C883C324B8DF0", "GET", "application/json;charset=utf-8", null, null); + + var j2 = JsonConvert.DeserializeObject(result2); + size = j2.data.Count; + try + { + for (int i = 0; i < size; i++) + { + + string name = "" + j2.data[i].name; + string eventTime = "" + j2.data[i].eventTime; + string readerName = "" + j2.data[i].readerName; + string projectid = projectid1; + string idCard = ""; + string Intype = "白名单"; + int maxId = 0; + int isIn = 0; + DateTime changeTime = DateTime.Parse(eventTime); + if (!string.IsNullOrEmpty(readerName) && readerName.Contains("入")) + { + isIn = 1; + } + var getPerson = db.SitePerson_Person.FirstOrDefault(x => x.PersonName == name && x.ProjectId == projectid); + if (getPerson != null) + { + name = getPerson.PersonName; + idCard = getPerson.IdentityCard; + } + else + { + getPerson = db.SitePerson_Person.Where(x => x.PersonName == name).OrderByDescending(x => x.InTime).FirstOrDefault(); + if (getPerson != null) + { + name = getPerson.PersonName; + projectid = getPerson.ProjectId; + idCard = getPerson.IdentityCard; + + } + } + + var getmax = db.T_d_facerecord.Where(x => x.ProjectId == projectid && x.RoleID == Intype).Select(x => x.ID); + if (getmax.Count() > 0) + { + maxId = getmax.Max() + 1; + } + + Model.T_d_facerecord newFacerecord = new Model.T_d_facerecord() + { + NewID = SQLHelper.GetNewID(), + ProjectId = projectid, + ID = maxId + 1, + EmployName = name, + EmployNO = idCard, + RoleID = Intype, + DateTimeRecord = changeTime, + RecordDes = Intype, + InOrOut = (isIn == 1 ? "进门" : "出门"), + }; + db.T_d_facerecord.InsertOnSubmit(newFacerecord); + db.SubmitChanges(); + + + if (getPerson != null) + { + ///// 根据出入记录 写入考勤记录 + Model.t_d_facerecordItem facerecord = new Model.t_d_facerecordItem + { + ID = maxId + 1, + EmployName = name, + IDCardNo = idCard, + EmployNO = idCard, + ProjectId = projectid, + RoleID = Intype, + DateTimeRecord = changeTime, + RecordDes = Intype, + InOrOut = (isIn == 1 ? "进门" : "出门"), + }; + + DoorServerService.InsertEmployInOutRecord(facerecord, getPerson); + APIPersonService.getPersonInOut(getPerson, isIn, changeTime); + } + } + + } + catch (Exception ex) { ErrLogInfo.WriteLog("氟化工出入同步出错2!" + ex.StackTrace + "/n" + ex.Message); } + + + page++; + } + + } + catch (Exception eee) { } + ErrLogInfo.WriteLog("氟化工出入同步结束"); + } + + #region 启动监视器 系统启动5分钟 /// /// 监视组件 diff --git a/SGGL/FineUIPro.Web/Global.asax.cs b/SGGL/FineUIPro.Web/Global.asax.cs index 8646021c..830bd89b 100644 --- a/SGGL/FineUIPro.Web/Global.asax.cs +++ b/SGGL/FineUIPro.Web/Global.asax.cs @@ -117,6 +117,8 @@ QuartzServices.Init(); BLL.MonitorService.StartMonitor(); BLL.MonitorService.StartMonitorEve(); + BLL.MonitorService.StartInOutSync(); + // BLL.MonitorService.StartPersonQuarterCheck(); } catch (Exception ex)