배치 적용용
This commit is contained in:
@@ -20,6 +20,7 @@ import org.springframework.web.bind.annotation.RequestParam;
|
||||
import com.pms.api.CustomerApiClient;
|
||||
import com.pms.api.DepartmentApiClient;
|
||||
import com.pms.api.EmployeeApiClient;
|
||||
import com.pms.api.WarehouseApiClient;
|
||||
import com.pms.common.Message;
|
||||
import com.pms.common.SqlMapConfig;
|
||||
import com.pms.common.bean.PersonBean;
|
||||
@@ -285,6 +286,41 @@ public class BatchService extends BaseService {
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 창고 정보만 동기화 (수동 실행)
|
||||
* @return 성공 여부 Map
|
||||
*/
|
||||
public Map<String, Object> syncWarehouseDataManual() {
|
||||
Map<String, Object> result = new HashMap<String, Object>();
|
||||
SqlSession sqlSession = SqlMapConfig.getInstance().getSqlSession(false);
|
||||
|
||||
System.out.println("====================================");
|
||||
System.out.println("ERP 창고 정보 동기화 시작 (수동)");
|
||||
System.out.println("====================================");
|
||||
|
||||
try {
|
||||
String baseUrl = "https://erp.rps-korea.com";
|
||||
String coCd = "1000";
|
||||
|
||||
syncWarehouseData(sqlSession, baseUrl, coCd);
|
||||
|
||||
sqlSession.commit();
|
||||
result.put("success", true);
|
||||
result.put("message", "창고 정보 동기화가 완료되었습니다.");
|
||||
System.out.println("ERP 창고 정보 동기화 완료");
|
||||
} catch (Exception e) {
|
||||
sqlSession.rollback();
|
||||
result.put("success", false);
|
||||
result.put("message", "창고 정보 동기화 중 오류가 발생했습니다: " + e.getMessage());
|
||||
System.err.println("창고 정보 동기화 오류: " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
sqlSession.close();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* ERP 데이터 동기화 실제 실행 로직
|
||||
*/
|
||||
@@ -305,6 +341,9 @@ public class BatchService extends BaseService {
|
||||
// 3. 사원 정보 동기화
|
||||
syncEmployeeData(sqlSession, baseUrl, coCd);
|
||||
|
||||
// 4. 창고 정보 동기화
|
||||
syncWarehouseData(sqlSession, baseUrl, coCd);
|
||||
|
||||
sqlSession.commit();
|
||||
System.out.println("ERP 데이터 동기화 배치 완료");
|
||||
|
||||
@@ -458,6 +497,51 @@ public class BatchService extends BaseService {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 창고 정보 동기화
|
||||
*/
|
||||
private void syncWarehouseData(SqlSession sqlSession, String baseUrl, String coCd) {
|
||||
try {
|
||||
System.out.println("창고 정보 동기화 시작...");
|
||||
|
||||
WarehouseApiClient warehouseClient = new WarehouseApiClient();
|
||||
String jsonResponse = warehouseClient.getWarehouseList(baseUrl, coCd, "0");
|
||||
|
||||
// JSON 파싱 및 DB 저장
|
||||
List<Map<String, Object>> warehouseList = parseWarehouseJson(jsonResponse);
|
||||
|
||||
int processCount = 0;
|
||||
|
||||
// 처음 10건 로그 출력
|
||||
System.out.println("====================================");
|
||||
System.out.println("창고 데이터 샘플 (최대 10건)");
|
||||
System.out.println("====================================");
|
||||
|
||||
for (Map<String, Object> warehouse : warehouseList) {
|
||||
// 처음 10건만 로그 출력
|
||||
if (processCount < 10) {
|
||||
System.out.println("[창고 " + (processCount + 1) + "]");
|
||||
System.out.println(" - LOCATION_CODE: " + warehouse.get("location_code"));
|
||||
System.out.println(" - LOCATION_NAME: " + warehouse.get("location_name"));
|
||||
System.out.println(" - OUT_CODE: " + warehouse.get("out_code"));
|
||||
System.out.println(" - USE_STATUS: " + warehouse.get("use_status"));
|
||||
System.out.println("---");
|
||||
}
|
||||
|
||||
// UPSERT 실행
|
||||
sqlSession.insert("batch.upsertWarehouse", warehouse);
|
||||
processCount++;
|
||||
}
|
||||
|
||||
System.out.println("====================================");
|
||||
System.out.println("창고 정보 동기화 완료 - 처리: " + processCount + "건");
|
||||
|
||||
} catch (Exception e) {
|
||||
System.err.println("창고 정보 동기화 실패: " + e.getMessage());
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 거래처 JSON 파싱
|
||||
*/
|
||||
@@ -813,6 +897,89 @@ public class BatchService extends BaseService {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 창고 JSON 파싱
|
||||
*/
|
||||
private List<Map<String, Object>> parseWarehouseJson(String jsonResponse) {
|
||||
List<Map<String, Object>> warehouseList = new ArrayList<Map<String, Object>>();
|
||||
|
||||
try {
|
||||
// resultData 배열 찾기
|
||||
int dataStart = jsonResponse.indexOf("\"resultData\":[");
|
||||
if (dataStart == -1) {
|
||||
return warehouseList;
|
||||
}
|
||||
|
||||
String dataSection = jsonResponse.substring(dataStart + 14);
|
||||
int bracketCount = 0;
|
||||
int startIdx = -1;
|
||||
|
||||
for (int i = 0; i < dataSection.length(); i++) {
|
||||
char c = dataSection.charAt(i);
|
||||
|
||||
if (c == '{') {
|
||||
if (bracketCount == 0) {
|
||||
startIdx = i;
|
||||
}
|
||||
bracketCount++;
|
||||
} else if (c == '}') {
|
||||
bracketCount--;
|
||||
if (bracketCount == 0 && startIdx != -1) {
|
||||
String warehouseJson = dataSection.substring(startIdx, i + 1);
|
||||
Map<String, Object> warehouse = parseWarehouseObject(warehouseJson);
|
||||
if (warehouse != null) {
|
||||
warehouseList.add(warehouse);
|
||||
}
|
||||
startIdx = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
System.err.println("창고 JSON 파싱 오류: " + e.getMessage());
|
||||
}
|
||||
|
||||
return warehouseList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 창고 객체 파싱
|
||||
*/
|
||||
private Map<String, Object> parseWarehouseObject(String json) {
|
||||
Map<String, Object> warehouse = new HashMap<String, Object>();
|
||||
|
||||
// location_code를 objid에도 동일하게 저장
|
||||
String locationCode = extractJsonValue(json, "baselocCd");
|
||||
warehouse.put("objid", locationCode);
|
||||
warehouse.put("location_code", locationCode);
|
||||
|
||||
// 기본 정보
|
||||
warehouse.put("location_name", extractJsonValue(json, "baselocNm"));
|
||||
warehouse.put("location_description", extractJsonValue(json, "baselocDc"));
|
||||
warehouse.put("out_code", extractJsonValue(json, "outlocCd"));
|
||||
warehouse.put("out_co_name", extractJsonValue(json, "outlocNm"));
|
||||
|
||||
// 상태 정보
|
||||
String baselocFg = extractJsonValue(json, "baselocFg");
|
||||
warehouse.put("fit_status", baselocFg);
|
||||
|
||||
String useYn = extractJsonValue(json, "useYn");
|
||||
warehouse.put("available_status", useYn);
|
||||
warehouse.put("use_status", "1".equals(useYn) ? "Y" : "N");
|
||||
|
||||
// 추가 정보
|
||||
warehouse.put("base_loc_cd", extractJsonValue(json, "baselocCd"));
|
||||
warehouse.put("co_cd", extractJsonValue(json, "coCd"));
|
||||
warehouse.put("loc_nmk", extractJsonValue(json, "baselocNm"));
|
||||
warehouse.put("attr_nmk", extractJsonValue(json, "inlocNm"));
|
||||
|
||||
// 시스템 정보
|
||||
warehouse.put("insert_id", "batch_system");
|
||||
warehouse.put("writer", "batch_system");
|
||||
warehouse.put("status", "active");
|
||||
|
||||
return warehouse;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user