This commit is contained in:
杨红卫 2021-07-14 19:57:50 +08:00
parent ff100e0b7b
commit 4f2057ccd3
5 changed files with 141 additions and 3 deletions

View File

@ -7,7 +7,6 @@ namespace BLL
{
public class RealNameMonitorService
{
#region 5
/// <summary>
/// 监视组件
@ -79,5 +78,83 @@ namespace BLL
}
}
#endregion
#region 5-
/// <summary>
/// 监视组件
/// </summary>
private static Timer InOutmessageTimer;
/// <summary>
/// 启动监视器,不一定能成功,根据系统设置决定对监视器执行的操作 系统启动5分钟
/// </summary>
public static void StartInOutMonitor()
{
if (InOutmessageTimer != null)
{
InOutmessageTimer.Stop();
InOutmessageTimer.Dispose();
InOutmessageTimer = null;
}
InOutmessageTimer = new Timer
{
AutoReset = true
};
InOutmessageTimer.Elapsed += new ElapsedEventHandler(PersonInOutProcess);
InOutmessageTimer.Interval = 1000 * 60 * 60;// 60分钟 60000 * adTimeJ;
InOutmessageTimer.Start();
}
/// <summary>
/// 流程确认 定时执行 系统启动5分钟
/// </summary>
/// <param name="sender">Timer组件</param>
/// <param name="e">事件参数</param>
private static void PersonInOutProcess(object sender, ElapsedEventArgs e)
{
try
{
var result = (from x in Funs.DB.RealName_PersonInOutNow
group x by new
{
x.ProjectId,
date = x.ChangeTime.Value.Date,
x.IdcardNumber,
x.IsIn
} into g
where g.Count() > 1
select new
{
g.First().ProjectId,
date = g.First().ChangeTime.Value.Date,
g.First().IdcardNumber,
g.First().IsIn
}).Distinct();
foreach (var item in result)
{
var getDateRecords = from x in Funs.DB.RealName_PersonInOutNow
where x.ProjectId == item.ProjectId && x.ChangeTime.Value >= item.date.Date && x.ChangeTime.Value < item.date.Date.AddDays(1)
&& x.IdcardNumber == item.IdcardNumber
select x;
DateTime? minChangeTime = getDateRecords.Where(x => x.IsIn == true).Min(x => x.ChangeTime);
DateTime? maxChangeTime = getDateRecords.Where(x => x.IsIn == false).Max(x => x.ChangeTime);
var getDeleteR = from x in getDateRecords
where (minChangeTime.HasValue && x.IsIn == true && x.ChangeTime != minChangeTime) ||
(maxChangeTime.HasValue && x.IsIn == false && x.ChangeTime != maxChangeTime)
select x;
if (getDeleteR.Count() > 0)
{
Funs.DB.RealName_PersonInOutNow.DeleteAllOnSubmit(getDeleteR);
Funs.DB.SubmitChanges();
}
}
}
catch (Exception ex)
{
}
}
#endregion
}
}

View File

@ -47,8 +47,9 @@
////实名制同步定时器
try
{
BLL.RealNameMonitorService.StartInOutMonitor();
if (ConfigurationManager.AppSettings["EnableRealName"] == "True")
{
{
BLL.RealNameMonitorService.StartMonitor();
}
}

View File

@ -78,6 +78,9 @@
<f:Button ID="btnAttendance" IconFont="_Link" runat="server" Text="推送考勤"
Hidden="true" OnClick="btnAttendance_Click">
</f:Button>
<f:Button ID="btnDataProcess" IconFont="_Refresh" runat="server" ToolTip="去重"
Hidden="true" OnClick="btnDataProcess_Click">
</f:Button>
</Items>
</f:Toolbar>
</Toolbars>

View File

@ -25,7 +25,10 @@ namespace FineUIPro.Web.ZHGL.RealName
this.drpProject.SelectedValue = this.CurrUser.LoginProjectId;
this.drpProject.Readonly = true;
}
if (this.CurrUser.UserId == Const.hfnbdId)
{
this.btnDataProcess.Hidden = false;
}
this.SetPage();
}
}
@ -297,5 +300,50 @@ namespace FineUIPro.Web.ZHGL.RealName
}
}
}
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnDataProcess_Click(object sender, EventArgs e)
{
var result = (from x in Funs.DB.RealName_PersonInOutNow
group x by new
{
x.ProjectId,
date = x.ChangeTime.Value.Date,
x.IdcardNumber,
x.IsIn
} into g
where g.Count() > 1
select new
{
g.First().ProjectId,
date = g.First().ChangeTime.Value.Date,
g.First().IdcardNumber,
g.First().IsIn
}).Distinct().Take(500);
foreach (var item in result)
{
var getDateRecords = from x in Funs.DB.RealName_PersonInOutNow
where x.ProjectId == item.ProjectId && x.ChangeTime.Value >= item.date.Date && x.ChangeTime.Value < item.date.Date.AddDays(1)
&& x.IdcardNumber == item.IdcardNumber
select x;
DateTime? minChangeTime = getDateRecords.Where(x => x.IsIn == true).Min(x=>x.ChangeTime);
DateTime? maxChangeTime = getDateRecords.Where(x => x.IsIn == false).Max(x => x.ChangeTime);
var getDeleteR = from x in getDateRecords
where (minChangeTime.HasValue && x.IsIn == true && x.ChangeTime != minChangeTime) ||
(maxChangeTime.HasValue && x.IsIn == false && x.ChangeTime != maxChangeTime)
select x;
if (getDeleteR.Count() > 0)
{
Funs.DB.RealName_PersonInOutNow.DeleteAllOnSubmit(getDeleteR);
Funs.DB.SubmitChanges();
}
}
Alert.ShowInTop("完成!", MessageBoxIcon.Success);
}
}
}

View File

@ -182,5 +182,14 @@ namespace FineUIPro.Web.ZHGL.RealName {
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::FineUIPro.Button btnAttendance;
/// <summary>
/// btnDataProcess 控件。
/// </summary>
/// <remarks>
/// 自动生成的字段。
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::FineUIPro.Button btnDataProcess;
}
}