feat: G-1 작업지시 관리 API 구현

- 작업지시 테이블 마이그레이션 (work_orders, work_order_items, work_order_bending_details, work_order_issues)
- 작업지시 모델 4개 (WorkOrder, WorkOrderItem, WorkOrderBendingDetail, WorkOrderIssue)
- WorkOrderService 비즈니스 로직 구현
- WorkOrderController REST API 엔드포인트 11개
- FormRequest 검증 클래스 5개
- Swagger API 문서화 완료

API Endpoints:
- GET /work-orders (목록)
- GET /work-orders/stats (통계)
- POST /work-orders (등록)
- GET /work-orders/{id} (상세)
- PUT /work-orders/{id} (수정)
- DELETE /work-orders/{id} (삭제)
- PATCH /work-orders/{id}/status (상태변경)
- PATCH /work-orders/{id}/assign (담당자배정)
- PATCH /work-orders/{id}/bending/toggle (벤딩토글)
- POST /work-orders/{id}/issues (이슈등록)
- PATCH /work-orders/{id}/issues/{issueId}/resolve (이슈해결)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-12-26 13:57:42 +09:00
parent 5ab5353d4d
commit 05a53cdc8e
17 changed files with 2000 additions and 0 deletions

View File

@@ -0,0 +1,294 @@
<?php
namespace App\Models\Production;
use App\Models\Members\User;
use App\Models\Orders\Order;
use App\Models\Tenants\Department;
use App\Traits\BelongsToTenant;
use App\Traits\ModelTrait;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasOne;
use Illuminate\Database\Eloquent\SoftDeletes;
/**
* 작업지시 모델
*
* 생산 관리의 핵심 엔티티로 수주(SalesOrder)를 기반으로 생산 작업을 지시하고 추적
*/
class WorkOrder extends Model
{
use BelongsToTenant, ModelTrait, SoftDeletes;
protected $table = 'work_orders';
protected $fillable = [
'tenant_id',
'work_order_no',
'sales_order_id',
'project_name',
'process_type',
'status',
'assignee_id',
'team_id',
'scheduled_date',
'started_at',
'completed_at',
'shipped_at',
'memo',
'is_active',
'created_by',
'updated_by',
];
protected $casts = [
'scheduled_date' => 'date',
'started_at' => 'datetime',
'completed_at' => 'datetime',
'shipped_at' => 'datetime',
'is_active' => 'boolean',
];
protected $hidden = [
'deleted_at',
];
// ──────────────────────────────────────────────────────────────
// 상수
// ──────────────────────────────────────────────────────────────
/**
* 공정 유형
*/
public const PROCESS_SCREEN = 'screen';
public const PROCESS_SLAT = 'slat';
public const PROCESS_BENDING = 'bending';
public const PROCESS_TYPES = [
self::PROCESS_SCREEN,
self::PROCESS_SLAT,
self::PROCESS_BENDING,
];
/**
* 상태
*/
public const STATUS_UNASSIGNED = 'unassigned'; // 미배정
public const STATUS_PENDING = 'pending'; // 대기
public const STATUS_WAITING = 'waiting'; // 준비중
public const STATUS_IN_PROGRESS = 'in_progress'; // 진행중
public const STATUS_COMPLETED = 'completed'; // 완료
public const STATUS_SHIPPED = 'shipped'; // 출하
public const STATUSES = [
self::STATUS_UNASSIGNED,
self::STATUS_PENDING,
self::STATUS_WAITING,
self::STATUS_IN_PROGRESS,
self::STATUS_COMPLETED,
self::STATUS_SHIPPED,
];
// ──────────────────────────────────────────────────────────────
// 관계
// ──────────────────────────────────────────────────────────────
/**
* 수주
*/
public function salesOrder(): BelongsTo
{
return $this->belongsTo(Order::class, 'sales_order_id');
}
/**
* 담당자
*/
public function assignee(): BelongsTo
{
return $this->belongsTo(User::class, 'assignee_id');
}
/**
* 팀
*/
public function team(): BelongsTo
{
return $this->belongsTo(Department::class, 'team_id');
}
/**
* 작업지시 품목들
*/
public function items(): HasMany
{
return $this->hasMany(WorkOrderItem::class)->orderBy('sort_order');
}
/**
* 벤딩 상세 (1:1)
*/
public function bendingDetail(): HasOne
{
return $this->hasOne(WorkOrderBendingDetail::class);
}
/**
* 이슈들
*/
public function issues(): HasMany
{
return $this->hasMany(WorkOrderIssue::class);
}
/**
* 생성자
*/
public function creator(): BelongsTo
{
return $this->belongsTo(User::class, 'created_by');
}
/**
* 수정자
*/
public function updater(): BelongsTo
{
return $this->belongsTo(User::class, 'updated_by');
}
// ──────────────────────────────────────────────────────────────
// 스코프
// ──────────────────────────────────────────────────────────────
/**
* 상태별 필터
*/
public function scopeStatus($query, string $status)
{
return $query->where('status', $status);
}
/**
* 공정유형별 필터
*/
public function scopeProcessType($query, string $type)
{
return $query->where('process_type', $type);
}
/**
* 담당자별 필터
*/
public function scopeAssignee($query, int $assigneeId)
{
return $query->where('assignee_id', $assigneeId);
}
/**
* 팀별 필터
*/
public function scopeTeam($query, int $teamId)
{
return $query->where('team_id', $teamId);
}
/**
* 미배정
*/
public function scopeUnassigned($query)
{
return $query->where('status', self::STATUS_UNASSIGNED);
}
/**
* 진행중 (pending, waiting, in_progress)
*/
public function scopeInProgress($query)
{
return $query->whereIn('status', [
self::STATUS_PENDING,
self::STATUS_WAITING,
self::STATUS_IN_PROGRESS,
]);
}
/**
* 완료됨 (completed, shipped)
*/
public function scopeCompleted($query)
{
return $query->whereIn('status', [
self::STATUS_COMPLETED,
self::STATUS_SHIPPED,
]);
}
/**
* 예정일 범위
*/
public function scopeScheduledBetween($query, $from, $to)
{
return $query->whereBetween('scheduled_date', [$from, $to]);
}
// ──────────────────────────────────────────────────────────────
// 헬퍼 메서드
// ──────────────────────────────────────────────────────────────
/**
* 벤딩 공정인지 확인
*/
public function isBending(): bool
{
return $this->process_type === self::PROCESS_BENDING;
}
/**
* 미배정 상태인지 확인
*/
public function isUnassigned(): bool
{
return $this->status === self::STATUS_UNASSIGNED;
}
/**
* 진행중인지 확인
*/
public function isInProgress(): bool
{
return in_array($this->status, [
self::STATUS_PENDING,
self::STATUS_WAITING,
self::STATUS_IN_PROGRESS,
]);
}
/**
* 완료되었는지 확인
*/
public function isCompleted(): bool
{
return in_array($this->status, [
self::STATUS_COMPLETED,
self::STATUS_SHIPPED,
]);
}
/**
* 미해결 이슈 수
*/
public function getOpenIssuesCountAttribute(): int
{
return $this->issues()->where('status', '!=', 'resolved')->count();
}
}

