/// <summary> /// 获得当前用户的账号信息 /// </summary> /// <param name="category">查询对象分类</param> /// <param name="targetId">查询对象</param> /// <param name="nowBill">账户信息</param> /// <param name="user">查询用户</param> public NowBill GetNowMustPay(CategoryDictionary category, int targetId, NowBill nowBill) { var billPayTypes = DictionaryCache.Get().Values.Where(o => o.Code == "PayType" && o.Enable == true && o.ChineseName != "通用").ToList(); User user = userBLL.GetAccountUser(category, targetId, true); if (user == null) { return(nowBill); } var lastBalance = db.Balances.Where(o => o.TargetCategory == (int)category && o.TargetId == targetId).OrderByDescending(o => o.Id).Take(1).FirstOrDefault(); if (lastBalance == null) { return(nowBill); } nowBill = new NowBill(); nowBill.NowCost = lastBalance.Total; return(nowBill); }
/// <summary> /// 检测对象是否有和费用相关的告警触发或解除,并进行设备联动 /// 返回为需要付出告警的消息信息 /// </summary> /// <param name="userId"></param> public async Task <List <MessageData> > CheckIsArrearage(string userId1, int?buildingId = null, Balance balance = null, List <MonitoringConfig> monitoringConfigs = null) { TargetData targetInfo = new TargetData(); if (buildingId == null) { targetInfo = userBLL.GetTargetInfo(userId1); } else { targetInfo.Category = CategoryDictionary.Building; targetInfo.TargetId = (int)buildingId; } List <MessageData> results = new List <MessageData>(); //if (user != null) { var nowBill = new NowBill(); //当前账单 if (balance == null) { nowBill = GetNowMustPay(targetInfo.Category, targetInfo.TargetId, nowBill); } else { nowBill.NowCost = (decimal)balance.Total; } if (monitoringConfigs == null) { if (BLL.MyConsole.GetAppString("IsNeedSync") != "true") { monitoringConfigs = this.db.MonitoringConfig.Where(o => o.Enabled == true && o.ConfigTypeId == DictionaryCache.MonitoringConfigTypeWarning.Id && DictionaryCache.MessagesAboutMoney.Contains((int)o.WayId) && o.StartTime <= DateTime.Now && o.EndTime >= DateTime.Now && o.TargetTypeId == (targetInfo.Category == CategoryDictionary.Building ? DictionaryCache.ConfigToBuilding.Id : DictionaryCache.ConfigToOrg.Id) && o.TargetId == targetInfo.TargetId).ToList(); } else { monitoringConfigs = this.db.MonitoringConfig.Where(o => o.Enabled == true && (o.ConfigTypeId == DictionaryCache.MonitoringConfigTypeWarning.Id + 5) && DictionaryCache.MessagesAboutMoney.Contains((int)o.WayId) && o.StartTime <= DateTime.Now && o.EndTime >= DateTime.Now && o.TargetTypeId == (targetInfo.Category == CategoryDictionary.Building ? DictionaryCache.ConfigToBuilding.Id : DictionaryCache.ConfigToOrg.Id)).ToList(); } } if (monitoringConfigs.Count > 0) { //有此类型告警需求 foreach (var config in monitoringConfigs) { var messages = messageBLL.Filter(o => o.EndDate == null && o.MessageSourceTypeId == (targetInfo.Category == CategoryDictionary.Building ? DictionaryCache.MessageSourceTypeBuilding.Id : DictionaryCache.MessageSourceTypeOrg.Id) && o.SrcId == targetInfo.TargetId + "" && o.MessageTypeId == config.WayId).ToList(); if (nowBill.NowCost <= config.UnitValue) { //需要告警 //是否已经发出过此类告警,未结束 if (messages.Count() == 0) { //未发出此类告警,则触发告警联动,此方法用于缴费退费等操作,告警消息不从此发出, if (config.Value != null && BLL.MyConsole.GetAppString("IsNeedSync") != "true") { var action = DictionaryCache.Get()[Convert.ToInt32(config.Value)]; await meterBLL.LinkageControl(targetInfo.Category, new List <int> { targetInfo.TargetId }, action, 0); } string name = ""; if (targetInfo.Category == CategoryDictionary.Building) { name = buildingBLL.Find(targetInfo.TargetId).Name; } else { name = organizationBLL.Find(targetInfo.TargetId).Name; } var subject = name + config.Name + ",截止" + DateTime.Now.ToString(); subject = subject + ",您的可用金额为" + string.Format("{0:0.00}", nowBill.NowCost) + "元"; var message = messageBLL.CreateMessageData((int)config.WayId, DictionaryCache.MessageSourceTypeBuilding.Id, targetInfo.TargetId, subject, subject); results.Add(message); } } else { //解除此告警 if (messages.Count() > 0) { foreach (var item in messages) { item.EndDate = DateTime.Now; messageBLL.Update(item); } if (config.Value != null && BLL.MyConsole.GetAppString("IsNeedSync") != "true") { var action = DictionaryCache.Get()[Convert.ToInt32(config.Value)]; await meterBLL.LinkageControl(CategoryDictionary.Building, new List <int> { targetInfo.TargetId }, action, 0, false); } } } } } } return(results); }