From 650736038c03ff033069cc76ab51e84c97324d45 Mon Sep 17 00:00:00 2001 From: zxc <1272811460@qq.com> Date: Mon, 14 Sep 2020 15:18:36 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=89=E5=A4=A7=E8=83=BD=E5=8A=9B=E4=B9=98?= =?UTF-8?q?=E4=B8=8A=E5=AF=B9=E5=BA=94=E6=9D=83=E9=87=8D=EF=BC=8C=E5=9B=9B?= =?UTF-8?q?=E8=88=8D=E4=BA=94=E5=85=A5=E6=8F=90=E5=87=BA=E5=85=AC=E5=85=B1?= =?UTF-8?q?=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../screen/impl/IndexServiceImpl.java | 55 ++++++++++++++++--- .../screen/ScreenIndexDataMonthlyDao.xml | 30 +++++----- .../screen/ScreenIndexDataYearlyDao.xml | 8 +-- 3 files changed, 67 insertions(+), 26 deletions(-) diff --git a/epmet-module/data-report/data-report-server/src/main/java/com/epmet/datareport/service/evaluationindex/screen/impl/IndexServiceImpl.java b/epmet-module/data-report/data-report-server/src/main/java/com/epmet/datareport/service/evaluationindex/screen/impl/IndexServiceImpl.java index e3e6ce4a61..b0c9715031 100644 --- a/epmet-module/data-report/data-report-server/src/main/java/com/epmet/datareport/service/evaluationindex/screen/impl/IndexServiceImpl.java +++ b/epmet-module/data-report/data-report-server/src/main/java/com/epmet/datareport/service/evaluationindex/screen/impl/IndexServiceImpl.java @@ -15,6 +15,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.util.CollectionUtils; +import java.math.BigDecimal; import java.time.LocalDate; import java.util.ArrayList; import java.util.Comparator; @@ -53,6 +54,10 @@ public class IndexServiceImpl implements IndexService { if (null == yearAverageIndexResultDTO){ return new YearAverageIndexResultDTO(); } + yearAverageIndexResultDTO.setPartyDevAbility(getRound(yearAverageIndexResultDTO.getPartyDevAbility())); + yearAverageIndexResultDTO.setGovernAbility(getRound(yearAverageIndexResultDTO.getGovernAbility())); + yearAverageIndexResultDTO.setServiceAbility(getRound(yearAverageIndexResultDTO.getServiceAbility())); + yearAverageIndexResultDTO.setYearAverageIndex(getRound(yearAverageIndexResultDTO.getYearAverageIndex())); return yearAverageIndexResultDTO; } @@ -66,19 +71,23 @@ public class IndexServiceImpl implements IndexService { @Override public MonthPieChartResultDTO monthPieChart(MonthPieChartFormDTO monthPieChartFormDTO) { - MonthPieChartResultDTO monthPieChartResultDTO = screenIndexDataMonthlyDao.selectMonthPieChart(monthPieChartFormDTO.getAgencyId(),null); + MonthPieChartResultDTO pieChartDTO = screenIndexDataMonthlyDao.selectMonthPieChart(monthPieChartFormDTO.getAgencyId(),null); + if (null == pieChartDTO){ + return new MonthPieChartResultDTO(); + } + // 处理小数四舍五入 + pieChartDTO.setPartyDevAbility(getRound(pieChartDTO.getPartyDevAbility())); + pieChartDTO.setGovernAbility(getRound(pieChartDTO.getGovernAbility())); + pieChartDTO.setServiceAbility(getRound(pieChartDTO.getServiceAbility())); String monthId = dateUtils.getCurrentMonthId(); int time = NumConstant.TWELVE; //保证获取月度指数数据的最大可能性 - while(null == monthPieChartResultDTO && time > NumConstant.ONE){ + while(null == pieChartDTO && time > NumConstant.ONE){ time--; monthId = dateUtils.getPreviousMonthIdByDest(null,monthId); - monthPieChartResultDTO = screenIndexDataMonthlyDao.selectMonthPieChart(monthPieChartFormDTO.getAgencyId(),monthId); + pieChartDTO = screenIndexDataMonthlyDao.selectMonthPieChart(monthPieChartFormDTO.getAgencyId(),monthId); } - if (null == monthPieChartResultDTO){ - return new MonthPieChartResultDTO(); - } - return monthPieChartResultDTO; + return pieChartDTO; } /** @@ -112,6 +121,13 @@ public class IndexServiceImpl implements IndexService { result.setTotalIndexData(totalIndexData); return result; } + // 处理小数四舍五入 + monthBarchartResults.forEach(barchart -> { + barchart.setPartyDevAbility(getRound(barchart.getPartyDevAbility())); + barchart.setGovernAbility(getRound(barchart.getGovernAbility())); + barchart.setServiceAbility(getRound(barchart.getServiceAbility())); + barchart.setIndexTotal(getRound(barchart.getIndexTotal())); + }); List collect = monthBarchartResults.stream().sorted(Comparator.comparing(MonthBarchartResult::getMonthId)).collect(Collectors.toList()); //升序 当前月份在队尾 List _ymList = dateUtils.getXpro().keySet().stream().collect(Collectors.toList()); @@ -178,6 +194,13 @@ public class IndexServiceImpl implements IndexService { if (CollectionUtils.isEmpty(subAgencyIndexRankResultDTOS)){ return new ArrayList<>(); } + // 小数四舍五入 + subAgencyIndexRankResultDTOS.forEach(indexRank -> { + indexRank.setPartyDevAbility(getRound(indexRank.getPartyDevAbility())); + indexRank.setGovernAbility(getRound(indexRank.getGovernAbility())); + indexRank.setServiceAbility(getRound(indexRank.getServiceAbility())); + indexRank.setTotalIndex(getRound(indexRank.getTotalIndex())); + }); return subAgencyIndexRankResultDTOS; } @@ -191,7 +214,25 @@ public class IndexServiceImpl implements IndexService { } else if (ScreenConstant.MONTH_ID.equals(formDTO.getType())){ // 月(上一个月) 指数排行 subAgencyIndexRankResultDTOS = screenIndexDataMonthlyDao.selectAnNingSubAgencyIndexMonthlyRank(formDTO); + subAgencyIndexRankResultDTOS.forEach(rank -> { + rank.setPartyDevAbility(getRound(rank.getPartyDevAbility())); + rank.setGovernAbility(getRound(rank.getGovernAbility())); + rank.setServiceAbility(getRound(rank.getServiceAbility())); + rank.setTotalIndex(getRound(rank.getTotalIndex())); + }); } return subAgencyIndexRankResultDTOS; } + + /** + * @Description 小数四舍五入 + * @param d + * @author zxc + * @date 2020/9/14 2:01 下午 + */ + public Double getRound(Double d){ + BigDecimal bigDecimal = new BigDecimal(d); + BigDecimal b = bigDecimal.setScale(NumConstant.ONE, BigDecimal.ROUND_HALF_UP); + return Double.valueOf(b.toString()); + } } diff --git a/epmet-module/data-report/data-report-server/src/main/resources/mapper/screen/ScreenIndexDataMonthlyDao.xml b/epmet-module/data-report/data-report-server/src/main/resources/mapper/screen/ScreenIndexDataMonthlyDao.xml index 58a41b9d5f..0a040c2ccb 100644 --- a/epmet-module/data-report/data-report-server/src/main/resources/mapper/screen/ScreenIndexDataMonthlyDao.xml +++ b/epmet-module/data-report/data-report-server/src/main/resources/mapper/screen/ScreenIndexDataMonthlyDao.xml @@ -6,9 +6,9 @@ SELECT month_id AS monthId, - ROUND(service_ablity,1) AS serviceAbility, - ROUND(party_dev_ablity,1) AS partyDevAbility, - ROUND(govern_ablity,1) AS governAbility, - ROUND(index_total,1) AS indexTotal + service_ablity * SERVICE_ABLITY_WEIGHT AS serviceAbility, + party_dev_ablity * PARTY_DEV_WEIGHT AS partyDevAbility, + govern_ablity * GOVERN_ABLITY_WEIGHT AS governAbility, + (service_ablity * SERVICE_ABLITY_WEIGHT + party_dev_ablity * PARTY_DEV_WEIGHT + govern_ablity * GOVERN_ABLITY_WEIGHT) AS indexTotal FROM screen_index_data_monthly WHERE @@ -47,10 +47,10 @@ SELECT - ROUND(index_total,1) AS yearAverageIndex, - ROUND(service_ablity,1) AS serviceAbility, - ROUND(party_dev_ablity,1) AS partyDevAbility, - ROUND(govern_ablity,1) AS governAbility + index_total AS yearAverageIndex, + service_ablity AS serviceAbility, + party_dev_ablity AS partyDevAbility, + govern_ablity AS governAbility FROM screen_index_data_yearly WHERE