ClearLogAction.cs
5.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
using System;
using System.Collections.Generic;
using System.Linq;
using Infrastructure;
using Quartz;
using WebRepository;
namespace WebMvc
{
[PersistJobDataAfterExecution]
[DisallowConcurrentExecution]
public class ClearLogAction
{
private string ConnString { set; get; }
private IJobExecutionContext Context { set; get; }
public ClearLogAction(string _ConnString, IJobExecutionContext _Context)
{
ConnString = _ConnString;
Context = _Context;
}
public void Execute()
{
UnitWork _unitWork = new UnitWork(AppSettingsJson.JobContext(ConnString));
string sql = "";
string LogName = Context.JobDetail.JobDataMap.GetString("LogName");
int Days = Context.JobDetail.JobDataMap.GetInt("Days");
DbHelp dbHelp = new DbHelp(ConnString);
#region 执行任务语句
sql = string.Format("DELETE FROM [dbo].[sys_oper_log] WHERE createTime < '{0}';", DateTime.Now.AddDays(-1 * double.Parse(Days.ToString())));
dbHelp.DataOperator(sql);
sql = string.Format("DELETE FROM [dbo].[sys_job_log] WHERE createTime < '{0}';", DateTime.Now.AddDays(-1 * double.Parse(Days.ToString())));
dbHelp.DataOperator(sql);
sql = string.Format("DELETE FROM [dbo].[sys_interface_log] WHERE createTime < '{0}';", DateTime.Now.AddDays(-1 * double.Parse(30.ToString())));
dbHelp.DataOperator(sql);
sql = string.Format("DELETE FROM [dbo].[task_detail_history] WHERE createTime < '{0}';", DateTime.Now.AddDays(-1 * double.Parse(120.ToString())));
dbHelp.DataOperator(sql);
sql = string.Format("DELETE FROM [dbo].[task_history] WHERE createTime < '{0}';", DateTime.Now.AddDays(-1 * double.Parse(120.ToString())));
dbHelp.DataOperator(sql);
sql = string.Format("DELETE FROM [dbo].[inventory_transaction] WHERE createTime < '{0}';", DateTime.Now.AddDays(-1 * double.Parse(90.ToString())));
dbHelp.DataOperator(sql);
sql = string.Format("DELETE FROM [dbo].[inventory_out] WHERE createTime < '{0}';", DateTime.Now.AddDays(-1 * double.Parse(90.ToString())));
dbHelp.DataOperator(sql);
List<ReceiptHeader> receiptHeaders = _unitWork
.Find<ReceiptHeader>(n => n.CreateTime < DateTime.Now.AddDays(-1 * double.Parse(60.ToString())))
.ToList();
if (receiptHeaders.Any())
{
foreach (var receiptHeader in receiptHeaders)
{
ReceiptHeaderHistory receiptHeaderHistory = new ReceiptHeaderHistory();
receiptHeader.CopyTo(receiptHeaderHistory);
receiptHeaderHistory.Id = null;
_unitWork.Add(receiptHeaderHistory);
List<ReceiptDetail> receiptDetail1s = _unitWork.Find<ReceiptDetail>(u => u.ReceiptCode == receiptHeader.Code).ToList();
foreach (ReceiptDetail rd in receiptDetail1s)
{
ReceiptDetailHistory receiptDetailHistory = new ReceiptDetailHistory();
rd.CopyTo(receiptDetailHistory);
receiptDetailHistory.Id = null;
receiptDetailHistory.ReceiptId = receiptHeaderHistory.Id;
_unitWork.Add(receiptDetailHistory);
_unitWork.Delete(rd);
}
_unitWork.Delete(receiptHeader);
}
}
List<ShipmentHeader> shipmentHeaders = _unitWork
.Find<ShipmentHeader>(n => n.CreateTime < DateTime.Now.AddDays(-1 * double.Parse(60.ToString())))
.ToList();
if (shipmentHeaders.Any())
{
foreach (var shipmentHeader in shipmentHeaders)
{
ShipmentHeaderHistory shipmentHeaderHistory = new ShipmentHeaderHistory();
shipmentHeader.CopyTo(shipmentHeaderHistory);
shipmentHeaderHistory.Id = null;
_unitWork.Add(shipmentHeaderHistory);
List<ShipmentDetail> shipdtls = _unitWork.Find<ShipmentDetail>(u => u.ShipmentCode == shipmentHeader.Code).ToList();
foreach (ShipmentDetail sd in shipdtls)
{
ShipmentDetailHistory shipmentDetailHistory = new ShipmentDetailHistory();
sd.CopyTo(shipmentDetailHistory);
shipmentDetailHistory.Id = null;
shipmentDetailHistory.ShipmentId = shipmentHeaderHistory.Id;
_unitWork.Add(shipmentDetailHistory);
_unitWork.Delete(sd);
}
_unitWork.Delete(shipmentHeader);
}
}
List<InterfaceLog> DelinterfaceLogs = _unitWork.Find<InterfaceLog>(n => n.Status == 1 && (n.Type == "LK_In" || n.Type == "LK_Out")).ToList();
if (DelinterfaceLogs.Any())
{
foreach (var DelinterfaceLog in DelinterfaceLogs)
{
List<InterfaceLog> interfaceLogs = _unitWork.Find<InterfaceLog>(n => n.TaskNo == DelinterfaceLog.TaskNo).ToList();
foreach (var interfaceLog in interfaceLogs)
{
InterfaceLog_Old interfaceLogOld = new InterfaceLog_Old();
interfaceLog.CopyTo(interfaceLogOld);
interfaceLogOld.Id = null;
_unitWork.Add(interfaceLogOld);
_unitWork.Delete(interfaceLog);
}
}
}
#endregion
}
}
}