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

86 lines
2.4 KiB
C#
Raw 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 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);
}
}
}