feat(monitor): 添加操作日志绩效统计功能

- 在SysOperLogService中新增绩效概览、人员绩效和模块排行接口
- 在SysOperLogMapper中添加模块统计、人员统计和全局概览查询方法
- 在SysOperLogMapper.xml中实现绩效相关的SQL查询和ResultMap
- 在SysOperLogServiceImpl中实现绩效统计业务逻辑和评分算法
- 创建OperModuleStatVO、OperPersonVO和OperSummaryVO数据传输对象
- 新增OperPerformanceController提供绩效统计API接口
- 添加前端performance页面实现数据可视化展示和图表渲染
This commit is contained in:
2026-07-01 15:43:26 +08:00
parent ad25227400
commit 9233d09edc
11 changed files with 1101 additions and 4 deletions

View File

@@ -0,0 +1,43 @@
package com.klp.system.domain.bo;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
/**
* 操作日志绩效查询参数
*
* @author Reasonix
*/
@Data
@NoArgsConstructor
public class OperPerformanceQuery implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 开始时间
*/
private String beginTime;
/**
* 结束时间
*/
private String endTime;
/**
* 部门名称
*/
private String deptName;
/**
* 操作人员
*/
private String operName;
/**
* 模块标题
*/
private String title;
}

View File

@@ -0,0 +1,63 @@
package com.klp.system.domain.vo;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
/**
* 模块维度统计 VO
*
* @author Reasonix
*/
@Data
@NoArgsConstructor
public class OperModuleStatVO implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 模块标题
*/
private String title;
/**
* 该模块操作总次数
*/
private Long totalCount;
/**
* 新增次数 (businessType=1)
*/
private Long addCount;
/**
* 修改次数 (businessType=2)
*/
private Long editCount;
/**
* 删除次数 (businessType=3)
*/
private Long deleteCount;
/**
* 其它次数 (businessType=0)
*/
private Long otherCount;
/**
* 成功率 (成功次数/总次数 * 100)
*/
private Double successRate;
/**
* 操作人员(用于人员-模块明细关联)
*/
private String operName;
/**
* 使用该模块的人数
*/
private Long personCount;
}

View File

@@ -0,0 +1,101 @@
package com.klp.system.domain.vo;
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
import com.alibaba.excel.annotation.ExcelProperty;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**
* 人员绩效汇总 VO含模块明细
*
* @author Reasonix
*/
@Data
@NoArgsConstructor
@ExcelIgnoreUnannotated
public class OperPersonVO implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 操作人员
*/
@ExcelProperty(value = "操作人员")
private String operName;
/**
* 部门名称
*/
@ExcelProperty(value = "部门名称")
private String deptName;
/**
* 总操作次数
*/
@ExcelProperty(value = "总操作次数")
private Long totalCount;
/**
* 成功次数
*/
@ExcelProperty(value = "成功次数")
private Long successCount;
/**
* 失败次数
*/
@ExcelProperty(value = "失败次数")
private Long failCount;
/**
* 成功率 (%)
*/
@ExcelProperty(value = "成功率(%)")
private Double successRate;
/**
* 新增次数
*/
@ExcelProperty(value = "新增次数")
private Long addCount;
/**
* 修改次数
*/
@ExcelProperty(value = "修改次数")
private Long editCount;
/**
* 删除次数
*/
@ExcelProperty(value = "删除次数")
private Long deleteCount;
/**
* 其它次数
*/
@ExcelProperty(value = "其它次数")
private Long otherCount;
/**
* 综合评分
*/
@ExcelProperty(value = "综合评分")
private Double score;
/**
* 最近操作时间
*/
@ExcelProperty(value = "最近操作时间")
private Date lastOperTime;
/**
* 该人员的模块明细列表
*/
private List<OperModuleStatVO> moduleStats = new ArrayList<>();
}

View File

@@ -0,0 +1,48 @@
package com.klp.system.domain.vo;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
/**
* 绩效概览卡片 VO
*
* @author Reasonix
*/
@Data
@NoArgsConstructor
public class OperSummaryVO implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 总操作量
*/
private Long totalOperations;
/**
* 成功操作数
*/
private Long successCount;
/**
* 失败操作数
*/
private Long failCount;
/**
* 活跃人数
*/
private Long activePersonCount;
/**
* 活跃模块数
*/
private Long activeModuleCount;
/**
* 人均操作数
*/
private Double avgPerPerson;
}

View File

