コード例 #1
0
ファイル: PlanManager.cs プロジェクト: zh3305/Angular
        /// <summary>
        /// 生成单个二维码
        /// </summary>
        /// <param name="subProjectId"></param>
        /// <param name="pixel"></param>
        /// <returns></returns>
        public Task <string> SaveQrCode(Guid subProjectId, int pixel = 4)
        {
            var generator = new QRCodeGenerator();
            var filePath  = GetQrCodePath(subProjectId);

            // 如果存在就不生成
            if (File.Exists(filePath))
            {
                return(Task.FromResult(filePath));
            }
            // 生成二维码
//            var url = "https://dotnet.holacodes.com/app/home/relational-info?id=" + subProjectId;
            // 获取租户信息
            var tenantId    = CurrentUnitOfWork.GetTenantId();
            var tenancyName = tenantId.HasValue ? _tenantManager.GetById((int)tenantId).TenancyName : null;
            // 在url里面填入租户名字
            var url    = $"https://dotnet.holacodes.com/public;tenancyName={tenancyName}/relational-info?id=" + subProjectId;
            var qrCode = new QRCode(generator.CreateQrCode(url, QRCodeGenerator.ECCLevel.M, true));
            var bitmap = qrCode.GetGraphic(pixel, Color.Black, Color.White, true);

            bitmap.Save(filePath, ImageFormat.Jpeg);
            // 释放资源
            qrCode.Dispose();
            bitmap.Dispose();
            generator.Dispose();
            return(Task.FromResult(filePath));
        }
コード例 #2
0
        /// <summary>
        /// 创建一个日常任务类别
        /// </summary>
        /// <param name="procedureStep"></param>
        /// <returns></returns>
        public async Task <ProcedureStep> CreateRoutineCategory(ProcedureStep procedureStep)
        {
            var procedure = GetAll().FirstOrDefault(v => v.IsRoutine);

            // 如果为空则要新建一个procedure
            if (procedure == null)
            {
                procedure = new Procedure
                {
                    TenantId    = CurrentUnitOfWork.GetTenantId(),
                    Name        = "日常",
                    Description = "这是日常任务工序模板",
                    IsRoutine   = true
                };
                await InsertAsync(procedure);
            }

            // 给日常procedureId赋值
            procedureStep.ProcedureId  = procedure.Id;
            procedureStep.NumTaskItems = _repositoryProcedureStepTaskItem.GetAll()
                                         .Count(v => v.ProcedureStepId == procedureStep.Id);
            // 插入或者更新每一道工序
            await _repositoryProcedureStep.InsertOrUpdateAsync(procedureStep);

            return(procedureStep);
        }
コード例 #3
0
        public virtual IList <Permission> GetAllModulePermissions()
        {
            Func <int, IList <Permission> > p = (a) =>
            {
                //Host登录不进行模块查询
                if (CurrentUnitOfWork.GetTenantId() == null)
                //if (AbpSession.MultiTenancySide == Abp.MultiTenancy.MultiTenancySides.Host)
                {
                    return(new List <Permission>());
                }
                var permissions = new List <Permission>();
                var moduleInfos = Repository.GetAllIncluding(o => o.Buttons, o => o.ColumnInfos).ToList();
                //所有按钮的权限
                permissions.AddRange(moduleInfos.SelectMany(o => o.Buttons.Where(b => b.RequirePermission && b.IsEnabled).Select(b => new Permission(b.ButtonPermissionName, new LocalizableString(b.ButtonName, MasterConsts.LocalizationSourceName)))));

                //启用了权限的字段
                var fields = moduleInfos.SelectMany(o => o.ColumnInfos).Where(o => o.EnableFieldPermission);

                permissions.AddRange(fields.SelectMany(o =>
                {
                    var fieldPermisssions = new List <Permission>();
                    fieldPermisssions.Add(new Permission(o.ColumnAddPermission, new LocalizableString(o.ColumnName + "_添加", MasterConsts.LocalizationSourceName)));
                    fieldPermisssions.Add(new Permission(o.ColumnEditPermission, new LocalizableString(o.ColumnName + "_修改", MasterConsts.LocalizationSourceName)));
                    fieldPermisssions.Add(new Permission(o.ColumnViewPermission, new LocalizableString(o.ColumnName + "_查看", MasterConsts.LocalizationSourceName)));
                    return(fieldPermisssions);
                }));
                return(permissions);
            };
            var cacheKey = AbpSession.TenantId ?? 0;

            //return p(cacheKey);

            return(CacheManager.GetCache <int, IList <Permission> >("ModuleInfoPermission")
                   .Get(cacheKey, p));
        }
