|
@@ -0,0 +1,92 @@
|
|
|
+package com.hfln.portal.infrastructure.gateway.impl;
|
|
|
+
|
|
|
+import com.hfln.portal.common.dto.data.stat.ScreenStatsV2DTO;
|
|
|
+import com.hfln.portal.domain.gateway.WebStatsV2Gateway;
|
|
|
+import com.hfln.portal.infrastructure.service.*;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
+
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+@Slf4j
|
|
|
+@Service
|
|
|
+public class WebStatsV2GatewayImpl implements WebStatsV2Gateway {
|
|
|
+
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private DevInfoService devInfoService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private TblTenantService tblTenantService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private UserService userService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private AdminUserService adminuserService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ScreenStatsV2DTO queryScreenV2() {
|
|
|
+ ScreenStatsV2DTO res = new ScreenStatsV2DTO();
|
|
|
+ Map<String, BigDecimal> statInfo = devInfoService.queryStatInfoV2();
|
|
|
+ if (statInfo != null) {
|
|
|
+ res.setDeviceActivationCount(statInfo.get("deviceActivationCount") == null ? 0 : statInfo.get("deviceActivationCount").intValue());
|
|
|
+ res.setDeviceOnlineCount(statInfo.get("deviceOnlineCount") == null ? 0 : statInfo.get("deviceOnlineCount").intValue());
|
|
|
+ res.setDeviceMonthlyNewCount(statInfo.get("deviceMonthlyNewCount") == null ? 0 : statInfo.get("deviceMonthlyNewCount").intValue());
|
|
|
+ if (res.getDeviceActivationCount() != 0 && res.getDeviceOnlineCount() != 0) {
|
|
|
+ res.setDeviceActiveRate(statInfo.get("deviceOnlineCount").divide(statInfo.get("deviceActivationCount"), 4, BigDecimal.ROUND_HALF_UP).doubleValue());
|
|
|
+ } else {
|
|
|
+ res.setDeviceActiveRate(null);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ Map<String, BigDecimal> tenantStat = tblTenantService.queryStats();
|
|
|
+ if (tenantStat != null) {
|
|
|
+ res.setTenantCount(tenantStat.get("tenantCount") == null ? 0 : tenantStat.get("tenantCount").intValue());
|
|
|
+ res.setTenantMonthlyNewCount(tenantStat.get("tenantMonthlyNewCount") == null ? 0 : tenantStat.get("tenantMonthlyNewCount").intValue());
|
|
|
+ }
|
|
|
+
|
|
|
+ Map<String, BigDecimal> adminUserStat = adminuserService.queryStats();
|
|
|
+ if (adminUserStat != null) {
|
|
|
+ int adminUserCount = adminUserStat.get("adminUserCount") == null ? 0 : adminUserStat.get("adminUserCount").intValue();
|
|
|
+ res.setUserCount(res.getUserCount() + adminUserCount);
|
|
|
+ int adminUserMonthlyNewCount = adminUserStat.get("adminUserMonthlyNewCount") == null ? 0 : adminUserStat.get("adminUserMonthlyNewCount").intValue();
|
|
|
+ res.setUserMonthlyNewCount(res.getUserMonthlyNewCount() + adminUserMonthlyNewCount);
|
|
|
+ }
|
|
|
+
|
|
|
+ List<ScreenStatsV2DTO.UserDistributionInfo> userDistributionList = new ArrayList<>();
|
|
|
+ Map<String, BigDecimal> userStat = userService.queryStats();
|
|
|
+ if (userStat != null) {
|
|
|
+ res.setUserCount(res.getUserCount() + (userStat.get("userCount") == null ? 0 : userStat.get("userCount").intValue()));
|
|
|
+ res.setUserMonthlyNewCount(userStat.get("userMonthlyNewCount") == null ? 0 : userStat.get("userMonthlyNewCount").intValue());
|
|
|
+
|
|
|
+ ScreenStatsV2DTO.UserDistributionInfo userDistributionInfo = new ScreenStatsV2DTO.UserDistributionInfo();
|
|
|
+ userDistributionInfo.setDisType("personal");
|
|
|
+ userDistributionInfo.setDisTypeName("个人");
|
|
|
+ userDistributionInfo.setCount(res.getUserCount());
|
|
|
+ userDistributionList.add(userDistributionInfo);
|
|
|
+ }
|
|
|
+
|
|
|
+ List<Map<String, Object>> userDisList = adminuserService.queryUserDis();
|
|
|
+
|
|
|
+ if (!CollectionUtils.isEmpty(userDisList)) {
|
|
|
+ for (Map<String, Object> userDis : userDisList) {
|
|
|
+ ScreenStatsV2DTO.UserDistributionInfo userDistributionInfo = new ScreenStatsV2DTO.UserDistributionInfo();
|
|
|
+ userDistributionInfo.setDisType((String) userDis.get("disType"));
|
|
|
+ userDistributionInfo.setDisTypeName((String) userDis.get("disTypeName"));
|
|
|
+ userDistributionInfo.setCount(((Long) userDis.get("count")).intValue());
|
|
|
+ userDistributionList.add(userDistributionInfo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ res.setUserDistributionList(userDistributionList);
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|