From 92758a760a9b8612f264ff9d8897feae962c6c34 Mon Sep 17 00:00:00 2001
From: HK <461671400@qq.com>
Date: Mon, 10 May 2021 12:08:18 +0800
Subject: [PATCH] =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E4=BF=AE=E6=94=B9?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../Duty/RB_Duty_PlanDetails_ViewModel.cs     |  4 +-
 Edu.Module.Duty/DutyPlanModule.cs             | 42 ++++++++++++++++++-
 .../Controllers/Duty/DutyPlanController.cs    |  9 ++--
 Edu.WebApi/Timers/TimerJobj.cs                | 19 ++++++++-
 4 files changed, 65 insertions(+), 9 deletions(-)

diff --git a/Edu.Model/ViewModel/Duty/RB_Duty_PlanDetails_ViewModel.cs b/Edu.Model/ViewModel/Duty/RB_Duty_PlanDetails_ViewModel.cs
index 05bc5b62..1e11a1cd 100644
--- a/Edu.Model/ViewModel/Duty/RB_Duty_PlanDetails_ViewModel.cs
+++ b/Edu.Model/ViewModel/Duty/RB_Duty_PlanDetails_ViewModel.cs
@@ -82,7 +82,7 @@ namespace Edu.Model.ViewModel.Duty
             get
             {
                 string str = Common.ConvertHelper.FormatTimeStr(this.CheckTime);
-                if (str == "")
+                if (str == "" || str == "00:00")
                 {
                     str = "未打卡";
                 }
@@ -98,7 +98,7 @@ namespace Edu.Model.ViewModel.Duty
             get
             {
                 string str = Common.ConvertHelper.FormatTimeStr(this.FinishTime);
-                if (str == "")
+                if ( str == "" || str == "00:00")
                 {
                     str = "未打卡";
                 }
diff --git a/Edu.Module.Duty/DutyPlanModule.cs b/Edu.Module.Duty/DutyPlanModule.cs
index e2896fd1..d6686621 100644
--- a/Edu.Module.Duty/DutyPlanModule.cs
+++ b/Edu.Module.Duty/DutyPlanModule.cs
@@ -491,12 +491,30 @@ namespace Edu.Module.Duty
                 result.Add("Id", model?.Id);
                 result.Add("PlanDate", Common.ConvertHelper.FormatDate(model?.Date));
                 result.Add("WeekDay", Common.ConvertHelper.GetWeekDay(model?.Date));
+
                 result.Add("CheckTime", currentModel?.CheckTimeStr);
                 result.Add("CheckLateTime", currentModel?.CheckLateTime);
-                result.Add("CheckLateTimeStr", (currentModel?.CheckLateTime > 0 ? string.Format("[迟到{0}分钟]", currentModel.CheckLateTime) : "[正常]"));
+                if (currentModel?.CheckTimeStr != "未打卡")
+                {
+                    result.Add("CheckLateTimeStr", (currentModel?.CheckLateTime > 0 ? string.Format("[迟到{0}分钟]", currentModel.CheckLateTime) : "[正常]"));
+                }
+                else
+                {
+                    result.Add("CheckLateTimeStr", "");
+                }
+                
                 result.Add("FinishTime", currentModel?.FinishTimeStr);
                 result.Add("FinishLateTime", currentModel?.FinishLateTime);
-                result.Add("FinishLateTimeStr", (currentModel?.FinishLateTime > 0 ? string.Format("[早退{0}分钟]", currentModel.FinishLateTime) : "[正常]"));
+                if (currentModel?.FinishTimeStr != "未打卡")
+                {
+                    result.Add("FinishLateTimeStr", (currentModel?.FinishLateTime > 0 ? string.Format("[早退{0}分钟]", currentModel.FinishLateTime) : "[正常]"));
+                }
+                else
+                {
+                    result.Add("FinishLateTimeStr", "");
+
+                }
+                   
                 result.Add("SchoolName", model?.SchoolName);
                 result.Add("ShiftName", currentModel?.ShiftName);
                 result.Add("StartTime", currentModel?.StartTime);
@@ -914,6 +932,26 @@ namespace Edu.Module.Duty
             return flag;
         }
 
+        /// <summary>
+        /// 更新用户【值班完成】状态
+        /// </summary>
+        /// <param name="Id"></param>
+        /// <returns></returns>
+        public bool UpdateDutyFinishedModule(int Id)
+        {
+            Dictionary<string, object> fileds = new Dictionary<string, object>()
+            {
+                { nameof(RB_Duty_PlanDetails_ViewModel.Status), (int)DutyStatusEnum.DutyFinished },
+                { nameof(RB_Duty_PlanDetails_ViewModel.FinishTime), null},
+            };
+            List<WhereHelper> list = new List<WhereHelper>()
+            {
+                new WhereHelper(nameof(RB_Duty_PlanDetails_ViewModel.Id), Id),
+            };
+            var flag = duty_PlanDetailsRepository.Update(fileds, list);
+            return flag;
+        }
+
         /// <summary>
         /// 新增修改值班事项
         /// </summary>
diff --git a/Edu.WebApi/Controllers/Duty/DutyPlanController.cs b/Edu.WebApi/Controllers/Duty/DutyPlanController.cs
index 1c3ce2a1..6b021ad0 100644
--- a/Edu.WebApi/Controllers/Duty/DutyPlanController.cs
+++ b/Edu.WebApi/Controllers/Duty/DutyPlanController.cs
@@ -87,10 +87,10 @@ namespace Edu.WebApi.Controllers.Duty
                         qitem.StatusStr,
                         qitem.CheckTimeStr,
                         qitem.CheckLateTime,
-                        CheckLateTimeStr = (qitem.CheckLateTime > 0 ? string.Format("[迟到{0}分钟]", qitem.CheckLateTime) : "[正常]"),
+                        CheckLateTimeStr = (qitem.CheckTimeStr!="未打卡"?(  qitem.CheckLateTime > 0 ? string.Format("[迟到{0}分钟]", qitem.CheckLateTime) : "[正常]"):""),
                         qitem.FinishTimeStr,
                         qitem.FinishLateTime,
-                        FinishLateTimeStr = (qitem.FinishLateTime > 0 ? string.Format("[早退{0}分钟]", qitem.FinishLateTime) : "[正常]"),
+                        FinishLateTimeStr = (qitem.FinishTimeStr!="未打卡"?(qitem.FinishLateTime > 0 ? string.Format("[早退{0}分钟]", qitem.FinishLateTime) : "[正常]"):""),
                     })
                 });
             }
