【7.1.6】【statistics】重新抽离统计业务

pull/26/MERGE
fengshuonan 2022-02-10 22:20:00 +08:00
parent d6ec22408f
commit 80914544b9
27 changed files with 1057 additions and 144 deletions

View File

@ -6,7 +6,7 @@ package cn.stylefeng.roses.kernel.system.api.constants;
* @author xixiaowei
* @date 2022/2/9 16:42
*/
public interface InterfaceStatisticsCacheConstants {
public interface StatisticsCacheConstants {
/**
*
@ -16,5 +16,10 @@ public interface InterfaceStatisticsCacheConstants {
/**
*
*/
Long INTERFACE_STATISTICS_CACHE_TIMEOUT_SECONDS = 1200L;
Long INTERFACE_STATISTICS_CACHE_TIMEOUT_SECONDS = 3600L;
/**
* AOP
*/
int INTERFACE_STATISTICS_AOP_ORDER = 600;
}

View File

@ -1,59 +0,0 @@
package cn.stylefeng.roses.kernel.system.modular.home.aop;
import cn.stylefeng.roses.kernel.cache.api.CacheOperatorApi;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
/**
* AOP
*
* @author xixiaowei
* @date 2022/2/10 9:56
*/
@Slf4j
@Aspect
public class InterfaceStatisticsAop {
@Resource(name = "interCacheApi")
private CacheOperatorApi<String> interCacheApi;
@Pointcut(value = "@annotation(cn.stylefeng.roses.kernel.scanner.api.annotation.GetResource) ||" +
"@annotation(cn.stylefeng.roses.kernel.scanner.api.annotation.PostResource) ")
public void flowControl() {
}
@Around(value = "flowControl()")
public Object flowControl(ProceedingJoinPoint joinPoint) {
Object proceed = null;
try {
proceed = joinPoint.proceed();
} catch (Throwable throwable) {
throwable.printStackTrace();
} finally {
//方法执行后
saveFlowControl(joinPoint);
}
return proceed;
}
private void saveFlowControl(ProceedingJoinPoint joinPoint) {
String name = joinPoint.getSignature().getName();
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
// 获取URL
String url = request.getRequestURI();
// 存放到缓存中
interCacheApi.put(name, url, 600L);
}
}

View File

@ -1,23 +0,0 @@
package cn.stylefeng.roses.kernel.system.modular.home.cache;
import cn.hutool.cache.impl.TimedCache;
import cn.stylefeng.roses.kernel.cache.memory.AbstractMemoryCacheOperator;
import cn.stylefeng.roses.kernel.system.api.constants.InterfaceStatisticsCacheConstants;
/**
*
*
* @author xixiaowei
* @date 2022/2/9 16:36
*/
public class InterfaceStatisticsMemoryCache extends AbstractMemoryCacheOperator<String> {
public InterfaceStatisticsMemoryCache(TimedCache<String, String> timedCache) {
super(timedCache);
}
@Override
public String getCommonKeyPrefix() {
return InterfaceStatisticsCacheConstants.INTERFACE_STATISTICS_PREFIX;
}
}

View File

@ -1,23 +0,0 @@
package cn.stylefeng.roses.kernel.system.modular.home.cache;
import cn.stylefeng.roses.kernel.cache.redis.AbstractRedisCacheOperator;
import cn.stylefeng.roses.kernel.system.api.constants.InterfaceStatisticsCacheConstants;
import org.springframework.data.redis.core.RedisTemplate;
/**
*
*
* @author xixiaowei
* @date 2022/2/9 16:38
*/
public class InterfaceStatisticsRedisCache extends AbstractRedisCacheOperator<String> {
public InterfaceStatisticsRedisCache(RedisTemplate<String, String> redisTemplate) {
super(redisTemplate);
}
@Override
public String getCommonKeyPrefix() {
return InterfaceStatisticsCacheConstants.INTERFACE_STATISTICS_PREFIX;
}
}

View File

@ -1,7 +1,6 @@
package cn.stylefeng.roses.kernel.system.modular.home.service.Impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.stylefeng.roses.kernel.auth.api.context.LoginContext;
import cn.stylefeng.roses.kernel.auth.api.pojo.login.LoginUser;
import cn.stylefeng.roses.kernel.cache.api.CacheOperatorApi;
@ -21,6 +20,7 @@ import cn.stylefeng.roses.kernel.system.api.pojo.user.request.SysUserRequest;
import cn.stylefeng.roses.kernel.system.modular.home.entity.InterfaceStatistics;
import cn.stylefeng.roses.kernel.system.modular.home.mapper.InterfaceStatisticsMapper;
import cn.stylefeng.roses.kernel.system.modular.home.service.HomePageService;
import cn.stylefeng.roses.kernel.system.modular.statistic.entity.SysStatisticsCount;
import cn.stylefeng.roses.kernel.system.modular.user.entity.SysUserOrg;
import cn.stylefeng.roses.kernel.system.modular.user.service.SysUserOrgService;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
@ -59,8 +59,8 @@ public class HomePageServiceImpl extends ServiceImpl<InterfaceStatisticsMapper,
@Resource
private ResourceServiceApi resourceServiceApi;
@Resource(name = "interCountCacheApi")
private CacheOperatorApi<String> interCountCacheApi;
@Resource(name = "requestCountCacheApi")
private CacheOperatorApi<Map<Long, Integer>> requestCountCacheApi;
@Override
public List<LogRecordDTO> getDynamicList(LogManagerRequest logManagerRequest) {
@ -123,7 +123,7 @@ public class HomePageServiceImpl extends ServiceImpl<InterfaceStatisticsMapper,
String[] orgPids = hrOrganizationDTO.getOrgPids().split(",");
for (String orgPid : orgPids) {
if (organizationId.toString().equals(orgPid)) {
sectionNum ++;
sectionNum++;
}
}
}
@ -153,30 +153,11 @@ public class HomePageServiceImpl extends ServiceImpl<InterfaceStatisticsMapper,
@Override
public void interfaceStatistics() {
Map<String, String> allKeyValues = interCountCacheApi.getAllKeyValues();
if (ObjectUtil.isNotNull(allKeyValues.keySet())) {
for (String key : allKeyValues.keySet()) {
String value = interCountCacheApi.get(key);
InterfaceStatistics statistics = this.getOne(Wrappers.<InterfaceStatistics>lambdaQuery().eq(InterfaceStatistics::getInterfaceUrl, value));
// 不存在的数据添加
if (ObjectUtil.isNull(statistics)) {
InterfaceStatistics interfaceStatistics = new InterfaceStatistics();
interfaceStatistics.setInterfaceName(key);
interfaceStatistics.setInterfaceUrl(value);
interfaceStatistics.setRequestCount(1);
// 保存新数据
this.save(interfaceStatistics);
// 缓存到库中 删除缓存中数据
} else {
InterfaceStatistics interfaceStatistics = new InterfaceStatistics();
BeanUtil.copyProperties(statistics, interfaceStatistics);
interfaceStatistics.setRequestCount(interfaceStatistics.getRequestCount() + 1);
// 更新请求次数
this.updateById(interfaceStatistics);
// 缓存到库中 删除缓存中数据
}
interCountCacheApi.remove(key);
}
}
// key是用户idvalue的key是statUrlId最后的value是次数
Map<String, Map<Long, Integer>> userRequestStats = requestCountCacheApi.getAllKeyValues();
// todo
ArrayList<SysStatisticsCount> sysStatisticsCounts = new ArrayList<>();
}
}

