You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1035 lines
43 KiB
1035 lines
43 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace FangYar.Common
|
|
{
|
|
/// <summary>
|
|
/// 人员同步ICC帮助类
|
|
/// </summary>
|
|
public class EmpSyncIccHelper
|
|
{
|
|
// IccSyncUrlHead
|
|
/// <summary>
|
|
/// 人员新增ICC人脸库
|
|
/// </summary>
|
|
public static string IccEmpImgAddUrl = System.Configuration.ConfigurationManager.AppSettings["IccSyncUrlHead"] + System.Configuration.ConfigurationManager.AppSettings["IccEmpImgAddUrl"] + "";
|
|
/// <summary>
|
|
/// 人员修改ICC人脸库
|
|
/// </summary>
|
|
public static string IccEmpImgUpdUrl = System.Configuration.ConfigurationManager.AppSettings["IccSyncUrlHead"] + System.Configuration.ConfigurationManager.AppSettings["IccEmpImgUpdUrl"] + "";
|
|
/// <summary>
|
|
/// 人员删除ICC人脸库
|
|
/// </summary>
|
|
public static string IccEmpImgDelUrl = System.Configuration.ConfigurationManager.AppSettings["IccSyncUrlHead"] + System.Configuration.ConfigurationManager.AppSettings["IccEmpImgDelUrl"] + "";
|
|
|
|
|
|
/// <summary>
|
|
/// 人员新增ICC人员信息
|
|
/// </summary>
|
|
public static string IccEmpInfoAddUrl = System.Configuration.ConfigurationManager.AppSettings["IccSyncUrlHead"] + System.Configuration.ConfigurationManager.AppSettings["IccEmpInfoAddUrl"] + "";
|
|
/// <summary>
|
|
/// 人员修改ICC人员信息
|
|
/// </summary>
|
|
public static string IccEmpInfoUpdUrl = System.Configuration.ConfigurationManager.AppSettings["IccSyncUrlHead"] + System.Configuration.ConfigurationManager.AppSettings["IccEmpInfoUpdUrl"] + "";
|
|
/// <summary>
|
|
/// 人员删除ICC人员信息
|
|
/// </summary>
|
|
public static string IccEmpInfoDelUrl = System.Configuration.ConfigurationManager.AppSettings["IccSyncUrlHead"] + System.Configuration.ConfigurationManager.AppSettings["IccEmpInfoDelUrl"] + "";
|
|
|
|
/// <summary>
|
|
/// 人员门禁同步信息
|
|
/// </summary>
|
|
public static string IccEmpDoorSync = System.Configuration.ConfigurationManager.AppSettings["IccSyncUrlHead"] + System.Configuration.ConfigurationManager.AppSettings["IccEmpDoorSync"] + "";
|
|
|
|
|
|
|
|
|
|
#region 人员信息操作
|
|
|
|
/// <summary>
|
|
/// 人员信息添加
|
|
/// </summary>
|
|
/// <param name="eid"></param>
|
|
public static void EmpInfoAdd(string eid)
|
|
{
|
|
//new Thread(() =>
|
|
//{
|
|
try
|
|
{
|
|
//拼接数据查询sql
|
|
string sql = " SELECT * from tbl_sys_emp_icc_sync_state WHERE EMP_ID='" + eid + "' and INFO_TYPE='1' ";
|
|
//查询数据
|
|
var dtq = MySqlHelper.QueryTable(sql);
|
|
//判断数据是否存在
|
|
if (dtq.Rows.Count == 0)
|
|
{
|
|
//不存在,新增一条数据
|
|
string sqlIns = " insert into tbl_sys_emp_icc_sync_state (ID,EMP_ID,Device_Code,Upd_State,INFO_TYPE,Operat_Type) VALUES ('" + Guid.NewGuid().ToString("N") +
|
|
"','" + eid + "','','1','1','0') ";
|
|
//执行插入
|
|
MySqlHelper.Execute(sqlIns);
|
|
}
|
|
|
|
// 拼接调用同步接口参数
|
|
string paramStr = "userId=" + eid;
|
|
|
|
//插入日志信息ID
|
|
string insLogId = Guid.NewGuid().ToString("N");
|
|
//插入日志记录
|
|
InsLog(new TblSysEmpIccSyncLogMo() { ID = insLogId, EMP_ID = eid, INFO_TYPE = "3", POST_URL = IccEmpInfoAddUrl + "?" + paramStr });
|
|
|
|
//调用接口同步数据并获取返回值
|
|
//var retStr = WebCommonUtil.PostWebRequest(IccEmpInfoAddUrl, paramStr);
|
|
var retStr = WebCommonUtil.GetPostUrl(IccEmpInfoAddUrl + "?" + paramStr);
|
|
|
|
EmpSyncIccReturnMo postRetMo = JsonHelper.FromJSON<EmpSyncIccReturnMo>(retStr);
|
|
|
|
//更新调用接口返回结果到日志记录
|
|
UpdLog(new TblSysEmpIccSyncLogMo() { ID = insLogId, POST_RETURN_MSG = retStr, POST_RETURN_CODE = postRetMo.code });
|
|
|
|
//信息更新状态:0、初始状态;1、提交(同步中);2、成功;3、失败;
|
|
string Upd_State = "3";
|
|
//验证返回数据
|
|
switch (postRetMo.code)
|
|
{
|
|
//正常
|
|
case "200":
|
|
//更新同步状态为正常
|
|
Upd_State = "2";
|
|
break;
|
|
default:
|
|
//同步失败,调用更新
|
|
EmpInfoUpd(eid);
|
|
break;
|
|
}
|
|
// 更新状态表信息
|
|
string sqlUpd = " update tbl_sys_emp_icc_sync_state set Upd_State='" + Upd_State + "',Upd_Time=now(),Operat_Type='0',Info_Msg='" +
|
|
postRetMo.code + "' where EMP_ID='" + eid + "' and INFO_TYPE='1' ";
|
|
//执行更新
|
|
MySqlHelper.Execute(sqlUpd);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
string str = "Web请求异常:" + ex;
|
|
FangYar.Common.MyLogHelper.WriteMsg(new FangYar.Common.LogInfoMo()
|
|
{
|
|
message = str,
|
|
msgType = FangYar.Common.EnumLogMsgTypeEnum.Error,
|
|
path = "EmpSyncICC"
|
|
});
|
|
}
|
|
//}).Start();
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 人员信息更新
|
|
/// </summary>
|
|
/// <param name="eid"></param>
|
|
public static void EmpInfoUpd(string eid)
|
|
{
|
|
//new Thread(() =>
|
|
//{
|
|
try
|
|
{
|
|
//拼接数据查询sql
|
|
string sql = " SELECT * from tbl_sys_emp_icc_sync_state WHERE EMP_ID='" + eid + "' and INFO_TYPE='1' ";
|
|
//查询数据
|
|
var dtq = MySqlHelper.QueryTable(sql);
|
|
//判断数据是否存在
|
|
if (dtq.Rows.Count == 0)
|
|
{
|
|
//不存在,新增一条数据
|
|
string sqlIns = " insert into tbl_sys_emp_icc_sync_state (ID,EMP_ID,Device_Code,Upd_State,INFO_TYPE,Operat_Type) VALUES ('" + Guid.NewGuid().ToString("N") +
|
|
"','" + eid + "','','1','1','1') ";
|
|
//执行插入
|
|
MySqlHelper.Execute(sqlIns);
|
|
}
|
|
|
|
// 拼接调用同步接口参数
|
|
string paramStr = "userId=" + eid;
|
|
|
|
//插入日志信息ID
|
|
string insLogId = Guid.NewGuid().ToString("N");
|
|
//插入日志记录
|
|
InsLog(new TblSysEmpIccSyncLogMo() { ID = insLogId, EMP_ID = eid, INFO_TYPE = "4", POST_URL = IccEmpInfoUpdUrl + "?" + paramStr });
|
|
|
|
|
|
//调用接口同步数据并获取返回值
|
|
//var retStr = WebCommonUtil.PostWebRequest(IccEmpInfoUpdUrl, paramStr);
|
|
var retStr = WebCommonUtil.GetPostUrl(IccEmpInfoUpdUrl + "?" + paramStr);
|
|
|
|
EmpSyncIccReturnMo postRetMo = JsonHelper.FromJSON<EmpSyncIccReturnMo>(retStr);
|
|
|
|
//更新调用接口返回结果到日志记录
|
|
UpdLog(new TblSysEmpIccSyncLogMo() { ID = insLogId, POST_RETURN_MSG = retStr, POST_RETURN_CODE = postRetMo.code });
|
|
|
|
//信息更新状态:0、初始状态;1、提交(同步中);2、成功;3、失败;
|
|
string Upd_State = "3";
|
|
//验证返回数据
|
|
switch (postRetMo.code)
|
|
{
|
|
//正常
|
|
case "200":
|
|
//更新同步状态为正常
|
|
Upd_State = "2";
|
|
break;
|
|
}
|
|
// 更新状态表信息
|
|
string sqlUpd = " update tbl_sys_emp_icc_sync_state set Upd_State='" + Upd_State + "',Upd_Time=now(),Operat_Type='1',Info_Msg='" +
|
|
postRetMo.code + "' where EMP_ID='" + eid + "' and INFO_TYPE='1' ";
|
|
//执行更新
|
|
MySqlHelper.Execute(sqlUpd);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
string str = "Web请求异常:" + ex;
|
|
FangYar.Common.MyLogHelper.WriteMsg(new FangYar.Common.LogInfoMo()
|
|
{
|
|
message = str,
|
|
msgType = FangYar.Common.EnumLogMsgTypeEnum.Error,
|
|
path = "EmpSyncICC"
|
|
});
|
|
}
|
|
//}).Start();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 人员信息删除
|
|
/// </summary>
|
|
/// <param name="eid"></param>
|
|
public static void EmpInfoDel(string eid)
|
|
{
|
|
//new Thread(() =>
|
|
//{
|
|
try
|
|
{
|
|
//拼接数据查询sql
|
|
string sql = " SELECT * from tbl_sys_emp_icc_sync_state WHERE EMP_ID='" + eid + "' and INFO_TYPE='1' ";
|
|
//查询数据
|
|
var dtq = MySqlHelper.QueryTable(sql);
|
|
//判断数据是否存在
|
|
if (dtq.Rows.Count == 0)
|
|
{
|
|
//不存在,新增一条数据
|
|
string sqlIns = " insert into tbl_sys_emp_icc_sync_state (ID,EMP_ID,Device_Code,Upd_State,INFO_TYPE,Operat_Type) VALUES ('" + Guid.NewGuid().ToString("N") +
|
|
"','" + eid + "','','1','1','2') ";
|
|
//执行插入
|
|
MySqlHelper.Execute(sqlIns);
|
|
}
|
|
|
|
// 拼接调用同步接口参数
|
|
string paramStr = "userId=" + eid;
|
|
|
|
//插入日志信息ID
|
|
string insLogId = Guid.NewGuid().ToString("N");
|
|
//插入日志记录
|
|
InsLog(new TblSysEmpIccSyncLogMo() { ID = insLogId, EMP_ID = eid, INFO_TYPE = "5", POST_URL = IccEmpInfoDelUrl + "?" + paramStr });
|
|
|
|
//调用接口同步数据并获取返回值
|
|
//var retStr = WebCommonUtil.PostWebRequest(IccEmpInfoDelUrl, paramStr);
|
|
var retStr = WebCommonUtil.GetPostUrl(IccEmpInfoDelUrl + "?" + paramStr);
|
|
|
|
EmpSyncIccReturnMo postRetMo = JsonHelper.FromJSON<EmpSyncIccReturnMo>(retStr);
|
|
|
|
//更新调用接口返回结果到日志记录
|
|
UpdLog(new TblSysEmpIccSyncLogMo() { ID = insLogId, POST_RETURN_MSG = retStr, POST_RETURN_CODE = postRetMo.code });
|
|
|
|
//信息更新状态:0、初始状态;1、提交(同步中);2、成功;3、失败;
|
|
string Upd_State = "3";
|
|
//验证返回数据
|
|
switch (postRetMo.code)
|
|
{
|
|
//正常
|
|
case "200":
|
|
//更新同步状态为正常
|
|
Upd_State = "2";
|
|
break;
|
|
}
|
|
// 更新状态表信息
|
|
string sqlUpd = " update tbl_sys_emp_icc_sync_state set Upd_State='" + Upd_State + "',Upd_Time=now(),Operat_Type='2',Info_Msg='" +
|
|
postRetMo.code + "' where EMP_ID='" + eid + "' and INFO_TYPE='1' ";
|
|
//执行更新
|
|
MySqlHelper.Execute(sqlUpd);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
string str = "Web请求异常:" + ex;
|
|
FangYar.Common.MyLogHelper.WriteMsg(new FangYar.Common.LogInfoMo()
|
|
{
|
|
message = str,
|
|
msgType = FangYar.Common.EnumLogMsgTypeEnum.Error,
|
|
path = "EmpSyncICC"
|
|
});
|
|
}
|
|
//}).Start();
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 批量人员信息删除
|
|
/// </summary>
|
|
/// <param name="empList"></param>
|
|
public static void EmpInfoDelByEmpList(List<string> empList)
|
|
{
|
|
//new Thread(() =>
|
|
//{
|
|
try
|
|
{
|
|
string empStr = GetListConvertStr(empList);
|
|
|
|
//拼接数据删除sql
|
|
string sql = " DELETE FROM tbl_sys_emp_icc_sync_state WHERE EMP_ID in (" + empStr + ") and INFO_TYPE='1' ";
|
|
//执行删除信息状态
|
|
MySqlHelper.Execute(sql);
|
|
|
|
//拼接添加数据Sql
|
|
string sqlIns = " insert into tbl_sys_emp_icc_sync_state (ID,EMP_ID,Device_Code,Upd_State,INFO_TYPE,Operat_Type) " +
|
|
" SELECT UUID(),ID,'','1','1','2' FROM tbl_sys_emp WHERE ID in (" + empStr + ") ";
|
|
//执行数据插入
|
|
MySqlHelper.Execute(sqlIns);
|
|
|
|
// 拼接调用同步接口参数
|
|
string paramStr = "userId=" + string.Join(",", empList);
|
|
|
|
//插入日志信息ID
|
|
string insLogId = Guid.NewGuid().ToString("N");
|
|
//插入日志记录
|
|
InsLog(new TblSysEmpIccSyncLogMo() { ID = insLogId, EMP_ID = empList.Count + "", INFO_TYPE = "5", POST_URL = IccEmpInfoDelUrl + "?" + paramStr });
|
|
|
|
//调用接口同步数据并获取返回值
|
|
//var retStr = WebCommonUtil.PostWebRequest(IccEmpInfoDelUrl, paramStr);
|
|
var retStr = WebCommonUtil.GetPostUrl(IccEmpInfoDelUrl + "?" + paramStr);
|
|
|
|
EmpSyncIccReturnMo postRetMo = JsonHelper.FromJSON<EmpSyncIccReturnMo>(retStr);
|
|
|
|
////更新调用接口返回结果到日志记录
|
|
UpdLog(new TblSysEmpIccSyncLogMo() { ID = insLogId, POST_RETURN_MSG = retStr, POST_RETURN_CODE = postRetMo.code });
|
|
|
|
//信息更新状态:0、初始状态;1、提交(同步中);2、成功;3、失败;
|
|
string Upd_State = "3";
|
|
//验证返回数据
|
|
switch (postRetMo.code)
|
|
{
|
|
//正常
|
|
case "200":
|
|
//更新同步状态为正常
|
|
Upd_State = "2";
|
|
break;
|
|
}
|
|
// 更新状态表信息
|
|
string sqlUpd = " update tbl_sys_emp_icc_sync_state set Upd_State='" + Upd_State + "',Upd_Time=now(),Operat_Type='2',Info_Msg='" +
|
|
postRetMo.code + "' where EMP_ID in (" + empStr + ") and INFO_TYPE='1' ";
|
|
//执行更新
|
|
MySqlHelper.Execute(sqlUpd);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
string str = "Web请求异常:" + ex;
|
|
FangYar.Common.MyLogHelper.WriteMsg(new FangYar.Common.LogInfoMo()
|
|
{
|
|
message = str,
|
|
msgType = FangYar.Common.EnumLogMsgTypeEnum.Error,
|
|
path = "EmpSyncICC"
|
|
});
|
|
}
|
|
//}).Start();
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region 人脸信息操作
|
|
|
|
|
|
/// <summary>
|
|
/// 人脸信息添加
|
|
/// </summary>
|
|
/// <param name="eid"></param>
|
|
public static void EmpImgAdd(string eid)
|
|
{
|
|
//new Thread(() =>
|
|
//{
|
|
try
|
|
{
|
|
//拼接数据查询sql
|
|
string sql = " SELECT * from tbl_sys_emp_icc_sync_state WHERE EMP_ID='" + eid + "' and INFO_TYPE='3' ";
|
|
//查询数据
|
|
var dtq = MySqlHelper.QueryTable(sql);
|
|
//判断数据是否存在
|
|
if (dtq.Rows.Count == 0)
|
|
{
|
|
//不存在,新增一条数据
|
|
string sqlIns = " insert into tbl_sys_emp_icc_sync_state (ID,EMP_ID,Device_Code,Upd_State,INFO_TYPE,Operat_Type) VALUES ('" + Guid.NewGuid().ToString("N") +
|
|
"','" + eid + "','','1','3','0') ";
|
|
//执行插入
|
|
MySqlHelper.Execute(sqlIns);
|
|
}
|
|
//查询数据
|
|
var mo = GetEmpSyncIccByEid(eid);
|
|
// 拼接调用同步接口参数
|
|
string paramStr = "userId=" + eid + "&deptId=" + mo.ORG_ID;
|
|
|
|
//插入日志信息ID
|
|
string insLogId = Guid.NewGuid().ToString("N");
|
|
//插入日志记录
|
|
InsLog(new TblSysEmpIccSyncLogMo() { ID = insLogId, EMP_ID = eid, INFO_TYPE = "0", POST_URL = IccEmpImgAddUrl + "?" + paramStr });
|
|
|
|
//调用接口同步数据并获取返回值
|
|
//var retStr = WebCommonUtil.PostWebRequest(IccEmpImgAddUrl, paramStr);
|
|
var retStr = WebCommonUtil.GetPostUrl(IccEmpImgAddUrl + "?" + paramStr);
|
|
|
|
EmpSyncIccReturnMo postRetMo = JsonHelper.FromJSON<EmpSyncIccReturnMo>(retStr);
|
|
|
|
//更新调用接口返回结果到日志记录
|
|
UpdLog(new TblSysEmpIccSyncLogMo() { ID = insLogId, POST_RETURN_MSG = retStr, POST_RETURN_CODE = postRetMo.code });
|
|
|
|
//信息更新状态:0、初始状态;1、提交(同步中);2、成功;3、失败;
|
|
string Upd_State = "3";
|
|
//验证返回数据
|
|
switch (postRetMo.code)
|
|
{
|
|
//正常
|
|
case "200":
|
|
//更新同步状态为正常
|
|
Upd_State = "2";
|
|
break;
|
|
default:
|
|
//同步失败,调用更新
|
|
EmpImgUpd(eid);
|
|
break;
|
|
}
|
|
// 更新状态表信息
|
|
string sqlUpd = " update tbl_sys_emp_icc_sync_state set Upd_State='" + Upd_State + "',Upd_Time=now(),Operat_Type='0',Info_Msg='" +
|
|
postRetMo.code + "' where EMP_ID='" + eid + "' and INFO_TYPE='3' ";
|
|
//执行更新
|
|
MySqlHelper.Execute(sqlUpd);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
string str = "Web请求异常:" + ex;
|
|
FangYar.Common.MyLogHelper.WriteMsg(new FangYar.Common.LogInfoMo()
|
|
{
|
|
message = str,
|
|
msgType = FangYar.Common.EnumLogMsgTypeEnum.Error,
|
|
path = "EmpSyncICC"
|
|
});
|
|
}
|
|
//}).Start();
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 人脸信息修改
|
|
/// </summary>
|
|
/// <param name="eid"></param>
|
|
public static void EmpImgUpd(string eid)
|
|
{
|
|
//new Thread(() =>
|
|
//{
|
|
try
|
|
{
|
|
//拼接数据查询sql
|
|
string sql = " SELECT * from tbl_sys_emp_icc_sync_state WHERE EMP_ID='" + eid + "' and INFO_TYPE='3' ";
|
|
//查询数据
|
|
var dtq = MySqlHelper.QueryTable(sql);
|
|
//判断数据是否存在
|
|
if (dtq.Rows.Count == 0)
|
|
{
|
|
//不存在,新增一条数据
|
|
string sqlIns = " insert into tbl_sys_emp_icc_sync_state (ID,EMP_ID,Device_Code,Upd_State,INFO_TYPE,Operat_Type) VALUES ('" + Guid.NewGuid().ToString("N") +
|
|
"','" + eid + "','','1','3','1') ";
|
|
//执行插入
|
|
MySqlHelper.Execute(sqlIns);
|
|
}
|
|
|
|
//查询数据
|
|
var mo = GetEmpSyncIccByEid(eid);
|
|
// 拼接调用同步接口参数
|
|
string paramStr = "userId=" + eid + "&deptId=" + mo.ORG_ID;
|
|
|
|
//插入日志信息ID
|
|
string insLogId = Guid.NewGuid().ToString("N");
|
|
//插入日志记录
|
|
InsLog(new TblSysEmpIccSyncLogMo() { ID = insLogId, EMP_ID = eid, INFO_TYPE = "1", POST_URL = IccEmpImgUpdUrl + "?" + paramStr });
|
|
|
|
//调用接口同步数据并获取返回值
|
|
//var retStr = WebCommonUtil.PostWebRequest(IccEmpImgUpdUrl, paramStr);
|
|
var retStr = WebCommonUtil.GetPostUrl(IccEmpImgUpdUrl + "?" + paramStr);
|
|
|
|
EmpSyncIccReturnMo postRetMo = JsonHelper.FromJSON<EmpSyncIccReturnMo>(retStr);
|
|
|
|
//更新调用接口返回结果到日志记录
|
|
UpdLog(new TblSysEmpIccSyncLogMo() { ID = insLogId, POST_RETURN_MSG = retStr, POST_RETURN_CODE = postRetMo.code });
|
|
|
|
//信息更新状态:0、初始状态;1、提交(同步中);2、成功;3、失败;
|
|
string Upd_State = "3";
|
|
//验证返回数据
|
|
switch (postRetMo.code)
|
|
{
|
|
//正常
|
|
case "200":
|
|
//更新同步状态为正常
|
|
Upd_State = "2";
|
|
break;
|
|
}
|
|
// 更新状态表信息
|
|
string sqlUpd = " update tbl_sys_emp_icc_sync_state set Upd_State='" + Upd_State + "',Upd_Time=now(),Operat_Type='1',Info_Msg='" +
|
|
postRetMo.code + "' where EMP_ID='" + eid + "' and INFO_TYPE='3' ";
|
|
//执行更新
|
|
MySqlHelper.Execute(sqlUpd);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
string str = "Web请求异常:" + ex;
|
|
FangYar.Common.MyLogHelper.WriteMsg(new FangYar.Common.LogInfoMo()
|
|
{
|
|
message = str,
|
|
msgType = FangYar.Common.EnumLogMsgTypeEnum.Error,
|
|
path = "EmpSyncICC"
|
|
});
|
|
}
|
|
//}).Start();
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 人脸信息删除
|
|
/// </summary>
|
|
/// <param name="eid"></param>
|
|
public static void EmpImgDel(string eid)
|
|
{
|
|
//new Thread(() =>
|
|
//{
|
|
try
|
|
{
|
|
//拼接数据查询sql
|
|
string sql = " SELECT * from tbl_sys_emp_icc_sync_state WHERE EMP_ID='" + eid + "' and INFO_TYPE='3' ";
|
|
//查询数据
|
|
var dtq = MySqlHelper.QueryTable(sql);
|
|
//判断数据是否存在
|
|
if (dtq.Rows.Count == 0)
|
|
{
|
|
//不存在,新增一条数据
|
|
string sqlIns = " insert into tbl_sys_emp_icc_sync_state (ID,EMP_ID,Device_Code,Upd_State,INFO_TYPE,Operat_Type) VALUES ('" + Guid.NewGuid().ToString("N") +
|
|
"','" + eid + "','','1','3','2') ";
|
|
//执行插入
|
|
MySqlHelper.Execute(sqlIns);
|
|
}
|
|
|
|
//查询数据
|
|
var mo = GetEmpSyncIccByEid(eid);
|
|
// 拼接调用同步接口参数
|
|
string paramStr = "userId=" + eid + "&deptId=" + mo.ORG_ID;
|
|
|
|
//插入日志信息ID
|
|
string insLogId = Guid.NewGuid().ToString("N");
|
|
//插入日志记录
|
|
InsLog(new TblSysEmpIccSyncLogMo() { ID = insLogId, EMP_ID = eid, INFO_TYPE = "2", POST_URL = IccEmpImgDelUrl + "?" + paramStr });
|
|
|
|
//调用接口同步数据并获取返回值
|
|
//var retStr = WebCommonUtil.PostWebRequest(IccEmpImgDelUrl, paramStr);
|
|
var retStr = WebCommonUtil.GetPostUrl(IccEmpImgDelUrl + "?" + paramStr);
|
|
//返回数据转对象
|
|
EmpSyncIccReturnMo postRetMo = JsonHelper.FromJSON<EmpSyncIccReturnMo>(retStr);
|
|
//更新调用接口返回结果到日志记录
|
|
UpdLog(new TblSysEmpIccSyncLogMo() { ID = insLogId, POST_RETURN_MSG = retStr, POST_RETURN_CODE = postRetMo.code });
|
|
|
|
|
|
|
|
//信息更新状态:0、初始状态;1、提交(同步中);2、成功;3、失败;
|
|
string Upd_State = "3";
|
|
//验证返回数据
|
|
switch (postRetMo.code)
|
|
{
|
|
//正常
|
|
case "200":
|
|
//更新同步状态为正常
|
|
Upd_State = "2";
|
|
break;
|
|
}
|
|
// 更新状态表信息
|
|
string sqlUpd = " update tbl_sys_emp_icc_sync_state set Upd_State='" + Upd_State + "',Upd_Time=now(),Operat_Type='2',Info_Msg='" +
|
|
postRetMo.code + "' where EMP_ID='" + eid + "' and INFO_TYPE='3' ";
|
|
//执行更新
|
|
MySqlHelper.Execute(sqlUpd);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
string str = "Web请求异常:" + ex;
|
|
FangYar.Common.MyLogHelper.WriteMsg(new FangYar.Common.LogInfoMo()
|
|
{
|
|
message = str,
|
|
msgType = FangYar.Common.EnumLogMsgTypeEnum.Error,
|
|
path = "EmpSyncICC"
|
|
});
|
|
}
|
|
//}).Start();
|
|
}
|
|
|
|
///// <summary>
|
|
///// 批量人脸信息删除
|
|
///// </summary>
|
|
///// <param name="empList">人员信息集合</param>
|
|
///// <param name="orgId">机构信息ID</param>
|
|
//public static void EmpImgDelByEmpList(List<string> empList, string orgId)
|
|
//{
|
|
// //new Thread(() =>
|
|
// //{
|
|
// try
|
|
// {
|
|
|
|
// string empStr = GetListConvertStr(empList);
|
|
|
|
// //拼接数据删除sql
|
|
// string sql = " DELETE FROM tbl_sys_emp_icc_sync_state WHERE EMP_ID in (" + empStr + ") and INFO_TYPE='3' ";
|
|
// //执行删除信息状态
|
|
// MySqlHelper.Execute(sql);
|
|
|
|
// //拼接添加数据Sql
|
|
// string sqlIns = " insert into tbl_sys_emp_icc_sync_state (ID,EMP_ID,Device_Code,Upd_State,INFO_TYPE,Operat_Type) " +
|
|
// " SELECT UUID(),ID,'','1','3','2' FROM tbl_sys_emp WHERE ID in (" + empStr + ") ";
|
|
// //执行数据插入
|
|
// MySqlHelper.Execute(sqlIns);
|
|
|
|
|
|
// // 拼接调用同步接口参数
|
|
// string paramStr = "userId=" + string.Join(",", empList) + "&deptId=" + orgId;
|
|
|
|
// //插入日志信息ID
|
|
// string insLogId = Guid.NewGuid().ToString("N");
|
|
// //插入日志记录
|
|
// InsLog(new TblSysEmpIccSyncLogMo() { ID = insLogId, EMP_ID = empList.Count + "", INFO_TYPE = "2", POST_URL = IccEmpImgDelUrl + "?" + paramStr });
|
|
|
|
// //调用接口同步数据并获取返回值
|
|
// //var retStr = WebCommonUtil.PostWebRequest(IccEmpImgDelUrl, paramStr);
|
|
// var retStr = WebCommonUtil.GetPostUrl(IccEmpImgDelUrl + "?" + paramStr);
|
|
// //返回数据转对象
|
|
// EmpSyncIccReturnMo postRetMo = JsonHelper.FromJSON<EmpSyncIccReturnMo>(retStr);
|
|
// //更新调用接口返回结果到日志记录
|
|
// UpdLog(new TblSysEmpIccSyncLogMo() { ID = insLogId, POST_RETURN_MSG = retStr, POST_RETURN_CODE = postRetMo.code });
|
|
|
|
|
|
|
|
// //信息更新状态:0、初始状态;1、提交(同步中);2、成功;3、失败;
|
|
// string Upd_State = "3";
|
|
// //验证返回数据
|
|
// switch (postRetMo.code)
|
|
// {
|
|
// //正常
|
|
// case "200":
|
|
// //更新同步状态为正常
|
|
// Upd_State = "2";
|
|
// break;
|
|
// }
|
|
// // 更新状态表信息
|
|
// string sqlUpd = " update tbl_sys_emp_icc_sync_state set Upd_State='" + Upd_State + "',Upd_Time=now(),Operat_Type='2',Info_Msg='" +
|
|
// postRetMo.code + "' where EMP_ID in (" + empStr + ") and INFO_TYPE='3' ";
|
|
// //执行更新
|
|
// MySqlHelper.Execute(sqlUpd);
|
|
// }
|
|
// catch (Exception ex)
|
|
// {
|
|
// string str = "Web请求异常:" + ex;
|
|
// FangYar.Common.MyLogHelper.WriteMsg(new FangYar.Common.LogInfoMo()
|
|
// {
|
|
// message = str,
|
|
// msgType = FangYar.Common.EnumLogMsgTypeEnum.Error,
|
|
// path = "EmpSyncICC"
|
|
// });
|
|
// }
|
|
// //}).Start();
|
|
//}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 人员门禁信息操作
|
|
/// <summary>
|
|
/// 人员门禁信息同步
|
|
/// </summary>
|
|
/// <param name="eid"></param>
|
|
public static void EmpDoorSync(string eid)
|
|
{
|
|
//new Thread(() =>
|
|
//{
|
|
try
|
|
{
|
|
|
|
//查询数据
|
|
var mo = GetEmpSyncIccByEid(eid);
|
|
// 拼接调用同步接口参数
|
|
string paramStr = "userIds=" + eid + "&deviceIds=" + mo.Devices;
|
|
|
|
//插入日志信息ID
|
|
string insLogId = Guid.NewGuid().ToString("N");
|
|
//插入日志记录
|
|
InsLog(new TblSysEmpIccSyncLogMo() { ID = insLogId, EMP_ID = eid, INFO_TYPE = "6", POST_URL = IccEmpDoorSync + "?" + paramStr });
|
|
|
|
//调用接口同步数据并获取返回值
|
|
//var retStr = WebCommonUtil.PostWebRequest(IccEmpDoorSync, paramStr);
|
|
var retStr = WebCommonUtil.GetPostUrl(IccEmpDoorSync + "?" + paramStr);
|
|
|
|
EmpSyncIccReturnMo postRetMo = JsonHelper.FromJSON<EmpSyncIccReturnMo>(retStr);
|
|
|
|
//更新调用接口返回结果到日志记录
|
|
UpdLog(new TblSysEmpIccSyncLogMo() { ID = insLogId, POST_RETURN_MSG = retStr, POST_RETURN_CODE = postRetMo.code });
|
|
|
|
|
|
List<string> SQLStringList = new List<string>();
|
|
var doorArr = mo.Devices.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
|
|
foreach (var item in doorArr)
|
|
{
|
|
//拼接数据查询sql
|
|
string sql = " SELECT * from tbl_sys_emp_icc_sync_state WHERE EMP_ID='" + eid + "' and INFO_TYPE='2' and Device_Code='" + item + "' ";
|
|
//查询数据
|
|
var dtq = MySqlHelper.QueryTable(sql);
|
|
//判断数据是否存在
|
|
if (dtq.Rows.Count == 0)
|
|
{
|
|
//不存在,新增一条数据
|
|
string sqlIns = " insert into tbl_sys_emp_icc_sync_state (ID,EMP_ID,Device_Code,Upd_State,INFO_TYPE,Operat_Type) VALUES ('" + Guid.NewGuid().ToString("N") +
|
|
"','" + eid + "','" + item + "','1','2','0') ";
|
|
SQLStringList.Add(sqlIns);
|
|
}
|
|
else
|
|
{
|
|
string sqlUpd = " update tbl_sys_emp_icc_sync_state set Upd_State='1',Upd_Time=now(),Operat_Type='0',Info_Msg='' where EMP_ID='" + eid +
|
|
"' and INFO_TYPE='2'and Device_Code='" + item + "' ";
|
|
SQLStringList.Add(sqlUpd);
|
|
}
|
|
}
|
|
//执行插入
|
|
MySqlHelper.ExecuteSqlTran(SQLStringList);
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
string str = "Web请求异常:" + ex;
|
|
FangYar.Common.MyLogHelper.WriteMsg(new FangYar.Common.LogInfoMo()
|
|
{
|
|
message = str,
|
|
msgType = FangYar.Common.EnumLogMsgTypeEnum.Error,
|
|
path = "EmpSyncICC"
|
|
});
|
|
}
|
|
//}).Start();
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// 人员门禁信息删除
|
|
/// </summary>
|
|
/// <param name="eid"></param>
|
|
public static void EmpDoorDel(string eid)
|
|
{
|
|
//new Thread(() =>
|
|
//{
|
|
try
|
|
{
|
|
|
|
//查询数据
|
|
var mo = GetEmpSyncIccByEid(eid);
|
|
// 拼接调用同步接口参数
|
|
string paramStr = "userIds=" + eid + "&deviceIds=";
|
|
|
|
//插入日志信息ID
|
|
string insLogId = Guid.NewGuid().ToString("N");
|
|
//插入日志记录
|
|
InsLog(new TblSysEmpIccSyncLogMo() { ID = insLogId, EMP_ID = eid, INFO_TYPE = "8", POST_URL = IccEmpDoorSync + "?" + paramStr });
|
|
|
|
//调用接口同步数据并获取返回值
|
|
//var retStr = WebCommonUtil.PostWebRequest(IccEmpDoorSync, paramStr);
|
|
var retStr = WebCommonUtil.GetPostUrl(IccEmpDoorSync + "?" + paramStr);
|
|
|
|
EmpSyncIccReturnMo postRetMo = JsonHelper.FromJSON<EmpSyncIccReturnMo>(retStr);
|
|
|
|
//更新调用接口返回结果到日志记录
|
|
UpdLog(new TblSysEmpIccSyncLogMo() { ID = insLogId, POST_RETURN_MSG = retStr, POST_RETURN_CODE = postRetMo.code });
|
|
|
|
List<string> SQLStringList = new List<string>();
|
|
var doorArr = mo.Devices.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
|
|
foreach (var item in doorArr)
|
|
{
|
|
//拼接数据查询sql
|
|
string sql = " SELECT * from tbl_sys_emp_icc_sync_state WHERE EMP_ID='" + eid + "' and INFO_TYPE='2' and Device_Code='" + item + "' ";
|
|
//查询数据
|
|
var dtq = MySqlHelper.QueryTable(sql);
|
|
//判断数据是否存在
|
|
if (dtq.Rows.Count == 0)
|
|
{
|
|
//不存在,新增一条数据
|
|
string sqlIns = " insert into tbl_sys_emp_icc_sync_state (ID,EMP_ID,Device_Code,Upd_State,INFO_TYPE,Operat_Type) VALUES ('" + Guid.NewGuid().ToString("N") +
|
|
"','" + eid + "','" + item + "','1','2','2') ";
|
|
SQLStringList.Add(sqlIns);
|
|
}
|
|
else
|
|
{
|
|
string sqlUpd = " update tbl_sys_emp_icc_sync_state set Upd_State='1',Upd_Time=now(),Operat_Type='2',Info_Msg='' where EMP_ID='" + eid +
|
|
"' and INFO_TYPE='2'and Device_Code='" + item + "' ";
|
|
SQLStringList.Add(sqlUpd);
|
|
}
|
|
}
|
|
//执行插入
|
|
MySqlHelper.ExecuteSqlTran(SQLStringList);
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
string str = "Web请求异常:" + ex;
|
|
FangYar.Common.MyLogHelper.WriteMsg(new FangYar.Common.LogInfoMo()
|
|
{
|
|
message = str,
|
|
msgType = FangYar.Common.EnumLogMsgTypeEnum.Error,
|
|
path = "EmpSyncICC"
|
|
});
|
|
}
|
|
//}).Start();
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region 根据人员信息ID获取同步信息
|
|
private static EmpSyncIccMo GetEmpSyncIccByEid(string eid)
|
|
{
|
|
EmpSyncIccMo retMo = new EmpSyncIccMo();
|
|
try
|
|
{
|
|
string sqlStr = "SELECT ID,ORG_ID,(SELECT GROUP_CONCAT(EPUIP_ID) from tbl_epuip_org eo WHERE e.ORG_ID=eo.ORG_ID and EXTEND2='0') Devices from tbl_sys_emp e WHERE ID='" + eid + "'";
|
|
var dt = MySqlHelper.QueryTable(sqlStr);
|
|
if (dt.Rows.Count > 0)
|
|
{
|
|
retMo = new EmpSyncIccMo()
|
|
{
|
|
ID = dt.Rows[0]["ID"] + "",
|
|
ORG_ID = dt.Rows[0]["ORG_ID"] + "",
|
|
Devices = dt.Rows[0]["Devices"] + "",
|
|
|
|
//ORG_ID = "1cc32e7245694343b1e5ff41014eee74",
|
|
//Devices = "1000040,1000318",
|
|
};
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
string str = "根据ID获取对象异常:" + ex;
|
|
FangYar.Common.MyLogHelper.WriteMsg(new FangYar.Common.LogInfoMo()
|
|
{
|
|
message = str,
|
|
msgType = FangYar.Common.EnumLogMsgTypeEnum.Error,
|
|
path = "EmpSyncICC"
|
|
});
|
|
}
|
|
return retMo;
|
|
}
|
|
|
|
#endregion
|
|
|
|
/// <summary>
|
|
/// 人员同步请求ICC日志信息插入
|
|
/// </summary>
|
|
/// <param name="mo"></param>
|
|
public static void InsLog(TblSysEmpIccSyncLogMo mo)
|
|
{
|
|
try
|
|
{
|
|
if (mo != null)
|
|
{
|
|
//信息类型:0、人像库新增;1、人像库修改;2、人像库删除;3、icc人员新增;4、icc人员修改;5、icc人员删除;6、门禁授权新增;7、门禁授权修改;8、门禁授权删除;
|
|
switch (mo.INFO_TYPE)
|
|
{
|
|
case "0":
|
|
mo.INFO_TYPE_STR = "人像库新增";
|
|
break;
|
|
case "1":
|
|
mo.INFO_TYPE_STR = "人像库修改";
|
|
break;
|
|
case "2":
|
|
mo.INFO_TYPE_STR = "人像库删除";
|
|
break;
|
|
case "3":
|
|
mo.INFO_TYPE_STR = "icc人员新增";
|
|
break;
|
|
case "4":
|
|
mo.INFO_TYPE_STR = "icc人员修改";
|
|
break;
|
|
case "5":
|
|
mo.INFO_TYPE_STR = "icc人员删除";
|
|
break;
|
|
case "6":
|
|
mo.INFO_TYPE_STR = "门禁授权新增";
|
|
break;
|
|
case "7":
|
|
mo.INFO_TYPE_STR = "门禁授权修改";
|
|
break;
|
|
case "8":
|
|
mo.INFO_TYPE_STR = "门禁授权删除";
|
|
break;
|
|
}
|
|
//返回结果插入到日志表
|
|
string sqlInsLog = " insert into tbl_sys_emp_icc_sync_log (ID,EMP_ID,INFO_TYPE,INFO_TYPE_STR,POST_URL) VALUES ('" + mo.ID +
|
|
"','" + mo.EMP_ID + "','" + mo.INFO_TYPE + "','" + mo.INFO_TYPE_STR + "','" + mo.POST_URL + "') ";
|
|
//执行插入
|
|
MySqlHelper.Execute(sqlInsLog);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
string str = "插入日志信息异常:" + ex;
|
|
FangYar.Common.MyLogHelper.WriteMsg(new FangYar.Common.LogInfoMo()
|
|
{
|
|
message = str,
|
|
msgType = FangYar.Common.EnumLogMsgTypeEnum.Error,
|
|
path = "EmpSyncICC"
|
|
});
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 人员同步请求ICC日志信息更新
|
|
/// </summary>
|
|
/// <param name="mo"></param>
|
|
public static void UpdLog(TblSysEmpIccSyncLogMo mo)
|
|
{
|
|
try
|
|
{
|
|
if (mo != null)
|
|
{
|
|
//返回结果插入到日志表
|
|
string sqlInsLog = " update tbl_sys_emp_icc_sync_log set POST_RETURN_CODE = '" + mo.POST_RETURN_CODE + "',POST_RETURN_MSG='" + mo.POST_RETURN_MSG +
|
|
"',POST_RETURN_TIME=now() where id='" + mo.ID + "' ";
|
|
//执行插入
|
|
MySqlHelper.Execute(sqlInsLog);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
string str = "更新日志信息异常:" + ex;
|
|
FangYar.Common.MyLogHelper.WriteMsg(new FangYar.Common.LogInfoMo()
|
|
{
|
|
message = str,
|
|
msgType = FangYar.Common.EnumLogMsgTypeEnum.Error,
|
|
path = "EmpSyncICC"
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// 人员ID集合转In查询条件字符串
|
|
/// </summary>
|
|
/// <param name="list"></param>
|
|
/// <returns></returns>
|
|
private static string GetListConvertStr(List<string> list)
|
|
{
|
|
string retStr = "";
|
|
retStr = "'" + string.Join("','", list) + "'";
|
|
if (string.IsNullOrWhiteSpace(retStr))
|
|
{
|
|
retStr = "''";
|
|
}
|
|
return retStr;
|
|
}
|
|
|
|
}
|
|
/// <summary>
|
|
/// 营区人员同步ICC
|
|
/// </summary>
|
|
public class EmpSyncIccMo
|
|
{
|
|
/// <summary>
|
|
/// 信息ID
|
|
/// </summary>
|
|
public string ID { get; set; }
|
|
|
|
/// <summary>
|
|
/// 机构ID
|
|
/// </summary>
|
|
public string ORG_ID { get; set; }
|
|
|
|
/// <summary>
|
|
/// 设备集合
|
|
/// </summary>
|
|
public string Devices { get; set; }
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 提交数据返回模型
|
|
/// </summary>
|
|
public class EmpSyncIccReturnMo
|
|
{
|
|
/// <summary>
|
|
/// 返回编码:200、正常;400、错误;500、异常;
|
|
/// </summary>
|
|
public string code { get; set; }
|
|
/// <summary>
|
|
/// 结果:true、成功;;false、失败
|
|
/// </summary>
|
|
public string success { get; set; }
|
|
/// <summary>
|
|
/// 返回数据
|
|
/// </summary>
|
|
public object data { get; set; }
|
|
/// <summary>
|
|
/// 返回消息
|
|
/// </summary>
|
|
public string msg { get; set; }
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 营区人员ICC信息同步操作日志
|
|
/// </summary>
|
|
public class TblSysEmpIccSyncLogMo
|
|
{
|
|
/// <summary>
|
|
/// 信息ID
|
|
/// </summary>
|
|
public string ID { get; set; }
|
|
/// <summary>
|
|
/// 人员信息ID
|
|
/// </summary>
|
|
public string EMP_ID { get; set; }
|
|
/// <summary>
|
|
/// 调用更新后返回内容
|
|
/// </summary>
|
|
public string POST_RETURN_MSG { get; set; }
|
|
/// <summary>
|
|
/// 信息类型:0、人像库新增;1、人像库修改;2、人像库删除;3、icc人员新增;4、icc人员修改;5、icc人员删除;6、门禁授权新增;7、门禁授权修改;8、门禁授权删除;
|
|
/// </summary>
|
|
public string INFO_TYPE { get; set; }
|
|
/// <summary>
|
|
/// 提交返回状态码:200:正常;400:错误;500:异常;
|
|
/// </summary>
|
|
public string POST_RETURN_CODE { get; set; }
|
|
/// <summary>
|
|
/// 信息创建时间
|
|
/// </summary>
|
|
public string createtime { get; set; }
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public string Device_Code { get; set; }
|
|
/// <summary>
|
|
/// 请求信息路径
|
|
/// </summary>
|
|
public string POST_URL { get; set; }
|
|
/// <summary>
|
|
/// 请求信息返回时间
|
|
/// </summary>
|
|
public string POST_RETURN_TIME { get; set; }
|
|
/// <summary>
|
|
/// 请求信息操作中文:0、人像库新增;1、人像库修改;2、人像库删除;3、icc人员新增;4、icc人员修改;5、icc人员删除;6、门禁授权新增;7、门禁授权修改;8、门禁授权删除;
|
|
/// </summary>
|
|
public string INFO_TYPE_STR { get; set; }
|
|
|
|
}
|
|
|
|
}
|
|
|