From be8b47a820ae1989195616d59ef70ad4b9c759b9 Mon Sep 17 00:00:00 2001 From: zxc <954985706@qq.com> Date: Wed, 1 Jul 2020 14:29:51 +0800 Subject: [PATCH] =?UTF-8?q?=E7=99=BE=E5=88=86=E6=AF=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/result/TopicSummaryInfoResultDTO.java | 5 +++++ .../service/topic/impl/TopicServiceImpl.java | 17 +++++++++++++---- .../main/resources/mapper/topic/TopicDao.xml | 2 +- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/epmet-module/data-report/data-report-client/src/main/java/com/epmet/topic/dto/result/TopicSummaryInfoResultDTO.java b/epmet-module/data-report/data-report-client/src/main/java/com/epmet/topic/dto/result/TopicSummaryInfoResultDTO.java index 71b096ca0f..b007c41289 100644 --- a/epmet-module/data-report/data-report-client/src/main/java/com/epmet/topic/dto/result/TopicSummaryInfoResultDTO.java +++ b/epmet-module/data-report/data-report-client/src/main/java/com/epmet/topic/dto/result/TopicSummaryInfoResultDTO.java @@ -1,8 +1,10 @@ package com.epmet.topic.dto.result; +import com.fasterxml.jackson.annotation.JsonIgnore; import lombok.Data; import java.io.Serializable; +import java.math.BigDecimal; /** * @Author zxc @@ -27,4 +29,7 @@ public class TopicSummaryInfoResultDTO implements Serializable { * 百分比 */ private String ratio = "0.0%"; + + @JsonIgnore + private BigDecimal pro; } diff --git a/epmet-module/data-report/data-report-server/src/main/java/com/epmet/service/topic/impl/TopicServiceImpl.java b/epmet-module/data-report/data-report-server/src/main/java/com/epmet/service/topic/impl/TopicServiceImpl.java index 8c4309dfd6..339737305e 100644 --- a/epmet-module/data-report/data-report-server/src/main/java/com/epmet/service/topic/impl/TopicServiceImpl.java +++ b/epmet-module/data-report/data-report-server/src/main/java/com/epmet/service/topic/impl/TopicServiceImpl.java @@ -14,7 +14,9 @@ import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.math.BigDecimal; import java.text.DecimalFormat; +import java.text.NumberFormat; import java.time.LocalDate; import java.util.*; import java.util.stream.Collectors; @@ -187,12 +189,19 @@ public class TopicServiceImpl implements TopicService { TopicShiftedCountResultDTO shiftedCount = topicDao.getShiftedCount(agencyId); if (topicSummaryInfo.size() != NumConstant.ZERO && shiftedCount != null) { Integer collect = topicSummaryInfo.stream().collect(Collectors.summingInt(TopicSummaryInfoResultDTO::getValue)); - DecimalFormat decimalFormat = new DecimalFormat(".00"); - String ratio; - ratio = collect == NumConstant.ZERO ? NumConstant.ZERO + TopicConstant.RATIO : decimalFormat.format(((float) shiftedCount.getShiftedIssueCount() / (float) collect) * NumConstant.ONE_HUNDRED) + TopicConstant.RATIO; + topicSummaryInfo.forEach(topic -> { + String s = topic.getPro().setScale(NumConstant.TWO, BigDecimal.ROUND_HALF_UP).stripTrailingZeros().toPlainString(); + topic.setRatio(s.concat(TopicConstant.RATIO)); + }); TopicSummaryInfoResultDTO result = new TopicSummaryInfoResultDTO(); + if (collect == NumConstant.ZERO){ + result.setRatio(NumConstant.ZERO+TopicConstant.RATIO); + }else { + BigDecimal bigDecimal = new BigDecimal(((float) shiftedCount.getShiftedIssueCount() / (float) collect) * NumConstant.ONE_HUNDRED); + String s = bigDecimal.setScale(NumConstant.TWO, BigDecimal.ROUND_HALF_UP).stripTrailingZeros().toPlainString(); + result.setRatio(s.concat(TopicConstant.RATIO)); + } result.setName(TopicConstant.SHIFTED); - result.setRatio(ratio); result.setValue(shiftedCount.getShiftedIssueCount()); topicSummaryInfo.add(result); } diff --git a/epmet-module/data-report/data-report-server/src/main/resources/mapper/topic/TopicDao.xml b/epmet-module/data-report/data-report-server/src/main/resources/mapper/topic/TopicDao.xml index 29ddddc6c6..01d4a5d335 100644 --- a/epmet-module/data-report/data-report-server/src/main/resources/mapper/topic/TopicDao.xml +++ b/epmet-module/data-report/data-report-server/src/main/resources/mapper/topic/TopicDao.xml @@ -41,7 +41,7 @@ WHEN topic_status_id = 'hidden' THEN '已屏蔽' WHEN topic_status_id = 'closed' THEN '已关闭' ELSE '无' END) AS name, - CONCAT(ROUND(topic_proportion * 100,2),'%') AS ratio + (topic_proportion * 100) AS pro FROM fact_topic_status_agency_daily WHERE