Browse Source

操作日志统计分析功能

wukai 2 years ago
parent
commit
394a620cbf

+ 33 - 0
doc-admin/src/main/java/com/doc/web/controller/monitor/SysOperlogController.java

@@ -3,17 +3,23 @@ package com.doc.web.controller.monitor;
 import com.doc.common.annotation.Log;
 import com.doc.common.core.controller.BaseController;
 import com.doc.common.core.domain.AjaxResult;
+import com.doc.common.core.domain.entity.SysDictData;
 import com.doc.common.core.page.TableDataInfo;
 import com.doc.common.enums.BusinessType;
 import com.doc.common.utils.poi.ExcelUtil;
 import com.doc.system.domain.SysOperLog;
+import com.doc.system.domain.vo.LogCalcVO;
+import com.doc.system.service.ISysDictTypeService;
 import com.doc.system.service.ISysOperLogService;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.web.bind.annotation.*;
 
 import javax.annotation.Resource;
 import javax.servlet.http.HttpServletResponse;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
 
 /**
  * 操作日志记录
@@ -25,6 +31,8 @@ import java.util.List;
 public class SysOperlogController extends BaseController {
     @Resource
     private ISysOperLogService operLogService;
+    @Resource
+    private ISysDictTypeService dictTypeService;
 
     @PreAuthorize("@ss.hasPermi('monitor:operlog:list')")
     @GetMapping("/list")
@@ -34,6 +42,31 @@ public class SysOperlogController extends BaseController {
         return getDataTable(list);
     }
 
+    @PreAuthorize("@ss.hasPermi('monitor:operlog:calc')")
+    @GetMapping("/calc")
+    public TableDataInfo calc(SysOperLog operLog) {
+        List<LogCalcVO> list = operLogService.selectOperLogCalc(operLog);
+        return getDataTable(list);
+    }
+
+    @PreAuthorize("@ss.hasPermi('monitor:operlog:anal')")
+    @GetMapping("/anal")
+    public AjaxResult anal(SysOperLog operLog) {
+        List<SysDictData> dict = dictTypeService.selectDictDataByType("sys_oper_type");
+        Map<String, String> dictMap = dict.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));
+        List<Map<String, Object>> typeList = operLogService.selectTypeCalc(operLog);
+        typeList.stream().forEach(pie -> {
+            String s = String.valueOf(pie.get("business_type"));
+            pie.put("name", dictMap.get(s));
+        });
+
+        List<Map<String, Object>> timeList = operLogService.selectTimeCalc(operLog);
+        Map<String, Object> result = new HashMap<>(4);
+        result.put("pie", typeList);
+        result.put("line", timeList);
+        return AjaxResult.success(result);
+    }
+
     @Log(title = "操作日志", businessType = BusinessType.EXPORT)
     @PreAuthorize("@ss.hasPermi('monitor:operlog:export')")
     @PostMapping("/export")

+ 1 - 1
doc-common/src/main/java/com/doc/common/utils/encrypt/Sm3Util.java

@@ -30,7 +30,7 @@ public class Sm3Util {
     }
 
     public static void main(String[] args) throws Exception {
-        String message = "1234567";
+        String message = "1qaz@WSX";
         String en1 = encrypt(message);
         String en2 = SecurityUtils.encryptPassword(en1);
         System.out.println("SM3 Digest 1: " + en1);

+ 46 - 0
doc-system/src/main/java/com/doc/system/domain/vo/LogCalcVO.java

@@ -0,0 +1,46 @@
+package com.doc.system.domain.vo;
+
+import lombok.Data;
+
+/**
+ * 操作日志记录表 oper_log
+ *
+ * @author ruoyi
+ */
+@Data
+public class LogCalcVO {
+    private static final long serialVersionUID = 1L;
+
+    /**
+     * 操作模块
+     */
+    private String title;
+    private Integer eventType;
+    private Integer eventLevel;
+
+    /**
+     * 业务类型(0其它 1新增 2修改 3删除)
+     */
+    private Integer businessType;
+
+    /**
+     * 操作人员
+     */
+    private String operName;
+
+
+    /**
+     * 操作地址
+     */
+    private String operIp;
+
+    /**
+     * 操作状态(0正常 1异常)
+     */
+    private Integer status;
+
+    /**
+     * 操作次数
+     */
+    private Long times;
+}

+ 38 - 7
doc-system/src/main/java/com/doc/system/mapper/SysOperLogMapper.java

@@ -1,26 +1,28 @@
 package com.doc.system.mapper;
 
 import com.doc.system.domain.SysOperLog;
+import com.doc.system.domain.vo.LogAnalVO;
+import com.doc.system.domain.vo.LogCalcVO;
 
 import java.util.List;
