wyyay преди 2 години
родител
ревизия
5552783cf3

+ 111 - 0
vehicle-admin/src/main/java/com/ozs/web/controller/monitor/CacheController.java

@@ -0,0 +1,111 @@
+package com.ozs.web.controller.monitor;
+
+import com.ozs.common.constant.CacheConstants;
+import com.ozs.common.core.domain.AjaxResult;
+import com.ozs.common.utils.StringUtils;
+import com.ozs.system.domain.SysCache;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.redis.core.RedisCallback;
+import org.springframework.data.redis.core.RedisTemplate;
+import org.springframework.security.access.prepost.PreAuthorize;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.*;
+
+/**
+ * 缓存监控
+ *
+ * @author ruoyi
+ */
+@RestController
+@RequestMapping("/monitor/cache")
+public class CacheController
+{
+    @Autowired
+    private RedisTemplate<String, String> redisTemplate;
+
+    private final static List<SysCache> caches = new ArrayList<SysCache>();
+    {
+        caches.add(new SysCache(CacheConstants.LOGIN_TOKEN_KEY, "用户信息"));
+        caches.add(new SysCache(CacheConstants.SYS_CONFIG_KEY, "配置信息"));
+        caches.add(new SysCache(CacheConstants.SYS_DICT_KEY, "数据字典"));
+        caches.add(new SysCache(CacheConstants.CAPTCHA_CODE_KEY, "验证码"));
+        caches.add(new SysCache(CacheConstants.REPEAT_SUBMIT_KEY, "防重提交"));
+        caches.add(new SysCache(CacheConstants.RATE_LIMIT_KEY, "限流处理"));
+        caches.add(new SysCache(CacheConstants.PWD_ERR_CNT_KEY, "密码错误次数"));
+    }
+
+    @PreAuthorize("@ss.hasPermi('monitor:cache:list')")
+    @GetMapping()
+    public AjaxResult getInfo() throws Exception
+    {
+        Properties info = (Properties) redisTemplate.execute((RedisCallback<Object>) connection -> connection.info());
+        Properties commandStats = (Properties) redisTemplate.execute((RedisCallback<Object>) connection -> connection.info("commandstats"));
+        Object dbSize = redisTemplate.execute((RedisCallback<Object>) connection -> connection.dbSize());
+
+        Map<String, Object> result = new HashMap<>(3);
+        result.put("info", info);
+        result.put("dbSize", dbSize);
+
+        List<Map<String, String>> pieList = new ArrayList<>();
+        commandStats.stringPropertyNames().forEach(key -> {
+            Map<String, String> data = new HashMap<>(2);
+            String property = commandStats.getProperty(key);
+            data.put("name", StringUtils.removeStart(key, "cmdstat_"));
+            data.put("value", StringUtils.substringBetween(property, "calls=", ",usec"));
+            pieList.add(data);
+        });
+        result.put("commandStats", pieList);
+        return AjaxResult.success(result);
+    }
+
+    @PreAuthorize("@ss.hasPermi('monitor:cache:list')")
+    @GetMapping("/getNames")
+    public AjaxResult cache()
+    {
+        return AjaxResult.success(caches);
+    }
+
+    @PreAuthorize("@ss.hasPermi('monitor:cache:list')")
+    @GetMapping("/getKeys/{cacheName}")
+    public AjaxResult getCacheKeys(@PathVariable String cacheName)
+    {
+        Set<String> cacheKeys = redisTemplate.keys(cacheName + "*");
+        return AjaxResult.success(cacheKeys);
+    }
+
+    @PreAuthorize("@ss.hasPermi('monitor:cache:list')")
+    @GetMapping("/getValue/{cacheName}/{cacheKey}")
+    public AjaxResult getCacheValue(@PathVariable String cacheName, @PathVariable String cacheKey)
+    {
+        String cacheValue = redisTemplate.opsForValue().get(cacheKey);
+        SysCache sysCache = new SysCache(cacheName, cacheKey, cacheValue);
+        return AjaxResult.success(sysCache);
+    }
+
+    @PreAuthorize("@ss.hasPermi('monitor:cache:list')")
+    @DeleteMapping("/clearCacheName/{cacheName}")
+    public AjaxResult clearCacheName(@PathVariable String cacheName)
+    {
+        Collection<String> cacheKeys = redisTemplate.keys(cacheName + "*");
+        redisTemplate.delete(cacheKeys);
+        return AjaxResult.success();
+    }
+
+    @PreAuthorize("@ss.hasPermi('monitor:cache:list')")
+    @DeleteMapping("/clearCacheKey/{cacheKey}")
+    public AjaxResult clearCacheKey(@PathVariable String cacheKey)
+    {
+        redisTemplate.delete(cacheKey);
+        return AjaxResult.success();
+    }
+
+    @PreAuthorize("@ss.hasPermi('monitor:cache:list')")
+    @DeleteMapping("/clearCacheAll")
+    public AjaxResult clearCacheAll()
+    {
+        Collection<String> cacheKeys = redisTemplate.keys("*");
+        redisTemplate.delete(cacheKeys);
+        return AjaxResult.success();
+    }
+}

