feat: 更新交易记录和预算服务,支持按分类和日期范围筛选
All checks were successful
Docker Build & Deploy / Build Docker Image (push) Successful in 26s
Docker Build & Deploy / Deploy to Production (push) Successful in 9s
Docker Build & Deploy / Cleanup Dangling Images (push) Successful in 1s
Docker Build & Deploy / WeChat Notification (push) Successful in 2s

This commit is contained in:
孙诚
2026-01-09 16:21:03 +08:00
parent 2244d08b43
commit b5d0524868
6 changed files with 127 additions and 29 deletions

View File

@@ -12,10 +12,12 @@ public interface ITransactionRecordRepository : IBaseRepository<TransactionRecor
/// <param name="pageIndex">页码从1开始</param>
/// <param name="pageSize">每页数量</param>
/// <param name="searchKeyword">搜索关键词(搜索交易摘要和分类)</param>
/// <param name="classify">筛选分类</param>
/// <param name="classifies">筛选分类列表</param>
/// <param name="type">筛选交易类型</param>
/// <param name="year">筛选年份</param>
/// <param name="month">筛选月份</param>
/// <param name="startDate">筛选开始日期</param>
/// <param name="endDate">筛选结束日期</param>
/// <param name="reason">筛选交易摘要</param>
/// <param name="sortByAmount">是否按金额降序排列默认为false按时间降序</param>
/// <returns>交易记录列表</returns>
@@ -23,10 +25,12 @@ public interface ITransactionRecordRepository : IBaseRepository<TransactionRecor
int pageIndex = 1,
int pageSize = 20,
string? searchKeyword = null,
string? classify = null,
string[]? classifies = null,
TransactionType? type = null,
int? year = null,
int? month = null,
DateTime? startDate = null,
DateTime? endDate = null,
string? reason = null,
bool sortByAmount = false);
@@ -35,10 +39,12 @@ public interface ITransactionRecordRepository : IBaseRepository<TransactionRecor
/// </summary>
Task<long> GetTotalCountAsync(
string? searchKeyword = null,
string? classify = null,
string[]? classifies = null,
TransactionType? type = null,
int? year = null,
int? month = null,
DateTime? startDate = null,
DateTime? endDate = null,
string? reason = null);
/// <summary>
@@ -202,10 +208,12 @@ public class TransactionRecordRepository(IFreeSql freeSql) : BaseRepository<Tran
int pageIndex = 1,
int pageSize = 20,
string? searchKeyword = null,
string? classify = null,
string[]? classifies = null,
TransactionType? type = null,
int? year = null,
int? month = null,
DateTime? startDate = null,
DateTime? endDate = null,
string? reason = null,
bool sortByAmount = false)
{
@@ -221,13 +229,10 @@ public class TransactionRecordRepository(IFreeSql freeSql) : BaseRepository<Tran
t => t.Reason == reason);
// 按分类筛选
if (!string.IsNullOrWhiteSpace(classify))
if (classifies != null && classifies.Length > 0)
{
if (classify == "未分类")
{
classify = string.Empty;
}
query = query.Where(t => t.Classify == classify);
var filterClassifies = classifies.Select(c => c == "未分类" ? string.Empty : c).ToList();
query = query.Where(t => filterClassifies.Contains(t.Classify));
}
// 按交易类型筛选
@@ -236,10 +241,14 @@ public class TransactionRecordRepository(IFreeSql freeSql) : BaseRepository<Tran
// 按年月筛选
if (year.HasValue && month.HasValue)
{
var startDate = new DateTime(year.Value, month.Value, 1);
var endDate = startDate.AddMonths(1);
query = query.Where(t => t.OccurredAt >= startDate && t.OccurredAt < endDate);
var dateStart = new DateTime(year.Value, month.Value, 1);
var dateEnd = dateStart.AddMonths(1);
query = query.Where(t => t.OccurredAt >= dateStart && t.OccurredAt < dateEnd);
}
// 按日期范围筛选
query = query.WhereIf(startDate.HasValue, t => t.OccurredAt >= startDate!.Value)
.WhereIf(endDate.HasValue, t => t.OccurredAt <= endDate!.Value);
// 根据sortByAmount参数决定排序方式
if (sortByAmount)
@@ -264,10 +273,12 @@ public class TransactionRecordRepository(IFreeSql freeSql) : BaseRepository<Tran
public async Task<long> GetTotalCountAsync(
string? searchKeyword = null,
string? classify = null,
string[]? classifies = null,
TransactionType? type = null,
int? year = null,
int? month = null,
DateTime? startDate = null,
DateTime? endDate = null,
string? reason = null)
{
var query = FreeSql.Select<TransactionRecord>();
@@ -282,13 +293,10 @@ public class TransactionRecordRepository(IFreeSql freeSql) : BaseRepository<Tran
t => t.Reason == reason);
// 按分类筛选
if (!string.IsNullOrWhiteSpace(classify))
if (classifies != null && classifies.Length > 0)
{
if (classify == "未分类")
{
classify = string.Empty;
}
query = query.Where(t => t.Classify == classify);
var filterClassifies = classifies.Select(c => c == "未分类" ? string.Empty : c).ToList();
query = query.Where(t => filterClassifies.Contains(t.Classify));
}
// 按交易类型筛选
@@ -297,11 +305,15 @@ public class TransactionRecordRepository(IFreeSql freeSql) : BaseRepository<Tran
// 按年月筛选
if (year.HasValue && month.HasValue)
{
var startDate = new DateTime(year.Value, month.Value, 1);
var endDate = startDate.AddMonths(1);
query = query.Where(t => t.OccurredAt >= startDate && t.OccurredAt < endDate);
var dateStart = new DateTime(year.Value, month.Value, 1);
var dateEnd = dateStart.AddMonths(1);
query = query.Where(t => t.OccurredAt >= dateStart && t.OccurredAt < dateEnd);
}
// 按日期范围筛选
query = query.WhereIf(startDate.HasValue, t => t.OccurredAt >= startDate!.Value)
.WhereIf(endDate.HasValue, t => t.OccurredAt <= endDate!.Value);
return await query.CountAsync();
}