+import java.util.Map;
 
 /**
  * 操作日志 数据层
- * 
+ *
  * @author ruoyi
  */
-public interface SysOperLogMapper
-{
+public interface SysOperLogMapper {
     /**
      * 新增操作日志
-     * 
+     *
      * @param operLog 操作日志对象
      */
     public void insertOperlog(SysOperLog operLog);
 
     /**
      * 查询系统操作日志集合
-     * 
+     *
      * @param operLog 操作日志对象
      * @return 操作日志集合
      */
@@ -28,7 +30,7 @@ public interface SysOperLogMapper
 
     /**
      * 批量删除系统操作日志
-     * 
+     *
      * @param operIds 需要删除的操作日志ID
      * @return 结果
      */
@@ -36,7 +38,7 @@ public interface SysOperLogMapper
 
     /**
      * 查询操作日志详细
-     * 
+     *
      * @param operId 操作ID
      * @return 操作日志对象
      */
@@ -46,4 +48,33 @@ public interface SysOperLogMapper
      * 清空操作日志
      */
     public void cleanOperLog();
+
+    /**
+     * 统计
+     *
+     * @param operLog
+     * @return
+     */
+    List<LogCalcVO> selectOperLogCalc(SysOperLog operLog);
+
+    /**
+     * 分析
+     *
+     * @param operLog
+     * @return
+     */
+    List<LogAnalVO> selectOperLogAnal(SysOperLog operLog);
+    /**
+     * 查询按类型统计数据
+     * @param operLog input
+     * @return 结果集
+     */
+    List<Map<String, Object>> selectTypeCalc(SysOperLog operLog);
+    /**
+     * 查询按时间统计数据
+     *
+     * @param operLog input
+     * @return 结果集
+     */
+    List<Map<String, Object>> selectTimeCalc(SysOperLog operLog);
 }

+ 28 - 0
doc-system/src/main/java/com/doc/system/service/ISysOperLogService.java

@@ -1,8 +1,11 @@
 package com.doc.system.service;
 
 import com.doc.system.domain.SysOperLog;
+import com.doc.system.domain.vo.LogAnalVO;
+import com.doc.system.domain.vo.LogCalcVO;
 
 import java.util.List;
+import java.util.Map;
 
 /**
  * 操作日志 服务层
@@ -46,4 +49,29 @@ public interface ISysOperLogService
      * 清空操作日志
      */
     public void cleanOperLog();
+
+    /**
+     * 查询统计数据
+     * @param operLog input
+     * @return 结果集
+     */
+    List<LogCalcVO> selectOperLogCalc(SysOperLog operLog);
+    /**
+     * 查询分析数据
+     * @param operLog input
+     * @return 结果集
+     */
+    List<LogAnalVO> selectOperLogAnal(SysOperLog operLog);
+    /**
+     * 查询按类型统计数据
+     * @param operLog input
+     * @return 结果集
+     */
+    List<Map<String, Object>> selectTypeCalc(SysOperLog operLog);
+    /**
+     * 查询按时间统计数据
+     * @param operLog input
+     * @return 结果集
+     */
+    List<Map<String, Object>> selectTimeCalc(SysOperLog operLog);
 }

+ 47 - 0
doc-system/src/main/java/com/doc/system/service/impl/SysOperLogServiceImpl.java

@@ -1,12 +1,15 @@
 package com.doc.system.service.impl;
 
 import com.doc.system.domain.SysOperLog;
+import com.doc.system.domain.vo.LogAnalVO;
+import com.doc.system.domain.vo.LogCalcVO;
 import com.doc.system.mapper.SysOperLogMapper;
 import com.doc.system.service.ISysOperLogService;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
 import java.util.List;
+import java.util.Map;
 
 /**
  * 操作日志 服务层处理
@@ -68,4 +71,48 @@ public class SysOperLogServiceImpl implements ISysOperLogService {
     public void cleanOperLog() {
         operLogMapper.cleanOperLog();
     }
+
+    /**
+     * 查询统计数据
+     *
+     * @param operLog input
+     * @return 结果集
+     */
+    @Override
+    public List<LogCalcVO> selectOperLogCalc(SysOperLog operLog) {
+        return operLogMapper.selectOperLogCalc(operLog);
+    }
+
+    /**
+     * 查询分析数据
+     *
+     * @param operLog input
+     * @return 结果集
+     */
+    @Override
+    public List<LogAnalVO> selectOperLogAnal(SysOperLog operLog) {
+        return operLogMapper.selectOperLogAnal(operLog);
+    }
+
+    /**
+     * 查询按类型统计数据
+     *
+     * @param operLog input
+     * @return 结果集
+     */
+    @Override
+    public List<Map<String, Object>> selectTypeCalc(SysOperLog operLog) {
+        return operLogMapper.selectTypeCalc(operLog);
+    }
+
+    /**
+     * 查询按时间统计数据
+     *
+     * @param operLog input
+     * @return 结果集
+     */
+    @Override
+    public List<Map<String, Object>> selectTimeCalc(SysOperLog operLog) {
+        return operLogMapper.selectTimeCalc(operLog);
+    }
 }