View File

@ -0,0 +1,127 @@
package cn.stylefeng.roses.kernel.system.modular.statistic.aop;
import cn.stylefeng.roses.kernel.auth.api.context.LoginContext;
import cn.stylefeng.roses.kernel.auth.api.pojo.login.LoginUser;
import cn.stylefeng.roses.kernel.cache.api.CacheOperatorApi;
import cn.stylefeng.roses.kernel.rule.util.HttpServletUtil;
import cn.stylefeng.roses.kernel.system.api.constants.StatisticsCacheConstants;
import cn.stylefeng.roses.kernel.system.modular.statistic.context.StatisticsUrlContext;
import cn.stylefeng.roses.kernel.system.modular.statistic.entity.SysStatisticsUrl;
import cn.stylefeng.roses.kernel.system.modular.statistic.service.SysStatisticsCountService;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.core.Ordered;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* AOP
*
* @author xixiaowei
* @date 2022/2/10 9:56
*/
@Slf4j
@Aspect
public class InterfaceStatisticsAop implements Ordered {
@Resource(name = "requestCountCacheApi")
private CacheOperatorApi<Map<Long, Integer>> requestCountCacheApi;
@Resource
private SysStatisticsCountService sysStatisticsCountService;
/**
*
*
* @author fengshuonan
* @date 2022/2/10 20:25
*/
@Pointcut("execution(* *..controller.*.*(..))")
public void flowControl() {
}
/**
*
*
* @author fengshuonan
* @date 2022/2/10 20:25
*/
@Around(value = "flowControl()")
public Object flowControl(ProceedingJoinPoint joinPoint) throws Throwable {
// 先执行原有业务
Object proceed = joinPoint.proceed();
// 执行统计业务,只统计指定的几个接口
try {
saveRequestCount(joinPoint);
} catch (Exception e) {
// 统计业务出现异常打印日志
log.error("接口统计出现异常!", e);
}
return proceed;
}
/**
* url访
*
* @author fengshuonan
* @date 2022/2/10 21:25
*/
private void saveRequestCount(ProceedingJoinPoint joinPoint) {
// 获取请求的地址
HttpServletRequest request = HttpServletUtil.getRequest();
String currentUrl = request.getRequestURI();
// 获取当前登录用户
LoginUser loginUserNullable = LoginContext.me().getLoginUserNullable();
if (loginUserNullable == null) {
return;
}
// 判断当前url是否需要统计
List<SysStatisticsUrl> urls = StatisticsUrlContext.getUrls();
if (urls.stream().noneMatch(i -> currentUrl.equals(i.getStatUrl()))) {
return;
}
// 查看当前用户是否有缓存记录
Long userId = loginUserNullable.getUserId();
Long statUrlId = StatisticsUrlContext.getStatUrlId(currentUrl);
Map<Long, Integer> userStatList = null;
if (!requestCountCacheApi.contains(String.valueOf(userId))) {
userStatList = new HashMap<>();
} else {
userStatList = requestCountCacheApi.get(String.valueOf(userId));
}
// 增加这次统计
Integer urlCount = userStatList.get(statUrlId);
if (urlCount != null) {
int newUrlCount = urlCount + 1;
userStatList.put(statUrlId, newUrlCount);
} else {
// 没有缓存就从库里查询这个用户的访问记录
Integer userUrlCount = sysStatisticsCountService.getUserUrlCount(userId, statUrlId);
userStatList.put(statUrlId, userUrlCount);
}
// 存放到缓存中
requestCountCacheApi.put(String.valueOf(userId), userStatList, StatisticsCacheConstants.INTERFACE_STATISTICS_CACHE_TIMEOUT_SECONDS);
}
@Override
public int getOrder() {
return StatisticsCacheConstants.INTERFACE_STATISTICS_AOP_ORDER;
}
}

