Exemplo n.º 1
0
        /// <summary>
        /// 获得配置相关的设备
        /// </summary>
        /// <param name="configDetail"></param>
        /// <returns></returns>
        public List <int> GetMeterIdsInRoom(ConfigDetail configDetail, bool?isInUsed = null)
        {
            var building = buildingBLL.Find(configDetail.BuildingId);
            var bTreeId  = DictionaryCache.Get()[(int)configDetail.BuildingCategoryId].TreeId;
            var eTreeId  = DictionaryCache.Get()[(int)configDetail.EnergyCategoryId].TreeId;
            var meterIds = meterBLL.Filter(o =>
                                           //是其建筑下设备
                                           (configDetail.BuildingId == o.Building.Id ||
                                            o.Building.TreeId.StartsWith(building.TreeId + "-"))
                                           //分类正确,默认使用顶级分类
                                           && (configDetail.BuildingCategoryId == o.Building.BuildingCategoryId ||
                                               o.Building.BuildingCategoryDict.TreeId.StartsWith(bTreeId + "-"))
                                           //&& (configDetail.EnergyCategoryId == o.EnergyCategoryId ||
                                           //o.EnergyCategoryDict.TreeId.StartsWith(eTreeId + "-"))
                                           && (configDetail.EnergyCategoryId == o.EnergyCategoryId) &&
                                           o.TypeDict.ThirdValue == 1 &&
                                           o.Enable &&
                                           o.Access != null &&
                                           o.GbCode != null &&
                                           o.TypeDict.SecondValue == 1 &&
                                           (isInUsed == null?true:isInUsed == o.Enable)
                                           ).Select(o => o.Id).ToList();

            return(meterIds);
        }
Exemplo n.º 2
0
        //public static MaintenanceData ToViewData(this Maintenance node, CategoryDictionary suffix = CategoryDictionary.None)
        //{
        //    if (node == null)
        //        return null;
        //    return new MaintenanceData()
        //    {
        //        Id = node.Id,
        //        MaintenanceCategoryId = node.MaintenanceCategoryId,
        //        StateId = node.StateId,
        //        UserId = node.UserId,
        //        Title = node.Title,
        //        Content = node.Content,
        //        Picture = node.Picture,
        //        ObjectCategoryId = node.ObjectCategoryId,
        //        OperateObjectId = node.OperateObjectId,
        //        CreateDate = node.CreateDate,
        //        Comment = node.Comment,
        //        Rating = node.Rating,
        //        OperatorDiscription = node.OperatorDiscription
        //        //User = ((suffix & CategoryDictionary.User) == CategoryDictionary.User) && node.User != null ? node.User.ToViewData() : null,
        //        //MaintenanceCategory = node.MaintenanceCategory.ToViewData(),
        //        //State = node.MaintenanceState.ToViewData(),
        //        //ObjectCategory = node.MaintenanceObjectCategory.ToViewData()

        //    };
        //}

        //public static IList<MaintenanceData> ToViewList(this IQueryable<Maintenance> nodes, CategoryDictionary suffix = CategoryDictionary.None)
        //{
        //    if (nodes == null)
        //        return null;
        //    var nodeList = nodes.ToList();
        //    //var results = nodes.ToList().Select(x => x.ToViewData(suffix)).ToList();
        //    var results = nodeList.Select(node => new MaintenanceData()
        //    {
        //        Id = node.Id,
        //        MaintenanceCategoryId = node.MaintenanceCategoryId,
        //        StateId = node.StateId,
        //        UserId = node.UserId,
        //        Title = node.Title,
        //        Content = node.Content,
        //        Picture = node.Picture,
        //        ObjectCategoryId = node.ObjectCategoryId,
        //        OperateObjectId = node.OperateObjectId,
        //        CreateDate = node.CreateDate,
        //        Comment = node.Comment,
        //        Rating = node.Rating,
        //        OperatorDiscription = node.OperatorDiscription,

        //    }).ToList();

        //    return results;
        //}

        //public static Maintenance ToModel(this MaintenanceData node)
        //{
        //    return new Maintenance()
        //    {
        //        Id = node.Id,
        //        MaintenanceCategoryId = node.MaintenanceCategoryId,
        //        StateId = node.StateId,
        //        UserId = node.UserId,
        //        Title = node.Title,
        //        Content = node.Content,
        //        Picture = node.Picture,
        //        ObjectCategoryId = node.ObjectCategoryId,
        //        OperateObjectId = node.OperateObjectId,
        //        CreateDate = node.CreateDate,
        //        Comment = node.Comment,
        //        Rating = node.Rating,
        //        OperatorDiscription = node.OperatorDiscription,

        //    };
        //}
        #endregion

        #region Maintenance
        public static MaintenanceData ToViewData(this Maintenance node, CategoryDictionary suffix = CategoryDictionary.None)
        {
            UserBLL     userBLL     = new UserBLL();
            BuildingBLL buildingBLL = new BuildingBLL();

            if (node == null)
            {
                return(null);
            }
            return(new MaintenanceData()
            {
                Id = node.Id,
                MaintenanceCategoryId = node.MaintenanceCategoryId,
                StateId = node.StateId,
                UserId = node.UserId,
                BuildingId = node.BuildingId,
                ApproverId = node.ApproverId,
                OperatorId = node.OperatorId,
                Title = node.Title,
                Content = node.Content,
                PictureId = node.PictureId,
                CreateDate = node.CreateDate,
                Rating = node.Rating,
                MaintenanceTime = node.MaintenanceTime,
                PurchasingId = node.PurchasingId,
                PictureUrl = node.PictureUrl,
                User = ((suffix & CategoryDictionary.User) == CategoryDictionary.User) ? node.User.ToViewData() : null,         // node.User == null ? userBLL.Find(node.UserId).ToViewData() : node.User.ToViewData(),
                Approver = ((suffix & CategoryDictionary.User) == CategoryDictionary.User) ? node.Approver.ToViewData() : null, //node.ApproverId != null ? node.Approver == null ? userBLL.Find(node.ApproverId).ToViewData() : node.Approver.ToViewData() : null,
                Operator = ((suffix & CategoryDictionary.User) == CategoryDictionary.User) ? node.Operator.ToViewData() : null, //node.OperatorId != null ? node.Operator == null ? userBLL.Find(node.OperatorId).ToViewData() : node.Operator.ToViewData() : null,
                //State = node.State.ToViewData(),
                StateName = DictionaryCache.Get()[(int)node.StateId].ChineseName,
                BuildingName = buildingBLL.Find(node.BuildingId).Name,
            });
        }
