示例#1
0
        public async Task CreateAsync(BulkDataOperationDto bulkDataOperationDto)
        {
            if (string.IsNullOrEmpty(_requestContext.GroupId))
            {
                throw new YawnMassageException("ERROR_GROUP_NOT_DEFINED");
            }

            var permittedGroups = await _applicationService.GetPermittedGroupListAsync();

            if (_requestContext.GroupId != "any" && _requestContext.GroupId != "*" &&
                !permittedGroups.Where(c => c.Id == _requestContext.GroupId).Any())
            {
                throw new UnauthorizedAccessException("ERROR_UNAUTHORIZED");
            }

            if (bulkDataOperationDto.OperationTypeCode == BulkDataOperationType.Import &&
                bulkDataOperationDto.IsNewDatabaseFile)
            {
                if (bulkDataOperationDto.GroupId == "any")
                {
                    throw new YawnMassageException("ERROR_ANY_GROUP_NEW_DATABASE_FILE");
                }
                else if (!await _userContextService.HasPermissionAsync("BULKDATA_NEW_DATABASE_FILE"))
                {
                    throw new YawnMassageException("ERROR_NO_PERMISSION_NEW_DATABASE_FILE");
                }
            }

            var user = await _userService.GetUserAsync(_requestContext.UserId);

            var timeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById(user.TimeZone);
            var userDateTime = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, timeZoneInfo);

            var bulkDataOperation = new BulkDataOperation()
            {
                FileName = bulkDataOperationDto.OperationTypeCode == BulkDataOperations.ExportOperation ?
                           userDateTime.ToStandardReportNameFormatByDate(BulkDataFileDetails.ExportFileNamePrefix, BulkDataFileDetails.ExportFileExtension)
                    : bulkDataOperationDto.FileName,
                OperationStatusCode = BulkDataOperationStatus.Queued,
                OperationTypeCode   = bulkDataOperationDto.OperationTypeCode,
                RelatedGroupId      = bulkDataOperationDto.GroupId,
                RelatedUserId       = _requestContext.UserId,
                BlobReference       = bulkDataOperationDto.BlobReference,
                Remark            = bulkDataOperationDto.Remark,
                IsNewDatabaseFile = bulkDataOperationDto.IsNewDatabaseFile
            };

            await _systemDataContext.CreateDocumentAsync(bulkDataOperation);

            if (bulkDataOperationDto.OperationTypeCode == BulkDataOperations.ExportOperation)
            {
                await _platformServiceBusService.QueueBulkExportMessageAsync(bulkDataOperation.Id);
            }
            else
            {
                await _platformServiceBusService.QueueBulkImportMessageAsync(bulkDataOperation.Id);
            }
        }