View File

@ -0,0 +1,25 @@
package cn.stylefeng.roses.kernel.system.modular.statistic.cache;
import cn.hutool.cache.impl.TimedCache;
import cn.stylefeng.roses.kernel.cache.memory.AbstractMemoryCacheOperator;
import cn.stylefeng.roses.kernel.system.api.constants.StatisticsCacheConstants;
import java.util.Map;
/**
*
*
* @author xixiaowei
* @date 2022/2/9 16:36
*/
public class InterfaceStatisticsMemoryCache extends AbstractMemoryCacheOperator<Map<Long,Integer>> {
public InterfaceStatisticsMemoryCache(TimedCache<String, Map<Long,Integer>> timedCache) {
super(timedCache);
}
@Override
public String getCommonKeyPrefix() {
return StatisticsCacheConstants.INTERFACE_STATISTICS_PREFIX;
}
}

View File

@ -0,0 +1,25 @@
package cn.stylefeng.roses.kernel.system.modular.statistic.cache;
import cn.stylefeng.roses.kernel.cache.redis.AbstractRedisCacheOperator;
import cn.stylefeng.roses.kernel.system.api.constants.StatisticsCacheConstants;
import org.springframework.data.redis.core.RedisTemplate;
import java.util.Map;
/**
* Redis
*
* @author xixiaowei
* @date 2022/2/9 16:38
*/
public class InterfaceStatisticsRedisCache extends AbstractRedisCacheOperator<Map<Long,Integer>> {
public InterfaceStatisticsRedisCache(RedisTemplate<String, Map<Long,Integer>> redisTemplate) {
super(redisTemplate);
}
@Override
public String getCommonKeyPrefix() {
return StatisticsCacheConstants.INTERFACE_STATISTICS_PREFIX;
}
}

View File

@ -0,0 +1,70 @@
package cn.stylefeng.roses.kernel.system.modular.statistic.context;
import cn.stylefeng.roses.kernel.system.modular.statistic.entity.SysStatisticsUrl;
import cn.stylefeng.roses.kernel.system.modular.statistic.service.SysStatisticsUrlService;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* url
*
* @author fengshuonan
* @date 2022/2/10 21:35
*/
@Component
public class StatisticsUrlContext implements CommandLineRunner {
@Resource
private SysStatisticsUrlService sysStatisticsUrlService;
/**
* url
*/
private static List<SysStatisticsUrl> STATISTICS_URLS = new ArrayList<>(10);
/**
* urlkeyurlvaluestat_url_id
*/
private static Map<String,Long> STATISTICS_KEY_VALUES = new HashMap<>(10);
/**
* url
*
* @author fengshuonan
* @date 2022/2/10 21:37
*/
public static List<SysStatisticsUrl> getUrls(){
return STATISTICS_URLS;
}
/**
* urlstat_url_id
*
* @author fengshuonan
* @date 2022/2/10 21:37
*/
public static Long getStatUrlId(String url){
return STATISTICS_KEY_VALUES.get(url);
}
/**
* url
*
* @author fengshuonan
* @date 2022/2/10 21:37
*/
@Override
public void run(String... args) throws Exception {
STATISTICS_URLS = sysStatisticsUrlService.list();
for (SysStatisticsUrl statisticsUrl : STATISTICS_URLS) {
STATISTICS_KEY_VALUES.put(statisticsUrl.getStatUrl(),statisticsUrl.getStatUrlId());
}
}
}

View File