コード例 #4
0
        /// <summary>
        /// 通过TenantId取得用户,不在项目中的
        /// </summary>
        /// <param name="memberQuery"></param>
        /// <param name="tenantId"></param>
        /// <param name="searchKey"></param>
        /// <returns></returns>
        public async Task <IEnumerable <ProjectMember> > GetAllMemberNotInProject(string searchKey,
                                                                                  IQueryable <User> memberQuery = null)
        {
            var tenantId = CurrentUnitOfWork.GetTenantId();
            var tenant   = tenantId.HasValue ? await _tenantManager.GetByIdAsync((int)tenantId) : null;

            // 取得整个公司的人
//            CurrentUnitOfWork.DisableFilter(AbpDataFilters.MayHaveTenant);
            var query = _repositoryUser.GetAll();//.Where(v => v.TenantId == tenantId);

            // 筛选未在项目组中的人
            if (memberQuery != null)
            {
                query = query.Where(v => !memberQuery.Contains(v)).Include(v => v.Roles);
            }
            // 转换为member类型方便显示
            var projectMembers = new List <ProjectMember>();

            foreach (var one in query)
            {
                var member = new ProjectMember
                {
                    User   = one,
                    Tenant = tenant
                };
                projectMembers.Add(member);
            }

            // 筛选搜索的关键字
            if (!searchKey.IsNullOrWhiteSpace())
            {
                projectMembers = projectMembers.Where(v => v.User.Name.Contains(searchKey)).ToList();
            }
            return(projectMembers);
        }
コード例 #5
0
        /// <summary>
        /// 所有租户中剩下的人
        /// </summary>
        /// <param name="tenantId"></param>
        /// <param name="projectId"></param>
        /// <param name="searchKey"></param>
        /// <param name="currentTenantId"></param>
        /// <returns></returns>
        public IQueryable <ProjectMember> GetAllMember(Guid?projectId, string searchKey,
                                                       int?currentTenantId)
        {
//            CurrentUnitOfWork.DisableFilter(AbpDataFilters.MayHaveTenant);
            var query = _repositoryProjectMember.GetAll();

            // 筛选已分配的人
            query = query.Where(v => v.TenantId == CurrentUnitOfWork.GetTenantId());
            if (projectId.HasValue)
            {
                query = query.Where(v => v.ProjectId == projectId);
            }
            query = query.Include(i => i.User).ThenInclude(v => v.Roles)
                    .Include(i => i.Tenant).Include(i => i.Project);
            // 筛选出本租户才有的项目,两个queryable对象没法使用contains,所以需要toList
            var projectQuery = _repositoryProject.GetAll().Where(p => p.TenantId == currentTenantId).Select(v => v.Id);

            query = query.Where(v => projectQuery.Contains(v.ProjectId));
            // 筛选搜索的关键字
            if (!searchKey.IsNullOrWhiteSpace())
            {
                query = query.Where(v => v.User.Name.Contains(searchKey));
            }
            return(query);
        }
コード例 #6
0
        /// <summary>
        /// 创建
        /// </summary>
        /// <param name="Delivery"></param>
        /// <returns></returns>
        public virtual async Task CreateAsync(Delivery entity)
        {
            var homeOwer = await _homeOwerManager.HomeOwerRepository.FirstOrDefaultAsync(entity.HomeOwerId);

            if (homeOwer != null)
            {
                //title
                entity.Title = L("DeliveryTitleString", CultureInfo.CurrentUICulture, homeOwer.Name);
                //content
                entity.Content = L("DeliveryContentString", CultureInfo.CurrentUICulture, entity.Token);

                await DeliveryRepository.InsertAsync(entity);

                //添加消息通知
                var message = new Message(CurrentUnitOfWork.GetTenantId(), L("DeliveryTitleMessage", CultureInfo.CurrentUICulture, homeOwer.Name), L("DeliveryContentMessage", CultureInfo.CurrentUICulture, homeOwer.Name), null, EMessageStatusTypeUtils.GetValue("Sent"), homeOwer.CommunityId, entity.BuildingId, entity.FlatNoId, entity.HomeOwerId, entity.CommunityName, entity.BuildingName, entity.FlatNo);
                await _messageManager.CreateAsync(message);

                var userId      = _abpSession.UserId;
                var currentUser = _userManager.Users.FirstOrDefault(user => user.Id == userId);
                if (currentUser != null)
                {
                    Logger.InfoFormat("Admin {0} Create Delivery {1}", currentUser.UserName, entity.Title);
                }
            }
        }
コード例 #7
0
        //public PersonManager PersonManager { get; set; }

        /// <summary>
        /// 缓存方式获取所有有效策略
        /// </summary>
        /// <returns></returns>
        public virtual async Task <List <Tactic> > GetAllActiveTactics()
        {
            var tenantId = CurrentUnitOfWork.GetTenantId() ?? 0;

            return(await CacheManager.GetCache <int, List <Tactic> >("Tactics").GetAsync(tenantId, async o => {
                return await GetAll().Where(t => t.IsActive && t.TenantId == CurrentUnitOfWork.GetTenantId()).ToListAsync();
            }));
        }
コード例 #8
0
        /// <summary>
        /// 添加快递信息
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task <BuildingDto> CreateBuilding(CreateBuildingInput input)
        {
            var entity = new Building(CurrentUnitOfWork.GetTenantId(), input.CommunityId, input.BuildingName);

            await _manager.CreateAsync(entity);

            return(Mapper.Map <BuildingDto>(entity));
        }
コード例 #9
0
        private int?GetCurrentTenantId()
        {
            if (CurrentUnitOfWork != null)
            {
                return(CurrentUnitOfWork.GetTenantId());
            }

            return(AbpSession.TenantId);
        }
コード例 #10
0
        public async Task CreateDoor(CreateDoorInput input)
        {
            var community = _communityManager.CommunityRepository.FirstOrDefault(input.CommunityId);
            var entity    = new Door(CurrentUnitOfWork.GetTenantId(), community.Id, input.Name, input.PId, input.DepartId);

            entity.DepartId = community.DepartId;
            entity.DoorType = input.DoorType;
            await _manager.CreateAsync(entity);
        }
コード例 #11
0
        /// <summary>
        /// 生成唯一的key
        /// </summary>
        /// <param name="name"></param>
        /// <param name="groupId"></param>
        /// <returns></returns>
        protected string GeneratePictureKey(string name, long groupId)
        {
            if (CurrentUnitOfWork.GetTenantId().HasValue)
            {
                return($"{CurrentUnitOfWork.GetTenantId().Value}/{groupId}/{name}");
            }

            return(string.Empty);
        }
コード例 #12
0
        public virtual async Task <ModuleInfo> GetModuleInfo(string moduleKey)
        {
            //此处不能用abpsession,因为Host管理界面会模拟tenantid进行提交查询
            var tenantId = CurrentUnitOfWork.GetTenantId();
            //return await _moduleInfoRepository.GetAllIncluding(o => o.ColumnInfos, o => o.Buttons).Where(o => o.ModuleKey == moduleKey).FirstOrDefaultAsync();
            var key = moduleKey + "@" + (tenantId ?? 0);

            return(await CacheManager.GetCache <string, ModuleInfo>("ModuleInfo")
                   .GetAsync(key, async() => { return await Repository.GetAllIncluding(o => o.ColumnInfos, o => o.Buttons).Where(o => o.ModuleKey == moduleKey).FirstOrDefaultAsync(); }));
        }
コード例 #13
0
        public async Task CreateOpenAttemp(CreateOpenAttempInput input)
        {
            var homeOwer = await _homeOwerManager.HomeOwerRepository.FirstOrDefaultAsync(input.HomeOwerId);

            var entity = new OpenAttemp(CurrentUnitOfWork.GetTenantId(), homeOwer.CommunityId);

            entity.HomeOwerId = input.HomeOwerId;
            entity.UserName   = input.UserName;
            entity.IsSuccess  = input.IsSuccess;

            await _manager.CreateAsync(entity);
        }
コード例 #14
0
ファイル: ProviderAppService.cs プロジェクト: zh3305/Angular
        /// <summary>
        /// 创建
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public override async Task <ProviderDto> Create(CreateProviderInput input)
        {
            CheckCreatePermission();
            var entity = MapToEntity(input);

            entity.TenantId = CurrentUnitOfWork.GetTenantId();
            await Repository.InsertAsync(entity);

            await CurrentUnitOfWork.SaveChangesAsync();

            return(MapToEntityDto(entity));
        }
コード例 #15
0
        public async Task CreateAccessKey(CreateAccessKeyInput input)
        {
            var homeOwer = await _homeOwerManager.HomeOwerRepository.FirstOrDefaultAsync(input.HomeOwerId);

            var door = await _doorManager.DoorRepository.FirstOrDefaultAsync(input.DoorId);

            var entity    = new AccessKey(CurrentUnitOfWork.GetTenantId(), door, homeOwer, input.Validity, homeOwer.CommunityId);
            var accessKey = await _manager.CreateAsync(entity);


            accessKey.GetKey(door.PId, homeOwer.Phone, accessKey.Validity);
        }
