wzp
2021-07-28 864986e4cad03f6b9bba9a7e65379db496b62a6a
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
124
125
126
127
128
129
using AsiaINFO.SMS.DBFactory;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
namespace AsiaINFO.SMS.BusinessFactory
{
    public class DetectionBusiness
    {
        private static DetectionBusiness _instance = null;
 
        
 
        public static DetectionBusiness Instance
        {
            get
            {
                if (DetectionBusiness._instance == null)
                {
                    DetectionBusiness._instance = new DetectionBusiness();
                }
                return _instance;
            }
        }
 
        private DetectionBusiness() { }
        private Dictionary<int, Dictionary<string, bool>> _hasSubmitMobile = new Dictionary<int, Dictionary<string, bool>>();
 
        public bool checkMessageId(string msgId)
        {
            int curKey = this.getCurKey();
            int[] checkKeys = getCheckKeys(curKey);
            this.removeDict(curKey);
            foreach (int key in checkKeys)
            {
                if (this._hasSubmitMobile.ContainsKey(key) && this._hasSubmitMobile[key] != null)
                {
                    if (this._hasSubmitMobile[key].ContainsKey(msgId)) return true;
                }
            }
            return false;
        }
        private int getCurKey()
        {
            DateTime now = DateTime.Now;
            int min = (int.Parse(now.ToString("mm")) / 10);//0,1,2,3,4,5
            return min;
        }
        public void addSubmitMessageToCache(string msgId)
        {
            int curKey = this.getCurKey();
            if (this._hasSubmitMobile.ContainsKey(curKey) && this._hasSubmitMobile[curKey] != null)
            {
                Dictionary<string, bool> keys = this._hasSubmitMobile[curKey];
                keys.Add(msgId, true);
            }
            else if (this._hasSubmitMobile.ContainsKey(curKey))
            {
                Dictionary<string, bool> keys = new Dictionary<string, bool>();
                keys.Add(msgId, true);
                this._hasSubmitMobile[curKey] = keys;
            }
            else
            {
                Dictionary<string, bool> keys = new Dictionary<string, bool>();
                keys.Add(msgId, true);
                this._hasSubmitMobile.Add(curKey, keys);
            }
 
            DateTime now = DateTime.Now;
            int min = (int.Parse(now.ToString("mm")) / 10);
            //log4netService.Debug("addSubmitMessageToCache成功,总数:" + _hasSubmitMobile[min].Count);
        }
        private int[] getCheckKeys(int curKey)
        {
            if (curKey == 0)
            {
                return new int[] { 0, curKey + 5 };
            }
 
            return new int[] { curKey, curKey - 1 };
 
        }
        private bool isDelKey(int curKey, int delKey)
        {
            if (curKey == delKey) return false;
 
            if (curKey == 0 && delKey == 5)
            {
                return false;
            }
            if (delKey == curKey - 1) return false;
 
            //log4netService.Debug("移除成功,curKey=" + curKey);
            return true;
        }
 
 
        private void removeDict(int curKey)
        {
            List<int> keys = new List<int>();
            foreach (int key in this._hasSubmitMobile.Keys)
            {
                if (key == curKey)
                {
                    continue;
                }
                if (this.isDelKey(curKey, key))
                {
                    keys.Add(key);
                    //keys[keys.Count] = key;
                    //this._hasSubmitMobile[key] = null;
                }
 
            }
 
            for (int i = 0; i < keys.Count; i++)
            {
                int key = keys[i];
                this._hasSubmitMobile[key] = null;
            }
            //log4netService.Debug("removeDict正常:" + keys.Count);
        }
 
    }
 
 
}