mirror of
http://git.pig4cloud.com/pig/pigx.git
synced 2026-11-08 04:39:00 +08:00
ref: 日志管理增加图表展示接口,方便用户查看使用
This commit is contained in:
1 parent
936acbb716
commit
3e1d96f9b1
5 files changed
+76
-3
No files matched your search
+10
-1
@@ -31,13 +31,13 @@ import com.pig4cloud.pigx.common.excel.annotation.ResponseExcel;
|
||||
import com.pig4cloud.pigx.common.security.annotation.Inner;
|
||||
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.validation.Valid;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springdoc.core.annotations.ParameterObject;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import jakarta.validation.Valid;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
@@ -69,6 +69,15 @@ public class SysLogController {
|
||||
return R.ok(sysLogService.getLogByPage(page, sysLog));
|
||||
}
|
||||
|
||||
/**
|
||||
* 统计三十天内的数据
|
||||
* @return R
|
||||
*/
|
||||
@GetMapping("/sum")
|
||||
public R getLogSum() {
|
||||
return R.ok(sysLogService.getLogSum());
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除日志
|
||||
* @param ids ID
|
||||
|
||||
+9
@@ -23,6 +23,9 @@ import com.pig4cloud.pigx.admin.api.entity.SysLog;
|
||||
import com.pig4cloud.pigx.common.data.datascope.PigxBaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 日志表 Mapper 接口
|
||||
@@ -34,4 +37,10 @@ import org.apache.ibatis.annotations.Mapper;
|
||||
@Mapper
|
||||
public interface SysLogMapper extends PigxBaseMapper<SysLog> {
|
||||
|
||||
/**
|
||||
* 通过日志类型统计日志总数 返回一个包含日志类型和日志总数的列表
|
||||
* @return List<Map<String, Object>>
|
||||
*/
|
||||
List<Map<String, Object>> selectLogSumByType();
|
||||
|
||||
}
|
||||
+7
@@ -26,6 +26,7 @@ import com.pig4cloud.pigx.admin.api.entity.SysLog;
|
||||
import com.pig4cloud.pigx.admin.api.vo.PreLogVO;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -59,4 +60,10 @@ public interface SysLogService extends IService<SysLog> {
|
||||
*/
|
||||
Boolean saveLog(SysLogDTO sysLog);
|
||||
|
||||
/**
|
||||
* sum 函数计算三十天内的数据
|
||||
* @return list map
|
||||
*/
|
||||
List<Map<String, Object>> getLogSum();
|
||||
|
||||
}
|
||||
+12
-2
@@ -30,15 +30,16 @@ import com.pig4cloud.pigx.admin.api.entity.SysLog;
|
||||
import com.pig4cloud.pigx.admin.api.vo.PreLogVO;
|
||||
import com.pig4cloud.pigx.admin.mapper.SysLogMapper;
|
||||
import com.pig4cloud.pigx.admin.service.SysLogService;
|
||||
import com.pig4cloud.pigx.common.core.constant.CommonConstants;
|
||||
import com.pig4cloud.pigx.common.data.tenant.TenantBroker;
|
||||
import com.pig4cloud.pigx.common.data.tenant.TenantContextHolder;
|
||||
import com.pig4cloud.pigx.common.log.util.LogTypeEnum;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
@@ -61,7 +62,7 @@ public class SysLogServiceImpl extends ServiceImpl<SysLogMapper, SysLog> impleme
|
||||
public Boolean saveBatchLogs(List<PreLogVO> preLogVoList) {
|
||||
List<SysLog> sysLogs = preLogVoList.stream().map(pre -> {
|
||||
SysLog log = new SysLog();
|
||||
log.setLogType(CommonConstants.STATUS_LOCK);
|
||||
log.setLogType(LogTypeEnum.ERROR.getType());
|
||||
log.setTitle(pre.getInfo());
|
||||
log.setException(pre.getStack());
|
||||
log.setParams(pre.getMessage());
|
||||
@@ -106,4 +107,13 @@ public class SysLogServiceImpl extends ServiceImpl<SysLogMapper, SysLog> impleme
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* sum 函数计算三十天内的数据
|
||||
* @return list map
|
||||
*/
|
||||
@Override
|
||||
public List<Map<String, Object>> getLogSum() {
|
||||
return baseMapper.selectLogSumByType();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
~
|
||||
~ Copyright (c) 2018-2025, lengleng All rights reserved.
|
||||
~
|
||||
~ Redistribution and use in source and binary forms, with or without
|
||||
~ modification, are permitted provided that the following conditions are met:
|
||||
~
|
||||
~ Redistributions of source code must retain the above copyright notice,
|
||||
~ this list of conditions and the following disclaimer.
|
||||
~ Redistributions in binary form must reproduce the above copyright
|
||||
~ notice, this list of conditions and the following disclaimer in the
|
||||
~ documentation and/or other materials provided with the distribution.
|
||||
~ Neither the name of the pig4cloud.com developer nor the names of its
|
||||
~ contributors may be used to endorse or promote products derived from
|
||||
~ this software without specific prior written permission.
|
||||
~ Author: lengleng (wangiegie@gmail.com)
|
||||
~
|
||||
-->
|
||||
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.pig4cloud.pigx.admin.mapper.SysLogMapper">
|
||||
|
||||
<select id="selectLogSumByType" resultType="java.util.Map">
|
||||
SELECT
|
||||
DATE(create_time) AS log_date,
|
||||
SUM(CASE WHEN log_type = '0' THEN 1 ELSE 0 END) AS successful_count,
|
||||
SUM(CASE WHEN log_type = '9' THEN 1 ELSE 0 END) AS failed_count
|
||||
FROM
|
||||
sys_log
|
||||
WHERE
|
||||
create_time >= CURDATE() - INTERVAL 30 DAY
|
||||
GROUP BY
|
||||
log_date
|
||||
ORDER BY
|
||||
log_date;
|
||||
</select>
|
||||
</mapper>
|
||||
Reference in new issue
Block a user