@ -0,0 +1,98 @@
package cn.stylefeng.roses.kernel.system.modular.statistic.controller;
import cn.stylefeng.roses.kernel.rule.pojo.response.ResponseData;
import cn.stylefeng.roses.kernel.rule.pojo.response.SuccessResponseData;
import cn.stylefeng.roses.kernel.scanner.api.annotation.ApiResource;
import cn.stylefeng.roses.kernel.scanner.api.annotation.GetResource;
import cn.stylefeng.roses.kernel.scanner.api.annotation.PostResource;
import cn.stylefeng.roses.kernel.system.modular.statistic.pojo.request.SysStatisticsCountRequest;
import cn.stylefeng.roses.kernel.system.modular.statistic.service.SysStatisticsCountService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
/**
*
*
* @author fengshuonan
* @date 2022/02/10 21:17
*/
@RestController
@ApiResource(name = "常用功能的统计次数")
public class SysStatisticsController {
@Resource
private SysStatisticsCountService sysStatisticsCountService;
/**
*
*
* @author fengshuonan
* @date 2022/02/10 21:17
*/
@PostResource(name = "添加", path = "/sysStatisticsCount/add")
public ResponseData add(@RequestBody @Validated(SysStatisticsCountRequest.add.class) SysStatisticsCountRequest sysStatisticsCountRequest) {
sysStatisticsCountService.add(sysStatisticsCountRequest);
return new SuccessResponseData();
}
/**
*
*
* @author fengshuonan
* @date 2022/02/10 21:17
*/
@PostResource(name = "删除", path = "/sysStatisticsCount/delete")
public ResponseData delete(@RequestBody @Validated(SysStatisticsCountRequest.delete.class) SysStatisticsCountRequest sysStatisticsCountRequest) {
sysStatisticsCountService.del(sysStatisticsCountRequest);
return new SuccessResponseData();
}
/**
*
*
* @author fengshuonan
* @date 2022/02/10 21:17
*/
@PostResource(name = "编辑", path = "/sysStatisticsCount/edit")
public ResponseData edit(@RequestBody @Validated(SysStatisticsCountRequest.edit.class) SysStatisticsCountRequest sysStatisticsCountRequest) {
sysStatisticsCountService.edit(sysStatisticsCountRequest);
return new SuccessResponseData();
}
/**
*
*
* @author fengshuonan
* @date 2022/02/10 21:17
*/
@GetResource(name = "查看详情", path = "/sysStatisticsCount/detail")
public ResponseData detail(@Validated(SysStatisticsCountRequest.detail.class) SysStatisticsCountRequest sysStatisticsCountRequest) {
return new SuccessResponseData(sysStatisticsCountService.detail(sysStatisticsCountRequest));
}
/**
*
*
* @author fengshuonan
* @date 2022/02/10 21:17
*/
@GetResource(name = "获取列表", path = "/sysStatisticsCount/list")
public ResponseData list(SysStatisticsCountRequest sysStatisticsCountRequest) {
return new SuccessResponseData(sysStatisticsCountService.findList(sysStatisticsCountRequest));
}
/**
*
*
* @author fengshuonan
* @date 2022/02/10 21:17
*/
@GetResource(name = "分页查询", path = "/sysStatisticsCount/page")
public ResponseData page(SysStatisticsCountRequest sysStatisticsCountRequest) {
return new SuccessResponseData(sysStatisticsCountService.findPage(sysStatisticsCountRequest));
}
}

View File

@ -0,0 +1,46 @@
package cn.stylefeng.roses.kernel.system.modular.statistic.entity;
import cn.stylefeng.roses.kernel.db.api.pojo.entity.BaseEntity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import lombok.EqualsAndHashCode;
/**
*
*
* @author fengshuonan
* @date 2022/02/10 21:17
*/
@TableName("sys_statistics_count")
@Data
@EqualsAndHashCode(callSuper = true)
public class SysStatisticsCount extends BaseEntity {
/**
* ID
*/
@TableId(value = "stat_count_id", type = IdType.ASSIGN_ID)
private Long statCountId;
/**
* id
*/
@TableField("user_id")
private Long userId;
/**
* 访
*/
@TableField("stat_url_id")
private Long statUrlId;
/**
* 访
*/
@TableField("stat_count")
private Integer statCount;
}

View File

@ -0,0 +1,52 @@
package cn.stylefeng.roses.kernel.system.modular.statistic.entity;
import cn.stylefeng.roses.kernel.db.api.pojo.entity.BaseEntity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import lombok.EqualsAndHashCode;
/**
*
*
* @author fengshuonan
* @date 2022/02/10 21:17
*/
@TableName("sys_statistics_url")
@Data
@EqualsAndHashCode(callSuper = true)
public class SysStatisticsUrl extends BaseEntity {
/**
* ID
*/
@TableId(value = "stat_url_id", type = IdType.ASSIGN_ID)
private Long statUrlId;
/**
*
*/
@TableField("stat_name")
private String statName;
/**
* ID
*/
@TableField("stat_menu_id")
private String statMenuId;
/**
* URL
*/
@TableField("stat_url")
private String statUrl;
/**
* Y-N-
*/
@TableField("always_show")
private String alwaysShow;
}

View File

@ -0,0 +1,41 @@
package cn.stylefeng.roses.kernel.system.modular.statistic.enums;
import cn.stylefeng.roses.kernel.rule.constants.RuleConstants;
import cn.stylefeng.roses.kernel.rule.exception.AbstractExceptionEnum;
import lombok.Getter;
/**
*
*
* @author fengshuonan
* @date 2022/02/10 21:17
*/
@Getter
public enum SysStatisticsCountExceptionEnum implements AbstractExceptionEnum {
/**
*
*/
SYS_STATISTICS_COUNT_NOT_EXISTED(RuleConstants.USER_OPERATION_ERROR_TYPE_CODE + "10001", "查询结果不存在"),
/**
*
*/
PARAM_EMPTY(RuleConstants.USER_OPERATION_ERROR_TYPE_CODE + "10002", "请求参数不完整,无法查询用户请求次数");
/**
*
*/
private final String errorCode;
/**
*
*/
private final String userTip;
SysStatisticsCountExceptionEnum(String errorCode, String userTip) {
this.errorCode = errorCode;
this.userTip = userTip;
}
}

View File