コード例 #16
0
        public async Task CreateCommunity(CreateCommunityInput input)
        {
            double lat = 0;
            double lng = 0;

            if (!string.IsNullOrEmpty(input.LatLng))
            {
                lat = double.Parse(input.LatLng.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries)[0]);
                lng = double.Parse(input.LatLng.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries)[1]);
            }

            var community = new Community(CurrentUnitOfWork.GetTenantId(), input.Name, input.Address, lat, lng);

            if (input.DoorTypes != null)
            {
                community.DoorTypes = String.Join(",", input.DoorTypes);
            }
            if (input.Images != null)
            {
                community.Images = String.Join(",", input.Images);
            }

            await _communityManager.CreateAsync(community);

            CurrentUnitOfWork.SaveChanges();

            //设置当前用户的角色,有管理该小区的权限
            if (_abpSession.UserId.HasValue)
            {
                var currentUser = await _userManager.GetUserByIdAsync(_abpSession.UserId.Value);

                var distinctRoleIds = (
                    from userListRoleDto in currentUser.Roles
                    select userListRoleDto.RoleId
                    ).Distinct();
                //角色管理的小区id
                if (await _permissionChecker.IsGrantedAsync(AppPermissions.Pages_DoorSystem_Communities_Create))
                {
                    foreach (var roleId in distinctRoleIds)
                    {
                        var role         = (await _roleManager.GetRoleByIdAsync(roleId));
                        var communityIds = role.CommunityIdArray;
                        if (!communityIds.Contains(community.Id))
                        {
                            communityIds.Add(community.Id);
                        }
                        role.CommunityIdArray = communityIds;
                        await _roleManager.UpdateAsync(role);
                    }
                }
            }
        }
コード例 #17
0
 /// <summary>
 /// 创建工作项
 /// </summary>
 /// <param name="taskItem"></param>
 /// <returns></returns>
 /// <exception cref="UserFriendlyException"></exception>
 public async Task <TaskItem> CreateAsync(TaskItem taskItem)
 {
     try
     {
         taskItem.TenantId = CurrentUnitOfWork.GetTenantId();
         return(await _repositoryTaskItem.InsertAsync(taskItem));
     }
     catch (Exception e)
     {
         Logger.Warn(e.ToString(), e);
         throw new UserFriendlyException("创建失败");
     }
 }
コード例 #18
0
        public IList <Permission> GetAll()
        {
            //var key = AbpSession.TenantId ?? 0;
            var key = CurrentUnitOfWork.GetTenantId() ?? 0;

            return(_cacheManager.GetCache <int, IList <Permission> >("Permissions").Get(key, () => {
                var permissions = new List <Permission>();
                //加入导航权限
                permissions.AddRange(Resolve <IMenuManager>().GetAllMenuPermissions());
                //todo:加入菜单对应的资源权限
                //加入模块权限
                permissions.AddRange(Resolve <IModuleInfoManager>().GetAllModulePermissions());
                return permissions;
            }));
        }
コード例 #19
0
        /// <summary>
        /// 创建保修
        /// ================================
        /// 1. 状态:ReportSend
        /// 2. 没有完成时,完成时间显示 N/A
        /// 3. HandyName暂时手动填写
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task CreateReport(CreateReportInput input)
        {
            var homeOwer = await _homeOwerManager.HomeOwerRepository.FirstOrDefaultAsync(input.HomeOwerId);

            var community = await _communityManager.CommunityRepository.GetAsync(input.CommunityId);

            var building = await _buildingManager.BuildingRepository.GetAsync(input.BuildingId);

            var flatNo = await _flatNoManager.FlatNumberRepository.GetAsync(input.FlatNoId);

            var entity = new Report(CurrentUnitOfWork.GetTenantId(), input.Title, input.Content, input.FileArray, input.CommunityId, input.BuildingId, input.FlatNoId, input.HomeOwerId, community.Name, building.BuildingName, flatNo.FlatNo);

            entity.HomeOwerId = input.HomeOwerId;
            await _manager.CreateAsync(entity);
        }
