feat: 添加预算类别名称更新功能,优化相关控制器逻辑
All checks were successful
Docker Build & Deploy / Build Docker Image (push) Successful in 23s
Docker Build & Deploy / Deploy to Production (push) Successful in 7s
Docker Build & Deploy / Cleanup Dangling Images (push) Successful in 1s
Docker Build & Deploy / WeChat Notification (push) Successful in 1s
All checks were successful
Docker Build & Deploy / Build Docker Image (push) Successful in 23s
Docker Build & Deploy / Deploy to Production (push) Successful in 7s
Docker Build & Deploy / Cleanup Dangling Images (push) Successful in 1s
Docker Build & Deploy / WeChat Notification (push) Successful in 1s
This commit is contained in:
@@ -3,6 +3,8 @@
|
||||
public interface IBudgetRepository : IBaseRepository<BudgetRecord>
|
||||
{
|
||||
Task<decimal> GetCurrentAmountAsync(BudgetRecord budget, DateTime startDate, DateTime endDate);
|
||||
|
||||
Task UpdateBudgetCategoryNameAsync(string oldName, string newName, TransactionType type);
|
||||
}
|
||||
|
||||
public class BudgetRepository(IFreeSql freeSql) : BaseRepository<BudgetRecord>(freeSql), IBudgetRepository
|
||||
@@ -33,4 +35,31 @@ public class BudgetRepository(IFreeSql freeSql) : BaseRepository<BudgetRecord>(f
|
||||
|
||||
return await query.SumAsync(t => t.Amount);
|
||||
}
|
||||
|
||||
public async Task UpdateBudgetCategoryNameAsync(string oldName, string newName, TransactionType type)
|
||||
{
|
||||
var records = await FreeSql.Select<BudgetRecord>()
|
||||
.Where(b => b.SelectedCategories.Contains(oldName) &&
|
||||
((type == TransactionType.Expense && b.Category == BudgetCategory.Expense) ||
|
||||
(type == TransactionType.Income && b.Category == BudgetCategory.Income) ||
|
||||
(type == TransactionType.None && b.Category == BudgetCategory.Savings)))
|
||||
.ToListAsync();
|
||||
|
||||
foreach (var record in records)
|
||||
{
|
||||
var categories = record.SelectedCategories.Split(',').ToList();
|
||||
for (int i = 0; i < categories.Count; i++)
|
||||
{
|
||||
if (categories[i] == oldName)
|
||||
{
|
||||
categories[i] = newName;
|
||||
}
|
||||
}
|
||||
record.SelectedCategories = string.Join(',', categories);
|
||||
}
|
||||
|
||||
await FreeSql.Update<BudgetRecord>()
|
||||
.SetSource(records)
|
||||
.ExecuteAffrowsAsync();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,7 +90,7 @@
|
||||
/>
|
||||
|
||||
<!-- 日期选择弹窗 -->
|
||||
<van-popup v-model:show="showDatePicker" position="bottom" round>
|
||||
<van-popup v-model:show="showDatePicker" position="bottom" round teleport="body">
|
||||
<van-date-picker
|
||||
v-model="currentDate"
|
||||
title="选择日期"
|
||||
@@ -100,7 +100,7 @@
|
||||
</van-popup>
|
||||
|
||||
<!-- 时间选择弹窗 -->
|
||||
<van-popup v-model:show="showTimePicker" position="bottom" round>
|
||||
<van-popup v-model:show="showTimePicker" position="bottom" round teleport="body">
|
||||
<van-time-picker
|
||||
v-model="currentTime"
|
||||
title="选择时间"
|
||||
|
||||
@@ -72,7 +72,7 @@
|
||||
</van-form>
|
||||
</div>
|
||||
<template #footer>
|
||||
<van-button block type="primary" @click="onSubmit">保存预算</van-button>
|
||||
<van-button block round type="primary" @click="onSubmit">保存预算</van-button>
|
||||
</template>
|
||||
</PopupContainer>
|
||||
</template>
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
:style="{ height: height }"
|
||||
round
|
||||
:closeable="closeable"
|
||||
teleport="body"
|
||||
>
|
||||
<div class="popup-container">
|
||||
<!-- 头部区域 -->
|
||||
|
||||
@@ -232,7 +232,7 @@
|
||||
</PopupContainer>
|
||||
|
||||
<!-- 周期类型选择器 -->
|
||||
<van-popup v-model:show="showPeriodicTypePicker" position="bottom" round>
|
||||
<van-popup v-model:show="showPeriodicTypePicker" position="bottom" round teleport="body">
|
||||
<van-picker
|
||||
:columns="periodicTypeColumns"
|
||||
@confirm="onPeriodicTypeConfirm"
|
||||
@@ -241,7 +241,7 @@
|
||||
</van-popup>
|
||||
|
||||
<!-- 星期选择器 -->
|
||||
<van-popup v-model:show="showWeekdaysPicker" position="bottom" round>
|
||||
<van-popup v-model:show="showWeekdaysPicker" position="bottom" round teleport="body">
|
||||
<van-picker
|
||||
:columns="weekdaysColumns"
|
||||
@confirm="onWeekdaysConfirm"
|
||||
@@ -250,7 +250,7 @@
|
||||
</van-popup>
|
||||
|
||||
<!-- 日期选择器 -->
|
||||
<van-popup v-model:show="showMonthDaysPicker" position="bottom" round>
|
||||
<van-popup v-model:show="showMonthDaysPicker" position="bottom" round teleport="body">
|
||||
<van-picker
|
||||
:columns="monthDaysColumns"
|
||||
@confirm="onMonthDaysConfirm"
|
||||
|
||||
@@ -264,7 +264,7 @@
|
||||
</van-pull-refresh>
|
||||
|
||||
<!-- 月份选择器 -->
|
||||
<van-popup v-model:show="showMonthPicker" position="bottom" round>
|
||||
<van-popup v-model:show="showMonthPicker" position="bottom" round teleport="body">
|
||||
<van-date-picker
|
||||
v-model="selectedDate"
|
||||
title="选择月份"
|
||||
|
||||
@@ -5,7 +5,8 @@
|
||||
public class TransactionCategoryController(
|
||||
ITransactionCategoryRepository categoryRepository,
|
||||
ITransactionRecordRepository transactionRecordRepository,
|
||||
ILogger<TransactionCategoryController> logger
|
||||
ILogger<TransactionCategoryController> logger,
|
||||
IBudgetRepository budgetRepository
|
||||
) : ControllerBase
|
||||
{
|
||||
/// <summary>
|
||||
@@ -121,6 +122,7 @@ public class TransactionCategoryController(
|
||||
|
||||
// 同步更新交易记录中的分类名称
|
||||
await transactionRecordRepository.UpdateCategoryNameAsync(category.Name, dto.Name, category.Type);
|
||||
await budgetRepository.UpdateBudgetCategoryNameAsync(category.Name, dto.Name, category.Type);
|
||||
}
|
||||
|
||||
category.Name = dto.Name;
|
||||
|
||||
Reference in New Issue
Block a user