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

159 lines
4.9 KiB
C#

using CRM.Core.DTO.Hg;
using Microsoft.JScript.Vsa;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WX.CRM.BLL.Util;
using WX.CRM.Common;
using WX.CRM.Common.StockHelper;
using WX.CRM.Model.Enum;
using WX.CRM.WebHelper.UtilityModel;
namespace WX.CRM.WebHelper.DoItems
{
public sealed class HgPunishNoticeMessage : IPopupMessage
{
private readonly CACHE_BL cache_BL;
private static volatile HgPunishNoticeMessage instance = null;
public HgPunishNoticeMessage()
{
cache_BL = new CACHE_BL();
}
private static object locked = new Object();
public static HgPunishNoticeMessage Instance
{
get
{
if (instance == null)
{
lock (locked)
{
if (instance == null)
instance = new HgPunishNoticeMessage();
}
}
return instance;
}
}
private Dictionary<int, int> UserRes = new Dictionary<int, int>();
private static DateTime NoticeTime;
private void LoadResource()
{
LogHelper.Info("1");
if (DateTime.Now.Hour == 0)
{
UserRes.Clear();
}
if (DateTime.Now.Hour < 8)
{
return;
}
if (UserRes.Any())
{
if (DateTime.Now < NoticeTime.AddHours(1))
{
LogHelper.Info("2");
return;
}
}
LogHelper.Info("3");
var webapi = cache_BL.GetValue_Parameter(Parameter.Hg_Core_WebApi);
var url = $"{webapi}/order/GetCheckQualityNotice";
var punishNoticeDay = -7;
var punishNoticeDayCfg = Utility.GetSettingOrNullByKey("PunishNoticeDay");
if (!string.IsNullOrEmpty(punishNoticeDayCfg))
{
punishNoticeDay = Convert.ToInt32(punishNoticeDayCfg);
}
var dto = new HgCheckQualitySearchDto() { PageIndex = 1, PageSize = int.MaxValue, stime = DateTime.Now.AddDays(punishNoticeDay), etime = DateTime.Now };
var result = Utility.PostAjaxData(url, dto.ToJson(), Encoding.UTF8);
var rsp = JsonConvert.DeserializeObject<ApiResult<PageResult<Hg_CheckQuality_Notice>>>(result);
var data = rsp.Data.Data;
LogHelper.Info(data.ToJson());
foreach (var notice in data)
{
var sale = notice.Hg_CheckQuality_NoticeSigns.Find(p => p.NoticeLevel == "sale");
var manage = notice.Hg_CheckQuality_NoticeSigns.Find(p => p.NoticeLevel == "manage");
if (sale.Sign == 0)
{
if (UserRes.ContainsKey(sale.eid))
{
UserRes[sale.eid] += 1;
}
else
{
UserRes[sale.eid] = 1;
}
//UserRes[sale.eid].NoticeTime = DateTime.Now;
}
if (manage.Sign == 0)
{
if (UserRes.ContainsKey(manage.eid))
{
UserRes[manage.eid] += 1;
}
else
{
UserRes[manage.eid] = 1;
}
//UserRes[manage.eid].NoticeTime = DateTime.Now;
}
}
NoticeTime = DateTime.Now;
LogHelper.Info(NoticeTime.ToString());
}
public string GetMessage(decimal UserId)
{
try
{
var eid = Convert.ToInt32(InnerUserHelper.Instance.GetEidByUserId(UserId));
LoadResource();
UserRes.TryGetValue(eid, out var count);
if (count > 0)
{
return string.Format("{0}", count);
}
return string.Empty;
}
catch (Exception ex)
{
LogHelper.Error(ex);
return string.Empty;
}
}
public void SetView(decimal UserId)
{
try
{
var eid = Convert.ToInt32(InnerUserHelper.Instance.GetEidByUserId(UserId));
UserRes.Remove(eid);
}
catch (Exception ex)
{
LogHelper.Error(ex);
}
}
public string GetUrl()
{
return @"/Hg/MyCheckNoticeIndex";// 分配资源提醒
}
public class UserNoticeInfo
{
public int Count { get; set; }
public DateTime NoticeTime { get; set; }
}
}
}