using Face.Domain.Entities; using Face.Web.Areas.App.Models; using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Linq; using System.Runtime.Remoting.Messaging; using System.Web; using System.Web.Mvc; using static Face.Web.Areas.App.Controllers.GeneratePasswordController; namespace Face.Web.Areas.App.Controllers { public class GroupController : Controller { // GET: App/Group /// /// 分配人脸机key api /// /// /// [HttpPost] public ActionResult SetPassword(string jsondata) { //var host = request.Host.Value; // 获取域名 try { //var requestPath = HttpContext.Request.Path; var request = HttpContext.Request; string apiUrl = request.Url.ToString(); Uri uri = new Uri(apiUrl); string domain = uri.GetLeftPart(UriPartial.Authority); Alldata alldata = JsonConvert.DeserializeObject(jsondata); Returnmessage rm = new Returnmessage(); string ip = AesEncryptionExample.Getip(); tbl_face_white_list tfwl = SqlSugarBase.GesmartDb().Queryable().First(x => x.ip == ip); tbl_face_key_assign_log tfksls = new tbl_face_key_assign_log(); //ip地址在白名单里面 if (tfwl != null) { //ip地址在白名单里面并且有效 if (tfwl.Is_Avalable == 1) { rm = inspectdomain.returnmessage(domain, ip, alldata); return Json(rm); } //ip地址在白名单里面但是无效 else { string json = JsonConvert.SerializeObject(rm, Formatting.Indented); tfksls.AppKey = alldata.AppKey; tfksls.IP = ip; tfksls.SN = alldata.Content.SN; tfksls.ReqType = alldata.Content.ReqType; tfksls.TimeStamp = alldata.Timestamp; tfksls.MsgID = alldata.MsgID; tfksls.CreateDateTime = DateTime.Now; tfksls.Key = ""; tfksls.Return = json; tfksls.Result = "false"; tfksls.Remark = "分配key api调用失败"; tfksls.RequstCnt = 1; int count = SqlSugarBase.GesmartDb().Insertable(tfksls).ExecuteCommand(); if (count > 0) { return Json(rm); } else { return Json(rm); } } } //IP地址不在白名单里面 else { rm = inspectdomain.returnmessage(domain, ip, alldata); return Json(rm); //string json = JsonConvert.SerializeObject(rm, Formatting.Indented); //tfksls.AppKey = alldata.AppKey; //tfksls.IP = ip; //tfksls.SN = alldata.Content.SN; //tfksls.ReqType = alldata.Content.ReqType; //tfksls.TimeStamp = alldata.Timestamp; //tfksls.MsgID = alldata.MsgID; //tfksls.CreateDateTime = DateTime.Now; //tfksls.Key = ""; //tfksls.Return = json; //tfksls.Result = "false"; //tfksls.Remark = "分配key api调用失败"; //tfksls.RequstCnt = 1; //int count = SqlSugarBase.GesmartDb().Insertable(tfksls).ExecuteCommand(); //if (count > 0) //{ // return Json(rm); //} //else //{ // return Json(rm); //} } } catch (Exception ex) { Returnmessage rm = new Returnmessage(); rm.MsgID = ""; rm.ErrCode = "3002"; rm.ErrMsg = ex.ToString(); rm.Contents.SN = ""; rm.Contents.Key = ""; return Json(rm); } } /// /// 小程序查看人脸机key api /// /// /// [HttpPost] public ActionResult GetPasswordKey(string jsondata) { try { Getdata gd = JsonConvert.DeserializeObject(jsondata); var requestPath = HttpContext.Request.Path; var request = HttpContext.Request; string apiUrl = request.Url.ToString(); Uri uri = new Uri(apiUrl); string domain = uri.GetLeftPart(UriPartial.Authority); string ip = AesEncryptionExample.Getip(); tbl_face_white_list tfwl = SqlSugarBase.GesmartDb().Queryable().First(x => x.ip == ip); //List dm = SqlSugarBase.GesmartDb().Queryable().Where(x => x.HotelCode == gd.Content.HotelID).ToList(); returnminfo ri = new returnminfo(); //Domain.Entities.DeviceManage dms = dm.Find(x => x.RoomId == gd.Content.RoomID); tbl_face_key_request_log tfkrl = new tbl_face_key_request_log(); //ip地址在白名单里面 if (tfwl != null) { //ip地址在白名单里面并且有效 if (tfwl.Is_Avalable == 1) { ri = inspectdomain.setreturnmessage(domain, ip, gd); return Json(ri); } //ip地址在白名单里面但是无有效 else { tfkrl.AppKey = gd.AppKey; tfkrl.RoomID = gd.Content.RoomID; tfkrl.IP = ip; tfkrl.MsgID = gd.MsgID; tfkrl.RoomID = gd.Content.RoomID; tfkrl.TimeStamp = gd.Timestamp; tfkrl.HotelID = gd.Content.HotelID; tfkrl.DeviceSN = ""; tfkrl.DeviceBrand = ""; tfkrl.Key = ""; tfkrl.CreateDateTime = DateTime.Now; tfkrl.Result = "false"; tfkrl.Remark = "key查询api调用失败"; tfkrl.RequstCnt = tfkrl.RequstCnt + 1; tfkrl.Return = JsonConvert.SerializeObject(ri, Formatting.Indented); int count = SqlSugarBase.GesmartDb().Insertable(tfkrl).ExecuteCommand(); if (count > 0) { return Json(ri); } else { return Json(ri); } } } //ip地址没有在白名单里面 else { ri = inspectdomain.setreturnmessage(domain, ip, gd); return Json(ri); //tfkrl.AppKey = gd.AppKey; //tfkrl.RoomID = gd.Content.RoomID; //tfkrl.IP = ip; //tfkrl.MsgID = gd.MsgID; //tfkrl.RoomID = gd.Content.RoomID; //tfkrl.TimeStamp = gd.Timestamp; //tfkrl.HotelID = gd.Content.HotelID; //tfkrl.DeviceSN = ""; //tfkrl.DeviceBrand = ""; //tfkrl.Key = ""; //tfkrl.CreateDateTime = DateTime.Now; //tfkrl.Result = "false"; //tfkrl.Remark = "key查询api调用失败"; //tfkrl.RequstCnt = tfkrl.RequstCnt + 1; //tfkrl.Return = JsonConvert.SerializeObject(ri, Formatting.Indented); //int count = SqlSugarBase.GesmartDb().Insertable(tfkrl).ExecuteCommand(); //if (count > 0) //{ // return Json(ri); //} //else //{ // return Json(ri); //} } } catch (Exception ex) { returnminfo ri = new returnminfo(); ri.MsgID = ""; ri.ErrCode = "3002"; ri.ErrMsg = ex.ToString(); ri.Contents.DeviceBrand = ""; ri.Contents.Key = ""; ri.Contents.DeviceSN = ""; ri.Contents.HotelID = ""; ri.Contents.RoomID = 0; return Json(ri); } } [HttpPost] public ActionResult Gethotelandroom(string jsondata) { try { Getdata gd = JsonConvert.DeserializeObject(jsondata); var requestPath = HttpContext.Request.Path; var request = HttpContext.Request; string apiUrl = request.Url.ToString(); Uri uri = new Uri(apiUrl); string domain = uri.GetLeftPart(UriPartial.Authority); string ip = AesEncryptionExample.Getip(); tbl_face_white_list tfwl = SqlSugarBase.GesmartDb().Queryable().First(x => x.ip == ip); //List dm = SqlSugarBase.GesmartDb().Queryable().Where(x => x.HotelCode == gd.Content.HotelID).ToList(); returnminfo ri = new returnminfo(); //Domain.Entities.DeviceManage dms = dm.Find(x => x.RoomId == gd.Content.RoomID); tbl_face_key_request_log tfkrl = new tbl_face_key_request_log(); //ip地址在白名单里面 if (gd.AppKey=="BLW888") { //string s= Guid.NewGuid().ToString(); if (tfwl != null) { //ip地址在白名单里面并且有效 if (tfwl.Is_Avalable == 1) { ri = inspectdomain.Gethotelandroominfo(domain, ip, gd); } //ip地址在白名单里面但是无有效 else { tfkrl.AppKey = gd.AppKey; tfkrl.RoomID = gd.Content.RoomID; tfkrl.IP = ip; tfkrl.MsgID = gd.MsgID; tfkrl.RoomID = gd.Content.RoomID; tfkrl.TimeStamp = gd.Timestamp; tfkrl.HotelID = gd.Content.HotelID; tfkrl.DeviceSN = ""; tfkrl.DeviceBrand = ""; tfkrl.Key = ""; tfkrl.CreateDateTime = DateTime.Now; tfkrl.Result = "false"; tfkrl.Remark = "key查询api调用失败"; tfkrl.RequstCnt = tfkrl.RequstCnt + 1; tfkrl.Return = JsonConvert.SerializeObject(ri, Formatting.Indented); int count = SqlSugarBase.GesmartDb().Insertable(tfkrl).ExecuteCommand(); if (count > 0) { return Json(ri); } else { return Json(ri); } } } //ip地址没有在白名单里面 else { ri = inspectdomain.Gethotelandroominfo(domain, ip, gd); } return Json(ri); } else { ri.MsgID = gd.MsgID; ri.ErrCode = "4000"; ri.ErrMsg = "AppKey is wrong"; ri.Contents.DeviceBrand =""; ri.Contents.Key = ""; ri.Contents.DeviceSN =""; ri.Contents.HotelID = ""; ri.Contents.RoomID = 0; return Json(ri); } } catch (Exception ex) { returnminfo ri = new returnminfo(); ri.MsgID = ""; ri.ErrCode = "3002"; ri.ErrMsg = ex.ToString(); ri.Contents.DeviceBrand = ""; ri.Contents.Key = ""; ri.Contents.DeviceSN = ""; ri.Contents.HotelID = ""; ri.Contents.RoomID = 0; return Json(ri); } } } public static class inspectdomain { public static Returnmessage returnmessage(string domainname, string ip, Alldata alldata) { Returnmessage rm = new Returnmessage(); //tbl_face_white_list tblFWList = new tbl_face_white_list(); tbl_face_key tfk = SqlSugarBase.GesmartDb().Queryable().First(x => x.SN == alldata.Content.SN); List tfksl = SqlSugarBase.GesmartDb().Queryable().Where(x => x.SN == alldata.Content.SN).ToList(); tbl_face_key tfks = new tbl_face_key(); tbl_face_key_assign_log tfksls = new tbl_face_key_assign_log(); //http://localhost:55151本地测试使用 if (domainname == "http://face.blv-oa.com") { //数据库里面有这个sn信息 if (tfk != null) { //如果已存在密钥则直接下发密钥 if (alldata.Content.ReqType == 0) { // 数据有这个sn的数据并且有key值 if (!string.IsNullOrEmpty(tfk.Key)) { tfksls.AppKey = alldata.AppKey; tfksls.IP = ip; tfksls.SN = alldata.Content.SN; tfksls.ReqType = alldata.Content.ReqType; tfksls.TimeStamp = alldata.Timestamp; tfksls.MsgID = alldata.MsgID; tfksls.CreateDateTime = DateTime.Now; tfksls.Key = tfk.Key; rm.MsgID = alldata.MsgID; rm.ErrCode = "200"; rm.ErrMsg = "ok"; rm.Contents.SN = alldata.Content.SN; rm.Contents.Key = tfk.Key; string json = JsonConvert.SerializeObject(rm, Formatting.Indented); tfksls.Return = json; tfksls.Result = "true"; tfksls.Remark = "分配key api调用成功"; tfksls.RequstCnt = tfksl[tfksl.Count - 1].RequstCnt + 1; int count = SqlSugarBase.GesmartDb().Insertable(tfksls).ExecuteCommand(); if (count > 0) { return rm; } else { rm.MsgID = alldata.MsgID; rm.ErrCode = "3004"; rm.ErrMsg = "insert log database wrong"; rm.Contents.SN = alldata.Content.SN; rm.Contents.Key = ""; return rm; } } //数据有这个sn的数据没有key值 else { string key = AesEncryptionExample.Randomnumber(); rm.MsgID = alldata.MsgID; rm.ErrCode = "200"; rm.ErrMsg = "ok"; rm.Contents.SN = alldata.Content.SN; rm.Contents.Key = key; tfks.AppKey = alldata.AppKey; tfks.CreateDateTime = DateTime.Now; tfks.MsgID = alldata.MsgID; tfks.TimeStamp = alldata.Timestamp; tfks.SN = alldata.Content.SN; tfks.Key = key; tfks.ReqType = alldata.Content.ReqType; tfks.RequstCnt = tfk.RequstCnt + 1; string json = JsonConvert.SerializeObject(rm, Formatting.Indented); tfks.Return = json; tfks.AppKey = alldata.AppKey; tfks.Result = "true"; tfks.Remark = "分配key api调用成功"; tfks.Id = tfk.Id; tfksls.AppKey = alldata.AppKey; tfksls.IP = ip; tfksls.SN = alldata.Content.SN; tfksls.ReqType = alldata.Content.ReqType; tfksls.TimeStamp = alldata.Timestamp; tfksls.MsgID = alldata.MsgID; tfksls.CreateDateTime = DateTime.Now; tfksls.Key = key; tfksls.Return = json; tfksls.Result = "true"; tfksls.Remark = "分配key api调用成功"; tfksls.RequstCnt = tfksl[tfksl.Count - 1].RequstCnt + 1; int count = SqlSugarBase.GesmartDb().Insertable(tfksls).ExecuteCommand(); if (count > 0) { int counts = SqlSugarBase.GesmartDb().Updateable(tfks).Where(x => x.Id == tfks.Id).ExecuteCommand(); if (counts > 0) { return rm; } else { rm.MsgID = alldata.MsgID; rm.ErrCode = "3005"; rm.ErrMsg = "Updatea database wrong"; rm.Contents.SN = alldata.Content.SN; rm.Contents.Key = ""; return rm; } } else { rm.MsgID = alldata.MsgID; rm.ErrCode = "3004"; rm.ErrMsg = "insert log database wrong"; rm.Contents.SN = alldata.Content.SN; rm.Contents.Key = ""; return rm; } } } //无论是否存在密钥都重新生成新的密钥 else { string key = AesEncryptionExample.Randomnumber(); rm.MsgID = alldata.MsgID; rm.ErrCode = "200"; rm.ErrMsg = "ok"; rm.Contents.SN = alldata.Content.SN; rm.Contents.Key = key; string json = JsonConvert.SerializeObject(rm, Formatting.Indented); tfks.AppKey = alldata.AppKey; tfks.CreateDateTime = DateTime.Now; tfks.MsgID = alldata.MsgID; tfks.TimeStamp = alldata.Timestamp; tfks.SN = alldata.Content.SN; tfks.Key = key; tfks.ReqType = alldata.Content.ReqType; tfks.RequstCnt = tfk.RequstCnt + 1; tfks.Return = json; tfks.AppKey = alldata.AppKey; tfks.Result = "true"; tfks.Remark = "分配key api调用成功"; tfks.Id = tfk.Id; tfksls.AppKey = alldata.AppKey; tfksls.IP = ip; tfksls.SN = alldata.Content.SN; tfksls.ReqType = alldata.Content.ReqType; tfksls.TimeStamp = alldata.Timestamp; tfksls.MsgID = alldata.MsgID; tfksls.CreateDateTime = DateTime.Now; tfksls.Key = key; tfksls.Return = json; tfksls.Result = "true"; tfksls.Remark = "分配key api调用成功"; tfksls.RequstCnt = tfksl[tfksl.Count - 1].RequstCnt + 1; int count = SqlSugarBase.GesmartDb().Insertable(tfksls).ExecuteCommand(); if (count > 0) { int counts = SqlSugarBase.GesmartDb().Updateable(tfks).Where(x => x.Id == tfks.Id).ExecuteCommand(); if (counts > 0) { return rm; } else { rm.MsgID = alldata.MsgID; rm.ErrCode = "3005"; rm.ErrMsg = "Updatea database wrong"; rm.Contents.SN = alldata.Content.SN; rm.Contents.Key = ""; return rm; } } else { rm.MsgID = alldata.MsgID; rm.ErrCode = "3004"; rm.ErrMsg = "insert log database wrong"; rm.Contents.SN = alldata.Content.SN; rm.Contents.Key = ""; return rm; } } } else { string key = AesEncryptionExample.Randomnumber(); rm.MsgID = alldata.MsgID; rm.ErrCode = "200"; rm.ErrMsg = "ok"; rm.Contents.SN = alldata.Content.SN; rm.Contents.Key = key; string json = JsonConvert.SerializeObject(rm, Formatting.Indented); tfks.AppKey = alldata.AppKey; tfks.CreateDateTime = DateTime.Now; tfks.MsgID = alldata.MsgID; tfks.TimeStamp = alldata.Timestamp; tfks.SN = alldata.Content.SN; tfks.Key = key; tfks.ReqType = alldata.Content.ReqType; tfks.RequstCnt = tfks.RequstCnt + 1; //tfksls.Return = json; tfks.Return = json; tfks.AppKey = alldata.AppKey; tfks.Result = "true"; tfks.Remark = "分配key api调用成功"; tfksls.AppKey = alldata.AppKey; tfksls.IP = ip; tfksls.SN = alldata.Content.SN; tfksls.ReqType = alldata.Content.ReqType; tfksls.TimeStamp = alldata.Timestamp; tfksls.MsgID = alldata.MsgID; tfksls.CreateDateTime = DateTime.Now; tfksls.Key = key; tfksls.Return = json; tfksls.Result = "true"; tfksls.Remark = "分配key api调用成功"; tfksls.RequstCnt = tfksls.RequstCnt + 1; int count = SqlSugarBase.GesmartDb().Insertable(tfksls).ExecuteCommand(); if (count > 0) { int counts = SqlSugarBase.GesmartDb().Insertable(tfks).ExecuteCommand(); if (counts > 0) { return rm; } else { rm.MsgID = alldata.MsgID; rm.ErrCode = "3003"; rm.ErrMsg = "insert database wrong"; rm.Contents.SN = alldata.Content.SN; rm.Contents.Key = ""; return rm; } } else { rm.MsgID = alldata.MsgID; rm.ErrCode = "3004"; rm.ErrMsg = "insert log database wrong"; rm.Contents.SN = alldata.Content.SN; rm.Contents.Key = ""; return rm; } } //return rm; } else { rm.MsgID = alldata.MsgID; rm.ErrCode = "3009"; rm.ErrMsg = "Domain Name Error"; rm.Contents.SN = alldata.Content.SN; rm.Contents.Key = ""; return rm; } } public static returnminfo setreturnmessage(string domainname, string ip, Getdata gd) { List dm = SqlSugarBase.GesmartDb().Queryable().Where(x => x.HotelCode == gd.Content.HotelID).ToList(); returnminfo ri = new returnminfo(); Domain.Entities.DeviceManage dms = dm.Find(x => x.RoomId == gd.Content.RoomID); tbl_face_key_request_log tfkrl = new tbl_face_key_request_log(); // http://localhost:55151 if (domainname == "http://face.blv-oa.com") { //有酒店 if (dm.Count != 0) { //有酒店房间号码酒店房间号码对应 if (dms != null) { tbl_face_key tfk = SqlSugarBase.GesmartDb().Queryable().First(x => x.SN == dms.SerialNo); //有key的人脸机 if (tfk != null) { tfkrl.AppKey = gd.AppKey; tfkrl.RoomID = gd.Content.RoomID; tfkrl.IP = ip; tfkrl.MsgID = gd.MsgID; tfkrl.RoomID = gd.Content.RoomID; tfkrl.TimeStamp = gd.Timestamp; tfkrl.HotelID = gd.Content.HotelID; tfkrl.DeviceSN = tfk.SN; tfkrl.DeviceBrand = dms.Factory; tfkrl.Key = tfk.Key; tfkrl.CreateDateTime = DateTime.Now; tfkrl.Result = "true"; tfkrl.Remark = "key查询api调用成功"; tfkrl.RequstCnt = tfkrl.RequstCnt + 1; ri.MsgID = gd.MsgID; ri.ErrCode = "200"; ri.ErrMsg = "ok"; ri.Contents.DeviceBrand = dms.Factory; ri.Contents.Key = tfk.Key; ri.Contents.DeviceSN = tfk.SN; ri.Contents.HotelID = gd.Content.HotelID; ri.Contents.RoomID = gd.Content.RoomID; tfkrl.Return = JsonConvert.SerializeObject(ri, Formatting.Indented); int count = SqlSugarBase.GesmartDb().Insertable(tfkrl).ExecuteCommand(); if (count > 0) { return ri; } else { ri.MsgID = gd.MsgID; ri.ErrCode = "3004"; ri.ErrMsg = "insert log database wrong"; ri.Contents.DeviceBrand = dms.Factory; ri.Contents.Key = ""; ri.Contents.DeviceSN = tfk.SN; ri.Contents.HotelID = gd.Content.HotelID; ri.Contents.RoomID = gd.Content.RoomID; return ri; } } //没有key的人脸机 else { tfkrl.AppKey = gd.AppKey; tfkrl.RoomID = gd.Content.RoomID; tfkrl.IP = ip; tfkrl.MsgID = gd.MsgID; tfkrl.RoomID = gd.Content.RoomID; tfkrl.TimeStamp = gd.Timestamp; tfkrl.HotelID = gd.Content.HotelID; tfkrl.DeviceSN = tfk.SN; tfkrl.DeviceBrand = dms.Factory; tfkrl.Key = ""; tfkrl.CreateDateTime = DateTime.Now; tfkrl.Result = "false"; tfkrl.Remark = "key查询api调用失败"; tfkrl.RequstCnt = tfkrl.RequstCnt + 1; ri.MsgID = gd.MsgID; ri.ErrCode = "3006"; ri.ErrMsg = "Face machine does not have key!"; ri.Contents.DeviceBrand = dms.Factory; ri.Contents.Key = ""; ri.Contents.DeviceSN = tfk.SN; ri.Contents.HotelID = gd.Content.HotelID; ri.Contents.RoomID = gd.Content.RoomID; tfkrl.Return = JsonConvert.SerializeObject(ri, Formatting.Indented); int count = SqlSugarBase.GesmartDb().Insertable(tfkrl).ExecuteCommand(); if (count > 0) { return ri; } else { ri.MsgID = gd.MsgID; ri.ErrCode = "3004"; ri.ErrMsg = "insert log database wrong"; ri.Contents.DeviceBrand = dms.Factory; ri.Contents.Key = ""; ri.Contents.DeviceSN = tfk.SN; ri.Contents.HotelID = gd.Content.HotelID; ri.Contents.RoomID = gd.Content.RoomID; return ri; } } } //有酒店房间号码与酒店房间号码不对应 else { tfkrl.AppKey = gd.AppKey; tfkrl.RoomID = gd.Content.RoomID; tfkrl.IP = ip; tfkrl.MsgID = gd.MsgID; tfkrl.RoomID = gd.Content.RoomID; tfkrl.TimeStamp = gd.Timestamp; tfkrl.HotelID = gd.Content.HotelID; tfkrl.DeviceSN = ""; tfkrl.DeviceBrand = ""; tfkrl.Key = ""; tfkrl.CreateDateTime = DateTime.Now; tfkrl.Result = "false"; tfkrl.Remark = "key查询api调用失败"; tfkrl.RequstCnt = tfkrl.RequstCnt + 1; ri.MsgID = gd.MsgID; ri.ErrCode = "3007"; ri.ErrMsg = "the hotel does not have a room for it!"; ri.Contents.DeviceBrand = ""; ri.Contents.Key = ""; ri.Contents.DeviceSN = ""; ri.Contents.HotelID = gd.Content.HotelID; ri.Contents.RoomID = gd.Content.RoomID; tfkrl.Return = JsonConvert.SerializeObject(ri, Formatting.Indented); int count = SqlSugarBase.GesmartDb().Insertable(tfkrl).ExecuteCommand(); if (count > 0) { return ri; } else { ri.MsgID = gd.MsgID; ri.ErrCode = "3004"; ri.ErrMsg = "insert log database wrong"; ri.Contents.DeviceBrand = ""; ri.Contents.Key = ""; ri.Contents.DeviceSN = ""; ri.Contents.HotelID = gd.Content.HotelID; ri.Contents.RoomID = gd.Content.RoomID; return ri; } } } //无酒店 else { tfkrl.AppKey = gd.AppKey; tfkrl.RoomID = gd.Content.RoomID; tfkrl.IP = ip; tfkrl.MsgID = gd.MsgID; tfkrl.RoomID = gd.Content.RoomID; tfkrl.TimeStamp = gd.Timestamp; tfkrl.HotelID = gd.Content.HotelID; tfkrl.DeviceSN = ""; tfkrl.DeviceBrand = ""; tfkrl.Key = ""; tfkrl.CreateDateTime = DateTime.Now; tfkrl.Result = "false"; tfkrl.Remark = "key查询api调用失败"; tfkrl.RequstCnt = tfkrl.RequstCnt + 1; ri.MsgID = gd.MsgID; ri.ErrCode = "3008"; ri.ErrMsg = "there is no such hotel!"; ri.Contents.DeviceBrand = ""; ri.Contents.Key = ""; ri.Contents.DeviceSN = ""; ri.Contents.HotelID = gd.Content.HotelID; ri.Contents.RoomID = gd.Content.RoomID; tfkrl.Return = JsonConvert.SerializeObject(ri, Formatting.Indented); int count = SqlSugarBase.GesmartDb().Insertable(tfkrl).ExecuteCommand(); if (count > 0) { return ri; } else { ri.MsgID = gd.MsgID; ri.ErrCode = "3004"; ri.ErrMsg = "insert log database wrong"; ri.Contents.DeviceBrand = ""; ri.Contents.Key = ""; ri.Contents.DeviceSN = ""; ri.Contents.HotelID = gd.Content.HotelID; ri.Contents.RoomID = gd.Content.RoomID; return ri; } } } else { ri.MsgID = gd.MsgID; ri.ErrCode = "3009"; ri.ErrMsg = "Domain Name Error"; ri.Contents.DeviceBrand = ""; ri.Contents.Key = ""; ri.Contents.DeviceSN = ""; ri.Contents.HotelID = gd.Content.HotelID; ri.Contents.RoomID = gd.Content.RoomID; return ri; } } public static returnminfo Gethotelandroominfo(string domainname, string ip, Getdata gd) { List dm = SqlSugarBase.GesmartDb().Queryable().Where(x => x.HotelCode == gd.Content.HotelID).ToList(); returnminfo ri = new returnminfo(); Domain.Entities.DeviceManage dms = dm.Find(x => x.RoomId == gd.Content.RoomID); tbl_face_key_request_log tfkrl = new tbl_face_key_request_log(); // http://localhost:55151 // domainname http://face.blv-oa.com if (domainname == "http://face.blv-oa.com") { //有酒店 if (dm.Count != 0) { //有酒店房间号码酒店房间号码对应 if (dms != null) { //tbl_face_key tfk = SqlSugarBase.GesmartDb().Queryable().First(x => x.SN == dms.SerialNo); ////有key的人脸机 //if (tfk != null) //{ tfkrl.AppKey = gd.AppKey; tfkrl.RoomID = gd.Content.RoomID; tfkrl.IP = ip; tfkrl.MsgID = gd.MsgID; tfkrl.RoomID = gd.Content.RoomID; tfkrl.TimeStamp = gd.Timestamp; tfkrl.HotelID = gd.Content.HotelID; tfkrl.DeviceSN = dms.SerialNo; tfkrl.DeviceBrand = dms.Factory; //tfkrl.Key = tfk.Key; tfkrl.CreateDateTime = DateTime.Now; tfkrl.Result = "true"; tfkrl.Remark = "key查询api调用成功"; tfkrl.RequstCnt = tfkrl.RequstCnt + 1; ri.MsgID = gd.MsgID; ri.ErrCode = "200"; ri.ErrMsg = "ok"; ri.Contents.DeviceBrand = dms.Factory; //ri.Contents.Key = tfk.Key; ri.Contents.DeviceSN = dms.SerialNo; ri.Contents.HotelID = gd.Content.HotelID; ri.Contents.RoomID = gd.Content.RoomID; tfkrl.Return = JsonConvert.SerializeObject(ri, Formatting.Indented); int count = SqlSugarBase.GesmartDb().Insertable(tfkrl).ExecuteCommand(); if (count > 0) { return ri; } else { ri.MsgID = gd.MsgID; ri.ErrCode = "3004"; ri.ErrMsg = "insert log database wrong"; ri.Contents.DeviceBrand = dms.Factory; ri.Contents.Key = ""; ri.Contents.DeviceSN = dms.SerialNo; ri.Contents.HotelID = gd.Content.HotelID; ri.Contents.RoomID = gd.Content.RoomID; return ri; } //} //没有key的人脸机 //else //{ // tfkrl.AppKey = gd.AppKey; // tfkrl.RoomID = gd.Content.RoomID; // tfkrl.IP = ip; // tfkrl.MsgID = gd.MsgID; // tfkrl.RoomID = gd.Content.RoomID; // tfkrl.TimeStamp = gd.Timestamp; // tfkrl.HotelID = gd.Content.HotelID; // tfkrl.DeviceSN = tfk.SN; // tfkrl.DeviceBrand = dms.Factory; // tfkrl.Key = ""; // tfkrl.CreateDateTime = DateTime.Now; // tfkrl.Result = "false"; // tfkrl.Remark = "key查询api调用失败"; // tfkrl.RequstCnt = tfkrl.RequstCnt + 1; // ri.MsgID = gd.MsgID; // ri.ErrCode = "3006"; // ri.ErrMsg = "Face machine does not have key!"; // ri.Contents.DeviceBrand = dms.Factory; // ri.Contents.Key = ""; // ri.Contents.DeviceSN = tfk.SN; // ri.Contents.HotelID = gd.Content.HotelID; // ri.Contents.RoomID = gd.Content.RoomID; // tfkrl.Return = JsonConvert.SerializeObject(ri, Formatting.Indented); // int count = SqlSugarBase.GesmartDb().Insertable(tfkrl).ExecuteCommand(); // if (count > 0) // { // return ri; // } // else // { // ri.MsgID = gd.MsgID; // ri.ErrCode = "3004"; // ri.ErrMsg = "insert log database wrong"; // ri.Contents.DeviceBrand = dms.Factory; // ri.Contents.Key = ""; // ri.Contents.DeviceSN = tfk.SN; // ri.Contents.HotelID = gd.Content.HotelID; // ri.Contents.RoomID = gd.Content.RoomID; // return ri; // } //} } //有酒店房间号码与酒店房间号码不对应 else { tfkrl.AppKey = gd.AppKey; tfkrl.RoomID = gd.Content.RoomID; tfkrl.IP = ip; tfkrl.MsgID = gd.MsgID; tfkrl.RoomID = gd.Content.RoomID; tfkrl.TimeStamp = gd.Timestamp; tfkrl.HotelID = gd.Content.HotelID; tfkrl.DeviceSN = ""; tfkrl.DeviceBrand = ""; tfkrl.Key = ""; tfkrl.CreateDateTime = DateTime.Now; tfkrl.Result = "false"; tfkrl.Remark = "key查询api调用失败"; tfkrl.RequstCnt = tfkrl.RequstCnt + 1; ri.MsgID = gd.MsgID; ri.ErrCode = "3007"; ri.ErrMsg = "the hotel does not have a room for it!"; ri.Contents.DeviceBrand = ""; ri.Contents.Key = ""; ri.Contents.DeviceSN = ""; ri.Contents.HotelID = gd.Content.HotelID; ri.Contents.RoomID = gd.Content.RoomID; tfkrl.Return = JsonConvert.SerializeObject(ri, Formatting.Indented); int count = SqlSugarBase.GesmartDb().Insertable(tfkrl).ExecuteCommand(); if (count > 0) { return ri; } else { ri.MsgID = gd.MsgID; ri.ErrCode = "3004"; ri.ErrMsg = "insert log database wrong"; ri.Contents.DeviceBrand = ""; ri.Contents.Key = ""; ri.Contents.DeviceSN = ""; ri.Contents.HotelID = gd.Content.HotelID; ri.Contents.RoomID = gd.Content.RoomID; return ri; } } } //无酒店 else { tfkrl.AppKey = gd.AppKey; tfkrl.RoomID = gd.Content.RoomID; tfkrl.IP = ip; tfkrl.MsgID = gd.MsgID; tfkrl.RoomID = gd.Content.RoomID; tfkrl.TimeStamp = gd.Timestamp; tfkrl.HotelID = gd.Content.HotelID; tfkrl.DeviceSN = ""; tfkrl.DeviceBrand = ""; tfkrl.Key = ""; tfkrl.CreateDateTime = DateTime.Now; tfkrl.Result = "false"; tfkrl.Remark = "key查询api调用失败"; tfkrl.RequstCnt = tfkrl.RequstCnt + 1; ri.MsgID = gd.MsgID; ri.ErrCode = "3008"; ri.ErrMsg = "there is no such hotel!"; ri.Contents.DeviceBrand = ""; ri.Contents.Key = ""; ri.Contents.DeviceSN = ""; ri.Contents.HotelID = gd.Content.HotelID; ri.Contents.RoomID = gd.Content.RoomID; tfkrl.Return = JsonConvert.SerializeObject(ri, Formatting.Indented); int count = SqlSugarBase.GesmartDb().Insertable(tfkrl).ExecuteCommand(); if (count > 0) { return ri; } else { ri.MsgID = gd.MsgID; ri.ErrCode = "3004"; ri.ErrMsg = "insert log database wrong"; ri.Contents.DeviceBrand = ""; ri.Contents.Key = ""; ri.Contents.DeviceSN = ""; ri.Contents.HotelID = gd.Content.HotelID; ri.Contents.RoomID = gd.Content.RoomID; return ri; } } } else { ri.MsgID = gd.MsgID; ri.ErrCode = "3009"; ri.ErrMsg = "Domain Name Error"; ri.Contents.DeviceBrand = ""; ri.Contents.Key = ""; ri.Contents.DeviceSN = ""; ri.Contents.HotelID = gd.Content.HotelID; ri.Contents.RoomID = gd.Content.RoomID; return ri; } } } }