new updated

This commit is contained in:
xds
2025-02-11 13:46:50 +03:00
parent 510f527bec
commit c1d7e42a29
11 changed files with 3014 additions and 1220 deletions

View File

@@ -6,6 +6,7 @@ import org.bson.types.ObjectId
import org.slf4j.LoggerFactory
import org.springframework.cache.annotation.CacheEvict
import org.springframework.cache.annotation.Cacheable
import org.springframework.context.ApplicationEventPublisher
import org.springframework.data.domain.Sort
import org.springframework.data.domain.Sort.Direction
import org.springframework.data.mongodb.core.ReactiveMongoTemplate
@@ -37,8 +38,9 @@ import java.util.Date
@Service
class CategoryService(
private val categoryRepo: CategoryRepo,
private val transactionService: TransactionService,
private val mongoTemplate: ReactiveMongoTemplate
private val financialService: FinancialService,
private val mongoTemplate: ReactiveMongoTemplate,
private val eventPublisher: ApplicationEventPublisher
) {
private val logger = LoggerFactory.getLogger(javaClass)
@@ -115,7 +117,7 @@ class CategoryService(
return categoryRepo.findById(categoryId).switchIfEmpty(
Mono.error(IllegalArgumentException("Category with id: $categoryId not found"))
).flatMap {
transactionService.getTransactions(categoryId = categoryId)
financialService.getTransactions(categoryId = categoryId)
.flatMapMany { transactions ->
categoryRepo.findByName("Другое").switchIfEmpty(
categoryRepo.save(
@@ -126,10 +128,10 @@ class CategoryService(
icon = "🚮"
)
)
).flatMapMany { Category ->
).flatMapMany { category ->
Flux.fromIterable(transactions).flatMap { transaction ->
transaction.category = Category // Присваиваем конкретный объект категории
transactionService.editTransaction(transaction) // Сохраняем изменения
transaction.category = category // Присваиваем конкретный объект категории
financialService.editTransaction(transaction) // Сохраняем изменения
}
}
}
@@ -140,7 +142,6 @@ class CategoryService(
fun getBudgetCategories(dateFrom: LocalDate, dateTo: LocalDate): Mono<Map<String, Map<String, Double>>> {
logger.info("here cat starts")
val pipeline = listOf(
Document(
"\$lookup",
@@ -265,7 +266,6 @@ class CategoryService(
)
id to values
}
logger.info("here cat ends")
Mono.just(categories)
}

File diff suppressed because it is too large Load Diff