From 1e02ddcd520c15fbcb11cc060dd3d00e183a6ce8 Mon Sep 17 00:00:00 2001 From: schangxiang@126.com <schangxiang@126.com> Date: 周六, 31 8月 2024 14:49:11 +0800 Subject: [PATCH] 定时删除表数据成功 --- DataCapture/iWare_SCADA_DataCapture/iWare_SCADA_BusinessLogical/DataCaptureHandlerV2/DeleteDataHandler.cs | 14 +++++++ DataCapture/iWare_SCADA_DataCapture/iWare_SCADA_BusinessLogical/Utils/ClearDataHandler.cs | 68 ++++++++++++++++++++++++++++++++++ DataCapture/iWare_SCADA_DataCapture/iWare_SCADA_BusinessLogical/iWare_SCADA_BusinessLogical.csproj | 1 3 files changed, 83 insertions(+), 0 deletions(-) diff --git a/DataCapture/iWare_SCADA_DataCapture/iWare_SCADA_BusinessLogical/DataCaptureHandlerV2/DeleteDataHandler.cs b/DataCapture/iWare_SCADA_DataCapture/iWare_SCADA_BusinessLogical/DataCaptureHandlerV2/DeleteDataHandler.cs index e099bf6..1ad9bbf 100644 --- a/DataCapture/iWare_SCADA_DataCapture/iWare_SCADA_BusinessLogical/DataCaptureHandlerV2/DeleteDataHandler.cs +++ b/DataCapture/iWare_SCADA_DataCapture/iWare_SCADA_BusinessLogical/DataCaptureHandlerV2/DeleteDataHandler.cs @@ -60,6 +60,7 @@ try { LogTextHelper.BatchDeleteLog(); + Log4NetHelper.WriteInfoLog(logType, $"瀹氭椂鍒犻櫎鏃ュ織鏁版嵁鎴愬姛锛�"); } catch (Exception ex) @@ -67,6 +68,19 @@ Log4NetHelper.WriteErrorLog(logType, $"瀹氭椂鍒犻櫎鏃ュ織鏁版嵁寮傚父锛�", ex); } + try + { + ClearDataHandler.Delete_WorkPieceInfoLog(-7); + + ClearDataHandler.Delete_WorkPieceLog(-7); + + Log4NetHelper.WriteInfoLog(logType, $"瀹氭椂鍒犻櫎琛ㄦ暟鎹垚鍔燂細"); + } + catch (Exception ex) + { + Log4NetHelper.WriteErrorLog(logType, $"瀹氭椂鍒犻櫎琛ㄦ暟鎹垚鍔燂細", ex); + } + //澶勭悊OP60鐨勬暟鎹� try diff --git a/DataCapture/iWare_SCADA_DataCapture/iWare_SCADA_BusinessLogical/Utils/ClearDataHandler.cs b/DataCapture/iWare_SCADA_DataCapture/iWare_SCADA_BusinessLogical/Utils/ClearDataHandler.cs new file mode 100644 index 0000000..88bf30f --- /dev/null +++ b/DataCapture/iWare_SCADA_DataCapture/iWare_SCADA_BusinessLogical/Utils/ClearDataHandler.cs @@ -0,0 +1,68 @@ +锘� +using iWare_SCADA_Model; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace iWare_SCADA_BusinessLogical.Utils +{ + public class ClearDataHandler + { + /// <summary> + /// 绉婚櫎XX澶╁墠鐨� WorkPieceInfoLog 鏁版嵁 + /// </summary> + /// <param name="edm"></param> + public static void Delete_WorkPieceInfoLog(int days) + { + try + { + using (DbModel edm = new DbModel()) + { + var queryTime = DateTime.Now.AddDays(-days); + + var removeList = edm.WorkPieceInfoLog.Where(x => x.CreatedTime <= queryTime).ToList(); + if (removeList != null && removeList.Count > 0) + { + edm.WorkPieceInfoLog.RemoveRange(removeList); + } + edm.SaveChanges(); + } + } + catch (Exception ex) + { + Log4NetHelper.WriteErrorLog(LogType.DeleteData, "绉婚櫎XX澶╁墠鐨� WorkPieceInfoLog 鏁版嵁 鍑虹幇寮傚父", ex); + } + } + + + /// <summary> + /// 绉婚櫎XX澶╁墠鐨� WorkPieceLog 鏁版嵁 + /// </summary> + /// <param name="edm"></param> + public static void Delete_WorkPieceLog(int days) + { + try + { + using (DbModel edm = new DbModel()) + { + var queryTime = DateTime.Now.AddDays(-days); + + var removeList = edm.WorkPieceLog.Where(x => x.CreatedTime <= queryTime).ToList(); + if (removeList != null && removeList.Count > 0) + { + edm.WorkPieceLog.RemoveRange(removeList); + } + edm.SaveChanges(); + } + } + catch (Exception ex) + { + Log4NetHelper.WriteErrorLog(LogType.DeleteData, "绉婚櫎XX澶╁墠鐨� WorkPieceLog 鏁版嵁 鍑虹幇寮傚父", ex); + } + } + + + } +} \ No newline at end of file diff --git a/DataCapture/iWare_SCADA_DataCapture/iWare_SCADA_BusinessLogical/iWare_SCADA_BusinessLogical.csproj b/DataCapture/iWare_SCADA_DataCapture/iWare_SCADA_BusinessLogical/iWare_SCADA_BusinessLogical.csproj index 2bc86bd..c36463f 100644 --- a/DataCapture/iWare_SCADA_DataCapture/iWare_SCADA_BusinessLogical/iWare_SCADA_BusinessLogical.csproj +++ b/DataCapture/iWare_SCADA_DataCapture/iWare_SCADA_BusinessLogical/iWare_SCADA_BusinessLogical.csproj @@ -156,6 +156,7 @@ <DesignTime>True</DesignTime> <DependentUpon>Resources.resx</DependentUpon> </Compile> + <Compile Include="Utils\ClearDataHandler.cs" /> <Compile Include="Utils\WorkPieceProcessHelper.cs" /> <Compile Include="Utils\QualityStateHelper.cs" /> <Compile Include="Utils\MonitorHelper.cs" /> -- Gitblit v1.9.3