コード例 #20
0
ファイル: FileItemManager.cs プロジェクト: zh3305/Angular
        /// <summary>
        /// 创建唯一一个
        /// </summary>
        /// <param name="file"></param>
        /// <param name="relationalId"></param>
        /// <param name="category"></param>
        /// <returns></returns>
        public async Task <FileItem> CreateOnly(IFormFile file, Guid?relationalId, FileItemCategory category)
        {
            // 先删除原有的,包括数据库部分与文件部分
            if (!relationalId.HasValue)
            {
                throw new UserFriendlyException("请提供RelationalId");
            }
            await DeleteAll((Guid)relationalId, category);

            CurrentUnitOfWork.SaveChanges();
            // 再创建
            var obj = CreateFile(_hostingEnvironment, file, relationalId, category, CurrentUnitOfWork.GetTenantId());

            return(await Repository.InsertAsync(obj));
        }
コード例 #21
0
        /// <summary>
        /// 缓存方式获取实体所有数据
        /// </summary>
        /// <returns></returns>
        public virtual async Task <List <TEntity> > GetAllList()
        {
            var tenantId = CurrentUnitOfWork.GetTenantId();

            var key    = typeof(TEntity).FullName + "@" + (tenantId ?? 0);
            var result = await CacheManager.GetCache <string, List <TEntity> >(typeof(TEntity).FullName)
                         .GetAsync(key, async() => { return(await Repository.GetAll().ToListAsync()); });

            //if(result==null || result.Count == 0)
            //{
            //    await CacheManager.GetCache<string, List<TEntity>>(typeof(TEntity).FullName).RemoveAsync(key);
            //    result= await GetAll().ToListAsync();
            //}

            return(result);
        }
コード例 #22
0
        /// <summary>
        /// 添加快递信息
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task <DeliveryDto> CreateDelivery(CreateDeliveryInput input)
        {
            var flatNumber = await _flatNoManager.FlatNumberRepository.FirstOrDefaultAsync(input.FlatNoId);

            var homeOwer = await _homeOwerManager.HomeOwerRepository.FirstOrDefaultAsync(input.HomeOwerId);

            var entity = new Delivery(CurrentUnitOfWork.GetTenantId(), input.HomeOwerId, homeOwer.CommunityId, input.BuildingId, input.FlatNoId, flatNumber.Building.Community.Name, flatNumber.Building.BuildingName, flatNumber.FlatNo, input.Barcode);

            if (!string.IsNullOrEmpty(input.Content))
            {
                entity.Content = input.Content;
            }
            await _manager.CreateAsync(entity);

            return(Mapper.Map <DeliveryDto>(entity));
        }
コード例 #23
0
        /// <summary>
        /// 添加业主信息
        /// ================================
        /// 1. 业主录入初始状态:Initial
        /// 2. 业主录入,默认自带小区大门的门禁
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task CreateHomeOwer(CreateHomeOwerInput input)
        {
            var community = await _communityManager.CommunityRepository.FirstOrDefaultAsync(input.CommunityId);

            var entity = new HomeOwer(CurrentUnitOfWork.GetTenantId(), input.CommunityId, input.Forename, input.Surname, input.Phone, input.Email, EHomeOwerTitleTypeUtils.GetValue(input.Title), EHomeOwerGroupTypeUtils.GetValue(input.UserGroup), community.Name, input.AltContace, input.AltMobile);

            //录入业主关联的门禁
            entity.Doors = new List <Door>();
            //小区大门
            var gates = await _doorManager.DoorRepository.GetAllListAsync(d => d.DoorType == EDoorType.Gate.ToString());

            gates.ForEach(door =>
            {
                entity.Doors.Add(door);
            });

            await _manager.CreateAsync(entity);
        }
コード例 #24
0
        /// <summary>
        /// 业主审核,同时发放钥匙
        /// </summary>
        /// <param name="input">业主ID</param>
        /// <returns></returns>
        public async Task AuthHomeOwer(IdInput <long> input)
        {
            var homeOwer = await _manager.HomeOwerRepository.FirstOrDefaultAsync(input.Id);

            if (homeOwer.IsLock)
            {
                throw new UserFriendlyException(L("HomeOwerIsLocked"));
            }

            var doorIds = from d in homeOwer.Doors
                          select d.Id;
            var doors = await _doorManager.DoorRepository.GetAllListAsync(d => doorIds.Contains(d.Id));

            //发放钥匙
            foreach (var door in doors)
            {
                try
                {
                    var key = await _accessKeyManager.AccessKeyRepository.FirstOrDefaultAsync(k => k.HomeOwer.Id == homeOwer.Id && k.Door == door);

                    if (key == null)
                    {
                        key = new AccessKey(CurrentUnitOfWork.GetTenantId(), door, homeOwer, DateTime.Now.AddYears(50), homeOwer.CommunityId);
                        await _accessKeyManager.CreateAsync(key);

                        key.GetKey(door.PId, homeOwer.Phone, key.Validity);
                    }
                    else if (!key.IsAuth)
                    {
                        key.GetKey(door.PId, homeOwer.Phone, key.Validity);
                    }
                }
                catch (Exception)
                {
                    continue;
                }
            }

            homeOwer.Status    = EHomeOwerStatusType.Done;
            homeOwer.AuthTime  = DateTime.Now;
            homeOwer.AuthAdmin = base.GetCurrentUser().UserName;
            await _manager.UpdateAsync(homeOwer);
        }
