feat: 完善日报系统功能
主要更新: 1. 【核心变更】从批量拆分改为单个企业/用户选择生成 - 用户现在可以选择特定的企业或用户生成日报 - 企业列表显示企业名称(如"国营-西南-79路") - 用户列表显示用户姓名,并标注用户类型(企业用户/普通用户) 2. 【新增功能】求和功能 - 支持选择多个字段进行求和 - 求和结果显示在Excel表格底部 - 可对金额、电量等多列分别求和 3. 【数据库表结构更新】 - t_daily_report_config 新增字段:split_name(企业/用户名称)、sum_fields(求和字段列表) - t_daily_report_history 新增字段:split_name、sum_results(求和结果JSON) 4. 【前端页面优化】 - 配置管理:选择企业/用户时显示名称和订单数量 - 日报生成:支持选择单个企业/用户、字段和求和字段 - 历史记录:显示企业/用户名称和求和结果 5. 【API接口优化】 - 企业列表API:返回company_name、company_no、company_group等信息 - 用户列表API:返回user_name和用户类型标签 - 日报生成API:支持sum_fields参数 6. 【删除临时文件】清理debug调试API接口 所有代码静态检查通过,企业列表和用户列表API测试成功 Coze-Commit-Type: user Coze-User-ID: 3722323274763196 Coze-Conversation-ID: 9894087
This commit is contained in:
@@ -11,10 +11,12 @@ export async function GET() {
|
||||
// 尝试查询配置(如果表不存在会失败)
|
||||
let configs: any[] = [];
|
||||
try {
|
||||
const [configRows] = await pool.execute<any[]>(
|
||||
const connection = await pool.getConnection();
|
||||
const [configRows] = await connection.query<any[]>(
|
||||
'SELECT * FROM t_daily_report_config WHERE is_active = 1 ORDER BY create_time DESC'
|
||||
);
|
||||
configs = configRows || [];
|
||||
connection.release();
|
||||
} catch (dbError) {
|
||||
// 如果表不存在,返回空数组
|
||||
console.log('配置表查询失败,可能是表未初始化:', dbError);
|
||||
@@ -39,13 +41,20 @@ export async function GET() {
|
||||
export async function POST(request: NextRequest) {
|
||||
try {
|
||||
const body = await request.json();
|
||||
const { config_name, split_type, selected_fields } = body;
|
||||
const {
|
||||
config_name,
|
||||
split_type,
|
||||
split_value,
|
||||
split_name,
|
||||
selected_fields,
|
||||
sum_fields
|
||||
} = body;
|
||||
|
||||
// 验证必填字段
|
||||
if (!config_name || !split_type || !selected_fields || selected_fields.length === 0) {
|
||||
if (!config_name || !split_type || !split_value || !selected_fields || selected_fields.length === 0) {
|
||||
return NextResponse.json({
|
||||
success: false,
|
||||
message: '缺少必填字段'
|
||||
message: '缺少必填字段(配置名称、拆分方式、拆分值、选择的字段)'
|
||||
}, { status: 400 });
|
||||
}
|
||||
|
||||
@@ -57,17 +66,29 @@ export async function POST(request: NextRequest) {
|
||||
}, { status: 400 });
|
||||
}
|
||||
|
||||
// 获取连接
|
||||
const connection = await pool.getConnection();
|
||||
|
||||
// 插入配置
|
||||
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)]
|
||||
await connection.query(
|
||||
`INSERT INTO t_daily_report_config
|
||||
(config_name, split_type, split_value, split_name, selected_fields, sum_fields)
|
||||
VALUES (?, ?, ?, ?, ?, ?)`,
|
||||
[
|
||||
config_name,
|
||||
split_type,
|
||||
split_value,
|
||||
split_name || null,
|
||||
JSON.stringify(selected_fields),
|
||||
sum_fields ? JSON.stringify(sum_fields) : null
|
||||
]
|
||||
);
|
||||
|
||||
connection.release();
|
||||
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
message: '配置创建成功',
|
||||
data: result
|
||||
message: '配置创建成功'
|
||||
});
|
||||
} catch (error) {
|
||||
return NextResponse.json({
|
||||
|
||||
Reference in New Issue
Block a user