@@ -170,10 +170,11 @@ namespace Edu.WebApi.Controllers.Duty
                     item.TotalHandoverCount,
                     currentModel.CheckTimeStr,
                     currentModel.CheckLateTime,
-                    CheckLateTimeStr = (currentModel.CheckLateTime > 0 ? string.Format("[迟到{0}分钟]", currentModel.CheckLateTime) : "[正常]"),
+                    CheckLateTimeStr = (currentModel.CheckTimeStr != "未打卡" ? (currentModel.CheckLateTime > 0 ? string.Format("[迟到{0}分钟]", currentModel.CheckLateTime) : "[正常]") : ""),
+
                     currentModel.FinishTimeStr,
                     currentModel.FinishLateTime,
-                    FinishLateTimeStr = (currentModel.FinishLateTime > 0 ? string.Format("[早退{0}分钟]", currentModel.FinishLateTime) : "[正常]"),
+                    FinishLateTimeStr = (currentModel.FinishTimeStr != "未打卡" ? (currentModel.FinishLateTime > 0 ? string.Format("[早退{0}分钟]", currentModel.FinishLateTime) : "[正常]") : ""),
                 });
             }
             pageModel.Count = rowsCount;
diff --git a/Edu.WebApi/Timers/TimerJobj.cs b/Edu.WebApi/Timers/TimerJobj.cs
index ba98110e..48f49be3 100644
--- a/Edu.WebApi/Timers/TimerJobj.cs
+++ b/Edu.WebApi/Timers/TimerJobj.cs
@@ -22,7 +22,7 @@ namespace Edu.WebApi.Timers
             timer1.Enabled = true;
 
             timer2 = new System.Timers.Timer();
-            timer2.Interval = (1000 * 60) * (60*2); //2小时执行一次
+            timer2.Interval = (1000 * 60) * ( 1); //1小时执行一次
             timer2.Elapsed += new System.Timers.ElapsedEventHandler(DealDuty);
             timer2.Enabled = true;
         }
@@ -112,6 +112,23 @@ namespace Edu.WebApi.Timers
                         }
                     }
                 }
+
+                var list2= dutyPlanModule.GetDutyPlanPageModule(1, 20, out _, new Model.ViewModel.Duty.RB_Duty_Plan_ViewModel()
+                {
+                    QDutyStatus = 1,
+                    QEndDate = Common.ConvertHelper.FormatDate(DateTime.Now)
+                });
+                foreach (var item in list2)
+                {
+                    foreach (var subItem in item.PlanDetails)
+                    {
+                        var endTime = Convert.ToDateTime((Common.ConvertHelper.FormatDate(item.Date) + " " + subItem.EndTime)).AddHours(2);
+                        if (subItem.Status == Common.Enum.Duty.DutyStatusEnum.DutyIng && endTime < DateTime.Now)
+                        {
+                            dutyPlanModule.UpdateDutyFinishedModule(subItem.Id);
+                        }
+                    }
+                }
                 Interlocked.Exchange(ref inTimer2, 0);
             }
         }
-- 
2.18.1