package com.xuqm.tenant.service; import com.xuqm.tenant.entity.AppEntity; import com.xuqm.tenant.entity.FeatureServiceEntity; import com.xuqm.tenant.repository.AppRepository; import com.xuqm.tenant.repository.FeatureServiceRepository; import com.xuqm.tenant.repository.TenantRepository; import org.springframework.stereotype.Service; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @Service public class DashboardService { private final AppRepository appRepository; private final FeatureServiceRepository featureServiceRepository; private final TenantRepository tenantRepository; private final OperationLogService operationLogService; public DashboardService(AppRepository appRepository, FeatureServiceRepository featureServiceRepository, TenantRepository tenantRepository, OperationLogService operationLogService) { this.appRepository = appRepository; this.featureServiceRepository = featureServiceRepository; this.tenantRepository = tenantRepository; this.operationLogService = operationLogService; } public Map stats(String tenantId) { List apps = appRepository.findByTenantId(tenantId); long serviceCount = 0; for (AppEntity app : apps) { serviceCount += featureServiceRepository.findByAppId(app.getId()).stream() .filter(FeatureServiceEntity::isEnabled) .count(); } long subAccountCount = tenantRepository.countByParentId(tenantId); Map result = new LinkedHashMap<>(); result.put("appCount", apps.size()); result.put("serviceCount", serviceCount); result.put("subAccountCount", subAccountCount); operationLogService.record(tenantId, "CONSOLE", "DASHBOARD", tenantId, "VIEW_DASHBOARD", result); return result; } }