+ 27 - 0
vehicle-admin/src/main/java/com/ozs/web/controller/monitor/ServerController.java

@@ -0,0 +1,27 @@
+package com.ozs.web.controller.monitor;
+
+import com.ozs.common.core.domain.AjaxResult;
+import com.ozs.framework.web.domain.Server;
+import org.springframework.security.access.prepost.PreAuthorize;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * 服务器监控
+ *
+ * @author ruoyi
+ */
+@RestController
+@RequestMapping("/monitor/server")
+public class ServerController
+{
+    @PreAuthorize("@ss.hasPermi('monitor:server:list')")
+    @GetMapping()
+    public AjaxResult getInfo() throws Exception
+    {
+        Server server = new Server();
+        server.copyTo();
+        return AjaxResult.success(server);
+    }
+}

+ 122 - 0
vehicle-admin/src/main/java/com/ozs/web/controller/monitor/SysLoginInfoController.java

@@ -0,0 +1,122 @@
+package com.ozs.web.controller.monitor;
+
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.ozs.common.annotation.Log;
+import com.ozs.common.core.controller.BaseController;
+import com.ozs.common.core.domain.AjaxResult;
+import com.ozs.common.core.domain.vo.SysLoginInfoVo;
+import com.ozs.common.enums.BusinessType;
+import com.ozs.common.utils.poi.ExcelUtil;
+import com.ozs.framework.web.service.SysPasswordService;
+import com.ozs.system.domain.SysLoginInfo;
+import com.ozs.system.service.ISysLoginInfoService;
+import io.swagger.annotations.ApiOperation;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.security.access.prepost.PreAuthorize;
+import org.springframework.util.ObjectUtils;
+import org.springframework.web.bind.annotation.*;
+
+import javax.servlet.http.HttpServletResponse;
+import java.util.List;
+
+/**
+ * 系统访问记录
+ *
+ * @author ruoyi
+ */
+@RestController
+@RequestMapping("/monitor/logininfor")
+public class SysLoginInfoController extends BaseController {
+    @Autowired
+    private ISysLoginInfoService logininforService;
+
+    @Autowired
+    private SysPasswordService passwordService;
+
+//    @PreAuthorize("@ss.hasPermi('monitor:logininfor:list')")
+//    @GetMapping("/list")
+//    public TableDataInfo list(SysLoginInfo logininfor) {
+//        startPage();
+//        List<SysLoginInfo> list = logininforService.selectLogininforList(logininfor);
+//        return getDataTable(list);
+//    }
+
+    /**
+     * 获取登录日志分页列表
+     *
+     * @param sysLoginInfoVo
+     * @return
+     */
+    @ApiOperation(value = "获取登录日志分页列表")
+    @PostMapping("/list")
+    @PreAuthorize("@ss.hasPermi('monitor:logininfor:list')")
+    public AjaxResult list(@RequestBody SysLoginInfoVo sysLoginInfoVo) {
+        LambdaQueryWrapper<SysLoginInfo> wrapper = new LambdaQueryWrapper<SysLoginInfo>();
+        if (!ObjectUtils.isEmpty(sysLoginInfoVo.getIpaddr())) {
+            wrapper.like(SysLoginInfo::getIpaddr, sysLoginInfoVo.getIpaddr());
+        }
+        if (!ObjectUtils.isEmpty(sysLoginInfoVo.getUserName())) {
+            wrapper.like(SysLoginInfo::getUserName, sysLoginInfoVo.getUserName());
+        }
+        if (!ObjectUtils.isEmpty(sysLoginInfoVo.getStatus())) {
+            wrapper.like(SysLoginInfo::getStatus, sysLoginInfoVo.getStatus());
+        }
+        if (!ObjectUtils.isEmpty(sysLoginInfoVo.getLoginTime())) {
+            wrapper.like(SysLoginInfo::getLoginTime, sysLoginInfoVo.getLoginTime());
+        }
+        if (!ObjectUtils.isEmpty(sysLoginInfoVo.getStartTime())) {
+            wrapper.ge(SysLoginInfo::getLoginTime, sysLoginInfoVo.getStartTime());
+        }
+        if (!ObjectUtils.isEmpty(sysLoginInfoVo.getEndTime())) {
+            wrapper.le(SysLoginInfo::getLoginTime, sysLoginInfoVo.getEndTime());
+        }
+            wrapper.orderByDesc(SysLoginInfo::getLoginTime);
+        IPage<SysLoginInfo> page = logininforService.page(new Page<>(sysLoginInfoVo.getPageNum(), sysLoginInfoVo.getPageSize()), wrapper);
+        return AjaxResult.success(page);
+    }
+
+    @ApiOperation(value = "获取登录日志详细")
+    @PreAuthorize("@ss.hasPermi('monitor:logininfor:detail')")
+    @PostMapping("/detail")
+    public AjaxResult remove(Long infoId) {
+        SysLoginInfo info = logininforService.selectLoginLogById(infoId);
+        return AjaxResult.success(info);
+    }
+
+    @Log(title = "登录日志", businessType = BusinessType.EXPORT)
+    @PreAuthorize("@ss.hasPermi('monitor:logininfor:export')")
+    @PostMapping("/export")
+    public void export(HttpServletResponse response, SysLoginInfo logininfor) {
+        List<SysLoginInfo> list = logininforService.selectLogininforList(logininfor);
+        ExcelUtil<SysLoginInfo> util = new ExcelUtil<SysLoginInfo>(SysLoginInfo.class);
+        util.exportExcel(response, list, "登录日志");
+    }
+
+    @PreAuthorize("@ss.hasPermi('monitor:logininfor:remove')")
+    @Log(title = "登录日志", businessType = BusinessType.DELETE)
+    @DeleteMapping("/{infoIds}")
+    public AjaxResult remove(@PathVariable Long[] infoIds)
+    {
+        return toAjax(logininforService.deleteLogininforByIds(infoIds));
+    }
+
+    @PreAuthorize("@ss.hasPermi('monitor:logininfor:remove')")
+    @Log(title = "登录日志", businessType = BusinessType.CLEAN)
+    @DeleteMapping("/clean")
+    public AjaxResult clean()
+    {
+        logininforService.cleanLogininfor();
+        return success();
+    }
+
+    @PreAuthorize("@ss.hasPermi('monitor:logininfor:unlock')")
+    @Log(title = "账户解锁", businessType = BusinessType.OTHER)
+    @GetMapping("/unlock/{userName}")
+    public AjaxResult unlock(@PathVariable("userName") String userName)
+    {
+        passwordService.clearLoginRecordCache(userName);
+        return success();
+    }
+}

