커밋 APi 수정

This commit is contained in:
2026-02-10 15:26:26 +09:00
parent 2a838f3ce9
commit 4430040035
18 changed files with 1442 additions and 20 deletions

View File

@@ -24,6 +24,7 @@ import com.pms.api.WarehouseApiClient;
import com.pms.api.PartErpApiClient;
import com.pms.api.PartErpDeleteApiClient;
import com.pms.api.PartErpUpdateApiClient;
import com.pms.api.AmaranthUserApiClient;
import com.pms.common.Message;
import com.pms.common.SqlMapConfig;
import com.pms.common.bean.PersonBean;
@@ -184,6 +185,78 @@ public class BatchService extends BaseService {
executeSyncErpData();
}
/**
* LoginId 업데이트 자동 배치 (매일 새벽 00시 10분 실행)
* ERP 사원 동기화 이후 실행되어 Amaranth10 loginId를 user_info.user_id에 업데이트
*/
@Scheduled(cron="0 10 0 * * ?")
public void updateLoginIdAuto() {
System.out.println("====================================");
System.out.println("LoginId 업데이트 배치 시작 (자동)");
System.out.println("====================================");
SqlSession sqlSession = SqlMapConfig.getInstance().getSqlSession(false);
try {
String baseUrl = "https://erp.rps-korea.com";
// Amaranth10 API로 전체 사용자 정보 조회 (empSeq, loginId)
AmaranthUserApiClient apiClient = new AmaranthUserApiClient();
String jsonResponse = apiClient.getAllUserInfo(baseUrl);
// JSON 파싱
List<Map<String, Object>> amaranthUserList = parseAmaranthUserJson(jsonResponse);
if (amaranthUserList == null || amaranthUserList.isEmpty()) {
System.out.println("API 응답에서 사용자 정보를 찾을 수 없습니다.");
return;
}
System.out.println("" + amaranthUserList.size() + "건의 사용자 정보 처리 시작");
int updateCount = 0;
int skipCount = 0;
// empseq 기준으로 user_id 업데이트
for (Map<String, Object> amaranthUser : amaranthUserList) {
String empSeq = (String) amaranthUser.get("empSeq");
String loginId = (String) amaranthUser.get("loginId");
if (empSeq != null && !empSeq.isEmpty() && loginId != null && !loginId.isEmpty()) {
Map<String, Object> updateParam = new HashMap<String, Object>();
updateParam.put("empseq", empSeq);
updateParam.put("login_id", loginId);
int updated = sqlSession.update("batch.updateLoginId", updateParam);
if (updated > 0) {
updateCount++;
if (updateCount <= 10) {
System.out.println("[업데이트 " + updateCount + "] empseq: " + empSeq + " → loginId: " + loginId);
}
} else {
skipCount++;
}
} else {
skipCount++;
}
}
sqlSession.commit();
System.out.println("====================================");
System.out.println("LoginId 업데이트 완료 (자동)");
System.out.println("업데이트: " + updateCount + "");
System.out.println("스킵: " + skipCount + "");
System.out.println("====================================");
} catch (Exception e) {
sqlSession.rollback();
System.err.println("LoginId 업데이트 오류 (자동): " + e.getMessage());
e.printStackTrace();
} finally {
sqlSession.close();
}
}
/**
* 사원 정보만 동기화 (수동 실행)
* @return 성공 여부 Map
@@ -219,6 +292,198 @@ public class BatchService extends BaseService {
return result;
}
/**
* LoginId 업데이트 전용 배치 (수동 실행)
* Amaranth10 API로 전체 사용자 정보를 조회하여 empseq 기준으로 user_id 업데이트
* @return 성공 여부 Map
*/
public Map<String, Object> updateLoginIdManual() {
Map<String, Object> result = new HashMap<String, Object>();
SqlSession sqlSession = SqlMapConfig.getInstance().getSqlSession(false);
System.out.println("====================================");
System.out.println("LoginId 업데이트 배치 시작 (수동)");
System.out.println("====================================");
try {
String baseUrl = "https://erp.rps-korea.com";
// Amaranth10 API로 전체 사용자 정보 조회 (empSeq, loginId)
// 파라미터 없이 전체 조회
AmaranthUserApiClient apiClient = new AmaranthUserApiClient();
String jsonResponse = apiClient.getAllUserInfo(baseUrl);
// JSON 파싱
List<Map<String, Object>> amaranthUserList = parseAmaranthUserJson(jsonResponse);
if (amaranthUserList == null || amaranthUserList.isEmpty()) {
result.put("success", false);
result.put("message", "Amaranth10 API에서 사용자 정보를 가져올 수 없습니다.");
System.out.println("API 응답에서 사용자 정보를 찾을 수 없습니다.");
return result;
}
System.out.println("" + amaranthUserList.size() + "건의 사용자 정보 처리 시작");
int updateCount = 0;
int skipCount = 0;
// empseq 기준으로 user_id 업데이트
for (Map<String, Object> amaranthUser : amaranthUserList) {
String empSeq = (String) amaranthUser.get("empSeq");
String loginId = (String) amaranthUser.get("loginId");
if (empSeq != null && !empSeq.isEmpty() && loginId != null && !loginId.isEmpty()) {
Map<String, Object> updateParam = new HashMap<String, Object>();
updateParam.put("empseq", empSeq);
updateParam.put("login_id", loginId);
int updated = sqlSession.update("batch.updateLoginId", updateParam);
if (updated > 0) {
updateCount++;
if (updateCount <= 10) {
System.out.println("[업데이트 " + updateCount + "] empseq: " + empSeq + " → loginId: " + loginId);
}
} else {
skipCount++;
}
} else {
skipCount++;
}
}
sqlSession.commit();
result.put("success", true);
result.put("message", "LoginId 업데이트가 완료되었습니다. (업데이트: " + updateCount + "건, 스킵: " + skipCount + "건)");
System.out.println("====================================");
System.out.println("LoginId 업데이트 완료");
System.out.println("업데이트: " + updateCount + "");
System.out.println("스킵: " + skipCount + "");
System.out.println("====================================");
} catch (Exception e) {
sqlSession.rollback();
result.put("success", false);
result.put("message", "LoginId 업데이트 중 오류가 발생했습니다: " + e.getMessage());
System.err.println("LoginId 업데이트 오류: " + e.getMessage());
e.printStackTrace();
} finally {
sqlSession.close();
}
return result;
}
/**
* Amaranth10 사용자 정보 JSON 파싱
* resultData 배열에서 직접 empSeq, loginId 추출
*/
private List<Map<String, Object>> parseAmaranthUserJson(String jsonResponse) {
List<Map<String, Object>> userList = new ArrayList<Map<String, Object>>();
try {
// resultData 배열 추출
int resultDataStart = jsonResponse.indexOf("\"resultData\"");
if (resultDataStart == -1) {
System.err.println("resultData를 찾을 수 없습니다.");
return userList;
}
int arrayStart = jsonResponse.indexOf("[", resultDataStart);
if (arrayStart == -1) {
System.err.println("resultData 배열을 찾을 수 없습니다.");
return userList;
}
// 매칭되는 닫는 괄호 찾기
int arrayEnd = findMatchingBracket(jsonResponse, arrayStart);
if (arrayEnd == -1) {
System.err.println("resultData 배열의 끝을 찾을 수 없습니다.");
return userList;
}
String arrayContent = jsonResponse.substring(arrayStart + 1, arrayEnd);
// resultData 배열의 각 사용자 객체 파싱
int braceCount = 0;
int objStart = -1;
for (int i = 0; i < arrayContent.length(); i++) {
char c = arrayContent.charAt(i);
if (c == '{') {
if (braceCount == 0) {
objStart = i;
}
braceCount++;
} else if (c == '}') {
braceCount--;
if (braceCount == 0 && objStart != -1) {
String objStr = arrayContent.substring(objStart, i + 1);
Map<String, Object> user = parseAmaranthUserObject(objStr);
if (user != null && user.get("empSeq") != null && user.get("loginId") != null) {
userList.add(user);
}
objStart = -1;
}
}
}
System.out.println("파싱된 사용자 수: " + userList.size());
} catch (Exception e) {
System.err.println("Amaranth 사용자 JSON 파싱 오류: " + e.getMessage());
e.printStackTrace();
}
return userList;
}
/**
* Amaranth10 사용자 객체 파싱
*/
private Map<String, Object> parseAmaranthUserObject(String jsonObject) {
Map<String, Object> user = new HashMap<String, Object>();
try {
// empSeq 추출
String empSeq = extractJsonValue(jsonObject, "empSeq");
if (empSeq != null && !empSeq.isEmpty()) {
user.put("empSeq", empSeq);
}
// loginId 추출
String loginId = extractJsonValue(jsonObject, "loginId");
if (loginId != null && !loginId.isEmpty()) {
user.put("loginId", loginId);
}
} catch (Exception e) {
System.err.println("Amaranth 사용자 객체 파싱 오류: " + e.getMessage());
return null;
}
return user;
}
/**
* 매칭되는 괄호 찾기
*/
private int findMatchingBracket(String str, int startIndex) {
int count = 1;
for (int i = startIndex + 1; i < str.length(); i++) {
if (str.charAt(i) == '[') {
count++;
} else if (str.charAt(i) == ']') {
count--;
if (count == 0) {
return i;
}
}
}
return -1;
}
/**
* 부서 정보만 동기화 (수동 실행)
* @return 성공 여부 Map
@@ -826,7 +1091,8 @@ public class BatchService extends BaseService {
// JSON 필드 → user_info 테이블 컬럼 매핑
emp.put("sabun", extractJsonValue(json, "empCd")); // 사번 (empCd)
emp.put("user_id", extractJsonValue(json, "empCd")); // 사용자ID (empCd)
emp.put("empseq", extractJsonValue(json, "empSeq")); // 사원 시퀀스 (empSeq) - Amaranth10 전자결재용
// user_id는 별도 LoginId 업데이트 배치에서 처리 (Amaranth10 API 사용)
emp.put("user_password", "5715e7d798fd421c7100c435e7547e82"); // 기본 비밀번호 (MD5 해시)
emp.put("user_name", extractJsonValue(json, "korNm")); // 사용자명 (korNm)
emp.put("user_name_eng", extractJsonValue(json, "enlsNm")); // 영문명 (enlsNm)
@@ -838,11 +1104,11 @@ public class BatchService extends BaseService {
emp.put("email", extractJsonValue(json, "emalAdd")); // 이메일 (emalAdd)
emp.put("cell_phone", extractJsonValue(json, "emgcTel")); // 휴대폰 (emgcTel)
emp.put("user_type", extractJsonValue(json, "enrlFg")); // 사용자유형 (enrlFg - J01:재직)
emp.put("(주)RPS", extractJsonValue(json, "enrlNm")); // 사용자유형명 (enrlNm)
emp.put("user_type_name", extractJsonValue(json, "enrlNm")); // 사용자유형명 (enrlNm)
// 재직구분에 따른 상태 설정 (J01:재직=active, 그 외=inactive)
// 재직구분에 따른 상태 설정 (J01:재직=active, 그 외=inActive)
String enrlFg = extractJsonValue(json, "enrlFg");
emp.put("status", "J01".equals(enrlFg) ? "active" : "inactive"); // 상태
emp.put("status", "J01".equals(enrlFg) ? "active" : "inActive"); // 상태
// 퇴직일자 (rtrDt)
emp.put("end_date", extractJsonValue(json, "rtrDt")); // 종료일 (퇴직일)