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

133 lines
4.4 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.Res;
using WX.CRM.WebHelper.UtilityModel;
namespace WX.CRM.WebHelper.DoItems
{
/// <summary>
/// 分配资源提醒
/// </summary>
public sealed class AllocateResMessage : IPopupMessage
{
private IRES_ALLOCATESTRATEGY_Q _allocateRes;
#region
private static volatile AllocateResMessage instance = null;
private AllocateResMessage()
{
_allocateRes = Infrastructure.NinjectControllerFactory.ninjectKernel.Get<IRES_ALLOCATESTRATEGY_Q>();
}
// Lock对象线程安全所用
private static object locked = new Object();
public static AllocateResMessage Instance
{
get
{
if (instance == null)
{
lock (locked)
{
if (instance == null)
instance = new AllocateResMessage();
}
}
return instance;
}
}
#endregion
#region
//private Boolean NeedRefresh = true;
//private DateTime LastLoadTime = DateTime.Now;
private Dictionary<decimal, UserResourceCount> UserRes = new Dictionary<decimal, UserResourceCount>();
private void LoadResource(decimal UserId)
{
//lock (this)
{
//if (!NeedRefresh)
// return;
//重新加载未查看分配资源到UserRes
UserRes.Clear();
//查数据库
WX.CRM.Common.Pager pg = new WX.CRM.Common.Pager();
pg.page = 1;
pg.rows = int.MaxValue;
var lists = _allocateRes.GetMyAllocateResList(ref pg, null, UserId, null, 0, 0, 1, null, null, null);
//LogHelper.Info("lists:" + lists.Count.ToString());
var queryList = from a in lists group a by a.InneruserId into g select new { g.Key, time = g.Max(p => p.DisTime) };
var tipUser = new List<decimal>();
foreach (var item in queryList)
{
var spanTime = DateTime.Now - item.time;
if (spanTime.TotalSeconds < 31)
{
tipUser.Add(item.Key);
}
}
lists = lists.Where(p => tipUser.Contains(p.InneruserId)).ToList();
foreach (var list in lists)
{
UserResourceCount resinfo = null;
if (!UserRes.ContainsKey(list.InneruserId))
{
resinfo = new UserResourceCount
{
SalesId = list.InneruserId
};
UserRes.Add(list.InneruserId, resinfo);
}
else
{
resinfo = UserRes[list.InneruserId];
}
resinfo.Add(list.ResId.ToString());
}
//把NeedRefresh置为false
//NeedRefresh = false;
//LastLoadTime = DateTime.Now;
}
}
#endregion
public string GetUrl()
{
return @"../Res/Allocate/MyAllocatedRes";// 分配资源提醒
}
//public void SetNeedRefresh()
//{
// NeedRefresh = true;
//}
public void SetView(decimal UserId, string pkid)
{
if (!UserRes.ContainsKey(UserId))
return;
var ResInfo = UserRes[UserId];
if (ResInfo == null)
return;
ResInfo.Remove(pkid);
}
public string GetMessage(decimal UserId)
{
//if (((TimeSpan)(DateTime.Now - LastLoadTime)).TotalMinutes >= 3)
// SetNeedRefresh();
//if (NeedRefresh)
LoadResource(UserId);
if (!UserRes.ContainsKey(UserId))
return string.Empty;
var ResInfo = UserRes[UserId];
if (ResInfo == null || ResInfo.Count == 0)
return string.Empty;
// return string.Format(string.Join("#", ResInfo.PKIDS.Distinct()));
return string.Format("{0}", ResInfo.Count);
}
}
}