diff --git a/src/main/java/cokr/xit/fims/base/LoggingController.java b/src/main/java/cokr/xit/fims/base/LoggingController.java new file mode 100644 index 00000000..b7f6db39 --- /dev/null +++ b/src/main/java/cokr/xit/fims/base/LoggingController.java @@ -0,0 +1,119 @@ +package cokr.xit.fims.base; + +import java.util.Date; +import java.util.List; +import java.util.Map; +import java.util.stream.IntStream; + +import javax.annotation.Resource; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.web.servlet.ModelAndView; + +import cokr.xit.base.docs.xls.CellDef; +import cokr.xit.base.docs.xls.XLSWriter; +import cokr.xit.base.syslog.LogQuery; +import cokr.xit.base.syslog.service.LoggingService; +import cokr.xit.fims.task.TaskRequestMappingHandlerMapping; +import cokr.xit.foundation.data.DataFormat; +import cokr.xit.foundation.data.DataObject; +import cokr.xit.foundation.web.RequestHandlerReader; + +@Controller +public class LoggingController extends cokr.xit.base.syslog.web.LoggingController { + @Resource(name = "loggingService") + private LoggingService loggingService; + + @Autowired + private TaskRequestMappingHandlerMapping requestHandlers; + + private RequestHandlerReader requestReader = new RequestHandlerReader(); + + @Override + public ModelAndView getLogs(LogQuery req) { + boolean download = !isEmpty(req.getDownload()); + if (!download) + setFetchSize(req); + else + req.setPageNum(0).setFetchSize(0); + + String + toDate = req.getToDate(), + fromDate = req.getFromDate(); + if (isEmpty(toDate)) { + Date date = new Date(); + toDate = DataFormat.yyyy_mm_dd(date); + req.setToDate(toDate.replace("-", "")); + + if (isEmpty(fromDate)) { + fromDate = DataFormat.yyyy_mm_dd(new Date(date.getTime() - 1000L * 60L * 60L * 24L * 30L)); + req.setFromDate(fromDate.replace("-", "")); + } + } + + List + list = loggingService.getLogs(req), + web = list.stream() + .filter(row -> "web".equals(row.get("LOG_TYPE"))) + .toList(); + if (!list.isEmpty()) { + Map reqs = requestReader.asTree(requestHandlers).getIndex(); + list.forEach(row -> { + Object obj = row.get("REG_DT"); + row.set("REG_DT", DataFormat.yyyy_mm_dd_hh_mm_ss(obj)); + + obj = row.get("URL"); + if (isEmpty(obj)) return; + + DataObject reqInfo = reqs.get(obj); + row.set("DSCRP", reqInfo != null ? reqInfo.get("name") : ""); + }); + } + + if (!download) + return setCollectionInfo( + new ModelAndView("jsonView") + .addObject("fromDate", fromDate) + .addObject("toDate", toDate), + list, + "syslog" + ); + else + return download(list); + } + + private ModelAndView download(List list) { + List cellDefs = List.of( + new CellDef().setLabel("계정").setField("USER_ACNT"), + new CellDef().setLabel("사용자이름").setField("USER_NM"), + new CellDef().setLabel("IP 주소").setField("IP_ADDR"), + new CellDef().setLabel("로그유형").setField("LOG_TYPE_NM"), + new CellDef().setLabel("접속일시").setField("REG_DT"), + new CellDef().setLabel("URL").setField("URL"), + new CellDef().setLabel("설명").setField("DSCRP"), + new CellDef().setLabel("파일이름").setField("FILE_NM"), + new CellDef().setLabel("민감정보").setField("PSNL_INFO") + ); + XLSWriter xlsx = new XLSWriter() + .worksheet(0) + .trackWidth(IntStream.range(0, cellDefs.size()).toArray()) + .cell(0, 0) + .value("시스템 로그 목록").merge(0, cellDefs.size() - 1) + .cell(2, 0) + .rowValues(CellDef.header(cellDefs, null)) + .cell(3, 0) + .values( + list, + CellDef.values(cellDefs) + ) + .autoWidth(); + + return new ModelAndView("downloadView") + .addObject("download", + xlsx.getDownloadable() + .setFilename("시스템 로그 목록.xlsx") + ); + } + +} \ No newline at end of file diff --git a/src/main/resources/sql/mapper/base/file-mapper.xml b/src/main/resources/sql/mapper/base/file-mapper.xml index 55f5dc6b..55ecb7cd 100644 --- a/src/main/resources/sql/mapper/base/file-mapper.xml +++ b/src/main/resources/sql/mapper/base/file-mapper.xml @@ -61,7 +61,7 @@ SELECT A.*, FILE_PATH URL SELECT NEW_ID, CONCAT(DIR, NEW_ID, '.', #{file.extension}) PATH FROM ( - SELECT IFNULL(MAX(FILE_ID) + 1, CONCAT(THIS_DAY, '00001')) NEW_ID + SELECT NVL(MAX(FILE_ID) + 1, CONCAT(THIS_DAY, '00001')) NEW_ID FROM TB_FILE A, () B WHERE FILE_ID LIKE CONCAT(THIS_DAY, '%') ) T1, ( diff --git a/src/main/resources/sql/mapper/base/menu-mapper.xml b/src/main/resources/sql/mapper/base/menu-mapper.xml index 2856c0bc..599e1943 100644 --- a/src/main/resources/sql/mapper/base/menu-mapper.xml +++ b/src/main/resources/sql/mapper/base/menu-mapper.xml @@ -31,7 +31,7 @@ SELECT A.* /* 메뉴 등록(menuMapper.insertMenu) */ SELECT NEW_NO, NEW_ORD - FROM (SELECT IFNULL(MAX(MENU_NO) + 1, 0) NEW_NO FROM TB_MENU) A, + FROM (SELECT NVL(MAX(MENU_NO) + 1, 0) NEW_NO FROM TB_MENU) A, () B INSERT INTO TB_MENU ( MENU_NO @@ -69,7 +69,7 @@ UPDATE TB_MENU SET , IMG_CNF = #{menu.imageConf} WHERE MENU_NO = #{menu.id} -SELECT IFNULL(MAX(SRT_ORD) + 1, 0) NEW_ORD FROM TB_MENU WHERE PRNT_NO = IFNULL(#{parentID}, IFNULL(#{menu.parentID}, 0)) +SELECT NVL(MAX(SRT_ORD) + 1, 0) NEW_ORD FROM TB_MENU WHERE PRNT_NO = NVL(#{parentID}, NVL(#{menu.parentID}, 0)) /* 메뉴 이동(menuMapper.moveMenus) */ UPDATE TB_MENU SET diff --git a/src/main/resources/sql/mapper/base/syslog-mapper.xml b/src/main/resources/sql/mapper/base/syslog-mapper.xml index 8ebcf4a0..9a2fb533 100644 --- a/src/main/resources/sql/mapper/base/syslog-mapper.xml +++ b/src/main/resources/sql/mapper/base/syslog-mapper.xml @@ -16,8 +16,49 @@ + + /* 시스템 로그 등록(loggingMapper.insertLog) */ -SELECT CONCAT(TODAY, LPAD(NVL(SUBSTR(MAX(LOG_ID), 9) + 1, 1), 16, '0')) NEW_ID + +SELECT CONCAT(TODAY, LPAD(NVL(SUBSTR(MAX(LOG_ID), 9) + 1, 1), 16, '0')) NEW_ID FROM TB_SYS_LOG A, () B WHERE LOG_ID LIKE CONCAT(TODAY, '%') INSERT INTO TB_SYS_LOG ( diff --git a/src/main/resources/sql/mapper/base/utility.xml b/src/main/resources/sql/mapper/base/utility.xml index ab14fc82..7f335db7 100644 --- a/src/main/resources/sql/mapper/base/utility.xml +++ b/src/main/resources/sql/mapper/base/utility.xml @@ -30,8 +30,8 @@ SELECT FOUND_ROWS() TOT_CNT SELECTTODAY FROM DUAL -IFNULL(#{thisDay},) +NVL(#{thisDay},) -SELECTTHIS_DAY +SELECTTHIS_DAY FROM DUAL \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/jsp/base/menu/menu-main.jsp b/src/main/webapp/WEB-INF/jsp/base/menu/menu-main.jsp index 70d17fa7..8a966af9 100644 --- a/src/main/webapp/WEB-INF/jsp/base/menu/menu-main.jsp +++ b/src/main/webapp/WEB-INF/jsp/base/menu/menu-main.jsp @@ -1,6 +1,6 @@ <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" isELIgnored="false" session="false"%> <%@ include file="/WEB-INF/jsp/include/taglib.jsp"%> -" /--%> + 메뉴
diff --git a/src/main/webapp/WEB-INF/jsp/base/syslog/syslog-main.jsp b/src/main/webapp/WEB-INF/jsp/base/syslog/syslog-main.jsp new file mode 100644 index 00000000..3eedfa10 --- /dev/null +++ b/src/main/webapp/WEB-INF/jsp/base/syslog/syslog-main.jsp @@ -0,0 +1,155 @@ +<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" isELIgnored="false" session="false"%> +<%@ include file="/WEB-INF/jsp/include/taglib.jsp"%> +시스템 로그 + +
+ +
+ + \ No newline at end of file