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

92 lines
3.1 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 System.Collections.Generic;
using WX.CRM.IBLL.Wx;
using WX.CRM.WebHelper.UtilityModel;
namespace WX.CRM.WebHelper.DoItems
{
/// <summary>
/// 违规通知,总监收
/// </summary>
public class WxIlleGalerCodeZJNotice : IPopupMessage
{
private string url = @"../WeiXin/MyIllegalRecord/LookNotice?type=1&stime={0}&etime={1}";
private IWX_MyIllegalRecord _allocateRes;
#region
private static volatile WxIlleGalerCodeZJNotice instance = null;
private WxIlleGalerCodeZJNotice()
{
_allocateRes = Infrastructure.NinjectControllerFactory.ninjectKernel.Get<IWX_MyIllegalRecord>();
}
// Lock对象线程安全所用
private static object locked = new Object();
public static WxIlleGalerCodeZJNotice Instance
{
get
{
if (instance == null)
{
lock (locked)
{
if (instance == null)
instance = new WxIlleGalerCodeZJNotice();
}
}
return instance;
}
}
#endregion
public string GetUrl()
{
return url;// 分配资源提醒
}
private Boolean NeedRefresh = true;
private DateTime LastLoadTime = DateTime.Now;
Dictionary<decimal, WxIllegMsg> UserRes = new Dictionary<decimal, WxIllegMsg>();
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;
WxIllegMsg ResInfo = UserRes[UserId];
url = string.Format(url, ResInfo.ctime.ToShortDateString(), DateTime.Now.ToShortDateString());
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)
{
WxIllegMsg resinfo = new WxIllegMsg();
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;
}
}
}
}