コード例 #25
0
ファイル: PlanManager.cs プロジェクト: zh3305/Angular
        /// <summary>
        /// 批量生成二维码并下载,要把生成和下载分开的原因是:在文件下载的位置查询数据库,不建议这样做
        /// </summary>
        /// <param name="subProjectIds"></param>
        /// <param name="pixel"></param>
        /// <returns></returns>
        public Task SaveQrCodes(IEnumerable <Guid> subProjectIds, int pixel = 4)
        {
            var generator = new QRCodeGenerator();
            // 生成二维码,操作时间较长,获取hash名字做临时文件夹
            var hashName = MD5.Create().ComputeHash(Encoding.Default.GetBytes(DateTime.Now.ToLongTimeString()))
                           .ToString();
            var qrFolderPath = Path.Join(_hostingEnvironment.ContentRootPath, FileItemManager.FileItemsPath, hashName);

            Directory.CreateDirectory(qrFolderPath);
            foreach (var id in subProjectIds)
            {
//                var url = "https://dotnet.holacodes.com/app/home/relational-info?id=" + id;
                // 获取租户信息
                var tenantId    = CurrentUnitOfWork.GetTenantId();
                var tenancyName = tenantId.HasValue ? _tenantManager.GetById((int)tenantId).TenancyName : null;
                // 在url里面填入租户名字
                var url    = $"https://dotnet.holacodes.com/public;tenancyName={tenancyName}/relational-info?id=" + id;
                var qrCode = new QRCode(generator.CreateQrCode(url, QRCodeGenerator.ECCLevel.M, true));
                var bitmap = qrCode.GetGraphic(pixel, Color.Black, Color.White, true);
                bitmap.Save(Path.Join(qrFolderPath, id + ".jpg"), ImageFormat.Jpeg);
                qrCode.Dispose();
                bitmap.Dispose();
            }

            generator.Dispose();
            // 创建压缩文件
            var qrZipFile = GetQrCodesZipPath();

            if (File.Exists(qrZipFile))
            {
                File.Delete(qrZipFile);
            }
            System.IO.Compression.ZipFile.CreateFromDirectory(qrFolderPath, qrZipFile);
            // 删除临时文件
            if (Directory.Exists(qrFolderPath))
            {
                Directory.Delete(qrFolderPath, true);
            }
            return(Task.CompletedTask);
        }
コード例 #26
0
        private async Task CreateUserAsync(ImportUserDto input)
        {
            var tenantId = CurrentUnitOfWork.GetTenantId();

            if (tenantId.HasValue)
            {
                await _userPolicy.CheckMaxUserCountAsync(tenantId.Value);
            }

            var user = _objectMapper.Map <User>(input); //Passwords is not mapped (see mapping configuration)

            user.Password = input.Password;
            user.TenantId = tenantId;

            if (!input.Password.IsNullOrEmpty())
            {
                await UserManager.InitializeOptionsAsync(tenantId);

                foreach (var validator in _passwordValidators)
                {
                    (await validator.ValidateAsync(UserManager, user, input.Password)).CheckErrors();
                }

                user.Password = _passwordHasher.HashPassword(user, input.Password);
            }

            user.Roles = new List <UserRole>();
            var roleList = _roleManager.Roles.ToList();

            foreach (var roleName in input.AssignedRoleNames)
            {
                var correspondingRoleName = GetRoleNameFromDisplayName(roleName, roleList);
                var role = await _roleManager.GetRoleByNameAsync(correspondingRoleName);

                user.Roles.Add(new UserRole(tenantId, user.Id, role.Id));
            }

            (await UserManager.CreateAsync(user)).CheckErrors();
        }
