94 lines
3.2 KiB
C#
94 lines
3.2 KiB
C#
using Ninject;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using WX.CRM.IBLL.Res;
|
||
using WX.CRM.WebHelper.UtilityModel;
|
||
namespace WX.CRM.WebHelper.DoItems
|
||
{
|
||
/// <summary>
|
||
/// 诊股资源回收通知,总监收
|
||
/// </summary>
|
||
public class ResRecycleZJNotice : IPopupMessage
|
||
{
|
||
private string url = @"../Res/Activity/LookNotice?type=1&sdate={0}";
|
||
private IRES_ResRecycleRecord _allocateRes;
|
||
#region 单例
|
||
private static volatile ResRecycleZJNotice instance = null;
|
||
private ResRecycleZJNotice()
|
||
{
|
||
_allocateRes = Infrastructure.NinjectControllerFactory.ninjectKernel.Get<IRES_ResRecycleRecord>();
|
||
}
|
||
// Lock对象,线程安全所用
|
||
private static object locked = new Object();
|
||
public static ResRecycleZJNotice Instance
|
||
{
|
||
get
|
||
{
|
||
if (instance == null)
|
||
{
|
||
lock (locked)
|
||
{
|
||
if (instance == null)
|
||
instance = new ResRecycleZJNotice();
|
||
}
|
||
}
|
||
return instance;
|
||
}
|
||
}
|
||
#endregion
|
||
public string GetUrl()
|
||
{
|
||
return url;// 分配资源提醒
|
||
}
|
||
private Boolean NeedRefresh = true;
|
||
private DateTime LastLoadTime = DateTime.Now;
|
||
Dictionary<decimal, ResRecycleMsg> UserRes = new Dictionary<decimal, ResRecycleMsg>();
|
||
public void SetNeedRefresh()
|
||
{
|
||
NeedRefresh = true;
|
||
}
|
||
public string GetMessage(decimal UserId)
|
||
{
|
||
if (((TimeSpan)(DateTime.Now - LastLoadTime)).TotalMinutes >= 1)
|
||
SetNeedRefresh();
|
||
if (NeedRefresh)
|
||
LoadResource(UserId);
|
||
string messag = string.Empty;
|
||
if (!UserRes.ContainsKey(UserId))
|
||
return string.Empty;
|
||
ResRecycleMsg ResInfo = UserRes[UserId];
|
||
url = string.Format(url, ResInfo.ctime.ToShortDateString());
|
||
//Common.LogHelper.Info(ResInfo.ctime.ToString());
|
||
//Common.LogHelper.Info(url);
|
||
return string.Format(ResInfo.message);
|
||
}
|
||
private void LoadResource(decimal UserId)
|
||
{
|
||
lock (this)
|
||
{
|
||
if (!NeedRefresh)
|
||
return;
|
||
//重新加载未查看分配资源到UserRes
|
||
UserRes.Clear();
|
||
//查数据库
|
||
var lists = _allocateRes.GetNotice(1);
|
||
foreach (var model in lists)
|
||
{
|
||
ResRecycleMsg resinfo = new ResRecycleMsg();
|
||
resinfo.userid = model.inneruserid;
|
||
resinfo.message = model.content;
|
||
resinfo.ctime = model.ctime;
|
||
if (!UserRes.ContainsKey(model.inneruserid))
|
||
{
|
||
UserRes.Add(model.inneruserid, resinfo);
|
||
}
|
||
|
||
}
|
||
//把NeedRefresh置为false
|
||
NeedRefresh = false;
|
||
LastLoadTime = DateTime.Now;
|
||
}
|
||
}
|
||
}
|
||
}
|