Exemplo n.º 3
0
        /// <summary>
        /// 获得指定建筑的相关定价列表
        /// </summary>
        /// <param name="buildingId">建筑id,可以为空,为空时传第4个参数建筑id</param>
        ///  <param name="energyCategoryId">能耗类型</param>
        ///   <param name="time">有效时间</param>
        ///    <param name="building">建筑,和第一个参数取其1,为空时查询建筑id获得建筑</param>
        /// <returns></returns>
        public IQueryable <ConfigDetail> GetBuildingPriceConfigdetails(int?buildingId, int energyCategoryId, DateTime time, Building building = null)
        {
            var energyCategory = DictionaryCache.Get()[energyCategoryId];

            if (building == null)
            {
                building = buildingBLL.Find(buildingId);
            }
            var configdetails = this.db.ConfigDetail.Where(o =>
                                                           o.Enabled &&
                                                           (o.BuildingId == building.Id || building.TreeId.StartsWith(o.Building.TreeId + "-")) &&
                                                           (o.BuildingCategoryId == building.BuildingCategoryId || building.BuildingCategoryDict.TreeId.StartsWith(o.BuildingCategory.TreeId + "-")) &&
                                                           (o.EnergyCategoryId == energyCategory.Id || energyCategory.TreeId.StartsWith(o.EnergyCategory.TreeId + "-")) &&
                                                           o.Template.ConfigTypeId == (DictionaryCache.MonitoringConfigTypePrice.Id + 5) &&
                                                           o.Template.WayId == DictionaryCache.PriceWayNormal.Id &&
                                                           o.Template.Enabled
                                                           //&&o.Template.ConfigCycleSettings.Any(c=>c.BeginTime<=time&&c.EndTime>time)
                                                           && this.db.MonitoringConfig.Count(c => c.TemplateId == o.Template.Id && c.ConfigCycleSettings.Any(d => d.BeginTime <= time && d.EndTime > time)) > 0
                                                           );

            return(configdetails);
        }
Exemplo n.º 4
0
        /// <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);
        }