@@ -2,6 +2,12 @@ package com.klp.system.mapper;
import com.klp.common.core.mapper.BaseMapperPlus;
import com.klp.system.domain.SysOperLog;
import com.klp.system.domain.bo.OperPerformanceQuery;
import com.klp.system.domain.vo.OperModuleStatVO;
import com.klp.system.domain.vo.OperPersonVO;
import com.klp.system.domain.vo.OperSummaryVO;
import java.util.List;
/**
* 操作日志 数据层
@@ -10,4 +16,23 @@ import com.klp.system.domain.SysOperLog;
*/
public interface SysOperLogMapper extends BaseMapperPlus<SysOperLogMapper, SysOperLog, SysOperLog> {
/**
* 模块全局统计
*/
List<OperModuleStatVO> selectModuleSummary(OperPerformanceQuery query);
/**
* 按人员统计
*/
List<OperPersonVO> selectPersonSummary(OperPerformanceQuery query);
/**
* 按人员-模块明细统计
*/
List<OperModuleStatVO> selectPersonModuleDetail(OperPerformanceQuery query);
/**
* 全局概览统计
*/
OperSummaryVO selectGlobalSummary(OperPerformanceQuery query);
}

View File

@@ -3,6 +3,10 @@ package com.klp.system.service;
import com.klp.common.core.domain.PageQuery;
import com.klp.common.core.page.TableDataInfo;
import com.klp.system.domain.SysOperLog;
import com.klp.system.domain.bo.OperPerformanceQuery;
import com.klp.system.domain.vo.OperModuleStatVO;
import com.klp.system.domain.vo.OperPersonVO;
import com.klp.system.domain.vo.OperSummaryVO;
import java.util.List;
@@ -50,4 +54,19 @@ public interface ISysOperLogService {
* 清空操作日志
*/
void cleanOperLog();
/**
* 绩效概览统计
*/
OperSummaryVO selectPerformanceSummary(OperPerformanceQuery query);
/**
* 人员绩效列表(含模块明细)
*/
List<OperPersonVO> selectPersonPerformance(OperPerformanceQuery query);
/**
* 模块使用排行
*/
List<OperModuleStatVO> selectModuleRanking(OperPerformanceQuery query);
}

View File