@ -0,0 +1,36 @@
package cn.stylefeng.roses.kernel.system.modular.statistic.enums;
import cn.stylefeng.roses.kernel.rule.constants.RuleConstants;
import cn.stylefeng.roses.kernel.rule.exception.AbstractExceptionEnum;
import lombok.Getter;
/**
*
*
* @author fengshuonan
* @date 2022/02/10 21:17
*/
@Getter
public enum SysStatisticsUrlExceptionEnum implements AbstractExceptionEnum {
/**
*
*/
SYS_STATISTICS_URL_NOT_EXISTED(RuleConstants.USER_OPERATION_ERROR_TYPE_CODE + "10001", "查询结果不存在");
/**
*
*/
private final String errorCode;
/**
*
*/
private final String userTip;
SysStatisticsUrlExceptionEnum(String errorCode, String userTip) {
this.errorCode = errorCode;
this.userTip = userTip;
}
}

View File

@ -0,0 +1,14 @@
package cn.stylefeng.roses.kernel.system.modular.statistic.mapper;
import cn.stylefeng.roses.kernel.system.modular.statistic.entity.SysStatisticsCount;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
/**
* Mapper
*
* @author fengshuonan
* @date 2022/02/10 21:17
*/
public interface SysStatisticsCountMapper extends BaseMapper<SysStatisticsCount> {
}

View File

@ -0,0 +1,14 @@
package cn.stylefeng.roses.kernel.system.modular.statistic.mapper;
import cn.stylefeng.roses.kernel.system.modular.statistic.entity.SysStatisticsUrl;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
/**
* Mapper
*
* @author fengshuonan
* @date 2022/02/10 21:17
*/
public interface SysStatisticsUrlMapper extends BaseMapper<SysStatisticsUrl> {
}

View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.stylefeng.roses.kernel.system.modular.statistic.mapper.SysStatisticsCountMapper">
</mapper>

View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.stylefeng.roses.kernel.system.modular.statistic.mapper.SysStatisticsUrlMapper">
</mapper>

View File

@ -0,0 +1,45 @@
package cn.stylefeng.roses.kernel.system.modular.statistic.pojo.request;
import cn.stylefeng.roses.kernel.rule.annotation.ChineseDescription;
import cn.stylefeng.roses.kernel.rule.pojo.request.BaseRequest;
import lombok.Data;
import lombok.EqualsAndHashCode;
import javax.validation.constraints.NotNull;
/**
*
*
* @author fengshuonan
* @date 2022/02/10 21:17
*/
@EqualsAndHashCode(callSuper = true)
@Data
public class SysStatisticsCountRequest extends BaseRequest {
/**
* ID
*/
@NotNull(message = "主键ID不能为空", groups = {edit.class, delete.class})
@ChineseDescription("主键ID")
private Long statCountId;
/**
* id
*/
@ChineseDescription("用户id")
private Long userId;
/**
* 访
*/
@ChineseDescription("访问的地址")
private Long statUrlId;
/**
* 访
*/
@ChineseDescription("访问的次数")
private Integer statCount;
}

View File

@ -0,0 +1,51 @@
package cn.stylefeng.roses.kernel.system.modular.statistic.pojo.request;
import cn.stylefeng.roses.kernel.rule.annotation.ChineseDescription;
import cn.stylefeng.roses.kernel.rule.pojo.request.BaseRequest;
import lombok.Data;
import lombok.EqualsAndHashCode;
import javax.validation.constraints.NotNull;
/**
*
*
* @author fengshuonan
* @date 2022/02/10 21:17
*/
@EqualsAndHashCode(callSuper = true)
@Data
public class SysStatisticsUrlRequest extends BaseRequest {
/**
* ID
*/
@NotNull(message = "主键ID不能为空", groups = {edit.class, delete.class})
@ChineseDescription("主键ID")
private Long statUrlId;
/**
*
*/
@ChineseDescription("被统计名称")
private String statName;
/**
* ID
*/
@ChineseDescription("被统计菜单ID")
private String statMenuId;
/**
* URL
*/
@ChineseDescription("被统计的URL")
private String statUrl;
/**
* Y-N-
*/
@ChineseDescription("是否常驻显示Y-是N-否")
private String alwaysShow;
}

View File

@ -0,0 +1,82 @@
package cn.stylefeng.roses.kernel.system.modular.statistic.service;
import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
import cn.stylefeng.roses.kernel.system.modular.statistic.entity.SysStatisticsCount;
import cn.stylefeng.roses.kernel.system.modular.statistic.pojo.request.SysStatisticsCountRequest;
import com.baomidou.mybatisplus.extension.service.IService;
import java.util.List;
/**
*
*
* @author fengshuonan
* @date 2022/02/10 21:17
*/
public interface SysStatisticsCountService extends IService<SysStatisticsCount> {
/**
*
*
* @param sysStatisticsCountRequest
* @author fengshuonan
* @date 2022/02/10 21:17
*/
void add(SysStatisticsCountRequest sysStatisticsCountRequest);
/**
*
*
* @param sysStatisticsCountRequest
* @author fengshuonan
* @date 2022/02/10 21:17
*/
void del(SysStatisticsCountRequest sysStatisticsCountRequest);
/**
*
*
* @param sysStatisticsCountRequest
* @author fengshuonan
* @date 2022/02/10 21:17
*/
void edit(SysStatisticsCountRequest sysStatisticsCountRequest);
/**
*
*
* @param sysStatisticsCountRequest
* @author fengshuonan
* @date 2022/02/10 21:17
*/
SysStatisticsCount detail(SysStatisticsCountRequest sysStatisticsCountRequest);
/**
*
*
* @param sysStatisticsCountRequest
* @return List<SysStatisticsCount>
* @author fengshuonan
* @date 2022/02/10 21:17
*/
List<SysStatisticsCount> findList(SysStatisticsCountRequest sysStatisticsCountRequest);
/**
*
*
* @param sysStatisticsCountRequest
* @return PageResult<SysStatisticsCount>
* @author fengshuonan
* @date 2022/02/10 21:17
*/
PageResult<SysStatisticsCount> findPage(SysStatisticsCountRequest sysStatisticsCountRequest);
/**
*
*
* @author fengshuonan
* @date 2022/2/10 21:56
*/
Integer getUserUrlCount(Long userId, Long statUrlId);
}

