public ActionResult ExpenseSettings(ExpenseSettingsModel model) { var currentPropertyPlaceId = GetSessionModel().PropertyPlaceId.Value; if (model.NotificationDate == null) { model.NotificationDate = DateTime.Now.AddDays(1); } IBuildBLL buildBLL = BLLFactory <IBuildBLL> .GetBLL("BuildBLL"); //绑定楼座下拉列表 var buildList = buildBLL.GetList(b => b.PropertyPlaceId == currentPropertyPlaceId, "BuildName", true).ToList(); model.BuildList = buildList.Select(b => new SelectListItem() { Text = b.BuildName, Value = b.Id.ToString() }).ToList(); List <SelectListItem> unitList = new List <SelectListItem>(); unitList.Add(new SelectListItem() { Text = "选择单元", Value = string.Empty }); //绑定单元下拉列表 if (model.BuildId > 0) { IBuildUnitBLL unitBll = FactoryBLL.BLLFactory <IBuildUnitBLL> .GetBLL("BuildUnitBLL"); var units = unitBll.GetList(u => u.BuildId == model.BuildId).OrderBy(u => u.UnitName).Select(u => new SelectListItem() { Text = u.UnitName, Value = u.Id.ToString(), Selected = (u.Id == model.UnitId) }).ToList(); unitList.AddRange(units); } model.UnitList = unitList; //绑定缴费种类名称下拉列表 IPropertyExpenseTypeBLL typeBLL = BLLFactory <IPropertyExpenseTypeBLL> .GetBLL("PropertyExpenseTypeBLL"); model.ExpenseTypeList = typeBLL.GetList(t => t.IsFixed == model.ExpenseClassId && t.PropertyPlaceId == currentPropertyPlaceId).OrderBy(t => t.Name).Select(t => new SelectListItem() { Text = t.Name, Value = t.Id.ToString() }).ToList(); //绑定缴费明细 IBuildUnitBLL unitBLL = BLLFactory <IBuildUnitBLL> .GetBLL("BuildUnitBLL"); if (model.BuildId > 0) { var unit = unitBLL.GetEntity(u => u.BuildId == model.BuildId && u.Id == model.UnitId); if (unit != null) { var doorList = unit.BuildDoors.OrderBy(u => u.DoorName).ToList(); var doorIds = doorList.Select(d => d.Id); IHouseUserExpenseTemplateBLL expenseTemplateBLL = BLLFactory <IHouseUserExpenseTemplateBLL> .GetBLL("HouseUserExpenseTemplateBLL"); var allDoorExpenseByExpenseType = expenseTemplateBLL.GetList(e => e.ExpenseTypeId == model.ExpenseTypeId && e.BuildDoorId != null && doorIds.Contains(e.BuildDoorId.Value)); var houseUserExpenseTemplateList = new List <HouseUserExpenseTemplateModel>(); if (allDoorExpenseByExpenseType.Count() > 0) { var doorExpense = allDoorExpenseByExpenseType.FirstOrDefault(); model.ExpenseCircleId = doorExpense.ExpenseCycleId; model.NotificationDate = doorExpense.NotificationDate; } foreach (var door in doorList) { var houseUserExpenseTemplateModel = new HouseUserExpenseTemplateModel(); houseUserExpenseTemplateModel.DoorId = door.Id; houseUserExpenseTemplateModel.DoorName = door.DoorName; var doorExpense = allDoorExpenseByExpenseType.FirstOrDefault(e => e.BuildDoorId == door.Id); if (doorExpense != null) { houseUserExpenseTemplateModel.Expense = doorExpense.Expense.ToString(); } houseUserExpenseTemplateList.Add(houseUserExpenseTemplateModel); } model.HouseUserExpenseTemplateList = houseUserExpenseTemplateList; } } return(View(model)); }
public static void ExpenseNotification() { try { var allList = new List <T_HouseUserExpenseTemplate>(); //当前日期 DateTime CurrentDate = DateTime.Now.Date; //明天日期 DateTime TommorrowDate = CurrentDate.AddDays(1).Date; //所有符合发推送的缴费信息列表 IHouseUserExpenseTemplateBLL templateBLL = BLLFactory <IHouseUserExpenseTemplateBLL> .GetBLL("HouseUserExpenseTemplateBLL"); var expenseTemplateList = templateBLL.GetList().ToList(); foreach (var expenseTemplate in expenseTemplateList) { //看看要处理是不是今天,如果不是今天按照推送的周期加周期的天数(每月加30,每两月加60,每季度90...) var isCheck = CurrentDate <= expenseTemplate.NotificationDate && expenseTemplate.NotificationDate < TommorrowDate; if (isCheck) { allList.Add(expenseTemplate); } else { expenseTemplate.NotificationDate = expenseTemplate.NotificationDate.AddDays(expenseTemplate.ExpenseCycleId * 30); isCheck = CurrentDate <= expenseTemplate.NotificationDate && expenseTemplate.NotificationDate < TommorrowDate; if (isCheck) { allList.Add(expenseTemplate); } } } //保存到ExpenseDetail表 IHouseUserExpenseDetailsBLL expenseDetailsBLL = BLLFactory <IHouseUserExpenseDetailsBLL> .GetBLL("HouseUserExpenseDetailsBLL"); //缴费周期 应缴费开始时间加上缴费周期天数就是应缴费结束时间 int expensePeriod = int.Parse(ConfigurationManager.AppSettings["ExpensePeriod"].ToString()); var detailsList = expenseDetailsBLL.SaveExpenseDetails(allList, expensePeriod); var registrationIdList = new List <string>(); var title = "缴费提醒"; var content = "您有一条缴费提醒, 请注意查收。"; //将保存成功的ExpenseDetail队列发推送 if (detailsList.Count > 0) { CommonUtils.WriteLogInfo("已经进入到发推送里面"); IUserPushBLL userPushBLL = BLLFactory <IUserPushBLL> .GetBLL("UserPushBLL"); //全部保存成功后,取得所有要推送的用户 foreach (var item in detailsList) { var appUserIds = item.BuildDoor.PropertyIdentityVerifications.Select(p => p.AppUserId); var registrationIds = userPushBLL.GetList(u => appUserIds.Contains(u.UserId)).Select(u => u.RegistrationId); registrationIdList.AddRange(registrationIds); } foreach (var item in registrationIdList) { CommonUtils.WriteLogInfo(string.Format("发推送人的设备是:{0}", item)); } //批量推送出去 bool check = Property.Common.PropertyUtils.SendPush(title, content, ConstantParam.MOBILE_TYPE_OWNER, registrationIdList.ToArray()); CommonUtils.WriteLogInfo(string.Format("调用完推送返回的结果:{0}", check)); CommonUtils.WriteLogInfo("已经完成发推送。"); } } catch (Exception ex) { CommonUtils.WriteLogError(ex); } }