Exemplo n.º 5
0
        public static MessageData ToViewData(this Message node, CategoryDictionary suffix = CategoryDictionary.None)
        {
            if (node == null)
            {
                return(null);
            }
            var model = new MessageData()
            {
                Id                    = node.Id,
                MessageTypeId         = node.MessageTypeId,
                CreateDate            = node.CreateDate,
                EndDate               = node.EndDate,
                MessageSourceTypeId   = node.MessageSourceTypeId,
                SrcId                 = node.SrcId,
                Subject               = node.Subject,
                Body                  = node.Body,
                Url                   = node.Url,
                ActiveDate            = node.ActiveDate,
                IsDeleted             = node.IsDeleted,
                NotActiveDate         = node.NotActiveDate,
                AlertLevelId          = node.AlertLevelId, //告警等级
                MessageTypeName       = node.MessageType == null?DictionaryCache.Get()[node.MessageTypeId].ChineseName                                                                        : node.MessageType.ChineseName,
                MessageSourceTypeName = node.MessageSourceType == null?DictionaryCache.Get()[node.MessageSourceTypeId].ChineseName                                                            : node.MessageSourceType.ChineseName,
                MessageRecords        = ((suffix & CategoryDictionary.MessageRecord) == CategoryDictionary.MessageRecord) ? node.MessageRecords.ToList().Select(x => x.ToViewData()).ToList() : null
            };

            string MessageSourceTypeStr = node.MessageSourceType == null?DictionaryCache.Get()[node.MessageSourceTypeId].Description : node.MessageSourceType.Description;

            if (MessageSourceTypeStr != null)
            {
                ViewMeterFullInfoBLL meterBLL        = new ViewMeterFullInfoBLL();
                BuildingBLL          buildingBLL     = new BuildingBLL();
                OrganizationBLL      organizationBLL = new OrganizationBLL();
                UserBLL  userBLL  = new UserBLL();
                BrandBLL brandBLL = new BrandBLL();
                try
                {
                    int id = -1;
                    if (model.SrcId != null && int.TryParse(model.SrcId, out id))
                    {
                        if (MessageSourceTypeStr.ToLower() == "meter")
                        {
                            var meter = meterBLL.Find(id).ToViewData();
                            model.MessageSource = meter;
                            model.SenderName    = meter.Name;
                        }
                        else if (MessageSourceTypeStr.ToLower() == "building")
                        {
                            var m = buildingBLL.Find(id).ToViewData();
                            model.MessageSource = m;
                            model.SenderName    = m.Name;
                        }
                        else if (MessageSourceTypeStr.ToLower() == "organization")
                        {
                            var m = organizationBLL.Find(id).ToViewData();
                            model.MessageSource = m;
                            model.SenderName    = m.Name;
                        }
                        else if (MessageSourceTypeStr.ToLower() == "brand")
                        {
                            var m = brandBLL.Find(id).ToViewData();
                            model.MessageSource = m;
                            model.SenderName    = m.Name;
                        }
                        else if (MessageSourceTypeStr.ToLower() == "user")
                        {
                            var m = userBLL.Find(model.SrcId).ToViewData();
                            model.MessageSource = m;
                            model.SenderName    = m.FullName;
                        }
                    }
                    else
                    {
                        var m = userBLL.Find(model.SrcId).ToViewData();
                        model.MessageSource = m;
                        model.SenderName    = m.FullName;
                    }
                }
                catch { }
            }

            return(model);
        }