View File

@ -0,0 +1,74 @@
package cn.stylefeng.roses.kernel.system.modular.statistic.service;
import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
import cn.stylefeng.roses.kernel.system.modular.statistic.entity.SysStatisticsUrl;
import cn.stylefeng.roses.kernel.system.modular.statistic.pojo.request.SysStatisticsUrlRequest;
import com.baomidou.mybatisplus.extension.service.IService;
import java.util.List;
/**
*
*
* @author fengshuonan
* @date 2022/02/10 21:17
*/
public interface SysStatisticsUrlService extends IService<SysStatisticsUrl> {
/**
*
*
* @param sysStatisticsUrlRequest
* @author fengshuonan
* @date 2022/02/10 21:17
*/
void add(SysStatisticsUrlRequest sysStatisticsUrlRequest);
/**
*
*
* @param sysStatisticsUrlRequest
* @author fengshuonan
* @date 2022/02/10 21:17
*/
void del(SysStatisticsUrlRequest sysStatisticsUrlRequest);
/**
*
*
* @param sysStatisticsUrlRequest
* @author fengshuonan
* @date 2022/02/10 21:17
*/
void edit(SysStatisticsUrlRequest sysStatisticsUrlRequest);
/**
*
*
* @param sysStatisticsUrlRequest
* @author fengshuonan
* @date 2022/02/10 21:17
*/
SysStatisticsUrl detail(SysStatisticsUrlRequest sysStatisticsUrlRequest);
/**
*
*
* @param sysStatisticsUrlRequest
* @return List<SysStatisticsUrl>
* @author fengshuonan
* @date 2022/02/10 21:17
*/
List<SysStatisticsUrl> findList(SysStatisticsUrlRequest sysStatisticsUrlRequest);
/**
*
*
* @param sysStatisticsUrlRequest
* @return PageResult<SysStatisticsUrl>
* @author fengshuonan
* @date 2022/02/10 21:17
*/
PageResult<SysStatisticsUrl> findPage(SysStatisticsUrlRequest sysStatisticsUrlRequest);
}

View File

@ -0,0 +1,115 @@
package cn.stylefeng.roses.kernel.system.modular.statistic.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.stylefeng.roses.kernel.db.api.factory.PageFactory;
import cn.stylefeng.roses.kernel.db.api.factory.PageResultFactory;
import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
import cn.stylefeng.roses.kernel.rule.exception.base.ServiceException;
import cn.stylefeng.roses.kernel.system.api.exception.SystemModularException;
import cn.stylefeng.roses.kernel.system.modular.statistic.entity.SysStatisticsCount;
import cn.stylefeng.roses.kernel.system.modular.statistic.enums.SysStatisticsCountExceptionEnum;
import cn.stylefeng.roses.kernel.system.modular.statistic.mapper.SysStatisticsCountMapper;
import cn.stylefeng.roses.kernel.system.modular.statistic.pojo.request.SysStatisticsCountRequest;
import cn.stylefeng.roses.kernel.system.modular.statistic.service.SysStatisticsCountService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import java.util.List;
/**
*
*
* @author fengshuonan
* @date 2022/02/10 21:17
*/
@Service
public class SysStatisticsCountServiceImpl extends ServiceImpl<SysStatisticsCountMapper, SysStatisticsCount> implements SysStatisticsCountService {
@Override
public void add(SysStatisticsCountRequest sysStatisticsCountRequest) {
SysStatisticsCount sysStatisticsCount = new SysStatisticsCount();
BeanUtil.copyProperties(sysStatisticsCountRequest, sysStatisticsCount);
this.save(sysStatisticsCount);
}
@Override
public void del(SysStatisticsCountRequest sysStatisticsCountRequest) {
SysStatisticsCount sysStatisticsCount = this.querySysStatisticsCount(sysStatisticsCountRequest);
this.removeById(sysStatisticsCount.getStatCountId());
}
@Override
public void edit(SysStatisticsCountRequest sysStatisticsCountRequest) {
SysStatisticsCount sysStatisticsCount = this.querySysStatisticsCount(sysStatisticsCountRequest);
BeanUtil.copyProperties(sysStatisticsCountRequest, sysStatisticsCount);
this.updateById(sysStatisticsCount);
}
@Override
public SysStatisticsCount detail(SysStatisticsCountRequest sysStatisticsCountRequest) {
return this.querySysStatisticsCount(sysStatisticsCountRequest);
}
@Override
public PageResult<SysStatisticsCount> findPage(SysStatisticsCountRequest sysStatisticsCountRequest) {
LambdaQueryWrapper<SysStatisticsCount> wrapper = createWrapper(sysStatisticsCountRequest);
Page<SysStatisticsCount> sysRolePage = this.page(PageFactory.defaultPage(), wrapper);
return PageResultFactory.createPageResult(sysRolePage);
}
@Override
public Integer getUserUrlCount(Long userId, Long statUrlId) {
if (ObjectUtil.isEmpty(userId) || ObjectUtil.isEmpty(statUrlId)) {
throw new SystemModularException(SysStatisticsCountExceptionEnum.PARAM_EMPTY);
}
LambdaQueryWrapper<SysStatisticsCount> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(SysStatisticsCount::getUserId, userId);
queryWrapper.eq(SysStatisticsCount::getStatUrlId, statUrlId);
SysStatisticsCount one = this.getOne(queryWrapper);
if (one != null) {
return one.getStatCount();
} else {
return 0;
}
}
@Override
public List<SysStatisticsCount> findList(SysStatisticsCountRequest sysStatisticsCountRequest) {
LambdaQueryWrapper<SysStatisticsCount> wrapper = this.createWrapper(sysStatisticsCountRequest);
return this.list(wrapper);
}
/**
*
*
* @author fengshuonan
* @date 2022/02/10 21:17
*/
private SysStatisticsCount querySysStatisticsCount(SysStatisticsCountRequest sysStatisticsCountRequest) {
SysStatisticsCount sysStatisticsCount = this.getById(sysStatisticsCountRequest.getStatCountId());
if (ObjectUtil.isEmpty(sysStatisticsCount)) {
throw new ServiceException(SysStatisticsCountExceptionEnum.SYS_STATISTICS_COUNT_NOT_EXISTED);
}
return sysStatisticsCount;
}
/**
* wrapper
*
* @author fengshuonan
* @date 2022/02/10 21:17
*/
private LambdaQueryWrapper<SysStatisticsCount> createWrapper(SysStatisticsCountRequest sysStatisticsCountRequest) {
LambdaQueryWrapper<SysStatisticsCount> queryWrapper = new LambdaQueryWrapper<>();
Long userId = sysStatisticsCountRequest.getUserId();
queryWrapper.eq(ObjectUtil.isNotNull(userId), SysStatisticsCount::getUserId, userId);
return queryWrapper;
}
}