+ 122 - 0
doc-system/src/main/resources/mapper/system/SysOperLogMapper.xml

@@ -106,6 +106,128 @@
         <include refid="selectOperLogVo"/>
         where oper_id = #{operId}
     </select>
+    <select id="selectOperLogCalc" resultType="com.doc.system.domain.vo.LogCalcVO">
+        select
+        operator_type,
+        business_type,
+        oper_name,
+        oper_ip,
+        sum(1) times
+        from sys_oper_log
+        <where>
+            <if test="title != null and title != ''">
+                AND title like concat('%', #{title}, '%')
+            </if>
+            <if test="eventType != null">
+                AND event_type = #{eventType}
+            </if>
+            <if test="eventLevel != null">
+                AND event_level = #{eventLevel}
+            </if>
+            <if test="businessType != null">
+                AND business_type = #{businessType}
+            </if>
+            <if test="businessTypes != null and businessTypes.length > 0">
+                AND business_type in
+                <foreach collection="businessTypes" item="businessType" open="(" separator="," close=")">
+                    #{businessType}
+                </foreach>
+            </if>
+            <if test="status != null">
+                AND status = #{status}
+            </if>
+            <if test="operName != null and operName != ''">
+                AND oper_name like concat('%', #{operName}, '%')
+            </if>
+            <if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 -->
+                AND oper_time &gt;= #{params.beginTime}
+            </if>
+            <if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->
+                AND oper_time &lt;= #{params.endTime}
+            </if>
+        </where>
+        group by event_type, business_type, oper_name, oper_ip
+    </select>
+    <select id="selectOperLogAnal" resultType="com.doc.system.domain.vo.LogAnalVO"></select>
+    <select id="selectTypeCalc" resultType="java.util.Map">
+        select
+        business_type,
+        sum(1) value
+        from sys_oper_log
+        <where>
+            <if test="title != null and title != ''">
+                AND title like concat('%', #{title}, '%')
+            </if>
+            <if test="eventType != null">
+                AND event_type = #{eventType}
+            </if>
+            <if test="eventLevel != null">
+                AND event_level = #{eventLevel}
+            </if>
+            <if test="businessType != null">
+                AND business_type = #{businessType}
+            </if>
+            <if test="businessTypes != null and businessTypes.length > 0">
+                AND business_type in
+                <foreach collection="businessTypes" item="businessType" open="(" separator="," close=")">
+                    #{businessType}
+                </foreach>
+            </if>
+            <if test="status != null">
+                AND status = #{status}
+            </if>
+            <if test="operName != null and operName != ''">
+                AND oper_name like concat('%', #{operName}, '%')
+            </if>
+            <if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 -->
+                AND oper_time &gt;= #{params.beginTime}
+            </if>
+            <if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->
+                AND oper_time &lt;= #{params.endTime}
+            </if>
+        </where>
+        group by business_type
+    </select>
+    <select id="selectTimeCalc" resultType="java.util.Map">
+        select
+        DATE_FORMAT(oper_time, '%H') name,
+        sum(1) value
+        from sys_oper_log
+        <where>
+            <if test="title != null and title != ''">
+                AND title like concat('%', #{title}, '%')
+            </if>
+            <if test="eventType != null">
+                AND event_type = #{eventType}
+            </if>
+            <if test="eventLevel != null">
+                AND event_level = #{eventLevel}
+            </if>
+            <if test="businessType != null">
+                AND business_type = #{businessType}
+            </if>
+            <if test="businessTypes != null and businessTypes.length > 0">
+                AND business_type in
+                <foreach collection="businessTypes" item="businessType" open="(" separator="," close=")">
+                    #{businessType}
+                </foreach>
+            </if>
+            <if test="status != null">
+                AND status = #{status}
+            </if>
+            <if test="operName != null and operName != ''">
+                AND oper_name like concat('%', #{operName}, '%')
+            </if>
+            <if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 -->
+                AND oper_time &gt;= #{params.beginTime}
+            </if>
+            <if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->
+                AND oper_time &lt;= #{params.endTime}
+            </if>
+        </where>
+        group by DATE_FORMAT(oper_time, '%H')
+        order by name
+    </select>
 
     <update id="cleanOperLog">
         truncate table sys_oper_log