dao 2 weeks ago
parent
commit
56c166f9d1
3 changed files with 87 additions and 4 deletions
  1. +47
    -2
      DigitalSchoolApi/Controllers/HKAttendanceController.cs
  2. +11
    -1
      DigitalSchoolApi/Controllers/YKTController.cs
  3. +29
    -1
      DigitalSchoolApi/Controllers/海康考勤机/CHCNetSDK.cs

+ 47
- 2
DigitalSchoolApi/Controllers/HKAttendanceController.cs View File

@@ -14,6 +14,7 @@ using System.Web;
using AlarmCSharpDemo;
using Antlr.Runtime.Misc;
using Dapper;
using Learun.Util;
using Org.BouncyCastle.Asn1.X509;
using Org.BouncyCastle.Ocsp;

@@ -63,7 +64,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();
@@ -109,7 +110,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 + "'," +
@@ -1224,6 +1225,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<ADR_DeviceEntity>($"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 考勤结构体
/// <summary>
/// 考勤设备日志


+ 11
- 1
DigitalSchoolApi/Controllers/YKTController.cs View File

@@ -295,6 +295,16 @@ namespace DigitalSchoolApi.Controllers
return Ok(r);
}

public IHttpActionResult CaptureJPEG(string id)
{
var result=HKAttendanceController.CaptureJPEG(id);
return Ok(new
{
state = !result.Contains("设备"),
data = result
});
}

#region 长阳报名\晚归预警
/// <summary>
/// 长阳报名 保存后24小时自动提交
@@ -530,7 +540,7 @@ namespace DigitalSchoolApi.Controllers
//学生
RecurringJob.AddOrUpdate("SyncTLMZYMiddleToStuInfo",
() => TLMSchoolController.SyncStuInfoOracle(null),
Cron.Daily(1), TimeZoneInfo.Local);
Cron.MinuteInterval(5), TimeZoneInfo.Local);
return Ok();
}
/// <summary>


+ 29
- 1
DigitalSchoolApi/Controllers/海康考勤机/CHCNetSDK.cs View File

@@ -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: 初始化SDK,调用其他SDK函数的前提。
@@ -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);
}
}

Loading…
Cancel
Save