summaryrefslogtreecommitdiff
path: root/lib/sedp
diff options
context:
space:
mode:
authordujinkim <dujin.kim@dtsolution.co.kr>2025-09-30 10:08:53 +0000
committerdujinkim <dujin.kim@dtsolution.co.kr>2025-09-30 10:08:53 +0000
commit2c02afd48a4d9276a4f5c132e088540a578d0972 (patch)
treee5efdd3f48fad33681c139a4c58481f4514fb38e /lib/sedp
parent19794b32a6e3285fdeda7519ededdce451966f3d (diff)
(대표님) 폼리스트, spreadjs 관련 변경사항, 벤더문서 뷰 쿼리 수정, 이메일 템플릿 추가 등
Diffstat (limited to 'lib/sedp')
-rw-r--r--lib/sedp/get-form-tags.ts147
1 files changed, 143 insertions, 4 deletions
diff --git a/lib/sedp/get-form-tags.ts b/lib/sedp/get-form-tags.ts
index 310ef486..b81762c6 100644
--- a/lib/sedp/get-form-tags.ts
+++ b/lib/sedp/get-form-tags.ts
@@ -44,6 +44,96 @@ interface Column {
shi?: string | null;
}
+interface newRegister {
+ PROJ_NO: string;
+ MAP_ID: string;
+ EP_ID: string;
+ CATEGORY: string;
+ BYPASS: boolean;
+ REG_TYPE_ID: string;
+ TOOL_ID: string;
+ TOOL_TYPE: string;
+ SCOPES: string[];
+ MAP_CLS: {
+ TOOL_ATT_NAME: string;
+ ITEMS: ClassItmes[];
+ };
+ MAP_ATT: MapAttribute[];
+ MAP_TMPLS: string[];
+ CRTER_NO: string;
+ CRTE_DTM: string;
+ CHGER_NO: string;
+ _id: string;
+}
+
+interface ClassItmes {
+ SEDP_OBJ_CLS_ID: string;
+ TOOL_VALS: string;
+ ISDEFALUT: boolean;
+}
+
+interface MapAttribute {
+ SEDP_ATT_ID: string;
+ TOOL_ATT_NAME: string;
+ KEY_YN: boolean;
+ DUE_DATE: string; //"YYYY-MM-DDTHH:mm:ssZ"
+ INOUT: string | null;
+}
+
+
+
+async function getNewRegisters(projectCode: string): Promise<newRegister[]> {
+ try {
+ // 토큰(API 키) 가져오기
+ const apiKey = await getSEDPToken();
+
+ const SEDP_API_BASE_URL = process.env.SEDP_API_BASE_URL || 'http://sedpwebapi.ship.samsung.co.kr/api';
+
+ const response = await fetch(
+ `${SEDP_API_BASE_URL}/AdapterDataMapping/GetByToolID`,
+ {
+ method: 'POST',
+ headers: {
+ 'Content-Type': 'application/json',
+ 'accept': '*/*',
+ 'ApiKey': apiKey,
+ 'ProjectNo': projectCode
+ },
+ body: JSON.stringify({
+ ProjectNo: projectCode,
+ "TOOL_ID": "eVCP"
+ })
+ }
+ );
+
+ if (!response.ok) {
+ throw new Error(`새 레지스터 요청 실패: ${response.status} ${response.statusText}`);
+ }
+
+ // 안전하게 JSON 파싱
+ let data;
+ try {
+ data = await response.json();
+ } catch (parseError) {
+ console.error(`프로젝트 ${projectCode}의 새 레지스터 응답 파싱 실패:`, parseError);
+ // 응답 내용 로깅
+ const text = await response.clone().text();
+ console.log(`응답 내용: ${text.substring(0, 200)}${text.length > 200 ? '...' : ''}`);
+ throw new Error(`새 레지스터 응답 파싱 실패: ${parseError instanceof Error ? parseError.message : String(parseError)}`);
+ }
+
+ // 결과를 배열로 변환 (단일 객체인 경우 배열로 래핑)
+ let registers: newRegister[] = Array.isArray(data) ? data : [data];
+
+ console.log(`프로젝트 ${projectCode}에서 ${registers.length}개의 새 레지스터를 가져왔습니다.`);
+ return registers;
+ } catch (error) {
+ console.error(`프로젝트 ${projectCode}의 새 레지스터 가져오기 실패:`, error);
+ throw error;
+ }
+}
+
+
/**
* 태그 가져오기 서비스 함수
* contractItemId(packageId)를 기반으로 외부 시스템에서 태그 데이터를 가져와 DB에 저장
@@ -70,6 +160,10 @@ export async function importTagsFromSEDP(
// SEDP API에서 태그 데이터 가져오기
const tagData = await fetchTagDataFromSEDP(projectCode, formCode);
+ const newRegisters = await getNewRegisters(projectCode);
+
+ const registerMatched = newRegisters.find(v => v.REG_TYPE_ID === formCode).MAP_ATT
+
// 트랜잭션으로 모든 DB 작업 처리
return await db.transaction(async (tx) => {
@@ -459,7 +553,7 @@ export async function importTagsFromSEDP(
}
}
- const packageCode = projectType === "ship" ? tagEntry.ATTRIBUTES.find(v=>v.ATT_ID === "CM3003")?.VALUE :tagEntry.ATTRIBUTES.find(v=>v.ATT_ID === "ME5074")?.VALUE
+ const packageCode = projectType === "ship" ? tagEntry.ATTRIBUTES.find(v => v.ATT_ID === "CM3003")?.VALUE : tagEntry.ATTRIBUTES.find(v => v.ATT_ID === "ME5074")?.VALUE
// 기본 태그 데이터 객체 생성 (formEntries용)
const tagObject: any = {
@@ -470,9 +564,11 @@ export async function importTagsFromSEDP(
VNDRCD: vendorRecord[0].vendorCode,
VNDRNM_1: vendorRecord[0].vendorName,
status: "From S-EDP", // SEDP에서 가져온 데이터임을 표시
- ...(projectType === "ship" ? { CM3003: packageCode } : { ME5074:packageCode })
+ ...(projectType === "ship" ? { CM3003: packageCode } : { ME5074: packageCode })
}
+ let latestDueDate: Date | null = null;
+
// tags 테이블용 데이터 (UPSERT용)
const tagRecord = {
contractItemId: packageId,
@@ -491,7 +587,7 @@ export async function importTagsFromSEDP(
if (Array.isArray(tagEntry.ATTRIBUTES)) {
for (const attr of tagEntry.ATTRIBUTES) {
const columnInfo = columnsJSON.find(col => col.key === attr.ATT_ID);
- if (columnInfo && (columnInfo.shi === "BOTH" ||columnInfo.shi === "OUT" ||columnInfo.shi === null )) {
+ if (columnInfo && (columnInfo.shi === "BOTH" || columnInfo.shi === "OUT" || columnInfo.shi === null)) {
if (columnInfo.type === "NUMBER") {
if (attr.VALUE !== undefined && attr.VALUE !== null) {
if (typeof attr.VALUE === 'string') {
@@ -512,9 +608,46 @@ export async function importTagsFromSEDP(
tagObject[attr.ATT_ID] = attr.VALUE;
}
}
+
+ // registerMatched에서 해당 SEDP_ATT_ID의 DUE_DATE 찾기
+ if (registerMatched && Array.isArray(registerMatched)) {
+ const matchedAttribute = registerMatched.find(
+ regAttr => regAttr.SEDP_ATT_ID === attr.ATT_ID
+ );
+
+ if (matchedAttribute && matchedAttribute.DUE_DATE) {
+ try {
+ const dueDate = new Date(matchedAttribute.DUE_DATE);
+
+ // 유효한 날짜인지 확인
+ if (!isNaN(dueDate.getTime())) {
+ // 첫 번째 DUE_DATE이거나 현재까지 찾은 것보다 더 늦은 날짜인 경우 업데이트
+ if (!latestDueDate || dueDate > latestDueDate) {
+ latestDueDate = dueDate;
+ }
+ }
+ } catch (dateError) {
+ console.warn(`Invalid DUE_DATE format for ${attr.ATT_ID}: ${matchedAttribute.DUE_DATE}`);
+ }
+ }
+ }
+
}
}
+ if (latestDueDate) {
+ // ISO 형식의 문자열로 저장 (또는 원하는 형식으로 변경 가능)
+ tagObject.DUE_DATE = latestDueDate.toISOString();
+
+ // 또는 YYYY-MM-DD 형식을 원한다면:
+ // tagObject.DUE_DATE = latestDueDate.toISOString().split('T')[0];
+
+ // 또는 원본 형식 그대로 유지하려면:
+ // tagObject.DUE_DATE = latestDueDate.toISOString().replace('Z', '');
+ }
+
+
+
// 기존 태그가 있는지 확인하고 처리
const existingTag = existingTagMap.get(tagEntry.TAG_IDX);
@@ -550,8 +683,14 @@ export async function importTagsFromSEDP(
continue;
}
+ if (key === "DUE_DATE" && tagObject[key] !== existingTag.data[key]) {
+ updates[key] = tagObject[key];
+ hasUpdates = true;
+ continue;
+ }
+
const columnInfo = columnsJSON.find(col => col.key === key);
- if (columnInfo && (columnInfo.shi === "BOTH" ||columnInfo.shi === "OUT" ||columnInfo.shi === null )) {
+ if (columnInfo && (columnInfo.shi === "BOTH" || columnInfo.shi === "OUT" || columnInfo.shi === null)) {
if (existingTag.data[key] !== tagObject[key]) {
updates[key] = tagObject[key];
hasUpdates = true;