Exemple #1
0
        /// <summary>
        /// 获取与指定机构关联的一级建筑
        /// </summary>
        /// <param name="organizationId">机构编号</param>
        /// <returns></returns>
        public IQueryable <Building> GetPrimaryByOrg(int organizationId, bool includeDisable = false)
        {
            var organization = organizationBLL.Find(organizationId);
            var buidlings    = db.Buildings.Where(b => b.Organization.TreeId.StartsWith(organization.TreeId) && b.Enable && (includeDisable ? true : b.TypeDict.Enable));
            var result       = from bl in buidlings
                               join bc in buidlings
                               on bl.ParentId equals bc.Id into temp
                               from eb in temp.DefaultIfEmpty()
                               where eb == null
                               select bl;

            return(result);
        }
Exemple #2
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);
        }
Exemple #3
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);
        }
Exemple #4
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);
            }
        }
Exemple #5
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);
        }
Exemple #6
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;
            }
        }
Exemple #7
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);
        }