Răsfoiți Sursa

完成日志管理

shuzheng 9 ani în urmă
părinte
comite
5409494f44

+ 76 - 0
zheng-upms/zheng-upms-server/src/main/java/com/zheng/upms/server/controller/manage/UpmsLogController.java

@@ -0,0 +1,76 @@
+package com.zheng.upms.server.controller.manage;
+
+import com.zheng.common.base.BaseController;
+import com.zheng.upms.common.constant.UpmsResult;
+import com.zheng.upms.common.constant.UpmsResultConstant;
+import com.zheng.upms.dao.model.UpmsLog;
+import com.zheng.upms.dao.model.UpmsLogExample;
+import com.zheng.upms.rpc.api.UpmsLogService;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import org.apache.commons.lang.StringUtils;
+import org.apache.shiro.authz.annotation.RequiresPermissions;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * 日志controller
+ * Created by shuzheng on 2017/3/14.
+ */
+@Controller
+@Api(value = "日志管理", description = "日志管理")
+@RequestMapping("/manage/log")
+public class UpmsLogController extends BaseController {
+
+    private static Logger _log = LoggerFactory.getLogger(UpmsLogController.class);
+
+    @Autowired
+    private UpmsLogService upmsLogService;
+
+    @ApiOperation(value = "日志首页")
+    @RequiresPermissions("upms:log:read")
+    @RequestMapping(value = "/index", method = RequestMethod.GET)
+    public String index() {
+        return "/manage/log/index";
+    }
+
+    @ApiOperation(value = "日志列表")
+    @RequiresPermissions("upms:log:read")
+    @RequestMapping(value = "/list", method = RequestMethod.GET)
+    @ResponseBody
+    public Object list(
+            @RequestParam(required = false, defaultValue = "0", value = "offset") int offset,
+            @RequestParam(required = false, defaultValue = "10", value = "limit") int limit,
+            @RequestParam(required = false, value = "sort") String sort,
+            @RequestParam(required = false, value = "order") String order) {
+        UpmsLogExample upmsLogExample = new UpmsLogExample();
+        upmsLogExample.setOffset(offset);
+        upmsLogExample.setLimit(limit);
+        if (!StringUtils.isBlank(sort) && !StringUtils.isBlank(order)) {
+            upmsLogExample.setOrderByClause(sort + " " + order);
+        }
+        List<UpmsLog> rows = upmsLogService.selectByExample(upmsLogExample);
+        long total = upmsLogService.countByExample(upmsLogExample);
+        Map<String, Object> result = new HashMap<>();
+        result.put("rows", rows);
+        result.put("total", total);
+        return result;
+    }
+
+    @ApiOperation(value = "删除日志")
+    @RequiresPermissions("upms:log:delete")
+    @RequestMapping(value = "/delete/{ids}", method = RequestMethod.GET)
+    @ResponseBody
+    public Object delete(@PathVariable("ids") String ids) {
+        int count = upmsLogService.deleteByPrimaryKeys(ids);
+        return new UpmsResult(UpmsResultConstant.SUCCESS, count);
+    }
+
+}

+ 168 - 0
zheng-upms/zheng-upms-server/src/main/webapp/WEB-INF/jsp/manage/log/index.jsp

