아마란스 결재 수정

This commit is contained in:
2026-02-24 16:42:53 +09:00
parent 7cc1a789ce
commit 72a001f533
2 changed files with 92 additions and 23 deletions

View File

@@ -10,6 +10,7 @@ import javax.servlet.http.HttpSession;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.session.SqlSession;
import org.json.simple.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -2044,8 +2045,9 @@ public class ApprovalService {
return "{\"resultCode\":\"SUCCESS\",\"resultMessage\":\"성공하였습니다.\"}";
}
String targetType = CommonUtils.checkNull(mappingInfo.get("target_type"));
String targetObjId = CommonUtils.checkNull(mappingInfo.get("target_objid"));
mappingInfo = CommonUtils.toUpperCaseMapKey(mappingInfo);
String targetType = CommonUtils.checkNull(mappingInfo.get("TARGET_TYPE"));
String targetObjId = CommonUtils.checkNull(mappingInfo.get("TARGET_OBJID"));
System.out.println("매핑 정보 - targetType: " + targetType + ", targetObjId: " + targetObjId);
@@ -2125,8 +2127,13 @@ public class ApprovalService {
* @param paramMap approkey, formId, docId, userId, empSeq 등
* @return 제목/본문 JSON
*/
@SuppressWarnings("unchecked")
public String getAmaranthApprovalContents(Map paramMap){
// Amaranth에서 approkey 또는 approKey 두 가지 형태로 전달될 수 있음
String approkey = CommonUtils.checkNull(paramMap.get("approkey"));
if(approkey.isEmpty()){
approkey = CommonUtils.checkNull(paramMap.get("approKey"));
}
String docId = CommonUtils.checkNull(paramMap.get("docId"));
System.out.println("=== Amaranth 결재 본문 조회 ===");
@@ -2143,18 +2150,21 @@ public class ApprovalService {
searchParam.put("approKey", approkey);
Map<String, Object> mappingInfo = sqlSession.selectOne("approval.selectAmaranthApprovalByApproKey", searchParam);
System.out.println("매핑 조회 결과: " + (mappingInfo != null ? mappingInfo : "null (매핑 없음)"));
String title = "결재 문서";
String contentsHtml = "<p>연동 데이터를 찾을 수 없습니다.</p>";
if(mappingInfo != null){
String targetType = CommonUtils.checkNull(mappingInfo.get("target_type"));
String targetObjId = CommonUtils.checkNull(mappingInfo.get("target_objid"));
title = CommonUtils.checkNull(mappingInfo.get("approval_title"), "결재 문서");
// DB 조회 결과의 키 대소문자에 관계없이 처리
mappingInfo = CommonUtils.toUpperCaseMapKey(mappingInfo);
String targetType = CommonUtils.checkNull(mappingInfo.get("TARGET_TYPE"));
String targetObjId = CommonUtils.checkNull(mappingInfo.get("TARGET_OBJID"));
title = CommonUtils.checkNull(mappingInfo.get("APPROVAL_TITLE"), "결재 문서");
System.out.println("매핑 정보 - targetType: " + targetType + ", targetObjId: " + targetObjId);
if("PROPOSAL".equals(targetType) && !targetObjId.isEmpty()){
// 품의서 데이터 조회
Map<String, Object> proposalParam = new HashMap();
proposalParam.put("PROPOSAL_OBJID", targetObjId);
Map<String, Object> proposalInfo = sqlSession.selectOne("salesMng.getProposalInfo", proposalParam);
@@ -2171,26 +2181,34 @@ public class ApprovalService {
}
}
// UTF-8 인코딩 처리 (contentsEnc=U 설정됨)
String encodedTitle = java.net.URLEncoder.encode(title, "UTF-8");
String encodedContents = java.net.URLEncoder.encode(contentsHtml, "UTF-8");
// JSONObject로 안전한 JSON 응답 생성 (이스케이프 자동 처리)
JSONObject resultData = new JSONObject();
resultData.put("title", title);
resultData.put("contents", contentsHtml);
StringBuilder result = new StringBuilder();
result.append("{\"resultCode\":0,\"resultMessage\":\"SUCCESS\",\"resultData\":{");
result.append("\"title\":\"").append(escapeJsonValue(encodedTitle)).append("\",");
result.append("\"contents\":\"").append(escapeJsonValue(encodedContents)).append("\"");
result.append("}}");
return result.toString();
JSONObject response = new JSONObject();
response.put("resultCode", 0);
response.put("resultMessage", "SUCCESS");
response.put("resultData", resultData);
String responseStr = response.toJSONString();
System.out.println("Contents API 응답 길이: " + responseStr.length());
return responseStr;
} catch(Exception e){
System.err.println("결재 본문 조회 오류: " + e.getMessage());
e.printStackTrace();
StringBuilder result = new StringBuilder();
result.append("{\"resultCode\":0,\"resultMessage\":\"SUCCESS\",\"resultData\":{");
result.append("\"title\":\"결재 문서\",");
result.append("\"contents\":\"<p>본문 조회 중 오류가 발생했습니다.</p>\"");
result.append("}}");
return result.toString();
JSONObject resultData = new JSONObject();
resultData.put("title", "결재 문서");
resultData.put("contents", "<p>본문 조회 중 오류가 발생했습니다: " + (e.getMessage() != null ? e.getMessage() : "") + "</p>");
JSONObject response = new JSONObject();
response.put("resultCode", 0);
response.put("resultMessage", "SUCCESS");
response.put("resultData", resultData);
return response.toJSONString();
} finally {
if(sqlSession != null) sqlSession.close();
}