+ 116 - 0
vehicle-admin/src/main/java/com/ozs/web/controller/monitor/SysOperlogController.java

@@ -0,0 +1,116 @@
+package com.ozs.web.controller.monitor;
+
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.ozs.common.annotation.Log;
+import com.ozs.common.core.controller.BaseController;
+import com.ozs.common.core.domain.AjaxResult;
+import com.ozs.common.core.domain.vo.SysOperlogVo;
+import com.ozs.common.enums.BusinessType;
+import com.ozs.common.utils.poi.ExcelUtil;
+import com.ozs.system.domain.SysOperLog;
+import com.ozs.system.service.ISysOperLogService;
+import io.swagger.annotations.ApiOperation;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.security.access.prepost.PreAuthorize;
+import org.springframework.util.ObjectUtils;
+import org.springframework.web.bind.annotation.*;
+
+import javax.servlet.http.HttpServletResponse;
+import java.util.List;
+
+/**
+ * 操作日志记录
+ *
+ * @author ruoyi
+ */
+@RestController
+@RequestMapping("/monitor/operlog")
+public class SysOperlogController extends BaseController {
+    @Autowired
+    private ISysOperLogService operLogService;
+
+//    @PreAuthorize("@ss.hasPermi('monitor:operlog:list')")
+//    @GetMapping("/list")
+//    public TableDataInfo list(SysOperLog operLog)
+//    {
+//        startPage();
+//        List<SysOperLog> list = operLogService.selectOperLogList(operLog);
+//        return getDataTable(list);
+//    }
+
+    /**
+     * 获取操作日志分页列表
+     *
+     * @param sysOperlogVo
+     * @return
+     */
+    @PreAuthorize("@ss.hasPermi('monitor:operlog:list')")
+    @ApiOperation(value = "获取操作日志分页列表")
+    @PostMapping("/list")
+    public AjaxResult list(@RequestBody SysOperlogVo sysOperlogVo) {
+        LambdaQueryWrapper<SysOperLog> wrapper = new LambdaQueryWrapper<SysOperLog>();
+        if (!ObjectUtils.isEmpty(sysOperlogVo.getOperId())) {
+            wrapper.like(SysOperLog::getOperId, sysOperlogVo.getOperId());
+        }
+        if (!ObjectUtils.isEmpty(sysOperlogVo.getUserId())) {
+            wrapper.like(SysOperLog::getUserId, sysOperlogVo.getUserId());
+        }
+        if (!ObjectUtils.isEmpty(sysOperlogVo.getOperatorType())) {
+            wrapper.like(SysOperLog::getOperatorType, sysOperlogVo.getOperatorType());
+        }
+        if (!ObjectUtils.isEmpty(sysOperlogVo.getTitle())) {
+            wrapper.like(SysOperLog::getTitle, sysOperlogVo.getTitle());
+        }
+        if (!ObjectUtils.isEmpty(sysOperlogVo.getOperTime())) {
+            wrapper.like(SysOperLog::getOperTime, sysOperlogVo.getOperTime());
+        }
+        if (!ObjectUtils.isEmpty(sysOperlogVo.getStartTime())) {
+            wrapper.ge(SysOperLog::getOperTime, sysOperlogVo.getStartTime());
+        }
+        if (!ObjectUtils.isEmpty(sysOperlogVo.getEndTime())) {
+            wrapper.le(SysOperLog::getOperTime, sysOperlogVo.getEndTime());
+        }
+        if (!ObjectUtils.isEmpty(sysOperlogVo.getBusinessType())) {
+            wrapper.eq(SysOperLog::getBusinessType, sysOperlogVo.getBusinessType());
+        }
+            wrapper.orderByDesc(SysOperLog::getOperTime);
+        IPage<SysOperLog> page = operLogService.page(new Page<>(sysOperlogVo.getPageNum(), sysOperlogVo.getPageSize()), wrapper);
+        return AjaxResult.success(page);
+    }
+
+    @ApiOperation(value = "获取操作日志详细")
+    @PostMapping("/detail")
+    @PreAuthorize("@ss.hasPermi('monitor:operlog:detail')")
+    public AjaxResult detail(Long operId) {
+        SysOperLog sysOperLog = operLogService.selectOperLogById(operId);
+        return AjaxResult.success(sysOperLog);
+    }
+
+    @Log(title = "操作日志", businessType = BusinessType.EXPORT)
+    @PreAuthorize("@ss.hasPermi('monitor:operlog:export')")
+    @PostMapping("/export")
+    public void export(HttpServletResponse response, SysOperLog operLog) {
+        List<SysOperLog> list = operLogService.selectOperLogList(operLog);
+        ExcelUtil<SysOperLog> util = new ExcelUtil<SysOperLog>(SysOperLog.class);
+        util.exportExcel(response, list, "操作日志");
+    }
+
+    @Log(title = "操作日志", businessType = BusinessType.DELETE)
+    @PreAuthorize("@ss.hasPermi('monitor:operlog:remove')")
+    @DeleteMapping("/{operIds}")
+    public AjaxResult remove(@PathVariable Long[] operIds)
+    {
+        return toAjax(operLogService.deleteOperLogByIds(operIds));
+    }
+
+    @Log(title = "操作日志", businessType = BusinessType.CLEAN)
+    @PreAuthorize("@ss.hasPermi('monitor:operlog:remove')")
+    @DeleteMapping("/clean")
+    public AjaxResult clean()
+    {
+        operLogService.cleanOperLog();
+        return success();
+    }
+}

