TG.WXCRM.V4/WebHelper/DoItems/CsvrMessage.cs

93 lines
2.7 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using Ninject;
using System;
using System.Collections.Generic;
using System.Linq;
using WX.CRM.Common;
using WX.CRM.IBLL.Base;
using WX.CRM.IBLL.Csvr;
namespace WX.CRM.WebHelper.DoItems
{
/// <summary>
/// 分配资源提醒
/// </summary>
public sealed class CsvrMessage : IPopupMessage
{
private ICSVR_MESSAGE _allocateRes;
private IBAS_INNERUSER_Q _basuser;
#region
private static volatile CsvrMessage instance = null;
private CsvrMessage()
{
_allocateRes = Infrastructure.NinjectControllerFactory.ninjectKernel.Get<ICSVR_MESSAGE>();
_basuser = Infrastructure.NinjectControllerFactory.ninjectKernel.Get<IBAS_INNERUSER_Q>();
}
// Lock对象线程安全所用
private static object locked = new Object();
public static CsvrMessage Instance
{
get
{
if (instance == null)
{
lock (locked)
{
if (instance == null)
instance = new CsvrMessage();
}
}
return instance;
}
}
#endregion
#region
private Boolean NeedRefresh = true;
private DateTime LastLoadTime = DateTime.Now;
private void LoadResource(decimal UserId)
{
lock (this)
{
if (!NeedRefresh)
return;
var entry = _basuser.GetModel(UserId);
if (entry != null)
{
var count = _allocateRes.GetList(m => m.ISLOOK == 0 && m.EID == entry.EID).ToList().Count();
if (UserRes.ContainsKey(UserId))
UserRes[UserId] = count;
else
UserRes.Add(UserId, count);
}
NeedRefresh = false;
LastLoadTime = DateTime.Now;
}
}
#endregion
public string GetUrl()
{
return @"../Cms/CmsUp/Index";// 分配资源提醒
}
public void SetNeedRefresh()
{
NeedRefresh = true;
}
public void SetView(decimal UserId, string pkid)
{
}
private Dictionary<decimal, int> UserRes = new Dictionary<decimal, int>();
public string GetMessage(decimal UserId)
{
SetNeedRefresh();
if (NeedRefresh)
LoadResource(UserId);
if (!UserRes.ContainsKey(UserId))
return string.Empty;
var ResInfo = UserRes[UserId];
return string.Format("{0}", ResInfo);
}
}
}