浏览代码

完好率接口

Zimo 20 小时之前
父节点
当前提交
1e93286921

+ 67 - 3
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/stat/IotReportDeviceController.java

@@ -1,8 +1,6 @@
 package cn.iocoder.yudao.module.pms.controller.admin.stat;
 
 import cn.hutool.core.collection.CollUtil;
-import cn.iocoder.yudao.framework.common.exception.ErrorCode;
-import cn.iocoder.yudao.framework.common.exception.ServiceException;
 import cn.iocoder.yudao.framework.common.pojo.CommonResult;
 import cn.iocoder.yudao.framework.common.pojo.PageResult;
 import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
@@ -26,8 +24,8 @@ import cn.iocoder.yudao.module.system.dal.dataobject.dept.DeptDO;
 import cn.iocoder.yudao.module.system.dal.dataobject.dict.DictDataDO;
 import cn.iocoder.yudao.module.system.service.dept.DeptService;
 import cn.iocoder.yudao.module.system.service.dict.DictDataService;
-import com.alibaba.excel.EasyExcel;
 import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
 import io.swagger.v3.oas.annotations.Operation;
 import io.swagger.v3.oas.annotations.tags.Tag;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -43,10 +41,13 @@ import javax.annotation.security.PermitAll;
 import javax.servlet.http.HttpServletResponse;
 import javax.validation.Valid;
 import java.io.IOException;
+import java.math.BigDecimal;
+import java.math.RoundingMode;
 import java.net.URLEncoder;
 import java.util.*;
 import java.util.concurrent.atomic.AtomicInteger;
 import java.util.stream.Collectors;
+import java.util.stream.Stream;
 
 import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
 import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
@@ -341,4 +342,67 @@ public class IotReportDeviceController {
         String encodeFileName = URLEncoder.encode(fileName, "UTF-8").replaceAll("\\+", "%20");
         response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + encodeFileName + ".xlsx");
     }
+
+    @GetMapping("/rd/whl")
+    @PermitAll
+    public CommonResult<ImmutableMap<String, ImmutableMap<String, Number>>> getWhl() {
+        Set<Long> ids;
+//        if (Objects.nonNull(pageReqVO.getDeptId())) {
+        ids = deptService.getChildDeptIdListFromCache(163L);
+        ids.add(163L);
+        IotDevicePageReqVO iotDevicePageReqVO = new IotDevicePageReqVO();
+        iotDevicePageReqVO.setDeptIds(new ArrayList<>(ids));
+        iotDevicePageReqVO.setRemark("A");
+        Long totalA = iotDeviceMapper.getTotalA(iotDevicePageReqVO);
+        List<Long> failureCount = iotDeviceMapper.getFailureCount(iotDevicePageReqVO);
+        List<Long> repairCount = iotDeviceMapper.getRepairCount(iotDevicePageReqVO);
+        List<Long> combined = Stream.concat(failureCount.stream(), repairCount.stream())
+                .distinct()
+                .collect(Collectors.toList());
+        int size = combined.size();
+        BigDecimal total = BigDecimal.valueOf(totalA);
+        BigDecimal sizeA = BigDecimal.valueOf(size);
+        BigDecimal diff = total.subtract(sizeA);
+        // 计算百分比并保留两位小数
+        BigDecimal percentA = diff.multiply(BigDecimal.valueOf(100))
+                .divide(total, 2, RoundingMode.HALF_UP);
+
+        iotDevicePageReqVO.setRemark("B");
+        Long totalB = iotDeviceMapper.getTotalA(iotDevicePageReqVO);
+        List<Long> failureCountB = iotDeviceMapper.getFailureCount(iotDevicePageReqVO);
+        List<Long> repairCountB = iotDeviceMapper.getRepairCount(iotDevicePageReqVO);
+        List<Long> combinedB = Stream.concat(failureCountB.stream(), repairCountB.stream())
+                .distinct()
+                .collect(Collectors.toList());
+        int sizeB = combinedB.size();
+
+        BigDecimal totalBB = BigDecimal.valueOf(totalB);
+        BigDecimal sizeBB = BigDecimal.valueOf(sizeB);
+        BigDecimal diffB = totalBB.subtract(sizeBB);
+        // 计算百分比并保留两位小数
+        BigDecimal percentB = diffB.multiply(BigDecimal.valueOf(100))
+                .divide(totalBB, 2, RoundingMode.HALF_UP);
+
+
+        iotDevicePageReqVO.setRemark("C");
+        Long totalC = iotDeviceMapper.getTotalA(iotDevicePageReqVO);
+        List<Long> failureCountC = iotDeviceMapper.getFailureCount(iotDevicePageReqVO);
+        List<Long> repairCountC = iotDeviceMapper.getRepairCount(iotDevicePageReqVO);
+
+        List<Long> combinedC = Stream.concat(failureCountC.stream(), repairCountC.stream())
+                .distinct()
+                .collect(Collectors.toList());
+        int sizeC = combinedC.size();
+
+        BigDecimal totalCC = BigDecimal.valueOf(totalC);
+        BigDecimal sizeCC = BigDecimal.valueOf(sizeC);
+        BigDecimal diffC = totalCC.subtract(sizeCC);
+        // 计算百分比并保留两位小数
+        BigDecimal percentC = diffC.multiply(BigDecimal.valueOf(100))
+                .divide(totalCC, 2, RoundingMode.HALF_UP);
+
+
+        return CommonResult.success(ImmutableMap.of("a",ImmutableMap.of("percent", percentA,"total", totalA),
+                "b",ImmutableMap.of("percent", percentB,"total",totalB),"c",ImmutableMap.of("percent", percentC,"total", totalC)));
+    }
 }