#feature: update SQL generator

This commit is contained in:
2026-05-19 14:57:11 +08:00
parent 53bca7d609
commit 3c628eb391
10 changed files with 1043 additions and 165 deletions
+39 -23
View File
@@ -4,11 +4,13 @@ namespace App\Http\Controllers;
use App\Services\JiraService;
use Carbon\Carbon;
use Illuminate\Http\Request;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class JiraController extends Controller
{
private const WEEKLY_REPORT_PERIODS = ['this_week', 'last_week'];
private JiraService $jiraService;
public function __construct(JiraService $jiraService)
@@ -16,37 +18,44 @@ class JiraController extends Controller
$this->jiraService = $jiraService;
}
/**
* 生成上周周报
* 生成周报
*/
public function generateWeeklyReport(Request $request): JsonResponse
{
try {
$username = $request->input('username') ?: config('jira.default_user');
$period = $request->input('period', 'this_week');
if (!$username) {
if (! $username) {
return response()->json([
'success' => false,
'message' => '请提供用户名'
'message' => '请提供用户名',
], 400);
}
$report = $this->jiraService->generateWeeklyReport($username);
if (! in_array($period, self::WEEKLY_REPORT_PERIODS, true)) {
return response()->json([
'success' => false,
'message' => '无效的周报周期',
], 400);
}
$report = $this->jiraService->generateWeeklyReport($username, $period);
return response()->json([
'success' => true,
'data' => [
'report' => $report,
'username' => $username,
'generated_at' => Carbon::now()->format('Y-m-d H:i:s')
]
'period' => $period,
'generated_at' => Carbon::now()->format('Y-m-d H:i:s'),
],
]);
} catch (\Exception $e) {
return response()->json([
'success' => false,
'message' => '生成周报失败: ' . $e->getMessage()
'message' => '生成周报失败: '.$e->getMessage(),
], 500);
}
}
@@ -77,14 +86,14 @@ class JiraController extends Controller
'total_records' => $workLogs->count(),
'date_range' => [
'start' => $startDate->format('Y-m-d'),
'end' => $endDate->format('Y-m-d')
]
]
'end' => $endDate->format('Y-m-d'),
],
],
]);
} catch (\Exception $e) {
return response()->json([
'success' => false,
'message' => '获取工时记录失败: ' . $e->getMessage()
'message' => '获取工时记录失败: '.$e->getMessage(),
], 500);
}
}
@@ -98,8 +107,8 @@ class JiraController extends Controller
'success' => true,
'data' => [
'default_user' => config('jira.default_user', ''),
'host' => config('jira.host', '')
]
'host' => config('jira.host', ''),
],
]);
}
@@ -110,26 +119,33 @@ class JiraController extends Controller
{
try {
$username = $request->input('username') ?: config('jira.default_user');
$period = $request->input('period', 'this_week');
if (!$username) {
if (! $username) {
return response()->json([
'success' => false,
'message' => '请提供用户名'
'message' => '请提供用户名',
], 400);
}
$report = $this->jiraService->generateWeeklyReport($username);
$filename = sprintf('weekly_report_%s_%s.md', $username, Carbon::now()->subWeek()->format('Y-m-d'));
if (! in_array($period, self::WEEKLY_REPORT_PERIODS, true)) {
return response()->json([
'success' => false,
'message' => '无效的周报周期',
], 400);
}
$report = $this->jiraService->generateWeeklyReport($username, $period);
$filename = sprintf('weekly_report_%s_%s_%s.md', $username, $period, Carbon::now()->format('Y-m-d'));
return response($report)
->header('Content-Type', 'text/markdown')
->header('Content-Disposition', 'attachment; filename="' . $filename . '"');
->header('Content-Disposition', 'attachment; filename="'.$filename.'"');
} catch (\Exception $e) {
return response()->json([
'success' => false,
'message' => '下载周报失败: ' . $e->getMessage()
'message' => '下载周报失败: '.$e->getMessage(),
], 500);
}
}
}