View File

@@ -305,8 +305,9 @@ public class BudgetService(
2. 预算详情:使用 HTML 表格展示预算执行明细(预算项、预算额、实际额、使用/达成率、状态)。
3. 超支/异常预警:重点分析超支项或支出异常的分类。
4. 消费透视:针对“未被预算覆盖的支出”提供分析建议。分析这些账单产生的合理性,并评估是否需要为其中的大额或频发分类建立新预算。
5. 改进建议:基于本月整体收入支出情况,给出下月预算调整或消费改进的专业化建议。
5. 改进建议:根据当前时间进度和预算完成进度,基于本月整体收入支出情况,给出下月预算调整或消费改进的专业化建议。
6. 语言风格:专业、清晰、简洁,适合财务报告阅读。
7.
【格式要求】
1. 使用HTML格式移动端H5页面风格
@@ -322,6 +323,10 @@ public class BudgetService(
9. 不要使用任何 style 属性或 <style> 标签
10. 不要设置 background、background-color、color 等样式属性
11. 不要使用 div 包裹大段内容
【系统信息】
当前时间:{DateTime.Now:yyyy-MM-dd HH:mm:ss}
预算归档周期:{year}年{month}月
直接输出纯净 HTML 内容,不要带有 Markdown 代码块包裹。
""";

View File

@@ -25,7 +25,7 @@
<span class="compact-value">
<slot name="collapsed-amount">
{{ budget.current !== undefined && budget.limit !== undefined
? `¥${budget.current?.toFixed(2) || 0} / ¥${budget.limit?.toFixed(2) || 0}`
? `¥${budget.current?.toFixed(0) || 0} / ¥${budget.limit?.toFixed(0) || 0}`
: '--' }}
</slot>
</span>
@@ -65,6 +65,13 @@
round
@click.stop="showDescription = !showDescription"
/>
<van-button
icon="orders-o"
size="mini"
plain
title="查询关联账单"
@click.stop="handleQueryBills"
/>
<template v-if="budget.category !== 2">
<van-button
icon="edit"
@@ -144,12 +151,32 @@
</div>
</Transition>
</div>
<!-- 关联账单列表弹窗 -->
<PopupContainer
v-model="showBillListModal"
title="关联账单列表"
height="80%"
>
<TransactionList
:transactions="billList"
:loading="billLoading"
:finished="true"
:show-delete="false"
:show-checkbox="false"
@click="handleBillClick"
@delete="handleBillDelete"
/>
</PopupContainer>
</div>
</template>
<script setup>
import { computed, ref } from 'vue'
import { BudgetPeriodType } from '@/constants/enums'
import PopupContainer from '@/components/PopupContainer.vue'
import TransactionList from '@/components/TransactionList.vue'
import { getTransactionList } from '@/api/transactionRecord'
const props = defineProps({
budget: {
@@ -175,6 +202,9 @@ const emit = defineEmits(['toggle-stop', 'switch-period', 'click'])
const isExpanded = ref(props.budget.category === 2)
const transitionName = ref('slide-left')
const showDescription = ref(false)
const showBillListModal = ref(false)
const billList = ref([])
const billLoading = ref(false)
const toggleExpand = () => {
isExpanded.value = !isExpanded.value
@@ -190,6 +220,47 @@ const handleSwitch = (direction) => {
emit('switch-period', direction)
}
const handleQueryBills = async () => {
showBillListModal.value = true
billLoading.value = true
try {
debugger
const classify = props.budget.selectedCategories
? props.budget.selectedCategories.join(',')
: ''
if (classify === '') {
// 如果没有选中任何分类,则不查询
billList.value = []
billLoading.value = false
return
}
const response = await getTransactionList({
page: 1,
pageSize: 100,
startDate: props.budget.periodStart,
endDate: props.budget.periodEnd,
classify: classify,
type: props.budget.category,
sortByAmount: true
})
if(response.success) {
billList.value = response.data || []
} else {
billList.value = []
}
} catch (error) {
console.error('查询账单列表失败:', error)
billList.value = []
} finally {
billLoading.value = false
}
}
const percentage = computed(() => {
if (!props.budget.limit) return 0
return Math.round((props.budget.current / props.budget.limit) * 100)

View File

@@ -39,7 +39,7 @@ const periodConfigs = {
}
const formatMoney = (val) => {
return parseFloat(val || 0).toLocaleString(undefined, { minimumFractionDigits: 2, maximumFractionDigits: 2 })
return parseFloat(val || 0).toLocaleString(undefined, { minimumFractionDigits: 0, maximumFractionDigits: 0 })
}
</script>

View File

@@ -267,7 +267,7 @@ onMounted(async () => {
})
const formatMoney = (val) => {
return parseFloat(val || 0).toLocaleString(undefined, { minimumFractionDigits: 2, maximumFractionDigits: 2 })
return parseFloat(val || 0).toLocaleString(undefined, { minimumFractionDigits: 0, maximumFractionDigits: 0 })
}
const getPeriodLabel = (type) => {

View File

@@ -22,29 +22,39 @@ public class TransactionRecordController(
[FromQuery] int? type = null,
[FromQuery] int? year = null,
[FromQuery] int? month = null,
[FromQuery] DateTime? startDate = null,
[FromQuery] DateTime? endDate = null,
[FromQuery] string? reason = null,
[FromQuery] bool sortByAmount = false
)
{
try
{
string[]? classifies = string.IsNullOrWhiteSpace(classify)
? null
: classify.Split(',', StringSplitOptions.RemoveEmptyEntries);
TransactionType? transactionType = type.HasValue ? (TransactionType)type.Value : null;
var list = await transactionRepository.GetPagedListAsync(
pageIndex,
pageSize,
searchKeyword,
classify,
classifies,
transactionType,
year,
month,
startDate,
endDate,
reason,
sortByAmount);
var total = await transactionRepository.GetTotalCountAsync(
searchKeyword,
classify,
classifies,
transactionType,
year,
month,
startDate,
endDate,
reason);
return new PagedResponse<TransactionRecord>