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);
|
}
|
|
}
|
|
|
}
|