View File

@ -0,0 +1,106 @@
package cn.stylefeng.roses.kernel.system.modular.statistic.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.stylefeng.roses.kernel.db.api.factory.PageFactory;
import cn.stylefeng.roses.kernel.db.api.factory.PageResultFactory;
import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
import cn.stylefeng.roses.kernel.rule.exception.base.ServiceException;
import cn.stylefeng.roses.kernel.system.modular.statistic.entity.SysStatisticsUrl;
import cn.stylefeng.roses.kernel.system.modular.statistic.enums.SysStatisticsUrlExceptionEnum;
import cn.stylefeng.roses.kernel.system.modular.statistic.mapper.SysStatisticsUrlMapper;
import cn.stylefeng.roses.kernel.system.modular.statistic.pojo.request.SysStatisticsUrlRequest;
import cn.stylefeng.roses.kernel.system.modular.statistic.service.SysStatisticsUrlService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import java.util.List;
/**
*
*
* @author fengshuonan
* @date 2022/02/10 21:17
*/
@Service
public class SysStatisticsUrlServiceImpl extends ServiceImpl<SysStatisticsUrlMapper, SysStatisticsUrl> implements SysStatisticsUrlService {
@Override
public void add(SysStatisticsUrlRequest sysStatisticsUrlRequest) {
SysStatisticsUrl sysStatisticsUrl = new SysStatisticsUrl();
BeanUtil.copyProperties(sysStatisticsUrlRequest, sysStatisticsUrl);
this.save(sysStatisticsUrl);
}
@Override
public void del(SysStatisticsUrlRequest sysStatisticsUrlRequest) {
SysStatisticsUrl sysStatisticsUrl = this.querySysStatisticsUrl(sysStatisticsUrlRequest);
this.removeById(sysStatisticsUrl.getStatUrlId());
}
@Override
public void edit(SysStatisticsUrlRequest sysStatisticsUrlRequest) {
SysStatisticsUrl sysStatisticsUrl = this.querySysStatisticsUrl(sysStatisticsUrlRequest);
BeanUtil.copyProperties(sysStatisticsUrlRequest, sysStatisticsUrl);
this.updateById(sysStatisticsUrl);
}
@Override
public SysStatisticsUrl detail(SysStatisticsUrlRequest sysStatisticsUrlRequest) {
return this.querySysStatisticsUrl(sysStatisticsUrlRequest);
}
@Override
public PageResult<SysStatisticsUrl> findPage(SysStatisticsUrlRequest sysStatisticsUrlRequest) {
LambdaQueryWrapper<SysStatisticsUrl> wrapper = createWrapper(sysStatisticsUrlRequest);
Page<SysStatisticsUrl> sysRolePage = this.page(PageFactory.defaultPage(), wrapper);
return PageResultFactory.createPageResult(sysRolePage);
}
@Override
public List<SysStatisticsUrl> findList(SysStatisticsUrlRequest sysStatisticsUrlRequest) {
LambdaQueryWrapper<SysStatisticsUrl> wrapper = this.createWrapper(sysStatisticsUrlRequest);
return this.list(wrapper);
}
/**
*
*
* @author fengshuonan
* @date 2022/02/10 21:17
*/
private SysStatisticsUrl querySysStatisticsUrl(SysStatisticsUrlRequest sysStatisticsUrlRequest) {
SysStatisticsUrl sysStatisticsUrl = this.getById(sysStatisticsUrlRequest.getStatUrlId());
if (ObjectUtil.isEmpty(sysStatisticsUrl)) {
throw new ServiceException(SysStatisticsUrlExceptionEnum.SYS_STATISTICS_URL_NOT_EXISTED);
}
return sysStatisticsUrl;
}
/**
* wrapper
*
* @author fengshuonan
* @date 2022/02/10 21:17
*/
private LambdaQueryWrapper<SysStatisticsUrl> createWrapper(SysStatisticsUrlRequest sysStatisticsUrlRequest) {
LambdaQueryWrapper<SysStatisticsUrl> queryWrapper = new LambdaQueryWrapper<>();
Long statUrlId = sysStatisticsUrlRequest.getStatUrlId();
String statName = sysStatisticsUrlRequest.getStatName();
String statMenuId = sysStatisticsUrlRequest.getStatMenuId();
String statUrl = sysStatisticsUrlRequest.getStatUrl();
String alwaysShow = sysStatisticsUrlRequest.getAlwaysShow();
queryWrapper.eq(ObjectUtil.isNotNull(statUrlId), SysStatisticsUrl::getStatUrlId, statUrlId);
queryWrapper.like(ObjectUtil.isNotEmpty(statName), SysStatisticsUrl::getStatName, statName);
queryWrapper.like(ObjectUtil.isNotEmpty(statMenuId), SysStatisticsUrl::getStatMenuId, statMenuId);
queryWrapper.like(ObjectUtil.isNotEmpty(statUrl), SysStatisticsUrl::getStatUrl, statUrl);
queryWrapper.like(ObjectUtil.isNotEmpty(alwaysShow), SysStatisticsUrl::getAlwaysShow, alwaysShow);
return queryWrapper;
}
}

