From 6f34ab1ed6f8cb79a012a30a7b687e362c6f16c2 Mon Sep 17 00:00:00 2001 From: LR-20210131IOQH\Administrator <jackcold@163.com> Date: 星期四, 10 六月 2021 19:08:41 +0800 Subject: [PATCH] 打卡判断,增加前端浏览器mac获取,当mac获取为空时不判断 --- zhengcaioa/zhengcaioa/Controllers/AdmManagement/SigninController.cs | 169 +++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 files changed, 153 insertions(+), 16 deletions(-) diff --git a/zhengcaioa/zhengcaioa/Controllers/AdmManagement/SigninController.cs b/zhengcaioa/zhengcaioa/Controllers/AdmManagement/SigninController.cs index 2bfd86d..1fffe87 100644 --- a/zhengcaioa/zhengcaioa/Controllers/AdmManagement/SigninController.cs +++ b/zhengcaioa/zhengcaioa/Controllers/AdmManagement/SigninController.cs @@ -10,6 +10,8 @@ using zhengcaioa.Models; using Microsoft.AspNetCore.Http; using Newtonsoft.Json.Linq; +using System.Transactions; +using System.Runtime.InteropServices; namespace zhengcaioa.Controllers.AdmManagement { @@ -18,12 +20,15 @@ private readonly ILogger<SigninController> _logger; private readonly IAdmSigninService _signinService; private readonly ISysAttachmentService _sysAttachmentService; + private readonly IAdmAttendanceRuleService _attendanceRuleService; [CheckLogin] - public SigninController(ILogger<SigninController> logger, IAdmSigninService signinService, ISysAttachmentService sysAttachmentService) + public SigninController(ILogger<SigninController> logger, IAdmSigninService signinService, ISysAttachmentService sysAttachmentService + , IAdmAttendanceRuleService attendanceRuleService) { _logger = logger; _signinService = signinService; _sysAttachmentService = sysAttachmentService; + _attendanceRuleService = attendanceRuleService; } #region 鑰冨嫟绛惧埌鎵撳崱 @@ -79,12 +84,89 @@ /// <param name="signinType">10鏃╀笂涓婄彮 11鏃╀笂涓嬬彮 20涓嬪崍涓婄彮 21涓嬪崍涓嬬彮 30鍔犵彮涓婄彮 31鍔犵彮涓嬬彮</param> /// <returns></returns> [CheckLogin] - public string Save(string id,int signinType) - { - ResultEntity resultEntity = _signinService.save(id, signinType); + public string Save(string id,int signinType,string mac) + { + ResultEntity resultEntity = new ResultEntity(); + resultEntity.Result = false; + try + { + if (string.IsNullOrEmpty(mac)) + { + resultEntity = _signinService.save(id, signinType); + } + else + { + var curentuser = JsonConvert.DeserializeObject<PltUser>(HttpContext.Session.GetString("User")); + if(curentuser.IpMac == mac) + { + //var mac = GetClientMAC(GetClientIP()); + + } + else + { + resultEntity.Message = "鎵撳崱鐢佃剳妫�鏌ヤ笉鍖归厤銆�"; + } + } + } + catch(Exception er) + { } return JsonConvert.SerializeObject(resultEntity); } + + + [DllImport("Iphlpapi.dll")] + private static extern int SendARP(Int32 dest, Int32 host, ref Int64 mac, ref Int32 length); + + [DllImport("Ws2_32.dll")] + private static extern Int32 inet_addr(string ip); + + private string GetClientIP() + { + HttpContextAccessor context = new HttpContextAccessor(); + var ip = context.HttpContext?.Connection.RemoteIpAddress.ToString(); + var mac = GetClientMAC(ip); + var str = "IP:" + ip + " 锛孧AC:" + mac; + return str; + } + + private string GetClientMAC(string ip) + { + string mac_dest = string.Empty; + try + { + Int32 ldest = inet_addr(ip); //鐩殑鍦扮殑ip + Int32 lhost = inet_addr(""); //鏈嶅姟鍣ㄧ殑ip + Int64 macinfo = new Int64(); + Int32 len = 6; + int res = SendARP(ldest, 0, ref macinfo, ref len); + string mac_src = macinfo.ToString("X"); + while (mac_src.Length < 12) + { + mac_src = mac_src.Insert(0, "0"); + } + for (int i = 0; i < 11; i++) + { + if (0 == (i % 2)) + { + if (i == 10) + { + mac_dest = mac_dest.Insert(0, mac_src.Substring(i, 2)); + } + else + { + mac_dest = "-" + mac_dest.Insert(0, mac_src.Substring(i, 2)); + } + + } + } + } + catch (Exception ex) + { + throw ex; + } + return mac_dest; + } /// <summary> /// 鍙栧緱浠婂ぉ绛惧埌淇℃伅 @@ -236,25 +318,80 @@ #region 鑰冨嫟瑙勫垯 public IActionResult AttendanceRule() { + AdmAttendanceRuleDTO admAttendanceRuleDTO = _attendanceRuleService.Get(""); + admAttendanceRuleDTO.admAttendanceRulesDtlDTOs = _attendanceRuleService.GetDtlList(""); + + ViewData.Model = admAttendanceRuleDTO; return View(); } - public string SaveAttendanceRule(object leaveOff) + public string SaveAttendanceRule(AdmAttendanceRuleDTO dto) { + ResultEntity resultEntity = new ResultEntity(); + dto.Holiday = "1"; + dto.Rest = "1"; + resultEntity.Result = false; var curentuser = JsonConvert.DeserializeObject<PltUser>(HttpContext.Session.GetString("User")); ViewData["curentuser"] = curentuser; - //leaveOff.RecStatus = "A"; - //if (String.IsNullOrEmpty(leaveOff.Id)) - //{ - // leaveOff.Creater = curentuser.Id; - // leaveOff.Createtime = DateTime.Now; - //} - //leaveOff.Modifier = curentuser.Id; - //leaveOff.Modifytime = DateTime.Now; + using (TransactionScope scope = new TransactionScope()) + { + dto.RecStatus = "A"; + if (String.IsNullOrEmpty(dto.Id)) + { + dto.Creater = curentuser.Id; + dto.Createtime = DateTime.Now; + } + dto.Modifier = curentuser.Id; + dto.Modifytime = DateTime.Now; - //ResultEntity resultEntity = _signinService.SaveAskLeaveOff(leaveOff); - var ss = leaveOff; - return JsonConvert.SerializeObject(null); + resultEntity = _attendanceRuleService.save(dto); + + + _attendanceRuleService.RemoveDtlList(dto.Id); + + for (int i = 0; i < dto.holiday_s.Length; i++) + { + if(!String.IsNullOrEmpty(dto.holiday_s[i]) && !String.IsNullOrEmpty(dto.holiday_e[i])) + { + AdmAttendanceRulesDtlDTO admAttendanceRulesDtlDTO = new AdmAttendanceRulesDtlDTO(); + admAttendanceRulesDtlDTO.Pid = dto.Id; + admAttendanceRulesDtlDTO.ValueStart = dto.holiday_s[i]; + admAttendanceRulesDtlDTO.ValueEnd = dto.holiday_e[i]; + admAttendanceRulesDtlDTO.Name = "jiejiari"; + admAttendanceRulesDtlDTO.RecStatus = "A"; + admAttendanceRulesDtlDTO.Creater = curentuser.Id; + admAttendanceRulesDtlDTO.Createtime = DateTime.Now; + admAttendanceRulesDtlDTO.Modifier = admAttendanceRulesDtlDTO.Creater; + admAttendanceRulesDtlDTO.Modifytime = admAttendanceRulesDtlDTO.Createtime; + resultEntity = _attendanceRuleService.saveDtl(admAttendanceRulesDtlDTO); + } + + } + for (int i = 0; i < dto.rest_s.Length; i++) + { + if (!String.IsNullOrEmpty(dto.rest_s[i]) && !String.IsNullOrEmpty(dto.rest_e[i])) + { + AdmAttendanceRulesDtlDTO admAttendanceRulesDtlDTO = new AdmAttendanceRulesDtlDTO(); + admAttendanceRulesDtlDTO.Pid = dto.Id; + admAttendanceRulesDtlDTO.ValueStart = dto.rest_s[i]; + admAttendanceRulesDtlDTO.ValueEnd = dto.rest_e[i]; + admAttendanceRulesDtlDTO.Name = "tiaoxiuri"; + admAttendanceRulesDtlDTO.RecStatus = "A"; + admAttendanceRulesDtlDTO.Creater = curentuser.Id; + admAttendanceRulesDtlDTO.Createtime = DateTime.Now; + admAttendanceRulesDtlDTO.Modifier = admAttendanceRulesDtlDTO.Creater; + admAttendanceRulesDtlDTO.Modifytime = admAttendanceRulesDtlDTO.Createtime; + resultEntity = _attendanceRuleService.saveDtl(admAttendanceRulesDtlDTO); + } + + + } + scope.Complete(); + } + + + // var ss = leaveOff; + return JsonConvert.SerializeObject(resultEntity); } #endregion } -- Gitblit v1.9.1