fix limit increase when not planned
This commit is contained in:
@@ -50,46 +50,17 @@ class FinancialService(
|
|||||||
}
|
}
|
||||||
return@flatMap getBudgetSumsByCategory(transaction.category.id!!, budget)
|
return@flatMap getBudgetSumsByCategory(transaction.category.id!!, budget)
|
||||||
.flatMap { sums ->
|
.flatMap { sums ->
|
||||||
|
|
||||||
budgetCategory.currentPlanned = sums.getDouble("plannedAmount") ?: 0.0
|
budgetCategory.currentPlanned = sums.getDouble("plannedAmount") ?: 0.0
|
||||||
budgetCategory.currentSpent = sums.getDouble("instantAmount") ?: 0.0
|
budgetCategory.currentSpent = sums.getDouble("instantAmount") ?: 0.0
|
||||||
// При совпадении бюджетов разница просто корректирует лимит
|
// При совпадении бюджетов разница просто корректирует лимит
|
||||||
|
if (transaction.type.code == "PLANNED") {
|
||||||
budgetCategory.currentLimit += transaction.amount
|
budgetCategory.currentLimit += transaction.amount
|
||||||
logger.info("updateBudgetOnEdit end")
|
}
|
||||||
|
logger.info("updateBudgetOnCreate end")
|
||||||
budgetRepo.save(budget).then()
|
budgetRepo.save(budget).then()
|
||||||
}
|
}
|
||||||
// getBudgetCategories(budget.dateFrom, budget.dateTo).flatMap { categories ->
|
|
||||||
// val updatedCategoriesMono: Mono<List<BudgetCategory>> = when (transaction.type.code) {
|
|
||||||
// "PLANNED" -> Flux.fromIterable(budget.categories)
|
|
||||||
// .map { category ->
|
|
||||||
// if (category.category.id == transaction.category.id) {
|
|
||||||
// categories[category.category.id]?.let { data ->
|
|
||||||
// category.currentSpent = data["instantAmount"] ?: 0.0
|
|
||||||
// category.currentPlanned = data["plannedAmount"] ?: 0.0
|
|
||||||
// category.currentLimit += transaction.amount
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// category
|
|
||||||
// }.collectList()
|
|
||||||
//
|
//
|
||||||
// "INSTANT" -> Flux.fromIterable(budget.categories)
|
|
||||||
// .map { category ->
|
|
||||||
// if (category.category.id == transaction.category.id) {
|
|
||||||
// categories[category.category.id]?.let { data ->
|
|
||||||
// category.currentSpent = data["instantAmount"] ?: 0.0
|
|
||||||
// category.currentPlanned = data["plannedAmount"] ?: 0.0
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// category
|
|
||||||
// }.collectList()
|
|
||||||
//
|
|
||||||
// else -> Mono.just(budget.categories) // Добавляем обработку типа по умолчанию
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// updatedCategoriesMono.flatMap { updated ->
|
|
||||||
// budget.categories = updated.toMutableList()
|
|
||||||
// budgetRepo.save(budget).then() // Гарантируем завершение сохранения
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
}.then() // Возвращаем корректный Mono<Void>
|
}.then() // Возвращаем корректный Mono<Void>
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -132,7 +103,9 @@ class FinancialService(
|
|||||||
budgetCategory.currentPlanned = sums.getDouble("plannedAmount") ?: 0.0
|
budgetCategory.currentPlanned = sums.getDouble("plannedAmount") ?: 0.0
|
||||||
budgetCategory.currentSpent = sums.getDouble("instantAmount") ?: 0.0
|
budgetCategory.currentSpent = sums.getDouble("instantAmount") ?: 0.0
|
||||||
// При совпадении бюджетов разница просто корректирует лимит
|
// При совпадении бюджетов разница просто корректирует лимит
|
||||||
|
if (newTransaction.type.code == "PLANNED") {
|
||||||
budgetCategory.currentLimit += difference
|
budgetCategory.currentLimit += difference
|
||||||
|
}
|
||||||
logger.info("updateBudgetOnEdit end")
|
logger.info("updateBudgetOnEdit end")
|
||||||
budgetRepo.save(newBudget).then()
|
budgetRepo.save(newBudget).then()
|
||||||
}
|
}
|
||||||
@@ -151,7 +124,9 @@ class FinancialService(
|
|||||||
oldBudgetCategory.currentPlanned = sums.getDouble("plannedAmount") ?: 0.0
|
oldBudgetCategory.currentPlanned = sums.getDouble("plannedAmount") ?: 0.0
|
||||||
oldBudgetCategory.currentSpent = sums.getDouble("instantAmount") ?: 0.0
|
oldBudgetCategory.currentSpent = sums.getDouble("instantAmount") ?: 0.0
|
||||||
// В старом бюджете вычитаем разницу, так как транзакция перемещается
|
// В старом бюджете вычитаем разницу, так как транзакция перемещается
|
||||||
|
if (oldTransaction.type.code == "PLANNED") {
|
||||||
oldBudgetCategory.currentLimit -= difference
|
oldBudgetCategory.currentLimit -= difference
|
||||||
|
}
|
||||||
budgetRepo.save(oldBudget).then()
|
budgetRepo.save(oldBudget).then()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -164,7 +139,9 @@ class FinancialService(
|
|||||||
newBudgetCategory.currentPlanned = sums.getDouble("plannedAmount") ?: 0.0
|
newBudgetCategory.currentPlanned = sums.getDouble("plannedAmount") ?: 0.0
|
||||||
newBudgetCategory.currentSpent = sums.getDouble("instantAmount") ?: 0.0
|
newBudgetCategory.currentSpent = sums.getDouble("instantAmount") ?: 0.0
|
||||||
// В новом бюджете прибавляем разницу
|
// В новом бюджете прибавляем разницу
|
||||||
|
if (newTransaction.type.code == "PLANNED") {
|
||||||
newBudgetCategory.currentLimit += difference
|
newBudgetCategory.currentLimit += difference
|
||||||
|
}
|
||||||
budgetRepo.save(newBudget).then()
|
budgetRepo.save(newBudget).then()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -214,7 +191,6 @@ class FinancialService(
|
|||||||
}.then() // Возвращаем корректный Mono<Void>
|
}.then() // Возвращаем корректный Mono<Void>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Cacheable("budgetsList")
|
@Cacheable("budgetsList")
|
||||||
fun getBudgets(sortSetting: SortSetting? = null): Mono<MutableList<Budget>> {
|
fun getBudgets(sortSetting: SortSetting? = null): Mono<MutableList<Budget>> {
|
||||||
val sort = if (sortSetting != null) {
|
val sort = if (sortSetting != null) {
|
||||||
@@ -227,7 +203,6 @@ class FinancialService(
|
|||||||
.collectList() // Сбор Flux<Budget> в Mono<List<Budget>>
|
.collectList() // Сбор Flux<Budget> в Mono<List<Budget>>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// @Cacheable("budgets", key = "#id")
|
// @Cacheable("budgets", key = "#id")
|
||||||
fun getBudget(id: String): Mono<BudgetDTO> {
|
fun getBudget(id: String): Mono<BudgetDTO> {
|
||||||
return budgetRepo.findById(id)
|
return budgetRepo.findById(id)
|
||||||
@@ -279,7 +254,6 @@ class FinancialService(
|
|||||||
.switchIfEmpty(Mono.error(BudgetNotFoundException("Budget not found with id: $id")))
|
.switchIfEmpty(Mono.error(BudgetNotFoundException("Budget not found with id: $id")))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fun regenCats(): Mono<Void> {
|
fun regenCats(): Mono<Void> {
|
||||||
return budgetRepo.findAll()
|
return budgetRepo.findAll()
|
||||||
.flatMap { budget ->
|
.flatMap { budget ->
|
||||||
@@ -337,7 +311,6 @@ class FinancialService(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fun getBudgetByDate(date: LocalDate): Mono<Budget> {
|
fun getBudgetByDate(date: LocalDate): Mono<Budget> {
|
||||||
return budgetRepo.findByDateFromLessThanEqualAndDateToGreaterThanEqual(date, date).switchIfEmpty(Mono.empty())
|
return budgetRepo.findByDateFromLessThanEqualAndDateToGreaterThanEqual(date, date).switchIfEmpty(Mono.empty())
|
||||||
}
|
}
|
||||||
@@ -361,7 +334,6 @@ class FinancialService(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fun getBudgetTransactionsByType(budgetId: String): Mono<Map<String, List<Transaction>>> {
|
fun getBudgetTransactionsByType(budgetId: String): Mono<Map<String, List<Transaction>>> {
|
||||||
return budgetRepo.findById(budgetId).flatMap { it ->
|
return budgetRepo.findById(budgetId).flatMap { it ->
|
||||||
getTransactionsByTypes(it.dateFrom, it.dateTo)
|
getTransactionsByTypes(it.dateFrom, it.dateTo)
|
||||||
@@ -387,7 +359,6 @@ class FinancialService(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@CacheEvict(cacheNames = ["budgets", "budgetsList"], allEntries = true)
|
@CacheEvict(cacheNames = ["budgets", "budgetsList"], allEntries = true)
|
||||||
fun setCategoryLimit(budgetId: String, catId: String, limit: Double): Mono<BudgetCategory> {
|
fun setCategoryLimit(budgetId: String, catId: String, limit: Double): Mono<BudgetCategory> {
|
||||||
return budgetRepo.findById(budgetId).flatMap { budget ->
|
return budgetRepo.findById(budgetId).flatMap { budget ->
|
||||||
@@ -408,7 +379,6 @@ class FinancialService(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fun getWarns(budgetId: String, isHide: Boolean? = null): Mono<List<Warn>> {
|
fun getWarns(budgetId: String, isHide: Boolean? = null): Mono<List<Warn>> {
|
||||||
return warnRepo.findAllByBudgetIdAndIsHide(budgetId, isHide == true).collectList()
|
return warnRepo.findAllByBudgetIdAndIsHide(budgetId, isHide == true).collectList()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user