feat: 통합 품목 조회 API 및 가격 통합 시스템 구현

- 통합 품목 조회 API (materials + products UNION)
  - ItemsService, ItemsController, Swagger 문서 생성
  - 타입 필터링 (FG/PT/SM/RM/CS), 검색, 카테고리 지원
  - Collection merge 방식으로 UNION 쿼리 안정화

- 품목-가격 통합 조회
  - PricingService.getPriceByType() 추가 (SALE/PURCHASE 지원)
  - 단일 품목 조회 시 판매가/매입가 선택적 포함
  - 고객그룹 가격 우선순위 적용 및 시계열 조회

- 자재 타입 명시적 관리
  - materials.material_type 컬럼 추가 (SM/RM/CS)
  - 기존 데이터 344개 자동 변환 (RAW→RM, SUB→SM)
  - 인덱스 추가로 조회 성능 최적화

- DB 데이터 정규화
  - products.product_type: 760개 정규화 (PRODUCT→FG, PART/SUBASSEMBLY→PT)
  - 타입 코드 표준화로 API 일관성 확보

최종 데이터: 제품 760개(FG 297, PT 463), 자재 344개(SM 215, RM 129)
This commit is contained in:
2025-11-11 11:30:17 +09:00
parent fdef567863
commit ddc4bb99a0
10 changed files with 4996 additions and 6 deletions

View File

@@ -0,0 +1,45 @@
<?php
namespace App\Http\Controllers\Api\V1;
use App\Helpers\ApiResponse;
use App\Http\Controllers\Controller;
use App\Services\ItemsService;
use Illuminate\Http\Request;
class ItemsController extends Controller
{
public function __construct(private ItemsService $service) {}
/**
* 통합 품목 목록 조회 (materials + products)
*
* GET /api/v1/items
*/
public function index(Request $request)
{
return ApiResponse::handle(function () use ($request) {
$filters = $request->only(['type', 'search', 'q', 'category_id']);
$perPage = (int) ($request->input('size') ?? 20);
return $this->service->getItems($filters, $perPage);
}, __('message.fetched'));
}
/**
* 단일 품목 조회
*
* GET /api/v1/items/{id}?item_type=PRODUCT|MATERIAL&include_price=true&client_id=1&price_date=2025-01-10
*/
public function show(Request $request, int $id)
{
return ApiResponse::handle(function () use ($request, $id) {
$itemType = strtoupper($request->input('item_type', 'PRODUCT'));
$includePrice = filter_var($request->input('include_price', false), FILTER_VALIDATE_BOOLEAN);
$clientId = $request->input('client_id') ? (int) $request->input('client_id') : null;
$priceDate = $request->input('price_date');
return $this->service->getItem($itemType, $id, $includePrice, $clientId, $priceDate);
}, __('message.fetched'));
}
}