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>
|
public interface IBudgetRepository : IBaseRepository<BudgetRecord>
|
||||||
{
|
{
|
||||||
Task<decimal> GetCurrentAmountAsync(BudgetRecord budget, DateTime startDate, DateTime endDate);
|
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
|
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);
|
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
|
<van-date-picker
|
||||||
v-model="currentDate"
|
v-model="currentDate"
|
||||||
title="选择日期"
|
title="选择日期"
|
||||||
@@ -100,7 +100,7 @@
|
|||||||
</van-popup>
|
</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
|
<van-time-picker
|
||||||
v-model="currentTime"
|
v-model="currentTime"
|
||||||
title="选择时间"
|
title="选择时间"
|
||||||
|
|||||||
@@ -72,7 +72,7 @@
|
|||||||
</van-form>
|
</van-form>
|
||||||
</div>
|
</div>
|
||||||
<template #footer>
|
<template #footer>
|
||||||
<van-button block type="primary" @click="onSubmit">保存预算</van-button>
|
<van-button block round type="primary" @click="onSubmit">保存预算</van-button>
|
||||||
</template>
|
</template>
|
||||||
</PopupContainer>
|
</PopupContainer>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
:style="{ height: height }"
|
:style="{ height: height }"
|
||||||
round
|
round
|
||||||
:closeable="closeable"
|
:closeable="closeable"
|
||||||
|
teleport="body"
|
||||||
>
|
>
|
||||||
<div class="popup-container">
|
<div class="popup-container">
|
||||||
<!-- 头部区域 -->
|
<!-- 头部区域 -->
|
||||||
|
|||||||
@@ -232,7 +232,7 @@
|
|||||||
</PopupContainer>
|
</PopupContainer>
|
||||||
|
|
||||||
<!-- 周期类型选择器 -->
|
<!-- 周期类型选择器 -->
|
||||||
<van-popup v-model:show="showPeriodicTypePicker" position="bottom" round>
|
<van-popup v-model:show="showPeriodicTypePicker" position="bottom" round teleport="body">
|
||||||
<van-picker
|
<van-picker
|
||||||
:columns="periodicTypeColumns"
|
:columns="periodicTypeColumns"
|
||||||
@confirm="onPeriodicTypeConfirm"
|
@confirm="onPeriodicTypeConfirm"
|
||||||
@@ -241,7 +241,7 @@
|
|||||||
</van-popup>
|
</van-popup>
|
||||||
|
|
||||||
<!-- 星期选择器 -->
|
<!-- 星期选择器 -->
|
||||||
<van-popup v-model:show="showWeekdaysPicker" position="bottom" round>
|
<van-popup v-model:show="showWeekdaysPicker" position="bottom" round teleport="body">
|
||||||
<van-picker
|
<van-picker
|
||||||
:columns="weekdaysColumns"
|
:columns="weekdaysColumns"
|
||||||
@confirm="onWeekdaysConfirm"
|
@confirm="onWeekdaysConfirm"
|
||||||
@@ -250,7 +250,7 @@
|
|||||||
</van-popup>
|
</van-popup>
|
||||||
|
|
||||||
<!-- 日期选择器 -->
|
<!-- 日期选择器 -->
|
||||||
<van-popup v-model:show="showMonthDaysPicker" position="bottom" round>
|
<van-popup v-model:show="showMonthDaysPicker" position="bottom" round teleport="body">
|
||||||
<van-picker
|
<van-picker
|
||||||
:columns="monthDaysColumns"
|
:columns="monthDaysColumns"
|
||||||
@confirm="onMonthDaysConfirm"
|
@confirm="onMonthDaysConfirm"
|
||||||
|
|||||||
@@ -264,7 +264,7 @@
|
|||||||
</van-pull-refresh>
|
</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
|
<van-date-picker
|
||||||
v-model="selectedDate"
|
v-model="selectedDate"
|
||||||
title="选择月份"
|
title="选择月份"
|
||||||
|
|||||||
@@ -5,7 +5,8 @@
|
|||||||
public class TransactionCategoryController(
|
public class TransactionCategoryController(
|
||||||
ITransactionCategoryRepository categoryRepository,
|
ITransactionCategoryRepository categoryRepository,
|
||||||
ITransactionRecordRepository transactionRecordRepository,
|
ITransactionRecordRepository transactionRecordRepository,
|
||||||
ILogger<TransactionCategoryController> logger
|
ILogger<TransactionCategoryController> logger,
|
||||||
|
IBudgetRepository budgetRepository
|
||||||
) : ControllerBase
|
) : ControllerBase
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -121,6 +122,7 @@ public class TransactionCategoryController(
|
|||||||
|
|
||||||
// 同步更新交易记录中的分类名称
|
// 同步更新交易记录中的分类名称
|
||||||
await transactionRecordRepository.UpdateCategoryNameAsync(category.Name, dto.Name, category.Type);
|
await transactionRecordRepository.UpdateCategoryNameAsync(category.Name, dto.Name, category.Type);
|
||||||
|
await budgetRepository.UpdateBudgetCategoryNameAsync(category.Name, dto.Name, category.Type);
|
||||||
}
|
}
|
||||||
|
|
||||||
category.Name = dto.Name;
|
category.Name = dto.Name;
|
||||||
|
|||||||
Reference in New Issue
Block a user