diff --git a/kernel-s-system/system-business-home/pom.xml b/kernel-s-system/system-business-home/pom.xml index 2e20037e3..9d9857dbe 100644 --- a/kernel-s-system/system-business-home/pom.xml +++ b/kernel-s-system/system-business-home/pom.xml @@ -107,11 +107,19 @@ compile + cn.stylefeng.roses system-business-menu ${roses.version} + + + + cn.stylefeng.roses + system-business-organization + ${roses.version} + \ No newline at end of file diff --git a/kernel-s-system/system-business-home/src/main/java/cn/stylefeng/roses/kernel/system/modular/home/service/HomePageService.java b/kernel-s-system/system-business-home/src/main/java/cn/stylefeng/roses/kernel/system/modular/home/service/HomePageService.java index 999baa5bb..efb4b68d0 100644 --- a/kernel-s-system/system-business-home/src/main/java/cn/stylefeng/roses/kernel/system/modular/home/service/HomePageService.java +++ b/kernel-s-system/system-business-home/src/main/java/cn/stylefeng/roses/kernel/system/modular/home/service/HomePageService.java @@ -2,13 +2,8 @@ package cn.stylefeng.roses.kernel.system.modular.home.service; import cn.stylefeng.roses.kernel.log.api.pojo.record.LogRecordDTO; import cn.stylefeng.roses.kernel.system.api.pojo.home.HomeCompanyInfo; -import cn.stylefeng.roses.kernel.system.api.pojo.menu.antd.AntdSysMenuDTO; -import cn.stylefeng.roses.kernel.system.api.pojo.resource.ResourceRequest; -import cn.stylefeng.roses.kernel.system.api.pojo.user.OnlineUserDTO; import cn.stylefeng.roses.kernel.system.api.pojo.user.request.OnlineUserRequest; -import cn.stylefeng.roses.kernel.system.modular.home.entity.InterfaceStatistics; import cn.stylefeng.roses.kernel.system.modular.statistic.pojo.OnlineUserStat; -import com.baomidou.mybatisplus.extension.service.IService; import cn.stylefeng.roses.kernel.system.modular.menu.entity.SysMenu; import java.util.List; diff --git a/kernel-s-system/system-business-home/src/main/java/cn/stylefeng/roses/kernel/system/modular/home/service/impl/HomePageServiceImpl.java b/kernel-s-system/system-business-home/src/main/java/cn/stylefeng/roses/kernel/system/modular/home/service/impl/HomePageServiceImpl.java index 192f36618..6d39b0cb2 100644 --- a/kernel-s-system/system-business-home/src/main/java/cn/stylefeng/roses/kernel/system/modular/home/service/impl/HomePageServiceImpl.java +++ b/kernel-s-system/system-business-home/src/main/java/cn/stylefeng/roses/kernel/system/modular/home/service/impl/HomePageServiceImpl.java @@ -1,6 +1,5 @@ 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; @@ -9,13 +8,9 @@ import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult; import cn.stylefeng.roses.kernel.log.api.LogManagerApi; import cn.stylefeng.roses.kernel.log.api.pojo.manage.LogManagerRequest; import cn.stylefeng.roses.kernel.log.api.pojo.record.LogRecordDTO; -import cn.stylefeng.roses.kernel.scanner.api.pojo.resource.ResourceDefinition; -import cn.stylefeng.roses.kernel.scanner.api.pojo.resource.ResourceUrlParam; import cn.stylefeng.roses.kernel.system.api.*; import cn.stylefeng.roses.kernel.system.api.pojo.home.HomeCompanyInfo; -import cn.stylefeng.roses.kernel.system.api.pojo.menu.antd.AntdSysMenuDTO; import cn.stylefeng.roses.kernel.system.api.pojo.organization.HrOrganizationDTO; -import cn.stylefeng.roses.kernel.system.api.pojo.resource.ResourceRequest; import cn.stylefeng.roses.kernel.system.api.pojo.user.OnlineUserDTO; import cn.stylefeng.roses.kernel.system.api.pojo.user.request.OnlineUserRequest; import cn.stylefeng.roses.kernel.system.api.pojo.user.request.SysUserRequest; @@ -26,21 +21,15 @@ import cn.stylefeng.roses.kernel.system.modular.home.service.SysStatisticsCountS 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.statistic.entity.SysStatisticsCount; +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; -import cn.stylefeng.roses.kernel.system.modular.statistic.service.SysStatisticsCountService; 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; -import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import org.springframework.stereotype.Service; import javax.annotation.Resource; -import java.time.Year; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; import java.util.*; import java.util.stream.Collectors; @@ -60,7 +49,7 @@ public class HomePageServiceImpl implements HomePageService, HomePageServiceApi private UserServiceApi userServiceApi; @Resource - private OrganizationServiceApi organizationServiceApi; + private HrOrganizationService hrOrganizationService; @Resource private PositionServiceApi positionServiceApi; @@ -68,9 +57,6 @@ public class HomePageServiceImpl implements HomePageService, HomePageServiceApi @Resource private SysUserOrgService sysUserOrgService; - @Resource - private ResourceServiceApi resourceServiceApi; - @Resource(name = "requestCountCacheApi") private CacheOperatorApi> requestCountCacheApi; @@ -123,8 +109,8 @@ public class HomePageServiceImpl implements HomePageService, HomePageServiceApi HomeCompanyInfo homeCompanyInfo = new HomeCompanyInfo(); // 获取组织机构数量 - List hrOrganizationDTOS = organizationServiceApi.orgList(); - homeCompanyInfo.setOrganizationNum(hrOrganizationDTOS.size()); + List hrOrganizationList = hrOrganizationService.list(); + homeCompanyInfo.setOrganizationNum(hrOrganizationList.size()); // 获取企业人员总数 SysUserRequest sysUserRequest = new SysUserRequest(); @@ -140,21 +126,31 @@ public class HomePageServiceImpl implements HomePageService, HomePageServiceApi // 获取组织公司ID Long organizationId = loginUser.getOrganizationId(); - List sysUserOrgs = sysUserOrgService.list(Wrappers.lambdaQuery().eq(SysUserOrg::getOrgId, organizationId)); - homeCompanyInfo.setCurrentCompanyPersonNum(sysUserOrgs.size()); // 设置公司部门数 - int sectionNum = 0; - for (HrOrganizationDTO hrOrganizationDTO : hrOrganizationDTOS) { - String[] orgPids = hrOrganizationDTO.getOrgPids().split(","); + int sectionNum = 1; + // 去除[] 的部门集合 + List orgPidList = new ArrayList<>(); + for (HrOrganization hrOrganization : hrOrganizationList) { + String[] orgPids = hrOrganization.getOrgPids().split(","); for (String orgPid : orgPids) { + orgPid = orgPid.substring(1, orgPid.length() - 1); if (organizationId.toString().equals(orgPid)) { + orgPidList.add(orgPid); sectionNum++; } } } homeCompanyInfo.setCurrentDeptNum(sectionNum); + // 设置当前公司人数 + int currentCompanyPersonNum = 0; + for (String orgId : orgPidList) { + List sysUserOrgs = sysUserOrgService.list(Wrappers.lambdaQuery().eq(SysUserOrg::getOrgId, orgId)); + currentCompanyPersonNum += sysUserOrgs.size(); + } + homeCompanyInfo.setCurrentCompanyPersonNum(currentCompanyPersonNum); + return homeCompanyInfo; } @@ -166,7 +162,7 @@ public class HomePageServiceImpl implements HomePageService, HomePageServiceApi // 菜单ID集合 List statMenuIds = new ArrayList<>(); for (Long statUrlId : statUrlIds) { - SysStatisticsUrl sysStatisticsUrl = sysStatisticsUrlService.getOne(Wrappers.lambdaQuery().eq(SysStatisticsUrl::getStatUrl, statUrlId)); + SysStatisticsUrl sysStatisticsUrl = sysStatisticsUrlService.getById(statUrlId); String statMenuId = sysStatisticsUrl.getStatMenuId(); statMenuIds.add(statMenuId); } @@ -184,8 +180,8 @@ public class HomePageServiceImpl implements HomePageService, HomePageServiceApi // key是用户id,value的key是statUrlId,最后的value是次数 Map> userRequestStats = requestCountCacheApi.getAllKeyValues(); - ArrayList sysStatisticsCounts = new ArrayList<>(); - // 遍历填充数据 + List sysStatisticsCountList = new ArrayList<>(); + // 将数据存入DB for (String userId : userRequestStats.keySet()) { SysStatisticsCount sysStatisticsCount = new SysStatisticsCount(); sysStatisticsCount.setUserId(Long.valueOf(userId)); @@ -196,11 +192,10 @@ public class HomePageServiceImpl implements HomePageService, HomePageServiceApi } // 存放到集合中 - sysStatisticsCounts.add(sysStatisticsCount); + sysStatisticsCountList.add(sysStatisticsCount); } - // 批量存入数据库 - this.sysStatisticsCountService.saveBatch(sysStatisticsCounts); + // 更新DB + sysStatisticsCountService.saveOrUpdateBatch(sysStatisticsCountList); } - }