🔨 基础模块统计.
This commit is contained in:
@@ -0,0 +1,148 @@
|
||||
/*
|
||||
* Copyright (c) 2023 - present Dromara, All rights reserved.
|
||||
*
|
||||
* https://visor.dromara.org
|
||||
* https://visor.dromara.org.cn
|
||||
* https://visor.orionsec.cn
|
||||
*
|
||||
* Members:
|
||||
* Jiahang Li - ljh1553488six@139.com - author
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.dromara.visor.framework.common.entity;
|
||||
|
||||
import cn.orionsec.kit.lang.utils.collect.Lists;
|
||||
import cn.orionsec.kit.lang.utils.time.DateStream;
|
||||
import cn.orionsec.kit.lang.utils.time.Dates;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 统计区间枚举
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2024/12/23 14:02
|
||||
*/
|
||||
public enum StatisticsRange {
|
||||
|
||||
/**
|
||||
* 当天
|
||||
*/
|
||||
TODAY {
|
||||
@Override
|
||||
public Date getRangeEndTime(Date startTime) {
|
||||
return DateStream.of(startTime)
|
||||
.dayEnd()
|
||||
.date();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getDateRanges(Date startTime) {
|
||||
return Lists.singleton(Dates.format(startTime, Dates.YMD));
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* 日视图
|
||||
*/
|
||||
DAY {
|
||||
@Override
|
||||
public Date getRangeEndTime(Date startTime) {
|
||||
return DateStream.of(startTime)
|
||||
.dayEnd()
|
||||
.date();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getDateRanges(Date startTime) {
|
||||
return Lists.singleton(Dates.format(startTime, Dates.YMD));
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* 周视图
|
||||
*/
|
||||
WEEK {
|
||||
@Override
|
||||
public Date getRangeEndTime(Date startTime) {
|
||||
return DateStream.of(startTime)
|
||||
.addDay(7)
|
||||
.dayEnd()
|
||||
.date();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getDateRanges(Date startTime) {
|
||||
return Arrays.stream(Dates.getIncrementDayDates(startTime, 1, 7))
|
||||
.map(s -> Dates.format(s, Dates.YMD))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* 月视图
|
||||
*/
|
||||
MONTH {
|
||||
@Override
|
||||
public Date getRangeEndTime(Date startTime) {
|
||||
return DateStream.of(startTime)
|
||||
.addMonth(1)
|
||||
.dayEnd()
|
||||
.date();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getDateRanges(Date startTime) {
|
||||
int monthLastDay = Dates.getMonthLastDay(startTime);
|
||||
return Arrays.stream(Dates.getIncrementDayDates(startTime, 1, monthLastDay - 1))
|
||||
.map(s -> Dates.format(s, Dates.YMD))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
},
|
||||
|
||||
;
|
||||
|
||||
/**
|
||||
* 获取区间结束时间
|
||||
*
|
||||
* @param startTime startTime
|
||||
* @return end
|
||||
*/
|
||||
public abstract Date getRangeEndTime(Date startTime);
|
||||
|
||||
/**
|
||||
* 获取时间区间
|
||||
*
|
||||
* @param startTime startTime
|
||||
* @return ranges
|
||||
*/
|
||||
public abstract List<String> getDateRanges(Date startTime);
|
||||
|
||||
public static StatisticsRange of(String type) {
|
||||
if (type == null) {
|
||||
return TODAY;
|
||||
}
|
||||
for (StatisticsRange value : values()) {
|
||||
if (value.name().equals(type)) {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
return TODAY;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright (c) 2023 - present Dromara, All rights reserved.
|
||||
*
|
||||
* https://visor.dromara.org
|
||||
* https://visor.dromara.org.cn
|
||||
* https://visor.orionsec.cn
|
||||
*
|
||||
* Members:
|
||||
* Jiahang Li - ljh1553488six@139.com - author
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.dromara.visor.framework.common.entity.chart;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 柱状图图单系列数据
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2024/12/23 13:42
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Schema(name = "BarSingleChartData", description = "柱状图图单系列数据")
|
||||
public class BarSingleChartData {
|
||||
|
||||
@Schema(description = "数据")
|
||||
private Map<String, Integer> data;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright (c) 2023 - present Dromara, All rights reserved.
|
||||
*
|
||||
* https://visor.dromara.org
|
||||
* https://visor.dromara.org.cn
|
||||
* https://visor.orionsec.cn
|
||||
*
|
||||
* Members:
|
||||
* Jiahang Li - ljh1553488six@139.com - author
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.dromara.visor.framework.common.entity.chart;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 折线图多系列数据
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2024/12/23 13:41
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Schema(name = "LineChartData", description = "折线图多系列数据")
|
||||
public class LineChartData {
|
||||
|
||||
@Schema(description = "x轴")
|
||||
private List<String> x;
|
||||
|
||||
@Schema(description = "数据")
|
||||
private Map<String, List<Integer>> data;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright (c) 2023 - present Dromara, All rights reserved.
|
||||
*
|
||||
* https://visor.dromara.org
|
||||
* https://visor.dromara.org.cn
|
||||
* https://visor.orionsec.cn
|
||||
*
|
||||
* Members:
|
||||
* Jiahang Li - ljh1553488six@139.com - author
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.dromara.visor.framework.common.entity.chart;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 折线图单系列数据
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2024/12/23 13:42
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Schema(name = "LineSingleChartData", description = "折线图单系列数据")
|
||||
public class LineSingleChartData {
|
||||
|
||||
@Schema(description = "x轴")
|
||||
private List<String> x;
|
||||
|
||||
@Schema(description = "数据")
|
||||
private List<Integer> data;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright (c) 2023 - present Dromara, All rights reserved.
|
||||
*
|
||||
* https://visor.dromara.org
|
||||
* https://visor.dromara.org.cn
|
||||
* https://visor.orionsec.cn
|
||||
*
|
||||
* Members:
|
||||
* Jiahang Li - ljh1553488six@139.com - author
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.dromara.visor.framework.common.entity.chart;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 饼图数据
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2024/12/23 13:42
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Schema(name = "PieChartData", description = "饼图数据")
|
||||
public class PieChartData {
|
||||
|
||||
@Schema(description = "数据")
|
||||
private Map<String, Integer> data;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Copyright (c) 2023 - present Dromara, All rights reserved.
|
||||
*
|
||||
* https://visor.dromara.org
|
||||
* https://visor.dromara.org.cn
|
||||
* https://visor.orionsec.cn
|
||||
*
|
||||
* Members:
|
||||
* Jiahang Li - ljh1553488six@139.com - author
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.dromara.visor.module.infra.controller;
|
||||
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.dromara.visor.framework.log.core.annotation.IgnoreLog;
|
||||
import org.dromara.visor.framework.log.core.enums.IgnoreLogMode;
|
||||
import org.dromara.visor.framework.web.core.annotation.RestWrapper;
|
||||
import org.dromara.visor.module.infra.entity.vo.InfraWorkplaceStatisticsVO;
|
||||
import org.dromara.visor.module.infra.service.InfraStatisticsService;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* infra - 统计服务
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2024/12/23 16:07
|
||||
*/
|
||||
@Tag(name = "infra - 统计服务")
|
||||
@Slf4j
|
||||
@Validated
|
||||
@RestWrapper
|
||||
@RestController
|
||||
@RequestMapping("/infra/statistics")
|
||||
public class InfraStatisticsController {
|
||||
|
||||
@Resource
|
||||
private InfraStatisticsService infraStatisticsService;
|
||||
|
||||
@IgnoreLog(IgnoreLogMode.RET)
|
||||
@GetMapping("/get-workplace")
|
||||
@Operation(summary = "查询工作台统计信息")
|
||||
public InfraWorkplaceStatisticsVO getWorkplaceStatisticsData() {
|
||||
return infraStatisticsService.getWorkplaceStatisticsData();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -24,9 +24,12 @@ package org.dromara.visor.module.infra.dao;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.dromara.visor.framework.mybatis.core.mapper.IMapper;
|
||||
import org.dromara.visor.module.infra.entity.domain.OperatorLogDO;
|
||||
import org.dromara.visor.module.infra.entity.po.OperatorLogCountPO;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -63,4 +66,16 @@ public interface OperatorLogDAO extends IMapper<OperatorLogDO> {
|
||||
return this.delete(wrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询操作日志数量
|
||||
*
|
||||
* @param userId userId
|
||||
* @param startTime startTime
|
||||
* @param endTime endTime
|
||||
* @return rows
|
||||
*/
|
||||
List<OperatorLogCountPO> selectOperatorLogCount(@Param("userId") Long userId,
|
||||
@Param("startTime") Date startTime,
|
||||
@Param("endTime") Date endTime);
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright (c) 2023 - present Dromara, All rights reserved.
|
||||
*
|
||||
* https://visor.dromara.org
|
||||
* https://visor.dromara.org.cn
|
||||
* https://visor.orionsec.cn
|
||||
*
|
||||
* Members:
|
||||
* Jiahang Li - ljh1553488six@139.com - author
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.dromara.visor.module.infra.define.cache;
|
||||
|
||||
import cn.orionsec.kit.lang.define.cache.key.CacheKeyBuilder;
|
||||
import cn.orionsec.kit.lang.define.cache.key.CacheKeyDefine;
|
||||
import cn.orionsec.kit.lang.define.cache.key.struct.RedisCacheStruct;
|
||||
import org.dromara.visor.module.infra.entity.vo.InfraWorkplaceStatisticsVO;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* infra 模块统计缓存 key
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2024/12/23 16:10
|
||||
*/
|
||||
public interface InfraStatisticsCacheKeyDefine {
|
||||
|
||||
CacheKeyDefine WORKPLACE_DATA = new CacheKeyBuilder()
|
||||
.key("data:statistics:infra-workplace:{}:{}")
|
||||
.desc("基建模块工作台统计 ${userId} ${time}")
|
||||
.type(InfraWorkplaceStatisticsVO.class)
|
||||
.struct(RedisCacheStruct.STRING)
|
||||
.timeout(10, TimeUnit.MINUTES)
|
||||
.build();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright (c) 2023 - present Dromara, All rights reserved.
|
||||
*
|
||||
* https://visor.dromara.org
|
||||
* https://visor.dromara.org.cn
|
||||
* https://visor.orionsec.cn
|
||||
*
|
||||
* Members:
|
||||
* Jiahang Li - ljh1553488six@139.com - author
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.dromara.visor.module.infra.entity.po;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 操作日志数量
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2024/12/23 16:24
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Schema(name = "OperatorLogCountPO", description = "操作日志数量")
|
||||
public class OperatorLogCountPO implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Schema(description = "操作日期")
|
||||
private String operatorDate;
|
||||
|
||||
@Schema(description = "结果")
|
||||
private Integer result;
|
||||
|
||||
@Schema(description = "操作次数")
|
||||
private Integer count;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Copyright (c) 2023 - present Dromara, All rights reserved.
|
||||
*
|
||||
* https://visor.dromara.org
|
||||
* https://visor.dromara.org.cn
|
||||
* https://visor.orionsec.cn
|
||||
*
|
||||
* Members:
|
||||
* Jiahang Li - ljh1553488six@139.com - author
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.dromara.visor.module.infra.entity.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.dromara.visor.framework.common.entity.chart.LineSingleChartData;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 基建模块工作台统计响应
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2024/12/23 17:38
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Schema(name = "InfraWorkplaceStatisticsVO", description = "基建模块工作台统计响应")
|
||||
public class InfraWorkplaceStatisticsVO {
|
||||
|
||||
@Schema(description = "userId")
|
||||
private Long userId;
|
||||
|
||||
@Schema(description = "用户名")
|
||||
private String username;
|
||||
|
||||
@Schema(description = "花名")
|
||||
private String nickname;
|
||||
|
||||
@Schema(description = "未读消息数量")
|
||||
private Integer unreadMessageCount;
|
||||
|
||||
@Schema(description = "上次登录时间")
|
||||
private Date lastLoginTime;
|
||||
|
||||
@Schema(description = "当前登录会话数量")
|
||||
private Integer userSessionCount;
|
||||
|
||||
@Schema(description = "系统操作数量图表")
|
||||
private LineSingleChartData operatorChart;
|
||||
|
||||
@Schema(description = "用户登录日志")
|
||||
private List<LoginHistoryVO> loginHistoryList;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright (c) 2023 - present Dromara, All rights reserved.
|
||||
*
|
||||
* https://visor.dromara.org
|
||||
* https://visor.dromara.org.cn
|
||||
* https://visor.orionsec.cn
|
||||
*
|
||||
* Members:
|
||||
* Jiahang Li - ljh1553488six@139.com - author
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.dromara.visor.module.infra.service;
|
||||
|
||||
import org.dromara.visor.framework.common.entity.chart.LineSingleChartData;
|
||||
import org.dromara.visor.module.infra.entity.vo.InfraWorkplaceStatisticsVO;
|
||||
|
||||
/**
|
||||
* 基建模块统计服务
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2024/12/23 16:52
|
||||
*/
|
||||
public interface InfraStatisticsService {
|
||||
|
||||
/**
|
||||
* 查询工作台统计信息
|
||||
*
|
||||
* @return data
|
||||
*/
|
||||
InfraWorkplaceStatisticsVO getWorkplaceStatisticsData();
|
||||
|
||||
/**
|
||||
* 获取用户操作日志图表
|
||||
*
|
||||
* @param userId userId
|
||||
* @return data
|
||||
*/
|
||||
LineSingleChartData getUserOperatorLogChart(Long userId);
|
||||
|
||||
}
|
||||
@@ -62,6 +62,14 @@ public interface SystemMessageService {
|
||||
*/
|
||||
Map<String, Integer> getSystemMessageCount(Boolean queryUnread);
|
||||
|
||||
/**
|
||||
* 查询未读消息数量
|
||||
*
|
||||
* @param receiverId receiverId
|
||||
* @return count
|
||||
*/
|
||||
Integer getUnreadSystemMessageCount(Long receiverId);
|
||||
|
||||
/**
|
||||
* 查询是否有未读消息
|
||||
*
|
||||
|
||||
@@ -36,6 +36,14 @@ import java.util.List;
|
||||
*/
|
||||
public interface SystemUserManagementService {
|
||||
|
||||
/**
|
||||
* 获取用户会话数量
|
||||
*
|
||||
* @param userId userId
|
||||
* @return count
|
||||
*/
|
||||
Integer getUserSessionCount(Long userId);
|
||||
|
||||
/**
|
||||
* 获取用户会话列表
|
||||
*
|
||||
|
||||
@@ -0,0 +1,139 @@
|
||||
/*
|
||||
* Copyright (c) 2023 - present Dromara, All rights reserved.
|
||||
*
|
||||
* https://visor.dromara.org
|
||||
* https://visor.dromara.org.cn
|
||||
* https://visor.orionsec.cn
|
||||
*
|
||||
* Members:
|
||||
* Jiahang Li - ljh1553488six@139.com - author
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.dromara.visor.module.infra.service.impl;
|
||||
|
||||
import cn.orionsec.kit.lang.utils.time.Dates;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.dromara.visor.framework.common.entity.StatisticsRange;
|
||||
import org.dromara.visor.framework.common.entity.chart.LineSingleChartData;
|
||||
import org.dromara.visor.framework.redis.core.utils.RedisStrings;
|
||||
import org.dromara.visor.framework.security.core.utils.SecurityUtils;
|
||||
import org.dromara.visor.module.infra.dao.OperatorLogDAO;
|
||||
import org.dromara.visor.module.infra.dao.SystemUserDAO;
|
||||
import org.dromara.visor.module.infra.define.cache.InfraStatisticsCacheKeyDefine;
|
||||
import org.dromara.visor.module.infra.entity.domain.SystemUserDO;
|
||||
import org.dromara.visor.module.infra.entity.po.OperatorLogCountPO;
|
||||
import org.dromara.visor.module.infra.entity.vo.InfraWorkplaceStatisticsVO;
|
||||
import org.dromara.visor.module.infra.entity.vo.LoginHistoryVO;
|
||||
import org.dromara.visor.module.infra.service.InfraStatisticsService;
|
||||
import org.dromara.visor.module.infra.service.OperatorLogService;
|
||||
import org.dromara.visor.module.infra.service.SystemMessageService;
|
||||
import org.dromara.visor.module.infra.service.SystemUserManagementService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 基建模块统计服务实现类
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2024/12/23 16:52
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class InfraStatisticsServiceImpl implements InfraStatisticsService {
|
||||
|
||||
@Resource
|
||||
private SystemUserDAO systemUserDAO;
|
||||
|
||||
@Resource
|
||||
private OperatorLogDAO operatorLogDAO;
|
||||
|
||||
@Resource
|
||||
private OperatorLogService operatorLogService;
|
||||
|
||||
@Resource
|
||||
private SystemMessageService systemMessageService;
|
||||
|
||||
@Resource
|
||||
private SystemUserManagementService systemUserManagementService;
|
||||
|
||||
@Override
|
||||
public InfraWorkplaceStatisticsVO getWorkplaceStatisticsData() {
|
||||
Long userId = SecurityUtils.getLoginUserId();
|
||||
// 读取缓存
|
||||
String cacheKey = InfraStatisticsCacheKeyDefine.WORKPLACE_DATA.format(userId, Dates.current(Dates.YMD2));
|
||||
InfraWorkplaceStatisticsVO data = RedisStrings.getJson(cacheKey, InfraStatisticsCacheKeyDefine.WORKPLACE_DATA);
|
||||
if (data == null) {
|
||||
// 查询用户操作日志图表
|
||||
LineSingleChartData operatorChart = this.getUserOperatorLogChart(userId);
|
||||
data = InfraWorkplaceStatisticsVO.builder()
|
||||
.userId(userId)
|
||||
.operatorChart(operatorChart)
|
||||
.build();
|
||||
// 设置缓存
|
||||
RedisStrings.setJson(cacheKey, InfraStatisticsCacheKeyDefine.WORKPLACE_DATA, data);
|
||||
}
|
||||
// 查询用户信息
|
||||
SystemUserDO user = systemUserDAO.of()
|
||||
.createWrapper()
|
||||
.select(SystemUserDO::getId,
|
||||
SystemUserDO::getUsername,
|
||||
SystemUserDO::getNickname,
|
||||
SystemUserDO::getLastLoginTime)
|
||||
.eq(SystemUserDO::getId, userId)
|
||||
.then()
|
||||
.getOne();
|
||||
data.setUsername(user.getUsername());
|
||||
data.setNickname(user.getNickname());
|
||||
data.setLastLoginTime(user.getLastLoginTime());
|
||||
// 查询未读消息数量
|
||||
Integer unreadMessageCount = systemMessageService.getUnreadSystemMessageCount(userId);
|
||||
data.setUnreadMessageCount(unreadMessageCount);
|
||||
// 查询当前登录会话数量
|
||||
Integer userSessionCount = systemUserManagementService.getUserSessionCount(userId);
|
||||
data.setUserSessionCount(userSessionCount);
|
||||
// 查询用户登录日志
|
||||
List<LoginHistoryVO> loginHistoryList = operatorLogService.getLoginHistory(user.getUsername(), 10);
|
||||
data.setLoginHistoryList(loginHistoryList);
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LineSingleChartData getUserOperatorLogChart(Long userId) {
|
||||
Date endTime = new Date();
|
||||
Date startTime = Dates.stream()
|
||||
.clearHms()
|
||||
.addDay(-6)
|
||||
.get();
|
||||
List<String> rangeDays = StatisticsRange.WEEK.getDateRanges(startTime);
|
||||
// 查询操作数量
|
||||
Map<String, Integer> countMap = operatorLogDAO.selectOperatorLogCount(userId, startTime, endTime)
|
||||
.stream()
|
||||
.collect(Collectors.toMap(OperatorLogCountPO::getOperatorDate, OperatorLogCountPO::getCount));
|
||||
// 构建每天的数据
|
||||
List<Integer> data = rangeDays.stream()
|
||||
.map(s -> countMap.getOrDefault(s, 0))
|
||||
.collect(Collectors.toList());
|
||||
return LineSingleChartData.builder()
|
||||
.x(rangeDays)
|
||||
.data(data)
|
||||
.build();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -114,6 +114,17 @@ public class SystemMessageServiceImpl implements SystemMessageService {
|
||||
Functions.right()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getUnreadSystemMessageCount(Long receiverId) {
|
||||
return systemMessageDAO.of()
|
||||
.createWrapper()
|
||||
.eq(SystemMessageDO::getReceiverId, receiverId)
|
||||
.eq(SystemMessageDO::getStatus, MessageStatusEnum.UNREAD.getStatus())
|
||||
.then()
|
||||
.count()
|
||||
.intValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean checkHasUnreadMessage() {
|
||||
// 查询
|
||||
|
||||
@@ -62,6 +62,13 @@ public class SystemUserManagementServiceImpl implements SystemUserManagementServ
|
||||
@Resource
|
||||
private SystemUserDAO systemUserDAO;
|
||||
|
||||
@Override
|
||||
public Integer getUserSessionCount(Long userId) {
|
||||
// 扫描缓存
|
||||
Set<String> keys = RedisStrings.scanKeys(UserCacheKeyDefine.LOGIN_TOKEN.format(userId, "*"));
|
||||
return Lists.size(keys);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<UserSessionVO> getUserSessionList(Long userId) {
|
||||
// 扫描缓存
|
||||
|
||||
@@ -26,9 +26,25 @@
|
||||
<result column="deleted" property="deleted"/>
|
||||
</resultMap>
|
||||
|
||||
<!-- 操作数量映射结果 -->
|
||||
<resultMap id="CountResultMap" type="org.dromara.visor.module.infra.entity.po.OperatorLogCountPO">
|
||||
<result column="operator_date" property="operatorDate"/>
|
||||
<result column="result" property="result"/>
|
||||
<result column="total_count" property="count"/>
|
||||
</resultMap>
|
||||
|
||||
<!-- 通用查询结果列 -->
|
||||
<sql id="Base_Column_List">
|
||||
id, user_id, username, trace_id, address, location, user_agent, risk_level, module, type, log_info, extra, result, error_message, return_value, duration, start_time, end_time, create_time, deleted
|
||||
</sql>
|
||||
|
||||
<select id="selectOperatorLogCount" resultMap="CountResultMap">
|
||||
SELECT DATE(create_time) operator_date, COUNT(1) total_count
|
||||
FROM operator_log
|
||||
WHERE deleted = 0
|
||||
AND user_id = #{userId}
|
||||
AND create_time BETWEEN #{startTime} AND #{endTime}
|
||||
GROUP BY operator_date
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
|
||||
Reference in New Issue
Block a user