Commit c63b99e4 by fsn

登录日志的新增

parent f20fee94
package com.stylefeng.guns.modular.system.controller;
import com.baomidou.mybatisplus.mapper.SqlRunner;
import com.baomidou.mybatisplus.plugins.Page;
import com.stylefeng.guns.common.constant.factory.PageFactory;
import com.stylefeng.guns.common.controller.BaseController;
import com.stylefeng.guns.modular.system.dao.LogDao;
import com.stylefeng.guns.modular.system.warpper.LogWarpper;
import com.stylefeng.guns.persistence.model.OperationLog;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
/**
* 日志管理的控制器
*
* @author fengshuonan
* @Date 2017年4月5日 19:45:36
*/
@Controller
@RequestMapping("/loginLog")
public class LoginLogController extends BaseController {
private static String PREFIX = "/system/log/";
@Resource
private LogDao logDao;
/**
* 跳转到日志管理的首页
*/
@RequestMapping("")
public String index() {
return PREFIX + "login_log.html";
}
/**
* 查询操作日志列表
*/
@RequestMapping("/list")
@ResponseBody
public Object list(@RequestParam(required = false) String beginTime, @RequestParam(required = false) String endTime, @RequestParam(required = false) String logName) {
Page<OperationLog> page = new PageFactory<OperationLog>().defaultPage();
List<Map<String, Object>> result = logDao.getLoginLogs(page, beginTime, endTime, logName);
page.setRecords((List<OperationLog>) new LogWarpper(result).warp());
return super.packForBT(page);
}
/**
* 清空日志
*/
@RequestMapping("/delLoginLog")
@ResponseBody
public Object delLog() {
SqlRunner.db().delete("delete from _login_log");
return super.SUCCESS_TIP;
}
}
...@@ -23,4 +23,11 @@ public interface LogDao{ ...@@ -23,4 +23,11 @@ public interface LogDao{
*/ */
List<Map<String, Object>> getOperationLogs(Page<OperationLog> page, @Param("beginTime") String beginTime, @Param("endTime") String endTime, @Param("logName") String logName); List<Map<String, Object>> getOperationLogs(Page<OperationLog> page, @Param("beginTime") String beginTime, @Param("endTime") String endTime, @Param("logName") String logName);
/**
* 获取登录日志
*
* @author stylefeng
* @Date 2017/4/16 23:48
*/
List<Map<String, Object>> getLoginLogs(Page<OperationLog> page, @Param("beginTime") String beginTime, @Param("endTime") String endTime, @Param("logName") String logName);
} }
...@@ -13,4 +13,14 @@ ...@@ -13,4 +13,14 @@
order by createTime DESC order by createTime DESC
</select> </select>
<select id="getLoginLogs" resultType="map">
select * from _login_log where 1 = 1
<if test="beginTime != null and beginTime !='' and endTime != null and endTime != ''">
and (createTime between CONCAT(#{beginTime},' 00:00:00') and CONCAT(#{endTime},' 23:59:59'))
</if>
<if test="logName != null and logName !=''">
and logname like CONCAT('%',#{logName},'%')
</if>
order by createTime DESC
</select>
</mapper> </mapper>
\ No newline at end of file
...@@ -29,7 +29,7 @@ public class LogWarpper extends BaseControllerWarpper { ...@@ -29,7 +29,7 @@ public class LogWarpper extends BaseControllerWarpper {
} }
//如果信息中包含分割符号;;; 则分割字符串返给前台 //如果信息中包含分割符号;;; 则分割字符串返给前台
if (message.indexOf(Contrast.separator) != -1) { if (ToolUtil.isNotEmpty(message) && message.indexOf(Contrast.separator) != -1) {
String[] msgs = message.split(Contrast.separator); String[] msgs = message.split(Contrast.separator);
map.put("regularMessage",msgs); map.put("regularMessage",msgs);
}else{ }else{
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
<div class="col-sm-12"> <div class="col-sm-12">
<div class="ibox float-e-margins"> <div class="ibox float-e-margins">
<div class="ibox-title"> <div class="ibox-title">
<h5>日志管理</h5> <h5>业务日志</h5>
</div> </div>
<div class="ibox-content"> <div class="ibox-content">
<div class="row row-lg"> <div class="row row-lg">
......
@layout("/common/_container.html"){
<div class="row">
<div class="col-sm-12">
<div class="ibox float-e-margins">
<div class="ibox-title">
<h5>登录日志</h5>
</div>
<div class="ibox-content">
<div class="row row-lg">
<div class="col-sm-12">
<div class="row">
<div class="col-sm-3">
<#TimeCon id="beginTime" name="开始时间" isTime="false" pattern="YYYY-MM-DD" />
</div>
<div class="col-sm-3">
<#TimeCon id="endTime" name="结束时间" isTime="false" pattern="YYYY-MM-DD" />
</div>
<div class="col-sm-3">
<#NameCon id="logName" name="日志名称" />
</div>
<div class="col-sm-3">
<#button name="搜索" icon="fa-search" clickFun="LoginLog.search()"/>
</div>
</div>
<div class="hidden-xs" id="LoginLogTableToolbar" role="group">
<#button name="清空日志" icon="fa-plus" clickFun="LoginLog.delLog()"/>
</div>
<#table id="LoginLogTable"/>
</div>
</div>
</div>
</div>
</div>
</div>
<script src="${ctxPath}/static/modular/system/log/login_log.js"></script>
@}
/**
* 日志管理初始化
*/
var LoginLog = {
id: "LoginLogTable", //表格id
seItem: null, //选中的条目
table: null,
layerIndex: -1
};
/**
* 初始化表格的列
*/
LoginLog.initColumn = function () {
return [
{field: 'selectItem', radio: true},
{title: 'id', field: 'id', visible: false, align: 'center', valign: 'middle'},
{title: '日志名称', field: 'logname', align: 'center', valign: 'middle'},
{title: '用户id', field: 'userid', align: 'center', valign: 'middle'},
{title: '时间', field: 'createtime', align: 'center', valign: 'middle'},
{title: '具体消息', field: 'message', align: 'center', valign: 'middle'},
{title: 'ip', field: 'ip', align: 'center', valign: 'middle'}];
};
/**
* 检查是否选中
*/
LoginLog.check = function () {
var selected = $('#' + this.id).bootstrapTable('getSelections');
if(selected.length == 0){
Feng.info("请先选中表格中的某一记录!");
return false;
}else{
LoginLog.seItem = selected[0];
return true;
}
};
/**
* 清空日志
*/
LoginLog.delLog = function () {
Feng.confirm("是否清空所有日志?",function(){
var ajax = Feng.baseAjax("/loginLog/delLoginLog","清空日志");
ajax.start();
LoginLog.table.refresh();
});
}
/**
* 查询日志列表
*/
LoginLog.search = function () {
var queryData = {};
queryData['logName'] = $("#logName").val();
queryData['beginTime'] = $("#beginTime").val();
queryData['endTime'] = $("#endTime").val();
LoginLog.table.refresh({query: queryData});
};
$(function () {
var defaultColunms = LoginLog.initColumn();
var table = new BSTable(LoginLog.id, "/loginLog/list", defaultColunms);
table.setPaginationType("server");
LoginLog.table = table.init();
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment