[agent-pipeline] pipe-20260327131904-jedw round-2

This commit is contained in:
DDD1542
2026-03-27 23:23:52 +09:00
parent 65ad32ca75
commit c73628e57a
93 changed files with 2561 additions and 2148 deletions
@@ -1,6 +1,6 @@
package com.erp.service;
import com.erp.mapper.TableManagementMapper;
import com.erp.common.BaseService;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
@@ -13,24 +13,25 @@ import java.util.stream.Collectors;
/**
* 테이블 관리 서비스.
* - 정적 메타데이터 쿼리 → TableManagementMapper (MyBatis XML)
* - 정적 메타데이터 쿼리 → sqlSession (MyBatis XML)
* - 동적 테이블 CRUD (임의 테이블/컬럼) → JdbcTemplate (런타임 SQL 빌드 불가피)
*/
@Service
@RequiredArgsConstructor
@Slf4j
public class TableManagementService {
public class TableManagementService extends BaseService {
private final TableManagementMapper tableManagementMapper;
private final JdbcTemplate jdbcTemplate;
private final ObjectMapper objectMapper;
private static final String NS = "com.erp.mapper.TableManagementMapper.";
// ──────────────────────────────────────────────────
// 테이블 목록
// ──────────────────────────────────────────────────
public List<Map<String, Object>> getTableList() {
List<Map<String, Object>> tables = tableManagementMapper.getTableList();
List<Map<String, Object>> tables = sqlSession.selectList(NS + "getTableList");
// columnCount BigInt → Integer 변환
for (Map<String, Object> t : tables) {
Object cnt = t.get("columnCount");
@@ -49,14 +50,15 @@ public class TableManagementService {
params.put("size", size);
params.put("offset", (long) (page - 1) * size);
int total = tableManagementMapper.getColumnListCnt(params);
Integer totalObj = sqlSession.selectOne(NS + "getColumnListCnt", params);
int total = totalObj != null ? totalObj : 0;
List<Map<String, Object>> columns;
if (companyCode != null && !companyCode.isBlank()) {
params.put("companyCode", companyCode);
columns = tableManagementMapper.getColumnListWithCompany(params);
columns = sqlSession.selectList(NS + "getColumnListWithCompany", params);
} else {
columns = tableManagementMapper.getColumnList(params);
columns = sqlSession.selectList(NS + "getColumnList", params);
}
int totalPages = total == 0 ? 1 : (int) Math.ceil((double) total / size);
@@ -76,13 +78,13 @@ public class TableManagementService {
public List<Map<String, Object>> getTableSchema(String tableName) {
Map<String, Object> params = new HashMap<>();
params.put("tableName", tableName);
return tableManagementMapper.getTableSchemaList(params);
return sqlSession.selectList(NS + "getTableSchemaList", params);
}
public boolean checkTableExists(String tableName) {
Map<String, Object> params = new HashMap<>();
params.put("tableName", tableName);
Map<String, Object> result = tableManagementMapper.checkTableExists(params);
Map<String, Object> result = sqlSession.selectOne(NS + "checkTableExists", params);
Object exists = result != null ? result.get("exists") : null;
return Boolean.TRUE.equals(exists);
}
@@ -91,7 +93,8 @@ public class TableManagementService {
Map<String, Object> params = new HashMap<>();
params.put("tableName", sanitize(tableName));
params.put("columnName", sanitize(columnName));
return tableManagementMapper.checkTableHasColumn(params) > 0;
Integer cntObj = sqlSession.selectOne(NS + "checkTableHasColumn", params);
return cntObj != null && cntObj > 0;
}
// ──────────────────────────────────────────────────
@@ -101,7 +104,7 @@ public class TableManagementService {
public Map<String, Object> getTableLabels(String tableName) {
Map<String, Object> params = new HashMap<>();
params.put("tableName", tableName);
return tableManagementMapper.getTableLabelInfo(params);
return sqlSession.selectOne(NS + "getTableLabelInfo", params);
}
@Transactional
@@ -110,14 +113,14 @@ public class TableManagementService {
params.put("tableName", tableName);
params.put("displayName", displayName);
params.put("description", description != null ? description : "");
tableManagementMapper.upsertTableLabel(params);
sqlSession.update(NS + "upsertTableLabel", params);
log.info("테이블 라벨 업데이트: {}", tableName);
}
private void ensureTableInLabels(String tableName) {
Map<String, Object> params = new HashMap<>();
params.put("tableName", tableName);
tableManagementMapper.insertTableLabelIfNotExists(params);
sqlSession.insert(NS + "insertTableLabelIfNotExists", params);
}
// ──────────────────────────────────────────────────
@@ -128,7 +131,7 @@ public class TableManagementService {
Map<String, Object> params = new HashMap<>();
params.put("tableName", tableName);
params.put("columnName", columnName);
return tableManagementMapper.getColumnLabelInfo(params);
return sqlSession.selectOne(NS + "getColumnLabelInfo", params);
}
// ──────────────────────────────────────────────────
@@ -156,7 +159,7 @@ public class TableManagementService {
params.put("isVisible", settings.getOrDefault("isVisible", true));
params.put("companyCode", companyCode);
params.put("categoryRef", "category".equals(inputType) ? settings.get("categoryRef") : null);
tableManagementMapper.upsertColumnSettings(params);
sqlSession.update(NS + "upsertColumnSettings", params);
// 화면 레이아웃 동기화
syncScreenLayouts(tableName, columnName, inputType, companyCode);
@@ -189,7 +192,7 @@ public class TableManagementService {
params.put("clearEntity", false);
params.put("clearCode", false);
params.put("clearCategory", false);
tableManagementMapper.upsertColumnInputType(params);
sqlSession.update(NS + "upsertColumnInputType", params);
log.info("컬럼 웹타입 설정: {}.{} = {}", tableName, columnName, finalType);
}
@@ -207,7 +210,7 @@ public class TableManagementService {
params.put("clearEntity", !"entity".equals(finalType));
params.put("clearCode", !"code".equals(finalType));
params.put("clearCategory", !"category".equals(finalType));
tableManagementMapper.upsertColumnInputType(params);
sqlSession.update(NS + "upsertColumnInputType", params);
syncScreenLayouts(tableName, columnName, finalType, companyCode);
log.info("컬럼 입력타입 설정: {}.{} = {}, company={}", tableName, columnName, finalType, companyCode);
}
@@ -216,7 +219,7 @@ public class TableManagementService {
Map<String, Object> params = new HashMap<>();
params.put("tableName", tableName);
params.put("companyCode", companyCode);
return tableManagementMapper.getColumnInputTypeList(params);
return sqlSession.selectList(NS + "getColumnInputTypeList", params);
}
// ──────────────────────────────────────────────────
@@ -227,7 +230,7 @@ public class TableManagementService {
Map<String, Object> params = new HashMap<>();
params.put("tableName", tableName);
List<Map<String, Object>> pkResult = tableManagementMapper.getTablePrimaryKeyList(params);
List<Map<String, Object>> pkResult = sqlSession.selectList(NS + "getTablePrimaryKeyList", params);
Map<String, Object> primaryKey = new HashMap<>();
if (!pkResult.isEmpty()) {
Map<String, Object> pk = pkResult.get(0);
@@ -238,7 +241,7 @@ public class TableManagementService {
primaryKey.put("columns", List.of());
}
List<Map<String, Object>> indexResult = tableManagementMapper.getTableIndexList(params);
List<Map<String, Object>> indexResult = sqlSession.selectList(NS + "getTableIndexList", params);
List<Map<String, Object>> indexes = indexResult.stream().map(row -> {
Map<String, Object> idx = new HashMap<>();
idx.put("name", row.get("indexName"));
@@ -259,7 +262,7 @@ public class TableManagementService {
// 기존 PK 삭제
Map<String, Object> params = new HashMap<>();
params.put("tableName", safeTable);
List<Map<String, Object>> existingPk = tableManagementMapper.getTablePrimaryKeyList(params);
List<Map<String, Object>> existingPk = sqlSession.selectList(NS + "getTablePrimaryKeyList", params);
if (!existingPk.isEmpty()) {
String constraintName = (String) existingPk.get(0).get("constraintName");
jdbcTemplate.execute(
@@ -310,7 +313,7 @@ public class TableManagementService {
params.put("columnName", columnName);
params.put("isNullable", nullable ? "Y" : "N");
params.put("companyCode", companyCode);
tableManagementMapper.upsertNullable(params);
sqlSession.update(NS + "upsertNullable", params);
log.info("NOT NULL 토글: {}.{} nullable={}, company={}", tableName, columnName, nullable, companyCode);
}
@@ -322,7 +325,7 @@ public class TableManagementService {
params.put("columnName", columnName);
params.put("isUnique", unique ? "Y" : "N");
params.put("companyCode", companyCode);
tableManagementMapper.upsertUnique(params);
sqlSession.update(NS + "upsertUnique", params);
log.info("UNIQUE 토글: {}.{} unique={}, company={}", tableName, columnName, unique, companyCode);
}
@@ -336,7 +339,7 @@ public class TableManagementService {
Map<String, Object> params = new HashMap<>();
params.put("tableName", tableName);
params.put("companyCode", companyCode);
List<Map<String, Object>> notNullCols = tableManagementMapper.getNotNullColumnList(params);
List<Map<String, Object>> notNullCols = sqlSession.selectList(NS + "getNotNullColumnList", params);
List<String> violations = new ArrayList<>();
for (Map<String, Object> col : notNullCols) {
@@ -356,7 +359,7 @@ public class TableManagementService {
Map<String, Object> params = new HashMap<>();
params.put("tableName", tableName);
params.put("companyCode", companyCode);
List<Map<String, Object>> uniqueCols = tableManagementMapper.getUniqueColumnList(params);
List<Map<String, Object>> uniqueCols = sqlSession.selectList(NS + "getUniqueColumnList", params);
String safeTable = sanitize(tableName);
List<String> violations = new ArrayList<>();
@@ -630,7 +633,7 @@ public class TableManagementService {
params.put("tableName", tableName);
params.put("isActive", isActive);
params.put("logColumns", String.join(",", targetCols));
tableManagementMapper.upsertLogConfig(params);
sqlSession.update(NS + "upsertLogConfig", params);
log.info("로그 테이블 생성: {}", safeLog);
}
@@ -638,7 +641,7 @@ public class TableManagementService {
public Map<String, Object> getLogConfig(String tableName) {
Map<String, Object> params = new HashMap<>();
params.put("tableName", tableName);
return tableManagementMapper.getLogConfigInfo(params);
return sqlSession.selectOne(NS + "getLogConfigInfo", params);
}
public Map<String, Object> getLogData(String tableName, int page, int size) {
@@ -672,7 +675,7 @@ public class TableManagementService {
params.put("tableName", tableName);
params.put("isActive", isActive);
params.put("logColumns", "");
tableManagementMapper.upsertLogConfig(params);
sqlSession.update(NS + "upsertLogConfig", params);
log.info("로그 테이블 토글: {} → {}", tableName, isActive);
}
@@ -682,7 +685,7 @@ public class TableManagementService {
public Map<String, Object> checkDatabaseConnection() {
try {
tableManagementMapper.checkDatabaseConnection();
sqlSession.selectOne(NS + "checkDatabaseConnection", null);
return Map.of("connected", true, "message", "데이터베이스 연결 정상");
} catch (Exception e) {
log.error("DB 연결 실패", e);
@@ -697,20 +700,20 @@ public class TableManagementService {
public List<Map<String, Object>> getCategoryColumnsByCompany(String companyCode) {
Map<String, Object> params = new HashMap<>();
params.put("companyCode", companyCode);
return tableManagementMapper.getCategoryColumnListByCompany(params);
return sqlSession.selectList(NS + "getCategoryColumnListByCompany", params);
}
public List<Map<String, Object>> getNumberingColumnsByCompany(String companyCode) {
Map<String, Object> params = new HashMap<>();
params.put("companyCode", companyCode);
return tableManagementMapper.getNumberingColumnListByCompany(params);
return sqlSession.selectList(NS + "getNumberingColumnListByCompany", params);
}
public List<Map<String, Object>> getCategoryColumnsByMenu(String companyCode, Object menuObjid) {
Map<String, Object> params = new HashMap<>();
params.put("companyCode", companyCode);
params.put("menuObjid", menuObjid);
return tableManagementMapper.getCategoryColumnListByMenu(params);
return sqlSession.selectList(NS + "getCategoryColumnListByMenu", params);
}
// ──────────────────────────────────────────────────
@@ -723,7 +726,7 @@ public class TableManagementService {
params.put("leftTable", leftTable);
params.put("rightTable", rightTable);
params.put("companyCode", companyCode);
List<Map<String, Object>> relations = tableManagementMapper.getEntityRelationList(params);
List<Map<String, Object>> relations = sqlSession.selectList(NS + "getEntityRelationList", params);
Map<String, Object> result = new HashMap<>();
result.put("leftTable", leftTable);
result.put("rightTable", rightTable);
@@ -735,7 +738,7 @@ public class TableManagementService {
Map<String, Object> params = new HashMap<>();
params.put("tableName", tableName);
params.put("companyCode", companyCode);
return tableManagementMapper.getReferencedByTableList(params);
return sqlSession.selectList(NS + "getReferencedByTableList", params);
}
// ──────────────────────────────────────────────────
@@ -895,7 +898,7 @@ public class TableManagementService {
p.put("inputType", inputType);
p.put("companyCode", companyCode);
p.put("componentId", mapInputTypeToComponentId(inputType));
tableManagementMapper.syncScreenLayoutsInputType(p);
sqlSession.update(NS + "syncScreenLayoutsInputType", p);
} catch (Exception e) {
log.warn("화면 레이아웃 동기화 실패 (무시됨): {}.{}", tableName, columnName);
}