2026-03-02 17:43:47 +09:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\Api\Admin\Rd;
|
|
|
|
|
|
|
|
|
|
use App\Http\Controllers\Controller;
|
|
|
|
|
use App\Http\Requests\Rd\StoreAiQuotationRequest;
|
|
|
|
|
use App\Services\Rd\AiQuotationService;
|
|
|
|
|
use Illuminate\Http\JsonResponse;
|
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
use Illuminate\View\View;
|
|
|
|
|
|
|
|
|
|
class AiQuotationController extends Controller
|
|
|
|
|
{
|
|
|
|
|
public function __construct(
|
|
|
|
|
private readonly AiQuotationService $quotationService
|
|
|
|
|
) {}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 목록 (HTMX partial 또는 JSON)
|
|
|
|
|
*/
|
|
|
|
|
public function index(Request $request): View|JsonResponse
|
|
|
|
|
{
|
|
|
|
|
$params = $request->only(['status', 'search', 'per_page']);
|
|
|
|
|
$quotations = $this->quotationService->getList($params);
|
|
|
|
|
|
|
|
|
|
if ($request->header('HX-Request')) {
|
|
|
|
|
return view('rd.ai-quotation.partials.table', compact('quotations'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return response()->json([
|
|
|
|
|
'success' => true,
|
|
|
|
|
'data' => $quotations,
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 견적 생성 + AI 분석 실행
|
|
|
|
|
*/
|
|
|
|
|
public function store(StoreAiQuotationRequest $request): JsonResponse
|
|
|
|
|
{
|
|
|
|
|
$result = $this->quotationService->createAndAnalyze($request->validated());
|
|
|
|
|
|
|
|
|
|
if ($result['ok']) {
|
|
|
|
|
return response()->json([
|
|
|
|
|
'success' => true,
|
|
|
|
|
'message' => 'AI 분석이 완료되었습니다.',
|
|
|
|
|
'data' => $result['quotation'],
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return response()->json([
|
|
|
|
|
'success' => false,
|
|
|
|
|
'message' => 'AI 분석에 실패했습니다.',
|
|
|
|
|
'error' => $result['error'],
|
|
|
|
|
'data' => $result['quotation'] ?? null,
|
|
|
|
|
], 422);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 상세 조회
|
|
|
|
|
*/
|
|
|
|
|
public function show(int $id): JsonResponse
|
|
|
|
|
{
|
|
|
|
|
$quotation = $this->quotationService->getById($id);
|
|
|
|
|
|
|
|
|
|
if (! $quotation) {
|
|
|
|
|
return response()->json([
|
|
|
|
|
'success' => false,
|
|
|
|
|
'message' => 'AI 견적을 찾을 수 없습니다.',
|
|
|
|
|
], 404);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return response()->json([
|
|
|
|
|
'success' => true,
|
|
|
|
|
'data' => $quotation,
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* AI 재분석
|
|
|
|
|
*/
|
|
|
|
|
public function analyze(int $id): JsonResponse
|
|
|
|
|
{
|
|
|
|
|
$quotation = $this->quotationService->getById($id);
|
|
|
|
|
|
|
|
|
|
if (! $quotation) {
|
|
|
|
|
return response()->json([
|
|
|
|
|
'success' => false,
|
|
|
|
|
'message' => 'AI 견적을 찾을 수 없습니다.',
|
|
|
|
|
], 404);
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-03 15:57:31 +09:00
|
|
|
// 제조 모드는 제조용 분석 실행
|
|
|
|
|
if ($quotation->isManufacture()) {
|
|
|
|
|
$result = $this->quotationService->runManufactureAnalysis($quotation);
|
|
|
|
|
} else {
|
|
|
|
|
$result = $this->quotationService->runAnalysis($quotation);
|
|
|
|
|
}
|
2026-03-02 17:43:47 +09:00
|
|
|
|
|
|
|
|
if ($result['ok']) {
|
|
|
|
|
return response()->json([
|
|
|
|
|
'success' => true,
|
|
|
|
|
'message' => 'AI 재분석이 완료되었습니다.',
|
|
|
|
|
'data' => $result['quotation'],
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return response()->json([
|
|
|
|
|
'success' => false,
|
|
|
|
|
'message' => 'AI 재분석에 실패했습니다.',
|
|
|
|
|
'error' => $result['error'],
|
|
|
|
|
], 422);
|
|
|
|
|
}
|
2026-03-03 15:57:31 +09:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 견적 편집 저장
|
|
|
|
|
*/
|
|
|
|
|
public function update(Request $request, int $id): JsonResponse
|
|
|
|
|
{
|
|
|
|
|
$result = $this->quotationService->updateQuotation($id, $request->all());
|
|
|
|
|
|
|
|
|
|
if ($result['ok']) {
|
|
|
|
|
return response()->json([
|
|
|
|
|
'success' => true,
|
|
|
|
|
'message' => '견적이 저장되었습니다.',
|
|
|
|
|
'data' => $result['quotation'],
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return response()->json([
|
|
|
|
|
'success' => false,
|
|
|
|
|
'message' => '견적 저장에 실패했습니다.',
|
|
|
|
|
'error' => $result['error'] ?? null,
|
|
|
|
|
], 422);
|
|
|
|
|
}
|
2026-03-02 17:43:47 +09:00
|
|
|
}
|