109 lines
3.4 KiB
C#
109 lines
3.4 KiB
C#
using Ninject;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
using WX.CRM.IBLL.Csvr;
|
||
using WX.CRM.WebHelper.UtilityModel;
|
||
|
||
namespace WX.CRM.WebHelper.DoItems
|
||
{
|
||
public sealed class MSGOpenAccountMessage : IPopupMessage
|
||
{
|
||
private ICSVR_MSGOPENACCOUNT_Q _openAccount;
|
||
#region 单例
|
||
private static volatile MSGOpenAccountMessage instance = null;
|
||
private MSGOpenAccountMessage()
|
||
{
|
||
_openAccount = Infrastructure.NinjectControllerFactory.ninjectKernel.Get<ICSVR_MSGOPENACCOUNT_Q>();
|
||
}
|
||
// Lock对象,线程安全所用
|
||
private static object locked = new Object();
|
||
public static MSGOpenAccountMessage Instance
|
||
{
|
||
get
|
||
{
|
||
if (instance == null)
|
||
{
|
||
lock (locked)
|
||
{
|
||
if (instance == null)
|
||
instance = new MSGOpenAccountMessage();
|
||
}
|
||
}
|
||
|
||
return instance;
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 私有数据
|
||
private Boolean NeedRefresh = true;
|
||
private DateTime LastLoadTime = DateTime.Now;
|
||
Dictionary<decimal, UserResourceCount> UserRes = new Dictionary<decimal, UserResourceCount>();
|
||
private void LoadResource()
|
||
{
|
||
lock (this)
|
||
{
|
||
if (!NeedRefresh)
|
||
return;
|
||
//重新加载未查看分配资源到UserRes
|
||
UserRes.Clear();
|
||
//查数据库
|
||
var lists = _openAccount.GetNoIsViewOpenAccount();
|
||
foreach (var list in lists)
|
||
{
|
||
|
||
UserResourceCount resinfo = null;
|
||
if (!UserRes.ContainsKey(list.SALESID))
|
||
{
|
||
resinfo = new UserResourceCount();
|
||
resinfo.SalesId = list.SALESID;
|
||
UserRes.Add(list.SALESID, resinfo);
|
||
}
|
||
else
|
||
{
|
||
resinfo = UserRes[list.SALESID];
|
||
}
|
||
resinfo.Add(list.RESID.ToString());
|
||
}
|
||
|
||
//把NeedRefresh置为false
|
||
NeedRefresh = false;
|
||
LastLoadTime = DateTime.Now;
|
||
}
|
||
}
|
||
#endregion
|
||
public string GetUrl()
|
||
{
|
||
return @"../Csvr/MsgOpenAccount/RedirectToCustomerDetial";// 新开户提醒
|
||
}
|
||
public void SetNeedRefresh()
|
||
{
|
||
NeedRefresh = true;
|
||
}
|
||
public void SetView(decimal UserId, string pkid)
|
||
{
|
||
if (!UserRes.ContainsKey(UserId))
|
||
return;
|
||
var ResInfo = UserRes[UserId];
|
||
if (ResInfo == null)
|
||
return;
|
||
ResInfo.Remove(pkid);
|
||
}
|
||
|
||
public string GetMessage(decimal UserId)
|
||
{
|
||
if (((TimeSpan)(DateTime.Now - LastLoadTime)).TotalMinutes >= 20)
|
||
SetNeedRefresh();
|
||
if (NeedRefresh)
|
||
LoadResource();
|
||
if (!UserRes.ContainsKey(UserId))
|
||
return string.Empty;
|
||
var ResInfo = UserRes[UserId];
|
||
if (ResInfo == null || ResInfo.Count == 0)
|
||
return string.Empty;
|
||
return string.Format(string.Join("#", ResInfo.PKIDS.Distinct()));
|
||
}
|
||
}
|
||
}
|