コード例 #27
0
        /// <summary>
        /// 创建
        /// </summary>
        /// <param name="OpenAttemp"></param>
        /// <returns></returns>
        public virtual async Task CreateAsync(OpenAttemp entity)
        {
            entity.TenantId = CurrentUnitOfWork.GetTenantId();

            var homeOwer = await _homeOwerManager.HomeOwerRepository.FirstOrDefaultAsync(entity.HomeOwerId);

            if (homeOwer != null)
            {
                entity.HomeOwerName = homeOwer.Name;
            }

            if (AuditInfoProvider != null)
            {
                var auditInfo = new AuditInfo();
                AuditInfoProvider.Fill(auditInfo);
                entity.BrowserInfo     = auditInfo.BrowserInfo;
                entity.ClientIpAddress = auditInfo.ClientIpAddress;
                entity.ClientName      = auditInfo.ClientName;
            }

            await OpenAttempRepository.InsertAsync(entity);
        }
コード例 #28
0
        /// <summary>
        /// 添加信息
        /// ================================
        /// 业主通知:选择具体业主然后添加信息
        /// 1. 记录CommunityId, BuildingId, FlatNoId, HomeOwerId
        /// 2. IsPublic = false
        /// 3. IsRead = false
        /// ================================
        /// 公告:选择单元楼然后添加信息
        /// 1. 记录CommunityId, BuildingId
        /// 2. FlatNoId, HomeOwerId为Null
        /// 3. IsPublic = true
        /// 4. IsRead = null
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task CreateMessage(CreateMessageInput input)
        {
            #region 公告
            if (input.BuildingIds != null)
            {
                foreach (long buildingId in input.BuildingIds)
                {
                    var building = await _buildingManager.BuildingRepository.GetAsync(buildingId);

                    if (building != null)
                    {
                        var entity = new Message(CurrentUnitOfWork.GetTenantId(), input.Title, input.Content, input.FileArray, EMessageStatusTypeUtils.GetValue(input.Status), building.CommunityId, buildingId);
                        await _manager.CreateAsync(entity);
                    }
                }
            }
            #endregion

            #region 消息
            if (input.BuildingIds != null)
            {
                foreach (var homeOwerDto in input.HomeOwerIds)
                {
                    var community = await _communityManager.CommunityRepository.GetAsync(homeOwerDto.CommunityId);

                    var building = await _buildingManager.BuildingRepository.GetAsync(homeOwerDto.BuildingId);

                    var flatNo = await _flatNoManager.FlatNumberRepository.GetAsync(homeOwerDto.FlatNoId);

                    if (community != null && building != null && flatNo != null)
                    {
                        var entity = new Message(CurrentUnitOfWork.GetTenantId(), input.Title, input.Content, input.FileArray, EMessageStatusTypeUtils.GetValue(input.Status), homeOwerDto.CommunityId, homeOwerDto.BuildingId, homeOwerDto.FlatNoId, homeOwerDto.HomeOwerId, community.Name, building.BuildingName, flatNo.FlatNo);
                        await _manager.CreateAsync(entity);
                    }
                }
            }
            #endregion
        }
コード例 #29
0
        /// <summary>
        /// 获取DealerSalesInfo的分页列表信息
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task <PagedResultDto <DealerSalesInfoListDto> > GetPaged(GetDealerSalesInfosInput input)
        {
            var tenantId = CurrentUnitOfWork.GetTenantId();
            var company  = await _companyRepository.FirstOrDefaultAsync(c => c.Id == tenantId);

            if (company == null)
            {
                return(null);
            }

            var dealerMarketDptRelations = _dealerMarketDptRelationRepository.GetAll()
                                           .WhereIf(input.MarketingDepartmentId.HasValue, dm => dm.MarketId == input.MarketingDepartmentId);
            var dealerSalesInfoes = _dealersalesinfoRepository.GetAll();

            dealerSalesInfoes = company.Type == DcsCompanyType.分公司
                ? dealerSalesInfoes.Where(d => d.BranchId == tenantId) : dealerSalesInfoes.Where(d => d.DealerId == tenantId);

            var dealers = _dealerRepository.GetAll()
                          .Where(d => dealerMarketDptRelations.Any(dm => d.Id == dm.DealerId) && d.Type == DcsDealerType.一级经销商)
                          .WhereIf(!input.Filter.IsNullOrWhiteSpace(), d => d.Code.Contains(input.Filter) || d.Name.Contains(input.Filter))
                          .WhereIf(input.DealerStatus != null, d => input.DealerStatus.Contains(d.Status));
            var query = from dsi in dealerSalesInfoes
                        join d in dealers on dsi.DealerId equals d.Id
                        join c in _companyRepository.GetAll() on d.Id equals c.Id
                        select new DealerSalesInfoListDto
            {
                Id         = dsi.Id,
                DealerCode = d.Code,
                DealerCompanyBusinessScope       = c.BusinessScope,
                DealerCompanyFoundDate           = c.FoundDate,
                DealerCompanyLegalRepresentative = c.LegalRepresentative,
                DealerCompanyRegisterCapital     = c.RegisterCapital,
                DealerCreateTime   = d.CreationTime,
                DealerCreatorName  = d.CreatorName,
                DealerId           = d.Id,
                DealerModifierName = d.ModifierName,
                DealerModifyTime   = d.LastModificationTime,
                DealerName         = d.Name,
                DealerShortName    = d.ShortName,
                DealerStatus       = d.Status,
                DealerType         = d.Type,
                ErpServiceCode     = dsi.ErpServiceCode,
                SalesHotline       = dsi.SalesHotline,
                ShopLevel          = dsi.ShopLevel,
                ShopProperty       = dsi.ShopProperty
            };

            var dealersalesinfoCount = await query.CountAsync();

            var dealersalesinfos = await query
                                   .OrderBy(input.Sorting)
                                   .PageBy(input)
                                   .ToListAsync();

            //var dealersalesinfoListDtos = dealersalesinfos.Select(d => d.dsi).MapTo<List<DealerSalesInfoListDto>>();

            return(new PagedResultDto <DealerSalesInfoListDto>(
                       dealersalesinfoCount,
                       dealersalesinfos
                       ));
        }
