품목 API 업데이트
This commit is contained in:
@@ -21,6 +21,7 @@ import com.pms.api.CustomerApiClient;
|
||||
import com.pms.api.DepartmentApiClient;
|
||||
import com.pms.api.EmployeeApiClient;
|
||||
import com.pms.api.WarehouseApiClient;
|
||||
import com.pms.api.PartErpApiClient;
|
||||
import com.pms.common.Message;
|
||||
import com.pms.common.SqlMapConfig;
|
||||
import com.pms.common.bean.PersonBean;
|
||||
@@ -980,6 +981,225 @@ public class BatchService extends BaseService {
|
||||
|
||||
return warehouse;
|
||||
}
|
||||
|
||||
/**
|
||||
* 전체 PART 정보를 ERP로 전송 (수동 실행)
|
||||
* @return 성공 여부 Map
|
||||
*/
|
||||
public Map<String, Object> sendAllPartsToErp() {
|
||||
Map<String, Object> result = new HashMap<String, Object>();
|
||||
SqlSession sqlSession = SqlMapConfig.getInstance().getSqlSession(false);
|
||||
|
||||
System.out.println("====================================");
|
||||
System.out.println("전체 PART 정보 ERP 전송 시작");
|
||||
System.out.println("====================================");
|
||||
|
||||
try {
|
||||
String baseUrl = "https://erp.rps-korea.com";
|
||||
|
||||
// DB에서 전체 PART 목록 조회
|
||||
List<Map<String, Object>> partList = sqlSession.selectList("part.selectAllPartListForErp");
|
||||
|
||||
if (partList == null || partList.isEmpty()) {
|
||||
result.put("success", false);
|
||||
result.put("message", "전송할 PART 정보가 없습니다.");
|
||||
return result;
|
||||
}
|
||||
|
||||
PartErpApiClient partErpClient = new PartErpApiClient();
|
||||
int successCount = 0;
|
||||
int failCount = 0;
|
||||
StringBuilder errorMessages = new StringBuilder();
|
||||
|
||||
System.out.println("총 " + partList.size() + "건의 PART를 ERP로 전송합니다...");
|
||||
|
||||
for (int i = 0; i < partList.size(); i++) {
|
||||
Map<String, Object> part = partList.get(i);
|
||||
try {
|
||||
// DB에서 가져온 값
|
||||
String itemCd = CommonUtils.checkNull(part.get("part_no"));
|
||||
String itemNm = CommonUtils.checkNull(part.get("part_name"));
|
||||
String acctFg = CommonUtils.checkNull(part.get("acctfg"));
|
||||
String odrFg = CommonUtils.checkNull(part.get("odrfg"));
|
||||
|
||||
// 하드코딩 고정값
|
||||
String coCd = "1000"; // 회사코드
|
||||
String unitDc = "1"; // 단위
|
||||
String unitmangDc = "1"; // 단위관리
|
||||
int unitchngNb = 1; // 단위변환
|
||||
String lotFg = "0"; // LOT구분
|
||||
String qcFg = "0"; // 검사구분
|
||||
String reqFg = "0"; // 청구구분
|
||||
String setitemFg = "0"; // 세트품목구분
|
||||
String useYn = "1"; // 사용여부
|
||||
|
||||
// 필수값 체크
|
||||
if (itemCd.isEmpty() || itemNm.isEmpty()) {
|
||||
failCount++;
|
||||
continue;
|
||||
}
|
||||
|
||||
// 진행 상황 로그 (100건마다)
|
||||
if ((i + 1) % 100 == 0) {
|
||||
System.out.println("진행 중... " + (i + 1) + "/" + partList.size() + " (성공: " + successCount + ", 실패: " + failCount + ")");
|
||||
}
|
||||
|
||||
// ERP로 전송
|
||||
String response = partErpClient.sendPartToErp(baseUrl, coCd, itemCd, itemNm,
|
||||
acctFg, odrFg, unitDc, unitmangDc, unitchngNb, lotFg, qcFg, reqFg, setitemFg, useYn);
|
||||
|
||||
// 응답 확인
|
||||
if (response.contains("\"resultCode\":0") || response.contains("\"resultCode\":\"0\"")) {
|
||||
successCount++;
|
||||
} else {
|
||||
failCount++;
|
||||
if (failCount <= 5) {
|
||||
errorMessages.append(itemCd).append(": ").append(response).append("\n");
|
||||
}
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
failCount++;
|
||||
if (failCount <= 5) {
|
||||
errorMessages.append(CommonUtils.checkNull(part.get("part_no"))).append(": ")
|
||||
.append(e.getMessage()).append("\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
result.put("success", true);
|
||||
result.put("message", "PART 전송 완료 - 성공: " + successCount + "건, 실패: " + failCount + "건");
|
||||
if (errorMessages.length() > 0) {
|
||||
result.put("errors", errorMessages.toString());
|
||||
}
|
||||
|
||||
System.out.println("====================================");
|
||||
System.out.println("PART 전송 완료 - 성공: " + successCount + "건, 실패: " + failCount + "건");
|
||||
System.out.println("====================================");
|
||||
|
||||
} catch (Exception e) {
|
||||
result.put("success", false);
|
||||
result.put("message", "PART 전송 중 오류가 발생했습니다: " + e.getMessage());
|
||||
System.err.println("PART 전송 오류: " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
sqlSession.close();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 단일 PART 정보를 ERP로 전송
|
||||
* @param partObjid PART OBJID
|
||||
* @return 성공 여부 Map
|
||||
*/
|
||||
public Map<String, Object> sendSinglePartToErp(String partObjid) {
|
||||
Map<String, Object> result = new HashMap<String, Object>();
|
||||
SqlSession sqlSession = SqlMapConfig.getInstance().getSqlSession(false);
|
||||
|
||||
try {
|
||||
String baseUrl = "https://erp.rps-korea.com";
|
||||
|
||||
// DB에서 PART 정보 조회
|
||||
Map<String, Object> paramMap = new HashMap<String, Object>();
|
||||
paramMap.put("objid", partObjid);
|
||||
Map<String, Object> part = sqlSession.selectOne("part.selectPartByObjid", paramMap);
|
||||
|
||||
if (part == null) {
|
||||
result.put("success", false);
|
||||
result.put("message", "PART 정보를 찾을 수 없습니다.");
|
||||
return result;
|
||||
}
|
||||
|
||||
// DB에서 가져온 값
|
||||
String itemCd = CommonUtils.checkNull(part.get("part_no"));
|
||||
String itemNm = CommonUtils.checkNull(part.get("part_name"));
|
||||
String acctFg = CommonUtils.checkNull(part.get("acctfg"));
|
||||
String odrFg = CommonUtils.checkNull(part.get("odrfg"));
|
||||
|
||||
// 하드코딩 고정값
|
||||
String coCd = "1000"; // 회사코드
|
||||
String unitDc = "1"; // 단위
|
||||
String unitmangDc = "1"; // 단위관리
|
||||
int unitchngNb = 1; // 단위변환
|
||||
String lotFg = "0"; // LOT구분
|
||||
String qcFg = "0"; // 검사구분
|
||||
String reqFg = "0"; // 청구구분
|
||||
String setitemFg = "0"; // 세트품목구분
|
||||
String useYn = "1"; // 사용여부
|
||||
|
||||
// 필수값 체크
|
||||
if (itemCd.isEmpty() || itemNm.isEmpty()) {
|
||||
result.put("success", false);
|
||||
result.put("message", "품번 또는 품명이 없습니다.");
|
||||
return result;
|
||||
}
|
||||
|
||||
// ERP로 전송
|
||||
PartErpApiClient partErpClient = new PartErpApiClient();
|
||||
String response = partErpClient.sendPartToErp(baseUrl, coCd, itemCd, itemNm,
|
||||
acctFg, odrFg, unitDc, unitmangDc, unitchngNb, lotFg, qcFg, reqFg, setitemFg, useYn);
|
||||
|
||||
// 응답 확인
|
||||
if (response.contains("\"resultCode\":0") || response.contains("\"resultCode\":\"0\"")) {
|
||||
result.put("success", true);
|
||||
result.put("message", "PART 정보가 ERP로 전송되었습니다.");
|
||||
} else {
|
||||
result.put("success", false);
|
||||
result.put("message", "ERP 전송 실패: " + response);
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
result.put("success", false);
|
||||
result.put("message", "PART 전송 중 오류가 발생했습니다: " + e.getMessage());
|
||||
System.err.println("PART 전송 오류: " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
sqlSession.close();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* major_category를 acctFg로 변환
|
||||
* 0:원재료,1:부재료,2:제품,4:반제품,5:상품,6:저장품,7:비용,8:수익
|
||||
*/
|
||||
private String convertAcctFg(String majorCategory) {
|
||||
if (majorCategory == null || majorCategory.isEmpty()) {
|
||||
return "7"; // 기본값: 비용
|
||||
}
|
||||
|
||||
// major_category 값에 따라 매핑
|
||||
if (majorCategory.contains("원재료")) return "0";
|
||||
if (majorCategory.contains("부재료")) return "1";
|
||||
if (majorCategory.contains("제품")) return "2";
|
||||
if (majorCategory.contains("반제품")) return "4";
|
||||
if (majorCategory.contains("상품")) return "5";
|
||||
if (majorCategory.contains("저장품")) return "6";
|
||||
if (majorCategory.contains("비용")) return "7";
|
||||
if (majorCategory.contains("수익")) return "8";
|
||||
|
||||
return "7"; // 기본값: 비용
|
||||
}
|
||||
|
||||
/**
|
||||
* sub_category를 odrFg로 변환
|
||||
* 0:구매,1:생산,8:Phantom
|
||||
*/
|
||||
private String convertOdrFg(String subCategory) {
|
||||
if (subCategory == null || subCategory.isEmpty()) {
|
||||
return "0"; // 기본값: 구매
|
||||
}
|
||||
|
||||
// sub_category 값에 따라 매핑
|
||||
if (subCategory.contains("구매")) return "0";
|
||||
if (subCategory.contains("생산")) return "1";
|
||||
if (subCategory.contains("Phantom") || subCategory.contains("phantom")) return "8";
|
||||
|
||||
return "0"; // 기본값: 구매
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user