summaryrefslogtreecommitdiff
path: root/lib/forms
diff options
context:
space:
mode:
authordujinkim <dujin.kim@dtsolution.co.kr>2025-07-28 11:44:16 +0000
committerdujinkim <dujin.kim@dtsolution.co.kr>2025-07-28 11:44:16 +0000
commitc228a89c2834ee63b209bad608837c39643f350e (patch)
tree39c9a121b556af872072dd80750dedf2d2d62335 /lib/forms
parent50ae0b8f02c034e60d4cbb504620dfa1575a836f (diff)
(대표님) 의존성 docx 추가, basicContract API, gtc(계약일반조건), 벤더평가 esg 평가데이터 내보내기 개선, S-EDP 피드백 대응(CLS_ID, ITEM NO 등)
Diffstat (limited to 'lib/forms')
-rw-r--r--lib/forms/services.ts60
1 files changed, 60 insertions, 0 deletions
diff --git a/lib/forms/services.ts b/lib/forms/services.ts
index 02333095..b517ff18 100644
--- a/lib/forms/services.ts
+++ b/lib/forms/services.ts
@@ -1049,6 +1049,7 @@ interface SEDPAttribute {
interface SEDPDataItem {
TAG_NO: string;
TAG_DESC: string;
+ CLS_ID:string;
ATTRIBUTES: SEDPAttribute[];
SCOPE: string;
TOOLID: string;
@@ -1096,12 +1097,16 @@ async function transformDataToSEDPFormat(
// Cache for packageCode to avoid duplicate DB queries for same tag
const packageCodeCache = new Map<string, string>();
+ // Cache for tagClass code to avoid duplicate DB queries for same tag
+ const tagClassCodeCache = new Map<string, string>();
+
// Transform each row
const transformedItems = [];
for (const row of tableData) {
// Get packageCode for this specific tag
let packageCode = formCode; // fallback to formCode
+ let tagClassCode = ""; // for CLS_ID
if (row.TAG_NO && contractItemId) {
// Check cache first
@@ -1120,6 +1125,28 @@ async function transformDataToSEDPFormat(
});
if (tagResult) {
+ // Get tagClass code if tagClassId exists
+ if (tagResult.tagClassId) {
+ // Check tagClass cache first
+ if (tagClassCodeCache.has(cacheKey)) {
+ tagClassCode = tagClassCodeCache.get(cacheKey)!;
+ } else {
+ const tagClassResult = await db.query.tagClasses.findFirst({
+ where: eq(tagClasses.id, tagResult.tagClassId)
+ });
+
+ if (tagClassResult) {
+ tagClassCode = tagClassResult.code;
+ console.log(`Found tagClass code for tag ${row.TAG_NO}: ${tagClassCode}`);
+ } else {
+ console.warn(`No tagClass found for tagClassId: ${tagResult.tagClassId}`);
+ }
+
+ // Cache the tagClass code result
+ tagClassCodeCache.set(cacheKey, tagClassCode);
+ }
+ }
+
// Get the contract item
const contractItemResult = await db.query.contractItems.findFirst({
where: eq(contractItems.id, tagResult.contractItemId)
@@ -1152,6 +1179,38 @@ async function transformDataToSEDPFormat(
packageCodeCache.set(cacheKey, packageCode);
}
}
+
+ // Get tagClass code if not already retrieved above
+ if (!tagClassCode && tagClassCodeCache.has(cacheKey)) {
+ tagClassCode = tagClassCodeCache.get(cacheKey)!;
+ } else if (!tagClassCode) {
+ try {
+ const tagResult = await db.query.tags.findFirst({
+ where: and(
+ eq(tags.contractItemId, contractItemId),
+ eq(tags.tagNo, row.TAG_NO)
+ )
+ });
+
+ if (tagResult && tagResult.tagClassId) {
+ const tagClassResult = await db.query.tagClasses.findFirst({
+ where: eq(tagClasses.id, tagResult.tagClassId)
+ });
+
+ if (tagClassResult) {
+ tagClassCode = tagClassResult.code;
+ console.log(`Found tagClass code for tag ${row.TAG_NO}: ${tagClassCode}`);
+ }
+ }
+
+ // Cache the tagClass code result
+ tagClassCodeCache.set(cacheKey, tagClassCode);
+ } catch (error) {
+ console.error(`Error fetching tagClass code for tag ${row.TAG_NO}:`, error);
+ // Cache empty string as fallback
+ tagClassCodeCache.set(cacheKey, "");
+ }
+ }
}
// Create base SEDP item with required fields
@@ -1169,6 +1228,7 @@ async function transformDataToSEDPFormat(
CRTER_NO: designerNo,
CHGER_NO: designerNo,
TYPE: packageCode, // Use packageCode instead of formCode
+ CLS_ID: tagClassCode, // Add CLS_ID with tagClass code
PROJ_NO: projectNo,
REV_NO: "00",
CRTE_DTM: currentTimestamp,