feat: 공정 관리 API 개선 및 ProcessItem 추가
- ProcessItem 모델 및 마이그레이션 추가 - Process 요청/서비스 로직 수정 - Swagger API 문서 추가 Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
|
||||
use App\Models\Process;
|
||||
use App\Models\ProcessClassificationRule;
|
||||
use App\Models\ProcessItem;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
|
||||
@@ -24,7 +25,7 @@ public function index(array $params)
|
||||
|
||||
$query = Process::query()
|
||||
->where('tenant_id', $tenantId)
|
||||
->with('classificationRules');
|
||||
->with(['classificationRules', 'processItems.item:id,code,name']);
|
||||
|
||||
// 검색어
|
||||
if ($q !== '') {
|
||||
@@ -61,7 +62,7 @@ public function show(int $id)
|
||||
$tenantId = $this->tenantId();
|
||||
|
||||
$process = Process::where('tenant_id', $tenantId)
|
||||
->with('classificationRules')
|
||||
->with(['classificationRules', 'processItems.item:id,code,name'])
|
||||
->find($id);
|
||||
|
||||
if (! $process) {
|
||||
@@ -92,14 +93,18 @@ public function store(array $data)
|
||||
}
|
||||
|
||||
$rules = $data['classification_rules'] ?? [];
|
||||
unset($data['classification_rules']);
|
||||
$itemIds = $data['item_ids'] ?? [];
|
||||
unset($data['classification_rules'], $data['item_ids']);
|
||||
|
||||
$process = Process::create($data);
|
||||
|
||||
// 분류 규칙 저장
|
||||
// 분류 규칙 저장 (패턴 규칙)
|
||||
$this->syncClassificationRules($process, $rules);
|
||||
|
||||
return $process->load('classificationRules');
|
||||
// 개별 품목 연결
|
||||
$this->syncProcessItems($process, $itemIds);
|
||||
|
||||
return $process->load(['classificationRules', 'processItems.item:id,code,name']);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -125,7 +130,8 @@ public function update(int $id, array $data)
|
||||
}
|
||||
|
||||
$rules = $data['classification_rules'] ?? null;
|
||||
unset($data['classification_rules']);
|
||||
$itemIds = $data['item_ids'] ?? null;
|
||||
unset($data['classification_rules'], $data['item_ids']);
|
||||
|
||||
$process->update($data);
|
||||
|
||||
@@ -134,7 +140,12 @@ public function update(int $id, array $data)
|
||||
$this->syncClassificationRules($process, $rules);
|
||||
}
|
||||
|
||||
return $process->fresh('classificationRules');
|
||||
// 개별 품목 동기화 (전달된 경우만)
|
||||
if ($itemIds !== null) {
|
||||
$this->syncProcessItems($process, $itemIds);
|
||||
}
|
||||
|
||||
return $process->fresh(['classificationRules', 'processItems.item:id,code,name']);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -190,7 +201,7 @@ public function toggleActive(int $id)
|
||||
'updated_by' => $userId,
|
||||
]);
|
||||
|
||||
return $process->fresh('classificationRules');
|
||||
return $process->fresh(['classificationRules', 'processItems.item:id,code,name']);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -200,7 +211,7 @@ private function generateProcessCode(int $tenantId): string
|
||||
{
|
||||
$lastProcess = Process::where('tenant_id', $tenantId)
|
||||
->withTrashed()
|
||||
->orderByRaw("CAST(SUBSTRING(process_code, 3) AS UNSIGNED) DESC")
|
||||
->orderByRaw('CAST(SUBSTRING(process_code, 3) AS UNSIGNED) DESC')
|
||||
->first();
|
||||
|
||||
if ($lastProcess && preg_match('/^P-(\d+)$/', $lastProcess->process_code, $matches)) {
|
||||
@@ -213,18 +224,18 @@ private function generateProcessCode(int $tenantId): string
|
||||
}
|
||||
|
||||
/**
|
||||
* 분류 규칙 동기화
|
||||
* 분류 규칙 동기화 (패턴 규칙용)
|
||||
*/
|
||||
private function syncClassificationRules(Process $process, array $rules): void
|
||||
{
|
||||
// 기존 규칙 삭제
|
||||
$process->classificationRules()->delete();
|
||||
|
||||
// 새 규칙 생성
|
||||
// 새 규칙 생성 (패턴 규칙만)
|
||||
foreach ($rules as $index => $rule) {
|
||||
ProcessClassificationRule::create([
|
||||
'process_id' => $process->id,
|
||||
'registration_type' => $rule['registration_type'] ?? 'pattern',
|
||||
'registration_type' => 'pattern',
|
||||
'rule_type' => $rule['rule_type'],
|
||||
'matching_type' => $rule['matching_type'],
|
||||
'condition_value' => $rule['condition_value'],
|
||||
@@ -235,6 +246,27 @@ private function syncClassificationRules(Process $process, array $rules): void
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 개별 품목 연결 동기화
|
||||
*
|
||||
* @param array $itemIds 품목 ID 배열
|
||||
*/
|
||||
private function syncProcessItems(Process $process, array $itemIds): void
|
||||
{
|
||||
// 기존 연결 삭제
|
||||
$process->processItems()->delete();
|
||||
|
||||
// 새 연결 생성
|
||||
foreach ($itemIds as $index => $itemId) {
|
||||
ProcessItem::create([
|
||||
'process_id' => $process->id,
|
||||
'item_id' => $itemId,
|
||||
'priority' => $index,
|
||||
'is_active' => true,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 드롭다운용 공정 옵션 목록
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user