mirror of https://gitee.com/stylefeng/roses
【7.1.6】【statistics】重新抽离统计业务
parent
d6ec22408f
commit
80914544b9
|
@ -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;
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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) {
|
||||
|
@ -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是用户id,value的key是statUrlId,最后的value是次数
|
||||
Map<String, Map<Long, Integer>> userRequestStats = requestCountCacheApi.getAllKeyValues();
|
||||
|
||||
// todo
|
||||
ArrayList<SysStatisticsCount> sysStatisticsCounts = new ArrayList<>();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
|
||||
/**
|
||||
* 需要被统计的url集合,key是url,value是stat_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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取url对应的stat_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());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -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));
|
||||
}
|
||||
|
||||
}
|
|
@ -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;
|
||||
|
||||
}
|
|
@ -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;
|
||||
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
|
@ -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> {
|
||||
|
||||
}
|
|
@ -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> {
|
||||
|
||||
}
|
|
@ -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>
|
|
@ -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>
|
|
@ -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;
|
||||
|
||||
}
|
|
@ -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;
|
||||
|
||||
}
|
|
@ -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);
|
||||
|
||||
}
|
|
@ -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);
|
||||
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
|
@ -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;
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
Loading…
Reference in New Issue