From 983dd9e60d4b48e3989a2f33b3d3d31b9650ec78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E6=99=93=E5=AF=92?= <823756726@qq.com> Date: Mon, 28 Oct 2024 17:59:14 +0800 Subject: [PATCH] =?UTF-8?q?=E8=80=83=E5=8B=A4=E6=9C=BA=E6=8A=93=E5=9B=BE?= =?UTF-8?q?=E7=A8=8B=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/HKAttendanceController.cs | 49 ++++++++++++++++++- DigitalSchoolApi/Controllers/YKTController.cs | 12 ++++- .../Controllers/海康考勤机/CHCNetSDK.cs | 30 +++++++++++- 3 files changed, 87 insertions(+), 4 deletions(-) diff --git a/DigitalSchoolApi/Controllers/HKAttendanceController.cs b/DigitalSchoolApi/Controllers/HKAttendanceController.cs index 68f39f3..bd5c485 100644 --- a/DigitalSchoolApi/Controllers/HKAttendanceController.cs +++ b/DigitalSchoolApi/Controllers/HKAttendanceController.cs @@ -10,6 +10,7 @@ using System.Runtime.InteropServices; using System.Web; using AlarmCSharpDemo; using Dapper; +using Learun.Util; namespace DigitalSchoolApi.Controllers { @@ -57,7 +58,7 @@ namespace DigitalSchoolApi.Controllers { //开始自动打卡 //删除今日考勤 - connmis.Execute("delete from ADR_Record where ADYear='"+ workDateTime.Year + "' and ADMonth='" + workDateTime.Month.ToString().PadLeft(2,'0') + "' and ADDay='"+ workDateTime.Day.ToString().PadLeft(2,'0') + "' and UserNo='"+ useritem.EmpNo + "'"); + connmis.Execute("delete from ADR_Record where ADYear='" + workDateTime.Year + "' and ADMonth='" + workDateTime.Month.ToString().PadLeft(2, '0') + "' and ADDay='" + workDateTime.Day.ToString().PadLeft(2, '0') + "' and UserNo='" + useritem.EmpNo + "'"); //上午上班 ADR_RecordEntity adrRecordEntity = new ADR_RecordEntity(); adrRecordEntity.Create(); @@ -103,7 +104,7 @@ namespace DigitalSchoolApi.Controllers //adrRecordEntity.ADTime = offworkDateTime.AddMinutes(10); //adrRecordEntity.ClockTime = offworkDateTime.AddMinutes(10); //liangkun 2021-05-06 应客户要求改为下午6:00下班 - adrRecordEntity.ADTime = Convert.ToDateTime(datenow + " 18:00"); + adrRecordEntity.ADTime = Convert.ToDateTime(datenow + " 18:00"); adrRecordEntity.ClockTime = Convert.ToDateTime(datenow + " 18:00"); connmis.Execute("insert into ADR_Record(ID, UserNo, ADType, ADTime, ClockTime, ClockStatus, ClockPlace, ADYear, ADMonth, ADDay, ADPhoto) values(" + "'" + adrRecordEntity.ID + "','" + adrRecordEntity.UserNo + "','" + adrRecordEntity.ADType + "','" + adrRecordEntity.ADTime + "'," + @@ -1114,6 +1115,50 @@ namespace DigitalSchoolApi.Controllers } } + public static string CaptureJPEG(string id) + { + try + { + using (IDbConnection connmis = new SqlConnection(_misConnection)) + { + uint iBuffSize = 400000; + byte[] byJpegPicBuffer = new byte[iBuffSize]; + uint dwSizeReturned = 0; + var deviceEntity = connmis.QueryFirstOrDefault($"select * from ADR_Device where id='{id}';"); + if (deviceEntity == null) + { + return "设备不存在!"; + } + if (deviceEntity.F_EnabledMark == 0) + { + return "设备未启用!"; + } + #region 登录考勤机 + CHCNetSDK.NET_DVR_Init(); + CHCNetSDK.NET_DVR_DEVICEINFO_V30 DeviceInfo = new CHCNetSDK.NET_DVR_DEVICEINFO_V30(); + var m_lUserID = CHCNetSDK.NET_DVR_Login_V30(deviceEntity.IpAddress, deviceEntity.PortNumber.Value, deviceEntity.AdminAccount, deviceEntity.AdminPwd, ref DeviceInfo); + if (m_lUserID < 0) + { + return "设备登录失败!"; + } + #endregion + CHCNetSDK.NET_DVR_JPEGPARA lpJpegPara = new CHCNetSDK.NET_DVR_JPEGPARA(); + lpJpegPara.wPicQuality = 0; + lpJpegPara.wPicSize = 0xff; + + if (CHCNetSDK.NET_DVR_CaptureJPEGPicture_NEW(m_lUserID, 1 + (int)DeviceInfo.byStartChan, ref lpJpegPara, byJpegPicBuffer, + iBuffSize, ref dwSizeReturned)) + { + return "data:image/jpeg;base64," + Convert.ToBase64String(byJpegPicBuffer, 0, (int)dwSizeReturned); + } + return "设备抓图失败!"; + } + } + catch (Exception e) + { + return "设备抓图异常:" + e.Message; + } + } #region 考勤结构体 /// /// 考勤设备日志 diff --git a/DigitalSchoolApi/Controllers/YKTController.cs b/DigitalSchoolApi/Controllers/YKTController.cs index 7ef5251..13074f0 100644 --- a/DigitalSchoolApi/Controllers/YKTController.cs +++ b/DigitalSchoolApi/Controllers/YKTController.cs @@ -274,6 +274,16 @@ namespace DigitalSchoolApi.Controllers return Ok(); } + public IHttpActionResult CaptureJPEG(string id) + { + var result=HKAttendanceController.CaptureJPEG(id); + return Ok(new + { + state = !result.Contains("设备"), + data = result + }); + } + #region 长阳报名\晚归预警 /// /// 长阳报名 保存后24小时自动提交 @@ -509,7 +519,7 @@ namespace DigitalSchoolApi.Controllers //学生 RecurringJob.AddOrUpdate("SyncTLMZYMiddleToStuInfo", () => TLMSchoolController.SyncStuInfoOracle(null), - Cron.Daily(1), TimeZoneInfo.Local); + Cron.MinuteInterval(5), TimeZoneInfo.Local); return Ok(); } /// diff --git a/DigitalSchoolApi/Controllers/海康考勤机/CHCNetSDK.cs b/DigitalSchoolApi/Controllers/海康考勤机/CHCNetSDK.cs index 2c3a893..f64385c 100644 --- a/DigitalSchoolApi/Controllers/海康考勤机/CHCNetSDK.cs +++ b/DigitalSchoolApi/Controllers/海康考勤机/CHCNetSDK.cs @@ -328,7 +328,16 @@ namespace AlarmCSharpDemo [MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 24, ArraySubType = UnmanagedType.I1)] public byte[] byRes; } - + //ͼƬ + [StructLayoutAttribute(LayoutKind.Sequential)] + public struct NET_DVR_JPEGPARA + { + /*ע⣺ͼѹֱΪVGAʱ֧0=CIF, 1=QCIF, 2=D1ץͼ + ֱΪ3=UXGA(1600x1200), 4=SVGA(800x600), 5=HD720p(1280x720),6=VGA,7=XVGA, 8=HD900p + ֵ֧ǰֱʵץͼ*/ + public ushort wPicSize;/* 0=CIF, 1=QCIF, 2=D1 3=UXGA(1600x1200), 4=SVGA(800x600), 5=HD720p(1280x720),6=VGA*/ + public ushort wPicQuality;/* ͼƬϵ 0- 1-Ϻ 2-һ */ + } /********************************************************* Function: NET_DVR_Init Desc: ʼSDKSDKǰᡣ @@ -349,11 +358,30 @@ namespace AlarmCSharpDemo public static extern bool NET_DVR_SetExceptionCallBack_V30(uint nMessage, IntPtr hWnd, EXCEPYIONCALLBACK fExceptionCallBack, IntPtr pUser); [DllImport(@"HCNetSDK.dll")] public static extern bool NET_DVR_SetDVRMessageCallBack_V31(MSGCallBack_V31 fMessageCallBack, IntPtr pUser); + /********************************************************* + Function: NET_DVR_Login_V30 + Desc: + Input: sDVRIP [in] 豸IPַ + wServerPort [in] 豸˿ں + sUserName [in] ¼û + sPassword [in] û + Output: lpDeviceInfo [out] 豸Ϣ + Return: -1ʾʧܣֵʾصûIDֵ + **********************************************************/ + [DllImport(@".\HCNetSDK.dll")] + public static extern Int32 NET_DVR_Login_V30(string sDVRIP, Int32 wDVRPort, string sUserName, string sPassword, ref NET_DVR_DEVICEINFO_V30 lpDeviceInfo); [DllImport(@"HCNetSDK.dll")] public static extern int NET_DVR_Login_V40(ref NET_DVR_USER_LOGIN_INFO pLoginInfo, ref NET_DVR_DEVICEINFO_V40 lpDeviceInfo); [DllImport(@"HCNetSDK.dll")] public static extern int NET_DVR_SetupAlarmChan_V41(int lUserID, ref NET_DVR_SETUPALARM_PARAM lpSetupParam); [DllImport(@"HCNetSDK.dll")] public static extern bool NET_DVR_CloseAlarmChan_V30(int lAlarmHandle); + //2005-09-15 + [DllImport(@".\HCNetSDK.dll")] + public static extern bool NET_DVR_CaptureJPEGPicture(int lUserID, int lChannel, ref NET_DVR_JPEGPARA lpJpegPara, string sPicFileName); + + //JPEGץͼڴ + [DllImport(@".\HCNetSDK.dll")] + public static extern bool NET_DVR_CaptureJPEGPicture_NEW(int lUserID, int lChannel, ref NET_DVR_JPEGPARA lpJpegPara, byte[] sJpegPicBuffer, uint dwPicSize, ref uint lpSizeReturned); } } \ No newline at end of file