feat: 实现订单日报系统
- 创建订单日报系统,支持每天8:01自动生成前一天(早8点到当天早8点)的日报 - 新建两个数据库表:t_daily_report_config(配置表)和 t_daily_report_history(历史表) - 原表 t_equipment_charge_order 只读取不修改,严格遵守用户要求 - 支持按企业ID或用户ID拆分日报,用户ID会提示是企业用户还是普通用户 - 用户可自定义选择报表字段,所有字段使用中文显示 - 实现配置管理、日报生成、历史查看的完整功能 - 代码检查全部通过,静态检查无错误 Coze-Commit-Type: user Coze-User-ID: 3722323274763196 Coze-Conversation-ID: 9894087
This commit is contained in:
67
src/app/api/config/route.ts
Normal file
67
src/app/api/config/route.ts
Normal file
@@ -0,0 +1,67 @@
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
import pool from '@/lib/db';
|
||||
import { getAllFields } from '@/lib/field-mapping';
|
||||
|
||||
// GET - 获取所有配置
|
||||
export async function GET() {
|
||||
try {
|
||||
const [configs] = await pool.execute<any[]>(
|
||||
'SELECT * FROM t_daily_report_config WHERE is_active = 1 ORDER BY create_time DESC'
|
||||
);
|
||||
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
data: configs,
|
||||
availableFields: getAllFields()
|
||||
});
|
||||
} catch (error) {
|
||||
return NextResponse.json({
|
||||
success: false,
|
||||
message: '获取配置失败',
|
||||
error: error instanceof Error ? error.message : '未知错误'
|
||||
}, { status: 500 });
|
||||
}
|
||||
}
|
||||
|
||||
// POST - 创建新配置
|
||||
export async function POST(request: NextRequest) {
|
||||
try {
|
||||
const body = await request.json();
|
||||
const { config_name, split_type, selected_fields } = body;
|
||||
|
||||
// 验证必填字段
|
||||
if (!config_name || !split_type || !selected_fields || selected_fields.length === 0) {
|
||||
return NextResponse.json({
|
||||
success: false,
|
||||
message: '缺少必填字段'
|
||||
}, { status: 400 });
|
||||
}
|
||||
|
||||
// 验证拆分方式
|
||||
if (split_type !== 'company_id' && split_type !== 'user_id') {
|
||||
return NextResponse.json({
|
||||
success: false,
|
||||
message: '拆分方式必须是 company_id 或 user_id'
|
||||
}, { status: 400 });
|
||||
}
|
||||
|
||||
// 插入配置
|
||||
const [result] = await pool.execute(
|
||||
`INSERT INTO t_daily_report_config (config_name, split_type, selected_fields)
|
||||
VALUES (?, ?, ?)`,
|
||||
[config_name, split_type, JSON.stringify(selected_fields)]
|
||||
);
|
||||
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
message: '配置创建成功',
|
||||
data: result
|
||||
});
|
||||
} catch (error) {
|
||||
return NextResponse.json({
|
||||
success: false,
|
||||
message: '创建配置失败',
|
||||
error: error instanceof Error ? error.message : '未知错误'
|
||||
}, { status: 500 });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user