@@ -10,6 +10,10 @@ import com.klp.common.core.page.TableDataInfo;
import com.klp.common.utils.StringUtils;
import com.klp.common.utils.ip.AddressUtils;
import com.klp.system.domain.SysOperLog;
import com.klp.system.domain.bo.OperPerformanceQuery;
import com.klp.system.domain.vo.OperModuleStatVO;
import com.klp.system.domain.vo.OperPersonVO;
import com.klp.system.domain.vo.OperSummaryVO;
import com.klp.system.mapper.SysOperLogMapper;
import com.klp.system.service.ISysOperLogService;
import lombok.RequiredArgsConstructor;
@@ -17,10 +21,8 @@ import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.stream.Collectors;
/**
* 操作日志 服务层处理
@@ -138,4 +140,64 @@ public class SysOperLogServiceImpl implements ISysOperLogService {
public void cleanOperLog() {
baseMapper.delete(new LambdaQueryWrapper<>());
}
@Override
public OperSummaryVO selectPerformanceSummary(OperPerformanceQuery query) {
return baseMapper.selectGlobalSummary(query);
}
@Override
public List<OperModuleStatVO> selectModuleRanking(OperPerformanceQuery query) {
return baseMapper.selectModuleSummary(query);
}
@Override
public List<OperPersonVO> selectPersonPerformance(OperPerformanceQuery query) {
// 1. 查询人员汇总
List<OperPersonVO> personList = baseMapper.selectPersonSummary(query);
if (personList == null || personList.isEmpty()) {
return Collections.emptyList();
}
// 2. 查询人员-模块明细
List<OperModuleStatVO> allModuleDetails = baseMapper.selectPersonModuleDetail(query);
// 3. 按人员分组模块明细
Map<String, List<OperModuleStatVO>> moduleMap = Collections.emptyMap();
if (allModuleDetails != null && !allModuleDetails.isEmpty()) {
moduleMap = allModuleDetails.stream()
.collect(Collectors.groupingBy(m -> m.getOperName() != null ? m.getOperName() : ""));
}
// 4. 计算全局最大值用于评分归一化
long maxTotalCount = personList.stream()
.mapToLong(p -> p.getTotalCount() != null ? p.getTotalCount() : 0)
.max().orElse(1);
long maxModuleCount = moduleMap.values().stream()
.mapToInt(List::size)
.max().orElse(1);
// 5. 组装数据并计算综合评分
for (OperPersonVO person : personList) {
String name = person.getOperName();
List<OperModuleStatVO> details = moduleMap.getOrDefault(name, Collections.emptyList());
person.setModuleStats(details);
// 计算综合评分: 次数×40% + 成功率×30% + 模块覆盖度×30%
double countScore = (person.getTotalCount() != null ? person.getTotalCount() : 0) * 1.0 / maxTotalCount * 40;
double successScore = (person.getSuccessRate() != null ? person.getSuccessRate() : 0) / 100.0 * 30;
double moduleScore = (maxModuleCount > 0 ? details.size() * 1.0 / maxModuleCount : 0) * 30;
double score = Math.round((countScore + successScore + moduleScore) * 100.0) / 100.0;
person.setScore(score);
}
// 6. 按评分降序排序
personList.sort((a, b) -> {
double sa = a.getScore() != null ? a.getScore() : 0;
double sb = b.getScore() != null ? b.getScore() : 0;
return Double.compare(sb, sa);
});
return personList;
}
}

View File

@@ -23,4 +23,173 @@
<result property="operTime" column="oper_time"/>
</resultMap>
<!-- 绩效相关 ResultMap -->
<resultMap type="com.klp.system.domain.vo.OperPersonVO" id="OperPersonResult">
<result property="operName" column="oper_name"/>
<result property="deptName" column="dept_name"/>
<result property="totalCount" column="total_count"/>
<result property="successCount" column="success_count"/>
<result property="failCount" column="fail_count"/>
<result property="successRate" column="success_rate"/>
<result property="addCount" column="add_count"/>
<result property="editCount" column="edit_count"/>
<result property="deleteCount" column="delete_count"/>
<result property="otherCount" column="other_count"/>
<result property="lastOperTime" column="last_oper_time"/>
</resultMap>
<resultMap type="com.klp.system.domain.vo.OperModuleStatVO" id="OperModuleStatResult">
<result property="operName" column="oper_name"/>
<result property="title" column="title"/>
<result property="totalCount" column="total_count"/>
<result property="addCount" column="add_count"/>
<result property="editCount" column="edit_count"/>
<result property="deleteCount" column="delete_count"/>
<result property="otherCount" column="other_count"/>
<result property="successRate" column="success_rate"/>
<result property="personCount" column="person_count"/>
</resultMap>
<resultMap type="com.klp.system.domain.vo.OperSummaryVO" id="OperSummaryResult">
<result property="totalOperations" column="total_operations"/>
<result property="successCount" column="success_count"/>
<result property="failCount" column="fail_count"/>
<result property="activePersonCount" column="active_person_count"/>
<result property="activeModuleCount" column="active_module_count"/>
<result property="avgPerPerson" column="avg_per_person"/>
</resultMap>
<!-- ========== 绩效聚合查询 ========== -->
<!-- 按模块全局统计 -->
<select id="selectModuleSummary" parameterType="com.klp.system.domain.bo.OperPerformanceQuery" resultMap="OperModuleStatResult">
SELECT
l.title,
COUNT(1) AS total_count,
SUM(CASE WHEN l.business_type = 1 THEN 1 ELSE 0 END) AS add_count,
SUM(CASE WHEN l.business_type = 2 THEN 1 ELSE 0 END) AS edit_count,
SUM(CASE WHEN l.business_type = 3 THEN 1 ELSE 0 END) AS delete_count,
SUM(CASE WHEN l.business_type = 0 THEN 1 ELSE 0 END) AS other_count,
ROUND(SUM(CASE WHEN l.status = 0 THEN 1 ELSE 0 END) * 100.0 / COUNT(1), 2) AS success_rate,
COUNT(DISTINCT l.oper_name) AS person_count
FROM sys_oper_log l
<where>
<if test="beginTime != null and beginTime != ''">
AND l.oper_time &gt;= #{beginTime}
</if>
<if test="endTime != null and endTime != ''">
AND l.oper_time &lt;= #{endTime}
</if>
<if test="deptName != null and deptName != ''">
AND l.dept_name LIKE CONCAT('%', #{deptName}, '%')
</if>
<if test="operName != null and operName != ''">
AND l.oper_name LIKE CONCAT('%', #{operName}, '%')
</if>
<if test="title != null and title != ''">
AND l.title LIKE CONCAT('%', #{title}, '%')
</if>
</where>
GROUP BY l.title
ORDER BY total_count DESC
</select>
<!-- 按人员统计 -->
<select id="selectPersonSummary" parameterType="com.klp.system.domain.bo.OperPerformanceQuery" resultMap="OperPersonResult">
SELECT
l.oper_name,
l.dept_name,
COUNT(1) AS total_count,
SUM(CASE WHEN l.status = 0 THEN 1 ELSE 0 END) AS success_count,
SUM(CASE WHEN l.status = 1 THEN 1 ELSE 0 END) AS fail_count,
ROUND(SUM(CASE WHEN l.status = 0 THEN 1 ELSE 0 END) * 100.0 / COUNT(1), 2) AS success_rate,
SUM(CASE WHEN l.business_type = 1 THEN 1 ELSE 0 END) AS add_count,
SUM(CASE WHEN l.business_type = 2 THEN 1 ELSE 0 END) AS edit_count,
SUM(CASE WHEN l.business_type = 3 THEN 1 ELSE 0 END) AS delete_count,
SUM(CASE WHEN l.business_type = 0 THEN 1 ELSE 0 END) AS other_count,
MAX(l.oper_time) AS last_oper_time
FROM sys_oper_log l
<where>
<if test="beginTime != null and beginTime != ''">
AND l.oper_time &gt;= #{beginTime}
</if>
<if test="endTime != null and endTime != ''">
AND l.oper_time &lt;= #{endTime}
</if>
<if test="deptName != null and deptName != ''">
AND l.dept_name LIKE CONCAT('%', #{deptName}, '%')
</if>
<if test="operName != null and operName != ''">
AND l.oper_name LIKE CONCAT('%', #{operName}, '%')
</if>
<if test="title != null and title != ''">
AND l.title LIKE CONCAT('%', #{title}, '%')
</if>
</where>
GROUP BY l.oper_name, l.dept_name
ORDER BY total_count DESC
</select>
<!-- 按人员-模块明细统计 -->
<select id="selectPersonModuleDetail" parameterType="com.klp.system.domain.bo.OperPerformanceQuery" resultMap="OperModuleStatResult">
SELECT
l.oper_name,
l.title,
COUNT(1) AS total_count,
SUM(CASE WHEN l.business_type = 1 THEN 1 ELSE 0 END) AS add_count,
SUM(CASE WHEN l.business_type = 2 THEN 1 ELSE 0 END) AS edit_count,
SUM(CASE WHEN l.business_type = 3 THEN 1 ELSE 0 END) AS delete_count,
SUM(CASE WHEN l.business_type = 0 THEN 1 ELSE 0 END) AS other_count,
ROUND(SUM(CASE WHEN l.status = 0 THEN 1 ELSE 0 END) * 100.0 / COUNT(1), 2) AS success_rate
FROM sys_oper_log l
<where>
<if test="beginTime != null and beginTime != ''">
AND l.oper_time &gt;= #{beginTime}
</if>
<if test="endTime != null and endTime != ''">
AND l.oper_time &lt;= #{endTime}
</if>
<if test="deptName != null and deptName != ''">
AND l.dept_name LIKE CONCAT('%', #{deptName}, '%')
</if>
<if test="operName != null and operName != ''">
AND l.oper_name LIKE CONCAT('%', #{operName}, '%')
</if>
<if test="title != null and title != ''">
AND l.title LIKE CONCAT('%', #{title}, '%')
</if>
</where>
GROUP BY l.oper_name, l.title
ORDER BY l.oper_name, total_count DESC
</select>
<!-- 全局概览统计 -->
<select id="selectGlobalSummary" parameterType="com.klp.system.domain.bo.OperPerformanceQuery" resultMap="OperSummaryResult">
SELECT
COUNT(1) AS total_operations,
SUM(CASE WHEN l.status = 0 THEN 1 ELSE 0 END) AS success_count,
SUM(CASE WHEN l.status = 1 THEN 1 ELSE 0 END) AS fail_count,
COUNT(DISTINCT l.oper_name) AS active_person_count,
COUNT(DISTINCT l.title) AS active_module_count,
ROUND(COUNT(1) * 1.0 / NULLIF(COUNT(DISTINCT l.oper_name), 0), 2) AS avg_per_person
FROM sys_oper_log l
<where>
<if test="beginTime != null and beginTime != ''">
AND l.oper_time &gt;= #{beginTime}
</if>
<if test="endTime != null and endTime != ''">
AND l.oper_time &lt;= #{endTime}
</if>
<if test="deptName != null and deptName != ''">
AND l.dept_name LIKE CONCAT('%', #{deptName}, '%')
</if>
<if test="operName != null and operName != ''">
AND l.oper_name LIKE CONCAT('%', #{operName}, '%')
</if>
<if test="title != null and title != ''">
AND l.title LIKE CONCAT('%', #{title}, '%')
</if>
</where>
</select>
</mapper>