86 lines
2.4 KiB
C#
86 lines
2.4 KiB
C#
using Ninject;
|
||
using System;
|
||
using WX.CRM.IBLL.Res;
|
||
|
||
namespace WX.CRM.WebHelper.DoItems
|
||
{
|
||
public sealed class DistributeResMessage : IPopupMessage
|
||
{
|
||
private IRES_DISTRIBUTE_Q _distributeQ;
|
||
#region 单例
|
||
private static volatile DistributeResMessage instance = null;
|
||
private DistributeResMessage()
|
||
{
|
||
_distributeQ = Infrastructure.NinjectControllerFactory.ninjectKernel.Get<IRES_DISTRIBUTE_Q>();
|
||
}
|
||
// Lock对象,线程安全所用
|
||
private static object locked = new Object();
|
||
public static DistributeResMessage Instance
|
||
{
|
||
get
|
||
{
|
||
if (instance == null)
|
||
{
|
||
lock (locked)
|
||
{
|
||
if (instance == null)
|
||
instance = new DistributeResMessage();
|
||
}
|
||
}
|
||
return instance;
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 私有数据
|
||
private Boolean NeedRefresh = true;
|
||
private DateTime LastLoadTime = DateTime.Now;
|
||
private int LoadResource(decimal UserId)
|
||
{
|
||
lock (this)
|
||
{
|
||
try
|
||
{
|
||
//if (!NeedRefresh)
|
||
// return 0;
|
||
//查数据库
|
||
var count = _distributeQ.GetNewDistributeCount(UserId);
|
||
//var count = 0;
|
||
|
||
//把NeedRefresh置为false
|
||
//NeedRefresh = false;
|
||
//LastLoadTime = DateTime.Now;
|
||
|
||
return count;
|
||
}
|
||
catch (Exception)
|
||
{
|
||
return 0;
|
||
}
|
||
|
||
}
|
||
}
|
||
#endregion
|
||
public string GetUrl()
|
||
{
|
||
return @"../Res/Distribute/MyActivityResDsb";// 分配资源提醒
|
||
}
|
||
public void SetNeedRefresh()
|
||
{
|
||
NeedRefresh = true;
|
||
}
|
||
|
||
public string GetMessage(decimal UserId)
|
||
{
|
||
//var count = 0;
|
||
//if (((TimeSpan)(DateTime.Now - LastLoadTime)).TotalMinutes >= 1)
|
||
// SetNeedRefresh();
|
||
//if (NeedRefresh)
|
||
var count = LoadResource(UserId);
|
||
if (count <= 0)
|
||
return string.Empty;
|
||
return string.Format("总监分配的优质白板资源:{0}个", count);
|
||
}
|
||
}
|
||
}
|