로그 조회 추가
parent
f01c7d8d24
commit
b926330ea1
@ -0,0 +1,81 @@
|
||||
package cokr.xit.base.syslog;
|
||||
|
||||
import cokr.xit.foundation.component.QueryRequest;
|
||||
|
||||
public class LogQuery extends QueryRequest {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private String[]
|
||||
logTypes,
|
||||
userIDs,
|
||||
userAccounts;
|
||||
private String
|
||||
userName,
|
||||
fromDate,
|
||||
toDate;
|
||||
|
||||
public String[] getLogTypes() {
|
||||
return ifEmpty(logTypes, null);
|
||||
}
|
||||
|
||||
public void setLogTypes(String... logTypes) {
|
||||
this.logTypes = logTypes;
|
||||
}
|
||||
|
||||
public String[] getUserIDs() {
|
||||
return ifEmpty(userIDs, null);
|
||||
}
|
||||
|
||||
public void setUserIDs(String... userIDs) {
|
||||
this.userIDs = userIDs;
|
||||
}
|
||||
|
||||
public String[] getUserAccounts() {
|
||||
return ifEmpty(userAccounts, null);
|
||||
}
|
||||
|
||||
public void setUserAccounts(String[] userAccounts) {
|
||||
this.userAccounts = userAccounts;
|
||||
}
|
||||
|
||||
public String getUserName() {
|
||||
return userName;
|
||||
}
|
||||
|
||||
public void setUserName(String userName) {
|
||||
this.userName = userName;
|
||||
}
|
||||
|
||||
public String getFromDate() {
|
||||
return fromDate;
|
||||
}
|
||||
|
||||
public void setFromDate(String fromDate) {
|
||||
this.fromDate = fromDate;
|
||||
}
|
||||
|
||||
public String getToDate() {
|
||||
return toDate;
|
||||
}
|
||||
|
||||
public void setToDate(String toDate) {
|
||||
this.toDate = toDate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getOrderBy() {
|
||||
String orderBy = blankIfEmpty(super.getOrderBy());
|
||||
if (isEmpty(orderBy)) {
|
||||
if (!isEmpty(logTypes))
|
||||
orderBy += "LOG_TYPE, ";
|
||||
if (!isEmpty(userIDs))
|
||||
orderBy += "USER_ID, ";
|
||||
if (!isEmpty(userAccounts))
|
||||
orderBy += "USER_ACNT, ";
|
||||
if (!isEmpty(userName))
|
||||
orderBy += "USER_NM, ";
|
||||
orderBy += "LOG_ID DESC";
|
||||
}
|
||||
return orderBy;
|
||||
}
|
||||
}
|
@ -1,6 +1,13 @@
|
||||
package cokr.xit.base.syslog.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import cokr.xit.base.syslog.LogQuery;
|
||||
import cokr.xit.foundation.data.DataObject;
|
||||
|
||||
/**시스템 로깅 서비스
|
||||
* @author mjkhan
|
||||
*/
|
||||
public interface LoggingService {}
|
||||
public interface LoggingService {
|
||||
List<DataObject> getLogs(LogQuery req);
|
||||
}
|
@ -0,0 +1,130 @@
|
||||
package cokr.xit.base.syslog.web;
|
||||
|
||||
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.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
|
||||
|
||||
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.foundation.data.DataFormat;
|
||||
import cokr.xit.foundation.data.DataObject;
|
||||
import cokr.xit.foundation.web.AbstractController;
|
||||
import cokr.xit.foundation.web.RequestHandlerReader;
|
||||
|
||||
@RequestMapping(name = "시스템 로그", value = "/syslog")
|
||||
public class LoggingController extends AbstractController {
|
||||
@Resource(name = "loggingService")
|
||||
private LoggingService loggingService;
|
||||
@Autowired
|
||||
private RequestMappingHandlerMapping requestHandlers;
|
||||
|
||||
private RequestHandlerReader requestReader = new RequestHandlerReader();
|
||||
|
||||
/**사용자 관리 메인화면(user/user-main)을 연다.
|
||||
* 조건없는 {@link #getUserList(UserQuery) 사용자 조회 결과}를 포함시킨다.
|
||||
* @return base/user/user-main
|
||||
*/
|
||||
@GetMapping(name="시스템 로그 메인", value="/main.do")
|
||||
public ModelAndView main() {
|
||||
ModelAndView mav = getLogs(new LogQuery().setPageNum(1));
|
||||
mav.setViewName("base/syslog/syslog-main");
|
||||
return mav.addObject("syslogList", toJson(mav.getModel().remove("syslogList")));
|
||||
}
|
||||
|
||||
@GetMapping(name = "시스템 로그 조회", value = "/list.do")
|
||||
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<DataObject>
|
||||
list = loggingService.getLogs(req),
|
||||
web = list.stream()
|
||||
.filter(row -> "web".equals(row.get("LOG_TYPE")))
|
||||
.toList();
|
||||
if (!list.isEmpty()) {
|
||||
Map<String, DataObject> 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<DataObject> list) {
|
||||
List<CellDef> 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")
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue