diff --git a/src/main/java/com/mca/cmmn/mapper/LogMapper.java b/src/main/java/com/mca/cmmn/mapper/LogMapper.java
new file mode 100644
index 0000000..f517c76
--- /dev/null
+++ b/src/main/java/com/mca/cmmn/mapper/LogMapper.java
@@ -0,0 +1,12 @@
+package com.mca.cmmn.mapper;
+
+import com.mca.cmmn.vo.BaseSearchVO;
+import com.mca.cmmn.vo.LogVO;
+import egovframework.rte.psl.dataaccess.mapper.Mapper;
+
+@Mapper("logMapper")
+public interface LogMapper {
+ void insertLog(LogVO logVO);
+
+ int selectLoginCnt(BaseSearchVO searchVO);
+}
diff --git a/src/main/java/com/mca/cmmn/service/LogService.java b/src/main/java/com/mca/cmmn/service/LogService.java
new file mode 100644
index 0000000..d918ec1
--- /dev/null
+++ b/src/main/java/com/mca/cmmn/service/LogService.java
@@ -0,0 +1,28 @@
+package com.mca.cmmn.service;
+
+import com.mca.cmmn.mapper.LogMapper;
+import com.mca.cmmn.vo.BaseSearchVO;
+import com.mca.cmmn.vo.LogVO;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.Resource;
+
+@Service("logService")
+public class LogService {
+
+ @Resource(name="logMapper")
+ LogMapper logMapper;
+
+ public void insertLog(LogVO logVO){
+ logMapper.insertLog(logVO);
+ }
+
+ public int selectLoginCnt(BaseSearchVO searchVO){
+ return logMapper.selectLoginCnt(searchVO);
+ }
+
+// public LayersVO selectFacility(String layer) {
+// return layersMapper.selectFacility(layer);
+// }
+
+}
diff --git a/src/main/java/com/mca/cmmn/vo/BaseSearchVO.java b/src/main/java/com/mca/cmmn/vo/BaseSearchVO.java
index 84045c7..2878ed4 100644
--- a/src/main/java/com/mca/cmmn/vo/BaseSearchVO.java
+++ b/src/main/java/com/mca/cmmn/vo/BaseSearchVO.java
@@ -1,5 +1,7 @@
package com.mca.cmmn.vo;
+import java.time.LocalDate;
+
public class BaseSearchVO {
/**
@@ -34,6 +36,9 @@ public class BaseSearchVO {
/** recordCountPerPage */
private int recordCountPerPage = 10;
+ private String searchStartDate;
+ private String searchEndDate;
+
public String getSearchCondition() {
return searchCondition;
}
@@ -105,4 +110,21 @@ public class BaseSearchVO {
public void setRecordCountPerPage(int recordCountPerPage) {
this.recordCountPerPage = recordCountPerPage;
}
+
+
+ public String getSearchStartDate() {
+ return searchStartDate;
+ }
+
+ public void setSearchStartDate(String searchStartDate) {
+ this.searchStartDate = searchStartDate;
+ }
+
+ public String getSearchEndDate() {
+ return searchEndDate;
+ }
+
+ public void setSearchEndDate(String searchEndDate) {
+ this.searchEndDate = searchEndDate;
+ }
}
diff --git a/src/main/java/com/mca/cmmn/vo/LogActions.java b/src/main/java/com/mca/cmmn/vo/LogActions.java
new file mode 100644
index 0000000..e076636
--- /dev/null
+++ b/src/main/java/com/mca/cmmn/vo/LogActions.java
@@ -0,0 +1,16 @@
+package com.mca.cmmn.vo;
+
+public enum LogActions {
+ LOGIN("login"),
+ LOGOUT("logout");
+
+ private String value;
+
+ LogActions(String value) {
+ this.value = value;
+ }
+
+ public String getValue(){
+ return value;
+ }
+}
diff --git a/src/main/java/com/mca/cmmn/vo/LogVO.java b/src/main/java/com/mca/cmmn/vo/LogVO.java
new file mode 100644
index 0000000..61c4ac4
--- /dev/null
+++ b/src/main/java/com/mca/cmmn/vo/LogVO.java
@@ -0,0 +1,61 @@
+package com.mca.cmmn.vo;
+
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
+
+public class LogVO {
+
+ private String log_cd;
+ private String userid;
+ private String action;
+ private String etc;
+ private LocalDateTime created_date;
+
+ public String getLog_cd() {
+ return log_cd;
+ }
+
+ public void setLog_cd(String log_cd) {
+ this.log_cd = log_cd;
+ }
+
+ public String getUserid() {
+ return userid;
+ }
+
+ public void setUserid(String userid) {
+ this.userid = userid;
+ }
+
+ public String getAction() {
+ return action;
+ }
+
+ public void setAction(String action) {
+ this.action = action;
+ }
+
+ public String getEtc() {
+ return etc;
+ }
+
+ public void setEtc(String etc) {
+ this.etc = etc;
+ }
+
+ public LocalDateTime getCreated_date() {
+ return created_date;
+ }
+
+ public void setCreated_date(LocalDateTime created_date) {
+ this.created_date = created_date;
+ }
+
+ public void setLog(String userid, String logAction, String etc, LocalDateTime now){
+ setLog_cd(now.format(DateTimeFormatter.ofPattern("yyyyMMddHHmmssSSS")).substring(2));
+ setUserid(userid);
+ setAction(logAction);
+ setEtc(etc);
+ setCreated_date(now);
+ }
+}
diff --git a/src/main/java/com/mca/cmmn/web/AdminController.java b/src/main/java/com/mca/cmmn/web/AdminController.java
index 94b13bc..a119e3e 100644
--- a/src/main/java/com/mca/cmmn/web/AdminController.java
+++ b/src/main/java/com/mca/cmmn/web/AdminController.java
@@ -1,11 +1,15 @@
package com.mca.cmmn.web;
+import java.time.LocalDate;
+import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
+import com.mca.cmmn.service.LogService;
+import com.mca.cmmn.vo.BaseSearchVO;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
@@ -60,6 +64,9 @@ public class AdminController {
@Resource(name="fieldDataService")
private FieldDataService fieldDataService;
+ @Resource(name = "logService")
+ private LogService logService;
+
/**
* 대시보드 페이지 이동
*
@@ -79,6 +86,15 @@ public class AdminController {
int standByCount = userService.selectUserStandByCount();
model.addAttribute("standByCount", standByCount);
+ BaseSearchVO searchVO = new BaseSearchVO();
+ LocalDate searchStartDate = LocalDate.now();
+ searchVO.setSearchStartDate(searchStartDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
+ searchVO.setSearchEndDate(searchStartDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
+ model.addAttribute("dayLoginCount", logService.selectLoginCnt(searchVO));
+
+ searchVO.setSearchStartDate(searchStartDate.minusMonths(1).format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
+ model.addAttribute("monthLoginCount", logService.selectLoginCnt(searchVO));
+
return "admin/dashBoard";
} catch (Exception e) {
diff --git a/src/main/java/com/mca/sec/LoginSuccessHandler.java b/src/main/java/com/mca/sec/LoginSuccessHandler.java
index a1c589b..efcacbf 100644
--- a/src/main/java/com/mca/sec/LoginSuccessHandler.java
+++ b/src/main/java/com/mca/sec/LoginSuccessHandler.java
@@ -1,12 +1,17 @@
package com.mca.sec;
import java.io.IOException;
+import java.time.LocalDateTime;
+import javax.annotation.Resource;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
+import com.mca.cmmn.service.LogService;
+import com.mca.cmmn.vo.LogActions;
+import com.mca.cmmn.vo.LogVO;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
@@ -16,32 +21,45 @@ import com.mca.sec.UserUtil;
public class LoginSuccessHandler implements AuthenticationSuccessHandler{
private String roleName;
+ @Resource(name="logService")
+ private LogService logService;
+
+
+
@Override
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response,
Authentication authentication) throws IOException, ServletException {
// TODO Auto-generated method stub
LoginUserVO user = UserUtil.getMemberInfo();
-
- HttpSession session = request.getSession();
- session.setAttribute("userVO", user);
-
- LoginSuccessHandler loginSuccessHandler = new LoginSuccessHandler();
- authentication.getAuthorities().forEach(authority ->{
- loginSuccessHandler.roleName = authority.getAuthority();
- });
-
- if(loginSuccessHandler.roleName.equals("ROLE_USER")) {
- response.sendRedirect("/map/request");
- return;
- }else if(loginSuccessHandler.roleName.equals("ROLE_ADMIN")) {
- response.sendRedirect("/admin/dashBoard");
- return;
- }else if(loginSuccessHandler.roleName.equals("ROLE_DISABLE")) {
- response.sendRedirect("/login?fail");
- return;
- }
- response.sendRedirect("/");
+ if(user == null){
+ response.sendRedirect("/");
+ }else{
+
+ HttpSession session = request.getSession();
+ session.setAttribute("userVO", user);
+
+ LoginSuccessHandler loginSuccessHandler = new LoginSuccessHandler();
+ authentication.getAuthorities().forEach(authority ->{
+ loginSuccessHandler.roleName = authority.getAuthority();
+ });
+
+ LogVO logVO = new LogVO();
+ logVO.setLog(user.getUserid(), LogActions.LOGIN.getValue(), null, LocalDateTime.now());
+ logService.insertLog(logVO);
+
+ switch (loginSuccessHandler.roleName) {
+ case "ROLE_USER":
+ response.sendRedirect("/map/request");
+ return;
+ case "ROLE_ADMIN":
+ response.sendRedirect("/admin/dashBoard");
+ return;
+ case "ROLE_DISABLE":
+ response.sendRedirect("/login?fail");
+ return;
+ }
+ }
}
}
diff --git a/src/main/java/com/mca/sec/LogoutSuccessHandler.java b/src/main/java/com/mca/sec/LogoutSuccessHandler.java
index 05cef44..8f40574 100644
--- a/src/main/java/com/mca/sec/LogoutSuccessHandler.java
+++ b/src/main/java/com/mca/sec/LogoutSuccessHandler.java
@@ -1,16 +1,24 @@
package com.mca.sec;
import java.io.IOException;
+import java.time.LocalDateTime;
+import javax.annotation.Resource;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import com.mca.cmmn.service.LogService;
+import com.mca.cmmn.vo.LogActions;
+import com.mca.cmmn.vo.LogVO;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.logout.SimpleUrlLogoutSuccessHandler;
public class LogoutSuccessHandler extends SimpleUrlLogoutSuccessHandler{
-
+
+ @Resource(name="logService")
+ private LogService logService;
+
private String successUrl = "/";
public void setSuccessUrl(String successUrl){
@@ -18,8 +26,14 @@ public class LogoutSuccessHandler extends SimpleUrlLogoutSuccessHandler{
}
public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException {
- setDefaultTargetUrl(successUrl);
- super.onLogoutSuccess(request, response, authentication);
- }
+
+ LogVO logVO = new LogVO();
+ logVO.setLog(authentication.getName(), LogActions.LOGOUT.getValue(), null, LocalDateTime.now());
+ logService.insertLog(logVO);
+
+ setDefaultTargetUrl(successUrl);
+ super.onLogoutSuccess(request, response, authentication);
+ }
+
}
diff --git a/src/main/resources/egovframework/sqlmap/mappers/cmmn/logMapper.xml b/src/main/resources/egovframework/sqlmap/mappers/cmmn/logMapper.xml
new file mode 100644
index 0000000..8c991f8
--- /dev/null
+++ b/src/main/resources/egovframework/sqlmap/mappers/cmmn/logMapper.xml
@@ -0,0 +1,19 @@
+
+
+
오늘 방문자 수
--
+-
+오늘 방문자 수
+최근 한달 방문자 수
--
--
-