View File

@@ -0,0 +1,131 @@
<?php
namespace App\Models\Production;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
/**
* 작업지시 벤딩 상세 모델
*
* 벤딩 공정의 세부 작업 항목 완료 상태를 추적
*/
class WorkOrderBendingDetail extends Model
{
protected $table = 'work_order_bending_details';
protected $fillable = [
'work_order_id',
'shaft_cutting',
'bearing',
'shaft_welding',
'assembly',
'winder_welding',
'frame_assembly',
'bundle_assembly',
'motor_assembly',
'bracket_assembly',
];
protected $casts = [
'shaft_cutting' => 'boolean',
'bearing' => 'boolean',
'shaft_welding' => 'boolean',
'assembly' => 'boolean',
'winder_welding' => 'boolean',
'frame_assembly' => 'boolean',
'bundle_assembly' => 'boolean',
'motor_assembly' => 'boolean',
'bracket_assembly' => 'boolean',
];
/**
* 벤딩 공정 항목 목록
*/
public const PROCESS_FIELDS = [
'shaft_cutting',
'bearing',
'shaft_welding',
'assembly',
'winder_welding',
'frame_assembly',
'bundle_assembly',
'motor_assembly',
'bracket_assembly',
];
// ──────────────────────────────────────────────────────────────
// 관계
// ──────────────────────────────────────────────────────────────
/**
* 작업지시
*/
public function workOrder(): BelongsTo
{
return $this->belongsTo(WorkOrder::class);
}
// ──────────────────────────────────────────────────────────────
// 헬퍼 메서드
// ──────────────────────────────────────────────────────────────
/**
* 완료된 항목 수
*/
public function getCompletedCountAttribute(): int
{
$count = 0;
foreach (self::PROCESS_FIELDS as $field) {
if ($this->{$field}) {
$count++;
}
}
return $count;
}
/**
* 전체 항목 수
*/
public function getTotalCountAttribute(): int
{
return count(self::PROCESS_FIELDS);
}
/**
* 진행률 (%)
*/
public function getProgressPercentAttribute(): int
{
$total = $this->total_count;
if ($total === 0) {
return 0;
}
return (int) round(($this->completed_count / $total) * 100);
}
/**
* 모든 항목이 완료되었는지 확인
*/
public function isAllCompleted(): bool
{
return $this->completed_count === $this->total_count;
}
/**
* 특정 항목 토글
*/
public function toggleField(string $field): bool
{
if (! in_array($field, self::PROCESS_FIELDS)) {
return false;
}
$this->{$field} = ! $this->{$field};
$this->save();
return true;
}
}

View File

@@ -0,0 +1,161 @@
<?php
namespace App\Models\Production;
use App\Models\Members\User;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
/**
* 작업지시 이슈 모델
*
* 작업지시 진행 중 발생한 이슈를 기록하고 추적
*/
class WorkOrderIssue extends Model
{
protected $table = 'work_order_issues';
protected $fillable = [
'work_order_id',
'title',
'description',
'priority',
'status',
'reported_by',
'resolved_by',
'resolved_at',
];
protected $casts = [
'resolved_at' => 'datetime',
];
// ──────────────────────────────────────────────────────────────
// 상수
// ──────────────────────────────────────────────────────────────
/**
* 우선순위
*/
public const PRIORITY_HIGH = 'high';
public const PRIORITY_MEDIUM = 'medium';
public const PRIORITY_LOW = 'low';
public const PRIORITIES = [
self::PRIORITY_HIGH,
self::PRIORITY_MEDIUM,
self::PRIORITY_LOW,
];
/**
* 상태
*/
public const STATUS_OPEN = 'open';
public const STATUS_IN_PROGRESS = 'in_progress';
public const STATUS_RESOLVED = 'resolved';
public const STATUSES = [
self::STATUS_OPEN,
self::STATUS_IN_PROGRESS,
self::STATUS_RESOLVED,
];
// ──────────────────────────────────────────────────────────────
// 관계
// ──────────────────────────────────────────────────────────────
/**
* 작업지시
*/
public function workOrder(): BelongsTo
{
return $this->belongsTo(WorkOrder::class);
}
/**
* 보고자
*/
public function reporter(): BelongsTo
{
return $this->belongsTo(User::class, 'reported_by');
}
/**
* 해결자
*/
public function resolver(): BelongsTo
{
return $this->belongsTo(User::class, 'resolved_by');
}
// ──────────────────────────────────────────────────────────────
// 스코프
// ──────────────────────────────────────────────────────────────
/**
* 열린 이슈
*/
public function scopeOpen($query)
{
return $query->where('status', self::STATUS_OPEN);
}
/**
* 미해결 이슈 (open + in_progress)
*/
public function scopeUnresolved($query)
{
return $query->whereIn('status', [self::STATUS_OPEN, self::STATUS_IN_PROGRESS]);
}
/**
* 해결된 이슈
*/
public function scopeResolved($query)
{
return $query->where('status', self::STATUS_RESOLVED);
}
/**
* 우선순위별
*/
public function scopePriority($query, string $priority)
{
return $query->where('priority', $priority);
}
/**
* 높은 우선순위
*/
public function scopeHighPriority($query)
{
return $query->where('priority', self::PRIORITY_HIGH);
}
// ──────────────────────────────────────────────────────────────
// 헬퍼 메서드
// ──────────────────────────────────────────────────────────────
/**
* 해결되었는지 확인
*/
public function isResolved(): bool
{
return $this->status === self::STATUS_RESOLVED;
}
/**
* 이슈 해결 처리
*/
public function resolve(int $userId): void
{
$this->status = self::STATUS_RESOLVED;
$this->resolved_by = $userId;
$this->resolved_at = now();
$this->save();
}
}

View File

@@ -0,0 +1,62 @@
<?php
namespace App\Models\Production;
use App\Models\Items\Item;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
/**
* 작업지시 품목 모델
*/
class WorkOrderItem extends Model
{
protected $table = 'work_order_items';
protected $fillable = [
'work_order_id',
'item_id',
'item_name',
'specification',
'quantity',
'unit',
'sort_order',
];
protected $casts = [
'quantity' => 'decimal:2',
'sort_order' => 'integer',
];
// ──────────────────────────────────────────────────────────────
// 관계
// ──────────────────────────────────────────────────────────────
/**
* 작업지시
*/
public function workOrder(): BelongsTo
{
return $this->belongsTo(WorkOrder::class);
}
/**
* 품목
*/
public function item(): BelongsTo
{
return $this->belongsTo(Item::class);
}
// ──────────────────────────────────────────────────────────────
// 스코프
// ──────────────────────────────────────────────────────────────
/**
* 정렬 순서
*/
public function scopeOrdered($query)
{
return $query->orderBy('sort_order');
}
}