View File

@ -1,4 +1,4 @@
package cn.stylefeng.roses.kernel.system.modular.home.timer;
package cn.stylefeng.roses.kernel.system.modular.statistic.timer;
import cn.stylefeng.roses.kernel.system.modular.home.service.HomePageService;
import cn.stylefeng.roses.kernel.timer.api.TimerAction;

View File

@ -27,15 +27,15 @@ package cn.stylefeng.roses.kernel.system.starter;
import cn.hutool.cache.CacheUtil;
import cn.hutool.cache.impl.TimedCache;
import cn.stylefeng.roses.kernel.cache.api.CacheOperatorApi;
import cn.stylefeng.roses.kernel.system.api.constants.InterfaceStatisticsCacheConstants;
import cn.stylefeng.roses.kernel.system.api.constants.StatisticsCacheConstants;
import cn.stylefeng.roses.kernel.system.api.constants.SystemCachesConstants;
import cn.stylefeng.roses.kernel.system.api.pojo.user.SysUserDTO;
import cn.stylefeng.roses.kernel.system.api.pojo.user.SysUserOrgDTO;
import cn.stylefeng.roses.kernel.system.modular.home.cache.InterfaceStatisticsMemoryCache;
import cn.stylefeng.roses.kernel.system.modular.role.cache.RoleDataScopeMemoryCache;
import cn.stylefeng.roses.kernel.system.modular.role.cache.RoleMemoryCache;
import cn.stylefeng.roses.kernel.system.modular.role.cache.RoleResourceMemoryCache;
import cn.stylefeng.roses.kernel.system.modular.role.entity.SysRole;
import cn.stylefeng.roses.kernel.system.modular.statistic.cache.InterfaceStatisticsMemoryCache;
import cn.stylefeng.roses.kernel.system.modular.theme.cache.ThemeMemoryCache;
import cn.stylefeng.roses.kernel.system.modular.theme.pojo.DefaultTheme;
import cn.stylefeng.roses.kernel.system.modular.user.cache.SysUserMemoryCache;
@ -46,6 +46,7 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.util.List;
import java.util.Map;
/**
*
@ -154,9 +155,9 @@ public class GunsSystemCacheAutoConfiguration {
* @date 2022/2/9 16:53
*/
@Bean
@ConditionalOnMissingBean(name = "interCountCacheApi")
public CacheOperatorApi<String> interCountCacheApi() {
TimedCache<String, String> timedCache = CacheUtil.newTimedCache(InterfaceStatisticsCacheConstants.INTERFACE_STATISTICS_CACHE_TIMEOUT_SECONDS);
@ConditionalOnMissingBean(name = "requestCountCacheApi")
public CacheOperatorApi<Map<Long,Integer>> requestCountCacheApi() {
TimedCache<String, Map<Long,Integer>> timedCache = CacheUtil.newTimedCache(StatisticsCacheConstants.INTERFACE_STATISTICS_CACHE_TIMEOUT_SECONDS);
return new InterfaceStatisticsMemoryCache(timedCache);
}
}

View File

@ -1,7 +1,7 @@
package cn.stylefeng.roses.kernel.system.starter;
import cn.stylefeng.roses.kernel.system.modular.home.aop.InterfaceStatisticsAop;
import cn.stylefeng.roses.kernel.system.modular.home.timer.InterfaceStatisticsTimer;
import cn.stylefeng.roses.kernel.system.modular.statistic.aop.InterfaceStatisticsAop;
import cn.stylefeng.roses.kernel.system.modular.statistic.timer.InterfaceStatisticsTimer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;