M182轴承端盖外观缺陷AOI
kingno
2025-05-26 5a405c7dce20d8c79a733c9c786cc42eb59fe81c
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
using Bro.Common.Helper;
using Bro.M135.DBManager;
using System.Diagnostics;
 
namespace Bro.M141.Process
{
    public class OldDataClear
    {
        public Lazy<Manager_P_PRODUCT> managerLazy = new Lazy<Manager_P_PRODUCT>();
        public Manager_P_PRODUCT manager =>managerLazy.Value;
 
        static object _instanceLock = new object();
        static OldDataClear instance = null;
        public static OldDataClear Instance
        {
            get
            {
                if (instance == null)
                {
                    lock (_instanceLock)
                    {
                        if (instance == null)
                        {
                            instance = new OldDataClear();
                        }
                    }
                }
                return instance;
            }
        }
 
        volatile bool _isStarted = false;
        bool _isAllowDeleteOp = true;
        int _dayLimit = 0;
 
        public void SetAllowFlag(bool isAllowed, int dayLimit)
        {
            _isAllowDeleteOp = isAllowed;
            _dayLimit = dayLimit;
        }
 
        public void RunClearOldData(int dayLimit)
        {
            if (_isStarted)
                return;
 
            _dayLimit = dayLimit;
            _isStarted = true;
 
            Task.Run(() =>
            {
                while (_isStarted)
                {
                    if (_dayLimit <= 0)
                        continue;
 
                    if (_isAllowDeleteOp)
                    {
                        Stopwatch sw = new Stopwatch();
                        sw.Start();
                        bool isMigrationOK = manager.DeletOldData(DateTime.Now.Date.AddDays(0 - _dayLimit), 100, out int dataNums, out string msg, out bool isNoData);
                        sw.Stop();
 
                        if (!isMigrationOK)
                        {
                            CommonLogger.LogAsync(DateTime.Now, EnumHelper.LogLevel.Error, $"数据删除失败,{msg}");
                        }
                        else
                        {
                            if (dataNums > 0)
                            {
                                CommonLogger.LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"{dataNums}条产品数据删除完成,耗时{sw.ElapsedMilliseconds}ms");
                            }
                        }
 
                        if (isNoData)
                        {
                            _isAllowDeleteOp = false;
                        }
                    }
 
                    Task.Delay(3000).Wait();
                }
            });
        }
    }
}