|
|
@@ -25,6 +25,7 @@ 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;
|
|
|
@@ -40,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;
|
|
|
@@ -384,4 +388,66 @@ 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, BigDecimal>> 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",percentA,"b",percentB,"c",percentC));
|
|
|
+ }
|
|
|
}
|