454 lines
20 KiB
C#
454 lines
20 KiB
C#
using BLL;
|
|
using BLL.API.HJGL;
|
|
using Model;
|
|
using SgManager.AI;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Configuration;
|
|
using System.Linq;
|
|
using System.Web;
|
|
using System.Web.Http;
|
|
using WebAPI.Models;
|
|
|
|
namespace WebAPI.Controllers
|
|
{
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public class FaceController : ApiController
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="form"></param>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
public Model.ResponeData Recognition([FromBody]FaceRecordForm form)
|
|
{
|
|
|
|
var responeData = new Model.ResponeData();
|
|
HttpFileCollection files = HttpContext.Current.Request.Files;
|
|
string localRoot = form.AttachUrl1;// HttpContext.Current.Request["AttachUrl1"];
|
|
string projectId = form.projectId;//HttpContext.Current.Request["projectId"];
|
|
string userId = form.userId;// HttpContext.Current.Request["userId"];
|
|
string userName = form.userName;////HttpContext.Current.Request["userName"];
|
|
localRoot = ConfigurationManager.AppSettings["localRoot"] + localRoot; //物理路径
|
|
string reUrl = string.Empty;
|
|
List<SgManager.AI.faceResult> kqFace = null;
|
|
try
|
|
{
|
|
kqFace = (List<SgManager.AI.faceResult>)SgManager.AI.FaceClass.SearchFileFace(localRoot);
|
|
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
responeData.message = "识别失败,人脸库信息为空" + localRoot;
|
|
responeData.data = localRoot;
|
|
responeData.code = 0;
|
|
}
|
|
|
|
if (kqFace == null || kqFace.Count == 0)
|
|
{
|
|
responeData.code = 0;
|
|
responeData.message = "识别失败,人脸库信息为空";
|
|
}
|
|
else if (kqFace[0].errMess != "SUCCESS")
|
|
{
|
|
responeData.code = 0;
|
|
try
|
|
{
|
|
responeData.message = BaiduError.getBaiduError(kqFace[0].errCode);
|
|
responeData.message = kqFace[0].errMess + "" + kqFace[0].errCode;
|
|
}
|
|
catch
|
|
{
|
|
}
|
|
}
|
|
else
|
|
{
|
|
try
|
|
{
|
|
string idCard = kqFace[0].user_id;
|
|
var welder = APIWelderService.GetWelderByIdCard(idCard,projectId );
|
|
if (welder != null)
|
|
{
|
|
var installtion1 = APIBaseInfoService.GetInstallationList(projectId, welder.WED_Unit);
|
|
var method = APIWelderService.GetWelderMethod(welder.WED_ID);
|
|
var steel = APIWelderService.GetWelderBSSteel(welder.WED_ID);
|
|
var consumables = APIWelderService.GetConsumables();
|
|
|
|
responeData.data = new { welder, installtion1, method, steel, consumables };
|
|
}
|
|
else
|
|
{
|
|
responeData.code = 0;
|
|
responeData.message = "识别成功,但焊工信息";
|
|
}
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
responeData.message = e.StackTrace;
|
|
responeData.code = 0;
|
|
}
|
|
}
|
|
return responeData;
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="form"></param>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
public Model.ResponeData SaveWXFacerecord([FromBody]FaceRecordForm form)
|
|
{
|
|
var responeData = new Model.ResponeData();
|
|
HttpFileCollection files = HttpContext.Current.Request.Files;
|
|
string localRoot = form.AttachUrl1;// HttpContext.Current.Request["AttachUrl1"];
|
|
string inOrOut = form.inOrOut;//HttpContext.Current.Request["inOrOut"];
|
|
string projectId = form.projectId;//HttpContext.Current.Request["projectId"];
|
|
string location = form.location;//HttpContext.Current.Request["location"];
|
|
string userId = form.userId;// HttpContext.Current.Request["userId"];
|
|
string userName = form.userName;////HttpContext.Current.Request["userName"];
|
|
localRoot = ConfigurationManager.AppSettings["localRoot"] + localRoot; //物理路径
|
|
string reUrl = string.Empty;
|
|
List<SgManager.AI.faceResult> kqFace = null;
|
|
try
|
|
{
|
|
kqFace = (List<SgManager.AI.faceResult>)SgManager.AI.FaceClass.SearchFileFace(localRoot);
|
|
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
responeData.message = "识别失败,人脸库信息为空"+ localRoot;
|
|
responeData.data = localRoot;
|
|
responeData.code = 0;
|
|
}
|
|
|
|
if (kqFace == null || kqFace.Count == 0)
|
|
{
|
|
responeData.code = 0;
|
|
responeData.message = "识别失败,人脸库信息为空";
|
|
}
|
|
else if (kqFace[0].errMess != "SUCCESS")
|
|
{
|
|
responeData.code = 0;
|
|
try
|
|
{
|
|
responeData.message = BaiduError.getBaiduError(kqFace[0].errCode);
|
|
responeData.message = kqFace[0].errMess+""+ kqFace[0].errCode;
|
|
}
|
|
catch {
|
|
}
|
|
}
|
|
else
|
|
{
|
|
string idCard = kqFace[0].user_id;
|
|
using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString))
|
|
{
|
|
var person = db.SitePerson_Person.FirstOrDefault(u => u.IdentityCard == idCard && u.ProjectId == projectId);
|
|
if (person != null)
|
|
{
|
|
string inOrOutS = "进门";
|
|
if (inOrOut == "1")
|
|
{
|
|
inOrOutS = "出门";
|
|
}
|
|
|
|
Model.t_d_facerecordItem newFacerecordItem = new Model.t_d_facerecordItem()
|
|
{
|
|
ProjectId = person.ProjectId,
|
|
ID = 0,
|
|
EmployName = person.PersonName,
|
|
DepartmentID = person.TeamGroupId,
|
|
DepartName = TeamGroupService.GetTeamGroupNameByTeamGroupId(person.TeamGroupId),
|
|
EmployNO = person.IdentityCard,
|
|
RoleID = "微信端",
|
|
DateTimeRecord = DateTime.Now,
|
|
RecordDes = "微信端:",
|
|
InOrOut = inOrOutS,
|
|
Des1 = form.AttachUrl1,
|
|
Des2 = form.location,
|
|
};
|
|
var getfacerecord = db.T_d_facerecord.Where(x => x.ProjectId == person.ProjectId);
|
|
if (getfacerecord.Count() > 0)
|
|
{
|
|
newFacerecordItem.ID = getfacerecord.Max(x => x.ID) + 1;
|
|
}
|
|
var areas = db.WxProjectGpsAre.Where(u => u.ProjectId == person.ProjectId).ToList();
|
|
if (areas != null && areas.Count > 0)
|
|
{
|
|
foreach (var area in areas)
|
|
{
|
|
var points = db.WxProjectGpsPoint.Where(u => u.GpsAreId == area.GpsAreId).OrderBy(x => x.Orders).ToList();
|
|
if (points != null && points.Count > 0)
|
|
{
|
|
// string points = area.Point;
|
|
//if (!string.IsNullOrEmpty(points))
|
|
//{
|
|
// string[] ps = points.Split('|');
|
|
Gpslocation myLocation = new Gpslocation();
|
|
string[] myp = location.Split(',');
|
|
myLocation.lat = float.Parse(myp[0]);
|
|
myLocation.lng = float.Parse(myp[1]);
|
|
List<Gpslocation> gpsLoactions = new List<Gpslocation>();
|
|
foreach (var po in points)
|
|
{
|
|
Gpslocation gp = new Gpslocation();
|
|
string[] p = po.Point.Split(',');
|
|
gp.lat = float.Parse(p[0]);
|
|
gp.lng = float.Parse(p[1]);
|
|
gpsLoactions.Add(gp);
|
|
|
|
}
|
|
if (GpsPolygonHelper.isPointInPolygon(myLocation, gpsLoactions))
|
|
{
|
|
newFacerecordItem.AreaID = area.GpsAreId;
|
|
newFacerecordItem.AreaName = area.GpsAreName;
|
|
|
|
newFacerecordItem.RecordDes += "打卡成功";
|
|
//APIPersonService.getPersonInOut(person.ProjectId, person.IdentityCard, isIn, DateTime.Now);
|
|
responeData.message = "打卡成功";
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if (responeData.message != "打卡成功")
|
|
{
|
|
newFacerecordItem.RecordDes += "识别成功,不在项目区域内打卡";
|
|
//responeData.code = 0;
|
|
responeData.message = "不在项目区域内打卡";
|
|
}
|
|
|
|
if(string.IsNullOrEmpty(location))
|
|
{
|
|
newFacerecordItem.RecordDes += "识别成功,无项目坐标信息";
|
|
// APIPersonService.getPersonInOut(person.ProjectId, person.CardNo, isIn, DateTime.Now);
|
|
responeData.message = "识别成功,无项目坐标信息";
|
|
}
|
|
SaveFacerecord(newFacerecordItem);
|
|
}
|
|
else
|
|
{
|
|
responeData.code = 0;
|
|
responeData.message = "识别成功,但无人员项目信息";
|
|
}
|
|
}
|
|
}
|
|
using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString))
|
|
{
|
|
Model.Sys_FaceRecordLog newLog = new Sys_FaceRecordLog
|
|
{
|
|
FaceRecordId = SQLHelper.GetNewID(),
|
|
RecordTime = DateTime.Now,
|
|
ProjectId = projectId,
|
|
UserId = userId,
|
|
UserName = userName,
|
|
LocalRoot = localRoot,
|
|
InOrOut = inOrOut,
|
|
Location = location,
|
|
Message = responeData.message,
|
|
};
|
|
|
|
db.Sys_FaceRecordLog.InsertOnSubmit(newLog);
|
|
db.SubmitChanges();
|
|
}
|
|
return responeData;
|
|
}
|
|
|
|
#region 保存人脸识别出入记录信息
|
|
/// <summary>
|
|
/// 保存出入记录信息
|
|
/// </summary>
|
|
/// <param name="facerecord">出入记录信息</param>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
public Model.ResponeData SaveFacerecord([FromBody] Model.t_d_facerecordItem facerecord)
|
|
{
|
|
var responeData = new Model.ResponeData();
|
|
try
|
|
{
|
|
using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString))
|
|
{
|
|
if (facerecord != null)
|
|
{
|
|
var getFacerecord = db.T_d_facerecord.FirstOrDefault(x => x.ID == facerecord.ID && x.ProjectId == facerecord.ProjectId);
|
|
if (getFacerecord == null)
|
|
{
|
|
Model.T_d_facerecord newFacerecord = new Model.T_d_facerecord()
|
|
{
|
|
NewID = SQLHelper.GetNewID(),
|
|
ProjectId = facerecord.ProjectId,
|
|
ID = facerecord.ID,
|
|
EmployName = facerecord.EmployName,
|
|
DepartmentID = facerecord.DepartmentID,
|
|
DepartName = facerecord.DepartName,
|
|
AreaID = facerecord.AreaID,
|
|
AreaName = facerecord.AreaName,
|
|
EmployNO = facerecord.EmployNO,
|
|
CardID = facerecord.CardID,
|
|
RoleID = facerecord.RoleID,
|
|
DateTimeRecord = facerecord.DateTimeRecord,
|
|
RecordDes = facerecord.RecordDes,
|
|
FaceIP = facerecord.FaceIP,
|
|
InOrOut = facerecord.InOrOut,
|
|
Des1 = facerecord.Des1,
|
|
Des2 = facerecord.Des2,
|
|
Des3 = facerecord.Des3,
|
|
Des4 = facerecord.Des4,
|
|
};
|
|
|
|
db.T_d_facerecord.InsertOnSubmit(newFacerecord);
|
|
db.SubmitChanges();
|
|
|
|
if (facerecord.DateTimeRecord.HasValue)
|
|
{
|
|
Model.SitePerson_PersonInOut newInOut = new Model.SitePerson_PersonInOut
|
|
{
|
|
ProjectId = facerecord.ProjectId,
|
|
IdentityCard = facerecord.EmployNO,
|
|
IsIn = facerecord.InOrOut == "进门" ? true : false,
|
|
ChangeTime = facerecord.DateTimeRecord.Value,
|
|
InOutWay = Const.InOutWay_3,
|
|
};
|
|
|
|
PersonInOutService.AddPersonInOut(newInOut);
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
responeData.code = 2;
|
|
responeData.message = "信息有误!";
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
responeData.code = 0;
|
|
responeData.message = ex.Message;
|
|
ErrLogInfo.WriteLog("WX接口-保存出入记录", ex);
|
|
}
|
|
|
|
return responeData;
|
|
}
|
|
#endregion
|
|
|
|
#region 保存刷卡出入记录信息
|
|
/// <summary>
|
|
/// 保存出入记录信息
|
|
/// </summary>
|
|
/// <param name="validcardevent">出入记录信息</param>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
public Model.ResponeData SaveValidcardevent([FromBody] Model.t_d_validcardeventItem validcardevent)
|
|
{
|
|
var responeData = new Model.ResponeData();
|
|
try
|
|
{
|
|
using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString))
|
|
{
|
|
if (validcardevent != null)
|
|
{
|
|
var getValidcardevent = db.T_d_facerecord.FirstOrDefault(x => x.ID == validcardevent.ValidEventID && x.ProjectId == validcardevent.ProjectId);
|
|
if (getValidcardevent == null)
|
|
{
|
|
Model.T_d_validcardevent newValidcardevent = new Model.T_d_validcardevent()
|
|
{
|
|
NewID = SQLHelper.GetNewID(),
|
|
ProjectId = validcardevent.ProjectId,
|
|
ValidEventID = validcardevent.ValidEventID,
|
|
RecordDateTime = validcardevent.RecordDateTime,
|
|
CardNO = validcardevent.CardNO,
|
|
ConsumerID = validcardevent.ConsumerID,
|
|
InOrOut = validcardevent.InOrOut,
|
|
ControllerID = validcardevent.ControllerID,
|
|
ReaderNO = validcardevent.ReaderNO,
|
|
RecordFlashLoc = validcardevent.RecordFlashLoc,
|
|
RecordAll = validcardevent.RecordAll,
|
|
JPGPath = validcardevent.JPGPath,
|
|
IsDown = validcardevent.IsDown,
|
|
EquipmentSN = validcardevent.EquipmentSN,
|
|
ConsumerNO = validcardevent.ConsumerNO,
|
|
EmployNO = validcardevent.EmployNO,
|
|
EmployName = validcardevent.EmployName,
|
|
CardType = validcardevent.CardType,
|
|
Card = validcardevent.Card,
|
|
DepartmentID = validcardevent.DepartmentID,
|
|
DepartmentName = validcardevent.DepartmentName,
|
|
ControllerSN = validcardevent.ControllerSN,
|
|
DoorID = validcardevent.DoorID,
|
|
DoorName = validcardevent.DoorName,
|
|
ReaderName = validcardevent.ReaderName,
|
|
AreaID = validcardevent.AreaID,
|
|
AreaName = validcardevent.AreaName,
|
|
WorkType = validcardevent.WorkType,
|
|
Positions = validcardevent.Positions,
|
|
IDCardNo = validcardevent.IDCardNo,
|
|
};
|
|
|
|
db.T_d_validcardevent.InsertOnSubmit(newValidcardevent);
|
|
db.SubmitChanges();
|
|
|
|
if (validcardevent.RecordDateTime.HasValue)
|
|
{
|
|
Model.SitePerson_PersonInOut newInOut = new Model.SitePerson_PersonInOut
|
|
{
|
|
ProjectId = validcardevent.ProjectId,
|
|
IdentityCard = validcardevent.IDCardNo,
|
|
IsIn = validcardevent.InOrOut == 1 ? true : false,
|
|
ChangeTime = validcardevent.RecordDateTime.Value,
|
|
InOutWay = Const.InOutWay_1,
|
|
};
|
|
|
|
PersonInOutService.AddPersonInOut(newInOut);
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
responeData.code = 2;
|
|
responeData.message = "信息有误!";
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
responeData.code = 0;
|
|
responeData.message = ex.Message;
|
|
}
|
|
|
|
return responeData;
|
|
}
|
|
#endregion
|
|
|
|
#region 获取门禁人员考勤统计
|
|
/// <summary>
|
|
/// 获取人员信息出入场记录
|
|
/// </summary>
|
|
/// <param name="projectId"></param>
|
|
/// <param name="startDate"></param>
|
|
/// <param name="endDate"></param>
|
|
/// <returns></returns>
|
|
public Model.ResponeData getInOutstatistics(string projectId, DateTime startDate, DateTime endDate)
|
|
{
|
|
var responeData = new Model.ResponeData();
|
|
try
|
|
{
|
|
string unitId = null;
|
|
string postId = null;
|
|
responeData.data = Funs.DB.spInOutManHoursReport(projectId, unitId, postId, startDate, endDate).ToList(); ;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
responeData.code = 0;
|
|
responeData.message = ex.Message;
|
|
}
|
|
return responeData;
|
|
}
|
|
#endregion
|
|
}
|
|
}
|