コード例 #30
0
        public virtual async Task <IHttpActionResult> FreshAccessKeys(long id, string userName, string token, int?tenantId = null)
        {
            base.AuthUser();
            using (CurrentUnitOfWork.SetTenantId(tenantId))
            {
                var homeOwer = _homeOwerManager.HomeOwerRepository.FirstOrDefault(h => h.Id == id);
                if (homeOwer == null)
                {
                    throw ErrorCodeTypeUtils.ThrowError(ErrorCodeType.HomeOwerNotExists);
                }
                var homeOwerUser = await _homeOwerUserManager.HomeOwerUserRepository.FirstOrDefaultAsync(hu => hu.HomeOwerId == homeOwer.Id);

                if (homeOwerUser == null)
                {
                    throw ErrorCodeTypeUtils.ThrowError(ErrorCodeType.HomeOwerUserNotExists);
                }
                if (homeOwer.Status == EHomeOwerStatusType.Waiting)
                {
                    throw ErrorCodeTypeUtils.ThrowError(ErrorCodeType.HomeOwerUserIsAuthing);
                }
                //获取业主门禁,判断是否已经添加钥匙,是否已经认证
                foreach (var door in homeOwer.Doors)
                {
                    var key = await _accessKeyManager.AccessKeyRepository.FirstOrDefaultAsync(k => k.Door == door && k.HomeOwer.Id == homeOwer.Id);

                    if (key == null)
                    {
                        key = new AccessKey(CurrentUnitOfWork.GetTenantId(), door, homeOwer, DateTime.Now.AddYears(50), homeOwer.CommunityId);

                        try
                        {
                            await _accessKeyManager.CreateAsync(key);
                        }
                        catch (UserFriendlyException ex)
                        {
                            if (ex.Message == "10")
                            {
                                ErrorCodeTypeUtils.ThrowError(ErrorCodeType.CreatedAccessKeyIsExistsButIsNotAuth);
                            }
                            else if (ex.Message == "11")
                            {
                                ErrorCodeTypeUtils.ThrowError(ErrorCodeType.CreatedAccessKeyIsExists);
                            }
                        }
                        key.GetKey(door.PId, homeOwer.Phone, key.Validity);
                    }
                    else if (!key.IsAuth)
                    {
                        key.GetKey(door.PId, homeOwer.Phone, key.Validity);
                    }
                }

                var list = (from a in _accessKeyManager.AccessKeyRepository.GetAll()
                            join d in _doorManager.DoorRepository.GetAll() on a.Door equals d
                            where a.HomeOwer.Id == homeOwer.Id && d.IsAuth
                            select new { KeyId = a.LockId, KeyValidity = a.Validity, CommunityId = d.DepartId, KeyName = d.Name, KeyType = d.DoorType, IsAuth = a.IsAuth }
                            ).ToList();

                var result = new ArrayList();
                list.ForEach(i =>
                {
                    result.Add(new
                    {
                        i.KeyId,
                        i.KeyValidity,
                        i.CommunityId,
                        i.KeyName,
                        KeyType = EDoorTypeUtils.GetEnum(i.KeyType),
                        i.IsAuth
                    });
                });

                return(Ok(new
                {
                    AppKey = _doorSystemSdk.Params["app_key"],
                    UserId = homeOwer.Phone,
                    AccessKeys = result
                }));
            }
        }