Exemplo n.º 6
0
        /// <summary>
        /// 发送消息
        /// </summary>
        /// <param name="isNotify">是否发送通知,true,返回需要发送的消息列表,需要在web层调用notifyHub发送</param>
        /// <param name="messageData">消息内容</param>
        /// <returns>需要发送通知的对象列表</returns>
        public List <NotifyInfo> SendMessageToNotify(bool isNotify, MessagesPostData messageData)
        {
            List <NotifyInfo> result = new List <NotifyInfo>();
            MessageData       data   = new MessageData();

            EntityTools.EntityCopy(messageData.Message, data, "");
            data.CreateDate = DateTime.Now;
            if (data.ActiveDate.Year == 1)
            {
                data.ActiveDate = Convert.ToDateTime("1900-1-1");
            }
            if (data.NotActiveDate.Year == 1)
            {
                data.NotActiveDate = Convert.ToDateTime("9999-1-1");
            }
            //data.MessageSourceType =DictionaryCache.Get()[data.MessageSourceTypeId];
            //data.MessageType =DictionaryCache.Get()[data.MessageTypeId];

            List <string>     ids   = new List <string>();
            IQueryable <User> users = userBLL.Filter(o => o.IsResignOrGraduate != true && o.SecurityStamp != null);
            //List<string> userList = userBLL.Filter(o => o.IsResignOrGraduate != true).Select(o => o.Id).ToList();
            List <string> userList = null;

            if (messageData.IdsByCategory != null && messageData.IdsByCategory.Count() != 0)
            {
                foreach (var idsByCategory in messageData.IdsByCategory)
                {
                    switch (idsByCategory.Key)
                    {
                    case CategoryDictionary.Building:
                        var usersByBuilding = new List <string>();
                        foreach (var r in idsByCategory.Value)
                        {
                            int    id     = Convert.ToInt32(r);
                            string treeId = buildingBLL.Find(id).TreeId;
                            var    list   = new List <string>();
                            list            = users.Where(o => !o.IsResignOrGraduate && o.Buildings.Any(x => x.TreeId.StartsWith(treeId + "-") || x.TreeId == treeId)).Select(o => o.Id).ToList();
                            usersByBuilding = usersByBuilding.Union(list).ToList();
                        }
                        if (userList == null)
                        {
                            userList = usersByBuilding;
                        }
                        else
                        {
                            userList = userList.Intersect(usersByBuilding).ToList();
                        }
                        break;

                    case CategoryDictionary.Role:
                        var usersByRole = new List <string>();
                        foreach (var r in idsByCategory.Value)
                        {
                            var list = new List <string>();
                            list        = users.Where(o => !o.IsResignOrGraduate && o.Roles.Any(x => x.Id == r)).Select(o => o.Id).ToList();
                            usersByRole = usersByRole.Union(list).ToList();
                        }
                        if (userList == null)
                        {
                            userList = usersByRole;
                        }
                        else
                        {
                            userList = userList.Intersect(usersByRole).ToList();
                        }
                        break;

                    case CategoryDictionary.Organization:
                        var usersByOrganization = new List <string>();
                        foreach (var r in idsByCategory.Value)
                        {
                            int    id     = Convert.ToInt32(r);
                            var    list   = new List <string>();
                            string treeId = organizationBLL.Find(id).TreeId;
                            list = users.Where(o => !o.IsResignOrGraduate && (o.Organizations.Any(c => c.TreeId.StartsWith(treeId) || c.TreeId == treeId)) || (o.OrganizationId == id || userBLL.db.Organizations.FirstOrDefault(c => c.Id == id).TreeId.StartsWith(treeId))).Select(o => o.Id).ToList();
                            usersByOrganization = usersByOrganization.Union(list).ToList();
                        }
                        if (userList == null)
                        {
                            userList = usersByOrganization;
                        }
                        else
                        {
                            userList = userList.Intersect(usersByOrganization).ToList();
                        }
                        break;

                    case CategoryDictionary.Org:
                        var usersByOrg = new List <string>();
                        foreach (var r in idsByCategory.Value)
                        {
                            int id   = Convert.ToInt32(r);
                            var list = new List <string>();
                            list       = users.Where(o => !o.IsResignOrGraduate && o.OrganizationId == id).Select(o => o.Id).ToList();
                            usersByOrg = usersByOrg.Union(list).ToList();
                        }
                        if (userList == null)
                        {
                            userList = usersByOrg;
                        }
                        else
                        {
                            userList = userList.Intersect(usersByOrg).ToList();
                        }
                        break;

                    case CategoryDictionary.User:
                        if (userList == null)
                        {
                            userList = idsByCategory.Value;
                        }
                        else
                        {
                            userList = userList.Intersect(idsByCategory.Value).ToList();
                        }
                        break;
                    }
                }
            }
            var node = Create(data.ToModel());

            if (userList.Count > 0)
            {
                foreach (var id in userList)
                {
                    var toUser = userBLL.Find(id);
                    if (toUser == null)
                    {
                        continue;
                    }
                    List <string> roles = new List <string>();
                    if (toUser.Roles != null)
                    {
                        foreach (var role in toUser.Roles)
                        {
                            roles.Add(role.Id);
                        }
                    }
                    var roleSub = subscribeBLL.Filter(o => o.TypeId == 290001 && o.MessageTypeId == messageData.Message.MessageTypeId && o.Enabled == true && roles.Contains(o.TargetId)).ToList(); //角色订阅
                    var userSub = subscribeBLL.Filter(o => o.TypeId == 290002 && o.MessageTypeId == messageData.Message.MessageTypeId && o.Enabled == true && o.TargetId == toUser.Id).ToList();    //用户退订
                    if (!((roleSub != null && roleSub.Count() > 0) && (userSub == null || (userSub != null && userSub.Count() == 0))))
                    {
                        continue;
                    }
                    if (isNotify)
                    {
                        List <int> receiveModels = new List <int>();
                        foreach (var m in userSub)
                        {
                            receiveModels.Add(m.ReceivingModelId);
                        }
                        var sub = roleSub.Where(o => !receiveModels.Contains(o.ReceivingModelId)).ToList();
                        if (sub.Count > 0)
                        {
                            //NotifyHub hub = new Hubs.NotifyHub();
                            //hub.Notify(data.ToViewData(), id, sub);
                            NotifyInfo info = new NotifyInfo();
                            info.msg    = data;
                            info.userId = id;
                            info.subs   = sub;
                            result.Add(info);
                        }
                    }
                    MessageRecord record = new MessageRecord();
                    record.MessageId  = node.Id;
                    record.IsDeleted  = false;
                    record.IsEnable   = false;
                    record.IsReaded   = false;
                    record.ReadedTime = null;
                    record.UserId     = id;
                    messageRecordBLL.Create(record);
                }

                return(result);
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 7
0
        public static BalanceData ToViewData(this Balance node, CategoryDictionary suffix = CategoryDictionary.None)
        {
            if (node == null)
            {
                return(null);
            }
            var model = new BalanceData()
            {
                Id                = node.Id,
                TargetId          = node.TargetId,
                TargetCategory    = node.TargetCategory,
                EnergyCategory    = node.EnergyCategory,
                Price             = node.Price,
                EnergyConsumption = node.EnergyConsumption,
                Overplus          = node.Overplus,
                Prepay            = node.Prepay,
                Subsidy           = node.Subsidy,
                Recharge          = node.Recharge,
                CashCharge        = node.CashCharge,
                CashCorrect       = node.CashCorrect,
                Usage             = node.Usage,
                Refund            = node.Refund,
                BadDebt           = node.BadDebt,
                Total             = node.Total,
                AuditDate         = node.AuditDate,
                CreateDate        = node.CreateDate,
                OperatorId        = node.OperatorId,
                TotalCashCharge   = node.TotalCashCharge,
                TotalRecharge     = node.TotalRecharge,
                TotalSubsidy      = node.TotalSubsidy,
                BalanceDetails    = node.BalanceDetails.ToList().Select(x => x.ToViewData()).ToList()
            };

            if ((suffix & CategoryDictionary.Manager) == CategoryDictionary.Manager)
            {
                var ctx_user = new UserBLL();
                var op       = ctx_user.Find(model.OperatorId);
                if (op != null)
                {
                    model.Operator = op.ToViewData();
                }
            }
            if ((suffix & CategoryDictionary.Building) == CategoryDictionary.Building || (suffix & CategoryDictionary.Organization) == CategoryDictionary.Organization)
            {
                if (model.TargetCategory == (int)CategoryDictionary.Building)
                {
                    var ctx_bid = new BuildingBLL();
                    var b       = ctx_bid.Find(model.TargetId);
                    if (b != null)
                    {
                        model.Target = b.ToViewData();
                    }
                }
                if (model.TargetCategory == (int)CategoryDictionary.Organization)
                {
                    var ctx_org = new OrganizationBLL();
                    var o       = ctx_org.Find(model.TargetId);
                    if (o != null)
                    {
                        model.Target = o.ToViewData();
                    }
                }
            }
            return(model);
        }
Exemplo n.º 8
0
        /// <summary>
        /// 批量创建缴费账号
        /// </summary>
        /// <param name="category">用户,机构或建筑</param>
        /// <param name="isOnlyOne">是否只创建一个统一管理账户(对建筑,组织机构)</param>
        /// <param name="ids">对象id集合</param>
        /// <param name="error">返回的错误信息</param>
        /// <param name="userAccounts">创建的账号</param>
        public void CreateAccounts(CategoryDictionary category, bool isOnlyOne, List <string> ids, out string error, out List <UserAccountData> userAccounts, bool isSaveChange = true)
        {
            Encrypt encrypt = new Encrypt();

            error        = "";
            userAccounts = new List <UserAccountData>();
            var roleId = RoleCache.PayMentRoleId;
            var role   = this.db.Roles.FirstOrDefault(o => o.Id == roleId);

            if (isSaveChange != true)
            {
                userBLL.shareContext = true;
            }
            //var balanceTypes = DictionaryCache.Get().Values.Where(o => o.Code == "BalanceType" && o.Enable == true).ToList();
            switch (category)
            {
            case CategoryDictionary.Building:
                if (isOnlyOne == false)
                {
                    foreach (var idStr in ids)
                    {
                        try
                        {
                            int id       = Convert.ToInt32(idStr);
                            var building = buildingBLL.Find(id);
                            if (building == null)
                            {
                                continue;
                            }
                            var user = userBLL.Filter(o => o.Roles.Any(c => c.Id == roleId) && o.Buildings.Any(c => c.Id == building.Id)).ToList();
                            if (user.Count() == 0)
                            {
                                //不存在,创建
                                User u = new User();
                                u.Id                   = (Guid.NewGuid().ToString("D"));
                                u.UserName             = building.Id + "";
                                u.FullName             = building.Name;
                                u.PasswordHash         = "fjnewcap_缴费账户_不登录";
                                u.EmailConfirmed       = true;
                                u.PhoneNumberConfirmed = true;
                                u.TwoFactorEnabled     = true;
                                u.StaffNo              = "";
                                u.LockoutEnabled       = false;
                                u.AccessFailedCount    = 0;
                                u.Roles.Add(role);
                                u.IsResignOrGraduate = false;
                                u.EnrollDate         = DateTime.Now;
                                u.Buildings.Add(building);
                                userBLL.Create(u);

                                //foreach (var item in balanceTypes)
                                //{
                                //    var account = new UserAccount();
                                //    account.AddTime = DateTime.Now;
                                //    account.Balance = encrypt.Encrypto("0");
                                //    account.UserId = u.Id;
                                //    account.Enable = true;
                                //    account.BalanceTypeId = item.Id;
                                //    account = this.Create(account);
                                //    userAccounts.Add(account.ToViewData());
                                //}
                            }
                            //else
                            //{
                            //    //存在,开启
                            //    string uid = user[0].Id;
                            //    var accounts = this.Filter(o => o.UserId == uid).ToList();
                            //    foreach (var item in accounts)
                            //    {
                            //        item.Enable = true;
                            //        this.Update(item);
                            //        userAccounts.Add(item.ToViewData());
                            //    }
                            //}
                        }
                        catch { }
                    }
                }
                else
                {
                    try
                    {
                        var user = userBLL.Filter(o => o.Roles.Any(c => c.Id == roleId) && o.Buildings.Any(c => ids.Contains(c.Id + ""))).ToList();
                        if (user.Count() != 0)
                        {
                            error = "已经有建筑存在缴费账户,请使用添加建筑至现有缴费账户操作实现";
                        }
                        else
                        {
                            //不存在,创建
                            User u = new User();
                            u.Id                   = (Guid.NewGuid().ToString("D"));
                            u.UserName             = "******";
                            u.FullName             = "公用缴费账户";
                            u.PasswordHash         = "fjnewcap_缴费账户_不登录";
                            u.EmailConfirmed       = true;
                            u.PhoneNumberConfirmed = true;
                            u.TwoFactorEnabled     = true;
                            u.LockoutEnabled       = false;
                            u.StaffNo              = "";
                            u.AccessFailedCount    = 0;
                            u.IsResignOrGraduate   = false;
                            u.EnrollDate           = DateTime.Now;
                            u.Roles.Add(role);
                            foreach (var id in ids)
                            {
                                try
                                {
                                    int buildingId = Convert.ToInt32(id);

                                    var users = userBLL.Filter(o => o.Roles.Any(c => c.Id == roleId) && o.Buildings.Any(c => c.Id == buildingId)).ToList();
                                    foreach (var user1 in users)
                                    {
                                        var builiding = user1.Buildings.FirstOrDefault(o => o.Id == buildingId);
                                        user1.Buildings.Remove(builiding);
                                    }
                                    u.Buildings.Add(buildingBLL.Find(buildingId));
                                }
                                catch { }
                            }
                            userBLL.Create(u);

                            //foreach (var item in balanceTypes)
                            //{
                            //    var account = new UserAccount();
                            //    account.AddTime = DateTime.Now;
                            //    account.Balance = encrypt.Encrypto("0");
                            //    account.UserId = u.Id;
                            //    account.Enable = true;
                            //    account.BalanceTypeId = item.Id;
                            //    account = this.Create(account);
                            //    userAccounts.Add(account.ToViewData());
                            //}
                        }
                    }
                    catch { }
                }
                break;

            case CategoryDictionary.Organization:
                if (isOnlyOne == false)
                {
                    foreach (var idStr in ids)
                    {
                        try
                        {
                            int id           = Convert.ToInt32(idStr);
                            var organization = organizationBLL.Find(id);
                            if (organization == null)
                            {
                                continue;
                            }
                            var user = userBLL.Filter(o => o.Roles.Any(c => c.Id == roleId) && o.Organizations.Any(c => c.Id == organization.Id)).ToList();
                            if (user.Count() == 0)
                            {
                                //不存在,创建
                                User u = new User();
                                u.Id                   = (Guid.NewGuid().ToString("D"));
                                u.UserName             = organization.Id + "";
                                u.FullName             = organization.Name;
                                u.PasswordHash         = "fjnewcap_缴费账户_不登录";
                                u.EmailConfirmed       = true;
                                u.PhoneNumberConfirmed = true;
                                u.TwoFactorEnabled     = true;
                                u.LockoutEnabled       = false;
                                u.StaffNo              = "";
                                u.AccessFailedCount    = 0;
                                u.IsResignOrGraduate   = false;
                                u.EnrollDate           = DateTime.Now;
                                u.Roles.Add(role);
                                u.Organizations.Add(organization);
                                userBLL.Create(u);
                                //foreach (var item in balanceTypes)
                                //{
                                //    var account = new UserAccount();
                                //    account.AddTime = DateTime.Now;
                                //    account.Balance = encrypt.Encrypto("0");
                                //    account.UserId = u.Id;
                                //    account.Enable = true;
                                //    account.BalanceTypeId = item.Id;
                                //    account = this.Create(account);
                                //    userAccounts.Add(account.ToViewData());
                                //}
                            }
                            //else
                            //{
                            //    //存在,开启
                            //    string uid = user[0].Id;
                            //    var accounts = this.Filter(o => o.UserId == uid).ToList();
                            //    foreach (var item in accounts)
                            //    {
                            //        item.Enable = true;
                            //        this.Update(item);
                            //        userAccounts.Add(item.ToViewData());
                            //    }
                            //}
                        }
                        catch (System.Data.Entity.Validation.DbEntityValidationException dbEx)
                        {
                            throw dbEx;
                        }
                        catch { }
                    }
                }
                else
                {
                    var user = userBLL.Filter(o => o.Roles.Any(c => c.Id == roleId) && o.Organizations.Any(c => ids.Contains(c.Id + ""))).ToList();
                    if (user.Count() != 0)
                    {
                        error = "已经有组织机构存在缴费账户,请使用添加组织机构至现有缴费账户操作实现";
                    }
                    else
                    {
                        //不存在,创建
                        User u = new User();
                        u.Id                   = (Guid.NewGuid().ToString("D"));
                        u.UserName             = "******";
                        u.FullName             = "公用缴费账户";
                        u.PasswordHash         = "fjnewcap_缴费账户_不登录";
                        u.EmailConfirmed       = true;
                        u.PhoneNumberConfirmed = true;
                        u.TwoFactorEnabled     = true;
                        u.LockoutEnabled       = false;
                        u.IsResignOrGraduate   = false;
                        u.StaffNo              = "";
                        u.EnrollDate           = DateTime.Now;
                        u.AccessFailedCount    = 0;
                        u.Roles.Add(role);
                        foreach (var id in ids)
                        {
                            try
                            {
                                u.Organizations.Add(organizationBLL.Find(Convert.ToInt32(id)));
                            }
                            catch { }
                        }
                        userBLL.Create(u);

                        //foreach (var item in balanceTypes)
                        //{
                        //    var account = new UserAccount();
                        //    account.AddTime = DateTime.Now;
                        //    account.Balance = encrypt.Encrypto("0");
                        //    account.UserId = u.Id;
                        //    account.Enable = true;
                        //    account.BalanceTypeId = item.Id;
                        //    account = this.Create(account);
                        //    userAccounts.Add(account.ToViewData());
                        //}
                    }
                }
                break;

            case CategoryDictionary.User:
                foreach (var id in ids)
                {
                    try
                    {
                        var user = userBLL.Find(id);
                        if (user == null)
                        {
                            continue;
                        }
                        var accounts = this.Filter(o => o.UserId == user.Id).ToList();
                        if (accounts.Count() == 0)
                        {
                            //add
                            //foreach (var item in balanceTypes)
                            //{
                            //    var account = new UserAccount();
                            //    account.AddTime = DateTime.Now;
                            //    account.Balance = encrypt.Encrypto("0");
                            //    account.UserId = user.Id;
                            //    account.Enable = true;
                            //    account.BalanceTypeId = item.Id;
                            //    account = this.Create(account);
                            //    userAccounts.Add(account.ToViewData());
                            //}
                        }
                        //else
                        //{
                        //    //已经存在,则开启
                        //    foreach (var item in accounts)
                        //    {
                        //        item.Enable = true;
                        //        this.Update(item);
                        //        userAccounts.Add(item.ToViewData());
                        //    }
                        //}
                    }
                    catch { }
                }
                break;

            default:
                error = "只为用户、机构、建筑开启账户";
                break;
            }
        }
        public static IList <BuildingMeterTypeUserData> ToViewList(this IQueryable <BuildingMeterTypeUser> nodes, CategoryDictionary suffix = CategoryDictionary.None)
        {
            UserBLL     userBLL     = new UserBLL();
            BuildingBLL buildingBLL = new BuildingBLL();

            if (nodes == null)
            {
                return(null);
            }
            var nodeList = nodes.ToList();
            var results  = nodeList.Select(node => new BuildingMeterTypeUserData()
            {
                Id            = node.Id,
                UserId        = node.UserId,
                MeterTypeId   = node.MeterTypeId,
                BuildingId    = node.BuildingId,
                Enable        = node.Enable,
                User          = (suffix & CategoryDictionary.User) == CategoryDictionary.User ? (node.User == null ? userBLL.Find(node.UserId).ToViewData() : node.User.ToViewData()) : null,
                MeterTypeName = node.MeterType == null ? DictionaryCache.Get()[node.MeterTypeId].ChineseName : node.MeterType.ChineseName,
                Building      = (suffix & CategoryDictionary.Building) == CategoryDictionary.Building ? (node.Building == null ? buildingBLL.Find(node.BuildingId).ToViewData() : node.Building.ToViewData()) : null
            }).ToList();

            return(results);
        }
        public static BuildingMeterTypeUserData ToViewData(this BuildingMeterTypeUser node, CategoryDictionary suffix = CategoryDictionary.None)
        {
            UserBLL     userBLL     = new UserBLL();
            BuildingBLL buildingBLL = new BuildingBLL();

            if (node == null)
            {
                return(null);
            }
            return(new BuildingMeterTypeUserData()
            {
                Id = node.Id,
                UserId = node.UserId,
                MeterTypeId = node.MeterTypeId,
                BuildingId = node.BuildingId,
                Enable = node.Enable,
                User = (suffix & CategoryDictionary.User) == CategoryDictionary.User ? (node.User == null ? userBLL.Find(node.UserId).ToViewData() : node.User.ToViewData()) : null,
                MeterTypeName = node.MeterType == null?DictionaryCache.Get()[node.MeterTypeId].ChineseName : node.MeterType.ChineseName,
                //MeterType = node.MeterType == null ? DictionaryCache.Get()[node.MeterTypeId].ToViewData() : node.MeterType.ToViewData(),
                Building = (suffix & CategoryDictionary.Building) == CategoryDictionary.Building ? (node.Building == null ? buildingBLL.Find(node.BuildingId).ToViewData() : node.Building.ToViewData()) : null
            });
        }
Exemplo n.º 11
0
        public static IList <MeterGroupData> ToViewList(this IQueryable <MeterGroup> nodes, CategoryDictionary suffix = CategoryDictionary.None)
        {
            //GroupBLL groupBLL = new GroupBLL();
            MeterBLL    meterBLL    = new MeterBLL();
            BuildingBLL buildingBLL = new BuildingBLL();

            if (nodes == null)
            {
                return(null);
            }
            var nodeList = nodes.ToList();
            var results  = nodeList.Select(node => new MeterGroupData()
            {
                Id         = node.Id,
                GroupId    = node.GroupId,
                MeterId    = node.MeterId,
                BuildingId = node.BuildingId,
                Enable     = node.Enable,
                //Group = (suffix & CategoryDictionary.Group) == CategoryDictionary.Group ? (node.Group == null ? groupBLL.Find(node.GroupId).ToViewData() : node.Group.ToViewData()) : null,
                Meter    = (suffix & CategoryDictionary.Meter) == CategoryDictionary.Meter ? (node.Group == null ? meterBLL.Find(node.MeterId).ToViewData() : node.Meter.ToViewData()) : null,
                Building = (suffix & CategoryDictionary.Building) == CategoryDictionary.Building ? (node.Building == null ? buildingBLL.Find(node.BuildingId).ToViewData() : node.Building.ToViewData()) : null,
            }).ToList();

            return(results);
        }
Exemplo n.º 12
0
        public static MeterGroupData ToViewData(this MeterGroup node, CategoryDictionary suffix = CategoryDictionary.None)
        {
            //GroupBLL groupBLL = new GroupBLL();
            MeterBLL    meterBLL    = new MeterBLL();
            BuildingBLL buildingBLL = new BuildingBLL();

            if (node == null)
            {
                return(null);
            }
            return(new MeterGroupData()
            {
                Id = node.Id,
                GroupId = node.GroupId,
                MeterId = node.MeterId,
                BuildingId = node.BuildingId,
                Enable = node.Enable,
                //Group = (suffix & CategoryDictionary.Group) == CategoryDictionary.Group ? (node.Group == null ? groupBLL.Find(node.GroupId).ToViewData() : node.Group.ToViewData()) : null,
                Meter = (suffix & CategoryDictionary.Meter) == CategoryDictionary.Meter ? (node.Meter == null ? meterBLL.Find(node.MeterId).ToViewData() : node.Meter.ToViewData()) : null,
                Building = (suffix & CategoryDictionary.Building) == CategoryDictionary.Building ? (node.Building == null ? buildingBLL.Find(node.BuildingId).ToViewData() : node.Building.ToViewData()) : null,
            });
        }
Exemplo n.º 13
0
        public static AttachmentData ToViewData(this Attachment node, CategoryDictionary suffix = CategoryDictionary.None)
        {
            if (node == null)
            {
                return(null);
            }
            var model = new AttachmentData()
            {
                Id                 = node.Id,
                TargetId           = node.TargetId,
                AttachmentTypeId   = node.AttachmentTypeId,
                AttachmentFormatId = node.AttachmentFormatId,
                Description        = node.Description,
                Size               = node.Size,
                CreateTime         = node.CreateTime,
                Path               = node.Path,
                OriginalName       = node.OriginalName,
                LogicalName        = node.LogicalName,
                AttachmentType     = node.AttachmentType == null?DictionaryCache.Get()[node.AttachmentTypeId].ToViewData() : node.AttachmentType.ToViewData(),
                                         AttachmentFormat = node.AttachmentFormat == null?DictionaryCache.Get()[node.AttachmentFormatId].ToViewData() : node.AttachmentFormat.ToViewData(),
            };

            string AttachmentTypeStr = node.AttachmentType == null?DictionaryCache.Get()[node.AttachmentTypeId].Description : node.AttachmentType.Description;

            if (AttachmentTypeStr != null)
            {
                ViewMeterFullInfoBLL meterBLL        = new ViewMeterFullInfoBLL();
                BuildingBLL          buildingBLL     = new BuildingBLL();
                OrganizationBLL      organizationBLL = new OrganizationBLL();
                UserBLL    userBLL    = new UserBLL();
                BrandBLL   brandBLL   = new BrandBLL();
                MessageBLL messageBLL = new MessageBLL();
                int        id         = -1;
                if (model.TargetId != null && int.TryParse(model.TargetId, out id))
                {
                    if (AttachmentTypeStr.ToLower() == "meter")
                    {
                        model.Target = meterBLL.Find(id).ToViewData();
                    }
                    else if (AttachmentTypeStr.ToLower() == "building")
                    {
                        model.Target = buildingBLL.Find(id).ToViewData();
                    }
                    else if (AttachmentTypeStr.ToLower() == "organization")
                    {
                        model.Target = organizationBLL.Find(id).ToViewData();
                    }
                    else if (AttachmentTypeStr.ToLower() == "brand")
                    {
                        model.Target = brandBLL.Find(id).ToViewData();
                    }
                    else if (AttachmentTypeStr.ToLower() == "message")
                    {
                        model.Target = messageBLL.Find(id).ToViewData();
                    }
                }
                else
                {
                    model.Target = userBLL.Find(model.TargetId).ToViewData();
                }
            }
            return(model);
        }