【7.1.6】【statistics】更新首页常用功能的统计

pull/26/MERGE
fengshuonan 2022-02-12 19:20:16 +08:00
parent 01a9efd795
commit 1ada004265
9 changed files with 83 additions and 20 deletions

View File

@ -35,7 +35,7 @@ public class SysStatisticsUrl extends BaseEntity {
* ID
*/
@TableField("stat_menu_id")
private String statMenuId;
private Long statMenuId;
/**
* URL

View File

@ -2,6 +2,9 @@ package cn.stylefeng.roses.kernel.system.modular.home.mapper;
import cn.stylefeng.roses.kernel.system.modular.home.entity.SysStatisticsUrl;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* Mapper
@ -11,4 +14,12 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
*/
public interface SysStatisticsUrlMapper extends BaseMapper<SysStatisticsUrl> {
/**
* urlIdid
*
* @author fengshuonan
* @date 2022/2/12 18:55
*/
List<Long> getMenuIdsByStatUrlIdList(@Param("statUrlIds") List<Long> statUrlIds);
}

View File

@ -1,5 +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 namespace="cn.stylefeng.roses.kernel.system.modular.home.mapper.SysStatisticsCountMapper">
</mapper>

View File

@ -1,5 +1,21 @@
<?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 namespace="cn.stylefeng.roses.kernel.system.modular.home.mapper.SysStatisticsUrlMapper">
<select id="getMenuIdsByStatUrlIdList" resultType="java.lang.Long">
select stat_menu_id as statMenuId from sys_statistics_url stat
<where>
<if test="statUrlIds != null and statUrlIds.size() > 0">
stat.stat_url_id in
<foreach item="item" collection="statUrlIds" index="index" open="(" separator="," close=")">
#{item}
</foreach>
</if>
</where>
order by field(stat_url_id,
<foreach item="item" collection="statUrlIds" index="index" open="" separator="," close=")">
#{item}
</foreach>
</select>
</mapper>

View File

@ -34,7 +34,7 @@ public class SysStatisticsUrlRequest extends BaseRequest {
* ID
*/
@ChineseDescription("ID")
private String statMenuId;
private Long statMenuId;
/**
* URL

View File

@ -19,11 +19,12 @@ import cn.stylefeng.roses.kernel.system.api.pojo.user.request.OnlineUserRequest;
import cn.stylefeng.roses.kernel.system.api.pojo.user.request.SysUserRequest;
import cn.stylefeng.roses.kernel.system.modular.home.entity.SysStatisticsCount;
import cn.stylefeng.roses.kernel.system.modular.home.entity.SysStatisticsUrl;
import cn.stylefeng.roses.kernel.system.modular.home.mapper.SysStatisticsUrlMapper;
import cn.stylefeng.roses.kernel.system.modular.home.service.HomePageService;
import cn.stylefeng.roses.kernel.system.modular.home.service.SysStatisticsCountService;
import cn.stylefeng.roses.kernel.system.modular.home.service.SysStatisticsUrlService;
import cn.stylefeng.roses.kernel.system.modular.menu.entity.SysMenu;
import cn.stylefeng.roses.kernel.system.modular.menu.service.SysMenuService;
import cn.stylefeng.roses.kernel.system.modular.menu.mapper.SysMenuMapper;
import cn.stylefeng.roses.kernel.system.modular.organization.entity.HrOrganization;
import cn.stylefeng.roses.kernel.system.modular.organization.service.HrOrganizationService;
import cn.stylefeng.roses.kernel.system.modular.statistic.pojo.OnlineUserStat;
@ -75,7 +76,10 @@ public class HomePageServiceImpl implements HomePageService, HomePageServiceApi
private SysStatisticsUrlService sysStatisticsUrlService;
@Resource
private SysMenuService sysMenuService;
private SysStatisticsUrlMapper sysStatisticsUrlMapper;
@Resource
private SysMenuMapper sysMenuMapper;
@Override
public List<LogRecordDTO> getRecentLogs() {
@ -156,24 +160,29 @@ public class HomePageServiceImpl implements HomePageService, HomePageServiceApi
LoginUser loginUser = LoginContext.me().getLoginUser();
List<SysStatisticsCount> statList = sysStatisticsCountService.list(
Wrappers.lambdaQuery(SysStatisticsCount.class).eq(SysStatisticsCount::getUserId, loginUser.getUserId()).orderByDesc(SysStatisticsCount::getStatCount));
List<Long> statUrlId = statList.stream().map(SysStatisticsCount::getStatUrlId).collect(Collectors.toList());
List<Long> statUrlIdList = statList.stream().map(SysStatisticsCount::getStatUrlId).collect(Collectors.toList());
// 获取系统常驻常用功能
LambdaQueryWrapper<SysStatisticsUrl> wrapper = Wrappers.lambdaQuery(SysStatisticsUrl.class)
.eq(SysStatisticsUrl::getAlwaysShow, YesOrNotEnum.Y)
.or()
.in(ObjectUtil.isNotEmpty(statUrlId), SysStatisticsUrl::getStatUrlId, statUrlId)
.select(SysStatisticsUrl::getStatMenuId);
.select(SysStatisticsUrl::getStatUrlId);
List<SysStatisticsUrl> alwaysShowList = sysStatisticsUrlService.list(wrapper);
// 获取菜单
List<String> usualMenuIds = alwaysShowList.stream().map(SysStatisticsUrl::getStatMenuId).collect(Collectors.toList());
// 将常驻功能放在统计的常用功能最前边
if (ObjectUtil.isNotEmpty(alwaysShowList)) {
statUrlIdList.addAll(0, alwaysShowList.stream().map(SysStatisticsUrl::getStatUrlId).collect(Collectors.toList()));
}
// 如果statUrlId大于8则只截取8个
if (statUrlIdList.size() > 8) {
statUrlIdList = statUrlIdList.subList(0, 8);
}
// 获取菜单id集合
List<Long> usualMenuIds = sysStatisticsUrlMapper.getMenuIdsByStatUrlIdList(statUrlIdList);
// 获取菜单对应的图标和名称信息
LambdaQueryWrapper<SysMenu> sysMenuLambdaQueryWrapper = Wrappers.lambdaQuery(SysMenu.class)
.in(SysMenu::getMenuId, usualMenuIds)
.select(SysMenu::getMenuName, SysMenu::getAntdvIcon, SysMenu::getAntdvRouter);
List<SysMenu> list = sysMenuService.list(sysMenuLambdaQueryWrapper);
List<SysMenu> list = sysMenuMapper.getMenuStatInfoByMenuIds(usualMenuIds);
// 菜单的icon需要转为大写驼峰
for (SysMenu sysMenu : list) {
@ -182,6 +191,7 @@ public class HomePageServiceImpl implements HomePageService, HomePageServiceApi
sysMenu.setAntdvIcon(StrUtil.upperFirst(StrUtil.toCamelCase(replace)));
}
}
return list;
}

View File

@ -90,13 +90,13 @@ public class SysStatisticsUrlServiceImpl extends ServiceImpl<SysStatisticsUrlMap
Long statUrlId = sysStatisticsUrlRequest.getStatUrlId();
String statName = sysStatisticsUrlRequest.getStatName();
String statMenuId = sysStatisticsUrlRequest.getStatMenuId();
Long 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.eq(ObjectUtil.isNotEmpty(statMenuId), SysStatisticsUrl::getStatMenuId, statMenuId);
queryWrapper.like(ObjectUtil.isNotEmpty(statUrl), SysStatisticsUrl::getStatUrl, statUrl);
queryWrapper.like(ObjectUtil.isNotEmpty(alwaysShow), SysStatisticsUrl::getAlwaysShow, alwaysShow);

View File

@ -26,6 +26,9 @@ package cn.stylefeng.roses.kernel.system.modular.menu.mapper;
import cn.stylefeng.roses.kernel.system.modular.menu.entity.SysMenu;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* mapper
@ -35,4 +38,12 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
*/
public interface SysMenuMapper extends BaseMapper<SysMenu> {
/**
*
*
* @author fengshuonan
* @date 2022/2/12 19:07
*/
List<SysMenu> getMenuStatInfoByMenuIds(@Param("menuIds") List<Long> menuIds);
}

View File

@ -2,5 +2,20 @@
<!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.menu.mapper.SysMenuMapper">
<select id="getMenuStatInfoByMenuIds" resultType="cn.stylefeng.roses.kernel.system.modular.menu.entity.SysMenu">
select menu_name as menuName, antdv_icon as antdvIcon , antdv_router as antdvRouter from sys_menu menu
<where>
<if test="menuIds != null and menuIds.size() > 0">
menu.menu_id in
<foreach item="item" collection="menuIds" index="index" open="(" separator="," close=")">
#{item}
</foreach>
</if>
</where>
order by field(menu_id,
<foreach item="item" collection="menuIds" index="index" open="" separator="," close=")">
#{item}
</foreach>
</select>
</mapper>