+ 89 - 0
vehicle-admin/src/main/java/com/ozs/web/controller/monitor/SysUserOnlineController.java

@@ -0,0 +1,89 @@
+package com.ozs.web.controller.monitor;
+
+import com.ozs.common.annotation.Log;
+import com.ozs.common.constant.CacheConstants;
+import com.ozs.common.core.controller.BaseController;
+import com.ozs.common.core.domain.AjaxResult;
+import com.ozs.common.core.domain.model.LoginUser;
+import com.ozs.common.core.page.TableDataInfo;
+import com.ozs.common.core.redis.RedisCache;
+import com.ozs.common.enums.BusinessType;
+import com.ozs.common.utils.StringUtils;
+import com.ozs.system.domain.SysUserOnline;
+import com.ozs.system.service.ISysUserOnlineService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.security.access.prepost.PreAuthorize;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * 在线用户监控
+ *
+ * @author ruoyi
+ */
+@RestController
+@RequestMapping("/monitor/online")
+public class SysUserOnlineController extends BaseController
+{
+    @Autowired
+    private ISysUserOnlineService userOnlineService;
+
+    @Autowired
+    private RedisCache redisCache;
+
+    @PreAuthorize("@ss.hasPermi('monitor:online:list')")
+    @GetMapping("/list")
+    public TableDataInfo list(String ipaddr, String userName)
+    {
+        Collection<String> keys = redisCache.keys(CacheConstants.LOGIN_TOKEN_KEY + "*");
+        List<SysUserOnline> userOnlineList = new ArrayList<SysUserOnline>();
+        for (String key : keys)
+        {
+            LoginUser user = redisCache.getCacheObject(key);
+            if (StringUtils.isNotEmpty(ipaddr) && StringUtils.isNotEmpty(userName))
+            {
+                if (StringUtils.equals(ipaddr, user.getIpaddr()) && StringUtils.equals(userName, user.getUsername()))
+                {
+                    userOnlineList.add(userOnlineService.selectOnlineByInfo(ipaddr, userName, user));
+                }
+            }
+            else if (StringUtils.isNotEmpty(ipaddr))
+            {
+                if (StringUtils.equals(ipaddr, user.getIpaddr()))
+                {
+                    userOnlineList.add(userOnlineService.selectOnlineByIpaddr(ipaddr, user));
+                }
+            }
+            else if (StringUtils.isNotEmpty(userName) && StringUtils.isNotNull(user.getUser()))
+            {
+                if (StringUtils.equals(userName, user.getUsername()))
+                {
+                    userOnlineList.add(userOnlineService.selectOnlineByUserName(userName, user));
+                }
+            }
+            else
+            {
+                userOnlineList.add(userOnlineService.loginUserToUserOnline(user));
+            }
+        }
+        Collections.reverse(userOnlineList);
+        userOnlineList.removeAll(Collections.singleton(null));
+        return getDataTable(userOnlineList);
+    }
+
+    /**
+     * 强退用户
+     */
+    @PreAuthorize("@ss.hasPermi('monitor:online:forceLogout')")
+    @Log(title = "在线用户", businessType = BusinessType.FORCE)
+    @DeleteMapping("/{tokenId}")
+    public AjaxResult forceLogout(@PathVariable String tokenId)
+    {
+        redisCache.deleteObject(CacheConstants.LOGIN_TOKEN_KEY + tokenId);
+        return success();
+    }
+}

+ 7 - 0
vehicle-admin/src/main/resources/mybatis/mybatis-config.xml

@@ -16,5 +16,12 @@ PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
         <!-- 使用驼峰命名法转换字段 -->
 		<!-- <setting name="mapUnderscoreToCamelCase" value="true"/> -->
 	</settings>
+    <plugins>
+        <!--        配置分页插件-->
+        <plugin interceptor="com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor">
+            <property name="@page" value="com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor"/>
+            <property name="page:dbType" value="MYSQL"/>
+        </plugin>
+    </plugins>
 	
 </configuration>