@@ -0,0 +1,168 @@
+<%@ page contentType="text/html; charset=utf-8"%>
+<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
+<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
+<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
+<%@ taglib uri="http://www.springframework.org/tags" prefix="spring"%>
+<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
+<%@taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
+<c:set var="basePath" value="${pageContext.request.contextPath}"/>
+<!DOCTYPE HTML>
+<html lang="zh-cn">
+<head>
+	<meta charset="utf-8">
+	<meta http-equiv="X-UA-Compatible" content="IE=edge">
+	<meta name="viewport" content="width=device-width, initial-scale=1">
+	<title>日志管理</title>
+	<jsp:include page="/resources/inc/head.jsp" flush="true"/>
+</head>
+<body>
+<div id="main">
+	<div id="toolbar">
+		<shiro:hasPermission name="upms:log:delete"><a class="waves-effect waves-button" href="javascript:;" onclick="deleteAction()"><i class="zmdi zmdi-close"></i> 删除日志</a></shiro:hasPermission>
+	</div>
+	<table id="table"></table>
+</div>
+<jsp:include page="/resources/inc/footer.jsp" flush="true"/>
+<script>
+var $table = $('#table');
+$(function() {
+	// bootstrap table初始化
+	$table.bootstrapTable({
+		url: '${basePath}/manage/log/list',
+		height: getHeight(),
+		striped: true,
+		search: true,
+		showRefresh: true,
+		showColumns: true,
+		minimumCountColumns: 2,
+		clickToSelect: true,
+		detailView: true,
+		detailFormatter: 'detailFormatter',
+		pagination: true,
+		paginationLoop: false,
+		sidePagination: 'server',
+		silentSort: false,
+		smartDisplay: false,
+		escape: true,
+		searchOnEnterKey: true,
+		idField: 'logId',
+		maintainSelected: true,
+		toolbar: '#toolbar',
+		columns: [
+			{field: 'ck', checkbox: true},
+			{field: 'logId', title: '编号', sortable: true, align: 'center'},
+			{field: 'description', title: '操作'},
+            {field: 'username', title: '操作用户'},
+			{field: 'startTime', title: '操作时间'},
+			{field: 'spendTime', title: '耗时'},
+			{field: 'url', title: '请求路径'},
+			{field: 'method', title: '请求类型'},
+			{field: 'parameter', title: '请求参数'},
+			{field: 'userAgent', title: '用户标识'},
+			{field: 'ip', title: 'IP地址'},
+			{field: 'permissions', title: '权限值'}
+		]
+	});
+});
+// 删除
+var deleteDialog;
+function deleteAction() {
+	var rows = $table.bootstrapTable('getSelections');
+	if (rows.length == 0) {
+		$.confirm({
+			title: false,
+			content: '请至少选择一条记录!',
+			autoClose: 'cancel|3000',
+			backgroundDismiss: true,
+			buttons: {
+				cancel: {
+					text: '取消',
+					btnClass: 'waves-effect waves-button'
+				}
+			}
+		});
+	} else {
+		deleteDialog = $.confirm({
+			type: 'red',
+			animationSpeed: 300,
+			title: false,
+			content: '确认删除该系统吗?',
+			buttons: {
+				confirm: {
+					text: '确认',
+					btnClass: 'waves-effect waves-button',
+					action: function () {
+						var ids = new Array();
+						for (var i in rows) {
+							ids.push(rows[i].logId);
+						}
+						$.ajax({
+							type: 'get',
+							url: '${basePath}/manage/log/delete/' + ids.join("-"),
+							success: function(result) {
+								if (result.code != 1) {
+									if (result.data instanceof Array) {
+										$.each(result.data, function(index, value) {
+											$.confirm({
+												theme: 'dark',
+												animation: 'rotateX',
+												closeAnimation: 'rotateX',
+												title: false,
+												content: value.errorMsg,
+												buttons: {
+													confirm: {
+														text: '确认',
+														btnClass: 'waves-effect waves-button waves-light'
+													}
+												}
+											});
+										});
+									} else {
+										$.confirm({
+											theme: 'dark',
+											animation: 'rotateX',
+											closeAnimation: 'rotateX',
+											title: false,
+											content: result.data.errorMsg,
+											buttons: {
+												confirm: {
+													text: '确认',
+													btnClass: 'waves-effect waves-button waves-light'
+												}
+											}
+										});
+									}
+								} else {
+									deleteDialog.close();
+									$table.bootstrapTable('refresh');
+								}
+							},
+							error: function(XMLHttpRequest, textStatus, errorThrown) {
+								$.confirm({
+									theme: 'dark',
+									animation: 'rotateX',
+									closeAnimation: 'rotateX',
+									title: false,
+									content: textStatus,
+									buttons: {
+										confirm: {
+											text: '确认',
+											btnClass: 'waves-effect waves-button waves-light'
+										}
+									}
+								});
+							}
+						});
+					}
+				},
+				cancel: {
+					text: '取消',
+					btnClass: 'waves-effect waves-button'
+				}
+			}
+		});
+	}
+}
+</script>
+</body>
+</html>