fix(API): 경동 견적 수식 핸들러 개선

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-11 15:58:42 +09:00
parent bcad646ea6
commit de10441275

View File

@@ -63,6 +63,38 @@ public function __construct(?EstimatePriceService $priceService = null)
'EST-ANGLE-BRACKET-철제800K' => 14910,
];
/**
* items master에서 코드로 아이템 조회 (캐싱 적용, id + name)
*
* @param string $code 아이템 코드
* @return array{id: int|null, name: string|null}
*/
private function lookupItem(string $code): array
{
static $cache = [];
if (isset($cache[$code])) {
return $cache[$code];
}
// 1. 고정 매핑에 ID만 있는 경우 → DB에서 name 조회
if (isset(self::FIXED_ITEM_MAPPINGS[$code])) {
$fixedId = self::FIXED_ITEM_MAPPINGS[$code];
$name = \App\Models\Items\Item::where('id', $fixedId)->value('name');
$cache[$code] = ['id' => $fixedId, 'name' => $name];
return $cache[$code];
}
// 2. DB에서 동적 조회 (BD-*, EST-* 패턴)
$item = \App\Models\Items\Item::where('tenant_id', self::TENANT_ID)
->where('code', $code)
->first(['id', 'name']);
$cache[$code] = ['id' => $item?->id, 'name' => $item?->name];
return $cache[$code];
}
/**
* items master에서 코드로 아이템 ID 조회 (캐싱 적용)
*
@@ -71,28 +103,14 @@ public function __construct(?EstimatePriceService $priceService = null)
*/
private function lookupItemId(string $code): ?int
{
// 1. 고정 매핑 먼저 확인
if (isset(self::FIXED_ITEM_MAPPINGS[$code])) {
return self::FIXED_ITEM_MAPPINGS[$code];
}
// 2. DB에서 동적 조회 (BD-*, EST-* 패턴)
static $cache = [];
if (isset($cache[$code])) {
return $cache[$code];
}
$item = \App\Models\Items\Item::where('tenant_id', self::TENANT_ID)
->where('code', $code)
->first(['id']);
$cache[$code] = $item?->id;
return $cache[$code];
return $this->lookupItem($code)['id'];
}
/**
* 아이템 배열에 item_code/item_id 매핑 추가
* 아이템 배열에 item_code/item_id 매핑 추가 + 마스터 품목명 적용
*
* items 마스터에 등록된 품목이면 마스터의 name을 item_name으로 사용하고,
* 미등록 품목이면 하드코딩된 item_name을 그대로 유지
*
* @param array $item 아이템 배열
* @param string $code 아이템 코드
@@ -100,10 +118,19 @@ private function lookupItemId(string $code): ?int
*/
private function withItemMapping(array $item, string $code): array
{
return array_merge($item, [
$looked = $this->lookupItem($code);
$merged = array_merge($item, [
'item_code' => $code,
'item_id' => $this->lookupItemId($code),
'item_id' => $looked['id'],
]);
// 마스터에 등록된 품목이면 마스터 name 사용
if ($looked['name']) {
$merged['item_name'] = $looked['name'];
}
return $merged;
}
/**