From b409bad9b52b613c05cb81b240be39d617dbb131 Mon Sep 17 00:00:00 2001 From: GUO <1923636941@qq.com> Date: Wed, 19 Jun 2024 21:51:30 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=A7=E5=B1=8Fbug=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../XzRiskPredictionController.java | 42 +++++++++---------- .../java/com/zhgd/xmgl/util/NumberUtils.java | 30 +++++++++++++ 2 files changed, 51 insertions(+), 21 deletions(-) diff --git a/src/main/java/com/zhgd/xmgl/modules/xz/controller/XzRiskPredictionController.java b/src/main/java/com/zhgd/xmgl/modules/xz/controller/XzRiskPredictionController.java index 159b202a6..ff1f517f3 100644 --- a/src/main/java/com/zhgd/xmgl/modules/xz/controller/XzRiskPredictionController.java +++ b/src/main/java/com/zhgd/xmgl/modules/xz/controller/XzRiskPredictionController.java @@ -265,7 +265,7 @@ public class XzRiskPredictionController { long specialNotCount = inspectionRecords.stream().filter(r -> enterpriseIds.contains(r.getEnterpriseId()) && r.getStatus() != 6 && r.getStatus() != 5 && r.getType() != null).count(); long specialCount = inspectionRecords.stream().filter(r -> enterpriseIds.contains(r.getEnterpriseId()) && r.getStatus() != 6 && r.getType() != null).count(); - oneVo.setTotalSpecialOperationsRiskRate(NumberUtils.occupyRate(specialNotCount, specialCount, 2)); + oneVo.setTotalSpecialOperationsRiskRate(NumberUtils.div(specialNotCount, specialCount, 2)); BigDecimal hiddenDangerScore = this.getHiddenDangerScore(projectSn, date, safeInspectionRecords, enterpriseIds, taskRecords); BigDecimal dangerEngScore = this.getScore(projectSn, date, dangerousEngineeringRecords, enterpriseIds, hiddenDangerInspectRecords, dangerousEngineeringSideStations); @@ -278,7 +278,7 @@ public class XzRiskPredictionController { long inspectionCount = inspectionRecords.stream().filter(r -> enterpriseIds.contains(r.getEnterpriseId()) && r.getStatus() != 6).count(); long inspectionNotCount = inspectionRecords.stream().filter(r -> enterpriseIds.contains(r.getEnterpriseId()) && r.getStatus() != 6 && r.getStatus() != 5).count(); - oneVo.setUnclosedHiddenDangersRate(NumberUtils.occupyRate(inspectionNotCount, inspectionCount, 2)); + oneVo.setUnclosedHiddenDangersRate(NumberUtils.div(inspectionNotCount, inspectionCount, 2)); oneVo.setEnterpriseId(mainEnterprise.getId()); oneVo.setEnterpriseName(mainEnterprise.getEnterpriseName()); rtList.add(oneVo); @@ -441,12 +441,12 @@ public class XzRiskPredictionController { vo.setTotalPersonnelRiskRate(0.0D); long specialNotCount = inspectionRecords.stream().filter(r -> r.getStatus() != 6 && r.getStatus() != 5 && r.getType() != null).count(); long specialCount = inspectionRecords.stream().filter(r -> r.getStatus() != 6 && r.getType() != null).count(); - vo.setTotalSpecialOperationsRiskRate(NumberUtils.occupyRate(specialNotCount, specialCount, 2)); + vo.setTotalSpecialOperationsRiskRate(NumberUtils.div(specialNotCount, specialCount, 2)); JSONObject ssJo = BeanUtil.toBean(securityQualityInspectionRecordController.getStatScore(projectSn), JSONObject.class); vo.setMonthlySafetyScoreRate(ssJo.getDouble("total")); long inspectionCount = inspectionRecords.stream().filter(r -> r.getStatus() != 6).count(); long inspectionNotCount = inspectionRecords.stream().filter(r -> r.getStatus() != 6 && r.getStatus() != 5).count(); - vo.setUnclosedHiddenDangersRate(NumberUtils.occupyRate(inspectionNotCount, inspectionCount, 2)); + vo.setUnclosedHiddenDangersRate(NumberUtils.div(inspectionNotCount, inspectionCount, 2)); return Result.success(vo); } @@ -510,14 +510,14 @@ public class XzRiskPredictionController { temHighLow++; } } - vo.setSpecialOperationFireSafety(NumberUtils.occupyRate(wind + yuLei, 6, 2)); - vo.setHighJobSafe(NumberUtils.occupyRate(wind + yuLeiXue, 6, 2)); - vo.setBlindPlatePlugSafe(NumberUtils.occupyRate(wind + yuLei, 6, 2)); - vo.setLimitSpaceSafe(NumberUtils.occupyRate(yu + temHighLow, 6, 2)); - vo.setOpenCircuitSafe(NumberUtils.occupyRate(wind + yuLei, 6, 2)); - vo.setTemporaryElectricitySafe(NumberUtils.occupyRate(yuLeiXue, 3, 2)); - vo.setHoistSafetyWork(NumberUtils.occupyRate(yuLeiXue, 3, 2)); - vo.setGroundSafet(NumberUtils.occupyRate(yu + temHigh, 6, 2)); + vo.setSpecialOperationFireSafety(NumberUtils.div(wind + yuLei, 6, 2)); + vo.setHighJobSafe(NumberUtils.div(wind + yuLeiXue, 6, 2)); + vo.setBlindPlatePlugSafe(NumberUtils.div(wind + yuLei, 6, 2)); + vo.setLimitSpaceSafe(NumberUtils.div(yu + temHighLow, 6, 2)); + vo.setOpenCircuitSafe(NumberUtils.div(wind + yuLei, 6, 2)); + vo.setTemporaryElectricitySafe(NumberUtils.div(yuLeiXue, 3, 2)); + vo.setHoistSafetyWork(NumberUtils.div(yuLeiXue, 3, 2)); + vo.setGroundSafet(NumberUtils.div(yu + temHigh, 6, 2)); } else { vo.setBlindPlatePlugSafe(0.0D); vo.setGroundSafet(0.0D); @@ -535,28 +535,28 @@ public class XzRiskPredictionController { .eq(XzSecurityQualityInspectionRecord::getRecordType, 1)); long nc1 = inspectionRecords.stream().filter(r -> !Objects.equals(r.getStatus(), 5) && Objects.equals(r.getType(), 2)).count(); long c1 = inspectionRecords.stream().filter(r -> Objects.equals(r.getType(), 2)).count(); - vo.setSpecialOperationFireSafety(NumberUtils.occupyRate(nc1, c1, 2)); + vo.setSpecialOperationFireSafety(NumberUtils.div(nc1, c1, 2)); long nc2 = inspectionRecords.stream().filter(r -> !Objects.equals(r.getStatus(), 5) && Objects.equals(r.getType(), 5)).count(); long c2 = inspectionRecords.stream().filter(r -> Objects.equals(r.getType(), 5)).count(); - vo.setHighJobSafe(NumberUtils.occupyRate(nc2, c2, 2)); + vo.setHighJobSafe(NumberUtils.div(nc2, c2, 2)); long nc3 = inspectionRecords.stream().filter(r -> !Objects.equals(r.getStatus(), 5) && Objects.equals(r.getType(), 4)).count(); long c3 = inspectionRecords.stream().filter(r -> Objects.equals(r.getType(), 4)).count(); - vo.setBlindPlatePlugSafe(NumberUtils.occupyRate(nc3, c3, 2)); + vo.setBlindPlatePlugSafe(NumberUtils.div(nc3, c3, 2)); long nc4 = inspectionRecords.stream().filter(r -> !Objects.equals(r.getStatus(), 5) && Objects.equals(r.getType(), 3)).count(); long c4 = inspectionRecords.stream().filter(r -> Objects.equals(r.getType(), 3)).count(); - vo.setLimitSpaceSafe(NumberUtils.occupyRate(nc4, c4, 2)); + vo.setLimitSpaceSafe(NumberUtils.div(nc4, c4, 2)); long nc5 = inspectionRecords.stream().filter(r -> !Objects.equals(r.getStatus(), 5) && Objects.equals(r.getType(), 9)).count(); long c5 = inspectionRecords.stream().filter(r -> Objects.equals(r.getType(), 9)).count(); - vo.setOpenCircuitSafe(NumberUtils.occupyRate(nc5, c5, 2)); + vo.setOpenCircuitSafe(NumberUtils.div(nc5, c5, 2)); long nc6 = inspectionRecords.stream().filter(r -> !Objects.equals(r.getStatus(), 5) && Objects.equals(r.getType(), 7)).count(); long c6 = inspectionRecords.stream().filter(r -> Objects.equals(r.getType(), 7)).count(); - vo.setTemporaryElectricitySafe(NumberUtils.occupyRate(nc6, c6, 2)); + vo.setTemporaryElectricitySafe(NumberUtils.div(nc6, c6, 2)); long nc7 = inspectionRecords.stream().filter(r -> !Objects.equals(r.getStatus(), 5) && Objects.equals(r.getType(), 6)).count(); long c7 = inspectionRecords.stream().filter(r -> Objects.equals(r.getType(), 6)).count(); - vo.setHoistSafetyWork(NumberUtils.occupyRate(nc7, c7, 2)); + vo.setHoistSafetyWork(NumberUtils.div(nc7, c7, 2)); long nc8 = inspectionRecords.stream().filter(r -> !Objects.equals(r.getStatus(), 5) && Objects.equals(r.getType(), 8)).count(); long c8 = inspectionRecords.stream().filter(r -> Objects.equals(r.getType(), 8)).count(); - vo.setGroundSafet(NumberUtils.occupyRate(nc8, c8, 2)); + vo.setGroundSafet(NumberUtils.div(nc8, c8, 2)); } return Result.success(vo); } @@ -590,7 +590,7 @@ public class XzRiskPredictionController { } } } - return NumberUtils.occupyRate(count, 6, 2); + return NumberUtils.div(count, 6, 2); } @ApiOperation(value = "查询项目下总包的人员风险趋势分析", notes = "查询项目下总包的人员风险趋势分析", httpMethod = "GET") diff --git a/src/main/java/com/zhgd/xmgl/util/NumberUtils.java b/src/main/java/com/zhgd/xmgl/util/NumberUtils.java index 34012bcba..0e619389c 100644 --- a/src/main/java/com/zhgd/xmgl/util/NumberUtils.java +++ b/src/main/java/com/zhgd/xmgl/util/NumberUtils.java @@ -28,6 +28,36 @@ public class NumberUtils { return NumberUtil.round(b1 / b2, scale).doubleValue(); } + /** + * 除以 + * + * @param b1 + * @param b2 + * @param scale + * @return + */ + public static Double div(Integer b1, Integer b2, Integer scale) { + if (b1 == null || b2 == null || b2.equals(0)) { + return null; + } + return NumberUtil.round(b1 * 1.0D / b2, scale).doubleValue(); + } + + /** + * 除以 + * + * @param b1 + * @param b2 + * @param scale + * @return + */ + public static Double div(Long b1, Long b2, Integer scale) { + if (b1 == null || b2 == null || b2.equals(0L)) { + return null; + } + return NumberUtil.round(b1 * 1.0D / b2, scale).doubleValue(); + } + /** * 涨跌幅比率,b1比b2增长多少 *