Merge branch 'main' of http://10.dbnt.co.kr:50501/DBNT/geoinfo_eGov_work
commit
82a20351cb
|
|
@ -45,23 +45,42 @@ public class ApiController {
|
|||
|
||||
@RequestMapping(value = "createApiKey.do")
|
||||
@ResponseBody
|
||||
public Map<String, Object> UserApiInfo(HttpServletRequest request, HttpServletResponse response, @RequestParam HashMap<String, Object> params) {
|
||||
public Map<String, Object> UserApiInfo(HttpServletRequest request, HttpServletResponse response, @RequestParam HashMap<String, Object> params) throws Exception {
|
||||
Map<String, Object> resultMap = new HashMap<>();
|
||||
|
||||
|
||||
strUtil sUtil = new strUtil();
|
||||
String userType = sUtil.checkNull(parseData.parseData((String)params.get("userType")));
|
||||
|
||||
String apiKey = KeyGenerator.generateUniqueKey();
|
||||
System.out.println("Generated apiKey ==>" + apiKey);
|
||||
log.info("apiKey ==> " + apiKey);
|
||||
log.info("userType ==> " + userType);
|
||||
String loginUserId = String.valueOf(request.getSession().getAttribute("USERID"));
|
||||
params.put("userid", loginUserId);
|
||||
params.put("userType", userType);
|
||||
|
||||
resultMap.put("code", "SUCCESS");
|
||||
resultMap.put("msg", "API 신청이 완료됐습니다.");
|
||||
resultMap.put("data",apiKey);
|
||||
apiService.addApiKey(params);
|
||||
//
|
||||
resultMap.put("code", params.get("p_result_code"));
|
||||
resultMap.put("msg", params.get("p_err_msg"));
|
||||
resultMap.put("data",params.get("apiKey"));
|
||||
|
||||
return resultMap;
|
||||
}
|
||||
|
||||
|
||||
@RequestMapping(value = "discardApiKey.do")
|
||||
@ResponseBody
|
||||
public Map<String, Object> discardApiKey(HttpServletRequest request, HttpServletResponse response, @RequestParam HashMap<String, Object> params) throws Exception {
|
||||
Map<String, Object> resultMap = new HashMap<>();
|
||||
strUtil sUtil = new strUtil();
|
||||
String apiSeq = sUtil.checkNull(parseData.parseData((String)params.get("apiSeq")));
|
||||
|
||||
String loginUserId = String.valueOf(request.getSession().getAttribute("USERID"));
|
||||
params.put("userid", loginUserId);
|
||||
params.put("apiSeq", apiSeq);
|
||||
|
||||
resultMap = apiService.deleteWebApiKey(params);
|
||||
//
|
||||
// resultMap.put("code", params.get("p_result_code"));
|
||||
// resultMap.put("msg", params.get("p_err_msg"));
|
||||
// resultMap.put("data",params.get("apiKey"));
|
||||
return resultMap;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package geoinfo.main.api.service;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
|
|
@ -14,4 +15,8 @@ public interface ApiMapper {
|
|||
public List<?> selectInfoList(HashMap<String, Object> params) throws Exception;
|
||||
|
||||
HashMap<String, Object> selectUserLatestKey(HashMap<String, Object> params) throws Exception;
|
||||
|
||||
public HashMap<String, Object> spAddWebApiKey(HashMap<String, Object> params) throws SQLException;
|
||||
|
||||
int deleteWebApiKey(HashMap<String, Object> params) throws Exception;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,4 +12,8 @@ public interface ApiService {
|
|||
List<?> selectInfoList(HashMap<String, Object> params) throws Exception;
|
||||
|
||||
HashMap<String, Object> selectUserLatestKey(HashMap<String, Object> params) throws Exception;
|
||||
|
||||
HashMap<String, Object> addApiKey(HashMap<String, Object> params) throws Exception;
|
||||
|
||||
HashMap<String, Object> deleteWebApiKey(HashMap<String, Object> params) throws Exception;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,25 +10,89 @@ import org.springframework.stereotype.Service;
|
|||
import egovframework.rte.psl.dataaccess.util.EgovMap;
|
||||
import geoinfo.main.api.service.ApiMapper;
|
||||
import geoinfo.main.api.service.ApiService;
|
||||
import geoinfo.util.KeyGenerator;
|
||||
|
||||
@Service("apiService")
|
||||
public class ApiServiceImpl implements ApiService{
|
||||
|
||||
@Resource(name="ApiMapper")
|
||||
private ApiMapper ApiMapper;
|
||||
private ApiMapper apiMapper;
|
||||
|
||||
@Override
|
||||
public int selectInfoListCnt(HashMap<String, Object> params) throws Exception {
|
||||
return ApiMapper.selectInfoListCnt(params);
|
||||
return apiMapper.selectInfoListCnt(params);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<?> selectInfoList(HashMap<String, Object> params) throws Exception {
|
||||
return ApiMapper.selectInfoList(params);
|
||||
return apiMapper.selectInfoList(params);
|
||||
}
|
||||
|
||||
@Override
|
||||
public HashMap<String, Object> selectUserLatestKey(HashMap<String, Object> params) throws Exception {
|
||||
return ApiMapper.selectUserLatestKey(params);
|
||||
return apiMapper.selectUserLatestKey(params);
|
||||
}
|
||||
|
||||
@Override
|
||||
public HashMap<String, Object> addApiKey(HashMap<String, Object> params) throws Exception {
|
||||
|
||||
String retCode = "";
|
||||
String retMsg = "";
|
||||
final int MAX_RETRY = 10;
|
||||
|
||||
for (int i = 0; i < MAX_RETRY; i++) {
|
||||
// 1. 새 키 생성
|
||||
String apiKey = KeyGenerator.generateUniqueKey();
|
||||
params.put("apiKey", apiKey);
|
||||
|
||||
// 2. SP 호출
|
||||
apiMapper.spAddWebApiKey(params);
|
||||
retCode = (String) params.get("p_result_code");
|
||||
retMsg = (String) params.get("p_err_msg");
|
||||
|
||||
// 3. 중복(61)이면 새로 생성해서 다시 시도
|
||||
if ("61".equals(retCode)) {
|
||||
System.out.println("중복된 키 감지(" + apiKey + "), 재시도 중...(" + (i + 1) + ")");
|
||||
continue;
|
||||
}
|
||||
|
||||
// 4. 중복이 아니면 루프 탈출
|
||||
break;
|
||||
}
|
||||
|
||||
// 5. 결과에 따라 처리 (switch → if)
|
||||
if ("100".equals(retCode)) {
|
||||
System.out.println("API Key 생성 성공");
|
||||
} else if ("62".equals(retCode)) {
|
||||
System.out.println("관리자 승인 대기: " + retMsg);
|
||||
} else if ("63".equals(retCode)) {
|
||||
System.out.println("유효기간 만료: " + retMsg);
|
||||
} else if ("82".equals(retCode)) {
|
||||
System.out.println("사용자 불가: " + retMsg);
|
||||
} else if ("61".equals(retCode)) {
|
||||
System.out.println("API Key 생성 실패: 중복으로 인해 " + MAX_RETRY + "회 시도 후 중단됨");
|
||||
} else {
|
||||
System.out.println("기타 코드: " + retCode + " (" + retMsg + ")");
|
||||
}
|
||||
|
||||
return params;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HashMap<String, Object> deleteWebApiKey(HashMap<String, Object> params) throws Exception {
|
||||
HashMap<String, Object> result = new HashMap<String, Object>();
|
||||
int resultCnt = 0;
|
||||
|
||||
resultCnt = apiMapper.deleteWebApiKey(params);
|
||||
|
||||
if (resultCnt > 0) {
|
||||
result.put("code", "SUCCESS");
|
||||
} else {
|
||||
result.put("code", "ERROR");
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -806,7 +806,6 @@ public class LoginController {
|
|||
// 로그인 횟수 제한 : 10분설정시 1/(24*6) 5분설정시 1/(24*12)
|
||||
map.put("userid", userid);
|
||||
Map<String, Object> selectWebMemberIn = loginService.selectWebMemberIn(map);
|
||||
cls = selectWebMemberIn.get("cls").toString();
|
||||
|
||||
boolean adminYn = false;
|
||||
|
||||
|
|
|
|||
|
|
@ -41,9 +41,26 @@
|
|||
FROM (SELECT *
|
||||
FROM WEB_API_KEY
|
||||
WHERE USERID = #{userid}
|
||||
AND END_DT >= SYSDATE
|
||||
-- AND END_DT >= SYSDATE
|
||||
ORDER BY END_DT DESC)
|
||||
WHERE ROWNUM = 1
|
||||
</select>
|
||||
|
||||
<!-- API KEY 생성하여 발급 -->
|
||||
<select id="spAddWebApiKey" parameterType="map" statementType="CALLABLE" resultType="HashMap">
|
||||
{ CALL SP_ADD_WEB_API_KEY(
|
||||
#{userid, mode=IN, jdbcType=VARCHAR},
|
||||
#{userType, mode=IN, jdbcType=VARCHAR},
|
||||
#{apiKey, mode=IN, jdbcType=VARCHAR},
|
||||
#{p_result_code, mode=OUT, jdbcType=VARCHAR},
|
||||
#{p_err_msg, mode=OUT, jdbcType=VARCHAR}
|
||||
) }
|
||||
</select>
|
||||
|
||||
<!-- API KEY 갱신을 위하여 기존 키정보 삭제 -->
|
||||
<delete id="deleteWebApiKey" parameterType="map">
|
||||
DELETE
|
||||
FROM WEB_API_KEY
|
||||
WHERE API_SEQ = #{apiSeq}
|
||||
</delete>
|
||||
</mapper>
|
||||
|
|
@ -8,25 +8,14 @@
|
|||
|
||||
<c:choose>
|
||||
<c:when test="${not empty userLastApiKey}">
|
||||
<!-- <div> -->
|
||||
<%-- <p>API_SEQ: ${userLastApiKey.API_SEQ}</p> --%>
|
||||
<%-- <p>USERID: ${userLastApiKey.USERID}</p> --%>
|
||||
<%-- <p>USER_TYPE: ${userLastApiKey.USER_TYPE}</p> --%>
|
||||
<%-- <p>API_KEY: ${userLastApiKey.API_KEY}</p> --%>
|
||||
<%-- <p>START_DT: <fmt:formatDate value="${userLastApiKey.START_DT}" pattern="yyyy-MM-dd HH:mm:ss" /></p> --%>
|
||||
<%-- <p>END_DT: <fmt:formatDate value="${userLastApiKey.END_DT}" pattern="yyyy-MM-dd HH:mm:ss" /></p> --%>
|
||||
<%-- <p>APPROVE_YN: ${userLastApiKey.APPROVE_YN}</p> --%>
|
||||
<!-- </div> -->
|
||||
|
||||
<div class="table-scrollable">
|
||||
|
||||
<table class="table table-bordered table-data">
|
||||
<tbody>
|
||||
<tr>
|
||||
<th>신청일</th>
|
||||
<td><fmt:formatDate value="${userLastApiKey.START_DT}" pattern="yyyy-MM-dd HH:mm:ss" /></td>
|
||||
<td><fmt:formatDate value="${userLastApiKey.START_DT}" pattern="yyyy-MM-dd HH:mm" /></td>
|
||||
<th>만료일</th>
|
||||
<td><fmt:formatDate value="${userLastApiKey.END_DT}" pattern="yyyy-MM-dd HH:mm:ss" /></td>
|
||||
<td><fmt:formatDate value="${userLastApiKey.END_DT}" pattern="yyyy-MM-dd HH:mm" /></td>
|
||||
<th>승인상태</th>
|
||||
<td>${userLastApiKey.APPROVE_YN eq 'Y' ? '승인' : '미승인'}</td>
|
||||
</tr>
|
||||
|
|
@ -38,7 +27,17 @@
|
|||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
</div>
|
||||
<!-- 현재 시간 생성 -->
|
||||
<jsp:useBean id="now" class="java.util.Date" />
|
||||
|
||||
<!-- END_DT가 현재 시간보다 과거면 갱신 버튼 표시 -->
|
||||
<c:if test="${userLastApiKey.END_DT.time lt now.time}">
|
||||
<div class="row text-right">
|
||||
<a href="javascript:void(0);" class="apiKeyReq btn btn-sm btn-green" onclick="javascript:discardApiKey();">갱신</a>
|
||||
</div>
|
||||
</c:if>
|
||||
</c:when>
|
||||
<c:otherwise>
|
||||
<form name="frm" method="post">
|
||||
|
|
@ -70,7 +69,37 @@
|
|||
data : {userType: userType},
|
||||
dataType :"json",
|
||||
success : function(res){
|
||||
alert("apiKey ==> " + res.data)
|
||||
// alert("apiKey ==> " + res.data)
|
||||
if (res.code == "100") {
|
||||
// alert("신청이 완료됐습니다. \nAPI KEY는 " + res.data + "입니다.")
|
||||
location.reload();
|
||||
} else {
|
||||
alert(res.msg)
|
||||
}
|
||||
},
|
||||
error : function(){
|
||||
alert("오류입니다.");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/* [갱신] 버튼 클릭
|
||||
* 만료일이 지나면 KEY를 새로 발급 받을 수 있다.
|
||||
*/
|
||||
function discardApiKey() {
|
||||
var apiSeq = '${userLastApiKey.API_SEQ}'
|
||||
$.ajax({
|
||||
url : "/discardApiKey.do",
|
||||
type : "post",
|
||||
data : {apiSeq: apiSeq},
|
||||
dataType :"json",
|
||||
success : function(res){
|
||||
if (res.code == "SUCCESS") {
|
||||
alert("갱신을 위해 재신청하세요.")
|
||||
location.reload();
|
||||
} else {
|
||||
alert(res.msg)
|
||||
}
|
||||
},
|
||||
error : function(){
|
||||
alert("오류입니다.");
|
||||
|
|
|
|||
|
|
@ -181,11 +181,15 @@
|
|||
</c:otherwise>
|
||||
</c:choose>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a href="#" onClick="gourl('apiKey')" onFocus="this.blur()" class="nav-link nav-toggle">
|
||||
<span class="title">API 신청</span>
|
||||
</a>
|
||||
</li>
|
||||
<c:if test="${isLogin == true}">
|
||||
<c:if test="${cls == 1}">
|
||||
<li class="nav-item">
|
||||
<a href="#" onClick="gourl('apiKey')" onFocus="this.blur()" class="nav-link nav-toggle">
|
||||
<span class="title">API 신청</span>
|
||||
</a>
|
||||
</li>
|
||||
</c:if>
|
||||
</c:if>
|
||||
|
||||
<c:if test="${isLogin == true}">
|
||||
<c:if test="${cls == 0}">
|
||||
|
|
|
|||
|
|
@ -172,7 +172,11 @@
|
|||
<a class="dropdown-toggle" data-toggle="dropdown" href="#" onClick="gourl('faq')" onFocus="this.blur()">시추정보 FAQ</a>
|
||||
</li>
|
||||
<li class="dropdown">
|
||||
<a class="dropdown-toggle" data-toggle="dropdown" href="#" onClick="gourl('apiKey')" onFocus="this.blur()">API 신청</a>
|
||||
<c:if test="${isLogin == true}">
|
||||
<c:if test="${cls == 1}">
|
||||
<a class="dropdown-toggle" data-toggle="dropdown" href="#" onClick="gourl('apiKey')" onFocus="this.blur()">API 신청</a>
|
||||
</c:if>
|
||||
</c:if>
|
||||
</li>
|
||||
<c:if test="${isLogin == true}">
|
||||
<c:if test="${cls == 0}">
|
||||
|
|
|
|||
|
|
@ -367,24 +367,28 @@
|
|||
</c:if>
|
||||
|
||||
<c:if test="${eGovUrl == 'apiKey.do'}">
|
||||
<!-- 커뮤니티 > API 신청 시작 -->
|
||||
<h1 class="page-title">
|
||||
<span class="page-title-text">API 신청</span>
|
||||
<ul class="page-category">
|
||||
<li class="category-item">게시판</li>
|
||||
<li class="category-item">API 신청</li>
|
||||
</ul>
|
||||
</h1>
|
||||
<script>
|
||||
$(document).ready(function(){
|
||||
// 상단메뉴 활성화
|
||||
$(".nav > li.dropdown:eq(6)").addClass("on");
|
||||
// 왼쪽메뉴 활성화
|
||||
$("#community_sub_menu").css("display", "block");
|
||||
$("#community_sub_menu > li.nav-item:eq(5)").addClass("active");
|
||||
});
|
||||
</script>
|
||||
<!-- 커뮤니티 > 시추정보 Q&A 끝 -->
|
||||
<c:if test="${isLogin == true}">
|
||||
<c:if test="${cls == 1}">
|
||||
<!-- 커뮤니티 > API 신청 시작 -->
|
||||
<h1 class="page-title">
|
||||
<span class="page-title-text">API 신청</span>
|
||||
<ul class="page-category">
|
||||
<li class="category-item">게시판</li>
|
||||
<li class="category-item">API 신청</li>
|
||||
</ul>
|
||||
</h1>
|
||||
<script>
|
||||
$(document).ready(function(){
|
||||
// 상단메뉴 활성화
|
||||
$(".nav > li.dropdown:eq(6)").addClass("on");
|
||||
// 왼쪽메뉴 활성화
|
||||
$("#community_sub_menu").css("display", "block");
|
||||
$("#community_sub_menu > li.nav-item:eq(5)").addClass("active");
|
||||
});
|
||||
</script>
|
||||
<!-- 커뮤니티 > 시추정보 Q&A 끝 -->
|
||||
</c:if>
|
||||
</c:if>
|
||||
</c:if>
|
||||
|
||||
<c:if test="${eGovUrl == 'homeEducationApplicationInquiry.do' || eGovUrl == 'homeEducationApplicationInput.do' }">
|
||||
|
|
|
|||
Loading…
Reference in New Issue